-
Notifications
You must be signed in to change notification settings - Fork 0
/
asdl.h
149 lines (127 loc) · 2.69 KB
/
asdl.h
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#ifndef TYPES_H
#define TYPES_H
#include <stdbool.h>
#include <stddef.h>
typedef struct Rule Rule;
typedef struct Type Type;
typedef struct Sum Sum;
typedef struct Product Product;
typedef struct Constructor Constructor;
typedef struct Field Field;
typedef struct GCNode GCNode;
typedef struct Heap Heap;
typedef struct Translator Translator;
typedef struct TypeId TypeId;
typedef struct Symtable Symtable;
typedef struct Stub Stub;
typedef enum FieldKind FieldKind;
typedef enum TypeKind TypeKind;
typedef enum TypeIdKind TypeIdKind;
struct Rule {
char *id;
Type *type;
Rule *next;
};
struct TypeId {
enum TypeIdKind {
TYYNAME_STRING,
TYYNAME_INT8,
TYYNAME_UINT8,
TYYNAME_INT16,
TYYNAME_UINT16,
TYYNAME_INT32,
TYYNAME_UINT32,
TYYNAME_INT64,
TYYNAME_UINT64,
TYYNAME_FLOAT32,
TYYNAME_FLOAT64,
TYYNAME_FLOAT80,
TYYNAME_CHAR,
TYYNAME_UCHAR,
TYYNAME_SIZE,
TYYNAME_USIZE,
TYYNAME_BOOL,
TYYNAME_IDENTIFIER,
TYYNAME_BYTEARRAY,
TYYNAME_ID,
} kind;
char *value;
};
struct Type {
enum TypeKind {
TYPE_SUM,
TYPE_PRODUCT,
} kind;
union {
Product *product;
Sum *sum;
};
};
struct Sum {
Constructor *constructors;
Field *attributes;
};
struct Product {
Field *fields;
};
struct Constructor {
char *id;
Field *fields;
Constructor *next;
bool is_enum;
};
struct Field {
enum FieldKind {
FIELD_SEQUENCE,
FIELD_OPTIONAL,
FIELD_NORMAL,
} kind;
TypeId *type_id;
char *id;
char *cache[4];
Field *next;
};
struct Translator {
FILE *locators;
FILE *prelude;
FILE *tydefs;
FILE *tyspecs;
FILE *decls;
FILE *defs;
FILE *appendage;
Rule *rules;
char *outpath;
char *sympath;
};
struct Symtable {
char *key;
void *value;
Symtable *next;
};
struct Stub {
char *id;
char *constructor_id;
Stub *next;
};
TypeId *create_typeid(TypeIdKind kind, char *value);
Field *add_field(TypeId *type_id, int opt, char *id);
Constructor *add_constructor(char *con_id, Field *fields, bool is_enum);
Rule *add_sum_type(Constructor *constructors, Field *attributes);
Rule *add_product_type(Field *fields);
Symtable *symtable_init(void);
void symtable_insert(const char *key, const void *value);
void *symtable_retrieve(const char *key);
bool symtable_exists(const char *key);
char *gc_strndup(const char *str, size_t n);
void translate_rule_chain(Rule *rules);
void assign_prefixes(char *fn);
void assign_suffixes(char *def, char *fn, char *arg, char *kind);
void init_translator(char *, char *);
void finalize_translator(void);
void dump_translator(void);
void init_absyn(void);
void finalize_absyn(void);
void dump_absyn(void);
void emit_prelude(char *s);
void emit_appendage(char *s);
#endif