Changeset 8135d4c for src/tests


Ignore:
Timestamp:
Aug 22, 2017, 7:31:52 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
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:
9aaac6e9
Parents:
fc56cdbf (diff), b3d413b (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' into references

Location:
src/tests
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • src/tests/.expect/32/KRfunctions.txt

    rfc56cdbf r8135d4c  
    1515}
    1616struct S {
    17     int __i__i_1;
     17int __i__i_1;
    1818};
    1919static inline void ___constructor__F_P2sS_autogen___1(struct S *___dst__P2sS_1);
     
    7979    __attribute__ ((unused)) int (*___retval_f14__PA0A0i_1)[][((unsigned int )10)];
    8080}
     81int __f15__Fi_iii__1(int __a__i_1, int __b__i_1, int __c__i_1){
     82    __attribute__ ((unused)) int ___retval_f15__i_1;
     83}
    8184const int __fred__FCi___1(){
    8285    __attribute__ ((unused)) const int ___retval_fred__Ci_1;
  • src/tests/.expect/64/KRfunctions.txt

    rfc56cdbf r8135d4c  
    7979    __attribute__ ((unused)) int (*___retval_f14__PA0A0i_1)[][((long unsigned int )10)];
    8080}
     81int __f15__Fi_iii__1(int __a__i_1, int __b__i_1, int __c__i_1){
     82    __attribute__ ((unused)) int ___retval_f15__i_1;
     83}
    8184const int __fred__FCi___1(){
    8285    __attribute__ ((unused)) const int ___retval_fred__Ci_1;
  • src/tests/KRfunctions.c

    rfc56cdbf r8135d4c  
    1010// Created On       : Thu Feb 16 15:23:17 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed May 24 22:05:00 2017
    13 // Update Count     : 3
     12// Last Modified On : Sun Aug 20 07:34:17 2017
     13// Update Count     : 7
    1414//
    1515
     
    3737int ((* f13( a, b, c ))[])[10] int a, * b, c[]; {}
    3838int (((* f14( a, b, c ))[])[10]) int a, * b, c[]; {}
     39f15( a, b, c ) {}
    3940
    4041const fred() {
  • src/tests/except-0.c

    rfc56cdbf r8135d4c  
    11// Draft of tests for exception handling.
     2// Outdated: The integer constant exceptions need to be replaced with virtual
     3// exceptions for the new system.
    24
    35// ERROR: exceptions do not interact with ^?{} properly.
     
    57#include <stdio.h>
    68#include <stdbool.h>
     9
     10#include "except-mac.h"
     11TRIVIAL_EXCEPTION(yin)
     12TRIVIAL_EXCEPTION(yang)
     13TRIVIAL_EXCEPTION(zen)
     14
    715
    816// Local type to mark exits from scopes. (see ERROR)
     
    2129
    2230
    23 // Local Exception Types and manual vtable types.
    24 //#define TRIVIAL_EXCEPTION(name) //TRIVAL_EXCEPTION(yin)
    25 struct yin;
    26 struct yin_vtable {
    27         struct exception_t_vtable const * parent;
    28         size_t size;
    29     void (*copy)(yin *this, yin * other);
    30     void (*free)(yin *this);
    31     const char (*msg)(yin *this);
    32 };
    33 struct yin {
    34         struct yin_vtable const * parent;
    35 };
    36 void yin_msg(yin) {
    37         return "in";
    38 }
    39 yin_vtable _yin_vtable_instance = {
    40         &_exception_t_vtable_instance, sizeof(yin), ?{}, ^?{}, yin_msg
    41 }
    42 
    43 
    44 void terminate(exception * except_value) {
     31// Mark throws: make sure to only pass in exception types.
     32forall(dtype T)
     33void terminate(T * except_value) {
    4534        signal_exit a = {"terminate function"};
    46         throw except_value;
     35        THROW(except_value);
    4736        printf("terminate returned\n");
    4837}
    4938
    50 void resume(exception * except_value) {
     39forall(dtype T)
     40void resume(T * except_value) {
    5141        signal_exit a = {"resume function"};
    52         throwResume except_value;
     42        THROW_RESUME(except_value);
    5343        printf("resume returned\n");
    5444}
     
    5848        signal_exit a = {"bar function"};
    5949        try {
    60                 terminate(4);
    61         } catch (3) {
    62                 printf("bar caught exception 3.\n");
     50                terminate(&(zen){});
     51        } catch (yin * error) {
     52                printf("bar caught exception yin.\n");
    6353        }
    6454}
     
    6858        try {
    6959                bar();
    70         } catch (4) {
    71                 printf("foo caught exception 4.\n");
    72         } catch (2) {
    73                 printf("foo caught exception 2.\n");
     60        } catch (yang * error) {
     61                printf("foo caught exception yang.\n");
     62        } catch (zen * error) {
     63                printf("foo caught exception zen.\n");
    7464        }
    7565}
     
    7969        signal_exit a = {"beta function"};
    8070        try {
    81                 resume(4);
    82         } catchResume (3) {
    83                 printf("beta caught exception 3\n");
     71                zen x;
     72                resume(&x);
     73        } catchResume (yin * error) {
     74                printf("beta caught exception yin\n");
    8475        }
    8576}
     
    8980        try {
    9081                beta();
    91         } catchResume (2) {
    92                 printf("alpha caught exception 2\n");
    93         } catchResume (4) {
    94                 printf("alpha caught exception 4\n");
     82        } catchResume (yang * error) {
     83                printf("alpha caught exception yang\n");
     84        } catchResume (zen * error) {
     85                printf("alpha caught exception zen\n");
    9586        }
    9687}
     
    115106void fallback() {
    116107        try {
    117                 resume(2);
    118         } catch (2) {
    119                 printf("fallback caught termination 2\n");
     108                zen x;
     109                resume(&x);
     110        } catch (zen * error) {
     111                printf("fallback caught termination zen\n");
    120112        }
    121113}
     
    125117        signal_exit a = {"terminate_swap"};
    126118        try {
    127                 terminate(2);
    128         } catch (2) {
    129                 terminate(3);
     119                yin x;
     120                terminate(&x);
     121        } catch (yin * error) {
     122                yang y;
     123                terminate(&y);
    130124        }
    131125}
     
    135129        try {
    136130                terminate_swap();
    137         } catch (3) {
    138                 printf("terminate_swapped caught exception 3\n");
     131        } catch (yang * error) {
     132                printf("terminate_swapped caught exception yang\n");
    139133        }
    140134}
     
    144138        signal_exit a = {"resume_swap"};
    145139        try {
    146                 resume(2);
    147         } catchResume (2) {
    148                 resume(3);
     140                yin x;
     141                resume(&x);
     142        } catchResume (yin * error) {
     143                yang y;
     144                resume(&y);
    149145        }
    150146}
     
    153149        try {
    154150                resume_swap();
    155         } catchResume (3) {
    156                 printf("resume_swapped caught exception 3\n");
     151        } catchResume (yang * error) {
     152                printf("resume_swapped caught exception yang\n");
    157153        }
    158154}
     
    162158        try {
    163159                try {
    164                         terminate(2);
    165                 } catch (2) {
    166                         printf("reterminate 2 caught and "
    167                                "will rethrow exception 2\n");
     160                        zen x;
     161                        terminate(&x);
     162                } catch (zen * error) {
     163                        printf("reterminate zen caught and "
     164                               "will rethrow exception zen\n");
    168165                        throw;
    169166                }
    170         } catch (2) {
    171                 printf("reterminate 1 caught exception 2\n");
     167        } catch (zen * error) {
     168                printf("reterminate 1 caught exception zen\n");
    172169        }
    173170}
     
    177174        try {
    178175                try {
    179                         resume(2);
    180                 } catchResume (2) {
    181                         printf("reresume 2 caught and rethrows exception 2\n");
     176                        zen x;
     177                        resume(&x);
     178                } catchResume (zen * error) {
     179                        printf("reresume zen caught and rethrows exception zen\n");
    182180                        throwResume;
    183181                }
    184         } catchResume (2) {
    185                 printf("reresume 1 caught exception 2\n");
     182        } catchResume (zen * error) {
     183                printf("reresume 1 caught exception zen\n");
    186184        }
    187185}
     
    191189        // terminate block, call resume
    192190        try {
    193                 resume(3);
    194         } catch (3) {
    195                 printf("fum caught exception 3\n");
     191                zen x;
     192                resume(&x);
     193        } catch (zen * error) {
     194                printf("fum caught exception zen\n");
    196195        }
    197196}
     
    200199        // resume block, call terminate
    201200        try {
    202                 terminate(3);
    203         } catchResume (3) {
    204                 printf("foe caught exception 3\n");
     201                zen y;
     202                terminate(&y);
     203        } catchResume (zen * error) {
     204                printf("foe caught exception zen\n");
    205205        }
    206206}
     
    210210        try {
    211211                foe();
    212         } catch (3) {
    213                 printf("fy caught exception 3\n");
     212        } catch (zen * error) {
     213                printf("fy caught exception zen\n");
    214214                fum();
    215215        }
     
    220220        try {
    221221                fy();
    222         } catchResume (3) {
    223                 printf("fee caught exception 3\n");
     222        } catchResume (zen * error) {
     223                printf("fee caught exception zen\n");
    224224        }
    225225}
     
    240240        reresume(); printf("\n");
    241241        fee(); printf("\n");
     242
    242243        // Uncaught termination test.
    243         terminate(7);
    244 }
     244        printf("Throw uncaught.\n");
     245        yang z;
     246        terminate(&z);
     247}
  • src/tests/except-1.c

    rfc56cdbf r8135d4c  
    11// Draft memory management test. (remember -fexceptions)
     2// Outdated: The integer constant exceptions need to be replaced with virtual
     3// exceptions for the new system.
    24
    35#include <stdio.h>
     6
     7#include "except-mac.h"
     8TRIVIAL_EXCEPTION(yin)
     9TRIVIAL_EXCEPTION(yang)
    410
    511int main()
    612{
    713        try {
    8                 throw 3;
     14                yin a;
     15                THROW(&a);
    916        }
    10         catch( 3 ) {
     17        catch( yin * err ) {
    1118                printf("First Caught\n");
    1219                try {
    13                         throw 4;
     20                        yang b;
     21                        THROW(&b);
    1422                }
    15                 catch( 4 ) {
     23                catch( yang * err ) {
    1624                        printf("Both Caught\n");
    1725                }
     
    2129        try {
    2230                try {
    23                         throw 2;
     31                        yang c;
     32                        THROW(&c);
    2433                }
    25                 catch( 2 ) {
     34                catch( yang * err ) {
    2635                        printf("First Catch and rethrow\n");
    2736                        throw;
    2837                }
    2938        }
    30         catch( 2 ) {
     39        catch( yang * err ) {
    3140                printf("Second Catch\n");
    3241        }
     
    3544        try {
    3645                try {
    37                         throw 5;
     46                        yin d;
     47                        THROW(&d);
    3848                }
    39                 catch( 5 ) {
     49                catch( yin * err ) {
    4050                        printf("Throw before cleanup\n");
    41                         throw 6;
     51                        yang e;
     52                        THROW(&e);
    4253                }
    4354        }
    44         catch( 6 ) {
     55        catch( yang * err ) {
    4556                printf("Catch after cleanup\n");
    4657        }
     
    4960        try {
    5061                try {
    51                         throw 7;
     62                        yin f;
     63                        THROW(&f);
    5264                }
    53                 catch( 7 ) {
     65                catch( yin * err ) {
    5466                        printf("Caught initial throw.\n");
    5567                        try {
    56                                 throw 8;
     68                                yang g;
     69                                THROW(&g);
    5770                        }
    58                         catch( 8 ) {
     71                        catch( yang * err ) {
    5972                                printf("Caught intermediate throw.\n");
    6073                        }
     
    6275                }
    6376        }
    64         catch( 7 ) {
     77        catch( yin * err ) {
    6578                printf("Caught final throw.\n");
    6679        }
  • src/tests/except-2.c

    rfc56cdbf r8135d4c  
    22
    33
    4 #include <string.h>
     4#include <stdlib>
     5#include "except-mac.h"
    56
    6 // Local Exception Types and manual vtable types.
    7 #define BASE_EXCEPT __cfaehm__base_exception_t
    8 #define TABLE(name) name##_vtable
    9 #define INSTANCE(name) _##name##_vtable_instance
    10 #define TRIVIAL_EXCEPTION(name) \
    11 struct name; \
    12 struct TABLE(name) { \
    13         struct __cfaehm__base_exception_t_vtable const * parent; \
    14         size_t size; \
    15         void (*copy)(name *this, name * other); \
    16         void (*free)(name *this); \
    17         const char * (*msg)(name *this); \
    18 }; \
    19 extern TABLE(name) INSTANCE(name); \
    20 struct name { \
    21         struct TABLE(name) const * virtual_table; \
    22 }; \
    23 const char * name##_msg(name * this) { \
    24         return #name; \
    25 } \
    26 void name##_copy(name * this, name * other) { \
    27         this->virtual_table = other->virtual_table; \
    28 } \
    29 TABLE(name) INSTANCE(name) @= { \
    30         .parent : &INSTANCE(__cfaehm__base_exception_t), \
    31         .size : sizeof(name), .copy : name##_copy, \
    32         .free : ^?{}, .msg : name##_msg \
    33 }; \
    34 void ?{}(name * this) { \
    35         this->virtual_table = &INSTANCE(name); \
    36 }
    377TRIVIAL_EXCEPTION(yin)
    388TRIVIAL_EXCEPTION(yang)
     
    4010struct num_error;
    4111struct num_error_vtable {
    42         struct exception_t_vtable const * parent;
     12        struct TABLE(BASE_EXCEPT) const * parent;
    4313        size_t size;
    4414        void (*copy)(num_error *this, num_error * other);
     
    4818};
    4919extern num_error_vtable INSTANCE(num_error);
     20
    5021struct num_error {
    5122        struct num_error_vtable const * virtual_table;
     
    5324        int num;
    5425};
     26
    5527void num_error_msg(num_error * this) {
    5628        if ( ! this->msg ) {
    57                 const char * base = "Num Error with code: X";
    58                 this->msg = strdup( base );
     29                static const char * base = "Num Error with code: X";
     30                this->msg = malloc(22);
     31                for (int i = 0 ; (this->msg[i] = base[i]) ; ++i);
    5932        }
    6033        this->msg[21] = '0' + this->num;
     
    6235}
    6336void ?{}(num_error * this, int num) {
    64         this->virtual_table = &_num_error_vtable_instance;
     37        this->virtual_table = &INSTANCE(num_error);
    6538        this->msg = 0;
    6639        this->num = num;
     
    7851}
    7952num_error_vtable _num_error_vtable_instance @= {
    80         &___cfaehm__base_exception_t_vtable_instance,
     53        &INSTANCE(BASE_EXCEPT),
    8154        sizeof(num_error), ?{}, ^?{},
    8255        num_error_msg, num_error_code
     
    8861        try {
    8962                yin black;
    90                 throw (BASE_EXCEPT *)&black;
    91         } catch( yin * error ) {
     63                THROW(&black);
     64        } catch ( yin * error ) {
    9265                printf("throw yin caught.\n");
    9366        }
     
    9568        try {
    9669                yang white;
    97                 throwResume (BASE_EXCEPT *)&white;
     70                THROW_RESUME(&white);
    9871                printf("> throwResume returned.\n");
    99         } catchResume( yang * error ) {
     72        } catchResume ( yang * error ) {
    10073                printf("throwResume yang caught <");
    10174        }
    10275
    103         /* Conditional catches are still a work in progress.
    10476        try {
    10577                num_error x = { 2 };
    106                 throw (struct exception_t *)&x;
     78                THROW(&x);
    10779        }
    108         catch (num_error * error0 ; 3 == error0->virtual_table->code( error0 ) ) {
    109                 printf("exception at %p\n", error0 );
     80        catch (num_error * error ; 3 == error->virtual_table->code( error ) ) {
     81                printf("exception at %p\n", error );
    11082                printf("Should not be printed.\n");
    11183        }
    112         catch (num_error * error1 ; 2 == error1->virtual_table->code( error1 ) ) {
     84        catch (num_error * error ; 2 == error->virtual_table->code( error ) ) {
    11385                printf("Should be printed.\n");
    114         }*/
     86        }
    11587}
    11688
Note: See TracChangeset for help on using the changeset viewer.