PostgreSQL Source Code  git master
_int_bool.c File Reference
#include "postgres.h"
#include "_int.h"
#include "miscadmin.h"
#include "utils/builtins.h"
Include dependency graph for _int_bool.c:

Go to the source code of this file.

Data Structures

struct  NODE
 
struct  WORKSTATE
 
struct  CHKVAL
 
struct  GinChkVal
 
struct  INFIX
 

Macros

#define WAITOPERAND   1
 
#define WAITENDOPERAND   2
 
#define WAITOPERATOR   3
 
#define STACKDEPTH   16
 
#define RESIZEBUF(inf, addsize)
 

Typedefs

typedef struct NODE NODE
 

Functions

 PG_FUNCTION_INFO_V1 (bqarr_in)
 
 PG_FUNCTION_INFO_V1 (bqarr_out)
 
 PG_FUNCTION_INFO_V1 (boolop)
 
 PG_FUNCTION_INFO_V1 (rboolop)
 
 PG_FUNCTION_INFO_V1 (querytree)
 
static int32 gettoken (WORKSTATE *state, int32 *val)
 
static void pushquery (WORKSTATE *state, int32 type, int32 val)
 
static int32 makepol (WORKSTATE *state)
 
static bool checkcondition_arr (void *checkval, ITEM *item, void *options)
 
static bool checkcondition_bit (void *checkval, ITEM *item, void *siglen)
 
static bool execute (ITEM *curitem, void *checkval, void *options, bool calcnot, bool(*chkcond)(void *checkval, ITEM *item, void *options))
 
bool signconsistent (QUERYTYPE *query, BITVECP sign, int siglen, bool calcnot)
 
bool execconsistent (QUERYTYPE *query, ArrayType *array, bool calcnot)
 
static bool checkcondition_gin (void *checkval, ITEM *item, void *options)
 
bool gin_bool_consistent (QUERYTYPE *query, bool *check)
 
static bool contains_required_value (ITEM *curitem)
 
bool query_has_required_values (QUERYTYPE *query)
 
Datum rboolop (PG_FUNCTION_ARGS)
 
Datum boolop (PG_FUNCTION_ARGS)
 
static void findoprnd (ITEM *ptr, int32 *pos)
 
Datum bqarr_in (PG_FUNCTION_ARGS)
 
static void infix (INFIX *in, bool first)
 
Datum bqarr_out (PG_FUNCTION_ARGS)
 
Datum querytree (PG_FUNCTION_ARGS)
 

Macro Definition Documentation

◆ RESIZEBUF

#define RESIZEBUF (   inf,
  addsize 
)
Value:
while( ( (inf)->cur - (inf)->buf ) + (addsize) + 1 >= (inf)->buflen ) { \
int32 len = inf->cur - inf->buf; \
inf->buflen *= 2; \
inf->buf = (char*) repalloc( (void*)inf->buf, inf->buflen ); \
inf->cur = inf->buf + len; \
}
struct cursor * cur
Definition: ecpg.c:28
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1188
const void size_t len
static char * buf
Definition: pg_test_fsync.c:67

Definition at line 555 of file _int_bool.c.

◆ STACKDEPTH

#define STACKDEPTH   16

Definition at line 147 of file _int_bool.c.

◆ WAITENDOPERAND

#define WAITENDOPERAND   2

Definition at line 19 of file _int_bool.c.

◆ WAITOPERAND

#define WAITOPERAND   1

Definition at line 18 of file _int_bool.c.

◆ WAITOPERATOR

#define WAITOPERATOR   3

Definition at line 20 of file _int_bool.c.

Typedef Documentation

◆ NODE

typedef struct NODE NODE

Function Documentation

◆ boolop()

Datum boolop ( PG_FUNCTION_ARGS  )

Definition at line 418 of file _int_bool.c.

