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_INT64_FIELD(fldname) \
73 token = pg_strtok(&length); \
74 token = pg_strtok(&length); \
75 local_node->fldname = strtoi64(token, NULL, 10)
78#define READ_UINT64_FIELD(fldname) \
79 token = pg_strtok(&length); \
80 token = pg_strtok(&length); \
81 local_node->fldname = strtou64(token, NULL, 10)
84#define READ_LONG_FIELD(fldname) \
85 token = pg_strtok(&length); \
86 token = pg_strtok(&length); \
87 local_node->fldname = atol(token)
90#define READ_OID_FIELD(fldname) \
91 token = pg_strtok(&length); \
92 token = pg_strtok(&length); \
93 local_node->fldname = atooid(token)
96#define READ_CHAR_FIELD(fldname) \
97 token = pg_strtok(&length); \
98 token = pg_strtok(&length); \
100 local_node->fldname = (length == 0) ? '\0' : (token[0] == '\\' ? token[1] : token[0])
103#define READ_ENUM_FIELD(fldname, enumtype) \
104 token = pg_strtok(&length); \
105 token = pg_strtok(&length); \
106 local_node->fldname = (enumtype) atoi(token)
109#define READ_FLOAT_FIELD(fldname) \
110 token = pg_strtok(&length); \
111 token = pg_strtok(&length); \
112 local_node->fldname = atof(token)
115#define READ_BOOL_FIELD(fldname) \
116 token = pg_strtok(&length); \
117 token = pg_strtok(&length); \
118 local_node->fldname = strtobool(token)
121#define READ_STRING_FIELD(fldname) \
122 token = pg_strtok(&length); \
123 token = pg_strtok(&length); \
124 local_node->fldname = nullable_string(token, length)
127#ifdef DEBUG_NODE_TESTS_ENABLED
128#define READ_LOCATION_FIELD(fldname) \
129 token = pg_strtok(&length); \
130 token = pg_strtok(&length); \
131 local_node->fldname = restore_location_fields ? atoi(token) : -1
133#define READ_LOCATION_FIELD(fldname) \
134 token = pg_strtok(&length); \
135 token = pg_strtok(&length); \
137 local_node->fldname = -1
141#define READ_NODE_FIELD(fldname) \
142 token = pg_strtok(&length); \
144 local_node->fldname = nodeRead(NULL, 0)
147#define READ_BITMAPSET_FIELD(fldname) \
148 token = pg_strtok(&length); \
150 local_node->fldname = _readBitmapset()
153#define READ_ATTRNUMBER_ARRAY(fldname, len) \
154 token = pg_strtok(&length); \
155 local_node->fldname = readAttrNumberCols(len)
158#define READ_OID_ARRAY(fldname, len) \
159 token = pg_strtok(&length); \
160 local_node->fldname = readOidCols(len)
163#define READ_INT_ARRAY(fldname, len) \
164 token = pg_strtok(&length); \
165 local_node->fldname = readIntCols(len)
168#define READ_BOOL_ARRAY(fldname, len) \
169 token = pg_strtok(&length); \
170 local_node->fldname = readBoolCols(len)
183#define atoui(x) ((unsigned int) strtoul((x), NULL, 10))
185#define strtobool(x) ((*(x) == 't') ? true : false)
194 if (length == 2 &&
token[0] ==
'"' &&
token[1] ==
'"')
217 elog(
ERROR,
"incomplete Bitmapset structure");
218 if (length != 1 ||
token[0] !=
'(')
223 elog(
ERROR,
"incomplete Bitmapset structure");
224 if (length != 1 ||
token[0] !=
'b')
234 elog(
ERROR,
"unterminated Bitmapset structure");
235 if (length == 1 &&
token[0] ==
')')
237 val = (int) strtol(
token, &endptr, 10);
238 if (endptr !=
token + length)
256#include "readfuncs.funcs.c"
278 if (local_node->constisnull)
281 local_node->constvalue =
readDatum(local_node->constbyval);
294 if (length == 3 && strncmp(
token,
"and", 3) == 0)
296 else if (length == 2 && strncmp(
token,
"or", 2) == 0)
298 else if (length == 3 && strncmp(
token,
"not", 3) == 0)
316 if (length == 4 && strncmp(
token,
"NULL", 4) == 0)
317 local_node->isnull =
true;
326 memcpy(&local_node->val, tmp,
sizeof(
Integer));
329 memcpy(&local_node->val, tmp,
sizeof(
Float));
332 memcpy(&local_node->val, tmp,
sizeof(
Boolean));
335 memcpy(&local_node->val, tmp,
sizeof(
String));
338 memcpy(&local_node->val, tmp,
sizeof(
BitString));
341 elog(
ERROR,
"unrecognized node type: %d",
361 switch (local_node->rtekind)
396 if (local_node->tablefunc)
400 local_node->coltypes = tf->coltypes;
401 local_node->coltypmods = tf->coltypmods;
402 local_node->colcollations = tf->colcollations;
436 (
int) local_node->rtekind);
454 if (length == 3 && strncmp(
token,
"ANY", 3) == 0)
459 else if (length == 3 && strncmp(
token,
"ALL", 3) == 0)
464 else if (length == 8 && strncmp(
token,
"DISTINCT", 8) == 0)
469 else if (length == 12 && strncmp(
token,
"NOT_DISTINCT", 12) == 0)
474 else if (length == 6 && strncmp(
token,
"NULLIF", 6) == 0)
479 else if (length == 2 && strncmp(
token,
"IN", 2) == 0)
484 else if (length == 4 && strncmp(
token,
"LIKE", 4) == 0)
489 else if (length == 5 && strncmp(
token,
"ILIKE", 5) == 0)
494 else if (length == 7 && strncmp(
token,
"SIMILAR", 7) == 0)
499 else if (length == 7 && strncmp(
token,
"BETWEEN", 7) == 0)
504 else if (length == 11 && strncmp(
token,
"NOT_BETWEEN", 11) == 0)
509 else if (length == 11 && strncmp(
token,
"BETWEEN_SYM", 11) == 0)
514 else if (length == 15 && strncmp(
token,
"NOT_BETWEEN_SYM", 15) == 0)
519 else if (length == 5 && strncmp(
token,
":name", 5) == 0)
522 local_node->name =
nodeRead(NULL, 0);
541 const char *extnodename;
550 elog(
ERROR,
"extnodename has to be supplied");
582#define MATCH(tokname, namelen) \
583 (length == namelen && memcmp(token, tokname, namelen) == 0)
585#include "readfuncs.switch.c"
617 elog(
ERROR,
"expected \"[\" to start datum, but got \"%s\"; length = %zu",
623 elog(
ERROR,
"byval datum but length = %zu", length);
629 s[
i] = (char) atoi(
token);
632 else if (length <= 0)
636 s = (
char *)
palloc(length);
637 for (
i = 0;
i < length;
i++)
640 s[
i] = (char) atoi(
token);
647 elog(
ERROR,
"expected \"]\" to end datum, but got \"%s\"; length = %zu",
661#define READ_SCALAR_ARRAY(fnname, datatype, convfunc) \
666 READ_TEMP_LOCALS(); \
667 token = pg_strtok(&length); \
669 elog(ERROR, "incomplete scalar array"); \
672 if (length != 1 || token[0] != '(') \
673 elog(ERROR, "unrecognized token: \"%.*s\"", length, token); \
674 vals = (datatype *) palloc(numCols * sizeof(datatype)); \
675 for (int i = 0; i < numCols; i++) \
677 token = pg_strtok(&length); \
678 if (token == NULL || token[0] == ')') \
679 elog(ERROR, "incomplete scalar array"); \
680 vals[i] = convfunc(token); \
682 token = pg_strtok(&length); \
683 if (token == NULL || length != 1 || token[0] != ')') \
684 elog(ERROR, "incomplete scalar array"); \
Bitmapset * bms_add_member(Bitmapset *a, int x)
const ExtensibleNodeMethods * GetExtensibleNodeMethods(const char *extnodename, bool missing_ok)
char * pstrdup(const char *in)
int * readIntCols(int numCols)
static Node * newNode(size_t size, NodeTag tag)
Oid * readOidCols(int numCols)
int16 * readAttrNumberCols(int numCols)
bool * readBoolCols(int numCols)
static Datum PointerGetDatum(const void *X)
char * debackslash(const char *token, int length)
void * nodeRead(const char *token, int tok_len)
const char * pg_strtok(int *length)
#define READ_INT_FIELD(fldname)
#define READ_UINT_FIELD(fldname)
#define READ_NODE_FIELD(fldname)
static ExtensibleNode * _readExtensibleNode(void)
#define READ_CHAR_FIELD(fldname)
static char * nullable_string(const char *token, int length)
#define READ_SCALAR_ARRAY(fnname, datatype, convfunc)
Node * parseNodeString(void)
#define READ_OID_FIELD(fldname)
#define READ_LOCATION_FIELD(fldname)
static Bitmapset * _readBitmapset(void)
static A_Const * _readA_Const(void)
static Const * _readConst(void)
#define READ_STRING_FIELD(fldname)
#define READ_FLOAT_FIELD(fldname)
Datum readDatum(bool typbyval)
#define READ_BOOL_FIELD(fldname)
static BoolExpr * _readBoolExpr(void)
#define READ_ENUM_FIELD(fldname, enumtype)
#define READ_TEMP_LOCALS()
static A_Expr * _readA_Expr(void)
Bitmapset * readBitmapset(void)
#define READ_LOCALS(nodeTypeName)
static RangeTblEntry * _readRangeTblEntry(void)
static const struct fns functions
void check_stack_depth(void)
void(* nodeRead)(struct ExtensibleNode *node)