From ac4d39f9db28743b6c1e9def7a61241a50b02335 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sun, 28 Mar 2004 21:15:01 +0000 Subject: * Added an operator `?' to test for attribute existence, e.g., `attrs ? x' yields true iff `attrs' has an attribute named `x'. --- src/libexpr/eval.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/libexpr/eval.cc') diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 2281ee7212..0623e49532 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -288,10 +288,17 @@ Expr evalExpr2(EvalState & state, Expr e) if (atMatch(m, e) >> "OpOr" >> e1 >> e2) return makeBool(evalBool(state, e1) || evalBool(state, e2)); - /* Attribut set update (//). */ + /* Attribute set update (//). */ if (atMatch(m, e) >> "OpUpdate" >> e1 >> e2) return updateAttrs(evalExpr(state, e1), evalExpr(state, e2)); + /* Attribute existence test (?). */ + if (atMatch(m, e) >> "OpHasAttr" >> e1 >> name) { + ATermMap attrs; + queryAllAttrs(evalExpr(state, e1), attrs); + return makeBool(attrs.get(name) != 0); + } + /* Barf. */ throw badTerm("invalid expression", e); } -- cgit 1.4.1