diff --git a/lix/libexpr/nixexpr.cc b/lix/libexpr/nixexpr.cc index 1f089a28a..d7844d6a7 100644 --- a/lix/libexpr/nixexpr.cc +++ b/lix/libexpr/nixexpr.cc @@ -21,11 +21,11 @@ std::ostream & operator <<(std::ostream & str, const SymbolStr & symbol) return printIdentifier(str, s); } -AttrName::AttrName(Symbol s) : symbol(s) +AttrName::AttrName(PosIdx pos, Symbol s) : pos(pos), symbol(s) { } -AttrName::AttrName(std::unique_ptr e) : expr(std::move(e)) +AttrName::AttrName(PosIdx pos, std::unique_ptr e) : pos(pos), expr(std::move(e)) { } diff --git a/lix/libexpr/nixexpr.hh b/lix/libexpr/nixexpr.hh index a29a5d9fd..6321a0803 100644 --- a/lix/libexpr/nixexpr.hh +++ b/lix/libexpr/nixexpr.hh @@ -28,10 +28,11 @@ struct StaticEnv; */ struct AttrName { + PosIdx pos; Symbol symbol; std::unique_ptr expr; - AttrName(Symbol s); - AttrName(std::unique_ptr e); + AttrName(PosIdx pos, Symbol s); + AttrName(PosIdx pos, std::unique_ptr e); }; typedef std::vector AttrPath; @@ -182,7 +183,7 @@ struct ExprSelect : Expr AttrPath attrPath; ExprSelect(const PosIdx & pos, std::unique_ptr e, AttrPath attrPath, std::unique_ptr def) : pos(pos), e(std::move(e)), def(std::move(def)), attrPath(std::move(attrPath)) { }; - ExprSelect(const PosIdx & pos, std::unique_ptr e, Symbol name) : pos(pos), e(std::move(e)) { attrPath.push_back(AttrName(name)); }; + ExprSelect(const PosIdx & pos, std::unique_ptr e, const PosIdx namePos, Symbol name) : pos(pos), e(std::move(e)) { attrPath.push_back(AttrName(namePos, name)); }; PosIdx getPos() const override { return pos; } COMMON_METHODS }; diff --git a/lix/libexpr/parser/parser-impl1.inc.cc b/lix/libexpr/parser/parser-impl1.inc.cc index d35024937..77b37b806 100644 --- a/lix/libexpr/parser/parser-impl1.inc.cc +++ b/lix/libexpr/parser/parser-impl1.inc.cc @@ -260,10 +260,10 @@ template<> struct BuildAST : change_head { struct AttrState : SubexprState { using SubexprState::SubexprState; - std::vector attrs; + AttrPath attrs; template - void pushAttr(T && attr, PosIdx) { attrs.emplace_back(std::forward(attr)); } + void pushAttr(T && attr, PosIdx pos) { attrs.emplace_back(pos, std::forward(attr)); } }; template<> struct BuildAST { @@ -311,12 +311,12 @@ struct BindingsStateLet : BindingsState { struct InheritState : SubexprState { using SubexprState::SubexprState; - std::vector> attrs; + std::vector attrs; std::unique_ptr from; PosIdx fromPos; template - void pushAttr(T && attr, PosIdx pos) { attrs.emplace_back(std::forward(attr), pos); } + void pushAttr(T && attr, PosIdx pos) { attrs.emplace_back(pos, std::forward(attr)); } }; template<> struct BuildAST { @@ -330,15 +330,15 @@ template<> struct BuildAST : change_head { static void success0(InheritState & s, BindingsState & b, State & ps) { auto & attrs = b.attrs.attrs; // TODO this should not reuse generic attrpath rules. - for (auto & [i, iPos] : s.attrs) { + for (auto & i : s.attrs) { if (i.symbol) continue; if (auto str = dynamic_cast(i.expr.get())) - i = AttrName(ps.symbols.create(str->s)); + i = AttrName(i.pos, ps.symbols.create(str->s)); else { throw ParseError({ .msg = HintFmt("dynamic attributes not allowed in inherit"), - .pos = ps.positions[iPos] + .pos = ps.positions[i.pos] }); } } @@ -347,9 +347,9 @@ template<> struct BuildAST : change_head { b.attrs.inheritFromExprs = std::make_unique>>(); auto fromExpr = ref(std::move(s.from)); b.attrs.inheritFromExprs->push_back(fromExpr); - for (auto & [i, iPos] : s.attrs) { + for (auto & i : s.attrs) { if (attrs.find(i.symbol) != attrs.end()) - ps.dupAttr(i.symbol, iPos, attrs[i.symbol].pos); + ps.dupAttr(i.symbol, i.pos, attrs[i.symbol].pos); auto inheritFrom = std::make_unique( s.fromPos, b.attrs.inheritFromExprs->size() - 1, @@ -358,19 +358,19 @@ template<> struct BuildAST : change_head { attrs.emplace( i.symbol, ExprAttrs::AttrDef( - std::make_unique(iPos, std::move(inheritFrom), i.symbol), - iPos, + std::make_unique(i.pos, std::move(inheritFrom), i.pos, i.symbol), + i.pos, ExprAttrs::AttrDef::Kind::InheritedFrom)); } } else { - for (auto & [i, iPos] : s.attrs) { + for (auto & i : s.attrs) { if (attrs.find(i.symbol) != attrs.end()) - ps.dupAttr(i.symbol, iPos, attrs[i.symbol].pos); + ps.dupAttr(i.symbol, i.pos, attrs[i.symbol].pos); attrs.emplace( i.symbol, ExprAttrs::AttrDef( - std::make_unique(iPos, i.symbol), - iPos, + std::make_unique(i.pos, i.symbol), + i.pos, ExprAttrs::AttrDef::Kind::Inherited)); } } @@ -693,7 +693,7 @@ template<> struct BuildAST : change_head(pos, pos, std::make_unique(std::move(b.set)), ps.s.body); + s.pushExpr(pos, pos, std::make_unique(std::move(b.set)), pos, ps.s.body); } };