Changes in tests/raii/dtor-early-exit.c [200fcb3:5a5d31a]
- File:
-
- 1 edited
-
tests/raii/dtor-early-exit.c (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tests/raii/dtor-early-exit.c
r200fcb3 r5a5d31a 10 10 // Created On : Wed Aug 17 08:26:25 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 11 22:05:24201813 // Update Count : 912 // Last Modified On : Sat Aug 11 07:58:39 2018 13 // Update Count : 8 14 14 // 15 15 … … 25 25 // don't want these called 26 26 void ?{}(A & a) { assert( false ); } 27 void ?{}(A & a, const char * name) { a.name = name; sout | "construct " | name ; a.x = (int*)malloc(); }27 void ?{}(A & a, const char * name) { a.name = name; sout | "construct " | name | endl; a.x = (int*)malloc(); } 28 28 void ?{}(A & a, const char * name, int * ptr) { assert( false ); } 29 29 30 30 A ?=?(A & a, A b) { sout | "assign " | a.name | " " | b.name; return a; } 31 void ?{}(A & a, A b) { sout | "copy construct " | b.name ; a.x = (int*)malloc(); }32 void ^?{}(A & a) { sout | "destruct " | a.name ; free(a.x); }31 void ?{}(A & a, A b) { sout | "copy construct " | b.name | endl; a.x = (int*)malloc(); } 32 void ^?{}(A & a) { sout | "destruct " | a.name | endl; free(a.x); } 33 33 34 34 // test returns 35 35 void f(int i) { 36 sout | "f i=" | i ;36 sout | "f i=" | i | endl; 37 37 A x = { "x" }; // construct x 38 38 { … … 55 55 void g() { 56 56 for (int i = 0; i < 10; i++) { 57 sout | "g for i=" | i ;57 sout | "g for i=" | i | endl; 58 58 A x = { "x" }; 59 59 // construct x 60 60 // destruct x 61 61 } 62 sout | nl;62 sout | endl; 63 63 { 64 64 int i = 0; 65 65 while (i < 10) { 66 sout | "g while i=" | i ;66 sout | "g while i=" | i | endl; 67 67 A x = { "x" }; 68 68 // construct x … … 71 71 } 72 72 } 73 sout ;73 sout | endl; 74 74 for (int i = 0; i < 10; i++) { 75 75 switch(10) { … … 78 78 case 10: { 79 79 A y = { "y" }; 80 sout | "g switch i=" | i ;80 sout | "g switch i=" | i | endl; 81 81 // construct y 82 82 break; // destruct y 83 83 } 84 84 default: { 85 sout | "g switch i=" | i ;85 sout | "g switch i=" | i | endl; 86 86 A x = { "x" }; 87 87 // construct x … … 90 90 } 91 91 } 92 sout | nl;92 sout | endl; 93 93 for (int k = 0; k < 2; k++) { 94 sout | "g for k=" | k ;94 sout | "g for k=" | k | endl; 95 95 L1: for (int i = 0; i < 10; i++) { 96 sout | "g for i=" | i ;96 sout | "g for i=" | i | endl; 97 97 98 98 A x = { "x" }; 99 99 if (i == 2) { 100 sout | "continue L1" ;100 sout | "continue L1" | endl; 101 101 continue; // destruct x 102 102 } else if (i == 3) { 103 sout | "break L1" ;103 sout | "break L1" | endl; 104 104 break; // destruct x 105 105 } 106 106 107 107 L2: for (int j = 0; j < 10; j++) { 108 sout | "g for j=" | j ;108 sout | "g for j=" | j | endl; 109 109 A y = { "y" }; 110 110 if (j == 0) { 111 sout | "continue L2" ;111 sout | "continue L2" | endl; 112 112 continue; // destruct y - missing because object that needs to be destructed is not a part of this block, it's a part of the for's block 113 113 } else if (j == 1) { 114 sout | "break L2" ;114 sout | "break L2" | endl; 115 115 break; // destruct y 116 116 } else if (i == 1) { 117 sout | "continue L1" ;117 sout | "continue L1" | endl; 118 118 continue L1; // destruct x,y - note: continue takes you to destructors for block, so only generate destructor for y 119 119 } else if (k == 1) { 120 sout | "break L1" ;120 sout | "break L1" | endl; 121 121 break L1; // destruct x,y 122 122 } … … 125 125 } 126 126 127 sout | nl;127 sout | endl; 128 128 L3: if( 3 ) { 129 129 A w = { "w" }; 130 130 if( 4 ) { 131 131 A v = { "v" }; 132 sout | "break L3" ;132 sout | "break L3" | endl; 133 133 break L3; 134 134 } … … 144 144 // * if S_L-S_G is non-empty, error 145 145 // * emit destructors for all variables in S_G-S_L 146 sout | "h" ;146 sout | "h" | endl; 147 147 { 148 148 L0: ; … … 152 152 A y = { "y" }; 153 153 // S_L1 = { y } 154 L1: sout | "L1" ;154 L1: sout | "L1" | endl; 155 155 A x = { "x" }; 156 156 // S_L2 = { y, x } 157 L2: sout | "L2" ;157 L2: sout | "L2" | endl; 158 158 if (i == 0) { 159 159 ++i; 160 sout | "goto L1" ;160 sout | "goto L1" | endl; 161 161 // S_G = { y, x } 162 162 goto L1; // jump back, destruct b/c before x definition … … 165 165 } else if (i == 1) { 166 166 ++i; 167 sout | "goto L2" ;167 sout | "goto L2" | endl; 168 168 // S_G = { y, x } 169 169 goto L2; // jump back, do not destruct … … 172 172 } else if (i == 2) { 173 173 ++i; 174 sout | "goto L3" ;174 sout | "goto L3" | endl; 175 175 // S_G = { y, x } 176 176 goto L3; // jump ahead, do not destruct … … 180 180 ++i; 181 181 A z = { "z" }; 182 sout | "goto L3-2" ;182 sout | "goto L3-2" | endl; 183 183 // S_G = { z, y, x } 184 184 goto L3; … … 187 187 } else { 188 188 ++i; 189 sout | "goto L4" ;189 sout | "goto L4" | endl; 190 190 // S_G = { y, x } 191 191 goto L4; // jump ahead, destruct b/c left block x was defined in … … 194 194 } 195 195 // S_L3 = { y, x } 196 L3: sout | "L3" ;197 sout | "goto L2-2" ;196 L3: sout | "L3" | endl; 197 sout | "goto L2-2" | endl; 198 198 // S_G = { y, x } 199 199 goto L2; // jump back, do not destruct … … 202 202 } 203 203 // S_L4 = {} 204 L4: sout | "L4" ;204 L4: sout | "L4" | endl; 205 205 if (i == 4) { 206 sout | "goto L0" ;206 sout | "goto L0" | endl; 207 207 // S_G = {} 208 208 goto L0; … … 240 240 f(i); 241 241 } 242 sout | nl;242 sout | endl; 243 243 g(); 244 sout | nl;244 sout | endl; 245 245 h(); 246 246
Note:
See TracChangeset
for help on using the changeset viewer.