]> granicus.if.org Git - php/commitdiff
Clean up JSON parser
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 19 Sep 2019 16:29:13 +0000 (18:29 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Thu, 19 Sep 2019 19:00:22 +0000 (21:00 +0200)
Don't use <value> type for JSON tokens that don't have a value
and remove the errlex productions -- we're going to get an
unexpected token error anyway, there's no need to handle these
explicitly.

This also removes the awkward workarounds for the unused value
warnings.

ext/json/json_parser.y

index ff9e50362a881d943b15de06041a3c5c3e26532c..ba7311c963763e1d3d1a82662a30b0e78c72a386 100644 (file)
@@ -32,10 +32,6 @@ int json_yydebug = 1;
 #define YYFREE free
 #endif
 
-#define PHP_JSON_USE(uv) ((void) (uv))
-#define PHP_JSON_USE_1(uvr, uv1) PHP_JSON_USE(uvr); PHP_JSON_USE(uv1)
-#define PHP_JSON_USE_2(uvr, uv1, uv2) PHP_JSON_USE(uvr); PHP_JSON_USE(uv1); PHP_JSON_USE(uv2)
-
 #define PHP_JSON_DEPTH_DEC --parser->depth
 #define PHP_JSON_DEPTH_INC \
        if (parser->max_depth && parser->depth >= parser->max_depth) { \
@@ -67,10 +63,10 @@ int json_yydebug = 1;
 %token <value> PHP_JSON_T_DOUBLE
 %token <value> PHP_JSON_T_STRING
 %token <value> PHP_JSON_T_ESTRING
-%token <value> PHP_JSON_T_EOI
-%token <value> PHP_JSON_T_ERROR
+%token PHP_JSON_T_EOI
+%token PHP_JSON_T_ERROR
 
-%type <value> start object key value array errlex
+%type <value> start object key value array
 %type <value> members member elements element
 %type <pair> pair
 
@@ -90,11 +86,7 @@ start:
                        {
                                ZVAL_COPY_VALUE(&$$, &$1);
                                ZVAL_COPY_VALUE(parser->return_value, &$1);
-                               PHP_JSON_USE($2); YYACCEPT;
-                       }
-       |       value errlex
-                       {
-                               PHP_JSON_USE_2($$, $1, $2);
+                               YYACCEPT;
                        }
 ;
 
@@ -148,10 +140,6 @@ member:
                                }
                                ZVAL_COPY_VALUE(&$$, &$1);
                        }
-       |       member errlex
-                       {
-                               PHP_JSON_USE_2($$, $1, $2);
-                       }
 ;
 
 pair:
@@ -160,10 +148,6 @@ pair:
                                $$.key = Z_STR($1);
                                ZVAL_COPY_VALUE(&$$.val, &$3);
                        }
-       |       key errlex
-                       {
-                               PHP_JSON_USE_2($$, $1, $2);
-                       }
 ;
 
 array:
@@ -212,10 +196,6 @@ element:
                                parser->methods.array_append(parser, &$1, &$3);
                                ZVAL_COPY_VALUE(&$$, &$1);
                        }
-       |       element errlex
-                       {
-                               PHP_JSON_USE_2($$, $1, $2);
-                       }
 ;
 
 key:
@@ -233,15 +213,6 @@ value:
        |       PHP_JSON_T_NUL
        |       PHP_JSON_T_TRUE
        |       PHP_JSON_T_FALSE
-       |       errlex
-;
-
-errlex:
-               PHP_JSON_T_ERROR
-                       {
-                               PHP_JSON_USE_1($$, $1);
-                               YYERROR;
-                       }
 ;
 
 %% /* Functions */