vbscript: Avoid special casing the global function when compiling a function's variables.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com> Signed-off-by: Jacek Caban <jacek@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
31046449e6
commit
71ce853032
|
@ -56,7 +56,6 @@ typedef struct {
|
|||
|
||||
dim_decl_t *dim_decls;
|
||||
dim_decl_t *dim_decls_tail;
|
||||
dynamic_var_t *global_vars;
|
||||
|
||||
const_decl_t *const_decls;
|
||||
const_decl_t *global_consts;
|
||||
|
@ -1479,43 +1478,19 @@ static HRESULT compile_func(compile_ctx_t *ctx, statement_t *stat, function_t *f
|
|||
|
||||
if(func->var_cnt) {
|
||||
dim_decl_t *dim_decl;
|
||||
unsigned i;
|
||||
|
||||
if(func->type == FUNC_GLOBAL) {
|
||||
dynamic_var_t *new_var;
|
||||
func->vars = compiler_alloc(ctx->code, func->var_cnt * sizeof(var_desc_t));
|
||||
if(!func->vars)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
func->var_cnt = 0;
|
||||
|
||||
for(dim_decl = ctx->dim_decls; dim_decl; dim_decl = dim_decl->next) {
|
||||
new_var = compiler_alloc(ctx->code, sizeof(*new_var));
|
||||
if(!new_var)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
new_var->name = compiler_alloc_string(ctx->code, dim_decl->name);
|
||||
if(!new_var->name)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
V_VT(&new_var->v) = VT_EMPTY;
|
||||
new_var->is_const = FALSE;
|
||||
new_var->array = NULL;
|
||||
|
||||
new_var->next = ctx->global_vars;
|
||||
ctx->global_vars = new_var;
|
||||
}
|
||||
}else {
|
||||
unsigned i;
|
||||
|
||||
func->vars = compiler_alloc(ctx->code, func->var_cnt * sizeof(var_desc_t));
|
||||
if(!func->vars)
|
||||
for(dim_decl = ctx->dim_decls, i=0; dim_decl; dim_decl = dim_decl->next, i++) {
|
||||
func->vars[i].name = compiler_alloc_string(ctx->code, dim_decl->name);
|
||||
if(!func->vars[i].name)
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
for(dim_decl = ctx->dim_decls, i=0; dim_decl; dim_decl = dim_decl->next, i++) {
|
||||
func->vars[i].name = compiler_alloc_string(ctx->code, dim_decl->name);
|
||||
if(!func->vars[i].name)
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
assert(i == func->var_cnt);
|
||||
}
|
||||
|
||||
assert(i == func->var_cnt);
|
||||
}
|
||||
|
||||
if(func->array_cnt) {
|
||||
|
@ -1809,12 +1784,13 @@ static BOOL lookup_script_identifier(script_ctx_t *script, const WCHAR *identifi
|
|||
|
||||
static HRESULT check_script_collisions(compile_ctx_t *ctx, script_ctx_t *script)
|
||||
{
|
||||
unsigned i, var_cnt = ctx->code->main_code.var_cnt;
|
||||
var_desc_t *vars = ctx->code->main_code.vars;
|
||||
class_desc_t *class;
|
||||
dynamic_var_t *var;
|
||||
|
||||
for(var = ctx->global_vars; var; var = var->next) {
|
||||
if(lookup_script_identifier(script, var->name)) {
|
||||
FIXME("%s: redefined\n", debugstr_w(var->name));
|
||||
for(i = 0; i < var_cnt; i++) {
|
||||
if(lookup_script_identifier(script, vars[i].name)) {
|
||||
FIXME("%s: redefined\n", debugstr_w(vars[i].name));
|
||||
return E_FAIL;
|
||||
}
|
||||
}
|
||||
|
@ -1894,10 +1870,10 @@ HRESULT compile_script(script_ctx_t *script, const WCHAR *src, const WCHAR *deli
|
|||
function_t *new_func, *func_iter;
|
||||
function_decl_t *func_decl;
|
||||
class_decl_t *class_decl;
|
||||
dynamic_var_t *var_iter;
|
||||
compile_ctx_t ctx;
|
||||
vbscode_t *code;
|
||||
size_t cnt;
|
||||
unsigned i;
|
||||
HRESULT hres;
|
||||
|
||||
if (!src) src = L"";
|
||||
|
@ -1912,7 +1888,6 @@ HRESULT compile_script(script_ctx_t *script, const WCHAR *src, const WCHAR *deli
|
|||
|
||||
ctx.funcs = NULL;
|
||||
ctx.func_decls = NULL;
|
||||
ctx.global_vars = NULL;
|
||||
ctx.classes = NULL;
|
||||
ctx.labels = NULL;
|
||||
ctx.global_consts = NULL;
|
||||
|
@ -1952,9 +1927,7 @@ HRESULT compile_script(script_ctx_t *script, const WCHAR *src, const WCHAR *deli
|
|||
return compile_error(script, hres);
|
||||
}
|
||||
|
||||
cnt = script->global_vars_cnt;
|
||||
for(var_iter = ctx.global_vars; var_iter; var_iter = var_iter->next)
|
||||
cnt++;
|
||||
cnt = script->global_vars_cnt + ctx.code->main_code.var_cnt;
|
||||
if(cnt > script->global_vars_size) {
|
||||
dynamic_var_t **new_vars;
|
||||
if(script->global_vars)
|
||||
|
@ -1982,8 +1955,22 @@ HRESULT compile_script(script_ctx_t *script, const WCHAR *src, const WCHAR *deli
|
|||
script->global_funcs_size = cnt;
|
||||
}
|
||||
|
||||
for(var_iter = ctx.global_vars; var_iter; var_iter = var_iter->next)
|
||||
script->global_vars[script->global_vars_cnt++] = var_iter;
|
||||
for(i = 0; i < ctx.code->main_code.var_cnt; i++) {
|
||||
dynamic_var_t *var = compiler_alloc(ctx.code, sizeof(*var));
|
||||
if(!var) {
|
||||
release_compiler(&ctx);
|
||||
return compile_error(script, E_OUTOFMEMORY);
|
||||
}
|
||||
|
||||
var->name = ctx.code->main_code.vars[i].name;
|
||||
V_VT(&var->v) = VT_EMPTY;
|
||||
var->is_const = FALSE;
|
||||
var->array = NULL;
|
||||
|
||||
script->global_vars[script->global_vars_cnt + i] = var;
|
||||
}
|
||||
|
||||
script->global_vars_cnt += ctx.code->main_code.var_cnt;
|
||||
|
||||
for(func_iter = ctx.funcs; func_iter; func_iter = func_iter->next) {
|
||||
unsigned i;
|
||||
|
|
Loading…
Reference in New Issue