From 01e58adce0767f1a484d80fcbcf67c7945cbc146 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 7 May 2010 12:43:57 +0000 Subject: [PATCH] * Store position info for inherited attributes. --- src/libexpr/eval.cc | 22 ++++++++++++---------- src/libexpr/nixexpr.cc | 24 ++++++++++++------------ src/libexpr/nixexpr.hh | 3 ++- src/libexpr/parser.y | 5 +++-- 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index b8ec410f3..69632eb37 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -430,11 +430,12 @@ void ExprAttrs::eval(EvalState & state, Env & env, Value & v) /* The inherited attributes, on the other hand, are evaluated in the original environment. */ - foreach (list::iterator, i, inherited) { - Value & v2 = (*v.attrs)[i->name].value; - Value * v3 = state.lookupVar(&env, *i); - mkCopy(v2, *v3); - mkCopy(env2.values[displ++], *v3); + foreach (list::iterator, i, inherited) { + nix::Attr & a = (*v.attrs)[i->first.name]; + Value * v2 = state.lookupVar(&env, i->first); + mkCopy(a.value, *v2); + mkCopy(env2.values[displ++], *v2); + a.pos = &i->second; } } @@ -446,9 +447,10 @@ void ExprAttrs::eval(EvalState & state, Env & env, Value & v) a.pos = &i->second.second; } - foreach (list::iterator, i, inherited) { - Value & v2 = (*v.attrs)[i->name].value; - mkCopy(v2, *state.lookupVar(&env, *i)); + foreach (list::iterator, i, inherited) { + nix::Attr & a = (*v.attrs)[i->first.name]; + mkCopy(a.value, *state.lookupVar(&env, i->first)); + a.pos = &i->second; } } } @@ -470,8 +472,8 @@ void ExprLet::eval(EvalState & state, Env & env, Value & v) /* The inherited attributes, on the other hand, are evaluated in the original environment. */ - foreach (list::iterator, i, attrs->inherited) - mkCopy(env2.values[displ++], *state.lookupVar(&env, *i)); + foreach (list::iterator, i, attrs->inherited) + mkCopy(env2.values[displ++], *state.lookupVar(&env, i->first)); state.eval(env2, body, v); } diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index af0632a94..898fdb609 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -55,8 +55,8 @@ void ExprAttrs::show(std::ostream & str) { if (recursive) str << "rec "; str << "{ "; - foreach (list::iterator, i, inherited) - str << "inherit " << i->name << "; "; + foreach (list::iterator, i, inherited) + str << "inherit " << i->first.name << "; "; foreach (Attrs::iterator, i, attrs) str << i->first << " = " << *i->second.first << "; "; str << "}"; @@ -91,8 +91,8 @@ void ExprLambda::show(std::ostream & str) void ExprLet::show(std::ostream & str) { str << "let "; - foreach (list::iterator, i, attrs->inherited) - str << "inherit " << i->name << "; "; + foreach (list::iterator, i, attrs->inherited) + str << "inherit " << i->first.name << "; "; foreach (ExprAttrs::Attrs::iterator, i, attrs->attrs) str << i->first << " = " << *i->second.first << "; "; str << "in " << *body; @@ -215,9 +215,9 @@ void ExprAttrs::bindVars(const StaticEnv & env) foreach (ExprAttrs::Attrs::iterator, i, attrs) newEnv.vars[i->first] = displ++; - foreach (list::iterator, i, inherited) { - newEnv.vars[i->name] = displ++; - i->bind(env); + foreach (list::iterator, i, inherited) { + newEnv.vars[i->first.name] = displ++; + i->first.bind(env); } foreach (ExprAttrs::Attrs::iterator, i, attrs) @@ -228,8 +228,8 @@ void ExprAttrs::bindVars(const StaticEnv & env) foreach (ExprAttrs::Attrs::iterator, i, attrs) i->second.first->bindVars(env); - foreach (list::iterator, i, inherited) - i->bind(env); + foreach (list::iterator, i, inherited) + i->first.bind(env); } } @@ -267,9 +267,9 @@ void ExprLet::bindVars(const StaticEnv & env) foreach (ExprAttrs::Attrs::iterator, i, attrs->attrs) newEnv.vars[i->first] = displ++; - foreach (list::iterator, i, attrs->inherited) { - newEnv.vars[i->name] = displ++; - i->bind(env); + foreach (list::iterator, i, attrs->inherited) { + newEnv.vars[i->first.name] = displ++; + i->first.bind(env); } foreach (ExprAttrs::Attrs::iterator, i, attrs->attrs) diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh index 36cb4e53c..1c72441b2 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/nixexpr.hh @@ -131,9 +131,10 @@ struct ExprAttrs : Expr { bool recursive; typedef std::pair Attr; + typedef std::pair Inherited; typedef std::map Attrs; Attrs attrs; - list inherited; + list inherited; std::map attrNames; // used during parsing ExprAttrs() : recursive(false) { }; COMMON_METHODS diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index 99980240f..7236bab19 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -377,8 +377,9 @@ binds foreach (vector::iterator, i, *$3) { if ($$->attrNames.find(*i) != $$->attrNames.end()) dupAttr(*i, makeCurPos(@3, data), $$->attrNames[*i]); - $$->inherited.push_back(*i); - $$->attrNames[*i] = makeCurPos(@3, data); + Pos pos = makeCurPos(@3, data); + $$->inherited.push_back(ExprAttrs::Inherited(*i, pos)); + $$->attrNames[*i] = pos; } } | binds INHERIT '(' expr ')' ids ';'