Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(735)

Side by Side Diff: tools/gn/template.cc

Issue 1869503004: Convert //tools to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, change iwyu fixes for converted directories to include <memory> Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/gn/template.h ('k') | tools/gn/test_with_scope.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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> 7 #include <utility>
8 8
9 #include "tools/gn/err.h" 9 #include "tools/gn/err.h"
10 #include "tools/gn/functions.h" 10 #include "tools/gn/functions.h"
11 #include "tools/gn/parse_tree.h" 11 #include "tools/gn/parse_tree.h"
12 #include "tools/gn/scope.h" 12 #include "tools/gn/scope.h"
13 #include "tools/gn/scope_per_file_provider.h" 13 #include "tools/gn/scope_per_file_provider.h"
14 #include "tools/gn/value.h" 14 #include "tools/gn/value.h"
15 15
16 Template::Template(const Scope* scope, const FunctionCallNode* def) 16 Template::Template(const Scope* scope, const FunctionCallNode* def)
17 : closure_(scope->MakeClosure()), 17 : closure_(scope->MakeClosure()),
18 definition_(def) { 18 definition_(def) {
19 } 19 }
20 20
21 Template::Template(scoped_ptr<Scope> scope, const FunctionCallNode* def) 21 Template::Template(std::unique_ptr<Scope> scope, const FunctionCallNode* def)
22 : closure_(std::move(scope)), definition_(def) {} 22 : closure_(std::move(scope)), definition_(def) {}
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
33 // simple values only. 33 // simple values only.
34 if (!EnsureNotProcessingImport(invocation, scope, err)) 34 if (!EnsureNotProcessingImport(invocation, scope, err))
35 return Value(); 35 return Value();
36 36
37 // First run the invocation's block. Need to allocate the scope on the heap 37 // First run the invocation's block. Need to allocate the scope on the heap
38 // so we can pass ownership to the template. 38 // so we can pass ownership to the template.
39 scoped_ptr<Scope> invocation_scope(new Scope(scope)); 39 std::unique_ptr<Scope> invocation_scope(new Scope(scope));
40 if (!FillTargetBlockScope(scope, invocation, 40 if (!FillTargetBlockScope(scope, invocation,
41 invocation->function().value().as_string(), 41 invocation->function().value().as_string(),
42 block, args, invocation_scope.get(), err)) 42 block, args, invocation_scope.get(), err))
43 return Value(); 43 return Value();
44 44
45 { 45 {
46 // Don't allow the block of the template invocation to include other 46 // Don't allow the block of the template invocation to include other
47 // targets configs, or template invocations. This must only be applied 47 // targets configs, or template invocations. This must only be applied
48 // to the invoker's block rather than the whole function because the 48 // to the invoker's block rather than the whole function because the
49 // template execution itself must be able to define targets, etc. 49 // template execution itself must be able to define targets, etc.
(...skipping 21 matching lines...) Expand all
71 template_scope.set_item_collector(scope->GetItemCollector()); 71 template_scope.set_item_collector(scope->GetItemCollector());
72 72
73 // We jump through some hoops to avoid copying the invocation scope when 73 // We jump through some hoops to avoid copying the invocation scope when
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, std::unique_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(std::move(invocation_scope)); 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
(...skipping 24 matching lines...) Expand all
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 }
OLDNEW
« no previous file with comments | « tools/gn/template.h ('k') | tools/gn/test_with_scope.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698