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