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
3 // found in the LICENSE file.
5 #ifndef TOOLS_GN_TEMPLATE_H_
6 #define TOOLS_GN_TEMPLATE_H_
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
15 class FunctionCallNode
;
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.
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
25 // reference will be taken by each .gn file that imports it. These files might
26 // execute the template in parallel.
27 class Template
: public base::RefCountedThreadSafe
<Template
> {
29 // Makes a new closure based on the given scope.
30 Template(const Scope
* scope
, const FunctionCallNode
* def
);
32 // Takes ownership of a previously-constructed closure.
33 Template(scoped_ptr
<Scope
> closure
, const FunctionCallNode
* def
);
35 // Invoke the template. The values correspond to the state of the code
36 // invoking the template.
37 Value
Invoke(Scope
* scope
,
38 const FunctionCallNode
* invocation
,
39 const std::vector
<Value
>& args
,
43 // Returns the location range where this template was defined.
44 LocationRange
GetDefinitionRange() const;
47 friend class base::RefCountedThreadSafe
<Template
>;
52 scoped_ptr
<Scope
> closure_
;
53 const FunctionCallNode
* definition_
;
56 #endif // TOOLS_GN_TEMPLATE_H_