diff options
-rw-r--r-- | src/libexpr/eval.cc | 49 | ||||
-rw-r--r-- | src/libexpr/expr-to-xml.cc | 12 | ||||
-rw-r--r-- | src/libexpr/nixexpr-ast.def | 5 | ||||
-rw-r--r-- | src/libexpr/nixexpr.cc | 13 | ||||
-rw-r--r-- | src/libexpr/parser.y | 9 | ||||
-rw-r--r-- | tests/lang/eval-fail-bad-value.nix | 7 | ||||
-rw-r--r-- | tests/lang/eval-okay-good-value.exp | 1 | ||||
-rw-r--r-- | tests/lang/eval-okay-good-value.nix | 7 | ||||
-rw-r--r-- | tests/lang/eval-okay-xml.exp.xml | 15 | ||||
-rw-r--r-- | tests/lang/eval-okay-xml.nix | 2 | ||||
-rw-r--r-- | tests/lang/parse-okay-1.exp | 2 | ||||
-rw-r--r-- | tests/lang/parse-okay-regression-20041027.exp | 2 | ||||
-rw-r--r-- | tests/lang/parse-okay-subversion.exp | 2 |
13 files changed, 22 insertions, 104 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 6d8137d9b812..15cccc6b7f56 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -92,9 +92,8 @@ static Expr substArgs(EvalState & state, ATermList recAttrs = ATempty; for (ATermIterator i(formals); i; ++i) { Expr name, def; - ValidValues valids2; DefaultValue def2; - if (!matchFormal(*i, name, valids2, def2)) abort(); /* can't happen */ + if (!matchFormal(*i, name, def2)) abort(); /* can't happen */ Expr value = subs[name]; @@ -106,21 +105,6 @@ static Expr substArgs(EvalState & state, defsUsed.push_back(name); recAttrs = ATinsert(recAttrs, makeBind(name, def, makeNoPos())); } - - ATermList valids; - if (matchValidValues(valids2, valids)) { - value = evalExpr(state, value); - bool found = false; - for (ATermIterator j(valids); j; ++j) { - Expr v = evalExpr(state, *j); - if (value == v) { - found = true; - break; - } - } - if (!found) throw TypeError(format("the argument named `%1%' has an illegal value") - % aterm2String(name)); - } } /* Make a recursive attribute set out of the (argument-name, @@ -139,8 +123,8 @@ static Expr substArgs(EvalState & state, /* One or more actual arguments were not declared as formal arguments. Find out which. */ for (ATermIterator i(formals); i; ++i) { - Expr name; ATerm d1, d2; - if (!matchFormal(*i, name, d1, d2)) abort(); + Expr name; ATerm d1; + if (!matchFormal(*i, name, d1)) abort(); subs.remove(name); } throw TypeError(format("the function does not expect an argument named `%1%'") @@ -393,8 +377,8 @@ Expr autoCallFunction(Expr e, const ATermMap & args) ATermMap actualArgs(ATgetLength(formals)); for (ATermIterator i(formals); i; ++i) { - Expr name, def, value; ATerm values, def2; - if (!matchFormal(*i, name, values, def2)) abort(); + Expr name, def, value; ATerm def2; + if (!matchFormal(*i, name, def2)) abort(); if ((value = args.get(name))) actualArgs.set(name, makeAttrRHS(value, makeNoPos())); else if (!matchDefaultValue(def2, def)) @@ -800,29 +784,6 @@ static Expr strictEvalExpr_(EvalState & state, Expr e, ATermMap & nfs) return makeList(ATreverse(es2)); } - ATermList formals; - ATerm body, pos; - if (matchFunction(e, formals, body, pos)) { - ATermList formals2 = ATempty; - - for (ATermIterator i(formals); i; ++i) { - Expr name; ValidValues valids; ATerm dummy; - if (!matchFormal(*i, name, valids, dummy)) abort(); - - ATermList valids2; - if (matchValidValues(valids, valids2)) { - ATermList valids3 = ATempty; - for (ATermIterator j(valids2); j; ++j) - valids3 = ATinsert(valids3, strictEvalExpr(state, *j, nfs)); - valids = makeValidValues(ATreverse(valids3)); - } - - formals2 = ATinsert(formals2, makeFormal(name, valids, dummy)); - } - - return makeFunction(ATreverse(formals2), body, pos); - } - return e; } diff --git a/src/libexpr/expr-to-xml.cc b/src/libexpr/expr-to-xml.cc index 947e62879f0c..c47f24e6c0f9 100644 --- a/src/libexpr/expr-to-xml.cc +++ b/src/libexpr/expr-to-xml.cc @@ -113,17 +113,9 @@ static void printTermAsXML(Expr e, XMLWriter & doc, PathSet & context, XMLOpenElement _(doc, "function"); for (ATermIterator i(formals); i; ++i) { - Expr name; ValidValues valids; ATerm dummy; - if (!matchFormal(*i, name, valids, dummy)) abort(); + Expr name; ATerm dummy; + if (!matchFormal(*i, name, dummy)) abort(); XMLOpenElement _(doc, "arg", singletonAttrs("name", aterm2String(name))); - - ATermList valids2; - if (matchValidValues(valids, valids2)) { - for (ATermIterator j(valids2); j; ++j) { - XMLOpenElement _(doc, "value"); - printTermAsXML(*j, doc, context, drvsSeen); - } - } } } diff --git a/src/libexpr/nixexpr-ast.def b/src/libexpr/nixexpr-ast.def index a06d34311ae1..a57a48613e53 100644 --- a/src/libexpr/nixexpr-ast.def +++ b/src/libexpr/nixexpr-ast.def @@ -76,10 +76,7 @@ Inherit | Expr ATermList Pos | ATerm | Scope | | Expr | -Formal | string ValidValues DefaultValue | ATerm | - -ValidValues | ATermList | ValidValues | -UnrestrictedValues | | ValidValues | +Formal | string DefaultValue | ATerm | DefaultValue | Expr | DefaultValue | NoDefaultValue | | DefaultValue | diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index 0f5ec030654f..310f714718fe 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -140,8 +140,8 @@ Expr substitute(const Substitution & subs, Expr e) if (matchFunction(e, formals, body, pos)) { ATermMap map(ATgetLength(formals)); for (ATermIterator i(formals); i; ++i) { - ATerm d1, d2; - if (!matchFormal(*i, name, d1, d2)) abort(); + ATerm d1; + if (!matchFormal(*i, name, d1)) abort(); map.set(name, makeRemoved()); } Substitution subs2(&subs, &map); @@ -230,15 +230,14 @@ static void checkVarDefs2(set<Expr> & done, const ATermMap & defs, Expr e) else if (matchFunction(e, formals, body, pos)) { ATermMap defs2(defs); for (ATermIterator i(formals); i; ++i) { - ATerm d1, d2; - if (!matchFormal(*i, name, d1, d2)) abort(); + ATerm d1; + if (!matchFormal(*i, name, d1)) abort(); defs2.set(name, (ATerm) ATempty); } for (ATermIterator i(formals); i; ++i) { - ATerm valids, deflt; + ATerm deflt; set<Expr> done2; - if (!matchFormal(*i, name, valids, deflt)) abort(); - checkVarDefs2(done, defs, valids); + if (!matchFormal(*i, name, deflt)) abort(); checkVarDefs2(done2, defs2, deflt); } set<Expr> done2; diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index cd3ba88aa658..9c941bb7d446 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -354,9 +354,8 @@ formals ; formal - : ID { $$ = makeFormal($1, makeUnrestrictedValues(), makeNoDefaultValue()); } - | ID ':' '[' expr_list ']' { $$ = makeFormal($1, makeValidValues($4), makeNoDefaultValue()); } - | ID '?' expr { $$ = makeFormal($1, makeUnrestrictedValues(), makeDefaultValue($3)); } + : ID { $$ = makeFormal($1, makeNoDefaultValue()); } + | ID '?' expr { $$ = makeFormal($1, makeDefaultValue($3)); } ; %% @@ -396,8 +395,8 @@ static void checkAttrSets(ATerm e) ATermMap names(ATgetLength(formals)); for (ATermIterator i(formals); i; ++i) { ATerm name; - ATerm d1, d2; - if (!matchFormal(*i, name, d1, d2)) abort(); + ATerm d1; + if (!matchFormal(*i, name, d1)) abort(); if (names.get(name)) throw EvalError(format("duplicate formal function argument `%1%' at %2%") % aterm2String(name) % showPos(pos)); diff --git a/tests/lang/eval-fail-bad-value.nix b/tests/lang/eval-fail-bad-value.nix deleted file mode 100644 index 97969145eeb1..000000000000 --- a/tests/lang/eval-fail-bad-value.nix +++ /dev/null @@ -1,7 +0,0 @@ -let { - - f = {x, y : ["baz" "bat"]}: x + y; - - body = f {x = "foo"; y = "bar";}; - -} diff --git a/tests/lang/eval-okay-good-value.exp b/tests/lang/eval-okay-good-value.exp deleted file mode 100644 index 7c3659b970e8..000000000000 --- a/tests/lang/eval-okay-good-value.exp +++ /dev/null @@ -1 +0,0 @@ -Str("foobar",[]) diff --git a/tests/lang/eval-okay-good-value.nix b/tests/lang/eval-okay-good-value.nix deleted file mode 100644 index 5dfc6d85e93c..000000000000 --- a/tests/lang/eval-okay-good-value.nix +++ /dev/null @@ -1,7 +0,0 @@ -let { - - f = {x, y : ["baz" "bar" "bat"]}: x + y; - - body = f {x = "foo"; y = "bar";}; - -} diff --git a/tests/lang/eval-okay-xml.exp.xml b/tests/lang/eval-okay-xml.exp.xml index bfb34f81d0ad..0310f335c353 100644 --- a/tests/lang/eval-okay-xml.exp.xml +++ b/tests/lang/eval-okay-xml.exp.xml @@ -15,23 +15,8 @@ <arg name="z"> </arg> <arg name="x"> - <value> - <string value="a" /> - </value> - <value> - <string value="b" /> - </value> - <value> - <string value="cd" /> - </value> </arg> <arg name="y"> - <value> - <bool value="true" /> - </value> - <value> - <bool value="false" /> - </value> </arg> </function> </attr> diff --git a/tests/lang/eval-okay-xml.nix b/tests/lang/eval-okay-xml.nix index 244b2c0fb401..8151337b98e0 100644 --- a/tests/lang/eval-okay-xml.nix +++ b/tests/lang/eval-okay-xml.nix @@ -8,6 +8,6 @@ rec { c = "foo" + "bar"; - f = {z, x : ["a" "b" ("c" + "d")], y : [true false]}: if y then x else z; + f = {z, x, y}: if y then x else z; } \ No newline at end of file diff --git a/tests/lang/parse-okay-1.exp b/tests/lang/parse-okay-1.exp index 1e4378fed75b..b8b08d95e1ac 100644 --- a/tests/lang/parse-okay-1.exp +++ b/tests/lang/parse-okay-1.exp @@ -1 +1 @@ -Function([Formal("x",UnrestrictedValues,NoDefaultValue),Formal("y",UnrestrictedValues,NoDefaultValue),Formal("z",UnrestrictedValues,NoDefaultValue)],OpPlus(OpPlus(Var("x"),Var("y")),Var("z")),NoPos) +Function([Formal("x",NoDefaultValue),Formal("y",NoDefaultValue),Formal("z",NoDefaultValue)],OpPlus(OpPlus(Var("x"),Var("y")),Var("z")),NoPos) diff --git a/tests/lang/parse-okay-regression-20041027.exp b/tests/lang/parse-okay-regression-20041027.exp index 246779fa5400..bc508d436c2e 100644 --- a/tests/lang/parse-okay-regression-20041027.exp +++ b/tests/lang/parse-okay-regression-20041027.exp @@ -1 +1 @@ -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) +Function([Formal("stdenv",NoDefaultValue),Formal("fetchurl",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) diff --git a/tests/lang/parse-okay-subversion.exp b/tests/lang/parse-okay-subversion.exp index 0ea2a88edcbe..b51a406b14e2 100644 --- a/tests/lang/parse-okay-subversion.exp +++ b/tests/lang/parse-okay-subversion.exp @@ -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("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) +Function([Formal("localServer",DefaultValue(Var("false"))),Formal("httpServer",DefaultValue(Var("false"))),Formal("sslSupport",DefaultValue(Var("false"))),Formal("pythonBindings",DefaultValue(Var("false"))),Formal("javaSwigBindings",DefaultValue(Var("false"))),Formal("javahlBindings",DefaultValue(Var("false"))),Formal("stdenv",NoDefaultValue),Formal("fetchurl",NoDefaultValue),Formal("openssl",DefaultValue(Var("null"))),Formal("httpd",DefaultValue(Var("null"))),Formal("db4",DefaultValue(Var("null"))),Formal("expat",NoDefaultValue),Formal("swig",DefaultValue(Var("null"))),Formal("j2sdk",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) |