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_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_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 1392 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().

1393 {
1394  dump_ind();
1395  printf("ASSERT ");
1396  dump_expr(stmt->cond);
1397  printf("\n");
1398 
1399  dump_indent += 2;
1400  if (stmt->message != NULL)
1401  {
1402  dump_ind();
1403  printf(" MESSAGE = ");
1404  dump_expr(stmt->message);
1405  printf("\n");
1406  }
1407  dump_indent -= 2;
1408 }
PLpgSQL_expr * message
Definition: plpgsql.h:732
static void dump_ind(void)
Definition: pl_funcs.c:784
static int dump_indent
Definition: pl_funcs.c:751
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1518
PLpgSQL_expr * cond
Definition: plpgsql.h:731

◆ dump_assign()

static void dump_assign ( PLpgSQL_stmt_assign stmt)
static

Definition at line 929 of file pl_funcs.c.

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

Referenced by dump_stmt().

930 {
931  dump_ind();
932  printf("ASSIGN var %d := ", stmt->varno);
933  dump_expr(stmt->expr);
934  printf("\n");
935 }
static void dump_ind(void)
Definition: pl_funcs.c:784
PLpgSQL_expr * expr
Definition: plpgsql.h:423
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1518

◆ dump_block()

static void dump_block ( PLpgSQL_stmt_block block)
static

Definition at line 888 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().

889 {
890  char *name;
891 
892  if (block->label == NULL)
893  name = "*unnamed*";
894  else
895  name = block->label;
896 
897  dump_ind();
898  printf("BLOCK <<%s>>\n", name);
899 
900  dump_stmts(block->body);
901 
902  if (block->exceptions)
903  {
904  ListCell *e;
905 
906  foreach(e, block->exceptions->exc_list)
907  {
909  PLpgSQL_condition *cond;
910 
911  dump_ind();
912  printf(" EXCEPTION WHEN ");
913  for (cond = exc->conditions; cond; cond = cond->next)
914  {
915  if (cond != exc->conditions)
916  printf(" OR ");
917  printf("%s", cond->condname);
918  }
919  printf(" THEN\n");
920  dump_stmts(exc->action);
921  }
922  }
923 
924  dump_ind();
925  printf(" END -- %s\n", name);
926 }
char * condname
Definition: plpgsql.h:377
struct PLpgSQL_condition * next
Definition: plpgsql.h:378
static void dump_ind(void)
Definition: pl_funcs.c:784
PLpgSQL_condition * conditions
Definition: plpgsql.h:397
#define lfirst(lc)
Definition: pg_list.h:106
PLpgSQL_exception_block * exceptions
Definition: plpgsql.h:412
const char * name
Definition: encode.c:521
e
Definition: preproc-init.c:82
static void dump_stmts(List *stmts)
Definition: pl_funcs.c:877

◆ dump_case()

static void dump_case ( PLpgSQL_stmt_case stmt)
static

Definition at line 968 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().

969 {
970  ListCell *l;
971 
972  dump_ind();
973  printf("CASE %d ", stmt->t_varno);
974  if (stmt->t_expr)
975  dump_expr(stmt->t_expr);
976  printf("\n");
977  dump_indent += 6;
978  foreach(l, stmt->case_when_list)
979  {
981 
982  dump_ind();
983  printf("WHEN ");
984  dump_expr(cwt->expr);
985  printf("\n");
986  dump_ind();
987  printf("THEN\n");
988  dump_indent += 2;
989  dump_stmts(cwt->stmts);
990  dump_indent -= 2;
991  }
992  if (stmt->have_else)
993  {
994  dump_ind();
995  printf("ELSE\n");
996  dump_indent += 2;
997  dump_stmts(stmt->else_stmts);
998  dump_indent -= 2;
999  }
1000  dump_indent -= 6;
1001  dump_ind();
1002  printf(" ENDCASE\n");
1003 }
List * else_stmts
Definition: plpgsql.h:490
PLpgSQL_expr * expr
Definition: plpgsql.h:499
List * case_when_list
Definition: plpgsql.h:488
static void dump_ind(void)
Definition: pl_funcs.c:784
#define lfirst(lc)
Definition: pg_list.h:106
static int dump_indent
Definition: pl_funcs.c:751
PLpgSQL_expr * t_expr
Definition: plpgsql.h:486
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1518
static void dump_stmts(List *stmts)
Definition: pl_funcs.c:877

◆ dump_close()

static void dump_close ( PLpgSQL_stmt_close stmt)
static

Definition at line 1227 of file pl_funcs.c.

References PLpgSQL_stmt_close::curvar, and dump_ind().

Referenced by dump_stmt().

1228 {
1229  dump_ind();
1230  printf("CLOSE curvar=%d\n", stmt->curvar);
1231 }
static void dump_ind(void)
Definition: pl_funcs.c:784

◆ dump_cursor_direction()

static void dump_cursor_direction ( PLpgSQL_stmt_fetch stmt)
static

Definition at line 1193 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().

1194 {
1195  dump_indent += 2;
1196  dump_ind();
1197  switch (stmt->direction)
1198  {
1199  case FETCH_FORWARD:
1200  printf(" FORWARD ");
1201  break;
1202  case FETCH_BACKWARD:
1203  printf(" BACKWARD ");
1204  break;
1205  case FETCH_ABSOLUTE:
1206  printf(" ABSOLUTE ");
1207  break;
1208  case FETCH_RELATIVE:
1209  printf(" RELATIVE ");
1210  break;
1211  default:
1212  printf("??? unknown cursor direction %d", stmt->direction);
1213  }
1214 
1215  if (stmt->expr)
1216  {
1217  dump_expr(stmt->expr);
1218  printf("\n");
1219  }
1220  else
1221  printf("%ld\n", stmt->how_many);
1222 
1223  dump_indent -= 2;
1224 }
FetchDirection direction
Definition: plpgsql.h:638
static void dump_ind(void)
Definition: pl_funcs.c:784
static int dump_indent
Definition: pl_funcs.c:751
PLpgSQL_expr * expr
Definition: plpgsql.h:640
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1518

◆ dump_dynexecute()

static void dump_dynexecute ( PLpgSQL_stmt_dynexecute stmt)
static

Definition at line 1430 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().

1431 {
1432  dump_ind();
1433  printf("EXECUTE ");
1434  dump_expr(stmt->query);
1435  printf("\n");
1436 
1437  dump_indent += 2;
1438  if (stmt->target != NULL)
1439  {
1440  dump_ind();
1441  printf(" INTO%s target = %d %s\n",
1442  stmt->strict ? " STRICT" : "",
1443  stmt->target->dno, stmt->target->refname);
1444  }
1445  if (stmt->params != NIL)
1446  {
1447  ListCell *lc;
1448  int i;
1449 
1450  dump_ind();
1451  printf(" USING\n");
1452  dump_indent += 2;
1453  i = 1;
1454  foreach(lc, stmt->params)
1455  {
1456  dump_ind();
1457  printf(" parameter %d: ", i++);
1458  dump_expr((PLpgSQL_expr *) lfirst(lc));
1459  printf("\n");
1460  }
1461  dump_indent -= 2;
1462  }
1463  dump_indent -= 2;
1464 }
#define NIL
Definition: pg_list.h:69
PLpgSQL_expr * query
Definition: plpgsql.h:757
static void dump_ind(void)
Definition: pl_funcs.c:784
#define lfirst(lc)
Definition: pg_list.h:106
static int dump_indent
Definition: pl_funcs.c:751
char * refname
Definition: plpgsql.h:212
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1518
int i
PLpgSQL_variable * target
Definition: plpgsql.h:760

