aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ast.cc13
-rw-r--r--eval.cc2
-rw-r--r--func.cc2
-rw-r--r--loc.h2
-rw-r--r--parser.cc7
5 files changed, 14 insertions, 12 deletions
diff --git a/ast.cc b/ast.cc
index fdd4588..b755ce9 100644
--- a/ast.cc
+++ b/ast.cc
@@ -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() {
diff --git a/eval.cc b/eval.cc
index 9060f36..b8d2fe6 100644
--- a/eval.cc
+++ b/eval.cc
@@ -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());
}
diff --git a/func.cc b/func.cc
index 621518d..047b36d 100644
--- a/func.cc
+++ b/func.cc
@@ -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);
}
diff --git a/loc.h b/loc.h
index 2884915..2d55c7d 100644
--- a/loc.h
+++ b/loc.h
@@ -16,4 +16,6 @@ struct Loc {
int lineno;
};
+#define LOCF(x) (x).filename, (x).lineno
+
#endif // LOC_H_
diff --git a/parser.cc b/parser.cc
index 526b8fe..8d872de 100644
--- a/parser.cc
+++ b/parser.cc
@@ -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) {