| 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/parse_tree.h" | 5 #include "tools/gn/parse_tree.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 } | 46 } |
| 47 | 47 |
| 48 AccessorNode::~AccessorNode() { | 48 AccessorNode::~AccessorNode() { |
| 49 } | 49 } |
| 50 | 50 |
| 51 const AccessorNode* AccessorNode::AsAccessor() const { | 51 const AccessorNode* AccessorNode::AsAccessor() const { |
| 52 return this; | 52 return this; |
| 53 } | 53 } |
| 54 | 54 |
| 55 Value AccessorNode::Execute(Scope* scope, Err* err) const { | 55 Value AccessorNode::Execute(Scope* scope, Err* err) const { |
| 56 if (index_) | 56 if (index_) { |
| 57 return ExecuteArrayAccess(scope, err); | 57 return ExecuteArrayAccess(scope, err); |
| 58 else if (member_) | 58 } else if (member_) { |
| 59 return ExecuteScopeAccess(scope, err); | 59 const Value* value = scope->GetValue(base_.value(), true); |
| 60 if (!value) { |
| 61 *err = MakeErrorDescribing("Undefined identifier."); |
| 62 return Value(); |
| 63 } |
| 64 if (value->type() == Value::SCOPE) { |
| 65 return ExecuteScopeAccess(scope, err); |
| 66 } else if (value->type() == Value::DICT) { |
| 67 return ExecuteDictAccess(value, err); |
| 68 } else { |
| 69 *err = MakeErrorDescribing( |
| 70 std::string("Type \"") + Value::DescribeType(value->type()) + |
| 71 "\" is not usable with the '.' operator."); |
| 72 return Value(); |
| 73 } |
| 74 } |
| 60 NOTREACHED(); | 75 NOTREACHED(); |
| 61 return Value(); | 76 return Value(); |
| 62 } | 77 } |
| 63 | 78 |
| 64 LocationRange AccessorNode::GetRange() const { | 79 LocationRange AccessorNode::GetRange() const { |
| 65 if (index_) | 80 if (index_) |
| 66 return LocationRange(base_.location(), index_->GetRange().end()); | 81 return LocationRange(base_.location(), index_->GetRange().end()); |
| 67 else if (member_) | 82 else if (member_) |
| 68 return LocationRange(base_.location(), member_->GetRange().end()); | 83 return LocationRange(base_.location(), member_->GetRange().end()); |
| 69 NOTREACHED(); | 84 NOTREACHED(); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 } | 173 } |
| 159 | 174 |
| 160 if (!result) { | 175 if (!result) { |
| 161 *err = Err(member_.get(), "No value named \"" + | 176 *err = Err(member_.get(), "No value named \"" + |
| 162 member_->value().value() + "\" in scope \"" + base_.value() + "\""); | 177 member_->value().value() + "\" in scope \"" + base_.value() + "\""); |
| 163 return Value(); | 178 return Value(); |
| 164 } | 179 } |
| 165 return *result; | 180 return *result; |
| 166 } | 181 } |
| 167 | 182 |
| 183 Value AccessorNode::ExecuteDictAccess(const Value* dict, Err* err) const { |
| 184 std::map<std::string, Value>::const_iterator found = |
| 185 dict->dict_value().find(member_->value().value().as_string()); |
| 186 if (found == dict->dict_value().end()) { |
| 187 *err = Err(member_.get(), "No value named \"" + |
| 188 member_->value().value() + "\" in scope \"" + base_.value() + "\""); |
| 189 return Value(); |
| 190 } |
| 191 return found->second; |
| 192 } |
| 193 |
| 168 // BinaryOpNode --------------------------------------------------------------- | 194 // BinaryOpNode --------------------------------------------------------------- |
| 169 | 195 |
| 170 BinaryOpNode::BinaryOpNode() { | 196 BinaryOpNode::BinaryOpNode() { |
| 171 } | 197 } |
| 172 | 198 |
| 173 BinaryOpNode::~BinaryOpNode() { | 199 BinaryOpNode::~BinaryOpNode() { |
| 174 } | 200 } |
| 175 | 201 |
| 176 const BinaryOpNode* BinaryOpNode::AsBinaryOp() const { | 202 const BinaryOpNode* BinaryOpNode::AsBinaryOp() const { |
| 177 return this; | 203 return this; |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 | 546 |
| 521 Err UnaryOpNode::MakeErrorDescribing(const std::string& msg, | 547 Err UnaryOpNode::MakeErrorDescribing(const std::string& msg, |
| 522 const std::string& help) const { | 548 const std::string& help) const { |
| 523 return Err(op_, msg, help); | 549 return Err(op_, msg, help); |
| 524 } | 550 } |
| 525 | 551 |
| 526 void UnaryOpNode::Print(std::ostream& out, int indent) const { | 552 void UnaryOpNode::Print(std::ostream& out, int indent) const { |
| 527 out << IndentFor(indent) << "UNARY(" << op_.value() << ")\n"; | 553 out << IndentFor(indent) << "UNARY(" << op_.value() << ")\n"; |
| 528 operand_->Print(out, indent + 1); | 554 operand_->Print(out, indent + 1); |
| 529 } | 555 } |
| OLD | NEW |