Project

General

Profile

[logo] 
 
Home
News
Activity
About/Contact
Major Tools
  Dinotrace
  Verilator
  Verilog-mode
  Verilog-Perl
Other Tools
  BugVise
  CovVise
  Force-Gate-Sim
  Gspice
  IPC::Locker
  Rsvn
  SVN::S4
  Voneline
  WFH
General Info
  Papers

Issue #1304

Codebase: Macro to iterate over nodes of known type

Added by Stefan Wallentowitz over 1 year ago. Updated over 1 year ago.

Status:
WillNotFix
Priority:
Low
Assignee:
-
Category:
-
% Done:

0%


Description

There is a pattern in the codebase when a list of nodes is iterated and the type of each of the nodes is equal and known. This is for example to iterate over lists of pins, etc.

This introduces a macro ASTNODE_ITERATE that has three parameters:

- type: Is the type of the nodes (Ast<type> is the matching class name)
- it: Name of the iterator variable
- init: Initialization statement for iterator

All occurrences of this pattern have been accordingly replaced:

for (Ast<type> *<it> = <init>; <it>; <it>=<it>->nextp()->cast<type>())

This improves readability and some time in the future this may be a good marker to replace data containers or similar.

astnode-iterate.patch View - Patch (26.9 KB) Stefan Wallentowitz, 04/18/2018 02:29 PM

History

#1 Updated by Stefan Wallentowitz over 1 year ago

Sorry, I copied the commit text and now found how strange it looks here.

#2 Updated by Wilson Snyder over 1 year ago

I need to think if I like this.

However please use the develop-v4 branch which will become 4.000 for any large-touch wholesale changes. Even more so as that removes the cast methods.

#3 Updated by Stefan Wallentowitz over 1 year ago

Thanks for pointing this out, I was not aware of this branch so far.

#4 Updated by Wilson Snyder over 1 year ago

  • Status changed from New to WillNotFix

For the time being I don't think we want to change this, but I appreciate your efforts to clean up and in general expect to accept other cleanups.

There's two main concerns. First, it makes the code harder to read for people not familiar with the code - if there was thousands it might be worth it but not for only 58. Second, in a few years once C++11 compilers are common (not yet), we can use the C++11 for loop syntax ("for (AstFoo* itp : nodep->itemsp()") for this and a lot of other things.

Also available in: Atom