-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9319c17
commit 1fd812b
Showing
2 changed files
with
5,083 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import ast | ||
import symtable | ||
from pathlib import Path | ||
|
||
|
||
def describe_symtable(st, recursive=True, indent=0): | ||
def print_d(s, *args): | ||
prefix = " " * indent | ||
print(prefix + s, *args) | ||
|
||
assert isinstance(st, symtable.SymbolTable) | ||
print_d("Symtable: type=%s, name=%s" % (st.get_type(), st.get_name())) | ||
print_d(" identifiers:", list(st.get_identifiers())) | ||
|
||
if recursive: | ||
for child_st in st.get_children(): | ||
describe_symtable(child_st, recursive, indent + 5) | ||
|
||
|
||
in_py_path = "../micro-benchmark" | ||
for _file in sorted(Path(in_py_path).rglob("*.py")): | ||
# Create a dictionary to store line numbers for identifiers | ||
identifiers = {} | ||
print(_file.parts[-4:]) | ||
describe_symtable( | ||
symtable.symtable(_file.read_text(), _file.name, compile_type="exec") | ||
) | ||
|
||
# Parse the code into an AST (Abstract Syntax Tree) | ||
tree = ast.parse(_file.read_text()) | ||
|
||
# Traverse the AST and extract line numbers for identifiers | ||
for node in ast.walk(tree): | ||
if isinstance(node, ast.Name): | ||
identifier = node.id | ||
lineno = node.lineno | ||
if identifier in identifiers: | ||
identifiers[identifier].append(lineno) | ||
else: | ||
identifiers[identifier] = [lineno] | ||
|
||
print("\n") | ||
print(identifiers) | ||
print("\n\n###########################\n\n") |
Oops, something went wrong.