419 {
421  QUERYTYPE *query = PG_GETARG_QUERYTYPE_P(1);
422  CHKVAL chkval;
423  bool result;
424 
426  PREPAREARR(val);
427  chkval.arrb = ARRPTR(val);
428  chkval.arre = chkval.arrb + ARRNELEMS(val);
429  result = execute(GETQUERY(query) + query->size - 1,
430  &chkval, NULL, true,
432  pfree(val);
433 
434  PG_FREE_IF_COPY(query, 1);
435  PG_RETURN_BOOL(result);
436 }
#define PREPAREARR(x)
Definition: _int.h:49
#define CHECKARRVALID(x)
Definition: _int.h:30
#define GETQUERY(x)
Definition: _int.h:157
#define PG_GETARG_QUERYTYPE_P(n)
Definition: _int.h:170
static bool checkcondition_arr(void *checkval, ITEM *item, void *options)
Definition: _int_bool.c:234
static bool execute(ITEM *curitem, void *checkval, void *options, bool calcnot, bool(*chkcond)(void *checkval, ITEM *item, void *options))
Definition: _int_bool.c:265
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:257
#define ARRNELEMS(x)
Definition: cube.c:26
#define ARRPTR(x)
Definition: cube.c:25
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:260
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
long val
Definition: informix.c:664
void pfree(void *pointer)
Definition: mcxt.c:1175
int32 * arrb
Definition: _int_bool.c:226
int32 * arre
Definition: _int_bool.c:227
int32 size
Definition: _int.h:150

References CHKVAL::arrb, CHKVAL::arre, ARRNELEMS, ARRPTR, CHECKARRVALID, checkcondition_arr(), execute(), GETQUERY, pfree(), PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P_COPY, PG_GETARG_QUERYTYPE_P, PG_RETURN_BOOL, PREPAREARR, QUERYTYPE::size, and val.

Referenced by _copyBoolExpr(), _equalBoolExpr(), is_andclause(), is_notclause(), is_orclause(), makeBoolExpr(), and rboolop().

◆ bqarr_in()

Datum bqarr_in ( PG_FUNCTION_ARGS  )

Definition at line 476 of file _int_bool.c.

477 {
478  char *buf = (char *) PG_GETARG_POINTER(0);
480  int32 i;
481  QUERYTYPE *query;
482  int32 commonlen;
483  ITEM *ptr;
484  NODE *tmp;
485  int32 pos = 0;
486 
487 #ifdef BS_DEBUG
488  StringInfoData pbuf;
489 #endif
490 
491  state.buf = buf;
492  state.state = WAITOPERAND;
493  state.count = 0;
494  state.num = 0;
495  state.str = NULL;
496 
497  /* make polish notation (postfix, but in reverse order) */
498  makepol(&state);
499  if (!state.num)
500  ereport(ERROR,
501  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
502  errmsg("empty query")));
503 
504  if (state.num > QUERYTYPEMAXITEMS)
505  ereport(ERROR,
506  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
507  errmsg("number of query items (%d) exceeds the maximum allowed (%d)",
508  state.num, (int) QUERYTYPEMAXITEMS)));
509  commonlen = COMPUTESIZE(state.num);
510 
511  query = (QUERYTYPE *) palloc(commonlen);
512  SET_VARSIZE(query, commonlen);
513  query->size = state.num;
514  ptr = GETQUERY(query);
515 
516  for (i = state.num - 1; i >= 0; i--)
517  {
518  ptr[i].type = state.str->type;
519  ptr[i].val = state.str->val;
520  tmp = state.str->next;
521  pfree(state.str);
522  state.str = tmp;
523  }
524 
525  pos = query->size - 1;
526  findoprnd(ptr, &pos);
527 #ifdef BS_DEBUG
528  initStringInfo(&pbuf);
529  for (i = 0; i < query->size; i++)
530  {
531  if (ptr[i].type == OPR)
532  appendStringInfo(&pbuf, "%c(%d) ", ptr[i].val, ptr[i].left);
533  else
534  appendStringInfo(&pbuf, "%d ", ptr[i].val);
535  }
536  elog(DEBUG3, "POR: %s", pbuf.data);
537  pfree(pbuf.data);
538 #endif
539 
540  PG_RETURN_POINTER(query);
541 }
#define COMPUTESIZE(size)
Definition: _int.h:155
#define OPR
Definition: _int.h:163
#define QUERYTYPEMAXITEMS
Definition: _int.h:156
static void findoprnd(ITEM *ptr, int32 *pos)
Definition: _int_bool.c:439
static int32 makepol(WORKSTATE *state)
Definition: _int_bool.c:153
#define WAITOPERAND
Definition: _int_bool.c:18
signed int int32
Definition: c.h:429
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define DEBUG3
Definition: elog.h:22
#define ERROR
Definition: elog.h:33
#define elog(elevel,...)
Definition: elog.h:218
#define ereport(elevel,...)
Definition: elog.h:143
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
int i
Definition: isn.c:73
void * palloc(Size size)
Definition: mcxt.c:1068
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:342
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
Definition: _int.h:141
int32 val
Definition: _int.h:144
int16 type
Definition: _int.h:142
Definition: _int_bool.c:27
Definition: regguts.h:318
struct state * next
Definition: regguts.h:327

