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

jscript: Return regexp string as jsstr_t from lexer.

parent 79557db9
...@@ -48,7 +48,7 @@ typedef struct { ...@@ -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) ...@@ -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) ...@@ -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, ...@@ -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;
......
...@@ -1201,8 +1201,7 @@ literal_t *parse_regexp(parser_ctx_t *ctx) ...@@ -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;
} }
...@@ -34,6 +34,7 @@ typedef struct _parser_ctx_t { ...@@ -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 { ...@@ -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 { ...@@ -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) ...@@ -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;
...@@ -1566,7 +1566,7 @@ void parser_release(parser_ctx_t *ctx) ...@@ -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 ...@@ -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)) {
......
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