PostgreSQL Source Code  git master
pl_funcs.c File Reference
#include "postgres.h"
#include "utils/memutils.h"
#include "plpgsql.h"
Include dependency graph for pl_funcs.c:

Go to the source code of this file.

Functions

void plpgsql_ns_init (void)
 
void plpgsql_ns_push (const char *label, PLpgSQL_label_type label_type)
 
void plpgsql_ns_pop (void)
 
PLpgSQL_nsitemplpgsql_ns_top (void)
 
void plpgsql_ns_additem (PLpgSQL_nsitem_type itemtype, int itemno, const char *name)
 
PLpgSQL_nsitemplpgsql_ns_lookup (PLpgSQL_nsitem *ns_cur, bool localmode, const char *name1, const char *name2, const char *name3, int *names_used)
 
PLpgSQL_nsitemplpgsql_ns_lookup_label (PLpgSQL_nsitem *ns_cur, const char *name)
 
PLpgSQL_nsitemplpgsql_ns_find_nearest_loop (PLpgSQL_nsitem *ns_cur)
 
const char * plpgsql_stmt_typename (PLpgSQL_stmt *stmt)
 
const char * plpgsql_getdiag_kindname (PLpgSQL_getdiag_kind kind)
 
static void free_stmt (PLpgSQL_stmt *stmt)
 
static void free_block (PLpgSQL_stmt_block *block)
 
static void free_assign (PLpgSQL_stmt_assign *stmt)
 
static void free_if (PLpgSQL_stmt_if *stmt)
 
static void free_case (PLpgSQL_stmt_case *stmt)
 
static void free_loop (PLpgSQL_stmt_loop *stmt)
 
static void free_while (PLpgSQL_stmt_while *stmt)
 
static void free_fori (PLpgSQL_stmt_fori *stmt)
 
static void free_fors (PLpgSQL_stmt_fors *stmt)
 
static void free_forc (PLpgSQL_stmt_forc *stmt)
 
static void free_foreach_a (PLpgSQL_stmt_foreach_a *stmt)
 
static void free_exit (PLpgSQL_stmt_exit *stmt)
 
static void free_return (PLpgSQL_stmt_return *stmt)
 
static void free_return_next (PLpgSQL_stmt_return_next *stmt)
 
static void free_return_query (PLpgSQL_stmt_return_query *stmt)
 
static void free_raise (PLpgSQL_stmt_raise *stmt)
 
static void free_assert (PLpgSQL_stmt_assert *stmt)
 
static void free_execsql (PLpgSQL_stmt_execsql *stmt)
 
static void free_dynexecute (PLpgSQL_stmt_dynexecute *stmt)
 
static void free_dynfors (PLpgSQL_stmt_dynfors *stmt)
 
static void free_getdiag (PLpgSQL_stmt_getdiag *stmt)
 
static void free_open (PLpgSQL_stmt_open *stmt)
 
static void free_fetch (PLpgSQL_stmt_fetch *stmt)
 
static void free_close (PLpgSQL_stmt_close *stmt)
 
static void free_perform (PLpgSQL_stmt_perform *stmt)
 
static void free_commit (PLpgSQL_stmt_commit *stmt)
 
static void free_rollback (PLpgSQL_stmt_rollback *stmt)
 
static void free_expr (PLpgSQL_expr *expr)
 
static void free_stmts (List *stmts)
 
void plpgsql_free_function_memory (PLpgSQL_function *func)
 
static void dump_ind (void)
 
static void dump_stmt (PLpgSQL_stmt *stmt)
 
static void dump_block (PLpgSQL_stmt_block *block)
 
static void dump_assign (PLpgSQL_stmt_assign *stmt)
 
static void dump_if (PLpgSQL_stmt_if *stmt)
 
static void dump_case (PLpgSQL_stmt_case *stmt)
 
static void dump_loop (PLpgSQL_stmt_loop *stmt)
 
static void dump_while (PLpgSQL_stmt_while *stmt)
 
static void dump_fori (PLpgSQL_stmt_fori *stmt)
 
static void dump_fors (PLpgSQL_stmt_fors *stmt)
 
static void dump_forc (PLpgSQL_stmt_forc *stmt)
 
static void dump_foreach_a (PLpgSQL_stmt_foreach_a *stmt)
 
static void dump_exit (PLpgSQL_stmt_exit *stmt)
 
static void dump_return (PLpgSQL_stmt_return *stmt)
 
static void dump_return_next (PLpgSQL_stmt_return_next *stmt)
 
static void dump_return_query (PLpgSQL_stmt_return_query *stmt)
 
static void dump_raise (PLpgSQL_stmt_raise *stmt)
 
static void dump_assert (PLpgSQL_stmt_assert *stmt)
 
static void dump_execsql (PLpgSQL_stmt_execsql *stmt)
 
static void dump_dynexecute (PLpgSQL_stmt_dynexecute *stmt)
 
static void dump_dynfors (PLpgSQL_stmt_dynfors *stmt)
 
static void dump_getdiag (PLpgSQL_stmt_getdiag *stmt)
 
static void dump_open (PLpgSQL_stmt_open *stmt)
 
static void dump_fetch (PLpgSQL_stmt_fetch *stmt)
 
static void dump_cursor_direction (PLpgSQL_stmt_fetch *stmt)
 
static void dump_close (PLpgSQL_stmt_close *stmt)
 
static void dump_perform (PLpgSQL_stmt_perform *stmt)
 
static void dump_commit (PLpgSQL_stmt_commit *stmt)
 
static void dump_rollback (PLpgSQL_stmt_rollback *stmt)
 
static void dump_expr (PLpgSQL_expr *expr)
 
static void dump_stmts (List *stmts)
 
void plpgsql_dumptree (PLpgSQL_function *func)
 

Variables

static PLpgSQL_nsitemns_top = NULL
 
static int dump_indent
 

Function Documentation

◆ dump_assert()

static void dump_assert ( PLpgSQL_stmt_assert stmt)
static

Definition at line 1442 of file pl_funcs.c.

References PLpgSQL_stmt_assert::cond, dump_expr(), dump_ind(), dump_indent, and PLpgSQL_stmt_assert::message.

Referenced by dump_stmt().

1443 {
1444  dump_ind();
1445  printf("ASSERT ");
1446  dump_expr(stmt->cond);
1447  printf("\n");
1448 
1449  dump_indent += 2;
1450  if (stmt->message != NULL)
1451  {
1452  dump_ind();
1453  printf(" MESSAGE = ");
1454  dump_expr(stmt->message);
1455  printf("\n");
1456  }
1457  dump_indent -= 2;
1458 }
PLpgSQL_expr * message
Definition: plpgsql.h:825
static void dump_ind(void)
Definition: pl_funcs.c:814
static int dump_indent
Definition: pl_funcs.c:779
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1568
PLpgSQL_expr * cond
Definition: plpgsql.h:824

◆ dump_assign()

static void dump_assign ( PLpgSQL_stmt_assign stmt)
static

Definition at line 965 of file pl_funcs.c.

References dump_expr(), dump_ind(), PLpgSQL_stmt_assign::expr, and PLpgSQL_stmt_assign::varno.

Referenced by dump_stmt().

966 {
967  dump_ind();
968  printf("ASSIGN var %d := ", stmt->varno);
969  dump_expr(stmt->expr);
970  printf("\n");
971 }
static void dump_ind(void)
Definition: pl_funcs.c:814
PLpgSQL_expr * expr
Definition: plpgsql.h:498
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1568

◆ dump_block()

static void dump_block ( PLpgSQL_stmt_block block)
static

Definition at line 924 of file pl_funcs.c.

References PLpgSQL_exception::action, PLpgSQL_stmt_block::body, PLpgSQL_exception::conditions, PLpgSQL_condition::condname, dump_ind(), dump_stmts(), PLpgSQL_exception_block::exc_list, PLpgSQL_stmt_block::exceptions, PLpgSQL_stmt_block::label, lfirst, name, and PLpgSQL_condition::next.

Referenced by dump_stmt(), and plpgsql_dumptree().

925 {
926  char *name;
927 
928  if (block->label == NULL)
929  name = "*unnamed*";
930  else
931  name = block->label;
932 
933  dump_ind();
934  printf("BLOCK <<%s>>\n", name);
935 
936  dump_stmts(block->body);
937 
938  if (block->exceptions)
939  {
940  ListCell *e;
941 
942  foreach(e, block->exceptions->exc_list)
943  {
945  PLpgSQL_condition *cond;
946 
947  dump_ind();
948  printf(" EXCEPTION WHEN ");
949  for (cond = exc->conditions; cond; cond = cond->next)
950  {
951  if (cond != exc->conditions)
952  printf(" OR ");
953  printf("%s", cond->condname);
954  }
955  printf(" THEN\n");
956  dump_stmts(exc->action);
957  }
958  }
959 
960  dump_ind();
961  printf(" END -- %s\n", name);
962 }
char * condname
Definition: plpgsql.h:452
struct PLpgSQL_condition * next
Definition: plpgsql.h:453
static void dump_ind(void)
Definition: pl_funcs.c:814
PLpgSQL_condition * conditions
Definition: plpgsql.h:472
#define lfirst(lc)
Definition: pg_list.h:106
PLpgSQL_exception_block * exceptions
Definition: plpgsql.h:487
const char * name
Definition: encode.c:521
e
Definition: preproc-init.c:82
static void dump_stmts(List *stmts)
Definition: pl_funcs.c:913

◆ dump_case()

static void dump_case ( PLpgSQL_stmt_case stmt)
static

Definition at line 1004 of file pl_funcs.c.

References PLpgSQL_stmt_case::case_when_list, dump_expr(), dump_ind(), dump_indent, dump_stmts(), PLpgSQL_stmt_case::else_stmts, PLpgSQL_case_when::expr, PLpgSQL_stmt_case::have_else, lfirst, PLpgSQL_case_when::stmts, PLpgSQL_stmt_case::t_expr, and PLpgSQL_stmt_case::t_varno.

Referenced by dump_stmt().

1005 {
1006  ListCell *l;
1007 
1008  dump_ind();
1009  printf("CASE %d ", stmt->t_varno);
1010  if (stmt->t_expr)
1011  dump_expr(stmt->t_expr);
1012  printf("\n");
1013  dump_indent += 6;
1014  foreach(l, stmt->case_when_list)
1015  {
1017 
1018  dump_ind();
1019  printf("WHEN ");
1020  dump_expr(cwt->expr);
1021  printf("\n");
1022  dump_ind();
1023  printf("THEN\n");
1024  dump_indent += 2;
1025  dump_stmts(cwt->stmts);
1026  dump_indent -= 2;
1027  }
1028  if (stmt->have_else)
1029  {
1030  dump_ind();
1031  printf("ELSE\n");
1032  dump_indent += 2;
1033  dump_stmts(stmt->else_stmts);
1034  dump_indent -= 2;
1035  }
1036  dump_indent -= 6;
1037  dump_ind();
1038  printf(" ENDCASE\n");
1039 }
List * else_stmts
Definition: plpgsql.h:583
PLpgSQL_expr * expr
Definition: plpgsql.h:592
List * case_when_list
Definition: plpgsql.h:581
static void dump_ind(void)
Definition: pl_funcs.c:814
#define lfirst(lc)
Definition: pg_list.h:106
static int dump_indent
Definition: pl_funcs.c:779
PLpgSQL_expr * t_expr
Definition: plpgsql.h:579
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1568
static void dump_stmts(List *stmts)
Definition: pl_funcs.c:913

◆ dump_close()

static void dump_close ( PLpgSQL_stmt_close stmt)
static

Definition at line 1263 of file pl_funcs.c.

References PLpgSQL_stmt_close::curvar, and dump_ind().

Referenced by dump_stmt().

1264 {
1265  dump_ind();
1266  printf("CLOSE curvar=%d\n", stmt->curvar);
1267 }
static void dump_ind(void)
Definition: pl_funcs.c:814

