user32: Convert menu and string table resources to po files.
[wine.git] / dlls / jscript / engine.h
blob2800c863a0e68e16ba19e6092cf0f54faee02b5e
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*);
150 literal_t *new_boolean_literal(parser_ctx_t*,VARIANT_BOOL);
152 typedef struct _variable_declaration_t {
153 const WCHAR *identifier;
154 expression_t *expr;
156 struct _variable_declaration_t *next;
157 } variable_declaration_t;
159 typedef struct {
160 enum{
161 RT_NORMAL,
162 RT_RETURN,
163 RT_BREAK,
164 RT_CONTINUE
165 } type;
166 jsexcept_t ei;
167 } return_type_t;
169 typedef HRESULT (*statement_eval_t)(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
171 struct _statement_t {
172 statement_eval_t eval;
173 statement_t *next;
176 typedef struct {
177 statement_t stat;
178 statement_t *stat_list;
179 } block_statement_t;
181 typedef struct {
182 statement_t stat;
183 variable_declaration_t *variable_list;
184 } var_statement_t;
186 typedef struct {
187 statement_t stat;
188 expression_t *expr;
189 } expression_statement_t;
191 typedef struct {
192 statement_t stat;
193 expression_t *expr;
194 statement_t *if_stat;
195 statement_t *else_stat;
196 } if_statement_t;
198 typedef struct {
199 statement_t stat;
200 BOOL do_while;
201 expression_t *expr;
202 statement_t *statement;
203 } while_statement_t;
205 typedef struct {
206 statement_t stat;
207 variable_declaration_t *variable_list;
208 expression_t *begin_expr;
209 expression_t *expr;
210 expression_t *end_expr;
211 statement_t *statement;
212 } for_statement_t;
214 typedef struct {
215 statement_t stat;
216 variable_declaration_t *variable;
217 expression_t *expr;
218 expression_t *in_expr;
219 statement_t *statement;
220 } forin_statement_t;
222 typedef struct {
223 statement_t stat;
224 const WCHAR *identifier;
225 } branch_statement_t;
227 typedef struct {
228 statement_t stat;
229 expression_t *expr;
230 statement_t *statement;
231 } with_statement_t;
233 typedef struct {
234 statement_t stat;
235 const WCHAR *identifier;
236 statement_t *statement;
237 } labelled_statement_t;
239 typedef struct _case_clausule_t {
240 expression_t *expr;
241 statement_t *stat;
243 struct _case_clausule_t *next;
244 } case_clausule_t;
246 typedef struct {
247 statement_t stat;
248 expression_t *expr;
249 case_clausule_t *case_list;
250 } switch_statement_t;
252 typedef struct {
253 const WCHAR *identifier;
254 statement_t *statement;
255 } catch_block_t;
257 typedef struct {
258 statement_t stat;
259 statement_t *try_statement;
260 catch_block_t *catch_block;
261 statement_t *finally_statement;
262 } try_statement_t;
264 HRESULT block_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
265 HRESULT var_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
266 HRESULT empty_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
267 HRESULT expression_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
268 HRESULT if_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
269 HRESULT while_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
270 HRESULT for_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
271 HRESULT forin_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
272 HRESULT continue_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
273 HRESULT break_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
274 HRESULT return_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
275 HRESULT with_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
276 HRESULT labelled_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
277 HRESULT switch_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
278 HRESULT throw_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
279 HRESULT try_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
281 typedef struct {
282 enum {
283 EXPRVAL_VARIANT,
284 EXPRVAL_IDREF,
285 EXPRVAL_NAMEREF,
286 EXPRVAL_INVALID
287 } type;
288 union {
289 VARIANT var;
290 struct {
291 IDispatch *disp;
292 DISPID id;
293 } idref;
294 struct {
295 IDispatch *disp;
296 BSTR name;
297 } nameref;
298 BSTR identifier;
299 } u;
300 } exprval_t;
302 typedef HRESULT (*expression_eval_t)(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
304 struct _expression_t {
305 expression_eval_t eval;
308 struct _parameter_t {
309 const WCHAR *identifier;
311 struct _parameter_t *next;
314 struct _source_elements_t {
315 statement_t *statement;
316 statement_t *statement_tail;
317 function_declaration_t *functions;
318 var_list_t *variables;
321 struct _function_expression_t {
322 expression_t expr;
323 const WCHAR *identifier;
324 parameter_t *parameter_list;
325 source_elements_t *source_elements;
326 const WCHAR *src_str;
327 DWORD src_len;
330 typedef struct {
331 expression_t expr;
332 expression_t *expression1;
333 expression_t *expression2;
334 } binary_expression_t;
336 typedef struct {
337 expression_t expr;
338 expression_t *expression;
339 } unary_expression_t;
341 typedef struct {
342 expression_t expr;
343 expression_t *expression;
344 expression_t *true_expression;
345 expression_t *false_expression;
346 } conditional_expression_t;
348 typedef struct {
349 expression_t expr;
350 expression_t *member_expr;
351 expression_t *expression;
352 } array_expression_t;
354 typedef struct {
355 expression_t expr;
356 expression_t *expression;
357 const WCHAR *identifier;
358 } member_expression_t;
360 typedef struct _argument_t {
361 expression_t *expr;
363 struct _argument_t *next;
364 } argument_t;
366 typedef struct {
367 expression_t expr;
368 expression_t *expression;
369 argument_t *argument_list;
370 } call_expression_t;
372 typedef struct {
373 expression_t expr;
374 const WCHAR *identifier;
375 } identifier_expression_t;
377 typedef struct {
378 expression_t expr;
379 literal_t *literal;
380 } literal_expression_t;
382 typedef struct _array_element_t {
383 int elision;
384 expression_t *expr;
386 struct _array_element_t *next;
387 } array_element_t;
389 typedef struct {
390 expression_t expr;
391 array_element_t *element_list;
392 int length;
393 } array_literal_expression_t;
395 typedef struct _prop_val_t {
396 literal_t *name;
397 expression_t *value;
399 struct _prop_val_t *next;
400 } prop_val_t;
402 typedef struct {
403 expression_t expr;
404 prop_val_t *property_list;
405 } property_value_expression_t;
407 typedef enum {
408 EXPR_COMMA,
409 EXPR_OR,
410 EXPR_AND,
411 EXPR_BOR,
412 EXPR_BXOR,
413 EXPR_BAND,
414 EXPR_INSTANCEOF,
415 EXPR_IN,
416 EXPR_ADD,
417 EXPR_SUB,
418 EXPR_MUL,
419 EXPR_DIV,
420 EXPR_MOD,
421 EXPR_DELETE,
422 EXPR_VOID,
423 EXPR_TYPEOF,
424 EXPR_MINUS,
425 EXPR_PLUS,
426 EXPR_POSTINC,
427 EXPR_POSTDEC,
428 EXPR_PREINC,
429 EXPR_PREDEC,
430 EXPR_EQ,
431 EXPR_EQEQ,
432 EXPR_NOTEQ,
433 EXPR_NOTEQEQ,
434 EXPR_LESS,
435 EXPR_LESSEQ,
436 EXPR_GREATER,
437 EXPR_GREATEREQ,
438 EXPR_BITNEG,
439 EXPR_LOGNEG,
440 EXPR_LSHIFT,
441 EXPR_RSHIFT,
442 EXPR_RRSHIFT,
443 EXPR_ASSIGN,
444 EXPR_ASSIGNLSHIFT,
445 EXPR_ASSIGNRSHIFT,
446 EXPR_ASSIGNRRSHIFT,
447 EXPR_ASSIGNADD,
448 EXPR_ASSIGNSUB,
449 EXPR_ASSIGNMUL,
450 EXPR_ASSIGNDIV,
451 EXPR_ASSIGNMOD,
452 EXPR_ASSIGNAND,
453 EXPR_ASSIGNOR,
454 EXPR_ASSIGNXOR
455 } expression_type_t;
457 HRESULT function_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
458 HRESULT conditional_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
459 HRESULT array_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
460 HRESULT member_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
461 HRESULT new_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
462 HRESULT call_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
463 HRESULT this_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
464 HRESULT identifier_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
465 HRESULT literal_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
466 HRESULT array_literal_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
467 HRESULT property_value_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
469 HRESULT comma_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
470 HRESULT logical_or_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
471 HRESULT logical_and_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
472 HRESULT binary_or_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
473 HRESULT binary_xor_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
474 HRESULT binary_and_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
475 HRESULT instanceof_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
476 HRESULT in_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
477 HRESULT add_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
478 HRESULT sub_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
479 HRESULT mul_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
480 HRESULT div_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
481 HRESULT mod_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
482 HRESULT delete_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
483 HRESULT void_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
484 HRESULT typeof_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
485 HRESULT minus_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
486 HRESULT plus_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
487 HRESULT post_increment_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
488 HRESULT post_decrement_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
489 HRESULT pre_increment_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
490 HRESULT pre_decrement_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
491 HRESULT equal_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
492 HRESULT equal2_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
493 HRESULT not_equal_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
494 HRESULT not_equal2_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
495 HRESULT less_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
496 HRESULT lesseq_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
497 HRESULT greater_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
498 HRESULT greatereq_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
499 HRESULT binary_negation_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
500 HRESULT logical_negation_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
501 HRESULT left_shift_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
502 HRESULT right_shift_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
503 HRESULT right2_shift_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
504 HRESULT assign_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
505 HRESULT assign_lshift_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
506 HRESULT assign_rshift_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
507 HRESULT assign_rrshift_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
508 HRESULT assign_add_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
509 HRESULT assign_sub_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
510 HRESULT assign_mul_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
511 HRESULT assign_div_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
512 HRESULT assign_mod_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
513 HRESULT assign_and_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
514 HRESULT assign_or_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
515 HRESULT assign_xor_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);