summaryrefslogtreecommitdiff
path: root/type.h
blob: a67fabb6a0e24774c0ca93e765493d00f3ad738e (plain)
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
#ifndef TYPE_H
#define TYPE_H

#include "ccc.h"

struct data_type {
    const char* name;
    integral_t sz;
    bool is_floating;
};

struct fn_type {
    struct type_list* arg_types;
    struct type* return_type;
};

struct type {
    enum {
        TP_DATA,
        TP_PTR,
        TP_FN,
    } type;
    union {
        struct {
            const struct data_type* data_type;
            bool is_signed;
        } data;
        struct {
            const struct data_type* data_type;
            integral_t ptr_level;
        } pointer;
        struct fn_type fn;
    };
};

struct type_list {
    const struct type* type;
    struct type_list* next;
};

extern const struct data_type void_type;
extern const struct data_type char_type;
extern const struct data_type short_type;
extern const struct data_type int_type;
extern const struct data_type long_type;
extern const struct data_type long_long_type;
extern const struct data_type float_type;
extern const struct data_type double_type;
extern const struct data_type* primitive_types[];

extern const struct type integral_type;
extern const struct type floating_type;
extern const struct type character_type;
extern const struct type string_type;

#endif