parse.h 6.28 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * Copyright 2011 Jacek Caban for CodeWeavers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

19
typedef enum {
20
    EXPR_ADD,
21
    EXPR_AND,
22
    EXPR_BOOL,
23
    EXPR_BRACKETS,
24
    EXPR_CALL,
25
    EXPR_CONCAT,
26
    EXPR_DATE,
27
    EXPR_DIV,
28
    EXPR_DOT,
29
    EXPR_DOUBLE,
30
    EXPR_EMPTY,
31
    EXPR_EQUAL,
32
    EXPR_EQV,
33
    EXPR_EXP,
34 35
    EXPR_GT,
    EXPR_GTEQ,
36
    EXPR_IDIV,
37
    EXPR_IMP,
38
    EXPR_INT,
39
    EXPR_IS,
40 41
    EXPR_LT,
    EXPR_LTEQ,
42
    EXPR_ME,
43
    EXPR_MEMBER,
44
    EXPR_MOD,
45
    EXPR_MUL,
46
    EXPR_NEG,
47
    EXPR_NEQUAL,
48
    EXPR_NEW,
49
    EXPR_NOARG, /* not a real expression */
50
    EXPR_NOT,
51
    EXPR_NOTHING,
52
    EXPR_NULL,
53
    EXPR_OR,
54
    EXPR_STRING,
55
    EXPR_SUB,
56
    EXPR_XOR
57 58 59 60 61 62 63
} expression_type_t;

typedef struct _expression_t {
    expression_type_t type;
    struct _expression_t *next;
} expression_t;

64 65 66 67 68
typedef struct {
    expression_t expr;
    VARIANT_BOOL value;
} bool_expression_t;

69 70 71 72 73
typedef struct {
    expression_t expr;
    LONG value;
} int_expression_t;

74 75 76 77 78
typedef struct {
    expression_t expr;
    DATE value;
} date_expression_t;

79 80 81 82 83
typedef struct {
    expression_t expr;
    double value;
} double_expression_t;

84 85 86 87 88
typedef struct {
    expression_t expr;
    const WCHAR *value;
} string_expression_t;

89 90 91 92 93
typedef struct {
    expression_t expr;
    expression_t *subexpr;
} unary_expression_t;

94 95 96 97 98 99
typedef struct {
    expression_t expr;
    expression_t *left;
    expression_t *right;
} binary_expression_t;

100 101 102 103 104 105
typedef struct {
    expression_t expr;
    expression_t *obj_expr;
    const WCHAR *identifier;
} member_expression_t;

106 107 108 109 110 111
typedef struct {
    expression_t expr;
    expression_t *call_expr;
    expression_t *args;
} call_expression_t;

112
typedef enum {
113
    STAT_ASSIGN,
114
    STAT_CALL,
115
    STAT_CONST,
116
    STAT_DIM,
117 118
    STAT_DOUNTIL,
    STAT_DOWHILE,
119
    STAT_EXITDO,
120
    STAT_EXITFOR,
121
    STAT_EXITFUNC,
122
    STAT_EXITPROP,
123
    STAT_EXITSUB,
124
    STAT_FOREACH,
125
    STAT_FORTO,
126
    STAT_FUNC,
127
    STAT_IF,
128
    STAT_ONERROR,
129
    STAT_REDIM,
130
    STAT_SELECT,
131
    STAT_SET,
132
    STAT_STOP,
133
    STAT_UNTIL,
134
    STAT_WHILE,
135
    STAT_WHILELOOP,
136
    STAT_WITH,
137
    STAT_RETVAL
138 139 140 141
} statement_type_t;

typedef struct _statement_t {
    statement_type_t type;
142
    unsigned loc;
143 144 145 146 147
    struct _statement_t *next;
} statement_t;

typedef struct {
    statement_t stat;
148
    call_expression_t *expr;
149 150
} call_statement_t;

151 152
typedef struct {
    statement_t stat;
153
    expression_t *left_expr;
154 155 156
    expression_t *value_expr;
} assign_statement_t;

157 158 159 160 161
typedef struct _dim_list_t {
    unsigned val;
    struct _dim_list_t *next;
} dim_list_t;

162 163
typedef struct _dim_decl_t {
    const WCHAR *name;
164
    BOOL is_array;
165
    BOOL is_public; /* Used only for class members. */
166
    dim_list_t *dims;
167 168 169 170 171 172 173 174
    struct _dim_decl_t *next;
} dim_decl_t;

