summaryrefslogtreecommitdiffstats
path: root/tools/gn/scope.h
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-16 19:31:36 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-16 19:31:36 +0000
commitafb30e39c6791afed6cd12f085649400e4d80ae8 (patch)
treed70c0df0f227870789f6c5e9fdcb4e06de926f80 /tools/gn/scope.h
parentdb7cb05b956953a7868d6c4e359ead2f644965eb (diff)
downloadchromium_src-afb30e39c6791afed6cd12f085649400e4d80ae8.zip
chromium_src-afb30e39c6791afed6cd12f085649400e4d80ae8.tar.gz
chromium_src-afb30e39c6791afed6cd12f085649400e4d80ae8.tar.bz2
Support private values in GN.
This adds special handling for variables that begin with underscores, which is inspired by Dart. Such variables are not imported when doing an import, which gives .gni files a way to have intermediate private variables that won't pollute the scopes of the files that include them. This also applies to the root build config, which can have private values now. Adds some missing unused variable checks. This was disabled because processing imports would mean all imported variables were unused, and files not using all of them would get unused variable errors. This adds the option to mark merged values on a scope as used, which is used for imported values. BUG=341738 R=cjhopman@chromium.org Review URL: https://codereview.chromium.org/287693002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271078 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/gn/scope.h')
-rw-r--r--tools/gn/scope.h53
1 files changed, 40 insertions, 13 deletions
diff --git a/tools/gn/scope.h b/tools/gn/scope.h
index 53b3252..035d45b 100644
--- a/tools/gn/scope.h
+++ b/tools/gn/scope.h
@@ -65,6 +65,37 @@ class Scope {
Scope* scope_;
};
+ // Options for configuring scope merges.
+ struct MergeOptions {
+ // Defaults to all false, which are the things least likely to cause errors.
+ MergeOptions()
+ : clobber_existing(false),
+ skip_private_vars(false),
+ mark_used(false) {
+ }
+
+ // When set, all existing avlues in the destination scope will be
+ // overwritten.
+ //
+ // When false, it will be an error to merge a variable into another scope
+ // where a variable with the same name is already set. The exception is
+ // if both of the variables have the same value (which happens if you
+ // somehow multiply import the same file, for example). This case will be
+ // ignored since there is nothing getting lost.
+ bool clobber_existing;
+
+ // When true, private variables (names beginning with an underscore) will
+ // be copied to the destination scope. When false, private values will be
+ // skipped.
+ bool skip_private_vars;
+
+ // When set, values copied to the destination scope will be marked as used
+ // so won't trigger an unused variable warning. You want this when doing an
+ // import, for example, or files that don't need a variable from the .gni
+ // file will throw an error.
+ bool mark_used;
+ };
+
// Creates an empty toplevel scope.
Scope(const Settings* settings);
@@ -138,6 +169,10 @@ class Scope {
// scope. This does not search recursive scopes. Does nothing if not found.
void RemoveIdentifier(const base::StringPiece& ident);
+ // Removes from this scope all identifiers and templates that are considered
+ // private.
+ void RemovePrivateIdentifiers();
+
// Templates associated with this scope. A template can only be set once, so
// AddTemplate will fail and return false if a rule with that name already
// exists. GetTemplate returns NULL if the rule doesn't exist, and it will
@@ -169,30 +204,22 @@ class Scope {
// copied, neither will the reference to the containing scope (this is why
// it's "non-recursive").
//
- // If clobber_existing is true, any existing values will be overwritten. In
- // this mode, this function will never fail.
- //
- // If clobber_existing is false, it will be an error to merge a variable into
- // a scope that already has something with that name in scope (meaning in
- // that scope or in any of its containing scopes). If this happens, the error
- // will be set and the function will return false.
- //
// This is used in different contexts. When generating the error, the given
// parse node will be blamed, and the given desc will be used to describe
// the operation that doesn't support doing this. For example, desc_for_err
// would be "import" when doing an import, and the error string would say
// something like "The import contains...".
bool NonRecursiveMergeTo(Scope* dest,
- bool clobber_existing,
+ const MergeOptions& options,
const ParseNode* node_for_err,
const char* desc_for_err,
Err* err) const;
// Constructs a scope that is a copy of the current one. Nested scopes will
- // be collapsed until we reach a const containing scope. The resulting
- // closure will reference the const containing scope as its containing scope
- // (since we assume the const scope won't change, we don't have to copy its
- // values).
+ // be collapsed until we reach a const containing scope. Private values will
+ // be included. The resulting closure will reference the const containing
+ // scope as its containing scope (since we assume the const scope won't
+ // change, we don't have to copy its values).
scoped_ptr<Scope> MakeClosure() const;
// Makes an empty scope with the given name. Returns NULL if the name is