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