blob: 1abab3215890a6defc9fe5da92284dbdd1c4c55c [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
Fumitoshi Ukai744bb2b2015-06-25 00:10:52 +090015// +build ignore
16
Shinichiro Hamaji645cca72015-09-24 17:04:21 +090017#include "stmt.h"
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090018
19#include "eval.h"
Shinichiro Hamaji645cca72015-09-24 17:04:21 +090020#include "expr.h"
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090021#include "stringprintf.h"
Shinichiro Hamajic195f402015-06-24 14:44:04 +090022#include "strutil.h"
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090023
Shinichiro Hamaji645cca72015-09-24 17:04:21 +090024Stmt::Stmt() {}
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090025
Shinichiro Hamaji645cca72015-09-24 17:04:21 +090026Stmt::~Stmt() {}
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090027
Shinichiro Hamaji645cca72015-09-24 17:04:21 +090028string RuleStmt::DebugString() const {
29 return StringPrintf("RuleStmt(expr=%s term=%d after_term=%s loc=%s:%d)",
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090030 expr->DebugString().c_str(),
31 term,
Shinichiro Hamaji8ee8c372015-06-16 16:19:40 +090032 after_term->DebugString().c_str(),
33 LOCF(loc()));
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090034}
35
Shinichiro Hamaji645cca72015-09-24 17:04:21 +090036string AssignStmt::DebugString() const {
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090037 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 Hamaji645cca72015-09-24 17:04:21 +090050 return StringPrintf("AssignStmt(lhs=%s rhs=%s (%s) "
Shinichiro Hamaji81699be2015-06-22 18:07:38 +090051 "opstr=%s dir=%s loc=%s:%d)",
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090052 lhs->DebugString().c_str(),
53 rhs->DebugString().c_str(),
Shinichiro Hamajic195f402015-06-24 14:44:04 +090054 NoLineBreak(orig_rhs.as_string()).c_str(),
Shinichiro Hamaji8ee8c372015-06-16 16:19:40 +090055 opstr, dirstr, LOCF(loc()));
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090056}
57
Shinichiro Hamaji645cca72015-09-24 17:04:21 +090058string CommandStmt::DebugString() const {
59 return StringPrintf("CommandStmt(%s, loc=%s:%d)",
Shinichiro Hamaji8ee8c372015-06-16 16:19:40 +090060 expr->DebugString().c_str(), LOCF(loc()));
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090061}
62
Shinichiro Hamaji645cca72015-09-24 17:04:21 +090063string IfStmt::DebugString() const {
Shinichiro Hamaji7e256df2015-06-17 15:33:11 +090064 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 Hamaji645cca72015-09-24 17:04:21 +090071 return StringPrintf("IfStmt(op=%s, lhs=%s, rhs=%s t=%zu f=%zu loc=%s:%d)",
Shinichiro Hamaji7e256df2015-06-17 15:33:11 +090072 opstr,
73 lhs->DebugString().c_str(),
74 rhs->DebugString().c_str(),
Shinichiro Hamaji645cca72015-09-24 17:04:21 +090075 true_stmts.size(),
76 false_stmts.size(),
Shinichiro Hamaji7e256df2015-06-17 15:33:11 +090077 LOCF(loc()));
78}
79
Shinichiro Hamaji645cca72015-09-24 17:04:21 +090080string IncludeStmt::DebugString() const {
81 return StringPrintf("IncludeStmt(%s, loc=%s:%d)",
Shinichiro Hamaji42b625f2015-06-16 23:07:21 +090082 expr->DebugString().c_str(), LOCF(loc()));
83}
84
Shinichiro Hamaji645cca72015-09-24 17:04:21 +090085string ExportStmt::DebugString() const {
86 return StringPrintf("ExportStmt(%s, %d, loc=%s:%d)",
Shinichiro Hamaji45a0c762015-06-26 06:47:10 +090087 expr->DebugString().c_str(),
88 is_export,
89 LOCF(loc()));
90}
91
Shinichiro Hamaji645cca72015-09-24 17:04:21 +090092string ParseErrorStmt::DebugString() const {
93 return StringPrintf("ParseErrorStmt(%s, loc=%s:%d)",
Shinichiro Hamaji56227862015-08-05 16:53:37 +090094 msg.c_str(),
95 LOCF(loc()));
96}
97
Shinichiro Hamaji645cca72015-09-24 17:04:21 +090098RuleStmt::~RuleStmt() {
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090099 delete expr;
100 delete after_term;
101}
102
Shinichiro Hamaji645cca72015-09-24 17:04:21 +0900103void RuleStmt::Eval(Evaluator* ev) const {
Shinichiro Hamaji776ca302015-06-06 03:52:48 +0900104 ev->EvalRule(this);
105}
106
Shinichiro Hamaji645cca72015-09-24 17:04:21 +0900107AssignStmt::~AssignStmt() {
Shinichiro Hamaji776ca302015-06-06 03:52:48 +0900108 delete lhs;
109 delete rhs;
110}
111
Shinichiro Hamaji645cca72015-09-24 17:04:21 +0900112void AssignStmt::Eval(Evaluator* ev) const {
Shinichiro Hamaji776ca302015-06-06 03:52:48 +0900113 ev->EvalAssign(this);
114}
115
Shinichiro Hamaji645cca72015-09-24 17:04:21 +0900116CommandStmt::~CommandStmt() {
Shinichiro Hamaji776ca302015-06-06 03:52:48 +0900117 delete expr;
118}
119
Shinichiro Hamaji645cca72015-09-24 17:04:21 +0900120void CommandStmt::Eval(Evaluator* ev) const {
Shinichiro Hamaji776ca302015-06-06 03:52:48 +0900121 ev->EvalCommand(this);
122}
Shinichiro Hamaji42b625f2015-06-16 23:07:21 +0900123
Shinichiro Hamaji645cca72015-09-24 17:04:21 +0900124IfStmt::~IfStmt() {
Shinichiro Hamaji7e256df2015-06-17 15:33:11 +0900125 delete lhs;
126 delete rhs;
127}
128
Shinichiro Hamaji645cca72015-09-24 17:04:21 +0900129void IfStmt::Eval(Evaluator* ev) const {
Shinichiro Hamaji7e256df2015-06-17 15:33:11 +0900130 ev->EvalIf(this);
131}
132
Shinichiro Hamaji645cca72015-09-24 17:04:21 +0900133IncludeStmt::~IncludeStmt() {
Shinichiro Hamaji42b625f2015-06-16 23:07:21 +0900134 delete expr;
135}
136
Shinichiro Hamaji645cca72015-09-24 17:04:21 +0900137void IncludeStmt::Eval(Evaluator* ev) const {
Shinichiro Hamaji42b625f2015-06-16 23:07:21 +0900138 ev->EvalInclude(this);
139}
Shinichiro Hamaji45a0c762015-06-26 06:47:10 +0900140
Shinichiro Hamaji645cca72015-09-24 17:04:21 +0900141ExportStmt::~ExportStmt() {
Shinichiro Hamaji45a0c762015-06-26 06:47:10 +0900142 delete expr;
143}
144
Shinichiro Hamaji645cca72015-09-24 17:04:21 +0900145void ExportStmt::Eval(Evaluator* ev) const {
Shinichiro Hamaji45a0c762015-06-26 06:47:10 +0900146 ev->EvalExport(this);
147}
Shinichiro Hamaji56227862015-08-05 16:53:37 +0900148
Shinichiro Hamaji645cca72015-09-24 17:04:21 +0900149ParseErrorStmt::~ParseErrorStmt() {
Shinichiro Hamaji56227862015-08-05 16:53:37 +0900150}
151
Shinichiro Hamaji645cca72015-09-24 17:04:21 +0900152void ParseErrorStmt::Eval(Evaluator* ev) const {
Shinichiro Hamaji56227862015-08-05 16:53:37 +0900153 ev->set_loc(loc());
154 ev->Error(msg);
155}