◆ dump_dynfors()

static void dump_dynfors ( PLpgSQL_stmt_dynfors stmt)
static

Definition at line 1467 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().

1468 {
1469  dump_ind();
1470  printf("FORS %s EXECUTE ", stmt->var->refname);
1471  dump_expr(stmt->query);
1472  printf("\n");
1473  if (stmt->params != NIL)
1474  {
1475  ListCell *lc;
1476  int i;
1477 
1478  dump_indent += 2;
1479  dump_ind();
1480  printf(" USING\n");
1481  dump_indent += 2;
1482  i = 1;
1483  foreach(lc, stmt->params)
1484  {
1485  dump_ind();
1486  printf(" parameter $%d: ", i++);
1487  dump_expr((PLpgSQL_expr *) lfirst(lc));
1488  printf("\n");
1489  }
1490  dump_indent -= 4;
1491  }
1492  dump_stmts(stmt->body);
1493  dump_ind();
1494  printf(" ENDFORS\n");
1495 }
#define NIL
Definition: pg_list.h:69
PLpgSQL_expr * query
Definition: plpgsql.h:596
static void dump_ind(void)
Definition: pl_funcs.c:784
PLpgSQL_variable * var
Definition: plpgsql.h:593
#define lfirst(lc)
Definition: pg_list.h:106
static int dump_indent
Definition: pl_funcs.c:751
char * refname
Definition: plpgsql.h:212
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1518
int i
static void dump_stmts(List *stmts)
Definition: pl_funcs.c:877

◆ dump_execsql()

static void dump_execsql ( PLpgSQL_stmt_execsql stmt)
static

Definition at line 1411 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().

1412 {
1413  dump_ind();
1414  printf("EXECSQL ");
1415  dump_expr(stmt->sqlstmt);
1416  printf("\n");
1417 
1418  dump_indent += 2;
1419  if (stmt->target != NULL)
1420  {
1421  dump_ind();
1422  printf(" INTO%s target = %d %s\n",
1423  stmt->strict ? " STRICT" : "",
1424  stmt->target->dno, stmt->target->refname);
1425  }
1426  dump_indent -= 2;
1427 }
PLpgSQL_expr * sqlstmt
Definition: plpgsql.h:742
PLpgSQL_variable * target
Definition: plpgsql.h:747
static void dump_ind(void)
Definition: pl_funcs.c:784
static int dump_indent
Definition: pl_funcs.c:751
char * refname
Definition: plpgsql.h:212
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1518

◆ dump_exit()

static void dump_exit ( PLpgSQL_stmt_exit stmt)
static

Definition at line 1243 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().

1244 {
1245  dump_ind();
1246  printf("%s", stmt->is_exit ? "EXIT" : "CONTINUE");
1247  if (stmt->label != NULL)
1248  printf(" label='%s'", stmt->label);
1249  if (stmt->cond != NULL)
1250  {
1251  printf(" WHEN ");
1252  dump_expr(stmt->cond);
1253  }
1254  printf("\n");
1255 }
PLpgSQL_expr * cond
Definition: plpgsql.h:664
static void dump_ind(void)
Definition: pl_funcs.c:784
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1518

◆ dump_expr()

◆ dump_fetch()

static void dump_fetch ( PLpgSQL_stmt_fetch stmt)
static

Definition at line 1167 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().

1168 {
1169  dump_ind();
1170 
1171  if (!stmt->is_move)
1172  {
1173  printf("FETCH curvar=%d\n", stmt->curvar);
1174  dump_cursor_direction(stmt);
1175 
1176  dump_indent += 2;
1177  if (stmt->target != NULL)
1178  {
1179  dump_ind();
1180  printf(" target = %d %s\n",
1181  stmt->target->dno, stmt->target->refname);
1182  }
1183  dump_indent -= 2;
1184  }
1185  else
1186  {
1187  printf("MOVE curvar=%d\n", stmt->curvar);
1188  dump_cursor_direction(stmt);
1189  }
1190 }
static void dump_cursor_direction(PLpgSQL_stmt_fetch *stmt)
Definition: pl_funcs.c:1193
static void dump_ind(void)
Definition: pl_funcs.c:784
static int dump_indent
Definition: pl_funcs.c:751
char * refname
Definition: plpgsql.h:212
PLpgSQL_variable * target
Definition: plpgsql.h:636

◆ dump_forc()

static void dump_forc ( PLpgSQL_stmt_forc stmt)
static

Definition at line 1076 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().

1077 {
1078  dump_ind();
1079  printf("FORC %s ", stmt->var->refname);
1080  printf("curvar=%d\n", stmt->curvar);
1081 
1082  dump_indent += 2;
1083  if (stmt->argquery != NULL)
1084  {
1085  dump_ind();
1086  printf(" arguments = ");
1087  dump_expr(stmt->argquery);
1088  printf("\n");
1089  }
1090  dump_indent -= 2;
1091 
1092  dump_stmts(stmt->body);
1093 
1094  dump_ind();
1095  printf(" ENDFORC\n");
1096 }
PLpgSQL_variable * var
Definition: plpgsql.h:578
static void dump_ind(void)
Definition: pl_funcs.c:784
static int dump_indent
Definition: pl_funcs.c:751
char * refname
Definition: plpgsql.h:212
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1518
PLpgSQL_expr * argquery
Definition: plpgsql.h:582
static void dump_stmts(List *stmts)
Definition: pl_funcs.c:877

◆ dump_foreach_a()

static void dump_foreach_a ( PLpgSQL_stmt_foreach_a stmt)
static

Definition at line 1099 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().

1100 {
1101  dump_ind();
1102  printf("FOREACHA var %d ", stmt->varno);
1103  if (stmt->slice != 0)
1104  printf("SLICE %d ", stmt->slice);
1105  printf("IN ");
1106  dump_expr(stmt->expr);
1107  printf("\n");
1108 
1109  dump_stmts(stmt->body);
1110 
1111  dump_ind();
1112  printf(" ENDFOREACHA");
1113 }
PLpgSQL_expr * expr
Definition: plpgsql.h:610
static void dump_ind(void)
Definition: pl_funcs.c:784
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1518
static void dump_stmts(List *stmts)
Definition: pl_funcs.c:877

◆ dump_fori()

static void dump_fori ( PLpgSQL_stmt_fori stmt)
static

Definition at line 1032 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().

1033 {
1034  dump_ind();
1035  printf("FORI %s %s\n", stmt->var->refname, (stmt->reverse) ? "REVERSE" : "NORMAL");
1036 
1037  dump_indent += 2;
1038  dump_ind();
1039  printf(" lower = ");
1040  dump_expr(stmt->lower);
1041  printf("\n");
1042  dump_ind();
1043  printf(" upper = ");
1044  dump_expr(stmt->upper);
1045  printf("\n");
1046  if (stmt->step)
1047  {
1048  dump_ind();
1049  printf(" step = ");
1050  dump_expr(stmt->step);
1051  printf("\n");
1052  }
1053  dump_indent -= 2;
1054 
1055  dump_stmts(stmt->body);
1056 
1057  dump_ind();
1058  printf(" ENDFORI\n");
1059 }
char * refname
Definition: plpgsql.h:258
PLpgSQL_expr * lower
Definition: plpgsql.h:535
PLpgSQL_var * var
Definition: plpgsql.h:534
static void dump_ind(void)
Definition: pl_funcs.c:784
static int dump_indent
Definition: pl_funcs.c:751
PLpgSQL_expr * step
Definition: plpgsql.h:537
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1518
PLpgSQL_expr * upper
Definition: plpgsql.h:536
static void dump_stmts(List *stmts)
Definition: pl_funcs.c:877

