[njs] njs_parser_is_lvalue().

Igor Sysoev igor at sysoev.ru
Thu Aug 4 13:06:17 UTC 2016


details:   http://hg.nginx.org/njs/rev/f171ddad457e
branches:  
changeset: 138:f171ddad457e
user:      Igor Sysoev <igor at sysoev.ru>
date:      Thu Aug 04 14:43:20 2016 +0300
description:
njs_parser_is_lvalue().

diffstat:

 njs/njs_parser.h            |   7 ++-----
 njs/njs_parser_expression.c |  12 +++---------
 2 files changed, 5 insertions(+), 14 deletions(-)

diffs (53 lines):

diff -r e4f1fda52fe8 -r f171ddad457e njs/njs_parser.h
--- a/njs/njs_parser.h	Tue Jul 26 16:25:58 2016 +0300
+++ b/njs/njs_parser.h	Thu Aug 04 14:43:20 2016 +0300
@@ -213,11 +213,8 @@ typedef enum {
 } njs_variable_node_state_t;
 
 
-typedef enum {
-    NJS_LVALUE_NONE = 0,
-    NJS_LVALUE_ENABLED,
-    NJS_LVALUE_ASSIGNED,
-} njs_lvalue_state_t;
+#define njs_parser_is_lvalue(node)                                            \
+    ((node)->token == NJS_TOKEN_NAME || (node)->token == NJS_TOKEN_PROPERTY)
 
 
 typedef struct njs_parser_node_s    njs_parser_node_t;
diff -r e4f1fda52fe8 -r f171ddad457e njs/njs_parser_expression.c
--- a/njs/njs_parser_expression.c	Tue Jul 26 16:25:58 2016 +0300
+++ b/njs/njs_parser_expression.c	Thu Aug 04 14:43:20 2016 +0300
@@ -437,9 +437,7 @@ njs_parser_assignment_expression(njs_vm_
 
         node = parser->node;
 
-        if (parser->node->token != NJS_TOKEN_NAME
-            && parser->node->token != NJS_TOKEN_PROPERTY)
-        {
+        if (!njs_parser_is_lvalue(parser->node)) {
             return njs_parser_invalid_lvalue(vm, parser, "assignment");
         }
 
@@ -811,9 +809,7 @@ njs_parser_inc_dec_expression(njs_vm_t *
         return next;
     }
 
-    if (parser->node->token != NJS_TOKEN_NAME
-        && parser->node->token != NJS_TOKEN_PROPERTY)
-    {
+    if (!njs_parser_is_lvalue(parser->node)) {
         return njs_parser_invalid_lvalue(vm, parser, "prefix operation");
     }
 
@@ -865,9 +861,7 @@ njs_parser_post_inc_dec_expression(njs_v
         return token;
     }
 
-    if (parser->node->token != NJS_TOKEN_NAME
-        && parser->node->token != NJS_TOKEN_PROPERTY)
-    {
+    if (!njs_parser_is_lvalue(parser->node)) {
         return njs_parser_invalid_lvalue(vm, parser, "postfix operation");
     }
 



More information about the nginx-devel mailing list