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.cc

Issue 1007963003: Fixes to {} handling in GN. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/gn/functions_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/functions.cc
diff --git a/tools/gn/functions.cc b/tools/gn/functions.cc
index 1cfa6fec7f0735ec5bfaebe6f218f43b5a68cbb4..7798a969e8a55d6e76127f16a060bbac0a91fa2c 100644
--- a/tools/gn/functions.cc
+++ b/tools/gn/functions.cc
@@ -20,6 +20,27 @@
#include "tools/gn/token.h"
#include "tools/gn/value.h"
+namespace {
+
+// Some functions take a {} following them, and some don't. For the ones that
+// don't, this is used to verify that the given block node is null and will
+// set the error accordingly if it's not. Returns true if the block is null.
+bool VerifyNoBlockForFunctionCall(const FunctionCallNode* function,
+ const BlockNode* block,
+ Err* err) {
+ if (!block)
+ return true;
+
+ *err = Err(block, "Unexpected '{'.",
+ "This function call doesn't take a {} block following it, and you\n"
+ "can't have a {} block that's not connected to something like an if\n"
+ "statement or a target declaration.");
+ err->AppendRange(function->function().range());
+ return false;
+}
+
+} // namespace
+
bool EnsureNotProcessingImport(const ParseNode* node,
const Scope* scope,
Err* err) {
@@ -744,6 +765,14 @@ Value RunFunction(Scope* scope,
}
if (found_function->second.self_evaluating_args_runner) {
+ // Self evaluating args functions are special weird built-ins. Currently,
+ // only foreach() takes a block following it. Rather than force them all to
+ // check that they have a block or no block and risk bugs for new additions,
+ // check a whitelist here.
+ if (found_function->second.self_evaluating_args_runner != &RunForEach) {
+ if (!VerifyNoBlockForFunctionCall(function, block, err))
+ return Value();
+ }
return found_function->second.self_evaluating_args_runner(
scope, function, args_list, err);
}
@@ -784,6 +813,8 @@ Value RunFunction(Scope* scope,
}
// Otherwise it's a no-block function.
+ if (!VerifyNoBlockForFunctionCall(function, block, err))
+ return Value();
return found_function->second.no_block_runner(scope, function,
args.list_value(), err);
}
« no previous file with comments | « no previous file | tools/gn/functions_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698