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;
49 X(bool, 1, ARG_INT, 0) \
51 X(call, 1, ARG_UINT, ARG_UINT) \
52 X(call_member,1, ARG_UINT, ARG_UINT) \
53 X(carray, 1, ARG_UINT, 0) \
55 X(delete_ident,1,ARG_BSTR, 0) \
57 X(double, 1, ARG_SBL, 0) \
62 X(ident, 1, ARG_BSTR, 0) \
63 X(identid, 1, ARG_BSTR, ARG_INT) \
65 X(instanceof, 1, 0,0) \
66 X(int, 1, ARG_INT, 0) \
67 X(jmp, 0, ARG_ADDR, 0) \
68 X(jmp_nz, 0, ARG_ADDR, 0) \
69 X(jmp_z, 0, ARG_ADDR, 0) \
73 X(member, 1, ARG_BSTR, 0) \
74 X(memberid, 1, ARG_UINT, 0) \
81 X(new, 1, ARG_INT, 0) \
85 X(postinc, 1, ARG_INT, 0) \
86 X(preinc, 1, ARG_INT, 0) \
87 X(regexp, 1, ARG_STR, ARG_INT) \
90 X(str, 1, ARG_STR, 0) \
92 X(throw, 0, ARG_UINT, 0) \
93 X(throw_type, 0, ARG_UINT, ARG_STR) \
95 X(tree, 1, ARG_EXPR, 0) \
98 X(typeofident,1, 0,0) \
102 X(undefined, 1, 0,0) \
107 #define X(x,a,b,c) OP_##x,
142 unsigned bstr_pool_size;
146 void release_bytecode(bytecode_t*);
148 typedef struct _compiler_ctx_t compiler_ctx_t;
150 void release_compiler(compiler_ctx_t*);
152 typedef struct _parser_ctx_t {
159 script_ctx_t *script;
160 source_elements_t *source;
168 func_stack_t *func_stack;
171 compiler_ctx_t *compiler;
173 struct _parser_ctx_t *next;
176 HRESULT script_parse(script_ctx_t*,const WCHAR*,const WCHAR*,parser_ctx_t**) DECLSPEC_HIDDEN;
177 void parser_release(parser_ctx_t*) DECLSPEC_HIDDEN;
179 int parser_lex(void*,parser_ctx_t*) DECLSPEC_HIDDEN;
181 static inline void parser_addref(parser_ctx_t *ctx)
186 static inline void *parser_alloc(parser_ctx_t *ctx, DWORD size)
188 return jsheap_alloc(&ctx->heap, size);
191 static inline void *parser_alloc_tmp(parser_ctx_t *ctx, DWORD size)
193 return jsheap_alloc(&ctx->script->tmp_heap, size);
196 typedef struct _scope_chain_t {
199 struct _scope_chain_t *next;
202 HRESULT scope_push(scope_chain_t*,jsdisp_t*,scope_chain_t**) DECLSPEC_HIDDEN;
203 void scope_release(scope_chain_t*) DECLSPEC_HIDDEN;
205 static inline void scope_addref(scope_chain_t *scope)
213 parser_ctx_t *parser;
214 scope_chain_t *scope_chain;
227 static inline void exec_addref(exec_ctx_t *ctx)
232 void exec_release(exec_ctx_t*) DECLSPEC_HIDDEN;
233 HRESULT create_exec_ctx(script_ctx_t*,IDispatch*,jsdisp_t*,scope_chain_t*,BOOL,exec_ctx_t**) DECLSPEC_HIDDEN;
234 HRESULT exec_source(exec_ctx_t*,parser_ctx_t*,source_elements_t*,BOOL,jsexcept_t*,VARIANT*) DECLSPEC_HIDDEN;
236 typedef struct _statement_t statement_t;
237 typedef struct _parameter_t parameter_t;
239 HRESULT create_source_function(parser_ctx_t*,parameter_t*,source_elements_t*,scope_chain_t*,
240 const WCHAR*,DWORD,jsdisp_t**) DECLSPEC_HIDDEN;
266 literal_t *parse_regexp(parser_ctx_t*) DECLSPEC_HIDDEN;
267 literal_t *new_boolean_literal(parser_ctx_t*,VARIANT_BOOL) DECLSPEC_HIDDEN;
269 typedef struct _variable_declaration_t {
270 const WCHAR *identifier;
273 struct _variable_declaration_t *next;
274 } variable_declaration_t;
276 typedef struct _return_type_t return_type_t;
278 typedef HRESULT (*statement_eval_t)(script_ctx_t*,statement_t*,return_type_t*,VARIANT*);
280 struct _statement_t {
281 statement_eval_t eval;
287 statement_t *stat_list;
292 variable_declaration_t *variable_list;
298 } expression_statement_t;
303 statement_t *if_stat;
304 statement_t *else_stat;
311 statement_t *statement;
316 variable_declaration_t *variable_list;
317 expression_t *begin_expr;
319 expression_t *end_expr;
320 statement_t *statement;
325 variable_declaration_t *variable;
327 expression_t *in_expr;
328 statement_t *statement;
333 const WCHAR *identifier;
334 } branch_statement_t;
339 statement_t *statement;
344 const WCHAR *identifier;
345 statement_t *statement;
346 } labelled_statement_t;
348 typedef struct _case_clausule_t {
352 struct _case_clausule_t *next;
358 case_clausule_t *case_list;
359 } switch_statement_t;
362 const WCHAR *identifier;
363 statement_t *statement;
368 statement_t *try_statement;
369 catch_block_t *catch_block;
370 statement_t *finally_statement;
373 HRESULT block_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
374 HRESULT var_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
375 HRESULT empty_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
376 HRESULT expression_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
377 HRESULT if_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
378 HRESULT while_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
379 HRESULT for_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
380 HRESULT forin_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
381 HRESULT continue_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
382 HRESULT break_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
383 HRESULT return_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
384 HRESULT with_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
385 HRESULT labelled_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
386 HRESULT switch_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
387 HRESULT throw_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
388 HRESULT try_statement_eval(script_ctx_t*,statement_t*,return_type_t*,VARIANT*) DECLSPEC_HIDDEN;
467 typedef HRESULT (*expression_eval_t)(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
469 struct _expression_t {
470 expression_type_t type;
471 expression_eval_t eval;
475 struct _parameter_t {
476 const WCHAR *identifier;
478 struct _parameter_t *next;
481 struct _source_elements_t {
482 statement_t *statement;
483 statement_t *statement_tail;
484 function_declaration_t *functions;
485 var_list_t *variables;
488 struct _function_expression_t {
490 const WCHAR *identifier;
491 parameter_t *parameter_list;
492 source_elements_t *source_elements;
493 const WCHAR *src_str;
499 expression_t *expression1;
500 expression_t *expression2;
501 } binary_expression_t;
505 expression_t *expression;
506 } unary_expression_t;
510 expression_t *expression;
511 expression_t *true_expression;
512 expression_t *false_expression;
513 } conditional_expression_t;
517 expression_t *expression;
518 const WCHAR *identifier;
519 } member_expression_t;
521 typedef struct _argument_t {
524 struct _argument_t *next;
529 expression_t *expression;
530 argument_t *argument_list;
535 const WCHAR *identifier;
536 } identifier_expression_t;
541 } literal_expression_t;
543 typedef struct _array_element_t {
547 struct _array_element_t *next;
552 array_element_t *element_list;
554 } array_literal_expression_t;
556 typedef struct _prop_val_t {
560 struct _prop_val_t *next;
565 prop_val_t *property_list;
566 } property_value_expression_t;
568 HRESULT function_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
569 HRESULT array_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
570 HRESULT member_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
571 HRESULT identifier_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
572 HRESULT property_value_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
574 HRESULT compiled_expression_eval(script_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*) DECLSPEC_HIDDEN;
576 HRESULT compile_subscript(parser_ctx_t*,expression_t*,BOOL,unsigned*) DECLSPEC_HIDDEN;