aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/gfortran.dg/interface_32.f90
blob: a0f5f15d4a4460b7d1e37ba65f8fe4c0ef8f26e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
! { dg-do compile }
module m1
  implicit none

  type, abstract :: vector_class
  end type vector_class
end module m1
!---------------------------------------------------------------
module m2
  use m1
  implicit none

  type, abstract :: inner_product_class
  contains
    procedure(dot), deferred :: dot_v_v
    procedure(dot), deferred :: dot_g_g
    procedure(sub), deferred :: D_times_v
    procedure(sub), deferred :: D_times_g
  end type inner_product_class

  abstract interface
    function dot (this,a,b)
      import :: inner_product_class
      import :: vector_class
      class(inner_product_class), intent(in) :: this
      class(vector_class),        intent(in) :: a,b
      real                                   :: dot
    end function
    subroutine sub (this,a)
      import :: inner_product_class
      import :: vector_class
      class(inner_product_class), intent(in)    :: this
      class(vector_class),        intent(inout) :: a
    end subroutine
  end interface
end module m2
!---------------------------------------------------------------
module m3
  use :: m1
  use :: m2
  implicit none
  private
  public :: gradient_class

  type, abstract, extends(vector_class) :: gradient_class
    class(inner_product_class), pointer :: my_inner_product => NULL()
  contains
    procedure, non_overridable  :: inquire_inner_product
    procedure(op_g_v), deferred :: to_vector
  end type gradient_class

  abstract interface
    subroutine op_g_v(this,v)
      import vector_class
      import gradient_class
      class(gradient_class), intent(in)    :: this
      class(vector_class),   intent(inout) :: v
    end subroutine
  end interface
contains
  function inquire_inner_product (this)
    class(gradient_class)               :: this
    class(inner_product_class), pointer :: inquire_inner_product

    inquire_inner_product => this%my_inner_product
  end function inquire_inner_product
end module m3
!---------------------------------------------------------------
module m4
  use m3
  use m2
  implicit none
contains
  subroutine cg (g_initial)
    class(gradient_class),  intent(in)    :: g_initial

    class(inner_product_class), pointer   :: ip_save
    ip_save => g_initial%inquire_inner_product()
  end subroutine cg
end module m4