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/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
16 class FunctionCallNode
;
21 // Represents the information associated with a template() call in GN, which
22 // includes a closure and the code to run when the template is invoked.
24 // This class is immutable so we can reference it from multiple threads without
25 // locking. Normally, this will be assocated with a .gni file and then a
26 // reference will be taken by each .gn file that imports it. These files might
27 // execute the template in parallel.
28 class Template
: public base::RefCountedThreadSafe
<Template
> {
30 // Makes a new closure based on the given scope.
31 Template(const Scope
* scope
, const FunctionCallNode
* def
);
33 // Takes ownership of a previously-constructed closure.
34 Template(scoped_ptr
<Scope
> closure
, const FunctionCallNode
* def
);
36 // Invoke the template. The values correspond to the state of the code
37 // invoking the template.
38 Value
Invoke(Scope
* scope
,
39 const FunctionCallNode
* invocation
,
40 const std::vector
<Value
>& args
,
44 // Returns the location range where this template was defined.
45 LocationRange
GetDefinitionRange() const;
48 friend class base::RefCountedThreadSafe
<Template
>;
53 scoped_ptr
<Scope
> closure_
;
54 const FunctionCallNode
* definition_
;
57 #endif // TOOLS_GN_TEMPLATE_H_