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;
22 typedef struct _statement_t statement_t;
24 typedef struct _function_declaration_t {
25 function_expression_t *expr;
27 struct _function_declaration_t *next;
28 } function_declaration_t;
30 typedef struct _var_list_t {
31 const WCHAR *identifier;
33 struct _var_list_t *next;
36 typedef struct _func_stack {
37 function_declaration_t *func_head;
38 function_declaration_t *func_tail;
42 struct _func_stack *next;
50 X(bool, 1, ARG_INT, 0) \
52 X(call, 1, ARG_UINT, ARG_UINT) \
53 X(call_member,1, ARG_UINT, ARG_UINT) \
54 X(carray, 1, ARG_UINT, 0) \
56 X(delete_ident,1,ARG_BSTR, 0) \
58 X(double, 1, ARG_SBL, 0) \
61 X(func, 1, ARG_FUNC, 0) \
64 X(ident, 1, ARG_BSTR, 0) \
65 X(identid, 1, ARG_BSTR, ARG_INT) \
67 X(instanceof, 1, 0,0) \
68 X(int, 1, ARG_INT, 0) \
69 X(jmp, 0, ARG_ADDR, 0) \
70 X(jmp_nz, 0, ARG_ADDR, 0) \
71 X(jmp_z, 0, ARG_ADDR, 0) \
75 X(member, 1, ARG_BSTR, 0) \
76 X(memberid, 1, ARG_UINT, 0) \
83 X(new, 1, ARG_INT, 0) \
86 X(obj_prop, 1, ARG_BSTR, 0) \
89 X(postinc, 1, ARG_INT, 0) \
90 X(preinc, 1, ARG_INT, 0) \
91 X(regexp, 1, ARG_STR, ARG_INT) \
94 X(str, 1, ARG_STR, 0) \
96 X(throw, 0, ARG_UINT, 0) \
97 X(throw_type, 0, ARG_UINT, ARG_STR) \
99 X(tree, 1, ARG_STAT, 0) \
101 X(typeofid, 1, 0,0) \
102 X(typeofident,1, 0,0) \
106 X(undefined, 1, 0,0) \
111 #define X(x,a,b,c) OP_##x,
124 function_expression_t *func; /* FIXME */
148 unsigned bstr_pool_size;
152 void release_bytecode(bytecode_t*);
154 typedef struct _compiler_ctx_t compiler_ctx_t;
156 void release_compiler(compiler_ctx_t*);
158 typedef struct _parser_ctx_t {
165 script_ctx_t *script;
166 source_elements_t *source;
174 func_stack_t *func_stack;
177 compiler_ctx_t *compiler;
179 struct _parser_ctx_t *next;
182 HRESULT script_parse(script_ctx_t*,const WCHAR*,const WCHAR*,parser_ctx_t**) DECLSPEC_HIDDEN;
183 void parser_release(parser_ctx_t*) DECLSPEC_HIDDEN;
185 int parser_lex(void*,parser_ctx_t*) DECLSPEC_HIDDEN;
187 static inline void parser_addref(parser_ctx_t *ctx)
192 static inline void *parser_alloc(parser_ctx_t *ctx, DWORD size)
194 return jsheap_alloc(&ctx->heap, size);
197 static inline void *parser_alloc_tmp(parser_ctx_t *ctx, DWORD size)
199 return jsheap_alloc(&ctx->script->tmp_heap, size);
202 typedef struct _scope_chain_t {
205 struct _scope_chain_t *next;
208 HRESULT scope_push(scope_chain_t*,jsdisp_t*,scope_chain_t**) DECLSPEC_HIDDEN;
209 void scope_release(scope_chain_t*) DECLSPEC_HIDDEN;
211 static inline void scope_addref(scope_chain_t *scope)
216 typedef struct _return_type_t return_type_t;
221 parser_ctx_t *parser;
222 scope_chain_t *scope_chain;
233 return_type_t *rt; /* FIXME */
236 static inline void exec_addref(exec_ctx_t *ctx)
241 void exec_release(exec_ctx_t*) DECLSPEC_HIDDEN;
242 HRESULT create_exec_ctx(script_ctx_t*,IDispatch*,jsdisp_t*,scope_chain_t*,BOOL,exec_ctx_t**) DECLSPEC_HIDDEN;
243 HRESULT exec_source(exec_ctx_t*,parser_ctx_t*,source_elements_t*,BOOL,jsexcept_t*,VARIANT*) DECLSPEC_HIDDEN;
245 typedef struct _parameter_t parameter_t;
247 HRESULT create_source_function(parser_ctx_t*,parameter_t*,source_elements_t*,scope_chain_t*,
248 const WCHAR*,DWORD,jsdisp_t**) DECLSPEC_HIDDEN;
274 literal_t *parse_regexp(parser_ctx_t*) DECLSPEC_HIDDEN;
275 literal_t *new_boolean_literal(parser_ctx_t*,VARIANT_BOOL) DECLSPEC_HIDDEN;
277 typedef struct _variable_declaration_t {
278 const WCHAR *identifier;
281 struct _variable_declaration_t *next;
282 } variable_declaration_t;
284 typedef HRESULT (*statement_eval_t)(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
305 struct _statement_t {
306 statement_type_t type;
307 statement_eval_t eval;
314 statement_t *stat_list;
319 variable_declaration_t *variable_list;
325 } expression_statement_t;
330 statement_t *if_stat;
331 statement_t *else_stat;
338 statement_t *statement;
343 variable_declaration_t *variable_list;
344 expression_t *begin_expr;
346 expression_t *end_expr;
347 statement_t *statement;
352 variable_declaration_t *variable;
354 expression_t *in_expr;
355 statement_t *statement;
360 const WCHAR *identifier;
361 } branch_statement_t;
366 statement_t *statement;
371 const WCHAR *identifier;
372 statement_t *statement;
373 } labelled_statement_t;
375 typedef struct _case_clausule_t {
379 struct _case_clausule_t *next;
385 case_clausule_t *case_list;
386 } switch_statement_t;
389 const WCHAR *identifier;
390 statement_t *statement;
395 statement_t *try_statement;
396 catch_block_t *catch_block;
397 statement_t *finally_statement;
400 HRESULT compiled_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
401 HRESULT var_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
402 HRESULT while_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
403 HRESULT for_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
404 HRESULT forin_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
405 HRESULT continue_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
406 HRESULT break_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
407 HRESULT return_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
408 HRESULT with_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
409 HRESULT labelled_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
410 HRESULT switch_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
411 HRESULT throw_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
412 HRESULT try_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
491 struct _expression_t {
492 expression_type_t type;
496 struct _parameter_t {
497 const WCHAR *identifier;
499 struct _parameter_t *next;
502 struct _source_elements_t {
503 statement_t *statement;
504 statement_t *statement_tail;
505 function_declaration_t *functions;
506 var_list_t *variables;
509 struct _function_expression_t {
511 const WCHAR *identifier;
512 parameter_t *parameter_list;
513 source_elements_t *source_elements;
514 const WCHAR *src_str;
520 expression_t *expression1;
521 expression_t *expression2;
522 } binary_expression_t;
526 expression_t *expression;
527 } unary_expression_t;
531 expression_t *expression;
532 expression_t *true_expression;
533 expression_t *false_expression;
534 } conditional_expression_t;
538 expression_t *expression;
539 const WCHAR *identifier;
540 } member_expression_t;
542 typedef struct _argument_t {
545 struct _argument_t *next;
550 expression_t *expression;
551 argument_t *argument_list;
556 const WCHAR *identifier;
557 } identifier_expression_t;
562 } literal_expression_t;
564 typedef struct _array_element_t {
568 struct _array_element_t *next;
573 array_element_t *element_list;
575 } array_literal_expression_t;
577 typedef struct _prop_val_t {
581 struct _prop_val_t *next;
586 prop_val_t *property_list;
587 } property_value_expression_t;
589 HRESULT compile_subscript(parser_ctx_t*,expression_t*,BOOL,unsigned*) DECLSPEC_HIDDEN;
590 HRESULT compile_subscript_stat(parser_ctx_t*,statement_t*,BOOL,unsigned*) DECLSPEC_HIDDEN;