diff options
-rw-r--r-- | ast.cc | 13 | ||||
-rw-r--r-- | eval.cc | 2 | ||||
-rw-r--r-- | func.cc | 2 | ||||
-rw-r--r-- | loc.h | 2 | ||||
-rw-r--r-- | parser.cc | 7 |
5 files changed, 14 insertions, 12 deletions
@@ -9,10 +9,11 @@ AST::AST() {} AST::~AST() {} string RuleAST::DebugString() const { - return StringPrintf("RuleAST(expr=%s term=%d after_term=%s)", + return StringPrintf("RuleAST(expr=%s term=%d after_term=%s loc=%s:%d)", expr->DebugString().c_str(), term, - after_term->DebugString().c_str()); + after_term->DebugString().c_str(), + LOCF(loc())); } string AssignAST::DebugString() const { @@ -29,15 +30,15 @@ string AssignAST::DebugString() const { case AssignDirective::OVERRIDE: dirstr = "override"; break; case AssignDirective::EXPORT: dirstr = "export"; break; } - return StringPrintf("AssignAST(lhs=%s rhs=%s opstr=%s dir=%s)", + return StringPrintf("AssignAST(lhs=%s rhs=%s opstr=%s dir=%s loc=%s:%d)", lhs->DebugString().c_str(), rhs->DebugString().c_str(), - opstr, dirstr); + opstr, dirstr, LOCF(loc())); } string CommandAST::DebugString() const { - return StringPrintf("CommandAST(%s)", - expr->DebugString().c_str()); + return StringPrintf("CommandAST(%s, loc=%s:%d)", + expr->DebugString().c_str(), LOCF(loc())); } RuleAST::~RuleAST() { @@ -131,5 +131,5 @@ EvalResult* Evaluator::GetEvalResult() { } void Evaluator::Error(const string& msg) { - ERROR("%s:%d: %s", loc_.filename, loc_.lineno, msg.c_str()); + ERROR("%s:%d: %s", LOCF(loc_), msg.c_str()); } @@ -18,7 +18,7 @@ void BuiltinInfoFunc(const vector<Value*>& args, Evaluator* ev, string*) { void BuiltinWarningFunc(const vector<Value*>& args, Evaluator* ev, string*) { shared_ptr<string> a = args[0]->Eval(ev); - printf("%s:%d: %s\n", ev->loc().filename, ev->loc().lineno, a->c_str()); + printf("%s:%d: %s\n", LOCF(ev->loc()), a->c_str()); fflush(stdout); } @@ -16,4 +16,6 @@ struct Loc { int lineno; }; +#define LOCF(x) (x).filename, (x).lineno + #endif // LOC_H_ @@ -30,23 +30,22 @@ class Parser { l_ = 0; for (l_ = 0; l_ < buf_.size();) { - if (!fixed_lineno_) - ++loc_.lineno; size_t lf_cnt = 0; size_t e = FindEndOfLine(&lf_cnt); + if (!fixed_lineno_) + loc_.lineno += lf_cnt; StringPiece line(buf_.data() + l_, e - l_); ParseLine(line); if (e == buf_.size()) break; l_ = e + 1; - loc_.lineno += lf_cnt; } } private: void Error(const string& msg) { - ERROR("%s:%d: %s", loc_.filename, loc_.lineno, msg.c_str()); + ERROR("%s:%d: %s", LOCF(loc_), msg.c_str()); } size_t FindEndOfLine(size_t* lf_cnt) { |