From a8ecce74219050df48b25c01690438734f373108 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 7 Jun 2008 12:15:46 +0100 Subject: [PATCH] Make sure all declarations have a type --- tgt-vhdl/vhdl_element.cc | 17 +++++++++++------ tgt-vhdl/vhdl_element.hh | 14 +++++++------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/tgt-vhdl/vhdl_element.cc b/tgt-vhdl/vhdl_element.cc index 073ddc267..648cde01d 100644 --- a/tgt-vhdl/vhdl_element.cc +++ b/tgt-vhdl/vhdl_element.cc @@ -189,6 +189,16 @@ void vhdl_arch::emit(std::ofstream &of, int level) const blank_line(of, level); // Extra blank line after architectures; } +vhdl_decl *vhdl_arch::get_decl(const std::string &name) const +{ + decl_list_t::const_iterator it; + for (it = decls_.begin(); it != decls_.end(); ++it) { + if ((*it)->get_name() == name) + return *it; + } + return NULL; +} + /* * True if component `name' has already been declared in this * architecture. This is a bit of hack, since it uses typeid @@ -212,12 +222,7 @@ bool vhdl_arch::have_declared_component(const std::string &name) const */ bool vhdl_arch::have_declared(const std::string &name) const { - decl_list_t::const_iterator it; - for (it = decls_.begin(); it != decls_.end(); ++it) { - if ((*it)->get_name() == name) - return true; - } - return false; + return get_decl(name) != NULL; } vhdl_arch *vhdl_conc_stmt::get_parent() const diff --git a/tgt-vhdl/vhdl_element.hh b/tgt-vhdl/vhdl_element.hh index 3498fead3..3e14a2bd6 100644 --- a/tgt-vhdl/vhdl_element.hh +++ b/tgt-vhdl/vhdl_element.hh @@ -173,12 +173,15 @@ private: */ class vhdl_decl : public vhdl_element { public: - vhdl_decl(const char *name) : name_(name) {} + vhdl_decl(const char *name, vhdl_type *type=NULL) + : name_(name), type_(type) {} virtual ~vhdl_decl() {}; const std::string &get_name() const { return name_; } + const vhdl_type *get_type() const { return type_; } protected: std::string name_; + vhdl_type *type_; }; typedef std::list decl_list_t; @@ -211,12 +214,10 @@ private: class vhdl_var_decl : public vhdl_decl { public: vhdl_var_decl(const char *name, vhdl_type *type) - : vhdl_decl(name), type_(type) {} + : vhdl_decl(name, type) {} ~vhdl_var_decl(); void emit(std::ofstream &of, int level) const; -private: - vhdl_type *type_; }; @@ -226,12 +227,10 @@ private: class vhdl_signal_decl : public vhdl_decl { public: vhdl_signal_decl(const char *name, vhdl_type *type) - : vhdl_decl(name), type_(type) {} + : vhdl_decl(name, type) {} ~vhdl_signal_decl(); void emit(std::ofstream &of, int level) const; -private: - vhdl_type *type_; }; @@ -285,6 +284,7 @@ public: void emit(std::ofstream &of, int level=0) const; bool have_declared_component(const std::string &name) const; bool have_declared(const std::string &name) const; + vhdl_decl *get_decl(const std::string &name) const; void add_decl(vhdl_decl *decl); void add_stmt(vhdl_conc_stmt *stmt); vhdl_entity *get_parent() const;