Elaborate implicit chaining of constructors in class new.

This commit is contained in:
Stephen Williams 2013-11-02 15:00:40 -07:00
parent 9f83882bcc
commit 0157a156fb
2 changed files with 32 additions and 8 deletions

View File

@ -555,6 +555,11 @@ class PENewClass : public PExpr {
virtual NetExpr*elaborate_expr(Design*des, NetScope*scope,
ivl_type_t type, unsigned flags) const;
private:
NetExpr* elaborate_expr_constructor_(Design*des, NetScope*scope,
const netclass_t*ctype,
NetExpr*obj, unsigned flags) const;
private:
std::vector<PExpr*>parms_;
};

View File

@ -4675,16 +4675,19 @@ unsigned PENewClass::test_width(Design*, NetScope*, width_mode_t&)
return 1;
}
NetExpr* PENewClass::elaborate_expr(Design*des, NetScope*scope,
ivl_type_t ntype, unsigned) const
/*
* This elaborates the constructor for a class. This arranges for the
* call of parent class constructors, if present, and also
* initializers in front of an explicit constructor.
*/
NetExpr* PENewClass::elaborate_expr_constructor_(Design*des, NetScope*scope,
const netclass_t*ctype,
NetExpr*obj, unsigned flags) const
{
NetExpr*obj = new NetENew(ntype);
obj->set_line(*this);
if (const netclass_t*super_class = ctype->get_super()) {
obj = elaborate_expr_constructor_(des, scope, super_class, obj, flags);
}
// Find the constructor for the class. If there is no
// constructor then the result of this expression is the
// allocation alone.
const netclass_t*ctype = dynamic_cast<const netclass_t*> (ntype);
// If there is an initializer function, then pass the object
// through that function first. Note tha the initializer
@ -4720,6 +4723,7 @@ NetExpr* PENewClass::elaborate_expr(Design*des, NetScope*scope,
return obj;
}
NetFuncDef*def = new_scope->func_def();
ivl_assert(*this, def);
@ -4786,6 +4790,21 @@ NetExpr* PENewClass::elaborate_expr(Design*des, NetScope*scope,
return con;
}
NetExpr* PENewClass::elaborate_expr(Design*des, NetScope*scope,
ivl_type_t ntype, unsigned flags) const
{
NetExpr*obj = new NetENew(ntype);
obj->set_line(*this);
// Find the constructor for the class. If there is no
// constructor then the result of this expression is the
// allocation alone.
const netclass_t*ctype = dynamic_cast<const netclass_t*> (ntype);
obj = elaborate_expr_constructor_(des, scope, ctype, obj, flags);
return obj;
}
unsigned PENewCopy::test_width(Design*, NetScope*, width_mode_t&)
{
expr_type_ = IVL_VT_CLASS;