Welcome! Log In Create A New Profile

Advanced

[njs] Improved fields and typedefs naming in parser.

Alexander Borisov
February 26, 2020 08:24AM
details: https://hg.nginx.org/njs/rev/112c7f54f402
branches:
changeset: 1337:112c7f54f402
user: Alexander Borisov <alexander.borisov@nginx.com>
date: Wed Feb 26 16:22:12 2020 +0300
description:
Improved fields and typedefs naming in parser.

njs_token_t -> njs_token_type_t
node->token -> node->token_type
lexer->prev_token -> lexer->prev_type

diffstat:

src/njs_generator.c | 30 +-
src/njs_lexer.c | 6 +-
src/njs_lexer.h | 12 +-
src/njs_module.c | 10 +-
src/njs_parser.c | 994 ++++++++++++++++++++++---------------------
src/njs_parser.h | 84 +-
src/njs_parser_expression.c | 475 ++++++++++----------
src/njs_parser_terminal.c | 195 ++++----
src/njs_regexp.c | 2 +-
src/njs_regexp.h | 2 +-
10 files changed, 909 insertions(+), 901 deletions(-)

diffs (truncated from 3972 to 1000 lines):

diff -r 87d05fb35ff9 -r 112c7f54f402 src/njs_generator.c
--- a/src/njs_generator.c Wed Feb 26 16:22:10 2020 +0300
+++ b/src/njs_generator.c Wed Feb 26 16:22:12 2020 +0300
@@ -264,7 +264,7 @@ njs_generate(njs_vm_t *vm, njs_generator
return NJS_OK;
}

- switch (node->token) {
+ switch (node->token_type) {

case NJS_TOKEN_VAR:
return njs_generate_var_statement(vm, generator, node);
@@ -664,7 +664,7 @@ njs_generate_if_statement(njs_vm_t *vm,
jump_offset = njs_code_offset(generator, cond_jump);
label_offset = jump_offset + offsetof(njs_vmcode_cond_jump_t, offset);

- if (node->right != NULL && node->right->token == NJS_TOKEN_BRANCHING) {
+ if (node->right != NULL && node->right->token_type == NJS_TOKEN_BRANCHING) {

/* The "then" branch in a case of "if/then/else" statement. */

@@ -836,7 +836,7 @@ njs_generate_switch_statement(njs_vm_t *

for (branch = swtch->right; branch != NULL; branch = branch->left) {

- if (branch->token != NJS_TOKEN_DEFAULT) {
+ if (branch->token_type != NJS_TOKEN_DEFAULT) {

/* The "case" expression. */

@@ -887,7 +887,7 @@ njs_generate_switch_statement(njs_vm_t *

for (branch = swtch->right; branch != NULL; branch = branch->left) {

- if (branch->token == NJS_TOKEN_DEFAULT) {
+ if (branch->token_type == NJS_TOKEN_DEFAULT) {
njs_code_set_jump_offset(generator, njs_vmcode_jump_t, jump_offset);
jump = NULL;
node = branch;
@@ -1580,7 +1580,7 @@ njs_generate_stop_statement(njs_vm_t *vm
index = NJS_INDEX_NONE;
node = node->right;

- if (node != NULL && node->token != NJS_TOKEN_FUNCTION) {
+ if (node != NULL && node->token_type != NJS_TOKEN_FUNCTION) {
index = node->index;
}

@@ -1626,7 +1626,7 @@ njs_generate_assignment(njs_vm_t *vm, nj
expr = node->right;
expr->dest = NULL;

- if (lvalue->token == NJS_TOKEN_NAME) {
+ if (lvalue->token_type == NJS_TOKEN_NAME) {

ret = njs_generate_variable(vm, generator, lvalue, NJS_DECLARATION);
if (njs_slow_path(ret != NJS_OK)) {
@@ -1679,7 +1679,7 @@ njs_generate_assignment(njs_vm_t *vm, nj
* Preserve object and property values stored in variables in a case
* if the variables can be changed by side effects in expression.
*/
- if (object->token == NJS_TOKEN_NAME) {
+ if (object->token_type == NJS_TOKEN_NAME) {
src = object->index;

index = njs_generate_node_temp_index_get(vm, generator, object);
@@ -1690,7 +1690,7 @@ njs_generate_assignment(njs_vm_t *vm, nj
njs_generate_code_move(generator, move, index, src);
}

- if (property->token == NJS_TOKEN_NAME) {
+ if (property->token_type == NJS_TOKEN_NAME) {
src = property->index;

index = njs_generate_node_temp_index_get(vm, generator, property);
@@ -1707,7 +1707,7 @@ njs_generate_assignment(njs_vm_t *vm, nj
return ret;
}

- switch (lvalue->token) {
+ switch (lvalue->token_type) {
case NJS_TOKEN_PROPERTY_INIT:
njs_generate_code(generator, njs_vmcode_prop_set_t, prop_set,
NJS_VMCODE_PROPERTY_INIT, 3);
@@ -1749,7 +1749,7 @@ njs_generate_operation_assignment(njs_vm

lvalue = node->left;

- if (lvalue->token == NJS_TOKEN_NAME) {
+ if (lvalue->token_type == NJS_TOKEN_NAME) {

ret = njs_generate_variable(vm, generator, lvalue, NJS_DECLARATION);
if (njs_slow_path(ret != NJS_OK)) {
@@ -1912,7 +1912,7 @@ njs_generate_property_accessor(njs_vm_t
accessor->value = function->index;
accessor->object = object->index;
accessor->property = property->index;
- accessor->type = (node->token == NJS_TOKEN_PROPERTY_GETTER)
+ accessor->type = (node->token_type == NJS_TOKEN_PROPERTY_GETTER)
? NJS_OBJECT_PROP_GETTER : NJS_OBJECT_PROP_SETTER;

return NJS_OK;
@@ -2094,7 +2094,7 @@ njs_generate_3addr_operation(njs_vm_t *v

right = node->right;

- if (left->token == NJS_TOKEN_NAME) {
+ if (left->token_type == NJS_TOKEN_NAME) {

if (njs_slow_path(njs_parser_has_side_effect(right))) {
njs_generate_code(generator, njs_vmcode_move_t, move,
@@ -2184,7 +2184,7 @@ njs_generate_typeof_operation(njs_vm_t *

expr = node->left;

- if (expr->token == NJS_TOKEN_NAME) {
+ if (expr->token_type == NJS_TOKEN_NAME) {
ret = njs_generate_variable(vm, generator, expr, NJS_TYPEOF);
if (njs_slow_path(ret != NJS_OK)) {
return NJS_ERROR;
@@ -2227,7 +2227,7 @@ njs_generate_inc_dec_operation(njs_vm_t

lvalue = node->left;

- if (lvalue->token == NJS_TOKEN_NAME) {
+ if (lvalue->token_type == NJS_TOKEN_NAME) {

ret = njs_generate_variable(vm, generator, lvalue, NJS_DECLARATION);
if (njs_slow_path(ret != NJS_OK)) {
@@ -2860,7 +2860,7 @@ njs_generate_try_statement(njs_vm_t *vm,
catch_exit_label = undef_label;
catch_cont_label = undef_label;

- if (node->token == NJS_TOKEN_CATCH) {
+ if (node->token_type == NJS_TOKEN_CATCH) {
/* A "try/catch" case. */

catch_index = njs_variable_index(vm, node->left);
diff -r 87d05fb35ff9 -r 112c7f54f402 src/njs_lexer.c
--- a/src/njs_lexer.c Wed Feb 26 16:22:10 2020 +0300
+++ b/src/njs_lexer.c Wed Feb 26 16:22:12 2020 +0300
@@ -311,7 +311,7 @@ njs_lexer_init(njs_vm_t *vm, njs_lexer_t
}


-njs_token_t
+njs_token_type_t
njs_lexer_token(njs_vm_t *vm, njs_lexer_t *lexer)
{
njs_lexer_token_t *lt;
@@ -319,7 +319,7 @@ njs_lexer_token(njs_vm_t *vm, njs_lexer_
lexer->prev_start = lexer->start;

if (lexer->token != NULL) {
- lexer->prev_token = lexer->token->type;
+ lexer->prev_type = lexer->token->type;
njs_mp_free(vm->mem_pool, lexer->token);
}

@@ -336,7 +336,7 @@ njs_lexer_token(njs_vm_t *vm, njs_lexer_
}


-njs_token_t
+njs_token_type_t
njs_lexer_peek_token(njs_vm_t *vm, njs_lexer_t *lexer, size_t offset)
{
size_t i;
diff -r 87d05fb35ff9 -r 112c7f54f402 src/njs_lexer.h
--- a/src/njs_lexer.h Wed Feb 26 16:22:10 2020 +0300
+++ b/src/njs_lexer.h Wed Feb 26 16:22:12 2020 +0300
@@ -195,7 +195,7 @@ typedef enum {
NJS_TOKEN_SUPER,

NJS_TOKEN_RESERVED,
-} njs_token_t;
+} njs_token_type_t;


typedef struct {
@@ -205,7 +205,7 @@ typedef struct {

typedef struct {
njs_lexer_entry_t entry;
- njs_token_t type;
+ njs_token_type_t type;
} njs_keyword_t;


@@ -219,7 +219,7 @@ typedef struct {


typedef struct {
- njs_token_t type:16;
+ njs_token_type_t type:16;
uint32_t line;
uintptr_t unique_id;
njs_str_t text;
@@ -234,7 +234,7 @@ typedef struct {
uint8_t keyword;

u_char *prev_start;
- njs_token_t prev_token:16;
+ njs_token_type_t prev_type:16;

uint32_t line;
njs_str_t file;
@@ -251,8 +251,8 @@ typedef struct {
njs_int_t njs_lexer_init(njs_vm_t *vm, njs_lexer_t *lexer, njs_str_t *file,
u_char *start, u_char *end);

-njs_token_t njs_lexer_token(njs_vm_t *vm, njs_lexer_t *lexer);
-njs_token_t njs_lexer_peek_token(njs_vm_t *vm, njs_lexer_t *lexer,
+njs_token_type_t njs_lexer_token(njs_vm_t *vm, njs_lexer_t *lexer);
+njs_token_type_t njs_lexer_peek_token(njs_vm_t *vm, njs_lexer_t *lexer,
size_t offset);
njs_int_t njs_lexer_rollback(njs_vm_t *vm, njs_lexer_t *lexer);

diff -r 87d05fb35ff9 -r 112c7f54f402 src/njs_module.c
--- a/src/njs_module.c Wed Feb 26 16:22:10 2020 +0300
+++ b/src/njs_module.c Wed Feb 26 16:22:12 2020 +0300
@@ -104,7 +104,7 @@ njs_parser_module(njs_vm_t *vm, njs_pars
njs_str_t name, text;
njs_lexer_t *prev, lexer;
njs_module_t *module;
- njs_token_t token;
+ njs_token_type_t type;
njs_parser_node_t *node;
njs_module_info_t info;

@@ -161,13 +161,13 @@ njs_parser_module(njs_vm_t *vm, njs_pars

parser->lexer = &lexer;

- token = njs_parser_token(vm, parser);
- if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
+ type = njs_parser_token(vm, parser);
+ if (njs_slow_path(type <= NJS_TOKEN_ILLEGAL)) {
goto fail;
}

- token = njs_parser_module_lambda(vm, parser);
- if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
+ type = njs_parser_module_lambda(vm, parser);
+ if (njs_slow_path(type <= NJS_TOKEN_ILLEGAL)) {
goto fail;
}

diff -r 87d05fb35ff9 -r 112c7f54f402 src/njs_parser.c
--- a/src/njs_parser.c Wed Feb 26 16:22:10 2020 +0300
+++ b/src/njs_parser.c Wed Feb 26 16:22:12 2020 +0300
@@ -11,55 +11,59 @@
static njs_int_t njs_parser_scope_begin(njs_vm_t *vm, njs_parser_t *parser,
njs_scope_t type);
static void njs_parser_scope_end(njs_vm_t *vm, njs_parser_t *parser);
-static njs_token_t njs_parser_statement_chain(njs_vm_t *vm,
- njs_parser_t *parser, njs_token_t token, njs_bool_t top);
-static njs_token_t njs_parser_statement(njs_vm_t *vm, njs_parser_t *parser,
- njs_token_t token);
-static njs_token_t njs_parser_block_statement(njs_vm_t *vm,
+static njs_token_type_t njs_parser_statement_chain(njs_vm_t *vm,
+ njs_parser_t *parser, njs_token_type_t type, njs_bool_t top);
+static njs_token_type_t njs_parser_statement(njs_vm_t *vm, njs_parser_t *parser,
+ njs_token_type_t type);
+static njs_token_type_t njs_parser_block_statement(njs_vm_t *vm,
njs_parser_t *parser);
-static njs_token_t njs_parser_block(njs_vm_t *vm,
- njs_parser_t *parser, njs_token_t token);
-static njs_token_t njs_parser_labelled_statement(njs_vm_t *vm,
+static njs_token_type_t njs_parser_block(njs_vm_t *vm,
+ njs_parser_t *parser, njs_token_type_t type);
+static njs_token_type_t njs_parser_labelled_statement(njs_vm_t *vm,
njs_parser_t *parser);
-static njs_token_t njs_parser_function_declaration(njs_vm_t *vm,
+static njs_token_type_t njs_parser_function_declaration(njs_vm_t *vm,
njs_parser_t *parser);
-static njs_token_t njs_parser_lambda_arguments(njs_vm_t *vm,
+static njs_token_type_t njs_parser_lambda_arguments(njs_vm_t *vm,
njs_parser_t *parser, njs_function_lambda_t *lambda, njs_index_t index,
- njs_token_t token);
-static njs_token_t njs_parser_lambda_argument(njs_vm_t *vm,
+ njs_token_type_t type);
+static njs_token_type_t njs_parser_lambda_argument(njs_vm_t *vm,
njs_parser_t *parser, njs_index_t index);
-static njs_token_t njs_parser_lambda_body(njs_vm_t *vm, njs_parser_t *parser,
- njs_token_t token);
+static njs_token_type_t njs_parser_lambda_body(njs_vm_t *vm,
+ njs_parser_t *parser, njs_token_type_t type);
static njs_parser_node_t *njs_parser_return_set(njs_vm_t *vm,
njs_parser_t *parser, njs_parser_node_t *expr);
-static njs_token_t njs_parser_return_statement(njs_vm_t *vm,
+static njs_token_type_t njs_parser_return_statement(njs_vm_t *vm,
+ njs_parser_t *parser);
+static njs_token_type_t njs_parser_var_statement(njs_vm_t *vm,
+ njs_parser_t *parser, njs_token_type_t parent, njs_bool_t var_in);
+static njs_token_type_t njs_parser_if_statement(njs_vm_t *vm,
njs_parser_t *parser);
-static njs_token_t njs_parser_var_statement(njs_vm_t *vm, njs_parser_t *parser,
- njs_token_t parent, njs_bool_t var_in);
-static njs_token_t njs_parser_if_statement(njs_vm_t *vm, njs_parser_t *parser);
-static njs_token_t njs_parser_switch_statement(njs_vm_t *vm,
+static njs_token_type_t njs_parser_switch_statement(njs_vm_t *vm,
+ njs_parser_t *parser);
+static njs_token_type_t njs_parser_while_statement(njs_vm_t *vm,
njs_parser_t *parser);
-static njs_token_t njs_parser_while_statement(njs_vm_t *vm,
+static njs_token_type_t njs_parser_do_while_statement(njs_vm_t *vm,
njs_parser_t *parser);
-static njs_token_t njs_parser_do_while_statement(njs_vm_t *vm,
+static njs_token_type_t njs_parser_for_statement(njs_vm_t *vm,
njs_parser_t *parser);
-static njs_token_t njs_parser_for_statement(njs_vm_t *vm, njs_parser_t *parser);
-static njs_token_t njs_parser_var_in_statement(njs_vm_t *vm,
+static njs_token_type_t njs_parser_var_in_statement(njs_vm_t *vm,
njs_parser_t *parser, njs_parser_node_t *name);
-static njs_token_t njs_parser_for_in_statement(njs_vm_t *vm,
- njs_parser_t *parser, njs_str_t *name, njs_token_t token);
-static njs_token_t njs_parser_brk_statement(njs_vm_t *vm,
- njs_parser_t *parser, njs_token_t token);
-static njs_token_t njs_parser_try_statement(njs_vm_t *vm, njs_parser_t *parser);
-static njs_token_t njs_parser_try_block(njs_vm_t *vm, njs_parser_t *parser);
-static njs_token_t njs_parser_throw_statement(njs_vm_t *vm,
+static njs_token_type_t njs_parser_for_in_statement(njs_vm_t *vm,
+ njs_parser_t *parser, njs_str_t *name, njs_token_type_t type);
+static njs_token_type_t njs_parser_brk_statement(njs_vm_t *vm,
+ njs_parser_t *parser, njs_token_type_t type);
+static njs_token_type_t njs_parser_try_statement(njs_vm_t *vm,
njs_parser_t *parser);
-static njs_token_t njs_parser_import_statement(njs_vm_t *vm,
+static njs_token_type_t njs_parser_try_block(njs_vm_t *vm,
+ njs_parser_t *parser);
+static njs_token_type_t njs_parser_throw_statement(njs_vm_t *vm,
njs_parser_t *parser);
-static njs_token_t njs_parser_export_statement(njs_vm_t *vm,
+static njs_token_type_t njs_parser_import_statement(njs_vm_t *vm,
+ njs_parser_t *parser);
+static njs_token_type_t njs_parser_export_statement(njs_vm_t *vm,
njs_parser_t *parser);
static njs_int_t njs_parser_export_sink(njs_vm_t *vm, njs_parser_t *parser);
-static njs_token_t njs_parser_grouping_expression(njs_vm_t *vm,
+static njs_token_type_t njs_parser_grouping_expression(njs_vm_t *vm,
njs_parser_t *parser);


@@ -77,7 +81,7 @@ njs_int_t
njs_parser(njs_vm_t *vm, njs_parser_t *parser, njs_parser_t *prev)
{
njs_int_t ret;
- njs_token_t token;
+ njs_token_type_t type;
njs_parser_node_t *node;

ret = njs_parser_scope_begin(vm, parser, NJS_SCOPE_GLOBAL);
@@ -97,16 +101,16 @@ njs_parser(njs_vm_t *vm, njs_parser_t *p
}
}

- token = njs_parser_token(vm, parser);
-
- while (token != NJS_TOKEN_END) {
-
- token = njs_parser_statement_chain(vm, parser, token, 1);
- if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
+ type = njs_parser_token(vm, parser);
+
+ while (type != NJS_TOKEN_END) {
+
+ type = njs_parser_statement_chain(vm, parser, type, 1);
+ if (njs_slow_path(type <= NJS_TOKEN_ILLEGAL)) {
return NJS_ERROR;
}

- if (token == NJS_TOKEN_CLOSE_BRACE && vm->options.trailer) {
+ if (type == NJS_TOKEN_CLOSE_BRACE && vm->options.trailer) {
parser->lexer->start--;
break;
}
@@ -125,7 +129,7 @@ njs_parser(njs_vm_t *vm, njs_parser_t *p
njs_parser_chain_top_set(parser, node);
}

- node->token = NJS_TOKEN_END;
+ node->token_type = NJS_TOKEN_END;

if (njs_slow_path(parser->count != 0)) {
njs_internal_error(vm, "parser->count != 0");
@@ -264,9 +268,9 @@ njs_parser_scope_rbtree_compare(njs_rbtr
}


-static njs_token_t
+static njs_token_type_t
njs_parser_statement_chain(njs_vm_t *vm, njs_parser_t *parser,
- njs_token_t token, njs_bool_t top)
+ njs_token_type_t type, njs_bool_t top)
{
njs_parser_node_t *stmt, *last, *node, *new_node, **child;

@@ -277,17 +281,17 @@ njs_parser_statement_chain(njs_vm_t *vm,

njs_parser_enter(vm, parser);

- token = njs_parser_statement(vm, parser, token);
+ type = njs_parser_statement(vm, parser, type);

njs_parser_leave(parser);

- if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
- return njs_parser_unexpected_token(vm, parser, token);
+ if (njs_slow_path(type <= NJS_TOKEN_ILLEGAL)) {
+ return njs_parser_unexpected_token(vm, parser, type);
}

if (parser->node == NULL) {
/* The statement is empty block or just semicolon. */
- return token;
+ return type;
}

new_node = parser->node;
@@ -319,26 +323,26 @@ njs_parser_statement_chain(njs_vm_t *vm,

*child = stmt;

- while (token == NJS_TOKEN_SEMICOLON) {
- token = njs_parser_token(vm, parser);
- if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
+ while (type == NJS_TOKEN_SEMICOLON) {
+ type = njs_parser_token(vm, parser);
+ if (njs_slow_path(type <= NJS_TOKEN_ILLEGAL)) {
break;
}
}

- return token;
+ return type;
}


-static njs_token_t
+static njs_token_type_t
njs_parser_statement(njs_vm_t *vm, njs_parser_t *parser,
- njs_token_t token)
+ njs_token_type_t type)
{
size_t offset;

parser->node = NULL;

- switch (token) {
+ switch (type) {

case NJS_TOKEN_FUNCTION:
return njs_parser_function_declaration(vm, parser);
@@ -371,37 +375,37 @@ njs_parser_statement(njs_vm_t *vm, njs_p
if (vm->options.trailer) {
parser->node = NULL;
njs_thread_log_debug("BLOCK END");
- return token;
+ return type;
}

/* Fall through. */

default:

- switch (token) {
+ switch (type) {
case NJS_TOKEN_VAR:
- token = njs_parser_var_statement(vm, parser, token, 0);
+ type = njs_parser_var_statement(vm, parser, type, 0);
break;

case NJS_TOKEN_RETURN:
- token = njs_parser_return_statement(vm, parser);
+ type = njs_parser_return_statement(vm, parser);
break;

case NJS_TOKEN_THROW:
- token = njs_parser_throw_statement(vm, parser);
+ type = njs_parser_throw_statement(vm, parser);
break;

case NJS_TOKEN_CONTINUE:
case NJS_TOKEN_BREAK:
- token = njs_parser_brk_statement(vm, parser, token);
+ type = njs_parser_brk_statement(vm, parser, type);
break;

case NJS_TOKEN_IMPORT:
- token = njs_parser_import_statement(vm, parser);
+ type = njs_parser_import_statement(vm, parser);
break;

case NJS_TOKEN_EXPORT:
- token = njs_parser_export_statement(vm, parser);
+ type = njs_parser_export_statement(vm, parser);
break;

case NJS_TOKEN_NAME:
@@ -413,30 +417,30 @@ njs_parser_statement(njs_vm_t *vm, njs_p
/* Fall through. */

default:
- token = njs_parser_expression(vm, parser, token);
+ type = njs_parser_expression(vm, parser, type);
break;
}

- if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
- return token;
+ if (njs_slow_path(type <= NJS_TOKEN_ILLEGAL)) {
+ return type;
}

/*
* An expression must be terminated by semicolon,
* or by a close curly brace or by the end of line.
*/
- switch (token) {
+ switch (type) {

case NJS_TOKEN_SEMICOLON:
return njs_parser_token(vm, parser);

case NJS_TOKEN_CLOSE_BRACE:
case NJS_TOKEN_END:
- return token;
+ return type;

default:
- if (parser->lexer->prev_token == NJS_TOKEN_LINE_END) {
- return token;
+ if (parser->lexer->prev_type == NJS_TOKEN_LINE_END) {
+ return type;
}

return NJS_TOKEN_ILLEGAL;
@@ -445,16 +449,16 @@ njs_parser_statement(njs_vm_t *vm, njs_p
}


-static njs_token_t
+static njs_token_type_t
njs_parser_block_statement(njs_vm_t *vm, njs_parser_t *parser)
{
njs_int_t ret;
- njs_token_t token;
+ njs_token_type_t type;
njs_parser_node_t *node;

- token = njs_parser_token(vm, parser);
- if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
- return token;
+ type = njs_parser_token(vm, parser);
+ if (njs_slow_path(type <= NJS_TOKEN_ILLEGAL)) {
+ return type;
}

ret = njs_parser_scope_begin(vm, parser, NJS_SCOPE_BLOCK);
@@ -464,10 +468,10 @@ njs_parser_block_statement(njs_vm_t *vm,

parser->node = NULL;

- while (token != NJS_TOKEN_CLOSE_BRACE) {
- token = njs_parser_statement_chain(vm, parser, token, 0);
- if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
- return token;
+ while (type != NJS_TOKEN_CLOSE_BRACE) {
+ type = njs_parser_statement_chain(vm, parser, type, 0);
+ if (njs_slow_path(type <= NJS_TOKEN_ILLEGAL)) {
+ return type;
}
}

@@ -486,16 +490,16 @@ njs_parser_block_statement(njs_vm_t *vm,
}


-static njs_token_t
-njs_parser_block(njs_vm_t *vm, njs_parser_t *parser, njs_token_t token)
+static njs_token_type_t
+njs_parser_block(njs_vm_t *vm, njs_parser_t *parser, njs_token_type_t type)
{
- if (token == NJS_TOKEN_FUNCTION) {
+ if (type == NJS_TOKEN_FUNCTION) {
njs_parser_syntax_error(vm, parser,
"Functions can only be declared at top level or inside a block");
return NJS_TOKEN_ILLEGAL;
}

- return njs_parser_statement(vm, parser, token);
+ return njs_parser_statement(vm, parser, type);
}


@@ -540,14 +544,14 @@ njs_parser_variable_node(njs_vm_t *vm, n
}


-static njs_token_t
+static njs_token_type_t
njs_parser_labelled_statement(njs_vm_t *vm, njs_parser_t *parser)
{
- uintptr_t unique_id;
- njs_int_t ret;
- njs_str_t name;
- njs_token_t token;
- njs_variable_t *label;
+ uintptr_t unique_id;
+ njs_int_t ret;
+ njs_str_t name;
+ njs_variable_t *label;
+ njs_token_type_t type;

name = *njs_parser_text(parser);
unique_id = njs_parser_key_hash(parser);
@@ -564,19 +568,19 @@ njs_parser_labelled_statement(njs_vm_t *
return NJS_TOKEN_ERROR;
}

- token = njs_parser_token(vm, parser);
- if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
- return token;
+ type = njs_parser_token(vm, parser);
+ if (njs_slow_path(type <= NJS_TOKEN_ILLEGAL)) {
+ return type;
}

- token = njs_parser_match(vm, parser, token, NJS_TOKEN_COLON);
- if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
- return token;
+ type = njs_parser_match(vm, parser, type, NJS_TOKEN_COLON);
+ if (njs_slow_path(type <= NJS_TOKEN_ILLEGAL)) {
+ return type;
}

- token = njs_parser_statement(vm, parser, token);
-
- if (njs_fast_path(token > NJS_TOKEN_ILLEGAL)) {
+ type = njs_parser_statement(vm, parser, type);
+
+ if (njs_fast_path(type > NJS_TOKEN_ILLEGAL)) {

if (parser->node != NULL) {
/* The statement is not empty block or just semicolon. */
@@ -593,7 +597,7 @@ njs_parser_labelled_statement(njs_vm_t *
}
}

- return token;
+ return type;
}


@@ -635,13 +639,13 @@ njs_parser_function_alloc(njs_vm_t *vm,
}


-static njs_token_t
+static njs_token_type_t
njs_parser_function_declaration(njs_vm_t *vm, njs_parser_t *parser)
{
njs_int_t ret;
- njs_token_t token;
njs_variable_t *var;
njs_function_t *function;
+ njs_token_type_t type;
njs_parser_node_t *node;

node = njs_parser_node_new(vm, parser, NJS_TOKEN_FUNCTION);
@@ -651,13 +655,13 @@ njs_parser_function_declaration(njs_vm_t

node->token_line = njs_parser_token_line(parser);

- token = njs_parser_token(vm, parser);
- if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
- return token;
+ type = njs_parser_token(vm, parser);
+ if (njs_slow_path(type <= NJS_TOKEN_ILLEGAL)) {
+ return type;
}

- if (token != NJS_TOKEN_NAME) {
- if (njs_parser_restricted_identifier(token)) {
+ if (type != NJS_TOKEN_NAME) {
+ if (njs_parser_restricted_identifier(type)) {
njs_parser_syntax_error(vm, parser, "Identifier \"%V\" "
"is forbidden in function declaration",
njs_parser_text(parser));
@@ -676,9 +680,9 @@ njs_parser_function_declaration(njs_vm_t
return NJS_TOKEN_ERROR;
}

- token = njs_parser_token(vm, parser);
- if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
- return token;
+ type = njs_parser_token(vm, parser);
+ if (njs_slow_path(type <= NJS_TOKEN_ILLEGAL)) {
+ return type;
}

parser->node = node;
@@ -688,22 +692,22 @@ njs_parser_function_declaration(njs_vm_t
return NJS_TOKEN_ERROR;
}

- token = njs_parser_function_lambda(vm, parser, function->u.lambda, token);
+ type = njs_parser_function_lambda(vm, parser, function->u.lambda, type);

function->args_count = function->u.lambda->nargs
- function->u.lambda->rest_parameters;

- return token;
+ return type;
}


-njs_token_t
+njs_token_type_t
njs_parser_function_expression(njs_vm_t *vm, njs_parser_t *parser)
{
njs_int_t ret;
- njs_token_t token;
njs_variable_t *var;
njs_function_t *function;
+ njs_token_type_t type;
njs_parser_node_t *node;
njs_function_lambda_t *lambda;

@@ -715,9 +719,9 @@ njs_parser_function_expression(njs_vm_t
node->token_line = njs_parser_token_line(parser);
parser->node = node;

- token = njs_parser_token(vm, parser);
- if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
- return token;
+ type = njs_parser_token(vm, parser);
+ if (njs_slow_path(type <= NJS_TOKEN_ILLEGAL)) {
+ return type;
}

/*
@@ -729,15 +733,15 @@ njs_parser_function_expression(njs_vm_t
return NJS_TOKEN_ERROR;
}

- if (token == NJS_TOKEN_NAME) {
+ if (type == NJS_TOKEN_NAME) {
var = njs_parser_variable_add(vm, parser, NJS_VARIABLE_SHIM);
if (njs_slow_path(var == NULL)) {
return NJS_TOKEN_ERROR;
}

- token = njs_parser_token(vm, parser);
- if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
- return token;
+ type = njs_parser_token(vm, parser);
+ if (njs_slow_path(type <= NJS_TOKEN_ILLEGAL)) {
+ return type;
}

function = njs_parser_function_alloc(vm, parser, var);
@@ -757,17 +761,17 @@ njs_parser_function_expression(njs_vm_t

node->u.value.data.u.lambda = lambda;

- token = njs_parser_function_lambda(vm, parser, lambda, token);
+ type = njs_parser_function_lambda(vm, parser, lambda, type);

njs_parser_scope_end(vm, parser);

- return token;
+ return type;
}


-njs_token_t
+njs_token_type_t
njs_parser_function_lambda(njs_vm_t *vm, njs_parser_t *parser,
- njs_function_lambda_t *lambda, njs_token_t token)
+ njs_function_lambda_t *lambda, njs_token_type_t type)
{
njs_int_t ret;
njs_index_t index;
@@ -782,61 +786,61 @@ njs_parser_function_lambda(njs_vm_t *vm,
/* A "this" reservation. */
index += sizeof(njs_value_t);

- token = njs_parser_lambda_arguments(vm, parser, lambda, index, token);
- if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
- return token;
+ type = njs_parser_lambda_arguments(vm, parser, lambda, index, type);
+ if (njs_slow_path(type <= NJS_TOKEN_ILLEGAL)) {
+ return type;
}

- token = njs_parser_lambda_body(vm, parser, token);
- if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
- return token;
+ type = njs_parser_lambda_body(vm, parser, type);
+ if (njs_slow_path(type <= NJS_TOKEN_ILLEGAL)) {
+ return type;
}

njs_parser_scope_end(vm, parser);

- return token;
+ return type;
}


-static njs_token_t
+static njs_token_type_t
njs_parser_lambda_arguments(njs_vm_t *vm, njs_parser_t *parser,
- njs_function_lambda_t *lambda, njs_index_t index, njs_token_t token)
+ njs_function_lambda_t *lambda, njs_index_t index, njs_token_type_t type)
{
- token = njs_parser_match(vm, parser, token, NJS_TOKEN_OPEN_PARENTHESIS);
- if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
- return token;
+ type = njs_parser_match(vm, parser, type, NJS_TOKEN_OPEN_PARENTHESIS);
+ if (njs_slow_path(type <= NJS_TOKEN_ILLEGAL)) {
+ return type;
}

lambda->nargs = 0;

- while (token != NJS_TOKEN_CLOSE_PARENTHESIS) {
+ while (type != NJS_TOKEN_CLOSE_PARENTHESIS) {

if (njs_slow_path(lambda->rest_parameters)) {
return NJS_TOKEN_ILLEGAL;
}

- if (njs_slow_path(token == NJS_TOKEN_ELLIPSIS)) {
+ if (njs_slow_path(type == NJS_TOKEN_ELLIPSIS)) {
lambda->rest_parameters = 1;

- token = njs_parser_token(vm, parser);
- if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
+ type = njs_parser_token(vm, parser);
+ if (njs_slow_path(type <= NJS_TOKEN_ILLEGAL)) {
return NJS_TOKEN_ILLEGAL;
}
}

- if (njs_slow_path(token != NJS_TOKEN_NAME)) {
+ if (njs_slow_path(type != NJS_TOKEN_NAME)) {
return NJS_TOKEN_ILLEGAL;
}

- token = njs_parser_lambda_argument(vm, parser, index);
- if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
- return token;
+ type = njs_parser_lambda_argument(vm, parser, index);
+ if (njs_slow_path(type <= NJS_TOKEN_ILLEGAL)) {
+ return type;
}

- if (token == NJS_TOKEN_COMMA) {
- token = njs_parser_token(vm, parser);
- if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
- return token;
+ if (type == NJS_TOKEN_COMMA) {
+ type = njs_parser_token(vm, parser);
+ if (njs_slow_path(type <= NJS_TOKEN_ILLEGAL)) {
+ return type;
}
}

@@ -848,7 +852,7 @@ njs_parser_lambda_arguments(njs_vm_t *vm
}


-static njs_token_t
+static njs_token_type_t
njs_parser_lambda_argument(njs_vm_t *vm, njs_parser_t *parser,
njs_index_t index)
{
@@ -872,16 +876,17 @@ njs_parser_lambda_argument(njs_vm_t *vm,
}


-static njs_token_t
-njs_parser_lambda_body(njs_vm_t *vm, njs_parser_t *parser, njs_token_t token)
+static njs_token_type_t
+njs_parser_lambda_body(njs_vm_t *vm, njs_parser_t *parser,
+ njs_token_type_t type)
{
njs_parser_node_t *body, *last, *parent;

parent = parser->node;

- token = njs_parser_lambda_statements(vm, parser, token);
- if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
- return token;
+ type = njs_parser_lambda_statements(vm, parser, type);
+ if (njs_slow_path(type <= NJS_TOKEN_ILLEGAL)) {
+ return type;
}

last = NULL;
@@ -900,7 +905,7 @@ njs_parser_lambda_body(njs_vm_t *vm, njs
}
}

- if (last == NULL || last->token != NJS_TOKEN_RETURN) {
+ if (last == NULL || last->token_type != NJS_TOKEN_RETURN) {
/*
* There is no function body or the last function body
* body statement is not "return" statement.
@@ -915,7 +920,7 @@ njs_parser_lambda_body(njs_vm_t *vm, njs

parser->node = parent;

- return token;
+ return type;
}


@@ -946,21 +951,21 @@ njs_parser_return_set(njs_vm_t *vm, njs_
}


-njs_token_t
+njs_token_type_t
njs_parser_lambda_statements(njs_vm_t *vm, njs_parser_t *parser,
- njs_token_t token)
+ njs_token_type_t type)
{
- token = njs_parser_match(vm, parser, token, NJS_TOKEN_OPEN_BRACE);
- if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
- return token;
+ type = njs_parser_match(vm, parser, type, NJS_TOKEN_OPEN_BRACE);
+ if (njs_slow_path(type <= NJS_TOKEN_ILLEGAL)) {
+ return type;
}

parser->node = NULL;

- while (token != NJS_TOKEN_CLOSE_BRACE) {
- token = njs_parser_statement_chain(vm, parser, token, 1);
- if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
- return token;
+ while (type != NJS_TOKEN_CLOSE_BRACE) {
+ type = njs_parser_statement_chain(vm, parser, type, 1);
+ if (njs_slow_path(type <= NJS_TOKEN_ILLEGAL)) {
+ return type;
}
}

@@ -968,10 +973,10 @@ njs_parser_lambda_statements(njs_vm_t *v
}


-static njs_token_t
+static njs_token_type_t
njs_parser_return_statement(njs_vm_t *vm, njs_parser_t *parser)
{
- njs_token_t token;
+ njs_token_type_t type;
njs_parser_node_t *node;
njs_parser_scope_t *scope;

@@ -997,12 +1002,12 @@ njs_parser_return_statement(njs_vm_t *vm

parser->node = node;

- token = njs_lexer_token(vm, parser->lexer);
- if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
- return token;
+ type = njs_lexer_token(vm, parser->lexer);
+ if (njs_slow_path(type <= NJS_TOKEN_ILLEGAL)) {
+ return type;
}

- switch (token) {
+ switch (type) {

case NJS_TOKEN_LINE_END:
return njs_parser_token(vm, parser);
@@ -1010,31 +1015,31 @@ njs_parser_return_statement(njs_vm_t *vm
case NJS_TOKEN_SEMICOLON:
case NJS_TOKEN_CLOSE_BRACE:
case NJS_TOKEN_END:
- return token;
+ return type;

default:
- token = njs_parser_expression(vm, parser, token);
- if (njs_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
- return token;
+ type = njs_parser_expression(vm, parser, type);
+ if (njs_slow_path(type <= NJS_TOKEN_ILLEGAL)) {
+ return type;
}

- if (parser->node->token == NJS_TOKEN_FUNCTION) {
+ if (parser->node->token_type == NJS_TOKEN_FUNCTION) {
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Improved fields and typedefs naming in parser.

Alexander Borisov 89 February 26, 2020 08:24AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 92
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready