@@ -27,6 +27,7 @@ subroutine collect_source_parsing(testsuite)
27
27
& new_unittest(" program" , test_program), &
28
28
& new_unittest(" module" , test_module), &
29
29
& new_unittest(" module-with-subprogram" , test_module_with_subprogram), &
30
+ & new_unittest(" module-with-c-api" , test_module_with_c_api), &
30
31
& new_unittest(" module-end-stmt" , test_module_end_stmt), &
31
32
& new_unittest(" program-with-module" , test_program_with_module), &
32
33
& new_unittest(" submodule" , test_submodule), &
@@ -315,7 +316,7 @@ subroutine test_module(error)
315
316
& ' module my_mod ! A trailing comment' , &
316
317
& ' use module_one' , &
317
318
& ' interface' , &
318
- & ' module subroutine f()' , &
319
+ & ' module subroutine f() bind(C) ' , &
319
320
& ' end interface' , &
320
321
& ' integer :: program' , &
321
322
& ' program = 1' , &
@@ -325,6 +326,10 @@ subroutine test_module(error)
325
326
& ' contains' , &
326
327
& ' module subroutine&' , &
327
328
& ' e()' , &
329
+ & ' integer, parameter :: c = 1' , &
330
+ & ' integer :: & ' , &
331
+ & ' bind(c)' , &
332
+ & ' bind(c) = 1' , &
328
333
& ' end subroutine e' , &
329
334
& ' module subroutine f()' , &
330
335
& ' end subroutine f' , &
@@ -489,6 +494,54 @@ subroutine test_module_end_stmt(error)
489
494
end subroutine test_module_end_stmt
490
495
491
496
497
+ ! > Try to parse fortran module with exported C-API via bind(c)
498
+ ! > (this should be detected as FPM_UNIT_SUBPROGRAM not FPM_UNIT_MODULE to prevent pruning)
499
+ subroutine test_module_with_c_api (error )
500
+
501
+ ! > Error handling
502
+ type (error_t), allocatable , intent (out ) :: error
503
+
504
+ integer :: unit
505
+ character (:), allocatable :: temp_file
506
+ type (srcfile_t), allocatable :: f_source
507
+
508
+ allocate (temp_file, source= get_temp_filename())
509
+
510
+ open (file= temp_file, newunit= unit)
511
+ write (unit, ' (a)' ) &
512
+ & ' module my_mod' , &
513
+ & ' contains' , &
514
+ & ' subroutine f() &' , &
515
+ & ' bind(C)' , &
516
+ & ' end subroutine f' , &
517
+ & ' module function g()' , &
518
+ & ' end function g' , &
519
+ & ' end module test'
520
+ close (unit)
521
+
522
+ f_source = parse_f_source(temp_file,error)
523
+ if (allocated (error)) then
524
+ return
525
+ end if
526
+
527
+ if (f_source% unit_type /= FPM_UNIT_SUBPROGRAM) then
528
+ call test_failed(error,' Wrong unit type detected - expecting FPM_UNIT_SUBPROGRAM' )
529
+ return
530
+ end if
531
+
532
+ if (size (f_source% modules_provided) /= 1 ) then
533
+ call test_failed(error,' Unexpected modules_provided - expecting one' )
534
+ return
535
+ end if
536
+
537
+ if (size (f_source% modules_used) /= 0 ) then
538
+ call test_failed(error,' Incorrect number of modules_used - expecting zero' )
539
+ return
540
+ end if
541
+
542
+ end subroutine test_module_with_c_api
543
+
544
+
492
545
! > Try to parse combined fortran module and program
493
546
! > Check that parsed unit type is FPM_UNIT_PROGRAM
494
547
subroutine test_program_with_module (error )
0 commit comments