LCOV - code coverage report
Current view: top level - src/pl/plpgsql/src - pl_gram.c (source / functions) Hit Total Coverage
Test: PostgreSQL Lines: 199 282 70.6 %
Date: 2017-09-29 15:12:54 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11