aboutsummaryrefslogtreecommitdiffstats
path: root/expr.cc
diff options
context:
space:
mode:
authorDan Willemsen <dwillemsen@google.com>2017-10-11 22:17:48 -0700
committerDan Willemsen <dwillemsen@google.com>2017-10-11 22:20:49 -0700
commit3ce083f01d6e62e9fb9b328e312d97a074fe6128 (patch)
treec7f3d604ed57e0afb6eb591c1e531fd5373b2036 /expr.cc
parentbf6a27c3d31d1f0143e62461058a6d81b2242fbe (diff)
downloadandroid_build_kati-3ce083f01d6e62e9fb9b328e312d97a074fe6128.tar.gz
android_build_kati-3ce083f01d6e62e9fb9b328e312d97a074fe6128.tar.bz2
android_build_kati-3ce083f01d6e62e9fb9b328e312d97a074fe6128.zip
`clang-format -i -style=file *.cc *.h`
Change-Id: I62a87c5d8309b21265e904c0aeb9b3e094c9024a
Diffstat (limited to 'expr.cc')
-rw-r--r--expr.cc124
1 files changed, 53 insertions, 71 deletions
diff --git a/expr.cc b/expr.cc
index 641bf5a..f0afb7b 100644
--- a/expr.cc
+++ b/expr.cc
@@ -25,11 +25,9 @@
#include "strutil.h"
#include "var.h"
-Evaluable::Evaluable() {
-}
+Evaluable::Evaluable() {}
-Evaluable::~Evaluable() {
-}
+Evaluable::~Evaluable() {}
string Evaluable::Eval(Evaluator* ev) const {
string s;
@@ -37,11 +35,9 @@ string Evaluable::Eval(Evaluator* ev) const {
return s;
}
-Value::Value() {
-}
+Value::Value() {}
-Value::~Value() {
-}
+Value::~Value() {}
string Value::DebugString() const {
if (static_cast<const Value*>(this)) {
@@ -52,9 +48,7 @@ string Value::DebugString() const {
class Literal : public Value {
public:
- explicit Literal(StringPiece s)
- : s_(s) {
- }
+ explicit Literal(StringPiece s) : s_(s) {}
StringPiece val() const { return s_; }
@@ -65,9 +59,7 @@ class Literal : public Value {
virtual bool IsLiteral() const override { return true; }
virtual StringPiece GetLiteralValueUnsafe() const override { return s_; }
- virtual string DebugString_() const override {
- return s_.as_string();
- }
+ virtual string DebugString_() const override { return s_.as_string(); }
private:
StringPiece s_;
@@ -75,8 +67,7 @@ class Literal : public Value {
class Expr : public Value {
public:
- Expr() {
- }
+ Expr() {}
virtual ~Expr() {
for (Value* v : vals_) {
@@ -85,9 +76,7 @@ class Expr : public Value {
}
// Takes the ownership of |v|.
- void AddValue(Value* v) {
- vals_.push_back(v);
- }
+ void AddValue(Value* v) { vals_.push_back(v); }
virtual void Eval(Evaluator* ev, string* s) const override {
for (Value* v : vals_) {
@@ -126,11 +115,8 @@ class Expr : public Value {
class SymRef : public Value {
public:
- explicit SymRef(Symbol n)
- : name_(n) {
- }
- virtual ~SymRef() {
- }
+ explicit SymRef(Symbol n) : name_(n) {}
+ virtual ~SymRef() {}
virtual void Eval(Evaluator* ev, string* s) const override {
Var* v = ev->LookupVar(name_);
@@ -148,12 +134,8 @@ class SymRef : public Value {
class VarRef : public Value {
public:
- explicit VarRef(Value* n)
- : name_(n) {
- }
- virtual ~VarRef() {
- delete name_;
- }
+ explicit VarRef(Value* n) : name_(n) {}
+ virtual ~VarRef() { delete name_; }
virtual void Eval(Evaluator* ev, string* s) const override {
ev->IncrementEvalDepth();
@@ -176,8 +158,7 @@ class VarRef : public Value {
class VarSubst : public Value {
public:
explicit VarSubst(Value* n, Value* p, Value* s)
- : name_(n), pat_(p), subst_(s) {
- }
+ : name_(n), pat_(p), subst_(s) {}
virtual ~VarSubst() {
delete name_;
delete pat_;
@@ -203,8 +184,7 @@ class VarSubst : public Value {
}
virtual string DebugString_() const override {
- return StringPrintf("VarSubst(%s:%s=%s)",
- name_->DebugString().c_str(),
+ return StringPrintf("VarSubst(%s:%s=%s)", name_->DebugString().c_str(),
pat_->DebugString().c_str(),
subst_->DebugString().c_str());
}
@@ -217,9 +197,7 @@ class VarSubst : public Value {
class Func : public Value {
public:
- explicit Func(FuncInfo* fi)
- : fi_(fi) {
- }
+ explicit Func(FuncInfo* fi) : fi_(fi) {}
~Func() {
for (Value* a : args_)
@@ -234,14 +212,11 @@ class Func : public Value {
}
virtual string DebugString_() const override {
- return StringPrintf("Func(%s %s)",
- fi_->name,
+ return StringPrintf("Func(%s %s)", fi_->name,
JoinValues(args_, ",").c_str());
}
- void AddArg(Value* v) {
- args_.push_back(v);
- }
+ void AddArg(Value* v) { args_.push_back(v); }
const char* name() const { return fi_->name; }
int arity() const { return fi_->arity; }
@@ -285,7 +260,10 @@ bool ShouldHandleComments(ParseExprOpt opt) {
}
void ParseFunc(const Loc& loc,
- Func* f, StringPiece s, size_t i, char* terms,
+ Func* f,
+ StringPiece s,
+ size_t i,
+ char* terms,
size_t* index_out) {
terms[1] = ',';
terms[2] = '\0';
@@ -306,23 +284,24 @@ void ParseFunc(const Loc& loc,
if (isspace(s[i]))
continue;
if (s[i] == '\\') {
- char c = s.get(i+1);
+ char c = s.get(i + 1);
if (c == '\r' || c == '\n')
continue;
}
break;
}
}
- const bool trim_right_space = (f->trim_space() ||
- (nargs == 1 && f->trim_right_space_1st()));
+ const bool trim_right_space =
+ (f->trim_space() || (nargs == 1 && f->trim_right_space_1st()));
size_t n;
- Value* v = ParseExprImpl(loc, s.substr(i), terms, ParseExprOpt::FUNC,
- &n, trim_right_space);
+ Value* v = ParseExprImpl(loc, s.substr(i), terms, ParseExprOpt::FUNC, &n,
+ trim_right_space);
// TODO: concatLine???
f->AddArg(v);
i += n;
if (i == s.size()) {
- ERROR_LOC(loc, "*** unterminated call to function '%s': "
+ ERROR_LOC(loc,
+ "*** unterminated call to function '%s': "
"missing '%c'.",
f->name(), terms[0]);
}
@@ -337,7 +316,8 @@ void ParseFunc(const Loc& loc,
}
if (nargs <= f->min_arity()) {
- ERROR_LOC(loc, "*** insufficient number of arguments (%d) to function `%s'.",
+ ERROR_LOC(loc,
+ "*** insufficient number of arguments (%d) to function `%s'.",
nargs - 1, f->name());
}
@@ -359,8 +339,8 @@ Value* ParseDollar(const Loc& loc, StringPiece s, size_t* index_out) {
char terms[] = {cp, ':', ' ', 0};
for (size_t i = 2;;) {
size_t n;
- Value* vname = ParseExprImpl(loc, s.substr(i), terms,
- ParseExprOpt::NORMAL, &n);
+ Value* vname =
+ ParseExprImpl(loc, s.substr(i), terms, ParseExprOpt::NORMAL, &n);
i += n;
if (s[i] == cp) {
*index_out = i + 1;
@@ -388,7 +368,7 @@ Value* ParseDollar(const Loc& loc, StringPiece s, size_t* index_out) {
if (FuncInfo* fi = GetFuncInfo(lit->val())) {
delete lit;
Func* func = new Func(fi);
- ParseFunc(loc, func, s, i+1, terms, index_out);
+ ParseFunc(loc, func, s, i + 1, terms, index_out);
return func;
} else {
KATI_WARN_LOC(loc, "*warning*: unknown make function '%.*s': %.*s",
@@ -409,8 +389,8 @@ Value* ParseDollar(const Loc& loc, StringPiece s, size_t* index_out) {
terms[2] = '\0';
terms[1] = '=';
size_t n;
- Value* pat = ParseExprImpl(loc, s.substr(i+1), terms,
- ParseExprOpt::NORMAL, &n);
+ Value* pat =
+ ParseExprImpl(loc, s.substr(i + 1), terms, ParseExprOpt::NORMAL, &n);
i += 1 + n;
if (s[i] == cp) {
Expr* v = new Expr;
@@ -422,8 +402,8 @@ Value* ParseDollar(const Loc& loc, StringPiece s, size_t* index_out) {
}
terms[1] = '\0';
- Value* subst = ParseExprImpl(loc, s.substr(i+1), terms,
- ParseExprOpt::NORMAL, &n);
+ Value* subst =
+ ParseExprImpl(loc, s.substr(i + 1), terms, ParseExprOpt::NORMAL, &n);
i += 1 + n;
*index_out = i + 1;
return new VarSubst(vname->Compact(), pat, subst);
@@ -433,18 +413,20 @@ Value* ParseDollar(const Loc& loc, StringPiece s, size_t* index_out) {
// for detail.
size_t found = s.find(cp);
if (found != string::npos) {
- KATI_WARN_LOC(loc, "*warning*: unmatched parentheses: %.*s",
- SPF(s));
+ KATI_WARN_LOC(loc, "*warning*: unmatched parentheses: %.*s", SPF(s));
*index_out = s.size();
- return new SymRef(Intern(s.substr(2, found-2)));
+ return new SymRef(Intern(s.substr(2, found - 2)));
}
ERROR_LOC(loc, "*** unterminated variable reference.");
}
}
Value* ParseExprImpl(const Loc& loc,
- StringPiece s, const char* terms, ParseExprOpt opt,
- size_t* index_out, bool trim_right_space) {
+ StringPiece s,
+ const char* terms,
+ ParseExprOpt opt,
+ size_t* index_out,
+ bool trim_right_space) {
if (s.get(s.size() - 1) == '\r')
s.remove_suffix(1);
@@ -462,7 +444,7 @@ Value* ParseExprImpl(const Loc& loc,
// Handle a comment.
if (!terms && c == '#' && ShouldHandleComments(opt)) {
if (i > b)
- r->AddValue(new Literal(s.substr(b, i-b)));
+ r->AddValue(new Literal(s.substr(b, i - b)));
bool was_backslash = false;
for (; i < s.size() && !(s[i] == '\n' && !was_backslash); i++) {
was_backslash = !was_backslash && s[i] == '\\';
@@ -477,16 +459,16 @@ Value* ParseExprImpl(const Loc& loc,
}
if (i > b)
- r->AddValue(new Literal(s.substr(b, i-b)));
+ r->AddValue(new Literal(s.substr(b, i - b)));
- if (s[i+1] == '$') {
+ if (s[i + 1] == '$') {
r->AddValue(new Literal(StringPiece("$")));
i += 1;
b = i + 1;
continue;
}
- if (terms && strchr(terms, s[i+1])) {
+ if (terms && strchr(terms, s[i + 1])) {
*index_out = i + 1;
return r->Compact();
}
@@ -521,13 +503,13 @@ Value* ParseExprImpl(const Loc& loc,
}
if (c == '\\' && i + 1 < s.size() && opt != ParseExprOpt::COMMAND) {
- char n = s[i+1];
+ char n = s[i + 1];
if (n == '\\') {
i++;
continue;
}
if (n == '#' && ShouldHandleComments(opt)) {
- r->AddValue(new Literal(s.substr(b, i-b)));
+ r->AddValue(new Literal(s.substr(b, i - b)));
i++;
b = i;
continue;
@@ -537,7 +519,7 @@ Value* ParseExprImpl(const Loc& loc,
break;
}
if (i > b) {
- r->AddValue(new Literal(TrimRightSpace(s.substr(b, i-b))));
+ r->AddValue(new Literal(TrimRightSpace(s.substr(b, i - b))));
}
r->AddValue(new Literal(StringPiece(" ")));
// Skip the current escaped newline
@@ -546,7 +528,7 @@ Value* ParseExprImpl(const Loc& loc,
i++;
// Then continue skipping escaped newlines, spaces, and tabs
for (; i < s.size(); i++) {
- if (s[i] == '\\' && (s.get(i+1) == '\r' || s.get(i+1) == '\n')) {
+ if (s[i] == '\\' && (s.get(i + 1) == '\r' || s.get(i + 1) == '\n')) {
i++;
continue;
}
@@ -561,7 +543,7 @@ Value* ParseExprImpl(const Loc& loc,
}
if (i > b) {
- StringPiece rest = s.substr(b, i-b);
+ StringPiece rest = s.substr(b, i - b);
if (trim_right_space)
rest = TrimRightSpace(rest);
if (!rest.empty())