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

Side by Side Diff: tools/gn/function_template.cc

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, 3 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 | « no previous file | tools/gn/function_toolchain.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 #include "tools/gn/functions.h" 5 #include "tools/gn/functions.h"
6 6
7 #include "tools/gn/parse_tree.h" 7 #include "tools/gn/parse_tree.h"
8 #include "tools/gn/scope.h" 8 #include "tools/gn/scope.h"
9 #include "tools/gn/template.h" 9 #include "tools/gn/template.h"
10 #include "tools/gn/value.h" 10 #include "tools/gn/value.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 " # inside the template (since it has this name), which will in turn\n" 156 " # inside the template (since it has this name), which will in turn\n"
157 " # depend on the code gen action.\n" 157 " # depend on the code gen action.\n"
158 " deps = [ \":foo_idl_files\" ]\n" 158 " deps = [ \":foo_idl_files\" ]\n"
159 " }\n"; 159 " }\n";
160 160
161 Value RunTemplate(Scope* scope, 161 Value RunTemplate(Scope* scope,
162 const FunctionCallNode* function, 162 const FunctionCallNode* function,
163 const std::vector<Value>& args, 163 const std::vector<Value>& args,
164 BlockNode* block, 164 BlockNode* block,
165 Err* err) { 165 Err* err) {
166 // Of course you can have configs and targets in a template. But here, we're
167 // not actually executing the block, only declaring it. Marking the template
168 // declaration as non-nestable means that you can't put it inside a target,
169 // for example.
170 NonNestableBlock non_nestable(scope, function, "template");
171 if (!non_nestable.Enter(err))
172 return Value();
173
166 // TODO(brettw) determine if the function is built-in and throw an error if 174 // TODO(brettw) determine if the function is built-in and throw an error if
167 // it is. 175 // it is.
168 if (args.size() != 1) { 176 if (args.size() != 1) {
169 *err = Err(function->function(), 177 *err = Err(function->function(),
170 "Need exactly one string arg to template."); 178 "Need exactly one string arg to template.");
171 return Value(); 179 return Value();
172 } 180 }
173 if (!args[0].VerifyTypeIs(Value::STRING, err)) 181 if (!args[0].VerifyTypeIs(Value::STRING, err))
174 return Value(); 182 return Value();
175 std::string template_name = args[0].string_value(); 183 std::string template_name = args[0].string_value();
176 184
177 const Template* existing_template = scope->GetTemplate(template_name); 185 const Template* existing_template = scope->GetTemplate(template_name);
178 if (existing_template) { 186 if (existing_template) {
179 *err = Err(function, "Duplicate template definition.", 187 *err = Err(function, "Duplicate template definition.",
180 "A template with this name was already defined."); 188 "A template with this name was already defined.");
181 err->AppendSubErr(Err(existing_template->GetDefinitionRange(), 189 err->AppendSubErr(Err(existing_template->GetDefinitionRange(),
182 "Previous definition.")); 190 "Previous definition."));
183 return Value(); 191 return Value();
184 } 192 }
185 193
186 scope->AddTemplate(template_name, new Template(scope, function)); 194 scope->AddTemplate(template_name, new Template(scope, function));
187 return Value(); 195 return Value();
188 } 196 }
189 197
190 } // namespace functions 198 } // namespace functions
OLDNEW
« no previous file with comments | « no previous file | tools/gn/function_toolchain.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698