jscript: Return regexp string as jsstr_t from lexer.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2019-03-01 17:44:31 +01:00 committed by Alexandre Julliard
parent 79557db981
commit edc9df207c
4 changed files with 15 additions and 25 deletions

View File

@ -48,7 +48,7 @@ typedef struct {
int ref; int ref;
} function_local_t; } function_local_t;
typedef struct { typedef struct _compiler_ctx_t {
parser_ctx_t *parser; parser_ctx_t *parser;
bytecode_t *code; bytecode_t *code;
@ -130,7 +130,7 @@ static inline void *compiler_alloc(bytecode_t *code, size_t size)
return heap_pool_alloc(&code->heap, size); return heap_pool_alloc(&code->heap, size);
} }
static jsstr_t *compiler_alloc_string_len(compiler_ctx_t *ctx, const WCHAR *str, unsigned len) jsstr_t *compiler_alloc_string_len(compiler_ctx_t *ctx, const WCHAR *str, unsigned len)
{ {
jsstr_t *new_str; jsstr_t *new_str;
@ -825,22 +825,8 @@ static HRESULT compile_literal(compiler_ctx_t *ctx, literal_t *literal)
return push_instr(ctx, OP_null) ? S_OK : E_OUTOFMEMORY; return push_instr(ctx, OP_null) ? S_OK : E_OUTOFMEMORY;
case LT_STRING: case LT_STRING:
return push_instr_str(ctx, OP_str, literal->u.wstr); return push_instr_str(ctx, OP_str, literal->u.wstr);
case LT_REGEXP: { case LT_REGEXP:
unsigned instr; return push_instr_str_uint(ctx, OP_regexp, literal->u.regexp.str, literal->u.regexp.flags);
jsstr_t *str;
str = compiler_alloc_string_len(ctx, literal->u.regexp.str, literal->u.regexp.str_len);
if(!str)
return E_OUTOFMEMORY;
instr = push_instr(ctx, OP_regexp);
if(!instr)
return E_OUTOFMEMORY;
instr_ptr(ctx, instr)->u.arg[0].str = str;
instr_ptr(ctx, instr)->u.arg[1].uint = literal->u.regexp.flags;
return S_OK;
}
DEFAULT_UNREACHABLE; DEFAULT_UNREACHABLE;
} }
return E_FAIL; return E_FAIL;
@ -2480,7 +2466,7 @@ HRESULT compile_script(script_ctx_t *ctx, const WCHAR *code, const WCHAR *args,
} }
} }
hres = script_parse(ctx, compiler.code->source, delimiter, from_eval, &compiler.parser); hres = script_parse(ctx, &compiler, compiler.code->source, delimiter, from_eval, &compiler.parser);
if(FAILED(hres)) { if(FAILED(hres)) {
release_bytecode(compiler.code); release_bytecode(compiler.code);
return hres; return hres;

View File

@ -1201,8 +1201,7 @@ literal_t *parse_regexp(parser_ctx_t *ctx)
ret = parser_alloc(ctx, sizeof(literal_t)); ret = parser_alloc(ctx, sizeof(literal_t));
ret->type = LT_REGEXP; ret->type = LT_REGEXP;
ret->u.regexp.str = re; ret->u.regexp.str = compiler_alloc_string_len(ctx->compiler, re, re_len);
ret->u.regexp.str_len = re_len;
ret->u.regexp.flags = flags; ret->u.regexp.flags = flags;
return ret; return ret;
} }

View File

@ -34,6 +34,7 @@ typedef struct _parser_ctx_t {
const WCHAR *ptr; const WCHAR *ptr;
script_ctx_t *script; script_ctx_t *script;
struct _compiler_ctx_t *compiler;
source_elements_t *source; source_elements_t *source;
BOOL nl; BOOL nl;
BOOL implicit_nl_semicolon; BOOL implicit_nl_semicolon;
@ -47,7 +48,7 @@ typedef struct _parser_ctx_t {
heap_pool_t heap; heap_pool_t heap;
} parser_ctx_t; } parser_ctx_t;
HRESULT script_parse(script_ctx_t*,const WCHAR*,const WCHAR*,BOOL,parser_ctx_t**) DECLSPEC_HIDDEN; HRESULT script_parse(script_ctx_t*,struct _compiler_ctx_t*,const WCHAR*,const WCHAR*,BOOL,parser_ctx_t**) DECLSPEC_HIDDEN;
void parser_release(parser_ctx_t*) DECLSPEC_HIDDEN; void parser_release(parser_ctx_t*) DECLSPEC_HIDDEN;
int parser_lex(void*,parser_ctx_t*) DECLSPEC_HIDDEN; int parser_lex(void*,parser_ctx_t*) DECLSPEC_HIDDEN;
@ -81,8 +82,7 @@ typedef struct {
const WCHAR *wstr; const WCHAR *wstr;
BOOL bval; BOOL bval;
struct { struct {
const WCHAR *str; jsstr_t *str;
DWORD str_len;
DWORD flags; DWORD flags;
} regexp; } regexp;
} u; } u;
@ -399,3 +399,5 @@ static inline double get_ccnum(ccval_t v)
{ {
return v.is_num ? v.u.n : v.u.b; return v.is_num ? v.u.n : v.u.b;
} }
jsstr_t *compiler_alloc_string_len(struct _compiler_ctx_t*,const WCHAR *,unsigned) DECLSPEC_HIDDEN;

View File

@ -1566,7 +1566,7 @@ void parser_release(parser_ctx_t *ctx)
heap_free(ctx); heap_free(ctx);
} }
HRESULT script_parse(script_ctx_t *ctx, const WCHAR *code, const WCHAR *delimiter, BOOL from_eval, HRESULT script_parse(script_ctx_t *ctx, struct _compiler_ctx_t *compiler, const WCHAR *code, const WCHAR *delimiter, BOOL from_eval,
parser_ctx_t **ret) parser_ctx_t **ret)
{ {
parser_ctx_t *parser_ctx; parser_ctx_t *parser_ctx;
@ -1591,7 +1591,10 @@ HRESULT script_parse(script_ctx_t *ctx, const WCHAR *code, const WCHAR *delimite
mark = heap_pool_mark(&ctx->tmp_heap); mark = heap_pool_mark(&ctx->tmp_heap);
heap_pool_init(&parser_ctx->heap); heap_pool_init(&parser_ctx->heap);
parser_ctx->compiler = compiler;
parser_parse(parser_ctx); parser_parse(parser_ctx);
parser_ctx->compiler = NULL;
heap_pool_clear(mark); heap_pool_clear(mark);
hres = parser_ctx->hres; hres = parser_ctx->hres;
if(FAILED(hres)) { if(FAILED(hres)) {