|
16 | 16 |
|
17 | 17 | #include <ctype.h>
|
18 | 18 |
|
| 19 | +#include "access/attnum.h" |
19 | 20 | #include "lib/stringinfo.h"
|
20 | 21 | #include "miscadmin.h"
|
21 | 22 | #include "nodes/bitmapset.h"
|
@@ -96,48 +97,30 @@ static void outChar(StringInfo str, char c);
|
96 | 97 | (appendStringInfoString(str, " :" CppAsString(fldname) " "), \
|
97 | 98 | outBitmapset(str, node->fldname))
|
98 | 99 |
|
| 100 | +/* Write a variable-length array of AttrNumber */ |
99 | 101 | #define WRITE_ATTRNUMBER_ARRAY(fldname, len) \
|
100 |
| - do { \ |
101 |
| - appendStringInfoString(str, " :" CppAsString(fldname) " "); \ |
102 |
| - for (int i = 0; i < len; i++) \ |
103 |
| - appendStringInfo(str, " %d", node->fldname[i]); \ |
104 |
| - } while(0) |
| 102 | + (appendStringInfoString(str, " :" CppAsString(fldname) " "), \ |
| 103 | + writeAttrNumberCols(str, node->fldname, len)) |
105 | 104 |
|
| 105 | +/* Write a variable-length array of Oid */ |
106 | 106 | #define WRITE_OID_ARRAY(fldname, len) \
|
107 |
| - do { \ |
108 |
| - appendStringInfoString(str, " :" CppAsString(fldname) " "); \ |
109 |
| - for (int i = 0; i < len; i++) \ |
110 |
| - appendStringInfo(str, " %u", node->fldname[i]); \ |
111 |
| - } while(0) |
| 107 | + (appendStringInfoString(str, " :" CppAsString(fldname) " "), \ |
| 108 | + writeOidCols(str, node->fldname, len)) |
112 | 109 |
|
113 |
| -/* |
114 |
| - * This macro supports the case that the field is NULL. For the other array |
115 |
| - * macros, that is currently not needed. |
116 |
| - */ |
| 110 | +/* Write a variable-length array of Index */ |
117 | 111 | #define WRITE_INDEX_ARRAY(fldname, len) \
|
118 |
| - do { \ |
119 |
| - appendStringInfoString(str, " :" CppAsString(fldname) " "); \ |
120 |
| - if (node->fldname) \ |
121 |
| - for (int i = 0; i < len; i++) \ |
122 |
| - appendStringInfo(str, " %u", node->fldname[i]); \ |
123 |
| - else \ |
124 |
| - appendStringInfoString(str, "<>"); \ |
125 |
| - } while(0) |
| 112 | + (appendStringInfoString(str, " :" CppAsString(fldname) " "), \ |
| 113 | + writeIndexCols(str, node->fldname, len)) |
126 | 114 |
|
| 115 | +/* Write a variable-length array of int */ |
127 | 116 | #define WRITE_INT_ARRAY(fldname, len) \
|
128 |
| - do { \ |
129 |
| - appendStringInfoString(str, " :" CppAsString(fldname) " "); \ |
130 |
| - for (int i = 0; i < len; i++) \ |
131 |
| - appendStringInfo(str, " %d", node->fldname[i]); \ |
132 |
| - } while(0) |
| 117 | + (appendStringInfoString(str, " :" CppAsString(fldname) " "), \ |
| 118 | + writeIntCols(str, node->fldname, len)) |
133 | 119 |
|
| 120 | +/* Write a variable-length array of bool */ |
134 | 121 | #define WRITE_BOOL_ARRAY(fldname, len) \
|
135 |
| - do { \ |
136 |
| - appendStringInfoString(str, " :" CppAsString(fldname) " "); \ |
137 |
| - for (int i = 0; i < len; i++) \ |
138 |
| - appendStringInfo(str, " %s", booltostr(node->fldname[i])); \ |
139 |
| - } while(0) |
140 |
| - |
| 122 | + (appendStringInfoString(str, " :" CppAsString(fldname) " "), \ |
| 123 | + writeBoolCols(str, node->fldname, len)) |
141 | 124 |
|
142 | 125 | #define booltostr(x) ((x) ? "true" : "false")
|
143 | 126 |
|
@@ -196,6 +179,38 @@ outChar(StringInfo str, char c)
|
196 | 179 | outToken(str, in);
|
197 | 180 | }
|
198 | 181 |
|
| 182 | +/* |
| 183 | + * common implementation for scalar-array-writing functions |
| 184 | + * |
| 185 | + * The data format is either "<>" for a NULL pointer or "(item item item)". |
| 186 | + * fmtstr must include a leading space, and the rest of it must produce |
| 187 | + * something that will be seen as a single simple token by pg_strtok(). |
| 188 | + * convfunc can be empty, or the name of a conversion macro or function. |
| 189 | + */ |
| 190 | +#define WRITE_SCALAR_ARRAY(fnname, datatype, fmtstr, convfunc) \ |
| 191 | +static void \ |
| 192 | +fnname(StringInfo str, const datatype *arr, int len) \ |
| 193 | +{ \ |
| 194 | + if (arr != NULL) \ |
| 195 | + { \ |
| 196 | + appendStringInfoChar(str, '('); \ |
| 197 | + for (int i = 0; i < len; i++) \ |
| 198 | + appendStringInfo(str, fmtstr, convfunc(arr[i])); \ |
| 199 | + appendStringInfoChar(str, ')'); \ |
| 200 | + } \ |
| 201 | + else \ |
| 202 | + appendStringInfoString(str, "<>"); \ |
| 203 | +} |
| 204 | + |
| 205 | +WRITE_SCALAR_ARRAY(writeAttrNumberCols, AttrNumber, " %d",) |
| 206 | +WRITE_SCALAR_ARRAY(writeOidCols, Oid, " %u",) |
| 207 | +WRITE_SCALAR_ARRAY(writeIndexCols, Index, " %u",) |
| 208 | +WRITE_SCALAR_ARRAY(writeIntCols, int, " %d",) |
| 209 | +WRITE_SCALAR_ARRAY(writeBoolCols, bool, " %s", booltostr) |
| 210 | + |
| 211 | +/* |
| 212 | + * Print a List. |
| 213 | + */ |
199 | 214 | static void
|
200 | 215 | _outList(StringInfo str, const List *node)
|
201 | 216 | {
|
|
0 commit comments