Delete unused code in chrome/common or mark them as platform specific.
[chromium-blink-merge.git] / tools / gn / template.h
blob0b123e04ac404749da109734b48f01a5b5204074
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_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
14 class BlockNode;
15 class Err;
16 class FunctionCallNode;
17 class LocationRange;
18 class Scope;
19 class Value;
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> {
29 public:
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,
41 BlockNode* block,
42 Err* err) const;
44 // Returns the location range where this template was defined.
45 LocationRange GetDefinitionRange() const;
47 private:
48 friend class base::RefCountedThreadSafe<Template>;
50 Template();
51 ~Template();
53 scoped_ptr<Scope> closure_;
54 const FunctionCallNode* definition_;
57 #endif // TOOLS_GN_TEMPLATE_H_