blob: 876d7d341d164a0d282c0abb9f982d477bcf7b35 [file] [log] [blame]
Shinichiro Hamaji1d545aa2015-06-23 15:29:13 +09001// Copyright 2015 Google Inc. All rights reserved
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090015#ifndef AST_H_
16#define AST_H_
17
18#include <string>
Shinichiro Hamaji42b625f2015-06-16 23:07:21 +090019#include <vector>
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090020
21#include "loc.h"
22#include "string_piece.h"
23
24using namespace std;
25
26class Evaluator;
27struct Value;
28
29enum struct AssignOp {
30 EQ,
31 COLON_EQ,
32 PLUS_EQ,
33 QUESTION_EQ,
34};
35
Shinichiro Hamaji45a0c762015-06-26 06:47:10 +090036enum struct AssignDirective {
Shinichiro Hamaji420f7752015-06-26 04:02:02 +090037 NONE = 0,
38 OVERRIDE = 1,
39 EXPORT = 2,
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090040};
41
Shinichiro Hamaji42b625f2015-06-16 23:07:21 +090042enum struct CondOp {
43 IFEQ,
44 IFNEQ,
45 IFDEF,
46 IFNDEF,
47};
48
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090049struct AST {
50 public:
51 virtual ~AST();
52
53 Loc loc() const { return loc_; }
54 void set_loc(Loc loc) { loc_ = loc; }
55 StringPiece orig() const { return orig_; }
56
57 virtual void Eval(Evaluator* ev) const = 0;
58
59 virtual string DebugString() const = 0;
60
61 protected:
62 AST();
63
64 private:
65 Loc loc_;
66 StringPiece orig_;
67};
68
69struct RuleAST : public AST {
70 Value* expr;
71 char term;
72 Value* after_term;
73
74 virtual ~RuleAST();
75
76 virtual void Eval(Evaluator* ev) const;
77
78 virtual string DebugString() const;
79};
80
81struct AssignAST : public AST {
82 Value* lhs;
83 Value* rhs;
Shinichiro Hamaji81699be2015-06-22 18:07:38 +090084 StringPiece orig_rhs;
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090085 AssignOp op;
86 AssignDirective directive;
87
88 virtual ~AssignAST();
89
90 virtual void Eval(Evaluator* ev) const;
91
92 virtual string DebugString() const;
93};
94
95struct CommandAST : public AST {
96 Value* expr;
Shinichiro Hamaji631a9f82015-07-05 14:18:15 +090097 StringPiece orig;
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090098
99 virtual ~CommandAST();
100
101 virtual void Eval(Evaluator* ev) const;
102
103 virtual string DebugString() const;
104};
105
Shinichiro Hamaji42b625f2015-06-16 23:07:21 +0900106struct IfAST : public AST {
107 CondOp op;
108 Value* lhs;
109 Value* rhs;
Shinichiro Hamaji2847f092015-06-17 15:48:37 +0900110 vector<AST*> true_asts;
111 vector<AST*> false_asts;
Shinichiro Hamaji42b625f2015-06-16 23:07:21 +0900112
113 virtual ~IfAST();
114
115 virtual void Eval(Evaluator* ev) const;
116
117 virtual string DebugString() const;
118};
119
120struct IncludeAST : public AST {
121 Value* expr;
Shinichiro Hamajiefad2dd2015-06-17 03:08:02 +0900122 bool should_exist;
Shinichiro Hamaji42b625f2015-06-16 23:07:21 +0900123
124 virtual ~IncludeAST();
125
126 virtual void Eval(Evaluator* ev) const;
127
128 virtual string DebugString() const;
129};
130
131struct ExportAST : public AST {
132 Value* expr;
133 bool is_export;
134
135 virtual ~ExportAST();
136
137 virtual void Eval(Evaluator* ev) const;
138
139 virtual string DebugString() const;
140};
141
Shinichiro Hamaji776ca302015-06-06 03:52:48 +0900142#endif // AST_H_