mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 05:56:15 +02:00
* Canonicalise ASTs in `nix-instantiate --eval': remove position
info, sort attribute sets.
This commit is contained in:
parent
05879db628
commit
f23dcdd603
7 changed files with 49 additions and 5 deletions
|
@ -287,6 +287,45 @@ void checkVarDefs(const ATermMap & defs, Expr e)
|
|||
}
|
||||
|
||||
|
||||
struct Canonicalise : TermFun
|
||||
{
|
||||
ATerm operator () (ATerm e)
|
||||
{
|
||||
/* Remove position info. */
|
||||
ATerm path;
|
||||
int line, column;
|
||||
if (matchPos(e, path, line, column))
|
||||
return makeNoPos();
|
||||
|
||||
/* Sort attribute sets. */
|
||||
ATermList _;
|
||||
if (matchAttrs(e, _)) {
|
||||
ATermMap attrs;
|
||||
queryAllAttrs(e, attrs);
|
||||
StringSet names;
|
||||
for (ATermMap::const_iterator i = attrs.begin(); i != attrs.end(); ++i)
|
||||
names.insert(aterm2String(i->key));
|
||||
|
||||
ATermList attrs2 = ATempty;
|
||||
for (StringSet::reverse_iterator i = names.rbegin(); i != names.rend(); ++i)
|
||||
attrs2 = ATinsert(attrs2,
|
||||
makeBind(toATerm(*i), attrs.get(toATerm(*i)), makeNoPos()));
|
||||
|
||||
return makeAttrs(attrs2);
|
||||
}
|
||||
|
||||
return e;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Expr canonicaliseExpr(Expr & e)
|
||||
{
|
||||
Canonicalise canonicalise;
|
||||
return bottomupRewrite(canonicalise, e);
|
||||
}
|
||||
|
||||
|
||||
Expr makeBool(bool b)
|
||||
{
|
||||
return b ? eTrue : eFalse;
|
||||
|
|
|
@ -94,6 +94,11 @@ Expr substitute(const Substitution & subs, Expr e);
|
|||
void checkVarDefs(const ATermMap & def, Expr e);
|
||||
|
||||
|
||||
/* Canonicalise a Nix expression by sorting attributes and removing
|
||||
location information. */
|
||||
Expr canonicaliseExpr(Expr & e);
|
||||
|
||||
|
||||
/* Create an expression representing a boolean. */
|
||||
Expr makeBool(bool b);
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ static void printResult(EvalState & state, Expr e,
|
|||
if (xmlOutput)
|
||||
printTermAsXML(e, std::cout, context);
|
||||
else
|
||||
std::cout << format("%1%\n") % e;
|
||||
std::cout << format("%1%\n") % canonicaliseExpr(e);
|
||||
|
||||
else {
|
||||
DrvInfos drvs;
|
||||
|
|
|
@ -1 +1 @@
|
|||
Function([Formal("x",UnrestrictedValues,NoDefaultValue),Formal("y",UnrestrictedValues,NoDefaultValue),Formal("z",UnrestrictedValues,NoDefaultValue)],OpPlus(OpPlus(Var("x"),Var("y")),Var("z")),Pos("(string)",1,2))
|
||||
Function([Formal("x",UnrestrictedValues,NoDefaultValue),Formal("y",UnrestrictedValues,NoDefaultValue),Formal("z",UnrestrictedValues,NoDefaultValue)],OpPlus(OpPlus(Var("x"),Var("y")),Var("z")),NoPos)
|
||||
|
|
|
@ -1 +1 @@
|
|||
Rec([Bind("x",Var("y"),Pos("(string)",6,4)),Bind("y",Int(123),Pos("(string)",10,4)),Bind("foo",Str("multi\nline\n string\n test\r",[]),Pos("(string)",14,6)),Bind("z",Int(456),Pos("(string)",19,4))],[])
|
||||
Rec([Bind("x",Var("y"),NoPos),Bind("y",Int(123),NoPos),Bind("foo",Str("multi\nline\n string\n test\r",[]),NoPos),Bind("z",Int(456),NoPos)],[])
|
||||
|
|
|
@ -1 +1 @@
|
|||
Function([Formal("stdenv",UnrestrictedValues,NoDefaultValue),Formal("fetchurl",UnrestrictedValues,NoDefaultValue)],Call(Select(Var("stdenv"),"mkDerivation"),Attrs([Bind("name",Str("libXi-6.0.1",[]),Pos("(string)",4,7)),Bind("src",Call(Var("fetchurl"),Attrs([Bind("url",Str("http://freedesktop.org/~xlibs/release/libXi-6.0.1.tar.bz2",[]),Pos("(string)",6,8)),Bind("md5",Str("7e935a42428d63a387b3c048be0f2756",[]),Pos("(string)",7,8))])),Pos("(string)",5,6))])),Pos("(string)",1,2))
|
||||
Function([Formal("stdenv",UnrestrictedValues,NoDefaultValue),Formal("fetchurl",UnrestrictedValues,NoDefaultValue)],Call(Select(Var("stdenv"),"mkDerivation"),Attrs([Bind("name",Str("libXi-6.0.1",[]),NoPos),Bind("src",Call(Var("fetchurl"),Attrs([Bind("md5",Str("7e935a42428d63a387b3c048be0f2756",[]),NoPos),Bind("url",Str("http://freedesktop.org/~xlibs/release/libXi-6.0.1.tar.bz2",[]),NoPos)])),NoPos)])),NoPos)
|
||||
|
|
|
@ -1 +1 @@
|
|||
Function([Formal("localServer",UnrestrictedValues,DefaultValue(Var("false"))),Formal("httpServer",UnrestrictedValues,DefaultValue(Var("false"))),Formal("sslSupport",UnrestrictedValues,DefaultValue(Var("false"))),Formal("pythonBindings",UnrestrictedValues,DefaultValue(Var("false"))),Formal("javaSwigBindings",UnrestrictedValues,DefaultValue(Var("false"))),Formal("javahlBindings",UnrestrictedValues,DefaultValue(Var("false"))),Formal("stdenv",UnrestrictedValues,NoDefaultValue),Formal("fetchurl",UnrestrictedValues,NoDefaultValue),Formal("openssl",UnrestrictedValues,DefaultValue(Var("null"))),Formal("httpd",UnrestrictedValues,DefaultValue(Var("null"))),Formal("db4",UnrestrictedValues,DefaultValue(Var("null"))),Formal("expat",UnrestrictedValues,NoDefaultValue),Formal("swig",UnrestrictedValues,DefaultValue(Var("null"))),Formal("j2sdk",UnrestrictedValues,DefaultValue(Var("null")))],Assert(OpNEq(Var("expat"),Var("null")),Assert(OpImpl(Var("localServer"),OpNEq(Var("db4"),Var("null"))),Assert(OpImpl(Var("httpServer"),OpAnd(OpNEq(Var("httpd"),Var("null")),OpEq(Select(Var("httpd"),"expat"),Var("expat")))),Assert(OpImpl(Var("sslSupport"),OpAnd(OpNEq(Var("openssl"),Var("null")),OpImpl(Var("httpServer"),OpEq(Select(Var("httpd"),"openssl"),Var("openssl"))))),Assert(OpImpl(Var("pythonBindings"),OpAnd(OpNEq(Var("swig"),Var("null")),Select(Var("swig"),"pythonSupport"))),Assert(OpImpl(Var("javaSwigBindings"),OpAnd(OpNEq(Var("swig"),Var("null")),Select(Var("swig"),"javaSupport"))),Assert(OpImpl(Var("javahlBindings"),OpNEq(Var("j2sdk"),Var("null"))),Call(Select(Var("stdenv"),"mkDerivation"),Attrs([Bind("name",Str("subversion-1.1.1",[]),Pos("(string)",20,7)),Bind("builder",Path("/foo/bar"),Pos("(string)",22,10)),Bind("src",Call(Var("fetchurl"),Attrs([Bind("url",Str("http://subversion.tigris.org/tarballs/subversion-1.1.1.tar.bz2",[]),Pos("(string)",24,8)),Bind("md5",Str("a180c3fe91680389c210c99def54d9e0",[]),Pos("(string)",25,8))])),Pos("(string)",23,6)),Bind("patches",If(Var("javahlBindings"),List([Path("/javahl.patch")]),List([])),Pos("(string)",31,10)),Bind("openssl",If(Var("sslSupport"),Var("openssl"),Var("null")),Pos("(string)",33,10)),Bind("httpd",If(Var("httpServer"),Var("httpd"),Var("null")),Pos("(string)",34,8)),Bind("db4",If(Var("localServer"),Var("db4"),Var("null")),Pos("(string)",35,6)),Bind("swig",If(OpOr(Var("pythonBindings"),Var("javaSwigBindings")),Var("swig"),Var("null")),Pos("(string)",36,7)),Bind("python",If(Var("pythonBindings"),Select(Var("swig"),"python"),Var("null")),Pos("(string)",37,9)),Bind("j2sdk",If(Var("javaSwigBindings"),Select(Var("swig"),"j2sdk"),If(Var("javahlBindings"),Var("j2sdk"),Var("null"))),Pos("(string)",38,8)),Bind("expat",Var("expat"),Pos("(string)",41,10)),Bind("localServer",Var("localServer"),Pos("(string)",41,10)),Bind("httpServer",Var("httpServer"),Pos("(string)",41,10)),Bind("sslSupport",Var("sslSupport"),Pos("(string)",41,10)),Bind("pythonBindings",Var("pythonBindings"),Pos("(string)",41,10)),Bind("javaSwigBindings",Var("javaSwigBindings"),Pos("(string)",41,10)),Bind("javahlBindings",Var("javahlBindings"),Pos("(string)",41,10))])),Pos("(string)",17,7)),Pos("(string)",16,7)),Pos("(string)",15,7)),Pos("(string)",14,7)),Pos("(string)",13,7)),Pos("(string)",12,7)),Pos("(string)",11,7)),Pos("(string)",1,2))
|
||||
Function([Formal("localServer",UnrestrictedValues,DefaultValue(Var("false"))),Formal("httpServer",UnrestrictedValues,DefaultValue(Var("false"))),Formal("sslSupport",UnrestrictedValues,DefaultValue(Var("false"))),Formal("pythonBindings",UnrestrictedValues,DefaultValue(Var("false"))),Formal("javaSwigBindings",UnrestrictedValues,DefaultValue(Var("false"))),Formal("javahlBindings",UnrestrictedValues,DefaultValue(Var("false"))),Formal("stdenv",UnrestrictedValues,NoDefaultValue),Formal("fetchurl",UnrestrictedValues,NoDefaultValue),Formal("openssl",UnrestrictedValues,DefaultValue(Var("null"))),Formal("httpd",UnrestrictedValues,DefaultValue(Var("null"))),Formal("db4",UnrestrictedValues,DefaultValue(Var("null"))),Formal("expat",UnrestrictedValues,NoDefaultValue),Formal("swig",UnrestrictedValues,DefaultValue(Var("null"))),Formal("j2sdk",UnrestrictedValues,DefaultValue(Var("null")))],Assert(OpNEq(Var("expat"),Var("null")),Assert(OpImpl(Var("localServer"),OpNEq(Var("db4"),Var("null"))),Assert(OpImpl(Var("httpServer"),OpAnd(OpNEq(Var("httpd"),Var("null")),OpEq(Select(Var("httpd"),"expat"),Var("expat")))),Assert(OpImpl(Var("sslSupport"),OpAnd(OpNEq(Var("openssl"),Var("null")),OpImpl(Var("httpServer"),OpEq(Select(Var("httpd"),"openssl"),Var("openssl"))))),Assert(OpImpl(Var("pythonBindings"),OpAnd(OpNEq(Var("swig"),Var("null")),Select(Var("swig"),"pythonSupport"))),Assert(OpImpl(Var("javaSwigBindings"),OpAnd(OpNEq(Var("swig"),Var("null")),Select(Var("swig"),"javaSupport"))),Assert(OpImpl(Var("javahlBindings"),OpNEq(Var("j2sdk"),Var("null"))),Call(Select(Var("stdenv"),"mkDerivation"),Attrs([Bind("builder",Path("/foo/bar"),NoPos),Bind("db4",If(Var("localServer"),Var("db4"),Var("null")),NoPos),Bind("expat",Var("expat"),NoPos),Bind("httpServer",Var("httpServer"),NoPos),Bind("httpd",If(Var("httpServer"),Var("httpd"),Var("null")),NoPos),Bind("j2sdk",If(Var("javaSwigBindings"),Select(Var("swig"),"j2sdk"),If(Var("javahlBindings"),Var("j2sdk"),Var("null"))),NoPos),Bind("javaSwigBindings",Var("javaSwigBindings"),NoPos),Bind("javahlBindings",Var("javahlBindings"),NoPos),Bind("localServer",Var("localServer"),NoPos),Bind("name",Str("subversion-1.1.1",[]),NoPos),Bind("openssl",If(Var("sslSupport"),Var("openssl"),Var("null")),NoPos),Bind("patches",If(Var("javahlBindings"),List([Path("/javahl.patch")]),List([])),NoPos),Bind("python",If(Var("pythonBindings"),Select(Var("swig"),"python"),Var("null")),NoPos),Bind("pythonBindings",Var("pythonBindings"),NoPos),Bind("src",Call(Var("fetchurl"),Attrs([Bind("md5",Str("a180c3fe91680389c210c99def54d9e0",[]),NoPos),Bind("url",Str("http://subversion.tigris.org/tarballs/subversion-1.1.1.tar.bz2",[]),NoPos)])),NoPos),Bind("sslSupport",Var("sslSupport"),NoPos),Bind("swig",If(OpOr(Var("pythonBindings"),Var("javaSwigBindings")),Var("swig"),Var("null")),NoPos)])),NoPos),NoPos),NoPos),NoPos),NoPos),NoPos),NoPos),NoPos)
|
||||
|
|
Loading…
Reference in a new issue