forked from lix-project/lix
WIP: give ExprInheritFrom a handle to what its standing in for
This commit is contained in:
parent
e7517419a6
commit
3f6bfcc930
|
@ -144,7 +144,10 @@ struct ExprVar : Expr
|
||||||
*/
|
*/
|
||||||
struct ExprInheritFrom : ExprVar
|
struct ExprInheritFrom : ExprVar
|
||||||
{
|
{
|
||||||
ExprInheritFrom(PosIdx pos, Displacement displ): ExprVar(pos, {})
|
std::shared_ptr<Expr> fromExpr;
|
||||||
|
|
||||||
|
ExprInheritFrom(PosIdx pos, Displacement displ, std::shared_ptr<Expr> fromExpr)
|
||||||
|
: ExprVar(pos, {}), fromExpr(fromExpr)
|
||||||
{
|
{
|
||||||
this->level = 0;
|
this->level = 0;
|
||||||
this->displ = displ;
|
this->displ = displ;
|
||||||
|
@ -222,7 +225,7 @@ struct ExprAttrs : Expr
|
||||||
};
|
};
|
||||||
typedef std::map<Symbol, AttrDef> AttrDefs;
|
typedef std::map<Symbol, AttrDef> AttrDefs;
|
||||||
AttrDefs attrs;
|
AttrDefs attrs;
|
||||||
std::unique_ptr<std::vector<std::unique_ptr<Expr>>> inheritFromExprs;
|
std::unique_ptr<std::vector<std::shared_ptr<Expr>>> inheritFromExprs;
|
||||||
struct DynamicAttrDef {
|
struct DynamicAttrDef {
|
||||||
std::unique_ptr<Expr> nameExpr, valueExpr;
|
std::unique_ptr<Expr> nameExpr, valueExpr;
|
||||||
PosIdx pos;
|
PosIdx pos;
|
||||||
|
|
|
@ -317,18 +317,23 @@ template<> struct BuildAST<grammar::inherit> : change_head<InheritState> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (auto fromE = std::move(s.from)) {
|
if (s.from != nullptr) {
|
||||||
if (!b.attrs.inheritFromExprs)
|
if (!b.attrs.inheritFromExprs)
|
||||||
b.attrs.inheritFromExprs = std::make_unique<std::vector<std::unique_ptr<Expr>>>();
|
b.attrs.inheritFromExprs = std::make_unique<std::vector<std::shared_ptr<Expr>>>();
|
||||||
b.attrs.inheritFromExprs->push_back(std::move(fromE));
|
std::shared_ptr<Expr> fromExpr = std::move(s.from);
|
||||||
|
b.attrs.inheritFromExprs->push_back(fromExpr);
|
||||||
for (auto & [i, iPos] : s.attrs) {
|
for (auto & [i, iPos] : s.attrs) {
|
||||||
if (attrs.find(i.symbol) != attrs.end())
|
if (attrs.find(i.symbol) != attrs.end())
|
||||||
ps.dupAttr(i.symbol, iPos, attrs[i.symbol].pos);
|
ps.dupAttr(i.symbol, iPos, attrs[i.symbol].pos);
|
||||||
auto from = std::make_unique<ExprInheritFrom>(s.fromPos, b.attrs.inheritFromExprs->size() - 1);
|
auto inheritFrom = std::make_unique<ExprInheritFrom>(
|
||||||
|
s.fromPos,
|
||||||
|
b.attrs.inheritFromExprs->size() - 1,
|
||||||
|
fromExpr
|
||||||
|
);
|
||||||
attrs.emplace(
|
attrs.emplace(
|
||||||
i.symbol,
|
i.symbol,
|
||||||
ExprAttrs::AttrDef(
|
ExprAttrs::AttrDef(
|
||||||
std::make_unique<ExprSelect>(iPos, std::move(from), i.symbol),
|
std::make_unique<ExprSelect>(iPos, std::move(inheritFrom), i.symbol),
|
||||||
iPos,
|
iPos,
|
||||||
ExprAttrs::AttrDef::Kind::InheritedFrom));
|
ExprAttrs::AttrDef::Kind::InheritedFrom));
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,7 +103,7 @@ inline void State::addAttr(ExprAttrs * attrs, AttrPath && attrPath, std::unique_
|
||||||
auto * jAttrs = dynamic_cast<ExprAttrs *>(j->second.e.get());
|
auto * jAttrs = dynamic_cast<ExprAttrs *>(j->second.e.get());
|
||||||
if (jAttrs && ae) {
|
if (jAttrs && ae) {
|
||||||
if (ae->inheritFromExprs && !jAttrs->inheritFromExprs)
|
if (ae->inheritFromExprs && !jAttrs->inheritFromExprs)
|
||||||
jAttrs->inheritFromExprs = std::make_unique<std::vector<std::unique_ptr<Expr>>>();
|
jAttrs->inheritFromExprs = std::make_unique<std::vector<std::shared_ptr<Expr>>>();
|
||||||
for (auto & ad : ae->attrs) {
|
for (auto & ad : ae->attrs) {
|
||||||
auto j2 = jAttrs->attrs.find(ad.first);
|
auto j2 = jAttrs->attrs.find(ad.first);
|
||||||
if (j2 != jAttrs->attrs.end()) // Attr already defined in iAttrs, error.
|
if (j2 != jAttrs->attrs.end()) // Attr already defined in iAttrs, error.
|
||||||
|
|
Loading…
Reference in a new issue