| 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/err.h" | 5 #include "tools/gn/err.h" |
| 6 #include "tools/gn/functions.h" | 6 #include "tools/gn/functions.h" |
| 7 #include "tools/gn/parse_tree.h" | 7 #include "tools/gn/parse_tree.h" |
| 8 #include "tools/gn/scope.h" | 8 #include "tools/gn/scope.h" |
| 9 | 9 |
| 10 namespace functions { | 10 namespace functions { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 *err = Err(args_vector[0], "Expected an identifier for the loop var."); | 63 *err = Err(args_vector[0], "Expected an identifier for the loop var."); |
| 64 return Value(); | 64 return Value(); |
| 65 } | 65 } |
| 66 base::StringPiece loop_var(identifier->value().value()); | 66 base::StringPiece loop_var(identifier->value().value()); |
| 67 | 67 |
| 68 // Extract the list, avoid a copy if it's an identifier (common case). | 68 // Extract the list, avoid a copy if it's an identifier (common case). |
| 69 Value value_storage_for_exec; // Backing for list_value when we need to exec. | 69 Value value_storage_for_exec; // Backing for list_value when we need to exec. |
| 70 const Value* list_value = NULL; | 70 const Value* list_value = NULL; |
| 71 const IdentifierNode* list_identifier = args_vector[1]->AsIdentifier(); | 71 const IdentifierNode* list_identifier = args_vector[1]->AsIdentifier(); |
| 72 if (list_identifier) { | 72 if (list_identifier) { |
| 73 list_value = scope->GetValue(list_identifier->value().value()); | 73 list_value = scope->GetValue(list_identifier->value().value(), true); |
| 74 if (!list_value) { | 74 if (!list_value) { |
| 75 *err = Err(args_vector[1], "Undefined identifier."); | 75 *err = Err(args_vector[1], "Undefined identifier."); |
| 76 return Value(); | 76 return Value(); |
| 77 } | 77 } |
| 78 } else { | 78 } else { |
| 79 // Not an identifier, evaluate the node to get the result. | 79 // Not an identifier, evaluate the node to get the result. |
| 80 Scope list_exec_scope(scope); | 80 Scope list_exec_scope(scope); |
| 81 value_storage_for_exec = args_vector[1]->Execute(scope, err); | 81 value_storage_for_exec = args_vector[1]->Execute(scope, err); |
| 82 if (err->has_error()) | 82 if (err->has_error()) |
| 83 return Value(); | 83 return Value(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 scope->SetValue(loop_var, old_loop_value, old_loop_value.origin()); | 115 scope->SetValue(loop_var, old_loop_value, old_loop_value.origin()); |
| 116 } else { | 116 } else { |
| 117 // Loop variable was undefined before loop, delete it. | 117 // Loop variable was undefined before loop, delete it. |
| 118 scope->RemoveIdentifier(loop_var); | 118 scope->RemoveIdentifier(loop_var); |
| 119 } | 119 } |
| 120 | 120 |
| 121 return Value(); | 121 return Value(); |
| 122 } | 122 } |
| 123 | 123 |
| 124 } // namespace functions | 124 } // namespace functions |
| OLD | NEW |