vbscript: Added for..in statement tests.
[wine] / dlls / vbscript / parse.h
1 /*
2  * Copyright 2011 Jacek Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 typedef enum {
20     EXPR_ADD,
21     EXPR_AND,
22     EXPR_BOOL,
23     EXPR_CONCAT,
24     EXPR_DIV,
25     EXPR_DOUBLE,
26     EXPR_EMPTY,
27     EXPR_EQUAL,
28     EXPR_EQV,
29     EXPR_EXP,
30     EXPR_GT,
31     EXPR_GTEQ,
32     EXPR_IDIV,
33     EXPR_IMP,
34     EXPR_IS,
35     EXPR_LT,
36     EXPR_LTEQ,
37     EXPR_ME,
38     EXPR_MEMBER,
39     EXPR_MOD,
40     EXPR_MUL,
41     EXPR_NEG,
42     EXPR_NEQUAL,
43     EXPR_NEW,
44     EXPR_NOT,
45     EXPR_NOTHING,
46     EXPR_NULL,
47     EXPR_OR,
48     EXPR_STRING,
49     EXPR_SUB,
50     EXPR_ULONG,
51     EXPR_USHORT,
52     EXPR_XOR
53 } expression_type_t;
54
55 typedef struct _expression_t {
56     expression_type_t type;
57     struct _expression_t *next;
58 } expression_t;
59
60 typedef struct {
61     expression_t expr;
62     VARIANT_BOOL value;
63 } bool_expression_t;
64
65 typedef struct {
66     expression_t expr;
67     LONG value;
68 } int_expression_t;
69
70 typedef struct {
71     expression_t expr;
72     double value;
73 } double_expression_t;
74
75 typedef struct {
76     expression_t expr;
77     const WCHAR *value;
78 } string_expression_t;
79
80 typedef struct {
81     expression_t expr;
82     expression_t *subexpr;
83 } unary_expression_t;
84
85 typedef struct {
86     expression_t expr;
87     expression_t *left;
88     expression_t *right;
89 } binary_expression_t;
90
91 typedef struct {
92     expression_t expr;
93     expression_t *obj_expr;
94     const WCHAR *identifier;
95     expression_t *args;
96 } member_expression_t;
97
98 typedef enum {
99     STAT_ASSIGN,
100     STAT_CALL,
101     STAT_CONST,
102     STAT_DIM,
103     STAT_DOUNTIL,
104     STAT_DOWHILE,
105     STAT_EXITDO,
106     STAT_EXITFUNC,
107     STAT_EXITPROP,
108     STAT_EXITSUB,
109     STAT_FORTO,
110     STAT_FUNC,
111     STAT_IF,
112     STAT_ONERROR,
113     STAT_SET,
114     STAT_STOP,
115     STAT_UNTIL,
116     STAT_WHILE,
117     STAT_WHILELOOP
118 } statement_type_t;
119
120 typedef struct _statement_t {
121     statement_type_t type;
122     struct _statement_t *next;
123 } statement_t;
124
125 typedef struct {
126     statement_t stat;
127     member_expression_t *expr;
128 } call_statement_t;
129
130 typedef struct {
131     statement_t stat;
132     member_expression_t *member_expr;
133     expression_t *value_expr;
134 } assign_statement_t;
135
136 typedef struct _dim_decl_t {
137     const WCHAR *name;
138     struct _dim_decl_t *next;
139 } dim_decl_t;
140
141 typedef struct _dim_statement_t {
142     statement_t stat;
143     dim_decl_t *dim_decls;
144 } dim_statement_t;
145
146 typedef struct _arg_decl_t {
147     const WCHAR *name;
148     BOOL by_ref;
149     struct _arg_decl_t *next;
150 } arg_decl_t;
151
152 typedef struct _function_decl_t {
153     const WCHAR *name;
154     function_type_t type;
155     BOOL is_public;
156     arg_decl_t *args;
157     statement_t *body;
158     struct _function_decl_t *next;
159     struct _function_decl_t *next_prop_func;
160 } function_decl_t;
161
162 typedef struct {
163     statement_t stat;
164     function_decl_t *func_decl;
165 } function_statement_t;
166
167 typedef struct _class_prop_decl_t {
168     BOOL is_public;
169     const WCHAR *name;
170     struct _class_prop_decl_t *next;
171 } class_prop_decl_t;
172
173 typedef struct _class_decl_t {
174     const WCHAR *name;
175     function_decl_t *funcs;
176     class_prop_decl_t *props;
177     struct _class_decl_t *next;
178 } class_decl_t;
179
180 typedef struct _elseif_decl_t {
181     expression_t *expr;
182     statement_t *stat;
183     struct _elseif_decl_t *next;
184 } elseif_decl_t;
185
186 typedef struct {
187     statement_t stat;
188     expression_t *expr;
189     statement_t *if_stat;
190     elseif_decl_t *elseifs;
191     statement_t *else_stat;
192 } if_statement_t;
193
194 typedef struct {
195     statement_t stat;
196     expression_t *expr;
197     statement_t *body;
198 } while_statement_t;
199
200 typedef struct {
201     statement_t stat;
202     const WCHAR *identifier;
203     expression_t *from_expr;
204     expression_t *to_expr;
205     expression_t *step_expr;
206     statement_t *body;
207 } forto_statement_t;
208
209 typedef struct {
210     statement_t stat;
211     BOOL resume_next;
212 } onerror_statement_t;
213
214 typedef struct _const_decl_t {
215     const WCHAR *name;
216     expression_t *value_expr;
217     struct _const_decl_t *next;
218 } const_decl_t;
219
220 typedef struct {
221     statement_t stat;
222     const_decl_t *decls;
223 } const_statement_t;
224
225 typedef struct {
226     const WCHAR *code;
227     const WCHAR *ptr;
228     const WCHAR *end;
229
230     BOOL option_explicit;
231     BOOL parse_complete;
232     HRESULT hres;
233
234     int last_token;
235     unsigned last_nl;
236
237     statement_t *stats;
238     statement_t *stats_tail;
239     class_decl_t *class_decls;
240
241     vbsheap_t heap;
242 } parser_ctx_t;
243
244 HRESULT parse_script(parser_ctx_t*,const WCHAR*) DECLSPEC_HIDDEN;
245 void parser_release(parser_ctx_t*) DECLSPEC_HIDDEN;
246 int parser_lex(void*,parser_ctx_t*) DECLSPEC_HIDDEN;
247 void *parser_alloc(parser_ctx_t*,size_t) DECLSPEC_HIDDEN;