Coverage Report

Created: 2026-10-28 06:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/php-src/ext/json/json_parser.tab.c
Line
Count
Source
1
/* A Bison parser, made by GNU Bison 3.8.2.  */
2
3
/* Bison implementation for Yacc-like parsers in C
4
5
   Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation,
6
   Inc.
7
8
   This program is free software: you can redistribute it and/or modify
9
   it under the terms of the GNU General Public License as published by
10
   the Free Software Foundation, either version 3 of the License, or
11
   (at your option) any later version.
12
13
   This program is distributed in the hope that it will be useful,
14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
   GNU General Public License for more details.
17
18
   You should have received a copy of the GNU General Public License
19
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
20
21
/* As a special exception, you may create a larger work that contains
22
   part or all of the Bison parser skeleton and distribute that work
23
   under terms of your choice, so long as that work isn't itself a
24
   parser generator using the skeleton or a modified version thereof
25
   as a parser skeleton.  Alternatively, if you modify or redistribute
26
   the parser skeleton itself, you may (at your option) remove this
27
   special exception, which will cause the skeleton and the resulting
28
   Bison output files to be licensed under the GNU General Public
29
   License without this special exception.
30
31
   This special exception was added by the Free Software Foundation in
32
   version 2.2 of Bison.  */
33
34
/* C LALR(1) parser skeleton written by Richard Stallman, by
35
   simplifying the original so-called "semantic" parser.  */
36
37
/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
38
   especially those whose name start with YY_ or yy_.  They are
39
   private implementation details that can be changed or removed.  */
40
41
/* All symbols defined below should begin with yy or YY, to avoid
42
   infringing on user name space.  This should be done even for local
43
   variables, as they might otherwise be expanded by user macros.
44
   There are some unavoidable exceptions within include files to
45
   define necessary library symbols; they are noted "INFRINGES ON
46
   USER NAME SPACE" below.  */
47
48
/* Identify Bison output, and Bison version.  */
49
#define YYBISON 30802
50
51
/* Bison version string.  */
52
#define YYBISON_VERSION "3.8.2"
53
54
/* Skeleton name.  */
55
#define YYSKELETON_NAME "yacc.c"
56
57
/* Pure parsers.  */
58
#define YYPURE 2
59
60
/* Push parsers.  */
61
#define YYPUSH 0
62
63
/* Pull parsers.  */
64
#define YYPULL 1
65
66
/* "%code top" blocks.  */
67
68
/*
69
  +----------------------------------------------------------------------+
70
  | Copyright © The PHP Group and Contributors.                          |
71
  +----------------------------------------------------------------------+
72
  | This source file is subject to the Modified BSD License that is      |
73
  | bundled with this package in the file LICENSE, and is available      |
74
  | through the World Wide Web at <https://www.php.net/license/>.        |
75
  |                                                                      |
76
  | SPDX-License-Identifier: BSD-3-Clause                                |
77
  +----------------------------------------------------------------------+
78
  | Author: Jakub Zelenka <bukka@php.net>                                |
79
  +----------------------------------------------------------------------+
80
*/
81
82
#include "php.h"
83
#include "php_json.h"
84
#include "php_json_parser.h"
85
86
#define YYDEBUG 0
87
88
#if YYDEBUG
89
int json_yydebug = 1;
90
#endif
91
92
#ifdef _MSC_VER
93
#define YYMALLOC malloc
94
#define YYFREE free
95
#endif
96
97
25.4M
#define PHP_JSON_DEPTH_DEC --parser->depth
98
#define PHP_JSON_DEPTH_INC \
99
25.5M
  if (parser->max_depth && parser->depth >= parser->max_depth) { \
100
58
    parser->scanner.errcode = PHP_JSON_ERROR_DEPTH; \
101
58
    YYERROR; \
102
58
  } \
103
25.5M
  ++parser->depth
104
105
106
/* Substitute the type names.  */
107
467k
#define YYSTYPE         PHP_JSON_YYSTYPE
108
/* Substitute the variable and function names.  */
109
#define yyparse         php_json_yyparse
110
121M
#define yylex           php_json_yylex
111
59.2k
#define yyerror         php_json_yyerror
112
#define yydebug         php_json_yydebug
113
69.2k
#define yynerrs         php_json_yynerrs
114
115
116
# ifndef YY_CAST
117
#  ifdef __cplusplus
118
#   define YY_CAST(Type, Val) static_cast<Type> (Val)
119
#   define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
120
#  else
121
467M
#   define YY_CAST(Type, Val) ((Type) (Val))
122
#   define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
123
#  endif
124
# endif
125
# ifndef YY_NULLPTR
126
#  if defined __cplusplus
127
#   if 201103L <= __cplusplus
128
#    define YY_NULLPTR nullptr
129
#   else
130
#    define YY_NULLPTR 0
131
#   endif
132
#  else
133
#   define YY_NULLPTR ((void*)0)
134
#  endif
135
# endif
136
137
#include "json_parser.tab.h"
138
/* Symbol kind.  */
139
enum yysymbol_kind_t
140
{
141
  YYSYMBOL_YYEMPTY = -2,
142
  YYSYMBOL_YYEOF = 0,                      /* "end of file"  */
143
  YYSYMBOL_YYerror = 1,                    /* error  */
144
  YYSYMBOL_YYUNDEF = 2,                    /* "invalid token"  */
145
  YYSYMBOL_PHP_JSON_T_NUL = 3,             /* PHP_JSON_T_NUL  */
146
  YYSYMBOL_PHP_JSON_T_TRUE = 4,            /* PHP_JSON_T_TRUE  */
147
  YYSYMBOL_PHP_JSON_T_FALSE = 5,           /* PHP_JSON_T_FALSE  */
148
  YYSYMBOL_PHP_JSON_T_INT = 6,             /* PHP_JSON_T_INT  */
149
  YYSYMBOL_PHP_JSON_T_DOUBLE = 7,          /* PHP_JSON_T_DOUBLE  */
150
  YYSYMBOL_PHP_JSON_T_STRING = 8,          /* PHP_JSON_T_STRING  */
151
  YYSYMBOL_PHP_JSON_T_ESTRING = 9,         /* PHP_JSON_T_ESTRING  */
152
  YYSYMBOL_PHP_JSON_T_EOI = 10,            /* PHP_JSON_T_EOI  */
153
  YYSYMBOL_PHP_JSON_T_ERROR = 11,          /* PHP_JSON_T_ERROR  */
154
  YYSYMBOL_12_ = 12,                       /* '{'  */
155
  YYSYMBOL_13_ = 13,                       /* '}'  */
156
  YYSYMBOL_14_ = 14,                       /* ']'  */
157
  YYSYMBOL_15_ = 15,                       /* ':'  */
158
  YYSYMBOL_16_ = 16,                       /* ','  */
159
  YYSYMBOL_17_ = 17,                       /* '['  */
160
  YYSYMBOL_YYACCEPT = 18,                  /* $accept  */
161
  YYSYMBOL_start = 19,                     /* start  */
162
  YYSYMBOL_object = 20,                    /* object  */
163
  YYSYMBOL_21_1 = 21,                      /* $@1  */
164
  YYSYMBOL_object_end = 22,                /* object_end  */
165
  YYSYMBOL_members = 23,                   /* members  */
166
  YYSYMBOL_member = 24,                    /* member  */
167
  YYSYMBOL_array = 25,                     /* array  */
168
  YYSYMBOL_26_2 = 26,                      /* $@2  */
169
  YYSYMBOL_array_end = 27,                 /* array_end  */
170
  YYSYMBOL_elements = 28,                  /* elements  */
171
  YYSYMBOL_element = 29,                   /* element  */
172
  YYSYMBOL_key = 30,                       /* key  */
173
  YYSYMBOL_value = 31                      /* value  */
174
};
175
typedef enum yysymbol_kind_t yysymbol_kind_t;
176
177
178
179
/* Unqualified %code blocks.  */
180
181
static int php_json_yylex(union YYSTYPE *value, php_json_parser *parser);
182
static void php_json_yyerror(php_json_parser *parser, char const *msg);
183
static int php_json_parser_array_create(php_json_parser *parser, zval *array);
184
static int php_json_parser_object_create(php_json_parser *parser, zval *array);
185
186
187
188
#ifdef short
189
# undef short
190
#endif
191
192
/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
193
   <limits.h> and (if available) <stdint.h> are included
194
   so that the code can choose integer types of a good width.  */
195
196
#ifndef __PTRDIFF_MAX__
197
# include <limits.h> /* INFRINGES ON USER NAME SPACE */
198
# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
199
#  include <stdint.h> /* INFRINGES ON USER NAME SPACE */
200
#  define YY_STDINT_H
201
# endif
202
#endif
203
204
/* Narrow types that promote to a signed type and that can represent a
205
   signed or unsigned integer of at least N bits.  In tables they can
206
   save space and decrease cache pressure.  Promoting to a signed type
207
   helps avoid bugs in integer arithmetic.  */
