mirror of
https://github.com/NixOS/nix.git
synced 2024-11-22 06:42:28 +00:00
use the same bindings print for ExprAttrs and ExprLet
this also has the effect of sorting let bindings lexicographically rather than by symbol creation order as was previously done, giving a better canonicalization in the process.
This commit is contained in:
parent
1f542adb3e
commit
6c08fba533
@ -70,10 +70,8 @@ void ExprOpHasAttr::show(const SymbolTable & symbols, std::ostream & str) const
|
|||||||
str << ") ? " << showAttrPath(symbols, attrPath) << ")";
|
str << ") ? " << showAttrPath(symbols, attrPath) << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExprAttrs::show(const SymbolTable & symbols, std::ostream & str) const
|
void ExprAttrs::showBindings(const SymbolTable & symbols, std::ostream & str) const
|
||||||
{
|
{
|
||||||
if (recursive) str << "rec ";
|
|
||||||
str << "{ ";
|
|
||||||
typedef const decltype(attrs)::value_type * Attr;
|
typedef const decltype(attrs)::value_type * Attr;
|
||||||
std::vector<Attr> sorted;
|
std::vector<Attr> sorted;
|
||||||
for (auto & i : attrs) sorted.push_back(&i);
|
for (auto & i : attrs) sorted.push_back(&i);
|
||||||
@ -97,6 +95,13 @@ void ExprAttrs::show(const SymbolTable & symbols, std::ostream & str) const
|
|||||||
i.valueExpr->show(symbols, str);
|
i.valueExpr->show(symbols, str);
|
||||||
str << "; ";
|
str << "; ";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExprAttrs::show(const SymbolTable & symbols, std::ostream & str) const
|
||||||
|
{
|
||||||
|
if (recursive) str << "rec ";
|
||||||
|
str << "{ ";
|
||||||
|
showBindings(symbols, str);
|
||||||
str << "}";
|
str << "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,15 +157,7 @@ void ExprCall::show(const SymbolTable & symbols, std::ostream & str) const
|
|||||||
void ExprLet::show(const SymbolTable & symbols, std::ostream & str) const
|
void ExprLet::show(const SymbolTable & symbols, std::ostream & str) const
|
||||||
{
|
{
|
||||||
str << "(let ";
|
str << "(let ";
|
||||||
for (auto & i : attrs->attrs)
|
attrs->showBindings(symbols, str);
|
||||||
if (i.second.inherited()) {
|
|
||||||
str << "inherit " << symbols[i.first] << "; ";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
str << symbols[i.first] << " = ";
|
|
||||||
i.second.e->show(symbols, str);
|
|
||||||
str << "; ";
|
|
||||||
}
|
|
||||||
str << "in ";
|
str << "in ";
|
||||||
body->show(symbols, str);
|
body->show(symbols, str);
|
||||||
str << ")";
|
str << ")";
|
||||||
|
@ -207,6 +207,8 @@ struct ExprAttrs : Expr
|
|||||||
ExprAttrs() : recursive(false) { };
|
ExprAttrs() : recursive(false) { };
|
||||||
PosIdx getPos() const override { return pos; }
|
PosIdx getPos() const override { return pos; }
|
||||||
COMMON_METHODS
|
COMMON_METHODS
|
||||||
|
|
||||||
|
void showBindings(const SymbolTable & symbols, std::ostream & str) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ExprList : Expr
|
struct ExprList : Expr
|
||||||
|
@ -1 +1 @@
|
|||||||
(let c = { }; b = 2; in { a = 1; inherit b ; d = (c).d; e = (c).e; f = 3; })
|
(let b = 2; c = { }; in { a = 1; inherit b ; d = (c).d; e = (c).e; f = 3; })
|
||||||
|
Loading…
Reference in New Issue
Block a user