shdocvw: Get rid of more *_THIS macros.
[wine/multimedia.git] / dlls / jscript / engine.h
blobd5e2d339d5ecaa405f990071b2f70a5031bc18f7
1 /*
2 * Copyright 2008 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 _function_expression_t function_expression_t;
22 typedef struct _function_declaration_t {
23 function_expression_t *expr;
25 struct _function_declaration_t *next;
26 } function_declaration_t;
28 typedef struct _var_list_t {
29 const WCHAR *identifier;
31 struct _var_list_t *next;
32 } var_list_t;
34 typedef struct _func_stack {
35 function_declaration_t *func_head;
36 function_declaration_t *func_tail;
37 var_list_t *var_head;
38 var_list_t *var_tail;
40 struct _func_stack *next;
41 } func_stack_t;
43 typedef struct _parser_ctx_t {
44 LONG ref;
46 WCHAR *begin;
47 const WCHAR *end;
48 const WCHAR *ptr;
50 script_ctx_t *script;
51 source_elements_t *source;
52 BOOL nl;
53 BOOL is_html;
54 BOOL lexer_error;
55 HRESULT hres;
57 jsheap_t heap;
59 func_stack_t *func_stack;
61 struct _parser_ctx_t *next;
62 } parser_ctx_t;
64 HRESULT script_parse(script_ctx_t*,const WCHAR*,const WCHAR*,parser_ctx_t**);
65 void parser_release(parser_ctx_t*);
67 int parser_lex(void*,parser_ctx_t*);
69 static inline void parser_addref(parser_ctx_t *ctx)
71 ctx->ref++;
74 static inline void *parser_alloc(parser_ctx_t *ctx, DWORD size)
76 return jsheap_alloc(&ctx->heap, size);
79 static inline void *parser_alloc_tmp(parser_ctx_t *ctx, DWORD size)
81 return jsheap_alloc(&ctx->script->tmp_heap, size);
84 typedef struct _scope_chain_t {
85 LONG ref;
86 jsdisp_t *obj;
87 struct _scope_chain_t *next;
88 } scope_chain_t;
90 HRESULT scope_push(scope_chain_t*,jsdisp_t*,scope_chain_t**);
91 void scope_release(scope_chain_t*);
93 static inline void scope_addref(scope_chain_t *scope)
95 scope->ref++;
98 struct _exec_ctx_t {
99 LONG ref;
101 parser_ctx_t *parser;
102 scope_chain_t *scope_chain;
103 jsdisp_t *var_disp;
104 IDispatch *this_obj;
105 BOOL is_global;
108 static inline void exec_addref(exec_ctx_t *ctx)
110 ctx->ref++;
113 void exec_release(exec_ctx_t*);
114 HRESULT create_exec_ctx(script_ctx_t*,IDispatch*,jsdisp_t*,scope_chain_t*,BOOL,exec_ctx_t**);
115 HRESULT exec_source(exec_ctx_t*,parser_ctx_t*,source_elements_t*,BOOL,jsexcept_t*,VARIANT*);
117 typedef struct _statement_t statement_t;
118 typedef struct _expression_t expression_t;
119 typedef struct _parameter_t parameter_t;
121 HRESULT create_source_function(parser_ctx_t*,parameter_t*,source_elements_t*,scope_chain_t*,
122 const WCHAR*,DWORD,jsdisp_t**);
124 typedef enum {
125 LT_INT,
126 LT_DOUBLE,
127 LT_STRING,
128 LT_BOOL,
129 LT_NULL,
130 LT_REGEXP
131 }literal_type_t;
133 typedef struct {
134 literal_type_t type;
135 union {
136 LONG lval;
137 double dval;
138 const WCHAR *wstr;
139 VARIANT_BOOL bval;
140 IDispatch *disp;
141 struct {
142 const WCHAR *str;
143 DWORD str_len;
144 DWORD flags;
145 } regexp;
146 } u;
147 } literal_t;
149 literal_t *parse_regexp(parser_ctx_t*);
151 typedef struct _variable_declaration_t {
152 const WCHAR *identifier;
153 expression_t *expr;
155 struct _variable_declaration_t *next;
156 } variable_declaration_t;
158 typedef struct {
159 enum{
160 RT_NORMAL,
161 RT_RETURN,
162 RT_BREAK,
163 RT_CONTINUE
164 } type;
165 jsexcept_t ei;
166 } return_type_t;
168 typedef HRESULT (*statement_eval_t)(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
170 struct _statement_t {
171 statement_eval_t eval;
172 statement_t *next;
175 typedef struct {
176 statement_t stat;
177 statement_t *stat_list;
178 } block_statement_t;
180 typedef struct {
181 statement_t stat;
182 variable_declaration_t *variable_list;
183 } var_statement_t;
185 typedef struct {
186 statement_t stat;
187 expression_t *expr;
188 } expression_statement_t;
190 typedef struct {
191 statement_t stat;
192 expression_t *expr;
193 statement_t *if_stat;
194 statement_t *else_stat;
195 } if_statement_t;
197 typedef struct {
198 statement_t stat;
199 BOOL do_while;
200 expression_t *expr;
201 statement_t *statement;
202 } while_statement_t;
204 typedef struct {
205 statement_t stat;
206 variable_declaration_t *variable_list;
207 expression_t *begin_expr;
208 expression_t *expr;
209 expression_t *end_expr;
210 statement_t *statement;
211 } for_statement_t;
213 typedef struct {
214 statement_t stat;
215 variable_declaration_t *variable;
216 expression_t *expr;
217 expression_t *in_expr;
218 statement_t *statement;
219 } forin_statement_t;
221 typedef struct {
222 statement_t stat;
223 const WCHAR *identifier;
224 } branch_statement_t;
226 typedef struct {
227 statement_t stat;
228 expression_t *expr;
229 statement_t *statement;
230 } with_statement_t;
232 typedef struct {
233 statement_t stat;
234 const WCHAR *identifier;
235 statement_t *statement;
236 } labelled_statement_t;
238 typedef struct _case_clausule_t {
239 expression_t *expr;
240 statement_t *stat;
242 struct _case_clausule_t *next;
243 } case_clausule_t;
245 typedef struct {
246 statement_t stat;
247 expression_t *expr;
248 case_clausule_t *case_list;
249 } switch_statement_t;
251 typedef struct {
252 const WCHAR *identifier;
253 statement_t *statement;
254 } catch_block_t;
256 typedef struct {
257 statement_t stat;
258 statement_t *try_statement;
259 catch_block_t *catch_block;
260 statement_t *finally_statement;
261 } try_statement_t;
263 HRESULT block_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
264 HRESULT var_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
265 HRESULT empty_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
266 HRESULT expression_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
267 HRESULT if_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
268 HRESULT while_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
269 HRESULT for_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
270 HRESULT forin_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
271 HRESULT continue_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
272 HRESULT break_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
273 HRESULT return_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
274 HRESULT with_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
275 HRESULT labelled_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
276 HRESULT switch_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
277 HRESULT throw_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
278 HRESULT try_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
280 typedef struct {
281 enum {
282 EXPRVAL_VARIANT,
283 EXPRVAL_IDREF,
284 EXPRVAL_NAMEREF,
285 EXPRVAL_INVALID
286 } type;
287 union {
288 VARIANT var;
289 struct {
290 IDispatch *disp;
291 DISPID id;
292 } idref;
293 struct {
294 IDispatch *disp;
295 BSTR name;
296 } nameref;
297 BSTR identifier;
298 } u;
299 } exprval_t;
301 typedef HRESULT (*expression_eval_t)(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
303 struct _expression_t {
304 expression_eval_t eval;
307 struct _parameter_t {
308 const WCHAR *identifier;
310 struct _parameter_t *next;
313 struct _source_elements_t {
314 statement_t *statement;
315 statement_t *statement_tail;
316 function_declaration_t *functions;
317 var_list_t *variables;
320 struct _function_expression_t {
321 expression_t expr;
322 const WCHAR *identifier;
323 parameter_t *parameter_list;
324 source_elements_t *source_elements;
325 const WCHAR *src_str;
326 DWORD src_len;
329 typedef struct {
330 expression_t expr;
331 expression_t *expression1;
332 expression_t *expression2;
333 } binary_expression_t;
335 typedef struct {
336 expression_t expr;
337 expression_t *expression;
338 } unary_expression_t;
340 typedef struct {
341 expression_t expr;
342 expression_t *expression;
343 expression_t *true_expression;
344 expression_t *false_expression;
345 } conditional_expression_t;
347 typedef struct {
348 expression_t expr;
349 expression_t *member_expr;
350 expression_t *expression;
351 } array_expression_t;
353 typedef struct {
354 expression_t expr;
355 expression_t *expression;
356 const WCHAR *identifier;
357 } member_expression_t;
359 typedef struct _argument_t {
360 expression_t *expr;
362 struct _argument_t *next;
363 } argument_t;
365 typedef struct {
366 expression_t expr;
367 expression_t *expression;
368 argument_t *argument_list;
369 } call_expression_t;
371 typedef struct {
372 expression_t expr;
373 const WCHAR *identifier;
374 } identifier_expression_t;
376 typedef struct {
377 expression_t expr;
378 literal_t *literal;
379 } literal_expression_t;
381 typedef struct _array_element_t {
382 int elision;
383 expression_t *expr;
385 struct _array_element_t *next;
386 } array_element_t;
388 typedef struct {
389 expression_t expr;
390 array_element_t *element_list;
391 int length;
392 } array_literal_expression_t;
394 typedef struct _prop_val_t {
395 literal_t *name;
396 expression_t *value;
398 struct _prop_val_t *next;
399 } prop_val_t;
401 typedef struct {
402 expression_t expr;
403 prop_val_t *property_list;
404 } property_value_expression_t;
406 typedef enum {
407 EXPR_COMMA,
408 EXPR_OR,
409 EXPR_AND,
410 EXPR_BOR,
411 EXPR_BXOR,
412 EXPR_BAND,
413 EXPR_INSTANCEOF,
414 EXPR_IN,
415 EXPR_ADD,
416 EXPR_SUB,
417 EXPR_MUL,
418 EXPR_DIV,
419 EXPR_MOD,
420 EXPR_DELETE,
421 EXPR_VOID,
422 EXPR_TYPEOF,
423 EXPR_MINUS,
424 EXPR_PLUS,
425 EXPR_POSTINC,
426 EXPR_POSTDEC,
427 EXPR_PREINC,
428 EXPR_PREDEC,
429 EXPR_EQ,
430 EXPR_EQEQ,
431 EXPR_NOTEQ,
432 EXPR_NOTEQEQ,
433 EXPR_LESS,
434 EXPR_LESSEQ,
435 EXPR_GREATER,
436 EXPR_GREATEREQ,
437 EXPR_BITNEG,
438 EXPR_LOGNEG,
439 EXPR_LSHIFT,
440 EXPR_RSHIFT,
441 EXPR_RRSHIFT,
442 EXPR_ASSIGN,
443 EXPR_ASSIGNLSHIFT,
444 EXPR_ASSIGNRSHIFT,
445 EXPR_ASSIGNRRSHIFT,
446 EXPR_ASSIGNADD,
447 EXPR_ASSIGNSUB,
448 EXPR_ASSIGNMUL,
449 EXPR_ASSIGNDIV,
450 EXPR_ASSIGNMOD,
451 EXPR_ASSIGNAND,
452 EXPR_ASSIGNOR,
453 EXPR_ASSIGNXOR
454 } expression_type_t;
456 HRESULT function_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
457 HRESULT conditional_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
458 HRESULT array_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
459 HRESULT member_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
460 HRESULT new_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
461 HRESULT call_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
462 HRESULT this_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
463 HRESULT identifier_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
464 HRESULT literal_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
465 HRESULT array_literal_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
466 HRESULT property_value_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
468 HRESULT comma_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
469 HRESULT logical_or_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
470 HRESULT logical_and_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
471 HRESULT binary_or_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
472 HRESULT binary_xor_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
473 HRESULT binary_and_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
474 HRESULT instanceof_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
475 HRESULT in_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
476 HRESULT add_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
477 HRESULT sub_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
478 HRESULT mul_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
479 HRESULT div_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
480 HRESULT mod_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
481 HRESULT delete_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
482 HRESULT void_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
483 HRESULT typeof_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
484 HRESULT minus_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
485 HRESULT plus_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
486 HRESULT post_increment_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
487 HRESULT post_decrement_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
488 HRESULT pre_increment_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
489 HRESULT pre_decrement_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
490 HRESULT equal_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
491 HRESULT equal2_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
492 HRESULT not_equal_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
493 HRESULT not_equal2_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
494 HRESULT less_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
495 HRESULT lesseq_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
496 HRESULT greater_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
497 HRESULT greatereq_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
498 HRESULT binary_negation_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
499 HRESULT logical_negation_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
500 HRESULT left_shift_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
501 HRESULT right_shift_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
502 HRESULT right2_shift_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
503 HRESULT assign_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
504 HRESULT assign_lshift_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
505 HRESULT assign_rshift_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
506 HRESULT assign_rrshift_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
507 HRESULT assign_add_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
508 HRESULT assign_sub_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
509 HRESULT assign_mul_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
510 HRESULT assign_div_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
511 HRESULT assign_mod_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
512 HRESULT assign_and_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
513 HRESULT assign_or_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
514 HRESULT assign_xor_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);