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