Skip to content

Commit 360457a

Browse files
committed
identifiervisitor.py: returns an identifier list in a nested AST.
1 parent f5030e4 commit 360457a

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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)

0 commit comments

Comments
 (0)