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
);
28 #define YYLEX_PARAM ctx
29 #define YYPARSE_PARAM ctx
31 static int parser_error
(const char*);
33 static void parse_complete
(parser_ctx_t
*,BOOL
);
35 static void source_add_statement
(parser_ctx_t
*,statement_t
*);
36 static void source_add_class
(parser_ctx_t
*,class_decl_t
*);
38 static void *new_expression
(parser_ctx_t
*,expression_type_t
,size_t);
39 static expression_t
*new_bool_expression
(parser_ctx_t
*,VARIANT_BOOL
);
40 static expression_t
*new_string_expression
(parser_ctx_t
*,const WCHAR
*);
41 static expression_t
*new_long_expression
(parser_ctx_t
*,expression_type_t
,LONG
);
42 static expression_t
*new_double_expression
(parser_ctx_t
*,double);
43 static expression_t
*new_unary_expression
(parser_ctx_t
*,expression_type_t
,expression_t
*);
44 static expression_t
*new_binary_expression
(parser_ctx_t
*,expression_type_t
,expression_t
*,expression_t
*);
45 static expression_t
*new_new_expression
(parser_ctx_t
*,const WCHAR
*);
47 static member_expression_t
*new_member_expression
(parser_ctx_t
*,expression_t
*,const WCHAR
*);
49 static void *new_statement
(parser_ctx_t
*,statement_type_t
,size_t);
50 static statement_t
*new_call_statement
(parser_ctx_t
*,member_expression_t
*);
51 static statement_t
*new_assign_statement
(parser_ctx_t
*,member_expression_t
*,expression_t
*);
52 static statement_t
*new_set_statement
(parser_ctx_t
*,member_expression_t
*,expression_t
*);
53 static statement_t
*new_dim_statement
(parser_ctx_t
*,dim_decl_t
*);
54 static statement_t
*new_while_statement
(parser_ctx_t
*,statement_type_t
,expression_t
*,statement_t
*);
55 static statement_t
*new_forto_statement
(parser_ctx_t
*,const WCHAR
*,expression_t
*,expression_t
*,expression_t
*,statement_t
*);
56 static statement_t
*new_foreach_statement
(parser_ctx_t
*,const WCHAR
*,expression_t
*,statement_t
*);
57 static statement_t
*new_if_statement
(parser_ctx_t
*,expression_t
*,statement_t
*,elseif_decl_t
*,statement_t
*);
58 static statement_t
*new_function_statement
(parser_ctx_t
*,function_decl_t
*);
59 static statement_t
*new_onerror_statement
(parser_ctx_t
*,BOOL
);
60 static statement_t
*new_const_statement
(parser_ctx_t
*,const_decl_t
*);
62 static dim_decl_t
*new_dim_decl
(parser_ctx_t
*,const WCHAR
*,dim_decl_t
*);
63 static elseif_decl_t
*new_elseif_decl
(parser_ctx_t
*,expression_t
*,statement_t
*);
64 static function_decl_t
*new_function_decl
(parser_ctx_t
*,const WCHAR
*,function_type_t
,unsigned,arg_decl_t
*,statement_t
*);
65 static arg_decl_t
*new_argument_decl
(parser_ctx_t
*,const WCHAR
*,BOOL
);
66 static const_decl_t
*new_const_decl
(parser_ctx_t
*,const WCHAR
*,expression_t
*);
68 static class_decl_t
*new_class_decl
(parser_ctx_t
*);
69 static class_decl_t
*add_class_function
(parser_ctx_t
*,class_decl_t
*,function_decl_t
*);
70 static class_decl_t
*add_variant_prop
(parser_ctx_t
*,class_decl_t
*,const WCHAR
*,unsigned);
72 static statement_t
*link_statements
(statement_t
*,statement_t
*);
74 #define STORAGE_IS_PRIVATE 1
75 #define STORAGE_IS_DEFAULT 2
77 #define CHECK_ERROR if(((parser_ctx_t*)ctx)->hres != S_OK) YYABORT
86 statement_t
*statement
;
87 expression_t
*expression
;
88 member_expression_t
*member
;
89 elseif_decl_t
*elseif
;
91 function_decl_t
*func_decl
;
93 class_decl_t
*class_decl
;
94 const_decl_t
*const_decl
;
101 %token tEOF tNL tREM tEMPTYBRACKETS
103 %token tNOT tAND tOR tXOR tEQV tIMP tNEQ
104 %token tIS tLTEQ tGTEQ tMOD
105 %token tCALL tDIM tSUB tFUNCTION tPROPERTY tGET tLET tCONST
106 %token tIF tELSE tELSEIF tEND tTHEN tEXIT
107 %token tWHILE tWEND tDO tLOOP tUNTIL tFOR tTO tSTEP tEACH tIN
109 %token tOPTION tEXPLICIT
111 %token tNOTHING tEMPTY tNULL
112 %token tCLASS tSET tNEW tPUBLIC tPRIVATE tDEFAULT tME
113 %token tERROR tNEXT tON tRESUME tGOTO
114 %token
<string> tIdentifier tString
115 %token
<lng
> tLong tShort
118 %type
<statement
> Statement SimpleStatement StatementNl StatementsNl StatementsNl_opt IfStatement Else_opt
119 %type
<expression
> Expression LiteralExpression PrimaryExpression EqualityExpression CallExpression
120 %type
<expression
> ConcatExpression AdditiveExpression ModExpression IntdivExpression MultiplicativeExpression ExpExpression
121 %type
<expression
> NotExpression UnaryExpression AndExpression OrExpression XorExpression EqvExpression
122 %type
<member
> MemberExpression
123 %type
<expression
> Arguments_opt ArgumentList_opt ArgumentList Step_opt
124 %type
<bool> OptionExplicit_opt DoType
125 %type
<arg_decl
> ArgumentsDecl_opt ArgumentDeclList ArgumentDecl
126 %type
<func_decl
> FunctionDecl PropertyDecl
127 %type
<elseif
> ElseIfs_opt ElseIfs ElseIf
128 %type
<class_decl
> ClassDeclaration ClassBody
129 %type
<uint
> Storage Storage_opt
130 %type
<dim_decl
> DimDeclList
131 %type
<const_decl
> ConstDecl ConstDeclList
136 : OptionExplicit_opt SourceElements tEOF
{ parse_complete
(ctx
, $1); }
139 : /* empty */ { $$
= FALSE
; }
140 | tOPTION tEXPLICIT tNL
{ $$
= TRUE
; }
144 | SourceElements StatementNl
{ source_add_statement
(ctx
, $2); }
145 | SourceElements ClassDeclaration
{ source_add_class
(ctx
, $2); }
148 : /* empty */ { $$
= NULL
; }
149 | StatementsNl
{ $$
= $1; }
152 : StatementNl
{ $$
= $1; }
153 | StatementNl StatementsNl
{ $$
= link_statements
($1, $2); }
156 : Statement tNL
{ $$
= $1; }
160 |
':' Statement
{ $$
= $2; }
161 | SimpleStatement
{ $$
= $1; }
162 | SimpleStatement
':' Statement
{ $1->next
= $3; $$
= $1; }
163 | SimpleStatement
':' { $$
= $1; }
166 : MemberExpression ArgumentList_opt
{ $1->args
= $2; $$
= new_call_statement
(ctx
, $1); CHECK_ERROR
; }
167 | tCALL MemberExpression Arguments_opt
{ $2->args
= $3; $$
= new_call_statement
(ctx
, $2); CHECK_ERROR
; }
168 | MemberExpression Arguments_opt
'=' Expression
169 { $1->args
= $2; $$
= new_assign_statement
(ctx
, $1, $4); CHECK_ERROR
; }
170 | tDIM DimDeclList
{ $$
= new_dim_statement
(ctx
, $2); CHECK_ERROR
; }
171 | IfStatement
{ $$
= $1; }
172 | tWHILE Expression tNL StatementsNl_opt tWEND
173 { $$
= new_while_statement
(ctx
, STAT_WHILE
, $2, $4); CHECK_ERROR
; }
174 | tDO DoType Expression tNL StatementsNl_opt tLOOP
175 { $$
= new_while_statement
(ctx
, $2 ? STAT_WHILELOOP
: STAT_UNTIL
, $3, $5);
177 | tDO tNL StatementsNl_opt tLOOP DoType Expression
178 { $$
= new_while_statement
(ctx
, $5 ? STAT_DOWHILE
: STAT_DOUNTIL
, $6, $3);
180 | FunctionDecl
{ $$
= new_function_statement
(ctx
, $1); CHECK_ERROR
; }
181 | tEXIT tDO
{ $$
= new_statement
(ctx
, STAT_EXITDO
, 0); CHECK_ERROR
; }
182 | tEXIT tFOR
{ $$
= new_statement
(ctx
, STAT_EXITFOR
, 0); CHECK_ERROR
; }
183 | tEXIT tFUNCTION
{ $$
= new_statement
(ctx
, STAT_EXITFUNC
, 0); CHECK_ERROR
; }
184 | tEXIT tPROPERTY
{ $$
= new_statement
(ctx
, STAT_EXITPROP
, 0); CHECK_ERROR
; }
185 | tEXIT tSUB
{ $$
= new_statement
(ctx
, STAT_EXITSUB
, 0); CHECK_ERROR
; }
186 | tSET MemberExpression Arguments_opt
'=' Expression
187 { $2->args
= $3; $$
= new_set_statement
(ctx
, $2, $5); CHECK_ERROR
; }
188 | tSTOP
{ $$
= new_statement
(ctx
, STAT_STOP
, 0); CHECK_ERROR
; }
189 | tON tERROR tRESUME tNEXT
{ $$
= new_onerror_statement
(ctx
, TRUE
); CHECK_ERROR
; }
190 | tON tERROR tGOTO
'0' { $$
= new_onerror_statement
(ctx
, FALSE
); CHECK_ERROR
; }
191 | tCONST ConstDeclList
{ $$
= new_const_statement
(ctx
, $2); CHECK_ERROR
; }
192 | tFOR tIdentifier
'=' Expression tTO Expression Step_opt tNL StatementsNl_opt tNEXT
193 { $$
= new_forto_statement
(ctx
, $2, $4, $6, $7, $9); CHECK_ERROR
; }
194 | tFOR tEACH tIdentifier tIN Expression tNL StatementsNl_opt tNEXT
195 { $$
= new_foreach_statement
(ctx
, $3, $5, $7); }
198 : tIdentifier
{ $$
= new_member_expression
(ctx
, NULL
, $1); CHECK_ERROR
; }
199 | CallExpression
'.' tIdentifier
{ $$
= new_member_expression
(ctx
, $1, $3); CHECK_ERROR
; }
201 DimDeclList
/* FIXME: Support arrays */
202 : tIdentifier
{ $$
= new_dim_decl
(ctx
, $1, NULL
); CHECK_ERROR
; }
203 | tIdentifier
',' DimDeclList
{ $$
= new_dim_decl
(ctx
, $1, $3); CHECK_ERROR
; }
206 : ConstDecl
{ $$
= $1; }
207 | ConstDecl
',' ConstDeclList
{ $1->next
= $3; $$
= $1; }
210 : tIdentifier
'=' LiteralExpression
{ $$
= new_const_decl
(ctx
, $1, $3); CHECK_ERROR
; }
213 : tWHILE
{ $$
= TRUE
; }
214 | tUNTIL
{ $$
= FALSE
; }
217 : /* empty */ { $$
= NULL
;}
218 | tSTEP Expression
{ $$
= $2; }
221 : tIF Expression tTHEN tNL StatementsNl ElseIfs_opt Else_opt tEND tIF
222 { $$
= new_if_statement
(ctx
, $2, $5, $6, $7); CHECK_ERROR
; }
223 | tIF Expression tTHEN Statement
{ $$
= new_if_statement
(ctx
, $2, $4, NULL
, NULL
); CHECK_ERROR
; }
224 | tIF Expression tTHEN Statement tELSE Statement
225 { $$
= new_if_statement
(ctx
, $2, $4, NULL
, $6); CHECK_ERROR
; }
228 : /* empty */ { $$
= NULL
; }
229 | ElseIfs
{ $$
= $1; }
232 : ElseIf
{ $$
= $1; }
233 | ElseIf ElseIfs
{ $1->next
= $2; $$
= $1; }
236 : tELSEIF Expression tTHEN tNL StatementsNl
237 { $$
= new_elseif_decl
(ctx
, $2, $5); }
240 : /* empty */ { $$
= NULL
; }
241 | tELSE tNL StatementsNl
{ $$
= $3; }
244 : EmptyBrackets_opt
{ $$
= NULL
; }
245 |
'(' ArgumentList
')' { $$
= $2; }
248 : EmptyBrackets_opt
{ $$
= NULL
; }
249 | ArgumentList
{ $$
= $1; }
252 : Expression
{ $$
= $1; }
253 | Expression
',' ArgumentList
{ $1->next
= $3; $$
= $1; }
260 : EqvExpression
{ $$
= $1; }
261 | Expression tIMP EqvExpression
{ $$
= new_binary_expression
(ctx
, EXPR_IMP
, $1, $3); CHECK_ERROR
; }
264 : XorExpression
{ $$
= $1; }
265 | EqvExpression tEQV XorExpression
{ $$
= new_binary_expression
(ctx
, EXPR_EQV
, $1, $3); CHECK_ERROR
; }
268 : OrExpression
{ $$
= $1; }
269 | XorExpression tXOR OrExpression
{ $$
= new_binary_expression
(ctx
, EXPR_XOR
, $1, $3); CHECK_ERROR
; }
272 : AndExpression
{ $$
= $1; }
273 | OrExpression tOR AndExpression
{ $$
= new_binary_expression
(ctx
, EXPR_OR
, $1, $3); CHECK_ERROR
; }
276 : NotExpression
{ $$
= $1; }
277 | AndExpression tAND NotExpression
{ $$
= new_binary_expression
(ctx
, EXPR_AND
, $1, $3); CHECK_ERROR
; }
280 : EqualityExpression
{ $$
= $1; }
281 | tNOT NotExpression
{ $$
= new_unary_expression
(ctx
, EXPR_NOT
, $2); CHECK_ERROR
; }
284 : ConcatExpression
{ $$
= $1; }
285 | EqualityExpression
'=' ConcatExpression
{ $$
= new_binary_expression
(ctx
, EXPR_EQUAL
, $1, $3); CHECK_ERROR
; }
286 | EqualityExpression tNEQ ConcatExpression
{ $$
= new_binary_expression
(ctx
, EXPR_NEQUAL
, $1, $3); CHECK_ERROR
; }
287 | EqualityExpression
'>' ConcatExpression
{ $$
= new_binary_expression
(ctx
, EXPR_GT
, $1, $3); CHECK_ERROR
; }
288 | EqualityExpression
'<' ConcatExpression
{ $$
= new_binary_expression
(ctx
, EXPR_LT
, $1, $3); CHECK_ERROR
; }
289 | EqualityExpression tGTEQ ConcatExpression
{ $$
= new_binary_expression
(ctx
, EXPR_GTEQ
, $1, $3); CHECK_ERROR
; }
290 | EqualityExpression tLTEQ ConcatExpression
{ $$
= new_binary_expression
(ctx
, EXPR_LTEQ
, $1, $3); CHECK_ERROR
; }
291 | EqualityExpression tIS ConcatExpression
{ $$
= new_binary_expression
(ctx
, EXPR_IS
, $1, $3); CHECK_ERROR
; }
294 : AdditiveExpression
{ $$
= $1; }
295 | ConcatExpression
'&' AdditiveExpression
{ $$
= new_binary_expression
(ctx
, EXPR_CONCAT
, $1, $3); CHECK_ERROR
; }
298 : ModExpression
{ $$
= $1; }
299 | AdditiveExpression
'+' ModExpression
{ $$
= new_binary_expression
(ctx
, EXPR_ADD
, $1, $3); CHECK_ERROR
; }
300 | AdditiveExpression
'-' ModExpression
{ $$
= new_binary_expression
(ctx
, EXPR_SUB
, $1, $3); CHECK_ERROR
; }
303 : IntdivExpression
{ $$
= $1; }
304 | ModExpression tMOD IntdivExpression
{ $$
= new_binary_expression
(ctx
, EXPR_MOD
, $1, $3); CHECK_ERROR
; }
307 : MultiplicativeExpression
{ $$
= $1; }
308 | IntdivExpression
'\\' MultiplicativeExpression
309 { $$
= new_binary_expression
(ctx
, EXPR_IDIV
, $1, $3); CHECK_ERROR
; }
311 MultiplicativeExpression
312 : ExpExpression
{ $$
= $1; }
313 | MultiplicativeExpression
'*' ExpExpression
314 { $$
= new_binary_expression
(ctx
, EXPR_MUL
, $1, $3); CHECK_ERROR
; }
315 | MultiplicativeExpression
'/' ExpExpression
316 { $$
= new_binary_expression
(ctx
, EXPR_DIV
, $1, $3); CHECK_ERROR
; }
319 : UnaryExpression
{ $$
= $1; }
320 | ExpExpression
'^' UnaryExpression
{ $$
= new_binary_expression
(ctx
, EXPR_EXP
, $1, $3); CHECK_ERROR
; }
323 : LiteralExpression
{ $$
= $1; }
324 | CallExpression
{ $$
= $1; }
325 | tNEW tIdentifier
{ $$
= new_new_expression
(ctx
, $2); CHECK_ERROR
; }
326 |
'-' UnaryExpression
{ $$
= new_unary_expression
(ctx
, EXPR_NEG
, $2); CHECK_ERROR
; }
329 : PrimaryExpression
{ $$
= $1; }
330 | MemberExpression Arguments_opt
{ $1->args
= $2; $$
= &$1->expr
; }
333 : tTRUE
{ $$
= new_bool_expression
(ctx
, VARIANT_TRUE
); CHECK_ERROR
; }
334 | tFALSE
{ $$
= new_bool_expression
(ctx
, VARIANT_FALSE
); CHECK_ERROR
; }
335 | tString
{ $$
= new_string_expression
(ctx
, $1); CHECK_ERROR
; }
336 | tShort
{ $$
= new_long_expression
(ctx
, EXPR_USHORT
, $1); CHECK_ERROR
; }
337 |
'0' { $$
= new_long_expression
(ctx
, EXPR_USHORT
, 0); CHECK_ERROR
; }
338 | tLong
{ $$
= new_long_expression
(ctx
, EXPR_ULONG
, $1); CHECK_ERROR
; }
339 | tDouble
{ $$
= new_double_expression
(ctx
, $1); CHECK_ERROR
; }
340 | tEMPTY
{ $$
= new_expression
(ctx
, EXPR_EMPTY
, 0); CHECK_ERROR
; }
341 | tNULL
{ $$
= new_expression
(ctx
, EXPR_NULL
, 0); CHECK_ERROR
; }
342 | tNOTHING
{ $$
= new_expression
(ctx
, EXPR_NOTHING
, 0); CHECK_ERROR
; }
345 : '(' Expression
')' { $$
= $2; }
346 | tME
{ $$
= new_expression
(ctx
, EXPR_ME
, 0); CHECK_ERROR
; }
349 : tCLASS tIdentifier tNL ClassBody tEND tCLASS tNL
{ $4->name
= $2; $$
= $4; }
352 : /* empty */ { $$
= new_class_decl
(ctx
); }
353 | FunctionDecl tNL ClassBody
{ $$
= add_class_function
(ctx
, $3, $1); CHECK_ERROR
; }
354 | Storage tIdentifier tNL ClassBody
{ $$
= add_variant_prop
(ctx
, $4, $2, $1); CHECK_ERROR
; }
355 | PropertyDecl tNL ClassBody
{ $$
= add_class_function
(ctx
, $3, $1); CHECK_ERROR
; }
358 : Storage_opt tPROPERTY tGET tIdentifier EmptyBrackets_opt tNL StatementsNl_opt tEND tPROPERTY
359 { $$
= new_function_decl
(ctx
, $4, FUNC_PROPGET
, $1, NULL
, $7); CHECK_ERROR
; }
360 | Storage_opt tPROPERTY tLET tIdentifier
'(' ArgumentDecl
')' tNL StatementsNl_opt tEND tPROPERTY
361 { $$
= new_function_decl
(ctx
, $4, FUNC_PROPLET
, $1, $6, $9); CHECK_ERROR
; }
362 | Storage_opt tPROPERTY tSET tIdentifier
'(' ArgumentDecl
')' tNL StatementsNl_opt tEND tPROPERTY
363 { $$
= new_function_decl
(ctx
, $4, FUNC_PROPSET
, $1, $6, $9); CHECK_ERROR
; }
366 : Storage_opt tSUB tIdentifier ArgumentsDecl_opt tNL StatementsNl_opt tEND tSUB
367 { $$
= new_function_decl
(ctx
, $3, FUNC_SUB
, $1, $4, $6); CHECK_ERROR
; }
368 | Storage_opt tFUNCTION tIdentifier ArgumentsDecl_opt tNL StatementsNl_opt tEND tFUNCTION
369 { $$
= new_function_decl
(ctx
, $3, FUNC_FUNCTION
, $1, $4, $6); CHECK_ERROR
; }
372 : /* empty*/ { $$
= 0; }
373 | Storage
{ $$
= $1; }
376 : tPUBLIC tDEFAULT
{ $$
= STORAGE_IS_DEFAULT
; }
377 | tPUBLIC
{ $$
= 0; }
378 | tPRIVATE
{ $$
= STORAGE_IS_PRIVATE
; }
381 : EmptyBrackets_opt
{ $$
= NULL
; }
382 |
'(' ArgumentDeclList
')' { $$
= $2; }
385 : ArgumentDecl
{ $$
= $1; }
386 | ArgumentDecl
',' ArgumentDeclList
{ $1->next
= $3; $$
= $1; }
389 : tIdentifier
{ $$
= new_argument_decl
(ctx
, $1, TRUE
); }
390 | tBYREF tIdentifier
{ $$
= new_argument_decl
(ctx
, $2, TRUE
); }
391 | tBYVAL tIdentifier
{ $$
= new_argument_decl
(ctx
, $2, FALSE
); }
395 static int parser_error
(const char *str
)
400 static void source_add_statement
(parser_ctx_t
*ctx
, statement_t
*stat
)
406 ctx
->stats_tail
->next
= stat
;
407 ctx
->stats_tail
= stat
;
409 ctx
->stats
= ctx
->stats_tail
= stat
;
413 static void source_add_class
(parser_ctx_t
*ctx
, class_decl_t
*class_decl
)
415 class_decl
->next
= ctx
->class_decls
;
416 ctx
->class_decls
= class_decl
;
419 static void parse_complete
(parser_ctx_t
*ctx
, BOOL option_explicit
)
421 ctx
->parse_complete
= TRUE
;
422 ctx
->option_explicit
= option_explicit
;
425 static void *new_expression
(parser_ctx_t
*ctx
, expression_type_t type
, size_t size
)
429 expr
= parser_alloc
(ctx
, size ? size
: sizeof
(*expr
));
438 static expression_t
*new_bool_expression
(parser_ctx_t
*ctx
, VARIANT_BOOL value
)
440 bool_expression_t
*expr
;
442 expr
= new_expression
(ctx
, EXPR_BOOL
, sizeof
(*expr
));
450 static expression_t
*new_string_expression
(parser_ctx_t
*ctx
, const WCHAR
*value
)
452 string_expression_t
*expr
;
454 expr
= new_expression
(ctx
, EXPR_STRING
, sizeof
(*expr
));
462 static expression_t
*new_long_expression
(parser_ctx_t
*ctx
, expression_type_t type
, LONG value
)
464 int_expression_t
*expr
;
466 expr
= new_expression
(ctx
, type
, sizeof
(*expr
));
474 static expression_t
*new_double_expression
(parser_ctx_t
*ctx
, double value
)
476 double_expression_t
*expr
;
478 expr
= new_expression
(ctx
, EXPR_DOUBLE
, sizeof
(*expr
));
486 static expression_t
*new_unary_expression
(parser_ctx_t
*ctx
, expression_type_t type
, expression_t
*subexpr
)
488 unary_expression_t
*expr
;
490 expr
= new_expression
(ctx
, type
, sizeof
(*expr
));
494 expr
->subexpr
= subexpr
;
498 static expression_t
*new_binary_expression
(parser_ctx_t
*ctx
, expression_type_t type
, expression_t
*left
, expression_t
*right
)
500 binary_expression_t
*expr
;
502 expr
= new_expression
(ctx
, type
, sizeof
(*expr
));
511 static member_expression_t
*new_member_expression
(parser_ctx_t
*ctx
, expression_t
*obj_expr
, const WCHAR
*identifier
)
513 member_expression_t
*expr
;
515 expr
= new_expression
(ctx
, EXPR_MEMBER
, sizeof
(*expr
));
519 expr
->obj_expr
= obj_expr
;
520 expr
->identifier
= identifier
;
525 static expression_t
*new_new_expression
(parser_ctx_t
*ctx
, const WCHAR
*identifier
)
527 string_expression_t
*expr
;
529 expr
= new_expression
(ctx
, EXPR_NEW
, sizeof
(*expr
));
533 expr
->value
= identifier
;
537 static void *new_statement
(parser_ctx_t
*ctx
, statement_type_t type
, size_t size
)
541 stat
= parser_alloc
(ctx
, size ? size
: sizeof
(*stat
));
550 static statement_t
*new_call_statement
(parser_ctx_t
*ctx
, member_expression_t
*expr
)
552 call_statement_t
*stat
;
554 stat
= new_statement
(ctx
, STAT_CALL
, sizeof
(*stat
));
562 static statement_t
*new_assign_statement
(parser_ctx_t
*ctx
, member_expression_t
*left
, expression_t
*right
)
564 assign_statement_t
*stat
;
566 stat
= new_statement
(ctx
, STAT_ASSIGN
, sizeof
(*stat
));
570 stat
->member_expr
= left
;
571 stat
->value_expr
= right
;
575 static statement_t
*new_set_statement
(parser_ctx_t
*ctx
, member_expression_t
*left
, expression_t
*right
)
577 assign_statement_t
*stat
;
579 stat
= new_statement
(ctx
, STAT_SET
, sizeof
(*stat
));
583 stat
->member_expr
= left
;
584 stat
->value_expr
= right
;
588 static dim_decl_t
*new_dim_decl
(parser_ctx_t
*ctx
, const WCHAR
*name
, dim_decl_t
*next
)
592 decl
= parser_alloc
(ctx
, sizeof
(*decl
));
601 static statement_t
*new_dim_statement
(parser_ctx_t
*ctx
, dim_decl_t
*decls
)
603 dim_statement_t
*stat
;
605 stat
= new_statement
(ctx
, STAT_DIM
, sizeof
(*stat
));
609 stat
->dim_decls
= decls
;
613 static elseif_decl_t
*new_elseif_decl
(parser_ctx_t
*ctx
, expression_t
*expr
, statement_t
*stat
)
617 decl
= parser_alloc
(ctx
, sizeof
(*decl
));
627 static statement_t
*new_while_statement
(parser_ctx_t
*ctx
, statement_type_t type
, expression_t
*expr
, statement_t
*body
)
629 while_statement_t
*stat
;
631 stat
= new_statement
(ctx
, type
, sizeof
(*stat
));
640 static statement_t
*new_forto_statement
(parser_ctx_t
*ctx
, const WCHAR
*identifier
, expression_t
*from_expr
,
641 expression_t
*to_expr
, expression_t
*step_expr
, statement_t
*body
)
643 forto_statement_t
*stat
;
645 stat
= new_statement
(ctx
, STAT_FORTO
, sizeof
(*stat
));
649 stat
->identifier
= identifier
;
650 stat
->from_expr
= from_expr
;
651 stat
->to_expr
= to_expr
;
652 stat
->step_expr
= step_expr
;
657 static statement_t
*new_foreach_statement
(parser_ctx_t
*ctx
, const WCHAR
*identifier
, expression_t
*group_expr
,
660 foreach_statement_t
*stat
;
662 stat
= new_statement
(ctx
, STAT_FOREACH
, sizeof
(*stat
));
666 stat
->identifier
= identifier
;
667 stat
->group_expr
= group_expr
;
672 static statement_t
*new_if_statement
(parser_ctx_t
*ctx
, expression_t
*expr
, statement_t
*if_stat
, elseif_decl_t
*elseif_decl
,
673 statement_t
*else_stat
)
675 if_statement_t
*stat
;
677 stat
= new_statement
(ctx
, STAT_IF
, sizeof
(*stat
));
682 stat
->if_stat
= if_stat
;
683 stat
->elseifs
= elseif_decl
;
684 stat
->else_stat
= else_stat
;
688 static statement_t
*new_onerror_statement
(parser_ctx_t
*ctx
, BOOL resume_next
)
690 onerror_statement_t
*stat
;
692 stat
= new_statement
(ctx
, STAT_ONERROR
, sizeof
(*stat
));
696 stat
->resume_next
= resume_next
;
700 static arg_decl_t
*new_argument_decl
(parser_ctx_t
*ctx
, const WCHAR
*name
, BOOL by_ref
)
702 arg_decl_t
*arg_decl
;
704 arg_decl
= parser_alloc
(ctx
, sizeof
(*arg_decl
));
708 arg_decl
->name
= name
;
709 arg_decl
->by_ref
= by_ref
;
710 arg_decl
->next
= NULL
;
714 static function_decl_t
*new_function_decl
(parser_ctx_t
*ctx
, const WCHAR
*name
, function_type_t type
,
715 unsigned storage_flags
, arg_decl_t
*arg_decl
, statement_t
*body
)
717 function_decl_t
*decl
;
719 if
(storage_flags
& STORAGE_IS_DEFAULT
) {
720 if
(type
== FUNC_PROPGET
) {
723 FIXME
("Invalid default property\n");
729 decl
= parser_alloc
(ctx
, sizeof
(*decl
));
735 decl
->is_public
= !(storage_flags
& STORAGE_IS_PRIVATE
);
736 decl
->args
= arg_decl
;
739 decl
->next_prop_func
= NULL
;
743 static statement_t
*new_function_statement
(parser_ctx_t
*ctx
, function_decl_t
*decl
)
745 function_statement_t
*stat
;
747 stat
= new_statement
(ctx
, STAT_FUNC
, sizeof
(*stat
));
751 stat
->func_decl
= decl
;
755 static class_decl_t
*new_class_decl
(parser_ctx_t
*ctx
)
757 class_decl_t
*class_decl
;
759 class_decl
= parser_alloc
(ctx
, sizeof
(*class_decl
));
763 class_decl
->funcs
= NULL
;
764 class_decl
->props
= NULL
;
765 class_decl
->next
= NULL
;
769 static class_decl_t
*add_class_function
(parser_ctx_t
*ctx
, class_decl_t
*class_decl
, function_decl_t
*decl
)
771 function_decl_t
*iter
;
773 for
(iter
= class_decl
->funcs
; iter
; iter
= iter
->next
) {
774 if
(!strcmpiW
(iter
->name
, decl
->name
)) {
775 if
(decl
->type
== FUNC_SUB || decl
->type
== FUNC_FUNCTION
) {
776 FIXME
("Redefinition of %s::%s\n", debugstr_w
(class_decl
->name
), debugstr_w
(decl
->name
));
782 if
(iter
->type
== decl
->type
) {
783 FIXME
("Redefinition of %s::%s\n", debugstr_w
(class_decl
->name
), debugstr_w
(decl
->name
));
787 if
(!iter
->next_prop_func
)
789 iter
= iter
->next_prop_func
;
792 iter
->next_prop_func
= decl
;
797 decl
->next
= class_decl
->funcs
;
798 class_decl
->funcs
= decl
;
802 static class_decl_t
*add_variant_prop
(parser_ctx_t
*ctx
, class_decl_t
*class_decl
, const WCHAR
*identifier
, unsigned storage_flags
)
804 class_prop_decl_t
*prop
;
806 if
(storage_flags
& STORAGE_IS_DEFAULT
) {
807 FIXME
("variant prop van't be default value\n");
812 prop
= parser_alloc
(ctx
, sizeof
(*prop
));
816 prop
->name
= identifier
;
817 prop
->is_public
= !(storage_flags
& STORAGE_IS_PRIVATE
);
818 prop
->next
= class_decl
->props
;
819 class_decl
->props
= prop
;
823 static const_decl_t
*new_const_decl
(parser_ctx_t
*ctx
, const WCHAR
*name
, expression_t
*expr
)
827 decl
= parser_alloc
(ctx
, sizeof
(*decl
));
832 decl
->value_expr
= expr
;
837 static statement_t
*new_const_statement
(parser_ctx_t
*ctx
, const_decl_t
*decls
)
839 const_statement_t
*stat
;
841 stat
= new_statement
(ctx
, STAT_CONST
, sizeof
(*stat
));
849 static statement_t
*link_statements
(statement_t
*head
, statement_t
*tail
)
853 for
(iter
= head
; iter
->next
; iter
= iter
->next
);
859 void *parser_alloc
(parser_ctx_t
*ctx
, size_t size
)
863 ret
= vbsheap_alloc
(&ctx
->heap
, size
);
865 ctx
->hres
= E_OUTOFMEMORY
;
869 HRESULT parse_script
(parser_ctx_t
*ctx
, const WCHAR
*code
)
871 ctx
->code
= ctx
->ptr
= code
;
872 ctx
->end
= ctx
->code
+ strlenW
(ctx
->code
);
874 vbsheap_init
(&ctx
->heap
);
876 ctx
->parse_complete
= FALSE
;
879 ctx
->last_token
= tNL
;
881 ctx
->stats
= ctx
->stats_tail
= NULL
;
882 ctx
->class_decls
= NULL
;
883 ctx
->option_explicit
= FALSE
;
887 if
(FAILED
(ctx
->hres
))
889 if
(!ctx
->parse_complete
) {
890 FIXME
("parser failed on parsing %s\n", debugstr_w
(ctx
->ptr
));
897 void parser_release
(parser_ctx_t
*ctx
)
899 vbsheap_free
(&ctx
->heap
);