summaryrefslogtreecommitdiff
path: root/include/parser/type.h
blob: b4c16cb115ba0cb16b22a30eb859542b4d0a3e8a (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
57
58
59
/*
 * Type parser.
 * Copyright (c) 2023-2024, Quinn Stephens and the OSMORA team.
 * Provided under the BSD 3-Clause license.
 */

#ifndef _PARSER_TYPE_H
#define _PARSER_TYPE_H

#include <stdbool.h>
#include <stddef.h>
#include "hashmap.h"
#include "parser.h"

enum type_kind {
    TYK_ALIAS,
    TYK_ENUM,
    TYK_STRUCT
};

struct enum_member {
    struct hashmap_entry hashmap_entry;

    char *name;
    size_t name_len;

    uint64_t value;
};

struct struct_member {
    struct hashmap_entry hashmap_entry;

    char *name;
    size_t name_len;

    size_t off, size;
    struct type *typ;
    int n_ptrs;
};

struct type {
    struct hashmap_entry hashmap_entry;

    enum type_kind kind;
    char *name;
    size_t name_len;

    size_t size;

    union {
        int n_ptrs;
        struct hashmap members;
    };
};

void parse_type(struct parser *ctx);
bool parse_type_ref(struct parser *ctx, struct type **typ_out, int *n_ptrs_out);

#endif /* !_PARSER_TYPE_H */