References appendStringInfo(), buf, COMPUTESIZE, StringInfoData::data, DEBUG3, elog, ereport, errcode(), errmsg(), ERROR, findoprnd(), GETQUERY, i, initStringInfo(), NODE::left, makepol(), state::next, OPR, palloc(), pfree(), PG_GETARG_POINTER, PG_RETURN_POINTER, QUERYTYPEMAXITEMS, SET_VARSIZE, QUERYTYPE::size, ITEM::type, generate_unaccent_rules::type, ITEM::val, val, and WAITOPERAND.

◆ bqarr_out()

Datum bqarr_out ( PG_FUNCTION_ARGS  )

Definition at line 640 of file _int_bool.c.

641 {
642  QUERYTYPE *query = PG_GETARG_QUERYTYPE_P(0);
643  INFIX nrm;
644 
645  if (query->size == 0)
646  ereport(ERROR,
647  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
648  errmsg("empty query")));
649 
650  nrm.curpol = GETQUERY(query) + query->size - 1;
651  nrm.buflen = 32;
652  nrm.cur = nrm.buf = (char *) palloc(sizeof(char) * nrm.buflen);
653  *(nrm.cur) = '\0';
654  infix(&nrm, true);
655 
656  PG_FREE_IF_COPY(query, 0);
657  PG_RETURN_POINTER(nrm.buf);
658 }
static void infix(INFIX *in, bool first)
Definition: _int_bool.c:563
char * buf
Definition: _int_bool.c:550
char * cur
Definition: _int_bool.c:551
int32 buflen
Definition: _int_bool.c:552
ITEM * curpol
Definition: _int_bool.c:549

References INFIX::buf, INFIX::buflen, INFIX::cur, INFIX::curpol, ereport, errcode(), errmsg(), ERROR, GETQUERY, infix(), palloc(), PG_FREE_IF_COPY, PG_GETARG_QUERYTYPE_P, PG_RETURN_POINTER, and QUERYTYPE::size.

◆ checkcondition_arr()

static bool checkcondition_arr ( void *  checkval,
ITEM item,
void *  options 
)
static

Definition at line 234 of file _int_bool.c.

235 {
236  int32 *StopLow = ((CHKVAL *) checkval)->arrb;
237  int32 *StopHigh = ((CHKVAL *) checkval)->arre;
238  int32 *StopMiddle;
239 
240  /* Loop invariant: StopLow <= val < StopHigh */
241 
242  while (StopLow < StopHigh)
243  {
244  StopMiddle = StopLow + (StopHigh - StopLow) / 2;
245  if (*StopMiddle == item->val)
246  return true;
247  else if (*StopMiddle < item->val)
248  StopLow = StopMiddle + 1;
249  else
250  StopHigh = StopMiddle;
251  }
252  return false;
253 }

References ITEM::val, and val.

Referenced by boolop(), and execconsistent().

◆ checkcondition_bit()

static bool checkcondition_bit ( void *  checkval,
ITEM item,
void *  siglen 
)
static

Definition at line 256 of file _int_bool.c.

257 {
258  return GETBIT(checkval, HASHVAL(item->val, (int) (intptr_t) siglen));
259 }
#define GETBIT(x, i)
Definition: blutils.c:33
#define HASHVAL(val, siglen)
Definition: hstore_gist.c:44

References GETBIT, HASHVAL, and ITEM::val.

Referenced by signconsistent().

◆ checkcondition_gin()

static bool checkcondition_gin ( void *  checkval,
ITEM item,
void *  options 
)
static

Definition at line 327 of file _int_bool.c.

328 {
329  GinChkVal *gcv = (GinChkVal *) checkval;
330 
331  return gcv->mapped_check[item - gcv->first];
332 }
ITEM * first
Definition: _int_bool.c:322
bool * mapped_check
Definition: _int_bool.c:323

References GinChkVal::first, and GinChkVal::mapped_check.

Referenced by gin_bool_consistent().

