push 9669c7d1f7bf34ed30fb547f8ace8a50165f3e4f
[wine/hacks.git] / dlls / jscript / engine.h
blob3746b5b6f2ccdeaee8b3c9d8d2806712cf7fe9d7
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;
21 typedef struct _obj_literal_t {
22 DispatchEx *obj;
23 struct _obj_literal_t *next;
24 } obj_literal_t;
26 typedef struct _var_list_t {
27 const WCHAR *identifier;
29 struct _var_list_t *next;
30 } var_list_t;
32 typedef struct _func_stack {
33 var_list_t *var_head;
34 var_list_t *var_tail;
36 struct _func_stack *next;
37 } func_stack_t;
39 typedef struct _parser_ctx_t {
40 LONG ref;
42 const WCHAR *ptr;
43 const WCHAR *begin;
44 const WCHAR *end;
46 script_ctx_t *script;
47 source_elements_t *source;
48 BOOL nl;
49 HRESULT hres;
51 jsheap_t heap;
53 obj_literal_t *obj_literals;
54 func_stack_t *func_stack;
56 struct _parser_ctx_t *next;
57 } parser_ctx_t;
59 HRESULT script_parse(script_ctx_t*,const WCHAR*,parser_ctx_t**);
60 void parser_release(parser_ctx_t*);
62 int parser_lex(void*,parser_ctx_t*);
64 static inline void parser_addref(parser_ctx_t *ctx)
66 ctx->ref++;
69 static inline void *parser_alloc(parser_ctx_t *ctx, DWORD size)
71 return jsheap_alloc(&ctx->heap, size);
74 static inline void *parser_alloc_tmp(parser_ctx_t *ctx, DWORD size)
76 return jsheap_alloc(&ctx->script->tmp_heap, size);
79 typedef struct _scope_chain_t {
80 LONG ref;
81 DispatchEx *obj;
82 struct _scope_chain_t *next;
83 } scope_chain_t;
85 HRESULT scope_push(scope_chain_t*,DispatchEx*,scope_chain_t**);
86 void scope_release(scope_chain_t*);
88 static inline void scope_addref(scope_chain_t *scope)
90 scope->ref++;
93 struct _exec_ctx_t {
94 LONG ref;
96 parser_ctx_t *parser;
97 scope_chain_t *scope_chain;
98 DispatchEx *var_disp;
99 IDispatch *this_obj;
102 static inline void exec_addref(exec_ctx_t *ctx)
104 ctx->ref++;
107 void exec_release(exec_ctx_t*);
108 HRESULT create_exec_ctx(IDispatch*,DispatchEx*,scope_chain_t*,exec_ctx_t**);
109 HRESULT exec_source(exec_ctx_t*,parser_ctx_t*,source_elements_t*,jsexcept_t*,VARIANT*);
111 typedef struct _statement_t statement_t;
112 typedef struct _expression_t expression_t;
113 typedef struct _parameter_t parameter_t;
115 HRESULT create_source_function(parser_ctx_t*,parameter_t*,source_elements_t*,scope_chain_t*,
116 const WCHAR*,DWORD,DispatchEx**);
118 typedef struct {
119 VARTYPE vt;
120 union {
121 LONG lval;
122 double dval;
123 const WCHAR *wstr;
124 VARIANT_BOOL bval;
125 IDispatch *disp;
126 } u;
127 } literal_t;
129 literal_t *parse_regexp(parser_ctx_t*);
131 typedef struct _variable_declaration_t {
132 const WCHAR *identifier;
133 expression_t *expr;
135 struct _variable_declaration_t *next;
136 } variable_declaration_t;
138 typedef struct {
139 enum{
140 RT_NORMAL,
141 RT_RETURN,
142 RT_BREAK,
143 RT_CONTINUE
144 } type;
145 jsexcept_t ei;
146 } return_type_t;
148 typedef HRESULT (*statement_eval_t)(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
150 struct _statement_t {
151 statement_eval_t eval;
152 statement_t *next;
155 typedef struct {
156 statement_t stat;
157 statement_t *stat_list;
158 } block_statement_t;
160 typedef struct {
161 statement_t stat;
162 variable_declaration_t *variable_list;
163 } var_statement_t;
165 typedef struct {
166 statement_t stat;
167 expression_t *expr;
168 } expression_statement_t;
170 typedef struct {
171 statement_t stat;
172 expression_t *expr;
173 statement_t *if_stat;
174 statement_t *else_stat;
175 } if_statement_t;
177 typedef struct {
178 statement_t stat;
179 BOOL do_while;
180 expression_t *expr;
181 statement_t *statement;
182 } while_statement_t;
184 typedef struct {
185 statement_t stat;
186 variable_declaration_t *variable_list;
187 expression_t *begin_expr;
188 expression_t *expr;
189 expression_t *end_expr;
190 statement_t *statement;
191 } for_statement_t;
193 typedef struct {
194 statement_t stat;
195 variable_declaration_t *variable;
196 expression_t *expr;
197 expression_t *in_expr;
198 statement_t *statement;
199 } forin_statement_t;
201 typedef struct {
202 statement_t stat;
203 const WCHAR *identifier;
204 } branch_statement_t;
206 typedef struct {
207 statement_t stat;
208 expression_t *expr;
209 statement_t *statement;
210 } with_statement_t;
212 typedef struct {
213 statement_t stat;
214 const WCHAR *identifier;
215 statement_t *statement;
216 } labelled_statement_t;
218 typedef struct _case_clausule_t {
219 expression_t *expr;
220 statement_t *stat;
222 struct _case_clausule_t *next;
223 } case_clausule_t;
225 typedef struct {
226 statement_t stat;
227 expression_t *expr;
228 case_clausule_t *case_list;
229 } switch_statement_t;
231 typedef struct {
232 const WCHAR *identifier;
233 statement_t *statement;
234 } catch_block_t;
236 typedef struct {
237 statement_t stat;
238 statement_t *try_statement;
239 catch_block_t *catch_block;
240 statement_t *finally_statement;
241 } try_statement_t;
243 HRESULT block_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
244 HRESULT var_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
245 HRESULT empty_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
246 HRESULT expression_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
247 HRESULT if_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
248 HRESULT while_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
249 HRESULT for_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
250 HRESULT forin_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
251 HRESULT continue_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
252 HRESULT break_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
253 HRESULT return_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
254 HRESULT with_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
255 HRESULT labelled_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
256 HRESULT switch_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
257 HRESULT throw_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
258 HRESULT try_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
260 typedef struct {
261 enum {
262 EXPRVAL_VARIANT,
263 EXPRVAL_IDREF,
264 EXPRVAL_NAMEREF
265 } type;
266 union {
267 VARIANT var;
268 struct {
269 IDispatch *disp;
270 DISPID id;
271 } idref;
272 struct {
273 IDispatch *disp;
274 BSTR name;
275 } nameref;
276 } u;
277 } exprval_t;
279 typedef HRESULT (*expression_eval_t)(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
281 struct _expression_t {
282 expression_eval_t eval;
285 struct _parameter_t {
286 const WCHAR *identifier;
288 struct _parameter_t *next;
291 typedef struct _function_declaration_t {
292 const WCHAR *identifier;
293 parameter_t *parameter_list;
294 source_elements_t *source_elements;
295 const WCHAR *src_str;
296 DWORD src_len;
298 struct _function_declaration_t *next;
299 } function_declaration_t;
301 struct _source_elements_t {
302 statement_t *statement;
303 statement_t *statement_tail;
304 function_declaration_t *functions;
305 function_declaration_t *functions_tail;
306 var_list_t *variables;
309 typedef struct {
310 expression_t expr;
311 const WCHAR *identifier;
312 parameter_t *parameter_list;
313 source_elements_t *source_elements;
314 const WCHAR *src_str;
315 DWORD src_len;
316 } function_expression_t;
318 typedef struct {
319 expression_t expr;
320 expression_t *expression1;
321 expression_t *expression2;
322 } binary_expression_t;
324 typedef struct {
325 expression_t expr;
326 expression_t *expression;
327 } unary_expression_t;
329 typedef struct {
330 expression_t expr;
331 expression_t *expression;
332 expression_t *true_expression;
333 expression_t *false_expression;
334 } conditional_expression_t;
336 typedef struct {
337 expression_t expr;
338 expression_t *member_expr;
339 expression_t *expression;
340 } array_expression_t;
342 typedef struct {
343 expression_t expr;
344 expression_t *expression;
345 const WCHAR *identifier;
346 } member_expression_t;
348 typedef struct _argument_t {
349 expression_t *expr;
351 struct _argument_t *next;
352 } argument_t;
354 typedef struct {
355 expression_t expr;
356 expression_t *expression;
357 argument_t *argument_list;
358 } call_expression_t;
360 typedef struct {
361 expression_t expr;
362 const WCHAR *identifier;
363 } identifier_expression_t;
365 typedef struct {
366 expression_t expr;
367 literal_t *literal;
368 } literal_expression_t;
370 typedef struct _array_element_t {
371 int elision;
372 expression_t *expr;
374 struct _array_element_t *next;
375 } array_element_t;
377 typedef struct {
378 expression_t expr;
379 array_element_t *element_list;
380 int length;
381 } array_literal_expression_t;
383 typedef struct _prop_val_t {
384 literal_t *name;
385 expression_t *value;
387 struct _prop_val_t *next;
388 } prop_val_t;
390 typedef struct {
391 expression_t expr;
392 prop_val_t *property_list;
393 } property_value_expression_t;
395 typedef enum {
396 EXPR_COMMA,
397 EXPR_OR,
398 EXPR_AND,
399 EXPR_BOR,
400 EXPR_BXOR,
401 EXPR_BAND,
402 EXPR_INSTANCEOF,
403 EXPR_IN,
404 EXPR_ADD,
405 EXPR_SUB,
406 EXPR_MUL,
407 EXPR_DIV,
408 EXPR_MOD,
409 EXPR_DELETE,
410 EXPR_VOID,
411 EXPR_TYPEOF,
412 EXPR_MINUS,
413 EXPR_PLUS,
414 EXPR_POSTINC,
415 EXPR_POSTDEC,
416 EXPR_PREINC,
417 EXPR_PREDEC,
418 EXPR_EQ,
419 EXPR_EQEQ,
420 EXPR_NOTEQ,
421 EXPR_NOTEQEQ,
422 EXPR_LESS,
423 EXPR_LESSEQ,
424 EXPR_GREATER,
425 EXPR_GREATEREQ,
426 EXPR_BITNEG,
427 EXPR_LOGNEG,
428 EXPR_LSHIFT,
429 EXPR_RSHIFT,
430 EXPR_RRSHIFT,
431 EXPR_ASSIGN,
432 EXPR_ASSIGNLSHIFT,
433 EXPR_ASSIGNRSHIFT,
434 EXPR_ASSIGNRRSHIFT,
435 EXPR_ASSIGNADD,
436 EXPR_ASSIGNSUB,
437 EXPR_ASSIGNMUL,
438 EXPR_ASSIGNDIV,
439 EXPR_ASSIGNMOD,
440 EXPR_ASSIGNAND,
441 EXPR_ASSIGNOR,
442 EXPR_ASSIGNXOR
443 } expression_type_t;
445 HRESULT function_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
446 HRESULT conditional_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
447 HRESULT array_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
448 HRESULT member_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
449 HRESULT new_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
450 HRESULT call_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
451 HRESULT this_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
452 HRESULT identifier_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
453 HRESULT literal_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
454 HRESULT array_literal_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
455 HRESULT property_value_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
457 HRESULT comma_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
458 HRESULT logical_or_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
459 HRESULT logical_and_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
460 HRESULT binary_or_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
461 HRESULT binary_xor_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
462 HRESULT binary_and_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
463 HRESULT instanceof_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
464 HRESULT in_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
465 HRESULT add_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
466 HRESULT sub_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
467 HRESULT mul_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
468 HRESULT div_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
469 HRESULT mod_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
470 HRESULT delete_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
471 HRESULT void_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
472 HRESULT typeof_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
473 HRESULT minus_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
474 HRESULT plus_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
475 HRESULT post_increment_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
476 HRESULT post_decrement_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
477 HRESULT pre_increment_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
478 HRESULT pre_decrement_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
479 HRESULT equal_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
480 HRESULT equal2_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
481 HRESULT not_equal_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
482 HRESULT not_equal2_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
483 HRESULT less_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
484 HRESULT lesseq_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
485 HRESULT greater_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
486 HRESULT greatereq_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
487 HRESULT binary_negation_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
488 HRESULT logical_negation_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
489 HRESULT left_shift_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
490 HRESULT right_shift_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
491 HRESULT right2_shift_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
492 HRESULT assign_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
493 HRESULT assign_lshift_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
494 HRESULT assign_rshift_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
495 HRESULT assign_rrshift_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
496 HRESULT assign_add_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
497 HRESULT assign_sub_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
498 HRESULT assign_mul_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
499 HRESULT assign_div_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
500 HRESULT assign_mod_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
501 HRESULT assign_and_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
502 HRESULT assign_or_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
503 HRESULT assign_xor_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);