2 * Copyright 2011 Jacek Caban for CodeWeavers
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.
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.
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
24 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(vbscript);
29 #define YYLEX_PARAM ctx
30 #define YYPARSE_PARAM ctx
32 static int parser_error(const char*);
34 static void parse_complete(parser_ctx_t*,BOOL);
36 static void source_add_statement(parser_ctx_t*,statement_t*);
37 static void source_add_class(parser_ctx_t*,class_decl_t*);
39 static void *new_expression(parser_ctx_t*,expression_type_t,size_t);
40 static expression_t *new_bool_expression(parser_ctx_t*,VARIANT_BOOL);
41 static expression_t *new_string_expression(parser_ctx_t*,const WCHAR*);
42 static expression_t *new_long_expression(parser_ctx_t*,expression_type_t,LONG);
43 static expression_t *new_double_expression(parser_ctx_t*,double);
44 static expression_t *new_unary_expression(parser_ctx_t*,expression_type_t,expression_t*);
45 static expression_t *new_binary_expression(parser_ctx_t*,expression_type_t,expression_t*,expression_t*);
46 static expression_t *new_new_expression(parser_ctx_t*,const WCHAR*);
48 static member_expression_t *new_member_expression(parser_ctx_t*,expression_t*,const WCHAR*);
50 static void *new_statement(parser_ctx_t*,statement_type_t,size_t);
51 static statement_t *new_call_statement(parser_ctx_t*,member_expression_t*);
52 static statement_t *new_assign_statement(parser_ctx_t*,member_expression_t*,expression_t*);
53 static statement_t *new_set_statement(parser_ctx_t*,member_expression_t*,expression_t*);
54 static statement_t *new_dim_statement(parser_ctx_t*,dim_decl_t*);
55 static statement_t *new_while_statement(parser_ctx_t*,statement_type_t,expression_t*,statement_t*);
56 static statement_t *new_if_statement(parser_ctx_t*,expression_t*,statement_t*,elseif_decl_t*,statement_t*);
57 static statement_t *new_function_statement(parser_ctx_t*,function_decl_t*);
58 static statement_t *new_onerror_statement(parser_ctx_t*,BOOL);
60 static dim_decl_t *new_dim_decl(parser_ctx_t*,const WCHAR*,dim_decl_t*);
61 static elseif_decl_t *new_elseif_decl(parser_ctx_t*,expression_t*,statement_t*);
62 static function_decl_t *new_function_decl(parser_ctx_t*,const WCHAR*,function_type_t,unsigned,arg_decl_t*,statement_t*);
63 static arg_decl_t *new_argument_decl(parser_ctx_t*,const WCHAR*,BOOL);
65 static class_decl_t *new_class_decl(parser_ctx_t*);
66 static class_decl_t *add_class_function(parser_ctx_t*,class_decl_t*,function_decl_t*);
67 static class_decl_t *add_variant_prop(parser_ctx_t*,class_decl_t*,const WCHAR*,unsigned);
69 #define STORAGE_IS_PRIVATE 1
70 #define STORAGE_IS_DEFAULT 2
72 #define CHECK_ERROR if(((parser_ctx_t*)ctx)->hres != S_OK) YYABORT
81 statement_t *statement;
82 expression_t *expression;
83 member_expression_t *member;
84 elseif_decl_t *elseif;
86 function_decl_t *func_decl;
88 class_decl_t *class_decl;
95 %token tEOF tNL tREM tEMPTYBRACKETS
97 %token tNOT tAND tOR tXOR tEQV tIMP tNEQ
98 %token tIS tLTEQ tGTEQ tMOD
99 %token tCALL tDIM tSUB tFUNCTION tPROPERTY tGET tLET
100 %token tIF tELSE tELSEIF tEND tTHEN tEXIT
101 %token tWHILE tWEND tDO tLOOP tUNTIL
103 %token tOPTION tEXPLICIT
105 %token tNOTHING tEMPTY tNULL
106 %token tCLASS tSET tNEW tPUBLIC tPRIVATE tDEFAULT tME
107 %token tERROR tNEXT tON tRESUME tGOTO
108 %token <string> tIdentifier tString
109 %token <lng> tLong tShort
112 %type <statement> Statement StatementNl StatementsNl StatementsNl_opt IfStatement Else_opt
113 %type <expression> Expression LiteralExpression PrimaryExpression EqualityExpression CallExpression
114 %type <expression> ConcatExpression AdditiveExpression ModExpression IntdivExpression MultiplicativeExpression ExpExpression
115 %type <expression> NotExpression UnaryExpression AndExpression OrExpression XorExpression EqvExpression
116 %type <member> MemberExpression
117 %type <expression> Arguments_opt ArgumentList_opt ArgumentList
118 %type <bool> OptionExplicit_opt DoType
119 %type <arg_decl> ArgumentsDecl_opt ArgumentDeclList ArgumentDecl
120 %type <func_decl> FunctionDecl PropertyDecl
121 %type <elseif> ElseIfs_opt ElseIfs ElseIf
122 %type <class_decl> ClassDeclaration ClassBody
123 %type <uint> Storage Storage_opt
124 %type <dim_decl> DimDeclList
129 : OptionExplicit_opt SourceElements tEOF { parse_complete(ctx, $1); }
132 : /* empty */ { $$ = FALSE; }
133 | tOPTION tEXPLICIT tNL { $$ = TRUE; }
137 | SourceElements StatementNl { source_add_statement(ctx, $2); }
138 | SourceElements ClassDeclaration { source_add_class(ctx, $2); }
141 : /* empty */ { $$ = NULL; }
142 | StatementsNl { $$ = $1; }
145 : StatementNl { $$ = $1; }
146 | StatementNl StatementsNl { $1->next = $2; $$ = $1; }
149 : Statement tNL { $$ = $1; }
152 : MemberExpression ArgumentList_opt { $1->args = $2; $$ = new_call_statement(ctx, $1); CHECK_ERROR; }
153 | tCALL MemberExpression Arguments_opt { $2->args = $3; $$ = new_call_statement(ctx, $2); CHECK_ERROR; }
154 | MemberExpression Arguments_opt '=' Expression
155 { $1->args = $2; $$ = new_assign_statement(ctx, $1, $4); CHECK_ERROR; }
156 | tDIM DimDeclList { $$ = new_dim_statement(ctx, $2); CHECK_ERROR; }
157 | IfStatement { $$ = $1; }
158 | tWHILE Expression tNL StatementsNl_opt tWEND
159 { $$ = new_while_statement(ctx, STAT_WHILE, $2, $4); CHECK_ERROR; }
160 | tDO DoType Expression tNL StatementsNl_opt tLOOP
161 { $$ = new_while_statement(ctx, $2 ? STAT_WHILELOOP : STAT_UNTIL, $3, $5);
163 | tDO tNL StatementsNl_opt tLOOP DoType Expression
164 { $$ = new_while_statement(ctx, $5 ? STAT_DOWHILE : STAT_DOUNTIL, $6, $3);
166 | FunctionDecl { $$ = new_function_statement(ctx, $1); CHECK_ERROR; }
167 | tEXIT tDO { $$ = new_statement(ctx, STAT_EXITDO, 0); CHECK_ERROR; }
168 | tEXIT tFUNCTION { $$ = new_statement(ctx, STAT_EXITFUNC, 0); CHECK_ERROR; }
169 | tEXIT tPROPERTY { $$ = new_statement(ctx, STAT_EXITPROP, 0); CHECK_ERROR; }
170 | tEXIT tSUB { $$ = new_statement(ctx, STAT_EXITSUB, 0); CHECK_ERROR; }
171 | tSET MemberExpression Arguments_opt '=' Expression
172 { $2->args = $3; $$ = new_set_statement(ctx, $2, $5); CHECK_ERROR; }
173 | tSTOP { $$ = new_statement(ctx, STAT_STOP, 0); CHECK_ERROR; }
174 | tON tERROR tRESUME tNEXT { $$ = new_onerror_statement(ctx, TRUE); CHECK_ERROR; }
175 | tON tERROR tGOTO '0' { $$ = new_onerror_statement(ctx, FALSE); CHECK_ERROR; }
178 : tIdentifier { $$ = new_member_expression(ctx, NULL, $1); CHECK_ERROR; }
179 | CallExpression '.' tIdentifier { $$ = new_member_expression(ctx, $1, $3); CHECK_ERROR; }
181 DimDeclList /* FIXME: Support arrays */
182 : tIdentifier { $$ = new_dim_decl(ctx, $1, NULL); CHECK_ERROR; }
183 | tIdentifier ',' DimDeclList { $$ = new_dim_decl(ctx, $1, $3); CHECK_ERROR; }
186 : tWHILE { $$ = TRUE; }
187 | tUNTIL { $$ = FALSE; }
190 : tIF Expression tTHEN tNL StatementsNl ElseIfs_opt Else_opt tEND tIF
191 { $$ = new_if_statement(ctx, $2, $5, $6, $7); CHECK_ERROR; }
192 /* FIXME: short if statement */
195 : /* empty */ { $$ = NULL; }
196 | ElseIfs { $$ = $1; }
199 : ElseIf { $$ = $1; }
200 | ElseIf ElseIfs { $1->next = $2; $$ = $1; }
203 : tELSEIF Expression tTHEN tNL StatementsNl
204 { $$ = new_elseif_decl(ctx, $2, $5); }
207 : /* empty */ { $$ = NULL; }
208 | tELSE tNL StatementsNl { $$ = $3; }
211 : EmptyBrackets_opt { $$ = NULL; }
212 | '(' ArgumentList ')' { $$ = $2; }
215 : EmptyBrackets_opt { $$ = NULL; }
216 | ArgumentList { $$ = $1; }
219 : Expression { $$ = $1; }
220 | Expression ',' ArgumentList { $1->next = $3; $$ = $1; }
227 : EqvExpression { $$ = $1; }
228 | Expression tIMP EqvExpression { $$ = new_binary_expression(ctx, EXPR_IMP, $1, $3); CHECK_ERROR; }
231 : XorExpression { $$ = $1; }
232 | EqvExpression tEQV XorExpression { $$ = new_binary_expression(ctx, EXPR_EQV, $1, $3); CHECK_ERROR; }
235 : OrExpression { $$ = $1; }
236 | XorExpression tXOR OrExpression { $$ = new_binary_expression(ctx, EXPR_XOR, $1, $3); CHECK_ERROR; }
239 : AndExpression { $$ = $1; }
240 | OrExpression tOR AndExpression { $$ = new_binary_expression(ctx, EXPR_OR, $1, $3); CHECK_ERROR; }
243 : NotExpression { $$ = $1; }
244 | AndExpression tAND NotExpression { $$ = new_binary_expression(ctx, EXPR_AND, $1, $3); CHECK_ERROR; }
247 : EqualityExpression { $$ = $1; }
248 | tNOT NotExpression { $$ = new_unary_expression(ctx, EXPR_NOT, $2); CHECK_ERROR; }
251 : ConcatExpression { $$ = $1; }
252 | EqualityExpression '=' ConcatExpression { $$ = new_binary_expression(ctx, EXPR_EQUAL, $1, $3); CHECK_ERROR; }
253 | EqualityExpression tNEQ ConcatExpression { $$ = new_binary_expression(ctx, EXPR_NEQUAL, $1, $3); CHECK_ERROR; }
254 | EqualityExpression '>' ConcatExpression { $$ = new_binary_expression(ctx, EXPR_GT, $1, $3); CHECK_ERROR; }
255 | EqualityExpression '<' ConcatExpression { $$ = new_binary_expression(ctx, EXPR_LT, $1, $3); CHECK_ERROR; }
256 | EqualityExpression tGTEQ ConcatExpression { $$ = new_binary_expression(ctx, EXPR_GTEQ, $1, $3); CHECK_ERROR; }
257 | EqualityExpression tLTEQ ConcatExpression { $$ = new_binary_expression(ctx, EXPR_LTEQ, $1, $3); CHECK_ERROR; }
258 | EqualityExpression tIS ConcatExpression { $$ = new_binary_expression(ctx, EXPR_IS, $1, $3); CHECK_ERROR; }
261 : AdditiveExpression { $$ = $1; }
262 | ConcatExpression '&' AdditiveExpression { $$ = new_binary_expression(ctx, EXPR_CONCAT, $1, $3); CHECK_ERROR; }
265 : ModExpression { $$ = $1; }
266 | AdditiveExpression '+' ModExpression { $$ = new_binary_expression(ctx, EXPR_ADD, $1, $3); CHECK_ERROR; }
267 | AdditiveExpression '-' ModExpression { $$ = new_binary_expression(ctx, EXPR_SUB, $1, $3); CHECK_ERROR; }
270 : IntdivExpression { $$ = $1; }
271 | ModExpression tMOD IntdivExpression { $$ = new_binary_expression(ctx, EXPR_MOD, $1, $3); CHECK_ERROR; }
274 : MultiplicativeExpression { $$ = $1; }
275 | IntdivExpression '\\' MultiplicativeExpression
276 { $$ = new_binary_expression(ctx, EXPR_IDIV, $1, $3); CHECK_ERROR; }
278 MultiplicativeExpression
279 : ExpExpression { $$ = $1; }
280 | MultiplicativeExpression '*' ExpExpression
281 { $$ = new_binary_expression(ctx, EXPR_MUL, $1, $3); CHECK_ERROR; }
282 | MultiplicativeExpression '/' ExpExpression
283 { $$ = new_binary_expression(ctx, EXPR_DIV, $1, $3); CHECK_ERROR; }
286 : UnaryExpression { $$ = $1; }
287 | ExpExpression '^' UnaryExpression { $$ = new_binary_expression(ctx, EXPR_EXP, $1, $3); CHECK_ERROR; }
290 : LiteralExpression { $$ = $1; }
291 | CallExpression { $$ = $1; }
292 | tNEW tIdentifier { $$ = new_new_expression(ctx, $2); CHECK_ERROR; }
293 | '-' UnaryExpression { $$ = new_unary_expression(ctx, EXPR_NEG, $2); CHECK_ERROR; }
296 : PrimaryExpression { $$ = $1; }
297 | MemberExpression Arguments_opt { $1->args = $2; $$ = &$1->expr; }
300 : tTRUE { $$ = new_bool_expression(ctx, VARIANT_TRUE); CHECK_ERROR; }
301 | tFALSE { $$ = new_bool_expression(ctx, VARIANT_FALSE); CHECK_ERROR; }
302 | tString { $$ = new_string_expression(ctx, $1); CHECK_ERROR; }
303 | tShort { $$ = new_long_expression(ctx, EXPR_USHORT, $1); CHECK_ERROR; }
304 | '0' { $$ = new_long_expression(ctx, EXPR_USHORT, 0); CHECK_ERROR; }
305 | tLong { $$ = new_long_expression(ctx, EXPR_ULONG, $1); CHECK_ERROR; }
306 | tDouble { $$ = new_double_expression(ctx, $1); CHECK_ERROR; }
307 | tEMPTY { $$ = new_expression(ctx, EXPR_EMPTY, 0); CHECK_ERROR; }
308 | tNULL { $$ = new_expression(ctx, EXPR_NULL, 0); CHECK_ERROR; }
309 | tNOTHING { $$ = new_expression(ctx, EXPR_NOTHING, 0); CHECK_ERROR; }
312 : '(' Expression ')' { $$ = $2; }
313 | tME { $$ = new_expression(ctx, EXPR_ME, 0); CHECK_ERROR; }
316 : tCLASS tIdentifier tNL ClassBody tEND tCLASS tNL { $4->name = $2; $$ = $4; }
319 : /* empty */ { $$ = new_class_decl(ctx); }
320 | FunctionDecl tNL ClassBody { $$ = add_class_function(ctx, $3, $1); CHECK_ERROR; }
321 | Storage tIdentifier tNL ClassBody { $$ = add_variant_prop(ctx, $4, $2, $1); CHECK_ERROR; }
322 | PropertyDecl tNL ClassBody { $$ = add_class_function(ctx, $3, $1); CHECK_ERROR; }
325 : Storage_opt tPROPERTY tGET tIdentifier EmptyBrackets_opt tNL StatementsNl_opt tEND tPROPERTY
326 { $$ = new_function_decl(ctx, $4, FUNC_PROPGET, $1, NULL, $7); CHECK_ERROR; }
327 | Storage_opt tPROPERTY tLET tIdentifier '(' ArgumentDecl ')' tNL StatementsNl_opt tEND tPROPERTY
328 { $$ = new_function_decl(ctx, $4, FUNC_PROPLET, $1, $6, $9); CHECK_ERROR; }
329 | Storage_opt tPROPERTY tSET tIdentifier '(' ArgumentDecl ')' tNL StatementsNl_opt tEND tPROPERTY
330 { $$ = new_function_decl(ctx, $4, FUNC_PROPSET, $1, $6, $9); CHECK_ERROR; }
333 : Storage_opt tSUB tIdentifier ArgumentsDecl_opt tNL StatementsNl_opt tEND tSUB
334 { $$ = new_function_decl(ctx, $3, FUNC_SUB, $1, $4, $6); CHECK_ERROR; }
335 | Storage_opt tFUNCTION tIdentifier ArgumentsDecl_opt tNL StatementsNl_opt tEND tFUNCTION
336 { $$ = new_function_decl(ctx, $3, FUNC_FUNCTION, $1, $4, $6); CHECK_ERROR; }
339 : /* empty*/ { $$ = 0; }
340 | Storage { $$ = $1; }
343 : tPUBLIC tDEFAULT { $$ = STORAGE_IS_DEFAULT; }
344 | tPUBLIC { $$ = 0; }
345 | tPRIVATE { $$ = STORAGE_IS_PRIVATE; }
348 : EmptyBrackets_opt { $$ = NULL; }
349 | '(' ArgumentDeclList ')' { $$ = $2; }
352 : ArgumentDecl { $$ = $1; }
353 | ArgumentDecl ',' ArgumentDeclList { $1->next = $3; $$ = $1; }
356 : tIdentifier { $$ = new_argument_decl(ctx, $1, TRUE); }
357 | tBYREF tIdentifier { $$ = new_argument_decl(ctx, $2, TRUE); }
358 | tBYVAL tIdentifier { $$ = new_argument_decl(ctx, $2, FALSE); }
362 static int parser_error(const char *str)
367 static void source_add_statement(parser_ctx_t *ctx, statement_t *stat)
370 ctx->stats_tail->next = stat;
371 ctx->stats_tail = stat;
373 ctx->stats = ctx->stats_tail = stat;
377 static void source_add_class(parser_ctx_t *ctx, class_decl_t *class_decl)
379 class_decl->next = ctx->class_decls;
380 ctx->class_decls = class_decl;
383 static void parse_complete(parser_ctx_t *ctx, BOOL option_explicit)
385 ctx->parse_complete = TRUE;
386 ctx->option_explicit = option_explicit;
389 static void *new_expression(parser_ctx_t *ctx, expression_type_t type, size_t size)
393 expr = parser_alloc(ctx, size ? size : sizeof(*expr));
402 static expression_t *new_bool_expression(parser_ctx_t *ctx, VARIANT_BOOL value)
404 bool_expression_t *expr;
406 expr = new_expression(ctx, EXPR_BOOL, sizeof(*expr));
414 static expression_t *new_string_expression(parser_ctx_t *ctx, const WCHAR *value)
416 string_expression_t *expr;
418 expr = new_expression(ctx, EXPR_STRING, sizeof(*expr));
426 static expression_t *new_long_expression(parser_ctx_t *ctx, expression_type_t type, LONG value)
428 int_expression_t *expr;
430 expr = new_expression(ctx, type, sizeof(*expr));
438 static expression_t *new_double_expression(parser_ctx_t *ctx, double value)
440 double_expression_t *expr;
442 expr = new_expression(ctx, EXPR_DOUBLE, sizeof(*expr));
450 static expression_t *new_unary_expression(parser_ctx_t *ctx, expression_type_t type, expression_t *subexpr)
452 unary_expression_t *expr;
454 expr = new_expression(ctx, type, sizeof(*expr));
458 expr->subexpr = subexpr;
462 static expression_t *new_binary_expression(parser_ctx_t *ctx, expression_type_t type, expression_t *left, expression_t *right)
464 binary_expression_t *expr;
466 expr = new_expression(ctx, type, sizeof(*expr));
475 static member_expression_t *new_member_expression(parser_ctx_t *ctx, expression_t *obj_expr, const WCHAR *identifier)
477 member_expression_t *expr;
479 expr = new_expression(ctx, EXPR_MEMBER, sizeof(*expr));
483 expr->obj_expr = obj_expr;
484 expr->identifier = identifier;
489 static expression_t *new_new_expression(parser_ctx_t *ctx, const WCHAR *identifier)
491 string_expression_t *expr;
493 expr = new_expression(ctx, EXPR_NEW, sizeof(*expr));
497 expr->value = identifier;
501 static void *new_statement(parser_ctx_t *ctx, statement_type_t type, size_t size)
505 stat = parser_alloc(ctx, size ? size : sizeof(*stat));
514 static statement_t *new_call_statement(parser_ctx_t *ctx, member_expression_t *expr)
516 call_statement_t *stat;
518 stat = new_statement(ctx, STAT_CALL, sizeof(*stat));
526 static statement_t *new_assign_statement(parser_ctx_t *ctx, member_expression_t *left, expression_t *right)
528 assign_statement_t *stat;
530 stat = new_statement(ctx, STAT_ASSIGN, sizeof(*stat));
534 stat->member_expr = left;
535 stat->value_expr = right;
539 static statement_t *new_set_statement(parser_ctx_t *ctx, member_expression_t *left, expression_t *right)
541 assign_statement_t *stat;
543 stat = new_statement(ctx, STAT_SET, sizeof(*stat));
547 stat->member_expr = left;
548 stat->value_expr = right;
552 static dim_decl_t *new_dim_decl(parser_ctx_t *ctx, const WCHAR *name, dim_decl_t *next)
556 decl = parser_alloc(ctx, sizeof(*decl));
565 static statement_t *new_dim_statement(parser_ctx_t *ctx, dim_decl_t *decls)
567 dim_statement_t *stat;
569 stat = new_statement(ctx, STAT_DIM, sizeof(*stat));
573 stat->dim_decls = decls;
577 static elseif_decl_t *new_elseif_decl(parser_ctx_t *ctx, expression_t *expr, statement_t *stat)
581 decl = parser_alloc(ctx, sizeof(*decl));
591 static statement_t *new_while_statement(parser_ctx_t *ctx, statement_type_t type, expression_t *expr, statement_t *body)
593 while_statement_t *stat;
595 stat = new_statement(ctx, type, sizeof(*stat));
604 static statement_t *new_if_statement(parser_ctx_t *ctx, expression_t *expr, statement_t *if_stat, elseif_decl_t *elseif_decl,
605 statement_t *else_stat)
607 if_statement_t *stat;
609 stat = new_statement(ctx, STAT_IF, sizeof(*stat));
614 stat->if_stat = if_stat;
615 stat->elseifs = elseif_decl;
616 stat->else_stat = else_stat;
620 static statement_t *new_onerror_statement(parser_ctx_t *ctx, BOOL resume_next)
622 onerror_statement_t *stat;
624 stat = new_statement(ctx, STAT_ONERROR, sizeof(*stat));
628 stat->resume_next = resume_next;
632 static arg_decl_t *new_argument_decl(parser_ctx_t *ctx, const WCHAR *name, BOOL by_ref)
634 arg_decl_t *arg_decl;
636 arg_decl = parser_alloc(ctx, sizeof(*arg_decl));
640 arg_decl->name = name;
641 arg_decl->by_ref = by_ref;
642 arg_decl->next = NULL;
646 static function_decl_t *new_function_decl(parser_ctx_t *ctx, const WCHAR *name, function_type_t type,
647 unsigned storage_flags, arg_decl_t *arg_decl, statement_t *body)
649 function_decl_t *decl;
651 if(storage_flags & STORAGE_IS_DEFAULT) {
652 if(type == FUNC_PROPGET) {
655 FIXME("Invalid default property\n");
661 decl = parser_alloc(ctx, sizeof(*decl));
667 decl->is_public = !(storage_flags & STORAGE_IS_PRIVATE);
668 decl->args = arg_decl;
671 decl->next_prop_func = NULL;
675 static statement_t *new_function_statement(parser_ctx_t *ctx, function_decl_t *decl)
677 function_statement_t *stat;
679 stat = new_statement(ctx, STAT_FUNC, sizeof(*stat));
683 stat->func_decl = decl;
687 static class_decl_t *new_class_decl(parser_ctx_t *ctx)
689 class_decl_t *class_decl;
691 class_decl = parser_alloc(ctx, sizeof(*class_decl));
695 class_decl->funcs = NULL;
696 class_decl->props = NULL;
697 class_decl->next = NULL;
701 static class_decl_t *add_class_function(parser_ctx_t *ctx, class_decl_t *class_decl, function_decl_t *decl)
703 function_decl_t *iter;
705 for(iter = class_decl->funcs; iter; iter = iter->next) {
706 if(!strcmpiW(iter->name, decl->name)) {
707 if(decl->type == FUNC_SUB || decl->type == FUNC_FUNCTION) {
708 FIXME("Redefinition of %s::%s\n", debugstr_w(class_decl->name), debugstr_w(decl->name));
714 if(iter->type == decl->type) {
715 FIXME("Redefinition of %s::%s\n", debugstr_w(class_decl->name), debugstr_w(decl->name));
719 if(!iter->next_prop_func)
721 iter = iter->next_prop_func;
724 iter->next_prop_func = decl;
729 decl->next = class_decl->funcs;
730 class_decl->funcs = decl;
734 static class_decl_t *add_variant_prop(parser_ctx_t *ctx, class_decl_t *class_decl, const WCHAR *identifier, unsigned storage_flags)
736 class_prop_decl_t *prop;
738 if(storage_flags & STORAGE_IS_DEFAULT) {
739 FIXME("variant prop van't be default value\n");
744 prop = parser_alloc(ctx, sizeof(*prop));
748 prop->name = identifier;
749 prop->is_public = !(storage_flags & STORAGE_IS_PRIVATE);
750 prop->next = class_decl->props;
751 class_decl->props = prop;
755 void *parser_alloc(parser_ctx_t *ctx, size_t size)
759 ret = vbsheap_alloc(&ctx->heap, size);
761 ctx->hres = E_OUTOFMEMORY;
765 HRESULT parse_script(parser_ctx_t *ctx, const WCHAR *code)
767 ctx->code = ctx->ptr = code;
768 ctx->end = ctx->code + strlenW(ctx->code);
770 vbsheap_init(&ctx->heap);
772 ctx->parse_complete = FALSE;
775 ctx->last_token = tNL;
777 ctx->stats = ctx->stats_tail = NULL;
778 ctx->class_decls = NULL;
779 ctx->option_explicit = FALSE;
783 if(FAILED(ctx->hres))
785 if(!ctx->parse_complete) {
786 FIXME("parser failed on parsing %s\n", debugstr_w(ctx->ptr));
793 void parser_release(parser_ctx_t *ctx)
795 vbsheap_free(&ctx->heap);