From dc80c2dfcbc9af7d21010206a368c95f3f5347b2 Mon Sep 17 00:00:00 2001 From: "Davide Gessa (dakk)" Date: Mon, 16 Oct 2023 13:04:33 +0200 Subject: [PATCH] rename decompose_to_symbols --- qlasskit/ast2logic/__init__.py | 2 +- qlasskit/ast2logic/t_expression.py | 6 +++--- qlasskit/ast2logic/t_statement.py | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/qlasskit/ast2logic/__init__.py b/qlasskit/ast2logic/__init__.py index 97395573..7915a41e 100644 --- a/qlasskit/ast2logic/__init__.py +++ b/qlasskit/ast2logic/__init__.py @@ -17,7 +17,7 @@ from .utils import flatten # noqa: F401, E402 from .typing import Args, BoolExpList # noqa: F401, E402 from .t_arguments import translate_argument, translate_arguments # noqa: F401, E402 -from .t_expression import translate_expression, type_of_exp # noqa: F401, E402 +from .t_expression import translate_expression, decompose_to_symbols # noqa: F401, E402 from .t_statement import translate_statement # noqa: F401, E402 from .t_ast import translate_ast # noqa: F401, E402 from . import exceptions # noqa: F401, E402 diff --git a/qlasskit/ast2logic/t_expression.py b/qlasskit/ast2logic/t_expression.py index 6b20ee21..d8017b36 100644 --- a/qlasskit/ast2logic/t_expression.py +++ b/qlasskit/ast2logic/t_expression.py @@ -21,13 +21,13 @@ from . import Env, exceptions -def type_of_exp(vlist, base, res=[]) -> List[Symbol]: - """Type inference for expressions: iterate over val, and decompose to bool""" +def decompose_to_symbols(vlist, base, res=[]) -> List[Symbol]: + """Decompose exp to symbols""" if isinstance(vlist, list): i = 0 res = [] for in_val in vlist: - r_new = type_of_exp(in_val, f"{base}.{i}", res) + r_new = decompose_to_symbols(in_val, f"{base}.{i}", res) if isinstance(r_new, list): res.extend(r_new) else: diff --git a/qlasskit/ast2logic/t_statement.py b/qlasskit/ast2logic/t_statement.py index 20551133..1bc82067 100644 --- a/qlasskit/ast2logic/t_statement.py +++ b/qlasskit/ast2logic/t_statement.py @@ -17,7 +17,7 @@ from sympy import Symbol from sympy.logic.boolalg import Boolean -from . import Binding, Env, exceptions, translate_expression, type_of_exp +from . import Binding, Env, decompose_to_symbols, exceptions, translate_expression def translate_statement( # noqa: C901 @@ -58,14 +58,14 @@ def translate_statement( # noqa: C901 raise exceptions.SymbolReassignedException(target) tval, val = translate_expression(stmt.value, env) # TODO: typecheck - res = type_of_exp(val, f"{target}") + res = decompose_to_symbols(val, f"{target}") env.bind(Binding(target, tval, [x[0] for x in res])) res = list(map(lambda x: (Symbol(x[0]), x[1]), res)) return res, env elif isinstance(stmt, ast.Return): texp, vexp = translate_expression(stmt.value, env) # TODO: typecheck - res = type_of_exp(vexp, "_ret") + res = decompose_to_symbols(vexp, "_ret") env.bind(Binding("_ret", texp, [x[0] for x in res])) res = list(map(lambda x: (Symbol(x[0]), x[1]), res)) return res, env