◆ dump_fors()

static void dump_fors ( PLpgSQL_stmt_fors stmt)
static

Definition at line 1062 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().

1063 {
1064  dump_ind();
1065  printf("FORS %s ", stmt->var->refname);
1066  dump_expr(stmt->query);
1067  printf("\n");
1068 
1069  dump_stmts(stmt->body);
1070 
1071  dump_ind();
1072  printf(" ENDFORS\n");
1073 }
PLpgSQL_variable * var
Definition: plpgsql.h:564
static void dump_ind(void)
Definition: pl_funcs.c:784
char * refname
Definition: plpgsql.h:212
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1518
PLpgSQL_expr * query
Definition: plpgsql.h:567
static void dump_stmts(List *stmts)
Definition: pl_funcs.c:877

◆ dump_getdiag()

static void dump_getdiag ( PLpgSQL_stmt_getdiag stmt)
static

Definition at line 1498 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().

1499 {
1500  ListCell *lc;
1501 
1502  dump_ind();
1503  printf("GET %s DIAGNOSTICS ", stmt->is_stacked ? "STACKED" : "CURRENT");
1504  foreach(lc, stmt->diag_items)
1505  {
1506  PLpgSQL_diag_item *diag_item = (PLpgSQL_diag_item *) lfirst(lc);
1507 
1508  if (lc != list_head(stmt->diag_items))
1509  printf(", ");
1510 
1511  printf("{var %d} = %s", diag_item->target,
1512  plpgsql_getdiag_kindname(diag_item->kind));
1513  }
1514  printf("\n");
1515 }
PLpgSQL_getdiag_kind kind
Definition: plpgsql.h:441
static ListCell * list_head(const List *l)
Definition: pg_list.h:77
static void dump_ind(void)
Definition: pl_funcs.c:784
#define lfirst(lc)
Definition: pg_list.h:106
const char * plpgsql_getdiag_kindname(PLpgSQL_getdiag_kind kind)
Definition: pl_funcs.c:296

◆ dump_if()

static void dump_if ( PLpgSQL_stmt_if stmt)
static

Definition at line 938 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().

939 {
940  ListCell *l;
941 
942  dump_ind();
943  printf("IF ");
944  dump_expr(stmt->cond);
945  printf(" THEN\n");
946  dump_stmts(stmt->then_body);
947  foreach(l, stmt->elsif_list)
948  {
950 
951  dump_ind();
952  printf(" ELSIF ");
953  dump_expr(elif->cond);
954  printf(" THEN\n");
955  dump_stmts(elif->stmts);
956  }
957  if (stmt->else_body != NIL)
958  {
959  dump_ind();
960  printf(" ELSE\n");
961  dump_stmts(stmt->else_body);
962  }
963  dump_ind();
964  printf(" ENDIF\n");
965 }
#define NIL
Definition: pg_list.h:69
PLpgSQL_expr * cond
Definition: plpgsql.h:463
List * then_body
Definition: plpgsql.h:464
List * elsif_list
Definition: plpgsql.h:465
List * stmts
Definition: plpgsql.h:476
PLpgSQL_expr * cond
Definition: plpgsql.h:475
static void dump_ind(void)
Definition: pl_funcs.c:784
#define lfirst(lc)
Definition: pg_list.h:106
List * else_body
Definition: plpgsql.h:466
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1518
static void dump_stmts(List *stmts)
Definition: pl_funcs.c:877

◆ dump_ind()

static void dump_ind ( void  )
static

◆ dump_loop()

static void dump_loop ( PLpgSQL_stmt_loop stmt)
static

Definition at line 1006 of file pl_funcs.c.

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

Referenced by dump_stmt().

1007 {
1008  dump_ind();
1009  printf("LOOP\n");
1010 
1011  dump_stmts(stmt->body);
1012 
1013  dump_ind();
1014  printf(" ENDLOOP\n");
1015 }
static void dump_ind(void)
Definition: pl_funcs.c:784
static void dump_stmts(List *stmts)
Definition: pl_funcs.c:877

◆ dump_open()

static void dump_open ( PLpgSQL_stmt_open stmt)
static

Definition at line 1116 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().

1117 {
1118  dump_ind();
1119  printf("OPEN curvar=%d\n", stmt->curvar);
1120 
1121  dump_indent += 2;
1122  if (stmt->argquery != NULL)
1123  {
1124  dump_ind();
1125  printf(" arguments = '");
1126  dump_expr(stmt->argquery);
1127  printf("'\n");
1128  }
1129  if (stmt->query != NULL)
1130  {
1131  dump_ind();
1132  printf(" query = '");
1133  dump_expr(stmt->query);
1134  printf("'\n");
1135  }
1136  if (stmt->dynquery != NULL)
1137  {
1138  dump_ind();
1139  printf(" execute = '");
1140  dump_expr(stmt->dynquery);
1141  printf("'\n");
1142 
1143  if (stmt->params != NIL)
1144  {
1145  ListCell *lc;
1146  int i;
1147 
1148  dump_indent += 2;
1149  dump_ind();
1150  printf(" USING\n");
1151  dump_indent += 2;
1152  i = 1;
1153  foreach(lc, stmt->params)
1154  {
1155  dump_ind();
1156  printf(" parameter $%d: ", i++);
1157  dump_expr((PLpgSQL_expr *) lfirst(lc));
1158  printf("\n");
1159  }
1160  dump_indent -= 4;
1161  }
1162  }
1163  dump_indent -= 2;
1164 }
#define NIL
Definition: pg_list.h:69
PLpgSQL_expr * dynquery
Definition: plpgsql.h:625
PLpgSQL_expr * query
Definition: plpgsql.h:624
static void dump_ind(void)
Definition: pl_funcs.c:784
#define lfirst(lc)
Definition: pg_list.h:106
static int dump_indent
Definition: pl_funcs.c:751
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1518
PLpgSQL_expr * argquery
Definition: plpgsql.h:623
int i

◆ dump_perform()

static void dump_perform ( PLpgSQL_stmt_perform stmt)
static

Definition at line 1234 of file pl_funcs.c.

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

Referenced by dump_stmt().

1235 {
1236  dump_ind();
1237  printf("PERFORM expr = ");
1238  dump_expr(stmt->expr);
1239  printf("\n");
1240 }
PLpgSQL_expr * expr
Definition: plpgsql.h:433
static void dump_ind(void)
Definition: pl_funcs.c:784
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1518

◆ dump_raise()

static void dump_raise ( PLpgSQL_stmt_raise stmt)
static

Definition at line 1323 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().

