diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-02-08T15·22+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-02-08T15·22+0000 |
commit | 8688e83194c11f66df2d38dfa9b274d2216773b2 (patch) | |
tree | 63811370efa750f65318b2244a6868cc1d4f9576 | |
parent | f8aadf14c3426f7ab2b7a934b602f812bcc5b8ae (diff) |
* When evaluating, automatically call functions with default arguments.
-rw-r--r-- | src/libexpr/get-drvs.cc | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/libexpr/get-drvs.cc b/src/libexpr/get-drvs.cc index c158a71dff5c..723d3a6bc744 100644 --- a/src/libexpr/get-drvs.cc +++ b/src/libexpr/get-drvs.cc @@ -37,10 +37,12 @@ void getDerivations(EvalState & state, Expr e, DrvInfos & drvs) e = evalExpr(state, e); - if (getDerivation(state, e, drv)) + if (getDerivation(state, e, drv)) { drvs.push_back(drv); + return; + } - else if (matchAttrs(e, es)) { + if (matchAttrs(e, es)) { ATermMap drvMap; queryAllAttrs(e, drvMap); for (ATermIterator i(drvMap.keys()); i; ++i) { @@ -51,9 +53,10 @@ void getDerivations(EvalState & state, Expr e, DrvInfos & drvs) ; // parseDerivations(state, drvMap.get(*i), drvs); } + return; } - else if (matchList(e, es)) { + if (matchList(e, es)) { for (ATermIterator i(es); i; ++i) { debug(format("evaluating list element")); if (getDerivation(state, *i, drv)) @@ -61,7 +64,23 @@ void getDerivations(EvalState & state, Expr e, DrvInfos & drvs) else getDerivations(state, *i, drvs); } + return; } -} + ATermList formals; + ATerm body, pos; + if (matchFunction(e, formals, body, pos)) { + for (ATermIterator i(formals); i; ++i) { + Expr name, def; + if (matchNoDefFormal(*i, name)) + throw Error(format("expression evaluates to a function with no-default arguments (`%1%')") + % aterm2String(name)); + else if (!matchDefFormal(*i, name, def)) + abort(); /* can't happen */ + } + getDerivations(state, makeCall(e, makeAttrs(ATermMap())), drvs); + return; + } + throw Error("expression does not evaluate to a derivation (or a set or list of those)"); +} |