libexpr: remove state reference from EvalError
nothing actually needs it. EvalErrorBuilder can have its own reference.
Change-Id: I8bf301d03a9c161519c130c95e58b1d5400e6411
This commit is contained in:
parent
e44dbfe97a
commit
63006438c4
3 changed files with 17 additions and 28 deletions
|
@ -14,7 +14,7 @@ EvalErrorBuilder<T> & EvalErrorBuilder<T>::withExitStatus(unsigned int exitStatu
|
|||
template<class T>
|
||||
EvalErrorBuilder<T> & EvalErrorBuilder<T>::atPos(PosIdx pos)
|
||||
{
|
||||
error.err.pos = error.state.positions[pos];
|
||||
error.err.pos = state.positions[pos];
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ template<class T>
|
|||
EvalErrorBuilder<T> & EvalErrorBuilder<T>::withTrace(PosIdx pos, const std::string_view text)
|
||||
{
|
||||
error.err.traces.push_front(
|
||||
Trace{.pos = error.state.positions[pos], .hint = HintFmt(std::string(text))});
|
||||
Trace{.pos = state.positions[pos], .hint = HintFmt(std::string(text))});
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -42,9 +42,9 @@ EvalErrorBuilder<T> & EvalErrorBuilder<T>::withSuggestions(Suggestions & s)
|
|||
template<class T>
|
||||
EvalErrorBuilder<T> & EvalErrorBuilder<T>::withFrame(const Env & env, const Expr & expr)
|
||||
{
|
||||
if (error.state.debug) {
|
||||
error.frame = error.state.debug->addTrace(DebugTrace{
|
||||
.pos = error.state.positions[expr.getPos()],
|
||||
if (state.debug) {
|
||||
error.frame = state.debug->addTrace(DebugTrace{
|
||||
.pos = state.positions[expr.getPos()],
|
||||
.expr = expr,
|
||||
.env = env,
|
||||
.hint = HintFmt("Fake frame for debugging purposes"),
|
||||
|
@ -57,7 +57,7 @@ EvalErrorBuilder<T> & EvalErrorBuilder<T>::withFrame(const Env & env, const Expr
|
|||
template<class T>
|
||||
EvalErrorBuilder<T> & EvalErrorBuilder<T>::addTrace(PosIdx pos, HintFmt hint)
|
||||
{
|
||||
error.addTrace(error.state.positions[pos], hint);
|
||||
error.addTrace(state.positions[pos], hint);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -67,18 +67,18 @@ EvalErrorBuilder<T> &
|
|||
EvalErrorBuilder<T>::addTrace(PosIdx pos, std::string_view formatString, const Args &... formatArgs)
|
||||
{
|
||||
|
||||
addTrace(error.state.positions[pos], HintFmt(std::string(formatString), formatArgs...));
|
||||
addTrace(state.positions[pos], HintFmt(std::string(formatString), formatArgs...));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void EvalErrorBuilder<T>::debugThrow()
|
||||
{
|
||||
if (error.state.debug) {
|
||||
if (auto last = error.state.debug->traces().next()) {
|
||||
if (state.debug) {
|
||||
if (auto last = state.debug->traces().next()) {
|
||||
const Env * env = &(*last)->env;
|
||||
const Expr * expr = &(*last)->expr;
|
||||
error.state.debug->runDebugRepl(error.state, &error, *env, *expr);
|
||||
state.debug->runDebugRepl(state, &error, *env, *expr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,20 +24,7 @@ class EvalError : public Error
|
|||
std::shared_ptr<const DebugTrace> frame;
|
||||
|
||||
public:
|
||||
EvalState & state;
|
||||
|
||||
EvalError(EvalState & state, ErrorInfo && errorInfo)
|
||||
: Error(errorInfo)
|
||||
, state(state)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
explicit EvalError(EvalState & state, const std::string & formatString, const Args &... formatArgs)
|
||||
: Error(formatString, formatArgs...)
|
||||
, state(state)
|
||||
{
|
||||
}
|
||||
using Error::Error;
|
||||
};
|
||||
|
||||
MakeError(ParseError, Error);
|
||||
|
@ -58,8 +45,8 @@ struct InvalidPathError : public EvalError
|
|||
{
|
||||
public:
|
||||
Path path;
|
||||
InvalidPathError(EvalState & state, const Path & path)
|
||||
: EvalError(state, "path '%s' did not exist in the store during evaluation", path)
|
||||
InvalidPathError(const Path & path)
|
||||
: EvalError("path '%s' did not exist in the store during evaluation", path)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
@ -74,9 +61,11 @@ class EvalErrorBuilder final
|
|||
{
|
||||
friend class EvalState;
|
||||
|
||||
EvalState & state;
|
||||
|
||||
template<typename... Args>
|
||||
explicit EvalErrorBuilder(EvalState & state, const Args &... args)
|
||||
: error(T(state, args...))
|
||||
: state(state), error(T(args...))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -567,7 +567,7 @@ static void prim_genericClosure(EvalState & state, const PosIdx pos, Value * * a
|
|||
static void prim_break(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
||||
{
|
||||
if (auto trace = state.debug ? state.debug->traces().next() : std::nullopt) {
|
||||
auto error = EvalError(state, ErrorInfo {
|
||||
auto error = EvalError(ErrorInfo {
|
||||
.level = lvlInfo,
|
||||
.msg = HintFmt("breakpoint reached"),
|
||||
.pos = state.positions[pos],
|
||||
|
|
Loading…
Reference in a new issue