◆ dump_commit()

static void dump_commit ( PLpgSQL_stmt_commit stmt)
static

Definition at line 1279 of file pl_funcs.c.

References dump_ind().

Referenced by dump_stmt().

1280 {
1281  dump_ind();
1282  printf("COMMIT\n");
1283 }
static void dump_ind(void)
Definition: pl_funcs.c:814

◆ dump_cursor_direction()

static void dump_cursor_direction ( PLpgSQL_stmt_fetch stmt)
static

Definition at line 1229 of file pl_funcs.c.

References PLpgSQL_stmt_fetch::direction, dump_expr(), dump_ind(), dump_indent, PLpgSQL_stmt_fetch::expr, FETCH_ABSOLUTE, FETCH_BACKWARD, FETCH_FORWARD, FETCH_RELATIVE, and PLpgSQL_stmt_fetch::how_many.

Referenced by dump_fetch().

1230 {
1231  dump_indent += 2;
1232  dump_ind();
1233  switch (stmt->direction)
1234  {
1235  case FETCH_FORWARD:
1236  printf(" FORWARD ");
1237  break;
1238  case FETCH_BACKWARD:
1239  printf(" BACKWARD ");
1240  break;
1241  case FETCH_ABSOLUTE:
1242  printf(" ABSOLUTE ");
1243  break;
1244  case FETCH_RELATIVE:
1245  printf(" RELATIVE ");
1246  break;
1247  default:
1248  printf("??? unknown cursor direction %d", stmt->direction);
1249  }
1250 
1251  if (stmt->expr)
1252  {
1253  dump_expr(stmt->expr);
1254  printf("\n");
1255  }
1256  else
1257  printf("%ld\n", stmt->how_many);
1258 
1259  dump_indent -= 2;
1260 }
FetchDirection direction
Definition: plpgsql.h:731
static void dump_ind(void)
Definition: pl_funcs.c:814
static int dump_indent
Definition: pl_funcs.c:779
PLpgSQL_expr * expr
Definition: plpgsql.h:733
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1568

◆ dump_dynexecute()

static void dump_dynexecute ( PLpgSQL_stmt_dynexecute stmt)
static

Definition at line 1480 of file pl_funcs.c.

References PLpgSQL_variable::dno, dump_expr(), dump_ind(), dump_indent, i, lfirst, NIL, PLpgSQL_stmt_dynexecute::params, PLpgSQL_stmt_dynexecute::query, PLpgSQL_variable::refname, PLpgSQL_stmt_dynexecute::strict, and PLpgSQL_stmt_dynexecute::target.

Referenced by dump_stmt().

1481 {
1482  dump_ind();
1483  printf("EXECUTE ");
1484  dump_expr(stmt->query);
1485  printf("\n");
1486 
1487  dump_indent += 2;
1488  if (stmt->target != NULL)
1489  {
1490  dump_ind();
1491  printf(" INTO%s target = %d %s\n",
1492  stmt->strict ? " STRICT" : "",
1493  stmt->target->dno, stmt->target->refname);
1494  }
1495  if (stmt->params != NIL)
1496  {
1497  ListCell *lc;
1498  int i;
1499 
1500  dump_ind();
1501  printf(" USING\n");
1502  dump_indent += 2;
1503  i = 1;
1504  foreach(lc, stmt->params)
1505  {
1506  dump_ind();
1507  printf(" parameter %d: ", i++);
1508  dump_expr((PLpgSQL_expr *) lfirst(lc));
1509  printf("\n");
1510  }
1511  dump_indent -= 2;
1512  }
1513  dump_indent -= 2;
1514 }
#define NIL
Definition: pg_list.h:69
PLpgSQL_expr * query
Definition: plpgsql.h:850
static void dump_ind(void)
Definition: pl_funcs.c:814
#define lfirst(lc)
Definition: pg_list.h:106
static int dump_indent
Definition: pl_funcs.c:779
char * refname
Definition: plpgsql.h:265
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1568
int i
PLpgSQL_variable * target
Definition: plpgsql.h:853

◆ dump_dynfors()

static void dump_dynfors ( PLpgSQL_stmt_dynfors stmt)
static

Definition at line 1517 of file pl_funcs.c.

References PLpgSQL_stmt_dynfors::body, dump_expr(), dump_ind(), dump_indent, dump_stmts(), i, lfirst, NIL, PLpgSQL_stmt_dynfors::params, PLpgSQL_stmt_dynfors::query, PLpgSQL_variable::refname, and PLpgSQL_stmt_dynfors::var.

Referenced by dump_stmt().

1518 {
1519  dump_ind();
1520  printf("FORS %s EXECUTE ", stmt->var->refname);
1521  dump_expr(stmt->query);
1522  printf("\n");
1523  if (stmt->params != NIL)
1524  {
1525  ListCell *lc;
1526  int i;
1527 
1528  dump_indent += 2;
1529  dump_ind();
1530  printf(" USING\n");
1531  dump_indent += 2;
1532  i = 1;
1533  foreach(lc, stmt->params)
1534  {
1535  dump_ind();
1536  printf(" parameter $%d: ", i++);
1537  dump_expr((PLpgSQL_expr *) lfirst(lc));
1538  printf("\n");
1539  }
1540  dump_indent -= 4;
1541  }
1542  dump_stmts(stmt->body);
1543  dump_ind();
1544  printf(" ENDFORS\n");
1545 }
#define NIL
Definition: pg_list.h:69
PLpgSQL_expr * query
Definition: plpgsql.h:689
static void dump_ind(void)
Definition: pl_funcs.c:814
PLpgSQL_variable * var
Definition: plpgsql.h:686
#define lfirst(lc)
Definition: pg_list.h:106
static int dump_indent
Definition: pl_funcs.c:779
char * refname
Definition: plpgsql.h:265
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1568
int i
static void dump_stmts(List *stmts)
Definition: pl_funcs.c:913

◆ dump_execsql()

static void dump_execsql ( PLpgSQL_stmt_execsql stmt)
static

Definition at line 1461 of file pl_funcs.c.

References PLpgSQL_variable::dno, dump_expr(), dump_ind(), dump_indent, PLpgSQL_variable::refname, PLpgSQL_stmt_execsql::sqlstmt, PLpgSQL_stmt_execsql::strict, and PLpgSQL_stmt_execsql::target.

Referenced by dump_stmt().

1462 {
1463  dump_ind();
1464  printf("EXECSQL ");
1465  dump_expr(stmt->sqlstmt);
1466  printf("\n");
1467 
1468  dump_indent += 2;
1469  if (stmt->target != NULL)
1470  {
1471  dump_ind();
1472  printf(" INTO%s target = %d %s\n",
1473  stmt->strict ? " STRICT" : "",
1474  stmt->target->dno, stmt->target->refname);
1475  }
1476  dump_indent -= 2;
1477 }
PLpgSQL_expr * sqlstmt
Definition: plpgsql.h:835
PLpgSQL_variable * target
Definition: plpgsql.h:840
static void dump_ind(void)
Definition: pl_funcs.c:814
static int dump_indent
Definition: pl_funcs.c:779
char * refname
Definition: plpgsql.h:265
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1568

◆ dump_exit()

static void dump_exit ( PLpgSQL_stmt_exit stmt)
static

Definition at line 1293 of file pl_funcs.c.

References PLpgSQL_stmt_exit::cond, dump_expr(), dump_ind(), PLpgSQL_stmt_exit::is_exit, and PLpgSQL_stmt_exit::label.

Referenced by dump_stmt().

1294 {
1295  dump_ind();
1296  printf("%s", stmt->is_exit ? "EXIT" : "CONTINUE");
1297  if (stmt->label != NULL)
1298  printf(" label='%s'", stmt->label);
1299  if (stmt->cond != NULL)
1300  {
1301  printf(" WHEN ");
1302  dump_expr(stmt->cond);
1303  }
1304  printf("\n");
1305 }
PLpgSQL_expr * cond
Definition: plpgsql.h:757
static void dump_ind(void)
Definition: pl_funcs.c:814
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1568

◆ dump_expr()

◆ dump_fetch()

static void dump_fetch ( PLpgSQL_stmt_fetch stmt)
static

Definition at line 1203 of file pl_funcs.c.

References PLpgSQL_stmt_fetch::curvar, PLpgSQL_variable::dno, dump_cursor_direction(), dump_ind(), dump_indent, PLpgSQL_stmt_fetch::is_move, PLpgSQL_variable::refname, and PLpgSQL_stmt_fetch::target.

Referenced by dump_stmt().

1204 {
1205  dump_ind();
1206 
1207  if (!stmt->is_move)
1208  {
1209  printf("FETCH curvar=%d\n", stmt->curvar);
1210  dump_cursor_direction(stmt);
1211 
1212  dump_indent += 2;
1213  if (stmt->target != NULL)
1214  {
1215  dump_ind();
1216  printf(" target = %d %s\n",
1217  stmt->target->dno, stmt->target->refname);
1218  }
1219  dump_indent -= 2;
1220  }
1221  else
1222  {
1223  printf("MOVE curvar=%d\n", stmt->curvar);
1224  dump_cursor_direction(stmt);
1225  }
1226 }
static void dump_cursor_direction(PLpgSQL_stmt_fetch *stmt)
Definition: pl_funcs.c:1229
static void dump_ind(void)
Definition: pl_funcs.c:814
static int dump_indent
Definition: pl_funcs.c:779
char * refname
Definition: plpgsql.h:265
PLpgSQL_variable * target
Definition: plpgsql.h:729

◆ dump_forc()

static void dump_forc ( PLpgSQL_stmt_forc stmt)
static

Definition at line 1112 of file pl_funcs.c.

References PLpgSQL_stmt_forc::argquery, PLpgSQL_stmt_forc::body, PLpgSQL_stmt_forc::curvar, dump_expr(), dump_ind(), dump_indent, dump_stmts(), PLpgSQL_variable::refname, and PLpgSQL_stmt_forc::var.

Referenced by dump_stmt().

1113 {
1114  dump_ind();
1115  printf("FORC %s ", stmt->var->refname);
1116  printf("curvar=%d\n", stmt->curvar);
1117 
1118  dump_indent += 2;
1119  if (stmt->argquery != NULL)
1120  {
1121  dump_ind();
1122  printf(" arguments = ");
1123  dump_expr(stmt->argquery);
1124  printf("\n");
1125  }
1126  dump_indent -= 2;
1127 
1128  dump_stmts(stmt->body);
1129 
1130  dump_ind();
1131  printf(" ENDFORC\n");
1132 }
PLpgSQL_variable * var
Definition: plpgsql.h:671
static void dump_ind(void)
Definition: pl_funcs.c:814
static int dump_indent
Definition: pl_funcs.c:779
char * refname
Definition: plpgsql.h:265
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1568
PLpgSQL_expr * argquery
Definition: plpgsql.h:675
static void dump_stmts(List *stmts)
Definition: pl_funcs.c:913

◆ dump_foreach_a()

static void dump_foreach_a ( PLpgSQL_stmt_foreach_a stmt)
static

Definition at line 1135 of file pl_funcs.c.

References PLpgSQL_stmt_foreach_a::body, dump_expr(), dump_ind(), dump_stmts(), PLpgSQL_stmt_foreach_a::expr, PLpgSQL_stmt_foreach_a::slice, and PLpgSQL_stmt_foreach_a::varno.

Referenced by dump_stmt().

1136 {
1137  dump_ind();
1138  printf("FOREACHA var %d ", stmt->varno);
1139  if (stmt->slice != 0)
1140  printf("SLICE %d ", stmt->slice);
1141  printf("IN ");
1142  dump_expr(stmt->expr);
1143  printf("\n");
1144 
1145  dump_stmts(stmt->body);
1146 
1147  dump_ind();
1148  printf(" ENDFOREACHA");
1149 }
PLpgSQL_expr * expr
Definition: plpgsql.h:703
static void dump_ind(void)
Definition: pl_funcs.c:814
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1568
static void dump_stmts(List *stmts)
Definition: pl_funcs.c:913

