PostgreSQL Source Code: contrib/intarray/_int_bool.c Source File (original) (raw)
1
2
3
5
8
14
15
16
17#define WAITOPERAND 1
18#define WAITENDOPERAND 2
19#define WAITOPERATOR 3
20
21
22
23
24
31
32typedef struct
33{
38
40
43
44
45
46
49{
50 char nnn[16];
52
53 *val = 0;
54
56 while (1)
57 {
59 return ERR;
60 switch (state->state)
61 {
64 if ((*(state->buf) >= '0' && *(state->buf) <= '9') ||
65 *(state->buf) == '-')
66 {
69 }
70 else if (*(state->buf) == '!')
71 {
74 return OPR;
75 }
76 else if (*(state->buf) == '(')
77 {
81 }
82 else if (*(state->buf) != ' ')
83 return ERR;
84 break;
86 if (*(state->buf) >= '0' && *(state->buf) <= '9')
87 {
89 }
90 else
91 {
92 long lval;
93
98 if (errno != 0 || (long) *val != lval)
99 return ERR;
101 return (state->count && *(state->buf) == '\0')
103 }
104 break;
106 if (*(state->buf) == '&' || *(state->buf) == '|')
107 {
111 return OPR;
112 }
113 else if (*(state->buf) == ')')
114 {
118 }
119 else if (*(state->buf) == '\0')
121 else if (*(state->buf) != ' ')
122 return ERR;
123 break;
124 default:
125 return ERR;
126 break;
127 }
129 }
130}
131
132
133
134
135static void
137{
139
143 state->str = tmp;
145}
146
147#define STACKDEPTH 16
148
149
150
151
154{
159
160
162
164 {
165 switch (type)
166 {
167 case VAL:
171 {
174 }
175 break;
176 case OPR:
179 else
180 {
184 errmsg("statement too complex")));
187 }
188 break;
191 return ERR;
194 {
197 }
198 break;
201 {
204 };
205 return END;
206 break;
207 case ERR:
208 default:
211 errmsg("syntax error")));
212 }
213 }
214
216 {
219 };
220 return END;
221}
222
228
229
230
231
232static bool
234{
238
239
240
242 {
245 return true;
248 else
250 }
251 return false;
252}
253
254static bool
259
260
261
262
263static bool
266{
267
269
272 else if (curitem->val == (int32) '!')
273 {
276 : true;
277 }
278 else if (curitem->val == (int32) '&')
279 {
282 else
283 return false;
284 }
285 else
286 {
288 return true;
289 else
291 }
292}
293
294
295
296
297bool
304
305
306bool
318
324
325static bool
332
333bool
335{
338 int i,
339 j = 0;
340
341 if (query->size <= 0)
342 return false;
343
344
345
346
347
350 for (i = 0; i < query->size; i++)
351 {
353 gcv.mapped_check[i] = check[j++];
354 }
355
359}
360
361static bool
363{
364
366
368 return true;
369 else if (curitem->val == (int32) '!')
370 {
371
372
373
374
375
376 return false;
377 }
378 else if (curitem->val == (int32) '&')
379 {
380
382 return true;
383 else
385 }
386 else
387 {
388
391 else
392 return false;
393 }
394}
395
396bool
398{
399 if (query->size <= 0)
400 return false;
402}
403
404
405
406
415
418{
422 bool result;
423
432
435}
436
437static void
439{
440
442
443#ifdef BS_DEBUG
445 "%d %c" : "%d %d", *pos, ptr[*pos].val);
446#endif
447 if (ptr[*pos].type == VAL)
448 {
449 ptr[*pos].left = 0;
450 (*pos)--;
451 }
452 else if (ptr[*pos].val == (int32) '!')
453 {
454 ptr[*pos].left = -1;
455 (*pos)--;
457 }
458 else
459 {
460 ITEM *curitem = &ptr[*pos];
461 int32 tmp = *pos;
462
463 (*pos)--;
465 curitem->left = *pos - tmp;
467 }
468}
469
470
471
472
473
476{
485 struct Node *escontext = fcinfo->context;
486
487#ifdef BS_DEBUG
489#endif
490
496 state.escontext = escontext;
497
498
504 errmsg("empty query")));
505
509 errmsg("number of query items (%d) exceeds the maximum allowed (%d)",
512
517
518 for (i = state.num - 1; i >= 0; i--)
519 {
525 }
526
527 pos = query->size - 1;
529#ifdef BS_DEBUG
531 for (i = 0; i < query->size; i++)
532 {
535 else
537 }
540#endif
541
543}
544
545
546
547
548
556
557#define RESIZEBUF(inf,addsize) while( ( (inf)->cur - (inf)->buf ) + (addsize) + 1 >= (inf)->buflen ) { \
558 int32 len = inf->cur - inf->buf; \
559 inf->buflen *= 2; \
560 inf->buf = (char*) repalloc( (void*)inf->buf, inf->buflen ); \
561 inf->cur = inf->buf + len; \
562}
563
564static void
566{
567
569
571 {
576 }
578 {
579 bool isopr = false;
580
582 *(in->cur) = '!';
583 in->cur++;
584 *(in->cur) = '\0';
587 {
592 }
595 {
599 }
600 }
601 else
602 {
605
607 if (op == (int32) '|' && !first)
608 {
612 }
613
615 nrm.buflen = 16;
617
618
620
621
623 infix(in, false);
624
625
630
631 if (op == (int32) '|' && !first)
632 {
636 }
637 }
638}
639
640
643{
646
647 if (query->size == 0)
650 errmsg("empty query")));
651
653 nrm.buflen = 32;
655 *(nrm.cur) = '\0';
657
660}
661
662
663
666{
667 elog(ERROR, "querytree is no longer implemented");
669}
#define COMPUTESIZE(size)
#define QUERYTYPEMAXITEMS
#define PG_GETARG_QUERYTYPE_P(n)
Datum querytree(PG_FUNCTION_ARGS)
Datum rboolop(PG_FUNCTION_ARGS)
static bool checkcondition_arr(void *checkval, ITEM *item, void *options)
bool signconsistent(QUERYTYPE *query, BITVECP sign, int siglen, bool calcnot)
static void pushquery(WORKSTATE *state, int32 type, int32 val)
static bool contains_required_value(ITEM *curitem)
static bool checkcondition_bit(void *checkval, ITEM *item, void *siglen)
#define RESIZEBUF(inf, addsize)
static void findoprnd(ITEM *ptr, int32 *pos)
static int32 makepol(WORKSTATE *state)
bool query_has_required_values(QUERYTYPE *query)
static int32 gettoken(WORKSTATE *state, int32 *val)
Datum bqarr_out(PG_FUNCTION_ARGS)
static void infix(INFIX *in, bool first)
bool execconsistent(QUERYTYPE *query, ArrayType *array, bool calcnot)
Datum boolop(PG_FUNCTION_ARGS)
Datum bqarr_in(PG_FUNCTION_ARGS)
static bool checkcondition_gin(void *checkval, ITEM *item, void *options)
static bool execute(ITEM *curitem, void *checkval, void *options, bool calcnot, bool(*chkcond)(void *checkval, ITEM *item, void *options))
bool gin_bool_consistent(QUERYTYPE *query, bool *check)
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
int errcode(int sqlerrcode)
#define ereturn(context, dummy_value,...)
#define ereport(elevel,...)
#define palloc_object(type)
#define palloc_array(type, count)
#define PG_FREE_IF_COPY(ptr, n)
#define DirectFunctionCall2(func, arg1, arg2)
#define PG_GETARG_POINTER(n)
#define PG_GETARG_DATUM(n)
#define PG_FUNCTION_INFO_V1(funcname)
#define PG_RETURN_POINTER(x)
#define PG_RETURN_BOOL(x)
#define HASHVAL(val, siglen)
void pfree(void *pointer)
static char buf[DEFAULT_XLOG_SEG_SIZE]
void check_stack_depth(void)
void appendStringInfo(StringInfo str, const char *fmt,...)
void initStringInfo(StringInfo str)
static void SET_VARSIZE(void *PTR, Size len)