Skip to content

Commit

Permalink
multi-functions contained in a function
Browse files Browse the repository at this point in the history
  • Loading branch information
shaoxc committed Mar 23, 2024
1 parent 8454c5a commit beded7d
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 24 deletions.
27 changes: 27 additions & 0 deletions examples/subroutine_contains_issue101/test.f90
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,30 @@ function member_function3(a) result(b)
b = 3 * a
end function member_function3
end subroutine routine_member_procedures2

function function_member_procedures(in1, in2, out1, out2) result(out3)
! Test member subroutine and function
implicit none
integer, intent(in) :: in1, in2
integer, intent(out) :: out1, out2
integer :: out3

out1 = member_function(in1)
out2 = member_function2(in2)
out3 = out1 + out2
contains
function member_function(a) result(b)
implicit none
integer, intent(in) :: a
integer :: b

b = 3 * a + 2
end function member_function
function member_function2(a) result(b)
implicit none
integer, intent(in) :: a
integer :: b

b = 2 * a
end function member_function2
end function function_member_procedures
73 changes: 49 additions & 24 deletions f90wrap/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,7 @@ def check_funct(cl, file, grab_hold_doc=True):

cl = file.next()

cont = 0
subroutine_lines = []
while True:

Expand All @@ -956,35 +957,59 @@ def check_funct(cl, file, grab_hold_doc=True):
cl = file.next()
continue

# Doc comment - return value
check = check_doc_rv(cl, file)
if check[0] != None:
out.ret_val_doc.append(check[0])
# contains statement
check = check_cont(cl, file)
if check[0] is not None:
cont = 1
cl = check[1]
continue

# Doc comment
check = check_doc(cl, file)
if check[0] != None:
out.doc.append(check[0])
cl = check[1]
continue
if cont == 0:
# Doc comment - return value
check = check_doc_rv(cl, file)
if check[0] != None:
out.ret_val_doc.append(check[0])
cl = check[1]
continue

# Interface section
check = check_interface_decl(cl, file)
if check[0] != None:
for a in check[0].procedures:
out.arguments.append(a)
cl = check[1]
continue
# Doc comment
check = check_doc(cl, file)
if check[0] != None:
out.doc.append(check[0])
cl = check[1]
continue

# Argument
check = check_arg(cl, file)
if check[0] != None:
for a in check[0]:
out.arguments.append(a)
# Interface section
check = check_interface_decl(cl, file)
if check[0] != None:
for a in check[0].procedures:
out.arguments.append(a)
cl = check[1]
continue
continue

# Argument
check = check_arg(cl, file)
if check[0] != None:
for a in check[0]:
out.arguments.append(a)
cl = check[1]
continue

else:
while True :
# Subroutine definition
check = check_subt(cl, file)
if check[0] is not None:
# Discard contained subroutine
cl = check[1]
continue

# Function definition
check = check_funct(cl, file)
if check[0] is not None:
# Discard contained function
cl = check[1]
continue
break

m = re.match(funct_end, cl)

Expand Down

0 comments on commit beded7d

Please sign in to comment.