From 045d9e7117b0df2ba5dd0683f0d6c7ff10972ba6 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 12 Feb 2016 15:17:03 +0100 Subject: [PATCH] vhdlpp: Improved type matching rules. --- vhdlpp/expression_elaborate.cc | 4 +++- vhdlpp/vtype.h | 3 +++ vhdlpp/vtype_match.cc | 7 +++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/vhdlpp/expression_elaborate.cc b/vhdlpp/expression_elaborate.cc index fa6a16841..e11a5e328 100644 --- a/vhdlpp/expression_elaborate.cc +++ b/vhdlpp/expression_elaborate.cc @@ -350,8 +350,10 @@ const VType* ExpBinary::probe_type(Entity*ent, ScopeBase*scope) const if (t2 == 0) return t1; - if (t1 == t2) + if (t1->type_match(t2)) return t1; + if (t2->type_match(t1)) + return t2; if (const VType*tb = resolve_operand_types_(t1, t2)) return tb; diff --git a/vhdlpp/vtype.h b/vhdlpp/vtype.h index fc1d52c0e..89b794a13 100644 --- a/vhdlpp/vtype.h +++ b/vhdlpp/vtype.h @@ -295,6 +295,9 @@ class VTypeRangeConst : public VTypeRange { return new VTypeRangeConst(base_type()->clone(), start_, end_); } + int64_t start() const { return start_; } + int64_t end() const { return end_; } + void write_to_stream(std::ostream&fd) const; private: diff --git a/vhdlpp/vtype_match.cc b/vhdlpp/vtype_match.cc index 459217879..3ceb4b231 100644 --- a/vhdlpp/vtype_match.cc +++ b/vhdlpp/vtype_match.cc @@ -53,6 +53,13 @@ bool VTypePrimitive::type_match(const VType*that) const (that_type == NATURAL || that_type == INTEGER)); } + if(const VTypeRangeConst*range = dynamic_cast(that)) { + if (type_ == INTEGER) + return true; + if (type_ == NATURAL && range->start() >= 0 && range->end() >= 0) + return true; + } + return false; }