Fix formatting of link routine

This commit is contained in:
Cary R 2023-08-22 20:40:15 -07:00
parent 2d41a43ae1
commit 77f7609b67
1 changed files with 24 additions and 29 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004-2021 Stephen Williams (steve@icarus.com)
* Copyright (c) 2004-2023 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
@ -200,42 +200,37 @@ void vvp_net_t::link(vvp_net_ptr_t port_to_link)
{
vvp_net_t*net = port_to_link.ptr();
// Connect nodes with vvp_fun_modpath_src to the head of the
// linked list, so that vvp_fun_modpath_src are always evaluated
// before their respective vvp_fun_modpath
if (dynamic_cast<vvp_fun_modpath_src*>(net->fun))
{
net->port[port_to_link.port()] = out_;
out_ = port_to_link;
}
// All other nodes connect after the last vvp_fun_modpath_src
else
{
// Connect nodes with vvp_fun_modpath_src to the head of the
// linked list, so that vvp_fun_modpath_src are always evaluated
// before their respective vvp_fun_modpath
if (dynamic_cast<vvp_fun_modpath_src*>(net->fun)) {
net->port[port_to_link.port()] = out_;
out_ = port_to_link;
// All other nodes connect after the last vvp_fun_modpath_src
} else {
// List is empty or first node has no vvp_fun_modpath_src
// then just insert the node into the head of linked list
if (out_.ptr() == nullptr || ! dynamic_cast<vvp_fun_modpath_src*>(out_.ptr()->fun))
{
net->port[port_to_link.port()] = out_;
out_ = port_to_link;
return;
}
if (out_.ptr() == nullptr || ! dynamic_cast<vvp_fun_modpath_src*>(out_.ptr()->fun)) {
net->port[port_to_link.port()] = out_;
out_ = port_to_link;
return;
}
vvp_net_ptr_t cur = out_;
vvp_net_ptr_t prev = vvp_net_ptr_t(nullptr,0);
vvp_net_ptr_t cur = out_;
vvp_net_ptr_t prev = vvp_net_ptr_t(nullptr,0);
// Traverse through linked list
while (dynamic_cast<vvp_fun_modpath_src*>(cur.ptr()->fun))
{
prev = cur;
cur = cur.ptr()->port[cur.port()];
if (!cur.ptr()) break; // End of list
}
while (dynamic_cast<vvp_fun_modpath_src*>(cur.ptr()->fun)) {
prev = cur;
cur = cur.ptr()->port[cur.port()];
if (! cur.ptr()) break; // End of list
}
assert(prev.ptr());
assert(prev.ptr());
// Insert after last vvp_fun_modpath_src (or end of list)
net->port[port_to_link.port()] = cur;
prev.ptr()->port[prev.port()] = port_to_link;
net->port[port_to_link.port()] = cur;
prev.ptr()->port[prev.port()] = port_to_link;
}
}