diff --git a/vhdlpp/sequential.h b/vhdlpp/sequential.h index 612a19b73..13a3f5947 100644 --- a/vhdlpp/sequential.h +++ b/vhdlpp/sequential.h @@ -135,6 +135,7 @@ class ReturnStmt : public SequentialStmt { ~ReturnStmt(); public: + int elaborate(Entity*ent, ScopeBase*scope); int emit(ostream&out, Entity*entity, ScopeBase*scope); void write_to_stream(std::ostream&fd); void dump(ostream&out, int indent) const; diff --git a/vhdlpp/sequential_elaborate.cc b/vhdlpp/sequential_elaborate.cc index 6756becaf..6509d6ae7 100644 --- a/vhdlpp/sequential_elaborate.cc +++ b/vhdlpp/sequential_elaborate.cc @@ -133,6 +133,22 @@ int IfSequential::Elsif::elaborate(Entity*ent, ScopeBase*scope) return errors; } +int ReturnStmt::elaborate(Entity*ent, ScopeBase*scope) +{ + const VType*ltype = NULL; + + // Try to determine the expression type by + // looking up the function return type. + const SubprogramBody*subp = dynamic_cast(scope); + if(subp) { + if(const SubprogramHeader*header = subp->header()) { + ltype = header->peek_return_type(); + } + } + + return val_->elaborate_expr(ent, scope, ltype); +} + int SignalSeqAssignment::elaborate(Entity*ent, ScopeBase*scope) { int errors = 0; diff --git a/vhdlpp/subprogram.h b/vhdlpp/subprogram.h index 50db83d86..c8898f86f 100644 --- a/vhdlpp/subprogram.h +++ b/vhdlpp/subprogram.h @@ -54,6 +54,8 @@ class SubprogramBody : public LineInfo, public ScopeBase { void write_to_stream(std::ostream&fd) const; void dump(std::ostream&fd) const; + const SubprogramHeader*header() const { return header_; } + private: std::list*statements_; SubprogramHeader*header_;