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 ExecuteDefineRule(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 define_rule."); |
| 21 return Value(); |
| 22 } |
| 23 if (!args[0].VerifyTypeIs(Value::STRING, err)) |
| 24 return Value(); |
| 25 std::string rule_name = args[0].string_value(); |
| 26 |
| 27 const FunctionCallNode* existing_rule = scope->GetRule(rule_name); |
| 28 if (existing_rule) { |
| 29 *err = Err(function, "Duplicate rule definition.", |
| 30 "A rule with this name was already defined."); |
| 31 err->AppendSubErr(Err(existing_rule->function(), "Previous definition.")); |
| 32 return Value(); |
| 33 } |
| 34 |
| 35 scope->AddRule(rule_name, function); |
| 36 return Value(); |
| 37 } |
OLD | NEW |