vbscript: Added class compiler 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_NOT,
38     EXPR_NULL,
39     EXPR_OR,
40     EXPR_STRING,
41     EXPR_SUB,
42     EXPR_ULONG,
43     EXPR_USHORT,
44     EXPR_XOR
45 } expression_type_t;
46
47 typedef struct _expression_t {
48     expression_type_t type;
49     struct _expression_t *next;
50 } expression_t;
51
52 typedef struct {
53     expression_t expr;
54     VARIANT_BOOL value;
55 } bool_expression_t;
56
57 typedef struct {
58     expression_t expr;
59     LONG value;
60 } int_expression_t;
61
62 typedef struct {
63     expression_t expr;
64     double value;
65 } double_expression_t;
66
67 typedef struct {
68     expression_t expr;
69     const WCHAR *value;
70 } string_expression_t;
71
72 typedef struct {
73     expression_t expr;
74     expression_t *subexpr;
75 } unary_expression_t;
76
77 typedef struct {
78     expression_t expr;
79     expression_t *left;
80     expression_t *right;
81 } binary_expression_t;
82
83 typedef struct {
84     expression_t expr;
85     expression_t *obj_expr;
86     const WCHAR *identifier;
87     expression_t *args;
88 } member_expression_t;
89
90 typedef enum {
91     STAT_ASSIGN,
92     STAT_CALL,
93     STAT_DIM,
94     STAT_EXITFUNC,
95     STAT_EXITSUB,
96     STAT_FUNC,
97     STAT_IF
98 } statement_type_t;
99
100 typedef struct _statement_t {
101     statement_type_t type;
102     struct _statement_t *next;
103 } statement_t;
104
105 typedef struct {
106     statement_t stat;
107     member_expression_t *expr;
108 } call_statement_t;
109
110 typedef struct {
111     statement_t stat;
112     member_expression_t *member_expr;
113     expression_t *value_expr;
114 } assign_statement_t;
115
116 typedef struct _dim_decl_t {
117     const WCHAR *name;
118     struct _dim_decl_t *next;
119 } dim_decl_t;
120
121 typedef struct _dim_statement_t {
122     statement_t stat;
123     dim_decl_t *dim_decls;
124 } dim_statement_t;
125
126 typedef struct _arg_decl_t {
127     const WCHAR *name;
128     BOOL by_ref;
129     struct _arg_decl_t *next;
130 } arg_decl_t;
131
132 typedef struct _function_decl_t {
133     const WCHAR *name;
134     function_type_t type;
135     arg_decl_t *args;
136     statement_t *body;
137     struct _function_decl_t *next;
138 } function_decl_t;
139
140 typedef struct _function_statement_t {
141     statement_t stat;
142     function_decl_t *func_decl;
143 } function_statement_t;
144
145 typedef struct _class_decl_t {
146     const WCHAR *name;
147     struct _class_decl_t *next;
148 } class_decl_t;
149
150 typedef struct _elseif_decl_t {
151     expression_t *expr;
152     statement_t *stat;
153     struct _elseif_decl_t *next;
154 } elseif_decl_t;
155
156 typedef struct {
157     statement_t stat;
158     expression_t *expr;
159     statement_t *if_stat;
160     elseif_decl_t *elseifs;
161     statement_t *else_stat;
162 } if_statement_t;
163
164 typedef struct {
165     const WCHAR *code;
166     const WCHAR *ptr;
167     const WCHAR *end;
168
169     BOOL option_explicit;
170     BOOL parse_complete;
171     HRESULT hres;
172
173     int last_token;
174     unsigned last_nl;
175
176     statement_t *stats;
177     statement_t *stats_tail;
178     class_decl_t *class_decls;
179
180     vbsheap_t heap;
181 } parser_ctx_t;
182
183 HRESULT parse_script(parser_ctx_t*,const WCHAR*) DECLSPEC_HIDDEN;
184 void parser_release(parser_ctx_t*) DECLSPEC_HIDDEN;
185 int parser_lex(void*,parser_ctx_t*) DECLSPEC_HIDDEN;
186 void *parser_alloc(parser_ctx_t*,size_t) DECLSPEC_HIDDEN;