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

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

Issue 964203002: tools/gn: Fix errors found by Facebook's flint tool. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix chromium-style plugin errors Created 5 years, 9 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
« no previous file with comments | « tools/gn/pattern.h ('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
(...skipping 30 matching lines...) Expand all
41 public: 41 public:
42 typedef base::hash_map<base::StringPiece, Value> KeyValueMap; 42 typedef base::hash_map<base::StringPiece, Value> KeyValueMap;
43 // Holds an owning list of Items. 43 // Holds an owning list of Items.
44 typedef ScopedVector<Item> ItemVector; 44 typedef ScopedVector<Item> ItemVector;
45 45
46 // 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
47 // automatically register itself on construction and deregister itself on 47 // automatically register itself on construction and deregister itself on
48 // destruction. 48 // destruction.
49 class ProgrammaticProvider { 49 class ProgrammaticProvider {
50 public: 50 public:
51 ProgrammaticProvider(Scope* scope) : scope_(scope) { 51 explicit ProgrammaticProvider(Scope* scope) : scope_(scope) {
52 scope_->AddProvider(this); 52 scope_->AddProvider(this);
53 } 53 }
54 ~ProgrammaticProvider() { 54 virtual ~ProgrammaticProvider();
55 scope_->RemoveProvider(this);
56 }
57 55
58 // Returns a non-null value if the given value can be programmatically 56 // Returns a non-null value if the given value can be programmatically
59 // generated, or NULL if there is none. 57 // generated, or NULL if there is none.
60 virtual const Value* GetProgrammaticValue( 58 virtual const Value* GetProgrammaticValue(
61 const base::StringPiece& ident) = 0; 59 const base::StringPiece& ident) = 0;
62 60
63 protected: 61 protected:
64 Scope* scope_; 62 Scope* scope_;
65 }; 63 };
66 64
(...skipping 22 matching lines...) Expand all
89 bool skip_private_vars; 87 bool skip_private_vars;
90 88
91 // 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
92 // 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
93 // 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
94 // file will throw an error. 92 // file will throw an error.
95 bool mark_used; 93 bool mark_used;
96 }; 94 };
97 95
98 // Creates an empty toplevel scope. 96 // Creates an empty toplevel scope.
99 Scope(const Settings* settings); 97 explicit Scope(const Settings* settings);
100 98
101 // Creates a dependent scope. 99 // Creates a dependent scope.
102 Scope(Scope* parent); 100 explicit Scope(Scope* parent);
103 Scope(const Scope* parent); 101 explicit Scope(const Scope* parent);
104 102
105 ~Scope(); 103 ~Scope();
106 104
107 const Settings* settings() const { return settings_; } 105 const Settings* settings() const { return settings_; }
108 106
109 // See the const_/mutable_containing_ var declaraions below. Yes, it's a 107 // See the const_/mutable_containing_ var declaraions below. Yes, it's a
110 // bit weird that we can have a const pointer to the "mutable" one. 108 // bit weird that we can have a const pointer to the "mutable" one.
111 Scope* mutable_containing() { return mutable_containing_; } 109 Scope* mutable_containing() { return mutable_containing_; }
112 const Scope* mutable_containing() const { return mutable_containing_; } 110 const Scope* mutable_containing() const { return mutable_containing_; }
113 const Scope* const_containing() const { return const_containing_; } 111 const Scope* const_containing() const { return const_containing_; }
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 // |found_on_scope| variable will be filled with the actual scope containing 289 // |found_on_scope| variable will be filled with the actual scope containing
292 // the key (if the pointer is non-NULL). 290 // the key (if the pointer is non-NULL).
293 void SetProperty(const void* key, void* value); 291 void SetProperty(const void* key, void* value);
294 void* GetProperty(const void* key, const Scope** found_on_scope) const; 292 void* GetProperty(const void* key, const Scope** found_on_scope) const;
295 293
296 private: 294 private:
297 friend class ProgrammaticProvider; 295 friend class ProgrammaticProvider;
298 296
299 struct Record { 297 struct Record {
300 Record() : used(false) {} 298 Record() : used(false) {}
301 Record(const Value& v) : used(false), value(v) {} 299 explicit Record(const Value& v) : used(false), value(v) {}
302 300
303 bool used; // Set to true when the variable is used. 301 bool used; // Set to true when the variable is used.
304 Value value; 302 Value value;
305 }; 303 };
306 304
307 void AddProvider(ProgrammaticProvider* p); 305 void AddProvider(ProgrammaticProvider* p);
308 void RemoveProvider(ProgrammaticProvider* p); 306 void RemoveProvider(ProgrammaticProvider* p);
309 307
310 // Scopes can have no containing scope (both null), a mutable containing 308 // Scopes can have no containing scope (both null), a mutable containing
311 // scope, or a const containing scope. The reason is that when we're doing 309 // scope, or a const containing scope. The reason is that when we're doing
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 345
348 typedef std::set<ProgrammaticProvider*> ProviderSet; 346 typedef std::set<ProgrammaticProvider*> ProviderSet;
349 ProviderSet programmatic_providers_; 347 ProviderSet programmatic_providers_;
350 348
351 SourceDir source_dir_; 349 SourceDir source_dir_;
352 350
353 DISALLOW_COPY_AND_ASSIGN(Scope); 351 DISALLOW_COPY_AND_ASSIGN(Scope);
354 }; 352 };
355 353
356 #endif // TOOLS_GN_SCOPE_H_ 354 #endif // TOOLS_GN_SCOPE_H_
OLDNEW
« no previous file with comments | « tools/gn/pattern.h ('k') | tools/gn/scope.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698