[PATCH v6 1/6] vbscript: Avoid special casing the global function when compiling a function's variables.
Gabriel Ivăncescu
gabrielopcode at gmail.com
Fri Nov 8 09:48:07 CST 2019
Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
---
dlls/vbscript/compile.c | 79 ++++++++++++++++++-----------------------
1 file changed, 35 insertions(+), 44 deletions(-)
diff --git a/dlls/vbscript/compile.c b/dlls/vbscript/compile.c
index 7b6649e..674b59e 100644
--- a/dlls/vbscript/compile.c
+++ b/dlls/vbscript/compile.c
@@ -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->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)
+ return E_OUTOFMEMORY;
- 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;
}
}
@@ -1891,13 +1867,14 @@ static void release_compiler(compile_ctx_t *ctx)
HRESULT compile_script(script_ctx_t *script, const WCHAR *src, const WCHAR *delimiter, DWORD flags, vbscode_t **ret)
{
+ dynamic_var_t *global_vars, *var_iter;
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 +1889,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 +1928,24 @@ 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++;
+ global_vars = NULL;
+ for(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;
+
+ var->next = global_vars;
+ global_vars = var;
+ }
+
+ 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,7 +1973,7 @@ 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)
+ for(var_iter = global_vars; var_iter; var_iter = var_iter->next)
script->global_vars[script->global_vars_cnt++] = var_iter;
for(func_iter = ctx.funcs; func_iter; func_iter = func_iter->next) {
--
2.21.0
More information about the wine-devel
mailing list