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
;
31 typedef struct _parser_ctx_t
{
37 source_elements_t
*source
;
39 BOOL implicit_nl_semicolon
;
50 HRESULT
script_parse(script_ctx_t
*,const WCHAR
*,const WCHAR
*,BOOL
,parser_ctx_t
**) DECLSPEC_HIDDEN
;
51 void parser_release(parser_ctx_t
*) DECLSPEC_HIDDEN
;
53 int parser_lex(void*,parser_ctx_t
*) DECLSPEC_HIDDEN
;
55 static inline void *parser_alloc(parser_ctx_t
*ctx
, DWORD size
)
57 return heap_pool_alloc(&ctx
->heap
, size
);
60 static inline void *parser_alloc_tmp(parser_ctx_t
*ctx
, DWORD size
)
62 return heap_pool_alloc(&ctx
->script
->tmp_heap
, size
);
87 literal_t
*parse_regexp(parser_ctx_t
*) DECLSPEC_HIDDEN
;
88 literal_t
*new_boolean_literal(parser_ctx_t
*,BOOL
) DECLSPEC_HIDDEN
;
90 typedef struct _variable_declaration_t
{
91 const WCHAR
*identifier
;
94 struct _variable_declaration_t
*next
;
95 struct _variable_declaration_t
*global_next
; /* for compiler */
96 } variable_declaration_t
;
117 struct _statement_t
{
118 statement_type_t type
;
124 statement_t
*stat_list
;
129 variable_declaration_t
*variable_list
;
135 } expression_statement_t
;
140 statement_t
*if_stat
;
141 statement_t
*else_stat
;
148 statement_t
*statement
;
153 variable_declaration_t
*variable_list
;
154 expression_t
*begin_expr
;
156 expression_t
*end_expr
;
157 statement_t
*statement
;
162 variable_declaration_t
*variable
;
164 expression_t
*in_expr
;
165 statement_t
*statement
;
170 const WCHAR
*identifier
;
171 } branch_statement_t
;
176 statement_t
*statement
;
181 const WCHAR
*identifier
;
182 statement_t
*statement
;
183 } labelled_statement_t
;
185 typedef struct _case_clausule_t
{
189 struct _case_clausule_t
*next
;
195 case_clausule_t
*case_list
;
196 } switch_statement_t
;
199 const WCHAR
*identifier
;
200 statement_t
*statement
;
205 statement_t
*try_statement
;
206 catch_block_t
*catch_block
;
207 statement_t
*finally_statement
;
271 struct _expression_t
{
272 expression_type_t type
;
275 typedef struct _parameter_t
{
276 const WCHAR
*identifier
;
277 struct _parameter_t
*next
;
280 struct _source_elements_t
{
281 statement_t
*statement
;
282 statement_t
*statement_tail
;
285 typedef struct _function_expression_t
{
287 const WCHAR
*identifier
;
288 parameter_t
*parameter_list
;
289 source_elements_t
*source_elements
;
290 const WCHAR
*src_str
;
293 struct _function_expression_t
*next
; /* for compiler */
294 } function_expression_t
;
298 expression_t
*expression1
;
299 expression_t
*expression2
;
300 } binary_expression_t
;
304 expression_t
*expression
;
305 } unary_expression_t
;
309 expression_t
*expression
;
310 expression_t
*true_expression
;
311 expression_t
*false_expression
;
312 } conditional_expression_t
;
316 expression_t
*expression
;
317 const WCHAR
*identifier
;
318 } member_expression_t
;
320 typedef struct _argument_t
{
323 struct _argument_t
*next
;
328 expression_t
*expression
;
329 argument_t
*argument_list
;
334 const WCHAR
*identifier
;
335 } identifier_expression_t
;
340 } literal_expression_t
;
342 typedef struct _array_element_t
{
346 struct _array_element_t
*next
;
351 array_element_t
*element_list
;
353 } array_literal_expression_t
;
355 typedef struct _prop_val_t
{
359 struct _prop_val_t
*next
;
364 prop_val_t
*property_list
;
365 } property_value_expression_t
;
367 BOOL
try_parse_ccval(parser_ctx_t
*,ccval_t
*) DECLSPEC_HIDDEN
;
368 BOOL
parse_cc_expr(parser_ctx_t
*) DECLSPEC_HIDDEN
;
370 static inline ccval_t
ccval_num(double n
)
378 static inline ccval_t
ccval_bool(BOOL b
)
386 static inline BOOL
get_ccbool(ccval_t v
)
388 return v
.is_num
? v
.u
.n
!= 0 : v
.u
.b
;
391 static inline double get_ccnum(ccval_t v
)
393 return v
.is_num
? v
.u
.n
: v
.u
.b
;