parse.h 5.67 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_NOARG, /* not a real expression */
46
    EXPR_NOT,
47
    EXPR_NOTHING,
48
    EXPR_NULL,
49
    EXPR_OR,
50
    EXPR_STRING,
51
    EXPR_SUB,
52
    EXPR_ULONG,
53 54
    EXPR_USHORT,
    EXPR_XOR
55 56 57 58 59 60 61
} expression_type_t;

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

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

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

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

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

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

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

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

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

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

142 143 144 145 146
typedef struct _dim_list_t {
    unsigned val;
    struct _dim_list_t *next;
} dim_list_t;

147 148
typedef struct _dim_decl_t {
    const WCHAR *name;
149
    BOOL is_array;
150
    BOOL is_public; /* Used only for class members. */
151
    dim_list_t *dims;
152 153 154 155 156 157 158 159
    struct _dim_decl_t *next;
} dim_decl_t;

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

160 161 162 163 164 165 166 167 168
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;
169
    BOOL is_public;
170 171 172
    arg_decl_t *args;
    statement_t *body;
    struct _function_decl_t *next;
173
    struct _function_decl_t *next_prop_func;
174 175
} function_decl_t;

176
typedef struct {
177 178 179 180
    statement_t stat;
    function_decl_t *func_decl;
} function_statement_t;

181 182
typedef struct _class_decl_t {
    const WCHAR *name;
183
    function_decl_t *funcs;
184
    dim_decl_t *props;
185 186 187
    struct _class_decl_t *next;
} class_decl_t;

188 189 190 191 192 193 194 195 196 197 198 199 200 201
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;

202 203 204 205 206 207
typedef struct {
    statement_t stat;
    expression_t *expr;
    statement_t *body;
} while_statement_t;

208 209 210 211 212 213 214 215 216
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;

217 218 219 220 221 222 223
typedef struct {
    statement_t stat;
    const WCHAR *identifier;
    expression_t *group_expr;
    statement_t *body;
} foreach_statement_t;

224 225 226 227 228
typedef struct {
    statement_t stat;
    BOOL resume_next;
} onerror_statement_t;

229 230 231 232 233 234 235 236 237 238 239
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;

240 241 242 243 244 245 246 247 248 249 250 251
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;

252 253 254 255 256
typedef struct {
    const WCHAR *code;
    const WCHAR *ptr;
    const WCHAR *end;

257
    BOOL option_explicit;
258
    BOOL parse_complete;
259
    BOOL is_html;
260
    HRESULT hres;
261 262 263

    int last_token;
    unsigned last_nl;
264 265 266

    statement_t *stats;
    statement_t *stats_tail;
267
    class_decl_t *class_decls;
268

269
    heap_pool_t heap;
270 271
} parser_ctx_t;

272
HRESULT parse_script(parser_ctx_t*,const WCHAR*,const WCHAR*) DECLSPEC_HIDDEN;
273
void parser_release(parser_ctx_t*) DECLSPEC_HIDDEN;
274
int parser_lex(void*,parser_ctx_t*) DECLSPEC_HIDDEN;
275
void *parser_alloc(parser_ctx_t*,size_t) DECLSPEC_HIDDEN;