Index: tools/gn/scope.h |
diff --git a/tools/gn/scope.h b/tools/gn/scope.h |
index 1b0246dad8e46bf7a51a08bd8a7da0371ae554c8..4bfc17ee08b57313a0e53a1ef1e8ee096b0908cb 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 are the things least likely to cause errors. |
+ MergeOptions() |
+ : clobber_existing(false), |
+ copy_private_vars(true), |
cjhopman
2014/05/14 16:42:43
nit: how about clear_private_vars so that the defa
brettw
2014/05/15 19:44:15
Done.
|
+ 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 copy_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); |
@@ -134,6 +165,9 @@ class Scope { |
const Value& v, |
const ParseNode* set_node); |
+ // Deletes the given named value from the current scope if it exists. |
+ void DeleteValue(const base::StringPiece& ident); |
+ |
// 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 |
@@ -159,36 +193,29 @@ class Scope { |
// Returns all values set in the current scope, without going to the parent |
// scopes. |
void GetCurrentScopeValues(KeyValueMap* output) const; |
+ void GetCurrentScopeVariables(std::vector<base::StringPiece>* output) const; |
// Copies this scope's values into the destination. Values from the |
// containing scope(s) (normally shadowed into the current one) will not be |
// 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 |
@@ -263,6 +290,11 @@ class Scope { |
void SetProperty(const void* key, void* value); |
void* GetProperty(const void* key, const Scope** found_on_scope) const; |
+ // Returns true if this variable name should be considered private. Private |
+ // values start with an underscore, and are not imported from "gni" files |
+ // when processing an import. |
+ static bool IsPrivateVar(const base::StringPiece& name); |
+ |
private: |
friend class ProgrammaticProvider; |