2 * Copyright 2014 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 _expression_t expression_t
;
21 typedef struct _statement_t statement_t
;
32 typedef struct _parser_ctx_t
{
38 struct _compiler_ctx_t
*compiler
;
39 source_elements_t
*source
;
41 BOOL implicit_nl_semicolon
;
53 HRESULT
script_parse(script_ctx_t
*,struct _compiler_ctx_t
*,struct _bytecode_t
*,const WCHAR
*,BOOL
,parser_ctx_t
**) DECLSPEC_HIDDEN
;
54 void parser_release(parser_ctx_t
*) DECLSPEC_HIDDEN
;
56 int parser_lex(void*,unsigned*,parser_ctx_t
*) DECLSPEC_HIDDEN
;
58 static inline void *parser_alloc(parser_ctx_t
*ctx
, DWORD size
)
60 return heap_pool_alloc(&ctx
->heap
, size
);
63 static inline void *parser_alloc_tmp(parser_ctx_t
*ctx
, DWORD size
)
65 return heap_pool_alloc(&ctx
->script
->tmp_heap
, size
);
68 BOOL
is_identifier_char(WCHAR
) DECLSPEC_HIDDEN
;
69 BOOL
unescape(WCHAR
*,size_t*) DECLSPEC_HIDDEN
;
70 HRESULT
parse_decimal(const WCHAR
**,const WCHAR
*,double*) DECLSPEC_HIDDEN
;
93 literal_t
*parse_regexp(parser_ctx_t
*) DECLSPEC_HIDDEN
;
94 literal_t
*new_boolean_literal(parser_ctx_t
*,BOOL
) DECLSPEC_HIDDEN
;
96 typedef struct _variable_declaration_t
{
97 const WCHAR
*identifier
;
100 struct _variable_declaration_t
*next
;
101 struct _variable_declaration_t
*global_next
; /* for compiler */
102 } variable_declaration_t
;
123 struct _statement_t
{
124 statement_type_t type
;
131 statement_t
*stat_list
;
136 variable_declaration_t
*variable_list
;
142 } expression_statement_t
;
147 statement_t
*if_stat
;
148 statement_t
*else_stat
;
155 statement_t
*statement
;
160 variable_declaration_t
*variable_list
;
161 expression_t
*begin_expr
;
164 expression_t
*end_expr
;
166 statement_t
*statement
;
171 variable_declaration_t
*variable
;
173 expression_t
*in_expr
;
174 statement_t
*statement
;
179 const WCHAR
*identifier
;
180 } branch_statement_t
;
185 statement_t
*statement
;
190 const WCHAR
*identifier
;
191 statement_t
*statement
;
192 } labelled_statement_t
;
194 typedef struct _case_clausule_t
{
199 struct _case_clausule_t
*next
;
205 case_clausule_t
*case_list
;
206 } switch_statement_t
;
209 const WCHAR
*identifier
;
210 statement_t
*statement
;
215 statement_t
*try_statement
;
216 catch_block_t
*catch_block
;
217 statement_t
*finally_statement
;
218 unsigned finally_loc
;
282 struct _expression_t
{
283 expression_type_t type
;
286 typedef struct _parameter_t
{
287 const WCHAR
*identifier
;
288 struct _parameter_t
*next
;
291 struct _source_elements_t
{
292 statement_t
*statement
;
293 statement_t
*statement_tail
;
296 typedef struct _function_expression_t
{
298 const WCHAR
*identifier
;
299 const WCHAR
*event_target
;
300 parameter_t
*parameter_list
;
301 source_elements_t
*source_elements
;
302 const WCHAR
*src_str
;
306 struct _function_expression_t
*next
; /* for compiler */
307 } function_expression_t
;
311 expression_t
*expression1
;
312 expression_t
*expression2
;
313 } binary_expression_t
;
317 expression_t
*expression
;
318 } unary_expression_t
;
322 expression_t
*expression
;
323 expression_t
*true_expression
;
324 expression_t
*false_expression
;
325 } conditional_expression_t
;
329 expression_t
*expression
;
330 const WCHAR
*identifier
;
331 } member_expression_t
;
333 typedef struct _argument_t
{
336 struct _argument_t
*next
;
341 expression_t
*expression
;
342 argument_t
*argument_list
;
347 const WCHAR
*identifier
;
348 } identifier_expression_t
;
353 } literal_expression_t
;
355 typedef struct _array_element_t
{
359 struct _array_element_t
*next
;
364 array_element_t
*element_list
;
366 } array_literal_expression_t
;
368 typedef struct _property_definition_t
{
373 struct _property_definition_t
*next
;
374 } property_definition_t
;
378 property_definition_t
*property_list
;
379 } property_value_expression_t
;
381 BOOL
try_parse_ccval(parser_ctx_t
*,ccval_t
*) DECLSPEC_HIDDEN
;
382 BOOL
parse_cc_expr(parser_ctx_t
*) DECLSPEC_HIDDEN
;
384 static inline ccval_t
ccval_num(double n
)
392 static inline ccval_t
ccval_bool(BOOL b
)
400 static inline BOOL
get_ccbool(ccval_t v
)
402 return v
.is_num
? v
.u
.n
!= 0 : v
.u
.b
;
405 static inline double get_ccnum(ccval_t v
)
407 return v
.is_num
? v
.u
.n
: v
.u
.b
;
410 jsstr_t
*compiler_alloc_string_len(struct _compiler_ctx_t
*,const WCHAR
*,unsigned) DECLSPEC_HIDDEN
;