From 8688e83194c11f66df2d38dfa9b274d2216773b2 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 8 Feb 2006 15:22:30 +0000 Subject: [PATCH] * When evaluating, automatically call functions with default arguments. --- src/libexpr/get-drvs.cc | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/libexpr/get-drvs.cc b/src/libexpr/get-drvs.cc index c158a71df..723d3a6bc 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)"); } - -