blob: 31a6ef4bc56f29620d7cd186383368cc322b2778 [file] [log] [blame]
Shinichiro Hamaji776ca302015-06-06 03:52:48 +09001#include "ast.h"
2
3#include "eval.h"
4#include "stringprintf.h"
5#include "value.h"
6
7AST::AST() {}
8
9AST::~AST() {}
10
11string RuleAST::DebugString() const {
Shinichiro Hamaji8ee8c372015-06-16 16:19:40 +090012 return StringPrintf("RuleAST(expr=%s term=%d after_term=%s loc=%s:%d)",
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090013 expr->DebugString().c_str(),
14 term,
Shinichiro Hamaji8ee8c372015-06-16 16:19:40 +090015 after_term->DebugString().c_str(),
16 LOCF(loc()));
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090017}
18
19string 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 Hamaji8ee8c372015-06-16 16:19:40 +090033 return StringPrintf("AssignAST(lhs=%s rhs=%s opstr=%s dir=%s loc=%s:%d)",
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090034 lhs->DebugString().c_str(),
35 rhs->DebugString().c_str(),
Shinichiro Hamaji8ee8c372015-06-16 16:19:40 +090036 opstr, dirstr, LOCF(loc()));
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090037}
38
39string CommandAST::DebugString() const {
Shinichiro Hamaji8ee8c372015-06-16 16:19:40 +090040 return StringPrintf("CommandAST(%s, loc=%s:%d)",
41 expr->DebugString().c_str(), LOCF(loc()));
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090042}
43
Shinichiro Hamaji7e256df2015-06-17 15:33:11 +090044string 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 Hamaji42b625f2015-06-16 23:07:21 +090059string IncludeAST::DebugString() const {
60 return StringPrintf("IncludeAST(%s, loc=%s:%d)",
61 expr->DebugString().c_str(), LOCF(loc()));
62}
63
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090064RuleAST::~RuleAST() {
65 delete expr;
66 delete after_term;
67}
68
69void RuleAST::Eval(Evaluator* ev) const {
70 ev->EvalRule(this);
71}
72
73AssignAST::~AssignAST() {
74 delete lhs;
75 delete rhs;
76}
77
78void AssignAST::Eval(Evaluator* ev) const {
79 ev->EvalAssign(this);
80}
81
82CommandAST::~CommandAST() {
83 delete expr;
84}
85
86void CommandAST::Eval(Evaluator* ev) const {
87 ev->EvalCommand(this);
88}
Shinichiro Hamaji42b625f2015-06-16 23:07:21 +090089
Shinichiro Hamaji7e256df2015-06-17 15:33:11 +090090IfAST::~IfAST() {
91 delete lhs;
92 delete rhs;
93}
94
95void IfAST::Eval(Evaluator* ev) const {
96 ev->EvalIf(this);
97}
98
Shinichiro Hamaji42b625f2015-06-16 23:07:21 +090099IncludeAST::~IncludeAST() {
100 delete expr;
101}
102
103void IncludeAST::Eval(Evaluator* ev) const {
104 ev->EvalInclude(this);
105}