-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode.h
250 lines (204 loc) · 4.9 KB
/
node.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#pragma once
#include "pos.h"
#include <stdbool.h>
#include <stddef.h>
struct unary {
// "*" for pointer access.. **** even for multiple pointer access only the
// first operator is here
const char *op;
struct node *operand;
union {
struct indirection {
// The pointer depth
int depth;
} indirection;
};
};
struct datatype {
int flags;
// i.e type of long, int, float ect..
int type;
// i.e long int. int being the secondary.
struct datatype *secondary;
// long
const char *type_str;
// The sizeof the datatype.
size_t size;
int pointer_depth;
union {
struct node *struct_node;
struct node *union_node;
};
struct array {
struct array_brackets *brackets;
/**
*
* The total array size: Equation = DATATYPE_SIZE * EACH_INDEX
*/
size_t size;
} array;
};
struct node
{
int type;
int flags;
struct pos pos;
struct node_binded {
// Pointer to our body node
struct node *owner;
// Pointer to the function this node is in.
struct node *function;
} binded;
union {
struct exp {
struct node *left;
struct node *right;
const char *op;
} exp;
struct parenthesis {
// The expression inside the parenthesis node.
struct node *exp;
} parenthesis;
struct var {
struct datatype type;
int padding;
// Aligned offset
int aoffset;
const char *name;
struct node *val;
} var;
struct node_tenary {
struct node *true_node;
struct node *false_node;
} tenary;
struct varlist {
// A list of struct node* variables.
struct vector *list;
} var_list;
struct bracket {
// int x[50]; [50] would be our bracket node. The inner would
// NODE_TYPE_NUMBER value of 50
struct node *inner;
} bracket;
struct _struct {
const char *name;
struct node *body_n;
/**
* struct abc
* {
*
* } var_name;
*
* NULL if no variable attached to structure.
*
*/
struct node *var;
} _struct;
struct _union {
const char *name;
struct node *body_n;
/**
* struct abc
* {
*
* } var_name;
*
* NULL if no variable attached to structure.
*
*/
struct node *var;
} _union;
struct body {
/**
* struct node* vector of statements
*/
struct vector *statements;
// The size of combined variables inside this body.
size_t size;
// True if the variable size had to be increased due to padding in the
// body.
bool padded;
// A pointer to the largest variable node in the statements vector.
struct node *largest_var_node;
} body;
struct function {
// Special flags
int flags;
// Return type i.e void, int, long ect...
struct datatype rtype;
// I.e function name "main"
const char *name;
struct function_arguments {
// Vector of struct node* . Must be type NODE_TYPE_VARIABLE
struct vector *vector;
// How much to add to the EBP to find the first argument.
size_t stack_addition;
} args;
// Pointer to the function body node, NULL if this is a function prototype
struct node *body_n;
struct stack_frame {
// A vector of stack_frame_element
struct vector *elements;
} frame;
// The stack size for all variables inside this function.
size_t stack_size;
} func;
struct statement {
struct return_stmt {
// The expression of the return
struct node *exp;
} return_stmt;
struct if_stmt {
// if(COND) {// body }
struct node *cond_node;
struct node *body_node;
// if(COND) {} else {}
struct node *next;
} if_stmt;
struct else_stmt {
struct node *body_node;
} else_stmt;
struct for_stmt {
struct node *init_node;
struct node *cond_node;
struct node *loop_node;
struct node *body_node;
} for_stmt;
struct while_stmt {
struct node *exp_node;
struct node *body_node;
} while_stmt;
struct do_while_stmt {
struct node *exp_node;
struct node *body_node;
} do_while_stmt;
struct switch_stmt {
struct node *exp;
struct node *body;
struct vector *cases;
bool has_default_case;
} switch_stmt;
struct _case_stmt {
struct node *exp;
} _case;
struct _goto_stmt {
struct node *label;
} _goto;
} stmt;
struct node_label {
struct node *name;
} label;
struct cast {
struct datatype dtype;
struct node *operand;
} cast;
struct unary unary;
};
union {
char cval;
const char *sval;
unsigned int inum;
unsigned long lnum;
unsigned long long llnum;
};
};