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 _expression_t expression_t
;
20 typedef struct _statement_t statement_t
;
32 typedef struct _parser_ctx_t
{
38 struct _compiler_ctx_t
*compiler
;
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
;
98 BOOL block_scope
, constant
;
101 struct _variable_declaration_t
*next
;
102 struct _variable_declaration_t
*global_next
; /* for compiler */
103 } variable_declaration_t
;
124 struct _statement_t
{
125 statement_type_t type
;
132 unsigned int scope_index
;
133 statement_t
*stat_list
;
138 variable_declaration_t
*variable_list
;
144 } expression_statement_t
;
149 statement_t
*if_stat
;
150 statement_t
*else_stat
;
157 statement_t
*statement
;
162 variable_declaration_t
*variable_list
;
163 expression_t
*begin_expr
;
166 expression_t
*end_expr
;
168 statement_t
*statement
;
169 unsigned int scope_index
;
174 variable_declaration_t
*variable
;
176 expression_t
*in_expr
;
177 statement_t
*statement
;
182 const WCHAR
*identifier
;
183 } branch_statement_t
;
188 statement_t
*statement
;
193 const WCHAR
*identifier
;
194 statement_t
*statement
;
195 } labelled_statement_t
;
197 typedef struct _case_clausule_t
{
202 struct _case_clausule_t
*next
;
208 case_clausule_t
*case_list
;
209 } switch_statement_t
;
212 const WCHAR
*identifier
;
213 statement_t
*statement
;
218 statement_t
*try_statement
;
219 catch_block_t
*catch_block
;
220 statement_t
*finally_statement
;
221 unsigned finally_loc
;
285 struct _expression_t
{
286 expression_type_t type
;
289 typedef struct _parameter_t
{
290 const WCHAR
*identifier
;
291 struct _parameter_t
*next
;
294 typedef struct _function_expression_t
{
296 const WCHAR
*identifier
;
297 const WCHAR
*event_target
;
298 parameter_t
*parameter_list
;
299 statement_t
*statement_list
;
300 const WCHAR
*src_str
;
304 unsigned int scope_index
;
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
;