OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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/parse_node_value_adapter.h" |
| 6 |
| 7 #include "tools/gn/parse_tree.h" |
| 8 #include "tools/gn/scope.h" |
| 9 |
| 10 ParseNodeValueAdapter::ParseNodeValueAdapter() : ref_(nullptr) { |
| 11 } |
| 12 |
| 13 ParseNodeValueAdapter::~ParseNodeValueAdapter() { |
| 14 } |
| 15 |
| 16 |
| 17 bool ParseNodeValueAdapter::Init(Scope* scope, |
| 18 const ParseNode* node, |
| 19 Err* err) { |
| 20 const IdentifierNode* identifier = node->AsIdentifier(); |
| 21 if (identifier) { |
| 22 ref_ = scope->GetValue(identifier->value().value(), true); |
| 23 if (!ref_) { |
| 24 identifier->MakeErrorDescribing("Undefined identifier"); |
| 25 return false; |
| 26 } |
| 27 return true; |
| 28 } |
| 29 |
| 30 temporary_ = node->Execute(scope, err); |
| 31 return !err->has_error(); |
| 32 } |
| 33 |
| 34 bool ParseNodeValueAdapter::InitForType(Scope* scope, |
| 35 const ParseNode* node, |
| 36 Value::Type type, |
| 37 Err* err) { |
| 38 if (!Init(scope, node, err)) |
| 39 return false; |
| 40 if (get().VerifyTypeIs(type, err)) |
| 41 return true; |
| 42 |
| 43 // Fix up the error range (see class comment in the header file) to be the |
| 44 // identifier node rather than the original value. |
| 45 *err = Err(node, err->message(), err->help_text()); |
| 46 return false; |
| 47 } |
OLD | NEW |