diff --git a/vhdlpp/package.cc b/vhdlpp/package.cc index d58f82093..c8ff5b466 100644 --- a/vhdlpp/package.cc +++ b/vhdlpp/package.cc @@ -53,6 +53,7 @@ int Package::elaborate() for(SubHeaderList::iterator it = subp_list.begin(); it != subp_list.end(); ++it) { + (*it)->set_package(this); errors += (*it)->elaborate(); } } diff --git a/vhdlpp/scope.cc b/vhdlpp/scope.cc index cbee2bea4..785ab1d98 100644 --- a/vhdlpp/scope.cc +++ b/vhdlpp/scope.cc @@ -317,11 +317,8 @@ SubprogramHeader*ScopeBase::match_subprogram(perm_string name, return NULL; } -void ActiveScope::set_package_header(Package*pkg) void ScopeBase::generate_name() { - assert(package_header_ == 0); - package_header_ = pkg; char buf[64]; // Generate a name for the scope diff --git a/vhdlpp/scope.h b/vhdlpp/scope.h index 4f1c13d47..5f88b384c 100644 --- a/vhdlpp/scope.h +++ b/vhdlpp/scope.h @@ -101,6 +101,11 @@ class ScopeBase { perm_string peek_name() const { return name_; } + void set_package_header(Package*pkg) { + assert(package_header_ == 0); + package_header_ = pkg; + } + protected: void cleanup(); @@ -158,6 +163,10 @@ class ScopeBase { void do_use_from(const ScopeBase*that); + // If this is a package body, then there is a Package header + // already declared. + Package*package_header_; + // Generates an unique name for the scope void generate_name(); @@ -193,8 +202,6 @@ class ActiveScope : public ScopeBase { ~ActiveScope() { } - void set_package_header(Package*); - // Pull items from "that" scope into "this" scope as is // defined by a "use" directive. The parser uses this method // to implement the "use ::*" directive. @@ -276,10 +283,6 @@ class ActiveScope : public ScopeBase { std::map incomplete_types; private: - // If this is a package body, then there is a Package header - // already declared. - Package*package_header_; - Entity*context_entity_; }; diff --git a/vhdlpp/subprogram.cc b/vhdlpp/subprogram.cc index f93ed1439..bd7d832cc 100644 --- a/vhdlpp/subprogram.cc +++ b/vhdlpp/subprogram.cc @@ -88,7 +88,7 @@ void SubprogramBody::write_to_stream(ostream&fd) const SubprogramHeader::SubprogramHeader(perm_string nam, list*ports, const VType*return_type) -: name_(nam), ports_(ports), return_type_(return_type), body_(NULL), parent_(NULL) +: name_(nam), ports_(ports), return_type_(return_type), body_(NULL), package_(NULL) { } @@ -172,12 +172,6 @@ const VType*SubprogramHeader::peek_param_type(int idx) const return NULL; } -void SubprogramHeader::set_parent(const ScopeBase*par) -{ - ivl_assert(*this, !parent_); - parent_ = par; -} - bool SubprogramHeader::unbounded() const { if(return_type_ && return_type_->is_unbounded()) return true; @@ -263,7 +257,7 @@ SubprogramHeader*SubprogramHeader::make_instance(std::vector argume } body_inst->set_statements(body_->statements_); - instance->set_parent(scope); + instance->set_package(package_); instance->set_body(body_inst); instance->fix_return_type(); } diff --git a/vhdlpp/subprogram.h b/vhdlpp/subprogram.h index 0338dc002..08473239e 100644 --- a/vhdlpp/subprogram.h +++ b/vhdlpp/subprogram.h @@ -31,6 +31,7 @@ class InterfacePort; class SequentialStmt; +class Package; class VType; class SubprogramBody : public LineInfo, public ScopeBase { @@ -78,8 +79,8 @@ class SubprogramHeader : public LineInfo { const VType*peek_param_type(int idx) const; const VType*peek_return_type() const { return return_type_; } - void set_parent(const ScopeBase*par); - inline const ScopeBase*get_parent() const { return parent_; } + inline void set_package(const Package*pkg) { assert(!package_); package_ = pkg; } + inline const Package*get_package() const { return package_; } // Checks if either return type or parameters are unbounded vectors. bool unbounded() const; @@ -138,7 +139,7 @@ class SubprogramHeader : public LineInfo { std::list*ports_; const VType*return_type_; SubprogramBody*body_; - const ScopeBase*parent_; + const Package*package_; }; // Class to define functions headers defined in the standard VHDL libraries. diff --git a/vhdlpp/subprogram_emit.cc b/vhdlpp/subprogram_emit.cc index 0aa02973e..2dab34a89 100644 --- a/vhdlpp/subprogram_emit.cc +++ b/vhdlpp/subprogram_emit.cc @@ -107,10 +107,9 @@ int SubprogramHeader::emit_full_name(const std::vector&argv, // the SV elaborator finds the correct VHDL elaborated // definition. It should not be emitted only if we call another // function from the same package. - const Package*pkg = dynamic_cast(parent_); const SubprogramBody*subp = dynamic_cast(scope); - if (pkg != 0 && (!subp || !subp->header() || subp->header()->get_parent() != pkg)) - out << "\\" << pkg->name() << " ::"; + if (package_ && (!subp || !subp->header() || subp->header()->get_package() != package_)) + out << "\\" << package_->name() << " ::"; return emit_name(argv, out, ent, scope); }