jscript: Added scope chain implementation.
[wine/hacks.git] / dlls / jscript / engine.h
blob964e2b70ee53c8b2fc1763227fa956eaaaafdc93
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;
80 static inline void exec_addref(exec_ctx_t *ctx)
82 ctx->ref++;
85 void exec_release(exec_ctx_t*);
86 HRESULT create_exec_ctx(scope_chain_t*,exec_ctx_t**);
87 HRESULT exec_source(exec_ctx_t*,parser_ctx_t*,source_elements_t*,jsexcept_t*,VARIANT*);
89 typedef struct _statement_t statement_t;
90 typedef struct _expression_t expression_t;
91 typedef struct _parameter_t parameter_t;
93 typedef struct {
94 VARTYPE vt;
95 union {
96 LONG lval;
97 double dval;
98 const WCHAR *wstr;
99 VARIANT_BOOL bval;
100 IDispatch *disp;
101 } u;
102 } literal_t;
104 typedef struct _variable_declaration_t {
105 const WCHAR *identifier;
106 expression_t *expr;
108 struct _variable_declaration_t *next;
109 } variable_declaration_t;
111 typedef struct {
112 enum{
113 RT_NORMAL,
114 RT_RETURN,
115 RT_BREAK,
116 RT_CONTINUE
117 } type;
118 jsexcept_t ei;
119 } return_type_t;
121 typedef HRESULT (*statement_eval_t)(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
123 struct _statement_t {
124 statement_eval_t eval;
125 statement_t *next;
128 typedef struct {
129 statement_t stat;
130 statement_t *stat_list;
131 } block_statement_t;
133 typedef struct {
134 statement_t stat;
135 variable_declaration_t *variable_list;
136 } var_statement_t;
138 typedef struct {
139 statement_t stat;
140 expression_t *expr;
141 } expression_statement_t;
143 typedef struct {
144 statement_t stat;
145 expression_t *expr;
146 statement_t *if_stat;
147 statement_t *else_stat;
148 } if_statement_t;
150 typedef struct {
151 statement_t stat;
152 expression_t *expr;
153 statement_t *statement;
154 } while_statement_t;
156 typedef struct {
157 statement_t stat;
158 variable_declaration_t *variable_list;
159 expression_t *begin_expr;
160 expression_t *expr;
161 expression_t *end_expr;
162 statement_t *statement;
163 } for_statement_t;
165 typedef struct {
166 statement_t stat;
167 variable_declaration_t *variable;
168 expression_t *expr;
169 expression_t *in_expr;
170 statement_t *statement;
171 } forin_statement_t;
173 typedef struct {
174 statement_t stat;
175 const WCHAR *identifier;
176 } branch_statement_t;
178 typedef struct {
179 statement_t stat;
180 expression_t *expr;
181 statement_t *statement;
182 } with_statement_t;
184 typedef struct {
185 statement_t stat;
186 const WCHAR *identifier;
187 statement_t *statement;
188 } labelled_statement_t;
190 typedef struct _case_clausule_t {
191 expression_t *expr;
192 statement_t *stat;
194 struct _case_clausule_t *next;
195 } case_clausule_t;
197 typedef struct {
198 statement_t stat;
199 expression_t *expr;
200 case_clausule_t *case_list;
201 } switch_statement_t;
203 typedef struct {
204 const WCHAR *identifier;
205 statement_t *statement;
206 } catch_block_t;
208 typedef struct {
209 statement_t stat;
210 statement_t *try_statement;
211 catch_block_t *catch_block;
212 statement_t *finally_statement;
213 } try_statement_t;
215 HRESULT block_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
216 HRESULT var_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
217 HRESULT empty_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
218 HRESULT expression_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
219 HRESULT if_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
220 HRESULT dowhile_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
221 HRESULT while_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
222 HRESULT for_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
223 HRESULT forin_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
224 HRESULT continue_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
225 HRESULT break_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
226 HRESULT return_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
227 HRESULT with_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
228 HRESULT labelled_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
229 HRESULT switch_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
230 HRESULT throw_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
231 HRESULT try_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
233 typedef struct {
234 enum {
235 EXPRVAL_VARIANT,
236 EXPRVAL_IDREF,
237 EXPRVAL_NAMEREF
238 } type;
239 union {
240 VARIANT var;
241 struct {
242 IDispatch *disp;
243 DISPID id;
244 } idref;
245 struct {
246 IDispatch *disp;
247 BSTR name;
248 } nameref;
249 } u;
250 } exprval_t;
252 typedef HRESULT (*expression_eval_t)(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
254 struct _expression_t {
255 expression_eval_t eval;
258 struct _parameter_t {
259 const WCHAR *identifier;
261 struct _parameter_t *next;
264 typedef struct _function_declaration_t {
265 const WCHAR *identifier;
266 parameter_t *parameter_list;
267 source_elements_t *source_elements;
269 struct _function_declaration_t *next;
270 } function_declaration_t;
272 struct _source_elements_t {
273 statement_t *statement;
274 statement_t *statement_tail;
275 function_declaration_t *functions;
276 function_declaration_t *functions_tail;
279 typedef struct {
280 expression_t expr;
281 const WCHAR *identifier;
282 parameter_t *parameter_list;
283 source_elements_t *source_elements;
284 } function_expression_t;
286 typedef struct {
287 expression_t expr;
288 expression_t *expression1;
289 expression_t *expression2;
290 } binary_expression_t;
292 typedef struct {
293 expression_t expr;
294 expression_t *expression;
295 } unary_expression_t;
297 typedef struct {
298 expression_t expr;
299 expression_t *expression;
300 expression_t *true_expression;
301 expression_t *false_expression;
302 } conditional_expression_t;
304 typedef struct {
305 expression_t expr;
306 expression_t *member_expr;
307 expression_t *expression;
308 } array_expression_t;
310 typedef struct {
311 expression_t expr;
312 expression_t *expression;
313 const WCHAR *identifier;
314 } member_expression_t;
316 typedef struct _argument_t {
317 expression_t *expr;
319 struct _argument_t *next;
320 } argument_t;
322 typedef struct {
323 expression_t expr;
324 expression_t *expression;
325 argument_t *argument_list;
326 } call_expression_t;
328 typedef struct {
329 expression_t expr;
330 const WCHAR *identifier;
331 } identifier_expression_t;
333 typedef struct {
334 expression_t expr;
335 literal_t *literal;
336 } literal_expression_t;
338 typedef struct _array_element_t {
339 int elision;
340 expression_t *expr;
342 struct _array_element_t *next;
343 } array_element_t;
345 typedef struct {
346 expression_t expr;
347 array_element_t *element_list;
348 int length;
349 } array_literal_expression_t;
351 typedef struct _prop_val_t {
352 literal_t *name;
353 expression_t *value;
355 struct _prop_val_t *next;
356 } prop_val_t;
358 typedef struct {
359 expression_t expr;
360 prop_val_t *property_list;
361 } property_value_expression_t;
363 typedef enum {
364 EXPR_COMMA,
365 EXPR_OR,
366 EXPR_AND,
367 EXPR_BOR,
368 EXPR_BXOR,
369 EXPR_BAND,
370 EXPR_INSTANCEOF,
371 EXPR_IN,
372 EXPR_ADD,
373 EXPR_SUB,
374 EXPR_MUL,
375 EXPR_DIV,
376 EXPR_MOD,
377 EXPR_DELETE,
378 EXPR_VOID,
379 EXPR_TYPEOF,
380 EXPR_MINUS,
381 EXPR_PLUS,
382 EXPR_POSTINC,
383 EXPR_POSTDEC,
384 EXPR_PREINC,
385 EXPR_PREDEC,
386 EXPR_NEW,
387 EXPR_EQ,
388 EXPR_EQEQ,
389 EXPR_NOTEQ,
390 EXPR_NOTEQEQ,
391 EXPR_LESS,
392 EXPR_LESSEQ,
393 EXPR_GREATER,
394 EXPR_GREATEREQ,
395 EXPR_BITNEG,
396 EXPR_LOGNEG,
397 EXPR_LSHIFT,
398 EXPR_RSHIFT,
399 EXPR_RRSHIFT,
400 EXPR_ASSIGN,
401 EXPR_ASSIGNLSHIFT,
402 EXPR_ASSIGNRSHIFT,
403 EXPR_ASSIGNRRSHIFT,
404 EXPR_ASSIGNADD,
405 EXPR_ASSIGNSUB,
406 EXPR_ASSIGNMUL,
407 EXPR_ASSIGNDIV,
408 EXPR_ASSIGNMOD,
409 EXPR_ASSIGNAND,
410 EXPR_ASSIGNOR,
411 EXPR_ASSIGNXOR
412 } expression_type_t;
414 HRESULT function_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
415 HRESULT conditional_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
416 HRESULT array_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
417 HRESULT member_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
418 HRESULT member_new_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
419 HRESULT call_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
420 HRESULT this_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
421 HRESULT identifier_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
422 HRESULT literal_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
423 HRESULT array_literal_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
424 HRESULT property_value_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
426 HRESULT comma_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
427 HRESULT logical_or_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
428 HRESULT logical_and_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
429 HRESULT binary_or_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
430 HRESULT binary_xor_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
431 HRESULT binary_and_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
432 HRESULT instanceof_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
433 HRESULT in_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
434 HRESULT add_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
435 HRESULT sub_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
436 HRESULT mul_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
437 HRESULT div_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
438 HRESULT mod_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
439 HRESULT delete_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
440 HRESULT void_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
441 HRESULT typeof_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
442 HRESULT minus_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
443 HRESULT plus_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
444 HRESULT post_increment_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
445 HRESULT post_decrement_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
446 HRESULT pre_increment_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
447 HRESULT pre_decrement_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
448 HRESULT new_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
449 HRESULT equal_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
450 HRESULT equal2_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
451 HRESULT not_equal_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
452 HRESULT not_equal2_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
453 HRESULT less_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
454 HRESULT lesseq_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
455 HRESULT greater_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
456 HRESULT greatereq_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
457 HRESULT binary_negation_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
458 HRESULT logical_negation_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
459 HRESULT left_shift_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
460 HRESULT right_shift_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
461 HRESULT right2_shift_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
462 HRESULT assign_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
463 HRESULT assign_lshift_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
464 HRESULT assign_rshift_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
465 HRESULT assign_rrshift_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
466 HRESULT assign_add_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
467 HRESULT assign_sub_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
468 HRESULT assign_mul_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
469 HRESULT assign_div_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
470 HRESULT assign_mod_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
471 HRESULT assign_and_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
472 HRESULT assign_or_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
473 HRESULT assign_xor_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);