[njs] Parser: added line positions for AST nodes.
Alexander Borisov
alexander.borisov at nginx.com
Fri Jun 5 12:26:49 UTC 2020
details: https://hg.nginx.org/njs/rev/bc79f5c80452
branches:
changeset: 1426:bc79f5c80452
user: Alexander Borisov <alexander.borisov at nginx.com>
date: Thu Jun 04 17:26:01 2020 +0300
description:
Parser: added line positions for AST nodes.
diffstat:
src/njs_lexer.c | 4 +-
src/njs_parser.c | 428 +++++++++++++++++++++++++++++++++++-------------------
src/njs_parser.h | 2 +
3 files changed, 282 insertions(+), 152 deletions(-)
diffs (truncated from 1381 to 1000 lines):
diff -r 790bde011274 -r bc79f5c80452 src/njs_lexer.c
--- a/src/njs_lexer.c Fri Jun 05 11:42:41 2020 +0000
+++ b/src/njs_lexer.c Thu Jun 04 17:26:01 2020 +0300
@@ -449,6 +449,7 @@ njs_lexer_make_token(njs_lexer_t *lexer,
}
token->type = njs_tokens[c];
+ token->line = lexer->line;
switch (token->type) {
@@ -566,7 +567,6 @@ njs_lexer_make_token(njs_lexer_t *lexer,
/* Fall through. */
default:
- token->line = lexer->line;
token->text.start = lexer->start - 1;
token->text.length = lexer->start - token->text.start;
@@ -668,7 +668,6 @@ njs_lexer_word(njs_lexer_t *lexer, njs_l
0x00, 0x00, 0x00, 0x00, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
};
- token->line = lexer->line;
token->text.start = lexer->start - 1;
hash_id = njs_djb_hash_add(NJS_DJB_HASH_INIT, *token->text.start);
@@ -866,6 +865,7 @@ njs_lexer_multi(njs_lexer_t *lexer, njs_
{
u_char c;
+ token->line = lexer->line;
token->text.start = lexer->start - 1;
while (length != 0 && multi != NULL && lexer->start < lexer->end) {
diff -r 790bde011274 -r bc79f5c80452 src/njs_parser.c
--- a/src/njs_parser.c Fri Jun 05 11:42:41 2020 +0000
+++ b/src/njs_parser.c Thu Jun 04 17:26:01 2020 +0300
@@ -563,6 +563,7 @@ njs_parser(njs_parser_t *parser, njs_par
}
parser->node->token_type = NJS_TOKEN_END;
+ parser->node->token_line = parser->lexer->line;
njs_parser_chain_top_set(parser, parser->node);
@@ -921,6 +922,17 @@ njs_parser_expression_parenthesis(njs_pa
}
+static njs_int_t
+njs_parser_set_line_state(njs_parser_t *parser,
+ njs_lexer_token_t *token, njs_queue_link_t *current)
+{
+ parser->node->token_line = (uint32_t) (uintptr_t) parser->target;
+ parser->target = NULL;
+
+ return njs_parser_stack_pop(parser);
+}
+
+
/*
* 12.2 Primary Expression.
*/
@@ -948,6 +960,7 @@ njs_parser_primary_expression_test(njs_p
}
node->u.value = njs_value_true;
+ node->token_line = token->line;
parser->node = node;
goto done;
@@ -959,6 +972,7 @@ njs_parser_primary_expression_test(njs_p
}
node->u.value = njs_value_false;
+ node->token_line = token->line;
parser->node = node;
goto done;
@@ -970,6 +984,7 @@ njs_parser_primary_expression_test(njs_p
}
njs_set_number(&node->u.value, token->number);
+ node->token_line = token->line;
parser->node = node;
goto done;
@@ -980,6 +995,8 @@ njs_parser_primary_expression_test(njs_p
return NJS_ERROR;
}
+ node->token_line = token->line;
+
ret = njs_parser_string_create(parser->vm, token, &node->u.value);
if (ret != NJS_OK) {
return NJS_ERROR;
@@ -996,6 +1013,8 @@ njs_parser_primary_expression_test(njs_p
return NJS_ERROR;
}
+ node->token_line = token->line;
+
ret = njs_parser_escape_string_create(parser, token, &node->u.value);
if (ret != NJS_TOKEN_STRING) {
return NJS_ERROR;
@@ -1013,11 +1032,27 @@ njs_parser_primary_expression_test(njs_p
/* ArrayLiteral */
case NJS_TOKEN_OPEN_BRACKET:
+ node = njs_parser_node_new(parser, NJS_TOKEN_ARRAY);
+ if (node == NULL) {
+ return NJS_ERROR;
+ }
+
+ node->token_line = token->line;
+ parser->node = node;
+
njs_parser_next(parser, njs_parser_array_literal);
break;
/* ObjectLiteral */
case NJS_TOKEN_OPEN_BRACE:
+ node = njs_parser_node_new(parser, NJS_TOKEN_OBJECT);
+ if (node == NULL) {
+ return NJS_ERROR;
+ }
+
+ node->token_line = token->line;
+ parser->node = node;
+
njs_parser_next(parser, njs_parser_object_literal);
break;
@@ -1039,7 +1074,6 @@ njs_parser_primary_expression_test(njs_p
}
node->token_line = token->line;
-
parser->node = node;
njs_parser_next(parser, njs_parser_function_expression);
@@ -1086,6 +1120,7 @@ njs_parser_primary_expression_test(njs_p
return NJS_ERROR;
}
+ node->token_line = token->line;
parser->node = node;
ret = njs_parser_regexp_literal(parser, token, current);
@@ -1102,6 +1137,7 @@ njs_parser_primary_expression_test(njs_p
return NJS_ERROR;
}
+ node->token_line = token->line;
parser->node = node;
njs_parser_next(parser, njs_parser_template_literal);
@@ -1140,6 +1176,7 @@ reference:
return NJS_ERROR;
}
+ node->token_line = token->line;
parser->node = node;
done:
@@ -1259,6 +1296,8 @@ njs_parser_template_literal(njs_parser_t
return NJS_ERROR;
}
+ array->token_line = token->line;
+
template = parser->node;
index = NJS_SCOPE_CALLEE_ARGUMENTS;
@@ -1532,14 +1571,8 @@ static njs_int_t
njs_parser_array_literal(njs_parser_t *parser, njs_lexer_token_t *token,
njs_queue_link_t *current)
{
- njs_parser_node_t *array;
-
- array = njs_parser_node_new(parser, NJS_TOKEN_ARRAY);
- if (array == NULL) {
- return NJS_ERROR;
- }
-
- parser->target = array;
+ parser->target = parser->node;
+ parser->node = NULL;
njs_parser_next(parser, njs_parser_array_element_list);
@@ -1644,20 +1677,16 @@ static njs_int_t
njs_parser_object_literal(njs_parser_t *parser, njs_lexer_token_t *token,
njs_queue_link_t *current)
{
- njs_parser_node_t *object, *node;
-
- object = njs_parser_node_new(parser, NJS_TOKEN_OBJECT);
- if (object == NULL) {
- return NJS_ERROR;
- }
+ njs_parser_node_t *node;
node = njs_parser_node_new(parser, 0);
if (node == NULL) {
return NJS_ERROR;
}
- node->left = object;
-
+ node->left = parser->node;
+
+ parser->node = NULL;
parser->target = node;
njs_parser_next(parser, njs_parser_property_definition_list);
@@ -1750,6 +1779,10 @@ njs_parser_property_name_node(njs_parser
property = njs_parser_node_string(parser->vm, token, parser);
}
+ if (property != NULL) {
+ property->token_line = token->line;
+ }
+
return property;
}
@@ -2103,8 +2136,6 @@ njs_parser_property(njs_parser_t *parser
switch (token->type) {
case NJS_TOKEN_OPEN_BRACKET:
- njs_lexer_consume_token(parser->lexer, 1);
-
node = njs_parser_node_new(parser, NJS_TOKEN_PROPERTY);
if (node == NULL) {
return NJS_ERROR;
@@ -2112,9 +2143,12 @@ njs_parser_property(njs_parser_t *parser
node->u.operation = NJS_VMCODE_PROPERTY_GET;
node->left = parser->node;
+ node->token_line = token->line;
parser->node = NULL;
+ njs_lexer_consume_token(parser->lexer, 1);
+
njs_parser_next(parser, njs_parser_expression);
return njs_parser_after(parser, current, node, 1,
@@ -2133,12 +2167,15 @@ njs_parser_property(njs_parser_t *parser
}
node->u.operation = NJS_VMCODE_PROPERTY_GET;
+ node->token_line = token->line;
prop_node = njs_parser_node_string(parser->vm, token, parser);
if (prop_node == NULL) {
return NJS_ERROR;
}
+ prop_node->token_line = token->line;
+
node->left = parser->node;
node->right = prop_node;
@@ -2153,15 +2190,17 @@ njs_parser_property(njs_parser_t *parser
return NJS_DECLINED;
case NJS_TOKEN_GRAVE:
- njs_lexer_consume_token(parser->lexer, 1);
-
node = njs_parser_create_call(parser, parser->node, 0);
if (node == NULL) {
return NJS_ERROR;
}
+ node->token_line = token->line;
+
parser->node = node;
+ njs_lexer_consume_token(parser->lexer, 1);
+
njs_parser_next(parser, njs_parser_template_literal);
break;
@@ -2437,18 +2476,20 @@ njs_parser_member_expression_new_after(n
return NJS_ERROR;
}
+ parser->node->token_line = token->line;
+
return njs_parser_stack_pop(parser);
}
- njs_lexer_consume_token(parser->lexer, 1);
-
func = njs_parser_create_call(parser, parser->node, 1);
if (func == NULL) {
return NJS_ERROR;
}
+ func->token_line = token->line;
parser->node = func;
+ njs_lexer_consume_token(parser->lexer, 1);
njs_parser_next(parser, njs_parser_arguments);
return njs_parser_after(parser, current, func, 1,
@@ -2562,15 +2603,15 @@ njs_parser_call_expression_args(njs_pars
return njs_parser_failed(parser);
}
- njs_lexer_consume_token(parser->lexer, 1);
-
func = njs_parser_create_call(parser, parser->node, 0);
if (func == NULL) {
return NJS_ERROR;
}
+ func->token_line = token->line;
parser->node = func;
+ njs_lexer_consume_token(parser->lexer, 1);
njs_parser_next(parser, njs_parser_arguments);
return njs_parser_after(parser, current, func, 1,
@@ -2594,15 +2635,15 @@ njs_parser_call_expression_after(njs_par
switch (token->type) {
case NJS_TOKEN_OPEN_PARENTHESIS:
- njs_lexer_consume_token(parser->lexer, 1);
-
func = njs_parser_create_call(parser, parser->node, 0);
if (func == NULL) {
return NJS_ERROR;
}
+ func->token_line = token->line;
parser->node = func;
+ njs_lexer_consume_token(parser->lexer, 1);
njs_parser_next(parser, njs_parser_arguments);
ret = njs_parser_after(parser, current, func, 1,
@@ -2730,9 +2771,10 @@ njs_parser_argument_list_after(njs_parse
node->index = parser->target->index + sizeof(njs_value_t);
}
+ node->token_line = token->line;
node->left = parser->node;
+
parser->node->dest = node;
-
parser->target->right = node;
parser->node = node;
@@ -2819,15 +2861,15 @@ njs_parser_optional_chain(njs_parser_t *
switch (token->type) {
case NJS_TOKEN_OPEN_PARENTHESIS:
- njs_lexer_consume_token(parser->lexer, 2);
-
func = njs_parser_create_call(parser, parser->node, 0);
if (func == NULL) {
return NJS_ERROR;
}
+ func->token_line = token->line;
parser->node = func;
+ njs_lexer_consume_token(parser->lexer, 2);
njs_parser_next(parser, njs_parser_arguments);
ret = njs_parser_after(parser, current, func, 1,
@@ -2878,15 +2920,15 @@ njs_parser_optional_chain_after(njs_pars
switch (token->type) {
case NJS_TOKEN_OPEN_PARENTHESIS:
- njs_lexer_consume_token(parser->lexer, 1);
-
func = njs_parser_create_call(parser, parser->node, 0);
if (func == NULL) {
return NJS_ERROR;
}
+ func->token_line = token->line;
parser->node = func;
+ njs_lexer_consume_token(parser->lexer, 1);
njs_parser_next(parser, njs_parser_arguments);
ret = njs_parser_after(parser, current, func, 1,
@@ -2957,6 +2999,7 @@ njs_parser_new_expression_after(njs_pars
return NJS_ERROR;
}
+ func->token_line = token->line;
parser->node = func;
return njs_parser_stack_pop(parser);
@@ -3028,15 +3071,15 @@ njs_parser_left_hand_side_expression_aft
switch (token->type) {
/* CallExpression */
case NJS_TOKEN_OPEN_PARENTHESIS:
- njs_lexer_consume_token(parser->lexer, 1);
-
func = njs_parser_create_call(parser, parser->node, 0);
if (func == NULL) {
return NJS_ERROR;
}
+ func->token_line = token->line;
parser->node = func;
+ njs_lexer_consume_token(parser->lexer, 1);
njs_parser_next(parser, njs_parser_arguments);
ret = njs_parser_after(parser, current, func, 1,
@@ -3108,17 +3151,18 @@ njs_parser_expression_node(njs_parser_t
return njs_parser_stack_pop(parser);
}
- njs_lexer_consume_token(parser->lexer, 1);
-
node = njs_parser_node_new(parser, type);
if (node == NULL) {
return NJS_ERROR;
}
+ node->token_line = token->line;
node->u.operation = operation;
node->left = parser->node;
node->left->dest = node;
+ njs_lexer_consume_token(parser->lexer, 1);
+
return njs_parser_after(parser, current, node, 0, after);
}
@@ -3154,6 +3198,7 @@ njs_parser_update_expression(njs_parser_
return NJS_ERROR;
}
+ node->token_line = token->line;
node->u.operation = operation;
njs_lexer_consume_token(parser->lexer, 1);
@@ -3193,9 +3238,9 @@ njs_parser_update_expression_post(njs_pa
return njs_parser_stack_pop(parser);
}
- njs_lexer_consume_token(parser->lexer, 1);
-
if (!njs_parser_is_lvalue(parser->node)) {
+ njs_lexer_consume_token(parser->lexer, 1);
+
njs_parser_ref_error(parser,
"Invalid left-hand side in postfix operation");
return NJS_DONE;
@@ -3206,10 +3251,14 @@ njs_parser_update_expression_post(njs_pa
return NJS_ERROR;
}
+ node->token_line = token->line;
node->u.operation = operation;
node->left = parser->node;
+
parser->node = node;
+ njs_lexer_consume_token(parser->lexer, 1);
+
return njs_parser_stack_pop(parser);
}
@@ -3293,17 +3342,18 @@ njs_parser_unary_expression(njs_parser_t
njs_parser_unary_expression_after);
}
- njs_lexer_consume_token(parser->lexer, 1);
-
node = njs_parser_node_new(parser, type);
if (node == NULL) {
return NJS_ERROR;
}
+ node->token_line = token->line;
node->u.operation = operation;
parser->target = node;
+ njs_lexer_consume_token(parser->lexer, 1);
+
return njs_parser_after(parser, current, node, 0,
njs_parser_unary_expression_next);
}
@@ -3435,6 +3485,7 @@ njs_parser_exponentiation_expression_mat
return NJS_ERROR;
}
+ node->token_line = token->line;
node->u.operation = NJS_VMCODE_EXPONENTIATION;
node->left = parser->node;
node->left->dest = node;
@@ -3501,6 +3552,7 @@ njs_parser_multiplicative_expression_mat
return NJS_ERROR;
}
+ node->token_line = token->line;
node->u.operation = operation;
node->left = parser->node;
node->left->dest = node;
@@ -3563,6 +3615,7 @@ njs_parser_additive_expression_match(njs
return NJS_ERROR;
}
+ node->token_line = token->line;
node->u.operation = operation;
node->left = parser->node;
node->left->dest = node;
@@ -3629,6 +3682,7 @@ njs_parser_shift_expression_match(njs_pa
return NJS_ERROR;
}
+ node->token_line = token->line;
node->u.operation = operation;
node->left = parser->node;
node->left->dest = node;
@@ -3707,6 +3761,7 @@ njs_parser_relational_expression_match(n
return NJS_ERROR;
}
+ node->token_line = token->line;
node->u.operation = operation;
node->left = parser->node;
node->left->dest = node;
@@ -3777,6 +3832,7 @@ njs_parser_equality_expression_match(njs
return NJS_ERROR;
}
+ node->token_line = token->line;
node->u.operation = operation;
node->left = parser->node;
node->left->dest = node;
@@ -3947,17 +4003,17 @@ njs_parser_coalesce_expression(njs_parse
return njs_parser_failed(parser);
}
- njs_lexer_consume_token(parser->lexer, 1);
-
node = njs_parser_node_new(parser, NJS_TOKEN_COALESCE);
if (node == NULL) {
return NJS_ERROR;
}
+ node->token_line = token->line;
node->u.operation = NJS_VMCODE_COALESCE;
node->left = parser->node;
node->left->dest = node;
+ njs_lexer_consume_token(parser->lexer, 1);
njs_parser_next(parser, njs_parser_bitwise_OR_expression);
return njs_parser_after(parser, current, node, 0,
@@ -4000,13 +4056,12 @@ njs_parser_conditional_question_mark(njs
return njs_parser_stack_pop(parser);
}
- njs_lexer_consume_token(parser->lexer, 1);
-
cond = njs_parser_node_new(parser, NJS_TOKEN_CONDITIONAL);
if (cond == NULL) {
return NJS_ERROR;
}
+ cond->token_line = token->line;
cond->left = parser->node;
node = njs_parser_node_new(parser, NJS_TOKEN_BRANCHING);
@@ -4014,8 +4069,10 @@ njs_parser_conditional_question_mark(njs
return NJS_ERROR;
}
+ node->token_line = token->line;
cond->right = node;
+ njs_lexer_consume_token(parser->lexer, 1);
njs_parser_next(parser, njs_parser_assignment_expression);
return njs_parser_after(parser, current, cond, 1,
@@ -4277,6 +4334,7 @@ njs_parser_assignment_operator(njs_parse
return NJS_ERROR;
}
+ node->token_line = token->line;
node->u.operation = operation;
node->left = parser->node;
@@ -4358,16 +4416,18 @@ njs_parser_statement(njs_parser_t *parse
return njs_parser_stack_pop(parser);
case NJS_TOKEN_EXPORT:
+ parser->line = token->line;
+
njs_lexer_consume_token(parser->lexer, 1);
-
njs_parser_next(parser, njs_parser_export);
return njs_parser_after(parser, current, parser->node, 1,
njs_parser_statement_after);
case NJS_TOKEN_IMPORT:
+ parser->line = token->line;
+
njs_lexer_consume_token(parser->lexer, 1);
-
njs_parser_next(parser, njs_parser_import);
return njs_parser_after(parser, current, parser->node, 1,
@@ -4425,12 +4485,10 @@ njs_parser_statement_wo_node(njs_parser_
break;
case NJS_TOKEN_CONTINUE:
- parser->line = token->line;
njs_parser_next(parser, njs_parser_continue_statement);
break;
case NJS_TOKEN_BREAK:
- parser->line = token->line;
njs_parser_next(parser, njs_parser_break_statement);
break;
@@ -4474,6 +4532,8 @@ njs_parser_statement_wo_node(njs_parser_
return NJS_OK;
}
+ parser->line = token->line;
+
njs_lexer_consume_token(parser->lexer, 1);
return NJS_OK;
@@ -4577,6 +4637,7 @@ static njs_int_t
njs_parser_block_statement(njs_parser_t *parser, njs_lexer_token_t *token,
njs_queue_link_t *current)
{
+ void *target;
njs_int_t ret;
ret = njs_parser_scope_begin(parser, NJS_SCOPE_BLOCK);
@@ -4584,16 +4645,19 @@ njs_parser_block_statement(njs_parser_t
return NJS_ERROR;
}
+ target = (void *) (uintptr_t) parser->line;
parser->node = NULL;
if (token->type == NJS_TOKEN_CLOSE_BRACE) {
+ parser->target = target;
+
njs_parser_next(parser, njs_parser_block_statement_close_brace);
return NJS_OK;
}
njs_parser_next(parser, njs_parser_statement_list);
- return njs_parser_after(parser, current, NULL, 1,
+ return njs_parser_after(parser, current, target, 1,
njs_parser_block_statement_close_brace);
}
@@ -4606,6 +4670,8 @@ njs_parser_block_statement_open_brace(nj
return njs_parser_failed(parser);
}
+ parser->line = token->line;
+
njs_lexer_consume_token(parser->lexer, 1);
token = njs_lexer_token(parser->lexer, 0);
@@ -4632,8 +4698,11 @@ njs_parser_block_statement_close_brace(n
return NJS_ERROR;
}
+ node->token_line = (uint32_t) (uintptr_t) parser->target;
node->left = parser->node;
node->right = NULL;
+
+ parser->target = NULL;
parser->node = node;
njs_parser_scope_end(parser);
@@ -4766,6 +4835,8 @@ njs_parser_variable_declaration(njs_pars
return NJS_ERROR;
}
+ name->token_line = token->line;
+
parser->node = name;
njs_lexer_consume_token(parser->lexer, 1);
@@ -4776,11 +4847,16 @@ njs_parser_variable_declaration(njs_pars
}
ret = njs_parser_initializer_assign(parser, NJS_TOKEN_VAR);
+ if (ret != NJS_OK) {
+ return ret;
+ }
+
+ parser->node->token_line = token->line;
if (token->type == NJS_TOKEN_ASSIGNMENT) {
njs_parser_next(parser, njs_parser_initializer);
- return ret;
+ return NJS_OK;
}
parser->target = parser->node;
@@ -4788,7 +4864,7 @@ njs_parser_variable_declaration(njs_pars
njs_parser_next(parser, njs_parser_initializer_after);
- return ret;
+ return NJS_OK;
}
@@ -4923,6 +4999,8 @@ njs_parser_if_statement(njs_parser_t *pa
return NJS_ERROR;
}
+ node->token_line = parser->line;
+
parser->node = NULL;
njs_parser_next(parser, njs_parser_expression);
@@ -4965,12 +5043,23 @@ static njs_int_t
njs_parser_else_statement(njs_parser_t *parser, njs_lexer_token_t *token,
njs_queue_link_t *current)
{
+ njs_parser_node_t *node;
+
parser->target->right = parser->node;
parser->node = NULL;
if (token->type == NJS_TOKEN_ELSE) {
+ node = njs_parser_node_new(parser, NJS_TOKEN_BRANCHING);
+ if (node == NULL) {
+ return NJS_ERROR;
+ }
+
+ node->token_line = token->line;
+ node->left = parser->target->right;
+
+ parser->target->right = node;
+
njs_lexer_consume_token(parser->lexer, 1);
-
njs_parser_next(parser, njs_parser_statement_wo_node);
return njs_parser_after(parser, current, parser->target, 1,
@@ -4987,17 +5076,7 @@ static njs_int_t
njs_parser_else_statement_after(njs_parser_t *parser, njs_lexer_token_t *token,
njs_queue_link_t *current)
{
- njs_parser_node_t *node;
-
- node = njs_parser_node_new(parser, NJS_TOKEN_BRANCHING);
- if (node == NULL) {
- return NJS_ERROR;
- }
-
- node->left = parser->target->right;
- node->right = parser->node;
-
- parser->target->right = node;
+ parser->target->right->right = parser->node;
parser->node = parser->target;
@@ -5009,11 +5088,20 @@ static njs_int_t
njs_parser_iteration_statement_do(njs_parser_t *parser,
njs_lexer_token_t *token, njs_queue_link_t *current)
{
+ njs_parser_node_t *node;
+
+ node = njs_parser_node_new(parser, NJS_TOKEN_DO);
+ if (node == NULL) {
+ return NJS_ERROR;
+ }
+
+ node->token_line = parser->line;
+
parser->node = NULL;
njs_parser_next(parser, njs_parser_statement_wo_node);
- return njs_parser_after(parser, current, NULL, 1,
+ return njs_parser_after(parser, current, node, 1,
njs_parser_iteration_statement_do_while);
}
@@ -5026,11 +5114,13 @@ njs_parser_iteration_statement_do_while(
return njs_parser_failed(parser);
}
+ parser->target->left = parser->node;
+
njs_lexer_consume_token(parser->lexer, 1);
njs_parser_next(parser, njs_parser_expression_parenthesis);
- return njs_parser_after(parser, current, parser->node, 1,
+ return njs_parser_after(parser, current, parser->target, 1,
njs_parser_do_while_semicolon);
}
@@ -5039,20 +5129,12 @@ static njs_int_t
njs_parser_do_while_semicolon(njs_parser_t *parser, njs_lexer_token_t *token,
njs_queue_link_t *current)
{
- njs_parser_node_t *node;
-
if (parser->strict_semicolon) {
return njs_parser_failed(parser);
}
- node = njs_parser_node_new(parser, NJS_TOKEN_DO);
- if (node == NULL) {
- return NJS_ERROR;
- }
-
- node->left = parser->target;
- node->right = parser->node;
- parser->node = node;
+ parser->target->right = parser->node;
+ parser->node = parser->target;
return njs_parser_stack_pop(parser);
}
@@ -5062,9 +5144,18 @@ static njs_int_t
njs_parser_iteration_statement_while(njs_parser_t *parser,
njs_lexer_token_t *token, njs_queue_link_t *current)
{
+ njs_parser_node_t *node;
+
+ node = njs_parser_node_new(parser, NJS_TOKEN_WHILE);
+ if (node == NULL) {
+ return NJS_ERROR;
+ }
+
+ node->token_line = token->line;
+
njs_parser_next(parser, njs_parser_expression_parenthesis);
- return njs_parser_after(parser, current, NULL, 1,
+ return njs_parser_after(parser, current, node, 1,
njs_parser_while_statement);
}
@@ -5073,15 +5164,13 @@ static njs_int_t
njs_parser_while_statement(njs_parser_t *parser, njs_lexer_token_t *token,
njs_queue_link_t *current)
{
- njs_parser_node_t *node;
-
- node = parser->node;
-
+ parser->target->right = parser->node;
parser->node = NULL;
njs_parser_next(parser, njs_parser_statement_wo_node);
- return njs_parser_after(parser, current, node, 1, njs_parser_while_after);
+ return njs_parser_after(parser, current, parser->target, 1,
+ njs_parser_while_after);
}
@@ -5089,16 +5178,8 @@ static njs_int_t
njs_parser_while_after(njs_parser_t *parser, njs_lexer_token_t *token,
njs_queue_link_t *current)
{
- njs_parser_node_t *node;
-
- node = njs_parser_node_new(parser, NJS_TOKEN_WHILE);
- if (node == NULL) {
- return NJS_ERROR;
- }
-
- node->left = parser->node;
- node->right = parser->target;
- parser->node = node;
+ parser->target->left = parser->node;
+ parser->node = parser->target;
return njs_parser_stack_pop(parser);
}
@@ -5113,7 +5194,9 @@ njs_parser_iteration_statement_for(njs_p
njs_parser_next(parser, njs_parser_iteration_statement_for_map);
- return NJS_OK;
+ return njs_parser_after(parser, current,
+ (void *) (uintptr_t) parser->line, 1,
+ njs_parser_set_line_state);
}
if (token->type == NJS_TOKEN_AWAIT) {
@@ -5226,7 +5309,7 @@ njs_parser_for_var_binding_or_var_list(n
{
njs_int_t ret;
njs_lexer_token_t *next;
- njs_parser_node_t *node;
+ njs_parser_node_t *node, *var;
switch (token->type) {
/* BindingPattern */
@@ -5256,13 +5339,23 @@ njs_parser_for_var_binding_or_var_list(n
return NJS_OK;
}
- node = njs_parser_variable_node(parser, token->unique_id,
+ var = njs_parser_variable_node(parser, token->unique_id,
NJS_VARIABLE_VAR);
+ if (var == NULL) {
+ return NJS_ERROR;
+ }
+
+ var->token_line = token->line;
+
+ parser->node = NULL;
+
+ node = njs_parser_node_new(parser, NJS_TOKEN_IN);
if (node == NULL) {
return NJS_ERROR;
}
- parser->node = NULL;
+ node->token_line = next->line;
+ node->left = var;
njs_parser_next(parser, njs_parser_expression);
@@ -5289,27 +5382,18 @@ static njs_int_t
njs_parser_for_var_in_statement(njs_parser_t *parser, njs_lexer_token_t *token,
njs_queue_link_t *current)
{
- njs_parser_node_t *node;
-
if (token->type != NJS_TOKEN_CLOSE_PARENTHESIS) {
return njs_parser_failed(parser);
}
njs_lexer_consume_token(parser->lexer, 1);
- node = njs_parser_node_new(parser, NJS_TOKEN_IN);
- if (node == NULL) {
- return NJS_ERROR;
- }
-
- node->left = parser->target;
- node->right = parser->node;
-
+ parser->target->right = parser->node;
parser->node = NULL;
njs_parser_next(parser, njs_parser_statement_wo_node);
- return njs_parser_after(parser, current, node, 1,
+ return njs_parser_after(parser, current, parser->target, 1,
njs_parser_for_var_in_statement_after);
}
@@ -5658,6 +5742,8 @@ njs_parser_return_statement(njs_parser_t
return NJS_ERROR;
}
+ node->token_line = parser->line;
+
switch (token->type) {
case NJS_TOKEN_SEMICOLON:
break;
@@ -5734,6 +5820,8 @@ njs_parser_switch_statement(njs_parser_t
return NJS_ERROR;
}
+ swtch->token_line = parser->line;
+
njs_parser_next(parser, njs_parser_expression_parenthesis);
ret = njs_parser_after(parser, current, swtch, 1,
@@ -5811,6 +5899,7 @@ njs_parser_switch_case_def(njs_parser_t
return NJS_ERROR;
}
+ branch->token_line = token->line;
branch->right = node;
njs_parser_next(parser, njs_parser_expression);
More information about the nginx-devel
mailing list