mirror of
https://github.com/NixOS/nix
synced 2025-07-07 01:51:47 +02:00
printEnvPosChain
This commit is contained in:
parent
310c689d31
commit
176911102c
11 changed files with 32193 additions and 4 deletions
|
@ -109,6 +109,7 @@ ref<EvalState> EvalCommand::getEvalState()
|
|||
if (startReplOnEvalErrors)
|
||||
debuggerHook = [evalState{ref<EvalState>(evalState)}](const Error & error, const Env & env) {
|
||||
printError("%s\n\n" ANSI_BOLD "Starting REPL to allow you to inspect the current state of the evaluator.\n" ANSI_NORMAL, error.what());
|
||||
// printEnvPosChain(env);
|
||||
printEnvBindings(env);
|
||||
auto vm = mapEnvBindings(env);
|
||||
runRepl(evalState, *vm);
|
||||
|
|
|
@ -648,13 +648,11 @@ std::optional<EvalState::Doc> EvalState::getDoc(Value & v)
|
|||
// LocalNoInline(valmap * mapBindings(Bindings &b))
|
||||
// {
|
||||
// auto map = new valmap();
|
||||
|
||||
// for (auto i = b.begin(); i != b.end(); ++i)
|
||||
// {
|
||||
// std::string s = i->name;
|
||||
// (*map)[s] = i->value;
|
||||
// }
|
||||
|
||||
// return map;
|
||||
// }
|
||||
|
||||
|
@ -668,12 +666,13 @@ std::optional<EvalState::Doc> EvalState::getDoc(Value & v)
|
|||
// }
|
||||
// }
|
||||
|
||||
|
||||
void printEnvBindings(const Env &env, int lv )
|
||||
{
|
||||
std::cout << "env " << lv << " type: " << env.type << std::endl;
|
||||
if (env.values[0]->type() == nAttrs) {
|
||||
Bindings::iterator j = env.values[0]->attrs->begin();
|
||||
|
||||
|
||||
while (j != env.values[0]->attrs->end()) {
|
||||
std::cout << lv << " env binding: " << j->name << std::endl;
|
||||
// if (countCalls && j->pos) attrSelects[*j->pos]++;
|
||||
|
@ -690,6 +689,33 @@ void printEnvBindings(const Env &env, int lv )
|
|||
}
|
||||
}
|
||||
|
||||
void printEnvPosChain(const Env &env, int lv )
|
||||
{
|
||||
std::cout << "printEnvPosChain " << lv << std::endl;
|
||||
|
||||
std::cout << "env" << env.values[0] << std::endl;
|
||||
|
||||
if (env.values[0] && env.values[0]->type() == nAttrs) {
|
||||
std::cout << "im in the loop" << std::endl;
|
||||
std::cout << "pos " << env.values[0]->attrs->pos << std::endl;
|
||||
if (env.values[0]->attrs->pos) {
|
||||
ErrPos ep(*env.values[0]->attrs->pos);
|
||||
auto loc = getCodeLines(ep);
|
||||
if (loc)
|
||||
printCodeLines(std::cout,
|
||||
std::__cxx11::to_string(lv),
|
||||
ep,
|
||||
*loc);
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "next env : " << env.up << std::endl;
|
||||
|
||||
if (env.up) {
|
||||
printEnvPosChain(*env.up, ++lv);
|
||||
}
|
||||
}
|
||||
|
||||
void mapEnvBindings(const Env &env, valmap & vm)
|
||||
{
|
||||
// add bindings for the next level up first.
|
||||
|
@ -699,7 +725,7 @@ void mapEnvBindings(const Env &env, valmap & vm)
|
|||
|
||||
// merge - and write over - higher level bindings.
|
||||
// note; skipping HasWithExpr that haven't been evaled yet.
|
||||
if (env.values[0]->type() == nAttrs) {
|
||||
if (env.values[0] && env.values[0]->type() == nAttrs) {
|
||||
auto map = valmap();
|
||||
|
||||
Bindings::iterator j = env.values[0]->attrs->begin();
|
||||
|
|
|
@ -45,6 +45,7 @@ struct Env
|
|||
|
||||
void printEnvBindings(const Env &env, int lv = 0);
|
||||
valmap * mapEnvBindings(const Env &env);
|
||||
void printEnvPosChain(const Env &env, int lv = 0);
|
||||
|
||||
Value & mkString(Value & v, std::string_view s, const PathSet & context = PathSet());
|
||||
|
||||
|
|
|
@ -100,6 +100,12 @@ struct ErrPos {
|
|||
}
|
||||
};
|
||||
|
||||
std::optional<LinesOfCode> getCodeLines(const ErrPos & errPos);
|
||||
void printCodeLines(std::ostream & out,
|
||||
const string & prefix,
|
||||
const ErrPos & errPos,
|
||||
const LinesOfCode & loc);
|
||||
|
||||
struct Trace {
|
||||
std::optional<ErrPos> pos;
|
||||
hintformat hint;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue