[PATCH v2] vbscript: Allow public and private declarations in global scope.

Robert Wilhelm robert.wilhelm at gmx.net
Mon Sep 28 05:47:52 CDT 2020


Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=46588
Signed-off-by: Robert Wilhelm <robert.wilhelm at 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





More information about the wine-devel mailing list