vbscript: Don't leak memory in parser.
[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_BOOL,
21     EXPR_EMPTY,
22     EXPR_EQUAL,
23     EXPR_MEMBER,
24     EXPR_NOT,
25     EXPR_NULL,
26     EXPR_STRING
27 } expression_type_t;
28
29 typedef struct _expression_t {
30     expression_type_t type;
31     struct _expression_t *next;
32 } expression_t;
33
34 typedef struct {
35     expression_t expr;
36     VARIANT_BOOL value;
37 } bool_expression_t;
38
39 typedef struct {
40     expression_t expr;
41     const WCHAR *value;
42 } string_expression_t;
43
44 typedef struct {
45     expression_t expr;
46     expression_t *subexpr;
47 } unary_expression_t;
48
49 typedef struct {
50     expression_t expr;
51     expression_t *left;
52     expression_t *right;
53 } binary_expression_t;
54
55 typedef struct {
56     expression_t expr;
57     expression_t *obj_expr;
58     const WCHAR *identifier;
59     expression_t *args;
60 } member_expression_t;
61
62 typedef enum {
63     STAT_CALL
64 } statement_type_t;
65
66 typedef struct _statement_t {
67     statement_type_t type;
68     struct _statement_t *next;
69 } statement_t;
70
71 typedef struct {
72     statement_t stat;
73     member_expression_t *expr;
74 } call_statement_t;
75
76 typedef struct {
77     const WCHAR *code;
78     const WCHAR *ptr;
79     const WCHAR *end;
80
81     BOOL option_explicit;
82     BOOL parse_complete;
83     HRESULT hres;
84
85     int last_token;
86     unsigned last_nl;
87
88     statement_t *stats;
89     statement_t *stats_tail;
90
91     vbsheap_t heap;
92 } parser_ctx_t;
93
94 HRESULT parse_script(parser_ctx_t*,const WCHAR*) DECLSPEC_HIDDEN;
95 void parser_release(parser_ctx_t*) DECLSPEC_HIDDEN;
96 int parser_lex(void*,parser_ctx_t*) DECLSPEC_HIDDEN;
97 void *parser_alloc(parser_ctx_t*,size_t) DECLSPEC_HIDDEN;