Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: tools/gn/scope.h

Issue 269723006: Add get_target_outputs function to GN (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/gn/loader.cc ('k') | tools/gn/scope.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/containers/hash_tables.h" 12 #include "base/containers/hash_tables.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/scoped_vector.h"
14 #include "tools/gn/err.h" 15 #include "tools/gn/err.h"
15 #include "tools/gn/pattern.h" 16 #include "tools/gn/pattern.h"
16 #include "tools/gn/source_dir.h" 17 #include "tools/gn/source_dir.h"
17 #include "tools/gn/value.h" 18 #include "tools/gn/value.h"
18 19
19 class FunctionCallNode; 20 class FunctionCallNode;
20 class ImportManager; 21 class ImportManager;
22 class Item;
21 class ParseNode; 23 class ParseNode;
22 class Settings; 24 class Settings;
23 class TargetManager; 25 class TargetManager;
24 class Template; 26 class Template;
25 27
26 // Scope for the script execution. 28 // Scope for the script execution.
27 // 29 //
28 // Scopes are nested. Writing goes into the toplevel scope, reading checks 30 // Scopes are nested. Writing goes into the toplevel scope, reading checks
29 // values resursively down the stack until a match is found or there are no 31 // values resursively down the stack until a match is found or there are no
30 // more containing scopes. 32 // more containing scopes.
31 // 33 //
32 // A containing scope can be const or non-const. The const containing scope is 34 // A containing scope can be const or non-const. The const containing scope is
33 // used primarily to refer to the master build config which is shared across 35 // used primarily to refer to the master build config which is shared across
34 // many invocations. A const containing scope, however, prevents us from 36 // many invocations. A const containing scope, however, prevents us from
35 // marking variables "used" which prevents us from issuing errors on unused 37 // marking variables "used" which prevents us from issuing errors on unused
36 // variables. So you should use a non-const containing scope whenever possible. 38 // variables. So you should use a non-const containing scope whenever possible.
37 class Scope { 39 class Scope {
38 public: 40 public:
39 typedef base::hash_map<base::StringPiece, Value> KeyValueMap; 41 typedef base::hash_map<base::StringPiece, Value> KeyValueMap;
42 // Holds an owning list of scoped_ptrs of Items (since we can't make a vector
43 // of scoped_ptrs).
44 typedef ScopedVector< scoped_ptr<Item> > ItemVector;
40 45
41 // Allows code to provide values for built-in variables. This class will 46 // Allows code to provide values for built-in variables. This class will
42 // automatically register itself on construction and deregister itself on 47 // automatically register itself on construction and deregister itself on
43 // destruction. 48 // destruction.
44 class ProgrammaticProvider { 49 class ProgrammaticProvider {
45 public: 50 public:
46 ProgrammaticProvider(Scope* scope) : scope_(scope) { 51 ProgrammaticProvider(Scope* scope) : scope_(scope) {
47 scope_->AddProvider(this); 52 scope_->AddProvider(this);
48 } 53 }
49 ~ProgrammaticProvider() { 54 ~ProgrammaticProvider() {
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 void SetProcessingImport(); 222 void SetProcessingImport();
218 void ClearProcessingImport(); 223 void ClearProcessingImport();
219 bool IsProcessingImport() const; 224 bool IsProcessingImport() const;
220 225
221 // The source directory associated with this scope. This will check embedded 226 // The source directory associated with this scope. This will check embedded
222 // scopes until it finds a nonempty source directory. This will default to 227 // scopes until it finds a nonempty source directory. This will default to
223 // an empty dir if no containing scope has a source dir set. 228 // an empty dir if no containing scope has a source dir set.
224 const SourceDir& GetSourceDir() const; 229 const SourceDir& GetSourceDir() const;
225 void set_source_dir(const SourceDir& d) { source_dir_ = d; } 230 void set_source_dir(const SourceDir& d) { source_dir_ = d; }
226 231
232 // The item collector is where Items (Targets, Configs, etc.) go that have
233 // been defined. If a scope can generate items, this non-owning pointer will
234 // point to the storage for such items. The creator of this scope will be
235 // responsible for setting up the collector and then dealing with the
236 // collected items once execution of the context is complete.
237 //
238 // The items in a scope are collected as we go and then dispatched at the end
239 // of execution of a scope so that we can query the previously-generated
240 // targets (like getting the outputs).
241 //
242 // This can be null if the current scope can not generate items (like for
243 // imports and such).
244 //
245 // When retrieving the collector, the non-const scopes are recursively
246 // queried. The collector is not copied for closures, etc.
247 void set_item_collector(ItemVector* collector) {
248 item_collector_ = collector;
249 }
250 ItemVector* GetItemCollector();
251
227 // Properties are opaque pointers that code can use to set state on a Scope 252 // Properties are opaque pointers that code can use to set state on a Scope
228 // that it can retrieve later. 253 // that it can retrieve later.
229 // 254 //
230 // The key should be a pointer to some use-case-specific object (to avoid 255 // The key should be a pointer to some use-case-specific object (to avoid
231 // collisions, otherwise it doesn't matter). Memory management is up to the 256 // collisions, otherwise it doesn't matter). Memory management is up to the
232 // setter. Setting the value to NULL will delete the property. 257 // setter. Setting the value to NULL will delete the property.
233 // 258 //
234 // Getting a property recursively searches all scopes, and the optional 259 // Getting a property recursively searches all scopes, and the optional
235 // |found_on_scope| variable will be filled with the actual scope containing 260 // |found_on_scope| variable will be filled with the actual scope containing
236 // the key (if the pointer is non-NULL). 261 // the key (if the pointer is non-NULL).
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 NamedScopeMap target_defaults_; 301 NamedScopeMap target_defaults_;
277 302
278 // Null indicates not set and that we should fallback to the containing 303 // Null indicates not set and that we should fallback to the containing
279 // scope's filter. 304 // scope's filter.
280 scoped_ptr<PatternList> sources_assignment_filter_; 305 scoped_ptr<PatternList> sources_assignment_filter_;
281 306
282 // Owning pointers, must be deleted. 307 // Owning pointers, must be deleted.
283 typedef std::map<std::string, const Template*> TemplateMap; 308 typedef std::map<std::string, const Template*> TemplateMap;
284 TemplateMap templates_; 309 TemplateMap templates_;
285 310
311 ItemVector* item_collector_;
312
286 // Opaque pointers. See SetProperty() above. 313 // Opaque pointers. See SetProperty() above.
287 typedef std::map<const void*, void*> PropertyMap; 314 typedef std::map<const void*, void*> PropertyMap;
288 PropertyMap properties_; 315 PropertyMap properties_;
289 316
290 typedef std::set<ProgrammaticProvider*> ProviderSet; 317 typedef std::set<ProgrammaticProvider*> ProviderSet;
291 ProviderSet programmatic_providers_; 318 ProviderSet programmatic_providers_;
292 319
293 SourceDir source_dir_; 320 SourceDir source_dir_;
294 321
295 DISALLOW_COPY_AND_ASSIGN(Scope); 322 DISALLOW_COPY_AND_ASSIGN(Scope);
296 }; 323 };
297 324
298 #endif // TOOLS_GN_SCOPE_H_ 325 #endif // TOOLS_GN_SCOPE_H_
OLDNEW
« no previous file with comments | « tools/gn/loader.cc ('k') | tools/gn/scope.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698