OLD | NEW |
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 Loading... |
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 |
OLD | NEW |