◆ dump_fori()

static void dump_fori ( PLpgSQL_stmt_fori stmt)
static

Definition at line 1068 of file pl_funcs.c.

References PLpgSQL_stmt_fori::body, dump_expr(), dump_ind(), dump_indent, dump_stmts(), PLpgSQL_stmt_fori::lower, PLpgSQL_var::refname, PLpgSQL_stmt_fori::reverse, PLpgSQL_stmt_fori::step, PLpgSQL_stmt_fori::upper, and PLpgSQL_stmt_fori::var.

Referenced by dump_stmt().

1069 {
1070  dump_ind();
1071  printf("FORI %s %s\n", stmt->var->refname, (stmt->reverse) ? "REVERSE" : "NORMAL");
1072 
1073  dump_indent += 2;
1074  dump_ind();
1075  printf(" lower = ");
1076  dump_expr(stmt->lower);
1077  printf("\n");
1078  dump_ind();
1079  printf(" upper = ");
1080  dump_expr(stmt->upper);
1081  printf("\n");
1082  if (stmt->step)
1083  {
1084  dump_ind();
1085  printf(" step = ");
1086  dump_expr(stmt->step);
1087  printf("\n");
1088  }
1089  dump_indent -= 2;
1090 
1091  dump_stmts(stmt->body);
1092 
1093  dump_ind();
1094  printf(" ENDFORI\n");
1095 }
char * refname
Definition: plpgsql.h:287
PLpgSQL_expr * lower
Definition: plpgsql.h:628
PLpgSQL_var * var
Definition: plpgsql.h:627
static void dump_ind(void)
Definition: pl_funcs.c:814
static int dump_indent
Definition: pl_funcs.c:779
PLpgSQL_expr * step
Definition: plpgsql.h:630
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1568
PLpgSQL_expr * upper
Definition: plpgsql.h:629
static void dump_stmts(List *stmts)
Definition: pl_funcs.c:913

◆ dump_fors()

static void dump_fors ( PLpgSQL_stmt_fors stmt)
static

Definition at line 1098 of file pl_funcs.c.

References PLpgSQL_stmt_fors::body, dump_expr(), dump_ind(), dump_stmts(), PLpgSQL_stmt_fors::query, PLpgSQL_variable::refname, and PLpgSQL_stmt_fors::var.

Referenced by dump_stmt().

1099 {
1100  dump_ind();
1101  printf("FORS %s ", stmt->var->refname);
1102  dump_expr(stmt->query);
1103  printf("\n");
1104 
1105  dump_stmts(stmt->body);
1106 
1107  dump_ind();
1108  printf(" ENDFORS\n");
1109 }
PLpgSQL_variable * var
Definition: plpgsql.h:657
static void dump_ind(void)
Definition: pl_funcs.c:814
char * refname
Definition: plpgsql.h:265
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1568
PLpgSQL_expr * query
Definition: plpgsql.h:660
static void dump_stmts(List *stmts)
Definition: pl_funcs.c:913

◆ dump_getdiag()

static void dump_getdiag ( PLpgSQL_stmt_getdiag stmt)
static

Definition at line 1548 of file pl_funcs.c.

References PLpgSQL_stmt_getdiag::diag_items, dump_ind(), PLpgSQL_stmt_getdiag::is_stacked, PLpgSQL_diag_item::kind, lfirst, list_head(), plpgsql_getdiag_kindname(), and PLpgSQL_diag_item::target.

Referenced by dump_stmt().

1549 {
1550  ListCell *lc;
1551 
1552  dump_ind();
1553  printf("GET %s DIAGNOSTICS ", stmt->is_stacked ? "STACKED" : "CURRENT");
1554  foreach(lc, stmt->diag_items)
1555  {
1556  PLpgSQL_diag_item *diag_item = (PLpgSQL_diag_item *) lfirst(lc);
1557 
1558  if (lc != list_head(stmt->diag_items))
1559  printf(", ");
1560 
1561  printf("{var %d} = %s", diag_item->target,
1562  plpgsql_getdiag_kindname(diag_item->kind));
1563  }
1564  printf("\n");
1565 }
PLpgSQL_getdiag_kind kind
Definition: plpgsql.h:534
static ListCell * list_head(const List *l)
Definition: pg_list.h:77
static void dump_ind(void)
Definition: pl_funcs.c:814
#define lfirst(lc)
Definition: pg_list.h:106
const char * plpgsql_getdiag_kindname(PLpgSQL_getdiag_kind kind)
Definition: pl_funcs.c:300

◆ dump_if()

static void dump_if ( PLpgSQL_stmt_if stmt)
static

Definition at line 974 of file pl_funcs.c.

References PLpgSQL_stmt_if::cond, PLpgSQL_if_elsif::cond, dump_expr(), dump_ind(), dump_stmts(), PLpgSQL_stmt_if::else_body, PLpgSQL_stmt_if::elsif_list, lfirst, NIL, PLpgSQL_if_elsif::stmts, and PLpgSQL_stmt_if::then_body.

Referenced by dump_stmt().

975 {
976  ListCell *l;
977 
978  dump_ind();
979  printf("IF ");
980  dump_expr(stmt->cond);
981  printf(" THEN\n");
982  dump_stmts(stmt->then_body);
983  foreach(l, stmt->elsif_list)
984  {
986 
987  dump_ind();
988  printf(" ELSIF ");
989  dump_expr(elif->cond);
990  printf(" THEN\n");
991  dump_stmts(elif->stmts);
992  }
993  if (stmt->else_body != NIL)
994  {
995  dump_ind();
996  printf(" ELSE\n");
997  dump_stmts(stmt->else_body);
998  }
999  dump_ind();
1000  printf(" ENDIF\n");
1001 }
#define NIL
Definition: pg_list.h:69
PLpgSQL_expr * cond
Definition: plpgsql.h:556
List * then_body
Definition: plpgsql.h:557
List * elsif_list
Definition: plpgsql.h:558
List * stmts
Definition: plpgsql.h:569
PLpgSQL_expr * cond
Definition: plpgsql.h:568
static void dump_ind(void)
Definition: pl_funcs.c:814
#define lfirst(lc)
Definition: pg_list.h:106
List * else_body
Definition: plpgsql.h:559
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1568
static void dump_stmts(List *stmts)
Definition: pl_funcs.c:913

◆ dump_ind()

◆ dump_loop()

static void dump_loop ( PLpgSQL_stmt_loop stmt)
static

Definition at line 1042 of file pl_funcs.c.

References PLpgSQL_stmt_loop::body, dump_ind(), and dump_stmts().

Referenced by dump_stmt().

1043 {
1044  dump_ind();
1045  printf("LOOP\n");
1046 
1047  dump_stmts(stmt->body);
1048 
1049  dump_ind();
1050  printf(" ENDLOOP\n");
1051 }
static void dump_ind(void)
Definition: pl_funcs.c:814
static void dump_stmts(List *stmts)
Definition: pl_funcs.c:913

◆ dump_open()

static void dump_open ( PLpgSQL_stmt_open stmt)
static

Definition at line 1152 of file pl_funcs.c.

References PLpgSQL_stmt_open::argquery, PLpgSQL_stmt_open::curvar, dump_expr(), dump_ind(), dump_indent, PLpgSQL_stmt_open::dynquery, i, lfirst, NIL, PLpgSQL_stmt_open::params, and PLpgSQL_stmt_open::query.

Referenced by dump_stmt().

1153 {
1154  dump_ind();
1155  printf("OPEN curvar=%d\n", stmt->curvar);
1156 
1157  dump_indent += 2;
1158  if (stmt->argquery != NULL)
1159  {
1160  dump_ind();
1161  printf(" arguments = '");
1162  dump_expr(stmt->argquery);
1163  printf("'\n");
1164  }
1165  if (stmt->query != NULL)
1166  {
1167  dump_ind();
1168  printf(" query = '");
1169  dump_expr(stmt->query);
1170  printf("'\n");
1171  }
1172  if (stmt->dynquery != NULL)
1173  {
1174  dump_ind();
1175  printf(" execute = '");
1176  dump_expr(stmt->dynquery);
1177  printf("'\n");
1178 
1179  if (stmt->params != NIL)
1180  {
1181  ListCell *lc;
1182  int i;
1183 
1184  dump_indent += 2;
1185  dump_ind();
1186  printf(" USING\n");
1187  dump_indent += 2;
1188  i = 1;
1189  foreach(lc, stmt->params)
1190  {
1191  dump_ind();
1192  printf(" parameter $%d: ", i++);
1193  dump_expr((PLpgSQL_expr *) lfirst(lc));
1194  printf("\n");
1195  }
1196  dump_indent -= 4;
1197  }
1198  }
1199  dump_indent -= 2;
1200 }
#define NIL
Definition: pg_list.h:69
PLpgSQL_expr * dynquery
Definition: plpgsql.h:718
PLpgSQL_expr * query
Definition: plpgsql.h:717
static void dump_ind(void)
Definition: pl_funcs.c:814
#define lfirst(lc)
Definition: pg_list.h:106
static int dump_indent
Definition: pl_funcs.c:779
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1568
PLpgSQL_expr * argquery
Definition: plpgsql.h:716
int i

◆ dump_perform()

static void dump_perform ( PLpgSQL_stmt_perform stmt)
static

Definition at line 1270 of file pl_funcs.c.

References dump_expr(), dump_ind(), and PLpgSQL_stmt_perform::expr.

Referenced by dump_stmt().

1271 {
1272  dump_ind();
1273  printf("PERFORM expr = ");
1274  dump_expr(stmt->expr);
1275  printf("\n");
1276 }
PLpgSQL_expr * expr
Definition: plpgsql.h:508
static void dump_ind(void)
Definition: pl_funcs.c:814
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1568

◆ dump_raise()

static void dump_raise ( PLpgSQL_stmt_raise stmt)
static

Definition at line 1373 of file pl_funcs.c.

References PLpgSQL_stmt_raise::condname, dump_expr(), dump_ind(), dump_indent, PLpgSQL_stmt_raise::elog_level, PLpgSQL_raise_option::expr, i, lfirst, PLpgSQL_stmt_raise::message, PLpgSQL_raise_option::opt_type, PLpgSQL_stmt_raise::options, PLpgSQL_stmt_raise::params, PLPGSQL_RAISEOPTION_COLUMN, PLPGSQL_RAISEOPTION_CONSTRAINT, PLPGSQL_RAISEOPTION_DATATYPE, PLPGSQL_RAISEOPTION_DETAIL, PLPGSQL_RAISEOPTION_ERRCODE, PLPGSQL_RAISEOPTION_HINT, PLPGSQL_RAISEOPTION_MESSAGE, PLPGSQL_RAISEOPTION_SCHEMA, and PLPGSQL_RAISEOPTION_TABLE.

Referenced by dump_stmt().

