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
;
21 typedef struct _obj_literal_t
{
23 struct _obj_literal_t
*next
;
26 typedef struct _parser_ctx_t
{
34 source_elements_t
*source
;
40 obj_literal_t
*obj_literals
;
42 struct _parser_ctx_t
*next
;
45 HRESULT
script_parse(script_ctx_t
*,const WCHAR
*,parser_ctx_t
**);
46 void parser_release(parser_ctx_t
*);
48 int parser_lex(void*,parser_ctx_t
*);
50 static inline void parser_addref(parser_ctx_t
*ctx
)
55 static inline void *parser_alloc(parser_ctx_t
*ctx
, DWORD size
)
57 return jsheap_alloc(&ctx
->heap
, size
);
60 static inline void *parser_alloc_tmp(parser_ctx_t
*ctx
, DWORD size
)
62 return jsheap_alloc(&ctx
->script
->tmp_heap
, size
);
65 typedef struct _scope_chain_t
{
68 struct _scope_chain_t
*next
;
71 HRESULT
scope_push(scope_chain_t
*,DispatchEx
*,scope_chain_t
**);
72 void scope_release(scope_chain_t
*);
74 static inline void scope_addref(scope_chain_t
*scope
)
83 scope_chain_t
*scope_chain
;
88 static inline void exec_addref(exec_ctx_t
*ctx
)
93 void exec_release(exec_ctx_t
*);
94 HRESULT
create_exec_ctx(IDispatch
*,DispatchEx
*,scope_chain_t
*,exec_ctx_t
**);
95 HRESULT
exec_source(exec_ctx_t
*,parser_ctx_t
*,source_elements_t
*,jsexcept_t
*,VARIANT
*);
97 typedef struct _statement_t statement_t
;
98 typedef struct _expression_t expression_t
;
99 typedef struct _parameter_t parameter_t
;
101 HRESULT
create_source_function(parser_ctx_t
*,parameter_t
*,source_elements_t
*,scope_chain_t
*,DispatchEx
**);
114 literal_t
*parse_regexp(parser_ctx_t
*);
116 typedef struct _variable_declaration_t
{
117 const WCHAR
*identifier
;
120 struct _variable_declaration_t
*next
;
121 } variable_declaration_t
;
133 typedef HRESULT (*statement_eval_t
)(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
135 struct _statement_t
{
136 statement_eval_t eval
;
142 statement_t
*stat_list
;
147 variable_declaration_t
*variable_list
;
153 } expression_statement_t
;
158 statement_t
*if_stat
;
159 statement_t
*else_stat
;
166 statement_t
*statement
;
171 variable_declaration_t
*variable_list
;
172 expression_t
*begin_expr
;
174 expression_t
*end_expr
;
175 statement_t
*statement
;
180 variable_declaration_t
*variable
;
182 expression_t
*in_expr
;
183 statement_t
*statement
;
188 const WCHAR
*identifier
;
189 } branch_statement_t
;
194 statement_t
*statement
;
199 const WCHAR
*identifier
;
200 statement_t
*statement
;
201 } labelled_statement_t
;
203 typedef struct _case_clausule_t
{
207 struct _case_clausule_t
*next
;
213 case_clausule_t
*case_list
;
214 } switch_statement_t
;
217 const WCHAR
*identifier
;
218 statement_t
*statement
;
223 statement_t
*try_statement
;
224 catch_block_t
*catch_block
;
225 statement_t
*finally_statement
;
228 HRESULT
block_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
229 HRESULT
var_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
230 HRESULT
empty_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
231 HRESULT
expression_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
232 HRESULT
if_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
233 HRESULT
while_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
234 HRESULT
for_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
235 HRESULT
forin_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
236 HRESULT
continue_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
237 HRESULT
break_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
238 HRESULT
return_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
239 HRESULT
with_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
240 HRESULT
labelled_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
241 HRESULT
switch_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
242 HRESULT
throw_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
243 HRESULT
try_statement_eval(exec_ctx_t
*,statement_t
*,return_type_t
*,VARIANT
*);
264 typedef HRESULT (*expression_eval_t
)(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
266 struct _expression_t
{
267 expression_eval_t eval
;
270 struct _parameter_t
{
271 const WCHAR
*identifier
;
273 struct _parameter_t
*next
;
276 typedef struct _function_declaration_t
{
277 const WCHAR
*identifier
;
278 parameter_t
*parameter_list
;
279 source_elements_t
*source_elements
;
281 struct _function_declaration_t
*next
;
282 } function_declaration_t
;
284 struct _source_elements_t
{
285 statement_t
*statement
;
286 statement_t
*statement_tail
;
287 function_declaration_t
*functions
;
288 function_declaration_t
*functions_tail
;
293 const WCHAR
*identifier
;
294 parameter_t
*parameter_list
;
295 source_elements_t
*source_elements
;
296 } function_expression_t
;
300 expression_t
*expression1
;
301 expression_t
*expression2
;
302 } binary_expression_t
;
306 expression_t
*expression
;
307 } unary_expression_t
;
311 expression_t
*expression
;
312 expression_t
*true_expression
;
313 expression_t
*false_expression
;
314 } conditional_expression_t
;
318 expression_t
*member_expr
;
319 expression_t
*expression
;
320 } array_expression_t
;
324 expression_t
*expression
;
325 const WCHAR
*identifier
;
326 } member_expression_t
;
328 typedef struct _argument_t
{
331 struct _argument_t
*next
;
336 expression_t
*expression
;
337 argument_t
*argument_list
;
342 const WCHAR
*identifier
;
343 } identifier_expression_t
;
348 } literal_expression_t
;
350 typedef struct _array_element_t
{
354 struct _array_element_t
*next
;
359 array_element_t
*element_list
;
361 } array_literal_expression_t
;
363 typedef struct _prop_val_t
{
367 struct _prop_val_t
*next
;
372 prop_val_t
*property_list
;
373 } property_value_expression_t
;
425 HRESULT
function_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
426 HRESULT
conditional_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
427 HRESULT
array_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
428 HRESULT
member_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
429 HRESULT
new_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
430 HRESULT
call_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
431 HRESULT
this_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
432 HRESULT
identifier_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
433 HRESULT
literal_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
434 HRESULT
array_literal_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
435 HRESULT
property_value_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
437 HRESULT
comma_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
438 HRESULT
logical_or_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
439 HRESULT
logical_and_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
440 HRESULT
binary_or_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
441 HRESULT
binary_xor_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
442 HRESULT
binary_and_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
443 HRESULT
instanceof_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
444 HRESULT
in_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
445 HRESULT
add_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
446 HRESULT
sub_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
447 HRESULT
mul_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
448 HRESULT
div_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
449 HRESULT
mod_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
450 HRESULT
delete_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
451 HRESULT
void_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
452 HRESULT
typeof_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
453 HRESULT
minus_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
454 HRESULT
plus_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
455 HRESULT
post_increment_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
456 HRESULT
post_decrement_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
457 HRESULT
pre_increment_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
458 HRESULT
pre_decrement_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
459 HRESULT
equal_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
460 HRESULT
equal2_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
461 HRESULT
not_equal_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
462 HRESULT
not_equal2_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
463 HRESULT
less_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
464 HRESULT
lesseq_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
465 HRESULT
greater_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
466 HRESULT
greatereq_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
467 HRESULT
binary_negation_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
468 HRESULT
logical_negation_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
469 HRESULT
left_shift_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
470 HRESULT
right_shift_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
471 HRESULT
right2_shift_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
472 HRESULT
assign_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
473 HRESULT
assign_lshift_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
474 HRESULT
assign_rshift_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
475 HRESULT
assign_rrshift_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
476 HRESULT
assign_add_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
477 HRESULT
assign_sub_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
478 HRESULT
assign_mul_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
479 HRESULT
assign_div_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
480 HRESULT
assign_mod_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
481 HRESULT
assign_and_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
482 HRESULT
assign_or_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);
483 HRESULT
assign_xor_expression_eval(exec_ctx_t
*,expression_t
*,DWORD
,jsexcept_t
*,exprval_t
*);