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