1324 {
1325  ListCell *lc;
1326  int i = 0;
1327 
1328  dump_ind();
1329  printf("RAISE level=%d", stmt->elog_level);
1330  if (stmt->condname)
1331  printf(" condname='%s'", stmt->condname);
1332  if (stmt->message)
1333  printf(" message='%s'", stmt->message);
1334  printf("\n");
1335  dump_indent += 2;
1336  foreach(lc, stmt->params)
1337  {
1338  dump_ind();
1339  printf(" parameter %d: ", i++);
1340  dump_expr((PLpgSQL_expr *) lfirst(lc));
1341  printf("\n");
1342  }
1343  if (stmt->options)
1344  {
1345  dump_ind();
1346  printf(" USING\n");
1347  dump_indent += 2;
1348  foreach(lc, stmt->options)
1349  {
1351 
1352  dump_ind();
1353  switch (opt->opt_type)
1354  {
1356  printf(" ERRCODE = ");
1357  break;
1359  printf(" MESSAGE = ");
1360  break;
1362  printf(" DETAIL = ");
1363  break;
1365  printf(" HINT = ");
1366  break;
1368  printf(" COLUMN = ");
1369  break;
1371  printf(" CONSTRAINT = ");
1372  break;
1374  printf(" DATATYPE = ");
1375  break;
1377  printf(" TABLE = ");
1378  break;
1380  printf(" SCHEMA = ");
1381  break;
1382  }
1383  dump_expr(opt->expr);
1384  printf("\n");
1385  }
1386  dump_indent -= 2;
1387  }
1388  dump_indent -= 2;
1389 }
PLpgSQL_raise_option_type opt_type
Definition: plpgsql.h:720
static void dump_ind(void)
Definition: pl_funcs.c:784
#define lfirst(lc)
Definition: pg_list.h:106
static int dump_indent
Definition: pl_funcs.c:751
PLpgSQL_expr * expr
Definition: plpgsql.h:721
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1518
int i

◆ dump_return()

static void dump_return ( PLpgSQL_stmt_return stmt)
static

Definition at line 1258 of file pl_funcs.c.

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

Referenced by dump_stmt().

1259 {
1260  dump_ind();
1261  printf("RETURN ");
1262  if (stmt->retvarno >= 0)
1263  printf("variable %d", stmt->retvarno);
1264  else if (stmt->expr != NULL)
1265  dump_expr(stmt->expr);
1266  else
1267  printf("NULL");
1268  printf("\n");
1269 }
PLpgSQL_expr * expr
Definition: plpgsql.h:674
static void dump_ind(void)
Definition: pl_funcs.c:784
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1518

◆ dump_return_next()

static void dump_return_next ( PLpgSQL_stmt_return_next stmt)
static

Definition at line 1272 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().

1273 {
1274  dump_ind();
1275  printf("RETURN NEXT ");
1276  if (stmt->retvarno >= 0)
1277  printf("variable %d", stmt->retvarno);
1278  else if (stmt->expr != NULL)
1279  dump_expr(stmt->expr);
1280  else
1281  printf("NULL");
1282  printf("\n");
1283 }
PLpgSQL_expr * expr
Definition: plpgsql.h:685
static void dump_ind(void)
Definition: pl_funcs.c:784
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1518

◆ dump_return_query()

static void dump_return_query ( PLpgSQL_stmt_return_query stmt)
static

Definition at line 1286 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().

1287 {
1288  dump_ind();
1289  if (stmt->query)
1290  {
1291  printf("RETURN QUERY ");
1292  dump_expr(stmt->query);
1293  printf("\n");
1294  }
1295  else
1296  {
1297  printf("RETURN QUERY EXECUTE ");
1298  dump_expr(stmt->dynquery);
1299  printf("\n");
1300  if (stmt->params != NIL)
1301  {
1302  ListCell *lc;
1303  int i;
1304 
1305  dump_indent += 2;
1306  dump_ind();
1307  printf(" USING\n");
1308  dump_indent += 2;
1309  i = 1;
1310  foreach(lc, stmt->params)
1311  {
1312  dump_ind();
1313  printf(" parameter $%d: ", i++);
1314  dump_expr((PLpgSQL_expr *) lfirst(lc));
1315  printf("\n");
1316  }
1317  dump_indent -= 4;
1318  }
1319  }
1320 }
#define NIL
Definition: pg_list.h:69
PLpgSQL_expr * query
Definition: plpgsql.h:696
static void dump_ind(void)
Definition: pl_funcs.c:784
#define lfirst(lc)
Definition: pg_list.h:106
static int dump_indent
Definition: pl_funcs.c:751
PLpgSQL_expr * dynquery
Definition: plpgsql.h:697
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1518
int i

◆ dump_stmt()

static void dump_stmt ( PLpgSQL_stmt stmt)
static

Definition at line 793 of file pl_funcs.c.

References PLpgSQL_stmt::cmd_type, PLpgSQL_stmt_perform::cmd_type, dump_assert(), dump_assign(), dump_block(), dump_case(), dump_close(), 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_while(), elog, ERROR, PLpgSQL_stmt::lineno, PLPGSQL_STMT_ASSERT, PLPGSQL_STMT_ASSIGN, PLPGSQL_STMT_BLOCK, PLPGSQL_STMT_CASE, PLPGSQL_STMT_CLOSE, 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, and PLPGSQL_STMT_WHILE.

Referenced by dump_stmts().

794 {
795  printf("%3d:", stmt->lineno);
796  switch (stmt->cmd_type)
797  {
798  case PLPGSQL_STMT_BLOCK:
799  dump_block((PLpgSQL_stmt_block *) stmt);
800  break;
801  case PLPGSQL_STMT_ASSIGN:
803  break;
804  case PLPGSQL_STMT_IF:
805  dump_if((PLpgSQL_stmt_if *) stmt);
806  break;
807  case PLPGSQL_STMT_CASE:
808  dump_case((PLpgSQL_stmt_case *) stmt);
809  break;
810  case PLPGSQL_STMT_LOOP:
811  dump_loop((PLpgSQL_stmt_loop *) stmt);
812  break;
813  case PLPGSQL_STMT_WHILE:
814  dump_while((PLpgSQL_stmt_while *) stmt);
815  break;
816  case PLPGSQL_STMT_FORI:
817  dump_fori((PLpgSQL_stmt_fori *) stmt);
818  break;
819  case PLPGSQL_STMT_FORS:
820  dump_fors((PLpgSQL_stmt_fors *) stmt);
821  break;
822  case PLPGSQL_STMT_FORC:
823  dump_forc((PLpgSQL_stmt_forc *) stmt);
824  break;
827  break;
828  case PLPGSQL_STMT_EXIT:
829  dump_exit((PLpgSQL_stmt_exit *) stmt);
830  break;
831  case PLPGSQL_STMT_RETURN:
833  break;
836  break;
839  break;
840  case PLPGSQL_STMT_RAISE:
841  dump_raise((PLpgSQL_stmt_raise *) stmt);
842  break;
843  case PLPGSQL_STMT_ASSERT:
845  break;
848  break;
851  break;
854  break;
857  break;
858  case PLPGSQL_STMT_OPEN:
859  dump_open((PLpgSQL_stmt_open *) stmt);
860  break;
861  case PLPGSQL_STMT_FETCH:
862  dump_fetch((PLpgSQL_stmt_fetch *) stmt);
863  break;
864  case PLPGSQL_STMT_CLOSE:
865  dump_close((PLpgSQL_stmt_close *) stmt);
866  break;
869  break;
870  default:
871  elog(ERROR, "unrecognized cmd_type: %d", stmt->cmd_type);
872  break;
873  }
874 }
int lineno
Definition: plpgsql.h:368
static void dump_raise(PLpgSQL_stmt_raise *stmt)
Definition: pl_funcs.c:1323
static void dump_perform(PLpgSQL_stmt_perform *stmt)
Definition: pl_funcs.c:1234
static void dump_forc(PLpgSQL_stmt_forc *stmt)
Definition: pl_funcs.c:1076
static void dump_fors(PLpgSQL_stmt_fors *stmt)
Definition: pl_funcs.c:1062
static void dump_fetch(PLpgSQL_stmt_fetch *stmt)
Definition: pl_funcs.c:1167
#define ERROR
Definition: elog.h:43
static void dump_case(PLpgSQL_stmt_case *stmt)
Definition: pl_funcs.c:968
static void dump_getdiag(PLpgSQL_stmt_getdiag *stmt)
Definition: pl_funcs.c:1498
static void dump_if(PLpgSQL_stmt_if *stmt)
Definition: pl_funcs.c:938
static void dump_return_query(PLpgSQL_stmt_return_query *stmt)
Definition: pl_funcs.c:1286
static void dump_return(PLpgSQL_stmt_return *stmt)
Definition: pl_funcs.c:1258
static void dump_return_next(PLpgSQL_stmt_return_next *stmt)
Definition: pl_funcs.c:1272
static void dump_loop(PLpgSQL_stmt_loop *stmt)
Definition: pl_funcs.c:1006
static void dump_close(PLpgSQL_stmt_close *stmt)
Definition: pl_funcs.c:1227
static void dump_while(PLpgSQL_stmt_while *stmt)
Definition: pl_funcs.c:1018
static void dump_execsql(PLpgSQL_stmt_execsql *stmt)
Definition: pl_funcs.c:1411
static void dump_dynexecute(PLpgSQL_stmt_dynexecute *stmt)
Definition: pl_funcs.c:1430
static void dump_dynfors(PLpgSQL_stmt_dynfors *stmt)
Definition: pl_funcs.c:1467
static void dump_block(PLpgSQL_stmt_block *block)
Definition: pl_funcs.c:888
static void dump_foreach_a(PLpgSQL_stmt_foreach_a *stmt)
Definition: pl_funcs.c:1099
static void dump_assert(PLpgSQL_stmt_assert *stmt)
Definition: pl_funcs.c:1392
static void dump_open(PLpgSQL_stmt_open *stmt)
Definition: pl_funcs.c:1116
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:367
static void dump_fori(PLpgSQL_stmt_fori *stmt)
Definition: pl_funcs.c:1032
#define elog
Definition: elog.h:219
static void dump_assign(PLpgSQL_stmt_assign *stmt)
Definition: pl_funcs.c:929
static void dump_exit(PLpgSQL_stmt_exit *stmt)
Definition: pl_funcs.c:1243

