about summary refs log tree commit diff
path: root/src/libexpr/eval.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2004-03-28T21·15+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2004-03-28T21·15+0000
commitac4d39f9db28743b6c1e9def7a61241a50b02335 (patch)
tree85311119f03b0d44c8a2fe861706924349b792f1 /src/libexpr/eval.cc
parentf958bcdf1f9f66759a2512e4b7c0b0ba5647960a (diff)
* Added an operator `?' to test for attribute existence, e.g.,
  `attrs ? x' yields true iff `attrs' has an attribute named `x'.

Diffstat (limited to 'src/libexpr/eval.cc')
-rw-r--r--src/libexpr/eval.cc9
1 files changed, 8 insertions, 1 deletions
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);
 }