Skip to content

Commit

Permalink
Fix symbol and scalar conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
phschaad committed Dec 24, 2024
1 parent e657f2c commit 2cbfcd5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
23 changes: 23 additions & 0 deletions dace/frontend/fortran/fortran_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,30 @@ def ast2sdfg(self, node: ast_internal_classes.Program_Node, sdfg: SDFG, cfg: Con
for i in self.startpoint.specification_part.symbols:
self.translate(i, sdfg, cfg)

# Sort the specifications to be translated in such a way that scalars are processed last. This means that
# where necessary they can be treated as symbols as opposed to scalars - for instance when they are used to
# describe the size of a data container.
scalar_vardecls = []
non_scalar_vardecls = []
other_specifications = []
for i in self.startpoint.specification_part.specifications:
if isinstance(i, ast_internal_classes.Decl_Stmt_Node):
has_array = False
for j in i.vardecl:
if isinstance(j, ast_internal_classes.Var_Decl_Node):
if j.sizes is not None:
has_array = True
if has_array:
non_scalar_vardecls.append(i)
else:
scalar_vardecls.append(i)
else:
other_specifications.append(i)
for i in non_scalar_vardecls:
self.translate(i, sdfg, cfg)
for i in other_specifications:
self.translate(i, sdfg, cfg)
for i in scalar_vardecls:
self.translate(i, sdfg, cfg)
for i in self.startpoint.specification_part.specifications:
self._add_simple_state_to_cfg(cfg, "start_struct_size")
Expand Down
8 changes: 4 additions & 4 deletions tests/fortran/array_attributes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,10 @@ def test_fortran_frontend_array_arbitrary_attribute2():
arrsize2=arrsize2,
arrsize3=arrsize3,
arrsize4=arrsize4)
assert a[1, 1] == arrsize
assert a[1, 2] == arrsize2
assert a[1, 3] == arrsize3
assert a[1, 4] == arrsize4
assert a[0, 0] == arrsize
assert a[0, 1] == arrsize2
assert a[0, 2] == arrsize3
assert a[0, 3] == arrsize4


if __name__ == "__main__":
Expand Down

0 comments on commit 2cbfcd5

Please sign in to comment.