about summary refs log tree commit diff
path: root/src/libexpr/primops.cc
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2013-11-18T21·22+0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2013-11-18T21·22+0100
commit285df765b91588e39d6f35a32e30b84c3cb5be75 (patch)
tree8f93b3fd527f44f14eacefb6c4c9385f670e8aea /src/libexpr/primops.cc
parentfc33fd86b7727365caab44c05a90d5b52209131b (diff)
Add a primop unsafeGetAttrPos to return the position of an attribute
Diffstat (limited to 'src/libexpr/primops.cc')
-rw-r--r--src/libexpr/primops.cc16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 180a24dffc91..5f2a58454627 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -776,6 +776,19 @@ void prim_getAttr(EvalState & state, Value * * args, Value & v)
 }
 
 
+/* Return position information of the specified attribute. */
+void prim_unsafeGetAttrPos(EvalState & state, Value * * args, Value & v)
+{
+    string attr = state.forceStringNoCtx(*args[0]);
+    state.forceAttrs(*args[1]);
+    Bindings::iterator i = args[1]->attrs->find(state.symbols.create(attr));
+    if (i == args[1]->attrs->end())
+        mkNull(v);
+    else
+        state.mkPos(v, i->pos);
+}
+
+
 /* Dynamic version of the `?' operator. */
 static void prim_hasAttr(EvalState & state, Value * * args, Value & v)
 {
@@ -1201,7 +1214,7 @@ void EvalState::createBaseEnv()
     mkBool(v, false);
     addConstant("false", v);
 
-    v.type = tNull;
+    mkNull(v);
     addConstant("null", v);
 
     mkInt(v, time(0));
@@ -1252,6 +1265,7 @@ void EvalState::createBaseEnv()
     // Sets
     addPrimOp("__attrNames", 1, prim_attrNames);
     addPrimOp("__getAttr", 2, prim_getAttr);
+    addPrimOp("__unsafeGetAttrPos", 2, prim_unsafeGetAttrPos);
     addPrimOp("__hasAttr", 2, prim_hasAttr);
     addPrimOp("__isAttrs", 1, prim_isAttrs);
     addPrimOp("removeAttrs", 2, prim_removeAttrs);