about summary refs log tree commit diff
path: root/src/libexpr/eval.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/eval.cc
parentfc33fd86b7727365caab44c05a90d5b52209131b (diff)
Add a primop unsafeGetAttrPos to return the position of an attribute
Diffstat (limited to 'src/libexpr/eval.cc')
-rw-r--r--src/libexpr/eval.cc19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 7fb38c0fd79c..c2db006c1414 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -410,6 +410,19 @@ void EvalState::mkThunk_(Value & v, Expr * expr)
 }
 
 
+void EvalState::mkPos(Value & v, Pos * pos)
+{
+    if (pos) {
+        mkAttrs(v, 3);
+        mkString(*allocAttr(v, sFile), pos->file);
+        mkInt(*allocAttr(v, sLine), pos->line);
+        mkInt(*allocAttr(v, sColumn), pos->column);
+        v.attrs->sort();
+    } else
+        mkNull(v);
+}
+
+
 /* Create a thunk for the delayed computation of the given expression
    in the given environment.  But if the expression is a variable,
    then look it up right away.  This significantly reduces the number
@@ -1044,11 +1057,7 @@ void ExprConcatStrings::eval(EvalState & state, Env & env, Value & v)
 
 void ExprPos::eval(EvalState & state, Env & env, Value & v)
 {
-    state.mkAttrs(v, 3);
-    mkString(*state.allocAttr(v, state.sFile), pos.file);
-    mkInt(*state.allocAttr(v, state.sLine), pos.line);
-    mkInt(*state.allocAttr(v, state.sColumn), pos.column);
-    v.attrs->sort();
+    state.mkPos(v, &pos);
 }