Chromium Code Reviews| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <tuple> | 10 #include <tuple> |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 480 } | 480 } |
| 481 | 481 |
| 482 IdentifierNode::~IdentifierNode() { | 482 IdentifierNode::~IdentifierNode() { |
| 483 } | 483 } |
| 484 | 484 |
| 485 const IdentifierNode* IdentifierNode::AsIdentifier() const { | 485 const IdentifierNode* IdentifierNode::AsIdentifier() const { |
| 486 return this; | 486 return this; |
| 487 } | 487 } |
| 488 | 488 |
| 489 Value IdentifierNode::Execute(Scope* scope, Err* err) const { | 489 Value IdentifierNode::Execute(Scope* scope, Err* err) const { |
| 490 const Value* value = scope->GetValue(value_.value(), true); | 490 const Scope *found_in_scope = nullptr; |
|
brettw
2016/11/18 22:07:43
Put the * next to the type like you do for Value b
Dirk Pranke
2016/11/18 22:35:40
ack.
| |
| 491 const Value* value = scope->GetValueWithScope(value_.value(), true, | |
| 492 &found_in_scope); | |
| 491 Value result; | 493 Value result; |
| 492 if (!value) { | 494 if (!value) { |
| 493 *err = MakeErrorDescribing("Undefined identifier"); | 495 *err = MakeErrorDescribing("Undefined identifier"); |
| 494 return result; | 496 return result; |
| 495 } | 497 } |
| 496 | 498 |
| 499 // Check that the scope that contains the defined value and the | |
|
brettw
2016/11/18 22:07:43
I think it would be easier to follow if this was i
Dirk Pranke
2016/11/18 22:35:39
Acknowledged.
| |
| 500 // current scope are not part of the same declare_args() block, in | |
| 501 // order to prevent reading a value that might be overridden later. | |
| 502 const Scope *found_args_scope = nullptr; | |
| 503 if (found_in_scope) | |
| 504 found_in_scope->GetProperty(&kInDeclareArgsKey, &found_args_scope); | |
| 505 | |
| 506 const Scope* cur_args_scope = nullptr; | |
| 507 scope->GetProperty(&kInDeclareArgsKey, &cur_args_scope); | |
| 508 if (found_args_scope && cur_args_scope && | |
| 509 (found_args_scope == cur_args_scope)) { | |
| 510 *err = MakeErrorDescribing( | |
| 511 "Reading a variable defined in the same declare_args() call."); | |
| 512 return result; | |
| 513 } | |
| 514 | |
| 497 result = *value; | 515 result = *value; |
| 498 result.set_origin(this); | 516 result.set_origin(this); |
| 499 return result; | 517 return result; |
| 500 } | 518 } |
| 501 | 519 |
| 502 LocationRange IdentifierNode::GetRange() const { | 520 LocationRange IdentifierNode::GetRange() const { |
| 503 return value_.range(); | 521 return value_.range(); |
| 504 } | 522 } |
| 505 | 523 |
| 506 Err IdentifierNode::MakeErrorDescribing(const std::string& msg, | 524 Err IdentifierNode::MakeErrorDescribing(const std::string& msg, |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 867 | 885 |
| 868 Err EndNode::MakeErrorDescribing(const std::string& msg, | 886 Err EndNode::MakeErrorDescribing(const std::string& msg, |
| 869 const std::string& help) const { | 887 const std::string& help) const { |
| 870 return Err(value_, msg, help); | 888 return Err(value_, msg, help); |
| 871 } | 889 } |
| 872 | 890 |
| 873 void EndNode::Print(std::ostream& out, int indent) const { | 891 void EndNode::Print(std::ostream& out, int indent) const { |
| 874 out << IndentFor(indent) << "END(" << value_.value() << ")\n"; | 892 out << IndentFor(indent) << "END(" << value_.value() << ")\n"; |
| 875 PrintComments(out, indent); | 893 PrintComments(out, indent); |
| 876 } | 894 } |
| OLD | NEW |