◆ contains_required_value()

static bool contains_required_value ( ITEM curitem)
static

Definition at line 363 of file _int_bool.c.

364 {
365  /* since this function recurses, it could be driven to stack overflow */
367 
368  if (curitem->type == VAL)
369  return true;
370  else if (curitem->val == (int32) '!')
371  {
372  /*
373  * Assume anything under a NOT is non-required. For some cases with
374  * nested NOTs, we could prove there's a required value, but it seems
375  * unlikely to be worth the trouble.
376  */
377  return false;
378  }
379  else if (curitem->val == (int32) '&')
380  {
381  /* If either side has a required value, we're good */
382  if (contains_required_value(curitem + curitem->left))
383  return true;
384  else
385  return contains_required_value(curitem - 1);
386  }
387  else
388  { /* |-operator */
389  /* Both sides must have required values */
390  if (contains_required_value(curitem + curitem->left))
391  return contains_required_value(curitem - 1);
392  else
393  return false;
394  }
395 }
#define VAL
Definition: _int.h:162
static bool contains_required_value(ITEM *curitem)
Definition: _int_bool.c:363
void check_stack_depth(void)
Definition: postgres.c:3500
int16 left
Definition: _int.h:143

References check_stack_depth(), ITEM::left, ITEM::type, ITEM::val, and VAL.

Referenced by query_has_required_values().

◆ execconsistent()

bool execconsistent ( QUERYTYPE query,
ArrayType array,
bool  calcnot 
)

Definition at line 308 of file _int_bool.c.

309 {
310  CHKVAL chkval;
311 
312  CHECKARRVALID(array);
313  chkval.arrb = ARRPTR(array);
314  chkval.arre = chkval.arrb + ARRNELEMS(array);
315  return execute(GETQUERY(query) + query->size - 1,
316  (void *) &chkval, NULL, calcnot,
318 }

References CHKVAL::arrb, CHKVAL::arre, ARRNELEMS, ARRPTR, CHECKARRVALID, checkcondition_arr(), execute(), GETQUERY, and QUERYTYPE::size.

Referenced by g_int_consistent().

◆ execute()

static bool execute ( ITEM curitem,
void *  checkval,
void *  options,
bool  calcnot,
bool(*)(void *checkval, ITEM *item, void *options chkcond 
)
static

Definition at line 265 of file _int_bool.c.

267 {
268  /* since this function recurses, it could be driven to stack overflow */
270 
271  if (curitem->type == VAL)
272  return (*chkcond) (checkval, curitem, options);
273  else if (curitem->val == (int32) '!')
274  {
275  return calcnot ?
276  ((execute(curitem - 1, checkval, options, calcnot, chkcond)) ? false : true)
277  : true;
278  }
279  else if (curitem->val == (int32) '&')
280  {
281  if (execute(curitem + curitem->left, checkval, options, calcnot, chkcond))
282  return execute(curitem - 1, checkval, options, calcnot, chkcond);
283  else
284  return false;
285  }
286  else
287  { /* |-operator */
288  if (execute(curitem + curitem->left, checkval, options, calcnot, chkcond))
289  return true;
290  else
291  return execute(curitem - 1, checkval, options, calcnot, chkcond);
292  }
293 }
return true
Definition: isn.c:126
static char ** options

References check_stack_depth(), options, ITEM::type, and VAL.

Referenced by boolop(), execconsistent(), gin_bool_consistent(), and signconsistent().

◆ findoprnd()

static void findoprnd ( ITEM ptr,
int32 pos 
)
static

Definition at line 439 of file _int_bool.c.

440 {
441  /* since this function recurses, it could be driven to stack overflow. */
443 
444 #ifdef BS_DEBUG
445  elog(DEBUG3, (ptr[*pos].type == OPR) ?
446  "%d %c" : "%d %d", *pos, ptr[*pos].val);
447 #endif
448  if (ptr[*pos].type == VAL)
449  {
450  ptr[*pos].left = 0;
451  (*pos)--;
452  }
453  else if (ptr[*pos].val == (int32) '!')
454  {
455  ptr[*pos].left = -1;
456  (*pos)--;
457  findoprnd(ptr, pos);
458  }
459  else
460  {
461  ITEM *curitem = &ptr[*pos];
462  int32 tmp = *pos;
463 
464  (*pos)--;
465  findoprnd(ptr, pos);
466  curitem->left = *pos - tmp;
467  findoprnd(ptr, pos);
468  }
469 }

References check_stack_depth(), DEBUG3, elog, ITEM::left, OPR, generate_unaccent_rules::type, VAL, and val.

Referenced by bqarr_in().

◆ gettoken()

static int32 gettoken ( WORKSTATE state,
int32 val 
)
static

Definition at line 48 of file _int_bool.c.

49 {
50  char nnn[16];
51  int innn;
52 
53  *val = 0; /* default result */
54 
55  innn = 0;
56  while (1)
57  {
58  if (innn >= sizeof(nnn))
59  return ERR; /* buffer overrun => syntax error */
60  switch (state->state)
61  {
62  case WAITOPERAND:
63  innn = 0;
64  if ((*(state->buf) >= '0' && *(state->buf) <= '9') ||
65  *(state->buf) == '-')
66  {
67  state->state = WAITENDOPERAND;
68  nnn[innn++] = *(state->buf);
69  }
70  else if (*(state->buf) == '!')
71  {
72  (state->buf)++;
73  *val = (int32) '!';
74  return OPR;
75  }
76  else if (*(state->buf) == '(')
77  {
78  state->count++;
79  (state->buf)++;
80  return OPEN;
81  }
82  else if (*(state->buf) != ' ')
83  return ERR;
84  break;
85  case WAITENDOPERAND:
86  if (*(state->buf) >= '0' && *(state->buf) <= '9')
87  {
88  nnn[innn++] = *(state->buf);
89  }
90  else
91  {
92  long lval;
93 
94  nnn[innn] = '\0';
95  errno = 0;
96  lval = strtol(nnn, NULL, 0);
97  *val = (int32) lval;
98  if (errno != 0 || (long) *val != lval)
99  return ERR;
100  state->state = WAITOPERATOR;
101  return (state->count && *(state->buf) == '\0')
102  ? ERR : VAL;
103  }
104  break;
105  case WAITOPERATOR:
106  if (*(state->buf) == '&' || *(state->buf) == '|')
107  {
108  state->state = WAITOPERAND;
109  *val = (int32) *(state->buf);
110  (state->buf)++;
111  return OPR;
112  }
113  else if (*(state->buf) == ')')
114  {
115  (state->buf)++;
116  state->count--;
117  return (state->count < 0) ? ERR : CLOSE;
118  }
119  else if (*(state->buf) == '\0')
120  return (state->count) ? ERR : END;
121  else if (*(state->buf) != ' ')
122  return ERR;
123  break;
124  default:
125  return ERR;
126  break;
127  }
128  (state->buf)++;
129  }
130 }
#define CLOSE
Definition: _int.h:165
#define OPEN
Definition: _int.h:164
#define END
Definition: _int.h:160
#define ERR
Definition: _int.h:161
#define WAITENDOPERAND
Definition: _int_bool.c:19
#define WAITOPERATOR
Definition: _int_bool.c:20

References CLOSE, END, ERR, OPEN, OPR, VAL, val, WAITENDOPERAND, WAITOPERAND, and WAITOPERATOR.

Referenced by makepol().

◆ gin_bool_consistent()

bool gin_bool_consistent ( QUERYTYPE query,
bool check 
)

Definition at line 335 of file _int_bool.c.

336 {
337  GinChkVal gcv;
338  ITEM *items = GETQUERY(query);
339  int i,
340  j = 0;
341 
342  if (query->size <= 0)
343  return false;
344 
345  /*
346  * Set up data for checkcondition_gin. This must agree with the query
347  * extraction code in ginint4_queryextract.
348  */
349  gcv.first = items;
350  gcv.mapped_check = (bool *) palloc(sizeof(bool) * query->size);
351  for (i = 0; i < query->size; i++)
352  {
353  if (items[i].type == VAL)
354  gcv.mapped_check[i] = check[j++];
355  }
356 
357  return execute(GETQUERY(query) + query->size - 1,
358  (void *) &gcv, NULL, true,
360 }
static bool checkcondition_gin(void *checkval, ITEM *item, void *options)
Definition: _int_bool.c:327
int j
Definition: isn.c:74

References checkcondition_gin(), execute(), GinChkVal::first, GETQUERY, i, j, GinChkVal::mapped_check, palloc(), QUERYTYPE::size, generate_unaccent_rules::type, and VAL.

Referenced by ginint4_consistent().

◆ infix()

static void infix ( INFIX in,
bool  first 
)
static

Definition at line 563 of file _int_bool.c.

564 {
565  /* since this function recurses, it could be driven to stack overflow. */
567 
568  if (in->curpol->type == VAL)
569  {
570  RESIZEBUF(in, 11);
571  sprintf(in->cur, "%d", in->curpol->val);
572  in->cur = strchr(in->cur, '\0');
573  in->curpol--;
574  }
575  else if (in->curpol->val == (int32) '!')
576  {
577  bool isopr = false;
578 
579  RESIZEBUF(in, 1);
580  *(in->cur) = '!';
581  in->cur++;
582  *(in->cur) = '\0';
583  in->curpol--;
584  if (in->curpol->type == OPR)
585  {
586  isopr = true;
587  RESIZEBUF(in, 2);
588  sprintf(in->cur, "( ");
589  in->cur = strchr(in->cur, '\0');
590  }
591  infix(in, isopr);
592  if (isopr)
593  {
594  RESIZEBUF(in, 2);
595  sprintf(in->cur, " )");
596  in->cur = strchr(in->cur, '\0');
597  }
598  }
599  else
600  {
601  int32 op = in->curpol->val;
602  INFIX nrm;
603 
604  in->curpol--;
605  if (op == (int32) '|' && !first)
606  {
607  RESIZEBUF(in, 2);
608  sprintf(in->cur, "( ");
609  in->cur = strchr(in->cur, '\0');
610  }
611 
612  nrm.curpol = in->curpol;
613  nrm.buflen = 16;
614  nrm.cur = nrm.buf = (char *) palloc(sizeof(char) * nrm.buflen);
615 
616  /* get right operand */
617  infix(&nrm, false);
618 
619  /* get & print left operand */
620  in->curpol = nrm.curpol;
621  infix(in, false);
622 
623  /* print operator & right operand */
624  RESIZEBUF(in, 3 + (nrm.cur - nrm.buf));
625  sprintf(in->cur, " %c %s", op, nrm.buf);
626  in->cur = strchr(in->cur, '\0');
627  pfree(nrm.buf);
628 
629  if (op == (int32) '|' && !first)
630  {
631  RESIZEBUF(in, 2);
632  sprintf(in->cur, " )");
633  in->cur = strchr(in->cur, '\0');
634  }
635  }
636 }
#define RESIZEBUF(inf, addsize)
Definition: _int_bool.c:555
#define sprintf
Definition: port.h:227

References INFIX::buf, INFIX::buflen, check_stack_depth(), INFIX::cur, INFIX::curpol, OPR, palloc(), pfree(), RESIZEBUF, sprintf, ITEM::type, ITEM::val, and VAL.

Referenced by bqarr_out().

◆ makepol()

static int32 makepol ( WORKSTATE state)
static

Definition at line 153 of file _int_bool.c.

154 {
155  int32 val,
156  type;
157  int32 stack[STACKDEPTH];
158  int32 lenstack = 0;
159 
160  /* since this function recurses, it could be driven to stack overflow */
162 
163  while ((type = gettoken(state, &val)) != END)
164  {
165  switch (type)
166  {
167  case VAL:
168  pushquery(state, type, val);
169  while (lenstack && (stack[lenstack - 1] == (int32) '&' ||
170  stack[lenstack - 1] == (int32) '!'))
171  {
172  lenstack--;
173  pushquery(state, OPR, stack[lenstack]);
174  }
175  break;
176  case OPR:
177  if (lenstack && val == (int32) '|')
178  pushquery(state, OPR, val);
179  else
180  {
181  if (lenstack == STACKDEPTH)
182  ereport(ERROR,
183  (errcode(ERRCODE_STATEMENT_TOO_COMPLEX),
184  errmsg("statement too complex")));
185  stack[lenstack] = val;
186  lenstack++;
187  }
188  break;
189  case OPEN:
190  if (makepol(state) == ERR)
191  return ERR;
192  while (lenstack && (stack[lenstack - 1] == (int32) '&' ||
193  stack[lenstack - 1] == (int32) '!'))
194  {
195  lenstack--;
196  pushquery(state, OPR, stack[lenstack]);
197  }
198  break;
199  case CLOSE:
200  while (lenstack)
201  {
202  lenstack--;
203  pushquery(state, OPR, stack[lenstack]);
204  };
205  return END;
206  break;
207  case ERR:
208  default:
209  ereport(ERROR,
210  (errcode(ERRCODE_SYNTAX_ERROR),
211  errmsg("syntax error")));
212  return ERR;
213  }
214  }
215 
216  while (lenstack)
217  {
218  lenstack--;
219  pushquery(state, OPR, stack[lenstack]);
220  };
221  return END;
222 }
static void pushquery(WORKSTATE *state, int32 type, int32 val)
Definition: _int_bool.c:136
static int32 gettoken(WORKSTATE *state, int32 *val)
Definition: _int_bool.c:48
#define STACKDEPTH
Definition: _int_bool.c:147

References check_stack_depth(), CLOSE, END, ereport, ERR, errcode(), errmsg(), ERROR, gettoken(), OPEN, OPR, pushquery(), STACKDEPTH, generate_unaccent_rules::type, VAL, and val.

Referenced by bqarr_in().

◆ PG_FUNCTION_INFO_V1() [1/5]

PG_FUNCTION_INFO_V1 ( boolop  )

◆ PG_FUNCTION_INFO_V1() [2/5]

PG_FUNCTION_INFO_V1 ( bqarr_in  )

◆ PG_FUNCTION_INFO_V1() [3/5]

PG_FUNCTION_INFO_V1 ( bqarr_out  )

◆ PG_FUNCTION_INFO_V1() [4/5]

PG_FUNCTION_INFO_V1 ( querytree  )

◆ PG_FUNCTION_INFO_V1() [5/5]

PG_FUNCTION_INFO_V1 ( rboolop  )

◆ pushquery()

static void pushquery ( WORKSTATE state,
int32  type,
int32  val 
)
static

Definition at line 136 of file _int_bool.c.

137 {
138  NODE *tmp = (NODE *) palloc(sizeof(NODE));
139 
140  tmp->type = type;
141  tmp->val = val;
142  tmp->next = state->str;
143  state->str = tmp;
144  state->num++;
145 }
struct NODE * next
Definition: _int_bool.c:30
int32 val
Definition: _int_bool.c:29
int32 type
Definition: _int_bool.c:28

References NODE::next, palloc(), NODE::type, generate_unaccent_rules::type, NODE::val, and val.

Referenced by makepol().

◆ query_has_required_values()

bool query_has_required_values ( QUERYTYPE query)

Definition at line 398 of file _int_bool.c.

399 {
400  if (query->size <= 0)
401  return false;
402  return contains_required_value(GETQUERY(query) + query->size - 1);
403 }

References contains_required_value(), GETQUERY, and QUERYTYPE::size.

Referenced by ginint4_queryextract().

◆ querytree()

Datum querytree ( PG_FUNCTION_ARGS  )

Definition at line 663 of file _int_bool.c.

664 {
665  elog(ERROR, "querytree is no longer implemented");
666  PG_RETURN_NULL();
667 }
#define PG_RETURN_NULL()
Definition: fmgr.h:345

References elog, ERROR, and PG_RETURN_NULL.

Referenced by inline_function(), inline_set_returning_function(), and pg_plan_query().

◆ rboolop()

Datum rboolop ( PG_FUNCTION_ARGS  )

Definition at line 409 of file _int_bool.c.

410 {
411  /* just reverse the operands */
413  PG_GETARG_DATUM(1),
414  PG_GETARG_DATUM(0));
415 }
Datum boolop(PG_FUNCTION_ARGS)
Definition: _int_bool.c:418
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:633
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268

References boolop(), DirectFunctionCall2, and PG_GETARG_DATUM.

◆ signconsistent()

bool signconsistent ( QUERYTYPE query,
BITVECP  sign,
int  siglen,
bool  calcnot 
)

Definition at line 299 of file _int_bool.c.

300 {
301  return execute(GETQUERY(query) + query->size - 1,
302  (void *) sign, (void *) (intptr_t) siglen, calcnot,
304 }
static bool checkcondition_bit(void *checkval, ITEM *item, void *siglen)
Definition: _int_bool.c:256
char sign
Definition: informix.c:668

References checkcondition_bit(), execute(), GETQUERY, sign, and QUERYTYPE::size.

Referenced by g_intbig_consistent().