OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 " }\n" | 146 " }\n" |
147 " }\n"; | 147 " }\n"; |
148 | 148 |
149 // This function takes a ListNode rather than a resolved vector of values | 149 // This function takes a ListNode rather than a resolved vector of values |
150 // both avoid copying the potentially-large source scope, and so the variables | 150 // both avoid copying the potentially-large source scope, and so the variables |
151 // in the source scope can be marked as used. | 151 // in the source scope can be marked as used. |
152 Value RunForwardVariablesFrom(Scope* scope, | 152 Value RunForwardVariablesFrom(Scope* scope, |
153 const FunctionCallNode* function, | 153 const FunctionCallNode* function, |
154 const ListNode* args_list, | 154 const ListNode* args_list, |
155 Err* err) { | 155 Err* err) { |
156 const std::vector<const ParseNode*>& args_vector = args_list->contents(); | 156 const auto& args_vector = args_list->contents(); |
157 if (args_vector.size() != 2 && args_vector.size() != 3) { | 157 if (args_vector.size() != 2 && args_vector.size() != 3) { |
158 *err = Err(function, "Wrong number of arguments.", | 158 *err = Err(function, "Wrong number of arguments.", |
159 "Expecting two or three arguments."); | 159 "Expecting two or three arguments."); |
160 return Value(); | 160 return Value(); |
161 } | 161 } |
162 | 162 |
163 // Extract the scope identifier. This assumes the first parameter is an | 163 // Extract the scope identifier. This assumes the first parameter is an |
164 // identifier. It is difficult to write code where this is not the case, and | 164 // identifier. It is difficult to write code where this is not the case, and |
165 // this saves an expensive scope copy. If necessary, this could be expanded | 165 // this saves an expensive scope copy. If necessary, this could be expanded |
166 // to execute the ParseNode and get the value out if it's not an identifer. | 166 // to execute the ParseNode and get the value out if it's not an identifer. |
167 const IdentifierNode* identifier = args_vector[0]->AsIdentifier(); | 167 const IdentifierNode* identifier = args_vector[0]->AsIdentifier(); |
168 if (!identifier) { | 168 if (!identifier) { |
169 *err = Err(args_vector[0], "Expected an identifier for the scope."); | 169 *err = Err(args_vector[0].get(), "Expected an identifier for the scope."); |
170 return Value(); | 170 return Value(); |
171 } | 171 } |
172 | 172 |
173 // Extract the source scope. | 173 // Extract the source scope. |
174 Value* value = scope->GetMutableValue(identifier->value().value(), true); | 174 Value* value = scope->GetMutableValue(identifier->value().value(), true); |
175 if (!value) { | 175 if (!value) { |
176 *err = Err(identifier, "Undefined identifier."); | 176 *err = Err(identifier, "Undefined identifier."); |
177 return Value(); | 177 return Value(); |
178 } | 178 } |
179 if (!value->VerifyTypeIs(Value::SCOPE, err)) | 179 if (!value->VerifyTypeIs(Value::SCOPE, err)) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 } | 218 } |
219 } | 219 } |
220 | 220 |
221 // Not the right type of argument. | 221 // Not the right type of argument. |
222 *err = Err(what_value, "Not a valid list of variables to copy.", | 222 *err = Err(what_value, "Not a valid list of variables to copy.", |
223 "Expecting either the string \"*\" or a list of strings."); | 223 "Expecting either the string \"*\" or a list of strings."); |
224 return Value(); | 224 return Value(); |
225 } | 225 } |
226 | 226 |
227 } // namespace functions | 227 } // namespace functions |
OLD | NEW |