rename z.py
diff --git a/z_test.py b/z.py
similarity index 85%
rename from z_test.py
rename to z.py
index c1aab48..2247bb3 100644
--- a/z_test.py
+++ b/z.py
@@ -8,7 +8,7 @@
""" Converts the declaration into a nested list.
"""
typ = type(decl)
-
+
if typ == TypeDecl:
return ['TypeDecl', expand_decl(decl.type)]
elif typ == IdentifierType:
@@ -18,9 +18,9 @@
elif typ in [Struct, Union]:
decls = [expand_decl(d) for d in decl.decls or []]
return [typ.__name__, decl.name, decls]
- else:
+ else:
nested = expand_decl(decl.type)
-
+
if typ == Decl:
if decl.quals:
return ['Decl', decl.quals, decl.name, nested]
@@ -49,22 +49,22 @@
class NodeVisitor(object):
def __init__(self):
self.current_parent = None
-
+
def visit(self, node):
- """ Visit a node.
+ """ Visit a node.
"""
method = 'visit_' + node.__class__.__name__
visitor = getattr(self, method, self.generic_visit)
return visitor(node)
-
+
def visit_FuncCall(self, node):
print("Visiting FuncCall")
print(node.show())
print('---- parent ----')
print(self.current_parent.show())
-
+
def generic_visit(self, node):
- """ Called if no explicit visitor function exists for a
+ """ Called if no explicit visitor function exists for a
node. Implements preorder visiting of the node.
"""
oldparent = self.current_parent
@@ -74,20 +74,17 @@
self.current_parent = oldparent
-if __name__ == "__main__":
+if __name__ == "__main__":
source_code = r'''
- typedef int foobar;
- typedef int foobar;
- void main(void) {
- foobar i;
- }
+ struct sample
+ {
+ int nodeId;
+ char nodeName[10];
+ } SSample;
'''
- parser = CParser(lex_optimize=False, yacc_optimize=False, yacc_debug=True)
+ parser = CParser()
ast = parser.parse(source_code, filename='zz')
ast.show(showcoord=False, attrnames=True, nodenames=True)
- #~ nv=NodeVisitor()
- #~ nv.visit(ast)
- print('-- done --')