Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/codegen/codegen_expressions_part2.inc
Original file line number Diff line number Diff line change
Expand Up @@ -267,30 +267,30 @@
step_code = generate_code_from_arena(arena, node%step_expr_index)
step_code = trim(step_code)
if (allocated(node%var_name)) then
inner = "(" // expr_code // ", " // node%var_name // "=" // &
start_code // ", " // end_code // ", " // step_code // ")"
inner = expr_code // ", " // node%var_name // "=" // &
start_code // ", " // end_code // ", " // step_code
else
inner = "(" // expr_code // ", i=" // start_code // ", " // &
end_code // ", " // step_code // ")"
inner = expr_code // ", i=" // start_code // ", " // &
end_code // ", " // step_code
end if
else
if (allocated(node%var_name)) then
inner = "(" // expr_code // ", " // node%var_name // "=" // &
start_code // ", " // end_code // ")"
inner = expr_code // ", " // node%var_name // "=" // &
start_code // ", " // end_code
else
inner = "(" // expr_code // ", i=" // start_code // ", " // &
end_code // ")"
inner = expr_code // ", i=" // start_code // ", " // &
end_code
end if
end if

if (present(type_spec)) then
if (len_trim(type_spec) > 0) then
code = "(/ " // trim(type_spec) // " :: " // trim(inner) // " /)"
code = "[" // trim(type_spec) // " :: (" // trim(inner) // ")]"
else
code = "(/ " // trim(inner) // " /)"
code = "[(" // trim(inner) // ")]"
end if
else
code = "(/ " // trim(inner) // " /)"
code = "[(" // trim(inner) // ")]"
end if
class default
! Not a do loop node - fallback
Expand Down
7 changes: 4 additions & 3 deletions test/frontend/test_issue_1580_dimension_statement.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
program test_issue_1580_dimension_statement
use transformation_api, only: transform_lazy_fortran_string
implicit none

call run_dimension_conversion_test()
print *, ""
Expand Down Expand Up @@ -46,11 +47,11 @@ subroutine run_dimension_conversion_test()
error stop 1
end if

has_assignment = index(output_code, "arr1 = (/(i, i=1,10)/)") > 0
has_assignment = index(output_code, "arr1 = [(i, i=1,10)]") > 0
has_assignment = has_assignment .or. &
index(output_code, "arr1 = (/(i, i=1, 10) /)") > 0
index(output_code, "arr1 = [(i, i=1, 10)]") > 0
has_assignment = has_assignment .or. &
index(output_code, "arr1 = (/(i, i = 1, 10) /)") > 0
index(output_code, "arr1 = [(i, i = 1, 10)]") > 0

if (.not. has_assignment) then
print *, "FAIL: array constructor assignment not preserved"
Expand Down
23 changes: 12 additions & 11 deletions test/integration/feature_tests/test_implied_do_loops.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
program test_implied_do_loops
use transformation_api, only: transform_lazy_fortran_string
implicit none
character(len=:), allocatable :: output, error_msg

write (*, '(A)') "=== Testing Implied Do Loop Array Constructors ==="
Expand All @@ -23,12 +24,12 @@ subroutine test_simple_implied_do()
error stop 1
end if

! The generated code should use legacy (/ /) syntax for compatibility
if (contains_without_spaces(output, "(/(i,i=1,5)/)")) then
! The generated code should use modern [...] syntax for compatibility
if (contains_without_spaces(output, "[(i,i=1,5)]")) then
print *, " PASS: Simple implied do loop"
else
print *, " FAIL: Simple implied do loop - Expected" // &
" (/ (i, i=1, 5) /) syntax"
" [(i, i=1, 5)] syntax"
print *, " Got:", trim(output)
error stop 1
end if
Expand All @@ -45,11 +46,11 @@ subroutine test_complex_implied_do()
error stop 1
end if

if (contains_without_spaces(output, "sum((/(i*2,i=1,10)/))")) then
if (contains_without_spaces(output, "sum([(i*2,i=1,10)])")) then
print *, " PASS: Implied do with expression"
else
print *, " FAIL: Implied do with expression - Expected" // &
" sum((/ (i*2, i=1, 10) /))"
" sum([(i*2, i=1, 10)])"
print *, " Got:", trim(output)
error stop 1
end if
Expand All @@ -58,13 +59,13 @@ end subroutine test_complex_implied_do
subroutine test_nested_implied_do_levels()
character(len=:), allocatable :: input
character(len=*), parameter :: nested2_pattern = &
"reshape((/((i*10+j,j=1,3),i=1,3)/),[3,3])"
"reshape([((i*10+j,j=1,3),i=1,3)],[3,3])"
character(len=*), parameter :: nested3_pattern = &
"reshape((/(((i*100+j*10+k,k=1,3),j=1,3),i=1,3)/),[3,3,3])"
"reshape([(((i*100+j*10+k,k=1,3),j=1,3),i=1,3)],[3,3,3])"
character(len=*), parameter :: nested2_expect = &
"reshape((/((i*10 + j, j=1, 3), i=1, 3) /), [3, 3])"
"reshape([((i*10 + j, j=1, 3), i=1, 3)], [3, 3])"
character(len=*), parameter :: nested3_expect = &
"reshape((/(((i*100 + j*10 + k, k=1, 3), j=1, 3), i=1, 3) /), " // &
"reshape([(((i*100 + j*10 + k, k=1, 3), j=1, 3), i=1, 3)], " // &
"[3, 3, 3])"

input = 'matrix = reshape([((i*10 + j, j=1,3), i=1,3)], [3,3])'
Expand Down Expand Up @@ -114,10 +115,10 @@ subroutine test_nested_function_with_implied_do()
error stop 1
end if

if (contains_without_spaces(output, "(/(sqrt(real(i)),i=1,5)/)")) then
if (contains_without_spaces(output, "[(sqrt(real(i)),i=1,5)]")) then
print *, " PASS: Nested functions with implied do"
else
print *, " FAIL: Nested functions with implied do - Expected legacy syntax"
print *, " FAIL: Nested functions with implied do - Expected modern syntax"
print *, " Got:", trim(output)
error stop 1
end if
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ program test_issue_1575_implied_do_array_constructor
end if
end if

if (index(transformed, 'arr = (/(i*2, i=1, 10) /)') == 0) then
if (index(transformed, 'arr = [(i*2, i=1, 10)]') == 0) then
print *, 'FAIL: implied-do constructor lost'
print *, 'Output:'
print *, trim(transformed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ program test_issue_1777_negative_stride
stop 1
end if

if (index(transformed, '(/(i, i=10, 1, -2) /)') == 0) then
if (index(transformed, '[(i, i=10, 1, -2)]') == 0) then
print *, 'FAIL: implied-do with negative stride lost'
print *, 'Output:'
print *, trim(transformed)
Expand Down