◆ dump_stmts()

static void dump_stmts ( List stmts)
static

Definition at line 877 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().

878 {
879  ListCell *s;
880 
881  dump_indent += 2;
882  foreach(s, stmts)
883  dump_stmt((PLpgSQL_stmt *) lfirst(s));
884  dump_indent -= 2;
885 }
#define lfirst(lc)
Definition: pg_list.h:106
static int dump_indent
Definition: pl_funcs.c:751
static void dump_stmt(PLpgSQL_stmt *stmt)
Definition: pl_funcs.c:793

◆ dump_while()

static void dump_while ( PLpgSQL_stmt_while stmt)
static

Definition at line 1018 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().

1019 {
1020  dump_ind();
1021  printf("WHILE ");
1022  dump_expr(stmt->cond);
1023  printf("\n");
1024 
1025  dump_stmts(stmt->body);
1026 
1027  dump_ind();
1028  printf(" ENDWHILE\n");
1029 }
PLpgSQL_expr * cond
Definition: plpgsql.h:522
static void dump_ind(void)
Definition: pl_funcs.c:784
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1518
static void dump_stmts(List *stmts)
Definition: pl_funcs.c:877

◆ free_assert()

static void free_assert ( PLpgSQL_stmt_assert stmt)
static

Definition at line 642 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().

643 {
644  free_expr(stmt->cond);
645  free_expr(stmt->message);
646 }
PLpgSQL_expr * message
Definition: plpgsql.h:732
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:685
PLpgSQL_expr * cond
Definition: plpgsql.h:731

◆ free_assign()

static void free_assign ( PLpgSQL_stmt_assign stmt)
static

Definition at line 481 of file pl_funcs.c.

References PLpgSQL_stmt_assign::expr, and free_expr().

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

482 {
483  free_expr(stmt->expr);
484 }
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:685
PLpgSQL_expr * expr
Definition: plpgsql.h:423

◆ free_block()

static void free_block ( PLpgSQL_stmt_block block)
static

Definition at line 464 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().

465 {
466  free_stmts(block->body);
467  if (block->exceptions)
468  {
469  ListCell *e;
470 
471  foreach(e, block->exceptions->exc_list)
472  {
474 
475  free_stmts(exc->action);
476  }
477  }
478 }
static void free_stmts(List *stmts)
Definition: pl_funcs.c:453
#define lfirst(lc)
Definition: pg_list.h:106
PLpgSQL_exception_block * exceptions
Definition: plpgsql.h:412
e
Definition: preproc-init.c:82

◆ free_case()

static void free_case ( PLpgSQL_stmt_case stmt)
static

Definition at line 504 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().

505 {
506  ListCell *l;
507 
508  free_expr(stmt->t_expr);
509  foreach(l, stmt->case_when_list)
510  {
512 
513  free_expr(cwt->expr);
514  free_stmts(cwt->stmts);
515  }
516  free_stmts(stmt->else_stmts);
517 }
List * else_stmts
Definition: plpgsql.h:490
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:685
PLpgSQL_expr * expr
Definition: plpgsql.h:499
List * case_when_list
Definition: plpgsql.h:488
static void free_stmts(List *stmts)
Definition: pl_funcs.c:453
#define lfirst(lc)
Definition: pg_list.h:106
PLpgSQL_expr * t_expr
Definition: plpgsql.h:486

◆ free_close()

static void free_close ( PLpgSQL_stmt_close stmt)
static

Definition at line 583 of file pl_funcs.c.

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

584 {
585 }

◆ free_dynexecute()

static void free_dynexecute ( PLpgSQL_stmt_dynexecute stmt)
static

Definition at line 655 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().

656 {
657  ListCell *lc;
658 
659  free_expr(stmt->query);
660  foreach(lc, stmt->params)
661  {
662  free_expr((PLpgSQL_expr *) lfirst(lc));
663  }
664 }
PLpgSQL_expr * query
Definition: plpgsql.h:757
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:685
#define lfirst(lc)
Definition: pg_list.h:106

◆ free_dynfors()

static void free_dynfors ( PLpgSQL_stmt_dynfors stmt)
static

Definition at line 667 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().

668 {
669  ListCell *lc;
670 
671  free_stmts(stmt->body);
672  free_expr(stmt->query);
673  foreach(lc, stmt->params)
674  {
675  free_expr((PLpgSQL_expr *) lfirst(lc));
676  }
677 }
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:685
PLpgSQL_expr * query
Definition: plpgsql.h:596
static void free_stmts(List *stmts)
Definition: pl_funcs.c:453
#define lfirst(lc)
Definition: pg_list.h:106

◆ free_execsql()

static void free_execsql ( PLpgSQL_stmt_execsql stmt)
static

Definition at line 649 of file pl_funcs.c.

References free_expr(), and PLpgSQL_stmt_execsql::sqlstmt.

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

650 {
651  free_expr(stmt->sqlstmt);
652 }
PLpgSQL_expr * sqlstmt
Definition: plpgsql.h:742
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:685

◆ free_exit()

static void free_exit ( PLpgSQL_stmt_exit stmt)
static

Definition at line 594 of file pl_funcs.c.

References PLpgSQL_stmt_exit::cond, and free_expr().

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