typedef struct _dim_statement_t {
    statement_t stat;
    dim_decl_t *dim_decls;
} dim_statement_t;

175 176 177 178 179 180 181
typedef struct {
    statement_t stat;
    const WCHAR *identifier;
    BOOL preserve;
    expression_t *dims;
} redim_statement_t;

182 183 184 185 186 187 188 189 190
typedef struct _arg_decl_t {
    const WCHAR *name;
    BOOL by_ref;
    struct _arg_decl_t *next;
} arg_decl_t;

typedef struct _function_decl_t {
    const WCHAR *name;
    function_type_t type;
191
    BOOL is_public;
192
    BOOL is_default;
193 194 195
    arg_decl_t *args;
    statement_t *body;
    struct _function_decl_t *next;
196
    struct _function_decl_t *next_prop_func;
197 198
} function_decl_t;

199
typedef struct {
200 201 202 203
    statement_t stat;
    function_decl_t *func_decl;
} function_statement_t;

204 205
typedef struct _class_decl_t {
    const WCHAR *name;
206
    function_decl_t *funcs;
207
    dim_decl_t *props;
208 209 210
    struct _class_decl_t *next;
} class_decl_t;

211 212 213
typedef struct _elseif_decl_t {
    expression_t *expr;
    statement_t *stat;
214
    unsigned loc;
215 216 217 218 219 220 221 222 223 224 225
    struct _elseif_decl_t *next;
} elseif_decl_t;

typedef struct {
    statement_t stat;
    expression_t *expr;
    statement_t *if_stat;
    elseif_decl_t *elseifs;
    statement_t *else_stat;
} if_statement_t;

226 227 228 229 230 231
typedef struct {
    statement_t stat;
    expression_t *expr;
    statement_t *body;
} while_statement_t;

232 233 234 235 236 237 238 239 240
typedef struct {
    statement_t stat;
    const WCHAR *identifier;
    expression_t *from_expr;
    expression_t *to_expr;
    expression_t *step_expr;
    statement_t *body;
} forto_statement_t;

241 242 243 244 245 246 247
typedef struct {
    statement_t stat;
    const WCHAR *identifier;
    expression_t *group_expr;
    statement_t *body;
} foreach_statement_t;

248 249 250 251 252
typedef struct {
    statement_t stat;
    BOOL resume_next;
} onerror_statement_t;

253 254 255 256 257 258 259 260 261 262 263
typedef struct _const_decl_t {
    const WCHAR *name;
    expression_t *value_expr;
    struct _const_decl_t *next;
} const_decl_t;

typedef struct {
    statement_t stat;
    const_decl_t *decls;
} const_statement_t;

264 265 266 267 268 269 270 271 272 273 274 275
typedef struct _case_clausule_t {
    expression_t *expr;
    statement_t *stat;
    struct _case_clausule_t *next;
} case_clausule_t;

typedef struct {
    statement_t stat;
    expression_t *expr;
    case_clausule_t *case_clausules;
} select_statement_t;

276 277 278 279 280 281
typedef struct {
    statement_t stat;
    expression_t *expr;
    statement_t *body;
} with_statement_t;

282 283 284 285 286
typedef struct {
    statement_t stat;
    expression_t *expr;
} retval_statement_t;

287 288 289 290 291
typedef struct {
    const WCHAR *code;
    const WCHAR *ptr;
    const WCHAR *end;

292
    BOOL option_explicit;
293
    BOOL is_html;
294
    HRESULT hres;
295
    int error_loc;
296
    LCID lcid;
297 298 299

    int last_token;
    unsigned last_nl;
300 301 302

    statement_t *stats;
    statement_t *stats_tail;
303
    class_decl_t *class_decls;
304

305
    heap_pool_t heap;
306 307
} parser_ctx_t;

308
HRESULT parse_script(parser_ctx_t*,const WCHAR*,const WCHAR*,DWORD) DECLSPEC_HIDDEN;
309
void parser_release(parser_ctx_t*) DECLSPEC_HIDDEN;
310
int parser_lex(void*,unsigned*,parser_ctx_t*) DECLSPEC_HIDDEN;
311
void *parser_alloc(parser_ctx_t*,size_t) DECLSPEC_HIDDEN;