Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=46588 Signed-off-by: Robert Wilhelm robert.wilhelm@gmx.net --- dlls/vbscript/compile.c | 7 +++++++ dlls/vbscript/parse.h | 2 ++ dlls/vbscript/parser.y | 11 +++++++---- dlls/vbscript/tests/lang.vbs | 4 ++++ dlls/vbscript/tests/run.c | 14 ++++++++++++++ 5 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/dlls/vbscript/compile.c b/dlls/vbscript/compile.c index 164c2d15cfa..5f3aaf076fa 100644 --- a/dlls/vbscript/compile.c +++ b/dlls/vbscript/compile.c @@ -1092,6 +1092,11 @@ static HRESULT compile_dim_statement(compile_ctx_t *ctx, dim_statement_t *stat) { dim_decl_t *dim_decl = stat->dim_decls;
+ if(stat->stat.type != STAT_DIM && ctx->func != &ctx->code->main_code) { + FIXME("private or public declarations are not allowed in functions or subs\n"); + return E_FAIL; + } + while(1) { if(lookup_dim_decls(ctx, dim_decl->name) || lookup_args_name(ctx, dim_decl->name) || lookup_const_decls(ctx, dim_decl->name, FALSE)) { @@ -1328,6 +1333,8 @@ static HRESULT compile_statement(compile_ctx_t *ctx, statement_ctx_t *stat_ctx, hres = compile_const_statement(ctx, (const_statement_t*)stat); break; case STAT_DIM: + case STAT_PRIVATE: + case STAT_PUBLIC: hres = compile_dim_statement(ctx, (dim_statement_t*)stat); break; case STAT_DOWHILE: diff --git a/dlls/vbscript/parse.h b/dlls/vbscript/parse.h index ab81bb3ae41..ee273f9bb74 100644 --- a/dlls/vbscript/parse.h +++ b/dlls/vbscript/parse.h @@ -120,6 +120,8 @@ typedef enum { STAT_FUNC, STAT_IF, STAT_ONERROR, + STAT_PRIVATE, + STAT_PUBLIC, STAT_REDIM, STAT_SELECT, STAT_SET, diff --git a/dlls/vbscript/parser.y b/dlls/vbscript/parser.y index 924d0b973ba..a4e8df6e7c9 100644 --- a/dlls/vbscript/parser.y +++ b/dlls/vbscript/parser.y @@ -49,7 +49,7 @@ static void *new_statement(parser_ctx_t*,statement_type_t,size_t,unsigned); static statement_t *new_call_statement(parser_ctx_t*,unsigned,BOOL,expression_t*); static statement_t *new_assign_statement(parser_ctx_t*,unsigned,expression_t*,expression_t*); static statement_t *new_set_statement(parser_ctx_t*,unsigned,expression_t*,expression_t*); -static statement_t *new_dim_statement(parser_ctx_t*,unsigned,dim_decl_t*); +static statement_t *new_dim_statement(parser_ctx_t*,unsigned,statement_type_t,dim_decl_t*); static statement_t *new_redim_statement(parser_ctx_t*,unsigned,const WCHAR*,BOOL,expression_t*); static statement_t *new_while_statement(parser_ctx_t*,unsigned,statement_type_t,expression_t*,statement_t*); static statement_t *new_forto_statement(parser_ctx_t*,unsigned,const WCHAR*,expression_t*,expression_t*,expression_t*,statement_t*); @@ -197,7 +197,10 @@ SimpleStatement | tCALL UnaryExpression { $$ = new_call_statement(ctx, @$, TRUE, $2); CHECK_ERROR; } | CallExpression '=' Expression { $$ = new_assign_statement(ctx, @$, $1, $3); CHECK_ERROR; } - | tDIM DimDeclList { $$ = new_dim_statement(ctx, @$, $2); CHECK_ERROR; } + | tDIM DimDeclList { $$ = new_dim_statement(ctx, @$, STAT_DIM, $2); CHECK_ERROR; } + | tPRIVATE DimDeclList { $$ = new_dim_statement(ctx, @$, STAT_PRIVATE, $2); CHECK_ERROR; } + | tPUBLIC DimDeclList { $$ = new_dim_statement(ctx, @$, STAT_PUBLIC, $2); CHECK_ERROR; } + | tREDIM Preserve_opt tIdentifier '(' ArgumentList ')' { $$ = new_redim_statement(ctx, @$, $3, $2, $5); CHECK_ERROR; } | IfStatement { $$ = $1; } @@ -811,11 +814,11 @@ static dim_list_t *new_dim(parser_ctx_t *ctx, unsigned val, dim_list_t *next) return ret; }
-static statement_t *new_dim_statement(parser_ctx_t *ctx, unsigned loc, dim_decl_t *decls) +static statement_t *new_dim_statement(parser_ctx_t *ctx, unsigned loc, statement_type_t type, dim_decl_t *decls) { dim_statement_t *stat;
- stat = new_statement(ctx, STAT_DIM, sizeof(*stat), loc); + stat = new_statement(ctx, type, sizeof(*stat), loc); if(!stat) return NULL;
diff --git a/dlls/vbscript/tests/lang.vbs b/dlls/vbscript/tests/lang.vbs index 9f254f502bd..dc16c50faef 100644 --- a/dlls/vbscript/tests/lang.vbs +++ b/dlls/vbscript/tests/lang.vbs @@ -69,6 +69,10 @@ Call ok(x = "xx", "x = " & x & " expected ""xx""")
Dim public1 : public1 = 42 Call ok(public1 = 42, "public1=" & public1 & " expected & " & 42) +Private priv1 : priv1 = 43 +Call ok(priv1 = 43, "priv1=" & priv1 & " expected & " & 43) +Public pub1 : pub1 = 44 +Call ok(pub1 = 44, "pub1=" & pub1 & " expected & " & 44)
Call ok(true <> false, "true <> false is false") Call ok(not (true <> true), "true <> true is true") diff --git a/dlls/vbscript/tests/run.c b/dlls/vbscript/tests/run.c index 6dcd13bf752..06d9514f03f 100644 --- a/dlls/vbscript/tests/run.c +++ b/dlls/vbscript/tests/run.c @@ -2544,6 +2544,20 @@ static void test_parse_errors(void) " throwInt &h87001234&\n" "end if\n", 2, 1 + }, + { + /* private declaration in function or sub*/ + "function f\n" + " private p\n" + "end function\n", + 1, 4 + }, + { + /* public declaration in function or sub */ + "sub f\n" + " public p\n" + "end sub\n", + 1, 4 } }; HRESULT hres; -- 2.26.2
Hi Robert,
On 25.09.2020 11:30, Robert Wilhelm wrote:
@@ -197,7 +197,10 @@ SimpleStatement | tCALL UnaryExpression { $$ = new_call_statement(ctx, @$, TRUE, $2); CHECK_ERROR; } | CallExpression '=' Expression { $$ = new_assign_statement(ctx, @$, $1, $3); CHECK_ERROR; }
- | tDIM DimDeclList { $$ = new_dim_statement(ctx, @$, $2); CHECK_ERROR; }
- | tDIM DimDeclList { $$ = new_dim_statement(ctx, @$, STAT_DIM, $2); CHECK_ERROR; }
- | tPRIVATE DimDeclList { $$ = new_dim_statement(ctx, @$, STAT_PRIVATE, $2); CHECK_ERROR; }
- | tPUBLIC DimDeclList { $$ = new_dim_statement(ctx, @$, STAT_PUBLIC, $2); CHECK_ERROR; }
I wonder if it would fit better in SourceElements. It would guarantee that it's parsed only in the global code and the check in compile_dim_statement would not be needed.
BTW, it should probably affect places like ScriptDisp_GetTypeInfo, but we can leave it for now. It would be probably easier to do after switching to CreateTypeInfo.
Thanks,
Jacek
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=46588 Signed-off-by: Robert Wilhelm robert.wilhelm@gmx.net --- v2: As suggested by Jacek, I moved the the dimdeclaration to SourceElements. No more check is needed in compile_dim_statement. This adds one reduce/shift conflict regarding "Public Default". It should be harmless as bison always shifts. --- dlls/vbscript/parser.y | 19 +++++++++++++------ dlls/vbscript/tests/lang.vbs | 4 ++++ dlls/vbscript/tests/run.c | 14 ++++++++++++++ 3 files changed, 31 insertions(+), 6 deletions(-)
diff --git a/dlls/vbscript/parser.y b/dlls/vbscript/parser.y index 924d0b973ba..d29a9892e69 100644 --- a/dlls/vbscript/parser.y +++ b/dlls/vbscript/parser.y @@ -130,7 +130,7 @@ static statement_t *link_statements(statement_t*,statement_t*); %token <integer> tInt %token <dbl> tDouble
-%type <statement> Statement SimpleStatement StatementNl StatementsNl StatementsNl_opt BodyStatements IfStatement Else_opt +%type <statement> GlobalDimDeclaration Statement SimpleStatement StatementNl StatementsNl StatementsNl_opt BodyStatements IfStatement Else_opt %type <expression> Expression LiteralExpression PrimaryExpression EqualityExpression CallExpression ExpressionNl_opt %type <expression> ConcatExpression AdditiveExpression ModExpression IntdivExpression MultiplicativeExpression ExpExpression %type <expression> NotExpression UnaryExpression AndExpression OrExpression XorExpression EqvExpression SignExpression @@ -142,7 +142,7 @@ static statement_t *link_statements(statement_t*,statement_t*); %type <func_decl> FunctionDecl PropertyDecl %type <elseif> ElseIfs_opt ElseIfs ElseIf %type <class_decl> ClassDeclaration ClassBody -%type <uint> Storage Storage_opt IntegerValue +%type <uint> ClassStorage Storage Storage_opt IntegerValue %type <dim_decl> DimDeclList DimDecl %type <dim_list> DimList %type <const_decl> ConstDecl ConstDeclList @@ -161,9 +161,13 @@ OptionExplicit_opt
SourceElements : /* empty */ + | SourceElements GlobalDimDeclaration StSep { source_add_statement(ctx, $2); } | SourceElements StatementNl { source_add_statement(ctx, $2); } | SourceElements ClassDeclaration { source_add_class(ctx, $2); }
+GlobalDimDeclaration + : Storage DimDeclList { $$ = new_dim_statement(ctx, @$, $2); CHECK_ERROR; } + ExpressionNl_opt : /* empty */ { $$ = NULL; } | Expression tNL { $$ = $1; } @@ -435,9 +439,9 @@ ClassBody | FunctionDecl { $$ = add_class_function(ctx, new_class_decl(ctx), $1); CHECK_ERROR; } | FunctionDecl StSep ClassBody { $$ = add_class_function(ctx, $3, $1); CHECK_ERROR; } /* FIXME: We should use DimDecl here to support arrays, but that conflicts with PropertyDecl. */ - | Storage tIdentifier { dim_decl_t *dim_decl = new_dim_decl(ctx, $2, FALSE, NULL); CHECK_ERROR; + | ClassStorage tIdentifier { dim_decl_t *dim_decl = new_dim_decl(ctx, $2, FALSE, NULL); CHECK_ERROR; $$ = add_dim_prop(ctx, new_class_decl(ctx), dim_decl, $1); CHECK_ERROR; } - | Storage tIdentifier StSep ClassBody { dim_decl_t *dim_decl = new_dim_decl(ctx, $2, FALSE, NULL); CHECK_ERROR; + | ClassStorage tIdentifier StSep ClassBody { dim_decl_t *dim_decl = new_dim_decl(ctx, $2, FALSE, NULL); CHECK_ERROR; $$ = add_dim_prop(ctx, $4, dim_decl, $1); CHECK_ERROR; } | tDIM DimDecl { $$ = add_dim_prop(ctx, new_class_decl(ctx), $2, 0); CHECK_ERROR; } | tDIM DimDecl StSep ClassBody { $$ = add_dim_prop(ctx, $4, $2, 0); CHECK_ERROR; } @@ -460,11 +464,14 @@ FunctionDecl
Storage_opt : /* empty*/ { $$ = 0; } + | ClassStorage { $$ = $1; } + +ClassStorage + : tPUBLIC tDEFAULT { $$ = STORAGE_IS_DEFAULT; } | Storage { $$ = $1; }
Storage - : tPUBLIC tDEFAULT { $$ = STORAGE_IS_DEFAULT; } - | tPUBLIC { $$ = 0; } + : tPUBLIC { $$ = 0; } | tPRIVATE { $$ = STORAGE_IS_PRIVATE; }
ArgumentsDecl_opt diff --git a/dlls/vbscript/tests/lang.vbs b/dlls/vbscript/tests/lang.vbs index 9f254f502bd..dc16c50faef 100644 --- a/dlls/vbscript/tests/lang.vbs +++ b/dlls/vbscript/tests/lang.vbs @@ -69,6 +69,10 @@ Call ok(x = "xx", "x = " & x & " expected ""xx""")
Dim public1 : public1 = 42 Call ok(public1 = 42, "public1=" & public1 & " expected & " & 42) +Private priv1 : priv1 = 43 +Call ok(priv1 = 43, "priv1=" & priv1 & " expected & " & 43) +Public pub1 : pub1 = 44 +Call ok(pub1 = 44, "pub1=" & pub1 & " expected & " & 44)
Call ok(true <> false, "true <> false is false") Call ok(not (true <> true), "true <> true is true") diff --git a/dlls/vbscript/tests/run.c b/dlls/vbscript/tests/run.c index 6dcd13bf752..f0661b71fb8 100644 --- a/dlls/vbscript/tests/run.c +++ b/dlls/vbscript/tests/run.c @@ -2544,6 +2544,20 @@ static void test_parse_errors(void) " throwInt &h87001234&\n" "end if\n", 2, 1 + }, + { + /* private declaration in function or sub*/ + "function f\n" + " private p\n" + "end function\n", + 1, 12 + }, + { + /* public declaration in function or sub */ + "sub f\n" + " public p\n" + "end sub\n", + 1, 11 } }; HRESULT hres; -- 2.26.2
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=79395
Your paranoid android.
=== w2008s64 (32 bit report) ===
vbscript: run.c:2580: Test failed: [18] error char 4 expected 12 run.c:2580: Test failed: [19] error char 4 expected 11
=== w8 (32 bit report) ===
vbscript: run.c:2580: Test failed: [18] error char 4 expected 12 run.c:2580: Test failed: [19] error char 4 expected 11
=== w8adm (32 bit report) ===
vbscript: run.c:2580: Test failed: [18] error char 4 expected 12 run.c:2580: Test failed: [19] error char 4 expected 11
=== w1064v1507 (32 bit report) ===
vbscript: run.c:2580: Test failed: [18] error char 4 expected 12 run.c:2580: Test failed: [19] error char 4 expected 11
=== w1064v1809 (32 bit report) ===
vbscript: run.c:2580: Test failed: [18] error char 4 expected 12 run.c:2580: Test failed: [19] error char 4 expected 11
=== w10pro64 (32 bit report) ===
vbscript: run.c:2580: Test failed: [18] error char 4 expected 12 run.c:2580: Test failed: [19] error char 4 expected 11
=== w10pro64_2scr (32 bit report) ===
vbscript: run.c:2580: Test failed: [18] error char 4 expected 12 run.c:2580: Test failed: [19] error char 4 expected 11
=== w10pro64_ar (32 bit report) ===
vbscript: run.c:2580: Test failed: [18] error char 4 expected 12 run.c:2580: Test failed: [19] error char 4 expected 11
=== w10pro64_he (32 bit report) ===
vbscript: run.c:2580: Test failed: [18] error char 4 expected 12 run.c:2580: Test failed: [19] error char 4 expected 11
=== w10pro64_ja (32 bit report) ===
vbscript: run.c:2580: Test failed: [18] error char 4 expected 12 run.c:2580: Test failed: [19] error char 4 expected 11
=== w10pro64_zh_CN (32 bit report) ===
vbscript: run.c:2580: Test failed: [18] error char 4 expected 12 run.c:2580: Test failed: [19] error char 4 expected 11
=== w2008s64 (64 bit report) ===
vbscript: run.c:2580: Test failed: [18] error char 4 expected 12 run.c:2580: Test failed: [19] error char 4 expected 11
=== w864 (64 bit report) ===
vbscript: run.c:2580: Test failed: [18] error char 4 expected 12 run.c:2580: Test failed: [19] error char 4 expected 11
=== w1064v1507 (64 bit report) ===
vbscript: run.c:2580: Test failed: [18] error char 4 expected 12 run.c:2580: Test failed: [19] error char 4 expected 11
=== w1064v1809 (64 bit report) ===
vbscript: run.c:2580: Test failed: [18] error char 4 expected 12 run.c:2580: Test failed: [19] error char 4 expected 11
=== w10pro64 (64 bit report) ===
vbscript: run.c:2580: Test failed: [18] error char 4 expected 12 run.c:2580: Test failed: [19] error char 4 expected 11
=== w10pro64_2scr (64 bit report) ===
vbscript: run.c:2580: Test failed: [18] error char 4 expected 12 run.c:2580: Test failed: [19] error char 4 expected 11
=== w10pro64_ar (64 bit report) ===
vbscript: run.c:2580: Test failed: [18] error char 4 expected 12 run.c:2580: Test failed: [19] error char 4 expected 11
=== w10pro64_he (64 bit report) ===
vbscript: run.c:2580: Test failed: [18] error char 4 expected 12 run.c:2580: Test failed: [19] error char 4 expected 11
=== w10pro64_ja (64 bit report) ===
vbscript: run.c:2580: Test failed: [18] error char 4 expected 12 run.c:2580: Test failed: [19] error char 4 expected 11
=== w10pro64_zh_CN (64 bit report) ===
vbscript: run.c:2580: Test failed: [18] error char 4 expected 12 run.c:2580: Test failed: [19] error char 4 expected 11
Hi Robert,
On 28.09.2020 12:47, Robert Wilhelm wrote:
v2: As suggested by Jacek, I moved the the dimdeclaration to SourceElements. No more check is needed in compile_dim_statement. This adds one reduce/shift conflict regarding "Public Default". It should be harmless as bison always shifts.
It seems that simply partially duplicating Storage rule can avoid the conflict. As for the test bot, it seem that Windows is not consequent about how it reports the error, so I stripped that part and sent a new version.
Thanks,
Jacek
Hi Jacek,
Your version looks very nice. Thanks a lot for your timely reviews and for cleaning up my patch.
Robert
On Mon, 2020-09-28 at 20:12 +0200, Jacek Caban wrote:
Hi Robert,
On 28.09.2020 12:47, Robert Wilhelm wrote:
v2: As suggested by Jacek, I moved the the dimdeclaration to SourceElements. No more check is needed in compile_dim_statement. This adds one reduce/shift conflict regarding "Public Default". It should be harmless as bison always shifts.
It seems that simply partially duplicating Storage rule can avoid the conflict. As for the test bot, it seem that Windows is not consequent about how it reports the error, so I stripped that part and sent a new version.
Thanks,
Jacek