Allow classes to reference declarations in their enclosing scope(s).

The original implementation made each class a root scope. They should
be added to the scope hierarchy just like any other declaration.
This commit is contained in:
Martin Whitaker 2019-12-22 10:38:40 +00:00
parent 7f95abc6ab
commit 465e0d2710
6 changed files with 9 additions and 43 deletions

View File

@ -359,7 +359,7 @@ NetAssign_* PEIdent::elaborate_lval_method_class_member_(Design*des,
{
if (!gn_system_verilog())
return 0;
if (scope->parent() == 0)
if (scope->parent() == 0 || scope->type() == NetScope::CLASS)
return 0;
if (path_.size() != 1)
return 0;

View File

@ -482,10 +482,7 @@ static void elaborate_scope_class(Design*des, NetScope*scope, PClass*pclass)
ivl_assert(*pclass, use_type->save_elaborated_type == 0);
use_type->save_elaborated_type = use_class;
// Class scopes have no parent scope, because references are
// not allowed to escape a class method. But they are allowed
// to reference the compilation unit scope.
NetScope*class_scope = new NetScope(0, hname_t(pclass->pscope_name()),
NetScope*class_scope = new NetScope(scope, hname_t(pclass->pscope_name()),
NetScope::CLASS, scope->unit());
class_scope->set_line(pclass);
class_scope->set_class_def(use_class);

View File

@ -1,7 +1,7 @@
#ifndef IVL_ivl_target_priv_H
#define IVL_ivl_target_priv_H
/*
* Copyright (c) 2008-2017 Stephen Williams (steve@icarus.com)
* Copyright (c) 2008-2019 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -51,7 +51,6 @@ struct ivl_design_s {
ivl_process_t threads_;
// Keep arrays of root scopes.
std::map<const NetScope*,ivl_scope_t> classes;
std::vector<ivl_scope_t> packages;
std::vector<ivl_scope_t> roots;

View File

@ -130,7 +130,6 @@ NetScope::NetScope(NetScope*up, const hname_t&n, NetScope::TYPE t, NetScope*in_u
unit_ = this;
if (up) {
assert(t!=CLASS);
need_const_func_ = up->need_const_func_;
is_const_func_ = up->is_const_func_;
time_unit_ = up->time_unit();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000-2018 Stephen Williams (steve@icarus.com)
* Copyright (c) 2000-2019 Stephen Williams (steve@icarus.com)
* Copyright CERN 2013 / Stephen Williams (steve@icarus.com)
* Copyright (c) 2016 CERN Michele Castellana (michele.castellana@cern.ch)
*
@ -93,11 +93,7 @@ extern "C" void ivl_design_roots(ivl_design_t des, ivl_scope_t **scopes,
assert (nscopes && scopes);
if (des->root_scope_list.size() == 0) {
size_t fill = 0;
des->root_scope_list.resize(des->packages.size() + des->roots.size() + des->classes.size());
for (map<const NetScope*,ivl_scope_t>::iterator idx = des->classes.begin()
; idx != des->classes.end() ; ++ idx)
des->root_scope_list[fill++] = idx->second;
des->root_scope_list.resize(des->packages.size() + des->roots.size());
for (size_t idx = 0 ; idx < des->packages.size() ; idx += 1)
des->root_scope_list[fill++] = des->packages[idx];

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000-2018 Stephen Williams (steve@icarus.com)
* Copyright (c) 2000-2019 Stephen Williams (steve@icarus.com)
* Copyright CERN 2013 / Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
@ -256,11 +256,6 @@ ivl_scope_t dll_target::find_scope(ivl_design_s &des, const NetScope*cur)
return 0;
}
if (cur->type() == NetScope::CLASS) {
ivl_scope_t tmp = des.classes[cur];
return tmp;
}
for (unsigned idx = 0; idx < des.roots.size(); idx += 1) {
assert(des.roots[idx]);
ivl_scope_t scope = find_scope_from_root(des.roots[idx], cur);
@ -275,13 +270,6 @@ ivl_scope_t dll_target::find_scope(ivl_design_s &des, const NetScope*cur)
return scope;
}
for (map<const NetScope*,ivl_scope_t>::iterator idx = des.classes.begin()
; idx != des.classes.end() ; ++ idx) {
ivl_scope_t scope = find_scope_from_root(idx->second, cur);
if (scope)
return scope;
}
return 0;
}
@ -667,11 +655,6 @@ void dll_target::add_root(const NetScope *s)
des_.packages.push_back(root_);
break;
case NetScope::CLASS:
root_->ports = 0;
des_.classes[s] = root_;
break;
default:
assert(0);
break;
@ -2478,16 +2461,7 @@ void dll_target::net_probe(const NetEvProbe*)
void dll_target::scope(const NetScope*net)
{
if (net->parent()==0 && net->type()==NetScope::CLASS) {
if (debug_emit) {
cerr << "dll_target::scope: "
<< "Add class " << scope_path(net)
<< " as a root scope." << endl;
}
add_root(net);
} if (net->parent() == 0) {
if (net->parent() == 0) {
// Root scopes are already created...
@ -2561,7 +2535,8 @@ void dll_target::scope(const NetScope*net)
scop->tname_ = scop->name_;
break;
case NetScope::CLASS:
assert(0);
scop->type_ = IVL_SCT_CLASS;
scop->tname_ = scop->name_;
break;
}
}