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-18T19·14+0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2013-11-18T19·16+0100
commitfc33fd86b7727365caab44c05a90d5b52209131b (patch)
treeba12d5e943e0e3b0d9aa5a9e25f1fa784dc369f0 /src/libexpr/eval.cc
parent90b5e692846d9b7a951155c5ed4fc7cf72b08e31 (diff)
Add a symbol __curPos that expands to the current source location
I.e. an attribute set { file = <string>; line = <int>; column = <int>; }.
Diffstat (limited to 'src/libexpr/eval.cc')
-rw-r--r--src/libexpr/eval.cc13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index b3fc6791a2ae..7fb38c0fd79c 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -142,6 +142,9 @@ EvalState::EvalState()
     , sOutputs(symbols.create("outputs"))
     , sOutputName(symbols.create("outputName"))
     , sIgnoreNulls(symbols.create("__ignoreNulls"))
+    , sFile(symbols.create("file"))
+    , sLine(symbols.create("line"))
+    , sColumn(symbols.create("column"))
     , repair(false)
     , baseEnv(allocEnv(128))
     , staticBaseEnv(false, 0)
@@ -1039,6 +1042,16 @@ 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();
+}
+
+
 void EvalState::strictForceValue(Value & v)
 {
     forceValue(v);