* Store position info for inherited attributes.
This commit is contained in:
parent
83d7b89660
commit
01e58adce0
|
@ -430,11 +430,12 @@ void ExprAttrs::eval(EvalState & state, Env & env, Value & v)
|
||||||
|
|
||||||
/* The inherited attributes, on the other hand, are
|
/* The inherited attributes, on the other hand, are
|
||||||
evaluated in the original environment. */
|
evaluated in the original environment. */
|
||||||
foreach (list<VarRef>::iterator, i, inherited) {
|
foreach (list<Inherited>::iterator, i, inherited) {
|
||||||
Value & v2 = (*v.attrs)[i->name].value;
|
nix::Attr & a = (*v.attrs)[i->first.name];
|
||||||
Value * v3 = state.lookupVar(&env, *i);
|
Value * v2 = state.lookupVar(&env, i->first);
|
||||||
mkCopy(v2, *v3);
|
mkCopy(a.value, *v2);
|
||||||
mkCopy(env2.values[displ++], *v3);
|
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;
|
a.pos = &i->second.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (list<VarRef>::iterator, i, inherited) {
|
foreach (list<Inherited>::iterator, i, inherited) {
|
||||||
Value & v2 = (*v.attrs)[i->name].value;
|
nix::Attr & a = (*v.attrs)[i->first.name];
|
||||||
mkCopy(v2, *state.lookupVar(&env, *i));
|
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 inherited attributes, on the other hand, are evaluated in
|
||||||
the original environment. */
|
the original environment. */
|
||||||
foreach (list<VarRef>::iterator, i, attrs->inherited)
|
foreach (list<ExprAttrs::Inherited>::iterator, i, attrs->inherited)
|
||||||
mkCopy(env2.values[displ++], *state.lookupVar(&env, *i));
|
mkCopy(env2.values[displ++], *state.lookupVar(&env, i->first));
|
||||||
|
|
||||||
state.eval(env2, body, v);
|
state.eval(env2, body, v);
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,8 +55,8 @@ void ExprAttrs::show(std::ostream & str)
|
||||||
{
|
{
|
||||||
if (recursive) str << "rec ";
|
if (recursive) str << "rec ";
|
||||||
str << "{ ";
|
str << "{ ";
|
||||||
foreach (list<VarRef>::iterator, i, inherited)
|
foreach (list<Inherited>::iterator, i, inherited)
|
||||||
str << "inherit " << i->name << "; ";
|
str << "inherit " << i->first.name << "; ";
|
||||||
foreach (Attrs::iterator, i, attrs)
|
foreach (Attrs::iterator, i, attrs)
|
||||||
str << i->first << " = " << *i->second.first << "; ";
|
str << i->first << " = " << *i->second.first << "; ";
|
||||||
str << "}";
|
str << "}";
|
||||||
|
@ -91,8 +91,8 @@ void ExprLambda::show(std::ostream & str)
|
||||||
void ExprLet::show(std::ostream & str)
|
void ExprLet::show(std::ostream & str)
|
||||||
{
|
{
|
||||||
str << "let ";
|
str << "let ";
|
||||||
foreach (list<VarRef>::iterator, i, attrs->inherited)
|
foreach (list<ExprAttrs::Inherited>::iterator, i, attrs->inherited)
|
||||||
str << "inherit " << i->name << "; ";
|
str << "inherit " << i->first.name << "; ";
|
||||||
foreach (ExprAttrs::Attrs::iterator, i, attrs->attrs)
|
foreach (ExprAttrs::Attrs::iterator, i, attrs->attrs)
|
||||||
str << i->first << " = " << *i->second.first << "; ";
|
str << i->first << " = " << *i->second.first << "; ";
|
||||||
str << "in " << *body;
|
str << "in " << *body;
|
||||||
|
@ -215,9 +215,9 @@ void ExprAttrs::bindVars(const StaticEnv & env)
|
||||||
foreach (ExprAttrs::Attrs::iterator, i, attrs)
|
foreach (ExprAttrs::Attrs::iterator, i, attrs)
|
||||||
newEnv.vars[i->first] = displ++;
|
newEnv.vars[i->first] = displ++;
|
||||||
|
|
||||||
foreach (list<VarRef>::iterator, i, inherited) {
|
foreach (list<Inherited>::iterator, i, inherited) {
|
||||||
newEnv.vars[i->name] = displ++;
|
newEnv.vars[i->first.name] = displ++;
|
||||||
i->bind(env);
|
i->first.bind(env);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (ExprAttrs::Attrs::iterator, i, attrs)
|
foreach (ExprAttrs::Attrs::iterator, i, attrs)
|
||||||
|
@ -228,8 +228,8 @@ void ExprAttrs::bindVars(const StaticEnv & env)
|
||||||
foreach (ExprAttrs::Attrs::iterator, i, attrs)
|
foreach (ExprAttrs::Attrs::iterator, i, attrs)
|
||||||
i->second.first->bindVars(env);
|
i->second.first->bindVars(env);
|
||||||
|
|
||||||
foreach (list<VarRef>::iterator, i, inherited)
|
foreach (list<Inherited>::iterator, i, inherited)
|
||||||
i->bind(env);
|
i->first.bind(env);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,9 +267,9 @@ void ExprLet::bindVars(const StaticEnv & env)
|
||||||
foreach (ExprAttrs::Attrs::iterator, i, attrs->attrs)
|
foreach (ExprAttrs::Attrs::iterator, i, attrs->attrs)
|
||||||
newEnv.vars[i->first] = displ++;
|
newEnv.vars[i->first] = displ++;
|
||||||
|
|
||||||
foreach (list<VarRef>::iterator, i, attrs->inherited) {
|
foreach (list<ExprAttrs::Inherited>::iterator, i, attrs->inherited) {
|
||||||
newEnv.vars[i->name] = displ++;
|
newEnv.vars[i->first.name] = displ++;
|
||||||
i->bind(env);
|
i->first.bind(env);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (ExprAttrs::Attrs::iterator, i, attrs->attrs)
|
foreach (ExprAttrs::Attrs::iterator, i, attrs->attrs)
|
||||||
|
|
|
@ -131,9 +131,10 @@ struct ExprAttrs : Expr
|
||||||
{
|
{
|
||||||
bool recursive;
|
bool recursive;
|
||||||
typedef std::pair<Expr *, Pos> Attr;
|
typedef std::pair<Expr *, Pos> Attr;
|
||||||
|
typedef std::pair<VarRef, Pos> Inherited;
|
||||||
typedef std::map<Symbol, Attr> Attrs;
|
typedef std::map<Symbol, Attr> Attrs;
|
||||||
Attrs attrs;
|
Attrs attrs;
|
||||||
list<VarRef> inherited;
|
list<Inherited> inherited;
|
||||||
std::map<Symbol, Pos> attrNames; // used during parsing
|
std::map<Symbol, Pos> attrNames; // used during parsing
|
||||||
ExprAttrs() : recursive(false) { };
|
ExprAttrs() : recursive(false) { };
|
||||||
COMMON_METHODS
|
COMMON_METHODS
|
||||||
|
|
|
@ -377,8 +377,9 @@ binds
|
||||||
foreach (vector<Symbol>::iterator, i, *$3) {
|
foreach (vector<Symbol>::iterator, i, *$3) {
|
||||||
if ($$->attrNames.find(*i) != $$->attrNames.end())
|
if ($$->attrNames.find(*i) != $$->attrNames.end())
|
||||||
dupAttr(*i, makeCurPos(@3, data), $$->attrNames[*i]);
|
dupAttr(*i, makeCurPos(@3, data), $$->attrNames[*i]);
|
||||||
$$->inherited.push_back(*i);
|
Pos pos = makeCurPos(@3, data);
|
||||||
$$->attrNames[*i] = makeCurPos(@3, data);
|
$$->inherited.push_back(ExprAttrs::Inherited(*i, pos));
|
||||||
|
$$->attrNames[*i] = pos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
| binds INHERIT '(' expr ')' ids ';'
|
| binds INHERIT '(' expr ')' ids ';'
|
||||||
|
|
Loading…
Reference in a new issue