parse.h 5.25 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_CONCAT,
24
    EXPR_DIV,
25
    EXPR_DOUBLE,
26
    EXPR_EMPTY,
27
    EXPR_EQUAL,
28
    EXPR_EQV,
29
    EXPR_EXP,
30 31
    EXPR_GT,
    EXPR_GTEQ,
32
    EXPR_IDIV,
33
    EXPR_IMP,
34
    EXPR_IS,
35 36
    EXPR_LT,
    EXPR_LTEQ,
37
    EXPR_ME,
38
    EXPR_MEMBER,
39
    EXPR_MOD,
40
    EXPR_MUL,
41
    EXPR_NEG,
42
    EXPR_NEQUAL,
43
    EXPR_NEW,
44
    EXPR_NOT,
45
    EXPR_NOTHING,
46
    EXPR_NULL,
47
    EXPR_OR,
48
    EXPR_STRING,
49
    EXPR_SUB,
50
    EXPR_ULONG,
51 52
    EXPR_USHORT,
    EXPR_XOR
53 54 55 56 57 58 59
} expression_type_t;

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

60 61 62 63 64
typedef struct {
    expression_t expr;
    VARIANT_BOOL value;
} bool_expression_t;

65 66 67 68 69 70 71 72 73 74
typedef struct {
    expression_t expr;
    LONG value;
} int_expression_t;

typedef struct {
    expression_t expr;
    double value;
} double_expression_t;

75 76 77 78 79
typedef struct {
    expression_t expr;
    const WCHAR *value;
} string_expression_t;

80 81 82 83 84
typedef struct {
    expression_t expr;
    expression_t *subexpr;
} unary_expression_t;

85 86 87 88 89 90
typedef struct {
    expression_t expr;
    expression_t *left;
    expression_t *right;
} binary_expression_t;

91 92 93 94 95 96 97 98
typedef struct {
    expression_t expr;
    expression_t *obj_expr;
    const WCHAR *identifier;
    expression_t *args;
} member_expression_t;

typedef enum {
99
    STAT_ASSIGN,
100
    STAT_CALL,
101
    STAT_CONST,
102
    STAT_DIM,
103 104
    STAT_DOUNTIL,
    STAT_DOWHILE,
105
    STAT_EXITDO,
106
    STAT_EXITFOR,
107
    STAT_EXITFUNC,
108
    STAT_EXITPROP,
109
    STAT_EXITSUB,
110
    STAT_FOREACH,
111
    STAT_FORTO,
112
    STAT_FUNC,
113
    STAT_IF,
114
    STAT_ONERROR,
115
    STAT_SET,
116
    STAT_STOP,
117
    STAT_UNTIL,
118 119
    STAT_WHILE,
    STAT_WHILELOOP
120 121 122 123 124 125 126 127 128 129 130 131
} statement_type_t;

typedef struct _statement_t {
    statement_type_t type;
    struct _statement_t *next;
} statement_t;

typedef struct {
    statement_t stat;
    member_expression_t *expr;
} call_statement_t;

132 133 134 135 136 137
typedef struct {
    statement_t stat;
    member_expression_t *member_expr;
    expression_t *value_expr;
} assign_statement_t;

138 139 140 141 142 143 144 145 146 147
typedef struct _dim_decl_t {
    const WCHAR *name;
    struct _dim_decl_t *next;
} dim_decl_t;

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

148 149 150 151 152 153 154 155 156
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;
157
    BOOL is_public;
158 159 160
    arg_decl_t *args;
    statement_t *body;
    struct _function_decl_t *next;
161
    struct _function_decl_t *next_prop_func;
162 163
} function_decl_t;

164
typedef struct {
165 166 167 168
    statement_t stat;
    function_decl_t *func_decl;
} function_statement_t;

169 170 171 172 173 174
typedef struct _class_prop_decl_t {
    BOOL is_public;
    const WCHAR *name;
    struct _class_prop_decl_t *next;
} class_prop_decl_t;

175 176
typedef struct _class_decl_t {
    const WCHAR *name;
177
    function_decl_t *funcs;
178
    class_prop_decl_t *props;
179 180 181
    struct _class_decl_t *next;
} class_decl_t;

182 183 184 185 186 187 188 189 190 191 192 193 194 195
typedef struct _elseif_decl_t {
    expression_t *expr;
    statement_t *stat;
    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;

196 197 198 199 200 201
typedef struct {
    statement_t stat;
    expression_t *expr;
    statement_t *body;
} while_statement_t;

202 203 204 205 206 207 208 209 210
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;

211 212 213 214 215 216 217
typedef struct {
    statement_t stat;
    const WCHAR *identifier;
    expression_t *group_expr;
    statement_t *body;
} foreach_statement_t;

218 219 220 221 222
typedef struct {
    statement_t stat;
    BOOL resume_next;
} onerror_statement_t;

223 224 225 226 227 228 229 230 231 232 233
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;

234 235 236 237 238
typedef struct {
    const WCHAR *code;
    const WCHAR *ptr;
    const WCHAR *end;

239
    BOOL option_explicit;
240 241
    BOOL parse_complete;
    HRESULT hres;
242 243 244

    int last_token;
    unsigned last_nl;
245 246 247

    statement_t *stats;
    statement_t *stats_tail;
248
    class_decl_t *class_decls;
249 250

    vbsheap_t heap;
251 252
} parser_ctx_t;

253
HRESULT parse_script(parser_ctx_t*,const WCHAR*) DECLSPEC_HIDDEN;
254
void parser_release(parser_ctx_t*) DECLSPEC_HIDDEN;
255
int parser_lex(void*,parser_ctx_t*) DECLSPEC_HIDDEN;
256
void *parser_alloc(parser_ctx_t*,size_t) DECLSPEC_HIDDEN;