2012-11-12 02:42:31 +01:00
|
|
|
/*
|
2017-10-08 22:16:50 +02:00
|
|
|
* Copyright (c) 2012-2017 Stephen Williams (steve@icarus.com)
|
2012-11-12 02:42:31 +01:00
|
|
|
*
|
|
|
|
|
* This source code is free software; you can redistribute it
|
|
|
|
|
* and/or modify it in source code form under the terms of the GNU
|
|
|
|
|
* General Public License as published by the Free Software
|
|
|
|
|
* Foundation; either version 2 of the License, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
# include "netclass.h"
|
2013-03-15 04:08:32 +01:00
|
|
|
# include "netlist.h"
|
2012-11-25 19:13:05 +01:00
|
|
|
# include <iostream>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
2012-11-12 02:42:31 +01:00
|
|
|
|
2022-03-17 12:25:28 +01:00
|
|
|
netclass_t::netclass_t(perm_string name, const netclass_t*super)
|
2022-12-28 08:59:39 +01:00
|
|
|
: name_(name), super_(super), class_scope_(0), definition_scope_(0), virtual_class_(false)
|
2012-11-12 02:42:31 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
netclass_t::~netclass_t()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-12 23:05:11 +01:00
|
|
|
bool netclass_t::set_property(perm_string pname, property_qualifier_t qual,
|
|
|
|
|
ivl_type_t ptype)
|
2012-11-25 19:13:05 +01:00
|
|
|
{
|
2012-12-10 02:59:16 +01:00
|
|
|
map<perm_string,size_t>::const_iterator cur;
|
2012-11-25 19:13:05 +01:00
|
|
|
cur = properties_.find(pname);
|
|
|
|
|
if (cur != properties_.end())
|
|
|
|
|
return false;
|
|
|
|
|
|
2012-12-10 02:59:16 +01:00
|
|
|
prop_t tmp;
|
|
|
|
|
tmp.name = pname;
|
2013-06-26 15:16:24 +02:00
|
|
|
tmp.qual = qual;
|
2012-12-10 02:59:16 +01:00
|
|
|
tmp.type = ptype;
|
2013-06-28 16:57:35 +02:00
|
|
|
tmp.initialized_flag = false;
|
2012-12-10 02:59:16 +01:00
|
|
|
property_table_.push_back(tmp);
|
|
|
|
|
|
|
|
|
|
properties_[pname] = property_table_.size()-1;
|
2012-11-25 19:13:05 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-14 01:30:42 +02:00
|
|
|
void netclass_t::set_class_scope(NetScope*class_scope__)
|
2013-03-15 04:08:32 +01:00
|
|
|
{
|
|
|
|
|
assert(class_scope_ == 0);
|
2014-10-14 01:30:42 +02:00
|
|
|
class_scope_ = class_scope__;
|
2013-03-15 04:08:32 +01:00
|
|
|
}
|
|
|
|
|
|
2014-09-16 02:33:56 +02:00
|
|
|
void netclass_t::set_definition_scope(NetScope*use_definition_scope)
|
2014-09-02 18:22:41 +02:00
|
|
|
{
|
|
|
|
|
assert(definition_scope_ == 0);
|
2014-09-16 02:33:56 +02:00
|
|
|
definition_scope_ = use_definition_scope;
|
2014-09-02 18:22:41 +02:00
|
|
|
}
|
|
|
|
|
|
2012-11-12 02:42:31 +01:00
|
|
|
ivl_variable_type_t netclass_t::base_type() const
|
|
|
|
|
{
|
|
|
|
|
return IVL_VT_CLASS;
|
|
|
|
|
}
|
2012-11-25 19:13:05 +01:00
|
|
|
|
2013-10-31 02:35:00 +01:00
|
|
|
size_t netclass_t::get_properties(void) const
|
|
|
|
|
{
|
|
|
|
|
size_t res = properties_.size();
|
|
|
|
|
if (super_) res += super_->get_properties();
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-10 02:59:16 +01:00
|
|
|
int netclass_t::property_idx_from_name(perm_string pname) const
|
|
|
|
|
{
|
|
|
|
|
map<perm_string,size_t>::const_iterator cur;
|
|
|
|
|
cur = properties_.find(pname);
|
2013-10-31 02:35:00 +01:00
|
|
|
if (cur == properties_.end()) {
|
|
|
|
|
if (super_)
|
|
|
|
|
return super_->property_idx_from_name(pname);
|
|
|
|
|
else
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2012-12-10 02:59:16 +01:00
|
|
|
|
2013-10-31 02:35:00 +01:00
|
|
|
int pidx = cur->second;
|
|
|
|
|
if (super_) pidx += super_->get_properties();
|
|
|
|
|
return pidx;
|
2012-11-25 19:13:05 +01:00
|
|
|
}
|
2012-12-01 21:03:01 +01:00
|
|
|
|
|
|
|
|
const char*netclass_t::get_prop_name(size_t idx) const
|
|
|
|
|
{
|
2013-10-31 02:35:00 +01:00
|
|
|
size_t super_size = 0;
|
|
|
|
|
if (super_) super_size = super_->get_properties();
|
|
|
|
|
|
|
|
|
|
assert(idx < (super_size + property_table_.size()));
|
|
|
|
|
if (idx < super_size)
|
|
|
|
|
return super_->get_prop_name(idx);
|
|
|
|
|
else
|
|
|
|
|
return property_table_[idx-super_size].name;
|
2012-12-01 21:03:01 +01:00
|
|
|
}
|
|
|
|
|
|
2013-06-26 15:16:24 +02:00
|
|
|
property_qualifier_t netclass_t::get_prop_qual(size_t idx) const
|
|
|
|
|
{
|
2013-10-31 02:35:00 +01:00
|
|
|
size_t super_size = 0;
|
|
|
|
|
if (super_) super_size = super_->get_properties();
|
|
|
|
|
|
|
|
|
|
assert(idx < (super_size+property_table_.size()));
|
|
|
|
|
if (idx < super_size)
|
|
|
|
|
return super_->get_prop_qual(idx);
|
|
|
|
|
else
|
|
|
|
|
return property_table_[idx-super_size].qual;
|
2013-06-26 15:16:24 +02:00
|
|
|
}
|
|
|
|
|
|
2012-12-01 21:03:01 +01:00
|
|
|
ivl_type_t netclass_t::get_prop_type(size_t idx) const
|
|
|
|
|
{
|
2013-10-31 02:35:00 +01:00
|
|
|
size_t super_size = 0;
|
|
|
|
|
if (super_) super_size = super_->get_properties();
|
|
|
|
|
|
|
|
|
|
assert(idx < (super_size+property_table_.size()));
|
|
|
|
|
if (idx < super_size)
|
|
|
|
|
return super_->get_prop_type(idx);
|
|
|
|
|
else
|
|
|
|
|
return property_table_[idx-super_size].type;
|
2012-12-01 21:03:01 +01:00
|
|
|
}
|
2013-03-15 04:08:32 +01:00
|
|
|
|
2013-06-28 16:57:35 +02:00
|
|
|
bool netclass_t::get_prop_initialized(size_t idx) const
|
|
|
|
|
{
|
2013-10-31 02:35:00 +01:00
|
|
|
size_t super_size = 0;
|
|
|
|
|
if (super_) super_size = super_->get_properties();
|
|
|
|
|
|
|
|
|
|
assert(idx < (super_size+property_table_.size()));
|
|
|
|
|
if (idx < super_size)
|
|
|
|
|
return super_->get_prop_initialized(idx);
|
|
|
|
|
else
|
|
|
|
|
return property_table_[idx].initialized_flag;
|
2013-06-28 16:57:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void netclass_t::set_prop_initialized(size_t idx) const
|
|
|
|
|
{
|
2013-10-31 02:35:00 +01:00
|
|
|
size_t super_size = 0;
|
|
|
|
|
if (super_) super_size = super_->get_properties();
|
|
|
|
|
|
|
|
|
|
assert(idx >= super_size && idx < (super_size+property_table_.size()));
|
|
|
|
|
idx -= super_size;
|
|
|
|
|
|
2013-06-28 16:57:35 +02:00
|
|
|
assert(! property_table_[idx].initialized_flag);
|
|
|
|
|
property_table_[idx].initialized_flag = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool netclass_t::test_for_missing_initializers() const
|
|
|
|
|
{
|
|
|
|
|
for (size_t idx = 0 ; idx < property_table_.size() ; idx += 1) {
|
|
|
|
|
if (property_table_[idx].initialized_flag)
|
|
|
|
|
continue;
|
|
|
|
|
if (property_table_[idx].qual.test_const())
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-15 03:03:21 +02:00
|
|
|
NetScope*netclass_t::method_from_name(perm_string name) const
|
2013-03-15 04:08:32 +01:00
|
|
|
{
|
|
|
|
|
NetScope*task = class_scope_->child( hname_t(name) );
|
2017-10-08 22:16:50 +02:00
|
|
|
if ((task == 0) && super_)
|
|
|
|
|
task = super_->method_from_name(name);
|
2013-03-15 04:08:32 +01:00
|
|
|
return task;
|
|
|
|
|
|
|
|
|
|
}
|
2013-06-26 15:16:24 +02:00
|
|
|
|
2023-06-17 16:50:05 +02:00
|
|
|
NetScope* netclass_t::get_constructor() const
|
|
|
|
|
{
|
|
|
|
|
auto task = class_scope_->child(hname_t(perm_string::literal("new")));
|
|
|
|
|
if (task)
|
|
|
|
|
return task;
|
|
|
|
|
|
|
|
|
|
task = class_scope_->child(hname_t(perm_string::literal("new@")));
|
|
|
|
|
if (task)
|
|
|
|
|
return task;
|
|
|
|
|
|
|
|
|
|
if (super_)
|
|
|
|
|
return super_->get_constructor();
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-03 04:41:58 +02:00
|
|
|
NetNet* netclass_t::find_static_property(perm_string name) const
|
|
|
|
|
{
|
2022-09-24 19:01:54 +02:00
|
|
|
NetNet *net = class_scope_->find_signal(name);
|
|
|
|
|
if (net)
|
|
|
|
|
return net;
|
|
|
|
|
|
|
|
|
|
if (super_)
|
|
|
|
|
return super_->find_static_property(name);
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
2013-07-03 04:41:58 +02:00
|
|
|
}
|
|
|
|
|
|
2013-06-26 15:16:24 +02:00
|
|
|
bool netclass_t::test_scope_is_method(const NetScope*scope) const
|
|
|
|
|
{
|
|
|
|
|
while (scope && scope != class_scope_) {
|
|
|
|
|
scope = scope->parent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (scope == 0)
|
|
|
|
|
return false;
|
|
|
|
|
else
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2022-02-19 12:58:27 +01:00
|
|
|
|
|
|
|
|
const NetExpr* netclass_t::get_parameter(Design *des, perm_string name,
|
|
|
|
|
ivl_type_t &par_type) const
|
|
|
|
|
{
|
|
|
|
|
return class_scope_->get_parameter(des, name, par_type);
|
|
|
|
|
}
|
2022-09-17 22:01:58 +02:00
|
|
|
|
|
|
|
|
bool netclass_t::test_compatibility(ivl_type_t that) const
|
|
|
|
|
{
|
|
|
|
|
for (const netclass_t *class_type = dynamic_cast<const netclass_t *>(that);
|
|
|
|
|
class_type; class_type = class_type->get_super()) {
|
|
|
|
|
if (class_type == this)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|