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

Robert Wilhelm robert.wilhelm at gmx.net
Fri Sep 25 04:30:04 CDT 2020


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





More information about the wine-devel mailing list