Jacek Caban : jscript: Return regexp string as jsstr_t from lexer.

Alexandre Julliard julliard at winehq.org
Mon Mar 4 15:08:25 CST 2019


Module: wine
Branch: master
Commit: edc9df207c12d7560e9f32c0b0cb4b8ee98130ed
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=edc9df207c12d7560e9f32c0b0cb4b8ee98130ed

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Fri Mar  1 17:44:31 2019 +0100

jscript: Return regexp string as jsstr_t from lexer.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/jscript/compile.c | 24 +++++-------------------
 dlls/jscript/lex.c     |  3 +--
 dlls/jscript/parser.h  |  8 +++++---
 dlls/jscript/parser.y  |  5 ++++-
 4 files changed, 15 insertions(+), 25 deletions(-)

diff --git a/dlls/jscript/compile.c b/dlls/jscript/compile.c
index 5c60ab0..d165dd7 100644
--- a/dlls/jscript/compile.c
+++ b/dlls/jscript/compile.c
@@ -48,7 +48,7 @@ typedef struct {
     int ref;
 } function_local_t;
 
-typedef struct {
+typedef struct _compiler_ctx_t {
     parser_ctx_t *parser;
     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);
 }
 
-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;
 
@@ -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;
     case LT_STRING:
         return push_instr_str(ctx, OP_str, literal->u.wstr);
-    case LT_REGEXP: {
-        unsigned instr;
-        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;
-    }
+    case LT_REGEXP:
+        return push_instr_str_uint(ctx, OP_regexp, literal->u.regexp.str, literal->u.regexp.flags);
     DEFAULT_UNREACHABLE;
     }
     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)) {
         release_bytecode(compiler.code);
         return hres;
diff --git a/dlls/jscript/lex.c b/dlls/jscript/lex.c
index 2f0172c..b3a7923 100644
--- a/dlls/jscript/lex.c
+++ b/dlls/jscript/lex.c
@@ -1201,8 +1201,7 @@ literal_t *parse_regexp(parser_ctx_t *ctx)
 
     ret = parser_alloc(ctx, sizeof(literal_t));
     ret->type = LT_REGEXP;
-    ret->u.regexp.str = re;
-    ret->u.regexp.str_len = re_len;
+    ret->u.regexp.str = compiler_alloc_string_len(ctx->compiler, re, re_len);
     ret->u.regexp.flags = flags;
     return ret;
 }
diff --git a/dlls/jscript/parser.h b/dlls/jscript/parser.h
index f4f044c..0be13d5 100644
--- a/dlls/jscript/parser.h
+++ b/dlls/jscript/parser.h
@@ -34,6 +34,7 @@ typedef struct _parser_ctx_t {
     const WCHAR *ptr;
 
     script_ctx_t *script;
+    struct _compiler_ctx_t *compiler;
     source_elements_t *source;
     BOOL nl;
     BOOL implicit_nl_semicolon;
@@ -47,7 +48,7 @@ typedef struct _parser_ctx_t {
     heap_pool_t heap;
 } 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;
 
 int parser_lex(void*,parser_ctx_t*) DECLSPEC_HIDDEN;
@@ -81,8 +82,7 @@ typedef struct {
         const WCHAR *wstr;
         BOOL bval;
         struct {
-            const WCHAR *str;
-            DWORD str_len;
+            jsstr_t *str;
             DWORD flags;
         } regexp;
     } u;
@@ -399,3 +399,5 @@ static inline double get_ccnum(ccval_t v)
 {
     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;
diff --git a/dlls/jscript/parser.y b/dlls/jscript/parser.y
index 157bc18..57aecf6 100644
--- a/dlls/jscript/parser.y
+++ b/dlls/jscript/parser.y
@@ -1566,7 +1566,7 @@ void parser_release(parser_ctx_t *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 *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);
     heap_pool_init(&parser_ctx->heap);
 
+    parser_ctx->compiler = compiler;
     parser_parse(parser_ctx);
+    parser_ctx->compiler = NULL;
+
     heap_pool_clear(mark);
     hres = parser_ctx->hres;
     if(FAILED(hres)) {




More information about the wine-cvs mailing list