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