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