user32: Get rid of the unused parameter in the EmptyClipboard driver entry point.
[wine.git] / dlls / jscript / parser.h
blobf8d404f8d6d9e56048803056210fb6fcfb2bdb16
1 /*
2 * Copyright 2014 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 typedef struct _source_elements_t source_elements_t;
20 typedef struct _expression_t expression_t;
21 typedef struct _statement_t statement_t;
23 typedef struct {
24 BOOL is_num;
25 union {
26 BOOL b;
27 double n;
28 } u;
29 } ccval_t;
31 typedef struct _parser_ctx_t {
32 const WCHAR *begin;
33 const WCHAR *end;
34 const WCHAR *ptr;
36 script_ctx_t *script;
37 source_elements_t *source;
38 BOOL nl;
39 BOOL implicit_nl_semicolon;
40 BOOL is_html;
41 BOOL lexer_error;
42 HRESULT hres;
44 ccval_t ccval;
45 unsigned cc_if_depth;
47 heap_pool_t heap;
48 } parser_ctx_t;
50 HRESULT script_parse(script_ctx_t*,const WCHAR*,const WCHAR*,BOOL,parser_ctx_t**) DECLSPEC_HIDDEN;
51 void parser_release(parser_ctx_t*) DECLSPEC_HIDDEN;
53 int parser_lex(void*,parser_ctx_t*) DECLSPEC_HIDDEN;
55 static inline void *parser_alloc(parser_ctx_t *ctx, DWORD size)
57 return heap_pool_alloc(&ctx->heap, size);
60 static inline void *parser_alloc_tmp(parser_ctx_t *ctx, DWORD size)
62 return heap_pool_alloc(&ctx->script->tmp_heap, size);
65 typedef enum {
66 LT_DOUBLE,
67 LT_STRING,
68 LT_BOOL,
69 LT_NULL,
70 LT_REGEXP
71 }literal_type_t;
73 typedef struct {
74 literal_type_t type;
75 union {
76 double dval;
77 const WCHAR *wstr;
78 BOOL bval;
79 struct {
80 const WCHAR *str;
81 DWORD str_len;
82 DWORD flags;
83 } regexp;
84 } u;
85 } literal_t;
87 literal_t *parse_regexp(parser_ctx_t*) DECLSPEC_HIDDEN;
88 literal_t *new_boolean_literal(parser_ctx_t*,BOOL) DECLSPEC_HIDDEN;
90 typedef struct _variable_declaration_t {
91 const WCHAR *identifier;
92 expression_t *expr;
94 struct _variable_declaration_t *next;
95 struct _variable_declaration_t *global_next; /* for compiler */
96 } variable_declaration_t;
98 typedef enum {
99 STAT_BLOCK,
100 STAT_BREAK,
101 STAT_CONTINUE,
102 STAT_EMPTY,
103 STAT_EXPR,
104 STAT_FOR,
105 STAT_FORIN,
106 STAT_IF,
107 STAT_LABEL,
108 STAT_RETURN,
109 STAT_SWITCH,
110 STAT_THROW,
111 STAT_TRY,
112 STAT_VAR,
113 STAT_WHILE,
114 STAT_WITH
115 } statement_type_t;
117 struct _statement_t {
118 statement_type_t type;
119 statement_t *next;
122 typedef struct {
123 statement_t stat;
124 statement_t *stat_list;
125 } block_statement_t;
127 typedef struct {
128 statement_t stat;
129 variable_declaration_t *variable_list;
130 } var_statement_t;
132 typedef struct {
133 statement_t stat;
134 expression_t *expr;
135 } expression_statement_t;
137 typedef struct {
138 statement_t stat;
139 expression_t *expr;
140 statement_t *if_stat;
141 statement_t *else_stat;
142 } if_statement_t;
144 typedef struct {
145 statement_t stat;
146 BOOL do_while;
147 expression_t *expr;
148 statement_t *statement;
149 } while_statement_t;
151 typedef struct {
152 statement_t stat;
153 variable_declaration_t *variable_list;
154 expression_t *begin_expr;
155 expression_t *expr;
156 expression_t *end_expr;
157 statement_t *statement;
158 } for_statement_t;
160 typedef struct {
161 statement_t stat;
162 variable_declaration_t *variable;
163 expression_t *expr;
164 expression_t *in_expr;
165 statement_t *statement;
166 } forin_statement_t;
168 typedef struct {
169 statement_t stat;
170 const WCHAR *identifier;
171 } branch_statement_t;
173 typedef struct {
174 statement_t stat;
175 expression_t *expr;
176 statement_t *statement;
177 } with_statement_t;
179 typedef struct {
180 statement_t stat;
181 const WCHAR *identifier;
182 statement_t *statement;
183 } labelled_statement_t;
185 typedef struct _case_clausule_t {
186 expression_t *expr;
187 statement_t *stat;
189 struct _case_clausule_t *next;
190 } case_clausule_t;
192 typedef struct {
193 statement_t stat;
194 expression_t *expr;
195 case_clausule_t *case_list;
196 } switch_statement_t;
198 typedef struct {
199 const WCHAR *identifier;
200 statement_t *statement;
201 } catch_block_t;
203 typedef struct {
204 statement_t stat;
205 statement_t *try_statement;
206 catch_block_t *catch_block;
207 statement_t *finally_statement;
208 } try_statement_t;
210 typedef enum {
211 EXPR_COMMA,
212 EXPR_OR,
213 EXPR_AND,
214 EXPR_BOR,
215 EXPR_BXOR,
216 EXPR_BAND,
217 EXPR_INSTANCEOF,
218 EXPR_IN,
219 EXPR_ADD,
220 EXPR_SUB,
221 EXPR_MUL,
222 EXPR_DIV,
223 EXPR_MOD,
224 EXPR_DELETE,
225 EXPR_VOID,
226 EXPR_TYPEOF,
227 EXPR_MINUS,
228 EXPR_PLUS,
229 EXPR_POSTINC,
230 EXPR_POSTDEC,
231 EXPR_PREINC,
232 EXPR_PREDEC,
233 EXPR_EQ,
234 EXPR_EQEQ,
235 EXPR_NOTEQ,
236 EXPR_NOTEQEQ,
237 EXPR_LESS,
238 EXPR_LESSEQ,
239 EXPR_GREATER,
240 EXPR_GREATEREQ,
241 EXPR_BITNEG,
242 EXPR_LOGNEG,
243 EXPR_LSHIFT,
244 EXPR_RSHIFT,
245 EXPR_RRSHIFT,
246 EXPR_ASSIGN,
247 EXPR_ASSIGNLSHIFT,
248 EXPR_ASSIGNRSHIFT,
249 EXPR_ASSIGNRRSHIFT,
250 EXPR_ASSIGNADD,
251 EXPR_ASSIGNSUB,
252 EXPR_ASSIGNMUL,
253 EXPR_ASSIGNDIV,
254 EXPR_ASSIGNMOD,
255 EXPR_ASSIGNAND,
256 EXPR_ASSIGNOR,
257 EXPR_ASSIGNXOR,
258 EXPR_COND,
259 EXPR_ARRAY,
260 EXPR_MEMBER,
261 EXPR_NEW,
262 EXPR_CALL,
263 EXPR_THIS,
264 EXPR_FUNC,
265 EXPR_IDENT,
266 EXPR_ARRAYLIT,
267 EXPR_PROPVAL,
268 EXPR_LITERAL
269 } expression_type_t;
271 struct _expression_t {
272 expression_type_t type;
275 typedef struct _parameter_t {
276 const WCHAR *identifier;
277 struct _parameter_t *next;
278 } parameter_t;
280 struct _source_elements_t {
281 statement_t *statement;
282 statement_t *statement_tail;
285 typedef struct _function_expression_t {
286 expression_t expr;
287 const WCHAR *identifier;
288 const WCHAR *event_target;
289 parameter_t *parameter_list;
290 source_elements_t *source_elements;
291 const WCHAR *src_str;
292 DWORD src_len;
294 struct _function_expression_t *next; /* for compiler */
295 } function_expression_t;
297 typedef struct {
298 expression_t expr;
299 expression_t *expression1;
300 expression_t *expression2;
301 } binary_expression_t;
303 typedef struct {
304 expression_t expr;
305 expression_t *expression;
306 } unary_expression_t;
308 typedef struct {
309 expression_t expr;
310 expression_t *expression;
311 expression_t *true_expression;
312 expression_t *false_expression;
313 } conditional_expression_t;
315 typedef struct {
316 expression_t expr;
317 expression_t *expression;
318 const WCHAR *identifier;
319 } member_expression_t;
321 typedef struct _argument_t {
322 expression_t *expr;
324 struct _argument_t *next;
325 } argument_t;
327 typedef struct {
328 expression_t expr;
329 expression_t *expression;
330 argument_t *argument_list;
331 } call_expression_t;
333 typedef struct {
334 expression_t expr;
335 const WCHAR *identifier;
336 } identifier_expression_t;
338 typedef struct {
339 expression_t expr;
340 literal_t *literal;
341 } literal_expression_t;
343 typedef struct _array_element_t {
344 int elision;
345 expression_t *expr;
347 struct _array_element_t *next;
348 } array_element_t;
350 typedef struct {
351 expression_t expr;
352 array_element_t *element_list;
353 int length;
354 } array_literal_expression_t;
356 typedef struct _prop_val_t {
357 literal_t *name;
358 expression_t *value;
360 struct _prop_val_t *next;
361 } prop_val_t;
363 typedef struct {
364 expression_t expr;
365 prop_val_t *property_list;
366 } property_value_expression_t;
368 BOOL try_parse_ccval(parser_ctx_t*,ccval_t*) DECLSPEC_HIDDEN;
369 BOOL parse_cc_expr(parser_ctx_t*) DECLSPEC_HIDDEN;
371 static inline ccval_t ccval_num(double n)
373 ccval_t r;
374 r.is_num = TRUE;
375 r.u.n = n;
376 return r;
379 static inline ccval_t ccval_bool(BOOL b)
381 ccval_t r;
382 r.is_num = FALSE;
383 r.u.b = b;
384 return r;
387 static inline BOOL get_ccbool(ccval_t v)
389 return v.is_num ? v.u.n != 0 : v.u.b;
392 static inline double get_ccnum(ccval_t v)
394 return v.is_num ? v.u.n : v.u.b;