blob: 68f007ee8ae5b43683dff5225b3fbcf528811e69 [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 Hamaji776ca302015-06-06 03:52:48 +090017#include "ast.h"
18
19#include "eval.h"
20#include "stringprintf.h"
Shinichiro Hamajic195f402015-06-24 14:44:04 +090021#include "strutil.h"
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090022#include "value.h"
23
24AST::AST() {}
25
26AST::~AST() {}
27
28string RuleAST::DebugString() const {
Shinichiro Hamaji8ee8c372015-06-16 16:19:40 +090029 return StringPrintf("RuleAST(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
36string 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 Hamaji81699be2015-06-22 18:07:38 +090050 return StringPrintf("AssignAST(lhs=%s rhs=%s (%s) "
51 "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
58string CommandAST::DebugString() const {
Shinichiro Hamaji8ee8c372015-06-16 16:19:40 +090059 return StringPrintf("CommandAST(%s, loc=%s:%d)",
60 expr->DebugString().c_str(), LOCF(loc()));
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090061}
62
Shinichiro Hamaji7e256df2015-06-17 15:33:11 +090063string 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 Hamaji6cb1c252015-06-17 16:22:51 +090071 return StringPrintf("IfAST(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 Hamaji6cb1c252015-06-17 16:22:51 +090075 true_asts.size(),
76 false_asts.size(),
Shinichiro Hamaji7e256df2015-06-17 15:33:11 +090077 LOCF(loc()));
78}
79
Shinichiro Hamaji42b625f2015-06-16 23:07:21 +090080string IncludeAST::DebugString() const {
81 return StringPrintf("IncludeAST(%s, loc=%s:%d)",
82 expr->DebugString().c_str(), LOCF(loc()));
83}
84
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090085RuleAST::~RuleAST() {
86 delete expr;
87 delete after_term;
88}
89
90void RuleAST::Eval(Evaluator* ev) const {
91 ev->EvalRule(this);
92}
93
94AssignAST::~AssignAST() {
95 delete lhs;
96 delete rhs;
97}
98
99void AssignAST::Eval(Evaluator* ev) const {
100 ev->EvalAssign(this);
101}
102
103CommandAST::~CommandAST() {
104 delete expr;
105}
106
107void CommandAST::Eval(Evaluator* ev) const {
108 ev->EvalCommand(this);
109}
Shinichiro Hamaji42b625f2015-06-16 23:07:21 +0900110
Shinichiro Hamaji7e256df2015-06-17 15:33:11 +0900111IfAST::~IfAST() {
112 delete lhs;
113 delete rhs;
114}
115
116void IfAST::Eval(Evaluator* ev) const {
117 ev->EvalIf(this);
118}
119
Shinichiro Hamaji42b625f2015-06-16 23:07:21 +0900120IncludeAST::~IncludeAST() {
121 delete expr;
122}
123
124void IncludeAST::Eval(Evaluator* ev) const {
125 ev->EvalInclude(this);
126}