Skip to content

Commit

Permalink
Make the test compile
Browse files Browse the repository at this point in the history
And move it to integration_tests.
  • Loading branch information
certik committed Jul 8, 2021
1 parent 3012134 commit 16f6806
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 49 deletions.
2 changes: 2 additions & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ RUN(NAME reserved_03 LABELS gfortran)

RUN(NAME namelist_01 LABELS gfortran)

RUN(NAME submodule_01 LABELS gfortran)

RUN(NAME intrinsics_01 LABELS gfortran) # sqrt, abs, log
RUN(NAME intrinsics_02 LABELS gfortran llvm) # sin
RUN(NAME intrinsics_03 LABELS gfortran llvm) # cos
Expand Down
103 changes: 103 additions & 0 deletions integration_tests/submodule_01.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
! Submodules test, taken from:
! https://www.ibm.com/docs/en/xl-fortran-aix/15.1.3?topic=techniques-submodules-fortran-2008
MODULE m1
TYPE Base
INTEGER :: i
END TYPE

INTERFACE
MODULE SUBROUTINE sub1(i, b) ! Module procedure interface body for sub1
INTEGER, INTENT(IN) :: i
TYPE(Base), INTENT(IN) :: b
END SUBROUTINE
END INTERFACE
END MODULE

MODULE m2
USE m1 ! Use association of module m1

INTERFACE
REAL MODULE FUNCTION func1() ! Module procedure interface body for func1
END FUNCTION

MODULE FUNCTION func2(b) ! Module procedure interface body for func2
TYPE(Base) :: b
TYPE(Base) :: func2
END FUNCTION
END INTERFACE
END MODULE

MODULE m4
USE m1 ! Use association of module m1
TYPE, EXTENDS(Base) :: NewType
REAL :: j
END TYPE
END MODULE

SUBMODULE (m1) m1sub
USE m4 ! Use association of module m4

CONTAINS
MODULE SUBROUTINE sub1(i, b) ! Implementation of sub1 declared in m1
INTEGER, INTENT(IN) :: i
TYPE(Base), INTENT(IN) :: b
PRINT *, "sub1", i, b
END SUBROUTINE
END SUBMODULE

SUBMODULE (m2) m2sub

CONTAINS
REAL MODULE FUNCTION func1() ! Implementation of func1 declared in m2
func1 = 20
END FUNCTION
END SUBMODULE

SUBMODULE (m2:m2sub) m2sub2

CONTAINS
MODULE FUNCTION func2(b) ! Implementation of func2 declared in m2
TYPE(Base) :: b
TYPE(Base) :: func2
func2 = b
END FUNCTION
END SUBMODULE

MODULE m3
INTERFACE
SUBROUTINE interfaceSub1(i, b)
USE m1
INTEGER, INTENT(IN) :: i
TYPE(Base), INTENT(IN) :: b
END SUBROUTINE

REAL FUNCTION interfaceFunc1()
END FUNCTION

FUNCTION interfaceFunc2(b)
USE m1
TYPE(Base) :: b
TYPE(Base) :: interfaceFunc2
END FUNCTION
END INTERFACE

TYPE Container
PROCEDURE(interfaceSub1), NOPASS, POINTER :: pp1
PROCEDURE(interfaceFunc1), NOPASS, POINTER :: pp2
PROCEDURE(interfaceFunc2), NOPASS, POINTER :: pp3
END TYPE
END MODULE

PROGRAM example
USE m1
USE m2
USE m3
TYPE(Container) :: c1
c1%pp1 => sub1
c1%pp2 => func1
c1%pp3 => func2

CALL c1%pp1(10, Base(11))
PRINT *, "func1", int(c1%pp2())
PRINT *, "func2", c1%pp3(Base(5))
END PROGRAM
34 changes: 0 additions & 34 deletions tests/procedure1.f90

This file was deleted.

13 changes: 0 additions & 13 deletions tests/reference/ast-procedure1-f98f545.json

This file was deleted.

1 change: 0 additions & 1 deletion tests/reference/ast-procedure1-f98f545.stdout

This file was deleted.

