Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 1 | #include "ast.h" |
| 2 | |
| 3 | #include "eval.h" |
| 4 | #include "stringprintf.h" |
| 5 | #include "value.h" |
| 6 | |
| 7 | AST::AST() {} |
| 8 | |
| 9 | AST::~AST() {} |
| 10 | |
| 11 | string RuleAST::DebugString() const { |
Shinichiro Hamaji | 8ee8c37 | 2015-06-16 16:19:40 +0900 | [diff] [blame] | 12 | return StringPrintf("RuleAST(expr=%s term=%d after_term=%s loc=%s:%d)", |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 13 | expr->DebugString().c_str(), |
| 14 | term, |
Shinichiro Hamaji | 8ee8c37 | 2015-06-16 16:19:40 +0900 | [diff] [blame] | 15 | after_term->DebugString().c_str(), |
| 16 | LOCF(loc())); |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | string AssignAST::DebugString() const { |
| 20 | const char* opstr = "???"; |
| 21 | switch (op) { |
| 22 | case AssignOp::EQ: opstr = "EQ"; break; |
| 23 | case AssignOp::COLON_EQ: opstr = "COLON_EQ"; break; |
| 24 | case AssignOp::PLUS_EQ: opstr = "PLUS_EQ"; break; |
| 25 | case AssignOp::QUESTION_EQ: opstr = "QUESTION_EQ"; break; |
| 26 | } |
| 27 | const char* dirstr = "???"; |
| 28 | switch (directive) { |
| 29 | case AssignDirective::NONE: dirstr = ""; break; |
| 30 | case AssignDirective::OVERRIDE: dirstr = "override"; break; |
| 31 | case AssignDirective::EXPORT: dirstr = "export"; break; |
| 32 | } |
Shinichiro Hamaji | 8ee8c37 | 2015-06-16 16:19:40 +0900 | [diff] [blame] | 33 | return StringPrintf("AssignAST(lhs=%s rhs=%s opstr=%s dir=%s loc=%s:%d)", |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 34 | lhs->DebugString().c_str(), |
| 35 | rhs->DebugString().c_str(), |
Shinichiro Hamaji | 8ee8c37 | 2015-06-16 16:19:40 +0900 | [diff] [blame] | 36 | opstr, dirstr, LOCF(loc())); |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | string CommandAST::DebugString() const { |
Shinichiro Hamaji | 8ee8c37 | 2015-06-16 16:19:40 +0900 | [diff] [blame] | 40 | return StringPrintf("CommandAST(%s, loc=%s:%d)", |
| 41 | expr->DebugString().c_str(), LOCF(loc())); |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 42 | } |
| 43 | |
Shinichiro Hamaji | 7e256df | 2015-06-17 15:33:11 +0900 | [diff] [blame^] | 44 | string IfAST::DebugString() const { |
| 45 | const char* opstr = "???"; |
| 46 | switch (op) { |
| 47 | case CondOp::IFEQ: opstr = "ifeq"; break; |
| 48 | case CondOp::IFNEQ: opstr = "ifneq"; break; |
| 49 | case CondOp::IFDEF: opstr = "ifdef"; break; |
| 50 | case CondOp::IFNDEF: opstr = "ifndef"; break; |
| 51 | } |
| 52 | return StringPrintf("IfAST(op=%s, lhs=%s, rhs=%s loc=%s:%d)", |
| 53 | opstr, |
| 54 | lhs->DebugString().c_str(), |
| 55 | rhs->DebugString().c_str(), |
| 56 | LOCF(loc())); |
| 57 | } |
| 58 | |
Shinichiro Hamaji | 42b625f | 2015-06-16 23:07:21 +0900 | [diff] [blame] | 59 | string IncludeAST::DebugString() const { |
| 60 | return StringPrintf("IncludeAST(%s, loc=%s:%d)", |
| 61 | expr->DebugString().c_str(), LOCF(loc())); |
| 62 | } |
| 63 | |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 64 | RuleAST::~RuleAST() { |
| 65 | delete expr; |
| 66 | delete after_term; |
| 67 | } |
| 68 | |
| 69 | void RuleAST::Eval(Evaluator* ev) const { |
| 70 | ev->EvalRule(this); |
| 71 | } |
| 72 | |
| 73 | AssignAST::~AssignAST() { |
| 74 | delete lhs; |
| 75 | delete rhs; |
| 76 | } |
| 77 | |
| 78 | void AssignAST::Eval(Evaluator* ev) const { |
| 79 | ev->EvalAssign(this); |
| 80 | } |
| 81 | |
| 82 | CommandAST::~CommandAST() { |
| 83 | delete expr; |
| 84 | } |
| 85 | |
| 86 | void CommandAST::Eval(Evaluator* ev) const { |
| 87 | ev->EvalCommand(this); |
| 88 | } |
Shinichiro Hamaji | 42b625f | 2015-06-16 23:07:21 +0900 | [diff] [blame] | 89 | |
Shinichiro Hamaji | 7e256df | 2015-06-17 15:33:11 +0900 | [diff] [blame^] | 90 | IfAST::~IfAST() { |
| 91 | delete lhs; |
| 92 | delete rhs; |
| 93 | } |
| 94 | |
| 95 | void IfAST::Eval(Evaluator* ev) const { |
| 96 | ev->EvalIf(this); |
| 97 | } |
| 98 | |
Shinichiro Hamaji | 42b625f | 2015-06-16 23:07:21 +0900 | [diff] [blame] | 99 | IncludeAST::~IncludeAST() { |
| 100 | delete expr; |
| 101 | } |
| 102 | |
| 103 | void IncludeAST::Eval(Evaluator* ev) const { |
| 104 | ev->EvalInclude(this); |
| 105 | } |