208
209
#ifdef __INT_LEAST8_MAX__
210
typedef __INT_LEAST8_TYPE__ yytype_int8;
211
#elif defined YY_STDINT_H
212
typedef int_least8_t yytype_int8;
213
#else
214
typedef signed char yytype_int8;
215
#endif
216
217
#ifdef __INT_LEAST16_MAX__
218
typedef __INT_LEAST16_TYPE__ yytype_int16;
219
#elif defined YY_STDINT_H
220
typedef int_least16_t yytype_int16;
221
#else
222
typedef short yytype_int16;
223
#endif
224
225
/* Work around bug in HP-UX 11.23, which defines these macros
226
   incorrectly for preprocessor constants.  This workaround can likely
227
   be removed in 2023, as HPE has promised support for HP-UX 11.23
228
   (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of
229
   <https://h20195.www2.hpe.com/V2/getpdf.aspx/4AA4-7673ENW.pdf>.  */
230
#ifdef __hpux
231
# undef UINT_LEAST8_MAX
232
# undef UINT_LEAST16_MAX
233
# define UINT_LEAST8_MAX 255
234
# define UINT_LEAST16_MAX 65535
235
#endif
236
237
#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
238
typedef __UINT_LEAST8_TYPE__ yytype_uint8;
239
#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
240
       && UINT_LEAST8_MAX <= INT_MAX)
241
typedef uint_least8_t yytype_uint8;
242
#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
243
typedef unsigned char yytype_uint8;
244
#else
245
typedef short yytype_uint8;
246
#endif
247
248
#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
249
typedef __UINT_LEAST16_TYPE__ yytype_uint16;
250
#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \
251
       && UINT_LEAST16_MAX <= INT_MAX)
252
typedef uint_least16_t yytype_uint16;
253
#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
254
typedef unsigned short yytype_uint16;
255
#else
256
typedef int yytype_uint16;
257
#endif
258
259
#ifndef YYPTRDIFF_T
260
# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
261
93.5k
#  define YYPTRDIFF_T __PTRDIFF_TYPE__
262
#  define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
263
# elif defined PTRDIFF_MAX
264
#  ifndef ptrdiff_t
265
#   include <stddef.h> /* INFRINGES ON USER NAME SPACE */
266
#  endif
267
#  define YYPTRDIFF_T ptrdiff_t
268
#  define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
269
# else
270
#  define YYPTRDIFF_T long
271
#  define YYPTRDIFF_MAXIMUM LONG_MAX
272
# endif
273
#endif
274
275
#ifndef YYSIZE_T
276
# ifdef __SIZE_TYPE__
277
#  define YYSIZE_T __SIZE_TYPE__
278
# elif defined size_t
279
#  define YYSIZE_T size_t
280
# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
281
#  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
282
#  define YYSIZE_T size_t
283
# else
284
#  define YYSIZE_T unsigned
285
# endif
286
#endif
287
288
#define YYSIZE_MAXIMUM                                  \
289
  YY_CAST (YYPTRDIFF_T,                                 \
290
           (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1)  \
291
            ? YYPTRDIFF_MAXIMUM                         \
292
            : YY_CAST (YYSIZE_T, -1)))
293
294
0
#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
295
296
297
/* Stored state numbers (used for stacks). */
298
typedef yytype_int8 yy_state_t;
299
300
/* State numbers in computations.  */
301
typedef int yy_state_fast_t;
302
303
#ifndef YY_
304
# if defined YYENABLE_NLS && YYENABLE_NLS
305
#  if ENABLE_NLS
306
#   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
307
#   define YY_(Msgid) dgettext ("bison-runtime", Msgid)
308
#  endif
309
# endif
310
# ifndef YY_
311
59.2k
#  define YY_(Msgid) Msgid
312
# endif
313
#endif
314
315
316
#ifndef YY_ATTRIBUTE_PURE
317
# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
318
#  define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
319
# else
320
#  define YY_ATTRIBUTE_PURE
321
# endif
322
#endif
323
324
#ifndef YY_ATTRIBUTE_UNUSED
325
# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
326
#  define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
327
# else
328
#  define YY_ATTRIBUTE_UNUSED
329
# endif
330
#endif
331
332
/* Suppress unused-variable warnings by "using" E.  */
333
#if ! defined lint || defined __GNUC__
334
526k
# define YY_USE(E) ((void) (E))
335
#else
336
# define YY_USE(E) /* empty */
337
#endif
338
339
/* Suppress an incorrect diagnostic about yylval being uninitialized.  */
340
#if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__
341
# if __GNUC__ * 100 + __GNUC_MINOR__ < 407
342
#  define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN                           \
343
    _Pragma ("GCC diagnostic push")                                     \
344
    _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")
345
# else
346
#  define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN                           \
347
    _Pragma ("GCC diagnostic push")                                     \
348
    _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")              \
349
    _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
350
# endif
351
# define YY_IGNORE_MAYBE_UNINITIALIZED_END      \
352
    _Pragma ("GCC diagnostic pop")
353
#else
354
187k
# define YY_INITIAL_VALUE(Value) Value
355
#endif
356
#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
357
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
358
# define YY_IGNORE_MAYBE_UNINITIALIZED_END
359
#endif
360
#ifndef YY_INITIAL_VALUE
361
# define YY_INITIAL_VALUE(Value) /* Nothing. */
362
#endif
363
364
#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
365
# define YY_IGNORE_USELESS_CAST_BEGIN                          \
366
    _Pragma ("GCC diagnostic push")                            \
367
    _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
368
# define YY_IGNORE_USELESS_CAST_END            \
369
    _Pragma ("GCC diagnostic pop")
370
#endif
371
#ifndef YY_IGNORE_USELESS_CAST_BEGIN
372
# define YY_IGNORE_USELESS_CAST_BEGIN
373
# define YY_IGNORE_USELESS_CAST_END
374
#endif
375
376
377
319M
#define YY_ASSERT(E) ((void) (0 && (E)))
378
379
#if !defined yyoverflow
380
381
/* The parser invokes alloca or malloc; define the necessary symbols.  */
382
383
# ifdef YYSTACK_USE_ALLOCA
384
#  if YYSTACK_USE_ALLOCA
385
#   ifdef __GNUC__
386
#    define YYSTACK_ALLOC __builtin_alloca
387
#   elif defined __BUILTIN_VA_ARG_INCR
388
#    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
389
#   elif defined _AIX
390
#    define YYSTACK_ALLOC __alloca
391
#   elif defined _MSC_VER
392
#    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
393
#    define alloca _alloca
394
#   else
395
#    define YYSTACK_ALLOC alloca
396
#    if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
397
#     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
398
      /* Use EXIT_SUCCESS as a witness for stdlib.h.  */
399
#     ifndef EXIT_SUCCESS
400
#      define EXIT_SUCCESS 0
401
#     endif
402
#    endif
403
#   endif
404
#  endif
405
# endif
406
407
# ifdef YYSTACK_ALLOC
408
   /* Pacify GCC's 'empty if-body' warning.  */
409
#  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
410
#  ifndef YYSTACK_ALLOC_MAXIMUM
411
    /* The OS might guarantee only one guard page at the bottom of the stack,
412
       and a page size can be as small as 4096 bytes.  So we cannot safely
413
       invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
414
       to allow for a few compiler-allocated temporary stack slots.  */
415
#   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
416
#  endif
417
# else
418
#  define YYSTACK_ALLOC YYMALLOC
419
0
#  define YYSTACK_FREE YYFREE
420
#  ifndef YYSTACK_ALLOC_MAXIMUM
421
#   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
422
#  endif
423
#  if (defined __cplusplus && ! defined EXIT_SUCCESS \
424
       && ! ((defined YYMALLOC || defined malloc) \
425
             && (defined YYFREE || defined free)))
426
#   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
427
#   ifndef EXIT_SUCCESS
428
#    define EXIT_SUCCESS 0
429
#   endif
430
#  endif
431
#  ifndef YYMALLOC
432
#   define YYMALLOC malloc
433
#   if ! defined malloc && ! defined EXIT_SUCCESS
434
void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
435
#   endif
436
#  endif
437
#  ifndef YYFREE
438
0
#   define YYFREE free
439
#   if ! defined free && ! defined EXIT_SUCCESS
440
void free (void *); /* INFRINGES ON USER NAME SPACE */
441
#   endif
442
#  endif
443
# endif
444
#endif /* !defined yyoverflow */
445
446
#if (! defined yyoverflow \
447
     && (! defined __cplusplus \
448
         || (defined PHP_JSON_YYSTYPE_IS_TRIVIAL && PHP_JSON_YYSTYPE_IS_TRIVIAL)))
449
450
/* A type that is properly aligned for any stack member.  */
451
union yyalloc
452
{
453
  yy_state_t yyss_alloc;
454
  YYSTYPE yyvs_alloc;
455
};
456
457
/* The size of the maximum gap between one aligned stack and the next.  */
458
0
# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1)
459
460
/* The size of an array large to enough to hold all stacks, each with
461
   N elements.  */
462
# define YYSTACK_BYTES(N) \
463
     ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \
464
      + YYSTACK_GAP_MAXIMUM)
465
466
# define YYCOPY_NEEDED 1
467
468
/* Relocate STACK from its old location to the new one.  The
469
   local variables YYSIZE and YYSTACKSIZE give the old and new number of
470
   elements in the stack, and YYPTR gives the new location of the
471
   stack.  Advance YYPTR to a properly aligned location for the next
472
   stack.  */
473
# define YYSTACK_RELOCATE(Stack_alloc, Stack)                           \
474
0
    do                                                                  \
475
0
      {                                                                 \
476
0
        YYPTRDIFF_T yynewbytes;                                         \
477
0
        YYCOPY (&yyptr->Stack_alloc, Stack, yysize);                    \
478
0
        Stack = &yyptr->Stack_alloc;                                    \
479
0
        yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
480
0
        yyptr += yynewbytes / YYSIZEOF (*yyptr);                        \
481
0
      }                                                                 \
482
0
    while (0)
483
484
#endif
485
486
#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
487
/* Copy COUNT objects from SRC to DST.  The source and destination do
488
   not overlap.  */
489
# ifndef YYCOPY
490
#  if defined __GNUC__ && 1 < __GNUC__
491
#   define YYCOPY(Dst, Src, Count) \
492
0
      __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
493
#  else
494
#   define YYCOPY(Dst, Src, Count)              \
495
      do                                        \
496
        {                                       \
497
          YYPTRDIFF_T yyi;                      \
498
          for (yyi = 0; yyi < (Count); yyi++)   \
499
            (Dst)[yyi] = (Src)[yyi];            \
500
        }                                       \
501
      while (0)
502
#  endif
503
# endif
504
#endif /* !YYCOPY_NEEDED */
505
506
/* YYFINAL -- State number of the termination state.  */
507
319M
#define YYFINAL  16
508
/* YYLAST -- Last index in YYTABLE.  */
509
444M
#define YYLAST   26
510
511
/* YYNTOKENS -- Number of terminals.  */
512
197M
#define YYNTOKENS  18
513
/* YYNNTS -- Number of nonterminals.  */
514
#define YYNNTS  14
515
/* YYNRULES -- Number of rules.  */
516
#define YYNRULES  29
517
/* YYNSTATES -- Number of states.  */
518
#define YYNSTATES  40
519
520
/* YYMAXUTOK -- Last valid token kind.  */
521
147M
#define YYMAXUTOK   266
522
523
524
/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
525
   as returned by yylex, with out-of-bounds checking.  */
526
#define YYTRANSLATE(YYX)                                \
527
147M
  (0 <= (YYX) && (YYX) <= YYMAXUTOK                     \
528
147M
   ? YY_CAST (yysymbol_kind_t, yytranslate[YYX])        \
529
147M
   : YYSYMBOL_YYUNDEF)
530
531
/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
532
   as returned by yylex.  */
533
static const yytype_int8 yytranslate[] =
534
{
535
       0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
536
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
537
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
538
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
539
       2,     2,     2,     2,    16,     2,     2,     2,     2,     2,
540
       2,     2,     2,     2,     2,     2,     2,     2,    15,     2,
541
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
542
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
543
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
544
       2,    17,     2,    14,     2,     2,     2,     2,     2,     2,
545
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
546
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
547
       2,     2,     2,    12,     2,    13,     2,     2,     2,     2,
548
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
549
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
550
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
551
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
552
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
553
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
554
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
555
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
556
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
557
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
558
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
559
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
560
       2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
561
       5,     6,     7,     8,     9,    10,    11
562
};
563
564
#if PHP_JSON_YYDEBUG
565
/* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */
566
static const yytype_uint8 yyrline[] =
567
{
568
       0,    76,    76,    87,    86,   104,   105,   113,   123,   127,
569
     136,   147,   146,   164,   165,   173,   183,   187,   196,   206,
570
     207,   211,   212,   213,   214,   215,   216,   217,   218,   219
571
};
572
#endif
573
574
/** Accessing symbol of state STATE.  */
575
204k
#define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State])
576
577
#if PHP_JSON_YYDEBUG || 0
578
/* The user-facing name of the symbol whose (internal) number is
579
   YYSYMBOL.  No bounds checking.  */
580
static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED;
581
582
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
583
   First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
584
static const char *const yytname[] =
585
{
586
  "\"end of file\"", "error", "\"invalid token\"", "PHP_JSON_T_NUL",
587
  "PHP_JSON_T_TRUE", "PHP_JSON_T_FALSE", "PHP_JSON_T_INT",
588
  "PHP_JSON_T_DOUBLE", "PHP_JSON_T_STRING", "PHP_JSON_T_ESTRING",
589
  "PHP_JSON_T_EOI", "PHP_JSON_T_ERROR", "'{'", "'}'", "']'", "':'", "','",
590
  "'['", "$accept", "start", "object", "$@1", "object_end", "members",
591
  "member", "array", "$@2", "array_end", "elements", "element", "key",
592
  "value", YY_NULLPTR
593
};
594
595
static const char *
596
yysymbol_name (yysymbol_kind_t yysymbol)
597
{
598
  return yytname[yysymbol];
599
}
600
#endif
601
602
319M
#define YYPACT_NINF (-16)
603
604
#define yypact_value_is_default(Yyn) \
605
319M
  ((Yyn) == YYPACT_NINF)
606
607
#define YYTABLE_NINF (-1)
608
609
#define yytable_value_is_error(Yyn) \
610
0
  0
611
612
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
613
   STATE-NUM.  */
614
static const yytype_int8 yypact[] =
615
{
616
      -1,   -16,   -16,   -16,   -16,   -16,   -16,   -16,   -16,   -16,
617
      12,   -16,   -16,    -9,     1,    -1,   -16,   -16,   -16,   -16,
618
       0,     5,     7,     4,     8,   -16,   -16,   -16,   -16,     1,
619
      -1,   -16,   -16,   -16,    -1,    10,   -16,   -16,    -1,   -16
620
};
621
622
/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
623
   Performed when YYTABLE does not specify something else to do.  Zero
624
   means the default is an error.  */
625
static const yytype_int8 yydefact[] =
626
{
627
       0,    27,    28,    29,    25,    26,    23,    24,     3,    11,
628
       0,    21,    22,     0,     7,    15,     1,     2,    19,    20,
629
       0,     8,     0,     0,    16,    17,     5,     6,     4,     0,
630
       0,    14,    13,    12,     0,     0,     9,    18,     0,    10
631
};
632
633
/* YYPGOTO[NTERM-NUM].  */
634
static const yytype_int8 yypgoto[] =
635
{
636
     -16,   -16,   -16,   -16,   -16,   -16,   -16,   -16,   -16,   -16,
637
     -16,   -16,    -3,   -15
638
};
639
640
/* YYDEFGOTO[NTERM-NUM].  */
641
static const yytype_int8 yydefgoto[] =
642
{
643
       0,    10,    11,    14,    28,    20,    21,    12,    15,    33,
644
      23,    24,    22,    13
645
};
646
647
/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM.  If
648
   positive, shift that token.  If negative, reduce the rule whose
649
   number is the opposite.  If YYTABLE_NINF, syntax error.  */
650
static const yytype_int8 yytable[] =
651
{
652
      25,    17,     1,     2,     3,     4,     5,     6,     7,    18,
653
      19,     8,    16,    26,    27,    36,     9,    31,    32,    37,
654
       0,    29,    30,    39,    34,    38,    35
655
};
656
657
static const yytype_int8 yycheck[] =
658
{
659
      15,    10,     3,     4,     5,     6,     7,     8,     9,     8,
660
       9,    12,     0,    13,    14,    30,    17,    13,    14,    34,
661
      -1,    16,    15,    38,    16,    15,    29
662
};
663
664
/* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of
665
   state STATE-NUM.  */
666
static const yytype_int8 yystos[] =
667
{
668
       0,     3,     4,     5,     6,     7,     8,     9,    12,    17,
669
      19,    20,    25,    31,    21,    26,     0,    10,     8,     9,
670
      23,    24,    30,    28,    29,    31,    13,    14,    22,    16,
671
      15,    13,    14,    27,    16,    30,    31,    31,    15,    31
672
};
673
674
/* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM.  */
675
static const yytype_int8 yyr1[] =
676
{
677
       0,    18,    19,    21,    20,    22,    22,    23,    23,    24,
678
      24,    26,    25,    27,    27,    28,    28,    29,    29,    30,
679
      30,    31,    31,    31,    31,    31,    31,    31,    31,    31
680
};
681
682
/* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM.  */
683
static const yytype_int8 yyr2[] =
684
{
685
       0,     2,     2,     0,     4,     1,     1,     0,     1,     3,
686
       5,     0,     4,     1,     1,     0,     1,     1,     3,     1,
687
       1,     1,     1,     1,     1,     1,     1,     1,     1,     1
688
};
689
690
691
enum { YYENOMEM = -2 };
692
693
#define yyerrok         (yyerrstatus = 0)
694
#define yyclearin       (yychar = PHP_JSON_YYEMPTY)
695
696
24.3k
#define YYACCEPT        goto yyacceptlab
697
69.2k
#define YYABORT         goto yyabortlab
698
9.98k
#define YYERROR         goto yyerrorlab
699
0
#define YYNOMEM         goto yyexhaustedlab
700
701
702
#define YYRECOVERING()  (!!yyerrstatus)
703
704
#define YYBACKUP(Token, Value)                                    \
705
  do                                                              \
706
    if (yychar == PHP_JSON_YYEMPTY)                                        \
707
      {                                                           \
708
        yychar = (Token);                                         \
709
        yylval = (Value);                                         \
710
        YYPOPSTACK (yylen);                                       \
711
        yystate = *yyssp;                                         \
712
        goto yybackup;                                            \
713
      }                                                           \
714
    else                                                          \
715
      {                                                           \
716
        yyerror (parser, YY_("syntax error: cannot back up")); \
717
        YYERROR;                                                  \
718
      }                                                           \
719
  while (0)
720
721
/* Backward compatibility with an undocumented macro.
722
   Use PHP_JSON_YYerror or PHP_JSON_YYUNDEF. */
723
#define YYERRCODE PHP_JSON_YYUNDEF
724
725
726
/* Enable debugging if requested.  */
727
#if PHP_JSON_YYDEBUG
728
729
# ifndef YYFPRINTF
730
#  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
731
#  define YYFPRINTF fprintf
732
# endif
733
734
# define YYDPRINTF(Args)                        \
735
do {                                            \
736
  if (yydebug)                                  \
737
    YYFPRINTF Args;                             \
738
} while (0)
739
740
741
742
743
# define YY_SYMBOL_PRINT(Title, Kind, Value, Location)                    \
744
do {                                                                      \
745
  if (yydebug)                                                            \
746
    {                                                                     \
747
      YYFPRINTF (stderr, "%s ", Title);                                   \
748
      yy_symbol_print (stderr,                                            \
749
                  Kind, Value, parser); \
750
      YYFPRINTF (stderr, "\n");                                           \
751
    }                                                                     \
752
} while (0)
753
754
755
/*-----------------------------------.
756
| Print this symbol's value on YYO.  |
757
`-----------------------------------*/
758
759
static void
760
yy_symbol_value_print (FILE *yyo,
761
                       yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, php_json_parser *parser)
762
{
763
  FILE *yyoutput = yyo;
764
  YY_USE (yyoutput);
765
  YY_USE (parser);
766
  if (!yyvaluep)
767
    return;
768
  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
769
  YY_USE (yykind);
770
  YY_IGNORE_MAYBE_UNINITIALIZED_END
771
}
772
773
774
/*---------------------------.
775
| Print this symbol on YYO.  |
776
`---------------------------*/
777
778
static void
779
yy_symbol_print (FILE *yyo,
780
                 yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, php_json_parser *parser)
781
{
782
  YYFPRINTF (yyo, "%s %s (",
783
             yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind));
784
785
  yy_symbol_value_print (yyo, yykind, yyvaluep, parser);
786
  YYFPRINTF (yyo, ")");
787
}
788
789
/*------------------------------------------------------------------.
790
| yy_stack_print -- Print the state stack from its BOTTOM up to its |
791
| TOP (included).                                                   |
792
`------------------------------------------------------------------*/
793
794
static void
795
yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
796
{
797
  YYFPRINTF (stderr, "Stack now");
798
  for (; yybottom <= yytop; yybottom++)
799
    {
800
      int yybot = *yybottom;
801
      YYFPRINTF (stderr, " %d", yybot);
802
    }
803
  YYFPRINTF (stderr, "\n");
804
}
805
806
# define YY_STACK_PRINT(Bottom, Top)                            \
807
do {                                                            \
808
  if (yydebug)                                                  \
809
    yy_stack_print ((Bottom), (Top));                           \
810
} while (0)
811
812
813
/*------------------------------------------------.
814
| Report that the YYRULE is going to be reduced.  |
815
`------------------------------------------------*/
816
817
static void
818
yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp,
819
                 int yyrule, php_json_parser *parser)
820
{
821
  int yylno = yyrline[yyrule];
822
  int yynrhs = yyr2[yyrule];
823
  int yyi;
824
  YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n",
825
             yyrule - 1, yylno);
826
  /* The symbols being reduced.  */
827
  for (yyi = 0; yyi < yynrhs; yyi++)
828
    {
829
      YYFPRINTF (stderr, "   $%d = ", yyi + 1);
830
      yy_symbol_print (stderr,
831
                       YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]),
832
                       &yyvsp[(yyi + 1) - (yynrhs)], parser);
833
      YYFPRINTF (stderr, "\n");
834
    }
835
}
836
837
# define YY_REDUCE_PRINT(Rule)          \
838
do {                                    \
839
  if (yydebug)                          \
840
    yy_reduce_print (yyssp, yyvsp, Rule, parser); \
841
} while (0)
842
843
/* Nonzero means print parse trace.  It is left uninitialized so that
844
   multiple parsers can coexist.  */
845
int yydebug;
846
#else /* !PHP_JSON_YYDEBUG */
847
441M
# define YYDPRINTF(Args) ((void) 0)
848
# define YY_SYMBOL_PRINT(Title, Kind, Value, Location)
849
# define YY_STACK_PRINT(Bottom, Top)
850
# define YY_REDUCE_PRINT(Rule)
851
#endif /* !PHP_JSON_YYDEBUG */
852
853
854
/* YYINITDEPTH -- initial size of the parser's stacks.  */
855
#ifndef YYINITDEPTH
856
93.5k
# define YYINITDEPTH 200
857
#endif
858
859
/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
860
   if the built-in stack extension method is used).
861
862
   Do not make this value too large; the results are undefined if
863
   YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
864
   evaluated with infinite-precision integer arithmetic.  */
865
866
#ifndef YYMAXDEPTH
867
0
# define YYMAXDEPTH 10000
868
#endif
869
870
871
872
873
874
875
/*-----------------------------------------------.
876
| Release the memory associated to this symbol.  |
877
`-----------------------------------------------*/
878
879
static void
880
yydestruct (const char *yymsg,
881
            yysymbol_kind_t yykind, YYSTYPE *yyvaluep, php_json_parser *parser)
882
263k
{
883
263k
  YY_USE (yyvaluep);
884
263k
  YY_USE (parser);
885
263k
  if (!yymsg)
886
0
    yymsg = "Deleting";
887
263k
  YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);
888
889
263k
  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
890
263k
  switch (yykind)
891
263k
    {
892
59
    case YYSYMBOL_PHP_JSON_T_NUL: /* PHP_JSON_T_NUL  */
893
59
            { zval_ptr_dtor_nogc(&((*yyvaluep).value)); }
894
59
        break;
895
896
67
    case YYSYMBOL_PHP_JSON_T_TRUE: /* PHP_JSON_T_TRUE  */
897
67
            { zval_ptr_dtor_nogc(&((*yyvaluep).value)); }
898
67
        break;
899
900
59
    case YYSYMBOL_PHP_JSON_T_FALSE: /* PHP_JSON_T_FALSE  */
901
59
            { zval_ptr_dtor_nogc(&((*yyvaluep).value)); }
902
59
        break;
903
904
927
    case YYSYMBOL_PHP_JSON_T_INT: /* PHP_JSON_T_INT  */
905
927
            { zval_ptr_dtor_nogc(&((*yyvaluep).value)); }
906
927
        break;
907
908
7.47k
    case YYSYMBOL_PHP_JSON_T_DOUBLE: /* PHP_JSON_T_DOUBLE  */
909
7.47k
            { zval_ptr_dtor_nogc(&((*yyvaluep).value)); }
910
7.47k
        break;
911
912
1.95k
    case YYSYMBOL_PHP_JSON_T_STRING: /* PHP_JSON_T_STRING  */
913
1.95k
            { zval_ptr_dtor_nogc(&((*yyvaluep).value)); }
914
1.95k
        break;
915
916
163
    case YYSYMBOL_PHP_JSON_T_ESTRING: /* PHP_JSON_T_ESTRING  */
917
163
            { zval_ptr_dtor_nogc(&((*yyvaluep).value)); }
918
163
        break;
919
920
0
    case YYSYMBOL_start: /* start  */
921
0
            { zval_ptr_dtor_nogc(&((*yyvaluep).value)); }
922
0
        break;
923
924
0
    case YYSYMBOL_object: /* object  */
925
0
            { zval_ptr_dtor_nogc(&((*yyvaluep).value)); }
926
0
        break;
927
928
23.2k
    case YYSYMBOL_members: /* members  */
929
23.2k
            { zval_ptr_dtor_nogc(&((*yyvaluep).value)); }
930
23.2k
        break;
931
932
11.4k
    case YYSYMBOL_member: /* member  */
933
11.4k
            { zval_ptr_dtor_nogc(&((*yyvaluep).value)); }
934
11.4k
        break;
935
936
0
    case YYSYMBOL_array: /* array  */
937
0
            { zval_ptr_dtor_nogc(&((*yyvaluep).value)); }
938
0
        break;
939
940
4.98k
    case YYSYMBOL_elements: /* elements  */
941
4.98k
            { zval_ptr_dtor_nogc(&((*yyvaluep).value)); }
942
4.98k
        break;
943
944
4.76k
    case YYSYMBOL_element: /* element  */
945
4.76k
            { zval_ptr_dtor_nogc(&((*yyvaluep).value)); }
946
4.76k
        break;
947
948
9.90k
    case YYSYMBOL_key: /* key  */
949
9.90k
            { zval_ptr_dtor_nogc(&((*yyvaluep).value)); }
950
9.90k
        break;
951
952
4.71k
    case YYSYMBOL_value: /* value  */
953
4.71k
            { zval_ptr_dtor_nogc(&((*yyvaluep).value)); }
954
4.71k
        break;
955
956
193k
      default:
957
193k
        break;
958
263k
    }
959
263k
  YY_IGNORE_MAYBE_UNINITIALIZED_END
960
263k
}
961
962
963
964
965
966
967
/*----------.
968
| yyparse.  |
969
`----------*/
970
971
int
972
yyparse (php_json_parser *parser)
973
93.5k
{
974
/* Lookahead token kind.  */
975
93.5k
int yychar;
976
977
978
/* The semantic value of the lookahead symbol.  */
979
/* Default value used for initialization, for pacifying older GCCs
980
   or non-GCC compilers.  */
981
93.5k
YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
982
93.5k
YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
983
984
    /* Number of syntax errors so far.  */
985
93.5k
    int yynerrs = 0;
986
987
93.5k
    yy_state_fast_t yystate = 0;
988
    /* Number of tokens to shift before error messages enabled.  */
989
93.5k
    int yyerrstatus = 0;
990
991
    /* Refer to the stacks through separate pointers, to allow yyoverflow
992
       to reallocate them elsewhere.  */
993
994
    /* Their size.  */
995
93.5k
    YYPTRDIFF_T yystacksize = YYINITDEPTH;
996
997
    /* The state stack: array, bottom, top.  */
998
93.5k
    yy_state_t yyssa[YYINITDEPTH];
999
93.5k
    yy_state_t *yyss = yyssa;
1000
93.5k
    yy_state_t *yyssp = yyss;
1001
1002
    /* The semantic value stack: array, bottom, top.  */
1003
93.5k
    YYSTYPE yyvsa[YYINITDEPTH];
1004
93.5k
    YYSTYPE *yyvs = yyvsa;
1005
93.5k
    YYSTYPE *yyvsp = yyvs;
1006
1007
93.5k
  int yyn;
1008
  /* The return value of yyparse.  */
1009
93.5k
  int yyresult;
1010
  /* Lookahead symbol kind.  */
1011
93.5k
  yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY;
1012
  /* The variables used to return semantic value and location from the
1013
     action routines.  */
1014
93.5k
  YYSTYPE yyval;
1015
1016
1017
1018
198M
#define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
1019
1020
  /* The number of symbols on the RHS of the reduced rule.
1021
     Keep to zero when no symbol should be popped.  */
1022
93.5k
  int yylen = 0;
1023
1024
93.5k
  YYDPRINTF ((stderr, "Starting parse\n"));
1025
1026
93.5k
  yychar = PHP_JSON_YYEMPTY; /* Cause a token to be read.  */
1027
1028
93.5k
  goto yysetstate;
1029
1030
1031
/*------------------------------------------------------------.
1032
| yynewstate -- push a new state, which is found in yystate.  |
1033
`------------------------------------------------------------*/
1034
319M
yynewstate:
1035
  /* In all cases, when you get here, the value and location stacks
1036
     have just been pushed.  So pushing a state here evens the stacks.  */
1037
319M
  yyssp++;
1038
1039
1040
/*--------------------------------------------------------------------.
1041
| yysetstate -- set current state (the top of the stack) to yystate.  |
1042
`--------------------------------------------------------------------*/
1043
319M
yysetstate:
1044
319M
  YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1045
319M
  YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
1046
319M
  YY_IGNORE_USELESS_CAST_BEGIN
1047
319M
  *yyssp = YY_CAST (yy_state_t, yystate);
1048
319M
  YY_IGNORE_USELESS_CAST_END
1049
319M
  YY_STACK_PRINT (yyss, yyssp);
1050
1051
319M
  if (yyss + yystacksize - 1 <= yyssp)
1052
#if !defined yyoverflow && !defined YYSTACK_RELOCATE
1053
    YYNOMEM;
1054
#else
1055
0
    {
1056
      /* Get the current used size of the three stacks, in elements.  */
1057
0
      YYPTRDIFF_T yysize = yyssp - yyss + 1;
1058
1059
# if defined yyoverflow
1060
      {
1061
        /* Give user a chance to reallocate the stack.  Use copies of
1062
           these so that the &'s don't force the real ones into
1063
           memory.  */
1064
        yy_state_t *yyss1 = yyss;
1065
        YYSTYPE *yyvs1 = yyvs;
1066
1067
        /* Each stack pointer address is followed by the size of the
1068
           data in use in that stack, in bytes.  This used to be a
1069
           conditional around just the two extra args, but that might
1070
           be undefined if yyoverflow is a macro.  */
1071
        yyoverflow (YY_("memory exhausted"),
1072
                    &yyss1, yysize * YYSIZEOF (*yyssp),
1073
                    &yyvs1, yysize * YYSIZEOF (*yyvsp),
1074
                    &yystacksize);
1075
        yyss = yyss1;
1076
        yyvs = yyvs1;
1077
      }
1078
# else /* defined YYSTACK_RELOCATE */
1079
      /* Extend the stack our own way.  */
1080
0
      if (YYMAXDEPTH <= yystacksize)
1081
0
        YYNOMEM;
1082
0
      yystacksize *= 2;
1083
0
      if (YYMAXDEPTH < yystacksize)
1084
0
        yystacksize = YYMAXDEPTH;
1085
1086
0
      {
1087
0
        yy_state_t *yyss1 = yyss;
1088
0
        union yyalloc *yyptr =
1089
0
          YY_CAST (union yyalloc *,
1090
0
                   YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
1091
0
        if (! yyptr)
1092
0
          YYNOMEM;
1093
0
        YYSTACK_RELOCATE (yyss_alloc, yyss);
1094
0
        YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1095
0
#  undef YYSTACK_RELOCATE
1096
0
        if (yyss1 != yyssa)
1097
0
          YYSTACK_FREE (yyss1);
1098
0
      }
1099
0
# endif
1100
1101
0
      yyssp = yyss + yysize - 1;
1102
0
      yyvsp = yyvs + yysize - 1;
1103
1104
0
      YY_IGNORE_USELESS_CAST_BEGIN
1105
0
      YYDPRINTF ((stderr, "Stack size increased to %ld\n",
1106
0
                  YY_CAST (long, yystacksize)));
1107
0
      YY_IGNORE_USELESS_CAST_END
1108
1109
0
      if (yyss + yystacksize - 1 <= yyssp)
1110
0
        YYABORT;
1111
0
    }
1112
319M
#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
1113
1114
1115
319M
  if (yystate == YYFINAL)
1116
0
    YYACCEPT;
1117
1118
319M
  goto yybackup;
1119
1120
1121
/*-----------.
1122
| yybackup.  |
1123
`-----------*/
1124
319M
yybackup:
1125
  /* Do appropriate processing given the current state.  Read a
1126
     lookahead token if we need one and don't already have one.  */
1127
1128
  /* First try to decide what to do without reference to lookahead token.  */
1129
319M
  yyn = yypact[yystate];
1130
319M
  if (yypact_value_is_default (yyn))
1131
172M
    goto yydefault;
1132
1133
  /* Not known => get a lookahead token if don't already have one.  */
1134
1135
  /* YYCHAR is either empty, or end-of-input, or a valid lookahead.  */
1136
147M
  if (yychar == PHP_JSON_YYEMPTY)
1137
121M
    {
1138
121M
      YYDPRINTF ((stderr, "Reading a token\n"));
1139
121M
      yychar = yylex (&yylval, parser);
1140
121M
    }
1141
1142
147M
  if (yychar <= PHP_JSON_YYEOF)
1143
0
    {
1144
0
      yychar = PHP_JSON_YYEOF;
1145
0
      yytoken = YYSYMBOL_YYEOF;
1146
0
      YYDPRINTF ((stderr, "Now at end of input.\n"));
1147
0
    }
1148
147M
  else if (yychar == PHP_JSON_YYerror)
1149
0
    {
1150
      /* The scanner already issued an error message, process directly
1151
         to error recovery.  But do not keep the error token as
1152
         lookahead, it is too special and may lead us to an endless
1153
         loop in error recovery. */
1154
0
      yychar = PHP_JSON_YYUNDEF;
1155
0
      yytoken = YYSYMBOL_YYerror;
1156
0
      goto yyerrlab1;
1157
0
    }
1158
147M
  else
1159
147M
    {
1160
147M
      yytoken = YYTRANSLATE (yychar);
1161
147M
      YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1162
147M
    }
1163
1164
  /* If the proper action on seeing token YYTOKEN is to reduce or to
1165
     detect an error, take that action.  */
1166
147M
  yyn += yytoken;
1167
147M
  if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1168
25.5M
    goto yydefault;
1169
121M
  yyn = yytable[yyn];
1170
121M
  if (yyn <= 0)
1171
0
    {
1172
0
      if (yytable_value_is_error (yyn))
1173
0
        goto yyerrlab;
1174
0
      yyn = -yyn;
1175
0
      goto yyreduce;
1176
0
    }
1177
1178
  /* Count tokens shifted since error; after three, turn off error
1179
     status.  */
1180
121M
  if (yyerrstatus)
1181
0
    yyerrstatus--;
1182
1183
  /* Shift the lookahead token.  */
1184
121M
  YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1185
121M
  yystate = yyn;
1186
121M
  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1187
121M
  *++yyvsp = yylval;
1188
121M
  YY_IGNORE_MAYBE_UNINITIALIZED_END
1189
1190
  /* Discard the shifted token.  */
1191
121M
  yychar = PHP_JSON_YYEMPTY;
1192
121M
  goto yynewstate;
1193
1194
1195
/*-----------------------------------------------------------.
1196
| yydefault -- do the default action for the current state.  |
1197
`-----------------------------------------------------------*/
1198
198M
yydefault:
1199
198M
  yyn = yydefact[yystate];
1200
198M
  if (yyn == 0)
1201
59.2k
    goto yyerrlab;
1202
198M
  goto yyreduce;
1203
1204
1205
/*-----------------------------.
1206
| yyreduce -- do a reduction.  |
1207
`-----------------------------*/
1208
198M
yyreduce:
1209
  /* yyn is the number of a rule to reduce with.  */
1210
198M
  yylen = yyr2[yyn];
1211
1212
  /* If YYLEN is nonzero, implement the default value of the action:
1213
     '$$ = $1'.
1214
1215
     Otherwise, the following line sets YYVAL to garbage.
1216
     This behavior is undocumented and Bison
1217
     users should not rely upon it.  Assigning to YYVAL
1218
     unconditionally makes the parser a bit smaller, and it avoids a
1219
     GCC warning that YYVAL may be used uninitialized.  */
1220
198M
  yyval = yyvsp[1-yylen];
1221
1222
1223
198M
  YY_REDUCE_PRINT (yyn);
1224
198M
  switch (yyn)
1225
198M
    {
1226
24.3k
  case 2: /* start: value PHP_JSON_T_EOI  */
1227
24.3k
                        {
1228
24.3k
        ZVAL_COPY_VALUE(&(yyval.value), &(yyvsp[-1].value));
1229
24.3k
        ZVAL_COPY_VALUE(parser->return_value, &(yyvsp[-1].value));
1230
24.3k
        (void) php_json_yynerrs;
1231
24.3k
        YYACCEPT;
1232
0
      }
1233
0
    break;
1234
1235
25.5M
  case 3: /* $@1: %empty  */
1236
25.5M
                        {
1237
25.5M
        PHP_JSON_DEPTH_INC;
1238
25.5M
        if (parser->methods.object_start && FAILURE == parser->methods.object_start(parser)) {
1239
0
          YYERROR;
1240
0
        }
1241
25.5M
      }
1242
25.5M
    break;
1243
1244
25.5M
  case 4: /* object: '{' $@1 members object_end  */
1245
25.4M
                        {
1246
25.4M
        ZVAL_COPY_VALUE(&(yyval.value), &(yyvsp[-1].value));
1247
25.4M
        PHP_JSON_DEPTH_DEC;
1248
25.4M
        if (parser->methods.object_end && FAILURE == parser->methods.object_end(parser, &(yyval.value))) {
1249
0
          YYERROR;
1250
0
        }
1251
25.4M
      }
1252
25.4M
    break;
1253
1254
25.4M
  case 6: /* object_end: ']'  */
1255
39
                        {
1256
39
        parser->scanner.errcode = PHP_JSON_ERROR_STATE_MISMATCH;
1257
39
        YYERROR;
1258
25.4M
      }
1259
0
    break;
1260
1261
25.4M
  case 7: /* members: %empty  */
1262
25.4M
                        {
1263
25.4M
        if ((parser->scanner.options & PHP_JSON_OBJECT_AS_ARRAY) && parser->methods.object_create == php_json_parser_object_create) {
1264
12.7M
          ZVAL_EMPTY_ARRAY(&(yyval.value));
1265
12.7M
        } else {
1266
12.7M
          if (UNEXPECTED(parser->methods.object_create(parser, &(yyval.value)) == FAILURE)) {
1267
0
            YYERROR;
1268
0
          }
1269
12.7M
        }
1270
25.4M
      }
1271
25.4M
    break;
1272
1273
25.4M
  case 9: /* member: key ':' value  */
1274
53.4k
                        {
1275
53.4k
        if (UNEXPECTED(parser->methods.object_create(parser, &(yyval.value)) == FAILURE)) {
1276
0
          YYERROR;
1277
0
        }
1278
53.4k
        if (parser->methods.object_update(parser, &(yyval.value), Z_STR((yyvsp[-2].value)), &(yyvsp[0].value)) == FAILURE) {
1279
9.60k
          YYERROR;
1280
9.60k
        }
1281
53.4k
      }
1282
43.8k
    break;
1283
1284
64.9k
  case 10: /* member: member ',' key ':' value  */
1285
64.9k
                        {
1286
64.9k
        if (parser->methods.object_update(parser, &(yyvsp[-4].value), Z_STR((yyvsp[-2].value)), &(yyvsp[0].value)) == FAILURE) {
1287
241
          YYERROR;
1288
241
        }
1289
64.6k
        ZVAL_COPY_VALUE(&(yyval.value), &(yyvsp[-4].value));
1290
64.6k
      }
1291
0
    break;
1292
1293
19.8k
  case 11: /* $@2: %empty  */
1294
19.8k
                        {
1295
19.8k
        PHP_JSON_DEPTH_INC;
1296
19.8k
        if (parser->methods.array_start && FAILURE == parser->methods.array_start(parser)) {
1297
0
          YYERROR;
1298
0
        }
1299
19.8k
      }
1300
19.8k
    break;
1301
1302
19.8k
  case 12: /* array: '[' $@2 elements array_end  */
1303
7.35k
                        {
1304
7.35k
        ZVAL_COPY_VALUE(&(yyval.value), &(yyvsp[-1].value));
1305
7.35k
        PHP_JSON_DEPTH_DEC;
1306
7.35k
        if (parser->methods.array_end && FAILURE == parser->methods.array_end(parser, &(yyval.value))) {
1307
0
          YYERROR;
1308
0
        }
1309
7.35k
      }
1310
7.35k
    break;
1311
1312
7.35k
  case 14: /* array_end: '}'  */
1313
35
                        {
1314
35
        parser->scanner.errcode = PHP_JSON_ERROR_STATE_MISMATCH;
1315
35
        YYERROR;
1316
7.35k
      }
1317
0
    break;
1318
1319
3.86k
  case 15: /* elements: %empty  */
1320
3.86k
                        {
1321
3.86k
        if (parser->methods.array_create == php_json_parser_array_create) {
1322
3.86k
          ZVAL_EMPTY_ARRAY(&(yyval.value));
1323
3.86k
        } else {
1324
0
          if (UNEXPECTED(parser->methods.array_create(parser, &(yyval.value)) == FAILURE)) {
1325
0
            YYERROR;
1326
0
          }
1327
0
        }
1328
3.86k
      }
1329
3.86k
    break;
1330
1331
13.2k
  case 17: /* element: value  */
1332
13.2k
                        {
1333
13.2k
        if (UNEXPECTED(parser->methods.array_create(parser, &(yyval.value)) == FAILURE)) {
1334
0
          YYERROR;
1335
0
        }
1336
13.2k
        if (UNEXPECTED(parser->methods.array_append(parser, &(yyval.value), &(yyvsp[0].value)) == FAILURE)) {
1337
0
          YYERROR;
1338
0
        }
1339
13.2k
      }
1340
13.2k
    break;
1341
1342
47.7M
  case 18: /* element: element ',' value  */
1343
47.7M
                        {
1344
47.7M
        if (UNEXPECTED(parser->methods.array_append(parser, &(yyvsp[-2].value), &(yyvsp[0].value)) == FAILURE)) {
1345
0
          YYERROR;
1346
0
        }
1347
47.7M
        ZVAL_COPY_VALUE(&(yyval.value), &(yyvsp[-2].value));
1348
47.7M
      }
1349
0
    break;
1350
1351
1352
1353
73.5M
      default: break;
1354
198M
    }
1355
  /* User semantic actions sometimes alter yychar, and that requires
1356
     that yytoken be updated with the new translation.  We take the
1357
     approach of translating immediately before every use of yytoken.
1358
     One alternative is translating here after every semantic action,
1359
     but that translation would be missed if the semantic action invokes
1360
     YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
1361
     if it invokes YYBACKUP.  In the case of YYABORT or YYACCEPT, an
1362
     incorrect destructor might then be invoked immediately.  In the
1363
     case of YYERROR or YYBACKUP, subsequent parser actions might lead
1364
     to an incorrect destructor call or verbose syntax error message
1365
     before the lookahead is translated.  */
1366
197M
  YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc);
1367
1368
197M
  YYPOPSTACK (yylen);
1369
197M
  yylen = 0;
1370
1371
197M
  *++yyvsp = yyval;
1372
1373
  /* Now 'shift' the result of the reduction.  Determine what state
1374
     that goes to, based on the state we popped back to and the rule
1375
     number reduced by.  */
1376
197M
  {
1377
197M
    const int yylhs = yyr1[yyn] - YYNTOKENS;
1378
197M
    const int yyi = yypgoto[yylhs] + *yyssp;
1379
197M
    yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
1380
197M
               ? yytable[yyi]
1381
197M
               : yydefgoto[yylhs]);
1382
197M
  }
