- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs_parse.h
More file actions
Latest commit
261 lines (232 loc) · 4.57 KB
/
Copy pathjs_parse.h
File metadata and controls
261 lines (232 loc) · 4.57 KB
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
//
typedefenum {
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;
typedefunion {
struct {
uint32_ttype:6; // type of parse node
uint32_tflag:5; // node flags
uint32_taux:6; // node flavor/parameter
uint32_tlineNo:15; // script line number
};
nodeTypedisplay:6;
uint32_tbits;
} Node;
typedefstruct {
uint32_tbeginning; // beginning of parse tree
uint32_ttableSize; // size of the parsetable
uint32_ttableNext; // size of the parsetable
uint32_tlineNo; // script line number
void*scanInfo; // yyscanner context
char*script; // name of the script
Node*table;
} parseData;
typedefenum {
for_in,
for_of
} forin;
typedefenum {
incr_before,
incr_after,
decr_before,
decr_after,
} incrdecr;
typedefenum {
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;
typedefenum {
neg_uminus,
neg_bitnot,
neg_not
} negate;
typedefenum {
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;
typedefenum {
nn_dbl,
nn_int,
nn_bool,
nn_null,
nn_this,
nn_args,
nn_undef,
nn_infinity,
nn_nan,
} numNodeType;
typedefstruct {
Nodehdr[1];
uint32_tbegin;
uint32_tfcnChain;
uint32_tmoduleSize;
uint8_tscript[];
} firstNode;
uint32_tnewNode (parseData*pd, nodeTypetype, uint32_tsize, boolzero);
uint32_tnewStrNode (parseData*pd, char*text, uint32_tsize);
firstNode*findFirstNode(Node*table, uint32_tslot);
typedefstruct {
Nodehdr[1];
uint32_ttryblk;
uint32_tbinding;
uint32_tcatchblk;
uint32_tfinallyblk;
} xcpNode;
typedefstruct {
Nodehdr[1];
uint32_tcondexpr;
uint32_ttrueexpr;
uint32_tfalseexpr;
} ternaryNode;
typedefstruct {
Nodehdr[1];
uint32_tcondexpr;
uint32_tthenstmt;
uint32_telsestmt;
} ifThenNode;
typedefstruct {
Nodehdr[1];
uint32_targCnt;
uint32_tname;
uint32_targs;
} fcnCallNode;
typedefstruct {
Nodehdr[1];
string_tstr;
} stringNode;
typedefstruct {
Nodehdr[1];
uint32_tright;
uint32_tleft;
} binaryNode;
typedefstruct {
Nodehdr[1];
union {
int64_tintval;
doubledblval;
boolboolval;
};
} numNode;
typedefstruct {
Nodehdr[1];
uint16_tframeIdx;
uint16_tlevel;
uint32_tname;
} symNode;
typedefstruct {
Nodehdr[1];
uint32_texprlist;
} arrayNode;
typedefstruct {
Nodehdr[1];
uint32_telemlist;
} objNode;
typedefstruct {
Nodehdr[1];
uint32_tinit;
uint32_tcond;
uint32_tincr;
uint32_tstmt;
symtab_tsymbols;
} forNode;
typedefstruct {
Nodehdr[1];
uint32_tvar;
uint32_texpr;
uint32_tstmt;
symtab_tsymbols;
} forInNode;
typedefstruct {
Nodehdr[1];
uint32_tcond;
uint32_tstmt;
} whileNode;
typedefstruct {
Nodehdr[1];
uint32_texpr;
} exprNode;
typedefstruct {
Nodehdr[1];
uint32_telem;
} listNode;
typedefstruct {
Nodehdr[1];
uint32_tbody;
symtab_tsymbols;
} blkEntryNode;
structFcnDeclNode {
Nodehdr[1];
uint32_tname;
uint32_tbody;
uint32_tnext;
uint32_tparams;
uint32_tnparams;
symtab_tsymbols;
};