From beded7dc55da52d227913d47fa0250b82f9f57d1 Mon Sep 17 00:00:00 2001 From: shaoxc Date: Sat, 23 Mar 2024 18:18:32 -0400 Subject: [PATCH] multi-functions contained in a function --- .../subroutine_contains_issue101/test.f90 | 27 +++++++ f90wrap/parser.py | 73 +++++++++++++------ 2 files changed, 76 insertions(+), 24 deletions(-) diff --git a/examples/subroutine_contains_issue101/test.f90 b/examples/subroutine_contains_issue101/test.f90 index 7a0c96fe..4684cabc 100644 --- a/examples/subroutine_contains_issue101/test.f90 +++ b/examples/subroutine_contains_issue101/test.f90 @@ -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 diff --git a/f90wrap/parser.py b/f90wrap/parser.py index 3e754504..90ebcfbd 100644 --- a/f90wrap/parser.py +++ b/f90wrap/parser.py @@ -930,6 +930,7 @@ def check_funct(cl, file, grab_hold_doc=True): cl = file.next() + cont = 0 subroutine_lines = [] while True: @@ -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)