Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef TOOLS_GN_SCOPE_H_ | 5 #ifndef TOOLS_GN_SCOPE_H_ |
| 6 #define TOOLS_GN_SCOPE_H_ | 6 #define TOOLS_GN_SCOPE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 protected: | 61 protected: |
| 62 Scope* scope_; | 62 Scope* scope_; |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 // Options for configuring scope merges. | 65 // Options for configuring scope merges. |
| 66 struct MergeOptions { | 66 struct MergeOptions { |
| 67 // Defaults to all false, which are the things least likely to cause errors. | 67 // Defaults to all false, which are the things least likely to cause errors. |
| 68 MergeOptions() | 68 MergeOptions() |
| 69 : clobber_existing(false), | 69 : clobber_existing(false), |
| 70 skip_private_vars(false), | 70 skip_private_vars(false), |
| 71 mark_used(false) { | 71 mark_dest_used(false) { |
| 72 } | 72 } |
| 73 | 73 |
| 74 // When set, all existing avlues in the destination scope will be | 74 // When set, all existing avlues in the destination scope will be |
| 75 // overwritten. | 75 // overwritten. |
| 76 // | 76 // |
| 77 // When false, it will be an error to merge a variable into another scope | 77 // When false, it will be an error to merge a variable into another scope |
| 78 // where a variable with the same name is already set. The exception is | 78 // where a variable with the same name is already set. The exception is |
| 79 // if both of the variables have the same value (which happens if you | 79 // if both of the variables have the same value (which happens if you |
| 80 // somehow multiply import the same file, for example). This case will be | 80 // somehow multiply import the same file, for example). This case will be |
| 81 // ignored since there is nothing getting lost. | 81 // ignored since there is nothing getting lost. |
| 82 bool clobber_existing; | 82 bool clobber_existing; |
| 83 | 83 |
| 84 // When true, private variables (names beginning with an underscore) will | 84 // When true, private variables (names beginning with an underscore) will |
| 85 // be copied to the destination scope. When false, private values will be | 85 // be copied to the destination scope. When false, private values will be |
| 86 // skipped. | 86 // skipped. |
| 87 bool skip_private_vars; | 87 bool skip_private_vars; |
| 88 | 88 |
| 89 // When set, values copied to the destination scope will be marked as used | 89 // When set, values copied to the destination scope will be marked as used |
| 90 // so won't trigger an unused variable warning. You want this when doing an | 90 // so won't trigger an unused variable warning. You want this when doing an |
| 91 // import, for example, or files that don't need a variable from the .gni | 91 // import, for example, or files that don't need a variable from the .gni |
| 92 // file will throw an error. | 92 // file will throw an error. |
| 93 bool mark_used; | 93 bool mark_dest_used; |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 // Creates an empty toplevel scope. | 96 // Creates an empty toplevel scope. |
| 97 explicit Scope(const Settings* settings); | 97 explicit Scope(const Settings* settings); |
| 98 | 98 |
| 99 // Creates a dependent scope. | 99 // Creates a dependent scope. |
| 100 explicit Scope(Scope* parent); | 100 explicit Scope(Scope* parent); |
| 101 explicit Scope(const Scope* parent); | 101 explicit Scope(const Scope* parent); |
| 102 | 102 |
| 103 ~Scope(); | 103 ~Scope(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 // Same as GetValue, but if the value exists in a parent scope, we'll copy | 148 // Same as GetValue, but if the value exists in a parent scope, we'll copy |
| 149 // it to the current scope. If the return value is non-null, the value is | 149 // it to the current scope. If the return value is non-null, the value is |
| 150 // guaranteed to be set in the current scope. Generatlly this will be used | 150 // guaranteed to be set in the current scope. Generatlly this will be used |
| 151 // if the calling code is planning on modifying the value in-place. | 151 // if the calling code is planning on modifying the value in-place. |
| 152 // | 152 // |
| 153 // Since this is used when doing read-modifies, we never count this access | 153 // Since this is used when doing read-modifies, we never count this access |
| 154 // as reading the variable, since we assume it will be written to. | 154 // as reading the variable, since we assume it will be written to. |
| 155 Value* GetValueForcedToCurrentScope(const base::StringPiece& ident, | 155 Value* GetValueForcedToCurrentScope(const base::StringPiece& ident, |
| 156 const ParseNode* set_node); | 156 const ParseNode* set_node); |
| 157 | 157 |
| 158 // Returns the StringPiece used to identify the value. This string piece | |
| 159 // will have the same contents as "ident" passed in, but may point to a | |
| 160 // different underlying buffer. This is useful because this StringPiece is | |
| 161 // static and won't be deleted for the life of the program, so it can be used | |
| 162 // as keys in places that may outlive a temporary. It will return an empty | |
| 163 // string for programatic and nonexistant values. | |
|
Dirk Pranke
2015/08/03 21:12:24
still have the "programmatic" typo
| |
| 164 base::StringPiece GetStorageKey(const base::StringPiece& ident) const; | |
| 165 | |
| 158 // The set_node indicates the statement that caused the set, for displaying | 166 // The set_node indicates the statement that caused the set, for displaying |
| 159 // errors later. Returns a pointer to the value in the current scope (a copy | 167 // errors later. Returns a pointer to the value in the current scope (a copy |
| 160 // is made for storage). | 168 // is made for storage). |
| 161 Value* SetValue(const base::StringPiece& ident, | 169 Value* SetValue(const base::StringPiece& ident, |
| 162 const Value& v, | 170 const Value& v, |
| 163 const ParseNode* set_node); | 171 const ParseNode* set_node); |
| 164 | 172 |
| 165 // Removes the value with the given identifier if it exists on the current | 173 // Removes the value with the given identifier if it exists on the current |
| 166 // scope. This does not search recursive scopes. Does nothing if not found. | 174 // scope. This does not search recursive scopes. Does nothing if not found. |
| 167 void RemoveIdentifier(const base::StringPiece& ident); | 175 void RemoveIdentifier(const base::StringPiece& ident); |
| 168 | 176 |
| 169 // Removes from this scope all identifiers and templates that are considered | 177 // Removes from this scope all identifiers and templates that are considered |
| 170 // private. | 178 // private. |
| 171 void RemovePrivateIdentifiers(); | 179 void RemovePrivateIdentifiers(); |
| 172 | 180 |
| 173 // Templates associated with this scope. A template can only be set once, so | 181 // Templates associated with this scope. A template can only be set once, so |
| 174 // AddTemplate will fail and return false if a rule with that name already | 182 // AddTemplate will fail and return false if a rule with that name already |
| 175 // exists. GetTemplate returns NULL if the rule doesn't exist, and it will | 183 // exists. GetTemplate returns NULL if the rule doesn't exist, and it will |
| 176 // check all containing scoped rescursively. | 184 // check all containing scoped rescursively. |
| 177 bool AddTemplate(const std::string& name, const Template* templ); | 185 bool AddTemplate(const std::string& name, const Template* templ); |
| 178 const Template* GetTemplate(const std::string& name) const; | 186 const Template* GetTemplate(const std::string& name) const; |
| 179 | 187 |
| 180 // Marks the given identifier as (un)used in the current scope. | 188 // Marks the given identifier as (un)used in the current scope. |
| 181 void MarkUsed(const base::StringPiece& ident); | 189 void MarkUsed(const base::StringPiece& ident); |
| 190 void MarkAllUsed(); | |
| 182 void MarkUnused(const base::StringPiece& ident); | 191 void MarkUnused(const base::StringPiece& ident); |
| 183 | 192 |
| 184 // Checks to see if the scope has a var set that hasn't been used. This is | 193 // Checks to see if the scope has a var set that hasn't been used. This is |
| 185 // called before replacing the var with a different one. It does not check | 194 // called before replacing the var with a different one. It does not check |
| 186 // containing scopes. | 195 // containing scopes. |
| 187 // | 196 // |
| 188 // If the identifier is present but hasnn't been used, return true. | 197 // If the identifier is present but hasnn't been used, return true. |
| 189 bool IsSetButUnused(const base::StringPiece& ident) const; | 198 bool IsSetButUnused(const base::StringPiece& ident) const; |
| 190 | 199 |
| 191 // Checks the scope to see if any values were set but not used, and fills in | 200 // Checks the scope to see if any values were set but not used, and fills in |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 | 354 |
| 346 typedef std::set<ProgrammaticProvider*> ProviderSet; | 355 typedef std::set<ProgrammaticProvider*> ProviderSet; |
| 347 ProviderSet programmatic_providers_; | 356 ProviderSet programmatic_providers_; |
| 348 | 357 |
| 349 SourceDir source_dir_; | 358 SourceDir source_dir_; |
| 350 | 359 |
| 351 DISALLOW_COPY_AND_ASSIGN(Scope); | 360 DISALLOW_COPY_AND_ASSIGN(Scope); |
| 352 }; | 361 }; |
| 353 | 362 |
| 354 #endif // TOOLS_GN_SCOPE_H_ | 363 #endif // TOOLS_GN_SCOPE_H_ |
| OLD | NEW |