From 285df765b91588e39d6f35a32e30b84c3cb5be75 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 18 Nov 2013 22:22:35 +0100 Subject: Add a primop unsafeGetAttrPos to return the position of an attribute --- src/libexpr/eval.cc | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/libexpr/eval.cc') 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); } -- cgit 1.4.1