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 _obj_literal_t
{
24 struct _obj_literal_t
*next
;
27 typedef struct _function_declaration_t
{
28 function_expression_t
*expr
;
30 struct _function_declaration_t
*next
;
31 } function_declaration_t
;
33 typedef struct _var_list_t
{
34 const WCHAR
*identifier
;
36 struct _var_list_t
*next
;
39 typedef struct _func_stack
{
40 function_declaration_t
*func_head
;
41 function_declaration_t
*func_tail
;
45 struct _func_stack
*next
;
48 typedef struct _parser_ctx_t
{
56 source_elements_t
*source
;
64 obj_literal_t
*obj_literals
;
65 func_stack_t
*func_stack
;
67 struct _parser_ctx_t
*next
;
70 HRESULT
script_parse(script_ctx_t
*,const WCHAR
*,const WCHAR
*,parser_ctx_t
**);
71 void parser_release(parser_ctx_t
*);
73 int parser_lex(void*,parser_ctx_t
*);
75 static inline void parser_addref(parser_ctx_t
*ctx
)
80 static inline void *parser_alloc(parser_ctx_t
*ctx
, DWORD size
)
82 return jsheap_alloc(&ctx
->heap
, size
);
85 static inline void *parser_alloc_tmp(parser_ctx_t
*ctx
, DWORD size
)
87 return jsheap_alloc(&ctx
->script
->tmp_heap
, size
);
90 typedef struct _scope_chain_t
{
93 struct _scope_chain_t
*next
;
96 HRESULT
scope_push(scope_chain_t
*,DispatchEx
*,scope_chain_t
**);
97 void scope_release(scope_chain_t
*);
99 static inline void scope_addref(scope_chain_t
*scope
)
107 parser_ctx_t
*parser
;
108 scope_chain_t
*scope_chain
;
109 DispatchEx
*var_disp
;
113 static inline void exec_addref(exec_ctx_t
*ctx
)
118 void exec_release(exec_ctx_t
*);
119 HRESULT
create_exec_ctx(IDispatch
*,DispatchEx
*,scope_chain_t
*,exec_ctx_t
**);
120 HRESULT
exec_source(exec_ctx_t
*,parser_ctx_t
*,source_elements_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
**);
140 literal_t
*parse_regexp(parser_ctx_t
*);
142 typedef struct _variable_declaration_t
{
143 const WCHAR
*identifier
;
146 struct _variable_declaration_t
*next
;
147 } variable_declaration_t
;
159 typedef HRESULT (*statement_eval_t
)(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
161 struct _statement_t
{
162 statement_eval_t eval
;
168 statement_t
*stat_list
;
173 variable_declaration_t
*variable_list
;
179 } expression_statement_t
;
184 statement_t
*if_stat
;
185 statement_t
*else_stat
;
192 statement_t
*statement
;
197 variable_declaration_t
*variable_list
;
198 expression_t
*begin_expr
;
200 expression_t
*end_expr
;
201 statement_t
*statement
;
206 variable_declaration_t
*variable
;
208 expression_t
*in_expr
;
209 statement_t
*statement
;
214 const WCHAR
*identifier
;
215 } branch_statement_t
;
220 statement_t
*statement
;
225 const WCHAR
*identifier
;
226 statement_t
*statement
;
227 } labelled_statement_t
;
229 typedef struct _case_clausule_t
{
233 struct _case_clausule_t
*next
;
239 case_clausule_t
*case_list
;
240 } switch_statement_t
;
243 const WCHAR
*identifier
;
244 statement_t
*statement
;
249 statement_t
*try_statement
;
250 catch_block_t
*catch_block
;
251 statement_t
*finally_statement
;
254 HRESULT
block_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
255 HRESULT
var_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
256 HRESULT
empty_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
257 HRESULT
expression_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
258 HRESULT
if_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
259 HRESULT
while_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
260 HRESULT
for_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
261 HRESULT
forin_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
262 HRESULT
continue_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
263 HRESULT
break_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
264 HRESULT
return_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
265 HRESULT
with_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
266 HRESULT
labelled_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
267 HRESULT
switch_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
268 HRESULT
throw_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
269 HRESULT
try_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
290 typedef HRESULT (*expression_eval_t
)(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
292 struct _expression_t
{
293 expression_eval_t eval
;
296 struct _parameter_t
{
297 const WCHAR
*identifier
;
299 struct _parameter_t
*next
;
302 struct _source_elements_t
{
303 statement_t
*statement
;
304 statement_t
*statement_tail
;
305 function_declaration_t
*functions
;
306 var_list_t
*variables
;
309 struct _function_expression_t
{
311 const WCHAR
*identifier
;
312 parameter_t
*parameter_list
;
313 source_elements_t
*source_elements
;
314 const WCHAR
*src_str
;
320 expression_t
*expression1
;
321 expression_t
*expression2
;
322 } binary_expression_t
;
326 expression_t
*expression
;
327 } unary_expression_t
;
331 expression_t
*expression
;
332 expression_t
*true_expression
;
333 expression_t
*false_expression
;
334 } conditional_expression_t
;
338 expression_t
*member_expr
;
339 expression_t
*expression
;
340 } array_expression_t
;
344 expression_t
*expression
;
345 const WCHAR
*identifier
;
346 } member_expression_t
;
348 typedef struct _argument_t
{
351 struct _argument_t
*next
;
356 expression_t
*expression
;
357 argument_t
*argument_list
;
362 const WCHAR
*identifier
;
363 } identifier_expression_t
;
368 } literal_expression_t
;
370 typedef struct _array_element_t
{
374 struct _array_element_t
*next
;
379 array_element_t
*element_list
;
381 } array_literal_expression_t
;
383 typedef struct _prop_val_t
{
387 struct _prop_val_t
*next
;
392 prop_val_t
*property_list
;
393 } property_value_expression_t
;
445 HRESULT
function_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
446 HRESULT
conditional_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
447 HRESULT
array_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
448 HRESULT
member_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
449 HRESULT
new_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
450 HRESULT
call_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
451 HRESULT
this_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
452 HRESULT
identifier_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
453 HRESULT
literal_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
454 HRESULT
array_literal_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
455 HRESULT
property_value_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
457 HRESULT
comma_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
458 HRESULT
logical_or_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
459 HRESULT
logical_and_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
460 HRESULT
binary_or_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
461 HRESULT
binary_xor_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
462 HRESULT
binary_and_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
463 HRESULT
instanceof_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
464 HRESULT
in_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
465 HRESULT
add_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
466 HRESULT
sub_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
467 HRESULT
mul_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
468 HRESULT
div_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
469 HRESULT
mod_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
470 HRESULT
delete_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
471 HRESULT
void_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
472 HRESULT
typeof_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
473 HRESULT
minus_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
474 HRESULT
plus_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
475 HRESULT
post_increment_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
476 HRESULT
post_decrement_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
477 HRESULT
pre_increment_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
478 HRESULT
pre_decrement_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
479 HRESULT
equal_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
480 HRESULT
equal2_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
481 HRESULT
not_equal_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
482 HRESULT
not_equal2_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
483 HRESULT
less_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
484 HRESULT
lesseq_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
485 HRESULT
greater_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
486 HRESULT
greatereq_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
487 HRESULT
binary_negation_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
488 HRESULT
logical_negation_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
489 HRESULT
left_shift_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
490 HRESULT
right_shift_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
491 HRESULT
right2_shift_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
492 HRESULT
assign_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
493 HRESULT
assign_lshift_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
494 HRESULT
assign_rshift_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
495 HRESULT
assign_rrshift_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
496 HRESULT
assign_add_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
497 HRESULT
assign_sub_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
498 HRESULT
assign_mul_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
499 HRESULT
assign_div_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
500 HRESULT
assign_mod_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
501 HRESULT
assign_and_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
502 HRESULT
assign_or_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
503 HRESULT
assign_xor_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);