Commit 45053135 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

vbscript: Add support for argument list in ReDim.

parent 82182a11
...@@ -1165,19 +1165,26 @@ static HRESULT compile_dim_statement(compile_ctx_t *ctx, dim_statement_t *stat) ...@@ -1165,19 +1165,26 @@ 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) static HRESULT compile_redim_statement(compile_ctx_t *ctx, redim_statement_t *stat)
{ {
redim_decl_t *decl = stat->redim_decls;
unsigned arg_cnt; unsigned arg_cnt;
HRESULT hres; HRESULT hres;
hres = compile_args(ctx, stat->dims, &arg_cnt); while(1) {
if(FAILED(hres)) hres = compile_args(ctx, decl->dims, &arg_cnt);
return hres; if(FAILED(hres))
return hres;
hres = push_instr_bstr_uint(ctx, stat->preserve ? OP_redim_preserve : OP_redim, stat->identifier, arg_cnt); hres = push_instr_bstr_uint(ctx, stat->preserve ? OP_redim_preserve : OP_redim, decl->identifier, arg_cnt);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
if(!emit_catch(ctx, 0)) if(!emit_catch(ctx, 0))
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
if(!decl->next)
break;
decl = decl->next;
}
return S_OK; return S_OK;
} }
......
...@@ -172,11 +172,16 @@ typedef struct _dim_statement_t { ...@@ -172,11 +172,16 @@ typedef struct _dim_statement_t {
dim_decl_t *dim_decls; dim_decl_t *dim_decls;
} dim_statement_t; } dim_statement_t;
typedef struct _redim_decl_t {
const WCHAR *identifier;
expression_t *dims;
struct _redim_decl_t *next;
} redim_decl_t;
typedef struct { typedef struct {
statement_t stat; statement_t stat;
const WCHAR *identifier;
BOOL preserve; BOOL preserve;
expression_t *dims; redim_decl_t *redim_decls;
} redim_statement_t; } redim_statement_t;
typedef struct _arg_decl_t { typedef struct _arg_decl_t {
......
...@@ -51,7 +51,7 @@ static statement_t *new_call_statement(parser_ctx_t*,unsigned,expression_t*); ...@@ -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_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_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,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_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_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*); 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 ...@@ -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_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 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 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 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); 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*); ...@@ -100,6 +101,7 @@ static statement_t *link_statements(statement_t*,statement_t*);
elseif_decl_t *elseif; elseif_decl_t *elseif;
dim_decl_t *dim_decl; dim_decl_t *dim_decl;
dim_list_t *dim_list; dim_list_t *dim_list;
redim_decl_t *redim_decl;
function_decl_t *func_decl; function_decl_t *func_decl;
arg_decl_t *arg_decl; arg_decl_t *arg_decl;
class_decl_t *class_decl; class_decl_t *class_decl;
...@@ -150,6 +152,7 @@ static statement_t *link_statements(statement_t*,statement_t*); ...@@ -150,6 +152,7 @@ static statement_t *link_statements(statement_t*,statement_t*);
%type <uint> Storage Storage_opt IntegerValue %type <uint> Storage Storage_opt IntegerValue
%type <dim_decl> DimDeclList DimDecl %type <dim_decl> DimDeclList DimDecl
%type <dim_list> DimList %type <dim_list> DimList
%type <redim_decl> ReDimDeclList ReDimDecl
%type <const_decl> ConstDecl ConstDeclList %type <const_decl> ConstDecl ConstDeclList
%type <string> Identifier %type <string> Identifier
%type <case_clausule> CaseClausules %type <case_clausule> CaseClausules
...@@ -209,8 +212,7 @@ SimpleStatement ...@@ -209,8 +212,7 @@ SimpleStatement
| CallExpression '=' Expression | CallExpression '=' Expression
{ $$ = new_assign_statement(ctx, @$, $1, $3); CHECK_ERROR; } { $$ = new_assign_statement(ctx, @$, $1, $3); CHECK_ERROR; }
| tDIM DimDeclList { $$ = new_dim_statement(ctx, @$, $2); CHECK_ERROR; } | tDIM DimDeclList { $$ = new_dim_statement(ctx, @$, $2); CHECK_ERROR; }
| tREDIM Preserve_opt tIdentifier '(' ArgumentList ')' | tREDIM Preserve_opt ReDimDeclList { $$ = new_redim_statement(ctx, @$, $2, $3); CHECK_ERROR; }
{ $$ = new_redim_statement(ctx, @$, $3, $2, $5); CHECK_ERROR; }
| IfStatement { $$ = $1; } | IfStatement { $$ = $1; }
| tWHILE Expression StSep StatementsNl_opt tWEND | tWHILE Expression StSep StatementsNl_opt tWEND
{ $$ = new_while_statement(ctx, @$, STAT_WHILE, $2, $4); CHECK_ERROR; } { $$ = new_while_statement(ctx, @$, STAT_WHILE, $2, $4); CHECK_ERROR; }
...@@ -251,6 +253,13 @@ Preserve_opt ...@@ -251,6 +253,13 @@ Preserve_opt
: /* empty */ { $$ = FALSE; } : /* empty */ { $$ = FALSE; }
| tPRESERVE { $$ = TRUE; } | tPRESERVE { $$ = TRUE; }
ReDimDecl
: tIdentifier '(' ArgumentList ')' { $$ = new_redim_decl(ctx, $1, $3); CHECK_ERROR; }
ReDimDeclList
: ReDimDecl { $$ = $1; }
| ReDimDecl ',' ReDimDeclList { $1->next = $3; $$ = $1; }
DimDeclList DimDeclList
: DimDecl { $$ = $1; } : DimDecl { $$ = $1; }
| DimDecl ',' DimDeclList { $1->next = $3; $$ = $1; } | DimDecl ',' DimDeclList { $1->next = $3; $$ = $1; }
...@@ -846,7 +855,21 @@ static statement_t *new_dim_statement(parser_ctx_t *ctx, unsigned loc, dim_decl_ ...@@ -846,7 +855,21 @@ static statement_t *new_dim_statement(parser_ctx_t *ctx, unsigned loc, dim_decl_
return &stat->stat; 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 *dims)
{
redim_decl_t *decl;
decl = parser_alloc(ctx, sizeof(*decl));
if(!decl)
return NULL;
decl->identifier = identifier;
decl->dims = dims;
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; redim_statement_t *stat;
...@@ -854,9 +877,8 @@ static statement_t *new_redim_statement(parser_ctx_t *ctx, unsigned loc, const W ...@@ -854,9 +877,8 @@ static statement_t *new_redim_statement(parser_ctx_t *ctx, unsigned loc, const W
if(!stat) if(!stat)
return NULL; return NULL;
stat->identifier = identifier;
stat->preserve = preserve; stat->preserve = preserve;
stat->dims = dims; stat->redim_decls = decls;
return &stat->stat; return &stat->stat;
} }
......
...@@ -1503,6 +1503,44 @@ e = err.number ...@@ -1503,6 +1503,44 @@ e = err.number
on error goto 0 on error goto 0
todo_wine_ok e = 10, "e = " & e todo_wine_ok e = 10, "e = " & e
sub TestReDimList
dim x, y
x = Array(1)
y = Array(1)
redim x(1, 3), y(2)
ok ubound(x, 1) = 1, "ubound(x, 1) = " & ubound(x, 1)
ok ubound(x, 2) = 3, "ubound(x, 2) = " & ubound(x, 2)
ok ubound(y, 1) = 2, "ubound(y, 1) = " & ubound(y, 1)
x(0,0) = 1.1
x(0,1) = 1.2
x(0,2) = 1.3
x(0,3) = 1.4
x(1,0) = 2.1
x(1,1) = 2.2
x(1,2) = 2.3
x(1,3) = 2.4
y(0) = 2.1
y(1) = 2.2
y(2) = 2.3
redim preserve x(1,1), y(3)
ok ubound(x, 1) = 1, "ubound(x, 1) = " & ubound(x, 1)
ok ubound(x, 2) = 1, "ubound(x, 2) = " & ubound(x, 2)
ok x(0,0) = 1.1, "x(0,0) = " & x(0,0)
ok x(0,1) = 1.2, "x(0,1) = " & x(0,1)
ok x(1,0) = 2.1, "x(1,0) = " & x(1,0)
ok x(1,1) = 2.2, "x(1,1) = " & x(1,1)
ok ubound(y, 1) = 3, "ubound(y, 1) = " & ubound(y, 1)
ok y(0) = 2.1, "y(0) = " & y(0)
ok y(1) = 2.2, "y(1) = " & y(1)
ok y(2) = 2.3, "y(2) = " & y(2)
ok y(3) = vbEmpty, "y(3) = " & y(3)
end sub
call TestReDimList
Class ArrClass Class ArrClass
Dim classarr(3) Dim classarr(3)
Dim classnoarr() Dim classnoarr()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment