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(tree, 1, ARG_EXPR) \
52 #define X(x,a,b) OP_##x,
76 void release_bytecode(bytecode_t
*);
78 typedef struct _compiler_ctx_t compiler_ctx_t
;
80 void release_compiler(compiler_ctx_t
*);
82 typedef struct _parser_ctx_t
{
90 source_elements_t
*source
;
98 func_stack_t
*func_stack
;
101 compiler_ctx_t
*compiler
;
103 struct _parser_ctx_t
*next
;
106 HRESULT
script_parse(script_ctx_t
*,const WCHAR
*,const WCHAR
*,parser_ctx_t
**) DECLSPEC_HIDDEN
;
107 void parser_release(parser_ctx_t
*) DECLSPEC_HIDDEN
;
109 int parser_lex(void*,parser_ctx_t
*) DECLSPEC_HIDDEN
;
111 static inline void parser_addref(parser_ctx_t
*ctx
)
116 static inline void *parser_alloc(parser_ctx_t
*ctx
, DWORD size
)
118 return jsheap_alloc(&ctx
->heap
, size
);
121 static inline void *parser_alloc_tmp(parser_ctx_t
*ctx
, DWORD size
)
123 return jsheap_alloc(&ctx
->script
->tmp_heap
, size
);
126 typedef struct _scope_chain_t
{
129 struct _scope_chain_t
*next
;
132 HRESULT
scope_push(scope_chain_t
*,jsdisp_t
*,scope_chain_t
**) DECLSPEC_HIDDEN
;
133 void scope_release(scope_chain_t
*) DECLSPEC_HIDDEN
;
135 static inline void scope_addref(scope_chain_t
*scope
)
143 parser_ctx_t
*parser
;
144 scope_chain_t
*scope_chain
;
157 static inline void exec_addref(exec_ctx_t
*ctx
)
162 void exec_release(exec_ctx_t
*) DECLSPEC_HIDDEN
;
163 HRESULT
create_exec_ctx(script_ctx_t
*,IDispatch
*,jsdisp_t
*,scope_chain_t
*,BOOL
,exec_ctx_t
**) DECLSPEC_HIDDEN
;
164 HRESULT
exec_source(exec_ctx_t
*,parser_ctx_t
*,source_elements_t
*,BOOL
,jsexcept_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
166 typedef struct _statement_t statement_t
;
167 typedef struct _parameter_t parameter_t
;
169 HRESULT
create_source_function(parser_ctx_t
*,parameter_t
*,source_elements_t
*,scope_chain_t
*,
170 const WCHAR
*,DWORD
,jsdisp_t
**) DECLSPEC_HIDDEN
;
197 literal_t
*parse_regexp(parser_ctx_t
*) DECLSPEC_HIDDEN
;
198 literal_t
*new_boolean_literal(parser_ctx_t
*,VARIANT_BOOL
) DECLSPEC_HIDDEN
;
200 typedef struct _variable_declaration_t
{
201 const WCHAR
*identifier
;
204 struct _variable_declaration_t
*next
;
205 } variable_declaration_t
;
207 typedef struct _return_type_t return_type_t
;
209 typedef HRESULT (*statement_eval_t
)(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
211 struct _statement_t
{
212 statement_eval_t eval
;
218 statement_t
*stat_list
;
223 variable_declaration_t
*variable_list
;
229 } expression_statement_t
;
234 statement_t
*if_stat
;
235 statement_t
*else_stat
;
242 statement_t
*statement
;
247 variable_declaration_t
*variable_list
;
248 expression_t
*begin_expr
;
250 expression_t
*end_expr
;
251 statement_t
*statement
;
256 variable_declaration_t
*variable
;
258 expression_t
*in_expr
;
259 statement_t
*statement
;
264 const WCHAR
*identifier
;
265 } branch_statement_t
;
270 statement_t
*statement
;
275 const WCHAR
*identifier
;
276 statement_t
*statement
;
277 } labelled_statement_t
;
279 typedef struct _case_clausule_t
{
283 struct _case_clausule_t
*next
;
289 case_clausule_t
*case_list
;
290 } switch_statement_t
;
293 const WCHAR
*identifier
;
294 statement_t
*statement
;
299 statement_t
*try_statement
;
300 catch_block_t
*catch_block
;
301 statement_t
*finally_statement
;
304 HRESULT
block_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
305 HRESULT
var_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
306 HRESULT
empty_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
307 HRESULT
expression_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
308 HRESULT
if_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
309 HRESULT
while_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
310 HRESULT
for_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
311 HRESULT
forin_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
312 HRESULT
continue_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
313 HRESULT
break_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
314 HRESULT
return_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
315 HRESULT
with_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
316 HRESULT
labelled_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
317 HRESULT
switch_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
318 HRESULT
throw_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
319 HRESULT
try_statement_eval(script_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*) DECLSPEC_HIDDEN
;
403 typedef HRESULT (*expression_eval_t
)(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
405 struct _expression_t
{
406 expression_type_t type
;
407 expression_eval_t eval
;
411 struct _parameter_t
{
412 const WCHAR
*identifier
;
414 struct _parameter_t
*next
;
417 struct _source_elements_t
{
418 statement_t
*statement
;
419 statement_t
*statement_tail
;
420 function_declaration_t
*functions
;
421 var_list_t
*variables
;
424 struct _function_expression_t
{
426 const WCHAR
*identifier
;
427 parameter_t
*parameter_list
;
428 source_elements_t
*source_elements
;
429 const WCHAR
*src_str
;
435 expression_t
*expression1
;
436 expression_t
*expression2
;
437 } binary_expression_t
;
441 expression_t
*expression
;
442 } unary_expression_t
;
446 expression_t
*expression
;
447 expression_t
*true_expression
;
448 expression_t
*false_expression
;
449 } conditional_expression_t
;
453 expression_t
*member_expr
;
454 expression_t
*expression
;
455 } array_expression_t
;
459 expression_t
*expression
;
460 const WCHAR
*identifier
;
461 } member_expression_t
;
463 typedef struct _argument_t
{
466 struct _argument_t
*next
;
471 expression_t
*expression
;
472 argument_t
*argument_list
;
477 const WCHAR
*identifier
;
478 } identifier_expression_t
;
483 } literal_expression_t
;
485 typedef struct _array_element_t
{
489 struct _array_element_t
*next
;
494 array_element_t
*element_list
;
496 } array_literal_expression_t
;
498 typedef struct _prop_val_t
{
502 struct _prop_val_t
*next
;
507 prop_val_t
*property_list
;
508 } property_value_expression_t
;
510 HRESULT
function_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
511 HRESULT
conditional_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
512 HRESULT
array_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
513 HRESULT
member_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
514 HRESULT
new_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
515 HRESULT
call_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
516 HRESULT
this_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
517 HRESULT
identifier_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
518 HRESULT
literal_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
519 HRESULT
array_literal_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
520 HRESULT
property_value_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
522 HRESULT
comma_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
523 HRESULT
logical_or_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
524 HRESULT
logical_and_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
525 HRESULT
binary_or_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
526 HRESULT
binary_xor_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
527 HRESULT
binary_and_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
528 HRESULT
instanceof_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
529 HRESULT
in_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
530 HRESULT
add_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
531 HRESULT
sub_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
532 HRESULT
mul_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
533 HRESULT
div_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
534 HRESULT
mod_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
535 HRESULT
delete_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
536 HRESULT
void_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
537 HRESULT
typeof_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
538 HRESULT
minus_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
539 HRESULT
plus_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
540 HRESULT
post_increment_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
541 HRESULT
post_decrement_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
542 HRESULT
pre_increment_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
543 HRESULT
pre_decrement_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
544 HRESULT
equal_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
545 HRESULT
not_equal_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
546 HRESULT
less_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
547 HRESULT
lesseq_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
548 HRESULT
greater_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
549 HRESULT
greatereq_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
550 HRESULT
binary_negation_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
551 HRESULT
left_shift_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
552 HRESULT
right_shift_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
553 HRESULT
right2_shift_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
554 HRESULT
assign_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
555 HRESULT
assign_lshift_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
556 HRESULT
assign_rshift_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
557 HRESULT
assign_rrshift_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
558 HRESULT
assign_add_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
559 HRESULT
assign_sub_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
560 HRESULT
assign_mul_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
561 HRESULT
assign_div_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
562 HRESULT
assign_mod_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
563 HRESULT
assign_and_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
564 HRESULT
assign_or_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
565 HRESULT
assign_xor_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
567 HRESULT
compiled_expression_eval(script_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*) DECLSPEC_HIDDEN
;
569 HRESULT
compile_subscript(parser_ctx_t
*,expression_t
*,unsigned*) DECLSPEC_HIDDEN
;