Ignore:
Timestamp:
Oct 29, 2019, 4:01:24 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 moved

Legend:

Unmodified
Added
Removed
  • tests/raii/dtor-early-exit.cfa

    r7951100 rb067d9b  
    1010// Created On       : Wed Aug 17 08:26:25 2016
    1111// 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>
    2219
    2320struct A {
     
    2825// don't want these called
    2926void ?{}(A & a) { assert( false ); }
    30 void ?{}(A & a, const char * name) { a.name = name; sout | "construct " | name | endl; a.x = (int*)malloc(); }
     27void ?{}(A & a, const char * name) { a.name = name; sout | "construct " | name; a.x = (int*)malloc(); }
    3128void ?{}(A & a, const char * name, int * ptr) { assert( false ); }
    3229
    3330A ?=?(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); }
     31void ?{}(A & a, A b) { sout | "copy construct " | b.name; a.x = (int*)malloc(); }
     32void ^?{}(A & a) { sout | "destruct " | a.name; free(a.x); }
    3633
    3734// test returns
    3835void f(int i) {
    39         sout | "f i=" | i | endl;
     36        sout | "f i=" | i;
    4037        A x = { "x" };  // construct x
    4138        {
     
    5855void g() {
    5956        for (int i = 0; i < 10; i++) {
    60                 sout | "g for i=" | i | endl;
     57                sout | "g for i=" | i;
    6158                A x = { "x" };
    6259                // construct x
    6360                // destruct x
    6461        }
    65         sout | endl;
     62        sout | nl;
    6663        {
    6764                int i = 0;
    6865                while (i < 10) {
    69                         sout | "g while i=" | i | endl;
     66                        sout | "g while i=" | i;
    7067                        A x = { "x" };
    7168                        // construct x
     
    7471                }
    7572        }
    76         sout | endl;
     73        sout | nl;
    7774        for (int i = 0; i < 10; i++) {
    7875                switch(10) {
     
    8178                        case 10: {
    8279                                A y = { "y" };
    83                                 sout | "g switch i=" | i | endl;
     80                                sout | "g switch i=" | i;
    8481                                // construct y
    8582                                break; // destruct y
    8683                        }
    8784                        default: {
    88                                 sout | "g switch i=" | i | endl;
     85                                sout | "g switch i=" | i;
    8986                                A x = { "x" };
    9087                                // construct x
     
    9390                }
    9491        }
    95         sout | endl;
     92        sout | nl;
    9693        for (int k = 0; k < 2; k++) {
    97                 sout | "g for k=" | k | endl;
     94                sout | "g for k=" | k;
    9895                L1: for (int i = 0; i < 10; i++) {
    99                         sout | "g for i=" | i | endl;
     96                        sout | "g for i=" | i;
    10097
    10198                        A x = { "x" };
    10299                        if (i == 2) {
    103                                 sout | "continue L1" | endl;
     100                                sout | "continue L1";
    104101                                continue;  // destruct x
    105102                        } else if (i == 3) {
    106                                 sout | "break L1" | endl;
     103                                sout | "break L1";
    107104                                break;  // destruct x
    108105                        }
    109106
    110107                        L2: for (int j = 0; j < 10; j++) {
    111                                 sout | "g for j=" | j | endl;
     108                                sout | "g for j=" | j;
    112109                                A y = { "y" };
    113110                                if (j == 0) {
    114                                         sout | "continue L2" | endl;
     111                                        sout | "continue L2";
    115112                                        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
    116113                                } else if (j == 1) {
    117                                         sout | "break L2" | endl;
     114                                        sout | "break L2";
    118115                                        break;  // destruct y
    119116                                } else if (i == 1) {
    120                                         sout | "continue L1" | endl;
     117                                        sout | "continue L1";
    121118                                        continue L1; // destruct x,y - note: continue takes you to destructors for block, so only generate destructor for y
    122119                                } else if (k == 1) {
    123                                         sout | "break L1" | endl;
     120                                        sout | "break L1";
    124121                                        break L1;  // destruct x,y
    125122                                }
     
    128125        }
    129126
    130         sout | endl;
     127        sout | nl;
    131128        L3: if( 3 ) {
    132129                A w = { "w" };
    133130                if( 4 ) {
    134131                        A v = { "v" };
    135                         sout | "break L3" | endl;
     132                        sout | "break L3";
    136133                        break L3;
    137134                }
     
    147144        // * if S_L-S_G is non-empty, error
    148145        // * emit destructors for all variables in S_G-S_L
    149         sout | "h" | endl;
     146        sout | "h";
    150147        {
    151148                L0: ;
     
    155152                        A y = { "y" };
    156153                        // S_L1 = { y }
    157                 L1: sout | "L1" | endl;
     154                L1: sout | "L1";
    158155                        A x = { "x" };
    159156                        // S_L2 = { y, x }
    160                 L2: sout | "L2" | endl;
     157                L2: sout | "L2";
    161158                        if (i == 0) {
    162159                                ++i;
    163                                 sout | "goto L1" | endl;
     160                                sout | "goto L1";
    164161                                // S_G = { y, x }
    165162                                goto L1;  // jump back, destruct b/c before x definition
     
    168165                        } else if (i == 1) {
    169166                                ++i;
    170                                 sout | "goto L2" | endl;
     167                                sout | "goto L2";
    171168                                // S_G = { y, x }
    172169                                goto L2;  // jump back, do not destruct
     
    175172                        } else if (i == 2) {
    176173                                ++i;
    177                                 sout | "goto L3" | endl;
     174                                sout | "goto L3";
    178175                                // S_G = { y, x }
    179176                                goto L3;  // jump ahead, do not destruct
     
    183180                                ++i;
    184181                                A z = { "z" };
    185                                 sout | "goto L3-2" | endl;
     182                                sout | "goto L3-2";
    186183                                // S_G = { z, y, x }
    187184                                goto L3;
     
    190187                        } else {
    191188                                ++i;
    192                                 sout | "goto L4" | endl;
     189                                sout | "goto L4";
    193190                                // S_G = { y, x }
    194191                                goto L4;  // jump ahead, destruct b/c left block x was defined in
     
    197194                        }
    198195                        // S_L3 = { y, x }
    199                 L3: sout | "L3" | endl;
    200                         sout | "goto L2-2" | endl;
     196                L3: sout | "L3";
     197                        sout | "goto L2-2";
    201198                        // S_G = { y, x }
    202199                        goto L2; // jump back, do not destruct
     
    205202        }
    206203        // S_L4 = {}
    207         L4: sout | "L4" | endl;
     204        L4: sout | "L4";
    208205        if (i == 4) {
    209                 sout | "goto L0" | endl;
     206                sout | "goto L0";
    210207                // S_G = {}
    211208                goto L0;
     
    243240                f(i);
    244241        }
    245         sout | endl;
     242        sout | nl;
    246243        g();
    247         sout | endl;
     244        sout | nl;
    248245        h();
    249246
Note: See TracChangeset for help on using the changeset viewer.