pdh: Add more Pdh macros and prototypes to the headers.
[wine/multimedia.git] / dlls / vbscript / parser.y
blob63423d168b51a65398c114b300655a068f37e5c6
1 /*
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
21 #include "vbscript.h"
22 #include "parse.h"
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_if_statement(parser_ctx_t*,expression_t*,statement_t*,elseif_decl_t*,statement_t*);
56 static statement_t *new_function_statement(parser_ctx_t*,function_decl_t*);
58 static dim_decl_t *new_dim_decl(parser_ctx_t*,const WCHAR*,dim_decl_t*);
59 static elseif_decl_t *new_elseif_decl(parser_ctx_t*,expression_t*,statement_t*);
60 static function_decl_t *new_function_decl(parser_ctx_t*,const WCHAR*,function_type_t,unsigned,arg_decl_t*,statement_t*);
61 static arg_decl_t *new_argument_decl(parser_ctx_t*,const WCHAR*,BOOL);
63 static class_decl_t *new_class_decl(parser_ctx_t*);
64 static class_decl_t *add_class_function(parser_ctx_t*,class_decl_t*,function_decl_t*);
66 #define STORAGE_IS_PRIVATE 1
67 #define STORAGE_IS_DEFAULT 2
69 #define CHECK_ERROR if(((parser_ctx_t*)ctx)->hres != S_OK) YYABORT
73 %pure_parser
74 %start Program
76 %union {
77 const WCHAR *string;
78 statement_t *statement;
79 expression_t *expression;
80 member_expression_t *member;
81 elseif_decl_t *elseif;
82 dim_decl_t *dim_decl;
83 function_decl_t *func_decl;
84 arg_decl_t *arg_decl;
85 class_decl_t *class_decl;
86 unsigned uint;
87 LONG lng;
88 BOOL bool;
89 double dbl;
92 %token tEOF tNL tREM tEMPTYBRACKETS
93 %token tTRUE tFALSE
94 %token tNOT tAND tOR tXOR tEQV tIMP tNEQ
95 %token tIS tLTEQ tGTEQ tMOD
96 %token tCALL tDIM tSUB tFUNCTION tPROPERTY tGET tLET
97 %token tIF tELSE tELSEIF tEND tTHEN tEXIT
98 %token tWHILE tWEND tDO tLOOP tUNTIL
99 %token tBYREF tBYVAL
100 %token tOPTION tEXPLICIT
101 %token tSTOP
102 %token tNOTHING tEMPTY tNULL
103 %token tCLASS tSET tNEW tPUBLIC tPRIVATE tDEFAULT tME
104 %token tERROR tNEXT tON tRESUME tGOTO
105 %token <string> tIdentifier tString
106 %token <lng> tLong tShort
107 %token <dbl> tDouble
109 %type <statement> Statement StatementNl StatementsNl StatementsNl_opt IfStatement Else_opt
110 %type <expression> Expression LiteralExpression PrimaryExpression EqualityExpression CallExpression
111 %type <expression> ConcatExpression AdditiveExpression ModExpression IntdivExpression MultiplicativeExpression ExpExpression
112 %type <expression> NotExpression UnaryExpression AndExpression OrExpression XorExpression EqvExpression
113 %type <member> MemberExpression
114 %type <expression> Arguments_opt ArgumentList_opt ArgumentList
115 %type <bool> OptionExplicit_opt
116 %type <arg_decl> ArgumentsDecl_opt ArgumentDeclList ArgumentDecl
117 %type <func_decl> FunctionDecl
118 %type <elseif> ElseIfs_opt ElseIfs ElseIf
119 %type <class_decl> ClassDeclaration ClassBody
120 %type <uint> Storage Storage_opt
121 %type <dim_decl> DimDeclList
125 Program
126 : OptionExplicit_opt SourceElements tEOF { parse_complete(ctx, $1); }
128 OptionExplicit_opt
129 : /* empty */ { $$ = FALSE; }
130 | tOPTION tEXPLICIT tNL { $$ = TRUE; }
132 SourceElements
133 : /* empty */
134 | SourceElements StatementNl { source_add_statement(ctx, $2); }
135 | SourceElements ClassDeclaration { source_add_class(ctx, $2); }
137 StatementsNl_opt
138 : /* empty */ { $$ = NULL; }
139 | StatementsNl { $$ = $1; }
141 StatementsNl
142 : StatementNl { $$ = $1; }
143 | StatementNl StatementsNl { $1->next = $2; $$ = $1; }
145 StatementNl
146 : Statement tNL { $$ = $1; }
148 Statement
149 : MemberExpression ArgumentList_opt { $1->args = $2; $$ = new_call_statement(ctx, $1); CHECK_ERROR; }
150 | tCALL MemberExpression Arguments_opt { $2->args = $3; $$ = new_call_statement(ctx, $2); CHECK_ERROR; }
151 | MemberExpression Arguments_opt '=' Expression
152 { $1->args = $2; $$ = new_assign_statement(ctx, $1, $4); CHECK_ERROR; }
153 | tDIM DimDeclList { $$ = new_dim_statement(ctx, $2); CHECK_ERROR; }
154 | IfStatement { $$ = $1; }
155 | FunctionDecl { $$ = new_function_statement(ctx, $1); CHECK_ERROR; }
156 | tEXIT tFUNCTION { $$ = new_statement(ctx, STAT_EXITFUNC, 0); CHECK_ERROR; }
157 | tEXIT tSUB { $$ = new_statement(ctx, STAT_EXITSUB, 0); CHECK_ERROR; }
158 | tSET MemberExpression Arguments_opt '=' Expression
159 { $2->args = $3; $$ = new_set_statement(ctx, $2, $5); CHECK_ERROR; }
160 | tSTOP { $$ = new_statement(ctx, STAT_STOP, 0); CHECK_ERROR; }
162 MemberExpression
163 : tIdentifier { $$ = new_member_expression(ctx, NULL, $1); CHECK_ERROR; }
164 | CallExpression '.' tIdentifier { $$ = new_member_expression(ctx, $1, $3); CHECK_ERROR; }
166 DimDeclList /* FIXME: Support arrays */
167 : tIdentifier { $$ = new_dim_decl(ctx, $1, NULL); CHECK_ERROR; }
168 | tIdentifier ',' DimDeclList { $$ = new_dim_decl(ctx, $1, $3); CHECK_ERROR; }
170 IfStatement
171 : tIF Expression tTHEN tNL StatementsNl ElseIfs_opt Else_opt tEND tIF
172 { $$ = new_if_statement(ctx, $2, $5, $6, $7); CHECK_ERROR; }
173 /* FIXME: short if statement */
175 ElseIfs_opt
176 : /* empty */ { $$ = NULL; }
177 | ElseIfs { $$ = $1; }
179 ElseIfs
180 : ElseIf { $$ = $1; }
181 | ElseIf ElseIfs { $1->next = $2; $$ = $1; }
183 ElseIf
184 : tELSEIF Expression tTHEN tNL StatementsNl
185 { $$ = new_elseif_decl(ctx, $2, $5); }
187 Else_opt
188 : /* empty */ { $$ = NULL; }
189 | tELSE tNL StatementsNl { $$ = $3; }
191 Arguments_opt
192 : EmptyBrackets_opt { $$ = NULL; }
193 | '(' ArgumentList ')' { $$ = $2; }
195 ArgumentList_opt
196 : EmptyBrackets_opt { $$ = NULL; }
197 | ArgumentList { $$ = $1; }
199 ArgumentList
200 : Expression { $$ = $1; }
201 | Expression ',' ArgumentList { $1->next = $3; $$ = $1; }
203 EmptyBrackets_opt
204 : /* empty */
205 | tEMPTYBRACKETS
207 Expression
208 : EqvExpression { $$ = $1; }
209 | Expression tIMP EqvExpression { $$ = new_binary_expression(ctx, EXPR_IMP, $1, $3); CHECK_ERROR; }
211 EqvExpression
212 : XorExpression { $$ = $1; }
213 | EqvExpression tEQV XorExpression { $$ = new_binary_expression(ctx, EXPR_EQV, $1, $3); CHECK_ERROR; }
215 XorExpression
216 : OrExpression { $$ = $1; }
217 | XorExpression tXOR OrExpression { $$ = new_binary_expression(ctx, EXPR_XOR, $1, $3); CHECK_ERROR; }
219 OrExpression
220 : AndExpression { $$ = $1; }
221 | OrExpression tOR AndExpression { $$ = new_binary_expression(ctx, EXPR_OR, $1, $3); CHECK_ERROR; }
223 AndExpression
224 : NotExpression { $$ = $1; }
225 | AndExpression tAND NotExpression { $$ = new_binary_expression(ctx, EXPR_AND, $1, $3); CHECK_ERROR; }
227 NotExpression
228 : EqualityExpression { $$ = $1; }
229 | tNOT NotExpression { $$ = new_unary_expression(ctx, EXPR_NOT, $2); CHECK_ERROR; }
231 EqualityExpression
232 : ConcatExpression { $$ = $1; }
233 | EqualityExpression '=' ConcatExpression { $$ = new_binary_expression(ctx, EXPR_EQUAL, $1, $3); CHECK_ERROR; }
234 | EqualityExpression tNEQ ConcatExpression { $$ = new_binary_expression(ctx, EXPR_NEQUAL, $1, $3); CHECK_ERROR; }
236 ConcatExpression
237 : AdditiveExpression { $$ = $1; }
238 | ConcatExpression '&' AdditiveExpression { $$ = new_binary_expression(ctx, EXPR_CONCAT, $1, $3); CHECK_ERROR; }
240 AdditiveExpression
241 : ModExpression { $$ = $1; }
242 | AdditiveExpression '+' ModExpression { $$ = new_binary_expression(ctx, EXPR_ADD, $1, $3); CHECK_ERROR; }
243 | AdditiveExpression '-' ModExpression { $$ = new_binary_expression(ctx, EXPR_SUB, $1, $3); CHECK_ERROR; }
245 ModExpression
246 : IntdivExpression { $$ = $1; }
247 | ModExpression tMOD IntdivExpression { $$ = new_binary_expression(ctx, EXPR_MOD, $1, $3); CHECK_ERROR; }
249 IntdivExpression
250 : MultiplicativeExpression { $$ = $1; }
251 | IntdivExpression '\\' MultiplicativeExpression
252 { $$ = new_binary_expression(ctx, EXPR_IDIV, $1, $3); CHECK_ERROR; }
254 MultiplicativeExpression
255 : ExpExpression { $$ = $1; }
256 | MultiplicativeExpression '*' ExpExpression
257 { $$ = new_binary_expression(ctx, EXPR_MUL, $1, $3); CHECK_ERROR; }
258 | MultiplicativeExpression '/' ExpExpression
259 { $$ = new_binary_expression(ctx, EXPR_DIV, $1, $3); CHECK_ERROR; }
261 ExpExpression
262 : UnaryExpression { $$ = $1; }
263 | ExpExpression '^' UnaryExpression { $$ = new_binary_expression(ctx, EXPR_EXP, $1, $3); CHECK_ERROR; }
265 UnaryExpression
266 : LiteralExpression { $$ = $1; }
267 | CallExpression { $$ = $1; }
268 | tNEW tIdentifier { $$ = new_new_expression(ctx, $2); CHECK_ERROR; }
269 | '-' UnaryExpression { $$ = new_unary_expression(ctx, EXPR_NEG, $2); CHECK_ERROR; }
271 CallExpression
272 : PrimaryExpression { $$ = $1; }
273 | MemberExpression Arguments_opt { $1->args = $2; $$ = &$1->expr; }
275 LiteralExpression
276 : tTRUE { $$ = new_bool_expression(ctx, VARIANT_TRUE); CHECK_ERROR; }
277 | tFALSE { $$ = new_bool_expression(ctx, VARIANT_FALSE); CHECK_ERROR; }
278 | tString { $$ = new_string_expression(ctx, $1); CHECK_ERROR; }
279 | tShort { $$ = new_long_expression(ctx, EXPR_USHORT, $1); CHECK_ERROR; }
280 | '0' { $$ = new_long_expression(ctx, EXPR_USHORT, 0); CHECK_ERROR; }
281 | tLong { $$ = new_long_expression(ctx, EXPR_ULONG, $1); CHECK_ERROR; }
282 | tDouble { $$ = new_double_expression(ctx, $1); CHECK_ERROR; }
283 | tEMPTY { $$ = new_expression(ctx, EXPR_EMPTY, 0); CHECK_ERROR; }
284 | tNULL { $$ = new_expression(ctx, EXPR_NULL, 0); CHECK_ERROR; }
285 | tNOTHING { $$ = new_expression(ctx, EXPR_NOTHING, 0); CHECK_ERROR; }
287 PrimaryExpression
288 : '(' Expression ')' { $$ = $2; }
290 ClassDeclaration
291 : tCLASS tIdentifier tNL ClassBody tEND tCLASS tNL { $4->name = $2; $$ = $4; }
293 ClassBody
294 : /* empty */ { $$ = new_class_decl(ctx); }
295 | FunctionDecl tNL ClassBody { $$ = add_class_function(ctx, $3, $1); CHECK_ERROR; }
297 FunctionDecl
298 : Storage_opt tSUB tIdentifier ArgumentsDecl_opt tNL StatementsNl_opt tEND tSUB
299 { $$ = new_function_decl(ctx, $3, FUNC_SUB, $1, $4, $6); CHECK_ERROR; }
300 | Storage_opt tFUNCTION tIdentifier ArgumentsDecl_opt tNL StatementsNl_opt tEND tFUNCTION
301 { $$ = new_function_decl(ctx, $3, FUNC_FUNCTION, $1, $4, $6); CHECK_ERROR; }
303 Storage_opt
304 : /* empty*/ { $$ = 0; }
305 | Storage { $$ = $1; }
307 Storage
308 : tPUBLIC tDEFAULT { $$ = STORAGE_IS_DEFAULT; }
309 | tPUBLIC { $$ = 0; }
310 | tPRIVATE { $$ = STORAGE_IS_PRIVATE; }
312 ArgumentsDecl_opt
313 : EmptyBrackets_opt { $$ = NULL; }
314 | '(' ArgumentDeclList ')' { $$ = $2; }
316 ArgumentDeclList
317 : ArgumentDecl { $$ = $1; }
318 | ArgumentDecl ',' ArgumentDeclList { $1->next = $3; $$ = $1; }
320 ArgumentDecl
321 : tIdentifier { $$ = new_argument_decl(ctx, $1, TRUE); }
322 | tBYREF tIdentifier { $$ = new_argument_decl(ctx, $2, TRUE); }
323 | tBYVAL tIdentifier { $$ = new_argument_decl(ctx, $2, FALSE); }
327 static int parser_error(const char *str)
329 return 0;
332 static void source_add_statement(parser_ctx_t *ctx, statement_t *stat)
334 if(ctx->stats) {
335 ctx->stats_tail->next = stat;
336 ctx->stats_tail = stat;
337 }else {
338 ctx->stats = ctx->stats_tail = stat;
342 static void source_add_class(parser_ctx_t *ctx, class_decl_t *class_decl)
344 class_decl->next = ctx->class_decls;
345 ctx->class_decls = class_decl;
348 static void parse_complete(parser_ctx_t *ctx, BOOL option_explicit)
350 ctx->parse_complete = TRUE;
351 ctx->option_explicit = option_explicit;
354 static void *new_expression(parser_ctx_t *ctx, expression_type_t type, size_t size)
356 expression_t *expr;
358 expr = parser_alloc(ctx, size ? size : sizeof(*expr));
359 if(expr) {
360 expr->type = type;
361 expr->next = NULL;
364 return expr;
367 static expression_t *new_bool_expression(parser_ctx_t *ctx, VARIANT_BOOL value)
369 bool_expression_t *expr;
371 expr = new_expression(ctx, EXPR_BOOL, sizeof(*expr));
372 if(!expr)
373 return NULL;
375 expr->value = value;
376 return &expr->expr;
379 static expression_t *new_string_expression(parser_ctx_t *ctx, const WCHAR *value)
381 string_expression_t *expr;
383 expr = new_expression(ctx, EXPR_STRING, sizeof(*expr));
384 if(!expr)
385 return NULL;
387 expr->value = value;
388 return &expr->expr;
391 static expression_t *new_long_expression(parser_ctx_t *ctx, expression_type_t type, LONG value)
393 int_expression_t *expr;
395 expr = new_expression(ctx, type, sizeof(*expr));
396 if(!expr)
397 return NULL;
399 expr->value = value;
400 return &expr->expr;
403 static expression_t *new_double_expression(parser_ctx_t *ctx, double value)
405 double_expression_t *expr;
407 expr = new_expression(ctx, EXPR_DOUBLE, sizeof(*expr));
408 if(!expr)
409 return NULL;
411 expr->value = value;
412 return &expr->expr;
415 static expression_t *new_unary_expression(parser_ctx_t *ctx, expression_type_t type, expression_t *subexpr)
417 unary_expression_t *expr;
419 expr = new_expression(ctx, type, sizeof(*expr));
420 if(!expr)
421 return NULL;
423 expr->subexpr = subexpr;
424 return &expr->expr;
427 static expression_t *new_binary_expression(parser_ctx_t *ctx, expression_type_t type, expression_t *left, expression_t *right)
429 binary_expression_t *expr;
431 expr = new_expression(ctx, type, sizeof(*expr));
432 if(!expr)
433 return NULL;
435 expr->left = left;
436 expr->right = right;
437 return &expr->expr;
440 static member_expression_t *new_member_expression(parser_ctx_t *ctx, expression_t *obj_expr, const WCHAR *identifier)
442 member_expression_t *expr;
444 expr = new_expression(ctx, EXPR_MEMBER, sizeof(*expr));
445 if(!expr)
446 return NULL;
448 expr->obj_expr = obj_expr;
449 expr->identifier = identifier;
450 expr->args = NULL;
451 return expr;
454 static expression_t *new_new_expression(parser_ctx_t *ctx, const WCHAR *identifier)
456 string_expression_t *expr;
458 expr = new_expression(ctx, EXPR_NEW, sizeof(*expr));
459 if(!expr)
460 return NULL;
462 expr->value = identifier;
463 return &expr->expr;
466 static void *new_statement(parser_ctx_t *ctx, statement_type_t type, size_t size)
468 statement_t *stat;
470 stat = parser_alloc(ctx, size ? size : sizeof(*stat));
471 if(stat) {
472 stat->type = type;
473 stat->next = NULL;
476 return stat;
479 static statement_t *new_call_statement(parser_ctx_t *ctx, member_expression_t *expr)
481 call_statement_t *stat;
483 stat = new_statement(ctx, STAT_CALL, sizeof(*stat));
484 if(!stat)
485 return NULL;
487 stat->expr = expr;
488 return &stat->stat;
491 static statement_t *new_assign_statement(parser_ctx_t *ctx, member_expression_t *left, expression_t *right)
493 assign_statement_t *stat;
495 stat = new_statement(ctx, STAT_ASSIGN, sizeof(*stat));
496 if(!stat)
497 return NULL;
499 stat->member_expr = left;
500 stat->value_expr = right;
501 return &stat->stat;
504 static statement_t *new_set_statement(parser_ctx_t *ctx, member_expression_t *left, expression_t *right)
506 assign_statement_t *stat;
508 stat = new_statement(ctx, STAT_SET, sizeof(*stat));
509 if(!stat)
510 return NULL;
512 stat->member_expr = left;
513 stat->value_expr = right;
514 return &stat->stat;
517 static dim_decl_t *new_dim_decl(parser_ctx_t *ctx, const WCHAR *name, dim_decl_t *next)
519 dim_decl_t *decl;
521 decl = parser_alloc(ctx, sizeof(*decl));
522 if(!decl)
523 return NULL;
525 decl->name = name;
526 decl->next = next;
527 return decl;
530 static statement_t *new_dim_statement(parser_ctx_t *ctx, dim_decl_t *decls)
532 dim_statement_t *stat;
534 stat = new_statement(ctx, STAT_DIM, sizeof(*stat));
535 if(!stat)
536 return NULL;
538 stat->dim_decls = decls;
539 return &stat->stat;
542 static elseif_decl_t *new_elseif_decl(parser_ctx_t *ctx, expression_t *expr, statement_t *stat)
544 elseif_decl_t *decl;
546 decl = parser_alloc(ctx, sizeof(*decl));
547 if(!decl)
548 return NULL;
550 decl->expr = expr;
551 decl->stat = stat;
552 decl->next = NULL;
553 return decl;
556 static statement_t *new_if_statement(parser_ctx_t *ctx, expression_t *expr, statement_t *if_stat, elseif_decl_t *elseif_decl,
557 statement_t *else_stat)
559 if_statement_t *stat;
561 stat = new_statement(ctx, STAT_IF, sizeof(*stat));
562 if(!stat)
563 return NULL;
565 stat->expr = expr;
566 stat->if_stat = if_stat;
567 stat->elseifs = elseif_decl;
568 stat->else_stat = else_stat;
569 return &stat->stat;
572 static arg_decl_t *new_argument_decl(parser_ctx_t *ctx, const WCHAR *name, BOOL by_ref)
574 arg_decl_t *arg_decl;
576 arg_decl = parser_alloc(ctx, sizeof(*arg_decl));
577 if(!arg_decl)
578 return NULL;
580 arg_decl->name = name;
581 arg_decl->by_ref = by_ref;
582 arg_decl->next = NULL;
583 return arg_decl;
586 static function_decl_t *new_function_decl(parser_ctx_t *ctx, const WCHAR *name, function_type_t type,
587 unsigned storage_flags, arg_decl_t *arg_decl, statement_t *body)
589 function_decl_t *decl;
591 if(storage_flags & STORAGE_IS_DEFAULT) {
592 FIXME("Function declared as default property\n");
593 ctx->hres = E_FAIL;
594 return NULL;
597 decl = parser_alloc(ctx, sizeof(*decl));
598 if(!decl)
599 return NULL;
601 decl->name = name;
602 decl->type = type;
603 decl->is_public = !(storage_flags & STORAGE_IS_PRIVATE);
604 decl->args = arg_decl;
605 decl->body = body;
606 decl->next = NULL;
607 return decl;
610 static statement_t *new_function_statement(parser_ctx_t *ctx, function_decl_t *decl)
612 function_statement_t *stat;
614 stat = new_statement(ctx, STAT_FUNC, sizeof(*stat));
615 if(!stat)
616 return NULL;
618 stat->func_decl = decl;
619 return &stat->stat;
622 static class_decl_t *new_class_decl(parser_ctx_t *ctx)
624 class_decl_t *class_decl;
626 class_decl = parser_alloc(ctx, sizeof(*class_decl));
627 if(!class_decl)
628 return NULL;
630 class_decl->funcs = NULL;
631 class_decl->next = NULL;
632 return class_decl;
635 static class_decl_t *add_class_function(parser_ctx_t *ctx, class_decl_t *class_decl, function_decl_t *decl)
637 function_decl_t *iter;
639 for(iter = class_decl->funcs; iter; iter = iter->next) {
640 if(!strcmpiW(iter->name, decl->name)) {
641 if(decl->type == FUNC_SUB || decl->type == FUNC_FUNCTION) {
642 FIXME("Redefinition of %s::%s\n", debugstr_w(class_decl->name), debugstr_w(decl->name));
643 ctx->hres = E_FAIL;
644 return NULL;
649 decl->next = class_decl->funcs;
650 class_decl->funcs = decl;
651 return class_decl;
654 void *parser_alloc(parser_ctx_t *ctx, size_t size)
656 void *ret;
658 ret = vbsheap_alloc(&ctx->heap, size);
659 if(!ret)
660 ctx->hres = E_OUTOFMEMORY;
661 return ret;
664 HRESULT parse_script(parser_ctx_t *ctx, const WCHAR *code)
666 ctx->code = ctx->ptr = code;
667 ctx->end = ctx->code + strlenW(ctx->code);
669 vbsheap_init(&ctx->heap);
671 ctx->parse_complete = FALSE;
672 ctx->hres = S_OK;
674 ctx->last_token = tNL;
675 ctx->last_nl = 0;
676 ctx->stats = ctx->stats_tail = NULL;
677 ctx->class_decls = NULL;
678 ctx->option_explicit = FALSE;
680 parser_parse(ctx);
682 if(FAILED(ctx->hres))
683 return ctx->hres;
684 if(!ctx->parse_complete) {
685 FIXME("parser failed on parsing %s\n", debugstr_w(ctx->ptr));
686 return E_FAIL;
689 return S_OK;
692 void parser_release(parser_ctx_t *ctx)
694 vbsheap_free(&ctx->heap);