From 07543315cfdf66ac0e49244374f763cdd52a215f Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 23 Aug 2016 17:12:36 +0200 Subject: [PATCH] vhdlpp: Stricter array type matching Arrays type match if they have a common parent, instead of the element type. Now (un)signed & std_logic_vector types do not match, as it should be in VHDL. --- vhdlpp/vtype.h | 2 ++ vhdlpp/vtype_match.cc | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/vhdlpp/vtype.h b/vhdlpp/vtype.h index a0576c51f..4f34c62ac 100644 --- a/vhdlpp/vtype.h +++ b/vhdlpp/vtype.h @@ -253,6 +253,8 @@ class VTypeArray : public VType { // To handle subtypes inline void set_parent_type(const VTypeArray*parent) { parent_ = parent; } + const VTypeArray*get_parent_type() const { return parent_; } + // Wherever it is possible, replaces range lsb & msb expressions with // constant integers. void evaluate_ranges(ScopeBase*scope); diff --git a/vhdlpp/vtype_match.cc b/vhdlpp/vtype_match.cc index a4a49b1b5..c99a2fd78 100644 --- a/vhdlpp/vtype_match.cc +++ b/vhdlpp/vtype_match.cc @@ -70,7 +70,15 @@ bool VTypeArray::type_match(const VType*that) const // Check if both arrays are of the same size if(const VTypeArray*arr = dynamic_cast(that)) { - if(!element_type()->type_match(arr->element_type())) + const VTypeArray*this_parent = this; + while(const VTypeArray*tmp = this_parent->get_parent_type()) + this_parent = tmp; + + const VTypeArray*that_parent = arr; + while(const VTypeArray*tmp = that_parent->get_parent_type()) + that_parent = tmp; + + if(this_parent != that_parent) return false; int this_width = get_width(NULL);