wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / jscript / parser.h
blob3fa699c86d3f84efb93b4d3edd013a2bd20ed43b
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;
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 source_elements_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**) DECLSPEC_HIDDEN;
54 void parser_release(parser_ctx_t*) DECLSPEC_HIDDEN;
56 int parser_lex(void*,unsigned*,parser_ctx_t*) DECLSPEC_HIDDEN;
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) DECLSPEC_HIDDEN;
69 BOOL unescape(WCHAR*,size_t*) DECLSPEC_HIDDEN;
70 HRESULT parse_decimal(const WCHAR**,const WCHAR*,double*) DECLSPEC_HIDDEN;
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*) DECLSPEC_HIDDEN;
94 literal_t *new_boolean_literal(parser_ctx_t*,BOOL) DECLSPEC_HIDDEN;
96 typedef struct _variable_declaration_t {
97 const WCHAR *identifier;
98 expression_t *expr;
100 struct _variable_declaration_t *next;
101 struct _variable_declaration_t *global_next; /* for compiler */
102 } variable_declaration_t;
104 typedef enum {
105 STAT_BLOCK,
106 STAT_BREAK,
107 STAT_CONTINUE,
108 STAT_EMPTY,
109 STAT_EXPR,
110 STAT_FOR,
111 STAT_FORIN,
112 STAT_IF,
113 STAT_LABEL,
114 STAT_RETURN,
115 STAT_SWITCH,
116 STAT_THROW,
117 STAT_TRY,
118 STAT_VAR,
119 STAT_WHILE,
120 STAT_WITH
121 } statement_type_t;
123 struct _statement_t {
124 statement_type_t type;
125 statement_t *next;
126 unsigned loc;
129 typedef struct {
130 statement_t stat;
131 statement_t *stat_list;
132 } block_statement_t;
134 typedef struct {
135 statement_t stat;
136 variable_declaration_t *variable_list;
137 } var_statement_t;
139 typedef struct {
140 statement_t stat;
141 expression_t *expr;
142 } expression_statement_t;
144 typedef struct {
145 statement_t stat;
146 expression_t *expr;
147 statement_t *if_stat;
148 statement_t *else_stat;
149 } if_statement_t;
151 typedef struct {
152 statement_t stat;
153 BOOL do_while;
154 expression_t *expr;
155 statement_t *statement;
156 } while_statement_t;
158 typedef struct {
159 statement_t stat;
160 variable_declaration_t *variable_list;
161 expression_t *begin_expr;
162 expression_t *expr;
163 unsigned expr_loc;
164 expression_t *end_expr;
165 unsigned end_loc;
166 statement_t *statement;
167 } for_statement_t;
169 typedef struct {
170 statement_t stat;
171 variable_declaration_t *variable;
172 expression_t *expr;
173 expression_t *in_expr;
174 statement_t *statement;
175 } forin_statement_t;
177 typedef struct {
178 statement_t stat;
179 const WCHAR *identifier;
180 } branch_statement_t;
182 typedef struct {
183 statement_t stat;
184 expression_t *expr;
185 statement_t *statement;
186 } with_statement_t;
188 typedef struct {
189 statement_t stat;
190 const WCHAR *identifier;
191 statement_t *statement;
192 } labelled_statement_t;
194 typedef struct _case_clausule_t {
195 expression_t *expr;
196 unsigned loc;
197 statement_t *stat;
199 struct _case_clausule_t *next;
200 } case_clausule_t;
202 typedef struct {
203 statement_t stat;
204 expression_t *expr;
205 case_clausule_t *case_list;
206 } switch_statement_t;
208 typedef struct {
209 const WCHAR *identifier;
210 statement_t *statement;
211 } catch_block_t;
213 typedef struct {
214 statement_t stat;
215 statement_t *try_statement;
216 catch_block_t *catch_block;
217 statement_t *finally_statement;
218 unsigned finally_loc;
219 } try_statement_t;
221 typedef enum {
222 EXPR_COMMA,
223 EXPR_OR,
224 EXPR_AND,
225 EXPR_BOR,
226 EXPR_BXOR,
227 EXPR_BAND,
228 EXPR_INSTANCEOF,
229 EXPR_IN,
230 EXPR_ADD,
231 EXPR_SUB,
232 EXPR_MUL,
233 EXPR_DIV,
234 EXPR_MOD,
235 EXPR_DELETE,
236 EXPR_VOID,
237 EXPR_TYPEOF,
238 EXPR_MINUS,
239 EXPR_PLUS,
240 EXPR_POSTINC,
241 EXPR_POSTDEC,
242 EXPR_PREINC,
243 EXPR_PREDEC,
244 EXPR_EQ,
245 EXPR_EQEQ,
246 EXPR_NOTEQ,
247 EXPR_NOTEQEQ,
248 EXPR_LESS,
249 EXPR_LESSEQ,
250 EXPR_GREATER,
251 EXPR_GREATEREQ,
252 EXPR_BITNEG,
253 EXPR_LOGNEG,
254 EXPR_LSHIFT,
255 EXPR_RSHIFT,
256 EXPR_RRSHIFT,
257 EXPR_ASSIGN,
258 EXPR_ASSIGNLSHIFT,
259 EXPR_ASSIGNRSHIFT,
260 EXPR_ASSIGNRRSHIFT,
261 EXPR_ASSIGNADD,
262 EXPR_ASSIGNSUB,
263 EXPR_ASSIGNMUL,
264 EXPR_ASSIGNDIV,
265 EXPR_ASSIGNMOD,
266 EXPR_ASSIGNAND,
267 EXPR_ASSIGNOR,
268 EXPR_ASSIGNXOR,
269 EXPR_COND,
270 EXPR_ARRAY,
271 EXPR_MEMBER,
272 EXPR_NEW,
273 EXPR_CALL,
274 EXPR_THIS,
275 EXPR_FUNC,
276 EXPR_IDENT,
277 EXPR_ARRAYLIT,
278 EXPR_PROPVAL,
279 EXPR_LITERAL
280 } expression_type_t;
282 struct _expression_t {
283 expression_type_t type;
286 typedef struct _parameter_t {
287 const WCHAR *identifier;
288 struct _parameter_t *next;
289 } parameter_t;
291 struct _source_elements_t {
292 statement_t *statement;
293 statement_t *statement_tail;
296 typedef struct _function_expression_t {
297 expression_t expr;
298 const WCHAR *identifier;
299 const WCHAR *event_target;
300 parameter_t *parameter_list;
301 source_elements_t *source_elements;
302 const WCHAR *src_str;
303 DWORD src_len;
304 unsigned func_id;
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*) DECLSPEC_HIDDEN;
382 BOOL parse_cc_expr(parser_ctx_t*) DECLSPEC_HIDDEN;
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) DECLSPEC_HIDDEN;