13 changes: 13 additions & 0 deletions tests/reference/ast-submodule_01-2524ba9.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "ast-submodule_01-2524ba9",
"cmd": "lfortran --show-ast --no-color {infile} -o {outfile}",
"infile": "tests/../integration_tests/submodule_01.f90",
"infile_hash": "ed0ecc9003bb9cd8e6be1f4f77cd3e59f45d09f2ba2f64029dc3680e",
"outfile": null,
"outfile_hash": null,
"stdout": "ast-submodule_01-2524ba9.stdout",
"stdout_hash": "6d715a6d90ef8db704478de6c2c2db02e580cc5318daa854c4472b63",
"stderr": null,
"stderr_hash": null,
"returncode": 0
}
1 change: 1 addition & 0 deletions tests/reference/ast-submodule_01-2524ba9.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(TranslationUnit [(Module m1 [] [] [(DerivedType Base [] [(Declaration (AttrType TypeInteger [] ()) [] [(i [] [] () None ())])] []) (Interface (InterfaceHeader) [(InterfaceProc (Subroutine sub1 [(i) (b)] [(SimpleAttribute AttrModule)] () [] [] [] [(Declaration (AttrType TypeInteger [] ()) [(AttrIntent In)] [(i [] [] () None ())]) (Declaration (AttrType TypeType [] Base) [(AttrIntent In)] [(b [] [] () None ())])] [] []))])] []) (Module m2 [(Use [] m1 [] .false.)] [] [(Interface (InterfaceHeader) [(InterfaceProc (Function func1 [] [(AttrType TypeReal [] ()) (SimpleAttribute AttrModule)] () () [] [] [] [] [] [])) (InterfaceProc (Function func2 [(b)] [(SimpleAttribute AttrModule)] () () [] [] [] [(Declaration (AttrType TypeType [] Base) [] [(b [] [] () None ())]) (Declaration (AttrType TypeType [] Base) [] [(func2 [] [] () None ())])] [] []))])] []) (Module m4 [(Use [] m1 [] .false.)] [] [(DerivedType NewType [(AttrExtends Base)] [(Declaration (AttrType TypeReal [] ()) [] [(j [] [] () None ())])] [])] []) (Submodule m1 () m1sub [(Use [] m4 [] .false.)] [] [] [(Subroutine sub1 [(i) (b)] [(SimpleAttribute AttrModule)] () [] [] [] [(Declaration (AttrType TypeInteger [] ()) [(AttrIntent In)] [(i [] [] () None ())]) (Declaration (AttrType TypeType [] Base) [(AttrIntent In)] [(b [] [] () None ())])] [(Print 0 () [(Str "sub1") i b])] [])]) (Submodule m2 () m2sub [] [] [] [(Function func1 [] [(AttrType TypeReal [] ()) (SimpleAttribute AttrModule)] () () [] [] [] [] [(= 0 func1 20)] [])]) (Submodule m2 m2sub m2sub2 [] [] [] [(Function func2 [(b)] [(SimpleAttribute AttrModule)] () () [] [] [] [(Declaration (AttrType TypeType [] Base) [] [(b [] [] () None ())]) (Declaration (AttrType TypeType [] Base) [] [(func2 [] [] () None ())])] [(= 0 func2 b)] [])]) (Module m3 [] [] [(Interface (InterfaceHeader) [(InterfaceProc (Subroutine interfaceSub1 [(i) (b)] [] () [(Use [] m1 [] .false.)] [] [] [(Declaration (AttrType TypeInteger [] ()) [(AttrIntent In)] [(i [] [] () None ())]) (Declaration (AttrType TypeType [] Base) [(AttrIntent In)] [(b [] [] () None ())])] [] [])) (InterfaceProc (Function interfaceFunc1 [] [(AttrType TypeReal [] ())] () () [] [] [] [] [] [])) (InterfaceProc (Function interfaceFunc2 [(b)] [] () () [(Use [] m1 [] .false.)] [] [] [(Declaration (AttrType TypeType [] Base) [] [(b [] [] () None ())]) (Declaration (AttrType TypeType [] Base) [] [(interfaceFunc2 [] [] () None ())])] [] []))]) (DerivedType Container [] [(Declaration (AttrType TypeProcedure [] interfaceSub1) [(SimpleAttribute AttrNoPass) (SimpleAttribute AttrPointer)] [(pp1 [] [] () None ())]) (Declaration (AttrType TypeProcedure [] interfaceFunc1) [(SimpleAttribute AttrNoPass) (SimpleAttribute AttrPointer)] [(pp2 [] [] () None ())]) (Declaration (AttrType TypeProcedure [] interfaceFunc2) [(SimpleAttribute AttrNoPass) (SimpleAttribute AttrPointer)] [(pp3 [] [] () None ())])] [])] []) (Program example [(Use [] m1 [] .false.) (Use [] m2 [] .false.) (Use [] m3 [] .false.)] [] [(Declaration (AttrType TypeType [] Container) [] [(c1 [] [] () None ())])] [(=> 0 pp1 sub1) (=> 0 pp2 func1) (=> 0 pp3 func2) (SubroutineCall 0 pp1 [(c1 [])] [(() 10 ()) (() (FuncCallOrArray Base [] [(() 11 ())] [] []) ())] []) (Print 0 () [(Str "func1") (FuncCallOrArray int [] [(() (FuncCallOrArray pp2 [(c1 [])] [] [] []) ())] [] [])]) (Print 0 () [(Str "func2") (FuncCallOrArray pp3 [(c1 [])] [(() (FuncCallOrArray Base [] [(() 5 ())] [] []) ())] [] [])])] [])])
2 changes: 1 addition & 1 deletion tests/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ ast = true
ast_f90 = true

[[test]]
filename = "procedure1.f90"
filename = "../integration_tests/submodule_01.f90"
ast = true

[[test]]
Expand Down

0 comments on commit 16f6806

Please sign in to comment.