Skip to content

Commit 9676aa5

Browse files
refactor: add more properties to func node
1 parent af6d8a0 commit 9676aa5

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

natrix/ast_node.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,26 @@ def modifiers(self) -> List[str]:
176176
if "id" in decorator
177177
]
178178

179+
@cached_property
180+
def is_runtime_code(self) -> bool:
181+
return not (self.is_constructor or self.is_from_interface)
182+
183+
@cached_property
184+
def is_external(self) -> bool:
185+
"""
186+
Check if the function is external by looking for the 'external' modifier.
187+
"""
188+
return "external" in self.modifiers
189+
190+
@cached_property
191+
def is_internal(self) -> bool:
192+
"""
193+
Check if the function is internal by looking for the 'internal' modifier.
194+
"""
195+
return "internal" in self.modifiers or not (
196+
"external" in self.modifiers or self.is_runtime_code
197+
)
198+
179199
@cached_property
180200
def memory_accesses(self) -> List[MemoryAccess]:
181201
"""

natrix/rules/implicit_internal.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ def __init__(self):
2121
)
2222

2323
def visit_FunctionDef(self, node: FunctionDefNode):
24+
print(f"Checking function: {node.get('name')}")
25+
print(f"{node.is_runtime_code=}")
26+
print(f"{node.is_external=}")
2427
if (
25-
node.is_constructor
26-
or node.is_from_interface
27-
or "external" in node.modifiers
28+
# not an internal function
29+
not node.is_runtime_code
30+
or node.is_external
31+
# explicit internal
2832
or "internal" in node.modifiers
2933
):
3034
return

0 commit comments

Comments
 (0)