From eb73571fe987344c0caca9ada621a129d1883c2b Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Wed, 22 Jan 2020 23:27:54 +0100 Subject: [PATCH] vbscript: Pass parser error location to compiler. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/vbscript/compile.c | 15 +++++++-------- dlls/vbscript/parse.h | 1 + dlls/vbscript/parser.y | 3 +++ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/dlls/vbscript/compile.c b/dlls/vbscript/compile.c index 769bbf15ba9..1f9462aee8b 100644 --- a/dlls/vbscript/compile.c +++ b/dlls/vbscript/compile.c @@ -1917,27 +1917,25 @@ HRESULT compile_script(script_ctx_t *script, const WCHAR *src, const WCHAR *deli vbscode_t *code; HRESULT hres; + memset(&ctx, 0, sizeof(ctx)); code = ctx.code = alloc_vbscode(&ctx, src, cookie, start_line); if(!ctx.code) return E_OUTOFMEMORY; hres = parse_script(&ctx.parser, code->source, delimiter, flags); if(FAILED(hres)) { + if(ctx.parser.error_loc != -1) + ctx.loc = ctx.parser.error_loc; hres = compile_error(script, hres); release_vbscode(code); return hres; } - ctx.func_decls = NULL; - ctx.labels = NULL; - ctx.global_consts = NULL; - ctx.stat_ctx = NULL; - ctx.labels_cnt = ctx.labels_size = 0; - hres = compile_func(&ctx, ctx.parser.stats, &ctx.code->main_code); if(FAILED(hres)) { + hres = compile_error(script, hres); release_compiler(&ctx); - return compile_error(script, hres); + return hres; } ctx.global_consts = ctx.const_decls; @@ -1947,8 +1945,9 @@ HRESULT compile_script(script_ctx_t *script, const WCHAR *src, const WCHAR *deli for(func_decl = ctx.func_decls; func_decl; func_decl = func_decl->next) { hres = create_function(&ctx, func_decl, &new_func); if(FAILED(hres)) { + hres = compile_error(script, hres); release_compiler(&ctx); - return compile_error(script, hres); + return hres; } new_func->next = ctx.code->funcs; diff --git a/dlls/vbscript/parse.h b/dlls/vbscript/parse.h index 8d68e781fb2..568d8b9a423 100644 --- a/dlls/vbscript/parse.h +++ b/dlls/vbscript/parse.h @@ -286,6 +286,7 @@ typedef struct { BOOL option_explicit; BOOL is_html; HRESULT hres; + int error_loc; int last_token; unsigned last_nl; diff --git a/dlls/vbscript/parser.y b/dlls/vbscript/parser.y index 16a673fac7a..8ebfc82f005 100644 --- a/dlls/vbscript/parser.y +++ b/dlls/vbscript/parser.y @@ -505,6 +505,8 @@ StSep static int parser_error(unsigned *loc, parser_ctx_t *ctx, const char *str) { + if(ctx->error_loc == -1) + ctx->error_loc = *loc; if(ctx->hres == S_OK) { FIXME("%s: %s\n", debugstr_w(ctx->code + *loc), debugstr_a(str)); ctx->hres = E_FAIL; @@ -1142,6 +1144,7 @@ HRESULT parse_script(parser_ctx_t *ctx, const WCHAR *code, const WCHAR *delimite heap_pool_init(&ctx->heap); ctx->hres = S_OK; + ctx->error_loc = -1; ctx->last_token = tNL; ctx->last_nl = 0; ctx->stats = ctx->stats_tail = NULL;