|
43 | 43 |
|
44 | 44 | from psyclone.errors import GenerationError |
45 | 45 | from psyclone.psyGen import CodedKern |
| 46 | +from psyclone.psyir.frontend.fortran import FortranReader |
46 | 47 | from psyclone.psyir.nodes import (Assignment, Call, CodeBlock, Container, |
47 | 48 | Literal, Reference, Routine, ScopingNode) |
48 | 49 | from psyclone.psyir.symbols import ( |
@@ -400,6 +401,47 @@ def test_routine_update_parent_symbol_table_illegal_parent(fortran_reader): |
400 | 401 | in str(excinfo.value)) |
401 | 402 |
|
402 | 403 |
|
| 404 | +@pytest.mark.parametrize("routine_type", ["function", "subroutine"]) |
| 405 | +def test_routine_update_parent_symbol_table_with_comments(routine_type): |
| 406 | + ''' Test when we have a CodeBlock representing a routine that |
| 407 | + if there are also comments before it in the tree we can still |
| 408 | + check the name of the subroutine without failing inside |
| 409 | + update_parent_symbol_table. ''' |
| 410 | + |
| 411 | + code = f"""module test |
| 412 | +
|
| 413 | + contains |
| 414 | +
|
| 415 | + ! This routine will be a codeblock. |
| 416 | + {routine_type} routine() |
| 417 | + procedure (halo_exchange_routine) :: exchange_halo_group |
| 418 | + end {routine_type} |
| 419 | +
|
| 420 | + subroutine routine1(a, b, c) |
| 421 | + integer, intent(inout) :: a, b, c |
| 422 | +
|
| 423 | + call routine2() |
| 424 | + end subroutine |
| 425 | +
|
| 426 | + subroutine routine2() |
| 427 | +
|
| 428 | + end subroutine |
| 429 | +
|
| 430 | +end module""" |
| 431 | + |
| 432 | + fortran_reader = FortranReader(ignore_comments=False) |
| 433 | + psyir = fortran_reader.psyir_from_source(code) |
| 434 | + alt_routine = Routine.create("routine") |
| 435 | + |
| 436 | + module = psyir.walk(Container)[1] |
| 437 | + assert isinstance(module.children[0], CodeBlock) |
| 438 | + with pytest.raises(GenerationError) as excinfo: |
| 439 | + module.addchild(alt_routine) |
| 440 | + assert ("Can't add routine 'routine' into a scope that already contains " |
| 441 | + "a resolved symbol with the same name." |
| 442 | + in str(excinfo.value)) |
| 443 | + |
| 444 | + |
403 | 445 | def test_routine_update_parent_symbol_table(): |
404 | 446 | ''' Test the update_parent_symbol_table function of the Routine class. |
405 | 447 | Some of the tests here are accessed through addchild of a container. ''' |
|
0 commit comments