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