aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr
diff options
context:
space:
mode:
authorBen Burdette <bburdette@gmail.com>2021-09-15 16:16:53 -0600
committerBen Burdette <bburdette@gmail.com>2021-09-15 16:16:53 -0600
commitcd8c232b554776031f61cee5f70a8825c60fbfdb (patch)
treee36bab7f8eeeeb683e0a0e4a3508129f8f3f4dbf /src/libexpr
parent1e04b2568d4898d253891cd2a9da00754611d927 (diff)
add cout debugging
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/eval.cc2
-rw-r--r--src/libexpr/nixexpr.cc42
-rw-r--r--src/libexpr/nixexpr.hh1
-rw-r--r--src/libexpr/parser.y11
-rw-r--r--src/libexpr/primops.cc4
5 files changed, 52 insertions, 8 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 69e3a4107..bcef2008f 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -918,6 +918,8 @@ LocalNoInlineNoReturn(void throwUndefinedVarError(const Pos & pos, const char *
.errPos = pos
});
+ std::cout << "pre debuggerHook" << std::endl;
+
if (debuggerHook)
debuggerHook(error, env);
throw error;
diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc
index 218e35f33..f8ded2157 100644
--- a/src/libexpr/nixexpr.cc
+++ b/src/libexpr/nixexpr.cc
@@ -3,7 +3,7 @@
#include "util.hh"
#include <cstdlib>
-
+#include <iostream>
namespace nix {
@@ -283,6 +283,7 @@ void ExprVar::bindVars(const std::shared_ptr<const StaticEnv> &env)
enclosing `with'. If there is no `with', then we can issue an
"undefined variable" error now. */
if (withLevel == -1)
+ std::cout << " throw UndefinedVarError({" << std::endl;
throw UndefinedVarError({
.msg = hintfmt("undefined variable '%1%'", name),
.errPos = pos
@@ -310,11 +311,12 @@ void ExprOpHasAttr::bindVars(const std::shared_ptr<const StaticEnv> &env)
void ExprAttrs::bindVars(const std::shared_ptr<const StaticEnv> &env)
{
- const StaticEnv * dynamicEnv = env.get();
- auto newEnv = std::shared_ptr<StaticEnv>(new StaticEnv(false, env.get())); // also make shared_ptr?
+ std::cout << "ExprAttrs::bindVars" << std::endl;
+ // auto dynamicEnv(env);
if (recursive) {
- dynamicEnv = newEnv.get();
+ // dynamicEnv = newEnv.get();
+ auto newEnv = std::shared_ptr<StaticEnv>(new StaticEnv(false, env.get())); // also make shared_ptr?
unsigned int displ = 0;
for (auto & i : attrs)
@@ -322,16 +324,25 @@ void ExprAttrs::bindVars(const std::shared_ptr<const StaticEnv> &env)
for (auto & i : attrs)
i.second.e->bindVars(i.second.inherited ? env : newEnv);
+
+ for (auto & i : dynamicAttrs) {
+ i.nameExpr->bindVars(newEnv);
+ i.valueExpr->bindVars(newEnv);
+ }
}
- else
+ else {
for (auto & i : attrs)
i.second.e->bindVars(env);
- for (auto & i : dynamicAttrs) {
- i.nameExpr->bindVars(newEnv);
- i.valueExpr->bindVars(newEnv);
+ for (auto & i : dynamicAttrs) {
+ i.nameExpr->bindVars(env);
+ i.valueExpr->bindVars(env);
+ }
}
+
+ std::cout << "ExprAttrs::bindVars end" << std::endl;
+
}
void ExprList::bindVars(const std::shared_ptr<const StaticEnv> &env)
@@ -375,6 +386,7 @@ void ExprLet::bindVars(const std::shared_ptr<const StaticEnv> &env)
void ExprWith::bindVars(const std::shared_ptr<const StaticEnv> &env)
{
+ std::cout << " ExprWith::bindVars " << std::endl;
/* Does this `with' have an enclosing `with'? If so, record its
level so that `lookupVar' can look up variables in the previous
`with' if this one doesn't contain the desired attribute. */
@@ -387,9 +399,23 @@ void ExprWith::bindVars(const std::shared_ptr<const StaticEnv> &env)
break;
}
+ std::cout << " ExprWith::bindVars 1" << std::endl;
+ attrs->show(std::cout);
+ std::cout << std::endl;
attrs->bindVars(env);
auto newEnv = std::shared_ptr<StaticEnv>(new StaticEnv(false, env.get())); // also make shared_ptr?
+ std::cout << " ExprWith::bindVars 2" << std::endl;
+ std::cout << " body: " << std::endl;
+ body->show(std::cout);
+ std::cout << std::endl;
+
+ std::cout << "ExprWith::newenv: " << newEnv->vars.size() << std::endl;
+ for (auto i = newEnv->vars.begin(); i != newEnv->vars.end(); ++i)
+ std::cout << "EvalState::parse newEnv " << i->first << std::endl;
+
+
body->bindVars(newEnv);
+ std::cout << " ExprWith::bindVars 3" << std::endl;
}
void ExprIf::bindVars(const std::shared_ptr<const StaticEnv> &env)
diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh
index 4c55cb64b..ce3ee9f4d 100644
--- a/src/libexpr/nixexpr.hh
+++ b/src/libexpr/nixexpr.hh
@@ -20,6 +20,7 @@ MakeError(UndefinedVarError, Error);
MakeError(MissingArgumentError, EvalError);
MakeError(RestrictedPathError, Error);
+extern std::function<void(const Error & error, const Env & env)> debuggerHook;
/* Position objects. */
diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y
index d1e898677..a3432eb32 100644
--- a/src/libexpr/parser.y
+++ b/src/libexpr/parser.y
@@ -22,6 +22,8 @@
#include "eval.hh"
#include "globals.hh"
+#include <iostream>
+
namespace nix {
struct ParseData
@@ -572,6 +574,10 @@ namespace nix {
Expr * EvalState::parse(const char * text, FileOrigin origin,
const Path & path, const Path & basePath, std::shared_ptr<StaticEnv> & staticEnv)
{
+ std::cout << "EvalState::parse " << std::endl;
+ for (auto i = staticEnv->vars.begin(); i != staticEnv->vars.end(); ++i)
+ std::cout << "EvalState::parse staticEnv " << i->first << std::endl;
+
yyscan_t scanner;
ParseData data(*this);
data.origin = origin;
@@ -595,8 +601,13 @@ Expr * EvalState::parse(const char * text, FileOrigin origin,
if (res) throw ParseError(data.error.value());
+
+ std::cout << "EvalState::parse pre bindvars " << std::endl;
+
data.result->bindVars(staticEnv);
+ std::cout << "EvalState::parse post bindVars " << std::endl;
+
return data.result;
}
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 0400c8942..7a277a7f5 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -110,6 +110,8 @@ static void mkOutputString(EvalState & state, Value & v,
argument. */
static void import(EvalState & state, const Pos & pos, Value & vPath, Value * vScope, Value & v)
{
+ std::cout << " import " << std::endl;
+
PathSet context;
Path path = state.coerceToPath(pos, vPath, context);
@@ -194,6 +196,8 @@ static void import(EvalState & state, const Pos & pos, Value & vPath, Value * vS
env->values[displ++] = attr.value;
}
+ std::cout << "import staticenv: {} " << staticEnv << std::endl;
+
printTalkative("evaluating file '%1%'", realPath);
Expr * e = state.parseExprFromFile(resolveExprPath(realPath), staticEnv);