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 | |
Fumitoshi Ukai | 744bb2b | 2015-06-25 00:10:52 +0900 | [diff] [blame] | 15 | // +build ignore |
| 16 | |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 17 | #include "ast.h" |
| 18 | |
| 19 | #include "eval.h" |
| 20 | #include "stringprintf.h" |
Shinichiro Hamaji | c195f40 | 2015-06-24 14:44:04 +0900 | [diff] [blame] | 21 | #include "strutil.h" |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 22 | #include "value.h" |
| 23 | |
| 24 | AST::AST() {} |
| 25 | |
| 26 | AST::~AST() {} |
| 27 | |
| 28 | string RuleAST::DebugString() const { |
Shinichiro Hamaji | 8ee8c37 | 2015-06-16 16:19:40 +0900 | [diff] [blame] | 29 | 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] | 30 | expr->DebugString().c_str(), |
| 31 | term, |
Shinichiro Hamaji | 8ee8c37 | 2015-06-16 16:19:40 +0900 | [diff] [blame] | 32 | after_term->DebugString().c_str(), |
| 33 | LOCF(loc())); |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | string AssignAST::DebugString() const { |
| 37 | const char* opstr = "???"; |
| 38 | switch (op) { |
| 39 | case AssignOp::EQ: opstr = "EQ"; break; |
| 40 | case AssignOp::COLON_EQ: opstr = "COLON_EQ"; break; |
| 41 | case AssignOp::PLUS_EQ: opstr = "PLUS_EQ"; break; |
| 42 | case AssignOp::QUESTION_EQ: opstr = "QUESTION_EQ"; break; |
| 43 | } |
| 44 | const char* dirstr = "???"; |
| 45 | switch (directive) { |
| 46 | case AssignDirective::NONE: dirstr = ""; break; |
| 47 | case AssignDirective::OVERRIDE: dirstr = "override"; break; |
| 48 | case AssignDirective::EXPORT: dirstr = "export"; break; |
| 49 | } |
Shinichiro Hamaji | 81699be | 2015-06-22 18:07:38 +0900 | [diff] [blame] | 50 | return StringPrintf("AssignAST(lhs=%s rhs=%s (%s) " |
| 51 | "opstr=%s dir=%s loc=%s:%d)", |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 52 | lhs->DebugString().c_str(), |
| 53 | rhs->DebugString().c_str(), |
Shinichiro Hamaji | c195f40 | 2015-06-24 14:44:04 +0900 | [diff] [blame] | 54 | NoLineBreak(orig_rhs.as_string()).c_str(), |
Shinichiro Hamaji | 8ee8c37 | 2015-06-16 16:19:40 +0900 | [diff] [blame] | 55 | opstr, dirstr, LOCF(loc())); |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | string CommandAST::DebugString() const { |
Shinichiro Hamaji | 8ee8c37 | 2015-06-16 16:19:40 +0900 | [diff] [blame] | 59 | return StringPrintf("CommandAST(%s, loc=%s:%d)", |
| 60 | expr->DebugString().c_str(), LOCF(loc())); |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 61 | } |
| 62 | |
Shinichiro Hamaji | 7e256df | 2015-06-17 15:33:11 +0900 | [diff] [blame] | 63 | string IfAST::DebugString() const { |
| 64 | const char* opstr = "???"; |
| 65 | switch (op) { |
| 66 | case CondOp::IFEQ: opstr = "ifeq"; break; |
| 67 | case CondOp::IFNEQ: opstr = "ifneq"; break; |
| 68 | case CondOp::IFDEF: opstr = "ifdef"; break; |
| 69 | case CondOp::IFNDEF: opstr = "ifndef"; break; |
| 70 | } |
Shinichiro Hamaji | 6cb1c25 | 2015-06-17 16:22:51 +0900 | [diff] [blame] | 71 | 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] | 72 | opstr, |
| 73 | lhs->DebugString().c_str(), |
| 74 | rhs->DebugString().c_str(), |
Shinichiro Hamaji | 6cb1c25 | 2015-06-17 16:22:51 +0900 | [diff] [blame] | 75 | true_asts.size(), |
| 76 | false_asts.size(), |
Shinichiro Hamaji | 7e256df | 2015-06-17 15:33:11 +0900 | [diff] [blame] | 77 | LOCF(loc())); |
| 78 | } |
| 79 | |
Shinichiro Hamaji | 42b625f | 2015-06-16 23:07:21 +0900 | [diff] [blame] | 80 | string IncludeAST::DebugString() const { |
| 81 | return StringPrintf("IncludeAST(%s, loc=%s:%d)", |
| 82 | expr->DebugString().c_str(), LOCF(loc())); |
| 83 | } |
| 84 | |
Shinichiro Hamaji | 45a0c76 | 2015-06-26 06:47:10 +0900 | [diff] [blame] | 85 | string ExportAST::DebugString() const { |
| 86 | return StringPrintf("ExportAST(%s, %d, loc=%s:%d)", |
| 87 | expr->DebugString().c_str(), |
| 88 | is_export, |
| 89 | LOCF(loc())); |
| 90 | } |
| 91 | |
Shinichiro Hamaji | 5622786 | 2015-08-05 16:53:37 +0900 | [diff] [blame] | 92 | string ParseErrorAST::DebugString() const { |
| 93 | return StringPrintf("ParseErrorAST(%s, loc=%s:%d)", |
| 94 | msg.c_str(), |
| 95 | LOCF(loc())); |
| 96 | } |
| 97 | |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 98 | RuleAST::~RuleAST() { |
| 99 | delete expr; |
| 100 | delete after_term; |
| 101 | } |
| 102 | |
| 103 | void RuleAST::Eval(Evaluator* ev) const { |
| 104 | ev->EvalRule(this); |
| 105 | } |
| 106 | |
| 107 | AssignAST::~AssignAST() { |
| 108 | delete lhs; |
| 109 | delete rhs; |
| 110 | } |
| 111 | |
| 112 | void AssignAST::Eval(Evaluator* ev) const { |
| 113 | ev->EvalAssign(this); |
| 114 | } |
| 115 | |
| 116 | CommandAST::~CommandAST() { |
| 117 | delete expr; |
| 118 | } |
| 119 | |
| 120 | void CommandAST::Eval(Evaluator* ev) const { |
| 121 | ev->EvalCommand(this); |
| 122 | } |
Shinichiro Hamaji | 42b625f | 2015-06-16 23:07:21 +0900 | [diff] [blame] | 123 | |
Shinichiro Hamaji | 7e256df | 2015-06-17 15:33:11 +0900 | [diff] [blame] | 124 | IfAST::~IfAST() { |
| 125 | delete lhs; |
| 126 | delete rhs; |
| 127 | } |
| 128 | |
| 129 | void IfAST::Eval(Evaluator* ev) const { |
| 130 | ev->EvalIf(this); |
| 131 | } |
| 132 | |
Shinichiro Hamaji | 42b625f | 2015-06-16 23:07:21 +0900 | [diff] [blame] | 133 | IncludeAST::~IncludeAST() { |
| 134 | delete expr; |
| 135 | } |
| 136 | |
| 137 | void IncludeAST::Eval(Evaluator* ev) const { |
| 138 | ev->EvalInclude(this); |
| 139 | } |
Shinichiro Hamaji | 45a0c76 | 2015-06-26 06:47:10 +0900 | [diff] [blame] | 140 | |
| 141 | ExportAST::~ExportAST() { |
| 142 | delete expr; |
| 143 | } |
| 144 | |
| 145 | void ExportAST::Eval(Evaluator* ev) const { |
| 146 | ev->EvalExport(this); |
| 147 | } |
Shinichiro Hamaji | 5622786 | 2015-08-05 16:53:37 +0900 | [diff] [blame] | 148 | |
| 149 | ParseErrorAST::~ParseErrorAST() { |
| 150 | } |
| 151 | |
| 152 | void ParseErrorAST::Eval(Evaluator* ev) const { |
| 153 | ev->set_loc(loc()); |
| 154 | ev->Error(msg); |
| 155 | } |