Classes in $root scope up to elaboration.

This commit is contained in:
Stephen Williams 2014-09-14 20:01:14 -07:00
parent 98799ff7fa
commit fa21527e9f
4 changed files with 49 additions and 13 deletions

View File

@ -416,6 +416,7 @@ static void elaborate_scope_class(Design*des, NetScope*scope, PClass*pclass)
netclass_t*use_base_class = 0;
if (base_class) {
ivl_assert(*pclass, scope);
use_base_class = scope->find_class(base_class->name);
if (use_base_class == 0) {
cerr << pclass->get_fileline() << ": error: "
@ -440,14 +441,22 @@ static void elaborate_scope_class(Design*des, NetScope*scope, PClass*pclass)
// elaborated class definition.
for (map<perm_string, class_type_t::prop_info_t>::iterator cur = use_type->properties.begin()
; cur != use_type->properties.end() ; ++ cur) {
ivl_type_s*tmp = cur->second.type->elaborate_type(des, scope);
ivl_assert(*pclass, tmp);
if (debug_scopes) {
cerr << pclass->get_fileline() << ": elaborate_scope_class: "
<< " Property " << cur->first
<< " type=" << *tmp << endl;
if (scope) {
ivl_type_s*tmp = cur->second.type->elaborate_type(des, scope);
ivl_assert(*pclass, tmp);
if (debug_scopes) {
cerr << pclass->get_fileline() << ": elaborate_scope_class: "
<< " Property " << cur->first
<< " type=" << *tmp << endl;
}
use_class->set_property(cur->first, cur->second.qual, tmp);
} else {
cerr << pclass->get_fileline() << ": sorry: Don't know how to elaborate "
<< "property " << cur->first
<< " for class type in $root scope," << endl;
des->errors += 1;
}
use_class->set_property(cur->first, cur->second.qual, tmp);
}
for (map<perm_string,PTask*>::iterator cur = pclass->tasks.begin()
@ -486,7 +495,14 @@ static void elaborate_scope_class(Design*des, NetScope*scope, PClass*pclass)
cur->second->elaborate_scope(des, method_scope);
}
scope->add_class(use_class);
if (scope) {
scope->add_class(use_class);
} else {
cerr << pclass->get_fileline() << ": sorry: "
<< "Don't know how to elaborate class in $root scope." << endl;
des->errors += 1;
}
}
static void elaborate_scope_classes(Design*des, NetScope*scope,
@ -498,6 +514,18 @@ static void elaborate_scope_classes(Design*des, NetScope*scope,
}
}
void elaborate_rootscope_classes(Design*des)
{
if (pform_classes.empty())
return;
for (map<perm_string,PClass*>::iterator cur = pform_classes.begin()
; cur != pform_classes.end() ; ++ cur) {
blend_class_constructors(cur->second);
elaborate_scope_class(des, 0, cur->second);
}
}
static void replace_scope_parameters_(NetScope*scope, const LineInfo&loc,
const Module::replace_t&replacements)
{

View File

@ -5993,6 +5993,9 @@ Design* elaborate(list<perm_string>roots)
// Elaborate enum sets in $root scope.
elaborate_rootscope_enumerations(des);
// Elaborate classes in $root scope.
elaborate_rootscope_classes(des);
// Elaborate the packages. Package elaboration is simpler
// because there are fewer sub-scopes involved.
i = 0;

View File

@ -28,6 +28,7 @@
class Design;
class Module;
class PClass;
class PPackage;
class PUdp;
class data_type_t;
@ -42,11 +43,13 @@ extern std::map<perm_string,Module*> pform_modules;
extern std::map<perm_string,PUdp*> pform_primitives;
extern std::map<perm_string,data_type_t*> pform_typedefs;
extern std::set<enum_type_t*> pform_enum_sets;
extern std::map<perm_string,PClass*> pform_classes;
extern std::map<perm_string,PPackage*> pform_packages;
extern void pform_dump(std::ostream&out, const PPackage*pac);
extern void elaborate_rootscope_enumerations(Design*des);
extern void elaborate_rootscope_classes(Design*des);
/*
* This code actually invokes the parser to make modules. The first

View File

@ -66,6 +66,11 @@ map<perm_string,PUdp*> pform_primitives;
map<perm_string,data_type_t*>pform_typedefs;
set<enum_type_t*>pform_enum_sets;
/*
* Class definitions in the $root scope go here.
*/
map<perm_string,PClass*> pform_classes;
std::string vlltype::get_fileline() const
{
ostringstream buf;
@ -331,10 +336,7 @@ PClass* pform_push_class_scope(const struct vlltype&loc, perm_string name)
/* If no scope was found then this is being defined in the
* compilation unit scope. */
if (scopex == 0) {
cerr << class_scope->get_fileline() << ": sorry: class "
"declarations in the compilation unit scope are not yet "
"supported." << endl;
error_count += 1;
pform_classes[name] = class_scope;
lexical_scope = class_scope;
return class_scope;
}