Commit ca15adfd authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Get rid of parser function collecting hack by moving the logic to compiler.

parent 7b5af236
...@@ -56,6 +56,9 @@ typedef struct { ...@@ -56,6 +56,9 @@ typedef struct {
variable_declaration_t *var_head; variable_declaration_t *var_head;
variable_declaration_t *var_tail; variable_declaration_t *var_tail;
function_expression_t *func_head;
function_expression_t *func_tail;
} compiler_ctx_t; } compiler_ctx_t;
static const struct { static const struct {
...@@ -815,6 +818,8 @@ static HRESULT compile_object_literal(compiler_ctx_t *ctx, property_value_expres ...@@ -815,6 +818,8 @@ static HRESULT compile_object_literal(compiler_ctx_t *ctx, property_value_expres
static HRESULT compile_function_expression(compiler_ctx_t *ctx, function_expression_t *expr) static HRESULT compile_function_expression(compiler_ctx_t *ctx, function_expression_t *expr)
{ {
ctx->func_tail = ctx->func_tail ? (ctx->func_tail->next = expr) : (ctx->func_head = expr);
/* FIXME: not exactly right */ /* FIXME: not exactly right */
if(expr->identifier) { if(expr->identifier) {
ctx->func->func_cnt++; ctx->func->func_cnt++;
...@@ -1787,13 +1792,14 @@ static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source, ...@@ -1787,13 +1792,14 @@ static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source,
BOOL from_eval, function_code_t *func) BOOL from_eval, function_code_t *func)
{ {
variable_declaration_t *var_iter; variable_declaration_t *var_iter;
function_declaration_t *iter; function_expression_t *iter;
unsigned off, i; unsigned off, i;
HRESULT hres; HRESULT hres;
TRACE("\n"); TRACE("\n");
ctx->var_head = ctx->var_tail = NULL; ctx->var_head = ctx->var_tail = NULL;
ctx->func_head = ctx->func_tail = NULL;
off = ctx->code_off; off = ctx->code_off;
ctx->func = func; ctx->func = func;
...@@ -1856,8 +1862,8 @@ static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source, ...@@ -1856,8 +1862,8 @@ static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source,
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
memset(func->funcs, 0, func->func_cnt * sizeof(*func->funcs)); memset(func->funcs, 0, func->func_cnt * sizeof(*func->funcs));
for(iter = source->functions, i=0; iter; iter = iter->next, i++) { for(iter = ctx->func_head, i=0; iter; iter = iter->next, i++) {
hres = compile_function(ctx, iter->expr->source_elements, iter->expr, FALSE, func->funcs+i); hres = compile_function(ctx, iter->source_elements, iter, FALSE, func->funcs+i);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
} }
......
...@@ -17,23 +17,9 @@ ...@@ -17,23 +17,9 @@
*/ */
typedef struct _source_elements_t source_elements_t; typedef struct _source_elements_t source_elements_t;
typedef struct _function_expression_t function_expression_t;
typedef struct _expression_t expression_t; typedef struct _expression_t expression_t;
typedef struct _statement_t statement_t; typedef struct _statement_t statement_t;
typedef struct _function_declaration_t {
function_expression_t *expr;
struct _function_declaration_t *next;
} function_declaration_t;
typedef struct _func_stack {
function_declaration_t *func_head;
function_declaration_t *func_tail;
struct _func_stack *next;
} func_stack_t;
typedef struct { typedef struct {
const WCHAR *begin; const WCHAR *begin;
const WCHAR *end; const WCHAR *end;
...@@ -47,8 +33,6 @@ typedef struct { ...@@ -47,8 +33,6 @@ typedef struct {
HRESULT hres; HRESULT hres;
jsheap_t heap; jsheap_t heap;
func_stack_t *func_stack;
} parser_ctx_t; } parser_ctx_t;
#define OP_LIST \ #define OP_LIST \
...@@ -497,17 +481,18 @@ typedef struct _parameter_t { ...@@ -497,17 +481,18 @@ typedef struct _parameter_t {
struct _source_elements_t { struct _source_elements_t {
statement_t *statement; statement_t *statement;
statement_t *statement_tail; statement_t *statement_tail;
function_declaration_t *functions;
}; };
struct _function_expression_t { typedef struct _function_expression_t {
expression_t expr; expression_t expr;
const WCHAR *identifier; const WCHAR *identifier;
parameter_t *parameter_list; parameter_t *parameter_list;
source_elements_t *source_elements; source_elements_t *source_elements;
const WCHAR *src_str; const WCHAR *src_str;
DWORD src_len; DWORD src_len;
};
struct _function_expression_t *next; /* for compiler */
} function_expression_t;
typedef struct { typedef struct {
expression_t expr; expression_t expr;
......
...@@ -29,7 +29,6 @@ static void set_error(parser_ctx_t*,UINT); ...@@ -29,7 +29,6 @@ static void set_error(parser_ctx_t*,UINT);
static BOOL explicit_error(parser_ctx_t*,void*,WCHAR); static BOOL explicit_error(parser_ctx_t*,void*,WCHAR);
static BOOL allow_auto_semicolon(parser_ctx_t*); static BOOL allow_auto_semicolon(parser_ctx_t*);
static void program_parsed(parser_ctx_t*,source_elements_t*); static void program_parsed(parser_ctx_t*,source_elements_t*);
static source_elements_t *function_body_parsed(parser_ctx_t*,source_elements_t*);
typedef struct _statement_list_t { typedef struct _statement_list_t {
statement_t *head; statement_t *head;
...@@ -117,12 +116,6 @@ typedef struct _parameter_list_t { ...@@ -117,12 +116,6 @@ typedef struct _parameter_list_t {
static parameter_list_t *new_parameter_list(parser_ctx_t*,const WCHAR*); static parameter_list_t *new_parameter_list(parser_ctx_t*,const WCHAR*);
static parameter_list_t *parameter_list_add(parser_ctx_t*,parameter_list_t*,const WCHAR*); static parameter_list_t *parameter_list_add(parser_ctx_t*,parameter_list_t*,const WCHAR*);
static void push_func(parser_ctx_t*);
static inline void pop_func(parser_ctx_t *ctx)
{
ctx->func_stack = ctx->func_stack->next;
}
static void *new_expression(parser_ctx_t *ctx,expression_type_t,size_t); static void *new_expression(parser_ctx_t *ctx,expression_type_t,size_t);
static expression_t *new_function_expression(parser_ctx_t*,const WCHAR*,parameter_list_t*, static expression_t *new_function_expression(parser_ctx_t*,const WCHAR*,parameter_list_t*,
source_elements_t*,const WCHAR*,DWORD); source_elements_t*,const WCHAR*,DWORD);
...@@ -271,11 +264,11 @@ FunctionExpression ...@@ -271,11 +264,11 @@ FunctionExpression
{ $$ = new_function_expression(ctx, $2, $4, $7, $1, $8-$1+1); } { $$ = new_function_expression(ctx, $2, $4, $7, $1, $8-$1+1); }
KFunction KFunction
: kFUNCTION { push_func(ctx); $$ = $1; } : kFUNCTION { $$ = $1; }
/* ECMA-262 3rd Edition 13 */ /* ECMA-262 3rd Edition 13 */
FunctionBody FunctionBody
: SourceElements { $$ = function_body_parsed(ctx, $1); } : SourceElements { $$ = $1; }
/* ECMA-262 3rd Edition 13 */ /* ECMA-262 3rd Edition 13 */
FormalParameterList FormalParameterList
...@@ -1307,23 +1300,13 @@ static expression_t *new_function_expression(parser_ctx_t *ctx, const WCHAR *ide ...@@ -1307,23 +1300,13 @@ static expression_t *new_function_expression(parser_ctx_t *ctx, const WCHAR *ide
parameter_list_t *parameter_list, source_elements_t *source_elements, const WCHAR *src_str, DWORD src_len) parameter_list_t *parameter_list, source_elements_t *source_elements, const WCHAR *src_str, DWORD src_len)
{ {
function_expression_t *ret = new_expression(ctx, EXPR_FUNC, sizeof(*ret)); function_expression_t *ret = new_expression(ctx, EXPR_FUNC, sizeof(*ret));
function_declaration_t *decl;
ret->identifier = identifier; ret->identifier = identifier;
ret->parameter_list = parameter_list ? parameter_list->head : NULL; ret->parameter_list = parameter_list ? parameter_list->head : NULL;
ret->source_elements = source_elements; ret->source_elements = source_elements;
ret->src_str = src_str; ret->src_str = src_str;
ret->src_len = src_len; ret->src_len = src_len;
ret->next = NULL;
decl = parser_alloc(ctx, sizeof(function_declaration_t));
decl->expr = ret;
decl->next = NULL;
if(ctx->func_stack->func_tail)
ctx->func_stack->func_tail = ctx->func_stack->func_tail->next = decl;
else
ctx->func_stack->func_head = ctx->func_stack->func_tail = decl;
return &ret->expr; return &ret->expr;
} }
...@@ -1490,29 +1473,8 @@ static statement_list_t *statement_list_add(statement_list_t *list, statement_t ...@@ -1490,29 +1473,8 @@ static statement_list_t *statement_list_add(statement_list_t *list, statement_t
return list; return list;
} }
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->next = ctx->func_stack;
ctx->func_stack = new_func;
}
static source_elements_t *function_body_parsed(parser_ctx_t *ctx, source_elements_t *source)
{
source->functions = ctx->func_stack->func_head;
pop_func(ctx);
return source;
}
static void program_parsed(parser_ctx_t *ctx, source_elements_t *source) static void program_parsed(parser_ctx_t *ctx, source_elements_t *source)
{ {
source->functions = ctx->func_stack->func_head;
pop_func(ctx);
ctx->source = source; ctx->source = source;
if(!ctx->lexer_error) if(!ctx->lexer_error)
ctx->hres = S_OK; ctx->hres = S_OK;
...@@ -1550,8 +1512,6 @@ HRESULT script_parse(script_ctx_t *ctx, const WCHAR *code, const WCHAR *delimite ...@@ -1550,8 +1512,6 @@ HRESULT script_parse(script_ctx_t *ctx, const WCHAR *code, const WCHAR *delimite
mark = jsheap_mark(&ctx->tmp_heap); mark = jsheap_mark(&ctx->tmp_heap);
jsheap_init(&parser_ctx->heap); jsheap_init(&parser_ctx->heap);
push_func(parser_ctx);
parser_parse(parser_ctx); parser_parse(parser_ctx);
jsheap_clear(mark); jsheap_clear(mark);
hres = parser_ctx->hres; hres = parser_ctx->hres;
......
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