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