vhdlpp: ExpName resolves enum values.

This commit is contained in:
Maciej Suminski 2015-02-06 10:44:22 +01:00
parent fc0728ab6f
commit 12b4914b63
6 changed files with 37 additions and 0 deletions

View File

@ -906,6 +906,10 @@ const VType* ExpName::probe_type(Entity*ent, ScopeBase*scope) const
if (arc && (gtype = arc->probe_genvar_type(name_))) {
return gtype;
}
if (scope->is_enum_name(name_)) {
return &primitive_INTEGER;
}
}
cerr << get_fileline() << ": error: Signal/variable " << name_

View File

@ -2393,6 +2393,9 @@ type_declaration
tmp->set_definition($4);
active_scope->incomplete_types.erase(cur);
}
if(const VTypeEnum*enum_type = dynamic_cast<const VTypeEnum*>($4)) {
active_scope->use_enum(enum_type);
}
}
delete[]$2;
}

View File

@ -59,6 +59,8 @@ ScopeBase::ScopeBase(const ActiveScope&ref)
use_subprograms_ = ref.use_subprograms_;
cur_subprograms_ = ref.cur_subprograms_;
use_enums_ = ref.use_enums_;
// This constructor is invoked when the parser is finished with
// an active scope and is making the actual scope. At this point
// we know that "this" is the parent scope for the subprograms,
@ -181,6 +183,17 @@ Subprogram* ScopeBase::find_subprogram(perm_string name) const
return 0;
}
bool ScopeBase::is_enum_name(perm_string name) const
{
for(list<const VTypeEnum*>::const_iterator it = use_enums_.begin();
it != use_enums_.end(); ++it) {
if((*it)->has_name(name))
return true;
}
return false;
}
/*
* This method is only used by the ActiveScope derived class to import
* definition from another scope.
@ -219,6 +232,8 @@ void ScopeBase::do_use_from(const ScopeBase*that)
; cur != that->cur_constants_.end() ; ++ cur) {
use_constants_[cur->first] = cur->second;
}
use_enums_ = that->use_enums_;
}
void ScopeBase::transfer_from(ScopeBase&ref)

View File

@ -58,6 +58,7 @@ class ScopeBase {
Variable* find_variable(perm_string by_name) const;
virtual const InterfacePort* find_param(perm_string by_name) const;
Subprogram* find_subprogram(perm_string by_name) const;
bool is_enum_name(perm_string name) const;
// Moves all signals, variables and components from another scope to
// this one. After the transfer new_* maps are emptied in the another scope.
void transfer_from(ScopeBase&ref);
@ -114,6 +115,8 @@ class ScopeBase {
std::map<perm_string, Subprogram*> use_subprograms_; //imported
std::map<perm_string, Subprogram*> cur_subprograms_; //current
std::list<const VTypeEnum*> use_enums_;
void do_use_from(const ScopeBase*that);
};
@ -199,6 +202,9 @@ class ActiveScope : public ScopeBase {
cur_types_[name] = t;
}
inline void use_enum(const VTypeEnum* t)
{ use_enums_.push_back(t); }
inline void use_name(perm_string name, const VType* t)
{ use_types_[name] = t; }

View File

@ -23,6 +23,7 @@
# include <map>
# include <typeinfo>
# include <cassert>
# include <algorithm>
using namespace std;
@ -251,6 +252,11 @@ void VTypeEnum::show(ostream&out) const
out << ")";
}
bool VTypeEnum::has_name(perm_string name) const
{
return std::find(names_.begin(), names_.end(), name) != names_.end();
}
VTypeRecord::VTypeRecord(std::list<element_t*>*elements)
: elements_(elements->size())
{

View File

@ -295,6 +295,9 @@ class VTypeEnum : public VType {
void show(std::ostream&) const;
int emit_def(std::ostream&out, perm_string name) const;
// Checks if the name is stored in the enum.
bool has_name(perm_string name) const;
private:
std::vector<perm_string>names_;
};