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/input_conversion.h" | 5 #include "tools/gn/input_conversion.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 // Sets the origin of the value and any nested values with the given node. | 31 // Sets the origin of the value and any nested values with the given node. |
32 Value ParseValueOrScope(const Settings* settings, | 32 Value ParseValueOrScope(const Settings* settings, |
33 const std::string& input, | 33 const std::string& input, |
34 ValueOrScope what, | 34 ValueOrScope what, |
35 const ParseNode* origin, | 35 const ParseNode* origin, |
36 Err* err) { | 36 Err* err) { |
37 // The memory for these will be kept around by the input file manager | 37 // The memory for these will be kept around by the input file manager |
38 // so the origin parse nodes for the values will be preserved. | 38 // so the origin parse nodes for the values will be preserved. |
39 InputFile* input_file; | 39 InputFile* input_file; |
40 std::vector<Token>* tokens; | 40 std::vector<Token>* tokens; |
41 scoped_ptr<ParseNode>* parse_root_ptr; | 41 std::unique_ptr<ParseNode>* parse_root_ptr; |
42 g_scheduler->input_file_manager()->AddDynamicInput( | 42 g_scheduler->input_file_manager()->AddDynamicInput( |
43 SourceFile(), &input_file, &tokens, &parse_root_ptr); | 43 SourceFile(), &input_file, &tokens, &parse_root_ptr); |
44 | 44 |
45 input_file->SetContents(input); | 45 input_file->SetContents(input); |
46 if (origin) { | 46 if (origin) { |
47 // This description will be the blame for any error messages caused by | 47 // This description will be the blame for any error messages caused by |
48 // script parsing or if a value is blamed. It will say | 48 // script parsing or if a value is blamed. It will say |
49 // "Error at <...>:line:char" so here we try to make a string for <...> | 49 // "Error at <...>:line:char" so here we try to make a string for <...> |
50 // that reads well in this context. | 50 // that reads well in this context. |
51 input_file->set_friendly_name( | 51 input_file->set_friendly_name( |
(...skipping 15 matching lines...) Expand all Loading... |
67 *parse_root_ptr = Parser::Parse(*tokens, err); // Will return a Block. | 67 *parse_root_ptr = Parser::Parse(*tokens, err); // Will return a Block. |
68 if (err->has_error()) | 68 if (err->has_error()) |
69 return Value(); | 69 return Value(); |
70 ParseNode* parse_root = parse_root_ptr->get(); // For nicer syntax below. | 70 ParseNode* parse_root = parse_root_ptr->get(); // For nicer syntax below. |
71 | 71 |
72 // It's valid for the result to be a null pointer, this just means that the | 72 // It's valid for the result to be a null pointer, this just means that the |
73 // script returned nothing. | 73 // script returned nothing. |
74 if (!parse_root) | 74 if (!parse_root) |
75 return Value(); | 75 return Value(); |
76 | 76 |
77 scoped_ptr<Scope> scope(new Scope(settings)); | 77 std::unique_ptr<Scope> scope(new Scope(settings)); |
78 Value result = parse_root->Execute(scope.get(), err); | 78 Value result = parse_root->Execute(scope.get(), err); |
79 if (err->has_error()) | 79 if (err->has_error()) |
80 return Value(); | 80 return Value(); |
81 | 81 |
82 // When we want the result as a scope, the result is actually the scope | 82 // When we want the result as a scope, the result is actually the scope |
83 // we made, rather than the result of running the block (which will be empty). | 83 // we made, rather than the result of running the block (which will be empty). |
84 if (what == PARSE_SCOPE) { | 84 if (what == PARSE_SCOPE) { |
85 DCHECK(result.type() == Value::NONE); | 85 DCHECK(result.type() == Value::NONE); |
86 result = Value(origin, std::move(scope)); | 86 result = Value(origin, std::move(scope)); |
87 } | 87 } |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 const ParseNode* origin, | 204 const ParseNode* origin, |
205 const Value& input_conversion_value, | 205 const Value& input_conversion_value, |
206 Err* err) { | 206 Err* err) { |
207 if (input_conversion_value.type() == Value::NONE) | 207 if (input_conversion_value.type() == Value::NONE) |
208 return Value(); // Allow null inputs to mean discard the result. | 208 return Value(); // Allow null inputs to mean discard the result. |
209 if (!input_conversion_value.VerifyTypeIs(Value::STRING, err)) | 209 if (!input_conversion_value.VerifyTypeIs(Value::STRING, err)) |
210 return Value(); | 210 return Value(); |
211 return DoConvertInputToValue(settings, input, origin, input_conversion_value, | 211 return DoConvertInputToValue(settings, input, origin, input_conversion_value, |
212 input_conversion_value.string_value(), err); | 212 input_conversion_value.string_value(), err); |
213 } | 213 } |
OLD | NEW |