mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Add scope type and other symboltable properties.
This commit is contained in:
1 parent
78e9f01ad0
commit
e181826b5f
4 files changed
+92
-29
No files matched your search
+16
-9
@@ -26,11 +26,12 @@ print(t)
|
||||
|
||||
shift = 3
|
||||
def print_node(node, indent=0):
|
||||
indents = ' ' * indent
|
||||
if isinstance(node, ast.AST):
|
||||
lineno = 'row={}'.format(node.lineno) if hasattr(node, 'lineno') else ''
|
||||
print(' '*indent, "NODE", node.__class__.__name__, lineno)
|
||||
print(indents, "NODE", node.__class__.__name__, lineno)
|
||||
for field in node._fields:
|
||||
print(' '*indent,'-', field)
|
||||
print(indents,'-', field)
|
||||
f = getattr(node, field)
|
||||
if isinstance(f, list):
|
||||
for f2 in f:
|
||||
@@ -38,7 +39,7 @@ def print_node(node, indent=0):
|
||||
else:
|
||||
print_node(f, indent=indent+shift)
|
||||
else:
|
||||
print(' '*indent, 'OBJ', node)
|
||||
print(indents, 'OBJ', node)
|
||||
|
||||
print_node(t)
|
||||
|
||||
@@ -53,18 +54,24 @@ flag_names = [
|
||||
]
|
||||
|
||||
def print_table(table, indent=0):
|
||||
print(' '*indent, 'table:', table.get_name())
|
||||
print(' '*indent, ' ', 'Syms:')
|
||||
indents = ' ' * indent
|
||||
print(indents, 'table:', table.get_name())
|
||||
print(indents, ' ', 'name:', table.get_name())
|
||||
print(indents, ' ', 'type:', table.get_type())
|
||||
print(indents, ' ', 'line:', table.get_lineno())
|
||||
print(indents, ' ', 'identifiers:', table.get_identifiers())
|
||||
print(indents, ' ', 'Syms:')
|
||||
for sym in table.get_symbols():
|
||||
flags = []
|
||||
for flag_name in flag_names:
|
||||
func = getattr(sym, flag_name)
|
||||
if func():
|
||||
flags.append(flag_name)
|
||||
print(' '*indent, ' sym:', sym.get_name(), 'flags:', ' '.join(flags))
|
||||
print(' '*indent, ' ', 'Child tables:')
|
||||
for child in table.get_children():
|
||||
print_table(child, indent=indent+shift)
|
||||
print(indents, ' sym:', sym.get_name(), 'flags:', ' '.join(flags))
|
||||
if table.has_children():
|
||||
print(indents, ' ', 'Child tables:')
|
||||
for child in table.get_children():
|
||||
print_table(child, indent=indent+shift)
|
||||
|
||||
table = symtable.symtable(source, 'a', 'exec')
|
||||
print_table(table)
|
||||
|
||||
Reference in new issue
Block a user