aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr
diff options
context:
space:
mode:
authorBen Burdette <bburdette@gmail.com>2021-09-13 11:57:25 -0600
committerBen Burdette <bburdette@gmail.com>2021-09-13 11:57:25 -0600
commit176911102ce2c0be06bbfed9099f364d71c3c679 (patch)
treee8b0c12410c5126d57313601ba73c0afdc5e8851 /src/libexpr
parent310c689d317d1eb4bcf50cd11d84165fe2ffd512 (diff)
printEnvPosChain
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/eval.cc34
-rw-r--r--src/libexpr/eval.hh1
2 files changed, 31 insertions, 4 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index c6fb052f4..19379b876 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -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();
diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh
index ca3a7b742..c96e2c726 100644
--- a/src/libexpr/eval.hh
+++ b/src/libexpr/eval.hh
@@ -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());