windowscodecs: Silence fixme for IID_CMetaBitmapRenderTarget.
[wine.git] / dlls / jscript / parser.h
blob3b616b43b07b041944c150468d92e9eb4609e0a4
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 _expression_t expression_t;
20 typedef struct _statement_t statement_t;
22 struct _bytecode_t;
24 typedef struct {
25 BOOL is_num;
26 union {
27 BOOL b;
28 double n;
29 } u;
30 } ccval_t;
32 typedef struct _parser_ctx_t {
33 const WCHAR *begin;
34 const WCHAR *end;
35 const WCHAR *ptr;
37 script_ctx_t *script;
38 struct _compiler_ctx_t *compiler;
39 statement_t *source;
40 BOOL nl;
41 BOOL implicit_nl_semicolon;
42 BOOL is_html;
43 BOOL lexer_error;
44 HRESULT hres;
45 unsigned error_loc;
47 ccval_t ccval;
48 unsigned cc_if_depth;
50 heap_pool_t heap;
51 } parser_ctx_t;
53 HRESULT script_parse(script_ctx_t*,struct _compiler_ctx_t*,struct _bytecode_t*,const WCHAR*,BOOL,parser_ctx_t**);
54 void parser_release(parser_ctx_t*);
56 int parser_lex(void*,unsigned*,parser_ctx_t*);
58 static inline void *parser_alloc(parser_ctx_t *ctx, DWORD size)
60 return heap_pool_alloc(&ctx->heap, size);
63 static inline void *parser_alloc_tmp(parser_ctx_t *ctx, DWORD size)
65 return heap_pool_alloc(&ctx->script->tmp_heap, size);
68 BOOL is_identifier_char(WCHAR);
69 BOOL unescape(WCHAR*,size_t*);
70 HRESULT parse_decimal(const WCHAR**,const WCHAR*,double*);
72 typedef enum {
73 LT_DOUBLE,
74 LT_STRING,
75 LT_BOOL,
76 LT_NULL,
77 LT_REGEXP
78 }literal_type_t;
80 typedef struct {
81 literal_type_t type;
82 union {
83 double dval;
84 jsstr_t *str;
85 BOOL bval;
86 struct {
87 jsstr_t *str;
88 DWORD flags;
89 } regexp;
90 } u;
91 } literal_t;
93 literal_t *parse_regexp(parser_ctx_t*);
94 literal_t *new_boolean_literal(parser_ctx_t*,BOOL);
96 typedef struct _variable_declaration_t {
97 const WCHAR *identifier;
98 BOOL block_scope, constant;
99 expression_t *expr;
101 struct _variable_declaration_t *next;
102 struct _variable_declaration_t *global_next; /* for compiler */
103 } variable_declaration_t;
105 typedef enum {
106 STAT_BLOCK,
107 STAT_BREAK,
108 STAT_CONTINUE,
109 STAT_EMPTY,
110 STAT_EXPR,
111 STAT_FOR,
112 STAT_FORIN,
113 STAT_IF,
114 STAT_LABEL,
115 STAT_RETURN,
116 STAT_SWITCH,
117 STAT_THROW,
118 STAT_TRY,
119 STAT_VAR,
120 STAT_WHILE,
121 STAT_WITH
122 } statement_type_t;
124 struct _statement_t {
125 statement_type_t type;
126 statement_t *next;
127 unsigned loc;
130 typedef struct {
131 statement_t stat;
132 unsigned int scope_index;
133 statement_t *stat_list;
134 } block_statement_t;
136 typedef struct {
137 statement_t stat;
138 variable_declaration_t *variable_list;
139 } var_statement_t;
141 typedef struct {
142 statement_t stat;
143 expression_t *expr;
144 } expression_statement_t;
146 typedef struct {
147 statement_t stat;
148 expression_t *expr;
149 statement_t *if_stat;
150 statement_t *else_stat;
151 } if_statement_t;
153 typedef struct {
154 statement_t stat;
155 BOOL do_while;
156 expression_t *expr;
157 statement_t *statement;
158 } while_statement_t;
160 typedef struct {
161 statement_t stat;
162 variable_declaration_t *variable_list;
163 expression_t *begin_expr;
164 expression_t *expr;
165 unsigned expr_loc;
166 expression_t *end_expr;
167 unsigned end_loc;
168 statement_t *statement;
169 unsigned int scope_index;
170 } for_statement_t;
172 typedef struct {
173 statement_t stat;
174 variable_declaration_t *variable;
175 expression_t *expr;
176 expression_t *in_expr;
177 statement_t *statement;
178 } forin_statement_t;
180 typedef struct {
181 statement_t stat;
182 const WCHAR *identifier;
183 } branch_statement_t;
185 typedef struct {
186 statement_t stat;
187 expression_t *expr;
188 statement_t *statement;
189 } with_statement_t;
191 typedef struct {
192 statement_t stat;
193 const WCHAR *identifier;
194 statement_t *statement;
195 } labelled_statement_t;
197 typedef struct _case_clausule_t {
198 expression_t *expr;
199 unsigned loc;
200 statement_t *stat;
202 struct _case_clausule_t *next;
203 } case_clausule_t;
205 typedef struct {
206 statement_t stat;
207 expression_t *expr;
208 case_clausule_t *case_list;
209 } switch_statement_t;
211 typedef struct {
212 const WCHAR *identifier;
213 statement_t *statement;
214 } catch_block_t;
216 typedef struct {
217 statement_t stat;
218 statement_t *try_statement;
219 catch_block_t *catch_block;
220 statement_t *finally_statement;
221 unsigned finally_loc;
222 } try_statement_t;
224 typedef enum {
225 EXPR_COMMA,
226 EXPR_OR,
227 EXPR_AND,
228 EXPR_BOR,
229 EXPR_BXOR,
230 EXPR_BAND,
231 EXPR_INSTANCEOF,
232 EXPR_IN,
233 EXPR_ADD,
234 EXPR_SUB,
235 EXPR_MUL,
236 EXPR_DIV,
237 EXPR_MOD,
238 EXPR_DELETE,
239 EXPR_VOID,
240 EXPR_TYPEOF,
241 EXPR_MINUS,
242 EXPR_PLUS,
243 EXPR_POSTINC,
244 EXPR_POSTDEC,
245 EXPR_PREINC,
246 EXPR_PREDEC,
247 EXPR_EQ,
248 EXPR_EQEQ,
249 EXPR_NOTEQ,
250 EXPR_NOTEQEQ,
251 EXPR_LESS,
252 EXPR_LESSEQ,
253 EXPR_GREATER,
254 EXPR_GREATEREQ,
255 EXPR_BITNEG,
256 EXPR_LOGNEG,
257 EXPR_LSHIFT,
258 EXPR_RSHIFT,
259 EXPR_RRSHIFT,
260 EXPR_ASSIGN,
261 EXPR_ASSIGNLSHIFT,
262 EXPR_ASSIGNRSHIFT,
263 EXPR_ASSIGNRRSHIFT,
264 EXPR_ASSIGNADD,
265 EXPR_ASSIGNSUB,
266 EXPR_ASSIGNMUL,
267 EXPR_ASSIGNDIV,
268 EXPR_ASSIGNMOD,
269 EXPR_ASSIGNAND,
270 EXPR_ASSIGNOR,
271 EXPR_ASSIGNXOR,
272 EXPR_COND,
273 EXPR_ARRAY,
274 EXPR_MEMBER,
275 EXPR_NEW,
276 EXPR_CALL,
277 EXPR_THIS,
278 EXPR_FUNC,
279 EXPR_IDENT,
280 EXPR_ARRAYLIT,
281 EXPR_PROPVAL,
282 EXPR_LITERAL
283 } expression_type_t;
285 struct _expression_t {
286 expression_type_t type;
289 typedef struct _parameter_t {
290 const WCHAR *identifier;
291 struct _parameter_t *next;
292 } parameter_t;
294 typedef struct _function_expression_t {
295 expression_t expr;
296 const WCHAR *identifier;
297 const WCHAR *event_target;
298 parameter_t *parameter_list;
299 statement_t *statement_list;
300 const WCHAR *src_str;
301 DWORD src_len;
302 unsigned func_id;
303 BOOL is_statement;
304 unsigned int scope_index;
306 struct _function_expression_t *next; /* for compiler */
307 } function_expression_t;
309 typedef struct {
310 expression_t expr;
311 expression_t *expression1;
312 expression_t *expression2;
313 } binary_expression_t;
315 typedef struct {
316 expression_t expr;
317 expression_t *expression;
318 } unary_expression_t;
320 typedef struct {
321 expression_t expr;
322 expression_t *expression;
323 expression_t *true_expression;
324 expression_t *false_expression;
325 } conditional_expression_t;
327 typedef struct {
328 expression_t expr;
329 expression_t *expression;
330 const WCHAR *identifier;
331 } member_expression_t;
333 typedef struct _argument_t {
334 expression_t *expr;
336 struct _argument_t *next;
337 } argument_t;
339 typedef struct {
340 expression_t expr;
341 expression_t *expression;
342 argument_t *argument_list;
343 } call_expression_t;
345 typedef struct {
346 expression_t expr;
347 const WCHAR *identifier;
348 } identifier_expression_t;
350 typedef struct {
351 expression_t expr;
352 literal_t *literal;
353 } literal_expression_t;
355 typedef struct _array_element_t {
356 int elision;
357 expression_t *expr;
359 struct _array_element_t *next;
360 } array_element_t;
362 typedef struct {
363 expression_t expr;
364 array_element_t *element_list;
365 int length;
366 } array_literal_expression_t;
368 typedef struct _property_definition_t {
369 unsigned type;
370 literal_t *name;
371 expression_t *value;
373 struct _property_definition_t *next;
374 } property_definition_t;
376 typedef struct {
377 expression_t expr;
378 property_definition_t *property_list;
379 } property_value_expression_t;
381 BOOL try_parse_ccval(parser_ctx_t*,ccval_t*);
382 BOOL parse_cc_expr(parser_ctx_t*);
384 static inline ccval_t ccval_num(double n)
386 ccval_t r;
387 r.is_num = TRUE;
388 r.u.n = n;
389 return r;
392 static inline ccval_t ccval_bool(BOOL b)
394 ccval_t r;
395 r.is_num = FALSE;
396 r.u.b = b;
397 return r;
400 static inline BOOL get_ccbool(ccval_t v)
402 return v.is_num ? v.u.n != 0 : v.u.b;
405 static inline double get_ccnum(ccval_t v)
407 return v.is_num ? v.u.n : v.u.b;
410 jsstr_t *compiler_alloc_string_len(struct _compiler_ctx_t*,const WCHAR *,unsigned);