PageRenderTime 85ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 1ms

/lib_pq/src/pl/plpgsql/src/pl_gram.c

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