d3d11: Sync formats with dxgi.
[wine.git] / dlls / jscript / parser.h
blobc3dcb82f071e41e5da5411edf73b52a7b4b57bdf
1 /*
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;
23 typedef struct {
24 BOOL is_num;
25 union {
26 BOOL b;
27 double n;
28 } u;
29 } ccval_t;
31 typedef struct _parser_ctx_t {
32 const WCHAR *begin;
33 const WCHAR *end;
34 const WCHAR *ptr;
36 script_ctx_t *script;
37 source_elements_t *source;
38 BOOL nl;
39 BOOL implicit_nl_semicolon;
40 BOOL is_html;
41 BOOL lexer_error;
42 HRESULT hres;
44 ccval_t ccval;
45 unsigned cc_if_depth;
47 heap_pool_t heap;
48 } parser_ctx_t;
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);
65 BOOL is_identifier_char(WCHAR) DECLSPEC_HIDDEN;
66 BOOL unescape(WCHAR*) DECLSPEC_HIDDEN;
67 HRESULT parse_decimal(const WCHAR**,const WCHAR*,double*) DECLSPEC_HIDDEN;
69 typedef enum {
70 LT_DOUBLE,
71 LT_STRING,
72 LT_BOOL,
73 LT_NULL,
74 LT_REGEXP
75 }literal_type_t;
77 typedef struct {
78 literal_type_t type;
79 union {
80 double dval;
81 const WCHAR *wstr;
82 BOOL bval;
83 struct {
84 const WCHAR *str;
85 DWORD str_len;
86 DWORD flags;
87 } regexp;
88 } u;
89 } literal_t;
91 literal_t *parse_regexp(parser_ctx_t*) DECLSPEC_HIDDEN;
92 literal_t *new_boolean_literal(parser_ctx_t*,BOOL) DECLSPEC_HIDDEN;
94 typedef struct _variable_declaration_t {
95 const WCHAR *identifier;
96 expression_t *expr;
98 struct _variable_declaration_t *next;
99 struct _variable_declaration_t *global_next; /* for compiler */
100 } variable_declaration_t;
102 typedef enum {
103 STAT_BLOCK,
104 STAT_BREAK,
105 STAT_CONTINUE,
106 STAT_EMPTY,
107 STAT_EXPR,
108 STAT_FOR,
109 STAT_FORIN,
110 STAT_IF,
111 STAT_LABEL,
112 STAT_RETURN,
113 STAT_SWITCH,
114 STAT_THROW,
115 STAT_TRY,
116 STAT_VAR,
117 STAT_WHILE,
118 STAT_WITH
119 } statement_type_t;
121 struct _statement_t {
122 statement_type_t type;
123 statement_t *next;
126 typedef struct {
127 statement_t stat;
128 statement_t *stat_list;
129 } block_statement_t;
131 typedef struct {
132 statement_t stat;
133 variable_declaration_t *variable_list;
134 } var_statement_t;
136 typedef struct {
137 statement_t stat;
138 expression_t *expr;
139 } expression_statement_t;
141 typedef struct {
142 statement_t stat;
143 expression_t *expr;
144 statement_t *if_stat;
145 statement_t *else_stat;
146 } if_statement_t;
148 typedef struct {
149 statement_t stat;
150 BOOL do_while;
151 expression_t *expr;
152 statement_t *statement;
153 } while_statement_t;
155 typedef struct {
156 statement_t stat;
157 variable_declaration_t *variable_list;
158 expression_t *begin_expr;
159 expression_t *expr;
160 expression_t *end_expr;
161 statement_t *statement;
162 } for_statement_t;
164 typedef struct {
165 statement_t stat;
166 variable_declaration_t *variable;
167 expression_t *expr;
168 expression_t *in_expr;
169 statement_t *statement;
170 } forin_statement_t;
172 typedef struct {
173 statement_t stat;
174 const WCHAR *identifier;
175 } branch_statement_t;
177 typedef struct {
178 statement_t stat;
179 expression_t *expr;
180 statement_t *statement;
181 } with_statement_t;
183 typedef struct {
184 statement_t stat;
185 const WCHAR *identifier;
186 statement_t *statement;
187 } labelled_statement_t;
189 typedef struct _case_clausule_t {
190 expression_t *expr;
191 statement_t *stat;
193 struct _case_clausule_t *next;
194 } case_clausule_t;
196 typedef struct {
197 statement_t stat;
198 expression_t *expr;
199 case_clausule_t *case_list;
200 } switch_statement_t;
202 typedef struct {
203 const WCHAR *identifier;
204 statement_t *statement;
205 } catch_block_t;
207 typedef struct {
208 statement_t stat;
209 statement_t *try_statement;
210 catch_block_t *catch_block;
211 statement_t *finally_statement;
212 } try_statement_t;
214 typedef enum {
215 EXPR_COMMA,
216 EXPR_OR,
217 EXPR_AND,
218 EXPR_BOR,
219 EXPR_BXOR,
220 EXPR_BAND,
221 EXPR_INSTANCEOF,
222 EXPR_IN,
223 EXPR_ADD,
224 EXPR_SUB,
225 EXPR_MUL,
226 EXPR_DIV,
227 EXPR_MOD,
228 EXPR_DELETE,
229 EXPR_VOID,
230 EXPR_TYPEOF,
231 EXPR_MINUS,
232 EXPR_PLUS,
233 EXPR_POSTINC,
234 EXPR_POSTDEC,
235 EXPR_PREINC,
236 EXPR_PREDEC,
237 EXPR_EQ,
238 EXPR_EQEQ,
239 EXPR_NOTEQ,
240 EXPR_NOTEQEQ,
241 EXPR_LESS,
242 EXPR_LESSEQ,
243 EXPR_GREATER,
244 EXPR_GREATEREQ,
245 EXPR_BITNEG,
246 EXPR_LOGNEG,
247 EXPR_LSHIFT,
248 EXPR_RSHIFT,
249 EXPR_RRSHIFT,
250 EXPR_ASSIGN,
251 EXPR_ASSIGNLSHIFT,
252 EXPR_ASSIGNRSHIFT,
253 EXPR_ASSIGNRRSHIFT,
254 EXPR_ASSIGNADD,
255 EXPR_ASSIGNSUB,
256 EXPR_ASSIGNMUL,
257 EXPR_ASSIGNDIV,
258 EXPR_ASSIGNMOD,
259 EXPR_ASSIGNAND,
260 EXPR_ASSIGNOR,
261 EXPR_ASSIGNXOR,
262 EXPR_COND,
263 EXPR_ARRAY,
264 EXPR_MEMBER,
265 EXPR_NEW,
266 EXPR_CALL,
267 EXPR_THIS,
268 EXPR_FUNC,
269 EXPR_IDENT,
270 EXPR_ARRAYLIT,
271 EXPR_PROPVAL,
272 EXPR_LITERAL
273 } expression_type_t;
275 struct _expression_t {
276 expression_type_t type;
279 typedef struct _parameter_t {
280 const WCHAR *identifier;
281 struct _parameter_t *next;
282 } parameter_t;
284 struct _source_elements_t {
285 statement_t *statement;
286 statement_t *statement_tail;
289 typedef struct _function_expression_t {
290 expression_t expr;
291 const WCHAR *identifier;
292 const WCHAR *event_target;
293 parameter_t *parameter_list;
294 source_elements_t *source_elements;
295 const WCHAR *src_str;
296 DWORD src_len;
298 struct _function_expression_t *next; /* for compiler */
299 } function_expression_t;
301 typedef struct {
302 expression_t expr;
303 expression_t *expression1;
304 expression_t *expression2;
305 } binary_expression_t;
307 typedef struct {
308 expression_t expr;
309 expression_t *expression;
310 } unary_expression_t;
312 typedef struct {
313 expression_t expr;
314 expression_t *expression;
315 expression_t *true_expression;
316 expression_t *false_expression;
317 } conditional_expression_t;
319 typedef struct {
320 expression_t expr;
321 expression_t *expression;
322 const WCHAR *identifier;
323 } member_expression_t;
325 typedef struct _argument_t {
326 expression_t *expr;
328 struct _argument_t *next;
329 } argument_t;
331 typedef struct {
332 expression_t expr;
333 expression_t *expression;
334 argument_t *argument_list;
335 } call_expression_t;
337 typedef struct {
338 expression_t expr;
339 const WCHAR *identifier;
340 } identifier_expression_t;
342 typedef struct {
343 expression_t expr;
344 literal_t *literal;
345 } literal_expression_t;
347 typedef struct _array_element_t {
348 int elision;
349 expression_t *expr;
351 struct _array_element_t *next;
352 } array_element_t;
354 typedef struct {
355 expression_t expr;
356 array_element_t *element_list;
357 int length;
358 } array_literal_expression_t;
360 typedef struct _prop_val_t {
361 literal_t *name;
362 expression_t *value;
364 struct _prop_val_t *next;
365 } prop_val_t;
367 typedef struct {
368 expression_t expr;
369 prop_val_t *property_list;
370 } property_value_expression_t;
372 BOOL try_parse_ccval(parser_ctx_t*,ccval_t*) DECLSPEC_HIDDEN;
373 BOOL parse_cc_expr(parser_ctx_t*) DECLSPEC_HIDDEN;
375 static inline ccval_t ccval_num(double n)
377 ccval_t r;
378 r.is_num = TRUE;
379 r.u.n = n;
380 return r;
383 static inline ccval_t ccval_bool(BOOL b)
385 ccval_t r;
386 r.is_num = FALSE;
387 r.u.b = b;
388 return r;
391 static inline BOOL get_ccbool(ccval_t v)
393 return v.is_num ? v.u.n != 0 : v.u.b;
396 static inline double get_ccnum(ccval_t v)
398 return v.is_num ? v.u.n : v.u.b;