vhdlpp: Added VTypeArray::basic_type() to cope with
arrays based on typedefs.
This commit is contained in:
parent
22d18cb28d
commit
cb03802a17
|
|
@ -767,7 +767,7 @@ int ExpString::emit_as_array_(ostream& out, Entity*, Architecture*, const VTypeA
|
|||
int errors = 0;
|
||||
assert(arr->dimensions() == 1);
|
||||
|
||||
const VTypePrimitive*etype = dynamic_cast<const VTypePrimitive*> (arr->element_type());
|
||||
const VTypePrimitive*etype = dynamic_cast<const VTypePrimitive*> (arr->basic_type());
|
||||
assert(etype);
|
||||
|
||||
// Detect the special case that this is an array of
|
||||
|
|
|
|||
|
|
@ -98,6 +98,29 @@ VTypeArray::~VTypeArray()
|
|||
{
|
||||
}
|
||||
|
||||
const VType* VTypeArray::basic_type(bool typedef_allowed) const
|
||||
{
|
||||
const VType*t = etype_;
|
||||
const VTypeDef*tdef = NULL;
|
||||
bool progress = false;
|
||||
|
||||
do {
|
||||
progress = false;
|
||||
|
||||
if((tdef = dynamic_cast<const VTypeDef*>(t))) {
|
||||
t = tdef->peek_definition();
|
||||
}
|
||||
|
||||
if(const VTypeArray*arr = dynamic_cast<const VTypeArray*>(t)) {
|
||||
t = arr->element_type();
|
||||
progress = true;
|
||||
} else if(tdef) { // return the typedef if it does not define an array
|
||||
t = typedef_allowed ? tdef : tdef->peek_definition();
|
||||
}
|
||||
} while(progress);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
void VTypeArray::show(ostream&out) const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -206,6 +206,12 @@ class VTypeArray : public VType {
|
|||
// returns the type of element held in the array
|
||||
inline const VType* element_type() const { return etype_; }
|
||||
|
||||
// returns the basic type of element held in the array
|
||||
// (unfolds typedefs and multidimensional arrays)
|
||||
// typedef_allowed decides if VTypeDef can be returned or should
|
||||
// it be unfolded
|
||||
const VType* basic_type(bool typedef_allowed = true) const;
|
||||
|
||||
int emit_def(std::ostream&out, perm_string name) const;
|
||||
int emit_typedef(std::ostream&out, typedef_context_t&ctx) const;
|
||||
int emit_dimensions(std::ostream&out) const;
|
||||
|
|
|
|||
|
|
@ -60,12 +60,8 @@ int VTypeArray::emit_def(ostream&out, perm_string name) const
|
|||
{
|
||||
int errors = 0;
|
||||
|
||||
const VTypeArray*cur = this;
|
||||
while (const VTypeArray*sub = dynamic_cast<const VTypeArray*> (cur->etype_)) {
|
||||
cur = sub;
|
||||
}
|
||||
const VType*raw_base = basic_type();
|
||||
|
||||
const VType*raw_base = cur->etype_;
|
||||
const VTypePrimitive*base = dynamic_cast<const VTypePrimitive*> (raw_base);
|
||||
|
||||
if (base) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue