46 #define READ_LOCALS_NO_FIELDS(nodeTypeName) \
47 nodeTypeName *local_node = makeNode(nodeTypeName)
50 #define READ_TEMP_LOCALS() \
55 #define READ_LOCALS(nodeTypeName) \
56 READ_LOCALS_NO_FIELDS(nodeTypeName); \
60 #define READ_INT_FIELD(fldname) \
61 token = pg_strtok(&length); \
62 token = pg_strtok(&length); \
63 local_node->fldname = atoi(token)
66 #define READ_UINT_FIELD(fldname) \
67 token = pg_strtok(&length); \
68 token = pg_strtok(&length); \
69 local_node->fldname = atoui(token)
72 #define READ_UINT64_FIELD(fldname) \
73 token = pg_strtok(&length); \
74 token = pg_strtok(&length); \
75 local_node->fldname = strtou64(token, NULL, 10)
78 #define READ_LONG_FIELD(fldname) \
79 token = pg_strtok(&length); \
80 token = pg_strtok(&length); \
81 local_node->fldname = atol(token)
84 #define READ_OID_FIELD(fldname) \
85 token = pg_strtok(&length); \
86 token = pg_strtok(&length); \
87 local_node->fldname = atooid(token)
90 #define READ_CHAR_FIELD(fldname) \
91 token = pg_strtok(&length); \
92 token = pg_strtok(&length); \
94 local_node->fldname = (length == 0) ? '\0' : (token[0] == '\\' ? token[1] : token[0])
97 #define READ_ENUM_FIELD(fldname, enumtype) \
98 token = pg_strtok(&length); \
99 token = pg_strtok(&length); \
100 local_node->fldname = (enumtype) atoi(token)
103 #define READ_FLOAT_FIELD(fldname) \
104 token = pg_strtok(&length); \
105 token = pg_strtok(&length); \
106 local_node->fldname = atof(token)
109 #define READ_BOOL_FIELD(fldname) \
110 token = pg_strtok(&length); \
111 token = pg_strtok(&length); \
112 local_node->fldname = strtobool(token)
115 #define READ_STRING_FIELD(fldname) \
116 token = pg_strtok(&length); \
117 token = pg_strtok(&length); \
118 local_node->fldname = nullable_string(token, length)
121 #ifdef DEBUG_NODE_TESTS_ENABLED
122 #define READ_LOCATION_FIELD(fldname) \
123 token = pg_strtok(&length); \
124 token = pg_strtok(&length); \
125 local_node->fldname = restore_location_fields ? atoi(token) : -1
127 #define READ_LOCATION_FIELD(fldname) \
128 token = pg_strtok(&length); \
129 token = pg_strtok(&length); \
131 local_node->fldname = -1
135 #define READ_NODE_FIELD(fldname) \
136 token = pg_strtok(&length); \
138 local_node->fldname = nodeRead(NULL, 0)
141 #define READ_BITMAPSET_FIELD(fldname) \
142 token = pg_strtok(&length); \
144 local_node->fldname = _readBitmapset()
147 #define READ_ATTRNUMBER_ARRAY(fldname, len) \
148 token = pg_strtok(&length); \
149 local_node->fldname = readAttrNumberCols(len)
152 #define READ_OID_ARRAY(fldname, len) \
153 token = pg_strtok(&length); \
154 local_node->fldname = readOidCols(len)
157 #define READ_INT_ARRAY(fldname, len) \
158 token = pg_strtok(&length); \
159 local_node->fldname = readIntCols(len)
162 #define READ_BOOL_ARRAY(fldname, len) \
163 token = pg_strtok(&length); \
164 local_node->fldname = readBoolCols(len)
167 #define READ_DONE() \
177 #define atoui(x) ((unsigned int) strtoul((x), NULL, 10))
179 #define strtobool(x) ((*(x) == 't') ? true : false)
188 if (length == 2 &&
token[0] ==
'"' &&
token[1] ==
'"')
211 elog(
ERROR,
"incomplete Bitmapset structure");
212 if (length != 1 ||
token[0] !=
'(')
217 elog(
ERROR,
"incomplete Bitmapset structure");
218 if (length != 1 ||
token[0] !=
'b')
228 elog(
ERROR,
"unterminated Bitmapset structure");
229 if (length == 1 &&
token[0] ==
')')
231 val = (int) strtol(
token, &endptr, 10);
232 if (endptr !=
token + length)
250 #include "readfuncs.funcs.c"
272 if (local_node->constisnull)
275 local_node->constvalue =
readDatum(local_node->constbyval);
288 if (length == 3 && strncmp(
token,
"and", 3) == 0)
290 else if (length == 2 && strncmp(
token,
"or", 2) == 0)
292 else if (length == 3 && strncmp(
token,
"not", 3) == 0)
310 if (length == 4 && strncmp(
token,
"NULL", 4) == 0)
311 local_node->isnull =
true;
320 memcpy(&local_node->val, tmp,
sizeof(
Integer));
323 memcpy(&local_node->val, tmp,
sizeof(
Float));
326 memcpy(&local_node->val, tmp,
sizeof(
Boolean));
329 memcpy(&local_node->val, tmp,
sizeof(
String));
332 memcpy(&local_node->val, tmp,
sizeof(
BitString));
335 elog(
ERROR,
"unrecognized node type: %d",
355 switch (local_node->rtekind)
390 if (local_node->tablefunc)
394 local_node->coltypes = tf->coltypes;
395 local_node->coltypmods = tf->coltypmods;
396 local_node->colcollations = tf->colcollations;
430 (
int) local_node->rtekind);
448 if (length == 3 && strncmp(
token,
"ANY", 3) == 0)
453 else if (length == 3 && strncmp(
token,
"ALL", 3) == 0)
458 else if (length == 8 && strncmp(
token,
"DISTINCT", 8) == 0)
463 else if (length == 12 && strncmp(
token,
"NOT_DISTINCT", 12) == 0)
468 else if (length == 6 && strncmp(
token,
"NULLIF", 6) == 0)
473 else if (length == 2 && strncmp(
token,
"IN", 2) == 0)
478 else if (length == 4 && strncmp(
token,
"LIKE", 4) == 0)
483 else if (length == 5 && strncmp(
token,
"ILIKE", 5) == 0)
488 else if (length == 7 && strncmp(
token,
"SIMILAR", 7) == 0)
493 else if (length == 7 && strncmp(
token,
"BETWEEN", 7) == 0)
498 else if (length == 11 && strncmp(
token,
"NOT_BETWEEN", 11) == 0)
503 else if (length == 11 && strncmp(
token,
"BETWEEN_SYM", 11) == 0)
508 else if (length == 15 && strncmp(
token,
"NOT_BETWEEN_SYM", 15) == 0)
513 else if (length == 5 && strncmp(
token,
":name", 5) == 0)
516 local_node->name =
nodeRead(NULL, 0);
533 const char *extnodename;
542 elog(
ERROR,
"extnodename has to be supplied");
574 #define MATCH(tokname, namelen) \
575 (length == namelen && memcmp(token, tokname, namelen) == 0)
577 #include "readfuncs.switch.c"
609 elog(
ERROR,
"expected \"[\" to start datum, but got \"%s\"; length = %zu",
615 elog(
ERROR,
"byval datum but length = %zu", length);
621 s[
i] = (char) atoi(
token);
624 else if (length <= 0)
628 s = (
char *)
palloc(length);
629 for (
i = 0;
i < length;
i++)
632 s[
i] = (char) atoi(
token);
639 elog(
ERROR,
"expected \"]\" to end datum, but got \"%s\"; length = %zu",
653 #define READ_SCALAR_ARRAY(fnname, datatype, convfunc) \
655 fnname(int numCols) \
658 READ_TEMP_LOCALS(); \
659 token = pg_strtok(&length); \
661 elog(ERROR, "incomplete scalar array"); \
664 if (length != 1 || token[0] != '(') \
665 elog(ERROR, "unrecognized token: \"%.*s\"", length, token); \
666 vals = (datatype *) palloc(numCols * sizeof(datatype)); \
667 for (int i = 0; i < numCols; i++) \
669 token = pg_strtok(&length); \
670 if (token == NULL || token[0] == ')') \
671 elog(ERROR, "incomplete scalar array"); \
672 vals[i] = convfunc(token); \
674 token = pg_strtok(&length); \
675 if (token == NULL || length != 1 || token[0] != ')') \
676 elog(ERROR, "incomplete scalar array"); \
Bitmapset * bms_add_member(Bitmapset *a, int x)
static void PGresult * res
const ExtensibleNodeMethods * GetExtensibleNodeMethods(const char *extnodename, bool missing_ok)
char * pstrdup(const char *in)
static Node * newNode(size_t size, NodeTag tag)
int * readIntCols(int numCols)
bool * readBoolCols(int numCols)
Oid * readOidCols(int numCols)
int16 * readAttrNumberCols(int numCols)
void check_stack_depth(void)
static Datum PointerGetDatum(const void *X)
const char * pg_strtok(int *length)
char * debackslash(const char *token, int length)
void * nodeRead(const char *token, int tok_len)
static A_Const * _readA_Const(void)
#define READ_INT_FIELD(fldname)
static char * nullable_string(const char *token, int length)
#define READ_UINT_FIELD(fldname)
#define READ_NODE_FIELD(fldname)
static RangeTblEntry * _readRangeTblEntry(void)
#define READ_CHAR_FIELD(fldname)
#define READ_SCALAR_ARRAY(fnname, datatype, convfunc)
Node * parseNodeString(void)
static Const * _readConst(void)
#define READ_OID_FIELD(fldname)
#define READ_LOCATION_FIELD(fldname)
#define READ_STRING_FIELD(fldname)
static BoolExpr * _readBoolExpr(void)
#define READ_FLOAT_FIELD(fldname)
Datum readDatum(bool typbyval)
static ExtensibleNode * _readExtensibleNode(void)
#define READ_BOOL_FIELD(fldname)
Bitmapset * readBitmapset(void)
static A_Expr * _readA_Expr(void)
static Bitmapset * _readBitmapset(void)
#define READ_ENUM_FIELD(fldname, enumtype)
#define READ_TEMP_LOCALS()
#define READ_LOCALS(nodeTypeName)
static const struct fns functions
void(* nodeRead)(struct ExtensibleNode *node)