From 9a22d5590a4ba010f53e8ba5ed9f3b87740b8ea1 Mon Sep 17 00:00:00 2001 From: Daniel Bauer <daniel.j.bauer@fau.de> Date: Tue, 18 Feb 2025 15:00:41 +0100 Subject: [PATCH] extend symbol canonicalization: recurse into statements, skip empty nodes and raise if anything unknown is encountered --- .../transformations/canonicalize_symbols.py | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/pystencils/backend/transformations/canonicalize_symbols.py b/src/pystencils/backend/transformations/canonicalize_symbols.py index 17875caa1..eb1aa1851 100644 --- a/src/pystencils/backend/transformations/canonicalize_symbols.py +++ b/src/pystencils/backend/transformations/canonicalize_symbols.py @@ -3,7 +3,15 @@ from ..memory import PsSymbol from ..exceptions import PsInternalCompilerError from ..ast import PsAstNode -from ..ast.structural import PsDeclaration, PsAssignment, PsLoop, PsConditional, PsBlock +from ..ast.structural import ( + PsDeclaration, + PsAssignment, + PsLoop, + PsConditional, + PsBlock, + PsStatement, + PsEmptyLeafMixIn, +) from ..ast.expressions import PsSymbolExpr, PsExpression from ...types import constify @@ -117,3 +125,14 @@ class CanonicalizeSymbols: case PsBlock(statements): for stmt in statements[::-1]: self.visit(stmt, cc) + + case PsStatement(expr): + self.visit(expr, cc) + + case PsEmptyLeafMixIn(): + ... + + case unknown: + raise PsInternalCompilerError( + f"Can't canonicalize symbols in {unknown} ({repr(unknown)})." + ) -- GitLab