From 774609fbbb0401ed4a51d30c205d88b402908088 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 23 Jan 2015 17:07:19 +0100 Subject: [PATCH] vhdlpp: VTypeArray stores parent type, in case it is a subtype. --- vhdlpp/parse_misc.cc | 1 + vhdlpp/vtype.cc | 4 ++-- vhdlpp/vtype.h | 6 +++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/vhdlpp/parse_misc.cc b/vhdlpp/parse_misc.cc index 734443d3e..f49a631c3 100644 --- a/vhdlpp/parse_misc.cc +++ b/vhdlpp/parse_misc.cc @@ -105,6 +105,7 @@ static const VType* calculate_subtype_array(const YYLTYPE&loc, const char*base_n VTypeArray*subtype = new VTypeArray(element, range, base_array->signed_vector()); + subtype->set_parent_type(base_array); return subtype; } diff --git a/vhdlpp/vtype.cc b/vhdlpp/vtype.cc index ea3341ce7..6e8ac00dd 100644 --- a/vhdlpp/vtype.cc +++ b/vhdlpp/vtype.cc @@ -77,7 +77,7 @@ void VTypePrimitive::show(ostream&out) const } VTypeArray::VTypeArray(const VType*element, const vector&r, bool sv) -: etype_(element), ranges_(r), signed_flag_(sv) +: etype_(element), ranges_(r), signed_flag_(sv), parent_(NULL) { } @@ -89,7 +89,7 @@ VTypeArray::VTypeArray(const VType*element, const vector&r, * this is a memory leak. Something to fix. */ VTypeArray::VTypeArray(const VType*element, std::list*r, bool sv) -: etype_(element), ranges_(r->size()), signed_flag_(sv) +: etype_(element), ranges_(r->size()), signed_flag_(sv), parent_(NULL) { for (size_t idx = 0 ; idx < ranges_.size() ; idx += 1) { prange_t*curp = r->front(); diff --git a/vhdlpp/vtype.h b/vhdlpp/vtype.h index 5310e868a..a98c81a5d 100644 --- a/vhdlpp/vtype.h +++ b/vhdlpp/vtype.h @@ -212,7 +212,7 @@ class VTypeArray : public VType { inline bool signed_vector() const { return signed_flag_; } // returns the type of element held in the array - inline const VType* element_type() const { return etype_; } + inline const VType* element_type() const { return parent_ ? parent_->element_type() : etype_; } // returns the basic type of element held in the array // (unfolds typedefs and multidimensional arrays) @@ -227,6 +227,9 @@ class VTypeArray : public VType { bool is_unbounded() const; + // To handle subtypes + inline void set_parent_type(const VTypeArray*parent) { parent_ = parent; } + private: int emit_with_dims_(std::ostream&out, bool packed, perm_string name) const; @@ -235,6 +238,7 @@ class VTypeArray : public VType { std::vector ranges_; bool signed_flag_; + const VTypeArray*parent_; }; class VTypeRange : public VType {