595 {
596  free_expr(stmt->cond);
597 }
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:685
PLpgSQL_expr * cond
Definition: plpgsql.h:664

◆ free_expr()

static void free_expr ( PLpgSQL_expr expr)
static

◆ free_fetch()

static void free_fetch ( PLpgSQL_stmt_fetch stmt)
static

Definition at line 577 of file pl_funcs.c.

References PLpgSQL_stmt_fetch::expr, and free_expr().

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

578 {
579  free_expr(stmt->expr);
580 }
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:685
PLpgSQL_expr * expr
Definition: plpgsql.h:640

◆ free_forc()

static void free_forc ( PLpgSQL_stmt_forc stmt)
static

Definition at line 549 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().

550 {
551  free_stmts(stmt->body);
552  free_expr(stmt->argquery);
553 }
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:685
static void free_stmts(List *stmts)
Definition: pl_funcs.c:453
PLpgSQL_expr * argquery
Definition: plpgsql.h:582

◆ free_foreach_a()

static void free_foreach_a ( PLpgSQL_stmt_foreach_a stmt)
static

Definition at line 556 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().

557 {
558  free_expr(stmt->expr);
559  free_stmts(stmt->body);
560 }
PLpgSQL_expr * expr
Definition: plpgsql.h:610
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:685
static void free_stmts(List *stmts)
Definition: pl_funcs.c:453

◆ free_fori()

static void free_fori ( PLpgSQL_stmt_fori stmt)
static

Definition at line 533 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().

534 {
535  free_expr(stmt->lower);
536  free_expr(stmt->upper);
537  free_expr(stmt->step);
538  free_stmts(stmt->body);
539 }
PLpgSQL_expr * lower
Definition: plpgsql.h:535
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:685
static void free_stmts(List *stmts)
Definition: pl_funcs.c:453
PLpgSQL_expr * step
Definition: plpgsql.h:537
PLpgSQL_expr * upper
Definition: plpgsql.h:536

◆ free_fors()

static void free_fors ( PLpgSQL_stmt_fors stmt)
static

Definition at line 542 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().

543 {
544  free_stmts(stmt->body);
545  free_expr(stmt->query);
546 }
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:685
static void free_stmts(List *stmts)
Definition: pl_funcs.c:453
PLpgSQL_expr * query
Definition: plpgsql.h:567

◆ free_getdiag()

static void free_getdiag ( PLpgSQL_stmt_getdiag stmt)
static

Definition at line 680 of file pl_funcs.c.

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

681 {
682 }

◆ free_if()

static void free_if ( PLpgSQL_stmt_if stmt)
static

Definition at line 487 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().

488 {
489  ListCell *l;
490 
491  free_expr(stmt->cond);
492  free_stmts(stmt->then_body);
493  foreach(l, stmt->elsif_list)
494  {
496 
497  free_expr(elif->cond);
498  free_stmts(elif->stmts);
499  }
500  free_stmts(stmt->else_body);
501 }
PLpgSQL_expr * cond
Definition: plpgsql.h:463
List * then_body
Definition: plpgsql.h:464
List * elsif_list
Definition: plpgsql.h:465
List * stmts
Definition: plpgsql.h:476
PLpgSQL_expr * cond
Definition: plpgsql.h:475
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:685
static void free_stmts(List *stmts)
Definition: pl_funcs.c:453
#define lfirst(lc)
Definition: pg_list.h:106
List * else_body
Definition: plpgsql.h:466

◆ free_loop()

static void free_loop ( PLpgSQL_stmt_loop stmt)
static

Definition at line 520 of file pl_funcs.c.

References PLpgSQL_stmt_loop::body, and free_stmts().

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

521 {
522  free_stmts(stmt->body);
523 }
static void free_stmts(List *stmts)
Definition: pl_funcs.c:453

◆ free_open()

static void free_open ( PLpgSQL_stmt_open stmt)
static

Definition at line 563 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().

564 {
565  ListCell *lc;
566 
567  free_expr(stmt->argquery);
568  free_expr(stmt->query);
569  free_expr(stmt->dynquery);
570  foreach(lc, stmt->params)
571  {
572  free_expr((PLpgSQL_expr *) lfirst(lc));
573  }
574 }
PLpgSQL_expr * dynquery
Definition: plpgsql.h:625
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:685
PLpgSQL_expr * query
Definition: plpgsql.h:624
#define lfirst(lc)
Definition: pg_list.h:106
PLpgSQL_expr * argquery
Definition: plpgsql.h:623

◆ free_perform()

static void free_perform ( PLpgSQL_stmt_perform stmt)
static

Definition at line 588 of file pl_funcs.c.

References PLpgSQL_stmt_perform::expr, and free_expr().

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

589 {
590  free_expr(stmt->expr);
591 }
PLpgSQL_expr * expr
Definition: plpgsql.h:433
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:685

◆ free_raise()

static void free_raise ( PLpgSQL_stmt_raise stmt)
static

Definition at line 625 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().

626 {
627  ListCell *lc;
628 
629  foreach(lc, stmt->params)
630  {
631  free_expr((PLpgSQL_expr *) lfirst(lc));
632  }
633  foreach(lc, stmt->options)
634  {
636 
637  free_expr(opt->expr);
638  }
639 }
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:685
#define lfirst(lc)
Definition: pg_list.h:106
PLpgSQL_expr * expr
Definition: plpgsql.h:721

◆ free_return()

static void free_return ( PLpgSQL_stmt_return stmt)
static

Definition at line 600 of file pl_funcs.c.

References PLpgSQL_stmt_return::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:674
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:685

◆ free_return_next()

static void free_return_next ( PLpgSQL_stmt_return_next stmt)
static

Definition at line 606 of file pl_funcs.c.

References PLpgSQL_stmt_return_next::expr, and free_expr().

Referenced by free_stmt(), and plpgsql_getdiag_kindname().

607 {
608  free_expr(stmt->expr);
609 }
PLpgSQL_expr * expr
Definition: plpgsql.h:685
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:685

◆ free_return_query()

static void free_return_query ( PLpgSQL_stmt_return_query stmt)
static

Definition at line 612 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().

613 {
614  ListCell *lc;
615 
616  free_expr(stmt->query);
617  free_expr(stmt->dynquery);
618  foreach(lc, stmt->params)
619  {
620  free_expr((PLpgSQL_expr *) lfirst(lc));
621  }
622 }
PLpgSQL_expr * query
Definition: plpgsql.h:696
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:685
#define lfirst(lc)
Definition: pg_list.h:106
PLpgSQL_expr * dynquery
Definition: plpgsql.h:697

◆ free_stmt()

static void free_stmt ( PLpgSQL_stmt stmt)
static

Definition at line 370 of file pl_funcs.c.

References PLpgSQL_stmt::cmd_type, PLpgSQL_stmt_perform::cmd_type, elog, ERROR, free_assert(), free_assign(), free_block(), free_case(), free_close(), 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_while(), PLPGSQL_STMT_ASSERT, PLPGSQL_STMT_ASSIGN, PLPGSQL_STMT_BLOCK, PLPGSQL_STMT_CASE, PLPGSQL_STMT_CLOSE, 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, and PLPGSQL_STMT_WHILE.

Referenced by free_stmts(), and plpgsql_getdiag_kindname().

