Skip to content

Commit

Permalink
Add support for Fortran modules in scope parent assignment pass
Browse files Browse the repository at this point in the history
  • Loading branch information
mcopik committed Sep 8, 2023
1 parent b37c1f5 commit 70c33dd
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
3 changes: 2 additions & 1 deletion dace/frontend/fortran/ast_internal_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def __init__(self, *args, **kwargs): # real signature unknown
Union[
Subroutine_Subprogram_Node,
Function_Subprogram_Node,
Main_Program_Node
Main_Program_Node,
Module_Node
]
] = None
for k, v in kwargs.items():
Expand Down
3 changes: 2 additions & 1 deletion dace/frontend/fortran/ast_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ def visit(self, node: ast_internal_classes.FNode, parent_node: Optional[ast_inte
parent_node_types = [
ast_internal_classes.Subroutine_Subprogram_Node,
ast_internal_classes.Function_Subprogram_Node,
ast_internal_classes.Main_Program_Node
ast_internal_classes.Main_Program_Node,
ast_internal_classes.Module_Node
]

if parent_node is not None and type(parent_node) in parent_node_types:
Expand Down
37 changes: 37 additions & 0 deletions tests/fortran/parent_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,44 @@ def test_fortran_frontend_parent():
for execution in subroutine.execution_part.execution:
assert execution.parent == subroutine

def test_fortran_frontend_module():
"""
Tests that the Fortran frontend can parse array accesses and that the accessed indices are correct.
"""
test_string = """
module test_module
implicit none
! good enough approximation
integer, parameter :: pi = 4
end module test_module
PROGRAM access_test
implicit none
double precision d(4)
d(1)=0
CALL array_access_test_function(d)
end
SUBROUTINE array_access_test_function(d)
double precision d(4)
d(2)=5.5
END SUBROUTINE array_access_test_function
"""
ast, functions = fortran_parser.create_ast_from_string(test_string, "array_access_test")
ast_transforms.ParentScopeAssigner().visit(ast)

assert ast.parent is None
assert ast.main_program.parent == None

module = ast.modules[0]
assert module.parent == None
specification = module.specification_part.specifications[0]
assert specification.parent == module


if __name__ == "__main__":

test_fortran_frontend_parent()
test_fortran_frontend_module()

0 comments on commit 70c33dd

Please sign in to comment.