jscript: Added postfix increment expression implementation.
[wine.git] / dlls / jscript / engine.h
blob57a68c2812b0e3ef4bb9f869216027d954e71695
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 _parser_ctx_t {
22 LONG ref;
24 const WCHAR *ptr;
25 const WCHAR *begin;
26 const WCHAR *end;
28 script_ctx_t *script;
29 source_elements_t *source;
30 BOOL nl;
31 HRESULT hres;
33 jsheap_t tmp_heap;
34 jsheap_t heap;
36 struct _parser_ctx_t *next;
37 } parser_ctx_t;
39 HRESULT script_parse(script_ctx_t*,const WCHAR*,parser_ctx_t**);
40 void parser_release(parser_ctx_t*);
42 int parser_lex(void*,parser_ctx_t*);
44 static inline void parser_addref(parser_ctx_t *ctx)
46 ctx->ref++;
49 static inline void *parser_alloc(parser_ctx_t *ctx, DWORD size)
51 return jsheap_alloc(&ctx->heap, size);
54 static inline void *parser_alloc_tmp(parser_ctx_t *ctx, DWORD size)
56 return jsheap_alloc(&ctx->tmp_heap, size);
59 typedef struct _scope_chain_t {
60 LONG ref;
61 DispatchEx *obj;
62 struct _scope_chain_t *next;
63 } scope_chain_t;
65 HRESULT scope_push(scope_chain_t*,DispatchEx*,scope_chain_t**);
66 void scope_release(scope_chain_t*);
68 static inline void scope_addref(scope_chain_t *scope)
70 scope->ref++;
73 struct _exec_ctx_t {
74 LONG ref;
76 parser_ctx_t *parser;
77 scope_chain_t *scope_chain;
78 DispatchEx *var_disp;
79 IDispatch *this_obj;
82 static inline void exec_addref(exec_ctx_t *ctx)
84 ctx->ref++;
87 void exec_release(exec_ctx_t*);
88 HRESULT create_exec_ctx(IDispatch*,DispatchEx*,scope_chain_t*,exec_ctx_t**);
89 HRESULT exec_source(exec_ctx_t*,parser_ctx_t*,source_elements_t*,jsexcept_t*,VARIANT*);
91 typedef struct _statement_t statement_t;
92 typedef struct _expression_t expression_t;
93 typedef struct _parameter_t parameter_t;
95 HRESULT create_source_function(parser_ctx_t*,parameter_t*,source_elements_t*,scope_chain_t*,DispatchEx**);
97 typedef struct {
98 VARTYPE vt;
99 union {
100 LONG lval;
101 double dval;
102 const WCHAR *wstr;
103 VARIANT_BOOL bval;
104 IDispatch *disp;
105 } u;
106 } literal_t;
108 typedef struct _variable_declaration_t {
109 const WCHAR *identifier;
110 expression_t *expr;
112 struct _variable_declaration_t *next;
113 } variable_declaration_t;
115 typedef struct {
116 enum{
117 RT_NORMAL,
118 RT_RETURN,
119 RT_BREAK,
120 RT_CONTINUE
121 } type;
122 jsexcept_t ei;
123 } return_type_t;
125 typedef HRESULT (*statement_eval_t)(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
127 struct _statement_t {
128 statement_eval_t eval;
129 statement_t *next;
132 typedef struct {
133 statement_t stat;
134 statement_t *stat_list;
135 } block_statement_t;
137 typedef struct {
138 statement_t stat;
139 variable_declaration_t *variable_list;
140 } var_statement_t;
142 typedef struct {
143 statement_t stat;
144 expression_t *expr;
145 } expression_statement_t;
147 typedef struct {
148 statement_t stat;
149 expression_t *expr;
150 statement_t *if_stat;
151 statement_t *else_stat;
152 } if_statement_t;
154 typedef struct {
155 statement_t stat;
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 expression_t *end_expr;
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 statement_t *stat;
198 struct _case_clausule_t *next;
199 } case_clausule_t;
201 typedef struct {
202 statement_t stat;
203 expression_t *expr;
204 case_clausule_t *case_list;
205 } switch_statement_t;
207 typedef struct {
208 const WCHAR *identifier;
209 statement_t *statement;
210 } catch_block_t;
212 typedef struct {
213 statement_t stat;
214 statement_t *try_statement;
215 catch_block_t *catch_block;
216 statement_t *finally_statement;
217 } try_statement_t;
219 HRESULT block_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
220 HRESULT var_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
221 HRESULT empty_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
222 HRESULT expression_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
223 HRESULT if_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
224 HRESULT dowhile_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
225 HRESULT while_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
226 HRESULT for_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
227 HRESULT forin_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
228 HRESULT continue_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
229 HRESULT break_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
230 HRESULT return_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
231 HRESULT with_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
232 HRESULT labelled_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
233 HRESULT switch_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
234 HRESULT throw_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
235 HRESULT try_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
237 typedef struct {
238 enum {
239 EXPRVAL_VARIANT,
240 EXPRVAL_IDREF,
241 EXPRVAL_NAMEREF
242 } type;
243 union {
244 VARIANT var;
245 struct {
246 IDispatch *disp;
247 DISPID id;
248 } idref;
249 struct {
250 IDispatch *disp;
251 BSTR name;
252 } nameref;
253 } u;
254 } exprval_t;
256 typedef HRESULT (*expression_eval_t)(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
258 struct _expression_t {
259 expression_eval_t eval;
262 struct _parameter_t {
263 const WCHAR *identifier;
265 struct _parameter_t *next;
268 typedef struct _function_declaration_t {
269 const WCHAR *identifier;
270 parameter_t *parameter_list;
271 source_elements_t *source_elements;
273 struct _function_declaration_t *next;
274 } function_declaration_t;
276 struct _source_elements_t {
277 statement_t *statement;
278 statement_t *statement_tail;
279 function_declaration_t *functions;
280 function_declaration_t *functions_tail;
283 typedef struct {
284 expression_t expr;
285 const WCHAR *identifier;
286 parameter_t *parameter_list;
287 source_elements_t *source_elements;
288 } function_expression_t;
290 typedef struct {
291 expression_t expr;
292 expression_t *expression1;
293 expression_t *expression2;
294 } binary_expression_t;
296 typedef struct {
297 expression_t expr;
298 expression_t *expression;
299 } unary_expression_t;
301 typedef struct {
302 expression_t expr;
303 expression_t *expression;
304 expression_t *true_expression;
305 expression_t *false_expression;
306 } conditional_expression_t;
308 typedef struct {
309 expression_t expr;
310 expression_t *member_expr;
311 expression_t *expression;
312 } array_expression_t;
314 typedef struct {
315 expression_t expr;
316 expression_t *expression;
317 const WCHAR *identifier;
318 } member_expression_t;
320 typedef struct _argument_t {
321 expression_t *expr;
323 struct _argument_t *next;
324 } argument_t;
326 typedef struct {
327 expression_t expr;
328 expression_t *expression;
329 argument_t *argument_list;
330 } call_expression_t;
332 typedef struct {
333 expression_t expr;
334 const WCHAR *identifier;
335 } identifier_expression_t;
337 typedef struct {
338 expression_t expr;
339 literal_t *literal;
340 } literal_expression_t;
342 typedef struct _array_element_t {
343 int elision;
344 expression_t *expr;
346 struct _array_element_t *next;
347 } array_element_t;
349 typedef struct {
350 expression_t expr;
351 array_element_t *element_list;
352 int length;
353 } array_literal_expression_t;
355 typedef struct _prop_val_t {
356 literal_t *name;
357 expression_t *value;
359 struct _prop_val_t *next;
360 } prop_val_t;
362 typedef struct {
363 expression_t expr;
364 prop_val_t *property_list;
365 } property_value_expression_t;
367 typedef enum {
368 EXPR_COMMA,
369 EXPR_OR,
370 EXPR_AND,
371 EXPR_BOR,
372 EXPR_BXOR,
373 EXPR_BAND,
374 EXPR_INSTANCEOF,
375 EXPR_IN,
376 EXPR_ADD,
377 EXPR_SUB,
378 EXPR_MUL,
379 EXPR_DIV,
380 EXPR_MOD,
381 EXPR_DELETE,
382 EXPR_VOID,
383 EXPR_TYPEOF,
384 EXPR_MINUS,
385 EXPR_PLUS,
386 EXPR_POSTINC,
387 EXPR_POSTDEC,
388 EXPR_PREINC,
389 EXPR_PREDEC,
390 EXPR_NEW,
391 EXPR_EQ,
392 EXPR_EQEQ,
393 EXPR_NOTEQ,
394 EXPR_NOTEQEQ,
395 EXPR_LESS,
396 EXPR_LESSEQ,
397 EXPR_GREATER,
398 EXPR_GREATEREQ,
399 EXPR_BITNEG,
400 EXPR_LOGNEG,
401 EXPR_LSHIFT,
402 EXPR_RSHIFT,
403 EXPR_RRSHIFT,
404 EXPR_ASSIGN,
405 EXPR_ASSIGNLSHIFT,
406 EXPR_ASSIGNRSHIFT,
407 EXPR_ASSIGNRRSHIFT,
408 EXPR_ASSIGNADD,
409 EXPR_ASSIGNSUB,
410 EXPR_ASSIGNMUL,
411 EXPR_ASSIGNDIV,
412 EXPR_ASSIGNMOD,
413 EXPR_ASSIGNAND,
414 EXPR_ASSIGNOR,
415 EXPR_ASSIGNXOR
416 } expression_type_t;
418 HRESULT function_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
419 HRESULT conditional_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
420 HRESULT array_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
421 HRESULT member_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
422 HRESULT member_new_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
423 HRESULT call_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
424 HRESULT this_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
425 HRESULT identifier_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
426 HRESULT literal_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
427 HRESULT array_literal_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
428 HRESULT property_value_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
430 HRESULT comma_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
431 HRESULT logical_or_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
432 HRESULT logical_and_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
433 HRESULT binary_or_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
434 HRESULT binary_xor_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
435 HRESULT binary_and_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
436 HRESULT instanceof_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
437 HRESULT in_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
438 HRESULT add_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
439 HRESULT sub_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
440 HRESULT mul_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
441 HRESULT div_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
442 HRESULT mod_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
443 HRESULT delete_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
444 HRESULT void_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
445 HRESULT typeof_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
446 HRESULT minus_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
447 HRESULT plus_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
448 HRESULT post_increment_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
449 HRESULT post_decrement_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
450 HRESULT pre_increment_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
451 HRESULT pre_decrement_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
452 HRESULT new_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
453 HRESULT equal_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
454 HRESULT equal2_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
455 HRESULT not_equal_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
456 HRESULT not_equal2_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
457 HRESULT less_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
458 HRESULT lesseq_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
459 HRESULT greater_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
460 HRESULT greatereq_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
461 HRESULT binary_negation_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
462 HRESULT logical_negation_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
463 HRESULT left_shift_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
464 HRESULT right_shift_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
465 HRESULT right2_shift_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
466 HRESULT assign_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
467 HRESULT assign_lshift_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
468 HRESULT assign_rshift_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
469 HRESULT assign_rrshift_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
470 HRESULT assign_add_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
471 HRESULT assign_sub_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
472 HRESULT assign_mul_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
473 HRESULT assign_div_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
474 HRESULT assign_mod_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
475 HRESULT assign_and_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
476 HRESULT assign_or_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
477 HRESULT assign_xor_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);