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;
21 typedef struct _expression_t expression_t;
23 typedef struct _function_declaration_t {
24 function_expression_t *expr;
26 struct _function_declaration_t *next;
27 } function_declaration_t;
29 typedef struct _var_list_t {
30 const WCHAR *identifier;
32 struct _var_list_t *next;
35 typedef struct _func_stack {
36 function_declaration_t *func_head;
37 function_declaration_t *func_tail;
41 struct _func_stack *next;
48 X(bool, 1, ARG_INT, 0) \
50 X(call, 1, ARG_UINT, ARG_UINT) \
51 X(call_member,1, ARG_UINT, ARG_UINT) \
52 X(carray, 1, ARG_UINT, 0) \
55 X(double, 1, ARG_SBL, 0) \
60 X(ident, 1, ARG_BSTR, 0) \
61 X(identid, 1, ARG_BSTR, ARG_INT) \
63 X(int, 1, ARG_INT, 0) \
64 X(jmp, 0, ARG_ADDR, 0) \
65 X(jmp_nz, 0, ARG_ADDR, 0) \
66 X(jmp_z, 0, ARG_ADDR, 0) \
69 X(member, 1, ARG_BSTR, 0) \
70 X(memberid, 1, ARG_UINT, 0) \
77 X(new, 1, ARG_INT, 0) \
81 X(postinc, 1, ARG_INT, 0) \
82 X(preinc, 1, ARG_INT, 0) \
83 X(regexp, 1, ARG_STR, ARG_INT) \
84 X(str, 1, ARG_STR, 0) \
86 X(throw, 0, ARG_UINT, 0) \
88 X(tree, 1, ARG_EXPR, 0) \
92 X(undefined, 1, 0,0) \
97 #define X(x,a,b,c) OP_##x,
132 unsigned bstr_pool_size;
136 void release_bytecode(bytecode_t*);
138 typedef struct _compiler_ctx_t compiler_ctx_t;
140 void release_compiler(compiler_ctx_t*);
142 typedef struct _parser_ctx_t {
149 script_ctx_t *script;
150 source_elements_t *source;
158 func_stack_t *func_stack;
161 compiler_ctx_t *compiler;
163 struct _parser_ctx_t *next;
166 HRESULT script_parse(script_ctx_t*,const WCHAR*,const WCHAR*,parser_ctx_t**) DECLSPEC_HIDDEN;
167 void parser_release(parser_ctx_t*) DECLSPEC_HIDDEN;
169 int parser_lex(void*,parser_ctx_t*) DECLSPEC_HIDDEN;
171 static inline void parser_addref(parser_ctx_t *ctx)
176 static inline void *parser_alloc(parser_ctx_t *ctx, DWORD size)
178 return jsheap_alloc(&ctx->heap, size);
181 static inline void *parser_alloc_tmp(parser_ctx_t *ctx, DWORD size)
183 return jsheap_alloc(&ctx->script->tmp_heap, size);
186 typedef struct _scope_chain_t {
189 struct _scope_chain_t *next;
192 HRESULT scope_push(scope_chain_t*,jsdisp_t*,scope_chain_t**) DECLSPEC_HIDDEN;
193 void scope_release(scope_chain_t*) DECLSPEC_HIDDEN;
195 static inline void scope_addref(scope_chain_t *scope)
203 parser_ctx_t *parser;
204 scope_chain_t *scope_chain;
217 static inline void exec_addref(exec_ctx_t *ctx)
222 void exec_release(exec_ctx_t*) DECLSPEC_HIDDEN;
223 HRESULT create_exec_ctx(script_ctx_t*,IDispatch*,jsdisp_t*,scope_chain_t*,BOOL,exec_ctx_t**) DECLSPEC_HIDDEN;
224 HRESULT exec_source(exec_ctx_t*,parser_ctx_t*,source_elements_t*,BOOL,jsexcept_t*,VARIANT*) DECLSPEC_HIDDEN;
226 typedef struct _statement_t statement_t;
227 typedef struct _parameter_t parameter_t;
229 HRESULT create_source_function(parser_ctx_t*,parameter_t*,source_elements_t*,scope_chain_t*,
230 const WCHAR*,DWORD,jsdisp_t**) DECLSPEC_HIDDEN;
256 literal_t *parse_regexp(parser_ctx_t*) DECLSPEC_HIDDEN;
257 literal_t *new_boolean_literal(parser_ctx_t*,VARIANT_BOOL) DECLSPEC_HIDDEN;
259 typedef struct _variable_declaration_t {
260 const WCHAR *identifier;
263 struct _variable_declaration_t *next;
264 } variable_declaration_t;
266 typedef struct _return_type_t return_type_t;
268 typedef HRESULT (*statement_eval_t)(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
270 struct _statement_t {
271 statement_eval_t eval;
277 statement_t *stat_list;
282 variable_declaration_t *variable_list;
288 } expression_statement_t;
293 statement_t *if_stat;
294 statement_t *else_stat;
301 statement_t *statement;
306 variable_declaration_t *variable_list;
307 expression_t *begin_expr;
309 expression_t *end_expr;
310 statement_t *statement;
315 variable_declaration_t *variable;
317 expression_t *in_expr;
318 statement_t *statement;
323 const WCHAR *identifier;
324 } branch_statement_t;
329 statement_t *statement;
334 const WCHAR *identifier;
335 statement_t *statement;
336 } labelled_statement_t;
338 typedef struct _case_clausule_t {
342 struct _case_clausule_t *next;
348 case_clausule_t *case_list;
349 } switch_statement_t;
352 const WCHAR *identifier;
353 statement_t *statement;
358 statement_t *try_statement;
359 catch_block_t *catch_block;
360 statement_t *finally_statement;
363 HRESULT block_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
364 HRESULT var_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
365 HRESULT empty_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
366 HRESULT expression_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
367 HRESULT if_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
368 HRESULT while_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
369 HRESULT for_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
370 HRESULT forin_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
371 HRESULT continue_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
372 HRESULT break_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
373 HRESULT return_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
374 HRESULT with_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
375 HRESULT labelled_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
376 HRESULT switch_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
377 HRESULT throw_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
378 HRESULT try_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
457 typedef HRESULT (*expression_eval_t)(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
459 struct _expression_t {
460 expression_type_t type;
461 expression_eval_t eval;
465 struct _parameter_t {
466 const WCHAR *identifier;
468 struct _parameter_t *next;
471 struct _source_elements_t {
472 statement_t *statement;
473 statement_t *statement_tail;
474 function_declaration_t *functions;
475 var_list_t *variables;
478 struct _function_expression_t {
480 const WCHAR *identifier;
481 parameter_t *parameter_list;
482 source_elements_t *source_elements;
483 const WCHAR *src_str;
489 expression_t *expression1;
490 expression_t *expression2;
491 } binary_expression_t;
495 expression_t *expression;
496 } unary_expression_t;
500 expression_t *expression;
501 expression_t *true_expression;
502 expression_t *false_expression;
503 } conditional_expression_t;
507 expression_t *expression;
508 const WCHAR *identifier;
509 } member_expression_t;
511 typedef struct _argument_t {
514 struct _argument_t *next;
519 expression_t *expression;
520 argument_t *argument_list;
525 const WCHAR *identifier;
526 } identifier_expression_t;
531 } literal_expression_t;
533 typedef struct _array_element_t {
537 struct _array_element_t *next;
542 array_element_t *element_list;
544 } array_literal_expression_t;
546 typedef struct _prop_val_t {
550 struct _prop_val_t *next;
555 prop_val_t *property_list;
556 } property_value_expression_t;
558 HRESULT function_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
559 HRESULT array_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
560 HRESULT member_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
561 HRESULT identifier_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
562 HRESULT property_value_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
564 HRESULT binary_and_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
565 HRESULT instanceof_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
566 HRESULT delete_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
567 HRESULT typeof_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
568 HRESULT left_shift_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
569 HRESULT right_shift_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
570 HRESULT right2_shift_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
571 HRESULT assign_lshift_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
572 HRESULT assign_rshift_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
573 HRESULT assign_rrshift_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
574 HRESULT assign_and_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
576 HRESULT compiled_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
578 HRESULT compile_subscript(parser_ctx_t*,expression_t*,BOOL,unsigned*) DECLSPEC_HIDDEN;