371 {
372  switch (stmt->cmd_type)
373  {
374  case PLPGSQL_STMT_BLOCK:
375  free_block((PLpgSQL_stmt_block *) stmt);
376  break;
377  case PLPGSQL_STMT_ASSIGN:
379  break;
380  case PLPGSQL_STMT_IF:
381  free_if((PLpgSQL_stmt_if *) stmt);
382  break;
383  case PLPGSQL_STMT_CASE:
384  free_case((PLpgSQL_stmt_case *) stmt);
385  break;
386  case PLPGSQL_STMT_LOOP:
387  free_loop((PLpgSQL_stmt_loop *) stmt);
388  break;
389  case PLPGSQL_STMT_WHILE:
390  free_while((PLpgSQL_stmt_while *) stmt);
391  break;
392  case PLPGSQL_STMT_FORI:
393  free_fori((PLpgSQL_stmt_fori *) stmt);
394  break;
395  case PLPGSQL_STMT_FORS:
396  free_fors((PLpgSQL_stmt_fors *) stmt);
397  break;
398  case PLPGSQL_STMT_FORC:
399  free_forc((PLpgSQL_stmt_forc *) stmt);
400  break;
403  break;
404  case PLPGSQL_STMT_EXIT:
405  free_exit((PLpgSQL_stmt_exit *) stmt);
406  break;
407  case PLPGSQL_STMT_RETURN:
409  break;
412  break;
415  break;
416  case PLPGSQL_STMT_RAISE:
417  free_raise((PLpgSQL_stmt_raise *) stmt);
418  break;
419  case PLPGSQL_STMT_ASSERT:
421  break;
424  break;
427  break;
430  break;
433  break;
434  case PLPGSQL_STMT_OPEN:
435  free_open((PLpgSQL_stmt_open *) stmt);
436  break;
437  case PLPGSQL_STMT_FETCH:
438  free_fetch((PLpgSQL_stmt_fetch *) stmt);
439  break;
440  case PLPGSQL_STMT_CLOSE:
441  free_close((PLpgSQL_stmt_close *) stmt);
442  break;
445  break;
446  default:
447  elog(ERROR, "unrecognized cmd_type: %d", stmt->cmd_type);
448  break;
449  }
450 }
static void free_assert(PLpgSQL_stmt_assert *stmt)
Definition: pl_funcs.c:642
static void free_dynexecute(PLpgSQL_stmt_dynexecute *stmt)
Definition: pl_funcs.c:655
static void free_raise(PLpgSQL_stmt_raise *stmt)
Definition: pl_funcs.c:625
static void free_open(PLpgSQL_stmt_open *stmt)
Definition: pl_funcs.c:563
static void free_return(PLpgSQL_stmt_return *stmt)
Definition: pl_funcs.c:600
static void free_loop(PLpgSQL_stmt_loop *stmt)
Definition: pl_funcs.c:520
static void free_dynfors(PLpgSQL_stmt_dynfors *stmt)
Definition: pl_funcs.c:667
static void free_assign(PLpgSQL_stmt_assign *stmt)
Definition: pl_funcs.c:481
static void free_getdiag(PLpgSQL_stmt_getdiag *stmt)
Definition: pl_funcs.c:680
#define ERROR
Definition: elog.h:43
static void free_fetch(PLpgSQL_stmt_fetch *stmt)
Definition: pl_funcs.c:577
static void free_close(PLpgSQL_stmt_close *stmt)
Definition: pl_funcs.c:583
static void free_case(PLpgSQL_stmt_case *stmt)
Definition: pl_funcs.c:504
static void free_fori(PLpgSQL_stmt_fori *stmt)
Definition: pl_funcs.c:533
static void free_perform(PLpgSQL_stmt_perform *stmt)
Definition: pl_funcs.c:588
static void free_return_next(PLpgSQL_stmt_return_next *stmt)
Definition: pl_funcs.c:606
static void free_fors(PLpgSQL_stmt_fors *stmt)
Definition: pl_funcs.c:542
static void free_exit(PLpgSQL_stmt_exit *stmt)
Definition: pl_funcs.c:594
static void free_if(PLpgSQL_stmt_if *stmt)
Definition: pl_funcs.c:487
static void free_return_query(PLpgSQL_stmt_return_query *stmt)
Definition: pl_funcs.c:612
static void free_execsql(PLpgSQL_stmt_execsql *stmt)
Definition: pl_funcs.c:649
static void free_forc(PLpgSQL_stmt_forc *stmt)
Definition: pl_funcs.c:549
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:367
static void free_while(PLpgSQL_stmt_while *stmt)
Definition: pl_funcs.c:526
#define elog
Definition: elog.h:219
static void free_foreach_a(PLpgSQL_stmt_foreach_a *stmt)
Definition: pl_funcs.c:556
static void free_block(PLpgSQL_stmt_block *block)
Definition: pl_funcs.c:464

◆ free_stmts()

static void free_stmts ( List stmts)
static

Definition at line 453 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().

454 {
455  ListCell *s;
456 
457  foreach(s, stmts)
458  {
459  free_stmt((PLpgSQL_stmt *) lfirst(s));
460  }
461 }
#define lfirst(lc)
Definition: pg_list.h:106
static void free_stmt(PLpgSQL_stmt *stmt)
Definition: pl_funcs.c:370

◆ free_while()

static void free_while ( PLpgSQL_stmt_while stmt)
static

Definition at line 526 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().

527 {
528  free_expr(stmt->cond);
529  free_stmts(stmt->body);
530 }
PLpgSQL_expr * cond
Definition: plpgsql.h:522
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:685
static void free_stmts(List *stmts)
Definition: pl_funcs.c:453

◆ plpgsql_dumptree()

void plpgsql_dumptree ( PLpgSQL_function func)

Definition at line 1524 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_REC, PLPGSQL_DTYPE_RECFIELD, PLPGSQL_DTYPE_ROW, PLPGSQL_DTYPE_VAR, PLpgSQL_var::refname, PLpgSQL_row::refname, PLpgSQL_type::typname, PLpgSQL_type::typoid, and PLpgSQL_row::varnos.

Referenced by do_compile().

