Shinichiro Hamaji | 1d545aa | 2015-06-23 15:29:13 +0900 | [diff] [blame] | 1 | // 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 Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 15 | #ifndef AST_H_ |
| 16 | #define AST_H_ |
| 17 | |
| 18 | #include <string> |
Shinichiro Hamaji | 42b625f | 2015-06-16 23:07:21 +0900 | [diff] [blame] | 19 | #include <vector> |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 20 | |
| 21 | #include "loc.h" |
| 22 | #include "string_piece.h" |
| 23 | |
| 24 | using namespace std; |
| 25 | |
| 26 | class Evaluator; |
| 27 | struct Value; |
| 28 | |
| 29 | enum struct AssignOp { |
| 30 | EQ, |
| 31 | COLON_EQ, |
| 32 | PLUS_EQ, |
| 33 | QUESTION_EQ, |
| 34 | }; |
| 35 | |
Shinichiro Hamaji | 45a0c76 | 2015-06-26 06:47:10 +0900 | [diff] [blame] | 36 | enum struct AssignDirective { |
Shinichiro Hamaji | 420f775 | 2015-06-26 04:02:02 +0900 | [diff] [blame] | 37 | NONE = 0, |
| 38 | OVERRIDE = 1, |
| 39 | EXPORT = 2, |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 40 | }; |
| 41 | |
Shinichiro Hamaji | 42b625f | 2015-06-16 23:07:21 +0900 | [diff] [blame] | 42 | enum struct CondOp { |
| 43 | IFEQ, |
| 44 | IFNEQ, |
| 45 | IFDEF, |
| 46 | IFNDEF, |
| 47 | }; |
| 48 | |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 49 | struct 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 | |
| 69 | struct 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 | |
| 81 | struct AssignAST : public AST { |
| 82 | Value* lhs; |
| 83 | Value* rhs; |
Shinichiro Hamaji | 81699be | 2015-06-22 18:07:38 +0900 | [diff] [blame] | 84 | StringPiece orig_rhs; |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 85 | 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 | |
| 95 | struct CommandAST : public AST { |
| 96 | Value* expr; |
Shinichiro Hamaji | 631a9f8 | 2015-07-05 14:18:15 +0900 | [diff] [blame] | 97 | StringPiece orig; |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 98 | |
| 99 | virtual ~CommandAST(); |
| 100 | |
| 101 | virtual void Eval(Evaluator* ev) const; |
| 102 | |
| 103 | virtual string DebugString() const; |
| 104 | }; |
| 105 | |
Shinichiro Hamaji | 42b625f | 2015-06-16 23:07:21 +0900 | [diff] [blame] | 106 | struct IfAST : public AST { |
| 107 | CondOp op; |
| 108 | Value* lhs; |
| 109 | Value* rhs; |
Shinichiro Hamaji | 2847f09 | 2015-06-17 15:48:37 +0900 | [diff] [blame] | 110 | vector<AST*> true_asts; |
| 111 | vector<AST*> false_asts; |
Shinichiro Hamaji | 42b625f | 2015-06-16 23:07:21 +0900 | [diff] [blame] | 112 | |
| 113 | virtual ~IfAST(); |
| 114 | |
| 115 | virtual void Eval(Evaluator* ev) const; |
| 116 | |
| 117 | virtual string DebugString() const; |
| 118 | }; |
| 119 | |
| 120 | struct IncludeAST : public AST { |
| 121 | Value* expr; |
Shinichiro Hamaji | efad2dd | 2015-06-17 03:08:02 +0900 | [diff] [blame] | 122 | bool should_exist; |
Shinichiro Hamaji | 42b625f | 2015-06-16 23:07:21 +0900 | [diff] [blame] | 123 | |
| 124 | virtual ~IncludeAST(); |
| 125 | |
| 126 | virtual void Eval(Evaluator* ev) const; |
| 127 | |
| 128 | virtual string DebugString() const; |
| 129 | }; |
| 130 | |
| 131 | struct 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 Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 142 | #endif // AST_H_ |