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