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

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

Issue 2148993002: Allow multiple set_default calls in GN. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 5 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/function_set_defaults.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 <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 const char* desc_for_err, 222 const char* desc_for_err,
223 Err* err) const; 223 Err* err) const;
224 224
225 // Constructs a scope that is a copy of the current one. Nested scopes will 225 // Constructs a scope that is a copy of the current one. Nested scopes will
226 // be collapsed until we reach a const containing scope. Private values will 226 // be collapsed until we reach a const containing scope. Private values will
227 // be included. The resulting closure will reference the const containing 227 // be included. The resulting closure will reference the const containing
228 // scope as its containing scope (since we assume the const scope won't 228 // scope as its containing scope (since we assume the const scope won't
229 // change, we don't have to copy its values). 229 // change, we don't have to copy its values).
230 std::unique_ptr<Scope> MakeClosure() const; 230 std::unique_ptr<Scope> MakeClosure() const;
231 231
232 // Makes an empty scope with the given name. Returns NULL if the name is 232 // Makes an empty scope with the given name. Overwrites any existing one.
233 // already set.
234 Scope* MakeTargetDefaults(const std::string& target_type); 233 Scope* MakeTargetDefaults(const std::string& target_type);
235 234
236 // Gets the scope associated with the given target name, or null if it hasn't 235 // Gets the scope associated with the given target name, or null if it hasn't
237 // been set. 236 // been set.
238 const Scope* GetTargetDefaults(const std::string& target_type) const; 237 const Scope* GetTargetDefaults(const std::string& target_type) const;
239 238
240 // Filter to apply when the sources variable is assigned. May return NULL. 239 // Filter to apply when the sources variable is assigned. May return NULL.
241 const PatternList* GetSourcesAssignmentFilter() const; 240 const PatternList* GetSourcesAssignmentFilter() const;
242 void set_sources_assignment_filter(std::unique_ptr<PatternList> f) { 241 void set_sources_assignment_filter(std::unique_ptr<PatternList> f) {
243 sources_assignment_filter_ = std::move(f); 242 sources_assignment_filter_ = std::move(f);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 friend class ProgrammaticProvider; 303 friend class ProgrammaticProvider;
305 304
306 struct Record { 305 struct Record {
307 Record() : used(false) {} 306 Record() : used(false) {}
308 explicit Record(const Value& v) : used(false), value(v) {} 307 explicit Record(const Value& v) : used(false), value(v) {}
309 308
310 bool used; // Set to true when the variable is used. 309 bool used; // Set to true when the variable is used.
311 Value value; 310 Value value;
312 }; 311 };
313 312
313 typedef base::hash_map<base::StringPiece, Record, base::StringPieceHash>
314 RecordMap;
315
314 void AddProvider(ProgrammaticProvider* p); 316 void AddProvider(ProgrammaticProvider* p);
315 void RemoveProvider(ProgrammaticProvider* p); 317 void RemoveProvider(ProgrammaticProvider* p);
316 318
319 // Returns true if the two RecordMaps contain the same values (the origins
320 // of the values may be different).
321 static bool RecordMapValuesEqual(const RecordMap& a, const RecordMap& b);
322
317 // Scopes can have no containing scope (both null), a mutable containing 323 // Scopes can have no containing scope (both null), a mutable containing
318 // scope, or a const containing scope. The reason is that when we're doing 324 // scope, or a const containing scope. The reason is that when we're doing
319 // a new target, we want to refer to the base_config scope which will be read 325 // a new target, we want to refer to the base_config scope which will be read
320 // by multiple threads at the same time, so we REALLY want it to be const. 326 // by multiple threads at the same time, so we REALLY want it to be const.
321 // When you jsut do a nested {}, however, we sometimes want to be able to 327 // When you jsut do a nested {}, however, we sometimes want to be able to
322 // change things (especially marking unused vars). 328 // change things (especially marking unused vars).
323 const Scope* const_containing_; 329 const Scope* const_containing_;
324 Scope* mutable_containing_; 330 Scope* mutable_containing_;
325 331
326 const Settings* settings_; 332 const Settings* settings_;
327 333
328 // Bits set for different modes. See the flag definitions in the .cc file 334 // Bits set for different modes. See the flag definitions in the .cc file
329 // for more. 335 // for more.
330 unsigned mode_flags_; 336 unsigned mode_flags_;
331 337
332 typedef base::hash_map<base::StringPiece, Record, base::StringPieceHash>
333 RecordMap;
334 RecordMap values_; 338 RecordMap values_;
335 339
336 // Note that this can't use string pieces since the names are constructed from 340 // Note that this can't use string pieces since the names are constructed from
337 // Values which might be deallocated before this goes out of scope. 341 // Values which might be deallocated before this goes out of scope.
338 typedef base::hash_map<std::string, std::unique_ptr<Scope>> NamedScopeMap; 342 typedef base::hash_map<std::string, std::unique_ptr<Scope>> NamedScopeMap;
339 NamedScopeMap target_defaults_; 343 NamedScopeMap target_defaults_;
340 344
341 // Null indicates not set and that we should fallback to the containing 345 // Null indicates not set and that we should fallback to the containing
342 // scope's filter. 346 // scope's filter.
343 std::unique_ptr<PatternList> sources_assignment_filter_; 347 std::unique_ptr<PatternList> sources_assignment_filter_;
(...skipping 10 matching lines...) Expand all
354 358
355 typedef std::set<ProgrammaticProvider*> ProviderSet; 359 typedef std::set<ProgrammaticProvider*> ProviderSet;
356 ProviderSet programmatic_providers_; 360 ProviderSet programmatic_providers_;
357 361
358 SourceDir source_dir_; 362 SourceDir source_dir_;
359 363
360 DISALLOW_COPY_AND_ASSIGN(Scope); 364 DISALLOW_COPY_AND_ASSIGN(Scope);
361 }; 365 };
362 366
363 #endif // TOOLS_GN_SCOPE_H_ 367 #endif // TOOLS_GN_SCOPE_H_
OLDNEW
« no previous file with comments | « tools/gn/function_set_defaults.cc ('k') | tools/gn/scope.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698