Created
February 5, 2019 15:34
-
-
Save xeioex/f3590c70011e59fcf2ed3fcc9f3da0ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # HG changeset patch | |
| # User hongzhidao <[email protected]> | |
| # Date 1549299198 -28800 | |
| # Tue Feb 05 00:53:18 2019 +0800 | |
| # Node ID 62893d7c2f3427c8a9a7af3cd8f677b58ba7fd55 | |
| # Parent 1568a0d46b0dbaf3702e3c43a18ac44d6782217b | |
| Reporting filename in generator errors. | |
| diff --git a/njs/njs_generator.c b/njs/njs_generator.c | |
| --- a/njs/njs_generator.c | |
| +++ b/njs/njs_generator.c | |
| @@ -163,8 +163,8 @@ static nxt_int_t njs_generate_function_d | |
| njs_function_lambda_t *lambda, uint32_t line); | |
| -static void njs_generate_syntax_error(njs_vm_t *vm, uint32_t token_line, | |
| - const char* fmt, ...); | |
| +static void njs_generate_syntax_error(njs_vm_t *vm, njs_parser_node_t *node, | |
| + const char *fmt, ...); | |
| #define njs_generate_code(generator, type, code) \ | |
| @@ -1407,8 +1407,7 @@ njs_generate_continue_statement(njs_vm_t | |
| syntax_error: | |
| - njs_generate_syntax_error(vm, node->token_line, | |
| - "Illegal continue statement"); | |
| + njs_generate_syntax_error(vm, node, "Illegal continue statement"); | |
| return NXT_ERROR; | |
| } | |
| @@ -1456,7 +1455,7 @@ njs_generate_break_statement(njs_vm_t *v | |
| syntax_error: | |
| - njs_generate_syntax_error(vm, node->token_line, "Illegal break statement"); | |
| + njs_generate_syntax_error(vm, node, "Illegal break statement"); | |
| return NXT_ERROR; | |
| } | |
| @@ -3162,15 +3161,29 @@ njs_generate_function_debug(njs_vm_t *vm | |
| static void | |
| -njs_generate_syntax_error(njs_vm_t *vm, uint32_t token_line, | |
| - const char* fmt, ...) | |
| +njs_generate_syntax_error(njs_vm_t *vm, njs_parser_node_t *node, | |
| + const char *fmt, ...) | |
| { | |
| - va_list args; | |
| - u_char buf[256], *end; | |
| + u_char msg[NXT_MAX_ERROR_STR]; | |
| + u_char *p, *end; | |
| + va_list args; | |
| + njs_parser_scope_t *scope; | |
| + | |
| + p = msg; | |
| + end = msg + NXT_MAX_ERROR_STR; | |
| va_start(args, fmt); | |
| - end = nxt_vsprintf(buf, buf + sizeof(buf), fmt, args); | |
| + p = nxt_vsprintf(p, end, fmt, args); | |
| va_end(args); | |
| - njs_syntax_error(vm, "%*s in %uD", end - buf, buf, token_line); | |
| + scope = node->scope; | |
| + | |
| + if (scope->file.start != NULL) { | |
| + p = nxt_sprintf(p, end, " in %V:%uD", &scope->file, node->token_line); | |
| + | |
| + } else { | |
| + p = nxt_sprintf(p, end, " in %uD", node->token_line); | |
| + } | |
| + | |
| + njs_error_new(vm, NJS_OBJECT_SYNTAX_ERROR, msg, p - msg); | |
| } | |
| diff --git a/njs/njs_parser.c b/njs/njs_parser.c | |
| --- a/njs/njs_parser.c | |
| +++ b/njs/njs_parser.c | |
| @@ -162,6 +162,7 @@ njs_parser(njs_vm_t *vm, njs_parser_t *p | |
| static njs_ret_t | |
| njs_parser_scope_begin(njs_vm_t *vm, njs_parser_t *parser, njs_scope_t type) | |
| { | |
| + nxt_int_t ret; | |
| nxt_uint_t nesting; | |
| nxt_array_t *values; | |
| njs_parser_scope_t *scope, *parent; | |
| @@ -188,13 +189,12 @@ njs_parser_scope_begin(njs_vm_t *vm, njs | |
| } | |
| } | |
| - scope = nxt_mp_alloc(vm->mem_pool, sizeof(njs_parser_scope_t)); | |
| + scope = nxt_mp_zalloc(vm->mem_pool, sizeof(njs_parser_scope_t)); | |
| if (nxt_slow_path(scope == NULL)) { | |
| return NXT_ERROR; | |
| } | |
| scope->type = type; | |
| - scope->top = NULL; | |
| if (type == NJS_SCOPE_FUNCTION) { | |
| scope->next_index[0] = type; | |
| @@ -230,6 +230,13 @@ njs_parser_scope_begin(njs_vm_t *vm, njs | |
| scope->values[0] = values; | |
| scope->values[1] = NULL; | |
| + if (parser->lexer->file.start != NULL) { | |
| + ret = njs_name_copy(vm, &scope->file, &parser->lexer->file); | |
| + if (nxt_slow_path(ret != NXT_OK)) { | |
| + return NXT_ERROR; | |
| + } | |
| + } | |
| + | |
| parent = parser->scope; | |
| scope->parent = parent; | |
| parser->scope = scope; | |
| @@ -2639,7 +2646,7 @@ njs_parser_trace_handler(nxt_trace_t *tr | |
| void | |
| njs_parser_error(njs_vm_t *vm, njs_parser_t *parser, njs_value_type_t type, | |
| const char *fmt, ...) | |
| - { | |
| +{ | |
| size_t width; | |
| u_char *p, *end; | |
| u_char msg[NXT_MAX_ERROR_STR]; | |
| diff --git a/njs/njs_parser.h b/njs/njs_parser.h | |
| --- a/njs/njs_parser.h | |
| +++ b/njs/njs_parser.h | |
| @@ -249,6 +249,8 @@ struct njs_parser_scope_s { | |
| nxt_array_t *values[2]; /* Array of njs_value_t. */ | |
| njs_index_t next_index[2]; | |
| + nxt_str_t file; | |
| + | |
| njs_scope_t type:8; | |
| uint8_t nesting; /* 4 bits */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment