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

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

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

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

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

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

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

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

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

typedef enum {
100
    STAT_ASSIGN,
101
    STAT_CALL,
102
    STAT_CONST,
103
    STAT_DIM,
104 105
    STAT_DOUNTIL,
    STAT_DOWHILE,
106
    STAT_EXITDO,
107
    STAT_EXITFOR,
108
    STAT_EXITFUNC,
109
    STAT_EXITPROP,
110
    STAT_EXITSUB,
111
    STAT_FOREACH,
112
    STAT_FORTO,
113
    STAT_FUNC,
114
    STAT_IF,
115
    STAT_ONERROR,
116
    STAT_SELECT,
117
    STAT_SET,
118
    STAT_STOP,
119
    STAT_UNTIL,
120 121
    STAT_WHILE,
    STAT_WHILELOOP
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;
132
    BOOL is_strict;
133 134
} call_statement_t;

135 136 137 138 139 140
typedef struct {
    statement_t stat;
    member_expression_t *member_expr;
    expression_t *value_expr;
} assign_statement_t;

141 142 143 144 145 146 147 148 149 150
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;

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

167
typedef struct {
168 169 170 171
    statement_t stat;
    function_decl_t *func_decl;
} function_statement_t;

172 173 174 175 176 177
typedef struct _class_prop_decl_t {
    BOOL is_public;
    const WCHAR *name;
    struct _class_prop_decl_t *next;
} class_prop_decl_t;

178 179
typedef struct _class_decl_t {
    const WCHAR *name;
180
    function_decl_t *funcs;
181
    class_prop_decl_t *props;
182 183 184
    struct _class_decl_t *next;
} class_decl_t;

185 186 187 188 189 190 191 192 193 194 195 196 197 198
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;

199 200 201 202 203 204
typedef struct {
    statement_t stat;
    expression_t *expr;
    statement_t *body;
} while_statement_t;

205 206 207 208 209 210 211 212 213
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;

214 215 216 217 218 219 220
typedef struct {
    statement_t stat;
    const WCHAR *identifier;
    expression_t *group_expr;
    statement_t *body;
} foreach_statement_t;

221 222 223 224 225
typedef struct {
    statement_t stat;
    BOOL resume_next;
} onerror_statement_t;

226 227 228 229 230 231 232 233 234 235 236
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;

237 238 239 240 241 242 243 244 245 246 247 248
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;

249 250 251 252 253
typedef struct {
    const WCHAR *code;
    const WCHAR *ptr;
    const WCHAR *end;

254
    BOOL option_explicit;
255 256
    BOOL parse_complete;
    HRESULT hres;
257 258 259

    int last_token;
    unsigned last_nl;
260 261 262

    statement_t *stats;
    statement_t *stats_tail;
263
    class_decl_t *class_decls;
264 265

    vbsheap_t heap;
266 267
} parser_ctx_t;

268
HRESULT parse_script(parser_ctx_t*,const WCHAR*) DECLSPEC_HIDDEN;
269
void parser_release(parser_ctx_t*) DECLSPEC_HIDDEN;
270
int parser_lex(void*,parser_ctx_t*) DECLSPEC_HIDDEN;
271
void *parser_alloc(parser_ctx_t*,size_t) DECLSPEC_HIDDEN;