From 53a803632ffe70df731d6f0c9ff2328f8e66f871 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Wed, 15 Jan 2025 04:58:51 +0000 Subject: [PATCH] Transformations: Fix downcaing of nested `InlineCall` symbols Nested calls to functions is not captured in `convert_to_lower_case`, which can break the Fortran-to-Python converter. This simple fix remedies this. --- loki/transformations/tests/test_utilities.py | 11 ++++++++++- loki/transformations/utilities.py | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/loki/transformations/tests/test_utilities.py b/loki/transformations/tests/test_utilities.py index ff27b4ea8..d18302da8 100644 --- a/loki/transformations/tests/test_utilities.py +++ b/loki/transformations/tests/test_utilities.py @@ -133,11 +133,20 @@ def test_transform_convert_to_lower_case(frontend): do K=1,ANOTHER_VAR LOWER_CASE(MIXEd_cASE(1, K)) = K - 1 end do + + miXed_CasE(1, 1) = Max(mIn(sQrT(9.0), 2.0), 1.0) end subroutine my_NOT_ALL_lowercase_ROUTINE """.strip() routine = Subroutine.from_source(fcode, frontend=frontend) convert_to_lower_case(routine) - assert all(var.name.islower() and str(var).islower() for var in FindVariables(unique=False).visit(routine.ir)) + assert all( + var.name.islower() and str(var).islower() + for var in FindVariables(unique=True).visit(routine.ir) + ) + assert all( + f.name.islower() and str(f).islower() + for f in FindInlineCalls().visit(routine.ir) + ) @pytest.mark.parametrize('frontend', available_frontends()) diff --git a/loki/transformations/utilities.py b/loki/transformations/utilities.py index 2a72434d4..5253f3e85 100644 --- a/loki/transformations/utilities.py +++ b/loki/transformations/utilities.py @@ -113,6 +113,7 @@ def convert_to_lower_case(routine): (stmt.variable, stmt.variable.clone(name=stmt.variable.name.lower())) for stmt in FindNodes(StatementFunction).visit(routine.spec) ) + mapper = recursive_expression_map_update(mapper, case_sensitive=True) routine.spec = SubstituteExpressions(mapper).visit(routine.spec) routine.body = SubstituteExpressions(mapper).visit(routine.body)