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

Unified Diff: tools/gn/functions.h

Issue 1314773005: Throw errors for nested targets in GN. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gn/function_toolchain.cc ('k') | tools/gn/functions.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/functions.h
diff --git a/tools/gn/functions.h b/tools/gn/functions.h
index 6015375f96f14c263e5d0b19d3991a73e6aaca09..f9c867d8093cc8c64eb5eff36f1e4791a59d03a8 100644
--- a/tools/gn/functions.h
+++ b/tools/gn/functions.h
@@ -430,4 +430,40 @@ Label MakeLabelForScope(const Scope* scope,
const FunctionCallNode* function,
const std::string& name);
+// Some tyesp of blocks can't be nested inside other ones. For such cases,
+// instantiate this object upon entering the block and Enter() will fail if
+// there is already another non-nestable block on the stack.
+class NonNestableBlock {
+ public:
+ enum Type {
+ CONFIG,
+ DECLARE_ARGS,
+ TARGET,
+ TEMPLATE,
+ TOOLCHAIN,
+ };
+
+ // type_description is a string that will be used in error messages
+ // describing the type of the block, for example, "template" or "config".
+ NonNestableBlock(Scope* scope,
+ const FunctionCallNode* function,
+ const char* type_description);
+ ~NonNestableBlock();
+
+ bool Enter(Err* err);
+
+ private:
+ // Used as a void* key for the Scope to track our property. The actual value
+ // is never used.
+ static const int kKey;
+
+ Scope* scope_;
+ const FunctionCallNode* function_;
+ const char* type_description_;
+
+ // Set to true when the key is added to the scope so we don't try to
+ // delete nonexistant keys which will cause assertions.
+ bool key_added_;
+};
+
#endif // TOOLS_GN_FUNCTIONS_H_
« no previous file with comments | « tools/gn/function_toolchain.cc ('k') | tools/gn/functions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698