jscript: Get rid of parser function collecting hack by moving the logic to compiler.
This commit is contained in:
parent
7b5af23604
commit
ca15adfde6
|
@ -56,6 +56,9 @@ typedef struct {
|
|||
|
||||
variable_declaration_t *var_head;
|
||||
variable_declaration_t *var_tail;
|
||||
|
||||
function_expression_t *func_head;
|
||||
function_expression_t *func_tail;
|
||||
} compiler_ctx_t;
|
||||
|
||||
static const struct {
|
||||
|
@ -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)
|
||||
{
|
||||
ctx->func_tail = ctx->func_tail ? (ctx->func_tail->next = expr) : (ctx->func_head = expr);
|
||||
|
||||
/* FIXME: not exactly right */
|
||||
if(expr->identifier) {
|
||||
ctx->func->func_cnt++;
|
||||
|
@ -1787,13 +1792,14 @@ static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source,
|
|||
BOOL from_eval, function_code_t *func)
|
||||
{
|
||||
variable_declaration_t *var_iter;
|
||||
function_declaration_t *iter;
|
||||
function_expression_t *iter;
|
||||
unsigned off, i;
|
||||
HRESULT hres;
|
||||
|
||||
TRACE("\n");
|
||||
|
||||
ctx->var_head = ctx->var_tail = NULL;
|
||||
ctx->func_head = ctx->func_tail = NULL;
|
||||
|
||||
off = ctx->code_off;
|
||||
ctx->func = func;
|
||||
|
@ -1856,8 +1862,8 @@ static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source,
|
|||
return E_OUTOFMEMORY;
|
||||
memset(func->funcs, 0, func->func_cnt * sizeof(*func->funcs));
|
||||
|
||||
for(iter = source->functions, i=0; iter; iter = iter->next, i++) {
|
||||
hres = compile_function(ctx, iter->expr->source_elements, iter->expr, FALSE, func->funcs+i);
|
||||
for(iter = ctx->func_head, i=0; iter; iter = iter->next, i++) {
|
||||
hres = compile_function(ctx, iter->source_elements, iter, FALSE, func->funcs+i);
|
||||
if(FAILED(hres))
|
||||
return hres;
|
||||
}
|
||||
|
|
|
@ -17,23 +17,9 @@
|
|||
*/
|
||||
|
||||
typedef struct _source_elements_t source_elements_t;
|
||||
typedef struct _function_expression_t function_expression_t;
|
||||
typedef struct _expression_t expression_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 {
|
||||
const WCHAR *begin;
|
||||
const WCHAR *end;
|
||||
|
@ -47,8 +33,6 @@ typedef struct {
|
|||
HRESULT hres;
|
||||
|
||||
jsheap_t heap;
|
||||
|
||||
func_stack_t *func_stack;
|
||||
} parser_ctx_t;
|
||||
|
||||
#define OP_LIST \
|
||||
|
@ -497,17 +481,18 @@ typedef struct _parameter_t {
|
|||
struct _source_elements_t {
|
||||
statement_t *statement;
|
||||
statement_t *statement_tail;
|
||||
function_declaration_t *functions;
|
||||
};
|
||||
|
||||
struct _function_expression_t {
|
||||
typedef struct _function_expression_t {
|
||||
expression_t expr;
|
||||
const WCHAR *identifier;
|
||||
parameter_t *parameter_list;
|
||||
source_elements_t *source_elements;
|
||||
const WCHAR *src_str;
|
||||
DWORD src_len;
|
||||
};
|
||||
|
||||
struct _function_expression_t *next; /* for compiler */
|
||||
} function_expression_t;
|
||||
|
||||
typedef struct {
|
||||
expression_t expr;
|
||||
|
|
|
@ -29,7 +29,6 @@ static void set_error(parser_ctx_t*,UINT);
|
|||
static BOOL explicit_error(parser_ctx_t*,void*,WCHAR);
|
||||
static BOOL allow_auto_semicolon(parser_ctx_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 {
|
||||
statement_t *head;
|
||||
|
@ -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 *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 expression_t *new_function_expression(parser_ctx_t*,const WCHAR*,parameter_list_t*,
|
||||
source_elements_t*,const WCHAR*,DWORD);
|
||||
|
@ -271,11 +264,11 @@ FunctionExpression
|
|||
{ $$ = new_function_expression(ctx, $2, $4, $7, $1, $8-$1+1); }
|
||||
|
||||
KFunction
|
||||
: kFUNCTION { push_func(ctx); $$ = $1; }
|
||||
: kFUNCTION { $$ = $1; }
|
||||
|
||||
/* ECMA-262 3rd Edition 13 */
|
||||
FunctionBody
|
||||
: SourceElements { $$ = function_body_parsed(ctx, $1); }
|
||||
: SourceElements { $$ = $1; }
|
||||
|
||||
/* ECMA-262 3rd Edition 13 */
|
||||
FormalParameterList
|
||||
|
@ -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)
|
||||
{
|
||||
function_expression_t *ret = new_expression(ctx, EXPR_FUNC, sizeof(*ret));
|
||||
function_declaration_t *decl;
|
||||
|
||||
ret->identifier = identifier;
|
||||
ret->parameter_list = parameter_list ? parameter_list->head : NULL;
|
||||
ret->source_elements = source_elements;
|
||||
ret->src_str = src_str;
|
||||
ret->src_len = src_len;
|
||||
|
||||
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;
|
||||
ret->next = NULL;
|
||||
|
||||
return &ret->expr;
|
||||
}
|
||||
|
@ -1490,29 +1473,8 @@ static statement_list_t *statement_list_add(statement_list_t *list, statement_t
|
|||
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)
|
||||
{
|
||||
source->functions = ctx->func_stack->func_head;
|
||||
pop_func(ctx);
|
||||
|
||||
ctx->source = source;
|
||||
if(!ctx->lexer_error)
|
||||
ctx->hres = S_OK;
|
||||
|
@ -1550,8 +1512,6 @@ HRESULT script_parse(script_ctx_t *ctx, const WCHAR *code, const WCHAR *delimite
|
|||
mark = jsheap_mark(&ctx->tmp_heap);
|
||||
jsheap_init(&parser_ctx->heap);
|
||||
|
||||
push_func(parser_ctx);
|
||||
|
||||
parser_parse(parser_ctx);
|
||||
jsheap_clear(mark);
|
||||
hres = parser_ctx->hres;
|
||||
|
|
Loading…
Reference in New Issue