-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs_parse.h
261 lines (232 loc) · 4.57 KB
/
js_parse.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
251
252
253
254
255
256
257
258
259
260
//
// Parse context
//
typedef enum {
node_first = 0,
node_endlist,
node_incr, // ++, --
node_enum, // enum decl
node_math, // math expr
node_neg, // - expr
node_num, // number
node_string, // string
node_fcncall, // func( exprlist )
node_builtin, // builtinfunc( exprlist )
node_var, // symbol
node_assign, // lval = rval
node_opassign, // lval (+|-)= rval
node_return, // return stmt
node_ifthen, // if (c) {..} else {..}
node_while, // while (c) do {..}
node_dowhile, // do {..} while (c)
node_for, // for (e; c; e) {..}
node_forin, // for (var x in|of y) {..}
node_list, // {expr,decl,arg}list
node_elemlist, // elem, elem, ...
node_array, // [ a, b, ... ]
node_obj, // { elem, elem, ... }
node_fcnexpr, // fcn ( paramlist )
node_fcndef, // function f(.) { .. }
node_elem, // name : value
node_access, // x.prop
node_typeof, // typeof x
node_ternary, // expr ? expr : expr
node_land, // expr && expr
node_lor, // expr || expr
node_xcp, // exception try catch finally
node_throw, // throw exception
node_block, // enter block
node_newobj, // NEW expr
node_pipe, // expr |> funcall
node_MAX
} nodeType;
typedef union {
struct {
uint32_t type:6; // type of parse node
uint32_t flag:5; // node flags
uint32_t aux:6; // node flavor/parameter
uint32_t lineNo:15; // script line number
};
nodeType display:6;
uint32_t bits;
} Node;
typedef struct {
uint32_t beginning; // beginning of parse tree
uint32_t tableSize; // size of the parsetable
uint32_t tableNext; // size of the parsetable
uint32_t lineNo; // script line number
void *scanInfo; // yyscanner context
char *script; // name of the script
Node *table;
} parseData;
typedef enum {
for_in,
for_of
} forin;
typedef enum {
incr_before,
incr_after,
decr_before,
decr_after,
} incrdecr;
typedef enum {
pm_assign,
pm_add,
pm_sub,
pm_mpy,
pm_div,
pm_mod,
pm_math,
pm_and,
pm_xor,
pm_or,
pm_lshift,
pm_rshift
} plusminus;
typedef enum {
neg_uminus,
neg_bitnot,
neg_not
} negate;
typedef enum {
math_add, // expr + epxr
math_sub, // expr - expr
math_mpy, // expr * expr
math_div, // expr / expr
math_mod, // expr % expr
math_comp, // last comp type
math_or, // expr | expr
math_and, // expr & expr
math_xor, // expr ^ expr
math_lshift, // expr << expr
math_rshift, // expr >> expr
math_rushift, // expr >>> expr
math_bits, // last bits type
math_lt, // expr < expr
math_le, // expr <= expr
math_eq, // expr == expr
math_ne, // expr != expr
math_ge, // expr >= expr
math_gt, // expr > expr
math_id, // expr === expr
math_nid, // expr !== expr
} mathops;
typedef enum {
nn_dbl,
nn_int,
nn_bool,
nn_null,
nn_this,
nn_args,
nn_undef,
nn_infinity,
nn_nan,
} numNodeType;
typedef struct {
Node hdr[1];
uint32_t begin;
uint32_t fcnChain;
uint32_t moduleSize;
uint8_t script[];
} firstNode;
uint32_t newNode (parseData *pd, nodeType type, uint32_t size, bool zero);
uint32_t newStrNode (parseData *pd, char *text, uint32_t size);
firstNode *findFirstNode(Node *table, uint32_t slot);
typedef struct {
Node hdr[1];
uint32_t tryblk;
uint32_t binding;
uint32_t catchblk;
uint32_t finallyblk;
} xcpNode;
typedef struct {
Node hdr[1];
uint32_t condexpr;
uint32_t trueexpr;
uint32_t falseexpr;
} ternaryNode;
typedef struct {
Node hdr[1];
uint32_t condexpr;
uint32_t thenstmt;
uint32_t elsestmt;
} ifThenNode;
typedef struct {
Node hdr[1];
uint32_t argCnt;
uint32_t name;
uint32_t args;
} fcnCallNode;
typedef struct {
Node hdr[1];
string_t str;
} stringNode;
typedef struct {
Node hdr[1];
uint32_t right;
uint32_t left;
} binaryNode;
typedef struct {
Node hdr[1];
union {
int64_t intval;
double dblval;
bool boolval;
};
} numNode;
typedef struct {
Node hdr[1];
uint16_t frameIdx;
uint16_t level;
uint32_t name;
} symNode;
typedef struct {
Node hdr[1];
uint32_t exprlist;
} arrayNode;
typedef struct {
Node hdr[1];
uint32_t elemlist;
} objNode;
typedef struct {
Node hdr[1];
uint32_t init;
uint32_t cond;
uint32_t incr;
uint32_t stmt;
symtab_t symbols;
} forNode;
typedef struct {
Node hdr[1];
uint32_t var;
uint32_t expr;
uint32_t stmt;
symtab_t symbols;
} forInNode;
typedef struct {
Node hdr[1];
uint32_t cond;
uint32_t stmt;
} whileNode;
typedef struct {
Node hdr[1];
uint32_t expr;
} exprNode;
typedef struct {
Node hdr[1];
uint32_t elem;
} listNode;
typedef struct {
Node hdr[1];
uint32_t body;
symtab_t symbols;
} blkEntryNode;
struct FcnDeclNode {
Node hdr[1];
uint32_t name;
uint32_t body;
uint32_t next;
uint32_t params;
uint32_t nparams;
symtab_t symbols;
};