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