1383
1384
197M
  goto yynewstate;
1385
1386
1387
/*--------------------------------------.
1388
| yyerrlab -- here on detecting error.  |
1389
`--------------------------------------*/
1390
59.2k
yyerrlab:
1391
  /* Make sure we have latest lookahead translation.  See comments at
1392
     user semantic actions for why this is necessary.  */
1393
59.2k
  yytoken = yychar == PHP_JSON_YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar);
1394
  /* If not already recovering from an error, report this error.  */
1395
59.2k
  if (!yyerrstatus)
1396
59.2k
    {
1397
59.2k
      ++yynerrs;
1398
59.2k
      yyerror (parser, YY_("syntax error"));
1399
59.2k
    }
1400
1401
59.2k
  if (yyerrstatus == 3)
1402
0
    {
1403
      /* If just tried and failed to reuse lookahead token after an
1404
         error, discard it.  */
1405
1406
0
      if (yychar <= PHP_JSON_YYEOF)
1407
0
        {
1408
          /* Return failure if at end of input.  */
1409
0
          if (yychar == PHP_JSON_YYEOF)
1410
0
            YYABORT;
1411
0
        }
1412
0
      else
1413
0
        {
1414
0
          yydestruct ("Error: discarding",
1415
0
                      yytoken, &yylval, parser);
1416
0
          yychar = PHP_JSON_YYEMPTY;
1417
0
        }
1418
0
    }
1419
1420
  /* Else will try to reuse lookahead token after shifting the error
1421
     token.  */
1422
59.2k
  goto yyerrlab1;
1423
1424
1425
/*---------------------------------------------------.
1426
| yyerrorlab -- error raised explicitly by YYERROR.  |
1427
`---------------------------------------------------*/
1428
59.2k
yyerrorlab:
1429
  /* Pacify compilers when the user code never invokes YYERROR and the
1430
     label yyerrorlab therefore never appears in user code.  */
1431
9.98k
  if (0)
1432
0
    YYERROR;
1433
9.98k
  ++yynerrs;
1434
1435
  /* Do not reclaim the symbols of the rule whose action triggered
1436
     this YYERROR.  */
1437
9.98k
  YYPOPSTACK (yylen);
1438
9.98k
  yylen = 0;
1439
9.98k
  YY_STACK_PRINT (yyss, yyssp);
1440
9.98k
  yystate = *yyssp;
1441
9.98k
  goto yyerrlab1;
1442
1443
1444
/*-------------------------------------------------------------.
1445
| yyerrlab1 -- common code for both syntax error and YYERROR.  |
1446
`-------------------------------------------------------------*/
1447
69.2k
yyerrlab1:
1448
69.2k
  yyerrstatus = 3;      /* Each real token shifted decrements this.  */
1449
1450
  /* Pop stack until we find a state that shifts the error token.  */
1451
69.2k
  for (;;)
1452
273k
    {
1453
273k
      yyn = yypact[yystate];
1454
273k
      if (!yypact_value_is_default (yyn))
1455
212k
        {
1456
212k
          yyn += YYSYMBOL_YYerror;
1457
212k
          if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror)
1458
0
            {
1459
0
              yyn = yytable[yyn];
1460
0
              if (0 < yyn)
1461
0
                break;
1462
0
            }
1463
212k
        }
1464
1465
      /* Pop the current state because it cannot handle the error token.  */
1466
273k
      if (yyssp == yyss)
1467
69.2k
        YYABORT;
1468
1469
1470
204k
      yydestruct ("Error: popping",
1471
204k
                  YY_ACCESSING_SYMBOL (yystate), yyvsp, parser);
1472
204k
      YYPOPSTACK (1);
1473
204k
      yystate = *yyssp;
1474
204k
      YY_STACK_PRINT (yyss, yyssp);
1475
204k
    }
1476
1477
0
  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1478
0
  *++yyvsp = yylval;
1479
0
  YY_IGNORE_MAYBE_UNINITIALIZED_END
1480
1481
1482
  /* Shift the error token.  */
1483
0
  YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp);
1484
1485
0
  yystate = yyn;
1486
0
  goto yynewstate;
1487
1488
1489
/*-------------------------------------.
1490
| yyacceptlab -- YYACCEPT comes here.  |
1491
`-------------------------------------*/
1492
24.3k
yyacceptlab:
1493
24.3k
  yyresult = 0;
1494
24.3k
  goto yyreturnlab;
1495
1496
1497
/*-----------------------------------.
1498
| yyabortlab -- YYABORT comes here.  |
1499
`-----------------------------------*/
1500
69.2k
yyabortlab:
1501
69.2k
  yyresult = 1;
1502
69.2k
  goto yyreturnlab;
1503
1504
1505
/*-----------------------------------------------------------.
1506
| yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here.  |
1507
`-----------------------------------------------------------*/
1508
0
yyexhaustedlab:
1509
0
  yyerror (parser, YY_("memory exhausted"));
1510
0
  yyresult = 2;
1511
0
  goto yyreturnlab;
1512
1513
1514
/*----------------------------------------------------------.
1515
| yyreturnlab -- parsing is finished, clean up and return.  |
1516
`----------------------------------------------------------*/
1517
93.5k
yyreturnlab:
1518
93.5k
  if (yychar != PHP_JSON_YYEMPTY)
1519
59.2k
    {
1520
      /* Make sure we have latest lookahead translation.  See comments at
1521
         user semantic actions for why this is necessary.  */
1522
59.2k
      yytoken = YYTRANSLATE (yychar);
1523
59.2k
      yydestruct ("Cleanup: discarding lookahead",
1524
59.2k
                  yytoken, &yylval, parser);
1525
59.2k
    }
1526
  /* Do not reclaim the symbols of the rule whose action triggered
1527
     this YYABORT or YYACCEPT.  */
1528
93.5k
  YYPOPSTACK (yylen);
1529
93.5k
  YY_STACK_PRINT (yyss, yyssp);
1530
93.5k
  while (yyssp != yyss)
1531
0
    {
1532
0
      yydestruct ("Cleanup: popping",
1533
0
                  YY_ACCESSING_SYMBOL (+*yyssp), yyvsp, parser);
1534
0
      YYPOPSTACK (1);
1535
0
    }
1536
93.5k
#ifndef yyoverflow
1537
93.5k
  if (yyss != yyssa)
