File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ #-------------------------------------------------------------------------------
2+ # identifiervisitor.py
3+ #
4+ # Identifier list generator in a nested operator
5+ #
6+ # Copyright (C) 2015, Shinya Takamaeda-Yamazaki
7+ # License: Apache 2.0
8+ #-------------------------------------------------------------------------------
9+
10+ import sys
11+ import os
12+
13+ sys .path .insert (0 , os .path .dirname (os .path .dirname (os .path .dirname (os .path .abspath (__file__ )))) )
14+
15+ if sys .version_info [0 ] >= 3 :
16+ from pyverilog .dataflow .visit import NodeVisitor
17+ else :
18+ from visit import NodeVisitor
19+
20+ class IdentifierVisitor (NodeVisitor ):
21+ def __init__ (self ):
22+ self .identifiers = []
23+
24+ def getIdentifiers (self ):
25+ return tuple (self .identifiers )
26+
27+ def reset (self ):
28+ self .identifiers = []
29+
30+ def visit_Identifier (self , node ):
31+ self .identifiers .append (node .name )
32+
33+ if __name__ == '__main__' :
34+ import pyverilog .vparser .ast as vast
35+
36+ a = vast .Identifier ('a' )
37+ b = vast .Identifier ('b' )
38+ c = vast .Plus (a , b )
39+
40+ v = IdentifierVisitor ()
41+ v .visit (c )
42+
43+ ids = v .getIdentifiers ()
44+ print (ids )
You can’t perform that action at this time.
0 commit comments