jscript: Added '!==' expression implementation.
[wine/wine64.git] / dlls / jscript / engine.h
blobce9253d8bd63f4f24bfb476be2e39a3957898adc
1 /*
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 _parser_ctx_t {
22 LONG ref;
24 const WCHAR *ptr;
25 const WCHAR *begin;
26 const WCHAR *end;
28 script_ctx_t *script;
29 source_elements_t *source;
30 BOOL nl;
31 HRESULT hres;
33 jsheap_t tmp_heap;
34 jsheap_t heap;
36 struct _parser_ctx_t *next;
37 } parser_ctx_t;
39 HRESULT script_parse(script_ctx_t*,const WCHAR*,parser_ctx_t**);
40 void parser_release(parser_ctx_t*);
42 int parser_lex(void*,parser_ctx_t*);
44 static inline void parser_addref(parser_ctx_t *ctx)
46 ctx->ref++;
49 static inline void *parser_alloc(parser_ctx_t *ctx, DWORD size)
51 return jsheap_alloc(&ctx->heap, size);
54 static inline void *parser_alloc_tmp(parser_ctx_t *ctx, DWORD size)
56 return jsheap_alloc(&ctx->tmp_heap, size);
59 typedef struct _scope_chain_t {
60 LONG ref;
61 DispatchEx *obj;
62 struct _scope_chain_t *next;
63 } scope_chain_t;
65 HRESULT scope_push(scope_chain_t*,DispatchEx*,scope_chain_t**);
66 void scope_release(scope_chain_t*);
68 static inline void scope_addref(scope_chain_t *scope)
70 scope->ref++;
73 struct _exec_ctx_t {
74 LONG ref;
76 parser_ctx_t *parser;
77 scope_chain_t *scope_chain;
78 DispatchEx *var_disp;
81 static inline void exec_addref(exec_ctx_t *ctx)
83 ctx->ref++;
86 void exec_release(exec_ctx_t*);
87 HRESULT create_exec_ctx(DispatchEx*,scope_chain_t*,exec_ctx_t**);
88 HRESULT exec_source(exec_ctx_t*,parser_ctx_t*,source_elements_t*,jsexcept_t*,VARIANT*);
90 typedef struct _statement_t statement_t;
91 typedef struct _expression_t expression_t;
92 typedef struct _parameter_t parameter_t;
94 typedef struct {
95 VARTYPE vt;
96 union {
97 LONG lval;
98 double dval;
99 const WCHAR *wstr;
100 VARIANT_BOOL bval;
101 IDispatch *disp;
102 } u;
103 } literal_t;
105 typedef struct _variable_declaration_t {
106 const WCHAR *identifier;
107 expression_t *expr;
109 struct _variable_declaration_t *next;
110 } variable_declaration_t;
112 typedef struct {
113 enum{
114 RT_NORMAL,
115 RT_RETURN,
116 RT_BREAK,
117 RT_CONTINUE
118 } type;
119 jsexcept_t ei;
120 } return_type_t;
122 typedef HRESULT (*statement_eval_t)(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
124 struct _statement_t {
125 statement_eval_t eval;
126 statement_t *next;
129 typedef struct {
130 statement_t stat;
131 statement_t *stat_list;
132 } block_statement_t;
134 typedef struct {
135 statement_t stat;
136 variable_declaration_t *variable_list;
137 } var_statement_t;
139 typedef struct {
140 statement_t stat;
141 expression_t *expr;
142 } expression_statement_t;
144 typedef struct {
145 statement_t stat;
146 expression_t *expr;
147 statement_t *if_stat;
148 statement_t *else_stat;
149 } if_statement_t;
151 typedef struct {
152 statement_t stat;
153 expression_t *expr;
154 statement_t *statement;
155 } while_statement_t;
157 typedef struct {
158 statement_t stat;
159 variable_declaration_t *variable_list;
160 expression_t *begin_expr;
161 expression_t *expr;
162 expression_t *end_expr;
163 statement_t *statement;
164 } for_statement_t;
166 typedef struct {
167 statement_t stat;
168 variable_declaration_t *variable;
169 expression_t *expr;
170 expression_t *in_expr;
171 statement_t *statement;
172 } forin_statement_t;
174 typedef struct {
175 statement_t stat;
176 const WCHAR *identifier;
177 } branch_statement_t;
179 typedef struct {
180 statement_t stat;
181 expression_t *expr;
182 statement_t *statement;
183 } with_statement_t;
185 typedef struct {
186 statement_t stat;
187 const WCHAR *identifier;
188 statement_t *statement;
189 } labelled_statement_t;
191 typedef struct _case_clausule_t {
192 expression_t *expr;
193 statement_t *stat;
195 struct _case_clausule_t *next;
196 } case_clausule_t;
198 typedef struct {
199 statement_t stat;
200 expression_t *expr;
201 case_clausule_t *case_list;
202 } switch_statement_t;
204 typedef struct {
205 const WCHAR *identifier;
206 statement_t *statement;
207 } catch_block_t;
209 typedef struct {
210 statement_t stat;
211 statement_t *try_statement;
212 catch_block_t *catch_block;
213 statement_t *finally_statement;
214 } try_statement_t;
216 HRESULT block_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
217 HRESULT var_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
218 HRESULT empty_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
219 HRESULT expression_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
220 HRESULT if_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
221 HRESULT dowhile_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
222 HRESULT while_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
223 HRESULT for_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
224 HRESULT forin_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
225 HRESULT continue_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
226 HRESULT break_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
227 HRESULT return_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
228 HRESULT with_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
229 HRESULT labelled_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
230 HRESULT switch_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
231 HRESULT throw_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
232 HRESULT try_statement_eval(exec_ctx_t*,statement_t*,return_type_t*,VARIANT*);
234 typedef struct {
235 enum {
236 EXPRVAL_VARIANT,
237 EXPRVAL_IDREF,
238 EXPRVAL_NAMEREF
239 } type;
240 union {
241 VARIANT var;
242 struct {
243 IDispatch *disp;
244 DISPID id;
245 } idref;
246 struct {
247 IDispatch *disp;
248 BSTR name;
249 } nameref;
250 } u;
251 } exprval_t;
253 typedef HRESULT (*expression_eval_t)(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
255 struct _expression_t {
256 expression_eval_t eval;
259 struct _parameter_t {
260 const WCHAR *identifier;
262 struct _parameter_t *next;
265 typedef struct _function_declaration_t {
266 const WCHAR *identifier;
267 parameter_t *parameter_list;
268 source_elements_t *source_elements;
270 struct _function_declaration_t *next;
271 } function_declaration_t;
273 struct _source_elements_t {
274 statement_t *statement;
275 statement_t *statement_tail;
276 function_declaration_t *functions;
277 function_declaration_t *functions_tail;
280 typedef struct {
281 expression_t expr;
282 const WCHAR *identifier;
283 parameter_t *parameter_list;
284 source_elements_t *source_elements;
285 } function_expression_t;
287 typedef struct {
288 expression_t expr;
289 expression_t *expression1;
290 expression_t *expression2;
291 } binary_expression_t;
293 typedef struct {
294 expression_t expr;
295 expression_t *expression;
296 } unary_expression_t;
298 typedef struct {
299 expression_t expr;
300 expression_t *expression;
301 expression_t *true_expression;
302 expression_t *false_expression;
303 } conditional_expression_t;
305 typedef struct {
306 expression_t expr;
307 expression_t *member_expr;
308 expression_t *expression;
309 } array_expression_t;
311 typedef struct {
312 expression_t expr;
313 expression_t *expression;
314 const WCHAR *identifier;
315 } member_expression_t;
317 typedef struct _argument_t {
318 expression_t *expr;
320 struct _argument_t *next;
321 } argument_t;
323 typedef struct {
324 expression_t expr;
325 expression_t *expression;
326 argument_t *argument_list;
327 } call_expression_t;
329 typedef struct {
330 expression_t expr;
331 const WCHAR *identifier;
332 } identifier_expression_t;
334 typedef struct {
335 expression_t expr;
336 literal_t *literal;
337 } literal_expression_t;
339 typedef struct _array_element_t {
340 int elision;
341 expression_t *expr;
343 struct _array_element_t *next;
344 } array_element_t;
346 typedef struct {
347 expression_t expr;
348 array_element_t *element_list;
349 int length;
350 } array_literal_expression_t;
352 typedef struct _prop_val_t {
353 literal_t *name;
354 expression_t *value;
356 struct _prop_val_t *next;
357 } prop_val_t;
359 typedef struct {
360 expression_t expr;
361 prop_val_t *property_list;
362 } property_value_expression_t;
364 typedef enum {
365 EXPR_COMMA,
366 EXPR_OR,
367 EXPR_AND,
368 EXPR_BOR,
369 EXPR_BXOR,
370 EXPR_BAND,
371 EXPR_INSTANCEOF,
372 EXPR_IN,
373 EXPR_ADD,
374 EXPR_SUB,
375 EXPR_MUL,
376 EXPR_DIV,
377 EXPR_MOD,
378 EXPR_DELETE,
379 EXPR_VOID,
380 EXPR_TYPEOF,
381 EXPR_MINUS,
382 EXPR_PLUS,
383 EXPR_POSTINC,
384 EXPR_POSTDEC,
385 EXPR_PREINC,
386 EXPR_PREDEC,
387 EXPR_NEW,
388 EXPR_EQ,
389 EXPR_EQEQ,
390 EXPR_NOTEQ,
391 EXPR_NOTEQEQ,
392 EXPR_LESS,
393 EXPR_LESSEQ,
394 EXPR_GREATER,
395 EXPR_GREATEREQ,
396 EXPR_BITNEG,
397 EXPR_LOGNEG,
398 EXPR_LSHIFT,
399 EXPR_RSHIFT,
400 EXPR_RRSHIFT,
401 EXPR_ASSIGN,
402 EXPR_ASSIGNLSHIFT,
403 EXPR_ASSIGNRSHIFT,
404 EXPR_ASSIGNRRSHIFT,
405 EXPR_ASSIGNADD,
406 EXPR_ASSIGNSUB,
407 EXPR_ASSIGNMUL,
408 EXPR_ASSIGNDIV,
409 EXPR_ASSIGNMOD,
410 EXPR_ASSIGNAND,
411 EXPR_ASSIGNOR,
412 EXPR_ASSIGNXOR
413 } expression_type_t;
415 HRESULT function_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
416 HRESULT conditional_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
417 HRESULT array_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
418 HRESULT member_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
419 HRESULT member_new_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
420 HRESULT call_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
421 HRESULT this_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
422 HRESULT identifier_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
423 HRESULT literal_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
424 HRESULT array_literal_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
425 HRESULT property_value_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
427 HRESULT comma_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
428 HRESULT logical_or_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
429 HRESULT logical_and_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
430 HRESULT binary_or_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
431 HRESULT binary_xor_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
432 HRESULT binary_and_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
433 HRESULT instanceof_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
434 HRESULT in_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
435 HRESULT add_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
436 HRESULT sub_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
437 HRESULT mul_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
438 HRESULT div_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
439 HRESULT mod_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
440 HRESULT delete_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
441 HRESULT void_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
442 HRESULT typeof_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
443 HRESULT minus_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
444 HRESULT plus_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
445 HRESULT post_increment_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
446 HRESULT post_decrement_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
447 HRESULT pre_increment_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
448 HRESULT pre_decrement_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
449 HRESULT new_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
450 HRESULT equal_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
451 HRESULT equal2_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
452 HRESULT not_equal_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
453 HRESULT not_equal2_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
454 HRESULT less_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
455 HRESULT lesseq_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
456 HRESULT greater_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
457 HRESULT greatereq_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
458 HRESULT binary_negation_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
459 HRESULT logical_negation_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
460 HRESULT left_shift_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
461 HRESULT right_shift_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
462 HRESULT right2_shift_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
463 HRESULT assign_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
464 HRESULT assign_lshift_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
465 HRESULT assign_rshift_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
466 HRESULT assign_rrshift_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
467 HRESULT assign_add_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
468 HRESULT assign_sub_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
469 HRESULT assign_mul_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
470 HRESULT assign_div_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
471 HRESULT assign_mod_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
472 HRESULT assign_and_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
473 HRESULT assign_or_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);
474 HRESULT assign_xor_expression_eval(exec_ctx_t*,expression_t*,DWORD,jsexcept_t*,exprval_t*);