- Timestamp:
- Jun 14, 2017, 2:46:27 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 78372fd, 838ef08
- Parents:
- e4e9173
- Location:
- doc/working/exception
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/working/exception/impl/exception.c
re4e9173 r6a48cc9 222 222 ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND; 223 223 shared_stack.current_handler_index = index; 224 225 224 226 225 // Based on the return value, check if we matched the exception -
doc/working/exception/impl/test-main.c
re4e9173 r6a48cc9 9 9 #define CLEANUP(function) \ 10 10 struct __cleanup_hook __hidden_hook __attribute__((cleanup(function))) 11 12 #define SET_UP_RESUME_NODE(handler_function) \ 13 struct __try_resume_node node \ 14 __attribute__((cleanup(__try_resume_node_delete))); \ 15 __try_resume_node_new(&node, handler_function) 11 16 12 17 void __try_resume_node_new(struct __try_resume_node * node, … … 153 158 printf("See you next time\n"); 154 159 } 155 CLEANUP(farewell_finally1); 156 { 157 printf("jump out of farewell\n"); 160 struct __cleanup_hook __hidden_hook 161 __attribute__((cleanup(farewell_finally1))); 162 { 163 printf("walk out of farewell\n"); 158 164 } 159 165 } … … 162 168 // Resume-to-Terminate Test: 163 169 void fallback() { 164 //raii_t a = {"fallback function\n"};165 170 { 166 171 void fallback_try1() { … … 186 191 } 187 192 } 193 194 // Terminate Throw New Exception: 195 void terminate_swap() { 196 raii_t a = {"terminate_swap"}; 197 { 198 void fn_try1() { 199 terminate(2); 200 } 201 void fn_catch1(int index, exception except) { 202 switch (index) { 203 case 1: 204 terminate(1); 205 break; 206 default: 207 printf("INVALID INDEX in terminate_swap: %d (%d)\n", 208 index, except); 209 } 210 } 211 int fn_match1(exception except) { 212 if (2 == except) { 213 return 1; 214 } else { 215 return 0; 216 } 217 } 218 __try_terminate(fn_try1, fn_catch1, fn_match1); 219 } 220 } 221 222 void terminate_swapped() { 223 raii_t a = {"terminate_swapped"}; 224 { 225 void fn_try1() { 226 terminate_swap(); 227 } 228 void fn_catch1(int index, exception except) { 229 switch (index) { 230 case 1: 231 printf("terminate_swapped caught exception 1\n"); 232 break; 233 default: 234 printf("INVALID INDEX in terminate_swapped: %d (%d)\n", 235 index, except); 236 } 237 } 238 int fn_match1(exception except) { 239 if (1 == except) { 240 return 1; 241 } else { 242 return 0; 243 } 244 } 245 __try_terminate(fn_try1, fn_catch1, fn_match1); 246 } 247 } 248 249 // Resume Throw New Exception: 250 void resume_swap() { 251 raii_t a = {"terminate_swap"}; 252 { 253 bool fn_handle1(exception except) { 254 if (2 == except) { 255 resume(1); 256 return true; 257 } else { 258 return false; 259 } 260 } 261 struct __try_resume_node node 262 __attribute__((cleanup(__try_resume_node_delete))); 263 __try_resume_node_new(&node, fn_handle1); 264 { 265 resume(2); 266 } 267 } 268 } 269 270 void resume_swapped() { 271 { 272 bool fn_handle1(exception except) { 273 if (1 == except) { 274 printf("resume_swapped caught exception 1\n"); 275 return true; 276 } else { 277 return false; 278 } 279 } 280 struct __try_resume_node node 281 __attribute__((cleanup(__try_resume_node_delete))); 282 __try_resume_node_new(&node, fn_handle1); 283 { 284 resume_swap(); 285 } 286 } 287 } 288 289 // Terminate Rethrow: 290 // I don't have an implementation for this. 291 292 // Resume Rethrow: 293 void reresume() { 294 { 295 bool reresume_handle1(exception except) { 296 if (1 == except) { 297 printf("reresume 1 caught exception 1\n"); 298 return true; 299 } else { 300 return false; 301 } 302 } 303 struct __try_resume_node node 304 __attribute__((cleanup(__try_resume_node_delete))); 305 __try_resume_node_new(&node, reresume_handle1); 306 { 307 bool reresume_handle2(exception except) { 308 if (1 == except) { 309 printf("reresume 2 caught and rethrows exception 1\n"); 310 return false; 311 } else { 312 return false; 313 } 314 } 315 struct __try_resume_node node 316 __attribute__((cleanup(__try_resume_node_delete))); 317 __try_resume_node_new(&node, reresume_handle2); 318 { 319 resume(1); 320 } 321 } 322 } 323 } 324 325 // Terminate-Resume interaction: 326 void fum() { 327 // terminate block, call resume 328 { 329 void fum_try1() { 330 resume(3); 331 } 332 void fum_catch1(int index, exception except) { 333 switch (index) { 334 case 1: 335 printf("fum caught exception 3\n"); 336 break; 337 default: 338 printf("INVALID INDEX in fum: %d (%d)\n", index, except); 339 } 340 } 341 int fum_match1(exception except) { 342 if (3 == except) { 343 return 1; 344 } else { 345 return 0; 346 } 347 } 348 __try_terminate(fum_try1, fum_catch1, fum_match1); 349 } 350 } 351 352 void foe() { 353 // resume block, call terminate 354 { 355 bool foe_handle1(exception except) { 356 if (3 == except) { 357 printf("foe caught exception 3\n"); 358 return true; 359 } else { 360 return false; 361 } 362 } 363 struct __try_resume_node node 364 __attribute__((cleanup(__try_resume_node_delete))); 365 __try_resume_node_new(&node, foe_handle1); 366 { 367 terminate(3); 368 } 369 } 370 } 371 372 void fy() { 373 // terminate block calls fum, call foe 374 { 375 void fy_try1() { 376 foe(); 377 } 378 void fy_catch1(int index, exception except) { 379 switch (index) { 380 case 1: 381 printf("fy caught exception 3\n"); 382 fum(); 383 break; 384 default: 385 printf("INVALID INDEX in fy: %d (%d)\n", index, except); 386 } 387 } 388 int fy_match1(exception except) { 389 if (3 == except) { 390 return 1; 391 } else { 392 return 0; 393 } 394 } 395 __try_terminate(fy_try1, fy_catch1, fy_match1); 396 } 397 } 398 399 void fee() { 400 // resume block, call fy 401 { 402 bool fee_handle1(exception except) { 403 if (3 == except) { 404 printf("fee caught exception 3\n"); 405 return true; 406 } else { 407 return false; 408 } 409 } 410 struct __try_resume_node node 411 __attribute__((cleanup(__try_resume_node_delete))); 412 __try_resume_node_new(&node, fee_handle1); 413 { 414 fy(); 415 } 416 } 417 } 418 188 419 189 420 // main: choose which tests to run … … 195 426 farewell(); printf("\n"); 196 427 fallback(); printf("\n"); 428 terminate_swapped(); printf("\n"); 429 resume_swapped(); printf("\n"); 430 reresume(); printf("\n"); 431 fee(); printf("\n"); 197 432 // Uncaught termination test. 198 433 terminate(7); -
doc/working/exception/translate.c
re4e9173 r6a48cc9 237 237 } 238 238 void finally1() { 239 // (Finally, because of timing, also work for resume.) 239 // Finally, because of timing, also works for resume. 240 // However this might not actually be better in any way. 240 241 __try_resume_cleanup(); 241 242
Note: See TracChangeset
for help on using the changeset viewer.