LCOV - code coverage report
Current view: top level - src/pl/plpgsql/src - pl_gram.c (source / functions) Hit Total Coverage
Test: PostgreSQL 12beta1 Lines: 217 294 73.8 %
Date: 2019-06-16 14:06:46 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* A Bison parser, made by GNU Bison 3.0.4.  */
       2             : 
       3             : /* Bison implementation for Yacc-like parsers in C
       4             : 
       5             :    Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
       6             : 
       7             :    This program is free software: you can redistribute it and/or modify
       8             :    it under the terms of the GNU General Public License as published by
       9             :    the Free Software Foundation, either version 3 of the License, or
      10             :    (at your option) any later version.
      11             : 
      12             :    This program is distributed in the hope that it will be useful,
      13             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :    GNU General Public License for more details.
      16             : 
      17             :    You should have received a copy of the GNU General Public License
      18             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
      19             : 
      20             : /* As a special exception, you may create a larger work that contains
      21             :    part or all of the Bison parser skeleton and distribute that work
      22             :    under terms of your choice, so long as that work isn't itself a
      23             :    parser generator using the skeleton or a modified version thereof
      24             :    as a parser skeleton.  Alternatively, if you modify or redistribute
      25             :    the parser skeleton itself, you may (at your option) remove this
      26             :    special exception, which will cause the skeleton and the resulting
      27             :    Bison output files to be licensed under the GNU General Public
      28             :    License without this special exception.
      29             : 
      30             :    This special exception was added by the Free Software Foundation in
      31             :    version 2.2 of Bison.  */
      32             : 
      33             : /* C LALR(1) parser skeleton written by Richard Stallman, by
      34             :    simplifying the original so-called "semantic" parser.  */
      35             : 
      36             : /* All symbols defined below should begin with yy or YY, to avoid
      37             :    infringing on user name space.  This should be done even for local
      38             :    variables, as they might otherwise be expanded by user macros.
      39             :    There are some unavoidable exceptions within include files to
      40             :    define necessary library symbols; they are noted "INFRINGES ON
      41             :    USER NAME SPACE" below.  */
      42             : 
      43             : /* Identify Bison output.  */
      44             : #define YYBISON 1
      45             : 
      46             : /* Bison version.  */
      47             : #define YYBISON_VERSION "3.0.4"
      48             : 
      49             : /* Skeleton name.  */
      50             : #define YYSKELETON_NAME "yacc.c"
      51             : 
      52             : /* Pure parsers.  */
      53             : #define YYPURE 0
      54             : 
      55             : /* Push parsers.  */
      56             : #define YYPUSH 0
      57             : 
      58             : /* Pull parsers.  */
      59             : #define YYPULL 1
      60             : 
      61             : 
      62             : /* Substitute the variable and function names.  */
      63             : #define yyparse         plpgsql_yyparse
      64             : #define yylex           plpgsql_yylex
      65             : #define yyerror         plpgsql_yyerror
      66             : #define yydebug         plpgsql_yydebug
      67             : #define yynerrs         plpgsql_yynerrs
      68             : 
      69             : #define yylval          plpgsql_yylval
      70             : #define yychar          plpgsql_yychar
      71             : #define yylloc          plpgsql_yylloc
      72             : 
      73             : /* Copy the first part of user declarations.  */
      74             : #line 1 "pl_gram.y" /* yacc.c:339  */
      75             : 
      76             : /*-------------------------------------------------------------------------
      77             :  *
      78             :  * pl_gram.y            - Parser for the PL/pgSQL procedural language
      79             :  *
      80             :  * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
      81             :  * Portions Copyright (c) 1994, Regents of the University of California
      82             :  *
      83             :  *
      84             :  * IDENTIFICATION
      85             :  *    src/pl/plpgsql/src/pl_gram.y
      86             :  *
      87             :  *-------------------------------------------------------------------------
      88             :  */
      89             : 
      90             : #include "postgres.h"
      91             : 
      92             : #include "catalog/namespace.h"
      93             : #include "catalog/pg_proc.h"
      94             : #include "catalog/pg_type.h"
      95             : #include "parser/parser.h"
      96             : #include "parser/parse_type.h"
      97             : #include "parser/scanner.h"
      98             : #include "parser/scansup.h"
      99             : #include "utils/builtins.h"
     100             : 
     101             : #include "plpgsql.h"
     102             : 
     103             : 
     104             : /* Location tracking support --- simpler than bison's default */
     105             : #define YYLLOC_DEFAULT(Current, Rhs, N) \
     106             :     do { \
     107             :         if (N) \
     108             :             (Current) = (Rhs)[1]; \
     109             :         else \
     110             :             (Current) = (Rhs)[0]; \
     111             :     } while (0)
     112             : 
     113             : /*
     114             :  * Bison doesn't allocate anything that needs to live across parser calls,
     115             :  * so we can easily have it use palloc instead of malloc.  This prevents
     116             :  * memory leaks if we error out during parsing.  Note this only works with
     117             :  * bison >= 2.0.  However, in bison 1.875 the default is to use alloca()
     118             :  * if possible, so there's not really much problem anyhow, at least if
     119             :  * you're building with gcc.
     120             :  */
     121             : #define YYMALLOC palloc
     122             : #define YYFREE   pfree
     123             : 
     124             : 
     125             : typedef struct
     126             : {
     127             :     int         location;
     128             :     int         leaderlen;
     129             : } sql_error_callback_arg;
     130             : 
     131             : #define parser_errposition(pos)  plpgsql_scanner_errposition(pos)
     132             : 
     133             : union YYSTYPE;                  /* need forward reference for tok_is_keyword */
     134             : 
     135             : static  bool            tok_is_keyword(int token, union YYSTYPE *lval,
     136             :                                        int kw_token, const char *kw_str);
     137             : static  void            word_is_not_variable(PLword *word, int location);
     138             : static  void            cword_is_not_variable(PLcword *cword, int location);
     139             : static  void            current_token_is_not_variable(int tok);
     140             : static  PLpgSQL_expr    *read_sql_construct(int until,
     141             :                                             int until2,
     142             :                                             int until3,
     143             :                                             const char *expected,
     144             :                                             const char *sqlstart,
     145             :                                             bool isexpression,
     146             :                                             bool valid_sql,
     147             :                                             bool trim,
     148             :                                             int *startloc,
     149             :                                             int *endtoken);
     150             : static  PLpgSQL_expr    *read_sql_expression(int until,
     151             :                                              const char *expected);
     152             : static  PLpgSQL_expr    *read_sql_expression2(int until, int until2,
     153             :                                               const char *expected,
     154             :                                               int *endtoken);
     155             : static  PLpgSQL_expr    *read_sql_stmt(const char *sqlstart);
     156             : static  PLpgSQL_type    *read_datatype(int tok);
     157             : static  PLpgSQL_stmt    *make_execsql_stmt(int firsttoken, int location);
     158             : static  PLpgSQL_stmt_fetch *read_fetch_direction(void);
     159             : static  void             complete_direction(PLpgSQL_stmt_fetch *fetch,
     160             :                                             bool *check_FROM);
     161             : static  PLpgSQL_stmt    *make_return_stmt(int location);
     162             : static  PLpgSQL_stmt    *make_return_next_stmt(int location);
     163             : static  PLpgSQL_stmt    *make_return_query_stmt(int location);
     164             : static  PLpgSQL_stmt    *make_case(int location, PLpgSQL_expr *t_expr,
     165             :                                    List *case_when_list, List *else_stmts);
     166             : static  char            *NameOfDatum(PLwdatum *wdatum);
     167             : static  void             check_assignable(PLpgSQL_datum *datum, int location);
     168             : static  void             read_into_target(PLpgSQL_variable **target,
     169             :                                           bool *strict);
     170             : static  PLpgSQL_row     *read_into_scalar_list(char *initial_name,
     171             :                                                PLpgSQL_datum *initial_datum,
     172             :                                                int initial_location);
     173             : static  PLpgSQL_row     *make_scalar_list1(char *initial_name,
     174             :                                            PLpgSQL_datum *initial_datum,
     175             :                                            int lineno, int location);
     176             : static  void             check_sql_expr(const char *stmt, int location,
     177             :                                         int leaderlen);
     178             : static  void             plpgsql_sql_error_callback(void *arg);
     179             : static  PLpgSQL_type    *parse_datatype(const char *string, int location);
     180             : static  void             check_labels(const char *start_label,
     181             :                                       const char *end_label,
     182             :                                       int end_location);
     183             : static  PLpgSQL_expr    *read_cursor_args(PLpgSQL_var *cursor,
     184             :                                           int until, const char *expected);
     185             : static  List            *read_raise_options(void);
     186             : static  void            check_raise_parameters(PLpgSQL_stmt_raise *stmt);
     187             : 
     188             : 
     189             : #line 190 "pl_gram.c" /* yacc.c:339  */
     190             : 
     191             : # ifndef YY_NULLPTR
     192             : #  if defined __cplusplus && 201103L <= __cplusplus
     193             : #   define YY_NULLPTR nullptr
     194             : #  else
     195             : #   define YY_NULLPTR 0
     196             : #  endif
     197             : # endif
     198             : 
     199             : /* Enabling verbose error messages.  */
     200             : #ifdef YYERROR_VERBOSE
     201             : # undef YYERROR_VERBOSE
     202             : # define YYERROR_VERBOSE 1
     203             : #else
     204             : # define YYERROR_VERBOSE 0
     205             : #endif
     206             : 
     207             : /* In a future release of Bison, this section will be replaced
     208             :    by #include "pl_gram.h".  */
     209             : #ifndef YY_PLPGSQL_YY_PL_GRAM_H_INCLUDED
     210             : # define YY_PLPGSQL_YY_PL_GRAM_H_INCLUDED
     211             : /* Debug traces.  */
     212             : #ifndef YYDEBUG
     213             : # define YYDEBUG 0
     214             : #endif
     215             : #if YYDEBUG
     216             : extern int plpgsql_yydebug;
     217             : #endif
     218             : 
     219             : /* Token type.  */
     220             : #ifndef YYTOKENTYPE
     221             : # define YYTOKENTYPE
     222             :   enum yytokentype
     223             :   {
     224             :     IDENT = 258,
     225             :     FCONST = 259,
     226             :     SCONST = 260,
     227             :     BCONST = 261,
     228             :     XCONST = 262,
     229             :     Op = 263,
     230             :     ICONST = 264,
     231             :     PARAM = 265,
     232             :     TYPECAST = 266,
     233             :     DOT_DOT = 267,
     234             :     COLON_EQUALS = 268,
     235             :     EQUALS_GREATER = 269,
     236             :     LESS_EQUALS = 270,
     237             :     GREATER_EQUALS = 271,
     238             :     NOT_EQUALS = 272,
     239             :     T_WORD = 273,
     240             :     T_CWORD = 274,
     241             :     T_DATUM = 275,
     242             :     LESS_LESS = 276,
     243             :     GREATER_GREATER = 277,
     244             :     K_ABSOLUTE = 278,
     245             :     K_ALIAS = 279,
     246             :     K_ALL = 280,
     247             :     K_AND = 281,
     248             :     K_ARRAY = 282,
     249             :     K_ASSERT = 283,
     250             :     K_BACKWARD = 284,
     251             :     K_BEGIN = 285,
     252             :     K_BY = 286,
     253             :     K_CALL = 287,
     254             :     K_CASE = 288,
     255             :     K_CHAIN = 289,
     256             :     K_CLOSE = 290,
     257             :     K_COLLATE = 291,
     258             :     K_COLUMN = 292,
     259             :     K_COLUMN_NAME = 293,
     260             :     K_COMMIT = 294,
     261             :     K_CONSTANT = 295,
     262             :     K_CONSTRAINT = 296,
     263             :     K_CONSTRAINT_NAME = 297,
     264             :     K_CONTINUE = 298,
     265             :     K_CURRENT = 299,
     266             :     K_CURSOR = 300,
     267             :     K_DATATYPE = 301,
     268             :     K_DEBUG = 302,
     269             :     K_DECLARE = 303,
     270             :     K_DEFAULT = 304,
     271             :     K_DETAIL = 305,
     272             :     K_DIAGNOSTICS = 306,
     273             :     K_DO = 307,
     274             :     K_DUMP = 308,
     275             :     K_ELSE = 309,
     276             :     K_ELSIF = 310,
     277             :     K_END = 311,
     278             :     K_ERRCODE = 312,
     279             :     K_ERROR = 313,
     280             :     K_EXCEPTION = 314,
     281             :     K_EXECUTE = 315,
     282             :     K_EXIT = 316,
     283             :     K_FETCH = 317,
     284             :     K_FIRST = 318,
     285             :     K_FOR = 319,
     286             :     K_FOREACH = 320,
     287             :     K_FORWARD = 321,
     288             :     K_FROM = 322,
     289             :     K_GET = 323,
     290             :     K_HINT = 324,
     291             :     K_IF = 325,
     292             :     K_IMPORT = 326,
     293             :     K_IN = 327,
     294             :     K_INFO = 328,
     295             :     K_INSERT = 329,
     296             :     K_INTO = 330,
     297             :     K_IS = 331,
     298             :     K_LAST = 332,
     299             :     K_LOG = 333,
     300             :     K_LOOP = 334,
     301             :     K_MESSAGE = 335,
     302             :     K_MESSAGE_TEXT = 336,
     303             :     K_MOVE = 337,
     304             :     K_NEXT = 338,
     305             :     K_NO = 339,
     306             :     K_NOT = 340,
     307             :     K_NOTICE = 341,
     308             :     K_NULL = 342,
     309             :     K_OPEN = 343,
     310             :     K_OPTION = 344,
     311             :     K_OR = 345,
     312             :     K_PERFORM = 346,
     313             :     K_PG_CONTEXT = 347,
     314             :     K_PG_DATATYPE_NAME = 348,
     315             :     K_PG_EXCEPTION_CONTEXT = 349,
     316             :     K_PG_EXCEPTION_DETAIL = 350,
     317             :     K_PG_EXCEPTION_HINT = 351,
     318             :     K_PRINT_STRICT_PARAMS = 352,
     319             :     K_PRIOR = 353,
     320             :     K_QUERY = 354,
     321             :     K_RAISE = 355,
     322             :     K_RELATIVE = 356,
     323             :     K_RESET = 357,
     324             :     K_RETURN = 358,
     325             :     K_RETURNED_SQLSTATE = 359,
     326             :     K_REVERSE = 360,
     327             :     K_ROLLBACK = 361,
     328             :     K_ROW_COUNT = 362,
     329             :     K_ROWTYPE = 363,
     330             :     K_SCHEMA = 364,
     331             :     K_SCHEMA_NAME = 365,
     332             :     K_SCROLL = 366,
     333             :     K_SET = 367,
     334             :     K_SLICE = 368,
     335             :     K_SQLSTATE = 369,
     336             :     K_STACKED = 370,
     337             :     K_STRICT = 371,
     338             :     K_TABLE = 372,
     339             :     K_TABLE_NAME = 373,
     340             :     K_THEN = 374,
     341             :     K_TO = 375,
     342             :     K_TYPE = 376,
     343             :     K_USE_COLUMN = 377,
     344             :     K_USE_VARIABLE = 378,
     345             :     K_USING = 379,
     346             :     K_VARIABLE_CONFLICT = 380,
     347             :     K_WARNING = 381,
     348             :     K_WHEN = 382,
     349             :     K_WHILE = 383
     350             :   };
     351             : #endif
     352             : 
     353             : /* Value type.  */
     354             : #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
     355             : 
     356             : union YYSTYPE
     357             : {
     358             : #line 120 "pl_gram.y" /* yacc.c:355  */
     359             : 
     360             :         core_YYSTYPE            core_yystype;
     361             :         /* these fields must match core_YYSTYPE: */
     362             :         int                     ival;
     363             :         char                    *str;
     364             :         const char              *keyword;
     365             : 
     366             :         PLword                  word;
     367             :         PLcword                 cword;
     368             :         PLwdatum                wdatum;
     369             :         bool                    boolean;
     370             :         Oid                     oid;
     371             :         struct
     372             :         {
     373             :             char *name;
     374             :             int  lineno;
     375             :         }                       varname;
     376             :         struct
     377             :         {
     378             :             char *name;
     379             :             int  lineno;
     380             :             PLpgSQL_datum   *scalar;
     381             :             PLpgSQL_datum   *row;
     382             :         }                       forvariable;
     383             :         struct
     384             :         {
     385             :             char *label;
     386             :             int  n_initvars;
     387             :             int  *initvarnos;
     388             :         }                       declhdr;
     389             :         struct
     390             :         {
     391             :             List *stmts;
     392             :             char *end_label;
     393             :             int   end_label_location;
     394             :         }                       loop_body;
     395             :         List                    *list;
     396             :         PLpgSQL_type            *dtype;
     397             :         PLpgSQL_datum           *datum;
     398             :         PLpgSQL_var             *var;
     399             :         PLpgSQL_expr            *expr;
     400             :         PLpgSQL_stmt            *stmt;
     401             :         PLpgSQL_condition       *condition;
     402             :         PLpgSQL_exception       *exception;
     403             :         PLpgSQL_exception_block *exception_block;
     404             :         PLpgSQL_nsitem          *nsitem;
     405             :         PLpgSQL_diag_item       *diagitem;
     406             :         PLpgSQL_stmt_fetch      *fetch;
     407             :         PLpgSQL_case_when       *casewhen;
     408             : 
     409             : #line 410 "pl_gram.c" /* yacc.c:355  */
     410             : };
     411             : 
     412             : typedef union YYSTYPE YYSTYPE;
     413             : # define YYSTYPE_IS_TRIVIAL 1
     414             : # define YYSTYPE_IS_DECLARED 1
     415             : #endif
     416             : 
     417             : /* Location type.  */
     418             : #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
     419             : typedef struct YYLTYPE YYLTYPE;
     420             : struct YYLTYPE
     421             : {
     422             :   int first_line;
     423             :   int first_column;
     424             :   int last_line;
     425             :   int last_column;
     426             : };
     427             : # define YYLTYPE_IS_DECLARED 1
     428             : # define YYLTYPE_IS_TRIVIAL 1
     429             : #endif
     430             : 
     431             : 
     432             : extern YYSTYPE plpgsql_yylval;
     433             : extern YYLTYPE plpgsql_yylloc;
     434             : int plpgsql_yyparse (void);
     435             : 
     436             : #endif /* !YY_PLPGSQL_YY_PL_GRAM_H_INCLUDED  */
     437             : 
     438             : /* Copy the second part of user declarations.  */
     439             : 
     440             : #line 441 "pl_gram.c" /* yacc.c:358  */
     441             : 
     442             : #ifdef short
     443             : # undef short
     444             : #endif
     445             : 
     446             : #ifdef YYTYPE_UINT8
     447             : typedef YYTYPE_UINT8 yytype_uint8;
     448             : #else
     449             : typedef unsigned char yytype_uint8;
     450             : #endif
     451             : 
     452             : #ifdef YYTYPE_INT8
     453             : typedef YYTYPE_INT8 yytype_int8;
     454             : #else
     455             : typedef signed char yytype_int8;
     456             : #endif
     457             : 
     458             : #ifdef YYTYPE_UINT16
     459             : typedef YYTYPE_UINT16 yytype_uint16;
     460             : #else
     461             : typedef unsigned short int yytype_uint16;
     462             : #endif
     463             : 
     464             : #ifdef YYTYPE_INT16
     465             : typedef YYTYPE_INT16 yytype_int16;
     466             : #else
     467             : typedef short int yytype_int16;
     468             : #endif
     469             : 
     470             : #ifndef YYSIZE_T
     471             : # ifdef __SIZE_TYPE__
     472             : #  define YYSIZE_T __SIZE_TYPE__
     473             : # elif defined size_t
     474             : #  define YYSIZE_T size_t
     475             : # elif ! defined YYSIZE_T
     476             : #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
     477             : #  define YYSIZE_T size_t
     478             : # else
     479             : #  define YYSIZE_T unsigned int
     480             : # endif
     481             : #endif
     482             : 
     483             : #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
     484             : 
     485             : #ifndef YY_
     486             : # if defined YYENABLE_NLS && YYENABLE_NLS
     487             : #  if ENABLE_NLS
     488             : #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
     489             : #   define YY_(Msgid) dgettext ("bison-runtime", Msgid)
     490             : #  endif
     491             : # endif
     492             : # ifndef YY_
     493             : #  define YY_(Msgid) Msgid
     494             : # endif
     495             : #endif
     496             : 
     497             : #ifndef YY_ATTRIBUTE
     498             : # if (defined __GNUC__                                               \
     499             :       && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__)))  \
     500             :      || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
     501             : #  define YY_ATTRIBUTE(Spec) __attribute__(Spec)
     502             : # else
     503             : #  define YY_ATTRIBUTE(Spec) /* empty */
     504             : # endif
     505             : #endif
     506             : 
     507             : #ifndef YY_ATTRIBUTE_PURE
     508             : # define YY_ATTRIBUTE_PURE   YY_ATTRIBUTE ((__pure__))
     509             : #endif
     510             : 
     511             : #ifndef YY_ATTRIBUTE_UNUSED
     512             : # define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
     513             : #endif
     514             : 
     515             : #if !defined _Noreturn \
     516             :      && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
     517             : # if defined _MSC_VER && 1200 <= _MSC_VER
     518             : #  define _Noreturn __declspec (noreturn)
     519             : # else
     520             : #  define _Noreturn YY_ATTRIBUTE ((__noreturn__))
     521             : # endif
     522             : #endif
     523             : 
     524             : /* Suppress unused-variable warnings by "using" E.  */
     525             : #if ! defined lint || defined __GNUC__
     526             : # define YYUSE(E) ((void) (E))
     527             : #else
     528             : # define YYUSE(E) /* empty */
     529             : #endif
     530             : 
     531             : #if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
     532             : /* Suppress an incorrect diagnostic about yylval being uninitialized.  */
     533             : # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
     534             :     _Pragma ("GCC diagnostic push") \
     535             :     _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
     536             :     _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
     537             : # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
     538             :     _Pragma ("GCC diagnostic pop")
     539             : #else
     540             : # define YY_INITIAL_VALUE(Value) Value
     541             : #endif
     542             : #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
     543             : # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
     544             : # define YY_IGNORE_MAYBE_UNINITIALIZED_END
     545             : #endif
     546             : #ifndef YY_INITIAL_VALUE
     547             : # define YY_INITIAL_VALUE(Value) /* Nothing. */
     548             : #endif
     549             : 
     550             : 
     551             : #if ! defined yyoverflow || YYERROR_VERBOSE
     552             : 
     553             : /* The parser invokes alloca or malloc; define the necessary symbols.  */
     554             : 
     555             : # ifdef YYSTACK_USE_ALLOCA
     556             : #  if YYSTACK_USE_ALLOCA
     557             : #   ifdef __GNUC__
     558             : #    define YYSTACK_ALLOC __builtin_alloca
     559             : #   elif defined __BUILTIN_VA_ARG_INCR
     560             : #    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
     561             : #   elif defined _AIX
     562             : #    define YYSTACK_ALLOC __alloca
     563             : #   elif defined _MSC_VER
     564             : #    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
     565             : #    define alloca _alloca
     566             : #   else
     567             : #    define YYSTACK_ALLOC alloca
     568             : #    if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
     569             : #     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
     570             :       /* Use EXIT_SUCCESS as a witness for stdlib.h.  */
     571             : #     ifndef EXIT_SUCCESS
     572             : #      define EXIT_SUCCESS 0
     573             : #     endif
     574             : #    endif
     575             : #   endif
     576             : #  endif
     577             : # endif
     578             : 
     579             : # ifdef YYSTACK_ALLOC
     580             :    /* Pacify GCC's 'empty if-body' warning.  */
     581             : #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
     582             : #  ifndef YYSTACK_ALLOC_MAXIMUM
     583             :     /* The OS might guarantee only one guard page at the bottom of the stack,
     584             :        and a page size can be as small as 4096 bytes.  So we cannot safely
     585             :        invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
     586             :        to allow for a few compiler-allocated temporary stack slots.  */
     587             : #   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
     588             : #  endif
     589             : # else
     590             : #  define YYSTACK_ALLOC YYMALLOC
     591             : #  define YYSTACK_FREE YYFREE
     592             : #  ifndef YYSTACK_ALLOC_MAXIMUM
     593             : #   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
     594             : #  endif
     595             : #  if (defined __cplusplus && ! defined EXIT_SUCCESS \
     596             :        && ! ((defined YYMALLOC || defined malloc) \
     597             :              && (defined YYFREE || defined free)))
     598             : #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
     599             : #   ifndef EXIT_SUCCESS
     600             : #    define EXIT_SUCCESS 0
     601             : #   endif
     602             : #  endif
     603             : #  ifndef YYMALLOC
     604             : #   define YYMALLOC malloc
     605             : #   if ! defined malloc && ! defined EXIT_SUCCESS
     606             : void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
     607             : #   endif
     608             : #  endif
     609             : #  ifndef YYFREE
     610             : #   define YYFREE free
     611             : #   if ! defined free && ! defined EXIT_SUCCESS
     612             : void free (void *); /* INFRINGES ON USER NAME SPACE */
     613             : #   endif
     614             : #  endif
     615             : # endif
     616             : #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
     617             : 
     618             : 
     619             : #if (! defined yyoverflow \
     620             :      && (! defined __cplusplus \
     621             :          || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \
     622             :              && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
     623             : 
     624             : /* A type that is properly aligned for any stack member.  */
     625             : union yyalloc
     626             : {
     627             :   yytype_int16 yyss_alloc;
     628             :   YYSTYPE yyvs_alloc;
     629             :   YYLTYPE yyls_alloc;
     630             : };
     631             : 
     632             : /* The size of the maximum gap between one aligned stack and the next.  */
     633             : # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
     634             : 
     635             : /* The size of an array large to enough to hold all stacks, each with
     636             :    N elements.  */
     637             : # define YYSTACK_BYTES(N) \
     638             :      ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
     639             :       + 2 * YYSTACK_GAP_MAXIMUM)
     640             : 
     641             : # define YYCOPY_NEEDED 1
     642             : 
     643             : /* Relocate STACK from its old location to the new one.  The
     644             :    local variables YYSIZE and YYSTACKSIZE give the old and new number of
     645             :    elements in the stack, and YYPTR gives the new location of the
     646             :    stack.  Advance YYPTR to a properly aligned location for the next
     647             :    stack.  */
     648             : # define YYSTACK_RELOCATE(Stack_alloc, Stack)                           \
     649             :     do                                                                  \
     650             :       {                                                                 \
     651             :         YYSIZE_T yynewbytes;                                            \
     652             :         YYCOPY (&yyptr->Stack_alloc, Stack, yysize);                    \
     653             :         Stack = &yyptr->Stack_alloc;                                    \
     654             :         yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
     655             :         yyptr += yynewbytes / sizeof (*yyptr);                          \
     656             :       }                                                                 \
     657             :     while (0)
     658             : 
     659             : #endif
     660             : 
     661             : #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
     662             : /* Copy COUNT objects from SRC to DST.  The source and destination do
     663             :    not overlap.  */
     664             : # ifndef YYCOPY
     665             : #  if defined __GNUC__ && 1 < __GNUC__
     666             : #   define YYCOPY(Dst, Src, Count) \
     667             :       __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
     668             : #  else
     669             : #   define YYCOPY(Dst, Src, Count)              \
     670             :       do                                        \
     671             :         {                                       \
     672             :           YYSIZE_T yyi;                         \
     673             :           for (yyi = 0; yyi < (Count); yyi++)   \
     674             :             (Dst)[yyi] = (Src)[yyi];            \
     675             :         }                                       \
     676             :       while (0)
     677             : #  endif
     678             : # endif
     679             : #endif /* !YYCOPY_NEEDED */
     680             : 
     681             : /* YYFINAL -- State number of the termination state.  */
     682             : #define YYFINAL  3
     683             : /* YYLAST -- Last index in YYTABLE.  */
     684             : #define YYLAST   1465
     685             : 
     686             : /* YYNTOKENS -- Number of terminals.  */
     687             : #define YYNTOKENS  136
     688             : /* YYNNTS -- Number of nonterminals.  */
     689             : #define YYNNTS  90
     690             : /* YYNRULES -- Number of rules.  */
     691             : #define YYNRULES  258
     692             : /* YYNSTATES -- Number of states.  */
     693             : #define YYNSTATES  342
     694             : 
     695             : /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
     696             :    by yylex, with out-of-bounds checking.  */
     697             : #define YYUNDEFTOK  2
     698             : #define YYMAXUTOK   383
     699             : 
     700             : #define YYTRANSLATE(YYX)                                                \
     701             :   ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
     702             : 
     703             : /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
     704             :    as returned by yylex, without out-of-bounds checking.  */
     705             : static const yytype_uint8 yytranslate[] =
     706             : {
     707             :        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     708             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     709             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     710             :        2,     2,     2,     2,     2,   129,     2,     2,     2,     2,
     711             :      131,   132,     2,     2,   133,     2,     2,     2,     2,     2,
     712             :        2,     2,     2,     2,     2,     2,     2,     2,     2,   130,
     713             :        2,   134,     2,     2,     2,     2,     2,     2,     2,     2,
     714             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     715             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     716             :        2,   135,     2,     2,     2,     2,     2,     2,     2,     2,
     717             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     718             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     719             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     720             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     721             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     722             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     723             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     724             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     725             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     726             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     727             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     728             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     729             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     730             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     731             :        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     732             :        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
     733             :        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
     734             :       15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
     735             :       25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
     736             :       35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
     737             :       45,    46,    47,    48,    49,    50,    51,    52,    53,    54,
     738             :       55,    56,    57,    58,    59,    60,    61,    62,    63,    64,
     739             :       65,    66,    67,    68,    69,    70,    71,    72,    73,    74,
     740             :       75,    76,    77,    78,    79,    80,    81,    82,    83,    84,
     741             :       85,    86,    87,    88,    89,    90,    91,    92,    93,    94,
     742             :       95,    96,    97,    98,    99,   100,   101,   102,   103,   104,
     743             :      105,   106,   107,   108,   109,   110,   111,   112,   113,   114,
     744             :      115,   116,   117,   118,   119,   120,   121,   122,   123,   124,
     745             :      125,   126,   127,   128
     746             : };
     747             : 
     748             : #if YYDEBUG
     749             :   /* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */
     750             : static const yytype_uint16 yyrline[] =
     751             : {
     752             :        0,   363,   363,   369,   370,   373,   377,   386,   390,   394,
     753             :      400,   404,   409,   410,   413,   436,   444,   451,   460,   472,
     754             :      473,   476,   477,   481,   494,   532,   538,   537,   589,   592,
     755             :      596,   603,   609,   612,   643,   647,   653,   661,   662,   664,
     756             :      679,   694,   722,   750,   781,   782,   787,   798,   799,   804,
     757             :      809,   816,   817,   821,   823,   829,   830,   838,   839,   843,
     758             :      844,   854,   856,   858,   860,   862,   864,   866,   868,   870,
     759             :      872,   874,   876,   878,   880,   882,   884,   886,   888,   890,
     760             :      892,   894,   896,   898,   900,   902,   906,   920,   934,   951,
     761             :      966,  1029,  1032,  1036,  1042,  1046,  1052,  1065,  1109,  1120,
     762             :     1125,  1133,  1138,  1155,  1173,  1176,  1190,  1193,  1199,  1206,
     763             :     1220,  1224,  1230,  1242,  1245,  1260,  1278,  1297,  1333,  1594,
     764             :     1620,  1634,  1641,  1680,  1683,  1689,  1742,  1746,  1752,  1778,
     765             :     1923,  1947,  1965,  1969,  1973,  1983,  1995,  2059,  2137,  2167,
     766             :     2180,  2185,  2199,  2206,  2220,  2235,  2236,  2237,  2240,  2253,
     767             :     2268,  2290,  2295,  2303,  2305,  2304,  2344,  2348,  2354,  2367,
     768             :     2376,  2382,  2419,  2423,  2427,  2431,  2435,  2439,  2447,  2451,
     769             :     2459,  2462,  2469,  2471,  2478,  2482,  2486,  2495,  2496,  2497,
     770             :     2498,  2499,  2500,  2501,  2502,  2503,  2504,  2505,  2506,  2507,
     771             :     2508,  2509,  2510,  2511,  2512,  2513,  2514,  2515,  2516,  2517,
     772             :     2518,  2519,  2520,  2521,  2522,  2523,  2524,  2525,  2526,  2527,
     773             :     2528,  2529,  2530,  2531,  2532,  2533,  2534,  2535,  2536,  2537,
     774             :     2538,  2539,  2540,  2541,  2542,  2543,  2544,  2545,  2546,  2547,
     775             :     2548,  2549,  2550,  2551,  2552,  2553,  2554,  2555,  2556,  2557,
     776             :     2558,  2559,  2560,  2561,  2562,  2563,  2564,  2565,  2566,  2567,
     777             :     2568,  2569,  2570,  2571,  2572,  2573,  2574,  2575,  2576
     778             : };
     779             : #endif
     780             : 
     781             : #if YYDEBUG || YYERROR_VERBOSE || 0
     782             : /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
     783             :    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
     784             : static const char *const yytname[] =
     785             : {
     786             :   "$end", "error", "$undefined", "IDENT", "FCONST", "SCONST", "BCONST",
     787             :   "XCONST", "Op", "ICONST", "PARAM", "TYPECAST", "DOT_DOT", "COLON_EQUALS",
     788             :   "EQUALS_GREATER", "LESS_EQUALS", "GREATER_EQUALS", "NOT_EQUALS",
     789             :   "T_WORD", "T_CWORD", "T_DATUM", "LESS_LESS", "GREATER_GREATER",
     790             :   "K_ABSOLUTE", "K_ALIAS", "K_ALL", "K_AND", "K_ARRAY", "K_ASSERT",
     791             :   "K_BACKWARD", "K_BEGIN", "K_BY", "K_CALL", "K_CASE", "K_CHAIN",
     792             :   "K_CLOSE", "K_COLLATE", "K_COLUMN", "K_COLUMN_NAME", "K_COMMIT",
     793             :   "K_CONSTANT", "K_CONSTRAINT", "K_CONSTRAINT_NAME", "K_CONTINUE",
     794             :   "K_CURRENT", "K_CURSOR", "K_DATATYPE", "K_DEBUG", "K_DECLARE",
     795             :   "K_DEFAULT", "K_DETAIL", "K_DIAGNOSTICS", "K_DO", "K_DUMP", "K_ELSE",
     796             :   "K_ELSIF", "K_END", "K_ERRCODE", "K_ERROR", "K_EXCEPTION", "K_EXECUTE",
     797             :   "K_EXIT", "K_FETCH", "K_FIRST", "K_FOR", "K_FOREACH", "K_FORWARD",
     798             :   "K_FROM", "K_GET", "K_HINT", "K_IF", "K_IMPORT", "K_IN", "K_INFO",
     799             :   "K_INSERT", "K_INTO", "K_IS", "K_LAST", "K_LOG", "K_LOOP", "K_MESSAGE",
     800             :   "K_MESSAGE_TEXT", "K_MOVE", "K_NEXT", "K_NO", "K_NOT", "K_NOTICE",
     801             :   "K_NULL", "K_OPEN", "K_OPTION", "K_OR", "K_PERFORM", "K_PG_CONTEXT",
     802             :   "K_PG_DATATYPE_NAME", "K_PG_EXCEPTION_CONTEXT", "K_PG_EXCEPTION_DETAIL",
     803             :   "K_PG_EXCEPTION_HINT", "K_PRINT_STRICT_PARAMS", "K_PRIOR", "K_QUERY",
     804             :   "K_RAISE", "K_RELATIVE", "K_RESET", "K_RETURN", "K_RETURNED_SQLSTATE",
     805             :   "K_REVERSE", "K_ROLLBACK", "K_ROW_COUNT", "K_ROWTYPE", "K_SCHEMA",
     806             :   "K_SCHEMA_NAME", "K_SCROLL", "K_SET", "K_SLICE", "K_SQLSTATE",
     807             :   "K_STACKED", "K_STRICT", "K_TABLE", "K_TABLE_NAME", "K_THEN", "K_TO",
     808             :   "K_TYPE", "K_USE_COLUMN", "K_USE_VARIABLE", "K_USING",
     809             :   "K_VARIABLE_CONFLICT", "K_WARNING", "K_WHEN", "K_WHILE", "'#'", "';'",
     810             :   "'('", "')'", "','", "'='", "'['", "$accept", "pl_function",
     811             :   "comp_options", "comp_option", "option_value", "opt_semi", "pl_block",
     812             :   "decl_sect", "decl_start", "decl_stmts", "decl_stmt", "decl_statement",
     813             :   "$@1", "opt_scrollable", "decl_cursor_query", "decl_cursor_args",
     814             :   "decl_cursor_arglist", "decl_cursor_arg", "decl_is_for",
     815             :   "decl_aliasitem", "decl_varname", "decl_const", "decl_datatype",
     816             :   "decl_collate", "decl_notnull", "decl_defval", "decl_defkey",
     817             :   "assign_operator", "proc_sect", "proc_stmt", "stmt_perform", "stmt_call",
     818             :   "stmt_assign", "stmt_getdiag", "getdiag_area_opt", "getdiag_list",
     819             :   "getdiag_list_item", "getdiag_item", "getdiag_target", "assign_var",
     820             :   "stmt_if", "stmt_elsifs", "stmt_else", "stmt_case",
     821             :   "opt_expr_until_when", "case_when_list", "case_when", "opt_case_else",
     822             :   "stmt_loop", "stmt_while", "stmt_for", "for_control", "for_variable",
     823             :   "stmt_foreach_a", "foreach_slice", "stmt_exit", "exit_type",
     824             :   "stmt_return", "stmt_raise", "stmt_assert", "loop_body", "stmt_execsql",
     825             :   "stmt_dynexecute", "stmt_open", "stmt_fetch", "stmt_move",
     826             :   "opt_fetch_direction", "stmt_close", "stmt_null", "stmt_commit",
     827             :   "stmt_rollback", "opt_transaction_chain", "stmt_set", "cursor_variable",
     828             :   "exception_sect", "@2", "proc_exceptions", "proc_exception",
     829             :   "proc_conditions", "proc_condition", "expr_until_semi",
     830             :   "expr_until_rightbracket", "expr_until_then", "expr_until_loop",
     831             :   "opt_block_label", "opt_loop_label", "opt_label", "opt_exitcond",
     832             :   "any_identifier", "unreserved_keyword", YY_NULLPTR
     833             : };
     834             : #endif
     835             : 
     836             : # ifdef YYPRINT
     837             : /* YYTOKNUM[NUM] -- (External) token number corresponding to the
     838             :    (internal) symbol number NUM (which must be that of a token).  */
     839             : static const yytype_uint16 yytoknum[] =
     840             : {
     841             :        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
     842             :      265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
     843             :      275,   276,   277,   278,   279,   280,   281,   282,   283,   284,
     844             :      285,   286,   287,   288,   289,   290,   291,   292,   293,   294,
     845             :      295,   296,   297,   298,   299,   300,   301,   302,   303,   304,
     846             :      305,   306,   307,   308,   309,   310,   311,   312,   313,   314,
     847             :      315,   316,   317,   318,   319,   320,   321,   322,   323,   324,
     848             :      325,   326,   327,   328,   329,   330,   331,   332,   333,   334,
     849             :      335,   336,   337,   338,   339,   340,   341,   342,   343,   344,
     850             :      345,   346,   347,   348,   349,   350,   351,   352,   353,   354,
     851             :      355,   356,   357,   358,   359,   360,   361,   362,   363,   364,
     852             :      365,   366,   367,   368,   369,   370,   371,   372,   373,   374,
     853             :      375,   376,   377,   378,   379,   380,   381,   382,   383,    35,
     854             :       59,    40,    41,    44,    61,    91
     855             : };
     856             : # endif
     857             : 
     858             : #define YYPACT_NINF -263
     859             : 
     860             : #define yypact_value_is_default(Yystate) \
     861             :   (!!((Yystate) == (-263)))
     862             : 
     863             : #define YYTABLE_NINF -168
     864             : 
     865             : #define yytable_value_is_error(Yytable_value) \
     866             :   0
     867             : 
     868             :   /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
     869             :      STATE-NUM.  */
     870             : static const yytype_int16 yypact[] =
     871             : {
     872             :     -263,    36,   -13,  -263,   369,   -66,  -263,   -87,    21,    13,
     873             :     -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,
     874             :     -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,
     875             :     -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,
     876             :     -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,
     877             :     -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,
     878             :     -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,
     879             :     -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,
     880             :     -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,
     881             :     -263,  -263,  -263,  -263,    44,  -263,    18,   693,   -39,  -263,
     882             :     -263,  -263,  -263,   260,  -263,  -263,  -263,  -263,  -263,  -263,
     883             :     -263,  -263,  1086,  -263,   369,  -263,   260,  -263,  -263,     4,
     884             :     -263,  -263,  -263,  -263,   369,  -263,  -263,  -263,    73,    63,
     885             :     -263,  -263,  -263,  -263,  -263,  -263,   -35,  -263,  -263,  -263,
     886             :     -263,   -32,    73,  -263,  -263,  -263,  -263,    63,  -263,   -31,
     887             :     -263,  -263,  -263,  -263,  -263,   -10,  -263,  -263,  -263,  -263,
     888             :     -263,  -263,  -263,   369,  -263,  -263,  -263,  -263,  -263,  -263,
     889             :     -263,  -263,  -263,  -263,  -263,  -263,  -263,    45,   -26,    92,
     890             :     -263,    53,  -263,     7,  -263,    74,  -263,   106,     2,  -263,
     891             :     -263,  -263,     0,   -17,     1,     5,    73,  -263,  -263,    82,
     892             :     -263,    73,  -263,  -263,  -263,     6,  -263,  -263,  -263,  -263,
     893             :     -263,   -70,  -263,   369,    89,    89,  -263,  -263,  -263,   478,
     894             :     -263,  -263,    98,    10,  -263,   -52,  -263,  -263,  -263,   101,
     895             :     -263,   369,     5,  -263,    62,    93,   908,     8,  -263,  -263,
     896             :     -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,    67,
     897             :       27,  1175,  -263,  -263,  -263,  -263,    11,  -263,    12,   587,
     898             :       57,  -263,  -263,  -263,    88,  -263,   -45,  -263,  -263,  -263,
     899             :     -263,  -263,  -263,   -60,  -263,    -7,    14,    24,  -263,  -263,
     900             :     -263,  -263,   136,    75,    69,  -263,  -263,   799,   -29,  -263,
     901             :     -263,  -263,    59,    -8,    -6,  1264,   117,   369,  -263,  -263,
     902             :       93,  -263,  -263,  -263,    95,  -263,   125,   369,   -46,  -263,
     903             :     -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,  -263,
     904             :       23,  -263,   150,  -263,  -263,  1353,  -263,    84,  -263,    25,
     905             :     -263,   799,  -263,  -263,  -263,   997,    26,  -263,  -263,  -263,
     906             :     -263,  -263
     907             : };
     908             : 
     909             :   /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
     910             :      Performed when YYTABLE does not specify something else to do.  Zero
     911             :      means the default is an error.  */
     912             : static const yytype_uint16 yydefact[] =
     913             : {
     914             :        3,     0,   166,     1,     0,     0,     4,    12,     0,    15,
     915             :      174,   176,   177,   178,   179,   180,   181,   182,   183,   184,
     916             :      185,   186,   187,   188,   189,   190,   191,   192,   193,   194,
     917             :      195,   196,   197,   198,   199,   200,   201,   202,   203,   204,
     918             :      205,   206,   207,   208,   209,   210,   211,   212,   213,   214,
     919             :      215,   216,   217,   218,   219,   220,   221,   222,   223,   224,
     920             :      225,   226,   227,   228,   229,   230,   231,   232,   233,   234,
     921             :      235,   236,   237,   238,   239,   240,   241,   242,   243,   244,
     922             :      245,   246,   247,   248,   249,   250,   251,   252,   253,   254,
     923             :      255,   256,   257,   258,     0,   175,     0,     0,     0,    13,
     924             :        2,    59,    18,    16,   167,     5,    10,     6,    11,     7,
     925             :        9,     8,   168,    42,     0,    22,    17,    20,    21,    44,
     926             :       43,   134,   135,   101,     0,   130,    87,   109,     0,   147,
     927             :      127,    88,   154,   136,   126,   140,    91,   164,   132,   133,
     928             :      140,     0,     0,   162,   129,   149,   128,   147,   148,     0,
     929             :       60,    75,    76,    62,    77,     0,    63,    64,    65,    66,
     930             :       67,    68,    69,   170,    70,    71,    72,    73,    74,    78,
     931             :       79,    80,    81,    82,    83,    84,    85,     0,     0,     0,
     932             :       19,     0,    45,     0,    30,     0,    46,     0,     0,   151,
     933             :      152,   150,     0,     0,     0,     0,     0,    92,    93,     0,
     934             :       59,     0,   142,   137,    86,     0,    61,    58,    57,   163,
     935             :      162,     0,   171,   170,     0,     0,    59,   165,    23,     0,
     936             :       29,    26,    47,   169,   164,   113,   111,   141,   145,     0,
     937             :      143,     0,   155,   157,     0,     0,   168,     0,   144,   102,
     938             :       89,   162,   172,   125,    14,   120,   121,   119,    59,     0,
     939             :      123,   168,   115,    59,    39,    41,     0,    40,    32,     0,
     940             :       51,    59,    59,   110,     0,   146,     0,   160,   161,   156,
     941             :      138,    99,   100,     0,    95,     0,    98,   106,   139,   173,
     942             :      117,   118,     0,     0,     0,   116,    25,     0,     0,    48,
     943             :       50,    49,     0,     0,   168,   168,     0,     0,    59,    90,
     944             :        0,    97,    59,   164,     0,   124,     0,   170,     0,    34,
     945             :       46,    38,    37,    31,    52,    56,    53,    24,    54,    55,
     946             :        0,   159,   168,    94,    96,   168,    59,     0,   165,     0,
     947             :       33,     0,    36,    27,   108,   168,     0,    59,   131,    35,
     948             :      103,   122
     949             : };
     950             : 
     951             :   /* YYPGOTO[NTERM-NUM].  */
     952             : static const yytype_int16 yypgoto[] =
     953             : {
     954             :     -263,  -263,  -263,  -263,  -263,  -263,   155,  -263,  -263,  -263,
     955             :       42,  -263,  -263,  -263,  -263,  -263,  -263,  -172,  -263,  -263,
     956             :     -262,  -263,  -150,  -263,  -263,  -263,  -263,  -241,   -97,  -263,
     957             :     -263,  -263,  -263,  -263,  -263,  -263,  -139,  -263,  -263,  -205,
     958             :     -263,  -263,  -263,  -263,  -263,  -263,   -63,  -263,  -263,  -263,
     959             :     -263,  -263,   -49,  -263,  -263,  -263,  -263,  -263,  -263,  -263,
     960             :     -232,  -263,  -263,  -263,  -263,  -263,    32,  -263,  -263,  -263,
     961             :     -263,    20,  -263,  -124,  -263,  -263,  -263,   -59,  -263,  -123,
     962             :     -178,  -263,  -213,  -153,  -263,  -263,  -203,  -263,    -4,   -96
     963             : };
     964             : 
     965             :   /* YYDEFGOTO[NTERM-NUM].  */
     966             : static const yytype_int16 yydefgoto[] =
     967             : {
     968             :       -1,     1,     2,     6,   107,   100,   149,     8,   103,   116,
     969             :      117,   118,   258,   185,   333,   288,   308,   309,   313,   256,
     970             :      119,   186,   222,   260,   293,   317,   318,   210,   251,   150,
     971             :      151,   152,   153,   154,   199,   273,   274,   324,   275,   155,
     972             :      156,   277,   304,   157,   188,   225,   226,   264,   158,   159,
     973             :      160,   248,   249,   161,   283,   162,   163,   164,   165,   166,
     974             :      252,   167,   168,   169,   170,   171,   196,   172,   173,   174,
     975             :      175,   194,   176,   192,   177,   195,   232,   233,   266,   267,
     976             :      204,   239,   200,   253,     9,   178,   211,   243,   212,    95
     977             : };
     978             : 
     979             :   /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM.  If
     980             :      positive, shift that token.  If negative, reduce the rule whose
     981             :      number is the opposite.  If YYTABLE_NINF, syntax error.  */
     982             : static const yytype_int16 yytable[] =
     983             : {
     984             :       94,   108,   262,   207,   112,   207,   207,   120,     4,   197,
     985             :      244,   261,   121,   122,   123,   124,   280,   228,   203,   109,
     986             :      120,   285,   125,    96,  -166,   310,   126,   127,   181,   128,
     987             :      276,    97,   240,   129,   301,   311,     3,   130,   214,   215,
     988             :     -167,   315,  -166,    99,   182,   297,   131,   312,  -112,   -28,
     989             :     -112,   101,   319,   216,   133,   134,   135,   241,  -167,    98,
     990             :      242,   102,   136,   279,   137,   138,   104,   229,   139,   310,
     991             :      299,   105,   234,   300,   298,   224,   140,   237,   302,   303,
     992             :      198,   141,   142,   110,   111,   143,   330,   331,   183,   193,
     993             :      326,   189,   190,   191,   144,   276,   145,   146,   202,   206,
     994             :      147,   213,   217,   236,   329,   341,   148,   245,   246,   247,
     995             :      179,   271,   272,   123,   218,   184,     5,   219,   220,   221,
     996             :      187,  -112,   316,   257,   208,   209,   208,   208,   223,   224,
     997             :      227,   230,   231,   235,   259,   265,   238,   270,   278,   281,
     998             :      282,   286,   292,   287,   296,   305,   314,   306,   307,   209,
     999             :      320,   327,   328,   334,   336,   338,   340,     7,   180,   339,
    1000             :      332,   323,   263,   291,   294,   295,   250,   205,   121,   122,
    1001             :      123,   124,   201,   269,   321,   337,     0,     0,   125,     0,
    1002             :     -166,     0,   126,   127,     0,   128,     0,     0,     0,   129,
    1003             :        0,   120,     0,   130,     0,     0,     0,     0,  -166,     0,
    1004             :        0,   322,   131,     0,     0,   325,  -158,     0,     0,     0,
    1005             :      133,   134,   135,     0,     0,     0,     0,     0,   136,     0,
    1006             :      137,   138,     0,     0,   139,     0,     0,   268,     0,   335,
    1007             :        0,     0,   140,     0,     0,   120,     0,   141,   142,     0,
    1008             :        0,   143,     0,     0,     0,     0,     0,     0,     0,     0,
    1009             :      144,     0,   145,   146,     0,     0,   147,     0,     0,     0,
    1010             :        0,     0,   148,     0,     0,     0,     0,     0,     0,     0,
    1011             :        0,     0,     0,     0,     0,     0,     0,  -158,   113,     0,
    1012             :        0,   114,     0,    12,    13,     0,    14,    15,    16,    17,
    1013             :        0,     0,    18,   268,    19,    20,    21,    22,    23,    24,
    1014             :       25,    26,    27,    28,    29,    30,    31,    32,   115,    33,
    1015             :       34,    35,    36,    37,     0,    38,     0,    39,    40,    41,
    1016             :        0,    42,    43,    44,     0,     0,    45,     0,    46,    47,
    1017             :        0,    48,     0,    49,    50,     0,    51,    52,    53,     0,
    1018             :       54,    55,    56,    57,    58,     0,    59,     0,    60,    61,
    1019             :        0,    62,    63,    64,    65,    66,    67,    68,    69,    70,
    1020             :       71,    72,    73,    74,    75,    76,    77,    78,    79,    80,
    1021             :       81,    82,    83,    84,    85,    86,     0,    87,    88,     0,
    1022             :        0,    89,    90,    91,     0,    92,    93,    10,     0,    11,
    1023             :        0,     0,    12,    13,     0,    14,    15,    16,    17,     0,
    1024             :        0,    18,     0,    19,    20,    21,    22,    23,    24,    25,
    1025             :       26,    27,    28,    29,    30,    31,    32,     0,    33,    34,
    1026             :       35,    36,    37,     0,    38,     0,    39,    40,    41,     0,
    1027             :       42,    43,    44,     0,     0,    45,     0,    46,    47,     0,
    1028             :       48,     0,    49,    50,     0,    51,    52,    53,     0,    54,
    1029             :       55,    56,    57,    58,     0,    59,     0,    60,    61,     0,
    1030             :       62,    63,    64,    65,    66,    67,    68,    69,    70,    71,
    1031             :       72,    73,    74,    75,    76,    77,    78,    79,    80,    81,
    1032             :       82,    83,    84,    85,    86,     0,    87,    88,     0,     0,
    1033             :       89,    90,    91,     0,    92,    93,   254,   255,     0,     0,
    1034             :        0,    12,    13,     0,    14,    15,    16,    17,     0,     0,
    1035             :       18,     0,    19,    20,    21,    22,    23,    24,    25,    26,
    1036             :       27,    28,    29,    30,    31,    32,     0,    33,    34,    35,
    1037             :       36,    37,     0,    38,     0,    39,    40,    41,     0,    42,
    1038             :       43,    44,     0,     0,    45,     0,    46,    47,     0,    48,
    1039             :        0,    49,    50,     0,    51,    52,    53,     0,    54,    55,
    1040             :       56,    57,    58,     0,    59,     0,    60,    61,     0,    62,
    1041             :       63,    64,    65,    66,    67,    68,    69,    70,    71,    72,
    1042             :       73,    74,    75,    76,    77,    78,    79,    80,    81,    82,
    1043             :       83,    84,    85,    86,     0,    87,    88,     0,     0,    89,
    1044             :       90,    91,     0,    92,    93,   289,   290,     0,     0,     0,
    1045             :       12,    13,     0,    14,    15,    16,    17,     0,     0,    18,
    1046             :        0,    19,    20,    21,    22,    23,    24,    25,    26,    27,
    1047             :       28,    29,    30,    31,    32,     0,    33,    34,    35,    36,
    1048             :       37,     0,    38,     0,    39,    40,    41,     0,    42,    43,
    1049             :       44,     0,     0,    45,     0,    46,    47,     0,    48,     0,
    1050             :       49,    50,     0,    51,    52,    53,     0,    54,    55,    56,
    1051             :       57,    58,     0,    59,     0,    60,    61,     0,    62,    63,
    1052             :       64,    65,    66,    67,    68,    69,    70,    71,    72,    73,
    1053             :       74,    75,    76,    77,    78,    79,    80,    81,    82,    83,
    1054             :       84,    85,    86,     0,    87,    88,     0,     0,    89,    90,
    1055             :       91,   106,    92,    93,     0,     0,    12,    13,     0,    14,
    1056             :       15,    16,    17,     0,     0,    18,     0,    19,    20,    21,
    1057             :       22,    23,    24,    25,    26,    27,    28,    29,    30,    31,
    1058             :       32,     0,    33,    34,    35,    36,    37,     0,    38,     0,
    1059             :       39,    40,    41,     0,    42,    43,    44,     0,     0,    45,
    1060             :        0,    46,    47,     0,    48,     0,    49,    50,     0,    51,
    1061             :       52,    53,     0,    54,    55,    56,    57,    58,     0,    59,
    1062             :        0,    60,    61,     0,    62,    63,    64,    65,    66,    67,
    1063             :       68,    69,    70,    71,    72,    73,    74,    75,    76,    77,
    1064             :       78,    79,    80,    81,    82,    83,    84,    85,    86,     0,
    1065             :       87,    88,     0,     0,    89,    90,    91,   113,    92,    93,
    1066             :        0,     0,    12,    13,     0,    14,    15,    16,    17,     0,
    1067             :        0,    18,     0,    19,    20,    21,    22,    23,    24,    25,
    1068             :       26,    27,    28,    29,    30,    31,    32,     0,    33,    34,
    1069             :       35,    36,    37,     0,    38,     0,    39,    40,    41,     0,
    1070             :       42,    43,    44,     0,     0,    45,     0,    46,    47,     0,
    1071             :       48,     0,    49,    50,     0,    51,    52,    53,     0,    54,
    1072             :       55,    56,    57,    58,     0,    59,     0,    60,    61,     0,
    1073             :       62,    63,    64,    65,    66,    67,    68,    69,    70,    71,
    1074             :       72,    73,    74,    75,    76,    77,    78,    79,    80,    81,
    1075             :       82,    83,    84,    85,    86,     0,    87,    88,     0,     0,
    1076             :       89,    90,    91,     0,    92,    93,   121,   122,   123,   124,
    1077             :        0,     0,     0,     0,     0,     0,   125,     0,  -166,     0,
    1078             :      126,   127,     0,   128,     0,     0,     0,   129,     0,     0,
    1079             :        0,   130,     0,     0,     0,     0,  -166,     0,     0,     0,
    1080             :      131,     0,  -104,  -104,  -104,     0,     0,     0,   133,   134,
    1081             :      135,     0,     0,     0,     0,     0,   136,     0,   137,   138,
    1082             :        0,     0,   139,     0,     0,     0,     0,     0,     0,     0,
    1083             :      140,     0,     0,     0,     0,   141,   142,     0,     0,   143,
    1084             :        0,     0,     0,     0,     0,     0,     0,     0,   144,     0,
    1085             :      145,   146,     0,     0,   147,   121,   122,   123,   124,     0,
    1086             :      148,     0,     0,     0,     0,   125,     0,  -166,     0,   126,
    1087             :      127,     0,   128,     0,     0,     0,   129,     0,     0,     0,
    1088             :      130,     0,     0,     0,     0,  -166,     0,     0,     0,   131,
    1089             :        0,  -105,  -105,  -105,     0,     0,     0,   133,   134,   135,
    1090             :        0,     0,     0,     0,     0,   136,     0,   137,   138,     0,
    1091             :        0,   139,     0,     0,     0,     0,     0,     0,     0,   140,
    1092             :        0,     0,     0,     0,   141,   142,     0,     0,   143,     0,
    1093             :        0,     0,     0,     0,     0,     0,     0,   144,     0,   145,
    1094             :      146,     0,     0,   147,   121,   122,   123,   124,     0,   148,
    1095             :        0,     0,     0,     0,   125,     0,  -166,     0,   126,   127,
    1096             :        0,   128,     0,     0,     0,   129,     0,     0,     0,   130,
    1097             :        0,     0,     0,     0,  -166,     0,     0,     0,   131,     0,
    1098             :        0,     0,  -153,     0,     0,   132,   133,   134,   135,     0,
    1099             :        0,     0,     0,     0,   136,     0,   137,   138,     0,     0,
    1100             :      139,     0,     0,     0,     0,     0,     0,     0,   140,     0,
    1101             :        0,     0,     0,   141,   142,     0,     0,   143,     0,     0,
    1102             :        0,     0,     0,     0,     0,     0,   144,     0,   145,   146,
    1103             :        0,     0,   147,   121,   122,   123,   124,     0,   148,     0,
    1104             :        0,     0,     0,   125,     0,  -166,     0,   126,   127,     0,
    1105             :      128,     0,     0,     0,   129,     0,     0,     0,   130,     0,
    1106             :        0,     0,     0,  -166,     0,     0,     0,   131,     0,     0,
    1107             :        0,   284,     0,     0,     0,   133,   134,   135,     0,     0,
    1108             :        0,     0,     0,   136,     0,   137,   138,     0,     0,   139,
    1109             :        0,     0,     0,     0,     0,     0,     0,   140,     0,     0,
    1110             :        0,     0,   141,   142,     0,     0,   143,     0,     0,     0,
    1111             :        0,     0,     0,     0,     0,   144,     0,   145,   146,     0,
    1112             :        0,   147,   121,   122,   123,   124,     0,   148,     0,     0,
    1113             :        0,     0,   125,     0,  -166,     0,   126,   127,     0,   128,
    1114             :        0,     0,     0,   129,     0,     0,     0,   130,     0,     0,
    1115             :        0,     0,  -166,     0,     0,     0,   131,     0,     0,     0,
    1116             :     -114,     0,     0,     0,   133,   134,   135,     0,     0,     0,
    1117             :        0,     0,   136,     0,   137,   138,     0,     0,   139,     0,
    1118             :        0,     0,     0,     0,     0,     0,   140,     0,     0,     0,
    1119             :        0,   141,   142,     0,     0,   143,     0,     0,     0,     0,
    1120             :        0,     0,     0,     0,   144,     0,   145,   146,     0,     0,
    1121             :      147,   121,   122,   123,   124,     0,   148,     0,     0,     0,
    1122             :        0,   125,     0,  -166,     0,   126,   127,     0,   128,     0,
    1123             :        0,     0,   129,     0,     0,     0,   130,     0,     0,     0,
    1124             :        0,  -166,     0,     0,     0,   131,     0,     0,     0,  -107,
    1125             :        0,     0,     0,   133,   134,   135,     0,     0,     0,     0,
    1126             :        0,   136,     0,   137,   138,     0,     0,   139,     0,     0,
    1127             :        0,     0,     0,     0,     0,   140,     0,     0,     0,     0,
    1128             :      141,   142,     0,     0,   143,     0,     0,     0,     0,     0,
    1129             :        0,     0,     0,   144,     0,   145,   146,     0,     0,   147,
    1130             :        0,     0,     0,     0,     0,   148
    1131             : };
    1132             : 
    1133             : static const yytype_int16 yycheck[] =
    1134             : {
    1135             :        4,    97,    54,    13,   101,    13,    13,   103,    21,    44,
    1136             :      213,   224,    18,    19,    20,    21,   248,    34,   142,    58,
    1137             :      116,   253,    28,    89,    30,   287,    32,    33,    24,    35,
    1138             :      235,    97,   210,    39,   275,    64,     0,    43,    64,    65,
    1139             :       30,    49,    48,   130,    40,    90,    52,    76,    54,    45,
    1140             :       56,    30,   293,    79,    60,    61,    62,   127,    48,   125,
    1141             :      130,    48,    68,   241,    70,    71,    22,    84,    74,   331,
    1142             :      130,    53,   196,   133,   119,   127,    82,   201,    54,    55,
    1143             :      115,    87,    88,   122,   123,    91,   132,   133,    84,    26,
    1144             :      303,    18,    19,    20,   100,   300,   102,   103,   130,   130,
    1145             :      106,    56,   128,   200,   307,   337,   112,    18,    19,    20,
    1146             :      114,    18,    19,    20,    22,   111,   129,    64,   111,    45,
    1147             :      124,   127,   130,   219,   134,   135,   134,   134,    22,   127,
    1148             :      130,   130,   127,    51,    36,    34,   130,    75,   130,    72,
    1149             :      113,   130,    85,   131,    56,     9,    87,    72,    79,   135,
    1150             :       33,    56,    27,   130,    70,   130,   130,     2,   116,   331,
    1151             :      310,   300,   225,   259,   261,   262,   215,   147,    18,    19,
    1152             :       20,    21,   140,   232,   297,   328,    -1,    -1,    28,    -1,
    1153             :       30,    -1,    32,    33,    -1,    35,    -1,    -1,    -1,    39,
    1154             :       -1,   287,    -1,    43,    -1,    -1,    -1,    -1,    48,    -1,
    1155             :       -1,   298,    52,    -1,    -1,   302,    56,    -1,    -1,    -1,
    1156             :       60,    61,    62,    -1,    -1,    -1,    -1,    -1,    68,    -1,
    1157             :       70,    71,    -1,    -1,    74,    -1,    -1,   231,    -1,   326,
    1158             :       -1,    -1,    82,    -1,    -1,   331,    -1,    87,    88,    -1,
    1159             :       -1,    91,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
    1160             :      100,    -1,   102,   103,    -1,    -1,   106,    -1,    -1,    -1,
    1161             :       -1,    -1,   112,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
    1162             :       -1,    -1,    -1,    -1,    -1,    -1,    -1,   127,    18,    -1,
    1163             :       -1,    21,    -1,    23,    24,    -1,    26,    27,    28,    29,
    1164             :       -1,    -1,    32,   297,    34,    35,    36,    37,    38,    39,
    1165             :       40,    41,    42,    43,    44,    45,    46,    47,    48,    49,
    1166             :       50,    51,    52,    53,    -1,    55,    -1,    57,    58,    59,
    1167             :       -1,    61,    62,    63,    -1,    -1,    66,    -1,    68,    69,
    1168             :       -1,    71,    -1,    73,    74,    -1,    76,    77,    78,    -1,
    1169             :       80,    81,    82,    83,    84,    -1,    86,    -1,    88,    89,
    1170             :       -1,    91,    92,    93,    94,    95,    96,    97,    98,    99,
    1171             :      100,   101,   102,   103,   104,   105,   106,   107,   108,   109,
    1172             :      110,   111,   112,   113,   114,   115,    -1,   117,   118,    -1,
    1173             :       -1,   121,   122,   123,    -1,   125,   126,    18,    -1,    20,
    1174             :       -1,    -1,    23,    24,    -1,    26,    27,    28,    29,    -1,
    1175             :       -1,    32,    -1,    34,    35,    36,    37,    38,    39,    40,
    1176             :       41,    42,    43,    44,    45,    46,    47,    -1,    49,    50,
    1177             :       51,    52,    53,    -1,    55,    -1,    57,    58,    59,    -1,
    1178             :       61,    62,    63,    -1,    -1,    66,    -1,    68,    69,    -1,
    1179             :       71,    -1,    73,    74,    -1,    76,    77,    78,    -1,    80,
    1180             :       81,    82,    83,    84,    -1,    86,    -1,    88,    89,    -1,
    1181             :       91,    92,    93,    94,    95,    96,    97,    98,    99,   100,
    1182             :      101,   102,   103,   104,   105,   106,   107,   108,   109,   110,
    1183             :      111,   112,   113,   114,   115,    -1,   117,   118,    -1,    -1,
    1184             :      121,   122,   123,    -1,   125,   126,    18,    19,    -1,    -1,
    1185             :       -1,    23,    24,    -1,    26,    27,    28,    29,    -1,    -1,
    1186             :       32,    -1,    34,    35,    36,    37,    38,    39,    40,    41,
    1187             :       42,    43,    44,    45,    46,    47,    -1,    49,    50,    51,
    1188             :       52,    53,    -1,    55,    -1,    57,    58,    59,    -1,    61,
    1189             :       62,    63,    -1,    -1,    66,    -1,    68,    69,    -1,    71,
    1190             :       -1,    73,    74,    -1,    76,    77,    78,    -1,    80,    81,
    1191             :       82,    83,    84,    -1,    86,    -1,    88,    89,    -1,    91,
    1192             :       92,    93,    94,    95,    96,    97,    98,    99,   100,   101,
    1193             :      102,   103,   104,   105,   106,   107,   108,   109,   110,   111,
    1194             :      112,   113,   114,   115,    -1,   117,   118,    -1,    -1,   121,
    1195             :      122,   123,    -1,   125,   126,    18,    19,    -1,    -1,    -1,
    1196             :       23,    24,    -1,    26,    27,    28,    29,    -1,    -1,    32,
    1197             :       -1,    34,    35,    36,    37,    38,    39,    40,    41,    42,
    1198             :       43,    44,    45,    46,    47,    -1,    49,    50,    51,    52,
    1199             :       53,    -1,    55,    -1,    57,    58,    59,    -1,    61,    62,
    1200             :       63,    -1,    -1,    66,    -1,    68,    69,    -1,    71,    -1,
    1201             :       73,    74,    -1,    76,    77,    78,    -1,    80,    81,    82,
    1202             :       83,    84,    -1,    86,    -1,    88,    89,    -1,    91,    92,
    1203             :       93,    94,    95,    96,    97,    98,    99,   100,   101,   102,
    1204             :      103,   104,   105,   106,   107,   108,   109,   110,   111,   112,
    1205             :      113,   114,   115,    -1,   117,   118,    -1,    -1,   121,   122,
    1206             :      123,    18,   125,   126,    -1,    -1,    23,    24,    -1,    26,
    1207             :       27,    28,    29,    -1,    -1,    32,    -1,    34,    35,    36,
    1208             :       37,    38,    39,    40,    41,    42,    43,    44,    45,    46,
    1209             :       47,    -1,    49,    50,    51,    52,    53,    -1,    55,    -1,
    1210             :       57,    58,    59,    -1,    61,    62,    63,    -1,    -1,    66,
    1211             :       -1,    68,    69,    -1,    71,    -1,    73,    74,    -1,    76,
    1212             :       77,    78,    -1,    80,    81,    82,    83,    84,    -1,    86,
    1213             :       -1,    88,    89,    -1,    91,    92,    93,    94,    95,    96,
    1214             :       97,    98,    99,   100,   101,   102,   103,   104,   105,   106,
    1215             :      107,   108,   109,   110,   111,   112,   113,   114,   115,    -1,
    1216             :      117,   118,    -1,    -1,   121,   122,   123,    18,   125,   126,
    1217             :       -1,    -1,    23,    24,    -1,    26,    27,    28,    29,    -1,
    1218             :       -1,    32,    -1,    34,    35,    36,    37,    38,    39,    40,
    1219             :       41,    42,    43,    44,    45,    46,    47,    -1,    49,    50,
    1220             :       51,    52,    53,    -1,    55,    -1,    57,    58,    59,    -1,
    1221             :       61,    62,    63,    -1,    -1,    66,    -1,    68,    69,    -1,
    1222             :       71,    -1,    73,    74,    -1,    76,    77,    78,    -1,    80,
    1223             :       81,    82,    83,    84,    -1,    86,    -1,    88,    89,    -1,
    1224             :       91,    92,    93,    94,    95,    96,    97,    98,    99,   100,
    1225             :      101,   102,   103,   104,   105,   106,   107,   108,   109,   110,
    1226             :      111,   112,   113,   114,   115,    -1,   117,   118,    -1,    -1,
    1227             :      121,   122,   123,    -1,   125,   126,    18,    19,    20,    21,
    1228             :       -1,    -1,    -1,    -1,    -1,    -1,    28,    -1,    30,    -1,
    1229             :       32,    33,    -1,    35,    -1,    -1,    -1,    39,    -1,    -1,
    1230             :       -1,    43,    -1,    -1,    -1,    -1,    48,    -1,    -1,    -1,
    1231             :       52,    -1,    54,    55,    56,    -1,    -1,    -1,    60,    61,
    1232             :       62,    -1,    -1,    -1,    -1,    -1,    68,    -1,    70,    71,
    1233             :       -1,    -1,    74,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
    1234             :       82,    -1,    -1,    -1,    -1,    87,    88,    -1,    -1,    91,
    1235             :       -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,   100,    -1,
    1236             :      102,   103,    -1,    -1,   106,    18,    19,    20,    21,    -1,
    1237             :      112,    -1,    -1,    -1,    -1,    28,    -1,    30,    -1,    32,
    1238             :       33,    -1,    35,    -1,    -1,    -1,    39,    -1,    -1,    -1,
    1239             :       43,    -1,    -1,    -1,    -1,    48,    -1,    -1,    -1,    52,
    1240             :       -1,    54,    55,    56,    -1,    -1,    -1,    60,    61,    62,
    1241             :       -1,    -1,    -1,    -1,    -1,    68,    -1,    70,    71,    -1,
    1242             :       -1,    74,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    82,
    1243             :       -1,    -1,    -1,    -1,    87,    88,    -1,    -1,    91,    -1,
    1244             :       -1,    -1,    -1,    -1,    -1,    -1,    -1,   100,    -1,   102,
    1245             :      103,    -1,    -1,   106,    18,    19,    20,    21,    -1,   112,
    1246             :       -1,    -1,    -1,    -1,    28,    -1,    30,    -1,    32,    33,
    1247             :       -1,    35,    -1,    -1,    -1,    39,    -1,    -1,    -1,    43,
    1248             :       -1,    -1,    -1,    -1,    48,    -1,    -1,    -1,    52,    -1,
    1249             :       -1,    -1,    56,    -1,    -1,    59,    60,    61,    62,    -1,
    1250             :       -1,    -1,    -1,    -1,    68,    -1,    70,    71,    -1,    -1,
    1251             :       74,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    82,    -1,
    1252             :       -1,    -1,    -1,    87,    88,    -1,    -1,    91,    -1,    -1,
    1253             :       -1,    -1,    -1,    -1,    -1,    -1,   100,    -1,   102,   103,
    1254             :       -1,    -1,   106,    18,    19,    20,    21,    -1,   112,    -1,
    1255             :       -1,    -1,    -1,    28,    -1,    30,    -1,    32,    33,    -1,
    1256             :       35,    -1,    -1,    -1,    39,    -1,    -1,    -1,    43,    -1,
    1257             :       -1,    -1,    -1,    48,    -1,    -1,    -1,    52,    -1,    -1,
    1258             :       -1,    56,    -1,    -1,    -1,    60,    61,    62,    -1,    -1,
    1259             :       -1,    -1,    -1,    68,    -1,    70,    71,    -1,    -1,    74,
    1260             :       -1,    -1,    -1,    -1,    -1,    -1,    -1,    82,    -1,    -1,
    1261             :       -1,    -1,    87,    88,    -1,    -1,    91,    -1,    -1,    -1,
    1262             :       -1,    -1,    -1,    -1,    -1,   100,    -1,   102,   103,    -1,
    1263             :       -1,   106,    18,    19,    20,    21,    -1,   112,    -1,    -1,
    1264             :       -1,    -1,    28,    -1,    30,    -1,    32,    33,    -1,    35,
    1265             :       -1,    -1,    -1,    39,    -1,    -1,    -1,    43,    -1,    -1,
    1266             :       -1,    -1,    48,    -1,    -1,    -1,    52,    -1,    -1,    -1,
    1267             :       56,    -1,    -1,    -1,    60,    61,    62,    -1,    -1,    -1,
    1268             :       -1,    -1,    68,    -1,    70,    71,    -1,    -1,    74,    -1,
    1269             :       -1,    -1,    -1,    -1,    -1,    -1,    82,    -1,    -1,    -1,
    1270             :       -1,    87,    88,    -1,    -1,    91,    -1,    -1,    -1,    -1,
    1271             :       -1,    -1,    -1,    -1,   100,    -1,   102,   103,    -1,    -1,
    1272             :      106,    18,    19,    20,    21,    -1,   112,    -1,    -1,    -1,
    1273             :       -1,    28,    -1,    30,    -1,    32,    33,    -1,    35,    -1,
    1274             :       -1,    -1,    39,    -1,    -1,    -1,    43,    -1,    -1,    -1,
    1275             :       -1,    48,    -1,    -1,    -1,    52,    -1,    -1,    -1,    56,
    1276             :       -1,    -1,    -1,    60,    61,    62,    -1,    -1,    -1,    -1,
    1277             :       -1,    68,    -1,    70,    71,    -1,    -1,    74,    -1,    -1,
    1278             :       -1,    -1,    -1,    -1,    -1,    82,    -1,    -1,    -1,    -1,
    1279             :       87,    88,    -1,    -1,    91,    -1,    -1,    -1,    -1,    -1,
    1280             :       -1,    -1,    -1,   100,    -1,   102,   103,    -1,    -1,   106,
    1281             :       -1,    -1,    -1,    -1,    -1,   112
    1282             : };
    1283             : 
    1284             :   /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
    1285             :      symbol of state STATE-NUM.  */
    1286             : static const yytype_uint8 yystos[] =
    1287             : {
    1288             :        0,   137,   138,     0,    21,   129,   139,   142,   143,   220,
    1289             :       18,    20,    23,    24,    26,    27,    28,    29,    32,    34,
    1290             :       35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
    1291             :       45,    46,    47,    49,    50,    51,    52,    53,    55,    57,
    1292             :       58,    59,    61,    62,    63,    66,    68,    69,    71,    73,
    1293             :       74,    76,    77,    78,    80,    81,    82,    83,    84,    86,
    1294             :       88,    89,    91,    92,    93,    94,    95,    96,    97,    98,
    1295             :       99,   100,   101,   102,   103,   104,   105,   106,   107,   108,
    1296             :      109,   110,   111,   112,   113,   114,   115,   117,   118,   121,
    1297             :      122,   123,   125,   126,   224,   225,    89,    97,   125,   130,
    1298             :      141,    30,    48,   144,    22,    53,    18,   140,   225,    58,
    1299             :      122,   123,   164,    18,    21,    48,   145,   146,   147,   156,
    1300             :      225,    18,    19,    20,    21,    28,    32,    33,    35,    39,
    1301             :       43,    52,    59,    60,    61,    62,    68,    70,    71,    74,
    1302             :       82,    87,    88,    91,   100,   102,   103,   106,   112,   142,
    1303             :      165,   166,   167,   168,   169,   175,   176,   179,   184,   185,
    1304             :      186,   189,   191,   192,   193,   194,   195,   197,   198,   199,
    1305             :      200,   201,   203,   204,   205,   206,   208,   210,   221,   224,
    1306             :      146,    24,    40,    84,   111,   149,   157,   224,   180,    18,
    1307             :       19,    20,   209,    26,   207,   211,   202,    44,   115,   170,
    1308             :      218,   202,   130,   209,   216,   207,   130,    13,   134,   135,
    1309             :      163,   222,   224,    56,    64,    65,    79,   128,    22,    64,
    1310             :      111,    45,   158,    22,   127,   181,   182,   130,    34,    84,
    1311             :      130,   127,   212,   213,   209,    51,   164,   209,   130,   217,
    1312             :      216,   127,   130,   223,   222,    18,    19,    20,   187,   188,
    1313             :      188,   164,   196,   219,    18,    19,   155,   225,   148,    36,
    1314             :      159,   218,    54,   182,   183,    34,   214,   215,   224,   213,
    1315             :       75,    18,    19,   171,   172,   174,   175,   177,   130,   216,
    1316             :      196,    72,   113,   190,    56,   196,   130,   131,   151,    18,
    1317             :       19,   225,    85,   160,   164,   164,    56,    90,   119,   130,
    1318             :      133,   163,    54,    55,   178,     9,    72,    79,   152,   153,
    1319             :      156,    64,    76,   154,    87,    49,   130,   161,   162,   163,
    1320             :       33,   215,   164,   172,   173,   164,   218,    56,    27,   222,
    1321             :      132,   133,   158,   150,   130,   164,    70,   219,   130,   153,
    1322             :      130,   196
    1323             : };
    1324             : 
    1325             :   /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
    1326             : static const yytype_uint8 yyr1[] =
    1327             : {
    1328             :        0,   136,   137,   138,   138,   139,   139,   139,   139,   139,
    1329             :      140,   140,   141,   141,   142,   143,   143,   143,   144,   145,
    1330             :      145,   146,   146,   146,   147,   147,   148,   147,   149,   149,
    1331             :      149,   150,   151,   151,   152,   152,   153,   154,   154,   155,
    1332             :      155,   155,   156,   156,   157,   157,   158,   159,   159,   159,
    1333             :      159,   160,   160,   161,   161,   162,   162,   163,   163,   164,
    1334             :      164,   165,   165,   165,   165,   165,   165,   165,   165,   165,
    1335             :      165,   165,   165,   165,   165,   165,   165,   165,   165,   165,
    1336             :      165,   165,   165,   165,   165,   165,   166,   167,   167,   168,
    1337             :      169,   170,   170,   170,   171,   171,   172,   173,   174,   174,
    1338             :      174,   175,   175,   176,   177,   177,   178,   178,   179,   180,
    1339             :      181,   181,   182,   183,   183,   184,   185,   186,   187,   188,
    1340             :      188,   188,   189,   190,   190,   191,   192,   192,   193,   194,
    1341             :      195,   196,   197,   197,   197,   197,   198,   199,   200,   201,
    1342             :      202,   203,   204,   205,   206,   207,   207,   207,   208,   208,
    1343             :      209,   209,   209,   210,   211,   210,   212,   212,   213,   214,
    1344             :      214,   215,   216,   217,   218,   219,   220,   220,   221,   221,
    1345             :      222,   222,   223,   223,   224,   224,   224,   225,   225,   225,
    1346             :      225,   225,   225,   225,   225,   225,   225,   225,   225,   225,
    1347             :      225,   225,   225,   225,   225,   225,   225,   225,   225,   225,
    1348             :      225,   225,   225,   225,   225,   225,   225,   225,   225,   225,
    1349             :      225,   225,   225,   225,   225,   225,   225,   225,   225,   225,
    1350             :      225,   225,   225,   225,   225,   225,   225,   225,   225,   225,
    1351             :      225,   225,   225,   225,   225,   225,   225,   225,   225,   225,
    1352             :      225,   225,   225,   225,   225,   225,   225,   225,   225,   225,
    1353             :      225,   225,   225,   225,   225,   225,   225,   225,   225
    1354             : };
    1355             : 
    1356             :   /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN.  */
    1357             : static const yytype_uint8 yyr2[] =
    1358             : {
    1359             :        0,     2,     3,     0,     2,     3,     3,     3,     3,     3,
    1360             :        1,     1,     0,     1,     6,     1,     2,     3,     1,     2,
    1361             :        1,     1,     1,     3,     6,     5,     0,     7,     0,     2,
    1362             :        1,     0,     0,     3,     1,     3,     2,     1,     1,     1,
    1363             :        1,     1,     1,     1,     0,     1,     0,     0,     2,     2,
    1364             :        2,     0,     2,     1,     1,     1,     1,     1,     1,     0,
    1365             :        2,     2,     1,     1,     1,     1,     1,     1,     1,     1,
    1366             :        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
    1367             :        1,     1,     1,     1,     1,     1,     2,     1,     1,     3,
    1368             :        5,     0,     1,     1,     3,     1,     3,     0,     1,     1,
    1369             :        1,     1,     3,     8,     0,     4,     0,     2,     7,     0,
    1370             :        2,     1,     3,     0,     2,     3,     4,     4,     2,     1,
    1371             :        1,     1,     8,     0,     2,     3,     1,     1,     1,     1,
    1372             :        1,     5,     1,     1,     1,     1,     1,     2,     4,     4,
    1373             :        0,     3,     2,     3,     3,     2,     3,     0,     1,     1,
    1374             :        1,     1,     1,     0,     0,     3,     2,     1,     4,     3,
    1375             :        1,     1,     0,     0,     0,     0,     0,     3,     0,     3,
    1376             :        0,     1,     1,     2,     1,     1,     1,     1,     1,     1,
    1377             :        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
    1378             :        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
    1379             :        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
    1380             :        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
    1381             :        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
    1382             :        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
    1383             :        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
    1384             :        1,     1,     1,     1,     1,     1,     1,     1,     1
    1385             : };
    1386             : 
    1387             : 
    1388             : #define yyerrok         (yyerrstatus = 0)
    1389             : #define yyclearin       (yychar = YYEMPTY)
    1390             : #define YYEMPTY         (-2)
    1391             : #define YYEOF           0
    1392             : 
    1393             : #define YYACCEPT        goto yyacceptlab
    1394             : #define YYABORT         goto yyabortlab
    1395             : #define YYERROR         goto yyerrorlab
    1396             : 
    1397             : 
    1398             : #define YYRECOVERING()  (!!yyerrstatus)
    1399             : 
    1400             : #define YYBACKUP(Token, Value)                                  \
    1401             : do                                                              \
    1402             :   if (yychar == YYEMPTY)                                        \
    1403             :     {                                                           \
    1404             :       yychar = (Token);                                         \
    1405             :       yylval = (Value);                                         \
    1406             :       YYPOPSTACK (yylen);                                       \
    1407             :       yystate = *yyssp;                                         \
    1408             :       goto yybackup;                                            \
    1409             :     }                                                           \
    1410             :   else                                                          \
    1411             :     {                                                           \
    1412             :       yyerror (YY_("syntax error: cannot back up")); \
    1413             :       YYERROR;                                                  \
    1414             :     }                                                           \
    1415             : while (0)
    1416             : 
    1417             : /* Error token number */
    1418             : #define YYTERROR        1
    1419             : #define YYERRCODE       256
    1420             : 
    1421             : 
    1422             : /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
    1423             :    If N is 0, then set CURRENT to the empty location which ends
    1424             :    the previous symbol: RHS[0] (always defined).  */
    1425             : 
    1426             : #ifndef YYLLOC_DEFAULT
    1427             : # define YYLLOC_DEFAULT(Current, Rhs, N)                                \
    1428             :     do                                                                  \
    1429             :       if (N)                                                            \
    1430             :         {                                                               \
    1431             :           (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;        \
    1432             :           (Current).first_column = YYRHSLOC (Rhs, 1).first_column;      \
    1433             :           (Current).last_line    = YYRHSLOC (Rhs, N).last_line;         \
    1434             :           (Current).last_column  = YYRHSLOC (Rhs, N).last_column;       \
    1435             :         }                                                               \
    1436             :       else                                                              \
    1437             :         {                                                               \
    1438             :           (Current).first_line   = (Current).last_line   =              \
    1439             :             YYRHSLOC (Rhs, 0).last_line;                                \
    1440             :           (Current).first_column = (Current).last_column =              \
    1441             :             YYRHSLOC (Rhs, 0).last_column;                              \
    1442             :         }                                                               \
    1443             :     while (0)
    1444             : #endif
    1445             : 
    1446             : #define YYRHSLOC(Rhs, K) ((Rhs)[K])
    1447             : 
    1448             : 
    1449             : /* Enable debugging if requested.  */
    1450             : #if YYDEBUG
    1451             : 
    1452             : # ifndef YYFPRINTF
    1453             : #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
    1454             : #  define YYFPRINTF fprintf
    1455             : # endif
    1456             : 
    1457             : # define YYDPRINTF(Args)                        \
    1458             : do {                                            \
    1459             :   if (yydebug)                                  \
    1460             :     YYFPRINTF Args;                             \
    1461             : } while (0)
    1462             : 
    1463             : 
    1464             : /* YY_LOCATION_PRINT -- Print the location on the stream.
    1465             :    This macro was not mandated originally: define only if we know
    1466             :    we won't break user code: when these are the locations we know.  */
    1467             : 
    1468             : #ifndef YY_LOCATION_PRINT
    1469             : # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
    1470             : 
    1471             : /* Print *YYLOCP on YYO.  Private, do not rely on its existence. */
    1472             : 
    1473             : YY_ATTRIBUTE_UNUSED
    1474             : static unsigned
    1475             : yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp)
    1476             : {
    1477             :   unsigned res = 0;
    1478             :   int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
    1479             :   if (0 <= yylocp->first_line)
    1480             :     {
    1481             :       res += YYFPRINTF (yyo, "%d", yylocp->first_line);
    1482             :       if (0 <= yylocp->first_column)
    1483             :         res += YYFPRINTF (yyo, ".%d", yylocp->first_column);
    1484             :     }
    1485             :   if (0 <= yylocp->last_line)
    1486             :     {
    1487             :       if (yylocp->first_line < yylocp->last_line)
    1488             :         {
    1489             :           res += YYFPRINTF (yyo, "-%d", yylocp->last_line);
    1490             :           if (0 <= end_col)
    1491             :             res += YYFPRINTF (yyo, ".%d", end_col);
    1492             :         }
    1493             :       else if (0 <= end_col && yylocp->first_column < end_col)
    1494             :         res += YYFPRINTF (yyo, "-%d", end_col);
    1495             :     }
    1496             :   return res;
    1497             :  }
    1498             : 
    1499             : #  define YY_LOCATION_PRINT(File, Loc)          \
    1500             :   yy_location_print_ (File, &(Loc))
    1501             : 
    1502             : # else
    1503             : #  define YY_LOCATION_PRINT(File, Loc) ((void) 0)
    1504             : # endif
    1505             : #endif
    1506             : 
    1507             : 
    1508             : # define YY_SYMBOL_PRINT(Title, Type, Value, Location)                    \
    1509             : do {                                                                      \
    1510             :   if (yydebug)                                                            \
    1511             :     {                                                                     \
    1512             :       YYFPRINTF (stderr, "%s ", Title);                                   \
    1513             :       yy_symbol_print (stderr,                                            \
    1514             :                   Type, Value, Location); \
    1515             :       YYFPRINTF (stderr, "\n");                                           \
    1516             :     }                                                                     \
    1517             : } while (0)
    1518             : 
    1519             : 
    1520             : /*----------------------------------------.
    1521             : | Print this symbol's value on YYOUTPUT.  |
    1522             : `----------------------------------------*/
    1523             : 
    1524             : static void
    1525             : yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
    1526             : {
    1527             :   FILE *yyo = yyoutput;
    1528             :   YYUSE (yyo);
    1529             :   YYUSE (yylocationp);
    1530             :   if (!yyvaluep)
    1531             :     return;
    1532             : # ifdef YYPRINT
    1533             :   if (yytype < YYNTOKENS)
    1534             :     YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
    1535             : # endif
    1536             :   YYUSE (yytype);
    1537             : }
    1538             : 
    1539             : 
    1540             : /*--------------------------------.
    1541             : | Print this symbol on YYOUTPUT.  |
    1542             : `--------------------------------*/
    1543             : 
    1544             : static void
    1545             : yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp)
    1546             : {
    1547             :   YYFPRINTF (yyoutput, "%s %s (",
    1548             :              yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
    1549             : 
    1550             :   YY_LOCATION_PRINT (yyoutput, *yylocationp);
    1551             :   YYFPRINTF (yyoutput, ": ");
    1552             :   yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp);
    1553             :   YYFPRINTF (yyoutput, ")");
    1554             : }
    1555             : 
    1556             : /*------------------------------------------------------------------.
    1557             : | yy_stack_print -- Print the state stack from its BOTTOM up to its |
    1558             : | TOP (included).                                                   |
    1559             : `------------------------------------------------------------------*/
    1560             : 
    1561             : static void
    1562             : yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
    1563             : {
    1564             :   YYFPRINTF (stderr, "Stack now");
    1565             :   for (; yybottom <= yytop; yybottom++)
    1566             :     {
    1567             :       int yybot = *yybottom;
    1568             :       YYFPRINTF (stderr, " %d", yybot);
    1569             :     }
    1570             :   YYFPRINTF (stderr, "\n");
    1571             : }
    1572             : 
    1573             : # define YY_STACK_PRINT(Bottom, Top)                            \
    1574             : do {                                                            \
    1575             :   if (yydebug)                                                  \
    1576             :     yy_stack_print ((Bottom), (Top));                           \
    1577             : } while (0)
    1578             : 
    1579             : 
    1580             : /*------------------------------------------------.
    1581             : | Report that the YYRULE is going to be reduced.  |
    1582             : `------------------------------------------------*/
    1583             : 
    1584             : static void
    1585             : yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule)
    1586             : {
    1587             :   unsigned long int yylno = yyrline[yyrule];
    1588             :   int yynrhs = yyr2[yyrule];
    1589             :   int yyi;
    1590             :   YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
    1591             :              yyrule - 1, yylno);
    1592             :   /* The symbols being reduced.  */
    1593             :   for (yyi = 0; yyi < yynrhs; yyi++)
    1594             :     {
    1595             :       YYFPRINTF (stderr, "   $%d = ", yyi + 1);
    1596             :       yy_symbol_print (stderr,
    1597             :                        yystos[yyssp[yyi + 1 - yynrhs]],
    1598             :                        &(yyvsp[(yyi + 1) - (yynrhs)])
    1599             :                        , &(yylsp[(yyi + 1) - (yynrhs)])                       );
    1600             :       YYFPRINTF (stderr, "\n");
    1601             :     }
    1602             : }
    1603             : 
    1604             : # define YY_REDUCE_PRINT(Rule)          \
    1605             : do {                                    \
    1606             :   if (yydebug)                          \
    1607             :     yy_reduce_print (yyssp, yyvsp, yylsp, Rule); \
    1608             : } while (0)
    1609             : 
    1610             : /* Nonzero means print parse trace.  It is left uninitialized so that
    1611             :    multiple parsers can coexist.  */
    1612             : int yydebug;
    1613             : #else /* !YYDEBUG */
    1614             : # define YYDPRINTF(Args)
    1615             : # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
    1616             : # define YY_STACK_PRINT(Bottom, Top)
    1617             : # define YY_REDUCE_PRINT(Rule)
    1618             : #endif /* !YYDEBUG */
    1619             : 
    1620             : 
    1621             : /* YYINITDEPTH -- initial size of the parser's stacks.  */
    1622             : #ifndef YYINITDEPTH
    1623             : # define YYINITDEPTH 200
    1624             : #endif
    1625             : 
    1626             : /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
    1627             :    if the built-in stack extension method is used).
    1628             : 
    1629             :    Do not make this value too large; the results are undefined if
    1630             :    YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
    1631             :    evaluated with infinite-precision integer arithmetic.  */
    1632             : 
    1633             : #ifndef YYMAXDEPTH
    1634             : # define YYMAXDEPTH 10000
    1635             : #endif
    1636             : 
    1637             : 
    1638             : #if YYERROR_VERBOSE
    1639             : 
    1640             : # ifndef yystrlen
    1641             : #  if defined __GLIBC__ && defined _STRING_H
    1642             : #   define yystrlen strlen
    1643             : #  else
    1644             : /* Return the length of YYSTR.  */
    1645             : static YYSIZE_T
    1646             : yystrlen (const char *yystr)
    1647             : {
    1648             :   YYSIZE_T yylen;
    1649             :   for (yylen = 0; yystr[yylen]; yylen++)
    1650             :     continue;
    1651             :   return yylen;
    1652             : }
    1653             : #  endif
    1654             : # endif
    1655             : 
    1656             : # ifndef yystpcpy
    1657             : #  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
    1658             : #   define yystpcpy stpcpy
    1659             : #  else
    1660             : /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
    1661             :    YYDEST.  */
    1662             : static char *
    1663             : yystpcpy (char *yydest, const char *yysrc)
    1664             : {
    1665             :   char *yyd = yydest;
    1666             :   const char *yys = yysrc;
    1667             : 
    1668             :   while ((*yyd++ = *yys++) != '\0')
    1669             :     continue;
    1670             : 
    1671             :   return yyd - 1;
    1672             : }
    1673             : #  endif
    1674             : # endif
    1675             : 
    1676             : # ifndef yytnamerr
    1677             : /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
    1678             :    quotes and backslashes, so that it's suitable for yyerror.  The
    1679             :    heuristic is that double-quoting is unnecessary unless the string
    1680             :    contains an apostrophe, a comma, or backslash (other than
    1681             :    backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
    1682             :    null, do not copy; instead, return the length of what the result
    1683             :    would have been.  */
    1684             : static YYSIZE_T
    1685             : yytnamerr (char *yyres, const char *yystr)
    1686             : {
    1687             :   if (*yystr == '"')
    1688             :     {
    1689             :       YYSIZE_T yyn = 0;
    1690             :       char const *yyp = yystr;
    1691             : 
    1692             :       for (;;)
    1693             :         switch (*++yyp)
    1694             :           {
    1695             :           case '\'':
    1696             :           case ',':
    1697             :             goto do_not_strip_quotes;
    1698             : 
    1699             :           case '\\':
    1700             :             if (*++yyp != '\\')
    1701             :               goto do_not_strip_quotes;
    1702             :             /* Fall through.  */
    1703             :           default:
    1704             :             if (yyres)
    1705             :               yyres[yyn] = *yyp;
    1706             :             yyn++;
    1707             :             break;
    1708             : 
    1709             :           case '"':
    1710             :             if (yyres)
    1711             :               yyres[yyn] = '\0';
    1712             :             return yyn;
    1713             :           }
    1714             :     do_not_strip_quotes: ;
    1715             :     }
    1716             : 
    1717             :   if (! yyres)
    1718             :     return yystrlen (yystr);
    1719             : 
    1720             :   return yystpcpy (yyres, yystr) - yyres;
    1721             : }
    1722             : # endif
    1723             : 
    1724             : /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
    1725             :    about the unexpected token YYTOKEN for the state stack whose top is
    1726             :    YYSSP.
    1727             : 
    1728             :    Return 0 if *YYMSG was successfully written.  Return 1 if *YYMSG is
    1729             :    not large enough to hold the message.  In that case, also set
    1730             :    *YYMSG_ALLOC to the required number of bytes.  Return 2 if the
    1731             :    required number of bytes is too large to store.  */
    1732             : static int
    1733             : yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
    1734             :                 yytype_int16 *yyssp, int yytoken)
    1735             : {
    1736             :   YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
    1737             :   YYSIZE_T yysize = yysize0;
    1738             :   enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
    1739             :   /* Internationalized format string. */
    1740             :   const char *yyformat = YY_NULLPTR;
    1741             :   /* Arguments of yyformat. */
    1742             :   char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
    1743             :   /* Number of reported tokens (one for the "unexpected", one per
    1744             :      "expected"). */
    1745             :   int yycount = 0;
    1746             : 
    1747             :   /* There are many possibilities here to consider:
    1748             :      - If this state is a consistent state with a default action, then
    1749             :        the only way this function was invoked is if the default action
    1750             :        is an error action.  In that case, don't check for expected
    1751             :        tokens because there are none.
    1752             :      - The only way there can be no lookahead present (in yychar) is if
    1753             :        this state is a consistent state with a default action.  Thus,
    1754             :        detecting the absence of a lookahead is sufficient to determine
    1755             :        that there is no unexpected or expected token to report.  In that
    1756             :        case, just report a simple "syntax error".
    1757             :      - Don't assume there isn't a lookahead just because this state is a
    1758             :        consistent state with a default action.  There might have been a
    1759             :        previous inconsistent state, consistent state with a non-default
    1760             :        action, or user semantic action that manipulated yychar.
    1761             :      - Of course, the expected token list depends on states to have
    1762             :        correct lookahead information, and it depends on the parser not
    1763             :        to perform extra reductions after fetching a lookahead from the
    1764             :        scanner and before detecting a syntax error.  Thus, state merging
    1765             :        (from LALR or IELR) and default reductions corrupt the expected
    1766             :        token list.  However, the list is correct for canonical LR with
    1767             :        one exception: it will still contain any token that will not be
    1768             :        accepted due to an error action in a later state.
    1769             :   */
    1770             :   if (yytoken != YYEMPTY)
    1771             :     {
    1772             :       int yyn = yypact[*yyssp];
    1773             :       yyarg[yycount++] = yytname[yytoken];
    1774             :       if (!yypact_value_is_default (yyn))
    1775             :         {
    1776             :           /* Start YYX at -YYN if negative to avoid negative indexes in
    1777             :              YYCHECK.  In other words, skip the first -YYN actions for
    1778             :              this state because they are default actions.  */
    1779             :           int yyxbegin = yyn < 0 ? -yyn : 0;
    1780             :           /* Stay within bounds of both yycheck and yytname.  */
    1781             :           int yychecklim = YYLAST - yyn + 1;
    1782             :           int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
    1783             :           int yyx;
    1784             : 
    1785             :           for (yyx = yyxbegin; yyx < yyxend; ++yyx)
    1786             :             if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
    1787             :                 && !yytable_value_is_error (yytable[yyx + yyn]))
    1788             :               {
    1789             :                 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
    1790             :                   {
    1791             :                     yycount = 1;
    1792             :                     yysize = yysize0;
    1793             :                     break;
    1794             :                   }
    1795             :                 yyarg[yycount++] = yytname[yyx];
    1796             :                 {
    1797             :                   YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
    1798             :                   if (! (yysize <= yysize1
    1799             :                          && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
    1800             :                     return 2;
    1801             :                   yysize = yysize1;
    1802             :                 }
    1803             :               }
    1804             :         }
    1805             :     }
    1806             : 
    1807             :   switch (yycount)
    1808             :     {
    1809             : # define YYCASE_(N, S)                      \
    1810             :       case N:                               \
    1811             :         yyformat = S;                       \
    1812             :       break
    1813             :       YYCASE_(0, YY_("syntax error"));
    1814             :       YYCASE_(1, YY_("syntax error, unexpected %s"));
    1815             :       YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
    1816             :       YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
    1817             :       YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
    1818             :       YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
    1819             : # undef YYCASE_
    1820             :     }
    1821             : 
    1822             :   {
    1823             :     YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
    1824             :     if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
    1825             :       return 2;
    1826             :     yysize = yysize1;
    1827             :   }
    1828             : 
    1829             :   if (*yymsg_alloc < yysize)
    1830             :     {
    1831             :       *yymsg_alloc = 2 * yysize;
    1832             :       if (! (yysize <= *yymsg_alloc
    1833             :              && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
    1834             :         *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
    1835             :       return 1;
    1836             :     }
    1837             : 
    1838             :   /* Avoid sprintf, as that infringes on the user's name space.
    1839             :      Don't have undefined behavior even if the translation
    1840             :      produced a string with the wrong number of "%s"s.  */
    1841             :   {
    1842             :     char *yyp = *yymsg;
    1843             :     int yyi = 0;
    1844             :     while ((*yyp = *yyformat) != '\0')
    1845             :       if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
    1846             :         {
    1847             :           yyp += yytnamerr (yyp, yyarg[yyi++]);
    1848             :           yyformat += 2;
    1849             :         }
    1850             :       else
    1851             :         {
    1852             :           yyp++;
    1853             :           yyformat++;
    1854             :         }
    1855             :   }
    1856             :   return 0;
    1857             : }
    1858             : #endif /* YYERROR_VERBOSE */
    1859             : 
    1860             : /*-----------------------------------------------.
    1861             : | Release the memory associated to this symbol.  |
    1862             : `-----------------------------------------------*/
    1863             : 
    1864             : static void
    1865        7152 : yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp)
    1866             : {
    1867             :   YYUSE (yyvaluep);
    1868             :   YYUSE (yylocationp);
    1869        7152 :   if (!yymsg)
    1870           0 :     yymsg = "Deleting";
    1871             :   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
    1872             : 
    1873             :   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
    1874             :   YYUSE (yytype);
    1875             :   YY_IGNORE_MAYBE_UNINITIALIZED_END
    1876        7152 : }
    1877             : 
    1878             : 
    1879             : 
    1880             : 
    1881             : /* The lookahead symbol.  */
    1882             : int yychar;
    1883             : 
    1884             : /* The semantic value of the lookahead symbol.  */
    1885             : YYSTYPE yylval;
    1886             : /* Location data for the lookahead symbol.  */
    1887             : YYLTYPE yylloc
    1888             : # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
    1889             :   = { 1, 1, 1, 1 }
    1890             : # endif
    1891             : ;
    1892             : /* Number of syntax errors so far.  */
    1893             : int yynerrs;
    1894             : 
    1895             : 
    1896             : /*----------.
    1897             : | yyparse.  |
    1898             : `----------*/
    1899             : 
    1900             : int
    1901        3672 : yyparse (void)
    1902             : {
    1903             :     int yystate;
    1904             :     /* Number of tokens to shift before error messages enabled.  */
    1905             :     int yyerrstatus;
    1906             : 
    1907             :     /* The stacks and their tools:
    1908             :        'yyss': related to states.
    1909             :        'yyvs': related to semantic values.
    1910             :        'yyls': related to locations.
    1911             : 
    1912             :        Refer to the stacks through separate pointers, to allow yyoverflow
    1913             :        to reallocate them elsewhere.  */
    1914             : 
    1915             :     /* The state stack.  */
    1916             :     yytype_int16 yyssa[YYINITDEPTH];
    1917             :     yytype_int16 *yyss;
    1918             :     yytype_int16 *yyssp;
    1919             : 
    1920             :     /* The semantic value stack.  */
    1921             :     YYSTYPE yyvsa[YYINITDEPTH];
    1922             :     YYSTYPE *yyvs;
    1923             :     YYSTYPE *yyvsp;
    1924             : 
    1925             :     /* The location stack.  */
    1926             :     YYLTYPE yylsa[YYINITDEPTH];
    1927             :     YYLTYPE *yyls;
    1928             :     YYLTYPE *yylsp;
    1929             : 
    1930             :     /* The locations where the error started and ended.  */
    1931             :     YYLTYPE yyerror_range[3];
    1932             : 
    1933             :     YYSIZE_T yystacksize;
    1934             : 
    1935             :   int yyn;
    1936             :   int yyresult;
    1937             :   /* Lookahead token as an internal (translated) token number.  */
    1938        3672 :   int yytoken = 0;
    1939             :   /* The variables used to return semantic value and location from the
    1940             :      action routines.  */
    1941             :   YYSTYPE yyval;
    1942             :   YYLTYPE yyloc;
    1943             : 
    1944             : #if YYERROR_VERBOSE
    1945             :   /* Buffer for error messages, and its allocated size.  */
    1946             :   char yymsgbuf[128];
    1947             :   char *yymsg = yymsgbuf;
    1948             :   YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
    1949             : #endif
    1950             : 
    1951             : #define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N), yylsp -= (N))
    1952             : 
    1953             :   /* The number of symbols on the RHS of the reduced rule.
    1954             :      Keep to zero when no symbol should be popped.  */
    1955        3672 :   int yylen = 0;
    1956             : 
    1957        3672 :   yyssp = yyss = yyssa;
    1958        3672 :   yyvsp = yyvs = yyvsa;
    1959        3672 :   yylsp = yyls = yylsa;
    1960        3672 :   yystacksize = YYINITDEPTH;
    1961             : 
    1962             :   YYDPRINTF ((stderr, "Starting parse\n"));
    1963             : 
    1964        3672 :   yystate = 0;
    1965        3672 :   yyerrstatus = 0;
    1966        3672 :   yynerrs = 0;
    1967        3672 :   yychar = YYEMPTY; /* Cause a token to be read.  */
    1968        3672 :   yylsp[0] = yylloc;
    1969        3672 :   goto yysetstate;
    1970             : 
    1971             : /*------------------------------------------------------------.
    1972             : | yynewstate -- Push a new state, which is found in yystate.  |
    1973             : `------------------------------------------------------------*/
    1974             :  yynewstate:
    1975             :   /* In all cases, when you get here, the value and location stacks
    1976             :      have just been pushed.  So pushing a state here evens the stacks.  */
    1977      175654 :   yyssp++;
    1978             : 
    1979             :  yysetstate:
    1980      179326 :   *yyssp = yystate;
    1981             : 
    1982      179326 :   if (yyss + yystacksize - 1 <= yyssp)
    1983             :     {
    1984             :       /* Get the current used size of the three stacks, in elements.  */
    1985           0 :       YYSIZE_T yysize = yyssp - yyss + 1;
    1986             : 
    1987             : #ifdef yyoverflow
    1988             :       {
    1989             :         /* Give user a chance to reallocate the stack.  Use copies of
    1990             :            these so that the &'s don't force the real ones into
    1991             :            memory.  */
    1992             :         YYSTYPE *yyvs1 = yyvs;
    1993             :         yytype_int16 *yyss1 = yyss;
    1994             :         YYLTYPE *yyls1 = yyls;
    1995             : 
    1996             :         /* Each stack pointer address is followed by the size of the
    1997             :            data in use in that stack, in bytes.  This used to be a
    1998             :            conditional around just the two extra args, but that might
    1999             :            be undefined if yyoverflow is a macro.  */
    2000             :         yyoverflow (YY_("memory exhausted"),
    2001             :                     &yyss1, yysize * sizeof (*yyssp),
    2002             :                     &yyvs1, yysize * sizeof (*yyvsp),
    2003             :                     &yyls1, yysize * sizeof (*yylsp),
    2004             :                     &yystacksize);
    2005             : 
    2006             :         yyls = yyls1;
    2007             :         yyss = yyss1;
    2008             :         yyvs = yyvs1;
    2009             :       }
    2010             : #else /* no yyoverflow */
    2011             : # ifndef YYSTACK_RELOCATE
    2012             :       goto yyexhaustedlab;
    2013             : # else
    2014             :       /* Extend the stack our own way.  */
    2015           0 :       if (YYMAXDEPTH <= yystacksize)
    2016           0 :         goto yyexhaustedlab;
    2017           0 :       yystacksize *= 2;
    2018           0 :       if (YYMAXDEPTH < yystacksize)
    2019           0 :         yystacksize = YYMAXDEPTH;
    2020             : 
    2021             :       {
    2022           0 :         yytype_int16 *yyss1 = yyss;
    2023           0 :         union yyalloc *yyptr =
    2024           0 :           (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
    2025           0 :         if (! yyptr)
    2026           0 :           goto yyexhaustedlab;
    2027           0 :         YYSTACK_RELOCATE (yyss_alloc, yyss);
    2028           0 :         YYSTACK_RELOCATE (yyvs_alloc, yyvs);
    2029           0 :         YYSTACK_RELOCATE (yyls_alloc, yyls);
    2030             : #  undef YYSTACK_RELOCATE
    2031           0 :         if (yyss1 != yyssa)
    2032           0 :           YYSTACK_FREE (yyss1);
    2033             :       }
    2034             : # endif
    2035             : #endif /* no yyoverflow */
    2036             : 
    2037           0 :       yyssp = yyss + yysize - 1;
    2038           0 :       yyvsp = yyvs + yysize - 1;
    2039           0 :       yylsp = yyls + yysize - 1;
    2040             : 
    2041             :       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
    2042             :                   (unsigned long int) yystacksize));
    2043             : 
    2044           0 :       if (yyss + yystacksize - 1 <= yyssp)
    2045           0 :         YYABORT;
    2046             :     }
    2047             : 
    2048             :   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
    2049             : 
    2050      179326 :   if (yystate == YYFINAL)
    2051        3576 :     YYACCEPT;
    2052             : 
    2053      175750 :   goto yybackup;
    2054             : 
    2055             : /*-----------.
    2056             : | yybackup.  |
    2057             : `-----------*/
    2058             : yybackup:
    2059             : 
    2060             :   /* Do appropriate processing given the current state.  Read a
    2061             :      lookahead token if we need one and don't already have one.  */
    2062             : 
    2063             :   /* First try to decide what to do without reference to lookahead token.  */
    2064      175750 :   yyn = yypact[yystate];
    2065      175750 :   if (yypact_value_is_default (yyn))
    2066       95146 :     goto yydefault;
    2067             : 
    2068             :   /* Not known => get a lookahead token if don't already have one.  */
    2069             : 
    2070             :   /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
    2071       80604 :   if (yychar == YYEMPTY)
    2072             :     {
    2073             :       YYDPRINTF ((stderr, "Reading a token: "));
    2074       52762 :       yychar = yylex ();
    2075             :     }
    2076             : 
    2077       80604 :   if (yychar <= YYEOF)
    2078             :     {
    2079        5876 :       yychar = yytoken = YYEOF;
    2080             :       YYDPRINTF ((stderr, "Now at end of input.\n"));
    2081             :     }
    2082             :   else
    2083             :     {
    2084       74728 :       yytoken = YYTRANSLATE (yychar);
    2085             :       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
    2086             :     }
    2087             : 
    2088             :   /* If the proper action on seeing token YYTOKEN is to reduce or to
    2089             :      detect an error, take that action.  */
    2090       80604 :   yyn += yytoken;
    2091       80604 :   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
    2092             :     goto yydefault;
    2093       57656 :   yyn = yytable[yyn];
    2094       57656 :   if (yyn <= 0)
    2095             :     {
    2096             :       if (yytable_value_is_error (yyn))
    2097             :         goto yyerrlab;
    2098        7058 :       yyn = -yyn;
    2099        7058 :       goto yyreduce;
    2100             :     }
    2101             : 
    2102             :   /* Count tokens shifted since error; after three, turn off error
    2103             :      status.  */
    2104       50598 :   if (yyerrstatus)
    2105           0 :     yyerrstatus--;
    2106             : 
    2107             :   /* Shift the lookahead token.  */
    2108             :   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
    2109             : 
    2110             :   /* Discard the shifted token.  */
    2111       50598 :   yychar = YYEMPTY;
    2112             : 
    2113       50598 :   yystate = yyn;
    2114             :   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
    2115       50598 :   *++yyvsp = yylval;
    2116             :   YY_IGNORE_MAYBE_UNINITIALIZED_END
    2117       50598 :   *++yylsp = yylloc;
    2118       50598 :   goto yynewstate;
    2119             : 
    2120             : 
    2121             : /*-----------------------------------------------------------.
    2122             : | yydefault -- do the default action for the current state.  |
    2123             : `-----------------------------------------------------------*/
    2124             : yydefault:
    2125      118094 :   yyn = yydefact[yystate];
    2126      118094 :   if (yyn == 0)
    2127           2 :     goto yyerrlab;
    2128      118092 :   goto yyreduce;
    2129             : 
    2130             : 
    2131             : /*-----------------------------.
    2132             : | yyreduce -- Do a reduction.  |
    2133             : `-----------------------------*/
    2134             : yyreduce:
    2135             :   /* yyn is the number of a rule to reduce with.  */
    2136      125150 :   yylen = yyr2[yyn];
    2137             : 
    2138             :   /* If YYLEN is nonzero, implement the default value of the action:
    2139             :      '$$ = $1'.
    2140             : 
    2141             :      Otherwise, the following line sets YYVAL to garbage.
    2142             :      This behavior is undocumented and Bison
    2143             :      users should not rely upon it.  Assigning to YYVAL
    2144             :      unconditionally makes the parser a bit smaller, and it avoids a
    2145             :      GCC warning that YYVAL may be used uninitialized.  */
    2146      125150 :   yyval = yyvsp[1-yylen];
    2147             : 
    2148             :   /* Default location.  */
    2149      125150 :   YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
    2150             :   YY_REDUCE_PRINT (yyn);
    2151      125150 :   switch (yyn)
    2152             :     {
    2153             :         case 2:
    2154             : #line 364 "pl_gram.y" /* yacc.c:1646  */
    2155             :     {
    2156             :                         plpgsql_parse_result = (PLpgSQL_stmt_block *) (yyvsp[-1].stmt);
    2157             :                     }
    2158             : #line 2159 "pl_gram.c" /* yacc.c:1646  */
    2159        3576 :     break;
    2160             : 
    2161             :   case 5:
    2162             : #line 374 "pl_gram.y" /* yacc.c:1646  */
    2163             :     {
    2164             :                         plpgsql_DumpExecTree = true;
    2165             :                     }
    2166             : #line 2167 "pl_gram.c" /* yacc.c:1646  */
    2167           0 :     break;
    2168             : 
    2169             :   case 6:
    2170             : #line 378 "pl_gram.y" /* yacc.c:1646  */
    2171             :     {
    2172             :                         if (strcmp((yyvsp[0].str), "on") == 0)
    2173             :                             plpgsql_curr_compile->print_strict_params = true;
    2174             :                         else if (strcmp((yyvsp[0].str), "off") == 0)
    2175             :                             plpgsql_curr_compile->print_strict_params = false;
    2176             :                         else
    2177             :                             elog(ERROR, "unrecognized print_strict_params option %s", (yyvsp[0].str));
    2178             :                     }
    2179             : #line 2180 "pl_gram.c" /* yacc.c:1646  */
    2180           8 :     break;
    2181             : 
    2182             :   case 7:
    2183             : #line 387 "pl_gram.y" /* yacc.c:1646  */
    2184             :     {
    2185             :                         plpgsql_curr_compile->resolve_option = PLPGSQL_RESOLVE_ERROR;
    2186             :                     }
    2187             : #line 2188 "pl_gram.c" /* yacc.c:1646  */
    2188           0 :     break;
    2189             : 
    2190             :   case 8:
    2191             : #line 391 "pl_gram.y" /* yacc.c:1646  */
    2192             :     {
    2193             :                         plpgsql_curr_compile->resolve_option = PLPGSQL_RESOLVE_VARIABLE;
    2194             :                     }
    2195             : #line 2196 "pl_gram.c" /* yacc.c:1646  */
    2196           4 :     break;
    2197             : 
    2198             :   case 9:
    2199             : #line 395 "pl_gram.y" /* yacc.c:1646  */
    2200             :     {
    2201             :                         plpgsql_curr_compile->resolve_option = PLPGSQL_RESOLVE_COLUMN;
    2202             :                     }
    2203             : #line 2204 "pl_gram.c" /* yacc.c:1646  */
    2204           4 :     break;
    2205             : 
    2206             :   case 10:
    2207             : #line 401 "pl_gram.y" /* yacc.c:1646  */
    2208             :     {
    2209             :                     (yyval.str) = (yyvsp[0].word).ident;
    2210             :                 }
    2211             : #line 2212 "pl_gram.c" /* yacc.c:1646  */
    2212           8 :     break;
    2213             : 
    2214             :   case 11:
    2215             : #line 405 "pl_gram.y" /* yacc.c:1646  */
    2216             :     {
    2217             :                     (yyval.str) = pstrdup((yyvsp[0].keyword));
    2218             :                 }
    2219             : #line 2220 "pl_gram.c" /* yacc.c:1646  */
    2220           0 :     break;
    2221             : 
    2222             :   case 14:
    2223             : #line 414 "pl_gram.y" /* yacc.c:1646  */
    2224             :     {
    2225             :                         PLpgSQL_stmt_block *new;
    2226             : 
    2227             :                         new = palloc0(sizeof(PLpgSQL_stmt_block));
    2228             : 
    2229             :                         new->cmd_type    = PLPGSQL_STMT_BLOCK;
    2230             :                         new->lineno      = plpgsql_location_to_lineno((yylsp[-4]));
    2231             :                         new->stmtid      = ++plpgsql_curr_compile->nstatements;
    2232             :                         new->label       = (yyvsp[-5].declhdr).label;
    2233             :                         new->n_initvars = (yyvsp[-5].declhdr).n_initvars;
    2234             :                         new->initvarnos = (yyvsp[-5].declhdr).initvarnos;
    2235             :                         new->body        = (yyvsp[-3].list);
    2236             :                         new->exceptions  = (yyvsp[-2].exception_block);
    2237             : 
    2238             :                         check_labels((yyvsp[-5].declhdr).label, (yyvsp[0].str), (yylsp[0]));
    2239             :                         plpgsql_ns_pop();
    2240             : 
    2241             :                         (yyval.stmt) = (PLpgSQL_stmt *)new;
    2242             :                     }
    2243             : #line 2244 "pl_gram.c" /* yacc.c:1646  */
    2244        3710 :     break;
    2245             : 
    2246             :   case 15:
    2247             : #line 437 "pl_gram.y" /* yacc.c:1646  */
    2248             :     {
    2249             :                         /* done with decls, so resume identifier lookup */
    2250             :                         plpgsql_IdentifierLookup = IDENTIFIER_LOOKUP_NORMAL;
    2251             :                         (yyval.declhdr).label     = (yyvsp[0].str);
    2252             :                         (yyval.declhdr).n_initvars = 0;
    2253             :                         (yyval.declhdr).initvarnos = NULL;
    2254             :                     }
    2255             : #line 2256 "pl_gram.c" /* yacc.c:1646  */
    2256        2456 :     break;
    2257             : 
    2258             :   case 16:
    2259             : #line 445 "pl_gram.y" /* yacc.c:1646  */
    2260             :     {
    2261             :                         plpgsql_IdentifierLookup = IDENTIFIER_LOOKUP_NORMAL;
    2262             :                         (yyval.declhdr).label     = (yyvsp[-1].str);
    2263             :                         (yyval.declhdr).n_initvars = 0;
    2264             :                         (yyval.declhdr).initvarnos = NULL;
    2265             :                     }
    2266             : #line 2267 "pl_gram.c" /* yacc.c:1646  */
    2267           4 :     break;
    2268             : 
    2269             :   case 17:
    2270             : #line 452 "pl_gram.y" /* yacc.c:1646  */
    2271             :     {
    2272             :                         plpgsql_IdentifierLookup = IDENTIFIER_LOOKUP_NORMAL;
    2273             :                         (yyval.declhdr).label     = (yyvsp[-2].str);
    2274             :                         /* Remember variables declared in decl_stmts */
    2275             :                         (yyval.declhdr).n_initvars = plpgsql_add_initdatums(&((yyval.declhdr).initvarnos));
    2276             :                     }
    2277             : #line 2278 "pl_gram.c" /* yacc.c:1646  */
    2278        1346 :     break;
    2279             : 
    2280             :   case 18:
    2281             : #line 461 "pl_gram.y" /* yacc.c:1646  */
    2282             :     {
    2283             :                         /* Forget any variables created before block */
    2284             :                         plpgsql_add_initdatums(NULL);
    2285             :                         /*
    2286             :                          * Disable scanner lookup of identifiers while
    2287             :                          * we process the decl_stmts
    2288             :                          */
    2289             :                         plpgsql_IdentifierLookup = IDENTIFIER_LOOKUP_DECLARE;
    2290             :                     }
    2291             : #line 2292 "pl_gram.c" /* yacc.c:1646  */
    2292        1360 :     break;
    2293             : 
    2294             :   case 22:
    2295             : #line 478 "pl_gram.y" /* yacc.c:1646  */
    2296             :     {
    2297             :                         /* We allow useless extra DECLAREs */
    2298             :                     }
    2299             : #line 2300 "pl_gram.c" /* yacc.c:1646  */
    2300           0 :     break;
    2301             : 
    2302             :   case 23:
    2303             : #line 482 "pl_gram.y" /* yacc.c:1646  */
    2304             :     {
    2305             :                         /*
    2306             :                          * Throw a helpful error if user tries to put block
    2307             :                          * label just before BEGIN, instead of before DECLARE.
    2308             :                          */
    2309             :                         ereport(ERROR,
    2310             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    2311             :                                  errmsg("block label must be placed before DECLARE, not after"),
    2312             :                                  parser_errposition((yylsp[-2]))));
    2313             :                     }
    2314             : #line 2315 "pl_gram.c" /* yacc.c:1646  */
    2315             :     break;
    2316             : 
    2317             :   case 24:
    2318             : #line 495 "pl_gram.y" /* yacc.c:1646  */
    2319             :     {
    2320             :                         PLpgSQL_variable    *var;
    2321             : 
    2322             :                         /*
    2323             :                          * If a collation is supplied, insert it into the
    2324             :                          * datatype.  We assume decl_datatype always returns
    2325             :                          * a freshly built struct not shared with other
    2326             :                          * variables.
    2327             :                          */
    2328             :                         if (OidIsValid((yyvsp[-2].oid)))
    2329             :                         {
    2330             :                             if (!OidIsValid((yyvsp[-3].dtype)->collation))
    2331             :                                 ereport(ERROR,
    2332             :                                         (errcode(ERRCODE_DATATYPE_MISMATCH),
    2333             :                                          errmsg("collations are not supported by type %s",
    2334             :                                                 format_type_be((yyvsp[-3].dtype)->typoid)),
    2335             :                                          parser_errposition((yylsp[-2]))));
    2336             :                             (yyvsp[-3].dtype)->collation = (yyvsp[-2].oid);
    2337             :                         }
    2338             : 
    2339             :                         var = plpgsql_build_variable((yyvsp[-5].varname).name, (yyvsp[-5].varname).lineno,
    2340             :                                                      (yyvsp[-3].dtype), true);
    2341             :                         var->isconst = (yyvsp[-4].boolean);
    2342             :                         var->notnull = (yyvsp[-1].boolean);
    2343             :                         var->default_val = (yyvsp[0].expr);
    2344             : 
    2345             :                         /*
    2346             :                          * The combination of NOT NULL without an initializer
    2347             :                          * can't work, so let's reject it at compile time.
    2348             :                          */
    2349             :                         if (var->notnull && var->default_val == NULL)
    2350             :                             ereport(ERROR,
    2351             :                                     (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
    2352             :                                      errmsg("variable \"%s\" must have a default value, since it's declared NOT NULL",
    2353             :                                             var->refname),
    2354             :                                      parser_errposition((yylsp[-1]))));
    2355             :                     }
    2356             : #line 2357 "pl_gram.c" /* yacc.c:1646  */
    2357        2166 :     break;
    2358             : 
    2359             :   case 25:
    2360             : #line 533 "pl_gram.y" /* yacc.c:1646  */
    2361             :     {
    2362             :                         plpgsql_ns_additem((yyvsp[-1].nsitem)->itemtype,
    2363             :                                            (yyvsp[-1].nsitem)->itemno, (yyvsp[-4].varname).name);
    2364             :                     }
    2365             : #line 2366 "pl_gram.c" /* yacc.c:1646  */
    2366          56 :     break;
    2367             : 
    2368             :   case 26:
    2369             : #line 538 "pl_gram.y" /* yacc.c:1646  */
    2370             :     { plpgsql_ns_push((yyvsp[-2].varname).name, PLPGSQL_LABEL_OTHER); }
    2371             : #line 2372 "pl_gram.c" /* yacc.c:1646  */
    2372          72 :     break;
    2373             : 
    2374             :   case 27:
    2375             : #line 540 "pl_gram.y" /* yacc.c:1646  */
    2376             :     {
    2377             :                         PLpgSQL_var *new;
    2378             :                         PLpgSQL_expr *curname_def;
    2379             :                         char        buf[1024];
    2380             :                         char        *cp1;
    2381             :                         char        *cp2;
    2382             : 
    2383             :                         /* pop local namespace for cursor args */
    2384             :                         plpgsql_ns_pop();
    2385             : 
    2386             :                         new = (PLpgSQL_var *)
    2387             :                             plpgsql_build_variable((yyvsp[-6].varname).name, (yyvsp[-6].varname).lineno,
    2388             :                                                    plpgsql_build_datatype(REFCURSOROID,
    2389             :                                                                           -1,
    2390             :                                                                           InvalidOid),
    2391             :                                                    true);
    2392             : 
    2393             :                         curname_def = palloc0(sizeof(PLpgSQL_expr));
    2394             : 
    2395             :                         strcpy(buf, "SELECT ");
    2396             :                         cp1 = new->refname;
    2397             :                         cp2 = buf + strlen(buf);
    2398             :                         /*
    2399             :                          * Don't trust standard_conforming_strings here;
    2400             :                          * it might change before we use the string.
    2401             :                          */
    2402             :                         if (strchr(cp1, '\\') != NULL)
    2403             :                             *cp2++ = ESCAPE_STRING_SYNTAX;
    2404             :                         *cp2++ = '\'';
    2405             :                         while (*cp1)
    2406             :                         {
    2407             :                             if (SQL_STR_DOUBLE(*cp1, true))
    2408             :                                 *cp2++ = *cp1;
    2409             :                             *cp2++ = *cp1++;
    2410             :                         }
    2411             :                         strcpy(cp2, "'::pg_catalog.refcursor");
    2412             :                         curname_def->query = pstrdup(buf);
    2413             :                         new->default_val = curname_def;
    2414             : 
    2415             :                         new->cursor_explicit_expr = (yyvsp[0].expr);
    2416             :                         if ((yyvsp[-2].datum) == NULL)
    2417             :                             new->cursor_explicit_argrow = -1;
    2418             :                         else
    2419             :                             new->cursor_explicit_argrow = (yyvsp[-2].datum)->dno;
    2420             :                         new->cursor_options = CURSOR_OPT_FAST_PLAN | (yyvsp[-5].ival);
    2421             :                     }
    2422             : #line 2423 "pl_gram.c" /* yacc.c:1646  */
    2423          72 :     break;
    2424             : 
    2425             :   case 28:
    2426             : #line 589 "pl_gram.y" /* yacc.c:1646  */
    2427             :     {
    2428             :                         (yyval.ival) = 0;
    2429             :                     }
    2430             : #line 2431 "pl_gram.c" /* yacc.c:1646  */
    2431          64 :     break;
    2432             : 
    2433             :   case 29:
    2434             : #line 593 "pl_gram.y" /* yacc.c:1646  */
    2435             :     {
    2436             :                         (yyval.ival) = CURSOR_OPT_NO_SCROLL;
    2437             :                     }
    2438             : #line 2439 "pl_gram.c" /* yacc.c:1646  */
    2439           4 :     break;
    2440             : 
    2441             :   case 30:
    2442             : #line 597 "pl_gram.y" /* yacc.c:1646  */
    2443             :     {
    2444             :                         (yyval.ival) = CURSOR_OPT_SCROLL;
    2445             :                     }
    2446             : #line 2447 "pl_gram.c" /* yacc.c:1646  */
    2447           4 :     break;
    2448             : 
    2449             :   case 31:
    2450             : #line 603 "pl_gram.y" /* yacc.c:1646  */
    2451             :     {
    2452             :                         (yyval.expr) = read_sql_stmt("");
    2453             :                     }
    2454             : #line 2455 "pl_gram.c" /* yacc.c:1646  */
    2455          72 :     break;
    2456             : 
    2457             :   case 32:
    2458             : #line 609 "pl_gram.y" /* yacc.c:1646  */
    2459             :     {
    2460             :                         (yyval.datum) = NULL;
    2461             :                     }
    2462             : #line 2463 "pl_gram.c" /* yacc.c:1646  */
    2463          24 :     break;
    2464             : 
    2465             :   case 33:
    2466             : #line 613 "pl_gram.y" /* yacc.c:1646  */
    2467             :     {
    2468             :                         PLpgSQL_row *new;
    2469             :                         int i;
    2470             :                         ListCell *l;
    2471             : 
    2472             :                         new = palloc0(sizeof(PLpgSQL_row));
    2473             :                         new->dtype = PLPGSQL_DTYPE_ROW;
    2474             :                         new->refname = "(unnamed row)";
    2475             :                         new->lineno = plpgsql_location_to_lineno((yylsp[-2]));
    2476             :                         new->rowtupdesc = NULL;
    2477             :                         new->nfields = list_length((yyvsp[-1].list));
    2478             :                         new->fieldnames = palloc(new->nfields * sizeof(char *));
    2479             :                         new->varnos = palloc(new->nfields * sizeof(int));
    2480             : 
    2481             :                         i = 0;
    2482             :                         foreach (l, (yyvsp[-1].list))
    2483             :                         {
    2484             :                             PLpgSQL_variable *arg = (PLpgSQL_variable *) lfirst(l);
    2485             :                             Assert(!arg->isconst);
    2486             :                             new->fieldnames[i] = arg->refname;
    2487             :                             new->varnos[i] = arg->dno;
    2488             :                             i++;
    2489             :                         }
    2490             :                         list_free((yyvsp[-1].list));
    2491             : 
    2492             :                         plpgsql_adddatum((PLpgSQL_datum *) new);
    2493             :                         (yyval.datum) = (PLpgSQL_datum *) new;
    2494             :                     }
    2495             : #line 2496 "pl_gram.c" /* yacc.c:1646  */
    2496          48 :     break;
    2497             : 
    2498             :   case 34:
    2499             : #line 644 "pl_gram.y" /* yacc.c:1646  */
    2500             :     {
    2501             :                         (yyval.list) = list_make1((yyvsp[0].datum));
    2502             :                     }
    2503             : #line 2504 "pl_gram.c" /* yacc.c:1646  */
    2504          48 :     break;
    2505             : 
    2506             :   case 35:
    2507             : #line 648 "pl_gram.y" /* yacc.c:1646  */
    2508             :     {
    2509             :                         (yyval.list) = lappend((yyvsp[-2].list), (yyvsp[0].datum));
    2510             :                     }
    2511             : #line 2512 "pl_gram.c" /* yacc.c:1646  */
    2512          48 :     break;
    2513             : 
    2514             :   case 36:
    2515             : #line 654 "pl_gram.y" /* yacc.c:1646  */
    2516             :     {
    2517             :                         (yyval.datum) = (PLpgSQL_datum *)
    2518             :                             plpgsql_build_variable((yyvsp[-1].varname).name, (yyvsp[-1].varname).lineno,
    2519             :                                                    (yyvsp[0].dtype), true);
    2520             :                     }
    2521             : #line 2522 "pl_gram.c" /* yacc.c:1646  */
    2522          96 :     break;
    2523             : 
    2524             :   case 39:
    2525             : #line 665 "pl_gram.y" /* yacc.c:1646  */
    2526             :     {
    2527             :                         PLpgSQL_nsitem *nsi;
    2528             : 
    2529             :                         nsi = plpgsql_ns_lookup(plpgsql_ns_top(), false,
    2530             :                                                 (yyvsp[0].word).ident, NULL, NULL,
    2531             :                                                 NULL);
    2532             :                         if (nsi == NULL)
    2533             :                             ereport(ERROR,
    2534             :                                     (errcode(ERRCODE_UNDEFINED_OBJECT),
    2535             :                                      errmsg("variable \"%s\" does not exist",
    2536             :                                             (yyvsp[0].word).ident),
    2537             :                                      parser_errposition((yylsp[0]))));
    2538             :                         (yyval.nsitem) = nsi;
    2539             :                     }
    2540             : #line 2541 "pl_gram.c" /* yacc.c:1646  */
    2541          56 :     break;
    2542             : 
    2543             :   case 40:
    2544             : #line 680 "pl_gram.y" /* yacc.c:1646  */
    2545             :     {
    2546             :                         PLpgSQL_nsitem *nsi;
    2547             : 
    2548             :                         nsi = plpgsql_ns_lookup(plpgsql_ns_top(), false,
    2549             :                                                 (yyvsp[0].keyword), NULL, NULL,
    2550             :                                                 NULL);
    2551             :                         if (nsi == NULL)
    2552             :                             ereport(ERROR,
    2553             :                                     (errcode(ERRCODE_UNDEFINED_OBJECT),
    2554             :                                      errmsg("variable \"%s\" does not exist",
    2555             :                                             (yyvsp[0].keyword)),
    2556             :                                      parser_errposition((yylsp[0]))));
    2557             :                         (yyval.nsitem) = nsi;
    2558             :                     }
    2559             : #line 2560 "pl_gram.c" /* yacc.c:1646  */
    2560           0 :     break;
    2561             : 
    2562             :   case 41:
    2563             : #line 695 "pl_gram.y" /* yacc.c:1646  */
    2564             :     {
    2565             :                         PLpgSQL_nsitem *nsi;
    2566             : 
    2567             :                         if (list_length((yyvsp[0].cword).idents) == 2)
    2568             :                             nsi = plpgsql_ns_lookup(plpgsql_ns_top(), false,
    2569             :                                                     strVal(linitial((yyvsp[0].cword).idents)),
    2570             :                                                     strVal(lsecond((yyvsp[0].cword).idents)),
    2571             :                                                     NULL,
    2572             :                                                     NULL);
    2573             :                         else if (list_length((yyvsp[0].cword).idents) == 3)
    2574             :                             nsi = plpgsql_ns_lookup(plpgsql_ns_top(), false,
    2575             :                                                     strVal(linitial((yyvsp[0].cword).idents)),
    2576             :                                                     strVal(lsecond((yyvsp[0].cword).idents)),
    2577             :                                                     strVal(lthird((yyvsp[0].cword).idents)),
    2578             :                                                     NULL);
    2579             :                         else
    2580             :                             nsi = NULL;
    2581             :                         if (nsi == NULL)
    2582             :                             ereport(ERROR,
    2583             :                                     (errcode(ERRCODE_UNDEFINED_OBJECT),
    2584             :                                      errmsg("variable \"%s\" does not exist",
    2585             :                                             NameListToString((yyvsp[0].cword).idents)),
    2586             :                                      parser_errposition((yylsp[0]))));
    2587             :                         (yyval.nsitem) = nsi;
    2588             :                     }
    2589             : #line 2590 "pl_gram.c" /* yacc.c:1646  */
    2590           0 :     break;
    2591             : 
    2592             :   case 42:
    2593             : #line 723 "pl_gram.y" /* yacc.c:1646  */
    2594             :     {
    2595             :                         (yyval.varname).name = (yyvsp[0].word).ident;
    2596             :                         (yyval.varname).lineno = plpgsql_location_to_lineno((yylsp[0]));
    2597             :                         /*
    2598             :                          * Check to make sure name isn't already declared
    2599             :                          * in the current block.
    2600             :                          */
    2601             :                         if (plpgsql_ns_lookup(plpgsql_ns_top(), true,
    2602             :                                               (yyvsp[0].word).ident, NULL, NULL,
    2603             :                                               NULL) != NULL)
    2604             :                             yyerror("duplicate declaration");
    2605             : 
    2606             :                         if (plpgsql_curr_compile->extra_warnings & PLPGSQL_XCHECK_SHADOWVAR ||
    2607             :                             plpgsql_curr_compile->extra_errors & PLPGSQL_XCHECK_SHADOWVAR)
    2608             :                         {
    2609             :                             PLpgSQL_nsitem *nsi;
    2610             :                             nsi = plpgsql_ns_lookup(plpgsql_ns_top(), false,
    2611             :                                                     (yyvsp[0].word).ident, NULL, NULL, NULL);
    2612             :                             if (nsi != NULL)
    2613             :                                 ereport(plpgsql_curr_compile->extra_errors & PLPGSQL_XCHECK_SHADOWVAR ? ERROR : WARNING,
    2614             :                                         (errcode(ERRCODE_DUPLICATE_ALIAS),
    2615             :                                          errmsg("variable \"%s\" shadows a previously defined variable",
    2616             :                                                 (yyvsp[0].word).ident),
    2617             :                                          parser_errposition((yylsp[0]))));
    2618             :                         }
    2619             : 
    2620             :                     }
    2621             : #line 2622 "pl_gram.c" /* yacc.c:1646  */
    2622        2380 :     break;
    2623             : 
    2624             :   case 43:
    2625             : #line 751 "pl_gram.y" /* yacc.c:1646  */
    2626             :     {
    2627             :                         (yyval.varname).name = pstrdup((yyvsp[0].keyword));
    2628             :                         (yyval.varname).lineno = plpgsql_location_to_lineno((yylsp[0]));
    2629             :                         /*
    2630             :                          * Check to make sure name isn't already declared
    2631             :                          * in the current block.
    2632             :                          */
    2633             :                         if (plpgsql_ns_lookup(plpgsql_ns_top(), true,
    2634             :                                               (yyvsp[0].keyword), NULL, NULL,
    2635             :                                               NULL) != NULL)
    2636             :                             yyerror("duplicate declaration");
    2637             : 
    2638             :                         if (plpgsql_curr_compile->extra_warnings & PLPGSQL_XCHECK_SHADOWVAR ||
    2639             :                             plpgsql_curr_compile->extra_errors & PLPGSQL_XCHECK_SHADOWVAR)
    2640             :                         {
    2641             :                             PLpgSQL_nsitem *nsi;
    2642             :                             nsi = plpgsql_ns_lookup(plpgsql_ns_top(), false,
    2643             :                                                     (yyvsp[0].keyword), NULL, NULL, NULL);
    2644             :                             if (nsi != NULL)
    2645             :                                 ereport(plpgsql_curr_compile->extra_errors & PLPGSQL_XCHECK_SHADOWVAR ? ERROR : WARNING,
    2646             :                                         (errcode(ERRCODE_DUPLICATE_ALIAS),
    2647             :                                          errmsg("variable \"%s\" shadows a previously defined variable",
    2648             :                                                 (yyvsp[0].keyword)),
    2649             :                                          parser_errposition((yylsp[0]))));
    2650             :                         }
    2651             : 
    2652             :                     }
    2653             : #line 2654 "pl_gram.c" /* yacc.c:1646  */
    2654          16 :     break;
    2655             : 
    2656             :   case 44:
    2657             : #line 781 "pl_gram.y" /* yacc.c:1646  */
    2658             :     { (yyval.boolean) = false; }
    2659             : #line 2660 "pl_gram.c" /* yacc.c:1646  */
    2660        2158 :     break;
    2661             : 
    2662             :   case 45:
    2663             : #line 783 "pl_gram.y" /* yacc.c:1646  */
    2664             :     { (yyval.boolean) = true; }
    2665             : #line 2666 "pl_gram.c" /* yacc.c:1646  */
    2666          14 :     break;
    2667             : 
    2668             :   case 46:
    2669             : #line 787 "pl_gram.y" /* yacc.c:1646  */
    2670             :     {
    2671             :                         /*
    2672             :                          * If there's a lookahead token, read_datatype
    2673             :                          * should consume it.
    2674             :                          */
    2675             :                         (yyval.dtype) = read_datatype(yychar);
    2676             :                         yyclearin;
    2677             :                     }
    2678             : #line 2679 "pl_gram.c" /* yacc.c:1646  */
    2679        2268 :     break;
    2680             : 
    2681             :   case 47:
    2682             : #line 798 "pl_gram.y" /* yacc.c:1646  */
    2683             :     { (yyval.oid) = InvalidOid; }
    2684             : #line 2685 "pl_gram.c" /* yacc.c:1646  */
    2685        2172 :     break;
    2686             : 
    2687             :   case 48:
    2688             : #line 800 "pl_gram.y" /* yacc.c:1646  */
    2689             :     {
    2690             :                         (yyval.oid) = get_collation_oid(list_make1(makeString((yyvsp[0].word).ident)),
    2691             :                                                false);
    2692             :                     }
    2693             : #line 2694 "pl_gram.c" /* yacc.c:1646  */
    2694           0 :     break;
    2695             : 
    2696             :   case 49:
    2697             : #line 805 "pl_gram.y" /* yacc.c:1646  */
    2698             :     {
    2699             :                         (yyval.oid) = get_collation_oid(list_make1(makeString(pstrdup((yyvsp[0].keyword)))),
    2700             :                                                false);
    2701             :                     }
    2702             : #line 2703 "pl_gram.c" /* yacc.c:1646  */
    2703           0 :     break;
    2704             : 
    2705             :   case 50:
    2706             : #line 810 "pl_gram.y" /* yacc.c:1646  */
    2707             :     {
    2708             :                         (yyval.oid) = get_collation_oid((yyvsp[0].cword).idents, false);
    2709             :                     }
    2710             : #line 2711 "pl_gram.c" /* yacc.c:1646  */
    2711           0 :     break;
    2712             : 
    2713             :   case 51:
    2714             : #line 816 "pl_gram.y" /* yacc.c:1646  */
    2715             :     { (yyval.boolean) = false; }
    2716             : #line 2717 "pl_gram.c" /* yacc.c:1646  */
    2717        2150 :     break;
    2718             : 
    2719             :   case 52:
    2720             : #line 818 "pl_gram.y" /* yacc.c:1646  */
    2721             :     { (yyval.boolean) = true; }
    2722             : #line 2723 "pl_gram.c" /* yacc.c:1646  */
    2723          22 :     break;
    2724             : 
    2725             :   case 53:
    2726             : #line 822 "pl_gram.y" /* yacc.c:1646  */
    2727             :     { (yyval.expr) = NULL; }
    2728             : #line 2729 "pl_gram.c" /* yacc.c:1646  */
    2729        1824 :     break;
    2730             : 
    2731             :   case 54:
    2732             : #line 824 "pl_gram.y" /* yacc.c:1646  */
    2733             :     {
    2734             :                         (yyval.expr) = read_sql_expression(';', ";");
    2735             :                     }
    2736             : #line 2737 "pl_gram.c" /* yacc.c:1646  */
    2737         348 :     break;
    2738             : 
    2739             :   case 59:
    2740             : #line 843 "pl_gram.y" /* yacc.c:1646  */
    2741             :     { (yyval.list) = NIL; }
    2742             : #line 2743 "pl_gram.c" /* yacc.c:1646  */
    2743        7740 :     break;
    2744             : 
    2745             :   case 60:
    2746             : #line 845 "pl_gram.y" /* yacc.c:1646  */
    2747             :     {
    2748             :                         /* don't bother linking null statements into list */
    2749             :                         if ((yyvsp[0].stmt) == NULL)
    2750             :                             (yyval.list) = (yyvsp[-1].list);
    2751             :                         else
    2752             :                             (yyval.list) = lappend((yyvsp[-1].list), (yyvsp[0].stmt));
    2753             :                     }
    2754             : #line 2755 "pl_gram.c" /* yacc.c:1646  */
    2755       14798 :     break;
    2756             : 
    2757             :   case 61:
    2758             : #line 855 "pl_gram.y" /* yacc.c:1646  */
    2759             :     { (yyval.stmt) = (yyvsp[-1].stmt); }
    2760             : #line 2761 "pl_gram.c" /* yacc.c:1646  */
    2761         134 :     break;
    2762             : 
    2763             :   case 62:
    2764             : #line 857 "pl_gram.y" /* yacc.c:1646  */
    2765             :     { (yyval.stmt) = (yyvsp[0].stmt); }
    2766             : #line 2767 "pl_gram.c" /* yacc.c:1646  */
    2767        2044 :     break;
    2768             : 
    2769             :   case 63:
    2770             : #line 859 "pl_gram.y" /* yacc.c:1646  */
    2771             :     { (yyval.stmt) = (yyvsp[0].stmt); }
    2772             : #line 2773 "pl_gram.c" /* yacc.c:1646  */
    2773        2708 :     break;
    2774             : 
    2775             :   case 64:
    2776             : #line 861 "pl_gram.y" /* yacc.c:1646  */
    2777             :     { (yyval.stmt) = (yyvsp[0].stmt); }
    2778             : #line 2779 "pl_gram.c" /* yacc.c:1646  */
    2779           4 :     break;
    2780             : 
    2781             :   case 65:
    2782             : #line 863 "pl_gram.y" /* yacc.c:1646  */
    2783             :     { (yyval.stmt) = (yyvsp[0].stmt); }
    2784             : #line 2785 "pl_gram.c" /* yacc.c:1646  */
    2785          32 :     break;
    2786             : 
    2787             :   case 66:
    2788             : #line 865 "pl_gram.y" /* yacc.c:1646  */
    2789             :     { (yyval.stmt) = (yyvsp[0].stmt); }
    2790             : #line 2791 "pl_gram.c" /* yacc.c:1646  */
    2791          54 :     break;
    2792             : 
    2793             :   case 67:
    2794             : #line 867 "pl_gram.y" /* yacc.c:1646  */
    2795             :     { (yyval.stmt) = (yyvsp[0].stmt); }
    2796             : #line 2797 "pl_gram.c" /* yacc.c:1646  */
    2797         496 :     break;
    2798             : 
    2799             :   case 68:
    2800             : #line 869 "pl_gram.y" /* yacc.c:1646  */
    2801             :     { (yyval.stmt) = (yyvsp[0].stmt); }
    2802             : #line 2803 "pl_gram.c" /* yacc.c:1646  */
    2803          40 :     break;
    2804             : 
    2805             :   case 69:
    2806             : #line 871 "pl_gram.y" /* yacc.c:1646  */
    2807             :     { (yyval.stmt) = (yyvsp[0].stmt); }
    2808             : #line 2809 "pl_gram.c" /* yacc.c:1646  */
    2809          90 :     break;
    2810             : 
    2811             :   case 70:
    2812             : #line 873 "pl_gram.y" /* yacc.c:1646  */
    2813             :     { (yyval.stmt) = (yyvsp[0].stmt); }
    2814             : #line 2815 "pl_gram.c" /* yacc.c:1646  */
    2815        3990 :     break;
    2816             : 
    2817             :   case 71:
    2818             : #line 875 "pl_gram.y" /* yacc.c:1646  */
    2819             :     { (yyval.stmt) = (yyvsp[0].stmt); }
    2820             : #line 2821 "pl_gram.c" /* yacc.c:1646  */
    2821        2850 :     break;
    2822             : 
    2823             :   case 72:
    2824             : #line 877 "pl_gram.y" /* yacc.c:1646  */
    2825             :     { (yyval.stmt) = (yyvsp[0].stmt); }
    2826             : #line 2827 "pl_gram.c" /* yacc.c:1646  */
    2827          34 :     break;
    2828             : 
    2829             :   case 73:
    2830             : #line 879 "pl_gram.y" /* yacc.c:1646  */
    2831             :     { (yyval.stmt) = (yyvsp[0].stmt); }
    2832             : #line 2833 "pl_gram.c" /* yacc.c:1646  */
    2833        1352 :     break;
    2834             : 
    2835             :   case 74:
    2836             : #line 881 "pl_gram.y" /* yacc.c:1646  */
    2837             :     { (yyval.stmt) = (yyvsp[0].stmt); }
    2838             : #line 2839 "pl_gram.c" /* yacc.c:1646  */
    2839         204 :     break;
    2840             : 
    2841             :   case 75:
    2842             : #line 883 "pl_gram.y" /* yacc.c:1646  */
    2843             :     { (yyval.stmt) = (yyvsp[0].stmt); }
    2844             : #line 2845 "pl_gram.c" /* yacc.c:1646  */
    2845         282 :     break;
    2846             : 
    2847             :   case 76:
    2848             : #line 885 "pl_gram.y" /* yacc.c:1646  */
    2849             :     { (yyval.stmt) = (yyvsp[0].stmt); }
    2850             : #line 2851 "pl_gram.c" /* yacc.c:1646  */
    2851          54 :     break;
    2852             : 
    2853             :   case 77:
    2854             : #line 887 "pl_gram.y" /* yacc.c:1646  */
    2855             :     { (yyval.stmt) = (yyvsp[0].stmt); }
    2856             : #line 2857 "pl_gram.c" /* yacc.c:1646  */
    2857          52 :     break;
    2858             : 
    2859             :   case 78:
    2860             : #line 889 "pl_gram.y" /* yacc.c:1646  */
    2861             :     { (yyval.stmt) = (yyvsp[0].stmt); }
    2862             : #line 2863 "pl_gram.c" /* yacc.c:1646  */
    2863          68 :     break;
    2864             : 
    2865             :   case 79:
    2866             : #line 891 "pl_gram.y" /* yacc.c:1646  */
    2867             :     { (yyval.stmt) = (yyvsp[0].stmt); }
    2868             : #line 2869 "pl_gram.c" /* yacc.c:1646  */
    2869          80 :     break;
    2870             : 
    2871             :   case 80:
    2872             : #line 893 "pl_gram.y" /* yacc.c:1646  */
    2873             :     { (yyval.stmt) = (yyvsp[0].stmt); }
    2874             : #line 2875 "pl_gram.c" /* yacc.c:1646  */
    2875          12 :     break;
    2876             : 
    2877             :   case 81:
    2878             : #line 895 "pl_gram.y" /* yacc.c:1646  */
    2879             :     { (yyval.stmt) = (yyvsp[0].stmt); }
    2880             : #line 2881 "pl_gram.c" /* yacc.c:1646  */
    2881          44 :     break;
    2882             : 
    2883             :   case 82:
    2884             : #line 897 "pl_gram.y" /* yacc.c:1646  */
    2885             :     { (yyval.stmt) = (yyvsp[0].stmt); }
    2886             : #line 2887 "pl_gram.c" /* yacc.c:1646  */
    2887          20 :     break;
    2888             : 
    2889             :   case 83:
    2890             : #line 899 "pl_gram.y" /* yacc.c:1646  */
    2891             :     { (yyval.stmt) = (yyvsp[0].stmt); }
    2892             : #line 2893 "pl_gram.c" /* yacc.c:1646  */
    2893          60 :     break;
    2894             : 
    2895             :   case 84:
    2896             : #line 901 "pl_gram.y" /* yacc.c:1646  */
    2897             :     { (yyval.stmt) = (yyvsp[0].stmt); }
    2898             : #line 2899 "pl_gram.c" /* yacc.c:1646  */
    2899          30 :     break;
    2900             : 
    2901             :   case 85:
    2902             : #line 903 "pl_gram.y" /* yacc.c:1646  */
    2903             :     { (yyval.stmt) = (yyvsp[0].stmt); }
    2904             : #line 2905 "pl_gram.c" /* yacc.c:1646  */
    2905          64 :     break;
    2906             : 
    2907             :   case 86:
    2908             : #line 907 "pl_gram.y" /* yacc.c:1646  */
    2909             :     {
    2910             :                         PLpgSQL_stmt_perform *new;
    2911             : 
    2912             :                         new = palloc0(sizeof(PLpgSQL_stmt_perform));
    2913             :                         new->cmd_type = PLPGSQL_STMT_PERFORM;
    2914             :                         new->lineno   = plpgsql_location_to_lineno((yylsp[-1]));
    2915             :                         new->stmtid = ++plpgsql_curr_compile->nstatements;
    2916             :                         new->expr  = (yyvsp[0].expr);
    2917             : 
    2918             :                         (yyval.stmt) = (PLpgSQL_stmt *)new;
    2919             :                     }
    2920             : #line 2921 "pl_gram.c" /* yacc.c:1646  */
    2921         282 :     break;
    2922             : 
    2923             :   case 87:
    2924             : #line 921 "pl_gram.y" /* yacc.c:1646  */
    2925             :     {
    2926             :                         PLpgSQL_stmt_call *new;
    2927             : 
    2928             :                         new = palloc0(sizeof(PLpgSQL_stmt_call));
    2929             :                         new->cmd_type = PLPGSQL_STMT_CALL;
    2930             :                         new->lineno = plpgsql_location_to_lineno((yylsp[0]));
    2931             :                         new->stmtid = ++plpgsql_curr_compile->nstatements;
    2932             :                         new->expr = read_sql_stmt("CALL ");
    2933             :                         new->is_call = true;
    2934             : 
    2935             :                         (yyval.stmt) = (PLpgSQL_stmt *)new;
    2936             : 
    2937             :                     }
    2938             : #line 2939 "pl_gram.c" /* yacc.c:1646  */
    2939          52 :     break;
    2940             : 
    2941             :   case 88:
    2942             : #line 935 "pl_gram.y" /* yacc.c:1646  */
    2943             :     {
    2944             :                         /* use the same structures as for CALL, for simplicity */
    2945             :                         PLpgSQL_stmt_call *new;
    2946             : 
    2947             :                         new = palloc0(sizeof(PLpgSQL_stmt_call));
    2948             :                         new->cmd_type = PLPGSQL_STMT_CALL;
    2949             :                         new->lineno = plpgsql_location_to_lineno((yylsp[0]));
    2950             :                         new->stmtid = ++plpgsql_curr_compile->nstatements;
    2951             :                         new->expr = read_sql_stmt("DO ");
    2952             :                         new->is_call = false;
    2953             : 
    2954             :                         (yyval.stmt) = (PLpgSQL_stmt *)new;
    2955             : 
    2956             :                     }
    2957             : #line 2958 "pl_gram.c" /* yacc.c:1646  */
    2958           2 :     break;
    2959             : 
    2960             :   case 89:
    2961             : #line 952 "pl_gram.y" /* yacc.c:1646  */
    2962             :     {
    2963             :                         PLpgSQL_stmt_assign *new;
    2964             : 
    2965             :                         new = palloc0(sizeof(PLpgSQL_stmt_assign));
    2966             :                         new->cmd_type = PLPGSQL_STMT_ASSIGN;
    2967             :                         new->lineno   = plpgsql_location_to_lineno((yylsp[-2]));
    2968             :                         new->stmtid = ++plpgsql_curr_compile->nstatements;
    2969             :                         new->varno = (yyvsp[-2].datum)->dno;
    2970             :                         new->expr  = (yyvsp[0].expr);
    2971             : 
    2972             :                         (yyval.stmt) = (PLpgSQL_stmt *)new;
    2973             :                     }
    2974             : #line 2975 "pl_gram.c" /* yacc.c:1646  */
    2975        2044 :     break;
    2976             : 
    2977             :   case 90:
    2978             : #line 967 "pl_gram.y" /* yacc.c:1646  */
    2979             :     {
    2980             :                         PLpgSQL_stmt_getdiag     *new;
    2981             :                         ListCell        *lc;
    2982             : 
    2983             :                         new = palloc0(sizeof(PLpgSQL_stmt_getdiag));
    2984             :                         new->cmd_type = PLPGSQL_STMT_GETDIAG;
    2985             :                         new->lineno   = plpgsql_location_to_lineno((yylsp[-4]));
    2986             :                         new->stmtid    = ++plpgsql_curr_compile->nstatements;
    2987             :                         new->is_stacked = (yyvsp[-3].boolean);
    2988             :                         new->diag_items = (yyvsp[-1].list);
    2989             : 
    2990             :                         /*
    2991             :                          * Check information items are valid for area option.
    2992             :                          */
    2993             :                         foreach(lc, new->diag_items)
    2994             :                         {
    2995             :                             PLpgSQL_diag_item *ditem = (PLpgSQL_diag_item *) lfirst(lc);
    2996             : 
    2997             :                             switch (ditem->kind)
    2998             :                             {
    2999             :                                 /* these fields are disallowed in stacked case */
    3000             :                                 case PLPGSQL_GETDIAG_ROW_COUNT:
    3001             :                                     if (new->is_stacked)
    3002             :                                         ereport(ERROR,
    3003             :                                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3004             :                                                  errmsg("diagnostics item %s is not allowed in GET STACKED DIAGNOSTICS",
    3005             :                                                         plpgsql_getdiag_kindname(ditem->kind)),
    3006             :                                                  parser_errposition((yylsp[-4]))));
    3007             :                                     break;
    3008             :                                 /* these fields are disallowed in current case */
    3009             :                                 case PLPGSQL_GETDIAG_ERROR_CONTEXT:
    3010             :                                 case PLPGSQL_GETDIAG_ERROR_DETAIL:
    3011             :                                 case PLPGSQL_GETDIAG_ERROR_HINT:
    3012             :                                 case PLPGSQL_GETDIAG_RETURNED_SQLSTATE:
    3013             :                                 case PLPGSQL_GETDIAG_COLUMN_NAME:
    3014             :                                 case PLPGSQL_GETDIAG_CONSTRAINT_NAME:
    3015             :                                 case PLPGSQL_GETDIAG_DATATYPE_NAME:
    3016             :                                 case PLPGSQL_GETDIAG_MESSAGE_TEXT:
    3017             :                                 case PLPGSQL_GETDIAG_TABLE_NAME:
    3018             :                                 case PLPGSQL_GETDIAG_SCHEMA_NAME:
    3019             :                                     if (!new->is_stacked)
    3020             :                                         ereport(ERROR,
    3021             :                                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3022             :                                                  errmsg("diagnostics item %s is not allowed in GET CURRENT DIAGNOSTICS",
    3023             :                                                         plpgsql_getdiag_kindname(ditem->kind)),
    3024             :                                                  parser_errposition((yylsp[-4]))));
    3025             :                                     break;
    3026             :                                 /* these fields are allowed in either case */
    3027             :                                 case PLPGSQL_GETDIAG_CONTEXT:
    3028             :                                     break;
    3029             :                                 default:
    3030             :                                     elog(ERROR, "unrecognized diagnostic item kind: %d",
    3031             :                                          ditem->kind);
    3032             :                                     break;
    3033             :                             }
    3034             :                         }
    3035             : 
    3036             :                         (yyval.stmt) = (PLpgSQL_stmt *)new;
    3037             :                     }
    3038             : #line 3039 "pl_gram.c" /* yacc.c:1646  */
    3039          52 :     break;
    3040             : 
    3041             :   case 91:
    3042             : #line 1029 "pl_gram.y" /* yacc.c:1646  */
    3043             :     {
    3044             :                         (yyval.boolean) = false;
    3045             :                     }
    3046             : #line 3047 "pl_gram.c" /* yacc.c:1646  */
    3047          36 :     break;
    3048             : 
    3049             :   case 92:
    3050             : #line 1033 "pl_gram.y" /* yacc.c:1646  */
    3051             :     {
    3052             :                         (yyval.boolean) = false;
    3053             :                     }
    3054             : #line 3055 "pl_gram.c" /* yacc.c:1646  */
    3055           0 :     break;
    3056             : 
    3057             :   case 93:
    3058             : #line 1037 "pl_gram.y" /* yacc.c:1646  */
    3059             :     {
    3060             :                         (yyval.boolean) = true;
    3061             :                     }
    3062             : #line 3063 "pl_gram.c" /* yacc.c:1646  */
    3063          20 :     break;
    3064             : 
    3065             :   case 94:
    3066             : #line 1043 "pl_gram.y" /* yacc.c:1646  */
    3067             :     {
    3068             :                         (yyval.list) = lappend((yyvsp[-2].list), (yyvsp[0].diagitem));
    3069             :                     }
    3070             : #line 3071 "pl_gram.c" /* yacc.c:1646  */
    3071          56 :     break;
    3072             : 
    3073             :   case 95:
    3074             : #line 1047 "pl_gram.y" /* yacc.c:1646  */
    3075             :     {
    3076             :                         (yyval.list) = list_make1((yyvsp[0].diagitem));
    3077             :                     }
    3078             : #line 3079 "pl_gram.c" /* yacc.c:1646  */
    3079          52 :     break;
    3080             : 
    3081             :   case 96:
    3082             : #line 1053 "pl_gram.y" /* yacc.c:1646  */
    3083             :     {
    3084             :                         PLpgSQL_diag_item *new;
    3085             : 
    3086             :                         new = palloc(sizeof(PLpgSQL_diag_item));
    3087             :                         new->target = (yyvsp[-2].datum)->dno;
    3088             :                         new->kind = (yyvsp[0].ival);
    3089             : 
    3090             :                         (yyval.diagitem) = new;
    3091             :                     }
    3092             : #line 3093 "pl_gram.c" /* yacc.c:1646  */
    3093         108 :     break;
    3094             : 
    3095             :   case 97:
    3096             : #line 1065 "pl_gram.y" /* yacc.c:1646  */
    3097             :     {
    3098             :                         int tok = yylex();
    3099             : 
    3100             :                         if (tok_is_keyword(tok, &yylval,
    3101             :                                            K_ROW_COUNT, "row_count"))
    3102             :                             (yyval.ival) = PLPGSQL_GETDIAG_ROW_COUNT;
    3103             :                         else if (tok_is_keyword(tok, &yylval,
    3104             :                                                 K_PG_CONTEXT, "pg_context"))
    3105             :                             (yyval.ival) = PLPGSQL_GETDIAG_CONTEXT;
    3106             :                         else if (tok_is_keyword(tok, &yylval,
    3107             :                                                 K_PG_EXCEPTION_DETAIL, "pg_exception_detail"))
    3108             :                             (yyval.ival) = PLPGSQL_GETDIAG_ERROR_DETAIL;
    3109             :                         else if (tok_is_keyword(tok, &yylval,
    3110             :                                                 K_PG_EXCEPTION_HINT, "pg_exception_hint"))
    3111             :                             (yyval.ival) = PLPGSQL_GETDIAG_ERROR_HINT;
    3112             :                         else if (tok_is_keyword(tok, &yylval,
    3113             :                                                 K_PG_EXCEPTION_CONTEXT, "pg_exception_context"))
    3114             :                             (yyval.ival) = PLPGSQL_GETDIAG_ERROR_CONTEXT;
    3115             :                         else if (tok_is_keyword(tok, &yylval,
    3116             :                                                 K_COLUMN_NAME, "column_name"))
    3117             :                             (yyval.ival) = PLPGSQL_GETDIAG_COLUMN_NAME;
    3118             :                         else if (tok_is_keyword(tok, &yylval,
    3119             :                                                 K_CONSTRAINT_NAME, "constraint_name"))
    3120             :                             (yyval.ival) = PLPGSQL_GETDIAG_CONSTRAINT_NAME;
    3121             :                         else if (tok_is_keyword(tok, &yylval,
    3122             :                                                 K_PG_DATATYPE_NAME, "pg_datatype_name"))
    3123             :                             (yyval.ival) = PLPGSQL_GETDIAG_DATATYPE_NAME;
    3124             :                         else if (tok_is_keyword(tok, &yylval,
    3125             :                                                 K_MESSAGE_TEXT, "message_text"))
    3126             :                             (yyval.ival) = PLPGSQL_GETDIAG_MESSAGE_TEXT;
    3127             :                         else if (tok_is_keyword(tok, &yylval,
    3128             :                                                 K_TABLE_NAME, "table_name"))
    3129             :                             (yyval.ival) = PLPGSQL_GETDIAG_TABLE_NAME;
    3130             :                         else if (tok_is_keyword(tok, &yylval,
    3131             :                                                 K_SCHEMA_NAME, "schema_name"))
    3132             :                             (yyval.ival) = PLPGSQL_GETDIAG_SCHEMA_NAME;
    3133             :                         else if (tok_is_keyword(tok, &yylval,
    3134             :                                                 K_RETURNED_SQLSTATE, "returned_sqlstate"))
    3135             :                             (yyval.ival) = PLPGSQL_GETDIAG_RETURNED_SQLSTATE;
    3136             :                         else
    3137             :                             yyerror("unrecognized GET DIAGNOSTICS item");
    3138             :                     }
    3139             : #line 3140 "pl_gram.c" /* yacc.c:1646  */
    3140         108 :     break;
    3141             : 
    3142             :   case 98:
    3143             : #line 1110 "pl_gram.y" /* yacc.c:1646  */
    3144             :     {
    3145             :                         if ((yyvsp[0].datum)->dtype == PLPGSQL_DTYPE_ROW ||
    3146             :                             (yyvsp[0].datum)->dtype == PLPGSQL_DTYPE_REC)
    3147             :                             ereport(ERROR,
    3148             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    3149             :                                      errmsg("\"%s\" is not a scalar variable",
    3150             :                                             ((PLpgSQL_variable *) (yyvsp[0].datum))->refname),
    3151             :                                      parser_errposition((yylsp[0]))));
    3152             :                         (yyval.datum) = (yyvsp[0].datum);
    3153             :                     }
    3154             : #line 3155 "pl_gram.c" /* yacc.c:1646  */
    3155         108 :     break;
    3156             : 
    3157             :   case 99:
    3158             : #line 1121 "pl_gram.y" /* yacc.c:1646  */
    3159             :     {
    3160             :                         /* just to give a better message than "syntax error" */
    3161             :                         word_is_not_variable(&((yyvsp[0].word)), (yylsp[0]));
    3162             :                     }
    3163             : #line 3164 "pl_gram.c" /* yacc.c:1646  */
    3164           0 :     break;
    3165             : 
    3166             :   case 100:
    3167             : #line 1126 "pl_gram.y" /* yacc.c:1646  */
    3168             :     {
    3169             :                         /* just to give a better message than "syntax error" */
    3170             :                         cword_is_not_variable(&((yyvsp[0].cword)), (yylsp[0]));
    3171             :                     }
    3172             : #line 3173 "pl_gram.c" /* yacc.c:1646  */
    3173           0 :     break;
    3174             : 
    3175             :   case 101:
    3176             : #line 1134 "pl_gram.y" /* yacc.c:1646  */
    3177             :     {
    3178             :                         check_assignable((yyvsp[0].wdatum).datum, (yylsp[0]));
    3179             :                         (yyval.datum) = (yyvsp[0].wdatum).datum;
    3180             :                     }
    3181             : #line 3182 "pl_gram.c" /* yacc.c:1646  */
    3182        2156 :     break;
    3183             : 
    3184             :   case 102:
    3185             : #line 1139 "pl_gram.y" /* yacc.c:1646  */
    3186             :     {
    3187             :                         PLpgSQL_arrayelem   *new;
    3188             : 
    3189             :                         new = palloc0(sizeof(PLpgSQL_arrayelem));
    3190             :                         new->dtype       = PLPGSQL_DTYPE_ARRAYELEM;
    3191             :                         new->subscript   = (yyvsp[0].expr);
    3192             :                         new->arrayparentno = (yyvsp[-2].datum)->dno;
    3193             :                         /* initialize cached type data to "not valid" */
    3194             :                         new->parenttypoid = InvalidOid;
    3195             : 
    3196             :                         plpgsql_adddatum((PLpgSQL_datum *) new);
    3197             : 
    3198             :                         (yyval.datum) = (PLpgSQL_datum *) new;
    3199             :                     }
    3200             : #line 3201 "pl_gram.c" /* yacc.c:1646  */
    3201          50 :     break;
    3202             : 
    3203             :   case 103:
    3204             : #line 1156 "pl_gram.y" /* yacc.c:1646  */
    3205             :     {
    3206             :                         PLpgSQL_stmt_if *new;
    3207             : 
    3208             :                         new = palloc0(sizeof(PLpgSQL_stmt_if));
    3209             :                         new->cmd_type    = PLPGSQL_STMT_IF;
    3210             :                         new->lineno      = plpgsql_location_to_lineno((yylsp[-7]));
    3211             :                         new->stmtid      = ++plpgsql_curr_compile->nstatements;
    3212             :                         new->cond        = (yyvsp[-6].expr);
    3213             :                         new->then_body   = (yyvsp[-5].list);
    3214             :                         new->elsif_list = (yyvsp[-4].list);
    3215             :                         new->else_body  = (yyvsp[-3].list);
    3216             : 
    3217             :                         (yyval.stmt) = (PLpgSQL_stmt *)new;
    3218             :                     }
    3219             : #line 3220 "pl_gram.c" /* yacc.c:1646  */
    3220        2708 :     break;
    3221             : 
    3222             :   case 104:
    3223             : #line 1173 "pl_gram.y" /* yacc.c:1646  */
    3224             :     {
    3225             :                         (yyval.list) = NIL;
    3226             :                     }
    3227             : #line 3228 "pl_gram.c" /* yacc.c:1646  */
    3228        2708 :     break;
    3229             : 
    3230             :   case 105:
    3231             : #line 1177 "pl_gram.y" /* yacc.c:1646  */
    3232             :     {
    3233             :                         PLpgSQL_if_elsif *new;
    3234             : 
    3235             :                         new = palloc0(sizeof(PLpgSQL_if_elsif));
    3236             :                         new->lineno = plpgsql_location_to_lineno((yylsp[-2]));
    3237             :                         new->cond   = (yyvsp[-1].expr);
    3238             :                         new->stmts  = (yyvsp[0].list);
    3239             : 
    3240             :                         (yyval.list) = lappend((yyvsp[-3].list), new);
    3241             :                     }
    3242             : #line 3243 "pl_gram.c" /* yacc.c:1646  */
    3243          72 :     break;
    3244             : 
    3245             :   case 106:
    3246             : #line 1190 "pl_gram.y" /* yacc.c:1646  */
    3247             :     {
    3248             :                         (yyval.list) = NIL;
    3249             :                     }
    3250             : #line 3251 "pl_gram.c" /* yacc.c:1646  */
    3251        2374 :     break;
    3252             : 
    3253             :   case 107:
    3254             : #line 1194 "pl_gram.y" /* yacc.c:1646  */
    3255             :     {
    3256             :                         (yyval.list) = (yyvsp[0].list);
    3257             :                     }
    3258             : #line 3259 "pl_gram.c" /* yacc.c:1646  */
    3259         334 :     break;
    3260             : 
    3261             :   case 108:
    3262             : #line 1200 "pl_gram.y" /* yacc.c:1646  */
    3263             :     {
    3264             :                         (yyval.stmt) = make_case((yylsp[-6]), (yyvsp[-5].expr), (yyvsp[-4].list), (yyvsp[-3].list));
    3265             :                     }
    3266             : #line 3267 "pl_gram.c" /* yacc.c:1646  */
    3267           4 :     break;
    3268             : 
    3269             :   case 109:
    3270             : #line 1206 "pl_gram.y" /* yacc.c:1646  */
    3271             :     {
    3272             :                         PLpgSQL_expr *expr = NULL;
    3273             :                         int tok = yylex();
    3274             : 
    3275             :                         if (tok != K_WHEN)
    3276             :                         {
    3277             :                             plpgsql_push_back_token(tok);
    3278             :                             expr = read_sql_expression(K_WHEN, "WHEN");
    3279             :                         }
    3280             :                         plpgsql_push_back_token(K_WHEN);
    3281             :                         (yyval.expr) = expr;
    3282             :                     }
    3283             : #line 3284 "pl_gram.c" /* yacc.c:1646  */
    3284           4 :     break;
    3285             : 
    3286             :   case 110:
    3287             : #line 1221 "pl_gram.y" /* yacc.c:1646  */
    3288             :     {
    3289             :                         (yyval.list) = lappend((yyvsp[-1].list), (yyvsp[0].casewhen));
    3290             :                     }
    3291             : #line 3292 "pl_gram.c" /* yacc.c:1646  */
    3292          10 :     break;
    3293             : 
    3294             :   case 111:
    3295             : #line 1225 "pl_gram.y" /* yacc.c:1646  */
    3296             :     {
    3297             :                         (yyval.list) = list_make1((yyvsp[0].casewhen));
    3298             :                     }
    3299             : #line 3300 "pl_gram.c" /* yacc.c:1646  */
    3300           4 :     break;
    3301             : 
    3302             :   case 112:
    3303             : #line 1231 "pl_gram.y" /* yacc.c:1646  */
    3304             :     {
    3305             :                         PLpgSQL_case_when *new = palloc(sizeof(PLpgSQL_case_when));
    3306             : 
    3307             :                         new->lineno  = plpgsql_location_to_lineno((yylsp[-2]));
    3308             :                         new->expr    = (yyvsp[-1].expr);
    3309             :                         new->stmts   = (yyvsp[0].list);
    3310             :                         (yyval.casewhen) = new;
    3311             :                     }
    3312             : #line 3313 "pl_gram.c" /* yacc.c:1646  */
    3313          14 :     break;
    3314             : 
    3315             :   case 113:
    3316             : #line 1242 "pl_gram.y" /* yacc.c:1646  */
    3317             :     {
    3318             :                         (yyval.list) = NIL;
    3319             :                     }
    3320             : #line 3321 "pl_gram.c" /* yacc.c:1646  */
    3321           2 :     break;
    3322             : 
    3323             :   case 114:
    3324             : #line 1246 "pl_gram.y" /* yacc.c:1646  */
    3325             :     {
    3326             :                         /*
    3327             :                          * proc_sect could return an empty list, but we
    3328             :                          * must distinguish that from not having ELSE at all.
    3329             :                          * Simplest fix is to return a list with one NULL
    3330             :                          * pointer, which make_case() must take care of.
    3331             :                          */
    3332             :                         if ((yyvsp[0].list) != NIL)
    3333             :                             (yyval.list) = (yyvsp[0].list);
    3334             :                         else
    3335             :                             (yyval.list) = list_make1(NULL);
    3336             :                     }
    3337             : #line 3338 "pl_gram.c" /* yacc.c:1646  */
    3338           2 :     break;
    3339             : 
    3340             :   case 115:
    3341             : #line 1261 "pl_gram.y" /* yacc.c:1646  */
    3342             :     {
    3343             :                         PLpgSQL_stmt_loop *new;
    3344             : 
    3345             :                         new = palloc0(sizeof(PLpgSQL_stmt_loop));
    3346             :                         new->cmd_type = PLPGSQL_STMT_LOOP;
    3347             :                         new->lineno   = plpgsql_location_to_lineno((yylsp[-1]));
    3348             :                         new->stmtid   = ++plpgsql_curr_compile->nstatements;
    3349             :                         new->label     = (yyvsp[-2].str);
    3350             :                         new->body      = (yyvsp[0].loop_body).stmts;
    3351             : 
    3352             :                         check_labels((yyvsp[-2].str), (yyvsp[0].loop_body).end_label, (yyvsp[0].loop_body).end_label_location);
    3353             :                         plpgsql_ns_pop();
    3354             : 
    3355             :                         (yyval.stmt) = (PLpgSQL_stmt *)new;
    3356             :                     }
    3357             : #line 3358 "pl_gram.c" /* yacc.c:1646  */
    3358          32 :     break;
    3359             : 
    3360             :   case 116:
    3361             : #line 1279 "pl_gram.y" /* yacc.c:1646  */
    3362             :     {
    3363             :                         PLpgSQL_stmt_while *new;
    3364             : 
    3365             :                         new = palloc0(sizeof(PLpgSQL_stmt_while));
    3366             :                         new->cmd_type = PLPGSQL_STMT_WHILE;
    3367             :                         new->lineno   = plpgsql_location_to_lineno((yylsp[-2]));
    3368             :                         new->stmtid    = ++plpgsql_curr_compile->nstatements;
    3369             :                         new->label     = (yyvsp[-3].str);
    3370             :                         new->cond      = (yyvsp[-1].expr);
    3371             :                         new->body      = (yyvsp[0].loop_body).stmts;
    3372             : 
    3373             :                         check_labels((yyvsp[-3].str), (yyvsp[0].loop_body).end_label, (yyvsp[0].loop_body).end_label_location);
    3374             :                         plpgsql_ns_pop();
    3375             : 
    3376             :                         (yyval.stmt) = (PLpgSQL_stmt *)new;
    3377             :                     }
    3378             : #line 3379 "pl_gram.c" /* yacc.c:1646  */
    3379          54 :     break;
    3380             : 
    3381             :   case 117:
    3382             : #line 1298 "pl_gram.y" /* yacc.c:1646  */
    3383             :     {
    3384             :                         /* This runs after we've scanned the loop body */
    3385             :                         if ((yyvsp[-1].stmt)->cmd_type == PLPGSQL_STMT_FORI)
    3386             :                         {
    3387             :                             PLpgSQL_stmt_fori       *new;
    3388             : 
    3389             :                             new = (PLpgSQL_stmt_fori *) (yyvsp[-1].stmt);
    3390             :                             new->lineno   = plpgsql_location_to_lineno((yylsp[-2]));
    3391             :                             new->stmtid    = ++plpgsql_curr_compile->nstatements;
    3392             :                             new->label     = (yyvsp[-3].str);
    3393             :                             new->body      = (yyvsp[0].loop_body).stmts;
    3394             :                             (yyval.stmt) = (PLpgSQL_stmt *) new;
    3395             :                         }
    3396             :                         else
    3397             :                         {
    3398             :                             PLpgSQL_stmt_forq       *new;
    3399             : 
    3400             :                             Assert((yyvsp[-1].stmt)->cmd_type == PLPGSQL_STMT_FORS ||
    3401             :                                    (yyvsp[-1].stmt)->cmd_type == PLPGSQL_STMT_FORC ||
    3402             :                                    (yyvsp[-1].stmt)->cmd_type == PLPGSQL_STMT_DYNFORS);
    3403             :                             /* forq is the common supertype of all three */
    3404             :                             new = (PLpgSQL_stmt_forq *) (yyvsp[-1].stmt);
    3405             :                             new->lineno   = plpgsql_location_to_lineno((yylsp[-2]));
    3406             :                             new->stmtid    = ++plpgsql_curr_compile->nstatements;
    3407             :                             new->label     = (yyvsp[-3].str);
    3408             :                             new->body      = (yyvsp[0].loop_body).stmts;
    3409             :                             (yyval.stmt) = (PLpgSQL_stmt *) new;
    3410             :                         }
    3411             : 
    3412             :                         check_labels((yyvsp[-3].str), (yyvsp[0].loop_body).end_label, (yyvsp[0].loop_body).end_label_location);
    3413             :                         /* close namespace started in opt_loop_label */
    3414             :                         plpgsql_ns_pop();
    3415             :                     }
    3416             : #line 3417 "pl_gram.c" /* yacc.c:1646  */
    3417         496 :     break;
    3418             : 
    3419             :   case 118:
    3420             : #line 1334 "pl_gram.y" /* yacc.c:1646  */
    3421             :     {
    3422             :                         int         tok = yylex();
    3423             :                         int         tokloc = yylloc;
    3424             : 
    3425             :                         if (tok == K_EXECUTE)
    3426             :                         {
    3427             :                             /* EXECUTE means it's a dynamic FOR loop */
    3428             :                             PLpgSQL_stmt_dynfors    *new;
    3429             :                             PLpgSQL_expr            *expr;
    3430             :                             int                     term;
    3431             : 
    3432             :                             expr = read_sql_expression2(K_LOOP, K_USING,
    3433             :                                                         "LOOP or USING",
    3434             :                                                         &term);
    3435             : 
    3436             :                             new = palloc0(sizeof(PLpgSQL_stmt_dynfors));
    3437             :                             new->cmd_type = PLPGSQL_STMT_DYNFORS;
    3438             :                             new->stmtid    = ++plpgsql_curr_compile->nstatements;
    3439             :                             if ((yyvsp[-1].forvariable).row)
    3440             :                             {
    3441             :                                 new->var = (PLpgSQL_variable *) (yyvsp[-1].forvariable).row;
    3442             :                                 check_assignable((yyvsp[-1].forvariable).row, (yylsp[-1]));
    3443             :                             }
    3444             :                             else if ((yyvsp[-1].forvariable).scalar)
    3445             :                             {
    3446             :                                 /* convert single scalar to list */
    3447             :                                 new->var = (PLpgSQL_variable *)
    3448             :                                     make_scalar_list1((yyvsp[-1].forvariable).name, (yyvsp[-1].forvariable).scalar,
    3449             :                                                       (yyvsp[-1].forvariable).lineno, (yylsp[-1]));
    3450             :                                 /* make_scalar_list1 did check_assignable */
    3451             :                             }
    3452             :                             else
    3453             :                             {
    3454             :                                 ereport(ERROR,
    3455             :                                         (errcode(ERRCODE_DATATYPE_MISMATCH),
    3456             :                                          errmsg("loop variable of loop over rows must be a record variable or list of scalar variables"),
    3457             :                                          parser_errposition((yylsp[-1]))));
    3458             :                             }
    3459             :                             new->query = expr;
    3460             : 
    3461             :                             if (term == K_USING)
    3462             :                             {
    3463             :                                 do
    3464             :                                 {
    3465             :                                     expr = read_sql_expression2(',', K_LOOP,
    3466             :                                                                 ", or LOOP",
    3467             :                                                                 &term);
    3468             :                                     new->params = lappend(new->params, expr);
    3469             :                                 } while (term == ',');
    3470             :                             }
    3471             : 
    3472             :                             (yyval.stmt) = (PLpgSQL_stmt *) new;
    3473             :                         }
    3474             :                         else if (tok == T_DATUM &&
    3475             :                                  yylval.wdatum.datum->dtype == PLPGSQL_DTYPE_VAR &&
    3476             :                                  ((PLpgSQL_var *) yylval.wdatum.datum)->datatype->typoid == REFCURSOROID)
    3477             :                         {
    3478             :                             /* It's FOR var IN cursor */
    3479             :                             PLpgSQL_stmt_forc   *new;
    3480             :                             PLpgSQL_var         *cursor = (PLpgSQL_var *) yylval.wdatum.datum;
    3481             : 
    3482             :                             new = (PLpgSQL_stmt_forc *) palloc0(sizeof(PLpgSQL_stmt_forc));
    3483             :                             new->cmd_type = PLPGSQL_STMT_FORC;
    3484             :                             new->stmtid = ++plpgsql_curr_compile->nstatements;
    3485             :                             new->curvar = cursor->dno;
    3486             : 
    3487             :                             /* Should have had a single variable name */
    3488             :                             if ((yyvsp[-1].forvariable).scalar && (yyvsp[-1].forvariable).row)
    3489             :                                 ereport(ERROR,
    3490             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
    3491             :                                          errmsg("cursor FOR loop must have only one target variable"),
    3492             :                                          parser_errposition((yylsp[-1]))));
    3493             : 
    3494             :                             /* can't use an unbound cursor this way */
    3495             :                             if (cursor->cursor_explicit_expr == NULL)
    3496             :                                 ereport(ERROR,
    3497             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
    3498             :                                          errmsg("cursor FOR loop must use a bound cursor variable"),
    3499             :                                          parser_errposition(tokloc)));
    3500             : 
    3501             :                             /* collect cursor's parameters if any */
    3502             :                             new->argquery = read_cursor_args(cursor,
    3503             :                                                              K_LOOP,
    3504             :                                                              "LOOP");
    3505             : 
    3506             :                             /* create loop's private RECORD variable */
    3507             :                             new->var = (PLpgSQL_variable *)
    3508             :                                 plpgsql_build_record((yyvsp[-1].forvariable).name,
    3509             :                                                      (yyvsp[-1].forvariable).lineno,
    3510             :                                                      NULL,
    3511             :                                                      RECORDOID,
    3512             :                                                      true);
    3513             : 
    3514             :                             (yyval.stmt) = (PLpgSQL_stmt *) new;
    3515             :                         }
    3516             :                         else
    3517             :                         {
    3518             :                             PLpgSQL_expr    *expr1;
    3519             :                             int             expr1loc;
    3520             :                             bool            reverse = false;
    3521             : 
    3522             :                             /*
    3523             :                              * We have to distinguish between two
    3524             :                              * alternatives: FOR var IN a .. b and FOR
    3525             :                              * var IN query. Unfortunately this is
    3526             :                              * tricky, since the query in the second
    3527             :                              * form needn't start with a SELECT
    3528             :                              * keyword.  We use the ugly hack of
    3529             :                              * looking for two periods after the first
    3530             :                              * token. We also check for the REVERSE
    3531             :                              * keyword, which means it must be an
    3532             :                              * integer loop.
    3533             :                              */
    3534             :                             if (tok_is_keyword(tok, &yylval,
    3535             :                                                K_REVERSE, "reverse"))
    3536             :                                 reverse = true;
    3537             :                             else
    3538             :                                 plpgsql_push_back_token(tok);
    3539             : 
    3540             :                             /*
    3541             :                              * Read tokens until we see either a ".."
    3542             :                              * or a LOOP. The text we read may not
    3543             :                              * necessarily be a well-formed SQL
    3544             :                              * statement, so we need to invoke
    3545             :                              * read_sql_construct directly.
    3546             :                              */
    3547             :                             expr1 = read_sql_construct(DOT_DOT,
    3548             :                                                        K_LOOP,
    3549             :                                                        0,
    3550             :                                                        "LOOP",
    3551             :                                                        "SELECT ",
    3552             :                                                        true,
    3553             :                                                        false,
    3554             :                                                        true,
    3555             :                                                        &expr1loc,
    3556             :                                                        &tok);
    3557             : 
    3558             :                             if (tok == DOT_DOT)
    3559             :                             {
    3560             :                                 /* Saw "..", so it must be an integer loop */
    3561             :                                 PLpgSQL_expr        *expr2;
    3562             :                                 PLpgSQL_expr        *expr_by;
    3563             :                                 PLpgSQL_var         *fvar;
    3564             :                                 PLpgSQL_stmt_fori   *new;
    3565             : 
    3566             :                                 /* Check first expression is well-formed */
    3567             :                                 check_sql_expr(expr1->query, expr1loc, 7);
    3568             : 
    3569             :                                 /* Read and check the second one */
    3570             :                                 expr2 = read_sql_expression2(K_LOOP, K_BY,
    3571             :                                                              "LOOP",
    3572             :                                                              &tok);
    3573             : 
    3574             :                                 /* Get the BY clause if any */
    3575             :                                 if (tok == K_BY)
    3576             :                                     expr_by = read_sql_expression(K_LOOP,
    3577             :                                                                   "LOOP");
    3578             :                                 else
    3579             :                                     expr_by = NULL;
    3580             : 
    3581             :                                 /* Should have had a single variable name */
    3582             :                                 if ((yyvsp[-1].forvariable).scalar && (yyvsp[-1].forvariable).row)
    3583             :                                     ereport(ERROR,
    3584             :                                             (errcode(ERRCODE_SYNTAX_ERROR),
    3585             :                                              errmsg("integer FOR loop must have only one target variable"),
    3586             :                                              parser_errposition((yylsp[-1]))));
    3587             : 
    3588             :                                 /* create loop's private variable */
    3589             :                                 fvar = (PLpgSQL_var *)
    3590             :                                     plpgsql_build_variable((yyvsp[-1].forvariable).name,
    3591             :                                                            (yyvsp[-1].forvariable).lineno,
    3592             :                                                            plpgsql_build_datatype(INT4OID,
    3593             :                                                                                   -1,
    3594             :                                                                                   InvalidOid),
    3595             :                                                            true);
    3596             : 
    3597             :                                 new = palloc0(sizeof(PLpgSQL_stmt_fori));
    3598             :                                 new->cmd_type = PLPGSQL_STMT_FORI;
    3599             :                                 new->stmtid    = ++plpgsql_curr_compile->nstatements;
    3600             :                                 new->var   = fvar;
    3601             :                                 new->reverse  = reverse;
    3602             :                                 new->lower     = expr1;
    3603             :                                 new->upper     = expr2;
    3604             :                                 new->step      = expr_by;
    3605             : 
    3606             :                                 (yyval.stmt) = (PLpgSQL_stmt *) new;
    3607             :                             }
    3608             :                             else
    3609             :                             {
    3610             :                                 /*
    3611             :                                  * No "..", so it must be a query loop. We've
    3612             :                                  * prefixed an extra SELECT to the query text,
    3613             :                                  * so we need to remove that before performing
    3614             :                                  * syntax checking.
    3615             :                                  */
    3616             :                                 char                *tmp_query;
    3617             :                                 PLpgSQL_stmt_fors   *new;
    3618             : 
    3619             :                                 if (reverse)
    3620             :                                     ereport(ERROR,
    3621             :                                             (errcode(ERRCODE_SYNTAX_ERROR),
    3622             :                                              errmsg("cannot specify REVERSE in query FOR loop"),
    3623             :                                              parser_errposition(tokloc)));
    3624             : 
    3625             :                                 Assert(strncmp(expr1->query, "SELECT ", 7) == 0);
    3626             :                                 tmp_query = pstrdup(expr1->query + 7);
    3627             :                                 pfree(expr1->query);
    3628             :                                 expr1->query = tmp_query;
    3629             : 
    3630             :                                 check_sql_expr(expr1->query, expr1loc, 0);
    3631             : 
    3632             :                                 new = palloc0(sizeof(PLpgSQL_stmt_fors));
    3633             :                                 new->cmd_type = PLPGSQL_STMT_FORS;
    3634             :                                 new->stmtid = ++plpgsql_curr_compile->nstatements;
    3635             :                                 if ((yyvsp[-1].forvariable).row)
    3636             :                                 {
    3637             :                                     new->var = (PLpgSQL_variable *) (yyvsp[-1].forvariable).row;
    3638             :                                     check_assignable((yyvsp[-1].forvariable).row, (yylsp[-1]));
    3639             :                                 }
    3640             :                                 else if ((yyvsp[-1].forvariable).scalar)
    3641             :                                 {
    3642             :                                     /* convert single scalar to list */
    3643             :                                     new->var = (PLpgSQL_variable *)
    3644             :                                         make_scalar_list1((yyvsp[-1].forvariable).name, (yyvsp[-1].forvariable).scalar,
    3645             :                                                           (yyvsp[-1].forvariable).lineno, (yylsp[-1]));
    3646             :                                     /* make_scalar_list1 did check_assignable */
    3647             :                                 }
    3648             :                                 else
    3649             :                                 {
    3650             :                                     ereport(ERROR,
    3651             :                                             (errcode(ERRCODE_SYNTAX_ERROR),
    3652             :                                              errmsg("loop variable of loop over rows must be a record variable or list of scalar variables"),
    3653             :                                              parser_errposition((yylsp[-1]))));
    3654             :                                 }
    3655             : 
    3656             :                                 new->query = expr1;
    3657             :                                 (yyval.stmt) = (PLpgSQL_stmt *) new;
    3658             :                             }
    3659             :                         }
    3660             :                     }
    3661             : #line 3662 "pl_gram.c" /* yacc.c:1646  */
    3662         502 :     break;
    3663             : 
    3664             :   case 119:
    3665             : #line 1595 "pl_gram.y" /* yacc.c:1646  */
    3666             :     {
    3667             :                         (yyval.forvariable).name = NameOfDatum(&((yyvsp[0].wdatum)));
    3668             :                         (yyval.forvariable).lineno = plpgsql_location_to_lineno((yylsp[0]));
    3669             :                         if ((yyvsp[0].wdatum).datum->dtype == PLPGSQL_DTYPE_ROW ||
    3670             :                             (yyvsp[0].wdatum).datum->dtype == PLPGSQL_DTYPE_REC)
    3671             :                         {
    3672             :                             (yyval.forvariable).scalar = NULL;
    3673             :                             (yyval.forvariable).row = (yyvsp[0].wdatum).datum;
    3674             :                         }
    3675             :                         else
    3676             :                         {
    3677             :                             int         tok;
    3678             : 
    3679             :                             (yyval.forvariable).scalar = (yyvsp[0].wdatum).datum;
    3680             :                             (yyval.forvariable).row = NULL;
    3681             :                             /* check for comma-separated list */
    3682             :                             tok = yylex();
    3683             :                             plpgsql_push_back_token(tok);
    3684             :                             if (tok == ',')
    3685             :                                 (yyval.forvariable).row = (PLpgSQL_datum *)
    3686             :                                     read_into_scalar_list((yyval.forvariable).name,
    3687             :                                                           (yyval.forvariable).scalar,
    3688             :                                                           (yylsp[0]));
    3689             :                         }
    3690             :                     }
    3691             : #line 3692 "pl_gram.c" /* yacc.c:1646  */
    3692         348 :     break;
    3693             : 
    3694             :   case 120:
    3695             : #line 1621 "pl_gram.y" /* yacc.c:1646  */
    3696             :     {
    3697             :                         int         tok;
    3698             : 
    3699             :                         (yyval.forvariable).name = (yyvsp[0].word).ident;
    3700             :                         (yyval.forvariable).lineno = plpgsql_location_to_lineno((yylsp[0]));
    3701             :                         (yyval.forvariable).scalar = NULL;
    3702             :                         (yyval.forvariable).row = NULL;
    3703             :                         /* check for comma-separated list */
    3704             :                         tok = yylex();
    3705             :                         plpgsql_push_back_token(tok);
    3706             :                         if (tok == ',')
    3707             :                             word_is_not_variable(&((yyvsp[0].word)), (yylsp[0]));
    3708             :                     }
    3709             : #line 3710 "pl_gram.c" /* yacc.c:1646  */
    3710         204 :     break;
    3711             : 
    3712             :   case 121:
    3713             : #line 1635 "pl_gram.y" /* yacc.c:1646  */
    3714             :     {
    3715             :                         /* just to give a better message than "syntax error" */
    3716             :                         cword_is_not_variable(&((yyvsp[0].cword)), (yylsp[0]));
    3717             :                     }
    3718             : #line 3719 "pl_gram.c" /* yacc.c:1646  */
    3719           0 :     break;
    3720             : 
    3721             :   case 122:
    3722             : #line 1642 "pl_gram.y" /* yacc.c:1646  */
    3723             :     {
    3724             :                         PLpgSQL_stmt_foreach_a *new;
    3725             : 
    3726             :                         new = palloc0(sizeof(PLpgSQL_stmt_foreach_a));
    3727             :                         new->cmd_type = PLPGSQL_STMT_FOREACH_A;
    3728             :                         new->lineno = plpgsql_location_to_lineno((yylsp[-6]));
    3729             :                         new->stmtid = ++plpgsql_curr_compile->nstatements;
    3730             :                         new->label = (yyvsp[-7].str);
    3731             :                         new->slice = (yyvsp[-4].ival);
    3732             :                         new->expr = (yyvsp[-1].expr);
    3733             :                         new->body = (yyvsp[0].loop_body).stmts;
    3734             : 
    3735             :                         if ((yyvsp[-5].forvariable).row)
    3736             :                         {
    3737             :                             new->varno = (yyvsp[-5].forvariable).row->dno;
    3738             :                             check_assignable((yyvsp[-5].forvariable).row, (yylsp[-5]));
    3739             :                         }
    3740             :                         else if ((yyvsp[-5].forvariable).scalar)
    3741             :                         {
    3742             :                             new->varno = (yyvsp[-5].forvariable).scalar->dno;
    3743             :                             check_assignable((yyvsp[-5].forvariable).scalar, (yylsp[-5]));
    3744             :                         }
    3745             :                         else
    3746             :                         {
    3747             :                             ereport(ERROR,
    3748             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    3749             :                                      errmsg("loop variable of FOREACH must be a known variable or list of variables"),
    3750             :                                              parser_errposition((yylsp[-5]))));
    3751             :                         }
    3752             : 
    3753             :                         check_labels((yyvsp[-7].str), (yyvsp[0].loop_body).end_label, (yyvsp[0].loop_body).end_label_location);
    3754             :                         plpgsql_ns_pop();
    3755             : 
    3756             :                         (yyval.stmt) = (PLpgSQL_stmt *) new;
    3757             :                     }
    3758             : #line 3759 "pl_gram.c" /* yacc.c:1646  */
    3759          40 :     break;
    3760             : 
    3761             :   case 123:
    3762             : #line 1680 "pl_gram.y" /* yacc.c:1646  */
    3763             :     {
    3764             :                         (yyval.ival) = 0;
    3765             :                     }
    3766             : #line 3767 "pl_gram.c" /* yacc.c:1646  */
    3767          20 :     break;
    3768             : 
    3769             :   case 124:
    3770             : #line 1684 "pl_gram.y" /* yacc.c:1646  */
    3771             :     {
    3772             :                         (yyval.ival) = (yyvsp[0].ival);
    3773             :                     }
    3774             : #line 3775 "pl_gram.c" /* yacc.c:1646  */
    3775          20 :     break;
    3776             : 
    3777             :   case 125:
    3778             : #line 1690 "pl_gram.y" /* yacc.c:1646  */
    3779             :     {
    3780             :                         PLpgSQL_stmt_exit *new;
    3781             : 
    3782             :                         new = palloc0(sizeof(PLpgSQL_stmt_exit));
    3783             :                         new->cmd_type = PLPGSQL_STMT_EXIT;
    3784             :                         new->stmtid    = ++plpgsql_curr_compile->nstatements;
    3785             :                         new->is_exit  = (yyvsp[-2].boolean);
    3786             :                         new->lineno    = plpgsql_location_to_lineno((yylsp[-2]));
    3787             :                         new->label     = (yyvsp[-1].str);
    3788             :                         new->cond      = (yyvsp[0].expr);
    3789             : 
    3790             :                         if ((yyvsp[-1].str))
    3791             :                         {
    3792             :                             /* We have a label, so verify it exists */
    3793             :                             PLpgSQL_nsitem *label;
    3794             : 
    3795             :                             label = plpgsql_ns_lookup_label(plpgsql_ns_top(), (yyvsp[-1].str));
    3796             :                             if (label == NULL)
    3797             :                                 ereport(ERROR,
    3798             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
    3799             :                                          errmsg("there is no label \"%s\" "
    3800             :                                                 "attached to any block or loop enclosing this statement",
    3801             :                                                 (yyvsp[-1].str)),
    3802             :                                          parser_errposition((yylsp[-1]))));
    3803             :                             /* CONTINUE only allows loop labels */
    3804             :                             if (label->itemno != PLPGSQL_LABEL_LOOP && !new->is_exit)
    3805             :                                 ereport(ERROR,
    3806             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
    3807             :                                          errmsg("block label \"%s\" cannot be used in CONTINUE",
    3808             :                                                 (yyvsp[-1].str)),
    3809             :                                          parser_errposition((yylsp[-1]))));
    3810             :                         }
    3811             :                         else
    3812             :                         {
    3813             :                             /*
    3814             :                              * No label, so make sure there is some loop (an
    3815             :                              * unlabelled EXIT does not match a block, so this
    3816             :                              * is the same test for both EXIT and CONTINUE)
    3817             :                              */
    3818             :                             if (plpgsql_ns_find_nearest_loop(plpgsql_ns_top()) == NULL)
    3819             :                                 ereport(ERROR,
    3820             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
    3821             :                                          new->is_exit ?
    3822             :                                          errmsg("EXIT cannot be used outside a loop, unless it has a label") :
    3823             :                                          errmsg("CONTINUE cannot be used outside a loop"),
    3824             :                                          parser_errposition((yylsp[-2]))));
    3825             :                         }
    3826             : 
    3827             :                         (yyval.stmt) = (PLpgSQL_stmt *)new;
    3828             :                     }
    3829             : #line 3830 "pl_gram.c" /* yacc.c:1646  */
    3830          90 :     break;
    3831             : 
    3832             :   case 126:
    3833             : #line 1743 "pl_gram.y" /* yacc.c:1646  */
    3834             :     {
    3835             :                         (yyval.boolean) = true;
    3836             :                     }
    3837             : #line 3838 "pl_gram.c" /* yacc.c:1646  */
    3838          62 :     break;
    3839             : 
    3840             :   case 127:
    3841             : #line 1747 "pl_gram.y" /* yacc.c:1646  */
    3842             :     {
    3843             :                         (yyval.boolean) = false;
    3844             :                     }
    3845             : #line 3846 "pl_gram.c" /* yacc.c:1646  */
    3846          38 :     break;
    3847             : 
    3848             :   case 128:
    3849             : #line 1753 "pl_gram.y" /* yacc.c:1646  */
    3850             :     {
    3851             :                         int tok;
    3852             : 
    3853             :                         tok = yylex();
    3854             :                         if (tok == 0)
    3855             :                             yyerror("unexpected end of function definition");
    3856             : 
    3857             :                         if (tok_is_keyword(tok, &yylval,
    3858             :                                            K_NEXT, "next"))
    3859             :                         {
    3860             :                             (yyval.stmt) = make_return_next_stmt((yylsp[0]));
    3861             :                         }
    3862             :                         else if (tok_is_keyword(tok, &yylval,
    3863             :                                                 K_QUERY, "query"))
    3864             :                         {
    3865             :                             (yyval.stmt) = make_return_query_stmt((yylsp[0]));
    3866             :                         }
    3867             :                         else
    3868             :                         {
    3869             :                             plpgsql_push_back_token(tok);
    3870             :                             (yyval.stmt) = make_return_stmt((yylsp[0]));
    3871             :                         }
    3872             :                     }
    3873             : #line 3874 "pl_gram.c" /* yacc.c:1646  */
    3874        3990 :     break;
    3875             : 
    3876             :   case 129:
    3877             : #line 1779 "pl_gram.y" /* yacc.c:1646  */
    3878             :     {
    3879             :                         PLpgSQL_stmt_raise      *new;
    3880             :                         int tok;
    3881             : 
    3882             :                         new = palloc(sizeof(PLpgSQL_stmt_raise));
    3883             : 
    3884             :                         new->cmd_type    = PLPGSQL_STMT_RAISE;
    3885             :                         new->lineno      = plpgsql_location_to_lineno((yylsp[0]));
    3886             :                         new->stmtid      = ++plpgsql_curr_compile->nstatements;
    3887             :                         new->elog_level = ERROR; /* default */
    3888             :                         new->condname    = NULL;
    3889             :                         new->message = NULL;
    3890             :                         new->params      = NIL;
    3891             :                         new->options = NIL;
    3892             : 
    3893             :                         tok = yylex();
    3894             :                         if (tok == 0)
    3895             :                             yyerror("unexpected end of function definition");
    3896             : 
    3897             :                         /*
    3898             :                          * We could have just RAISE, meaning to re-throw
    3899             :                          * the current error.
    3900             :                          */
    3901             :                         if (tok != ';')
    3902             :                         {
    3903             :                             /*
    3904             :                              * First is an optional elog severity level.
    3905             :                              */
    3906             :                             if (tok_is_keyword(tok, &yylval,
    3907             :                                                K_EXCEPTION, "exception"))
    3908             :                             {
    3909             :                                 new->elog_level = ERROR;
    3910             :                                 tok = yylex();
    3911             :                             }
    3912             :                             else if (tok_is_keyword(tok, &yylval,
    3913             :                                                     K_WARNING, "warning"))
    3914             :                             {
    3915             :                                 new->elog_level = WARNING;
    3916             :                                 tok = yylex();
    3917             :                             }
    3918             :                             else if (tok_is_keyword(tok, &yylval,
    3919             :                                                     K_NOTICE, "notice"))
    3920             :                             {
    3921             :                                 new->elog_level = NOTICE;
    3922             :                                 tok = yylex();
    3923             :                             }
    3924             :                             else if (tok_is_keyword(tok, &yylval,
    3925             :                                                     K_INFO, "info"))
    3926             :                             {
    3927             :                                 new->elog_level = INFO;
    3928             :                                 tok = yylex();
    3929             :                             }
    3930             :                             else if (tok_is_keyword(tok, &yylval,
    3931             :                                                     K_LOG, "log"))
    3932             :                             {
    3933             :                                 new->elog_level = LOG;
    3934             :                                 tok = yylex();
    3935             :                             }
    3936             :                             else if (tok_is_keyword(tok, &yylval,
    3937             :                                                     K_DEBUG, "debug"))
    3938             :                             {
    3939             :                                 new->elog_level = DEBUG1;
    3940             :                                 tok = yylex();
    3941             :                             }
    3942             :                             if (tok == 0)
    3943             :                                 yyerror("unexpected end of function definition");
    3944             : 
    3945             :                             /*
    3946             :                              * Next we can have a condition name, or
    3947             :                              * equivalently SQLSTATE 'xxxxx', or a string
    3948             :                              * literal that is the old-style message format,
    3949             :                              * or USING to start the option list immediately.
    3950             :                              */
    3951             :                             if (tok == SCONST)
    3952             :                             {
    3953             :                                 /* old style message and parameters */
    3954             :                                 new->message = yylval.str;
    3955             :                                 /*
    3956             :                                  * We expect either a semi-colon, which
    3957             :                                  * indicates no parameters, or a comma that
    3958             :                                  * begins the list of parameter expressions,
    3959             :                                  * or USING to begin the options list.
    3960             :                                  */
    3961             :                                 tok = yylex();
    3962             :                                 if (tok != ',' && tok != ';' && tok != K_USING)
    3963             :                                     yyerror("syntax error");
    3964             : 
    3965             :                                 while (tok == ',')
    3966             :                                 {
    3967             :                                     PLpgSQL_expr *expr;
    3968             : 
    3969             :                                     expr = read_sql_construct(',', ';', K_USING,
    3970             :                                                               ", or ; or USING",
    3971             :                                                               "SELECT ",
    3972             :                                                               true, true, true,
    3973             :                                                               NULL, &tok);
    3974             :                                     new->params = lappend(new->params, expr);
    3975             :                                 }
    3976             :                             }
    3977             :                             else if (tok != K_USING)
    3978             :                             {
    3979             :                                 /* must be condition name or SQLSTATE */
    3980             :                                 if (tok_is_keyword(tok, &yylval,
    3981             :                                                    K_SQLSTATE, "sqlstate"))
    3982             :                                 {
    3983             :                                     /* next token should be a string literal */
    3984             :                                     char   *sqlstatestr;
    3985             : 
    3986             :                                     if (yylex() != SCONST)
    3987             :                                         yyerror("syntax error");
    3988             :                                     sqlstatestr = yylval.str;
    3989             : 
    3990             :                                     if (strlen(sqlstatestr) != 5)
    3991             :                                         yyerror("invalid SQLSTATE code");
    3992             :                                     if (strspn(sqlstatestr, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") != 5)
    3993             :                                         yyerror("invalid SQLSTATE code");
    3994             :                                     new->condname = sqlstatestr;
    3995             :                                 }
    3996             :                                 else
    3997             :                                 {
    3998             :                                     if (tok == T_WORD)
    3999             :                                         new->condname = yylval.word.ident;
    4000             :                                     else if (plpgsql_token_is_unreserved_keyword(tok))
    4001             :                                         new->condname = pstrdup(yylval.keyword);
    4002             :                                     else
    4003             :                                         yyerror("syntax error");
    4004             :                                     plpgsql_recognize_err_condition(new->condname,
    4005             :                                                                     false);
    4006             :                                 }
    4007             :                                 tok = yylex();
    4008             :                                 if (tok != ';' && tok != K_USING)
    4009             :                                     yyerror("syntax error");
    4010             :                             }
    4011             : 
    4012             :                             if (tok == K_USING)
    4013             :                                 new->options = read_raise_options();
    4014             :                         }
    4015             : 
    4016             :                         check_raise_parameters(new);
    4017             : 
    4018             :                         (yyval.stmt) = (PLpgSQL_stmt *)new;
    4019             :                     }
    4020             : #line 4021 "pl_gram.c" /* yacc.c:1646  */
    4021        2850 :     break;
    4022             : 
    4023             :   case 130:
    4024             : #line 1924 "pl_gram.y" /* yacc.c:1646  */
    4025             :     {
    4026             :                         PLpgSQL_stmt_assert     *new;
    4027             :                         int tok;
    4028             : 
    4029             :                         new = palloc(sizeof(PLpgSQL_stmt_assert));
    4030             : 
    4031             :                         new->cmd_type    = PLPGSQL_STMT_ASSERT;
    4032             :                         new->lineno      = plpgsql_location_to_lineno((yylsp[0]));
    4033             :                         new->stmtid      = ++plpgsql_curr_compile->nstatements;
    4034             : 
    4035             :                         new->cond = read_sql_expression2(',', ';',
    4036             :                                                          ", or ;",
    4037             :                                                          &tok);
    4038             : 
    4039             :                         if (tok == ',')
    4040             :                             new->message = read_sql_expression(';', ";");
    4041             :                         else
    4042             :                             new->message = NULL;
    4043             : 
    4044             :                         (yyval.stmt) = (PLpgSQL_stmt *) new;
    4045             :                     }
    4046             : #line 4047 "pl_gram.c" /* yacc.c:1646  */
    4047          34 :     break;
    4048             : 
    4049             :   case 131:
    4050             : #line 1948 "pl_gram.y" /* yacc.c:1646  */
    4051             :     {
    4052             :                         (yyval.loop_body).stmts = (yyvsp[-4].list);
    4053             :                         (yyval.loop_body).end_label = (yyvsp[-1].str);
    4054             :                         (yyval.loop_body).end_label_location = (yylsp[-1]);
    4055             :                     }
    4056             : #line 4057 "pl_gram.c" /* yacc.c:1646  */
    4057         628 :     break;
    4058             : 
    4059             :   case 132:
    4060             : #line 1966 "pl_gram.y" /* yacc.c:1646  */
    4061             :     {
    4062             :                         (yyval.stmt) = make_execsql_stmt(K_IMPORT, (yylsp[0]));
    4063             :                     }
    4064             : #line 4065 "pl_gram.c" /* yacc.c:1646  */
    4065           0 :     break;
    4066             : 
    4067             :   case 133:
    4068             : #line 1970 "pl_gram.y" /* yacc.c:1646  */
    4069             :     {
    4070             :                         (yyval.stmt) = make_execsql_stmt(K_INSERT, (yylsp[0]));
    4071             :                     }
    4072             : #line 4073 "pl_gram.c" /* yacc.c:1646  */
    4073         356 :     break;
    4074             : 
    4075             :   case 134:
    4076             : #line 1974 "pl_gram.y" /* yacc.c:1646  */
    4077             :     {
    4078             :                         int         tok;
    4079             : 
    4080             :                         tok = yylex();
    4081             :                         plpgsql_push_back_token(tok);
    4082             :                         if (tok == '=' || tok == COLON_EQUALS || tok == '[')
    4083             :                             word_is_not_variable(&((yyvsp[0].word)), (yylsp[0]));
    4084             :                         (yyval.stmt) = make_execsql_stmt(T_WORD, (yylsp[0]));
    4085             :                     }
    4086             : #line 4087 "pl_gram.c" /* yacc.c:1646  */
    4087         996 :     break;
    4088             : 
    4089             :   case 135:
    4090             : #line 1984 "pl_gram.y" /* yacc.c:1646  */
    4091             :     {
    4092             :                         int         tok;
    4093             : 
    4094             :                         tok = yylex();
    4095             :                         plpgsql_push_back_token(tok);
    4096             :                         if (tok == '=' || tok == COLON_EQUALS || tok == '[')
    4097             :                             cword_is_not_variable(&((yyvsp[0].cword)), (yylsp[0]));
    4098             :                         (yyval.stmt) = make_execsql_stmt(T_CWORD, (yylsp[0]));
    4099             :                     }
    4100             : #line 4101 "pl_gram.c" /* yacc.c:1646  */
    4101           0 :     break;
    4102             : 
    4103             :   case 136:
    4104             : #line 1996 "pl_gram.y" /* yacc.c:1646  */
    4105             :     {
    4106             :                         PLpgSQL_stmt_dynexecute *new;
    4107             :                         PLpgSQL_expr *expr;
    4108             :                         int endtoken;
    4109             : 
    4110             :                         expr = read_sql_construct(K_INTO, K_USING, ';',
    4111             :                                                   "INTO or USING or ;",
    4112             :                                                   "SELECT ",
    4113             :                                                   true, true, true,
    4114             :                                                   NULL, &endtoken);
    4115             : 
    4116             :                         new = palloc(sizeof(PLpgSQL_stmt_dynexecute));
    4117             :                         new->cmd_type = PLPGSQL_STMT_DYNEXECUTE;
    4118             :                         new->lineno = plpgsql_location_to_lineno((yylsp[0]));
    4119             :                         new->stmtid = ++plpgsql_curr_compile->nstatements;
    4120             :                         new->query = expr;
    4121             :                         new->into = false;
    4122             :                         new->strict = false;
    4123             :                         new->target = NULL;
    4124             :                         new->params = NIL;
    4125             : 
    4126             :                         /*
    4127             :                          * We loop to allow the INTO and USING clauses to
    4128             :                          * appear in either order, since people easily get
    4129             :                          * that wrong.  This coding also prevents "INTO foo"
    4130             :                          * from getting absorbed into a USING expression,
    4131             :                          * which is *really* confusing.
    4132             :                          */
    4133             :                         for (;;)
    4134             :                         {
    4135             :                             if (endtoken == K_INTO)
    4136             :                             {
    4137             :                                 if (new->into)           /* multiple INTO */
    4138             :                                     yyerror("syntax error");
    4139             :                                 new->into = true;
    4140             :                                 read_into_target(&new->target, &new->strict);
    4141             :                                 endtoken = yylex();
    4142             :                             }
    4143             :                             else if (endtoken == K_USING)
    4144             :                             {
    4145             :                                 if (new->params)     /* multiple USING */
    4146             :                                     yyerror("syntax error");
    4147             :                                 do
    4148             :                                 {
    4149             :                                     expr = read_sql_construct(',', ';', K_INTO,
    4150             :                                                               ", or ; or INTO",
    4151             :                                                               "SELECT ",
    4152             :                                                               true, true, true,
    4153             :                                                               NULL, &endtoken);
    4154             :                                     new->params = lappend(new->params, expr);
    4155             :                                 } while (endtoken == ',');
    4156             :                             }
    4157             :                             else if (endtoken == ';')
    4158             :                                 break;
    4159             :                             else
    4160             :                                 yyerror("syntax error");
    4161             :                         }
    4162             : 
    4163             :                         (yyval.stmt) = (PLpgSQL_stmt *)new;
    4164             :                     }
    4165             : #line 4166 "pl_gram.c" /* yacc.c:1646  */
    4166         204 :     break;
    4167             : 
    4168             :   case 137:
    4169             : #line 2060 "pl_gram.y" /* yacc.c:1646  */
    4170             :     {
    4171             :                         PLpgSQL_stmt_open *new;
    4172             :                         int               tok;
    4173             : 
    4174             :                         new = palloc0(sizeof(PLpgSQL_stmt_open));
    4175             :                         new->cmd_type = PLPGSQL_STMT_OPEN;
    4176             :                         new->lineno = plpgsql_location_to_lineno((yylsp[-1]));
    4177             :                         new->stmtid = ++plpgsql_curr_compile->nstatements;
    4178             :                         new->curvar = (yyvsp[0].var)->dno;
    4179             :                         new->cursor_options = CURSOR_OPT_FAST_PLAN;
    4180             : 
    4181             :                         if ((yyvsp[0].var)->cursor_explicit_expr == NULL)
    4182             :                         {
    4183             :                             /* be nice if we could use opt_scrollable here */
    4184             :                             tok = yylex();
    4185             :                             if (tok_is_keyword(tok, &yylval,
    4186             :                                                K_NO, "no"))
    4187             :                             {
    4188             :                                 tok = yylex();
    4189             :                                 if (tok_is_keyword(tok, &yylval,
    4190             :                                                    K_SCROLL, "scroll"))
    4191             :                                 {
    4192             :                                     new->cursor_options |= CURSOR_OPT_NO_SCROLL;
    4193             :                                     tok = yylex();
    4194             :                                 }
    4195             :                             }
    4196             :                             else if (tok_is_keyword(tok, &yylval,
    4197             :                                                     K_SCROLL, "scroll"))
    4198             :                             {
    4199             :                                 new->cursor_options |= CURSOR_OPT_SCROLL;
    4200             :                                 tok = yylex();
    4201             :                             }
    4202             : 
    4203             :                             if (tok != K_FOR)
    4204             :                                 yyerror("syntax error, expected \"FOR\"");
    4205             : 
    4206             :                             tok = yylex();
    4207             :                             if (tok == K_EXECUTE)
    4208             :                             {
    4209             :                                 int     endtoken;
    4210             : 
    4211             :                                 new->dynquery =
    4212             :                                     read_sql_expression2(K_USING, ';',
    4213             :                                                          "USING or ;",
    4214             :                                                          &endtoken);
    4215             : 
    4216             :                                 /* If we found "USING", collect argument(s) */
    4217             :                                 if (endtoken == K_USING)
    4218             :                                 {
    4219             :                                     PLpgSQL_expr *expr;
    4220             : 
    4221             :                                     do
    4222             :                                     {
    4223             :                                         expr = read_sql_expression2(',', ';',
    4224             :                                                                     ", or ;",
    4225             :                                                                     &endtoken);
    4226             :                                         new->params = lappend(new->params,
    4227             :                                                               expr);
    4228             :                                     } while (endtoken == ',');
    4229             :                                 }
    4230             :                             }
    4231             :                             else
    4232             :                             {
    4233             :                                 plpgsql_push_back_token(tok);
    4234             :                                 new->query = read_sql_stmt("");
    4235             :                             }
    4236             :                         }
    4237             :                         else
    4238             :                         {
    4239             :                             /* predefined cursor query, so read args */
    4240             :                             new->argquery = read_cursor_args((yyvsp[0].var), ';', ";");
    4241             :                         }
    4242             : 
    4243             :                         (yyval.stmt) = (PLpgSQL_stmt *)new;
    4244             :                     }
    4245             : #line 4246 "pl_gram.c" /* yacc.c:1646  */
    4246          68 :     break;
    4247             : 
    4248             :   case 138:
    4249             : #line 2138 "pl_gram.y" /* yacc.c:1646  */
    4250             :     {
    4251             :                         PLpgSQL_stmt_fetch *fetch = (yyvsp[-2].fetch);
    4252             :                         PLpgSQL_variable *target;
    4253             : 
    4254             :                         /* We have already parsed everything through the INTO keyword */
    4255             :                         read_into_target(&target, NULL);
    4256             : 
    4257             :                         if (yylex() != ';')
    4258             :                             yyerror("syntax error");
    4259             : 
    4260             :                         /*
    4261             :                          * We don't allow multiple rows in PL/pgSQL's FETCH
    4262             :                          * statement, only in MOVE.
    4263             :                          */
    4264             :                         if (fetch->returns_multiple_rows)
    4265             :                             ereport(ERROR,
    4266             :                                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4267             :                                      errmsg("FETCH statement cannot return multiple rows"),
    4268             :                                      parser_errposition((yylsp[-3]))));
    4269             : 
    4270             :                         fetch->lineno = plpgsql_location_to_lineno((yylsp[-3]));
    4271             :                         fetch->target    = target;
    4272             :                         fetch->curvar    = (yyvsp[-1].var)->dno;
    4273             :                         fetch->is_move   = false;
    4274             : 
    4275             :                         (yyval.stmt) = (PLpgSQL_stmt *)fetch;
    4276             :                     }
    4277             : #line 4278 "pl_gram.c" /* yacc.c:1646  */
    4278          80 :     break;
    4279             : 
    4280             :   case 139:
    4281             : #line 2168 "pl_gram.y" /* yacc.c:1646  */
    4282             :     {
    4283             :                         PLpgSQL_stmt_fetch *fetch = (yyvsp[-2].fetch);
    4284             : 
    4285             :                         fetch->lineno = plpgsql_location_to_lineno((yylsp[-3]));
    4286             :                         fetch->curvar    = (yyvsp[-1].var)->dno;
    4287             :                         fetch->is_move   = true;
    4288             : 
    4289             :                         (yyval.stmt) = (PLpgSQL_stmt *)fetch;
    4290             :                     }
    4291             : #line 4292 "pl_gram.c" /* yacc.c:1646  */
    4292          12 :     break;
    4293             : 
    4294             :   case 140:
    4295             : #line 2180 "pl_gram.y" /* yacc.c:1646  */
    4296             :     {
    4297             :                         (yyval.fetch) = read_fetch_direction();
    4298             :                     }
    4299             : #line 4300 "pl_gram.c" /* yacc.c:1646  */
    4300          92 :     break;
    4301             : 
    4302             :   case 141:
    4303             : #line 2186 "pl_gram.y" /* yacc.c:1646  */
    4304             :     {
    4305             :                         PLpgSQL_stmt_close *new;
    4306             : 
    4307             :                         new = palloc(sizeof(PLpgSQL_stmt_close));
    4308             :                         new->cmd_type = PLPGSQL_STMT_CLOSE;
    4309             :                         new->lineno = plpgsql_location_to_lineno((yylsp[-2]));
    4310             :                         new->stmtid = ++plpgsql_curr_compile->nstatements;
    4311             :                         new->curvar = (yyvsp[-1].var)->dno;
    4312             : 
    4313             :                         (yyval.stmt) = (PLpgSQL_stmt *)new;
    4314             :                     }
    4315             : #line 4316 "pl_gram.c" /* yacc.c:1646  */
    4316          44 :     break;
    4317             : 
    4318             :   case 142:
    4319             : #line 2200 "pl_gram.y" /* yacc.c:1646  */
    4320             :     {
    4321             :                         /* We do not bother building a node for NULL */
    4322             :                         (yyval.stmt) = NULL;
    4323             :                     }
    4324             : #line 4325 "pl_gram.c" /* yacc.c:1646  */
    4325          20 :     break;
    4326             : 
    4327             :   case 143:
    4328             : #line 2207 "pl_gram.y" /* yacc.c:1646  */
    4329             :     {
    4330             :                         PLpgSQL_stmt_commit *new;
    4331             : 
    4332             :                         new = palloc(sizeof(PLpgSQL_stmt_commit));
    4333             :                         new->cmd_type = PLPGSQL_STMT_COMMIT;
    4334             :                         new->lineno = plpgsql_location_to_lineno((yylsp[-2]));
    4335             :                         new->stmtid = ++plpgsql_curr_compile->nstatements;
    4336             :                         new->chain = (yyvsp[-1].ival);
    4337             : 
    4338             :                         (yyval.stmt) = (PLpgSQL_stmt *)new;
    4339             :                     }
    4340             : #line 4341 "pl_gram.c" /* yacc.c:1646  */
    4341          60 :     break;
    4342             : 
    4343             :   case 144:
    4344             : #line 2221 "pl_gram.y" /* yacc.c:1646  */
    4345             :     {
    4346             :                         PLpgSQL_stmt_rollback *new;
    4347             : 
    4348             :                         new = palloc(sizeof(PLpgSQL_stmt_rollback));
    4349             :                         new->cmd_type = PLPGSQL_STMT_ROLLBACK;
    4350             :                         new->lineno = plpgsql_location_to_lineno((yylsp[-2]));
    4351             :                         new->stmtid = ++plpgsql_curr_compile->nstatements;
    4352             :                         new->chain = (yyvsp[-1].ival);
    4353             : 
    4354             :                         (yyval.stmt) = (PLpgSQL_stmt *)new;
    4355             :                     }
    4356             : #line 4357 "pl_gram.c" /* yacc.c:1646  */
    4357          30 :     break;
    4358             : 
    4359             :   case 145:
    4360             : #line 2235 "pl_gram.y" /* yacc.c:1646  */
    4361             :     { (yyval.ival) = true; }
    4362             : #line 4363 "pl_gram.c" /* yacc.c:1646  */
    4363           4 :     break;
    4364             : 
    4365             :   case 146:
    4366             : #line 2236 "pl_gram.y" /* yacc.c:1646  */
    4367             :     { (yyval.ival) = false; }
    4368             : #line 4369 "pl_gram.c" /* yacc.c:1646  */
    4369           0 :     break;
    4370             : 
    4371             :   case 147:
    4372             : #line 2237 "pl_gram.y" /* yacc.c:1646  */
    4373             :     { (yyval.ival) = false; }
    4374             : #line 4375 "pl_gram.c" /* yacc.c:1646  */
    4375          86 :     break;
    4376             : 
    4377             :   case 148:
    4378             : #line 2241 "pl_gram.y" /* yacc.c:1646  */
    4379             :     {
    4380             :                         PLpgSQL_stmt_set *new;
    4381             : 
    4382             :                         new = palloc0(sizeof(PLpgSQL_stmt_set));
    4383             :                         new->cmd_type = PLPGSQL_STMT_SET;
    4384             :                         new->lineno = plpgsql_location_to_lineno((yylsp[0]));
    4385             :                         new->stmtid = ++plpgsql_curr_compile->nstatements;
    4386             : 
    4387             :                         new->expr = read_sql_stmt("SET ");
    4388             : 
    4389             :                         (yyval.stmt) = (PLpgSQL_stmt *)new;
    4390             :                     }
    4391             : #line 4392 "pl_gram.c" /* yacc.c:1646  */
    4392          62 :     break;
    4393             : 
    4394             :   case 149:
    4395             : #line 2254 "pl_gram.y" /* yacc.c:1646  */
    4396             :     {
    4397             :                         PLpgSQL_stmt_set *new;
    4398             : 
    4399             :                         new = palloc0(sizeof(PLpgSQL_stmt_set));
    4400             :                         new->cmd_type = PLPGSQL_STMT_SET;
    4401             :                         new->lineno = plpgsql_location_to_lineno((yylsp[0]));
    4402             :                         new->stmtid = ++plpgsql_curr_compile->nstatements;
    4403             :                         new->expr = read_sql_stmt("RESET ");
    4404             : 
    4405             :                         (yyval.stmt) = (PLpgSQL_stmt *)new;
    4406             :                     }
    4407             : #line 4408 "pl_gram.c" /* yacc.c:1646  */
    4408           2 :     break;
    4409             : 
    4410             :   case 150:
    4411             : #line 2269 "pl_gram.y" /* yacc.c:1646  */
    4412             :     {
    4413             :                         /*
    4414             :                          * In principle we should support a cursor_variable
    4415             :                          * that is an array element, but for now we don't, so
    4416             :                          * just throw an error if next token is '['.
    4417             :                          */
    4418             :                         if ((yyvsp[0].wdatum).datum->dtype != PLPGSQL_DTYPE_VAR ||
    4419             :                             plpgsql_peek() == '[')
    4420             :                             ereport(ERROR,
    4421             :                                     (errcode(ERRCODE_DATATYPE_MISMATCH),
    4422             :                                      errmsg("cursor variable must be a simple variable"),
    4423             :                                      parser_errposition((yylsp[0]))));
    4424             : 
    4425             :                         if (((PLpgSQL_var *) (yyvsp[0].wdatum).datum)->datatype->typoid != REFCURSOROID)
    4426             :                             ereport(ERROR,
    4427             :                                     (errcode(ERRCODE_DATATYPE_MISMATCH),
    4428             :                                      errmsg("variable \"%s\" must be of type cursor or refcursor",
    4429             :                                             ((PLpgSQL_var *) (yyvsp[0].wdatum).datum)->refname),
    4430             :                                      parser_errposition((yylsp[0]))));
    4431             :                         (yyval.var) = (PLpgSQL_var *) (yyvsp[0].wdatum).datum;
    4432             :                     }
    4433             : #line 4434 "pl_gram.c" /* yacc.c:1646  */
    4434         220 :     break;
    4435             : 
    4436             :   case 151:
    4437             : #line 2291 "pl_gram.y" /* yacc.c:1646  */
    4438             :     {
    4439             :                         /* just to give a better message than "syntax error" */
    4440             :                         word_is_not_variable(&((yyvsp[0].word)), (yylsp[0]));
    4441             :                     }
    4442             : #line 4443 "pl_gram.c" /* yacc.c:1646  */
    4443           0 :     break;
    4444             : 
    4445             :   case 152:
    4446             : #line 2296 "pl_gram.y" /* yacc.c:1646  */
    4447             :     {
    4448             :                         /* just to give a better message than "syntax error" */
    4449             :                         cword_is_not_variable(&((yyvsp[0].cword)), (yylsp[0]));
    4450             :                     }
    4451             : #line 4452 "pl_gram.c" /* yacc.c:1646  */
    4452           0 :     break;
    4453             : 
    4454             :   case 153:
    4455             : #line 2303 "pl_gram.y" /* yacc.c:1646  */
    4456             :     { (yyval.exception_block) = NULL; }
    4457             : #line 4458 "pl_gram.c" /* yacc.c:1646  */
    4458        3550 :     break;
    4459             : 
    4460             :   case 154:
    4461             : #line 2305 "pl_gram.y" /* yacc.c:1646  */
    4462             :     {
    4463             :                         /*
    4464             :                          * We use a mid-rule action to add these
    4465             :                          * special variables to the namespace before
    4466             :                          * parsing the WHEN clauses themselves.  The
    4467             :                          * scope of the names extends to the end of the
    4468             :                          * current block.
    4469             :                          */
    4470             :                         int         lineno = plpgsql_location_to_lineno((yylsp[0]));
    4471             :                         PLpgSQL_exception_block *new = palloc(sizeof(PLpgSQL_exception_block));
    4472             :                         PLpgSQL_variable *var;
    4473             : 
    4474             :                         var = plpgsql_build_variable("sqlstate", lineno,
    4475             :                                                      plpgsql_build_datatype(TEXTOID,
    4476             :                                                                             -1,
    4477             :                                                                             plpgsql_curr_compile->fn_input_collation),
    4478             :                                                      true);
    4479             :                         var->isconst = true;
    4480             :                         new->sqlstate_varno = var->dno;
    4481             : 
    4482             :                         var = plpgsql_build_variable("sqlerrm", lineno,
    4483             :                                                      plpgsql_build_datatype(TEXTOID,
    4484             :                                                                             -1,
    4485             :                                                                             plpgsql_curr_compile->fn_input_collation),
    4486             :                                                      true);
    4487             :                         var->isconst = true;
    4488             :                         new->sqlerrm_varno = var->dno;
    4489             : 
    4490             :                         (yyval.exception_block) = new;
    4491             :                     }
    4492             : #line 4493 "pl_gram.c" /* yacc.c:1646  */
    4493         160 :     break;
    4494             : 
    4495             :   case 155:
    4496             : #line 2336 "pl_gram.y" /* yacc.c:1646  */
    4497             :     {
    4498             :                         PLpgSQL_exception_block *new = (yyvsp[-1].exception_block);
    4499             :                         new->exc_list = (yyvsp[0].list);
    4500             : 
    4501             :                         (yyval.exception_block) = new;
    4502             :                     }
    4503             : #line 4504 "pl_gram.c" /* yacc.c:1646  */
    4504         160 :     break;
    4505             : 
    4506             :   case 156:
    4507             : #line 2345 "pl_gram.y" /* yacc.c:1646  */
    4508             :     {
    4509             :                             (yyval.list) = lappend((yyvsp[-1].list), (yyvsp[0].exception));
    4510             :                         }
    4511             : #line 4512 "pl_gram.c" /* yacc.c:1646  */
    4512          10 :     break;
    4513             : 
    4514             :   case 157:
    4515             : #line 2349 "pl_gram.y" /* yacc.c:1646  */
    4516             :     {
    4517             :                             (yyval.list) = list_make1((yyvsp[0].exception));
    4518             :                         }
    4519             : #line 4520 "pl_gram.c" /* yacc.c:1646  */
    4520         160 :     break;
    4521             : 
    4522             :   case 158:
    4523             : #line 2355 "pl_gram.y" /* yacc.c:1646  */
    4524             :     {
    4525             :                         PLpgSQL_exception *new;
    4526             : 
    4527             :                         new = palloc0(sizeof(PLpgSQL_exception));
    4528             :                         new->lineno = plpgsql_location_to_lineno((yylsp[-3]));
    4529             :                         new->conditions = (yyvsp[-2].condition);
    4530             :                         new->action = (yyvsp[0].list);
    4531             : 
    4532             :                         (yyval.exception) = new;
    4533             :                     }
    4534             : #line 4535 "pl_gram.c" /* yacc.c:1646  */
    4535         170 :     break;
    4536             : 
    4537             :   case 159:
    4538             : #line 2368 "pl_gram.y" /* yacc.c:1646  */
    4539             :     {
    4540             :                             PLpgSQL_condition   *old;
    4541             : 
    4542             :                             for (old = (yyvsp[-2].condition); old->next != NULL; old = old->next)
    4543             :                                 /* skip */ ;
    4544             :                             old->next = (yyvsp[0].condition);
    4545             :                             (yyval.condition) = (yyvsp[-2].condition);
    4546             :                         }
    4547             : #line 4548 "pl_gram.c" /* yacc.c:1646  */
    4548          10 :     break;
    4549             : 
    4550             :   case 160:
    4551             : #line 2377 "pl_gram.y" /* yacc.c:1646  */
    4552             :     {
    4553             :                             (yyval.condition) = (yyvsp[0].condition);
    4554             :                         }
    4555             : #line 4556 "pl_gram.c" /* yacc.c:1646  */
    4556         170 :     break;
    4557             : 
    4558             :   case 161:
    4559             : #line 2383 "pl_gram.y" /* yacc.c:1646  */
    4560             :     {
    4561             :                             if (strcmp((yyvsp[0].str), "sqlstate") != 0)
    4562             :                             {
    4563             :                                 (yyval.condition) = plpgsql_parse_err_condition((yyvsp[0].str));
    4564             :                             }
    4565             :                             else
    4566             :                             {
    4567             :                                 PLpgSQL_condition *new;
    4568             :                                 char   *sqlstatestr;
    4569             : 
    4570             :                                 /* next token should be a string literal */
    4571             :                                 if (yylex() != SCONST)
    4572             :                                     yyerror("syntax error");
    4573             :                                 sqlstatestr = yylval.str;
    4574             : 
    4575             :                                 if (strlen(sqlstatestr) != 5)
    4576             :                                     yyerror("invalid SQLSTATE code");
    4577             :                                 if (strspn(sqlstatestr, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") != 5)
    4578             :                                     yyerror("invalid SQLSTATE code");
    4579             : 
    4580             :                                 new = palloc(sizeof(PLpgSQL_condition));
    4581             :                                 new->sqlerrstate =
    4582             :                                     MAKE_SQLSTATE(sqlstatestr[0],
    4583             :                                                   sqlstatestr[1],
    4584             :                                                   sqlstatestr[2],
    4585             :                                                   sqlstatestr[3],
    4586             :                                                   sqlstatestr[4]);
    4587             :                                 new->condname = sqlstatestr;
    4588             :                                 new->next = NULL;
    4589             : 
    4590             :                                 (yyval.condition) = new;
    4591             :                             }
    4592             :                         }
    4593             : #line 4594 "pl_gram.c" /* yacc.c:1646  */
    4594         180 :     break;
    4595             : 
    4596             :   case 162:
    4597             : #line 2419 "pl_gram.y" /* yacc.c:1646  */
    4598             :     { (yyval.expr) = read_sql_expression(';', ";"); }
    4599             : #line 4600 "pl_gram.c" /* yacc.c:1646  */
    4600        2372 :     break;
    4601             : 
    4602             :   case 163:
    4603             : #line 2423 "pl_gram.y" /* yacc.c:1646  */
    4604             :     { (yyval.expr) = read_sql_expression(']', "]"); }
    4605             : #line 4606 "pl_gram.c" /* yacc.c:1646  */
    4606          50 :     break;
    4607             : 
    4608             :   case 164:
    4609             : #line 2427 "pl_gram.y" /* yacc.c:1646  */
    4610             :     { (yyval.expr) = read_sql_expression(K_THEN, "THEN"); }
    4611             : #line 4612 "pl_gram.c" /* yacc.c:1646  */
    4612        2794 :     break;
    4613             : 
    4614             :   case 165:
    4615             : #line 2431 "pl_gram.y" /* yacc.c:1646  */
    4616             :     { (yyval.expr) = read_sql_expression(K_LOOP, "LOOP"); }
    4617             : #line 4618 "pl_gram.c" /* yacc.c:1646  */
    4618          94 :     break;
    4619             : 
    4620             :   case 166:
    4621             : #line 2435 "pl_gram.y" /* yacc.c:1646  */
    4622             :     {
    4623             :                         plpgsql_ns_push(NULL, PLPGSQL_LABEL_BLOCK);
    4624             :                         (yyval.str) = NULL;
    4625             :                     }
    4626             : #line 4627 "pl_gram.c" /* yacc.c:1646  */
    4627        3780 :     break;
    4628             : 
    4629             :   case 167:
    4630             : #line 2440 "pl_gram.y" /* yacc.c:1646  */
    4631             :     {
    4632             :                         plpgsql_ns_push((yyvsp[-1].str), PLPGSQL_LABEL_BLOCK);
    4633             :                         (yyval.str) = (yyvsp[-1].str);
    4634             :                     }
    4635             : #line 4636 "pl_gram.c" /* yacc.c:1646  */
    4636          36 :     break;
    4637             : 
    4638             :   case 168:
    4639             : #line 2447 "pl_gram.y" /* yacc.c:1646  */
    4640             :     {
    4641             :                         plpgsql_ns_push(NULL, PLPGSQL_LABEL_LOOP);
    4642             :                         (yyval.str) = NULL;
    4643             :                     }
    4644             : #line 4645 "pl_gram.c" /* yacc.c:1646  */
    4645         618 :     break;
    4646             : 
    4647             :   case 169:
    4648             : #line 2452 "pl_gram.y" /* yacc.c:1646  */
    4649             :     {
    4650             :                         plpgsql_ns_push((yyvsp[-1].str), PLPGSQL_LABEL_LOOP);
    4651             :                         (yyval.str) = (yyvsp[-1].str);
    4652             :                     }
    4653             : #line 4654 "pl_gram.c" /* yacc.c:1646  */
    4654          30 :     break;
    4655             : 
    4656             :   case 170:
    4657             : #line 2459 "pl_gram.y" /* yacc.c:1646  */
    4658             :     {
    4659             :                         (yyval.str) = NULL;
    4660             :                     }
    4661             : #line 4662 "pl_gram.c" /* yacc.c:1646  */
    4662        4398 :     break;
    4663             : 
    4664             :   case 171:
    4665             : #line 2463 "pl_gram.y" /* yacc.c:1646  */
    4666             :     {
    4667             :                         /* label validity will be checked by outer production */
    4668             :                         (yyval.str) = (yyvsp[0].str);
    4669             :                     }
    4670             : #line 4671 "pl_gram.c" /* yacc.c:1646  */
    4671          40 :     break;
    4672             : 
    4673             :   case 172:
    4674             : #line 2470 "pl_gram.y" /* yacc.c:1646  */
    4675             :     { (yyval.expr) = NULL; }
    4676             : #line 4677 "pl_gram.c" /* yacc.c:1646  */
    4677          54 :     break;
    4678             : 
    4679             :   case 173:
    4680             : #line 2472 "pl_gram.y" /* yacc.c:1646  */
    4681             :     { (yyval.expr) = (yyvsp[0].expr); }
    4682             : #line 4683 "pl_gram.c" /* yacc.c:1646  */
    4683          46 :     break;
    4684             : 
    4685             :   case 174:
    4686             : #line 2479 "pl_gram.y" /* yacc.c:1646  */
    4687             :     {
    4688             :                         (yyval.str) = (yyvsp[0].word).ident;
    4689             :                     }
    4690             : #line 4691 "pl_gram.c" /* yacc.c:1646  */
    4691         266 :     break;
    4692             : 
    4693             :   case 175:
    4694             : #line 2483 "pl_gram.y" /* yacc.c:1646  */
    4695             :     {
    4696             :                         (yyval.str) = pstrdup((yyvsp[0].keyword));
    4697             :                     }
    4698             : #line 4699 "pl_gram.c" /* yacc.c:1646  */
    4699           0 :     break;
    4700             : 
    4701             :   case 176:
    4702             : #line 2487 "pl_gram.y" /* yacc.c:1646  */
    4703             :     {
    4704             :                         if ((yyvsp[0].wdatum).ident == NULL) /* composite name not OK */
    4705             :                             yyerror("syntax error");
    4706             :                         (yyval.str) = (yyvsp[0].wdatum).ident;
    4707             :                     }
    4708             : #line 4709 "pl_gram.c" /* yacc.c:1646  */
    4709          20 :     break;
    4710             : 
    4711             : 
    4712             : #line 4713 "pl_gram.c" /* yacc.c:1646  */
    4713       14788 :       default: break;
    4714             :     }
    4715             :   /* User semantic actions sometimes alter yychar, and that requires
    4716             :      that yytoken be updated with the new translation.  We take the
    4717             :      approach of translating immediately before every use of yytoken.
    4718             :      One alternative is translating here after every semantic action,
    4719             :      but that translation would be missed if the semantic action invokes
    4720             :      YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
    4721             :      if it invokes YYBACKUP.  In the case of YYABORT or YYACCEPT, an
    4722             :      incorrect destructor might then be invoked immediately.  In the
    4723             :      case of YYERROR or YYBACKUP, subsequent parser actions might lead
    4724             :      to an incorrect destructor call or verbose syntax error message
    4725             :      before the lookahead is translated.  */
    4726             :   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
    4727             : 
    4728      125056 :   YYPOPSTACK (yylen);
    4729      125056 :   yylen = 0;
    4730             :   YY_STACK_PRINT (yyss, yyssp);
    4731             : 
    4732      125056 :   *++yyvsp = yyval;
    4733      125056 :   *++yylsp = yyloc;
    4734             : 
    4735             :   /* Now 'shift' the result of the reduction.  Determine what state
    4736             :      that goes to, based on the state we popped back to and the rule
    4737             :      number reduced by.  */
    4738             : 
    4739      125056 :   yyn = yyr1[yyn];
    4740             : 
    4741      125056 :   yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
    4742      125056 :   if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
    4743       33752 :     yystate = yytable[yystate];
    4744             :   else
    4745       91304 :     yystate = yydefgoto[yyn - YYNTOKENS];
    4746             : 
    4747      125056 :   goto yynewstate;
    4748             : 
    4749             : 
    4750             : /*--------------------------------------.
    4751             : | yyerrlab -- here on detecting error.  |
    4752             : `--------------------------------------*/
    4753             : yyerrlab:
    4754             :   /* Make sure we have latest lookahead translation.  See comments at
    4755             :      user semantic actions for why this is necessary.  */
    4756           2 :   yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
    4757             : 
    4758             :   /* If not already recovering from an error, report this error.  */
    4759           2 :   if (!yyerrstatus)
    4760             :     {
    4761           2 :       ++yynerrs;
    4762             : #if ! YYERROR_VERBOSE
    4763           2 :       yyerror (YY_("syntax error"));
    4764             : #else
    4765             : # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
    4766             :                                         yyssp, yytoken)
    4767             :       {
    4768             :         char const *yymsgp = YY_("syntax error");
    4769             :         int yysyntax_error_status;
    4770             :         yysyntax_error_status = YYSYNTAX_ERROR;
    4771             :         if (yysyntax_error_status == 0)
    4772             :           yymsgp = yymsg;
    4773             :         else if (yysyntax_error_status == 1)
    4774             :           {
    4775             :             if (yymsg != yymsgbuf)
    4776             :               YYSTACK_FREE (yymsg);
    4777             :             yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
    4778             :             if (!yymsg)
    4779             :               {
    4780             :                 yymsg = yymsgbuf;
    4781             :                 yymsg_alloc = sizeof yymsgbuf;
    4782             :                 yysyntax_error_status = 2;
    4783             :               }
    4784             :             else
    4785             :               {
    4786             :                 yysyntax_error_status = YYSYNTAX_ERROR;
    4787             :                 yymsgp = yymsg;
    4788             :               }
    4789             :           }
    4790             :         yyerror (yymsgp);
    4791             :         if (yysyntax_error_status == 2)
    4792             :           goto yyexhaustedlab;
    4793             :       }
    4794             : # undef YYSYNTAX_ERROR
    4795             : #endif
    4796             :     }
    4797             : 
    4798           0 :   yyerror_range[1] = yylloc;
    4799             : 
    4800           0 :   if (yyerrstatus == 3)
    4801             :     {
    4802             :       /* If just tried and failed to reuse lookahead token after an
    4803             :          error, discard it.  */
    4804             : 
    4805           0 :       if (yychar <= YYEOF)
    4806             :         {
    4807             :           /* Return failure if at end of input.  */
    4808           0 :           if (yychar == YYEOF)
    4809           0 :             YYABORT;
    4810             :         }
    4811             :       else
    4812             :         {
    4813           0 :           yydestruct ("Error: discarding",
    4814             :                       yytoken, &yylval, &yylloc);
    4815           0 :           yychar = YYEMPTY;
    4816             :         }
    4817             :     }
    4818             : 
    4819             :   /* Else will try to reuse lookahead token after shifting the error
    4820             :      token.  */
    4821           0 :   goto yyerrlab1;
    4822             : 
    4823             : 
    4824             : /*---------------------------------------------------.
    4825             : | yyerrorlab -- error raised explicitly by YYERROR.  |
    4826             : `---------------------------------------------------*/
    4827             : yyerrorlab:
    4828             : 
    4829             :   /* Pacify compilers like GCC when the user code never invokes
    4830             :      YYERROR and the label yyerrorlab therefore never appears in user
    4831             :      code.  */
    4832             :   if (/*CONSTCOND*/ 0)
    4833             :      goto yyerrorlab;
    4834             : 
    4835             :   yyerror_range[1] = yylsp[1-yylen];
    4836             :   /* Do not reclaim the symbols of the rule whose action triggered
    4837             :      this YYERROR.  */
    4838             :   YYPOPSTACK (yylen);
    4839             :   yylen = 0;
    4840             :   YY_STACK_PRINT (yyss, yyssp);
    4841             :   yystate = *yyssp;
    4842             :   goto yyerrlab1;
    4843             : 
    4844             : 
    4845             : /*-------------------------------------------------------------.
    4846             : | yyerrlab1 -- common code for both syntax error and YYERROR.  |
    4847             : `-------------------------------------------------------------*/
    4848             : yyerrlab1:
    4849           0 :   yyerrstatus = 3;      /* Each real token shifted decrements this.  */
    4850             : 
    4851             :   for (;;)
    4852             :     {
    4853           0 :       yyn = yypact[yystate];
    4854           0 :       if (!yypact_value_is_default (yyn))
    4855             :         {
    4856           0 :           yyn += YYTERROR;
    4857           0 :           if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
    4858             :             {
    4859           0 :               yyn = yytable[yyn];
    4860           0 :               if (0 < yyn)
    4861           0 :                 break;
    4862             :             }
    4863             :         }
    4864             : 
    4865             :       /* Pop the current state because it cannot handle the error token.  */
    4866           0 :       if (yyssp == yyss)
    4867           0 :         YYABORT;
    4868             : 
    4869           0 :       yyerror_range[1] = *yylsp;
    4870           0 :       yydestruct ("Error: popping",
    4871           0 :                   yystos[yystate], yyvsp, yylsp);
    4872           0 :       YYPOPSTACK (1);
    4873           0 :       yystate = *yyssp;
    4874             :       YY_STACK_PRINT (yyss, yyssp);
    4875             :     }
    4876             : 
    4877             :   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
    4878           0 :   *++yyvsp = yylval;
    4879             :   YY_IGNORE_MAYBE_UNINITIALIZED_END
    4880             : 
    4881           0 :   yyerror_range[2] = yylloc;
    4882             :   /* Using YYLLOC is tempting, but would change the location of
    4883             :      the lookahead.  YYLOC is available though.  */
    4884           0 :   YYLLOC_DEFAULT (yyloc, yyerror_range, 2);
    4885           0 :   *++yylsp = yyloc;
    4886             : 
    4887             :   /* Shift the error token.  */
    4888             :   YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
    4889             : 
    4890           0 :   yystate = yyn;
    4891           0 :   goto yynewstate;
    4892             : 
    4893             : 
    4894             : /*-------------------------------------.
    4895             : | yyacceptlab -- YYACCEPT comes here.  |
    4896             : `-------------------------------------*/
    4897             : yyacceptlab:
    4898        3576 :   yyresult = 0;
    4899        3576 :   goto yyreturn;
    4900             : 
    4901             : /*-----------------------------------.
    4902             : | yyabortlab -- YYABORT comes here.  |
    4903             : `-----------------------------------*/
    4904             : yyabortlab:
    4905           0 :   yyresult = 1;
    4906           0 :   goto yyreturn;
    4907             : 
    4908             : #if !defined yyoverflow || YYERROR_VERBOSE
    4909             : /*-------------------------------------------------.
    4910             : | yyexhaustedlab -- memory exhaustion comes here.  |
    4911             : `-------------------------------------------------*/
    4912             : yyexhaustedlab:
    4913           0 :   yyerror (YY_("memory exhausted"));
    4914             :   yyresult = 2;
    4915             :   /* Fall through.  */
    4916             : #endif
    4917             : 
    4918             : yyreturn:
    4919        3576 :   if (yychar != YYEMPTY)
    4920             :     {
    4921             :       /* Make sure we have latest lookahead translation.  See comments at
    4922             :          user semantic actions for why this is necessary.  */
    4923           0 :       yytoken = YYTRANSLATE (yychar);
    4924           0 :       yydestruct ("Cleanup: discarding lookahead",
    4925             :                   yytoken, &yylval, &yylloc);
    4926             :     }
    4927             :   /* Do not reclaim the symbols of the rule whose action triggered
    4928             :      this YYABORT or YYACCEPT.  */
    4929        3576 :   YYPOPSTACK (yylen);
    4930             :   YY_STACK_PRINT (yyss, yyssp);
    4931       14304 :   while (yyssp != yyss)
    4932             :     {
    4933        7152 :       yydestruct ("Cleanup: popping",
    4934        7152 :                   yystos[*yyssp], yyvsp, yylsp);
    4935        7152 :       YYPOPSTACK (1);
    4936             :     }
    4937             : #ifndef yyoverflow
    4938        3576 :   if (yyss != yyssa)
    4939           0 :     YYSTACK_FREE (yyss);
    4940             : #endif
    4941             : #if YYERROR_VERBOSE
    4942             :   if (yymsg != yymsgbuf)
    4943             :     YYSTACK_FREE (yymsg);
    4944             : #endif
    4945        3576 :   return yyresult;
    4946             : }
    4947             : #line 2579 "pl_gram.y" /* yacc.c:1906  */
    4948             : 
    4949             : 
    4950             : /*
    4951             :  * Check whether a token represents an "unreserved keyword".
    4952             :  * We have various places where we want to recognize a keyword in preference
    4953             :  * to a variable name, but not reserve that keyword in other contexts.
    4954             :  * Hence, this kluge.
    4955             :  */
    4956             : static bool
    4957             : tok_is_keyword(int token, union YYSTYPE *lval,
    4958             :                int kw_token, const char *kw_str)
    4959             : {
    4960             :     if (token == kw_token)
    4961             :     {
    4962             :         /* Normal case, was recognized by scanner (no conflicting variable) */
    4963             :         return true;
    4964             :     }
    4965             :     else if (token == T_DATUM)
    4966             :     {
    4967             :         /*
    4968             :          * It's a variable, so recheck the string name.  Note we will not
    4969             :          * match composite names (hence an unreserved word followed by "."
    4970             :          * will not be recognized).
    4971             :          */
    4972             :         if (!lval->wdatum.quoted && lval->wdatum.ident != NULL &&
    4973             :             strcmp(lval->wdatum.ident, kw_str) == 0)
    4974             :             return true;
    4975             :     }
    4976             :     return false;               /* not the keyword */
    4977             : }
    4978             : 
    4979             : /*
    4980             :  * Convenience routine to complain when we expected T_DATUM and got T_WORD,
    4981             :  * ie, unrecognized variable.
    4982             :  */
    4983             : static void
    4984             : word_is_not_variable(PLword *word, int location)
    4985             : {
    4986             :     ereport(ERROR,
    4987             :             (errcode(ERRCODE_SYNTAX_ERROR),
    4988             :              errmsg("\"%s\" is not a known variable",
    4989             :                     word->ident),
    4990             :              parser_errposition(location)));
    4991             : }
    4992             : 
    4993             : /* Same, for a CWORD */
    4994             : static void
    4995             : cword_is_not_variable(PLcword *cword, int location)
    4996             : {
    4997             :     ereport(ERROR,
    4998             :             (errcode(ERRCODE_SYNTAX_ERROR),
    4999             :              errmsg("\"%s\" is not a known variable",
    5000             :                     NameListToString(cword->idents)),
    5001             :              parser_errposition(location)));
    5002             : }
    5003             : 
    5004             : /*
    5005             :  * Convenience routine to complain when we expected T_DATUM and got
    5006             :  * something else.  "tok" must be the current token, since we also
    5007             :  * look at yylval and yylloc.
    5008             :  */
    5009             : static void
    5010             : current_token_is_not_variable(int tok)
    5011             : {
    5012             :     if (tok == T_WORD)
    5013             :         word_is_not_variable(&(yylval.word), yylloc);
    5014             :     else if (tok == T_CWORD)
    5015             :         cword_is_not_variable(&(yylval.cword), yylloc);
    5016             :     else
    5017             :         yyerror("syntax error");
    5018             : }
    5019             : 
    5020             : /* Convenience routine to read an expression with one possible terminator */
    5021             : static PLpgSQL_expr *
    5022             : read_sql_expression(int until, const char *expected)
    5023             : {
    5024             :     return read_sql_construct(until, 0, 0, expected,
    5025             :                               "SELECT ", true, true, true, NULL, NULL);
    5026             : }
    5027             : 
    5028             : /* Convenience routine to read an expression with two possible terminators */
    5029             : static PLpgSQL_expr *
    5030             : read_sql_expression2(int until, int until2, const char *expected,
    5031             :                      int *endtoken)
    5032             : {
    5033             :     return read_sql_construct(until, until2, 0, expected,
    5034             :                               "SELECT ", true, true, true, NULL, endtoken);
    5035             : }
    5036             : 
    5037             : /* Convenience routine to read a SQL statement that must end with ';' */
    5038             : static PLpgSQL_expr *
    5039             : read_sql_stmt(const char *sqlstart)
    5040             : {
    5041             :     return read_sql_construct(';', 0, 0, ";",
    5042             :                               sqlstart, false, true, true, NULL, NULL);
    5043             : }
    5044             : 
    5045             : /*
    5046             :  * Read a SQL construct and build a PLpgSQL_expr for it.
    5047             :  *
    5048             :  * until:       token code for expected terminator
    5049             :  * until2:      token code for alternate terminator (pass 0 if none)
    5050             :  * until3:      token code for another alternate terminator (pass 0 if none)
    5051             :  * expected:    text to use in complaining that terminator was not found
    5052             :  * sqlstart:    text to prefix to the accumulated SQL text
    5053             :  * isexpression: whether to say we're reading an "expression" or a "statement"
    5054             :  * valid_sql:   whether to check the syntax of the expr (prefixed with sqlstart)
    5055             :  * trim:        trim trailing whitespace
    5056             :  * startloc:    if not NULL, location of first token is stored at *startloc
    5057             :  * endtoken:    if not NULL, ending token is stored at *endtoken
    5058             :  *              (this is only interesting if until2 or until3 isn't zero)
    5059             :  */
    5060             : static PLpgSQL_expr *
    5061             : read_sql_construct(int until,
    5062             :                    int until2,
    5063             :                    int until3,
    5064             :                    const char *expected,
    5065             :                    const char *sqlstart,
    5066             :                    bool isexpression,
    5067             :                    bool valid_sql,
    5068             :                    bool trim,
    5069             :                    int *startloc,
    5070             :                    int *endtoken)
    5071             : {
    5072             :     int                 tok;
    5073             :     StringInfoData      ds;
    5074             :     IdentifierLookup    save_IdentifierLookup;
    5075             :     int                 startlocation = -1;
    5076             :     int                 parenlevel = 0;
    5077             :     PLpgSQL_expr        *expr;
    5078             : 
    5079             :     initStringInfo(&ds);
    5080             :     appendStringInfoString(&ds, sqlstart);
    5081             : 
    5082             :     /* special lookup mode for identifiers within the SQL text */
    5083             :     save_IdentifierLookup = plpgsql_IdentifierLookup;
    5084             :     plpgsql_IdentifierLookup = IDENTIFIER_LOOKUP_EXPR;
    5085             : 
    5086             :     for (;;)
    5087             :     {
    5088             :         tok = yylex();
    5089             :         if (startlocation < 0)           /* remember loc of first token */
    5090             :             startlocation = yylloc;
    5091             :         if (tok == until && parenlevel == 0)
    5092             :             break;
    5093             :         if (tok == until2 && parenlevel == 0)
    5094             :             break;
    5095             :         if (tok == until3 && parenlevel == 0)
    5096             :             break;
    5097             :         if (tok == '(' || tok == '[')
    5098             :             parenlevel++;
    5099             :         else if (tok == ')' || tok == ']')
    5100             :         {
    5101             :             parenlevel--;
    5102             :             if (parenlevel < 0)
    5103             :                 yyerror("mismatched parentheses");
    5104             :         }
    5105             :         /*
    5106             :          * End of function definition is an error, and we don't expect to
    5107             :          * hit a semicolon either (unless it's the until symbol, in which
    5108             :          * case we should have fallen out above).
    5109             :          */
    5110             :         if (tok == 0 || tok == ';')
    5111             :         {
    5112             :             if (parenlevel != 0)
    5113             :                 yyerror("mismatched parentheses");
    5114             :             if (isexpression)
    5115             :                 ereport(ERROR,
    5116             :                         (errcode(ERRCODE_SYNTAX_ERROR),
    5117             :                          errmsg("missing \"%s\" at end of SQL expression",
    5118             :                                 expected),
    5119             :                          parser_errposition(yylloc)));
    5120             :             else
    5121             :                 ereport(ERROR,
    5122             :                         (errcode(ERRCODE_SYNTAX_ERROR),
    5123             :                          errmsg("missing \"%s\" at end of SQL statement",
    5124             :                                 expected),
    5125             :                          parser_errposition(yylloc)));
    5126             :         }
    5127             :     }
    5128             : 
    5129             :     plpgsql_IdentifierLookup = save_IdentifierLookup;
    5130             : 
    5131             :     if (startloc)
    5132             :         *startloc = startlocation;
    5133             :     if (endtoken)
    5134             :         *endtoken = tok;
    5135             : 
    5136             :     /* give helpful complaint about empty input */
    5137             :     if (startlocation >= yylloc)
    5138             :     {
    5139             :         if (isexpression)
    5140             :             yyerror("missing expression");
    5141             :         else
    5142             :             yyerror("missing SQL statement");
    5143             :     }
    5144             : 
    5145             :     plpgsql_append_source_text(&ds, startlocation, yylloc);
    5146             : 
    5147             :     /* trim any trailing whitespace, for neatness */
    5148             :     if (trim)
    5149             :     {
    5150             :         while (ds.len > 0 && scanner_isspace(ds.data[ds.len - 1]))
    5151             :             ds.data[--ds.len] = '\0';
    5152             :     }
    5153             : 
    5154             :     expr = palloc0(sizeof(PLpgSQL_expr));
    5155             :     expr->query          = pstrdup(ds.data);
    5156             :     expr->plan           = NULL;
    5157             :     expr->paramnos       = NULL;
    5158             :     expr->rwparam        = -1;
    5159             :     expr->ns         = plpgsql_ns_top();
    5160             :     pfree(ds.data);
    5161             : 
    5162             :     if (valid_sql)
    5163             :         check_sql_expr(expr->query, startlocation, strlen(sqlstart));
    5164             : 
    5165             :     return expr;
    5166             : }
    5167             : 
    5168             : static PLpgSQL_type *
    5169             : read_datatype(int tok)
    5170             : {
    5171             :     StringInfoData      ds;
    5172             :     char               *type_name;
    5173             :     int                 startlocation;
    5174             :     PLpgSQL_type        *result;
    5175             :     int                 parenlevel = 0;
    5176             : 
    5177             :     /* Should only be called while parsing DECLARE sections */
    5178             :     Assert(plpgsql_IdentifierLookup == IDENTIFIER_LOOKUP_DECLARE);
    5179             : 
    5180             :     /* Often there will be a lookahead token, but if not, get one */
    5181             :     if (tok == YYEMPTY)
    5182             :         tok = yylex();
    5183             : 
    5184             :     startlocation = yylloc;
    5185             : 
    5186             :     /*
    5187             :      * If we have a simple or composite identifier, check for %TYPE
    5188             :      * and %ROWTYPE constructs.
    5189             :      */
    5190             :     if (tok == T_WORD)
    5191             :     {
    5192             :         char   *dtname = yylval.word.ident;
    5193             : 
    5194             :         tok = yylex();
    5195             :         if (tok == '%')
    5196             :         {
    5197             :             tok = yylex();
    5198             :             if (tok_is_keyword(tok, &yylval,
    5199             :                                K_TYPE, "type"))
    5200             :             {
    5201             :                 result = plpgsql_parse_wordtype(dtname);
    5202             :                 if (result)
    5203             :                     return result;
    5204             :             }
    5205             :             else if (tok_is_keyword(tok, &yylval,
    5206             :                                     K_ROWTYPE, "rowtype"))
    5207             :             {
    5208             :                 result = plpgsql_parse_wordrowtype(dtname);
    5209             :                 if (result)
    5210             :                     return result;
    5211             :             }
    5212             :         }
    5213             :     }
    5214             :     else if (plpgsql_token_is_unreserved_keyword(tok))
    5215             :     {
    5216             :         char   *dtname = pstrdup(yylval.keyword);
    5217             : 
    5218             :         tok = yylex();
    5219             :         if (tok == '%')
    5220             :         {
    5221             :             tok = yylex();
    5222             :             if (tok_is_keyword(tok, &yylval,
    5223             :                                K_TYPE, "type"))
    5224             :             {
    5225             :                 result = plpgsql_parse_wordtype(dtname);
    5226             :                 if (result)
    5227             :                     return result;
    5228             :             }
    5229             :             else if (tok_is_keyword(tok, &yylval,
    5230             :                                     K_ROWTYPE, "rowtype"))
    5231             :             {
    5232             :                 result = plpgsql_parse_wordrowtype(dtname);
    5233             :                 if (result)
    5234             :                     return result;
    5235             :             }
    5236             :         }
    5237             :     }
    5238             :     else if (tok == T_CWORD)
    5239             :     {
    5240             :         List   *dtnames = yylval.cword.idents;
    5241             : 
    5242             :         tok = yylex();
    5243             :         if (tok == '%')
    5244             :         {
    5245             :             tok = yylex();
    5246             :             if (tok_is_keyword(tok, &yylval,
    5247             :                                K_TYPE, "type"))
    5248             :             {
    5249             :                 result = plpgsql_parse_cwordtype(dtnames);
    5250             :                 if (result)
    5251             :                     return result;
    5252             :             }
    5253             :             else if (tok_is_keyword(tok, &yylval,
    5254             :                                     K_ROWTYPE, "rowtype"))
    5255             :             {
    5256             :                 result = plpgsql_parse_cwordrowtype(dtnames);
    5257             :                 if (result)
    5258             :                     return result;
    5259             :             }
    5260             :         }
    5261             :     }
    5262             : 
    5263             :     while (tok != ';')
    5264             :     {
    5265             :         if (tok == 0)
    5266             :         {
    5267             :             if (parenlevel != 0)
    5268             :                 yyerror("mismatched parentheses");
    5269             :             else
    5270             :                 yyerror("incomplete data type declaration");
    5271             :         }
    5272             :         /* Possible followers for datatype in a declaration */
    5273             :         if (tok == K_COLLATE || tok == K_NOT ||
    5274             :             tok == '=' || tok == COLON_EQUALS || tok == K_DEFAULT)
    5275             :             break;
    5276             :         /* Possible followers for datatype in a cursor_arg list */
    5277             :         if ((tok == ',' || tok == ')') && parenlevel == 0)
    5278             :             break;
    5279             :         if (tok == '(')
    5280             :             parenlevel++;
    5281             :         else if (tok == ')')
    5282             :             parenlevel--;
    5283             : 
    5284             :         tok = yylex();
    5285             :     }
    5286             : 
    5287             :     /* set up ds to contain complete typename text */
    5288             :     initStringInfo(&ds);
    5289             :     plpgsql_append_source_text(&ds, startlocation, yylloc);
    5290             :     type_name = ds.data;
    5291             : 
    5292             :     if (type_name[0] == '\0')
    5293             :         yyerror("missing data type declaration");
    5294             : 
    5295             :     result = parse_datatype(type_name, startlocation);
    5296             : 
    5297             :     pfree(ds.data);
    5298             : 
    5299             :     plpgsql_push_back_token(tok);
    5300             : 
    5301             :     return result;
    5302             : }
    5303             : 
    5304             : static PLpgSQL_stmt *
    5305             : make_execsql_stmt(int firsttoken, int location)
    5306             : {
    5307             :     StringInfoData      ds;
    5308             :     IdentifierLookup    save_IdentifierLookup;
    5309             :     PLpgSQL_stmt_execsql *execsql;
    5310             :     PLpgSQL_expr        *expr;
    5311             :     PLpgSQL_variable    *target = NULL;
    5312             :     int                 tok;
    5313             :     int                 prev_tok;
    5314             :     bool                have_into = false;
    5315             :     bool                have_strict = false;
    5316             :     int                 into_start_loc = -1;
    5317             :     int                 into_end_loc = -1;
    5318             : 
    5319             :     initStringInfo(&ds);
    5320             : 
    5321             :     /* special lookup mode for identifiers within the SQL text */
    5322             :     save_IdentifierLookup = plpgsql_IdentifierLookup;
    5323             :     plpgsql_IdentifierLookup = IDENTIFIER_LOOKUP_EXPR;
    5324             : 
    5325             :     /*
    5326             :      * Scan to the end of the SQL command.  Identify any INTO-variables
    5327             :      * clause lurking within it, and parse that via read_into_target().
    5328             :      *
    5329             :      * Because INTO is sometimes used in the main SQL grammar, we have to be
    5330             :      * careful not to take any such usage of INTO as a PL/pgSQL INTO clause.
    5331             :      * There are currently three such cases:
    5332             :      *
    5333             :      * 1. SELECT ... INTO.  We don't care, we just override that with the
    5334             :      * PL/pgSQL definition.
    5335             :      *
    5336             :      * 2. INSERT INTO.  This is relatively easy to recognize since the words
    5337             :      * must appear adjacently; but we can't assume INSERT starts the command,
    5338             :      * because it can appear in CREATE RULE or WITH.  Unfortunately, INSERT is
    5339             :      * *not* fully reserved, so that means there is a chance of a false match;
    5340             :      * but it's not very likely.
    5341             :      *
    5342             :      * 3. IMPORT FOREIGN SCHEMA ... INTO.  This is not allowed in CREATE RULE
    5343             :      * or WITH, so we just check for IMPORT as the command's first token.
    5344             :      * (If IMPORT FOREIGN SCHEMA returned data someone might wish to capture
    5345             :      * with an INTO-variables clause, we'd have to work much harder here.)
    5346             :      *
    5347             :      * Fortunately, INTO is a fully reserved word in the main grammar, so
    5348             :      * at least we need not worry about it appearing as an identifier.
    5349             :      *
    5350             :      * Any future additional uses of INTO in the main grammar will doubtless
    5351             :      * break this logic again ... beware!
    5352             :      */
    5353             :     tok = firsttoken;
    5354             :     for (;;)
    5355             :     {
    5356             :         prev_tok = tok;
    5357             :         tok = yylex();
    5358             :         if (have_into && into_end_loc < 0)
    5359             :             into_end_loc = yylloc;      /* token after the INTO part */
    5360             :         if (tok == ';')
    5361             :             break;
    5362             :         if (tok == 0)
    5363             :             yyerror("unexpected end of function definition");
    5364             :         if (tok == K_INTO)
    5365             :         {
    5366             :             if (prev_tok == K_INSERT)
    5367             :                 continue;       /* INSERT INTO is not an INTO-target */
    5368             :             if (firsttoken == K_IMPORT)
    5369             :                 continue;       /* IMPORT ... INTO is not an INTO-target */
    5370             :             if (have_into)
    5371             :                 yyerror("INTO specified more than once");
    5372             :             have_into = true;
    5373             :             into_start_loc = yylloc;
    5374             :             plpgsql_IdentifierLookup = IDENTIFIER_LOOKUP_NORMAL;
    5375             :             read_into_target(&target, &have_strict);
    5376             :             plpgsql_IdentifierLookup = IDENTIFIER_LOOKUP_EXPR;
    5377             :         }
    5378             :     }
    5379             : 
    5380             :     plpgsql_IdentifierLookup = save_IdentifierLookup;
    5381             : 
    5382             :     if (have_into)
    5383             :     {
    5384             :         /*
    5385             :          * Insert an appropriate number of spaces corresponding to the
    5386             :          * INTO text, so that locations within the redacted SQL statement
    5387             :          * still line up with those in the original source text.
    5388             :          */
    5389             :         plpgsql_append_source_text(&ds, location, into_start_loc);
    5390             :         appendStringInfoSpaces(&ds, into_end_loc - into_start_loc);
    5391             :         plpgsql_append_source_text(&ds, into_end_loc, yylloc);
    5392             :     }
    5393             :     else
    5394             :         plpgsql_append_source_text(&ds, location, yylloc);
    5395             : 
    5396             :     /* trim any trailing whitespace, for neatness */
    5397             :     while (ds.len > 0 && scanner_isspace(ds.data[ds.len - 1]))
    5398             :         ds.data[--ds.len] = '\0';
    5399             : 
    5400             :     expr = palloc0(sizeof(PLpgSQL_expr));
    5401             :     expr->query          = pstrdup(ds.data);
    5402             :     expr->plan           = NULL;
    5403             :     expr->paramnos       = NULL;
    5404             :     expr->rwparam        = -1;
    5405             :     expr->ns         = plpgsql_ns_top();
    5406             :     pfree(ds.data);
    5407             : 
    5408             :     check_sql_expr(expr->query, location, 0);
    5409             : 
    5410             :     execsql = palloc(sizeof(PLpgSQL_stmt_execsql));
    5411             :     execsql->cmd_type = PLPGSQL_STMT_EXECSQL;
    5412             :     execsql->lineno  = plpgsql_location_to_lineno(location);
    5413             :     execsql->stmtid  = ++plpgsql_curr_compile->nstatements;
    5414             :     execsql->sqlstmt = expr;
    5415             :     execsql->into     = have_into;
    5416             :     execsql->strict   = have_strict;
    5417             :     execsql->target   = target;
    5418             : 
    5419             :     return (PLpgSQL_stmt *) execsql;
    5420             : }
    5421             : 
    5422             : 
    5423             : /*
    5424             :  * Read FETCH or MOVE direction clause (everything through FROM/IN).
    5425             :  */
    5426             : static PLpgSQL_stmt_fetch *
    5427             : read_fetch_direction(void)
    5428             : {
    5429             :     PLpgSQL_stmt_fetch *fetch;
    5430             :     int         tok;
    5431             :     bool        check_FROM = true;
    5432             : 
    5433             :     /*
    5434             :      * We create the PLpgSQL_stmt_fetch struct here, but only fill in
    5435             :      * the fields arising from the optional direction clause
    5436             :      */
    5437             :     fetch = (PLpgSQL_stmt_fetch *) palloc0(sizeof(PLpgSQL_stmt_fetch));
    5438             :     fetch->cmd_type = PLPGSQL_STMT_FETCH;
    5439             :     fetch->stmtid    = ++plpgsql_curr_compile->nstatements;
    5440             :     /* set direction defaults: */
    5441             :     fetch->direction = FETCH_FORWARD;
    5442             :     fetch->how_many  = 1;
    5443             :     fetch->expr       = NULL;
    5444             :     fetch->returns_multiple_rows = false;
    5445             : 
    5446             :     tok = yylex();
    5447             :     if (tok == 0)
    5448             :         yyerror("unexpected end of function definition");
    5449             : 
    5450             :     if (tok_is_keyword(tok, &yylval,
    5451             :                        K_NEXT, "next"))
    5452             :     {
    5453             :         /* use defaults */
    5454             :     }
    5455             :     else if (tok_is_keyword(tok, &yylval,
    5456             :                             K_PRIOR, "prior"))
    5457             :     {
    5458             :         fetch->direction = FETCH_BACKWARD;
    5459             :     }
    5460             :     else if (tok_is_keyword(tok, &yylval,
    5461             :                             K_FIRST, "first"))
    5462             :     {
    5463             :         fetch->direction = FETCH_ABSOLUTE;
    5464             :     }
    5465             :     else if (tok_is_keyword(tok, &yylval,
    5466             :                             K_LAST, "last"))
    5467             :     {
    5468             :         fetch->direction = FETCH_ABSOLUTE;
    5469             :         fetch->how_many  = -1;
    5470             :     }
    5471             :     else if (tok_is_keyword(tok, &yylval,
    5472             :                             K_ABSOLUTE, "absolute"))
    5473             :     {
    5474             :         fetch->direction = FETCH_ABSOLUTE;
    5475             :         fetch->expr = read_sql_expression2(K_FROM, K_IN,
    5476             :                                            "FROM or IN",
    5477             :                                            NULL);
    5478             :         check_FROM = false;
    5479             :     }
    5480             :     else if (tok_is_keyword(tok, &yylval,
    5481             :                             K_RELATIVE, "relative"))
    5482             :     {
    5483             :         fetch->direction = FETCH_RELATIVE;
    5484             :         fetch->expr = read_sql_expression2(K_FROM, K_IN,
    5485             :                                            "FROM or IN",
    5486             :                                            NULL);
    5487             :         check_FROM = false;
    5488             :     }
    5489             :     else if (tok_is_keyword(tok, &yylval,
    5490             :                             K_ALL, "all"))
    5491             :     {
    5492             :         fetch->how_many = FETCH_ALL;
    5493             :         fetch->returns_multiple_rows = true;
    5494             :     }
    5495             :     else if (tok_is_keyword(tok, &yylval,
    5496             :                             K_FORWARD, "forward"))
    5497             :     {
    5498             :         complete_direction(fetch, &check_FROM);
    5499             :     }
    5500             :     else if (tok_is_keyword(tok, &yylval,
    5501             :                             K_BACKWARD, "backward"))
    5502             :     {
    5503             :         fetch->direction = FETCH_BACKWARD;
    5504             :         complete_direction(fetch, &check_FROM);
    5505             :     }
    5506             :     else if (tok == K_FROM || tok == K_IN)
    5507             :     {
    5508             :         /* empty direction */
    5509             :         check_FROM = false;
    5510             :     }
    5511             :     else if (tok == T_DATUM)
    5512             :     {
    5513             :         /* Assume there's no direction clause and tok is a cursor name */
    5514             :         plpgsql_push_back_token(tok);
    5515             :         check_FROM = false;
    5516             :     }
    5517             :     else
    5518             :     {
    5519             :         /*
    5520             :          * Assume it's a count expression with no preceding keyword.
    5521             :          * Note: we allow this syntax because core SQL does, but we don't
    5522             :          * document it because of the ambiguity with the omitted-direction
    5523             :          * case.  For instance, "MOVE n IN c" will fail if n is a variable.
    5524             :          * Perhaps this can be improved someday, but it's hardly worth a
    5525             :          * lot of work.
    5526             :          */
    5527             :         plpgsql_push_back_token(tok);
    5528             :         fetch->expr = read_sql_expression2(K_FROM, K_IN,
    5529             :                                            "FROM or IN",
    5530             :                                            NULL);
    5531             :         fetch->returns_multiple_rows = true;
    5532             :         check_FROM = false;
    5533             :     }
    5534             : 
    5535             :     /* check FROM or IN keyword after direction's specification */
    5536             :     if (check_FROM)
    5537             :     {
    5538             :         tok = yylex();
    5539             :         if (tok != K_FROM && tok != K_IN)
    5540             :             yyerror("expected FROM or IN");
    5541             :     }
    5542             : 
    5543             :     return fetch;
    5544             : }
    5545             : 
    5546             : /*
    5547             :  * Process remainder of FETCH/MOVE direction after FORWARD or BACKWARD.
    5548             :  * Allows these cases:
    5549             :  *   FORWARD expr,  FORWARD ALL,  FORWARD
    5550             :  *   BACKWARD expr, BACKWARD ALL, BACKWARD
    5551             :  */
    5552             : static void
    5553             : complete_direction(PLpgSQL_stmt_fetch *fetch,  bool *check_FROM)
    5554             : {
    5555             :     int         tok;
    5556             : 
    5557             :     tok = yylex();
    5558             :     if (tok == 0)
    5559             :         yyerror("unexpected end of function definition");
    5560             : 
    5561             :     if (tok == K_FROM || tok == K_IN)
    5562             :     {
    5563             :         *check_FROM = false;
    5564             :         return;
    5565             :     }
    5566             : 
    5567             :     if (tok == K_ALL)
    5568             :     {
    5569             :         fetch->how_many = FETCH_ALL;
    5570             :         fetch->returns_multiple_rows = true;
    5571             :         *check_FROM = true;
    5572             :         return;
    5573             :     }
    5574             : 
    5575             :     plpgsql_push_back_token(tok);
    5576             :     fetch->expr = read_sql_expression2(K_FROM, K_IN,
    5577             :                                        "FROM or IN",
    5578             :                                        NULL);
    5579             :     fetch->returns_multiple_rows = true;
    5580             :     *check_FROM = false;
    5581             : }
    5582             : 
    5583             : 
    5584             : static PLpgSQL_stmt *
    5585             : make_return_stmt(int location)
    5586             : {
    5587             :     PLpgSQL_stmt_return *new;
    5588             : 
    5589             :     new = palloc0(sizeof(PLpgSQL_stmt_return));
    5590             :     new->cmd_type = PLPGSQL_STMT_RETURN;
    5591             :     new->lineno   = plpgsql_location_to_lineno(location);
    5592             :     new->stmtid    = ++plpgsql_curr_compile->nstatements;
    5593             :     new->expr      = NULL;
    5594             :     new->retvarno = -1;
    5595             : 
    5596             :     if (plpgsql_curr_compile->fn_retset)
    5597             :     {
    5598             :         if (yylex() != ';')
    5599             :             ereport(ERROR,
    5600             :                     (errcode(ERRCODE_DATATYPE_MISMATCH),
    5601             :                      errmsg("RETURN cannot have a parameter in function returning set"),
    5602             :                      errhint("Use RETURN NEXT or RETURN QUERY."),
    5603             :                      parser_errposition(yylloc)));
    5604             :     }
    5605             :     else if (plpgsql_curr_compile->fn_rettype == VOIDOID)
    5606             :     {
    5607             :         if (yylex() != ';')
    5608             :         {
    5609             :             if (plpgsql_curr_compile->fn_prokind == PROKIND_PROCEDURE)
    5610             :                 ereport(ERROR,
    5611             :                         (errcode(ERRCODE_SYNTAX_ERROR),
    5612             :                          errmsg("RETURN cannot have a parameter in a procedure"),
    5613             :                          parser_errposition(yylloc)));
    5614             :             else
    5615             :                 ereport(ERROR,
    5616             :                         (errcode(ERRCODE_DATATYPE_MISMATCH),
    5617             :                          errmsg("RETURN cannot have a parameter in function returning void"),
    5618             :                          parser_errposition(yylloc)));
    5619             :         }
    5620             :     }
    5621             :     else if (plpgsql_curr_compile->out_param_varno >= 0)
    5622             :     {
    5623             :         if (yylex() != ';')
    5624             :             ereport(ERROR,
    5625             :                     (errcode(ERRCODE_DATATYPE_MISMATCH),
    5626             :                      errmsg("RETURN cannot have a parameter in function with OUT parameters"),
    5627             :                      parser_errposition(yylloc)));
    5628             :         new->retvarno = plpgsql_curr_compile->out_param_varno;
    5629             :     }
    5630             :     else
    5631             :     {
    5632             :         /*
    5633             :          * We want to special-case simple variable references for efficiency.
    5634             :          * So peek ahead to see if that's what we have.
    5635             :          */
    5636             :         int     tok = yylex();
    5637             : 
    5638             :         if (tok == T_DATUM && plpgsql_peek() == ';' &&
    5639             :             (yylval.wdatum.datum->dtype == PLPGSQL_DTYPE_VAR ||
    5640             :              yylval.wdatum.datum->dtype == PLPGSQL_DTYPE_PROMISE ||
    5641             :              yylval.wdatum.datum->dtype == PLPGSQL_DTYPE_ROW ||
    5642             :              yylval.wdatum.datum->dtype == PLPGSQL_DTYPE_REC))
    5643             :         {
    5644             :             new->retvarno = yylval.wdatum.datum->dno;
    5645             :             /* eat the semicolon token that we only peeked at above */
    5646             :             tok = yylex();
    5647             :             Assert(tok == ';');
    5648             :         }
    5649             :         else
    5650             :         {
    5651             :             /*
    5652             :              * Not (just) a variable name, so treat as expression.
    5653             :              *
    5654             :              * Note that a well-formed expression is _required_ here;
    5655             :              * anything else is a compile-time error.
    5656             :              */
    5657             :             plpgsql_push_back_token(tok);
    5658             :             new->expr = read_sql_expression(';', ";");
    5659             :         }
    5660             :     }
    5661             : 
    5662             :     return (PLpgSQL_stmt *) new;
    5663             : }
    5664             : 
    5665             : 
    5666             : static PLpgSQL_stmt *
    5667             : make_return_next_stmt(int location)
    5668             : {
    5669             :     PLpgSQL_stmt_return_next *new;
    5670             : 
    5671             :     if (!plpgsql_curr_compile->fn_retset)
    5672             :         ereport(ERROR,
    5673             :                 (errcode(ERRCODE_DATATYPE_MISMATCH),
    5674             :                  errmsg("cannot use RETURN NEXT in a non-SETOF function"),
    5675             :                  parser_errposition(location)));
    5676             : 
    5677             :     new = palloc0(sizeof(PLpgSQL_stmt_return_next));
    5678             :     new->cmd_type    = PLPGSQL_STMT_RETURN_NEXT;
    5679             :     new->lineno      = plpgsql_location_to_lineno(location);
    5680             :     new->stmtid      = ++plpgsql_curr_compile->nstatements;
    5681             :     new->expr        = NULL;
    5682             :     new->retvarno    = -1;
    5683             : 
    5684             :     if (plpgsql_curr_compile->out_param_varno >= 0)
    5685             :     {
    5686             :         if (yylex() != ';')
    5687             :             ereport(ERROR,
    5688             :                     (errcode(ERRCODE_DATATYPE_MISMATCH),
    5689             :                      errmsg("RETURN NEXT cannot have a parameter in function with OUT parameters"),
    5690             :                      parser_errposition(yylloc)));
    5691             :         new->retvarno = plpgsql_curr_compile->out_param_varno;
    5692             :     }
    5693             :     else
    5694             :     {
    5695             :         /*
    5696             :          * We want to special-case simple variable references for efficiency.
    5697             :          * So peek ahead to see if that's what we have.
    5698             :          */
    5699             :         int     tok = yylex();
    5700             : 
    5701             :         if (tok == T_DATUM && plpgsql_peek() == ';' &&
    5702             :             (yylval.wdatum.datum->dtype == PLPGSQL_DTYPE_VAR ||
    5703             :              yylval.wdatum.datum->dtype == PLPGSQL_DTYPE_PROMISE ||
    5704             :              yylval.wdatum.datum->dtype == PLPGSQL_DTYPE_ROW ||
    5705             :              yylval.wdatum.datum->dtype == PLPGSQL_DTYPE_REC))
    5706             :         {
    5707             :             new->retvarno = yylval.wdatum.datum->dno;
    5708             :             /* eat the semicolon token that we only peeked at above */
    5709             :             tok = yylex();
    5710             :             Assert(tok == ';');
    5711             :         }
    5712             :         else
    5713             :         {
    5714             :             /*
    5715             :              * Not (just) a variable name, so treat as expression.
    5716             :              *
    5717             :              * Note that a well-formed expression is _required_ here;
    5718             :              * anything else is a compile-time error.
    5719             :              */
    5720             :             plpgsql_push_back_token(tok);
    5721             :             new->expr = read_sql_expression(';', ";");
    5722             :         }
    5723             :     }
    5724             : 
    5725             :     return (PLpgSQL_stmt *) new;
    5726             : }
    5727             : 
    5728             : 
    5729             : static PLpgSQL_stmt *
    5730             : make_return_query_stmt(int location)
    5731             : {
    5732             :     PLpgSQL_stmt_return_query *new;
    5733             :     int         tok;
    5734             : 
    5735             :     if (!plpgsql_curr_compile->fn_retset)
    5736             :         ereport(ERROR,
    5737             :                 (errcode(ERRCODE_DATATYPE_MISMATCH),
    5738             :                  errmsg("cannot use RETURN QUERY in a non-SETOF function"),
    5739             :                  parser_errposition(location)));
    5740             : 
    5741             :     new = palloc0(sizeof(PLpgSQL_stmt_return_query));
    5742             :     new->cmd_type = PLPGSQL_STMT_RETURN_QUERY;
    5743             :     new->lineno = plpgsql_location_to_lineno(location);
    5744             :     new->stmtid = ++plpgsql_curr_compile->nstatements;
    5745             : 
    5746             :     /* check for RETURN QUERY EXECUTE */
    5747             :     if ((tok = yylex()) != K_EXECUTE)
    5748             :     {
    5749             :         /* ordinary static query */
    5750             :         plpgsql_push_back_token(tok);
    5751             :         new->query = read_sql_stmt("");
    5752             :     }
    5753             :     else
    5754             :     {
    5755             :         /* dynamic SQL */
    5756             :         int     term;
    5757             : 
    5758             :         new->dynquery = read_sql_expression2(';', K_USING, "; or USING",
    5759             :                                              &term);
    5760             :         if (term == K_USING)
    5761             :         {
    5762             :             do
    5763             :             {
    5764             :                 PLpgSQL_expr *expr;
    5765             : 
    5766             :                 expr = read_sql_expression2(',', ';', ", or ;", &term);
    5767             :                 new->params = lappend(new->params, expr);
    5768             :             } while (term == ',');
    5769             :         }
    5770             :     }
    5771             : 
    5772             :     return (PLpgSQL_stmt *) new;
    5773             : }
    5774             : 
    5775             : 
    5776             : /* convenience routine to fetch the name of a T_DATUM */
    5777             : static char *
    5778             : NameOfDatum(PLwdatum *wdatum)
    5779             : {
    5780             :     if (wdatum->ident)
    5781             :         return wdatum->ident;
    5782             :     Assert(wdatum->idents != NIL);
    5783             :     return NameListToString(wdatum->idents);
    5784             : }
    5785             : 
    5786             : static void
    5787             : check_assignable(PLpgSQL_datum *datum, int location)
    5788             : {
    5789             :     switch (datum->dtype)
    5790             :     {
    5791             :         case PLPGSQL_DTYPE_VAR:
    5792             :         case PLPGSQL_DTYPE_PROMISE:
    5793             :         case PLPGSQL_DTYPE_REC:
    5794             :             if (((PLpgSQL_variable *) datum)->isconst)
    5795             :                 ereport(ERROR,
    5796             :                         (errcode(ERRCODE_ERROR_IN_ASSIGNMENT),
    5797             :                          errmsg("variable \"%s\" is declared CONSTANT",
    5798             :                                 ((PLpgSQL_variable *) datum)->refname),
    5799             :                          parser_errposition(location)));
    5800             :             break;
    5801             :         case PLPGSQL_DTYPE_ROW:
    5802             :             /* always assignable; member vars were checked at compile time */
    5803             :             break;
    5804             :         case PLPGSQL_DTYPE_RECFIELD:
    5805             :             /* assignable if parent record is */
    5806             :             check_assignable(plpgsql_Datums[((PLpgSQL_recfield *) datum)->recparentno],
    5807             :                              location);
    5808             :             break;
    5809             :         case PLPGSQL_DTYPE_ARRAYELEM:
    5810             :             /* assignable if parent array is */
    5811             :             check_assignable(plpgsql_Datums[((PLpgSQL_arrayelem *) datum)->arrayparentno],
    5812             :                              location);
    5813             :             break;
    5814             :         default:
    5815             :             elog(ERROR, "unrecognized dtype: %d", datum->dtype);
    5816             :             break;
    5817             :     }
    5818             : }
    5819             : 
    5820             : /*
    5821             :  * Read the argument of an INTO clause.  On entry, we have just read the
    5822             :  * INTO keyword.
    5823             :  */
    5824             : static void
    5825             : read_into_target(PLpgSQL_variable **target, bool *strict)
    5826             : {
    5827             :     int         tok;
    5828             : 
    5829             :     /* Set default results */
    5830             :     *target = NULL;
    5831             :     if (strict)
    5832             :         *strict = false;
    5833             : 
    5834             :     tok = yylex();
    5835             :     if (strict && tok == K_STRICT)
    5836             :     {
    5837             :         *strict = true;
    5838             :         tok = yylex();
    5839             :     }
    5840             : 
    5841             :     /*
    5842             :      * Currently, a row or record variable can be the single INTO target,
    5843             :      * but not a member of a multi-target list.  So we throw error if there
    5844             :      * is a comma after it, because that probably means the user tried to
    5845             :      * write a multi-target list.  If this ever gets generalized, we should
    5846             :      * probably refactor read_into_scalar_list so it handles all cases.
    5847             :      */
    5848             :     switch (tok)
    5849             :     {
    5850             :         case T_DATUM:
    5851             :             if (yylval.wdatum.datum->dtype == PLPGSQL_DTYPE_ROW ||
    5852             :                 yylval.wdatum.datum->dtype == PLPGSQL_DTYPE_REC)
    5853             :             {
    5854             :                 check_assignable(yylval.wdatum.datum, yylloc);
    5855             :                 *target = (PLpgSQL_variable *) yylval.wdatum.datum;
    5856             : 
    5857             :                 if ((tok = yylex()) == ',')
    5858             :                     ereport(ERROR,
    5859             :                             (errcode(ERRCODE_SYNTAX_ERROR),
    5860             :                              errmsg("record variable cannot be part of multiple-item INTO list"),
    5861             :                              parser_errposition(yylloc)));
    5862             :                 plpgsql_push_back_token(tok);
    5863             :             }
    5864             :             else
    5865             :             {
    5866             :                 *target = (PLpgSQL_variable *)
    5867             :                     read_into_scalar_list(NameOfDatum(&(yylval.wdatum)),
    5868             :                                           yylval.wdatum.datum, yylloc);
    5869             :             }
    5870             :             break;
    5871             : 
    5872             :         default:
    5873             :             /* just to give a better message than "syntax error" */
    5874             :             current_token_is_not_variable(tok);
    5875             :     }
    5876             : }
    5877             : 
    5878             : /*
    5879             :  * Given the first datum and name in the INTO list, continue to read
    5880             :  * comma-separated scalar variables until we run out. Then construct
    5881             :  * and return a fake "row" variable that represents the list of
    5882             :  * scalars.
    5883             :  */
    5884             : static PLpgSQL_row *
    5885             : read_into_scalar_list(char *initial_name,
    5886             :                       PLpgSQL_datum *initial_datum,
    5887             :                       int initial_location)
    5888             : {
    5889             :     int              nfields;
    5890             :     char            *fieldnames[1024];
    5891             :     int              varnos[1024];
    5892             :     PLpgSQL_row     *row;
    5893             :     int              tok;
    5894             : 
    5895             :     check_assignable(initial_datum, initial_location);
    5896             :     fieldnames[0] = initial_name;
    5897             :     varnos[0]     = initial_datum->dno;
    5898             :     nfields       = 1;
    5899             : 
    5900             :     while ((tok = yylex()) == ',')
    5901             :     {
    5902             :         /* Check for array overflow */
    5903             :         if (nfields >= 1024)
    5904             :             ereport(ERROR,
    5905             :                     (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
    5906             :                      errmsg("too many INTO variables specified"),
    5907             :                      parser_errposition(yylloc)));
    5908             : 
    5909             :         tok = yylex();
    5910             :         switch (tok)
    5911             :         {
    5912             :             case T_DATUM:
    5913             :                 check_assignable(yylval.wdatum.datum, yylloc);
    5914             :                 if (yylval.wdatum.datum->dtype == PLPGSQL_DTYPE_ROW ||
    5915             :                     yylval.wdatum.datum->dtype == PLPGSQL_DTYPE_REC)
    5916             :                     ereport(ERROR,
    5917             :                             (errcode(ERRCODE_SYNTAX_ERROR),
    5918             :                              errmsg("\"%s\" is not a scalar variable",
    5919             :                                     NameOfDatum(&(yylval.wdatum))),
    5920             :                              parser_errposition(yylloc)));
    5921             :                 fieldnames[nfields] = NameOfDatum(&(yylval.wdatum));
    5922             :                 varnos[nfields++]   = yylval.wdatum.datum->dno;
    5923             :                 break;
    5924             : 
    5925             :             default:
    5926             :                 /* just to give a better message than "syntax error" */
    5927             :                 current_token_is_not_variable(tok);
    5928             :         }
    5929             :     }
    5930             : 
    5931             :     /*
    5932             :      * We read an extra, non-comma token from yylex(), so push it
    5933             :      * back onto the input stream
    5934             :      */
    5935             :     plpgsql_push_back_token(tok);
    5936             : 
    5937             :     row = palloc0(sizeof(PLpgSQL_row));
    5938             :     row->dtype = PLPGSQL_DTYPE_ROW;
    5939             :     row->refname = "(unnamed row)";
    5940             :     row->lineno = plpgsql_location_to_lineno(initial_location);
    5941             :     row->rowtupdesc = NULL;
    5942             :     row->nfields = nfields;
    5943             :     row->fieldnames = palloc(sizeof(char *) * nfields);
    5944             :     row->varnos = palloc(sizeof(int) * nfields);
    5945             :     while (--nfields >= 0)
    5946             :     {
    5947             :         row->fieldnames[nfields] = fieldnames[nfields];
    5948             :         row->varnos[nfields] = varnos[nfields];
    5949             :     }
    5950             : 
    5951             :     plpgsql_adddatum((PLpgSQL_datum *)row);
    5952             : 
    5953             :     return row;
    5954             : }
    5955             : 
    5956             : /*
    5957             :  * Convert a single scalar into a "row" list.  This is exactly
    5958             :  * like read_into_scalar_list except we never consume any input.
    5959             :  *
    5960             :  * Note: lineno could be computed from location, but since callers
    5961             :  * have it at hand already, we may as well pass it in.
    5962             :  */
    5963             : static PLpgSQL_row *
    5964             : make_scalar_list1(char *initial_name,
    5965             :                   PLpgSQL_datum *initial_datum,
    5966             :                   int lineno, int location)
    5967             : {
    5968             :     PLpgSQL_row     *row;
    5969             : 
    5970             :     check_assignable(initial_datum, location);
    5971             : 
    5972             :     row = palloc0(sizeof(PLpgSQL_row));
    5973             :     row->dtype = PLPGSQL_DTYPE_ROW;
    5974             :     row->refname = "(unnamed row)";
    5975             :     row->lineno = lineno;
    5976             :     row->rowtupdesc = NULL;
    5977             :     row->nfields = 1;
    5978             :     row->fieldnames = palloc(sizeof(char *));
    5979             :     row->varnos = palloc(sizeof(int));
    5980             :     row->fieldnames[0] = initial_name;
    5981             :     row->varnos[0] = initial_datum->dno;
    5982             : 
    5983             :     plpgsql_adddatum((PLpgSQL_datum *)row);
    5984             : 
    5985             :     return row;
    5986             : }
    5987             : 
    5988             : /*
    5989             :  * When the PL/pgSQL parser expects to see a SQL statement, it is very
    5990             :  * liberal in what it accepts; for example, we often assume an
    5991             :  * unrecognized keyword is the beginning of a SQL statement. This
    5992             :  * avoids the need to duplicate parts of the SQL grammar in the
    5993             :  * PL/pgSQL grammar, but it means we can accept wildly malformed
    5994             :  * input. To try and catch some of the more obviously invalid input,
    5995             :  * we run the strings we expect to be SQL statements through the main
    5996             :  * SQL parser.
    5997             :  *
    5998             :  * We only invoke the raw parser (not the analyzer); this doesn't do
    5999             :  * any database access and does not check any semantic rules, it just
    6000             :  * checks for basic syntactic correctness. We do this here, rather
    6001             :  * than after parsing has finished, because a malformed SQL statement
    6002             :  * may cause the PL/pgSQL parser to become confused about statement
    6003             :  * borders. So it is best to bail out as early as we can.
    6004             :  *
    6005             :  * It is assumed that "stmt" represents a copy of the function source text
    6006             :  * beginning at offset "location", with leader text of length "leaderlen"
    6007             :  * (typically "SELECT ") prefixed to the source text.  We use this assumption
    6008             :  * to transpose any error cursor position back to the function source text.
    6009             :  * If no error cursor is provided, we'll just point at "location".
    6010             :  */
    6011             : static void
    6012             : check_sql_expr(const char *stmt, int location, int leaderlen)
    6013             : {
    6014             :     sql_error_callback_arg cbarg;
    6015             :     ErrorContextCallback  syntax_errcontext;
    6016             :     MemoryContext oldCxt;
    6017             : 
    6018             :     if (!plpgsql_check_syntax)
    6019             :         return;
    6020             : 
    6021             :     cbarg.location = location;
    6022             :     cbarg.leaderlen = leaderlen;
    6023             : 
    6024             :     syntax_errcontext.callback = plpgsql_sql_error_callback;
    6025             :     syntax_errcontext.arg = &cbarg;
    6026             :     syntax_errcontext.previous = error_context_stack;
    6027             :     error_context_stack = &syntax_errcontext;
    6028             : 
    6029             :     oldCxt = MemoryContextSwitchTo(plpgsql_compile_tmp_cxt);
    6030             :     (void) raw_parser(stmt);
    6031             :     MemoryContextSwitchTo(oldCxt);
    6032             : 
    6033             :     /* Restore former ereport callback */
    6034             :     error_context_stack = syntax_errcontext.previous;
    6035             : }
    6036             : 
    6037             : static void
    6038             : plpgsql_sql_error_callback(void *arg)
    6039             : {
    6040             :     sql_error_callback_arg *cbarg = (sql_error_callback_arg *) arg;
    6041             :     int         errpos;
    6042             : 
    6043             :     /*
    6044             :      * First, set up internalerrposition to point to the start of the
    6045             :      * statement text within the function text.  Note this converts
    6046             :      * location (a byte offset) to a character number.
    6047             :      */
    6048             :     parser_errposition(cbarg->location);
    6049             : 
    6050             :     /*
    6051             :      * If the core parser provided an error position, transpose it.
    6052             :      * Note we are dealing with 1-based character numbers at this point.
    6053             :      */
    6054             :     errpos = geterrposition();
    6055             :     if (errpos > cbarg->leaderlen)
    6056             :     {
    6057             :         int     myerrpos = getinternalerrposition();
    6058             : 
    6059             :         if (myerrpos > 0)        /* safety check */
    6060             :             internalerrposition(myerrpos + errpos - cbarg->leaderlen - 1);
    6061             :     }
    6062             : 
    6063             :     /* In any case, flush errposition --- we want internalerrpos only */
    6064             :     errposition(0);
    6065             : }
    6066             : 
    6067             : /*
    6068             :  * Parse a SQL datatype name and produce a PLpgSQL_type structure.
    6069             :  *
    6070             :  * The heavy lifting is done elsewhere.  Here we are only concerned
    6071             :  * with setting up an errcontext link that will let us give an error
    6072             :  * cursor pointing into the plpgsql function source, if necessary.
    6073             :  * This is handled the same as in check_sql_expr(), and we likewise
    6074             :  * expect that the given string is a copy from the source text.
    6075             :  */
    6076             : static PLpgSQL_type *
    6077             : parse_datatype(const char *string, int location)
    6078             : {
    6079             :     Oid         type_id;
    6080             :     int32       typmod;
    6081             :     sql_error_callback_arg cbarg;
    6082             :     ErrorContextCallback  syntax_errcontext;
    6083             : 
    6084             :     cbarg.location = location;
    6085             :     cbarg.leaderlen = 0;
    6086             : 
    6087             :     syntax_errcontext.callback = plpgsql_sql_error_callback;
    6088             :     syntax_errcontext.arg = &cbarg;
    6089             :     syntax_errcontext.previous = error_context_stack;
    6090             :     error_context_stack = &syntax_errcontext;
    6091             : 
    6092             :     /* Let the main parser try to parse it under standard SQL rules */
    6093             :     parseTypeString(string, &type_id, &typmod, false);
    6094             : 
    6095             :     /* Restore former ereport callback */
    6096             :     error_context_stack = syntax_errcontext.previous;
    6097             : 
    6098             :     /* Okay, build a PLpgSQL_type data structure for it */
    6099             :     return plpgsql_build_datatype(type_id, typmod,
    6100             :                                   plpgsql_curr_compile->fn_input_collation);
    6101             : }
    6102             : 
    6103             : /*
    6104             :  * Check block starting and ending labels match.
    6105             :  */
    6106             : static void
    6107             : check_labels(const char *start_label, const char *end_label, int end_location)
    6108             : {
    6109             :     if (end_label)
    6110             :     {
    6111             :         if (!start_label)
    6112             :             ereport(ERROR,
    6113             :                     (errcode(ERRCODE_SYNTAX_ERROR),
    6114             :                      errmsg("end label \"%s\" specified for unlabelled block",
    6115             :                             end_label),
    6116             :                      parser_errposition(end_location)));
    6117             : 
    6118             :         if (strcmp(start_label, end_label) != 0)
    6119             :             ereport(ERROR,
    6120             :                     (errcode(ERRCODE_SYNTAX_ERROR),
    6121             :                      errmsg("end label \"%s\" differs from block's label \"%s\"",
    6122             :                             end_label, start_label),
    6123             :                      parser_errposition(end_location)));
    6124             :     }
    6125             : }
    6126             : 
    6127             : /*
    6128             :  * Read the arguments (if any) for a cursor, followed by the until token
    6129             :  *
    6130             :  * If cursor has no args, just swallow the until token and return NULL.
    6131             :  * If it does have args, we expect to see "( arg [, arg ...] )" followed
    6132             :  * by the until token, where arg may be a plain expression, or a named
    6133             :  * parameter assignment of the form argname := expr. Consume all that and
    6134             :  * return a SELECT query that evaluates the expression(s) (without the outer
    6135             :  * parens).
    6136             :  */
    6137             : static PLpgSQL_expr *
    6138             : read_cursor_args(PLpgSQL_var *cursor, int until, const char *expected)
    6139             : {
    6140             :     PLpgSQL_expr *expr;
    6141             :     PLpgSQL_row *row;
    6142             :     int         tok;
    6143             :     int         argc;
    6144             :     char      **argv;
    6145             :     StringInfoData ds;
    6146             :     char       *sqlstart = "SELECT ";
    6147             :     bool        any_named = false;
    6148             : 
    6149             :     tok = yylex();
    6150             :     if (cursor->cursor_explicit_argrow < 0)
    6151             :     {
    6152             :         /* No arguments expected */
    6153             :         if (tok == '(')
    6154             :             ereport(ERROR,
    6155             :                     (errcode(ERRCODE_SYNTAX_ERROR),
    6156             :                      errmsg("cursor \"%s\" has no arguments",
    6157             :                             cursor->refname),
    6158             :                      parser_errposition(yylloc)));
    6159             : 
    6160             :         if (tok != until)
    6161             :             yyerror("syntax error");
    6162             : 
    6163             :         return NULL;
    6164             :     }
    6165             : 
    6166             :     /* Else better provide arguments */
    6167             :     if (tok != '(')
    6168             :         ereport(ERROR,
    6169             :                 (errcode(ERRCODE_SYNTAX_ERROR),
    6170             :                  errmsg("cursor \"%s\" has arguments",
    6171             :                         cursor->refname),
    6172             :                  parser_errposition(yylloc)));
    6173             : 
    6174             :     /*
    6175             :      * Read the arguments, one by one.
    6176             :      */
    6177             :     row = (PLpgSQL_row *) plpgsql_Datums[cursor->cursor_explicit_argrow];
    6178             :     argv = (char **) palloc0(row->nfields * sizeof(char *));
    6179             : 
    6180             :     for (argc = 0; argc < row->nfields; argc++)
    6181             :     {
    6182             :         PLpgSQL_expr *item;
    6183             :         int     endtoken;
    6184             :         int     argpos;
    6185             :         int     tok1,
    6186             :                 tok2;
    6187             :         int     arglocation;
    6188             : 
    6189             :         /* Check if it's a named parameter: "param := value" */
    6190             :         plpgsql_peek2(&tok1, &tok2, &arglocation, NULL);
    6191             :         if (tok1 == IDENT && tok2 == COLON_EQUALS)
    6192             :         {
    6193             :             char   *argname;
    6194             :             IdentifierLookup save_IdentifierLookup;
    6195             : 
    6196             :             /* Read the argument name, ignoring any matching variable */
    6197             :             save_IdentifierLookup = plpgsql_IdentifierLookup;
    6198             :             plpgsql_IdentifierLookup = IDENTIFIER_LOOKUP_DECLARE;
    6199             :             yylex();
    6200             :             argname = yylval.str;
    6201             :             plpgsql_IdentifierLookup = save_IdentifierLookup;
    6202             : 
    6203             :             /* Match argument name to cursor arguments */
    6204             :             for (argpos = 0; argpos < row->nfields; argpos++)
    6205             :             {
    6206             :                 if (strcmp(row->fieldnames[argpos], argname) == 0)
    6207             :                     break;
    6208             :             }
    6209             :             if (argpos == row->nfields)
    6210             :                 ereport(ERROR,
    6211             :                         (errcode(ERRCODE_SYNTAX_ERROR),
    6212             :                          errmsg("cursor \"%s\" has no argument named \"%s\"",
    6213             :                                 cursor->refname, argname),
    6214             :                          parser_errposition(yylloc)));
    6215             : 
    6216             :             /*
    6217             :              * Eat the ":=". We already peeked, so the error should never
    6218             :              * happen.
    6219             :              */
    6220             :             tok2 = yylex();
    6221             :             if (tok2 != COLON_EQUALS)
    6222             :                 yyerror("syntax error");
    6223             : 
    6224             :             any_named = true;
    6225             :         }
    6226             :         else
    6227             :             argpos = argc;
    6228             : 
    6229             :         if (argv[argpos] != NULL)
    6230             :             ereport(ERROR,
    6231             :                     (errcode(ERRCODE_SYNTAX_ERROR),
    6232             :                      errmsg("value for parameter \"%s\" of cursor \"%s\" specified more than once",
    6233             :                             row->fieldnames[argpos], cursor->refname),
    6234             :                      parser_errposition(arglocation)));
    6235             : 
    6236             :         /*
    6237             :          * Read the value expression. To provide the user with meaningful
    6238             :          * parse error positions, we check the syntax immediately, instead of
    6239             :          * checking the final expression that may have the arguments
    6240             :          * reordered. Trailing whitespace must not be trimmed, because
    6241             :          * otherwise input of the form (param -- comment\n, param) would be
    6242             :          * translated into a form where the second parameter is commented
    6243             :          * out.
    6244             :          */
    6245             :         item = read_sql_construct(',', ')', 0,
    6246             :                                   ",\" or \")",
    6247             :                                   sqlstart,
    6248             :                                   true, true,
    6249             :                                   false, /* do not trim */
    6250             :                                   NULL, &endtoken);
    6251             : 
    6252             :         argv[argpos] = item->query + strlen(sqlstart);
    6253             : 
    6254             :         if (endtoken == ')' && !(argc == row->nfields - 1))
    6255             :             ereport(ERROR,
    6256             :                     (errcode(ERRCODE_SYNTAX_ERROR),
    6257             :                      errmsg("not enough arguments for cursor \"%s\"",
    6258             :                             cursor->refname),
    6259             :                      parser_errposition(yylloc)));
    6260             : 
    6261             :         if (endtoken == ',' && (argc == row->nfields - 1))
    6262             :             ereport(ERROR,
    6263             :                     (errcode(ERRCODE_SYNTAX_ERROR),
    6264             :                      errmsg("too many arguments for cursor \"%s\"",
    6265             :                             cursor->refname),
    6266             :                      parser_errposition(yylloc)));
    6267             :     }
    6268             : 
    6269             :     /* Make positional argument list */
    6270             :     initStringInfo(&ds);
    6271             :     appendStringInfoString(&ds, sqlstart);
    6272             :     for (argc = 0; argc < row->nfields; argc++)
    6273             :     {
    6274             :         Assert(argv[argc] != NULL);
    6275             : 
    6276             :         /*
    6277             :          * Because named notation allows permutated argument lists, include
    6278             :          * the parameter name for meaningful runtime errors.
    6279             :          */
    6280             :         appendStringInfoString(&ds, argv[argc]);
    6281             :         if (any_named)
    6282             :             appendStringInfo(&ds, " AS %s",
    6283             :                              quote_identifier(row->fieldnames[argc]));
    6284             :         if (argc < row->nfields - 1)
    6285             :             appendStringInfoString(&ds, ", ");
    6286             :     }
    6287             :     appendStringInfoChar(&ds, ';');
    6288             : 
    6289             :     expr = palloc0(sizeof(PLpgSQL_expr));
    6290             :     expr->query          = pstrdup(ds.data);
    6291             :     expr->plan           = NULL;
    6292             :     expr->paramnos       = NULL;
    6293             :     expr->rwparam        = -1;
    6294             :     expr->ns            = plpgsql_ns_top();
    6295             :     pfree(ds.data);
    6296             : 
    6297             :     /* Next we'd better find the until token */
    6298             :     tok = yylex();
    6299             :     if (tok != until)
    6300             :         yyerror("syntax error");
    6301             : 
    6302             :     return expr;
    6303             : }
    6304             : 
    6305             : /*
    6306             :  * Parse RAISE ... USING options
    6307             :  */
    6308             : static List *
    6309             : read_raise_options(void)
    6310             : {
    6311             :     List       *result = NIL;
    6312             : 
    6313             :     for (;;)
    6314             :     {
    6315             :         PLpgSQL_raise_option *opt;
    6316             :         int     tok;
    6317             : 
    6318             :         if ((tok = yylex()) == 0)
    6319             :             yyerror("unexpected end of function definition");
    6320             : 
    6321             :         opt = (PLpgSQL_raise_option *) palloc(sizeof(PLpgSQL_raise_option));
    6322             : 
    6323             :         if (tok_is_keyword(tok, &yylval,
    6324             :                            K_ERRCODE, "errcode"))
    6325             :             opt->opt_type = PLPGSQL_RAISEOPTION_ERRCODE;
    6326             :         else if (tok_is_keyword(tok, &yylval,
    6327             :                                 K_MESSAGE, "message"))
    6328             :             opt->opt_type = PLPGSQL_RAISEOPTION_MESSAGE;
    6329             :         else if (tok_is_keyword(tok, &yylval,
    6330             :                                 K_DETAIL, "detail"))
    6331             :             opt->opt_type = PLPGSQL_RAISEOPTION_DETAIL;
    6332             :         else if (tok_is_keyword(tok, &yylval,
    6333             :                                 K_HINT, "hint"))
    6334             :             opt->opt_type = PLPGSQL_RAISEOPTION_HINT;
    6335             :         else if (tok_is_keyword(tok, &yylval,
    6336             :                                 K_COLUMN, "column"))
    6337             :             opt->opt_type = PLPGSQL_RAISEOPTION_COLUMN;
    6338             :         else if (tok_is_keyword(tok, &yylval,
    6339             :                                 K_CONSTRAINT, "constraint"))
    6340             :             opt->opt_type = PLPGSQL_RAISEOPTION_CONSTRAINT;
    6341             :         else if (tok_is_keyword(tok, &yylval,
    6342             :                                 K_DATATYPE, "datatype"))
    6343             :             opt->opt_type = PLPGSQL_RAISEOPTION_DATATYPE;
    6344             :         else if (tok_is_keyword(tok, &yylval,
    6345             :                                 K_TABLE, "table"))
    6346             :             opt->opt_type = PLPGSQL_RAISEOPTION_TABLE;
    6347             :         else if (tok_is_keyword(tok, &yylval,
    6348             :                                 K_SCHEMA, "schema"))
    6349             :             opt->opt_type = PLPGSQL_RAISEOPTION_SCHEMA;
    6350             :         else
    6351             :             yyerror("unrecognized RAISE statement option");
    6352             : 
    6353             :         tok = yylex();
    6354             :         if (tok != '=' && tok != COLON_EQUALS)
    6355             :             yyerror("syntax error, expected \"=\"");
    6356             : 
    6357             :         opt->expr = read_sql_expression2(',', ';', ", or ;", &tok);
    6358             : 
    6359             :         result = lappend(result, opt);
    6360             : 
    6361             :         if (tok == ';')
    6362             :             break;
    6363             :     }
    6364             : 
    6365             :     return result;
    6366             : }
    6367             : 
    6368             : /*
    6369             :  * Check that the number of parameter placeholders in the message matches the
    6370             :  * number of parameters passed to it, if a message was given.
    6371             :  */
    6372             : static void
    6373             : check_raise_parameters(PLpgSQL_stmt_raise *stmt)
    6374             : {
    6375             :     char       *cp;
    6376             :     int         expected_nparams = 0;
    6377             : 
    6378             :     if (stmt->message == NULL)
    6379             :         return;
    6380             : 
    6381             :     for (cp = stmt->message; *cp; cp++)
    6382             :     {
    6383             :         if (cp[0] == '%')
    6384             :         {
    6385             :             /* ignore literal % characters */
    6386             :             if (cp[1] == '%')
    6387             :                 cp++;
    6388             :             else
    6389             :                 expected_nparams++;
    6390             :         }
    6391             :     }
    6392             : 
    6393             :     if (expected_nparams < list_length(stmt->params))
    6394             :         ereport(ERROR,
    6395             :                 (errcode(ERRCODE_SYNTAX_ERROR),
    6396             :                 errmsg("too many parameters specified for RAISE")));
    6397             :     if (expected_nparams > list_length(stmt->params))
    6398             :         ereport(ERROR,
    6399             :                 (errcode(ERRCODE_SYNTAX_ERROR),
    6400             :                 errmsg("too few parameters specified for RAISE")));
    6401             : }
    6402             : 
    6403             : /*
    6404             :  * Fix up CASE statement
    6405             :  */
    6406             : static PLpgSQL_stmt *
    6407             : make_case(int location, PLpgSQL_expr *t_expr,
    6408             :           List *case_when_list, List *else_stmts)
    6409             : {
    6410             :     PLpgSQL_stmt_case   *new;
    6411             : 
    6412             :     new = palloc(sizeof(PLpgSQL_stmt_case));
    6413             :     new->cmd_type = PLPGSQL_STMT_CASE;
    6414             :     new->lineno = plpgsql_location_to_lineno(location);
    6415             :     new->stmtid = ++plpgsql_curr_compile->nstatements;
    6416             :     new->t_expr = t_expr;
    6417             :     new->t_varno = 0;
    6418             :     new->case_when_list = case_when_list;
    6419             :     new->have_else = (else_stmts != NIL);
    6420             :     /* Get rid of list-with-NULL hack */
    6421             :     if (list_length(else_stmts) == 1 && linitial(else_stmts) == NULL)
    6422             :         new->else_stmts = NIL;
    6423             :     else
    6424             :         new->else_stmts = else_stmts;
    6425             : 
    6426             :     /*
    6427             :      * When test expression is present, we create a var for it and then
    6428             :      * convert all the WHEN expressions to "VAR IN (original_expression)".
    6429             :      * This is a bit klugy, but okay since we haven't yet done more than
    6430             :      * read the expressions as text.  (Note that previous parsing won't
    6431             :      * have complained if the WHEN ... THEN expression contained multiple
    6432             :      * comma-separated values.)
    6433             :      */
    6434             :     if (t_expr)
    6435             :     {
    6436             :         char    varname[32];
    6437             :         PLpgSQL_var *t_var;
    6438             :         ListCell *l;
    6439             : 
    6440             :         /* use a name unlikely to collide with any user names */
    6441             :         snprintf(varname, sizeof(varname), "__Case__Variable_%d__",
    6442             :                  plpgsql_nDatums);
    6443             : 
    6444             :         /*
    6445             :          * We don't yet know the result datatype of t_expr.  Build the
    6446             :          * variable as if it were INT4; we'll fix this at runtime if needed.
    6447             :          */
    6448             :         t_var = (PLpgSQL_var *)
    6449             :             plpgsql_build_variable(varname, new->lineno,
    6450             :                                    plpgsql_build_datatype(INT4OID,
    6451             :                                                           -1,
    6452             :                                                           InvalidOid),
    6453             :                                    true);
    6454             :         new->t_varno = t_var->dno;
    6455             : 
    6456             :         foreach(l, case_when_list)
    6457             :         {
    6458             :             PLpgSQL_case_when *cwt = (PLpgSQL_case_when *) lfirst(l);
    6459             :             PLpgSQL_expr *expr = cwt->expr;
    6460             :             StringInfoData  ds;
    6461             : 
    6462             :             /* copy expression query without SELECT keyword (expr->query + 7) */
    6463             :             Assert(strncmp(expr->query, "SELECT ", 7) == 0);
    6464             : 
    6465             :             /* And do the string hacking */
    6466             :             initStringInfo(&ds);
    6467             : 
    6468             :             appendStringInfo(&ds, "SELECT \"%s\" IN (%s)",
    6469             :                              varname, expr->query + 7);
    6470             : 
    6471             :             pfree(expr->query);
    6472             :             expr->query = pstrdup(ds.data);
    6473             :             /* Adjust expr's namespace to include the case variable */
    6474             :             expr->ns = plpgsql_ns_top();
    6475             : 
    6476             :             pfree(ds.data);
    6477             :         }
    6478             :     }
    6479             : 
    6480             :     return (PLpgSQL_stmt *) new;
    6481             : }

Generated by: LCOV version 1.13