diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-11-18 22:22:35 +0100 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-11-18 22:22:35 +0100 |
commit | 285df765b91588e39d6f35a32e30b84c3cb5be75 (patch) | |
tree | 8f93b3fd527f44f14eacefb6c4c9385f670e8aea /src/libexpr/primops.cc | |
parent | fc33fd86b7727365caab44c05a90d5b52209131b (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.cc | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 180a24dff..5f2a58454 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); |