The expr of AttrNames/DynamicAttrDefs is always an ExprConcatStrings
This commit is contained in:
parent
908e9ce259
commit
049a379ec6
3 changed files with 10 additions and 12 deletions
|
@ -642,15 +642,13 @@ void ExprAttrs::eval(EvalState & state, Env & env, Value & v)
|
||||||
/* dynamic attrs apply *after* rec and __overrides */
|
/* dynamic attrs apply *after* rec and __overrides */
|
||||||
foreach (DynamicAttrDefs::iterator, i, dynamicAttrs) {
|
foreach (DynamicAttrDefs::iterator, i, dynamicAttrs) {
|
||||||
Value nameVal;
|
Value nameVal;
|
||||||
assert(dynamic_cast<ExprConcatStrings *>(i->nameExpr));
|
if (i->nameExpr->es->size() == 1) {
|
||||||
ExprConcatStrings * nameExpr = static_cast<ExprConcatStrings *>(i->nameExpr);
|
i->nameExpr->es->front()->eval(state, *dynamicEnv, nameVal);
|
||||||
if (nameExpr->es->size() == 1) {
|
|
||||||
nameExpr->es->front()->eval(state, *dynamicEnv, nameVal);
|
|
||||||
state.forceValue(nameVal);
|
state.forceValue(nameVal);
|
||||||
if (nameVal.type == tNull)
|
if (nameVal.type == tNull)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
nameExpr->eval(state, *dynamicEnv, nameVal);
|
i->nameExpr->eval(state, *dynamicEnv, nameVal);
|
||||||
state.forceStringNoCtx(nameVal);
|
state.forceStringNoCtx(nameVal);
|
||||||
Symbol nameSym = state.symbols.create(nameVal.string.s);
|
Symbol nameSym = state.symbols.create(nameVal.string.s);
|
||||||
Bindings::iterator j = v.attrs->find(nameSym);
|
Bindings::iterator j = v.attrs->find(nameSym);
|
||||||
|
|
|
@ -50,16 +50,16 @@ struct Env;
|
||||||
struct Value;
|
struct Value;
|
||||||
class EvalState;
|
class EvalState;
|
||||||
struct StaticEnv;
|
struct StaticEnv;
|
||||||
struct Expr;
|
struct ExprConcatStrings;
|
||||||
|
|
||||||
|
|
||||||
/* An attribute path is a sequence of attribute names. */
|
/* An attribute path is a sequence of attribute names. */
|
||||||
struct AttrName
|
struct AttrName
|
||||||
{
|
{
|
||||||
Symbol symbol;
|
Symbol symbol;
|
||||||
Expr *expr;
|
ExprConcatStrings * expr;
|
||||||
AttrName(const Symbol & s) : symbol(s) {};
|
AttrName(const Symbol & s) : symbol(s) {};
|
||||||
AttrName(Expr *e) : expr(e) {};
|
AttrName(ExprConcatStrings * e) : expr(e) {};
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<AttrName> AttrPath;
|
typedef std::vector<AttrName> AttrPath;
|
||||||
|
@ -174,10 +174,10 @@ struct ExprAttrs : Expr
|
||||||
typedef std::map<Symbol, AttrDef> AttrDefs;
|
typedef std::map<Symbol, AttrDef> AttrDefs;
|
||||||
AttrDefs attrs;
|
AttrDefs attrs;
|
||||||
struct DynamicAttrDef {
|
struct DynamicAttrDef {
|
||||||
Expr * nameExpr;
|
ExprConcatStrings * nameExpr;
|
||||||
Expr * valueExpr;
|
Expr * valueExpr;
|
||||||
Pos pos;
|
Pos pos;
|
||||||
DynamicAttrDef(Expr * nameExpr, Expr * valueExpr, const Pos & pos) : nameExpr(nameExpr), valueExpr(valueExpr), pos(pos) { };
|
DynamicAttrDef(ExprConcatStrings * nameExpr, Expr * valueExpr, const Pos & pos) : nameExpr(nameExpr), valueExpr(valueExpr), pos(pos) { };
|
||||||
};
|
};
|
||||||
typedef std::vector<DynamicAttrDef> DynamicAttrDefs;
|
typedef std::vector<DynamicAttrDef> DynamicAttrDefs;
|
||||||
DynamicAttrDefs dynamicAttrs;
|
DynamicAttrDefs dynamicAttrs;
|
||||||
|
|
|
@ -488,7 +488,7 @@ attrpath
|
||||||
$$->push_back(AttrName(str->s));
|
$$->push_back(AttrName(str->s));
|
||||||
delete str;
|
delete str;
|
||||||
} else
|
} else
|
||||||
$$->push_back(AttrName($3));
|
$$->push_back(AttrName(static_cast<ExprConcatStrings *>($3)));
|
||||||
}
|
}
|
||||||
| attr { $$ = new vector<AttrName>; $$->push_back(AttrName(data->symbols.create($1))); }
|
| attr { $$ = new vector<AttrName>; $$->push_back(AttrName(data->symbols.create($1))); }
|
||||||
| string_attr
|
| string_attr
|
||||||
|
@ -498,7 +498,7 @@ attrpath
|
||||||
$$->push_back(AttrName(str->s));
|
$$->push_back(AttrName(str->s));
|
||||||
delete str;
|
delete str;
|
||||||
} else
|
} else
|
||||||
$$->push_back(AttrName($1));
|
$$->push_back(AttrName(static_cast<ExprConcatStrings *>($1)));
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue