Skip to content

Instantly share code, notes, and snippets.

@xeioex
Created December 29, 2018 15:14
Show Gist options
  • Save xeioex/34df8a611263545fd29209757fc6c6e7 to your computer and use it in GitHub Desktop.
Save xeioex/34df8a611263545fd29209757fc6c6e7 to your computer and use it in GitHub Desktop.
# HG changeset patch
# User hongzhidao <[email protected]>
# Date 1546094131 -28800
# Sat Dec 29 22:35:31 2018 +0800
# Node ID 39bbddb3f19c18e24b0df0adbd02e3b86e076cb4
# Parent 4538d14396e65616cb37733d617fbb57305763ab
Improved function naming in variable code.
Renaming:
1) njs_variable_get() to njs_variable_resolve().
2) njs_variable_find() to njs_variable_reference_resolve().
To better reflect what they do.
diff --git a/njs/njs_generator.c b/njs/njs_generator.c
--- a/njs/njs_generator.c
+++ b/njs/njs_generator.c
@@ -488,7 +488,7 @@ njs_generate_name(njs_vm_t *vm, njs_gene
njs_variable_t *var;
njs_vmcode_object_copy_t *copy;
- var = njs_variable_get(vm, node);
+ var = njs_variable_resolve(vm, node);
if (nxt_slow_path(var == NULL)) {
return NXT_ERROR;
}
@@ -2257,7 +2257,7 @@ njs_generate_function_declaration(njs_vm
njs_variable_t *var;
njs_function_lambda_t *lambda;
- var = njs_variable_get(vm, node);
+ var = njs_variable_resolve(vm, node);
if (nxt_slow_path(var == NULL)) {
return NXT_ERROR;
}
diff --git a/njs/njs_parser.h b/njs/njs_parser.h
--- a/njs/njs_parser.h
+++ b/njs/njs_parser.h
@@ -324,7 +324,7 @@ njs_token_t njs_parser_property_name(njs
njs_token_t njs_parser_property_token(njs_parser_t *parser);
njs_token_t njs_parser_token(njs_parser_t *parser);
nxt_int_t njs_parser_string_create(njs_vm_t *vm, njs_value_t *value);
-njs_variable_t *njs_variable_get(njs_vm_t *vm, njs_parser_node_t *node);
+njs_variable_t *njs_variable_resolve(njs_vm_t *vm, njs_parser_node_t *node);
njs_index_t njs_variable_typeof(njs_vm_t *vm, njs_parser_node_t *node);
njs_index_t njs_variable_index(njs_vm_t *vm, njs_parser_node_t *node);
nxt_bool_t njs_parser_has_side_effect(njs_parser_node_t *node);
diff --git a/njs/njs_variable.c b/njs/njs_variable.c
--- a/njs/njs_variable.c
+++ b/njs/njs_variable.c
@@ -9,8 +9,8 @@
#include <string.h>
-static njs_ret_t njs_variable_find(njs_vm_t *vm, njs_parser_scope_t *node_scope,
- njs_variable_reference_t *vr);
+static njs_ret_t njs_variable_reference_resolve(njs_vm_t *vm,
+ njs_variable_reference_t *vr, njs_parser_scope_t *node_scope);
static njs_variable_t *njs_variable_alloc(njs_vm_t *vm, nxt_str_t *name,
njs_variable_type_t type);
@@ -191,7 +191,7 @@ njs_variables_scope_resolve(njs_vm_t *vm
vr = &node->u.reference;
if (closure) {
- ret = njs_variable_find(vm, node->scope, vr);
+ ret = njs_variable_reference_resolve(vm, vr, node->scope);
if (nxt_slow_path(ret != NXT_OK)) {
continue;
}
@@ -201,7 +201,7 @@ njs_variables_scope_resolve(njs_vm_t *vm
}
}
- var = njs_variable_get(vm, node);
+ var = njs_variable_resolve(vm, node);
if (nxt_slow_path(var == NULL)) {
if (vr->type != NJS_TYPEOF) {
@@ -252,7 +252,7 @@ njs_variable_typeof(njs_vm_t *vm, njs_pa
vr = &node->u.reference;
- ret = njs_variable_find(vm, node->scope, vr);
+ ret = njs_variable_reference_resolve(vm, vr, node->scope);
if (nxt_fast_path(ret == NXT_OK)) {
return vr->variable->index;
@@ -271,7 +271,7 @@ njs_variable_index(njs_vm_t *vm, njs_par
return node->index;
}
- var = njs_variable_get(vm, node);
+ var = njs_variable_resolve(vm, node);
if (nxt_fast_path(var != NULL)) {
return var->index;
@@ -282,7 +282,7 @@ njs_variable_index(njs_vm_t *vm, njs_par
njs_variable_t *
-njs_variable_get(njs_vm_t *vm, njs_parser_node_t *node)
+njs_variable_resolve(njs_vm_t *vm, njs_parser_node_t *node)
{
nxt_int_t ret;
nxt_uint_t scope_index;
@@ -294,7 +294,7 @@ njs_variable_get(njs_vm_t *vm, njs_parse
vr = &node->u.reference;
- ret = njs_variable_find(vm, node->scope, vr);
+ ret = njs_variable_reference_resolve(vm, vr, node->scope);
if (nxt_slow_path(ret != NXT_OK)) {
goto not_found;
@@ -390,8 +390,8 @@ not_found:
static njs_ret_t
-njs_variable_find(njs_vm_t *vm, njs_parser_scope_t *node_scope,
- njs_variable_reference_t *vr)
+njs_variable_reference_resolve(njs_vm_t *vm, njs_variable_reference_t *vr,
+ njs_parser_scope_t *node_scope)
{
nxt_lvlhsh_query_t lhq;
njs_parser_scope_t *scope, *parent, *previous;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment