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