Jacek Caban : jscript: Moved collecting variable declarations from parser to compiler.

Alexandre Julliard julliard at winehq.org
Wed Apr 25 13:40:25 CDT 2012


Module: wine
Branch: master
Commit: 474f1152b23cd8a0d311f31d67a01a4e573864cb
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=474f1152b23cd8a0d311f31d67a01a4e573864cb

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Wed Apr 25 11:26:21 2012 +0200

jscript: Moved collecting variable declarations from parser to compiler.

---

 dlls/jscript/compile.c |   44 ++++++++++++++++++++++++++++++--------------
 dlls/jscript/engine.h  |   10 +---------
 dlls/jscript/parser.y  |   13 +------------
 3 files changed, 32 insertions(+), 35 deletions(-)

diff --git a/dlls/jscript/compile.c b/dlls/jscript/compile.c
index 796fb7b..c903651 100644
--- a/dlls/jscript/compile.c
+++ b/dlls/jscript/compile.c
@@ -53,6 +53,9 @@ typedef struct {
 
     statement_ctx_t *stat_ctx;
     function_code_t *func;
+
+    variable_declaration_t *var_head;
+    variable_declaration_t *var_tail;
 } compiler_ctx_t;
 
 static const struct {
@@ -988,7 +991,19 @@ static HRESULT compile_variable_list(compiler_ctx_t *ctx, variable_declaration_t
     variable_declaration_t *iter;
     HRESULT hres;
 
+    assert(list != NULL);
+
+    if(ctx->var_tail)
+        ctx->var_tail->global_next = list;
+    else
+        ctx->var_head = list;
+
     for(iter = list; iter; iter = iter->next) {
+        ctx->func->var_cnt++;
+        iter->global_next = iter->next;
+        if(!iter->next)
+            ctx->var_tail = iter;
+
         if(!iter->expr)
             continue;
 
@@ -1771,13 +1786,15 @@ static HRESULT init_code(compiler_ctx_t *compiler, const WCHAR *source)
 static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source, function_expression_t *func_expr,
         BOOL from_eval, function_code_t *func)
 {
+    variable_declaration_t *var_iter;
     function_declaration_t *iter;
-    var_list_t *var_iter;
     unsigned off, i;
     HRESULT hres;
 
     TRACE("\n");
 
+    ctx->var_head = ctx->var_tail = NULL;
+
     off = ctx->code_off;
     ctx->func = func;
     hres = compile_block_statement(ctx, source->statement);
@@ -1822,6 +1839,18 @@ static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source,
         }
     }
 
+    func->variables = compiler_alloc(ctx->code, func->var_cnt * sizeof(*func->variables));
+    if(!func->variables)
+        return E_OUTOFMEMORY;
+
+    for(var_iter = ctx->var_head, i=0; var_iter; var_iter = var_iter->global_next, i++) {
+        func->variables[i] = compiler_alloc_bstr(ctx, var_iter->identifier);
+        if(!func->variables[i])
+            return E_OUTOFMEMORY;
+    }
+
+    assert(i == func->var_cnt);
+
     func->funcs = compiler_alloc(ctx->code, func->func_cnt * sizeof(*func->funcs));
     if(!func->funcs)
         return E_OUTOFMEMORY;
@@ -1835,19 +1864,6 @@ static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source,
 
     assert(i == func->func_cnt);
 
-    for(var_iter = source->variables; var_iter; var_iter = var_iter->next)
-        func->var_cnt++;
-
-    func->variables = compiler_alloc(ctx->code, func->var_cnt * sizeof(*func->variables));
-    if(!func->variables)
-        return E_OUTOFMEMORY;
-
-    for(var_iter = source->variables, i=0; var_iter; var_iter = var_iter->next, i++) {
-        func->variables[i] = compiler_alloc_bstr(ctx, var_iter->identifier);
-        if(!func->variables[i])
-            return E_OUTOFMEMORY;
-    }
-
     return S_OK;
 }
 
diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h
index 20f3c45..6a318c7 100644
--- a/dlls/jscript/engine.h
+++ b/dlls/jscript/engine.h
@@ -27,17 +27,9 @@ typedef struct _function_declaration_t {
     struct _function_declaration_t *next;
 } function_declaration_t;
 
-typedef struct _var_list_t {
-    const WCHAR *identifier;
-
-    struct _var_list_t *next;
-} var_list_t;
-
 typedef struct _func_stack {
     function_declaration_t *func_head;
     function_declaration_t *func_tail;
-    var_list_t *var_head;
-    var_list_t *var_tail;
 
     struct _func_stack *next;
 } func_stack_t;
@@ -302,6 +294,7 @@ typedef struct _variable_declaration_t {
     expression_t *expr;
 
     struct _variable_declaration_t *next;
+    struct _variable_declaration_t *global_next; /* for compiler */
 } variable_declaration_t;
 
 typedef enum {
@@ -505,7 +498,6 @@ struct _source_elements_t {
     statement_t *statement;
     statement_t *statement_tail;
     function_declaration_t *functions;
-    var_list_t *variables;
 };
 
 struct _function_expression_t {
diff --git a/dlls/jscript/parser.y b/dlls/jscript/parser.y
index 6f31e15..c5984b2 100644
--- a/dlls/jscript/parser.y
+++ b/dlls/jscript/parser.y
@@ -1051,19 +1051,11 @@ static statement_t *new_block_statement(parser_ctx_t *ctx, statement_list_t *lis
 static variable_declaration_t *new_variable_declaration(parser_ctx_t *ctx, const WCHAR *identifier, expression_t *expr)
 {
     variable_declaration_t *ret = parser_alloc(ctx, sizeof(variable_declaration_t));
-    var_list_t *var_list = parser_alloc(ctx, sizeof(var_list_t));
 
     ret->identifier = identifier;
     ret->expr = expr;
     ret->next = NULL;
-
-    var_list->identifier = identifier;
-    var_list->next = NULL;
-
-    if(ctx->func_stack->var_tail)
-        ctx->func_stack->var_tail = ctx->func_stack->var_tail->next = var_list;
-    else
-        ctx->func_stack->var_head = ctx->func_stack->var_tail = var_list;
+    ret->global_next = NULL;
 
     return ret;
 }
@@ -1503,7 +1495,6 @@ static void push_func(parser_ctx_t *ctx)
     func_stack_t *new_func = parser_alloc_tmp(ctx, sizeof(func_stack_t));
 
     new_func->func_head = new_func->func_tail = NULL;
-    new_func->var_head = new_func->var_tail = NULL;
 
     new_func->next = ctx->func_stack;
     ctx->func_stack = new_func;
@@ -1512,7 +1503,6 @@ static void push_func(parser_ctx_t *ctx)
 static source_elements_t *function_body_parsed(parser_ctx_t *ctx, source_elements_t *source)
 {
     source->functions = ctx->func_stack->func_head;
-    source->variables = ctx->func_stack->var_head;
     pop_func(ctx);
 
     return source;
@@ -1521,7 +1511,6 @@ static source_elements_t *function_body_parsed(parser_ctx_t *ctx, source_element
 static void program_parsed(parser_ctx_t *ctx, source_elements_t *source)
 {
     source->functions = ctx->func_stack->func_head;
-    source->variables = ctx->func_stack->var_head;
     pop_func(ctx);
 
     ctx->source = source;




More information about the wine-cvs mailing list