This adds support for having lists in redim statements.
``` Dim x, y Redim x(20), y(30) ```
From: Jason Millard jsm174@gmail.com
--- dlls/vbscript/compile.c | 29 +++++++++++++++++++---------- dlls/vbscript/parse.h | 9 +++++++-- dlls/vbscript/parser.y | 34 ++++++++++++++++++++++++++++------ 3 files changed, 54 insertions(+), 18 deletions(-)
diff --git a/dlls/vbscript/compile.c b/dlls/vbscript/compile.c index 79819c39026..4e1cd0ee399 100644 --- a/dlls/vbscript/compile.c +++ b/dlls/vbscript/compile.c @@ -1165,19 +1165,28 @@ static HRESULT compile_dim_statement(compile_ctx_t *ctx, dim_statement_t *stat)
static HRESULT compile_redim_statement(compile_ctx_t *ctx, redim_statement_t *stat) { - unsigned arg_cnt; - HRESULT hres; + redim_decl_t * redim_decl = stat->redim_decls;
- hres = compile_args(ctx, stat->dims, &arg_cnt); - if(FAILED(hres)) - return hres; + while(1) { + unsigned arg_cnt; + HRESULT hres;
- hres = push_instr_bstr_uint(ctx, stat->preserve ? OP_redim_preserve : OP_redim, stat->identifier, arg_cnt); - if(FAILED(hres)) - return hres; + hres = compile_args(ctx, redim_decl->expression, &arg_cnt); + if(FAILED(hres)) + return hres;
- if(!emit_catch(ctx, 0)) - return E_OUTOFMEMORY; + hres = push_instr_bstr_uint(ctx, stat->preserve ? OP_redim_preserve : OP_redim, redim_decl->identifier, arg_cnt); + if(FAILED(hres)) + return hres; + + if(!emit_catch(ctx, 0)) + return E_OUTOFMEMORY; + + if(!redim_decl->next) + break; + + redim_decl = redim_decl->next; + }
return S_OK; } diff --git a/dlls/vbscript/parse.h b/dlls/vbscript/parse.h index 32cfcfe75c5..cec2c156825 100644 --- a/dlls/vbscript/parse.h +++ b/dlls/vbscript/parse.h @@ -172,11 +172,16 @@ typedef struct _dim_statement_t { dim_decl_t *dim_decls; } dim_statement_t;
+typedef struct _redim_decl_t { + const WCHAR *identifier; + expression_t *expression; + struct _redim_decl_t *next; +} redim_decl_t; + typedef struct { statement_t stat; - const WCHAR *identifier; BOOL preserve; - expression_t *dims; + redim_decl_t *redim_decls; } redim_statement_t;
typedef struct _arg_decl_t { diff --git a/dlls/vbscript/parser.y b/dlls/vbscript/parser.y index 90ed921c2a9..0754e47fbf9 100644 --- a/dlls/vbscript/parser.y +++ b/dlls/vbscript/parser.y @@ -51,7 +51,7 @@ static statement_t *new_call_statement(parser_ctx_t*,unsigned,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_redim_statement(parser_ctx_t*,unsigned,const WCHAR*,BOOL,expression_t*); +static statement_t *new_redim_statement(parser_ctx_t*,unsigned,BOOL,redim_decl_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*); static statement_t *new_foreach_statement(parser_ctx_t*,unsigned,const WCHAR*,expression_t*,statement_t*); @@ -64,6 +64,7 @@ static statement_t *new_with_statement(parser_ctx_t*,unsigned,expression_t*,stat
static dim_decl_t *new_dim_decl(parser_ctx_t*,const WCHAR*,BOOL,dim_list_t*); static dim_list_t *new_dim(parser_ctx_t*,unsigned,dim_list_t*); +static redim_decl_t *new_redim_decl(parser_ctx_t*,const WCHAR*,expression_t*); static elseif_decl_t *new_elseif_decl(parser_ctx_t*,unsigned,expression_t*,statement_t*); static function_decl_t *new_function_decl(parser_ctx_t*,const WCHAR*,function_type_t,unsigned,arg_decl_t*,statement_t*); static arg_decl_t *new_argument_decl(parser_ctx_t*,const WCHAR*,BOOL); @@ -100,6 +101,7 @@ static statement_t *link_statements(statement_t*,statement_t*); elseif_decl_t *elseif; dim_decl_t *dim_decl; dim_list_t *dim_list; + redim_decl_t *redim_decl; function_decl_t *func_decl; arg_decl_t *arg_decl; class_decl_t *class_decl; @@ -150,6 +152,7 @@ static statement_t *link_statements(statement_t*,statement_t*); %type <uint> Storage Storage_opt IntegerValue %type <dim_decl> DimDeclList DimDecl %type <dim_list> DimList +%type <redim_decl> RedimDeclList RedimDecl %type <const_decl> ConstDecl ConstDeclList %type <string> Identifier %type <case_clausule> CaseClausules @@ -209,8 +212,7 @@ SimpleStatement | CallExpression '=' Expression { $$ = new_assign_statement(ctx, @$, $1, $3); CHECK_ERROR; } | tDIM DimDeclList { $$ = new_dim_statement(ctx, @$, $2); CHECK_ERROR; } - | tREDIM Preserve_opt tIdentifier '(' ArgumentList ')' - { $$ = new_redim_statement(ctx, @$, $3, $2, $5); CHECK_ERROR; } + | tREDIM Preserve_opt RedimDeclList { $$ = new_redim_statement(ctx, @$, $2, $3); CHECK_ERROR; } | IfStatement { $$ = $1; } | tWHILE Expression StSep StatementsNl_opt tWEND { $$ = new_while_statement(ctx, @$, STAT_WHILE, $2, $4); CHECK_ERROR; } @@ -264,6 +266,13 @@ DimList : IntegerValue { $$ = new_dim(ctx, $1, NULL); } | IntegerValue ',' DimList { $$ = new_dim(ctx, $1, $3); }
+RedimDeclList + : RedimDecl { $$ = $1; } + | RedimDecl ',' RedimDecl { $1->next = $3; $$ = $1; } + +RedimDecl + : tIdentifier '(' ArgumentList ')' { $$ = new_redim_decl(ctx, $1, $3); CHECK_ERROR; } + ConstDeclList : ConstDecl { $$ = $1; } | ConstDecl ',' ConstDeclList { $1->next = $3; $$ = $1; } @@ -846,7 +855,21 @@ static statement_t *new_dim_statement(parser_ctx_t *ctx, unsigned loc, dim_decl_ return &stat->stat; }
-static statement_t *new_redim_statement(parser_ctx_t *ctx, unsigned loc, const WCHAR *identifier, BOOL preserve, expression_t *dims) +static redim_decl_t *new_redim_decl(parser_ctx_t *ctx, const WCHAR *identifier, expression_t *expression) +{ + redim_decl_t *decl; + + decl = parser_alloc(ctx, sizeof(*decl)); + if(!decl) + return NULL; + + decl->identifier = identifier; + decl->expression = expression; + decl->next = NULL; + return decl; +} + +static statement_t *new_redim_statement(parser_ctx_t *ctx, unsigned loc, BOOL preserve, redim_decl_t *decls) { redim_statement_t *stat;
@@ -854,9 +877,8 @@ static statement_t *new_redim_statement(parser_ctx_t *ctx, unsigned loc, const W if(!stat) return NULL;
- stat->identifier = identifier; stat->preserve = preserve; - stat->dims = dims; + stat->redim_decls = decls; return &stat->stat; }
Hi, Jason. Thank you for the fix, it's almost identical to what I sent yesterday as !1328, except for a lack of tests.
This merge request was closed by Jason Millard.
Sorry, I didn't realize that! This was my first time trying to submit a merge request and I was just trying to figure out the system here.
We can close this merge request then.