1 ! RUN: %python %S/test_folding.py %s %flang_fc1
2 ! Test folding of structure constructors
5 integer :: parent_field
7 type, extends(parent_type
) :: child_type
10 type parent_array_type
11 integer, dimension(2) :: parent_field
12 end type parent_array_type
13 type, extends(parent_array_type
) :: child_array_type
14 integer :: child_field
15 end type child_array_type
17 type(child_type
), parameter :: child_const1
= child_type(10, 11)
18 logical, parameter :: test_child1
= child_const1
%child_field
== 11
19 logical, parameter :: test_parent
= child_const1
%parent_field
== 10
21 type(child_type
), parameter :: child_const2
= child_type(12, 13)
22 type(child_type
), parameter :: array_var(2) = &
23 [child_type(14, 15), child_type(16, 17)]
24 logical, parameter :: test_array_child
= array_var(2)%child_field
== 17
25 logical, parameter :: test_array_parent
= array_var(2)%parent_field
== 16
28 real, dimension(3) :: real_field
30 type(array_type
), parameter :: array_var2
= &
31 array_type([(real(i
*i
), i
= 1,3)])
32 logical, parameter :: test_array_var
= array_var2
%real_field(2) == 4.0
34 type(child_type
), parameter, dimension(2) :: child_const3
= &
35 [child_type(18, 19), child_type(20, 21)]
36 integer, dimension(2), parameter :: int_const4
= &
37 child_const3(:)%parent_field
38 logical, parameter :: test_child2
= int_const4(1) == 18
40 type(child_array_type
), parameter, dimension(2) :: child_const5
= &
41 [child_array_type([22, 23], 24), child_array_type([25, 26], 27)]
42 integer, dimension(2), parameter :: int_const6
= child_const5(:)%parent_field(2)
43 logical, parameter :: test_child3
= int_const6(1) == 23
45 type(child_type
), parameter :: child_const7
= child_type(28, 29)
46 type(parent_type
), parameter :: parent_const8
= child_const7
%parent_type
47 logical, parameter :: test_child4
= parent_const8
%parent_field
== 28
49 type(child_type
), parameter :: child_const9
= &
50 child_type(parent_type(30), 31)
51 integer, parameter :: int_const10
= child_const9
%parent_field
52 logical, parameter :: test_child5
= int_const10
== 30
58 real :: grandparent_field
59 end type grandparent_type
60 type, extends(grandparent_type
) :: parent_type
61 integer :: parent_field
63 type, extends(parent_type
) :: child_type
67 type(child_type
), parameter :: child_const1
= child_type(10.0, 11, 12.0)
68 integer, parameter :: int_const2
= &
69 child_const1
%grandparent_type
%grandparent_field
70 logical, parameter :: test_child1
= int_const2
== 10.0
71 integer, parameter :: int_const3
= &
72 child_const1
%grandparent_field
73 logical, parameter :: test_child2
= int_const3
== 10.0
75 type(child_type
), parameter :: child_const4
= &
76 child_type(parent_type(13.0, 14), 15.0)
77 integer, parameter :: int_const5
= &
78 child_const4
%grandparent_type
%grandparent_field
79 logical, parameter :: test_child3
= int_const5
== 13.0
81 type(child_type
), parameter :: child_const6
= &
82 child_type(parent_type(grandparent_type(16.0), 17), 18.0)
83 integer, parameter :: int_const7
= &
84 child_const6
%grandparent_type
%grandparent_field
85 logical, parameter :: test_child4
= int_const7
== 16.0
86 integer, parameter :: int_const8
= &
87 child_const6
%grandparent_field
88 logical, parameter :: test_child5
= int_const8
== 16.0
92 ! tests that use components with default initializations and with the
93 ! components in the structure constructors in a different order from the
96 integer :: parent_field1
97 real :: parent_field2
= 20.0
98 logical :: parent_field3
100 type, extends(parent_type
) :: child_type
102 logical :: child_field2
= .false
.
103 integer :: child_field3
106 type(child_type
), parameter :: child_const1
= &
108 parent_field2
= 10.0, child_field3
= 11, &
109 child_field2
= .true
., parent_field3
= .false
., &
110 parent_field1
= 12, child_field1
= 13.3)
111 logical, parameter :: test_child1
= child_const1
%child_field1
== 13.3
112 logical, parameter :: test_child2
= child_const1
%child_field2
.eqv
. .true
.
113 logical, parameter :: test_child3
= child_const1
%child_field3
== 11
114 logical, parameter :: test_parent1
= child_const1
%parent_field1
== 12
115 logical, parameter :: test_parent2
= child_const1
%parent_field2
== 10.0
116 logical, parameter :: test_parent3
= child_const1
%parent_field3
.eqv
. .false
.
117 logical, parameter :: test_parent4
= &
118 child_const1
%parent_type
%parent_field1
== 12
119 logical, parameter :: test_parent5
= &
120 child_const1
%parent_type
%parent_field2
== 10.0
121 logical, parameter :: test_parent6
= &
122 child_const1
%parent_type
%parent_field3
.eqv
. .false
.
124 type(parent_type
), parameter ::parent_const1
= child_const1
%parent_type
125 logical, parameter :: test_parent7
= parent_const1
%parent_field1
== 12
126 logical, parameter :: test_parent8
= parent_const1
%parent_field2
== 10.0
127 logical, parameter :: test_parent9
= &
128 parent_const1
%parent_field3
.eqv
. .false
.
130 type(child_type
), parameter :: child_const2
= &
132 child_field3
= 14, parent_field3
= .true
., &
133 parent_field1
= 15, child_field1
= 16.6)
134 logical, parameter :: test_child4
= child_const2
%child_field1
== 16.6
135 logical, parameter :: test_child5
= child_const2
%child_field2
.eqv
. .false
.
136 logical, parameter :: test_child6
= child_const2
%child_field3
== 14
137 logical, parameter :: test_parent10
= child_const2
%parent_field1
== 15
138 logical, parameter :: test_parent11
= child_const2
%parent_field2
== 20.0
139 logical, parameter :: test_parent12
= child_const2
%parent_field3
.eqv
. .true
.
141 type(child_type
), parameter :: child_const3
= &
142 child_type(parent_type( &
143 parent_field2
= 17.7, parent_field3
= .false
., parent_field1
= 18), &
144 child_field2
= .false
., child_field1
= 19.9, child_field3
= 21)
145 logical, parameter :: test_child7
= child_const3
%parent_field1
== 18
146 logical, parameter :: test_child8
= child_const3
%parent_field2
== 17.7
147 logical, parameter :: test_child9
= child_const3
%parent_field3
.eqv
. .false
.
148 logical, parameter :: test_child10
= child_const3
%child_field1
== 19.9
149 logical, parameter :: test_child11
= child_const3
%child_field2
.eqv
. .false
.
150 logical, parameter :: test_child12
= child_const3
%child_field3
== 21
152 type(child_type
), parameter :: child_const4
= &
153 child_type(parent_type( &
154 parent_field3
= .true
., parent_field1
= 22), &
155 child_field1
= 23.4, child_field3
= 24)
156 logical, parameter :: test_child13
= child_const4
%parent_field1
== 22
157 logical, parameter :: test_child14
= child_const4
%parent_field2
== 20.0
158 logical, parameter :: test_child15
= child_const4
%parent_field3
.eqv
. .true
.
159 logical, parameter :: test_child16
= child_const4
%child_field1
== 23.4
160 logical, parameter :: test_child17
= child_const4
%child_field2
.eqv
. .false
.
161 logical, parameter :: test_child18
= child_const4
%child_field3
== 24