164 lines · plain
1! RUN: %python %S/test_folding.py %s %flang_fc12! Test folding of structure constructors3module m14 type parent_type5 integer :: parent_field6 end type parent_type7 type, extends(parent_type) :: child_type8 integer :: child_field9 end type child_type10 type parent_array_type11 integer, dimension(2) :: parent_field12 end type parent_array_type13 type, extends(parent_array_type) :: child_array_type14 integer :: child_field15 end type child_array_type16 17 type(child_type), parameter :: child_const1 = child_type(10, 11)18 logical, parameter :: test_child1 = child_const1%child_field == 1119 logical, parameter :: test_parent = child_const1%parent_field == 1020 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 == 1725 logical, parameter :: test_array_parent = array_var(2)%parent_field == 1626 27 type array_type28 real, dimension(3) :: real_field29 end type array_type30 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.033 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_field38 logical, parameter :: test_child2 = int_const4(1) == 1839 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) == 2344 45 type(child_type), parameter :: child_const7 = child_type(28, 29)46 type(parent_type), parameter :: parent_const8 = child_const7%parent_type47 logical, parameter :: test_child4 = parent_const8%parent_field == 2848 49 type(child_type), parameter :: child_const9 = &50 child_type(parent_type(30), 31)51 integer, parameter :: int_const10 = child_const9%parent_field52 logical, parameter :: test_child5 = int_const10 == 3053 54end module m155 56module m257 type grandparent_type58 real :: grandparent_field59 end type grandparent_type60 type, extends(grandparent_type) :: parent_type61 integer :: parent_field62 end type parent_type63 type, extends(parent_type) :: child_type64 real :: child_field65 end type child_type66 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_field70 logical, parameter :: test_child1 = int_const2 == 10.071 integer, parameter :: int_const3 = &72 child_const1%grandparent_field73 logical, parameter :: test_child2 = int_const3 == 10.074 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_field79 logical, parameter :: test_child3 = int_const5 == 13.080 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_field85 logical, parameter :: test_child4 = int_const7 == 16.086 integer, parameter :: int_const8 = &87 child_const6%grandparent_field88 logical, parameter :: test_child5 = int_const8 == 16.089end module m290 91module m392 ! tests that use components with default initializations and with the93 ! components in the structure constructors in a different order from the94 ! declared order95 type parent_type96 integer :: parent_field197 real :: parent_field2 = 20.098 logical :: parent_field399 end type parent_type100 type, extends(parent_type) :: child_type101 real :: child_field1102 logical :: child_field2 = .false.103 integer :: child_field3104 end type child_type105 106 type(child_type), parameter :: child_const1 = &107 child_type( &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.3112 logical, parameter :: test_child2 = child_const1%child_field2 .eqv. .true.113 logical, parameter :: test_child3 = child_const1%child_field3 == 11114 logical, parameter :: test_parent1 = child_const1%parent_field1 == 12115 logical, parameter :: test_parent2 = child_const1%parent_field2 == 10.0116 logical, parameter :: test_parent3 = child_const1%parent_field3 .eqv. .false.117 logical, parameter :: test_parent4 = &118 child_const1%parent_type%parent_field1 == 12119 logical, parameter :: test_parent5 = &120 child_const1%parent_type%parent_field2 == 10.0121 logical, parameter :: test_parent6 = &122 child_const1%parent_type%parent_field3 .eqv. .false.123 124 type(parent_type), parameter ::parent_const1 = child_const1%parent_type125 logical, parameter :: test_parent7 = parent_const1%parent_field1 == 12126 logical, parameter :: test_parent8 = parent_const1%parent_field2 == 10.0127 logical, parameter :: test_parent9 = &128 parent_const1%parent_field3 .eqv. .false.129 130 type(child_type), parameter :: child_const2 = &131 child_type( &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.6135 logical, parameter :: test_child5 = child_const2%child_field2 .eqv. .false.136 logical, parameter :: test_child6 = child_const2%child_field3 == 14137 logical, parameter :: test_parent10 = child_const2%parent_field1 == 15138 logical, parameter :: test_parent11 = child_const2%parent_field2 == 20.0139 logical, parameter :: test_parent12 = child_const2%parent_field3 .eqv. .true.140 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 == 18146 logical, parameter :: test_child8 = child_const3%parent_field2 == 17.7147 logical, parameter :: test_child9 = child_const3%parent_field3 .eqv. .false.148 logical, parameter :: test_child10 = child_const3%child_field1 == 19.9149 logical, parameter :: test_child11 = child_const3%child_field2 .eqv. .false.150 logical, parameter :: test_child12 = child_const3%child_field3 == 21151 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 == 22157 logical, parameter :: test_child14 = child_const4%parent_field2 == 20.0158 logical, parameter :: test_child15 = child_const4%parent_field3 .eqv. .true.159 logical, parameter :: test_child16 = child_const4%child_field1 == 23.4160 logical, parameter :: test_child17 = child_const4%child_field2 .eqv. .false.161 logical, parameter :: test_child18 = child_const4%child_field3 == 24162 163end module m3164