1374 {
1375  ListCell *lc;
1376  int i = 0;
1377 
1378  dump_ind();
1379  printf("RAISE level=%d", stmt->elog_level);
1380  if (stmt->condname)
1381  printf(" condname='%s'", stmt->condname);
1382  if (stmt->message)
1383  printf(" message='%s'", stmt->message);
1384  printf("\n");
1385  dump_indent += 2;
1386  foreach(lc, stmt->params)
1387  {
1388  dump_ind();
1389  printf(" parameter %d: ", i++);
1390  dump_expr((PLpgSQL_expr *) lfirst(lc));
1391  printf("\n");
1392  }
1393  if (stmt->options)
1394  {
1395  dump_ind();
1396  printf(" USING\n");
1397  dump_indent += 2;
1398  foreach(lc, stmt->options)
1399  {
1401 
1402  dump_ind();
1403  switch (opt->opt_type)
1404  {
1406  printf(" ERRCODE = ");
1407  break;
1409  printf(" MESSAGE = ");
1410  break;
1412  printf(" DETAIL = ");
1413  break;
1415  printf(" HINT = ");
1416  break;
1418  printf(" COLUMN = ");
1419  break;
1421  printf(" CONSTRAINT = ");
1422  break;
1424  printf(" DATATYPE = ");
1425  break;
1427  printf(" TABLE = ");
1428  break;
1430  printf(" SCHEMA = ");
1431  break;
1432  }
1433  dump_expr(opt->expr);
1434  printf("\n");
1435  }
1436  dump_indent -= 2;
1437  }
1438  dump_indent -= 2;
1439 }
PLpgSQL_raise_option_type opt_type
Definition: plpgsql.h:813
static void dump_ind(void)
Definition: pl_funcs.c:814
#define lfirst(lc)
Definition: pg_list.h:106
static int dump_indent
Definition: pl_funcs.c:779
PLpgSQL_expr * expr
Definition: plpgsql.h:814
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1568
int i

◆ dump_return()

static void dump_return ( PLpgSQL_stmt_return stmt)
static

Definition at line 1308 of file pl_funcs.c.

References dump_expr(), dump_ind(), PLpgSQL_stmt_return::expr, and PLpgSQL_stmt_return::retvarno.

Referenced by dump_stmt().

1309 {
1310  dump_ind();
1311  printf("RETURN ");
1312  if (stmt->retvarno >= 0)
1313  printf("variable %d", stmt->retvarno);
1314  else if (stmt->expr != NULL)
1315  dump_expr(stmt->expr);
1316  else
1317  printf("NULL");
1318  printf("\n");
1319 }
PLpgSQL_expr * expr
Definition: plpgsql.h:767
static void dump_ind(void)
Definition: pl_funcs.c:814
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1568

◆ dump_return_next()

static void dump_return_next ( PLpgSQL_stmt_return_next stmt)
static

Definition at line 1322 of file pl_funcs.c.

References dump_expr(), dump_ind(), PLpgSQL_stmt_return_next::expr, and PLpgSQL_stmt_return_next::retvarno.

Referenced by dump_stmt().

1323 {
1324  dump_ind();
1325  printf("RETURN NEXT ");
1326  if (stmt->retvarno >= 0)
1327  printf("variable %d", stmt->retvarno);
1328  else if (stmt->expr != NULL)
1329  dump_expr(stmt->expr);
1330  else
1331  printf("NULL");
1332  printf("\n");
1333 }
PLpgSQL_expr * expr
Definition: plpgsql.h:778
static void dump_ind(void)
Definition: pl_funcs.c:814
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1568

◆ dump_return_query()

static void dump_return_query ( PLpgSQL_stmt_return_query stmt)
static

Definition at line 1336 of file pl_funcs.c.

References dump_expr(), dump_ind(), dump_indent, PLpgSQL_stmt_return_query::dynquery, i, lfirst, NIL, PLpgSQL_stmt_return_query::params, and PLpgSQL_stmt_return_query::query.

Referenced by dump_stmt().

1337 {
1338  dump_ind();
1339  if (stmt->query)
1340  {
1341  printf("RETURN QUERY ");
1342  dump_expr(stmt->query);
1343  printf("\n");
1344  }
1345  else
1346  {
1347  printf("RETURN QUERY EXECUTE ");
1348  dump_expr(stmt->dynquery);
1349  printf("\n");
1350  if (stmt->params != NIL)
1351  {
1352  ListCell *lc;
1353  int i;
1354 
1355  dump_indent += 2;
1356  dump_ind();
1357  printf(" USING\n");
1358  dump_indent += 2;
1359  i = 1;
1360  foreach(lc, stmt->params)
1361  {
1362  dump_ind();
1363  printf(" parameter $%d: ", i++);
1364  dump_expr((PLpgSQL_expr *) lfirst(lc));
1365  printf("\n");
1366  }
1367  dump_indent -= 4;
1368  }
1369  }
1370 }
#define NIL
Definition: pg_list.h:69
PLpgSQL_expr * query
Definition: plpgsql.h:789
static void dump_ind(void)
Definition: pl_funcs.c:814
#define lfirst(lc)
Definition: pg_list.h:106
static int dump_indent
Definition: pl_funcs.c:779
PLpgSQL_expr * dynquery
Definition: plpgsql.h:790
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1568
int i

◆ dump_rollback()

static void dump_rollback ( PLpgSQL_stmt_rollback stmt)
static

Definition at line 1286 of file pl_funcs.c.

References dump_ind().

Referenced by dump_stmt().

1287 {
1288  dump_ind();
1289  printf("ROLLBACK\n");
1290 }
static void dump_ind(void)
Definition: pl_funcs.c:814

◆ dump_stmt()

static void dump_stmt ( PLpgSQL_stmt stmt)
static

Definition at line 823 of file pl_funcs.c.

References PLpgSQL_stmt::cmd_type, PLpgSQL_stmt_rollback::cmd_type, dump_assert(), dump_assign(), dump_block(), dump_case(), dump_close(), dump_commit(), dump_dynexecute(), dump_dynfors(), dump_execsql(), dump_exit(), dump_fetch(), dump_forc(), dump_foreach_a(), dump_fori(), dump_fors(), dump_getdiag(), dump_if(), dump_loop(), dump_open(), dump_perform(), dump_raise(), dump_return(), dump_return_next(), dump_return_query(), dump_rollback(), dump_while(), elog, ERROR, PLpgSQL_stmt::lineno, PLPGSQL_STMT_ASSERT, PLPGSQL_STMT_ASSIGN, PLPGSQL_STMT_BLOCK, PLPGSQL_STMT_CASE, PLPGSQL_STMT_CLOSE, PLPGSQL_STMT_COMMIT, PLPGSQL_STMT_DYNEXECUTE, PLPGSQL_STMT_DYNFORS, PLPGSQL_STMT_EXECSQL, PLPGSQL_STMT_EXIT, PLPGSQL_STMT_FETCH, PLPGSQL_STMT_FORC, PLPGSQL_STMT_FOREACH_A, PLPGSQL_STMT_FORI, PLPGSQL_STMT_FORS, PLPGSQL_STMT_GETDIAG, PLPGSQL_STMT_IF, PLPGSQL_STMT_LOOP, PLPGSQL_STMT_OPEN, PLPGSQL_STMT_PERFORM, PLPGSQL_STMT_RAISE, PLPGSQL_STMT_RETURN, PLPGSQL_STMT_RETURN_NEXT, PLPGSQL_STMT_RETURN_QUERY, PLPGSQL_STMT_ROLLBACK, and PLPGSQL_STMT_WHILE.

Referenced by dump_stmts().

824 {
825  printf("%3d:", stmt->lineno);
826  switch (stmt->cmd_type)
827  {
828  case PLPGSQL_STMT_BLOCK:
829  dump_block((PLpgSQL_stmt_block *) stmt);
830  break;
831  case PLPGSQL_STMT_ASSIGN:
833  break;
834  case PLPGSQL_STMT_IF:
835  dump_if((PLpgSQL_stmt_if *) stmt);
836  break;
837  case PLPGSQL_STMT_CASE:
838  dump_case((PLpgSQL_stmt_case *) stmt);
839  break;
840  case PLPGSQL_STMT_LOOP:
841  dump_loop((PLpgSQL_stmt_loop *) stmt);
842  break;
843  case PLPGSQL_STMT_WHILE:
844  dump_while((PLpgSQL_stmt_while *) stmt);
845  break;
846  case PLPGSQL_STMT_FORI:
847  dump_fori((PLpgSQL_stmt_fori *) stmt);
848  break;
849  case PLPGSQL_STMT_FORS:
850  dump_fors((PLpgSQL_stmt_fors *) stmt);
851  break;
852  case PLPGSQL_STMT_FORC:
853  dump_forc((PLpgSQL_stmt_forc *) stmt);
854  break;
857  break;
858  case PLPGSQL_STMT_EXIT:
859  dump_exit((PLpgSQL_stmt_exit *) stmt);
860  break;
861  case PLPGSQL_STMT_RETURN:
863  break;
866  break;
869  break;
870  case PLPGSQL_STMT_RAISE:
871  dump_raise((PLpgSQL_stmt_raise *) stmt);
872  break;
873  case PLPGSQL_STMT_ASSERT:
875  break;
878  break;
881  break;
884  break;
887  break;
888  case PLPGSQL_STMT_OPEN:
889  dump_open((PLpgSQL_stmt_open *) stmt);
890  break;
891  case PLPGSQL_STMT_FETCH:
892  dump_fetch((PLpgSQL_stmt_fetch *) stmt);
893  break;
894  case PLPGSQL_STMT_CLOSE:
895  dump_close((PLpgSQL_stmt_close *) stmt);
896  break;
899  break;
900  case PLPGSQL_STMT_COMMIT:
902  break;
905  break;
906  default:
907  elog(ERROR, "unrecognized cmd_type: %d", stmt->cmd_type);
908  break;
909  }
910 }
int lineno
Definition: plpgsql.h:443
static void dump_raise(PLpgSQL_stmt_raise *stmt)
Definition: pl_funcs.c:1373
static void dump_perform(PLpgSQL_stmt_perform *stmt)
Definition: pl_funcs.c:1270
static void dump_forc(PLpgSQL_stmt_forc *stmt)
Definition: pl_funcs.c:1112
static void dump_rollback(PLpgSQL_stmt_rollback *stmt)
Definition: pl_funcs.c:1286
static void dump_fors(PLpgSQL_stmt_fors *stmt)
Definition: pl_funcs.c:1098
static void dump_fetch(PLpgSQL_stmt_fetch *stmt)
Definition: pl_funcs.c:1203
#define ERROR
Definition: elog.h:43
static void dump_case(PLpgSQL_stmt_case *stmt)
Definition: pl_funcs.c:1004
static void dump_getdiag(PLpgSQL_stmt_getdiag *stmt)
Definition: pl_funcs.c:1548
static void dump_if(PLpgSQL_stmt_if *stmt)
Definition: pl_funcs.c:974
static void dump_return_query(PLpgSQL_stmt_return_query *stmt)
Definition: pl_funcs.c:1336
static void dump_return(PLpgSQL_stmt_return *stmt)
Definition: pl_funcs.c:1308
static void dump_return_next(PLpgSQL_stmt_return_next *stmt)
Definition: pl_funcs.c:1322
static void dump_loop(PLpgSQL_stmt_loop *stmt)
Definition: pl_funcs.c:1042
static void dump_close(PLpgSQL_stmt_close *stmt)
Definition: pl_funcs.c:1263
static void dump_while(PLpgSQL_stmt_while *stmt)
Definition: pl_funcs.c:1054
static void dump_execsql(PLpgSQL_stmt_execsql *stmt)
Definition: pl_funcs.c:1461
static void dump_dynexecute(PLpgSQL_stmt_dynexecute *stmt)
Definition: pl_funcs.c:1480
static void dump_dynfors(PLpgSQL_stmt_dynfors *stmt)
Definition: pl_funcs.c:1517
static void dump_block(PLpgSQL_stmt_block *block)
Definition: pl_funcs.c:924
static void dump_foreach_a(PLpgSQL_stmt_foreach_a *stmt)
Definition: pl_funcs.c:1135
static void dump_commit(PLpgSQL_stmt_commit *stmt)
Definition: pl_funcs.c:1279
static void dump_assert(PLpgSQL_stmt_assert *stmt)
Definition: pl_funcs.c:1442
static void dump_open(PLpgSQL_stmt_open *stmt)
Definition: pl_funcs.c:1152
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:442
static void dump_fori(PLpgSQL_stmt_fori *stmt)
Definition: pl_funcs.c:1068
#define elog
Definition: elog.h:219
static void dump_assign(PLpgSQL_stmt_assign *stmt)
Definition: pl_funcs.c:965
static void dump_exit(PLpgSQL_stmt_exit *stmt)
Definition: pl_funcs.c:1293

◆ dump_stmts()

static void dump_stmts ( List stmts)
static

Definition at line 913 of file pl_funcs.c.

References dump_indent, dump_stmt(), and lfirst.

Referenced by dump_block(), dump_case(), dump_dynfors(), dump_forc(), dump_foreach_a(), dump_fori(), dump_fors(), dump_if(), dump_loop(), and dump_while().

914 {
915  ListCell *s;
916 
917  dump_indent += 2;
918  foreach(s, stmts)
919  dump_stmt((PLpgSQL_stmt *) lfirst(s));
920  dump_indent -= 2;
921 }
#define lfirst(lc)
Definition: pg_list.h:106
static int dump_indent
Definition: pl_funcs.c:779
static void dump_stmt(PLpgSQL_stmt *stmt)
Definition: pl_funcs.c:823

◆ dump_while()

static void dump_while ( PLpgSQL_stmt_while stmt)
static

Definition at line 1054 of file pl_funcs.c.

References PLpgSQL_stmt_while::body, PLpgSQL_stmt_while::cond, dump_expr(), dump_ind(), and dump_stmts().

Referenced by dump_stmt().

1055 {
1056  dump_ind();
1057  printf("WHILE ");
1058  dump_expr(stmt->cond);
1059  printf("\n");
1060 
1061  dump_stmts(stmt->body);
1062 
1063  dump_ind();
1064  printf(" ENDWHILE\n");
1065 }
PLpgSQL_expr * cond
Definition: plpgsql.h:615
static void dump_ind(void)
Definition: pl_funcs.c:814
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1568
static void dump_stmts(List *stmts)
Definition: pl_funcs.c:913

◆ free_assert()

static void free_assert ( PLpgSQL_stmt_assert stmt)
static

Definition at line 664 of file pl_funcs.c.

References PLpgSQL_stmt_assert::cond, free_expr(), and PLpgSQL_stmt_assert::message.

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

665 {
666  free_expr(stmt->cond);
667  free_expr(stmt->message);
668 }
PLpgSQL_expr * message
Definition: plpgsql.h:825
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:707
PLpgSQL_expr * cond
Definition: plpgsql.h:824

◆ free_assign()

static void free_assign ( PLpgSQL_stmt_assign stmt)
static

Definition at line 493 of file pl_funcs.c.

References PLpgSQL_stmt_assign::expr, and free_expr().

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

494 {
495  free_expr(stmt->expr);
496 }
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:707
PLpgSQL_expr * expr
Definition: plpgsql.h:498

◆ free_block()

static void free_block ( PLpgSQL_stmt_block block)
static

Definition at line 476 of file pl_funcs.c.

References PLpgSQL_exception::action, PLpgSQL_stmt_block::body, PLpgSQL_exception_block::exc_list, PLpgSQL_stmt_block::exceptions, free_stmts(), and lfirst.

Referenced by free_stmt(), plpgsql_free_function_memory(), and plpgsql_getdiag_kindname().

477 {
478  free_stmts(block->body);
479  if (block->exceptions)
480  {
481  ListCell *e;
482 
483  foreach(e, block->exceptions->exc_list)
484  {
486 
487  free_stmts(exc->action);
488  }
489  }
490 }
static void free_stmts(List *stmts)
Definition: pl_funcs.c:465
#define lfirst(lc)
Definition: pg_list.h:106
PLpgSQL_exception_block * exceptions
Definition: plpgsql.h:487
e
Definition: preproc-init.c:82

◆ free_case()

static void free_case ( PLpgSQL_stmt_case stmt)
static

Definition at line 516 of file pl_funcs.c.

References PLpgSQL_stmt_case::case_when_list, PLpgSQL_stmt_case::else_stmts, PLpgSQL_case_when::expr, free_expr(), free_stmts(), lfirst, PLpgSQL_case_when::stmts, and PLpgSQL_stmt_case::t_expr.

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

517 {
518  ListCell *l;
519 
520  free_expr(stmt->t_expr);
521  foreach(l, stmt->case_when_list)
522  {
524 
525  free_expr(cwt->expr);
526  free_stmts(cwt->stmts);
527  }
528  free_stmts(stmt->else_stmts);
529 }
List * else_stmts
Definition: plpgsql.h:583
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:707
PLpgSQL_expr * expr
Definition: plpgsql.h:592
List * case_when_list
Definition: plpgsql.h:581
static void free_stmts(List *stmts)
Definition: pl_funcs.c:465
#define lfirst(lc)
Definition: pg_list.h:106
PLpgSQL_expr * t_expr
Definition: plpgsql.h:579

◆ free_close()

static void free_close ( PLpgSQL_stmt_close stmt)
static

Definition at line 595 of file pl_funcs.c.

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

596 {
597 }

◆ free_commit()

static void free_commit ( PLpgSQL_stmt_commit stmt)
static

Definition at line 606 of file pl_funcs.c.

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

607 {
608 }

◆ free_dynexecute()

static void free_dynexecute ( PLpgSQL_stmt_dynexecute stmt)
static

Definition at line 677 of file pl_funcs.c.

References free_expr(), lfirst, PLpgSQL_stmt_dynexecute::params, and PLpgSQL_stmt_dynexecute::query.

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

678 {
679  ListCell *lc;
680 
681  free_expr(stmt->query);
682  foreach(lc, stmt->params)
683  {
684  free_expr((PLpgSQL_expr *) lfirst(lc));
685  }
686 }
PLpgSQL_expr * query
Definition: plpgsql.h:850
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:707
#define lfirst(lc)
Definition: pg_list.h:106

◆ free_dynfors()

static void free_dynfors ( PLpgSQL_stmt_dynfors stmt)
static

Definition at line 689 of file pl_funcs.c.

References PLpgSQL_stmt_dynfors::body, free_expr(), free_stmts(), lfirst, PLpgSQL_stmt_dynfors::params, and PLpgSQL_stmt_dynfors::query.

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

690 {
691  ListCell *lc;
692 
693  free_stmts(stmt->body);
694  free_expr(stmt->query);
695  foreach(lc, stmt->params)
696  {
697  free_expr((PLpgSQL_expr *) lfirst(lc));
698  }
699 }
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:707
PLpgSQL_expr * query
Definition: plpgsql.h:689
static void free_stmts(List *stmts)
Definition: pl_funcs.c:465
#define lfirst(lc)
Definition: pg_list.h:106

◆ free_execsql()

static void free_execsql ( PLpgSQL_stmt_execsql stmt)
static

Definition at line 671 of file pl_funcs.c.

References free_expr(), and PLpgSQL_stmt_execsql::sqlstmt.

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

672 {
673  free_expr(stmt->sqlstmt);
674 }
PLpgSQL_expr * sqlstmt
Definition: plpgsql.h:835
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:707

◆ free_exit()

static void free_exit ( PLpgSQL_stmt_exit stmt)
static

Definition at line 616 of file pl_funcs.c.

References PLpgSQL_stmt_exit::cond, and free_expr().

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

617 {
618  free_expr(stmt->cond);
619 }
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:707
PLpgSQL_expr * cond
Definition: plpgsql.h:757

◆ free_expr()

static void free_expr ( PLpgSQL_expr expr)
static

◆ free_fetch()

static void free_fetch ( PLpgSQL_stmt_fetch stmt)
static

Definition at line 589 of file pl_funcs.c.

References PLpgSQL_stmt_fetch::expr, and free_expr().

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

590 {
591  free_expr(stmt->expr);
592 }
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:707
PLpgSQL_expr * expr
Definition: plpgsql.h:733

◆ free_forc()

static void free_forc ( PLpgSQL_stmt_forc stmt)
static

Definition at line 561 of file pl_funcs.c.

References PLpgSQL_stmt_forc::argquery, PLpgSQL_stmt_forc::body, free_expr(), and free_stmts().

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

562 {
563  free_stmts(stmt->body);
564  free_expr(stmt->argquery);
565 }
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:707
static void free_stmts(List *stmts)
Definition: pl_funcs.c:465
PLpgSQL_expr * argquery
Definition: plpgsql.h:675

◆ free_foreach_a()

static void free_foreach_a ( PLpgSQL_stmt_foreach_a stmt)
static

Definition at line 568 of file pl_funcs.c.

References PLpgSQL_stmt_foreach_a::body, PLpgSQL_stmt_foreach_a::expr, free_expr(), and free_stmts().

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

569 {
570  free_expr(stmt->expr);
571  free_stmts(stmt->body);
572 }
PLpgSQL_expr * expr
Definition: plpgsql.h:703
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:707
static void free_stmts(List *stmts)
Definition: pl_funcs.c:465

◆ free_fori()

static void free_fori ( PLpgSQL_stmt_fori stmt)
static

Definition at line 545 of file pl_funcs.c.

References PLpgSQL_stmt_fori::body, free_expr(), free_stmts(), PLpgSQL_stmt_fori::lower, PLpgSQL_stmt_fori::step, and PLpgSQL_stmt_fori::upper.

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

546 {
547  free_expr(stmt->lower);
548  free_expr(stmt->upper);
549  free_expr(stmt->step);
550  free_stmts(stmt->body);
551 }
PLpgSQL_expr * lower
Definition: plpgsql.h:628
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:707
static void free_stmts(List *stmts)
Definition: pl_funcs.c:465
PLpgSQL_expr * step
Definition: plpgsql.h:630
PLpgSQL_expr * upper
Definition: plpgsql.h:629

◆ free_fors()

static void free_fors ( PLpgSQL_stmt_fors stmt)
static

Definition at line 554 of file pl_funcs.c.

References PLpgSQL_stmt_fors::body, free_expr(), free_stmts(), and PLpgSQL_stmt_fors::query.

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

555 {
556  free_stmts(stmt->body);
557  free_expr(stmt->query);
558 }
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:707
static void free_stmts(List *stmts)
Definition: pl_funcs.c:465
PLpgSQL_expr * query
Definition: plpgsql.h:660

◆ free_getdiag()

static void free_getdiag ( PLpgSQL_stmt_getdiag stmt)
static

Definition at line 702 of file pl_funcs.c.

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

703 {
704 }

◆ free_if()

static void free_if ( PLpgSQL_stmt_if stmt)
static

Definition at line 499 of file pl_funcs.c.

References PLpgSQL_stmt_if::cond, PLpgSQL_if_elsif::cond, PLpgSQL_stmt_if::else_body, PLpgSQL_stmt_if::elsif_list, free_expr(), free_stmts(), lfirst, PLpgSQL_if_elsif::stmts, and PLpgSQL_stmt_if::then_body.

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

500 {
501  ListCell *l;
502 
503  free_expr(stmt->cond);
504  free_stmts(stmt->then_body);
505  foreach(l, stmt->elsif_list)
506  {
508 
509  free_expr(elif->cond);
510  free_stmts(elif->stmts);
511  }
512  free_stmts(stmt->else_body);
513 }
PLpgSQL_expr * cond
Definition: plpgsql.h:556
List * then_body
Definition: plpgsql.h:557
List * elsif_list
Definition: plpgsql.h:558
List * stmts
Definition: plpgsql.h:569
PLpgSQL_expr * cond
Definition: plpgsql.h:568
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:707
static void free_stmts(List *stmts)
Definition: pl_funcs.c:465
#define lfirst(lc)
Definition: pg_list.h:106
List * else_body
Definition: plpgsql.h:559

◆ free_loop()

static void free_loop ( PLpgSQL_stmt_loop stmt)
static

Definition at line 532 of file pl_funcs.c.

References PLpgSQL_stmt_loop::body, and free_stmts().

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

533 {
534  free_stmts(stmt->body);
535 }
static void free_stmts(List *stmts)
Definition: pl_funcs.c:465

◆ free_open()

static void free_open ( PLpgSQL_stmt_open stmt)
static

Definition at line 575 of file pl_funcs.c.

References PLpgSQL_stmt_open::argquery, PLpgSQL_stmt_open::dynquery, free_expr(), lfirst, PLpgSQL_stmt_open::params, and PLpgSQL_stmt_open::query.

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

576 {
577  ListCell *lc;
578 
579  free_expr(stmt->argquery);
580  free_expr(stmt->query);
581  free_expr(stmt->dynquery);
582  foreach(lc, stmt->params)
583  {
584  free_expr((PLpgSQL_expr *) lfirst(lc));
585  }
586 }
PLpgSQL_expr * dynquery
Definition: plpgsql.h:718
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:707
PLpgSQL_expr * query
Definition: plpgsql.h:717
#define lfirst(lc)
Definition: pg_list.h:106
PLpgSQL_expr * argquery
Definition: plpgsql.h:716

◆ free_perform()

static void free_perform ( PLpgSQL_stmt_perform stmt)
static

Definition at line 600 of file pl_funcs.c.

References PLpgSQL_stmt_perform::expr, and free_expr().

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

601 {
602  free_expr(stmt->expr);
603 }
PLpgSQL_expr * expr
Definition: plpgsql.h:508
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:707

◆ free_raise()

static void free_raise ( PLpgSQL_stmt_raise stmt)
static

Definition at line 647 of file pl_funcs.c.

References PLpgSQL_raise_option::expr, free_expr(), lfirst, PLpgSQL_stmt_raise::options, and PLpgSQL_stmt_raise::params.

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

648 {
649  ListCell *lc;
650 
651  foreach(lc, stmt->params)
652  {
653  free_expr((PLpgSQL_expr *) lfirst(lc));
654  }
655  foreach(lc, stmt->options)
656  {
658 
659  free_expr(opt->expr);
660  }
661 }
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:707
#define lfirst(lc)
Definition: pg_list.h:106
PLpgSQL_expr * expr
Definition: plpgsql.h:814

◆ free_return()

static void free_return ( PLpgSQL_stmt_return stmt)
static

Definition at line 622 of file pl_funcs.c.

References PLpgSQL_stmt_return::expr, and free_expr().

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

623 {
624  free_expr(stmt->expr);
625 }
PLpgSQL_expr * expr
Definition: plpgsql.h:767
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:707

◆ free_return_next()

static void free_return_next ( PLpgSQL_stmt_return_next stmt)
static

Definition at line 628 of file pl_funcs.c.

References PLpgSQL_stmt_return_next::expr, and free_expr().

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

629 {
630  free_expr(stmt->expr);
631 }
PLpgSQL_expr * expr
Definition: plpgsql.h:778
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:707

◆ free_return_query()

static void free_return_query ( PLpgSQL_stmt_return_query stmt)
static

Definition at line 634 of file pl_funcs.c.

References PLpgSQL_stmt_return_query::dynquery, free_expr(), lfirst, PLpgSQL_stmt_return_query::params, and PLpgSQL_stmt_return_query::query.

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

635 {
636  ListCell *lc;
637 
638  free_expr(stmt->query);
639  free_expr(stmt->dynquery);
640  foreach(lc, stmt->params)
641  {
642  free_expr((PLpgSQL_expr *) lfirst(lc));
643  }
644 }
PLpgSQL_expr * query
Definition: plpgsql.h:789
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:707
#define lfirst(lc)
Definition: pg_list.h:106
PLpgSQL_expr * dynquery
Definition: plpgsql.h:790

◆ free_rollback()

static void free_rollback ( PLpgSQL_stmt_rollback stmt)
static

Definition at line 611 of file pl_funcs.c.

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

612 {
613 }

◆ free_stmt()

static void free_stmt ( PLpgSQL_stmt stmt)
static

Definition at line 376 of file pl_funcs.c.

References PLpgSQL_stmt::cmd_type, PLpgSQL_stmt_rollback::cmd_type, elog, ERROR, free_assert(), free_assign(), free_block(), free_case(), free_close(), free_commit(), free_dynexecute(), free_dynfors(), free_execsql(), free_exit(), free_fetch(), free_forc(), free_foreach_a(), free_fori(), free_fors(), free_getdiag(), free_if(), free_loop(), free_open(), free_perform(), free_raise(), free_return(), free_return_next(), free_return_query(), free_rollback(), free_while(), PLPGSQL_STMT_ASSERT, PLPGSQL_STMT_ASSIGN, PLPGSQL_STMT_BLOCK, PLPGSQL_STMT_CASE, PLPGSQL_STMT_CLOSE, PLPGSQL_STMT_COMMIT, PLPGSQL_STMT_DYNEXECUTE, PLPGSQL_STMT_DYNFORS, PLPGSQL_STMT_EXECSQL, PLPGSQL_STMT_EXIT, PLPGSQL_STMT_FETCH, PLPGSQL_STMT_FORC, PLPGSQL_STMT_FOREACH_A, PLPGSQL_STMT_FORI, PLPGSQL_STMT_FORS, PLPGSQL_STMT_GETDIAG, PLPGSQL_STMT_IF, PLPGSQL_STMT_LOOP, PLPGSQL_STMT_OPEN, PLPGSQL_STMT_PERFORM, PLPGSQL_STMT_RAISE, PLPGSQL_STMT_RETURN, PLPGSQL_STMT_RETURN_NEXT, PLPGSQL_STMT_RETURN_QUERY, PLPGSQL_STMT_ROLLBACK, and PLPGSQL_STMT_WHILE.

Referenced by free_stmts(), and plpgsql_getdiag_kindname().

377 {
378  switch (stmt->cmd_type)
379  {
380  case PLPGSQL_STMT_BLOCK:
381  free_block((PLpgSQL_stmt_block *) stmt);
382  break;
383  case PLPGSQL_STMT_ASSIGN:
385  break;
386  case PLPGSQL_STMT_IF:
387  free_if((PLpgSQL_stmt_if *) stmt);
388  break;
389  case PLPGSQL_STMT_CASE:
390  free_case((PLpgSQL_stmt_case *) stmt);
391  break;
392  case PLPGSQL_STMT_LOOP:
393  free_loop((PLpgSQL_stmt_loop *) stmt);
394  break;
395  case PLPGSQL_STMT_WHILE:
396  free_while((PLpgSQL_stmt_while *) stmt);
397  break;
398  case PLPGSQL_STMT_FORI:
399  free_fori((PLpgSQL_stmt_fori *) stmt);
400  break;
401  case PLPGSQL_STMT_FORS:
402  free_fors((PLpgSQL_stmt_fors *) stmt);
403  break;
404  case PLPGSQL_STMT_FORC:
405  free_forc((PLpgSQL_stmt_forc *) stmt);
406  break;
409  break;
410  case PLPGSQL_STMT_EXIT:
411  free_exit((PLpgSQL_stmt_exit *) stmt);
412  break;
413  case PLPGSQL_STMT_RETURN:
415  break;
418  break;
421  break;
422  case PLPGSQL_STMT_RAISE:
423  free_raise((PLpgSQL_stmt_raise *) stmt);
424  break;
425  case PLPGSQL_STMT_ASSERT:
427  break;
430  break;
433  break;
436  break;
439  break;
440  case PLPGSQL_STMT_OPEN:
441  free_open((PLpgSQL_stmt_open *) stmt);
442  break;
443  case PLPGSQL_STMT_FETCH:
444  free_fetch((PLpgSQL_stmt_fetch *) stmt);
445  break;
446  case PLPGSQL_STMT_CLOSE:
447  free_close((PLpgSQL_stmt_close *) stmt);
448  break;
451  break;
452  case PLPGSQL_STMT_COMMIT:
454  break;
457  break;
458  default:
459  elog(ERROR, "unrecognized cmd_type: %d", stmt->cmd_type);
460  break;
461  }
462 }
static void free_assert(PLpgSQL_stmt_assert *stmt)
Definition: pl_funcs.c:664
static void free_dynexecute(PLpgSQL_stmt_dynexecute *stmt)
Definition: pl_funcs.c:677
static void free_raise(PLpgSQL_stmt_raise *stmt)
Definition: pl_funcs.c:647
static void free_open(PLpgSQL_stmt_open *stmt)
Definition: pl_funcs.c:575
static void free_return(PLpgSQL_stmt_return *stmt)
Definition: pl_funcs.c:622
static void free_loop(PLpgSQL_stmt_loop *stmt)
Definition: pl_funcs.c:532
static void free_dynfors(PLpgSQL_stmt_dynfors *stmt)
Definition: pl_funcs.c:689
static void free_rollback(PLpgSQL_stmt_rollback *stmt)
Definition: pl_funcs.c:611
static void free_assign(PLpgSQL_stmt_assign *stmt)
Definition: pl_funcs.c:493
static void free_getdiag(PLpgSQL_stmt_getdiag *stmt)
Definition: pl_funcs.c:702
#define ERROR
Definition: elog.h:43
static void free_fetch(PLpgSQL_stmt_fetch *stmt)
Definition: pl_funcs.c:589
static void free_close(PLpgSQL_stmt_close *stmt)
Definition: pl_funcs.c:595
static void free_case(PLpgSQL_stmt_case *stmt)
Definition: pl_funcs.c:516
static void free_fori(PLpgSQL_stmt_fori *stmt)
Definition: pl_funcs.c:545
static void free_perform(PLpgSQL_stmt_perform *stmt)
Definition: pl_funcs.c:600
static void free_return_next(PLpgSQL_stmt_return_next *stmt)
Definition: pl_funcs.c:628
static void free_fors(PLpgSQL_stmt_fors *stmt)
Definition: pl_funcs.c:554
static void free_exit(PLpgSQL_stmt_exit *stmt)
Definition: pl_funcs.c:616
static void free_if(PLpgSQL_stmt_if *stmt)
Definition: pl_funcs.c:499
static void free_return_query(PLpgSQL_stmt_return_query *stmt)
Definition: pl_funcs.c:634
static void free_execsql(PLpgSQL_stmt_execsql *stmt)
Definition: pl_funcs.c:671
static void free_forc(PLpgSQL_stmt_forc *stmt)
Definition: pl_funcs.c:561
static void free_commit(PLpgSQL_stmt_commit *stmt)
Definition: pl_funcs.c:606
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:442
static void free_while(PLpgSQL_stmt_while *stmt)
Definition: pl_funcs.c:538
#define elog
Definition: elog.h:219
static void free_foreach_a(PLpgSQL_stmt_foreach_a *stmt)
Definition: pl_funcs.c:568
static void free_block(PLpgSQL_stmt_block *block)
Definition: pl_funcs.c:476

◆ free_stmts()

static void free_stmts ( List stmts)
static

Definition at line 465 of file pl_funcs.c.

References free_stmt(), and lfirst.

Referenced by free_block(), free_case(), free_dynfors(), free_forc(), free_foreach_a(), free_fori(), free_fors(), free_if(), free_loop(), and free_while().

466 {
467  ListCell *s;
468 
469  foreach(s, stmts)
470  {
471  free_stmt((PLpgSQL_stmt *) lfirst(s));
472  }
473 }
#define lfirst(lc)
Definition: pg_list.h:106
static void free_stmt(PLpgSQL_stmt *stmt)
Definition: pl_funcs.c:376

◆ free_while()

static void free_while ( PLpgSQL_stmt_while stmt)
static

Definition at line 538 of file pl_funcs.c.

References PLpgSQL_stmt_while::body, PLpgSQL_stmt_while::cond, free_expr(), and free_stmts().

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

539 {
540  free_expr(stmt->cond);
541  free_stmts(stmt->body);
542 }
PLpgSQL_expr * cond
Definition: plpgsql.h:615
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:707
static void free_stmts(List *stmts)
Definition: pl_funcs.c:465

◆ plpgsql_dumptree()

void plpgsql_dumptree ( PLpgSQL_function func)

Definition at line 1574 of file pl_funcs.c.

References PLpgSQL_function::action, PLpgSQL_type::atttypmod, PLpgSQL_var::cursor_explicit_argrow, PLpgSQL_var::cursor_explicit_expr, PLpgSQL_var::datatype, PLpgSQL_function::datums, PLpgSQL_var::default_val, PLpgSQL_datum::dtype, PLpgSQL_arrayelem::dtype, dump_block(), dump_expr(), dump_indent, PLpgSQL_row::fieldnames, PLpgSQL_function::fn_signature, i, PLpgSQL_var::isconst, PLpgSQL_stmt_block::lineno, PLpgSQL_function::ndatums, PLpgSQL_row::nfields, PLpgSQL_var::notnull, PLPGSQL_DTYPE_ARRAYELEM, PLPGSQL_DTYPE_PROMISE, PLPGSQL_DTYPE_REC, PLPGSQL_DTYPE_RECFIELD, PLPGSQL_DTYPE_ROW, PLPGSQL_DTYPE_VAR, PLPGSQL_PROMISE_NONE, PLpgSQL_var::promise, PLpgSQL_var::refname, PLpgSQL_row::refname, PLpgSQL_type::typname, PLpgSQL_type::typoid, and PLpgSQL_row::varnos.

Referenced by do_compile().

1575 {
1576  int i;
1577  PLpgSQL_datum *d;
1578 
1579  printf("\nExecution tree of successfully compiled PL/pgSQL function %s:\n",
1580  func->fn_signature);
1581 
1582  printf("\nFunction's data area:\n");
1583  for (i = 0; i < func->ndatums; i++)
1584  {
1585  d = func->datums[i];
1586 
1587  printf(" entry %d: ", i);
1588  switch (d->dtype)
1589  {
1590  case PLPGSQL_DTYPE_VAR:
1591  case PLPGSQL_DTYPE_PROMISE:
1592  {
1593  PLpgSQL_var *var = (PLpgSQL_var *) d;
1594 
1595  printf("VAR %-16s type %s (typoid %u) atttypmod %d\n",
1596  var->refname, var->datatype->typname,
1597  var->datatype->typoid,
1598  var->datatype->atttypmod);
1599  if (var->isconst)
1600  printf(" CONSTANT\n");
1601  if (var->notnull)
1602  printf(" NOT NULL\n");
1603  if (var->default_val != NULL)
1604  {
1605  printf(" DEFAULT ");
1606  dump_expr(var->default_val);
1607  printf("\n");
1608  }
1609  if (var->cursor_explicit_expr != NULL)
1610  {
1611  if (var->cursor_explicit_argrow >= 0)
1612  printf(" CURSOR argument row %d\n", var->cursor_explicit_argrow);
1613 
1614  printf(" CURSOR IS ");
1616  printf("\n");
1617  }
1618  if (var->promise != PLPGSQL_PROMISE_NONE)
1619  printf(" PROMISE %d\n",
1620  (int) var->promise);
1621  }
1622  break;
1623  case PLPGSQL_DTYPE_ROW:
1624  {
1625  PLpgSQL_row *row = (PLpgSQL_row *) d;
1626  int i;
1627 
1628  printf("ROW %-16s fields", row->refname);
1629  for (i = 0; i < row->nfields; i++)
1630  {
1631  printf(" %s=var %d", row->fieldnames[i],
1632  row->varnos[i]);
1633  }
1634  printf("\n");
1635  }
1636  break;
1637  case PLPGSQL_DTYPE_REC:
1638  printf("REC %-16s typoid %u\n",
1639  ((PLpgSQL_rec *) d)->refname,
1640  ((PLpgSQL_rec *) d)->rectypeid);
1641  if (((PLpgSQL_rec *) d)->isconst)
1642  printf(" CONSTANT\n");
1643  if (((PLpgSQL_rec *) d)->notnull)
1644  printf(" NOT NULL\n");
1645  if (((PLpgSQL_rec *) d)->default_val != NULL)
1646  {
1647  printf(" DEFAULT ");
1648  dump_expr(((PLpgSQL_rec *) d)->default_val);
1649  printf("\n");
1650  }
1651  break;
1653  printf("RECFIELD %-16s of REC %d\n",
1654  ((PLpgSQL_recfield *) d)->fieldname,
1655  ((PLpgSQL_recfield *) d)->recparentno);
1656  break;
1658  printf("ARRAYELEM of VAR %d subscript ",
1659  ((PLpgSQL_arrayelem *) d)->arrayparentno);
1660  dump_expr(((PLpgSQL_arrayelem *) d)->subscript);
1661  printf("\n");
1662  break;
1663  default:
1664  printf("??? unknown data type %d\n", d->dtype);
1665  }
1666  }
1667  printf("\nFunction's statements:\n");
1668 
1669  dump_indent = 0;
1670  printf("%3d:", func->action->lineno);
1671  dump_block(func->action);
1672  printf("\nEnd of execution tree of function %s\n\n", func->fn_signature);
1673  fflush(stdout);
1674 }
PLpgSQL_promise_type promise
Definition: plpgsql.h:316
PLpgSQL_datum ** datums
Definition: plpgsql.h:939
char * refname
Definition: plpgsql.h:336
char * refname
Definition: plpgsql.h:287
PLpgSQL_stmt_block * action
Definition: plpgsql.h:943
PLpgSQL_expr * cursor_explicit_expr
Definition: plpgsql.h:301
PLpgSQL_type * datatype
Definition: plpgsql.h:294
bool isconst
Definition: plpgsql.h:289
PLpgSQL_datum_type dtype
Definition: plpgsql.h:251
bool notnull
Definition: plpgsql.h:290
int cursor_explicit_argrow
Definition: plpgsql.h:302
char ** fieldnames
Definition: plpgsql.h:351
PLpgSQL_expr * default_val
Definition: plpgsql.h:291
int * varnos
Definition: plpgsql.h:352
PLpgSQL_datum_type dtype
Definition: plpgsql.h:385
int nfields
Definition: plpgsql.h:350
static int dump_indent
Definition: pl_funcs.c:779
char * fn_signature
Definition: plpgsql.h:905
char * typname
Definition: plpgsql.h:199
static void dump_block(PLpgSQL_stmt_block *block)
Definition: pl_funcs.c:924
int32 atttypmod
Definition: plpgsql.h:207
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1568
int i
Oid typoid
Definition: plpgsql.h:200

◆ plpgsql_free_function_memory()

void plpgsql_free_function_memory ( PLpgSQL_function func)

Definition at line 717 of file pl_funcs.c.

References PLpgSQL_function::action, Assert, PLpgSQL_var::cursor_explicit_expr, PLpgSQL_function::datums, PLpgSQL_var::default_val, PLpgSQL_rec::default_val, PLpgSQL_datum::dtype, PLpgSQL_arrayelem::dtype, elog, ERROR, PLpgSQL_function::fn_cxt, free_block(), free_expr(), i, MemoryContextDelete(), PLpgSQL_function::ndatums, PLPGSQL_DTYPE_ARRAYELEM, PLPGSQL_DTYPE_PROMISE, PLPGSQL_DTYPE_REC, PLPGSQL_DTYPE_RECFIELD, PLPGSQL_DTYPE_ROW, PLPGSQL_DTYPE_VAR, and PLpgSQL_function::use_count.

Referenced by delete_function(), and plpgsql_inline_handler().

718 {
719  int i;
720 
721  /* Better not call this on an in-use function */
722  Assert(func->use_count == 0);
723 
724  /* Release plans associated with variable declarations */
725  for (i = 0; i < func->ndatums; i++)
726  {
727  PLpgSQL_datum *d = func->datums[i];
728 
729  switch (d->dtype)
730  {
731  case PLPGSQL_DTYPE_VAR:
733  {
734  PLpgSQL_var *var = (PLpgSQL_var *) d;
735 
736  free_expr(var->default_val);
738  }
739  break;
740  case PLPGSQL_DTYPE_ROW:
741  break;
742  case PLPGSQL_DTYPE_REC:
743  {
744  PLpgSQL_rec *rec = (PLpgSQL_rec *) d;
745 
746  free_expr(rec->default_val);
747  }
748  break;
750  break;
752  free_expr(((PLpgSQL_arrayelem *) d)->subscript);
753  break;
754  default:
755  elog(ERROR, "unrecognized data type: %d", d->dtype);
756  }
757  }
758  func->ndatums = 0;
759 
760  /* Release plans in statement tree */
761  if (func->action)
762  free_block(func->action);
763  func->action = NULL;
764 
765  /*
766  * And finally, release all memory except the PLpgSQL_function struct
767  * itself (which has to be kept around because there may be multiple
768  * fn_extra pointers to it).
769  */
770  if (func->fn_cxt)
772  func->fn_cxt = NULL;
773 }
PLpgSQL_datum ** datums
Definition: plpgsql.h:939
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:198
PLpgSQL_stmt_block * action
Definition: plpgsql.h:943
PLpgSQL_expr * cursor_explicit_expr
Definition: plpgsql.h:301
PLpgSQL_datum_type dtype
Definition: plpgsql.h:251
#define ERROR
Definition: elog.h:43
PLpgSQL_expr * default_val
Definition: plpgsql.h:291
unsigned long use_count
Definition: plpgsql.h:947
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:707
MemoryContext fn_cxt
Definition: plpgsql.h:912
#define Assert(condition)
Definition: c.h:688
int i
#define elog
Definition: elog.h:219
PLpgSQL_expr * default_val
Definition: plpgsql.h:366
static void free_block(PLpgSQL_stmt_block *block)
Definition: pl_funcs.c:476

◆ plpgsql_getdiag_kindname()

const char* plpgsql_getdiag_kindname ( PLpgSQL_getdiag_kind  kind)

Definition at line 300 of file pl_funcs.c.

References free_assert(), free_assign(), free_block(), free_case(), free_close(), free_commit(), free_dynexecute(), free_dynfors(), free_execsql(), free_exit(), free_expr(), free_fetch(), free_forc(), free_foreach_a(), free_fori(), free_fors(), free_getdiag(), free_if(), free_loop(), free_open(), free_perform(), free_raise(), free_return(), free_return_next(), free_return_query(), free_rollback(), free_stmt(), free_while(), PLPGSQL_GETDIAG_COLUMN_NAME, PLPGSQL_GETDIAG_CONSTRAINT_NAME, PLPGSQL_GETDIAG_CONTEXT, PLPGSQL_GETDIAG_DATATYPE_NAME, PLPGSQL_GETDIAG_ERROR_CONTEXT, PLPGSQL_GETDIAG_ERROR_DETAIL, PLPGSQL_GETDIAG_ERROR_HINT, PLPGSQL_GETDIAG_MESSAGE_TEXT, PLPGSQL_GETDIAG_RESULT_OID, PLPGSQL_GETDIAG_RETURNED_SQLSTATE, PLPGSQL_GETDIAG_ROW_COUNT, PLPGSQL_GETDIAG_SCHEMA_NAME, and PLPGSQL_GETDIAG_TABLE_NAME.

Referenced by dump_getdiag().

301 {
302  switch (kind)
303  {
305  return "ROW_COUNT";
307  return "RESULT_OID";
309  return "PG_CONTEXT";
311  return "PG_EXCEPTION_CONTEXT";
313  return "PG_EXCEPTION_DETAIL";
315  return "PG_EXCEPTION_HINT";
317  return "RETURNED_SQLSTATE";
319  return "COLUMN_NAME";
321  return "CONSTRAINT_NAME";
323  return "PG_DATATYPE_NAME";
325  return "MESSAGE_TEXT";
327  return "TABLE_NAME";
329  return "SCHEMA_NAME";
330  }
331 
332  return "unknown";
333 }

◆ plpgsql_ns_additem()

void plpgsql_ns_additem ( PLpgSQL_nsitem_type  itemtype,
int  itemno,
const char *  name 
)

Definition at line 94 of file pl_funcs.c.

References Assert, PLpgSQL_nsitem::itemno, PLpgSQL_nsitem::itemtype, PLpgSQL_nsitem::name, ns_top, offsetof, palloc(), PLPGSQL_NSTYPE_LABEL, and PLpgSQL_nsitem::prev.

Referenced by add_parameter_name(), plpgsql_build_record(), plpgsql_build_variable(), and plpgsql_ns_push().

95 {
96  PLpgSQL_nsitem *nse;
97 
98  Assert(name != NULL);
99  /* first item added must be a label */
100  Assert(ns_top != NULL || itemtype == PLPGSQL_NSTYPE_LABEL);
101 
102  nse = palloc(offsetof(PLpgSQL_nsitem, name) + strlen(name) + 1);
103  nse->itemtype = itemtype;
104  nse->itemno = itemno;
105  nse->prev = ns_top;
106  strcpy(nse->name, name);
107  ns_top = nse;
108 }
static PLpgSQL_nsitem * ns_top
Definition: pl_funcs.c:37
struct PLpgSQL_nsitem * prev
Definition: plpgsql.h:433
#define Assert(condition)
Definition: c.h:688
const char * name
Definition: encode.c:521
void * palloc(Size size)
Definition: mcxt.c:835
PLpgSQL_nsitem_type itemtype
Definition: plpgsql.h:426
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: plpgsql.h:434
#define offsetof(type, field)
Definition: c.h:611

◆ plpgsql_ns_find_nearest_loop()

PLpgSQL_nsitem* plpgsql_ns_find_nearest_loop ( PLpgSQL_nsitem ns_cur)

Definition at line 216 of file pl_funcs.c.

References PLpgSQL_nsitem::itemno, PLpgSQL_nsitem::itemtype, PLPGSQL_LABEL_LOOP, PLPGSQL_NSTYPE_LABEL, and PLpgSQL_nsitem::prev.

217 {
218  while (ns_cur != NULL)
219  {
220  if (ns_cur->itemtype == PLPGSQL_NSTYPE_LABEL &&
221  ns_cur->itemno == PLPGSQL_LABEL_LOOP)
222  return ns_cur;
223  ns_cur = ns_cur->prev;
224  }
225 
226  return NULL; /* no loop found */
227 }
struct PLpgSQL_nsitem * prev
Definition: plpgsql.h:433
PLpgSQL_nsitem_type itemtype
Definition: plpgsql.h:426

◆ plpgsql_ns_init()

void plpgsql_ns_init ( void  )

Definition at line 45 of file pl_funcs.c.

Referenced by do_compile(), and plpgsql_compile_inline().

46 {
47  ns_top = NULL;
48 }
static PLpgSQL_nsitem * ns_top
Definition: pl_funcs.c:37

◆ plpgsql_ns_lookup()

PLpgSQL_nsitem* plpgsql_ns_lookup ( PLpgSQL_nsitem ns_cur,
bool  localmode,
const char *  name1,
const char *  name2,
const char *  name3,
int *  names_used 
)

Definition at line 132 of file pl_funcs.c.

References PLpgSQL_nsitem::itemtype, PLpgSQL_nsitem::name, PLPGSQL_NSTYPE_LABEL, PLPGSQL_NSTYPE_VAR, and PLpgSQL_nsitem::prev.

Referenced by add_parameter_name(), plpgsql_param_ref(), plpgsql_parse_cwordtype(), plpgsql_parse_dblword(), plpgsql_parse_tripword(), plpgsql_parse_word(), plpgsql_parse_wordtype(), and resolve_column_ref().

135 {
136  /* Outer loop iterates once per block level in the namespace chain */
137  while (ns_cur != NULL)
138  {
139  PLpgSQL_nsitem *nsitem;
140 
141  /* Check this level for unqualified match to variable name */
142  for (nsitem = ns_cur;
143  nsitem->itemtype != PLPGSQL_NSTYPE_LABEL;
144  nsitem = nsitem->prev)
145  {
146  if (strcmp(nsitem->name, name1) == 0)
147  {
148  if (name2 == NULL ||
149  nsitem->itemtype != PLPGSQL_NSTYPE_VAR)
150  {
151  if (names_used)
152  *names_used = 1;
153  return nsitem;
154  }
155  }
156  }
157 
158  /* Check this level for qualified match to variable name */
159  if (name2 != NULL &&
160  strcmp(nsitem->name, name1) == 0)
161  {
162  for (nsitem = ns_cur;
163  nsitem->itemtype != PLPGSQL_NSTYPE_LABEL;
164  nsitem = nsitem->prev)
165  {
166  if (strcmp(nsitem->name, name2) == 0)
167  {
168  if (name3 == NULL ||
169  nsitem->itemtype != PLPGSQL_NSTYPE_VAR)
170  {
171  if (names_used)
172  *names_used = 2;
173  return nsitem;
174  }
175  }
176  }
177  }
178 
179  if (localmode)
180  break; /* do not look into upper levels */
181 
182  ns_cur = nsitem->prev;
183  }
184 
185  /* This is just to suppress possibly-uninitialized-variable warnings */
186  if (names_used)
187  *names_used = 0;
188  return NULL; /* No match found */
189 }
struct PLpgSQL_nsitem * prev
Definition: plpgsql.h:433
PLpgSQL_nsitem_type itemtype
Definition: plpgsql.h:426
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: plpgsql.h:434

◆ plpgsql_ns_lookup_label()

PLpgSQL_nsitem* plpgsql_ns_lookup_label ( PLpgSQL_nsitem ns_cur,
const char *  name 
)

Definition at line 197 of file pl_funcs.c.

References PLpgSQL_nsitem::itemtype, PLpgSQL_nsitem::name, PLPGSQL_NSTYPE_LABEL, and PLpgSQL_nsitem::prev.

198 {
199  while (ns_cur != NULL)
200  {
201  if (ns_cur->itemtype == PLPGSQL_NSTYPE_LABEL &&
202  strcmp(ns_cur->name, name) == 0)
203  return ns_cur;
204  ns_cur = ns_cur->prev;
205  }
206 
207  return NULL; /* label not found */
208 }
struct PLpgSQL_nsitem * prev
Definition: plpgsql.h:433
const char * name
Definition: encode.c:521
PLpgSQL_nsitem_type itemtype
Definition: plpgsql.h:426
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: plpgsql.h:434

◆ plpgsql_ns_pop()

void plpgsql_ns_pop ( void  )

Definition at line 69 of file pl_funcs.c.

References Assert, PLpgSQL_nsitem::itemtype, PLPGSQL_NSTYPE_LABEL, and PLpgSQL_nsitem::prev.

70 {
71  Assert(ns_top != NULL);
73  ns_top = ns_top->prev;
74  ns_top = ns_top->prev;
75 }
static PLpgSQL_nsitem * ns_top
Definition: pl_funcs.c:37
struct PLpgSQL_nsitem * prev
Definition: plpgsql.h:433
#define Assert(condition)
Definition: c.h:688
PLpgSQL_nsitem_type itemtype
Definition: plpgsql.h:426

◆ plpgsql_ns_push()

void plpgsql_ns_push ( const char *  label,
PLpgSQL_label_type  label_type 
)

Definition at line 56 of file pl_funcs.c.

References plpgsql_ns_additem(), and PLPGSQL_NSTYPE_LABEL.

Referenced by do_compile(), and plpgsql_compile_inline().

57 {
58  if (label == NULL)
59  label = "";
60  plpgsql_ns_additem(PLPGSQL_NSTYPE_LABEL, (int) label_type, label);
61 }
void plpgsql_ns_additem(PLpgSQL_nsitem_type itemtype, int itemno, const char *name)
Definition: pl_funcs.c:94
static char * label
Definition: pg_basebackup.c:82

◆ plpgsql_ns_top()

PLpgSQL_nsitem* plpgsql_ns_top ( void  )

Definition at line 83 of file pl_funcs.c.

References ns_top.

Referenced by add_parameter_name(), plpgsql_parse_cwordtype(), plpgsql_parse_dblword(), plpgsql_parse_tripword(), plpgsql_parse_word(), and plpgsql_parse_wordtype().

84 {
85  return ns_top;
86 }
static PLpgSQL_nsitem * ns_top
Definition: pl_funcs.c:37

◆ plpgsql_stmt_typename()

const char* plpgsql_stmt_typename ( PLpgSQL_stmt stmt)

Definition at line 234 of file pl_funcs.c.

References _, PLpgSQL_stmt::cmd_type, PLPGSQL_STMT_ASSERT, PLPGSQL_STMT_ASSIGN, PLPGSQL_STMT_BLOCK, PLPGSQL_STMT_CASE, PLPGSQL_STMT_CLOSE, PLPGSQL_STMT_COMMIT, PLPGSQL_STMT_DYNEXECUTE, PLPGSQL_STMT_DYNFORS, PLPGSQL_STMT_EXECSQL, PLPGSQL_STMT_EXIT, PLPGSQL_STMT_FETCH, PLPGSQL_STMT_FORC, PLPGSQL_STMT_FOREACH_A, PLPGSQL_STMT_FORI, PLPGSQL_STMT_FORS, PLPGSQL_STMT_GETDIAG, PLPGSQL_STMT_IF, PLPGSQL_STMT_LOOP, PLPGSQL_STMT_OPEN, PLPGSQL_STMT_PERFORM, PLPGSQL_STMT_RAISE, PLPGSQL_STMT_RETURN, PLPGSQL_STMT_RETURN_NEXT, PLPGSQL_STMT_RETURN_QUERY, PLPGSQL_STMT_ROLLBACK, and PLPGSQL_STMT_WHILE.

Referenced by plpgsql_exec_error_callback().

235 {
236  switch (stmt->cmd_type)
237  {
238  case PLPGSQL_STMT_BLOCK:
239  return _("statement block");
240  case PLPGSQL_STMT_ASSIGN:
241  return _("assignment");
242  case PLPGSQL_STMT_IF:
243  return "IF";
244  case PLPGSQL_STMT_CASE:
245  return "CASE";
246  case PLPGSQL_STMT_LOOP:
247  return "LOOP";
248  case PLPGSQL_STMT_WHILE:
249  return "WHILE";
250  case PLPGSQL_STMT_FORI:
251  return _("FOR with integer loop variable");
252  case PLPGSQL_STMT_FORS:
253  return _("FOR over SELECT rows");
254  case PLPGSQL_STMT_FORC:
255  return _("FOR over cursor");
257  return _("FOREACH over array");
258  case PLPGSQL_STMT_EXIT:
259  return ((PLpgSQL_stmt_exit *) stmt)->is_exit ? "EXIT" : "CONTINUE";
260  case PLPGSQL_STMT_RETURN:
261  return "RETURN";
263  return "RETURN NEXT";
265  return "RETURN QUERY";
266  case PLPGSQL_STMT_RAISE:
267  return "RAISE";
268  case PLPGSQL_STMT_ASSERT:
269  return "ASSERT";
271  return _("SQL statement");
273  return "EXECUTE";
275  return _("FOR over EXECUTE statement");
277  return ((PLpgSQL_stmt_getdiag *) stmt)->is_stacked ?
278  "GET STACKED DIAGNOSTICS" : "GET DIAGNOSTICS";
279  case PLPGSQL_STMT_OPEN:
280  return "OPEN";
281  case PLPGSQL_STMT_FETCH:
282  return ((PLpgSQL_stmt_fetch *) stmt)->is_move ? "MOVE" : "FETCH";
283  case PLPGSQL_STMT_CLOSE:
284  return "CLOSE";
286  return "PERFORM";
287  case PLPGSQL_STMT_COMMIT:
288  return "COMMIT";
290  return "ROLLBACK";
291  }
292 
293  return "unknown";
294 }
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:442
#define _(x)
Definition: elog.c:84

Variable Documentation

◆ dump_indent

◆ ns_top

PLpgSQL_nsitem* ns_top = NULL
static

Definition at line 37 of file pl_funcs.c.

Referenced by plpgsql_ns_additem(), and plpgsql_ns_top().