Skip to content

Commit

Permalink
refactor folding
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Oct 24, 2023
1 parent 733b510 commit 8c49b24
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions vyper/ast/folding.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Union

from vyper.ast import nodes as vy_ast
from vyper.builtins.functions import DISPATCH_TABLE
from vyper.exceptions import UnfoldableNode
from vyper.semantics.types.base import VyperType

Expand Down Expand Up @@ -115,10 +114,10 @@ def replace_builtin_functions(vyper_module: vy_ast.Module) -> int:
if not isinstance(node.func, vy_ast.Name):
continue

name = node.func.id
func = DISPATCH_TABLE.get(name)
func = node.func._metadata.get("type")
if func is None or not hasattr(func, "evaluate"):
continue

try:
new_node = func.evaluate(node) # type: ignore
except UnfoldableNode:
Expand Down Expand Up @@ -153,9 +152,6 @@ def replace_user_defined_constants(vyper_module: vy_ast.Module) -> int:
changed_nodes = 0

for node in vyper_module.get_children(vy_ast.VariableDecl):
if not isinstance(node.target, vy_ast.Name):
# left-hand-side of assignment is not a variable
continue
if not node.is_constant:
# annotation is not wrapped in `constant(...)`
continue
Expand Down Expand Up @@ -215,10 +211,10 @@ def replace_constant(
replacement_node : Constant | List | Call
Vyper ast node representing the literal value to be substituted in.
`Call` nodes are for struct constants.
type_ : VyperType
Type definition to be propagated to type checker.
raise_on_error: bool
Boolean indicating if `UnfoldableNode` exception should be raised or ignored.
type_ : VyperType, optional
Type definition to be propagated to type checker.
Returns
-------
Expand Down

0 comments on commit 8c49b24

Please sign in to comment.