LCOV - code coverage report
Current view: top level - src/pl/plpgsql/src - pl_gram.c (source / functions) Hit Total Coverage
Test: PostgreSQL 13devel Lines: 217 294 73.8 %
Date: 2019-08-24 15:07:19 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13