vbscript: Added do..while and do..until statements implementation.
[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_IDIV,
31     EXPR_IMP,
32     EXPR_MEMBER,
33     EXPR_MOD,
34     EXPR_MUL,
35     EXPR_NEG,
36     EXPR_NEQUAL,
37     EXPR_NEW,
38     EXPR_NOT,
39     EXPR_NOTHING,
40     EXPR_NULL,
41     EXPR_OR,
42     EXPR_STRING,
43     EXPR_SUB,
44     EXPR_ULONG,
45     EXPR_USHORT,
46     EXPR_XOR
47 } expression_type_t;
48
49 typedef struct _expression_t {
50     expression_type_t type;
51     struct _expression_t *next;
52 } expression_t;
53
54 typedef struct {
55     expression_t expr;
56     VARIANT_BOOL value;
57 } bool_expression_t;
58
59 typedef struct {
60     expression_t expr;
61     LONG value;
62 } int_expression_t;
63
64 typedef struct {
65     expression_t expr;
66     double value;
67 } double_expression_t;
68
69 typedef struct {
70     expression_t expr;
71     const WCHAR *value;
72 } string_expression_t;
73
74 typedef struct {
75     expression_t expr;
76     expression_t *subexpr;
77 } unary_expression_t;
78
79 typedef struct {
80     expression_t expr;
81     expression_t *left;
82     expression_t *right;
83 } binary_expression_t;
84
85 typedef struct {
86     expression_t expr;
87     expression_t *obj_expr;
88     const WCHAR *identifier;
89     expression_t *args;
90 } member_expression_t;
91
92 typedef enum {
93     STAT_ASSIGN,
94     STAT_CALL,
95     STAT_DIM,
96     STAT_DOUNTIL,
97     STAT_DOWHILE,
98     STAT_EXITDO,
99     STAT_EXITFUNC,
100     STAT_EXITPROP,
101     STAT_EXITSUB,
102     STAT_FUNC,
103     STAT_IF,
104     STAT_SET,
105     STAT_STOP,
106     STAT_UNTIL,
107     STAT_WHILE,
108     STAT_WHILELOOP
109 } statement_type_t;
110
111 typedef struct _statement_t {
112     statement_type_t type;
113     struct _statement_t *next;
114 } statement_t;
115
116 typedef struct {
117     statement_t stat;
118     member_expression_t *expr;
119 } call_statement_t;
120
121 typedef struct {
122     statement_t stat;
123     member_expression_t *member_expr;
124     expression_t *value_expr;
125 } assign_statement_t;
126
127 typedef struct _dim_decl_t {
128     const WCHAR *name;
129     struct _dim_decl_t *next;
130 } dim_decl_t;
131
132 typedef struct _dim_statement_t {
133     statement_t stat;
134     dim_decl_t *dim_decls;
135 } dim_statement_t;
136
137 typedef struct _arg_decl_t {
138     const WCHAR *name;
139     BOOL by_ref;
140     struct _arg_decl_t *next;
141 } arg_decl_t;
142
143 typedef struct _function_decl_t {
144     const WCHAR *name;
145     function_type_t type;
146     BOOL is_public;
147     arg_decl_t *args;
148     statement_t *body;
149     struct _function_decl_t *next;
150     struct _function_decl_t *next_prop_func;
151 } function_decl_t;
152
153 typedef struct {
154     statement_t stat;
155     function_decl_t *func_decl;
156 } function_statement_t;
157
158 typedef struct _class_prop_decl_t {
159     BOOL is_public;
160     const WCHAR *name;
161     struct _class_prop_decl_t *next;
162 } class_prop_decl_t;
163
164 typedef struct _class_decl_t {
165     const WCHAR *name;
166     function_decl_t *funcs;
167     class_prop_decl_t *props;
168     struct _class_decl_t *next;
169 } class_decl_t;
170
171 typedef struct _elseif_decl_t {
172     expression_t *expr;
173     statement_t *stat;
174     struct _elseif_decl_t *next;
175 } elseif_decl_t;
176
177 typedef struct {
178     statement_t stat;
179     expression_t *expr;
180     statement_t *if_stat;
181     elseif_decl_t *elseifs;
182     statement_t *else_stat;
183 } if_statement_t;
184
185 typedef struct {
186     statement_t stat;
187     expression_t *expr;
188     statement_t *body;
189 } while_statement_t;
190
191 typedef struct {
192     const WCHAR *code;
193     const WCHAR *ptr;
194     const WCHAR *end;
195
196     BOOL option_explicit;
197     BOOL parse_complete;
198     HRESULT hres;
199
200     int last_token;
201     unsigned last_nl;
202
203     statement_t *stats;
204     statement_t *stats_tail;
205     class_decl_t *class_decls;
206
207     vbsheap_t heap;
208 } parser_ctx_t;
209
210 HRESULT parse_script(parser_ctx_t*,const WCHAR*) DECLSPEC_HIDDEN;
211 void parser_release(parser_ctx_t*) DECLSPEC_HIDDEN;
212 int parser_lex(void*,parser_ctx_t*) DECLSPEC_HIDDEN;
213 void *parser_alloc(parser_ctx_t*,size_t) DECLSPEC_HIDDEN;