Skip to content

Commit 3f10136

Browse files
committed
poly_type: add abstract interface
1 parent a483b35 commit 3f10136

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

src/fortran/poly_type_lib.f90

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,36 @@ module poly_type
55
implicit none (type, external)
66

77
type, abstract :: base
8-
integer(c_int) :: A, C
8+
9+
integer(c_int) :: A, C
10+
11+
contains
12+
13+
procedure(constructor), deferred :: init
14+
915
end type base
1016

1117
type, extends(base) :: vthree
12-
integer(c_int) :: B = 3
18+
integer(c_int) :: B
19+
20+
contains
21+
procedure :: init => init_three
1322
end type vthree
1423

1524
type, extends(base) :: vfour
16-
integer(c_int) :: B = 4
25+
integer(c_int) :: B
26+
contains
27+
procedure :: init => init_four
1728
end type vfour
1829

30+
31+
abstract interface
32+
subroutine constructor(self)
33+
import base
34+
class(base), intent(inout) :: self
35+
end subroutine constructor
36+
end interface
37+
1938
contains
2039

2140

@@ -40,9 +59,27 @@ subroutine init_type(xtype, xC) bind(C)
4059
error stop "unknown init type"
4160
end select
4261

62+
x%C = 0
63+
64+
call x%init()
65+
4366
end subroutine init_type
4467

4568

69+
subroutine init_three(self)
70+
class(vthree), intent(inout) :: self
71+
72+
self%B = 3
73+
end subroutine
74+
75+
76+
subroutine init_four(self)
77+
class(vfour), intent(inout) :: self
78+
79+
self%B = 4
80+
end subroutine
81+
82+
4683
function assoc_type(xtype, xC) result(x)
4784
integer(c_int) :: xtype
4885
type(C_PTR), intent(inout) :: xC

0 commit comments

Comments
 (0)