aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.ckati4
-rw-r--r--eval.cc96
-rw-r--r--eval.h14
-rw-r--r--exec.cc2
-rw-r--r--expr.cc (renamed from value.cc)2
-rw-r--r--expr.h (renamed from value.h)6
-rw-r--r--file.cc6
-rw-r--r--file.h8
-rw-r--r--func.cc14
-rw-r--r--func.h2
-rw-r--r--main.cc26
-rw-r--r--parser.cc180
-rw-r--r--parser.h8
-rw-r--r--rule.cc2
-rw-r--r--rule.h2
-rw-r--r--stmt.cc (renamed from ast.cc)68
-rw-r--r--stmt.h (renamed from ast.h)44
-rw-r--r--var.cc2
-rw-r--r--var.h4
19 files changed, 245 insertions, 245 deletions
diff --git a/Makefile.ckati b/Makefile.ckati
index 26dc1f7..9c1f016 100644
--- a/Makefile.ckati
+++ b/Makefile.ckati
@@ -22,11 +22,11 @@ KATI_INTERMEDIATES_PATH ?= .
KATI_BIN_PATH ?= .
KATI_CXX_SRCS := \
- ast.cc \
command.cc \
dep.cc \
eval.cc \
exec.cc \
+ expr.cc \
file.cc \
file_cache.cc \
fileutil.cc \
@@ -40,12 +40,12 @@ KATI_CXX_SRCS := \
parser.cc \
rule.cc \
stats.cc \
+ stmt.cc \
string_piece.cc \
stringprintf.cc \
strutil.cc \
symtab.cc \
timeutil.cc \
- value.cc \
var.cc
KATI_CXX_GENERATED_SRCS := \
diff --git a/eval.cc b/eval.cc
index d950b8a..3920b05 100644
--- a/eval.cc
+++ b/eval.cc
@@ -19,15 +19,15 @@
#include <errno.h>
#include <string.h>
-#include "ast.h"
+#include "expr.h"
#include "file.h"
#include "file_cache.h"
#include "fileutil.h"
#include "parser.h"
#include "rule.h"
+#include "stmt.h"
#include "strutil.h"
#include "symtab.h"
-#include "value.h"
#include "var.h"
EvalResult::~EvalResult() {
@@ -96,34 +96,34 @@ Var* Evaluator::EvalRHS(Symbol lhs, Value* rhs_v, StringPiece orig_rhs,
return NULL;
}
-void Evaluator::EvalAssign(const AssignAST* ast) {
- loc_ = ast->loc();
+void Evaluator::EvalAssign(const AssignStmt* stmt) {
+ loc_ = stmt->loc();
last_rule_ = NULL;
- Symbol lhs = Intern(ast->lhs->Eval(this));
+ Symbol lhs = Intern(stmt->lhs->Eval(this));
if (lhs.empty())
Error("*** empty variable name.");
- Var* rhs = EvalRHS(lhs, ast->rhs, ast->orig_rhs, ast->op,
- ast->directive == AssignDirective::OVERRIDE);
+ Var* rhs = EvalRHS(lhs, stmt->rhs, stmt->orig_rhs, stmt->op,
+ stmt->directive == AssignDirective::OVERRIDE);
if (rhs)
vars_->Assign(lhs, rhs);
}
-void Evaluator::EvalRule(const RuleAST* ast) {
- loc_ = ast->loc();
+void Evaluator::EvalRule(const RuleStmt* stmt) {
+ loc_ = stmt->loc();
last_rule_ = NULL;
- const string&& expr = ast->expr->Eval(this);
+ const string&& expr = stmt->expr->Eval(this);
// See semicolon.mk.
if (expr.find_first_not_of(" \t\n;") == string::npos)
return;
Rule* rule;
RuleVarAssignment rule_var;
- ParseRule(loc_, expr, ast->term, &rule, &rule_var);
+ ParseRule(loc_, expr, stmt->term, &rule, &rule_var);
if (rule) {
- if (ast->term == ';') {
- rule->cmds.push_back(ast->after_term);
+ if (stmt->term == ';') {
+ rule->cmds.push_back(stmt->after_term);
}
LOG("Rule: %s", rule->DebugString().c_str());
@@ -138,13 +138,13 @@ void Evaluator::EvalRule(const RuleAST* ast) {
p.first->second = new Vars;
}
- Value* rhs = ast->after_term;
+ Value* rhs = stmt->after_term;
if (!rule_var.rhs.empty()) {
Value* lit = NewLiteral(rule_var.rhs);
if (rhs) {
// TODO: We always insert two whitespaces around the
// terminator. Preserve whitespaces properly.
- if (ast->term == ';') {
+ if (stmt->term == ';') {
rhs = NewExpr3(lit, NewLiteral(StringPiece(" ; ")), rhs);
} else {
rhs = NewExpr3(lit, NewLiteral(StringPiece(" = ")), rhs);
@@ -163,41 +163,41 @@ void Evaluator::EvalRule(const RuleAST* ast) {
}
}
-void Evaluator::EvalCommand(const CommandAST* ast) {
- loc_ = ast->loc();
+void Evaluator::EvalCommand(const CommandStmt* stmt) {
+ loc_ = stmt->loc();
if (!last_rule_) {
- vector<AST*> asts;
- ParseNotAfterRule(ast->orig, ast->loc(), &asts);
- for (AST* a : asts)
+ vector<Stmt*> stmts;
+ ParseNotAfterRule(stmt->orig, stmt->loc(), &stmts);
+ for (Stmt* a : stmts)
a->Eval(this);
return;
}
- last_rule_->cmds.push_back(ast->expr);
+ last_rule_->cmds.push_back(stmt->expr);
if (last_rule_->cmd_lineno == 0)
- last_rule_->cmd_lineno = ast->loc().lineno;
- LOG("Command: %s", ast->expr->DebugString().c_str());
+ last_rule_->cmd_lineno = stmt->loc().lineno;
+ LOG("Command: %s", stmt->expr->DebugString().c_str());
}
-void Evaluator::EvalIf(const IfAST* ast) {
- loc_ = ast->loc();
+void Evaluator::EvalIf(const IfStmt* stmt) {
+ loc_ = stmt->loc();
bool is_true;
- switch (ast->op) {
+ switch (stmt->op) {
case CondOp::IFDEF:
case CondOp::IFNDEF: {
- Symbol lhs = Intern(ast->lhs->Eval(this));
+ Symbol lhs = Intern(stmt->lhs->Eval(this));
Var* v = LookupVarInCurrentScope(lhs);
const string&& s = v->Eval(this);
- is_true = (s.empty() == (ast->op == CondOp::IFNDEF));
+ is_true = (s.empty() == (stmt->op == CondOp::IFNDEF));
break;
}
case CondOp::IFEQ:
case CondOp::IFNEQ: {
- const string&& lhs = ast->lhs->Eval(this);
- const string&& rhs = ast->rhs->Eval(this);
- is_true = ((lhs == rhs) == (ast->op == CondOp::IFEQ));
+ const string&& lhs = stmt->lhs->Eval(this);
+ const string&& rhs = stmt->rhs->Eval(this);
+ is_true = ((lhs == rhs) == (stmt->op == CondOp::IFEQ));
break;
}
default:
@@ -205,13 +205,13 @@ void Evaluator::EvalIf(const IfAST* ast) {
abort();
}
- const vector<AST*>* asts;
+ const vector<Stmt*>* stmts;
if (is_true) {
- asts = &ast->true_asts;
+ stmts = &stmt->true_stmts;
} else {
- asts = &ast->false_asts;
+ stmts = &stmt->false_stmts;
}
- for (AST* a : *asts) {
+ for (Stmt* a : *stmts) {
LOG("%s", a->DebugString().c_str());
a->Eval(this);
}
@@ -223,23 +223,23 @@ void Evaluator::DoInclude(const string& fname) {
Var* var_list = LookupVar(Intern("MAKEFILE_LIST"));
var_list->AppendVar(this, NewLiteral(Intern(TrimLeadingCurdir(fname)).str()));
- for (AST* ast : mk->asts()) {
- LOG("%s", ast->DebugString().c_str());
- ast->Eval(this);
+ for (Stmt* stmt : mk->stmts()) {
+ LOG("%s", stmt->DebugString().c_str());
+ stmt->Eval(this);
}
}
-void Evaluator::EvalInclude(const IncludeAST* ast) {
- loc_ = ast->loc();
+void Evaluator::EvalInclude(const IncludeStmt* stmt) {
+ loc_ = stmt->loc();
last_rule_ = NULL;
- const string&& pats = ast->expr->Eval(this);
+ const string&& pats = stmt->expr->Eval(this);
for (StringPiece pat : WordScanner(pats)) {
ScopedTerminator st(pat);
vector<string>* files;
Glob(pat.data(), &files);
- if (ast->should_exist) {
+ if (stmt->should_exist) {
if (files->empty()) {
Error(StringPrintf(
"%s: %s\n"
@@ -249,7 +249,7 @@ void Evaluator::EvalInclude(const IncludeAST* ast) {
}
for (const string& fname : *files) {
- if (!ast->should_exist && g_flags.ignore_optional_include_pattern &&
+ if (!stmt->should_exist && g_flags.ignore_optional_include_pattern &&
Pattern(g_flags.ignore_optional_include_pattern).Match(fname)) {
return;
}
@@ -258,15 +258,15 @@ void Evaluator::EvalInclude(const IncludeAST* ast) {
}
}
-void Evaluator::EvalExport(const ExportAST* ast) {
- loc_ = ast->loc();
+void Evaluator::EvalExport(const ExportStmt* stmt) {
+ loc_ = stmt->loc();
last_rule_ = NULL;
- const string&& exports = ast->expr->Eval(this);
+ const string&& exports = stmt->expr->Eval(this);
for (StringPiece tok : WordScanner(exports)) {
size_t equal_index = tok.find('=');
if (equal_index == string::npos) {
- exports_[Intern(tok)] = ast->is_export;
+ exports_[Intern(tok)] = stmt->is_export;
} else if (equal_index == 0 ||
(equal_index == 1 &&
(tok[0] == ':' || tok[0] == '?' || tok[0] == '+'))) {
@@ -276,7 +276,7 @@ void Evaluator::EvalExport(const ExportAST* ast) {
StringPiece lhs, rhs;
AssignOp op;
ParseAssignStatement(tok, equal_index, &lhs, &rhs, &op);
- exports_[Intern(lhs)] = ast->is_export;
+ exports_[Intern(lhs)] = stmt->is_export;
}
}
}
diff --git a/eval.h b/eval.h
index 1326a0e..3ebb21b 100644
--- a/eval.h
+++ b/eval.h
@@ -20,8 +20,8 @@
#include <unordered_set>
#include <vector>
-#include "ast.h"
#include "loc.h"
+#include "stmt.h"
#include "string_piece.h"
#include "symtab.h"
@@ -46,12 +46,12 @@ class Evaluator {
Evaluator(const Vars* vars);
~Evaluator();
- void EvalAssign(const AssignAST* ast);
- void EvalRule(const RuleAST* ast);
- void EvalCommand(const CommandAST* ast);
- void EvalIf(const IfAST* ast);
- void EvalInclude(const IncludeAST* ast);
- void EvalExport(const ExportAST* ast);
+ void EvalAssign(const AssignStmt* stmt);
+ void EvalRule(const RuleStmt* stmt);
+ void EvalCommand(const CommandStmt* stmt);
+ void EvalIf(const IfStmt* stmt);
+ void EvalInclude(const IncludeStmt* stmt);
+ void EvalExport(const ExportStmt* stmt);
Var* LookupVar(Symbol name);
// For target specific variables.
diff --git a/exec.cc b/exec.cc
index 563d615..afba609 100644
--- a/exec.cc
+++ b/exec.cc
@@ -27,13 +27,13 @@
#include "command.h"
#include "dep.h"
#include "eval.h"
+#include "expr.h"
#include "fileutil.h"
#include "flags.h"
#include "log.h"
#include "string_piece.h"
#include "strutil.h"
#include "symtab.h"
-#include "value.h"
#include "var.h"
namespace {
diff --git a/value.cc b/expr.cc
index 83c6b18..07cccc9 100644
--- a/value.cc
+++ b/expr.cc
@@ -14,7 +14,7 @@
// +build ignore
-#include "value.h"
+#include "expr.h"
#include <vector>
diff --git a/value.h b/expr.h
index 51ca29c..606ef90 100644
--- a/value.h
+++ b/expr.h
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#ifndef VALUE_H_
-#define VALUE_H_
+#ifndef EXPR_H_
+#define EXPR_H_
#include <string>
#include <vector>
@@ -68,4 +68,4 @@ Value* NewExpr3(Value* v1, Value* v2, Value* v3);
Value* NewLiteral(StringPiece s);
-#endif // VALUE_H_
+#endif // EXPR_H_
diff --git a/file.cc b/file.cc
index 7217a37..4c423e5 100644
--- a/file.cc
+++ b/file.cc
@@ -21,9 +21,9 @@
#include <sys/types.h>
#include <unistd.h>
-#include "ast.h"
#include "log.h"
#include "parser.h"
+#include "stmt.h"
Makefile::Makefile(const string& filename)
: buf_(NULL), len_(0), mtime_(0), filename_(filename) {
@@ -56,6 +56,6 @@ Makefile::Makefile(const string& filename)
Makefile::~Makefile() {
delete[] buf_;
- for (AST* ast : asts_)
- delete ast;
+ for (Stmt* stmt : stmts_)
+ delete stmt;
}
diff --git a/file.h b/file.h
index 5367320..1746343 100644
--- a/file.h
+++ b/file.h
@@ -22,7 +22,7 @@
using namespace std;
-struct AST;
+struct Stmt;
class Makefile {
public:
@@ -33,8 +33,8 @@ class Makefile {
size_t len() const { return len_; }
const string& filename() const { return filename_; }
- const vector<AST*>& asts() const { return asts_; }
- vector<AST*>* mutable_asts() { return &asts_; }
+ const vector<Stmt*>& stmts() const { return stmts_; }
+ vector<Stmt*>* mutable_stmts() { return &stmts_; }
bool Exists() const { return buf_; }
@@ -43,7 +43,7 @@ class Makefile {
size_t len_;
uint64_t mtime_;
string filename_;
- vector<AST*> asts_;
+ vector<Stmt*> stmts_;
};
#endif // FILE_H_
diff --git a/func.cc b/func.cc
index 25c41c1..6368e02 100644
--- a/func.cc
+++ b/func.cc
@@ -27,13 +27,13 @@
#include <memory>
#include <unordered_map>
-#include "ast.h"
#include "eval.h"
#include "fileutil.h"
#include "find.h"
#include "log.h"
#include "parser.h"
#include "stats.h"
+#include "stmt.h"
#include "strutil.h"
#include "symtab.h"
#include "var.h"
@@ -451,12 +451,12 @@ void EvalFunc(const vector<Value*>& args, Evaluator* ev, string*) {
//const string text = args[0]->Eval(ev);
string* text = new string;
args[0]->Eval(ev, text);
- vector<AST*> asts;
- Parse(*text, ev->loc(), &asts);
- for (AST* ast : asts) {
- LOG("%s", ast->DebugString().c_str());
- ast->Eval(ev);
- //delete ast;
+ vector<Stmt*> stmts;
+ Parse(*text, ev->loc(), &stmts);
+ for (Stmt* stmt : stmts) {
+ LOG("%s", stmt->DebugString().c_str());
+ stmt->Eval(ev);
+ //delete stmt;
}
}
diff --git a/func.h b/func.h
index 11fea28..8db2c7a 100644
--- a/func.h
+++ b/func.h
@@ -19,7 +19,7 @@
#include <string>
#include <vector>
-#include "value.h"
+#include "expr.h"
using namespace std;
diff --git a/main.cc b/main.cc
index 61bedf6..d09eb4f 100644
--- a/main.cc
+++ b/main.cc
@@ -21,7 +21,6 @@
#include <time.h>
#include <unistd.h>
-#include "ast.h"
#include "dep.h"
#include "eval.h"
#include "exec.h"
@@ -35,6 +34,7 @@
#include "ninja.h"
#include "parser.h"
#include "stats.h"
+#include "stmt.h"
#include "string_piece.h"
#include "stringprintf.h"
#include "strutil.h"
@@ -71,7 +71,7 @@ static void Quit() {
}
static void ReadBootstrapMakefile(const vector<Symbol>& targets,
- vector<AST*>* asts) {
+ vector<Stmt*>* stmts) {
string bootstrap = (
"CC?=cc\n"
#if defined(__APPLE__)
@@ -112,7 +112,7 @@ static void ReadBootstrapMakefile(const vector<Symbol>& targets,
CHECK(false);
}
bootstrap += StringPrintf("CURDIR:=%s\n", cwd);
- Parse(Intern(bootstrap).str(), Loc("*bootstrap*", 0), asts);
+ Parse(Intern(bootstrap).str(), Loc("*bootstrap*", 0), stmts);
}
static void SetVar(StringPiece l, VarOrigin origin, Vars* vars) {
@@ -155,12 +155,12 @@ static int Run(const vector<Symbol>& targets,
}
Evaluator* ev = new Evaluator(vars);
- vector<AST*> bootstrap_asts;
+ vector<Stmt*> bootstrap_asts;
ReadBootstrapMakefile(targets, &bootstrap_asts);
ev->set_is_bootstrap(true);
- for (AST* ast : bootstrap_asts) {
- LOG("%s", ast->DebugString().c_str());
- ast->Eval(ev);
+ for (Stmt* stmt : bootstrap_asts) {
+ LOG("%s", stmt->DebugString().c_str());
+ stmt->Eval(ev);
}
ev->set_is_bootstrap(false);
@@ -175,13 +175,13 @@ static int Run(const vector<Symbol>& targets,
{
ScopedTimeReporter tr("eval time");
Makefile* mk = cache_mgr->ReadMakefile(g_flags.makefile);
- for (AST* ast : mk->asts()) {
- LOG("%s", ast->DebugString().c_str());
- ast->Eval(ev);
+ for (Stmt* stmt : mk->stmts()) {
+ LOG("%s", stmt->DebugString().c_str());
+ stmt->Eval(ev);
}
}
- for (ParseErrorAST* err : GetParseErrors()) {
+ for (ParseErrorStmt* err : GetParseErrors()) {
WARN("%s:%d: warning for parse error in an unevaluated line: %s",
LOCF(err->loc()), err->msg.c_str());
}
@@ -221,8 +221,8 @@ static int Run(const vector<Symbol>& targets,
Exec(nodes, ev);
}
- for (AST* ast : bootstrap_asts)
- delete ast;
+ for (Stmt* stmt : bootstrap_asts)
+ delete stmt;
delete ev;
delete vars;
delete cache_mgr;
diff --git a/parser.cc b/parser.cc
index d8b33e4..106b576 100644
--- a/parser.cc
+++ b/parser.cc
@@ -19,14 +19,14 @@
#include <stack>
#include <unordered_map>
-#include "ast.h"
+#include "expr.h"
#include "file.h"
#include "loc.h"
#include "log.h"
#include "stats.h"
+#include "stmt.h"
#include "string_piece.h"
#include "strutil.h"
-#include "value.h"
enum struct ParserState {
NOT_AFTER_RULE = 0,
@@ -36,7 +36,7 @@ enum struct ParserState {
class Parser {
struct IfState {
- IfAST* ast;
+ IfStmt* stmt;
bool is_in_else;
int num_nest;
};
@@ -46,21 +46,21 @@ class Parser {
typedef unordered_map<StringPiece, DirectiveHandler> DirectiveMap;
public:
- Parser(StringPiece buf, const char* filename, vector<AST*>* asts)
+ Parser(StringPiece buf, const char* filename, vector<Stmt*>* stmts)
: buf_(buf),
state_(ParserState::NOT_AFTER_RULE),
- asts_(asts),
- out_asts_(asts),
+ stmts_(stmts),
+ out_stmts_(stmts),
num_if_nest_(0),
loc_(filename, 0),
fixed_lineno_(false) {
}
- Parser(StringPiece buf, const Loc& loc, vector<AST*>* asts)
+ Parser(StringPiece buf, const Loc& loc, vector<Stmt*>* stmts)
: buf_(buf),
state_(ParserState::NOT_AFTER_RULE),
- asts_(asts),
- out_asts_(asts),
+ stmts_(stmts),
+ out_stmts_(stmts),
num_if_nest_(0),
loc_(loc),
fixed_lineno_(true) {
@@ -131,15 +131,15 @@ class Parser {
void set_state(ParserState st) { state_ = st; }
- static vector<ParseErrorAST*> parse_errors;
+ static vector<ParseErrorStmt*> parse_errors;
private:
void Error(const string& msg) {
- ParseErrorAST* ast = new ParseErrorAST();
- ast->set_loc(loc_);
- ast->msg = msg;
- out_asts_->push_back(ast);
- parse_errors.push_back(ast);
+ ParseErrorStmt* stmt = new ParseErrorStmt();
+ stmt->set_loc(loc_);
+ stmt->msg = msg;
+ out_stmts_->push_back(stmt);
+ parse_errors.push_back(stmt);
}
size_t FindEndOfLine(size_t* lf_cnt) {
@@ -162,11 +162,11 @@ class Parser {
current_directive_ = AssignDirective::NONE;
if (line[0] == '\t' && state_ != ParserState::NOT_AFTER_RULE) {
- CommandAST* ast = new CommandAST();
- ast->set_loc(loc_);
- ast->expr = ParseExpr(line.substr(1), ParseExprOpt::COMMAND);
- ast->orig = line;
- out_asts_->push_back(ast);
+ CommandStmt* stmt = new CommandStmt();
+ stmt->set_loc(loc_);
+ stmt->expr = ParseExpr(line.substr(1), ParseExprOpt::COMMAND);
+ stmt->orig = line;
+ out_stmts_->push_back(stmt);
return;
}
@@ -217,23 +217,23 @@ class Parser {
}
const bool is_rule = sep != string::npos && line[sep] == ':';
- RuleAST* ast = new RuleAST();
- ast->set_loc(loc_);
+ RuleStmt* stmt = new RuleStmt();
+ stmt->set_loc(loc_);
size_t found = FindTwoOutsideParen(line.substr(sep + 1), '=', ';');
if (found != string::npos) {
found += sep + 1;
- ast->term = line[found];
+ stmt->term = line[found];
ParseExprOpt opt =
- ast->term == ';' ? ParseExprOpt::COMMAND : ParseExprOpt::NORMAL;
- ast->after_term = ParseExpr(TrimLeftSpace(line.substr(found + 1)), opt);
- ast->expr = ParseExpr(TrimSpace(line.substr(0, found)));
+ stmt->term == ';' ? ParseExprOpt::COMMAND : ParseExprOpt::NORMAL;
+ stmt->after_term = ParseExpr(TrimLeftSpace(line.substr(found + 1)), opt);
+ stmt->expr = ParseExpr(TrimSpace(line.substr(0, found)));
} else {
- ast->term = 0;
- ast->after_term = NULL;
- ast->expr = ParseExpr(line);
+ stmt->term = 0;
+ stmt->after_term = NULL;
+ stmt->expr = ParseExpr(line);
}
- out_asts_->push_back(ast);
+ out_stmts_->push_back(stmt);
state_ = is_rule ? ParserState::AFTER_RULE : ParserState::MAYBE_AFTER_RULE;
}
@@ -247,23 +247,23 @@ class Parser {
AssignOp op;
ParseAssignStatement(line, sep, &lhs, &rhs, &op);
- AssignAST* ast = new AssignAST();
- ast->set_loc(loc_);
- ast->lhs = ParseExpr(lhs);
- ast->rhs = ParseExpr(rhs);
- ast->orig_rhs = rhs;
- ast->op = op;
- ast->directive = current_directive_;
- out_asts_->push_back(ast);
+ AssignStmt* stmt = new AssignStmt();
+ stmt->set_loc(loc_);
+ stmt->lhs = ParseExpr(lhs);
+ stmt->rhs = ParseExpr(rhs);
+ stmt->orig_rhs = rhs;
+ stmt->op = op;
+ stmt->directive = current_directive_;
+ out_stmts_->push_back(stmt);
state_ = ParserState::NOT_AFTER_RULE;
}
void ParseInclude(StringPiece line, StringPiece directive) {
- IncludeAST* ast = new IncludeAST();
- ast->set_loc(loc_);
- ast->expr = ParseExpr(line);
- ast->should_exist = directive[0] == 'i';
- out_asts_->push_back(ast);
+ IncludeStmt* stmt = new IncludeStmt();
+ stmt->set_loc(loc_);
+ stmt->expr = ParseExpr(line);
+ stmt->should_exist = directive[0] == 'i';
+ out_stmts_->push_back(stmt);
state_ = ParserState::NOT_AFTER_RULE;
}
@@ -292,40 +292,40 @@ class Parser {
WARN("%s:%d: extraneous text after `endef' directive", LOCF(loc_));
}
- AssignAST* ast = new AssignAST();
- ast->set_loc(Loc(loc_.filename, define_start_line_));
- ast->lhs = ParseExpr(define_name_);
+ AssignStmt* stmt = new AssignStmt();
+ stmt->set_loc(Loc(loc_.filename, define_start_line_));
+ stmt->lhs = ParseExpr(define_name_);
StringPiece rhs;
if (define_start_)
rhs = buf_.substr(define_start_, l_ - define_start_ - 1);
- ast->rhs = ParseExpr(rhs, ParseExprOpt::DEFINE);
- ast->orig_rhs = rhs;
- ast->op = AssignOp::EQ;
- ast->directive = current_directive_;
- out_asts_->push_back(ast);
+ stmt->rhs = ParseExpr(rhs, ParseExprOpt::DEFINE);
+ stmt->orig_rhs = rhs;
+ stmt->op = AssignOp::EQ;
+ stmt->directive = current_directive_;
+ out_stmts_->push_back(stmt);
define_name_.clear();
}
- void EnterIf(IfAST* ast) {
+ void EnterIf(IfStmt* stmt) {
IfState* st = new IfState();
- st->ast = ast;
+ st->stmt = stmt;
st->is_in_else = false;
st->num_nest = num_if_nest_;
if_stack_.push(st);
- out_asts_ = &ast->true_asts;
+ out_stmts_ = &stmt->true_stmts;
}
void ParseIfdef(StringPiece line, StringPiece directive) {
- IfAST* ast = new IfAST();
- ast->set_loc(loc_);
- ast->op = directive[2] == 'n' ? CondOp::IFNDEF : CondOp::IFDEF;
- ast->lhs = ParseExpr(line);
- ast->rhs = NULL;
- out_asts_->push_back(ast);
- EnterIf(ast);
+ IfStmt* stmt = new IfStmt();
+ stmt->set_loc(loc_);
+ stmt->op = directive[2] == 'n' ? CondOp::IFNDEF : CondOp::IFDEF;
+ stmt->lhs = ParseExpr(line);
+ stmt->rhs = NULL;
+ out_stmts_->push_back(stmt);
+ EnterIf(stmt);
}
- bool ParseIfEqCond(StringPiece s, IfAST* ast) {
+ bool ParseIfEqCond(StringPiece s, IfStmt* stmt) {
if (s.empty()) {
return false;
}
@@ -334,11 +334,11 @@ class Parser {
s = s.substr(1, s.size() - 2);
char terms[] = {',', '\0'};
size_t n;
- ast->lhs = ParseExprImpl(loc_, s, terms, ParseExprOpt::NORMAL, &n, true);
+ stmt->lhs = ParseExprImpl(loc_, s, terms, ParseExprOpt::NORMAL, &n, true);
if (s[n] != ',')
return false;
s = TrimLeftSpace(s.substr(n+1));
- ast->rhs = ParseExprImpl(loc_, s, NULL, ParseExprOpt::NORMAL, &n);
+ stmt->rhs = ParseExprImpl(loc_, s, NULL, ParseExprOpt::NORMAL, &n);
s = TrimLeftSpace(s.substr(n));
} else {
for (int i = 0; i < 2; i++) {
@@ -352,9 +352,9 @@ class Parser {
return false;
Value* v = ParseExpr(s.substr(1, end - 1), ParseExprOpt::NORMAL);
if (i == 0)
- ast->lhs = v;
+ stmt->lhs = v;
else
- ast->rhs = v;
+ stmt->rhs = v;
s = TrimLeftSpace(s.substr(end+1));
}
}
@@ -366,17 +366,17 @@ class Parser {
}
void ParseIfeq(StringPiece line, StringPiece directive) {
- IfAST* ast = new IfAST();
- ast->set_loc(loc_);
- ast->op = directive[2] == 'n' ? CondOp::IFNEQ : CondOp::IFEQ;
+ IfStmt* stmt = new IfStmt();
+ stmt->set_loc(loc_);
+ stmt->op = directive[2] == 'n' ? CondOp::IFNEQ : CondOp::IFEQ;
- if (!ParseIfEqCond(line, ast)) {
+ if (!ParseIfEqCond(line, stmt)) {
Error("*** invalid syntax in conditional.");
return;
}
- out_asts_->push_back(ast);
- EnterIf(ast);
+ out_stmts_->push_back(stmt);
+ EnterIf(stmt);
}
void ParseElse(StringPiece line, StringPiece) {
@@ -388,7 +388,7 @@ class Parser {
return;
}
st->is_in_else = true;
- out_asts_ = &st->ast->false_asts;
+ out_stmts_ = &st->stmt->false_stmts;
StringPiece next_if = TrimLeftSpace(line);
if (next_if.empty())
@@ -413,13 +413,13 @@ class Parser {
delete if_stack_.top();
if_stack_.pop();
if (if_stack_.empty()) {
- out_asts_ = asts_;
+ out_stmts_ = stmts_;
} else {
IfState* st = if_stack_.top();
if (st->is_in_else)
- out_asts_ = &st->ast->false_asts;
+ out_stmts_ = &st->stmt->false_stmts;
else
- out_asts_ = &st->ast->true_asts;
+ out_stmts_ = &st->stmt->true_stmts;
}
}
}
@@ -430,11 +430,11 @@ class Parser {
}
void CreateExport(StringPiece line, bool is_export) {
- ExportAST* ast = new ExportAST;
- ast->set_loc(loc_);
- ast->expr = ParseExpr(line);
- ast->is_export = is_export;
- out_asts_->push_back(ast);
+ ExportStmt* stmt = new ExportStmt;
+ stmt->set_loc(loc_);
+ stmt->expr = ParseExpr(line);
+ stmt->is_export = is_export;
+ out_stmts_->push_back(stmt);
}
void ParseOverride(StringPiece line, StringPiece) {
@@ -504,8 +504,8 @@ class Parser {
size_t l_;
ParserState state_;
- vector<AST*>* asts_;
- vector<AST*>* out_asts_;
+ vector<Stmt*>* stmts_;
+ vector<Stmt*>* out_stmts_;
StringPiece define_name_;
size_t define_start_;
@@ -531,19 +531,19 @@ void Parse(Makefile* mk) {
COLLECT_STATS("parse file time");
Parser parser(StringPiece(mk->buf(), mk->len()),
mk->filename().c_str(),
- mk->mutable_asts());
+ mk->mutable_stmts());
parser.Parse();
}
-void Parse(StringPiece buf, const Loc& loc, vector<AST*>* out_asts) {
+void Parse(StringPiece buf, const Loc& loc, vector<Stmt*>* out_stmts) {
COLLECT_STATS("parse eval time");
- Parser parser(buf, loc, out_asts);
+ Parser parser(buf, loc, out_stmts);
parser.Parse();
}
void ParseNotAfterRule(StringPiece buf, const Loc& loc,
- vector<AST*>* out_asts) {
- Parser parser(buf, loc, out_asts);
+ vector<Stmt*>* out_stmts) {
+ Parser parser(buf, loc, out_stmts);
parser.set_state(ParserState::NOT_AFTER_RULE);
parser.Parse();
}
@@ -561,7 +561,7 @@ Parser::DirectiveMap* Parser::else_if_directives_;
Parser::DirectiveMap* Parser::assign_directives_;
size_t Parser::shortest_directive_len_;
size_t Parser::longest_directive_len_;
-vector<ParseErrorAST*> Parser::parse_errors;
+vector<ParseErrorStmt*> Parser::parse_errors;
void ParseAssignStatement(StringPiece line, size_t sep,
StringPiece* lhs, StringPiece* rhs, AssignOp* op) {
@@ -586,6 +586,6 @@ void ParseAssignStatement(StringPiece line, size_t sep,
*rhs = TrimSpace(line.substr(sep + 1));
}
-const vector<ParseErrorAST*>& GetParseErrors() {
+const vector<ParseErrorStmt*>& GetParseErrors() {
return Parser::parse_errors;
}
diff --git a/parser.h b/parser.h
index 857219d..95b7241 100644
--- a/parser.h
+++ b/parser.h
@@ -17,8 +17,8 @@
#include <vector>
-#include "ast.h"
#include "loc.h"
+#include "stmt.h"
#include "string_piece.h"
using namespace std;
@@ -26,9 +26,9 @@ using namespace std;
class Makefile;
void Parse(Makefile* mk);
-void Parse(StringPiece buf, const Loc& loc, vector<AST*>* out_asts);
+void Parse(StringPiece buf, const Loc& loc, vector<Stmt*>* out_asts);
void ParseNotAfterRule(StringPiece buf, const Loc& loc,
- vector<AST*>* out_asts);
+ vector<Stmt*>* out_asts);
void ParseAssignStatement(StringPiece line, size_t sep,
StringPiece* lhs, StringPiece* rhs, AssignOp* op);
@@ -36,6 +36,6 @@ void ParseAssignStatement(StringPiece line, size_t sep,
void InitParser();
void QuitParser();
-const vector<ParseErrorAST*>& GetParseErrors();
+const vector<ParseErrorStmt*>& GetParseErrors();
#endif // PARSER_H_
diff --git a/rule.cc b/rule.cc
index 175b43a..a77366a 100644
--- a/rule.cc
+++ b/rule.cc
@@ -16,12 +16,12 @@
#include "rule.h"
+#include "expr.h"
#include "log.h"
#include "parser.h"
#include "stringprintf.h"
#include "strutil.h"
#include "symtab.h"
-#include "value.h"
namespace {
diff --git a/rule.h b/rule.h
index c6fd72c..2a67368 100644
--- a/rule.h
+++ b/rule.h
@@ -17,9 +17,9 @@
#include <vector>
-#include "ast.h"
#include "loc.h"
#include "log.h"
+#include "stmt.h"
#include "string_piece.h"
#include "symtab.h"
diff --git a/ast.cc b/stmt.cc
index 50f2a6b..1abab32 100644
--- a/ast.cc
+++ b/stmt.cc
@@ -14,26 +14,26 @@
// +build ignore
-#include "ast.h"
+#include "stmt.h"
#include "eval.h"
+#include "expr.h"
#include "stringprintf.h"
#include "strutil.h"
-#include "value.h"
-AST::AST() {}
+Stmt::Stmt() {}
-AST::~AST() {}
+Stmt::~Stmt() {}
-string RuleAST::DebugString() const {
- return StringPrintf("RuleAST(expr=%s term=%d after_term=%s loc=%s:%d)",
+string RuleStmt::DebugString() const {
+ return StringPrintf("RuleStmt(expr=%s term=%d after_term=%s loc=%s:%d)",
expr->DebugString().c_str(),
term,
after_term->DebugString().c_str(),
LOCF(loc()));
}
-string AssignAST::DebugString() const {
+string AssignStmt::DebugString() const {
const char* opstr = "???";
switch (op) {
case AssignOp::EQ: opstr = "EQ"; break;
@@ -47,7 +47,7 @@ string AssignAST::DebugString() const {
case AssignDirective::OVERRIDE: dirstr = "override"; break;
case AssignDirective::EXPORT: dirstr = "export"; break;
}
- return StringPrintf("AssignAST(lhs=%s rhs=%s (%s) "
+ return StringPrintf("AssignStmt(lhs=%s rhs=%s (%s) "
"opstr=%s dir=%s loc=%s:%d)",
lhs->DebugString().c_str(),
rhs->DebugString().c_str(),
@@ -55,12 +55,12 @@ string AssignAST::DebugString() const {
opstr, dirstr, LOCF(loc()));
}
-string CommandAST::DebugString() const {
- return StringPrintf("CommandAST(%s, loc=%s:%d)",
+string CommandStmt::DebugString() const {
+ return StringPrintf("CommandStmt(%s, loc=%s:%d)",
expr->DebugString().c_str(), LOCF(loc()));
}
-string IfAST::DebugString() const {
+string IfStmt::DebugString() const {
const char* opstr = "???";
switch (op) {
case CondOp::IFEQ: opstr = "ifeq"; break;
@@ -68,88 +68,88 @@ string IfAST::DebugString() const {
case CondOp::IFDEF: opstr = "ifdef"; break;
case CondOp::IFNDEF: opstr = "ifndef"; break;
}
- return StringPrintf("IfAST(op=%s, lhs=%s, rhs=%s t=%zu f=%zu loc=%s:%d)",
+ return StringPrintf("IfStmt(op=%s, lhs=%s, rhs=%s t=%zu f=%zu loc=%s:%d)",
opstr,
lhs->DebugString().c_str(),
rhs->DebugString().c_str(),
- true_asts.size(),
- false_asts.size(),
+ true_stmts.size(),
+ false_stmts.size(),
LOCF(loc()));
}
-string IncludeAST::DebugString() const {
- return StringPrintf("IncludeAST(%s, loc=%s:%d)",
+string IncludeStmt::DebugString() const {
+ return StringPrintf("IncludeStmt(%s, loc=%s:%d)",
expr->DebugString().c_str(), LOCF(loc()));
}
-string ExportAST::DebugString() const {
- return StringPrintf("ExportAST(%s, %d, loc=%s:%d)",
+string ExportStmt::DebugString() const {
+ return StringPrintf("ExportStmt(%s, %d, loc=%s:%d)",
expr->DebugString().c_str(),
is_export,
LOCF(loc()));
}
-string ParseErrorAST::DebugString() const {
- return StringPrintf("ParseErrorAST(%s, loc=%s:%d)",
+string ParseErrorStmt::DebugString() const {
+ return StringPrintf("ParseErrorStmt(%s, loc=%s:%d)",
msg.c_str(),
LOCF(loc()));
}
-RuleAST::~RuleAST() {
+RuleStmt::~RuleStmt() {
delete expr;
delete after_term;
}
-void RuleAST::Eval(Evaluator* ev) const {
+void RuleStmt::Eval(Evaluator* ev) const {
ev->EvalRule(this);
}
-AssignAST::~AssignAST() {
+AssignStmt::~AssignStmt() {
delete lhs;
delete rhs;
}
-void AssignAST::Eval(Evaluator* ev) const {
+void AssignStmt::Eval(Evaluator* ev) const {
ev->EvalAssign(this);
}
-CommandAST::~CommandAST() {
+CommandStmt::~CommandStmt() {
delete expr;
}
-void CommandAST::Eval(Evaluator* ev) const {
+void CommandStmt::Eval(Evaluator* ev) const {
ev->EvalCommand(this);
}
-IfAST::~IfAST() {
+IfStmt::~IfStmt() {
delete lhs;
delete rhs;
}
-void IfAST::Eval(Evaluator* ev) const {
+void IfStmt::Eval(Evaluator* ev) const {
ev->EvalIf(this);
}
-IncludeAST::~IncludeAST() {
+IncludeStmt::~IncludeStmt() {
delete expr;
}
-void IncludeAST::Eval(Evaluator* ev) const {
+void IncludeStmt::Eval(Evaluator* ev) const {
ev->EvalInclude(this);
}
-ExportAST::~ExportAST() {
+ExportStmt::~ExportStmt() {
delete expr;
}
-void ExportAST::Eval(Evaluator* ev) const {
+void ExportStmt::Eval(Evaluator* ev) const {
ev->EvalExport(this);
}
-ParseErrorAST::~ParseErrorAST() {
+ParseErrorStmt::~ParseErrorStmt() {
}
-void ParseErrorAST::Eval(Evaluator* ev) const {
+void ParseErrorStmt::Eval(Evaluator* ev) const {
ev->set_loc(loc());
ev->Error(msg);
}
diff --git a/ast.h b/stmt.h
index 0289853..4d4c5eb 100644
--- a/ast.h
+++ b/stmt.h
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#ifndef AST_H_
-#define AST_H_
+#ifndef STMT_H_
+#define STMT_H_
#include <string>
#include <vector>
@@ -46,9 +46,9 @@ enum struct CondOp {
IFNDEF,
};
-struct AST {
+struct Stmt {
public:
- virtual ~AST();
+ virtual ~Stmt();
Loc loc() const { return loc_; }
void set_loc(Loc loc) { loc_ = loc; }
@@ -59,94 +59,94 @@ struct AST {
virtual string DebugString() const = 0;
protected:
- AST();
+ Stmt();
private:
Loc loc_;
StringPiece orig_;
};
-struct RuleAST : public AST {
+struct RuleStmt : public Stmt {
Value* expr;
char term;
Value* after_term;
- virtual ~RuleAST();
+ virtual ~RuleStmt();
virtual void Eval(Evaluator* ev) const;
virtual string DebugString() const;
};
-struct AssignAST : public AST {
+struct AssignStmt : public Stmt {
Value* lhs;
Value* rhs;
StringPiece orig_rhs;
AssignOp op;
AssignDirective directive;
- virtual ~AssignAST();
+ virtual ~AssignStmt();
virtual void Eval(Evaluator* ev) const;
virtual string DebugString() const;
};
-struct CommandAST : public AST {
+struct CommandStmt : public Stmt {
Value* expr;
StringPiece orig;
- virtual ~CommandAST();
+ virtual ~CommandStmt();
virtual void Eval(Evaluator* ev) const;
virtual string DebugString() const;
};
-struct IfAST : public AST {
+struct IfStmt : public Stmt {
CondOp op;
Value* lhs;
Value* rhs;
- vector<AST*> true_asts;
- vector<AST*> false_asts;
+ vector<Stmt*> true_stmts;
+ vector<Stmt*> false_stmts;
- virtual ~IfAST();
+ virtual ~IfStmt();
virtual void Eval(Evaluator* ev) const;
virtual string DebugString() const;
};
-struct IncludeAST : public AST {
+struct IncludeStmt : public Stmt {
Value* expr;
bool should_exist;
- virtual ~IncludeAST();
+ virtual ~IncludeStmt();
virtual void Eval(Evaluator* ev) const;
virtual string DebugString() const;
};
-struct ExportAST : public AST {
+struct ExportStmt : public Stmt {
Value* expr;
bool is_export;
- virtual ~ExportAST();
+ virtual ~ExportStmt();
virtual void Eval(Evaluator* ev) const;
virtual string DebugString() const;
};
-struct ParseErrorAST : public AST {
+struct ParseErrorStmt : public Stmt {
string msg;
- virtual ~ParseErrorAST();
+ virtual ~ParseErrorStmt();
virtual void Eval(Evaluator* ev) const;
virtual string DebugString() const;
};
-#endif // AST_H_
+#endif // STMT_H_
diff --git a/var.cc b/var.cc
index 8ee7588..d21dc4f 100644
--- a/var.cc
+++ b/var.cc
@@ -16,8 +16,8 @@
#include "var.h"
+#include "expr.h"
#include "log.h"
-#include "value.h"
UndefinedVar kUndefinedBuf;
UndefinedVar* kUndefined = &kUndefinedBuf;
diff --git a/var.h b/var.h
index e2eddc7..3bae262 100644
--- a/var.h
+++ b/var.h
@@ -19,10 +19,10 @@
#include <unordered_map>
#include <unordered_set>
-#include "ast.h"
+#include "expr.h"
+#include "stmt.h"
#include "string_piece.h"
#include "symtab.h"
-#include "value.h"
using namespace std;