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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 return Value(); | 94 return Value(); |
95 } | 95 } |
96 | 96 |
97 // If the loop variable was previously defined in this scope, save it so we | 97 // If the loop variable was previously defined in this scope, save it so we |
98 // can put it back after the loop is done. | 98 // can put it back after the loop is done. |
99 const Value* old_loop_value_ptr = scope->GetValue(loop_var); | 99 const Value* old_loop_value_ptr = scope->GetValue(loop_var); |
100 Value old_loop_value; | 100 Value old_loop_value; |
101 if (old_loop_value_ptr) | 101 if (old_loop_value_ptr) |
102 old_loop_value = *old_loop_value_ptr; | 102 old_loop_value = *old_loop_value_ptr; |
103 | 103 |
104 for (size_t i = 0; i < list.size(); i++) { | 104 for (const auto& cur : list) { |
105 scope->SetValue(loop_var, list[i], function); | 105 scope->SetValue(loop_var, cur, function); |
106 block->ExecuteBlockInScope(scope, err); | 106 block->ExecuteBlockInScope(scope, err); |
107 if (err->has_error()) | 107 if (err->has_error()) |
108 return Value(); | 108 return Value(); |
109 } | 109 } |
110 | 110 |
111 // Put back loop var. | 111 // Put back loop var. |
112 if (old_loop_value_ptr) { | 112 if (old_loop_value_ptr) { |
113 // Put back old value. Use the copy we made, rather than use the pointer, | 113 // Put back old value. Use the copy we made, rather than use the pointer, |
114 // which will probably point to the new value now in the scope. | 114 // which will probably point to the new value now in the scope. |
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 |