| 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 #ifndef TOOLS_GN_TEMPLATE_H_ | 5 #ifndef TOOLS_GN_TEMPLATE_H_ |
| 6 #define TOOLS_GN_TEMPLATE_H_ | 6 #define TOOLS_GN_TEMPLATE_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 8 #include <vector> | 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 | 12 |
| 13 class BlockNode; | 13 class BlockNode; |
| 14 class Err; | 14 class Err; |
| 15 class FunctionCallNode; | 15 class FunctionCallNode; |
| 16 class LocationRange; | 16 class LocationRange; |
| 17 class Scope; | 17 class Scope; |
| 18 class Value; | 18 class Value; |
| 19 | 19 |
| 20 // Represents the information associated with a template() call in GN, which | 20 // Represents the information associated with a template() call in GN, which |
| 21 // includes a closure and the code to run when the template is invoked. | 21 // includes a closure and the code to run when the template is invoked. |
| 22 // | 22 // |
| 23 // This class is immutable so we can reference it from multiple threads without | 23 // This class is immutable so we can reference it from multiple threads without |
| 24 // locking. Normally, this will be assocated with a .gni file and then a | 24 // locking. Normally, this will be assocated with a .gni file and then a |
| 25 // reference will be taken by each .gn file that imports it. These files might | 25 // reference will be taken by each .gn file that imports it. These files might |
| 26 // execute the template in parallel. | 26 // execute the template in parallel. |
| 27 class Template : public base::RefCountedThreadSafe<Template> { | 27 class Template : public base::RefCountedThreadSafe<Template> { |
| 28 public: | 28 public: |
| 29 // Makes a new closure based on the given scope. | 29 // Makes a new closure based on the given scope. |
| 30 Template(const Scope* scope, const FunctionCallNode* def); | 30 Template(const Scope* scope, const FunctionCallNode* def); |
| 31 | 31 |
| 32 // Takes ownership of a previously-constructed closure. | 32 // Takes ownership of a previously-constructed closure. |
| 33 Template(scoped_ptr<Scope> closure, const FunctionCallNode* def); | 33 Template(std::unique_ptr<Scope> closure, const FunctionCallNode* def); |
| 34 | 34 |
| 35 // Invoke the template. The values correspond to the state of the code | 35 // Invoke the template. The values correspond to the state of the code |
| 36 // invoking the template. | 36 // invoking the template. |
| 37 Value Invoke(Scope* scope, | 37 Value Invoke(Scope* scope, |
| 38 const FunctionCallNode* invocation, | 38 const FunctionCallNode* invocation, |
| 39 const std::vector<Value>& args, | 39 const std::vector<Value>& args, |
| 40 BlockNode* block, | 40 BlockNode* block, |
| 41 Err* err) const; | 41 Err* err) const; |
| 42 | 42 |
| 43 // Returns the location range where this template was defined. | 43 // Returns the location range where this template was defined. |
| 44 LocationRange GetDefinitionRange() const; | 44 LocationRange GetDefinitionRange() const; |
| 45 | 45 |
| 46 private: | 46 private: |
| 47 friend class base::RefCountedThreadSafe<Template>; | 47 friend class base::RefCountedThreadSafe<Template>; |
| 48 | 48 |
| 49 Template(); | 49 Template(); |
| 50 ~Template(); | 50 ~Template(); |
| 51 | 51 |
| 52 scoped_ptr<Scope> closure_; | 52 std::unique_ptr<Scope> closure_; |
| 53 const FunctionCallNode* definition_; | 53 const FunctionCallNode* definition_; |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 #endif // TOOLS_GN_TEMPLATE_H_ | 56 #endif // TOOLS_GN_TEMPLATE_H_ |
| OLD | NEW |