1525 {
1526  int i;
1527  PLpgSQL_datum *d;
1528 
1529  printf("\nExecution tree of successfully compiled PL/pgSQL function %s:\n",
1530  func->fn_signature);
1531 
1532  printf("\nFunction's data area:\n");
1533  for (i = 0; i < func->ndatums; i++)
1534  {
1535  d = func->datums[i];
1536 
1537  printf(" entry %d: ", i);
1538  switch (d->dtype)
1539  {
1540  case PLPGSQL_DTYPE_VAR:
1541  {
1542  PLpgSQL_var *var = (PLpgSQL_var *) d;
1543 
1544  printf("VAR %-16s type %s (typoid %u) atttypmod %d\n",
1545  var->refname, var->datatype->typname,
1546  var->datatype->typoid,
1547  var->datatype->atttypmod);
1548  if (var->isconst)
1549  printf(" CONSTANT\n");
1550  if (var->notnull)
1551  printf(" NOT NULL\n");
1552  if (var->default_val != NULL)
1553  {
1554  printf(" DEFAULT ");
1555  dump_expr(var->default_val);
1556  printf("\n");
1557  }
1558  if (var->cursor_explicit_expr != NULL)
1559  {
1560  if (var->cursor_explicit_argrow >= 0)
1561  printf(" CURSOR argument row %d\n", var->cursor_explicit_argrow);
1562 
1563  printf(" CURSOR IS ");
1565  printf("\n");
1566  }
1567  }
1568  break;
1569  case PLPGSQL_DTYPE_ROW:
1570  {
1571  PLpgSQL_row *row = (PLpgSQL_row *) d;
1572  int i;
1573 
1574  printf("ROW %-16s fields", row->refname);
1575  for (i = 0; i < row->nfields; i++)
1576  {
1577  if (row->fieldnames[i])
1578  printf(" %s=var %d", row->fieldnames[i],
1579  row->varnos[i]);
1580  }
1581  printf("\n");
1582  }
1583  break;
1584  case PLPGSQL_DTYPE_REC:
1585  printf("REC %s\n", ((PLpgSQL_rec *) d)->refname);
1586  break;
1588  printf("RECFIELD %-16s of REC %d\n",
1589  ((PLpgSQL_recfield *) d)->fieldname,
1590  ((PLpgSQL_recfield *) d)->recparentno);
1591  break;
1593  printf("ARRAYELEM of VAR %d subscript ",
1594  ((PLpgSQL_arrayelem *) d)->arrayparentno);
1595  dump_expr(((PLpgSQL_arrayelem *) d)->subscript);
1596  printf("\n");
1597  break;
1598  default:
1599  printf("??? unknown data type %d\n", d->dtype);
1600  }
1601  }
1602  printf("\nFunction's statements:\n");
1603 
1604  dump_indent = 0;
1605  printf("%3d:", func->action->lineno);
1606  dump_block(func->action);
1607  printf("\nEnd of execution tree of function %s\n\n", func->fn_signature);
1608  fflush(stdout);
1609 }
PLpgSQL_datum ** datums
Definition: plpgsql.h:859
char * refname
Definition: plpgsql.h:281
int notnull
Definition: plpgsql.h:263
int isconst
Definition: plpgsql.h:262
char * refname
Definition: plpgsql.h:258
PLpgSQL_stmt_block * action
Definition: plpgsql.h:863
PLpgSQL_expr * cursor_explicit_expr
Definition: plpgsql.h:265
PLpgSQL_type * datatype
Definition: plpgsql.h:261
PLpgSQL_datum_type dtype
Definition: plpgsql.h:198
int cursor_explicit_argrow
Definition: plpgsql.h:266
char ** fieldnames
Definition: plpgsql.h:293
PLpgSQL_expr * default_val
Definition: plpgsql.h:264
int * varnos
Definition: plpgsql.h:294
PLpgSQL_datum_type dtype
Definition: plpgsql.h:318
int nfields
Definition: plpgsql.h:292
static int dump_indent
Definition: pl_funcs.c:751
char * fn_signature
Definition: plpgsql.h:812
char * typname
Definition: plpgsql.h:178
static void dump_block(PLpgSQL_stmt_block *block)
Definition: pl_funcs.c:888
int32 atttypmod
Definition: plpgsql.h:187
static void dump_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:1518
int i
Oid typoid
Definition: plpgsql.h:179

◆ plpgsql_free_function_memory()

void plpgsql_free_function_memory ( PLpgSQL_function func)

Definition at line 695 of file pl_funcs.c.

References PLpgSQL_function::action, Assert, PLpgSQL_var::cursor_explicit_expr, PLpgSQL_function::datums, PLpgSQL_var::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_REC, PLPGSQL_DTYPE_RECFIELD, PLPGSQL_DTYPE_ROW, PLPGSQL_DTYPE_VAR, and PLpgSQL_function::use_count.

Referenced by delete_function(), and plpgsql_inline_handler().

696 {
697  int i;
698 
699  /* Better not call this on an in-use function */
700  Assert(func->use_count == 0);
701 
702  /* Release plans associated with variable declarations */
703  for (i = 0; i < func->ndatums; i++)
704  {
705  PLpgSQL_datum *d = func->datums[i];
706 
707  switch (d->dtype)
708  {
709  case PLPGSQL_DTYPE_VAR:
710  {
711  PLpgSQL_var *var = (PLpgSQL_var *) d;
712 
713  free_expr(var->default_val);
715  }
716  break;
717  case PLPGSQL_DTYPE_ROW:
718  break;
719  case PLPGSQL_DTYPE_REC:
720  break;
722  break;
724  free_expr(((PLpgSQL_arrayelem *) d)->subscript);
725  break;
726  default:
727  elog(ERROR, "unrecognized data type: %d", d->dtype);
728  }
729  }
730  func->ndatums = 0;
731 
732  /* Release plans in statement tree */
733  if (func->action)
734  free_block(func->action);
735  func->action = NULL;
736 
737  /*
738  * And finally, release all memory except the PLpgSQL_function struct
739  * itself (which has to be kept around because there may be multiple
740  * fn_extra pointers to it).
741  */
742  if (func->fn_cxt)
744  func->fn_cxt = NULL;
745 }
PLpgSQL_datum ** datums
Definition: plpgsql.h:859
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:198
PLpgSQL_stmt_block * action
Definition: plpgsql.h:863
PLpgSQL_expr * cursor_explicit_expr
Definition: plpgsql.h:265
PLpgSQL_datum_type dtype
Definition: plpgsql.h:198
#define ERROR
Definition: elog.h:43
PLpgSQL_expr * default_val
Definition: plpgsql.h:264
unsigned long use_count
Definition: plpgsql.h:867
static void free_expr(PLpgSQL_expr *expr)
Definition: pl_funcs.c:685
MemoryContext fn_cxt
Definition: plpgsql.h:819
#define Assert(condition)
Definition: c.h:680
int i
#define elog
Definition: elog.h:219
static void free_block(PLpgSQL_stmt_block *block)
Definition: pl_funcs.c:464

◆ plpgsql_getdiag_kindname()

const char* plpgsql_getdiag_kindname ( PLpgSQL_getdiag_kind  kind)

Definition at line 296 of file pl_funcs.c.

References free_assert(), free_assign(), free_block(), free_case(), free_close(), 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_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().

297 {
298  switch (kind)
299  {
301  return "ROW_COUNT";
303  return "RESULT_OID";
305  return "PG_CONTEXT";
307  return "PG_EXCEPTION_CONTEXT";
309  return "PG_EXCEPTION_DETAIL";
311  return "PG_EXCEPTION_HINT";
313  return "RETURNED_SQLSTATE";
315  return "COLUMN_NAME";
317  return "CONSTRAINT_NAME";
319  return "PG_DATATYPE_NAME";
321  return "MESSAGE_TEXT";
323  return "TABLE_NAME";
325  return "SCHEMA_NAME";
326  }
327 
328  return "unknown";
329 }

◆ 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:358
#define Assert(condition)
Definition: c.h:680
const char * name
Definition: encode.c:521
void * palloc(Size size)
Definition: mcxt.c:835
PLpgSQL_nsitem_type itemtype
Definition: plpgsql.h:351
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: plpgsql.h:359
#define offsetof(type, field)
Definition: c.h:603

◆ 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:358
PLpgSQL_nsitem_type itemtype
Definition: plpgsql.h:351

◆ 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:358
PLpgSQL_nsitem_type itemtype
Definition: plpgsql.h:351
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: plpgsql.h:359

◆ 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:358
const char * name
Definition: encode.c:521
PLpgSQL_nsitem_type itemtype
Definition: plpgsql.h:351
char name[FLEXIBLE_ARRAY_MEMBER]
Definition: plpgsql.h:359

◆ 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:358
#define Assert(condition)
Definition: c.h:680
PLpgSQL_nsitem_type itemtype
Definition: plpgsql.h:351

◆ 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_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, 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  }
288 
289  return "unknown";
290 }
PLpgSQL_stmt_type cmd_type
Definition: plpgsql.h:367
#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().