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
;
47 X(bool, 1, ARG_INT, 0) \
51 X(double, 1, ARG_SBL, 0) \
56 X(ident, 1, ARG_BSTR, 0) \
57 X(identid, 1, ARG_BSTR, 0) \
59 X(int, 1, ARG_INT, 0) \
60 X(jmp, 0, ARG_ADDR, 0) \
61 X(jmp_nz, 0, ARG_ADDR, 0) \
62 X(jmp_z, 0, ARG_ADDR, 0) \
65 X(member, 1, ARG_BSTR, 0) \
73 X(new, 1, ARG_INT, 0) \
77 X(regexp, 1, ARG_STR, ARG_INT) \
78 X(str, 1, ARG_STR, 0) \
80 X(throw, 0, ARG_UINT, 0) \
82 X(tree, 1, ARG_EXPR, 0) \
90 #define X(x,a,b,c) OP_##x,
125 unsigned bstr_pool_size
;
129 void release_bytecode(bytecode_t
*);
131 typedef struct _compiler_ctx_t compiler_ctx_t
;
133 void release_compiler(compiler_ctx_t
*);
135 typedef struct _parser_ctx_t
{
142 script_ctx_t
*script
;
143 source_elements_t
*source
;
151 func_stack_t
*func_stack
;
154 compiler_ctx_t
*compiler
;
156 struct _parser_ctx_t
*next
;
159 HRESULT
script_parse(script_ctx_t
*,const WCHAR
*,const WCHAR
*,parser_ctx_t
**) DECLSPEC_HIDDEN
;
160 void parser_release(parser_ctx_t
*) DECLSPEC_HIDDEN
;
162 int parser_lex(void*,parser_ctx_t
*) DECLSPEC_HIDDEN
;
164 static inline void parser_addref(parser_ctx_t
*ctx
)
169 static inline void *parser_alloc(parser_ctx_t
*ctx
, DWORD size
)
171 return jsheap_alloc(&ctx
->heap
, size
);
174 static inline void *parser_alloc_tmp(parser_ctx_t
*ctx
, DWORD size
)
176 return jsheap_alloc(&ctx
->script
->tmp_heap
, size
);
179 typedef struct _scope_chain_t
{
182 struct _scope_chain_t
*next
;
185 HRESULT
scope_push(scope_chain_t
*,jsdisp_t
*,scope_chain_t
**) DECLSPEC_HIDDEN
;
186 void scope_release(scope_chain_t
*) DECLSPEC_HIDDEN
;
188 static inline void scope_addref(scope_chain_t
*scope
)
196 parser_ctx_t
*parser
;
197 scope_chain_t
*scope_chain
;
210 static inline void exec_addref(exec_ctx_t
*ctx
)
215 void exec_release(exec_ctx_t
*) DECLSPEC_HIDDEN
;
216 HRESULT
create_exec_ctx(script_ctx_t
*,IDispatch
*,jsdisp_t
*,scope_chain_t
*,BOOL
,exec_ctx_t
**) DECLSPEC_HIDDEN
;
217 HRESULT
exec_source(exec_ctx_t
*,parser_ctx_t
*,source_elements_t
*,BOOL
,jsexcept_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
219 typedef struct _statement_t statement_t
;
220 typedef struct _parameter_t parameter_t
;
222 HRESULT
create_source_function(parser_ctx_t
*,parameter_t
*,source_elements_t
*,scope_chain_t
*,
223 const WCHAR
*,DWORD
,jsdisp_t
**) DECLSPEC_HIDDEN
;
249 literal_t
*parse_regexp(parser_ctx_t
*) DECLSPEC_HIDDEN
;
250 literal_t
*new_boolean_literal(parser_ctx_t
*,VARIANT_BOOL
) DECLSPEC_HIDDEN
;
252 typedef struct _variable_declaration_t
{
253 const WCHAR
*identifier
;
256 struct _variable_declaration_t
*next
;
257 } variable_declaration_t
;
259 typedef struct _return_type_t return_type_t
;
261 typedef HRESULT (*statement_eval_t
)(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
263 struct _statement_t
{
264 statement_eval_t eval
;
270 statement_t
*stat_list
;
275 variable_declaration_t
*variable_list
;
281 } expression_statement_t
;
286 statement_t
*if_stat
;
287 statement_t
*else_stat
;
294 statement_t
*statement
;
299 variable_declaration_t
*variable_list
;
300 expression_t
*begin_expr
;
302 expression_t
*end_expr
;
303 statement_t
*statement
;
308 variable_declaration_t
*variable
;
310 expression_t
*in_expr
;
311 statement_t
*statement
;
316 const WCHAR
*identifier
;
317 } branch_statement_t
;
322 statement_t
*statement
;
327 const WCHAR
*identifier
;
328 statement_t
*statement
;
329 } labelled_statement_t
;
331 typedef struct _case_clausule_t
{
335 struct _case_clausule_t
*next
;
341 case_clausule_t
*case_list
;
342 } switch_statement_t
;
345 const WCHAR
*identifier
;
346 statement_t
*statement
;
351 statement_t
*try_statement
;
352 catch_block_t
*catch_block
;
353 statement_t
*finally_statement
;
356 HRESULT
block_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
357 HRESULT
var_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
358 HRESULT
empty_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
359 HRESULT
expression_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
360 HRESULT
if_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
361 HRESULT
while_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
362 HRESULT
for_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
363 HRESULT
forin_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
364 HRESULT
continue_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
365 HRESULT
break_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
366 HRESULT
return_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
367 HRESULT
with_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
368 HRESULT
labelled_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
369 HRESULT
switch_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
370 HRESULT
throw_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
371 HRESULT
try_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
450 typedef HRESULT (*expression_eval_t
)(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
452 struct _expression_t
{
453 expression_type_t type
;
454 expression_eval_t eval
;
458 struct _parameter_t
{
459 const WCHAR
*identifier
;
461 struct _parameter_t
*next
;
464 struct _source_elements_t
{
465 statement_t
*statement
;
466 statement_t
*statement_tail
;
467 function_declaration_t
*functions
;
468 var_list_t
*variables
;
471 struct _function_expression_t
{
473 const WCHAR
*identifier
;
474 parameter_t
*parameter_list
;
475 source_elements_t
*source_elements
;
476 const WCHAR
*src_str
;
482 expression_t
*expression1
;
483 expression_t
*expression2
;
484 } binary_expression_t
;
488 expression_t
*expression
;
489 } unary_expression_t
;
493 expression_t
*expression
;
494 expression_t
*true_expression
;
495 expression_t
*false_expression
;
496 } conditional_expression_t
;
500 expression_t
*member_expr
;
501 expression_t
*expression
;
502 } array_expression_t
;
506 expression_t
*expression
;
507 const WCHAR
*identifier
;
508 } member_expression_t
;
510 typedef struct _argument_t
{
513 struct _argument_t
*next
;
518 expression_t
*expression
;
519 argument_t
*argument_list
;
524 const WCHAR
*identifier
;
525 } identifier_expression_t
;
530 } literal_expression_t
;
532 typedef struct _array_element_t
{
536 struct _array_element_t
*next
;
541 array_element_t
*element_list
;
543 } array_literal_expression_t
;
545 typedef struct _prop_val_t
{
549 struct _prop_val_t
*next
;
554 prop_val_t
*property_list
;
555 } property_value_expression_t
;
557 HRESULT
function_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
558 HRESULT
array_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
559 HRESULT
member_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
560 HRESULT
call_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
array_literal_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
563 HRESULT
property_value_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
565 HRESULT
binary_and_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
566 HRESULT
instanceof_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
567 HRESULT
delete_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
568 HRESULT
typeof_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
569 HRESULT
post_increment_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
570 HRESULT
post_decrement_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
571 HRESULT
pre_increment_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
572 HRESULT
pre_decrement_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
573 HRESULT
left_shift_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
574 HRESULT
right_shift_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
575 HRESULT
right2_shift_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
576 HRESULT
assign_lshift_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
577 HRESULT
assign_rshift_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
578 HRESULT
assign_rrshift_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
579 HRESULT
assign_and_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
580 HRESULT
assign_xor_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
582 HRESULT
compiled_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
584 HRESULT
compile_subscript(parser_ctx_t
*,expression_t
*,unsigned*) DECLSPEC_HIDDEN
;