diff options
author | Ben Burdette <bburdette@protonmail.com> | 2022-02-04 15:09:40 -0700 |
---|---|---|
committer | Ben Burdette <bburdette@protonmail.com> | 2022-02-04 15:09:40 -0700 |
commit | dbe3fd3735fa9aeb91720aa34dc447e5d925f3c4 (patch) | |
tree | a8b55d7fb2dbd70c10bbd521bc8458c9dbdd77c7 /src/libexpr/nixexpr.hh | |
parent | 3ddf864e1b2c5c27b2e6f7203e262c85bf760f7c (diff) | |
parent | bd383d1b6f91c4fe7ac21c52771e92027f649fa0 (diff) |
Merge branch 'master' into debug-step
Diffstat (limited to 'src/libexpr/nixexpr.hh')
-rw-r--r-- | src/libexpr/nixexpr.hh | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh index 8012c616e..64375b5ab 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/nixexpr.hh @@ -98,7 +98,7 @@ struct ExprInt : Expr { NixInt n; Value v; - ExprInt(NixInt n) : n(n) { mkInt(v, n); }; + ExprInt(NixInt n) : n(n) { v.mkInt(n); }; Value * maybeThunk(EvalState & state, Env & env); Pos* getPos() { return 0; } COMMON_METHODS @@ -108,7 +108,7 @@ struct ExprFloat : Expr { NixFloat nf; Value v; - ExprFloat(NixFloat nf) : nf(nf) { mkFloat(v, nf); }; + ExprFloat(NixFloat nf) : nf(nf) { v.mkFloat(nf); }; Value * maybeThunk(EvalState & state, Env & env); Pos* getPos() { return 0; } COMMON_METHODS @@ -116,22 +116,14 @@ struct ExprFloat : Expr struct ExprString : Expr { - Symbol s; + string s; Value v; - ExprString(const Symbol & s) : s(s) { mkString(v, s); }; + ExprString(std::string s) : s(std::move(s)) { v.mkString(this->s.data()); }; Value * maybeThunk(EvalState & state, Env & env); Pos* getPos() { return 0; } COMMON_METHODS }; -/* Temporary class used during parsing of indented strings. */ -struct ExprIndStr : Expr -{ - string s; - ExprIndStr(const string & s) : s(s) { }; - Pos* getPos() { return 0; } -}; - struct ExprPath : Expr { string s; @@ -237,10 +229,25 @@ struct Formal struct Formals { - typedef std::list<Formal> Formals_; + typedef std::vector<Formal> Formals_; Formals_ formals; - std::set<Symbol> argNames; // used during parsing bool ellipsis; + + bool has(Symbol arg) const { + auto it = std::lower_bound(formals.begin(), formals.end(), arg, + [] (const Formal & f, const Symbol & sym) { return f.name < sym; }); + return it != formals.end() && it->name == arg; + } + + std::vector<Formal> lexicographicOrder() const + { + std::vector<Formal> result(formals.begin(), formals.end()); + std::sort(result.begin(), result.end(), + [] (const Formal & a, const Formal & b) { + return std::string_view(a.name) < std::string_view(b.name); + }); + return result; + } }; struct ExprLambda : Expr @@ -253,11 +260,6 @@ struct ExprLambda : Expr ExprLambda(const Pos & pos, const Symbol & arg, Formals * formals, Expr * body) : pos(pos), arg(arg), formals(formals), body(body) { - if (!arg.empty() && formals && formals->argNames.find(arg) != formals->argNames.end()) - throw ParseError({ - .msg = hintfmt("duplicate formal function argument '%1%'", arg), - .errPos = pos - }); }; void setName(Symbol & name); string showNamePos() const; |