From ec448f8bb694b6f9546e49fe6a79b86ff2b2f90a Mon Sep 17 00:00:00 2001 From: zimbatm Date: Mon, 28 Oct 2019 21:22:38 +0100 Subject: [PATCH] libexpr: findDerivationFilename return Pos instead of tuple --- src/libexpr/attr-path.cc | 8 +++++--- src/libexpr/attr-path.hh | 6 ++---- src/nix/edit.cc | 6 +++--- src/nix/repl.cc | 4 +++- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/libexpr/attr-path.cc b/src/libexpr/attr-path.cc index 7a6d8dfd0..c86dbeebb 100644 --- a/src/libexpr/attr-path.cc +++ b/src/libexpr/attr-path.cc @@ -93,7 +93,7 @@ Value * findAlongAttrPath(EvalState & state, const string & attrPath, } -std::tuple findDerivationFilename(EvalState & state, Value & v, std::string what) +Pos findDerivationFilename(EvalState & state, Value & v, std::string what) { Value * v2; try { @@ -110,14 +110,16 @@ std::tuple findDerivationFilename(EvalState & state, Value & v throw Error("cannot parse meta.position attribute '%s'", pos); std::string filename(pos, 0, colon); - int lineno; + unsigned int lineno; try { lineno = std::stoi(std::string(pos, colon + 1)); } catch (std::invalid_argument & e) { throw Error("cannot parse line number '%s'", pos); } - return std::make_tuple(filename, lineno); + Symbol file = state.symbols.create(filename); + + return { file, lineno, 0 }; } diff --git a/src/libexpr/attr-path.hh b/src/libexpr/attr-path.hh index dca94cc78..716e5ba27 100644 --- a/src/libexpr/attr-path.hh +++ b/src/libexpr/attr-path.hh @@ -4,15 +4,13 @@ #include #include -#include namespace nix { Value * findAlongAttrPath(EvalState & state, const string & attrPath, Bindings & autoArgs, Value & vIn); -/* Heuristic to find the filename and lineno or a derivation. */ -std::tuple findDerivationFilename(EvalState & state, - Value & v, std::string what); +/* Heuristic to find the filename and lineno or a nix value. */ +Pos findDerivationFilename(EvalState & state, Value & v, std::string what); } diff --git a/src/nix/edit.cc b/src/nix/edit.cc index a4aa40bed..d0607747d 100644 --- a/src/nix/edit.cc +++ b/src/nix/edit.cc @@ -36,9 +36,9 @@ struct CmdEdit : InstallableCommand auto v = installable->toValue(*state); - std::string filename; - int lineno; - std::tie(filename, lineno) = findDerivationFilename(*state, *v, installable->what()); + Pos pos = findDerivationFilename(*state, *v, installable->what()); + std::string filename(pos.file); + int lineno(pos.line); stopProgressBar(); diff --git a/src/nix/repl.cc b/src/nix/repl.cc index 5cfb408f7..ed67c285f 100644 --- a/src/nix/repl.cc +++ b/src/nix/repl.cc @@ -481,7 +481,9 @@ bool NixRepl::processLine(string line) lineno = 0; } else { // assume it's a derivation - std::tie(filename, lineno) = findDerivationFilename(state, v, arg); + Pos pos = findDerivationFilename(state, v, arg); + filename = pos.file; + lineno = pos.line; } // Open in EDITOR