Skip to content

Commit

Permalink
TransformInline : Recursive application of the substitution in case o…
Browse files Browse the repository at this point in the history
…f nested variables
  • Loading branch information
JoeffreyLegaux committed Sep 13, 2023
1 parent de81913 commit faeb27b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions loki/transform/transform_inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
from loki.visitors import Transformer, FindNodes
from loki.subroutine import Subroutine
from loki.tools import as_tuple
from loki.logging import error

import sys

Check failure on line 25 in loki/transform/transform_inline.py

View workflow job for this annotation

GitHub Actions / code checks (3.11)

C0411: standard import "import sys" should be placed before "from loki.expression import FindVariables, FindInlineCalls, FindLiterals, SubstituteExpressions, SubstituteExpressionsMapper, LokiIdentityMapper" (wrong-import-order)


__all__ = [
Expand Down Expand Up @@ -260,6 +263,23 @@ def _map_unbound_dims(var, val):
# Substitute argument calls into a copy of the body
member_body = SubstituteExpressions(argmap).visit(member.body.body)

# Recurse for nested variables replacements
test = True
arg_names = [a.name for a in argmap]
depth = 0
while(test) :

Check failure on line 270 in loki/transform/transform_inline.py

View workflow job for this annotation

GitHub Actions / code checks (3.11)

C0325: Unnecessary parens after 'while' keyword (superfluous-parens)
depth += 1
test = False
for var in FindVariables().visit(member_body):
if var.name in arg_names:
test=True

Check failure on line 275 in loki/transform/transform_inline.py

View workflow job for this annotation

GitHub Actions / code checks (3.11)

C0303: Trailing whitespace (trailing-whitespace)
if test:
member_body = SubstituteExpressions(argmap).visit(member_body)

if depth > 10:
error(f'Too many recursions while inlining routine {routine.name}')
sys.exit(1)

# Inline substituted body within a pair of marker comments
comment = Comment(f'! [Loki] inlined member subroutine: {member.name}')
c_line = Comment('! =========================================')
Expand Down

0 comments on commit faeb27b

Please sign in to comment.