source: tests/exceptions/data-except.cfa @ e68d092

arm-ehenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-expr
Last change on this file since e68d092 was e68d092, checked in by Andrew Beach <ajbeach@…>, 2 years ago

Replaced my exception patch macros with a (hopefully temporary) addition to the standard libary, the same macros just cleaned up. See the exception tests for some example uses.

  • Property mode set to 100644
File size: 1002 bytes
Line 
1// Test exceptions that add data but no functionality.
2
3#include <exception.hfa>
4
5DATA_EXCEPTION(paired)(
6        int first;
7        int second;
8);
9
10void ?{}(paired & this, int first, int second) {
11        VTABLE_INIT(this, paired);
12        this.first = first;
13        this.second = second;
14}
15
16void copy(paired * this, paired * other) {
17        *this = *other;
18}
19
20const char * paired_msg(paired * this) {
21        return "paired";
22}
23
24VTABLE_INSTANCE(paired)(paired_msg);
25
26void throwPaired(int first, int second) {
27        paired exc = {first, second};
28}
29
30int main(int argc, char * argv[]) {
31        paired except = {3, 13};
32
33        try {
34                throw &except;
35        } catch (paired * exc) {
36                printf("%s(%d, %d)\n", paired_msg(exc), exc->first, exc->second);
37                ++exc->first;
38        }
39
40        printf("%s(%d, %d)\n", paired_msg(&except), except.first, except.second);
41
42        try {
43                throwResume &except;
44        } catchResume (paired * exc) {
45                printf("%s(%d, %d)\n", paired_msg(exc), exc->first, exc->second);
46                ++exc->first;
47        }
48
49        printf("%s(%d, %d)\n", paired_msg(&except), except.first, except.second);
50}
Note: See TracBrowser for help on using the repository browser.