blob: 344b42cc951ac41daf85085ff841f34e7b9562a3 [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
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090015#include "ast.h"
16
17#include "eval.h"
18#include "stringprintf.h"
19#include "value.h"
20
21AST::AST() {}
22
23AST::~AST() {}
24
25string RuleAST::DebugString() const {
Shinichiro Hamaji8ee8c372015-06-16 16:19:40 +090026 return StringPrintf("RuleAST(expr=%s term=%d after_term=%s loc=%s:%d)",
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090027 expr->DebugString().c_str(),
28 term,
Shinichiro Hamaji8ee8c372015-06-16 16:19:40 +090029 after_term->DebugString().c_str(),
30 LOCF(loc()));
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090031}
32
33string 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 Hamaji81699be2015-06-22 18:07:38 +090047 return StringPrintf("AssignAST(lhs=%s rhs=%s (%s) "
48 "opstr=%s dir=%s loc=%s:%d)",
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090049 lhs->DebugString().c_str(),
50 rhs->DebugString().c_str(),
Shinichiro Hamaji81699be2015-06-22 18:07:38 +090051 orig_rhs.as_string().c_str(),
Shinichiro Hamaji8ee8c372015-06-16 16:19:40 +090052 opstr, dirstr, LOCF(loc()));
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090053}
54
55string CommandAST::DebugString() const {
Shinichiro Hamaji8ee8c372015-06-16 16:19:40 +090056 return StringPrintf("CommandAST(%s, loc=%s:%d)",
57 expr->DebugString().c_str(), LOCF(loc()));
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090058}
59
Shinichiro Hamaji7e256df2015-06-17 15:33:11 +090060string 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 Hamaji6cb1c252015-06-17 16:22:51 +090068 return StringPrintf("IfAST(op=%s, lhs=%s, rhs=%s t=%zu f=%zu loc=%s:%d)",
Shinichiro Hamaji7e256df2015-06-17 15:33:11 +090069 opstr,
70 lhs->DebugString().c_str(),
71 rhs->DebugString().c_str(),
Shinichiro Hamaji6cb1c252015-06-17 16:22:51 +090072 true_asts.size(),
73 false_asts.size(),
Shinichiro Hamaji7e256df2015-06-17 15:33:11 +090074 LOCF(loc()));
75}
76
Shinichiro Hamaji42b625f2015-06-16 23:07:21 +090077string IncludeAST::DebugString() const {
78 return StringPrintf("IncludeAST(%s, loc=%s:%d)",
79 expr->DebugString().c_str(), LOCF(loc()));
80}
81
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090082RuleAST::~RuleAST() {
83 delete expr;
84 delete after_term;
85}
86
87void RuleAST::Eval(Evaluator* ev) const {
88 ev->EvalRule(this);
89}
90
91AssignAST::~AssignAST() {
92 delete lhs;
93 delete rhs;
94}
95
96void AssignAST::Eval(Evaluator* ev) const {
97 ev->EvalAssign(this);
98}
99
100CommandAST::~CommandAST() {
101 delete expr;
102}
103
104void CommandAST::Eval(Evaluator* ev) const {
105 ev->EvalCommand(this);
106}
Shinichiro Hamaji42b625f2015-06-16 23:07:21 +0900107
Shinichiro Hamaji7e256df2015-06-17 15:33:11 +0900108IfAST::~IfAST() {
109 delete lhs;
110 delete rhs;
111}
112
113void IfAST::Eval(Evaluator* ev) const {
114 ev->EvalIf(this);
115}
116
Shinichiro Hamaji42b625f2015-06-16 23:07:21 +0900117IncludeAST::~IncludeAST() {
118 delete expr;
119}
120
121void IncludeAST::Eval(Evaluator* ev) const {
122 ev->EvalInclude(this);
123}