| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "tools/gn/functions.h" | |
| 6 | |
| 7 #include "tools/gn/parse_tree.h" | |
| 8 #include "tools/gn/scope.h" | |
| 9 #include "tools/gn/value.h" | |
| 10 | |
| 11 Value ExecuteTemplate(Scope* scope, | |
| 12 const FunctionCallNode* function, | |
| 13 const std::vector<Value>& args, | |
| 14 BlockNode* block, | |
| 15 Err* err) { | |
| 16 // TODO(brettw) determine if the function is built-in and throw an error if | |
| 17 // it is. | |
| 18 if (args.size() != 1) { | |
| 19 *err = Err(function->function(), | |
| 20 "Need exactly one string arg to template."); | |
| 21 return Value(); | |
| 22 } | |
| 23 if (!args[0].VerifyTypeIs(Value::STRING, err)) | |
| 24 return Value(); | |
| 25 std::string template_name = args[0].string_value(); | |
| 26 | |
| 27 const FunctionCallNode* existing_template = scope->GetTemplate(template_name); | |
| 28 if (existing_template) { | |
| 29 *err = Err(function, "Duplicate template definition.", | |
| 30 "A template with this name was already defined."); | |
| 31 err->AppendSubErr(Err(existing_template->function(), | |
| 32 "Previous definition.")); | |
| 33 return Value(); | |
| 34 } | |
| 35 | |
| 36 scope->AddTemplate(template_name, function); | |
| 37 return Value(); | |
| 38 } | |
| OLD | NEW |