libexpr: Migrate makePositionThunks to return Value tuple
part of #1136 and a step towards #744 Change-Id: Ib2ccea4c098bbb66eaa47645b6fa59e56a6a6964
This commit is contained in:
+3
-1
@@ -857,7 +857,9 @@ void EvalState::mkPos(Value & v, PosIdx p)
|
||||
if (auto path = std::get_if<CheckedSourcePath>(&origin)) {
|
||||
auto attrs = ctx.buildBindings(3);
|
||||
attrs.alloc(ctx.symbols.sym_file) = {NewValueAs::string, path->to_string()};
|
||||
makePositionThunks(*this, p, attrs.alloc(ctx.symbols.sym_line), attrs.alloc(ctx.symbols.sym_column));
|
||||
Value & line = attrs.alloc(ctx.symbols.sym_line);
|
||||
Value & col = attrs.alloc(ctx.symbols.sym_column);
|
||||
std::tie(line, col) = makePositionThunks(*this, p);
|
||||
v = {NewValueAs::attrs, attrs};
|
||||
} else
|
||||
v.mkNull();
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <tuple>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <algorithm>
|
||||
@@ -1931,17 +1932,18 @@ static struct LazyPosAcessors {
|
||||
Value lineOfPos = {NewValueAs::primop, primop_lineOfPos},
|
||||
columnOfPos = {NewValueAs::primop, primop_columnOfPos};
|
||||
|
||||
void operator()(EvalState & state, const PosIdx pos, Value & line, Value & column)
|
||||
std::tuple<Value, Value> operator()(EvalState & state, const PosIdx pos)
|
||||
{
|
||||
Value posV{NewValueAs::integer, NixInt{pos.id}};
|
||||
line = {NewValueAs::app, state.ctx.mem, lineOfPos, posV};
|
||||
column = {NewValueAs::app, state.ctx.mem, columnOfPos, posV};
|
||||
Value line = {NewValueAs::app, state.ctx.mem, lineOfPos, posV};
|
||||
Value column = {NewValueAs::app, state.ctx.mem, columnOfPos, posV};
|
||||
return std::make_tuple(line, column);
|
||||
}
|
||||
} makeLazyPosAccessors;
|
||||
|
||||
void makePositionThunks(EvalState & state, const PosIdx pos, Value & line, Value & column)
|
||||
std::tuple<Value, Value> makePositionThunks(EvalState & state, const PosIdx pos)
|
||||
{
|
||||
makeLazyPosAccessors(state, pos, line, column);
|
||||
return makeLazyPosAccessors(state, pos);
|
||||
}
|
||||
|
||||
/* Dynamic version of the `?' operator. */
|
||||
|
||||
@@ -55,6 +55,5 @@ void prim_importNative(EvalState & state, Value * * args, Value & v);
|
||||
*/
|
||||
void prim_exec(EvalState & state, Value * * args, Value & v);
|
||||
|
||||
void makePositionThunks(EvalState & state, const PosIdx pos, Value & line, Value & column);
|
||||
|
||||
std::tuple<Value, Value> makePositionThunks(EvalState & state, const PosIdx pos);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user