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