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/template.h" | 5 #include "tools/gn/template.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "tools/gn/err.h" | 9 #include "tools/gn/err.h" |
8 #include "tools/gn/functions.h" | 10 #include "tools/gn/functions.h" |
9 #include "tools/gn/parse_tree.h" | 11 #include "tools/gn/parse_tree.h" |
10 #include "tools/gn/scope.h" | 12 #include "tools/gn/scope.h" |
11 #include "tools/gn/scope_per_file_provider.h" | 13 #include "tools/gn/scope_per_file_provider.h" |
12 #include "tools/gn/value.h" | 14 #include "tools/gn/value.h" |
13 | 15 |
14 Template::Template(const Scope* scope, const FunctionCallNode* def) | 16 Template::Template(const Scope* scope, const FunctionCallNode* def) |
15 : closure_(scope->MakeClosure()), | 17 : closure_(scope->MakeClosure()), |
16 definition_(def) { | 18 definition_(def) { |
17 } | 19 } |
18 | 20 |
19 Template::Template(scoped_ptr<Scope> scope, const FunctionCallNode* def) | 21 Template::Template(scoped_ptr<Scope> scope, const FunctionCallNode* def) |
20 : closure_(scope.Pass()), | 22 : closure_(std::move(scope)), definition_(def) {} |
21 definition_(def) { | |
22 } | |
23 | 23 |
24 Template::~Template() { | 24 Template::~Template() { |
25 } | 25 } |
26 | 26 |
27 Value Template::Invoke(Scope* scope, | 27 Value Template::Invoke(Scope* scope, |
28 const FunctionCallNode* invocation, | 28 const FunctionCallNode* invocation, |
29 const std::vector<Value>& args, | 29 const std::vector<Value>& args, |
30 BlockNode* block, | 30 BlockNode* block, |
31 Err* err) const { | 31 Err* err) const { |
32 // Don't allow templates to be executed from imported files. Imports are for | 32 // Don't allow templates to be executed from imported files. Imports are for |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 // setting it in the template scope (since the invocation scope may have | 74 // setting it in the template scope (since the invocation scope may have |
75 // large lists of source files in it and could be expensive to copy). | 75 // large lists of source files in it and could be expensive to copy). |
76 // | 76 // |
77 // Scope.SetValue will copy the value which will in turn copy the scope, but | 77 // Scope.SetValue will copy the value which will in turn copy the scope, but |
78 // if we instead create a value and then set the scope on it, the copy can | 78 // if we instead create a value and then set the scope on it, the copy can |
79 // be avoided. | 79 // be avoided. |
80 const char kInvoker[] = "invoker"; | 80 const char kInvoker[] = "invoker"; |
81 template_scope.SetValue(kInvoker, Value(nullptr, scoped_ptr<Scope>()), | 81 template_scope.SetValue(kInvoker, Value(nullptr, scoped_ptr<Scope>()), |
82 invocation); | 82 invocation); |
83 Value* invoker_value = template_scope.GetMutableValue(kInvoker, false); | 83 Value* invoker_value = template_scope.GetMutableValue(kInvoker, false); |
84 invoker_value->SetScopeValue(invocation_scope.Pass()); | 84 invoker_value->SetScopeValue(std::move(invocation_scope)); |
85 template_scope.set_source_dir(scope->GetSourceDir()); | 85 template_scope.set_source_dir(scope->GetSourceDir()); |
86 | 86 |
87 const base::StringPiece target_name("target_name"); | 87 const base::StringPiece target_name("target_name"); |
88 template_scope.SetValue(target_name, | 88 template_scope.SetValue(target_name, |
89 Value(invocation, args[0].string_value()), | 89 Value(invocation, args[0].string_value()), |
90 invocation); | 90 invocation); |
91 | 91 |
92 // Actually run the template code. | 92 // Actually run the template code. |
93 Value result = | 93 Value result = |
94 definition_->block()->Execute(&template_scope, err); | 94 definition_->block()->Execute(&template_scope, err); |
(...skipping 21 matching lines...) Expand all Loading... |
116 // Check for unused variables in the template itself. | 116 // Check for unused variables in the template itself. |
117 if (!template_scope.CheckForUnusedVars(err)) | 117 if (!template_scope.CheckForUnusedVars(err)) |
118 return Value(); | 118 return Value(); |
119 | 119 |
120 return result; | 120 return result; |
121 } | 121 } |
122 | 122 |
123 LocationRange Template::GetDefinitionRange() const { | 123 LocationRange Template::GetDefinitionRange() const { |
124 return definition_->GetRange(); | 124 return definition_->GetRange(); |
125 } | 125 } |
OLD | NEW |