Fortran-extract-interface-source.f90 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. ! A simple function
  2. logical function func_simple()
  3. func_simple = .true.
  4. end function func_simple
  5. ! A simple function, but with less friendly end
  6. logical function func_simple_1()
  7. func_simple_1 = .true.
  8. end function
  9. ! A simple function, but with even less friendly end
  10. logical function func_simple_2()
  11. func_simple_2 = .true.
  12. end
  13. ! A pure simple function
  14. pure logical function func_simple_pure()
  15. func_simple_pure = .true.
  16. end function func_simple_pure
  17. ! A pure recursive function
  18. recursive pure integer function func_simple_recursive_pure(i)
  19. integer, intent(in) :: i
  20. if (i <= 0) then
  21. func_simple_recursive_pure = i
  22. else
  23. func_simple_recursive_pure = i + func_simple_recursive_pure(i - 1)
  24. end if
  25. end function func_simple_recursive_pure
  26. ! An elemental simple function
  27. elemental logical function func_simple_elemental()
  28. func_simple_elemental = .true.
  29. end function func_simple_elemental
  30. ! A module with nonsense
  31. module bar
  32. type food
  33. integer :: cooking_method
  34. end type food
  35. type organic
  36. integer :: growing_method
  37. end type organic
  38. integer, parameter :: i_am_dim = 10
  39. end module bar
  40. ! A module with more nonsense
  41. module foo
  42. use bar, only: FOOD
  43. integer :: foo_int
  44. contains
  45. subroutine foo_sub(egg)
  46. integer, parameter :: egg_dim = 10
  47. type(Food), intent(in) :: egg
  48. write(*, *) egg
  49. end subroutine foo_sub
  50. elemental function foo_func() result(f)
  51. integer :: f
  52. f = 0
  53. end function
  54. end module foo
  55. ! An function with arguments and module imports
  56. integer(selected_int_kind(0)) function func_with_use_and_args(egg, ham)
  57. use foo
  58. ! Deliberate trailing spaces in next line
  59. use bar, only : organic, i_am_dim
  60. implicit none
  61. integer, intent(in) :: egg(i_am_dim)
  62. integer, intent(in) :: ham(i_am_dim, 2)
  63. real bacon
  64. ! Deliberate trailing spaces in next line
  65. type( organic ) :: tomato
  66. func_with_use_and_args = egg(1) + ham(1, 1)
  67. end function func_with_use_and_args
  68. ! A function with some parameters
  69. character(20) function func_with_parameters(egg, ham)
  70. implicit none
  71. character*(*), parameter :: x_param = '01234567890'
  72. character(*), parameter :: & ! throw in some comments
  73. y_param &
  74. = '!&!&!&!&!&!' ! how to make life interesting
  75. integer, parameter :: z = 20
  76. character(len(x_param)), intent(in) :: egg
  77. character(len(y_param)), intent(in) :: ham
  78. func_with_parameters = egg // ham
  79. end function func_with_parameters
  80. ! A function with some parameters, with a result
  81. function func_with_parameters_1(egg, ham) result(r)
  82. implicit none
  83. integer, parameter :: x_param = 10
  84. integer z_param
  85. parameter(z_param = 2)
  86. real, intent(in), dimension(x_param) :: egg
  87. integer, intent(in) :: ham
  88. logical :: r(z_param)
  89. r(1) = int(egg(1)) + ham > 0
  90. r(2) = .false.
  91. end function func_with_parameters_1
  92. ! A function with a contains
  93. character(10) function func_with_contains(mushroom, tomoato)
  94. character(5) mushroom
  95. character(5) tomoato
  96. func_with_contains = func_with_contains_1()
  97. contains
  98. character(10) function func_with_contains_1()
  99. func_with_contains_1 = mushroom // tomoato
  100. end function func_with_contains_1
  101. end function func_with_contains
  102. ! A function with its result declared after a local in the same statement
  103. Function func_mix_local_and_result(egg, ham, bacon) Result(Breakfast)
  104. Integer, Intent(in) :: egg, ham
  105. Real, Intent(in) :: bacon
  106. Real :: tomato, breakfast
  107. Breakfast = real(egg) + real(ham) + bacon
  108. End Function func_mix_local_and_result
  109. ! A simple subroutine
  110. subroutine sub_simple()
  111. end subroutine sub_simple
  112. ! A simple subroutine, with not so friendly end
  113. subroutine sub_simple_1()
  114. end subroutine
  115. ! A simple subroutine, with even less friendly end
  116. subroutine sub_simple_2()
  117. end
  118. ! A simple subroutine, with funny continuation
  119. subroutine sub_simple_3()
  120. end sub&
  121. &routine&
  122. & sub_simple_3
  123. ! A subroutine with a few contains
  124. subroutine sub_with_contains(foo) ! " &
  125. ! Deliberate trailing spaces in next line
  126. use Bar, only: i_am_dim
  127. character*(len('!"&''&"!')) & ! what a mess!
  128. foo
  129. call sub_with_contains_first()
  130. call sub_with_contains_second()
  131. call sub_with_contains_third()
  132. print*, foo
  133. contains
  134. subroutine sub_with_contains_first()
  135. interface
  136. integer function x()
  137. end function x
  138. end interface
  139. end subroutine sub_with_contains_first
  140. subroutine sub_with_contains_second()
  141. end subroutine
  142. subroutine sub_with_contains_third()
  143. end subroutine
  144. end subroutine sub_with_contains
  145. ! A subroutine with a renamed module import
  146. subroutine sub_with_renamed_import(i_am_dim)
  147. use bar, only: i_am_not_dim => i_am_dim
  148. integer, parameter :: d = 2
  149. complex :: i_am_dim(d)
  150. print*, i_am_dim
  151. end subroutine sub_with_renamed_import
  152. ! A subroutine with an external argument
  153. subroutine sub_with_external(proc)
  154. external proc
  155. call proc()
  156. end subroutine sub_with_external
  157. ! A subroutine with a variable named "end"
  158. subroutine sub_with_end()
  159. integer :: end
  160. end = 0
  161. end subroutine sub_with_end