1538
0
    YYSTACK_FREE (yyss);
1539
93.5k
#endif
1540
1541
93.5k
  return yyresult;
1542
69.2k
}
1543
1544
 /* Functions */
1545
1546
static int php_json_parser_array_create(php_json_parser *parser, zval *array)
1547
13.2k
{
1548
13.2k
  if (UNEXPECTED(!array_finit(array))) {
1549
0
    ZEND_ASSERT(ZEND_HAS_OOM());
1550
0
    return FAILURE;
1551
0
  }
1552
13.2k
  return SUCCESS;
1553
13.2k
}
1554
1555
static int php_json_parser_array_append(php_json_parser *parser, zval *array, zval *zvalue)
1556
47.7M
{
1557
47.7M
  if (UNEXPECTED(zend_hash_next_index_finsert(Z_ARRVAL_P(array), zvalue) == HASH_NOMEM)) {
1558
0
    ZEND_ASSERT(ZEND_HAS_OOM());
1559
0
    return FAILURE;
1560
0
  }
1561
47.7M
  return SUCCESS;
1562
47.7M
}
1563
1564
static int php_json_parser_object_create(php_json_parser *parser, zval *object)
1565
12.7M
{
1566
12.7M
  bool created;
1567
1568
12.7M
  if (parser->scanner.options & PHP_JSON_OBJECT_AS_ARRAY) {
1569
26.8k
    created = array_finit(object);
1570
12.7M
  } else {
1571
12.7M
    created = object_finit(object);
1572
12.7M
  }
1573
12.7M
  if (UNEXPECTED(!created)) {
1574
0
    ZEND_ASSERT(ZEND_HAS_OOM());
1575
0
    return FAILURE;
1576
0
  }
1577
12.7M
  return SUCCESS;
1578
12.7M
}
1579
1580
static int php_json_parser_object_update(php_json_parser *parser, zval *object, zend_string *key, zval *zvalue)
1581
118k
{
1582
  /* if JSON_OBJECT_AS_ARRAY is set */
1583
118k
  if (Z_TYPE_P(object) == IS_ARRAY) {
1584
60.4k
    if (UNEXPECTED(zend_symtable_fupdate(Z_ARRVAL_P(object), key, zvalue) == HASH_NOMEM)) {
1585
0
      return FAILURE;
1586
0
    }
1587
60.4k
  } else {
1588
57.8k
    if (ZSTR_LEN(key) > 0 && ZSTR_VAL(key)[0] == '\0') {
1589
9.84k
      parser->scanner.errcode = PHP_JSON_ERROR_INVALID_PROPERTY_NAME;
1590
9.84k
      zend_string_release_ex(key, 0);
1591
9.84k
      zval_ptr_dtor_nogc(zvalue);
1592
9.84k
      zval_ptr_dtor_nogc(object);
1593
9.84k
      return FAILURE;
1594
9.84k
    }
1595
48.0k
    zend_std_write_property(Z_OBJ_P(object), key, zvalue, NULL);
1596
48.0k
    Z_TRY_DELREF_P(zvalue);
1597
48.0k
    if (ZEND_HAS_OOM()) {
1598
0
      return FAILURE;
1599
0
    }
1600
48.0k
  }
1601
108k
  zend_string_release_ex(key, 0);
1602
1603
108k
  return SUCCESS;
1604
118k
}
1605
1606
static int php_json_parser_array_create_validate(php_json_parser *parser, zval *array)
1607
0
{
1608
0
  ZVAL_NULL(array);
1609
0
  return SUCCESS;
1610
0
}
1611
1612
static int php_json_parser_array_append_validate(php_json_parser *parser, zval *array, zval *zvalue)
1613
0
{
1614
0
  return SUCCESS;
1615
0
}
1616
1617
static int php_json_parser_object_create_validate(php_json_parser *parser, zval *object)
1618
0
{
1619
0
  ZVAL_NULL(object);
1620
0
  return SUCCESS;
1621
0
}
1622
1623
static int php_json_parser_object_update_validate(php_json_parser *parser, zval *object, zend_string *key, zval *zvalue)
1624
0
{
1625
0
  return SUCCESS;
1626
0
}
1627
1628
static int php_json_yylex(union YYSTYPE *value, php_json_parser *parser)
1629
121M
{
1630
121M
  int token = php_json_scan(&parser->scanner);
1631
1632
121M
  bool validate = parser->methods.array_create == php_json_parser_array_create_validate
1633
0
    && parser->methods.array_append == php_json_parser_array_append_validate
1634
0
    && parser->methods.object_create == php_json_parser_object_create_validate
1635
0
    && parser->methods.object_update == php_json_parser_object_update_validate;
1636
1637
121M
  if (validate) {
1638
0
    zval_ptr_dtor_str(&(parser->scanner.value));
1639
0
    ZVAL_UNDEF(&value->value);
1640
121M
  } else {
1641
121M
    value->value = parser->scanner.value;
1642
121M
  }
1643
1644
121M
  return token;
1645
121M
}
1646
1647
static void php_json_yyerror(php_json_parser *parser, char const *msg)
1648
59.2k
{
1649
59.2k
  if (!parser->scanner.errcode) {
1650
30.7k
    parser->scanner.errcode = PHP_JSON_ERROR_SYNTAX;
1651
30.7k
  }
1652
59.2k
}
1653
1654
PHP_JSON_API php_json_error_code php_json_parser_error_code(const php_json_parser *parser)
1655
0
{
1656
0
  return parser->scanner.errcode;
1657
0
}
1658
1659
static uint64_t php_json_compute_error_column(const php_json_scanner *s)
1660
0
{
1661
0
  const php_json_ctype *p = s->line_start;
1662
0
  const php_json_ctype *end = s->token;
1663
  /* Count characters from the start of the line to the failing token,
1664
   * folding UTF-8 continuation bytes into their leading byte. */
1665
0
  uint64_t column = 1;
1666
1667
0
  while (p < end) {
1668
0
    if ((*p & 0b11000000) != 0b10000000) {
1669
0
      column++;
1670
0
    }
1671
0
    p++;
1672
0
  }
1673
0
  return column;
1674
0
}
1675
1676
PHP_JSON_API void php_json_parser_error_details(const php_json_parser *parser, php_json_error_details *out)
1677
0
{
1678
0
  out->code = parser->scanner.errcode;
1679
0
  out->line = parser->scanner.line;
1680
0
  out->column = php_json_compute_error_column(&parser->scanner);
1681
0
}
1682
1683
static const php_json_parser_methods default_parser_methods =
1684
{
1685
  php_json_parser_array_create,
1686
  php_json_parser_array_append,
1687
  NULL,
1688
  NULL,
1689
  php_json_parser_object_create,
1690
  php_json_parser_object_update,
1691
  NULL,
1692
  NULL,
1693
};
1694
1695
static const php_json_parser_methods validate_parser_methods =
1696
{
1697
  php_json_parser_array_create_validate,
1698
  php_json_parser_array_append_validate,
1699
  NULL,
1700
  NULL,
1701
  php_json_parser_object_create_validate,
1702
  php_json_parser_object_update_validate,
1703
  NULL,
1704
  NULL,
1705
};
1706
1707
PHP_JSON_API void php_json_parser_init_ex(php_json_parser *parser,
1708
    zval *return_value,
1709
    const char *str,
1710
    size_t str_len,
1711
    int options,
1712
    int max_depth,
1713
    const php_json_parser_methods *parser_methods)
1714
93.5k
{
1715
93.5k
  memset(parser, 0, sizeof(php_json_parser));
1716
93.5k
  php_json_scanner_init(&parser->scanner, str, str_len, options);
1717
93.5k
  parser->depth = 1;
1718
93.5k
  parser->max_depth = max_depth;
1719
93.5k
  parser->return_value = return_value;
1720
93.5k
  memcpy(&parser->methods, parser_methods, sizeof(php_json_parser_methods));
1721
93.5k
}
1722
1723
PHP_JSON_API void php_json_parser_init(php_json_parser *parser,
1724
    zval *return_value,
1725
    const char *str,
1726
    size_t str_len,
1727
    int options,
1728
    int max_depth)
1729
93.5k
{
1730
93.5k
  php_json_parser_init_ex(
1731
93.5k
      parser,
1732
93.5k
      return_value,
1733
93.5k
      str,
1734
93.5k
      str_len,
1735
93.5k
      options,
1736
93.5k
      max_depth,
1737
93.5k
      &default_parser_methods);
1738
93.5k
}
1739
1740
PHP_JSON_API int php_json_parse(php_json_parser *parser)
1741
0
{
1742
0
  return php_json_yyparse(parser);
1743
0
}
1744
1745
const php_json_parser_methods* php_json_get_validate_methods(void)
1746
0
{
1747
0
  return &validate_parser_methods;
1748
0
}