Skip to content

Commit

Permalink
make parsing/unparsing code a staticmethod
Browse files Browse the repository at this point in the history
As title
  • Loading branch information
esc committed Apr 25, 2024
1 parent 040af33 commit adfbc51
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions numba_rvsdg/core/datastructures/ast_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,24 +215,21 @@ def __init__(
) -> None:
self.prune = prune
self.code = code
self.tree = self.unparse_code(code)
self.tree = AST2SCFGTransformer.unparse_code(code)
self.block_index: int = 1 # 0 is reserved for genesis block
self.blocks = ASTCFG()
# Initialize first (genesis) block, assume it's named zero.
# (This also initializes the self.current_block attribute.)
self.add_block(0)
self.loop_stack: list[LoopIndices] = []

def unparse_code(
self, code: str | Callable[..., Any]
) -> list[type[ast.AST]]:
@staticmethod
def unparse_code(code: str | Callable[..., Any]) -> list[type[ast.AST]]:
# Convert source code into AST.
if isinstance(self.code, str):
tree = ast.parse(self.code).body
elif callable(self.code):
tree = ast.parse(
textwrap.dedent(inspect.getsource(self.code))
).body
if isinstance(code, str):
tree = ast.parse(code).body
elif callable(code):
tree = ast.parse(textwrap.dedent(inspect.getsource(code))).body
else:
msg = "Type: '{type(self.cod}}' is not implemented."
raise NotImplementedError(msg)
Expand Down

0 comments on commit adfbc51

Please sign in to comment.