aboutsummaryrefslogtreecommitdiff
path: root/obsolete/table_test.c
blob: 46b9b8a7c4ac2f0553136af11368023cb3f0740f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <stdlib.h>
#include <stdio.h>
#include "semantics.h"
#define PV(str) \
    do \
    { \
        if (cscope_push_var(scope, newvar(str))) \
            fprintf(stderr, "Successfully pushed var: %s\n", str); \
        else \
            fprintf(stderr, "Naming conflicts deteced: %s\n", str); \
    } while(0)

#define PT(str) \
    do \
    { \
        if (cscope_push_type(scope, newtype(str))) \
            fprintf(stderr, "Successfully pushed type: %s\n", str); \
        else \
            fprintf(stderr, "Naming conflicts deteced: %s\n", str); \
    } while(0)

CVar_t newvar(const char *name) {
    return cvar_create(name, NULL, NULL);
}

CType_t newtype(const char *name) {
    return ctype_create(name, 0, NULL);
}

void manual() {
    CScope_t scope = cscope_create();
    PV("a");
    PV("b");
    PV("asdf");
    PV("fdsa");
    PV("hello");
    cscope_debug_print(scope);
    cscope_enter(scope);
    PV("a");
    PV("hello");
    PT("CType");
    cscope_debug_print(scope);
    cscope_enter(scope);
    PV("a");
    PV("yay");
    PV("world");
    PT("CType");
    PV("a");
    cscope_debug_print(scope);
    cscope_exit(scope);
    cscope_debug_print(scope);
    cscope_exit(scope);
    cscope_debug_print(scope);
}

char *str_gen(int len) {
    int i;
    char *str = malloc(len);
    for (i = 0; i < len; i++)
        str[i] = rand() % 2 + 'a';
    return str;
}

void autoforce() {
    static const int max_lvl = 100,
                    max_push = 10;
    int i, j;
    CScope_t scope = cscope_create();
    for (i = 0; i < max_lvl; i++)
    {
        cscope_enter(scope);
        int push = rand() % max_push;
        for (j = 0; j < push; j++)
        {
            int len = rand() % 3 + 1;
            int opt = rand() & 1;
            if (opt) PV(str_gen(len));
            else PT(str_gen(len));
        }
    }
    for (i = 0; i < max_lvl; i++)
    {
        cscope_debug_print(scope);
        cscope_exit(scope);
    }
}

int main() {
/*    manual(); */
    autoforce();
    return 0;
}