summaryrefslogtreecommitdiffstats
path: root/tools/gn/template.h
blob: 01768620ec98bbe293d05ba66c5044ddfa2f1a97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef TOOLS_GN_TEMPLATE_H_
#define TOOLS_GN_TEMPLATE_H_

#include <vector>

#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"

class BlockNode;
class Err;
class FunctionCallNode;
class LocationRange;
class Scope;
class Value;

class Template {
 public:
  // Makes a new closure based on the given scope.
  Template(const Scope* scope, const FunctionCallNode* def);

  // Takes ownership of a previously-constructed closure.
  Template(scoped_ptr<Scope> closure, const FunctionCallNode* def);

  ~Template();

  // Makes a copy of this template.
  scoped_ptr<Template> Clone() const;

  // Invoke the template. The values correspond to the state of the code
  // invoking the template.
  Value Invoke(Scope* scope,
               const FunctionCallNode* invocation,
               const std::vector<Value>& args,
               BlockNode* block,
               Err* err) const;

  // Returns the location range where this template was defined.
  LocationRange GetDefinitionRange() const;

 private:
  Template();

  scoped_ptr<Scope> closure_;
  const FunctionCallNode* definition_;

  DISALLOW_COPY_AND_ASSIGN(Template);
};

#endif  // TOOLS_GN_TEMPLATE_H_