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
;
22 typedef struct _function_declaration_t
{
23 function_expression_t
*expr
;
25 struct _function_declaration_t
*next
;
26 } function_declaration_t
;
28 typedef struct _var_list_t
{
29 const WCHAR
*identifier
;
31 struct _var_list_t
*next
;
34 typedef struct _func_stack
{
35 function_declaration_t
*func_head
;
36 function_declaration_t
*func_tail
;
40 struct _func_stack
*next
;
43 typedef struct _parser_ctx_t
{
51 source_elements_t
*source
;
59 func_stack_t
*func_stack
;
61 struct _parser_ctx_t
*next
;
64 HRESULT
script_parse(script_ctx_t
*,const WCHAR
*,const WCHAR
*,parser_ctx_t
**);
65 void parser_release(parser_ctx_t
*);
67 int parser_lex(void*,parser_ctx_t
*);
69 static inline void parser_addref(parser_ctx_t
*ctx
)
74 static inline void *parser_alloc(parser_ctx_t
*ctx
, DWORD size
)
76 return jsheap_alloc(&ctx
->heap
, size
);
79 static inline void *parser_alloc_tmp(parser_ctx_t
*ctx
, DWORD size
)
81 return jsheap_alloc(&ctx
->script
->tmp_heap
, size
);
84 typedef struct _scope_chain_t
{
87 struct _scope_chain_t
*next
;
90 HRESULT
scope_push(scope_chain_t
*,DispatchEx
*,scope_chain_t
**);
91 void scope_release(scope_chain_t
*);
93 static inline void scope_addref(scope_chain_t
*scope
)
101 parser_ctx_t
*parser
;
102 scope_chain_t
*scope_chain
;
103 DispatchEx
*var_disp
;
107 static inline void exec_addref(exec_ctx_t
*ctx
)
118 void exec_release(exec_ctx_t
*);
119 HRESULT
create_exec_ctx(script_ctx_t
*,IDispatch
*,DispatchEx
*,scope_chain_t
*,exec_ctx_t
**);
120 HRESULT
exec_source(exec_ctx_t
*,parser_ctx_t
*,source_elements_t
*,exec_type_t
,jsexcept_t
*,VARIANT
*);
122 typedef struct _statement_t statement_t
;
123 typedef struct _expression_t expression_t
;
124 typedef struct _parameter_t parameter_t
;
126 HRESULT
create_source_function(parser_ctx_t
*,parameter_t
*,source_elements_t
*,scope_chain_t
*,
127 const WCHAR
*,DWORD
,DispatchEx
**);
155 literal_t
*parse_regexp(parser_ctx_t
*);
157 typedef struct _variable_declaration_t
{
158 const WCHAR
*identifier
;
161 struct _variable_declaration_t
*next
;
162 } variable_declaration_t
;
174 typedef HRESULT (*statement_eval_t
)(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
176 struct _statement_t
{
177 statement_eval_t eval
;
183 statement_t
*stat_list
;
188 variable_declaration_t
*variable_list
;
194 } expression_statement_t
;
199 statement_t
*if_stat
;
200 statement_t
*else_stat
;
207 statement_t
*statement
;
212 variable_declaration_t
*variable_list
;
213 expression_t
*begin_expr
;
215 expression_t
*end_expr
;
216 statement_t
*statement
;
221 variable_declaration_t
*variable
;
223 expression_t
*in_expr
;
224 statement_t
*statement
;
229 const WCHAR
*identifier
;
230 } branch_statement_t
;
235 statement_t
*statement
;
240 const WCHAR
*identifier
;
241 statement_t
*statement
;
242 } labelled_statement_t
;
244 typedef struct _case_clausule_t
{
248 struct _case_clausule_t
*next
;
254 case_clausule_t
*case_list
;
255 } switch_statement_t
;
258 const WCHAR
*identifier
;
259 statement_t
*statement
;
264 statement_t
*try_statement
;
265 catch_block_t
*catch_block
;
266 statement_t
*finally_statement
;
269 HRESULT
block_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
270 HRESULT
var_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
271 HRESULT
empty_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
272 HRESULT
expression_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
273 HRESULT
if_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
274 HRESULT
while_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
275 HRESULT
for_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
276 HRESULT
forin_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
277 HRESULT
continue_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
278 HRESULT
break_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
279 HRESULT
return_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
280 HRESULT
with_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
281 HRESULT
labelled_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
282 HRESULT
switch_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
283 HRESULT
throw_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
284 HRESULT
try_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
307 typedef HRESULT (*expression_eval_t
)(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
309 struct _expression_t
{
310 expression_eval_t eval
;
313 struct _parameter_t
{
314 const WCHAR
*identifier
;
316 struct _parameter_t
*next
;
319 struct _source_elements_t
{
320 statement_t
*statement
;
321 statement_t
*statement_tail
;
322 function_declaration_t
*functions
;
323 var_list_t
*variables
;
326 struct _function_expression_t
{
328 const WCHAR
*identifier
;
329 parameter_t
*parameter_list
;
330 source_elements_t
*source_elements
;
331 const WCHAR
*src_str
;
337 expression_t
*expression1
;
338 expression_t
*expression2
;
339 } binary_expression_t
;
343 expression_t
*expression
;
344 } unary_expression_t
;
348 expression_t
*expression
;
349 expression_t
*true_expression
;
350 expression_t
*false_expression
;
351 } conditional_expression_t
;
355 expression_t
*member_expr
;
356 expression_t
*expression
;
357 } array_expression_t
;
361 expression_t
*expression
;
362 const WCHAR
*identifier
;
363 } member_expression_t
;
365 typedef struct _argument_t
{
368 struct _argument_t
*next
;
373 expression_t
*expression
;
374 argument_t
*argument_list
;
379 const WCHAR
*identifier
;
380 } identifier_expression_t
;
385 } literal_expression_t
;
387 typedef struct _array_element_t
{
391 struct _array_element_t
*next
;
396 array_element_t
*element_list
;
398 } array_literal_expression_t
;
400 typedef struct _prop_val_t
{
404 struct _prop_val_t
*next
;
409 prop_val_t
*property_list
;
410 } property_value_expression_t
;
462 HRESULT
function_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
463 HRESULT
conditional_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
464 HRESULT
array_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
465 HRESULT
member_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
466 HRESULT
new_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
467 HRESULT
call_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
468 HRESULT
this_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
469 HRESULT
identifier_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
470 HRESULT
literal_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
471 HRESULT
array_literal_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
472 HRESULT
property_value_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
474 HRESULT
comma_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
475 HRESULT
logical_or_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
476 HRESULT
logical_and_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
477 HRESULT
binary_or_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
478 HRESULT
binary_xor_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
479 HRESULT
binary_and_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
480 HRESULT
instanceof_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
481 HRESULT
in_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
482 HRESULT
add_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
483 HRESULT
sub_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
484 HRESULT
mul_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
485 HRESULT
div_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
486 HRESULT
mod_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
487 HRESULT
delete_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
488 HRESULT
void_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
489 HRESULT
typeof_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
490 HRESULT
minus_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
491 HRESULT
plus_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
492 HRESULT
post_increment_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
493 HRESULT
post_decrement_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
494 HRESULT
pre_increment_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
495 HRESULT
pre_decrement_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
496 HRESULT
equal_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
497 HRESULT
equal2_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
498 HRESULT
not_equal_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
499 HRESULT
not_equal2_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
500 HRESULT
less_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
501 HRESULT
lesseq_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
502 HRESULT
greater_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
503 HRESULT
greatereq_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
504 HRESULT
binary_negation_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
505 HRESULT
logical_negation_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
506 HRESULT
left_shift_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
507 HRESULT
right_shift_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
508 HRESULT
right2_shift_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
509 HRESULT
assign_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
510 HRESULT
assign_lshift_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
511 HRESULT
assign_rshift_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
512 HRESULT
assign_rrshift_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
513 HRESULT
assign_add_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
514 HRESULT
assign_sub_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
515 HRESULT
assign_mul_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
516 HRESULT
assign_div_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
517 HRESULT
assign_mod_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
518 HRESULT
assign_and_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
519 HRESULT
assign_or_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
520 HRESULT
assign_xor_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);