Changeset b067d9b for tests/raii/dtor-early-exit.cfa
- Timestamp:
- Oct 29, 2019, 4:01:24 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
- Children:
- 773db65, 9421f3d8
- Parents:
- 7951100 (diff), 8364209 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 moved
-
tests/raii/dtor-early-exit.cfa (moved) (moved from src/tests/raii/dtor-early-exit.c ) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tests/raii/dtor-early-exit.cfa
r7951100 rb067d9b 10 10 // Created On : Wed Aug 17 08:26:25 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Aug 17 08:29:37 2016 13 // Update Count : 2 14 // 15 16 #include <fstream> 17 #include <stdlib> 18 extern "C" { 19 #define false ((int)0) // until stdbool.h works 20 #define assert(cond) if (! (cond)) { sout | "Assertion failed: (" | #cond | ") at " __FILE__ | ":" | __LINE__ | endl; abort(); } 21 } 12 // Last Modified On : Fri Dec 21 08:45:19 2018 13 // Update Count : 10 14 // 15 16 #include <fstream.hfa> 17 #include <stdlib.hfa> 18 #include <assert.h> 22 19 23 20 struct A { … … 28 25 // don't want these called 29 26 void ?{}(A & a) { assert( false ); } 30 void ?{}(A & a, const char * name) { a.name = name; sout | "construct " | name | endl; a.x = (int*)malloc(); }27 void ?{}(A & a, const char * name) { a.name = name; sout | "construct " | name; a.x = (int*)malloc(); } 31 28 void ?{}(A & a, const char * name, int * ptr) { assert( false ); } 32 29 33 30 A ?=?(A & a, A b) { sout | "assign " | a.name | " " | b.name; return a; } 34 void ?{}(A & a, A b) { sout | "copy construct " | b.name | endl; a.x = (int*)malloc(); }35 void ^?{}(A & a) { sout | "destruct " | a.name | endl; free(a.x); }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); } 36 33 37 34 // test returns 38 35 void f(int i) { 39 sout | "f i=" | i | endl;36 sout | "f i=" | i; 40 37 A x = { "x" }; // construct x 41 38 { … … 58 55 void g() { 59 56 for (int i = 0; i < 10; i++) { 60 sout | "g for i=" | i | endl;57 sout | "g for i=" | i; 61 58 A x = { "x" }; 62 59 // construct x 63 60 // destruct x 64 61 } 65 sout | endl;62 sout | nl; 66 63 { 67 64 int i = 0; 68 65 while (i < 10) { 69 sout | "g while i=" | i | endl;66 sout | "g while i=" | i; 70 67 A x = { "x" }; 71 68 // construct x … … 74 71 } 75 72 } 76 sout | endl;73 sout | nl; 77 74 for (int i = 0; i < 10; i++) { 78 75 switch(10) { … … 81 78 case 10: { 82 79 A y = { "y" }; 83 sout | "g switch i=" | i | endl;80 sout | "g switch i=" | i; 84 81 // construct y 85 82 break; // destruct y 86 83 } 87 84 default: { 88 sout | "g switch i=" | i | endl;85 sout | "g switch i=" | i; 89 86 A x = { "x" }; 90 87 // construct x … … 93 90 } 94 91 } 95 sout | endl;92 sout | nl; 96 93 for (int k = 0; k < 2; k++) { 97 sout | "g for k=" | k | endl;94 sout | "g for k=" | k; 98 95 L1: for (int i = 0; i < 10; i++) { 99 sout | "g for i=" | i | endl;96 sout | "g for i=" | i; 100 97 101 98 A x = { "x" }; 102 99 if (i == 2) { 103 sout | "continue L1" | endl;100 sout | "continue L1"; 104 101 continue; // destruct x 105 102 } else if (i == 3) { 106 sout | "break L1" | endl;103 sout | "break L1"; 107 104 break; // destruct x 108 105 } 109 106 110 107 L2: for (int j = 0; j < 10; j++) { 111 sout | "g for j=" | j | endl;108 sout | "g for j=" | j; 112 109 A y = { "y" }; 113 110 if (j == 0) { 114 sout | "continue L2" | endl;111 sout | "continue L2"; 115 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 116 113 } else if (j == 1) { 117 sout | "break L2" | endl;114 sout | "break L2"; 118 115 break; // destruct y 119 116 } else if (i == 1) { 120 sout | "continue L1" | endl;117 sout | "continue L1"; 121 118 continue L1; // destruct x,y - note: continue takes you to destructors for block, so only generate destructor for y 122 119 } else if (k == 1) { 123 sout | "break L1" | endl;120 sout | "break L1"; 124 121 break L1; // destruct x,y 125 122 } … … 128 125 } 129 126 130 sout | endl;127 sout | nl; 131 128 L3: if( 3 ) { 132 129 A w = { "w" }; 133 130 if( 4 ) { 134 131 A v = { "v" }; 135 sout | "break L3" | endl;132 sout | "break L3"; 136 133 break L3; 137 134 } … … 147 144 // * if S_L-S_G is non-empty, error 148 145 // * emit destructors for all variables in S_G-S_L 149 sout | "h" | endl;146 sout | "h"; 150 147 { 151 148 L0: ; … … 155 152 A y = { "y" }; 156 153 // S_L1 = { y } 157 L1: sout | "L1" | endl;154 L1: sout | "L1"; 158 155 A x = { "x" }; 159 156 // S_L2 = { y, x } 160 L2: sout | "L2" | endl;157 L2: sout | "L2"; 161 158 if (i == 0) { 162 159 ++i; 163 sout | "goto L1" | endl;160 sout | "goto L1"; 164 161 // S_G = { y, x } 165 162 goto L1; // jump back, destruct b/c before x definition … … 168 165 } else if (i == 1) { 169 166 ++i; 170 sout | "goto L2" | endl;167 sout | "goto L2"; 171 168 // S_G = { y, x } 172 169 goto L2; // jump back, do not destruct … … 175 172 } else if (i == 2) { 176 173 ++i; 177 sout | "goto L3" | endl;174 sout | "goto L3"; 178 175 // S_G = { y, x } 179 176 goto L3; // jump ahead, do not destruct … … 183 180 ++i; 184 181 A z = { "z" }; 185 sout | "goto L3-2" | endl;182 sout | "goto L3-2"; 186 183 // S_G = { z, y, x } 187 184 goto L3; … … 190 187 } else { 191 188 ++i; 192 sout | "goto L4" | endl;189 sout | "goto L4"; 193 190 // S_G = { y, x } 194 191 goto L4; // jump ahead, destruct b/c left block x was defined in … … 197 194 } 198 195 // S_L3 = { y, x } 199 L3: sout | "L3" | endl;200 sout | "goto L2-2" | endl;196 L3: sout | "L3"; 197 sout | "goto L2-2"; 201 198 // S_G = { y, x } 202 199 goto L2; // jump back, do not destruct … … 205 202 } 206 203 // S_L4 = {} 207 L4: sout | "L4" | endl;204 L4: sout | "L4"; 208 205 if (i == 4) { 209 sout | "goto L0" | endl;206 sout | "goto L0"; 210 207 // S_G = {} 211 208 goto L0; … … 243 240 f(i); 244 241 } 245 sout | endl;242 sout | nl; 246 243 g(); 247 sout | endl;244 sout | nl; 248 245 h(); 249 246
Note:
See TracChangeset
for help on using the changeset viewer.