mirror of
https://github.com/NixOS/nix
synced 2025-07-09 07:53:55 +02:00
* Removed the "valid values" feature. Nobody uses it anyway.
This commit is contained in:
parent
b455c4c45c
commit
5664b6d7ba
13 changed files with 22 additions and 104 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 |
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue