PostgreSQL Source Code git master
Loading...
Searching...
No Matches
conditional.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  IfStackElem
 
struct  ConditionalStackData
 

Typedefs

typedef enum ifState ifState
 
typedef struct IfStackElem IfStackElem
 
typedef struct ConditionalStackData ConditionalStackData
 
typedef struct ConditionalStackDataConditionalStack
 

Enumerations

enum  ifState {
  IFSTATE_NONE = 0 , IFSTATE_TRUE , IFSTATE_FALSE , IFSTATE_IGNORED ,
  IFSTATE_ELSE_TRUE , IFSTATE_ELSE_FALSE
}
 

Functions

ConditionalStack conditional_stack_create (void)
 
void conditional_stack_reset (ConditionalStack cstack)
 
void conditional_stack_destroy (ConditionalStack cstack)
 
int conditional_stack_depth (ConditionalStack cstack)
 
void conditional_stack_push (ConditionalStack cstack, ifState new_state)
 
bool conditional_stack_pop (ConditionalStack cstack)
 
ifState conditional_stack_peek (ConditionalStack cstack)
 
bool conditional_stack_poke (ConditionalStack cstack, ifState new_state)
 
bool conditional_stack_empty (ConditionalStack cstack)
 
bool conditional_active (ConditionalStack cstack)
 
void conditional_stack_set_query_len (ConditionalStack cstack, int len)
 
int conditional_stack_get_query_len (ConditionalStack cstack)
 
void conditional_stack_set_paren_depth (ConditionalStack cstack, int depth)
 
int conditional_stack_get_paren_depth (ConditionalStack cstack)
 

Typedef Documentation

◆ ConditionalStack

◆ ConditionalStackData

◆ IfStackElem

◆ ifState

Enumeration Type Documentation

◆ ifState

Enumerator
IFSTATE_NONE 
IFSTATE_TRUE 
IFSTATE_FALSE 
IFSTATE_IGNORED 
IFSTATE_ELSE_TRUE 
IFSTATE_ELSE_FALSE 

Definition at line 29 of file conditional.h.

30{
31 IFSTATE_NONE = 0, /* not currently in an \if block */
32 IFSTATE_TRUE, /* currently in an \if or \elif that is true
33 * and all parent branches (if any) are true */
34 IFSTATE_FALSE, /* currently in an \if or \elif that is false
35 * but no true branch has yet been seen, and
36 * all parent branches (if any) are true */
37 IFSTATE_IGNORED, /* currently in an \elif that follows a true
38 * branch, or the whole \if is a child of a
39 * false parent branch */
40 IFSTATE_ELSE_TRUE, /* currently in an \else that is true and all
41 * parent branches (if any) are true */
42 IFSTATE_ELSE_FALSE, /* currently in an \else that is false or
43 * ignored */
44} ifState;
ifState
Definition conditional.h:30
@ IFSTATE_FALSE
Definition conditional.h:34
@ IFSTATE_ELSE_TRUE
Definition conditional.h:40
@ IFSTATE_IGNORED
Definition conditional.h:37
@ IFSTATE_TRUE
Definition conditional.h:32
@ IFSTATE_NONE
Definition conditional.h:31
@ IFSTATE_ELSE_FALSE
Definition conditional.h:42

Function Documentation

◆ conditional_active()

bool conditional_active ( ConditionalStack  cstack)
extern

Definition at line 140 of file conditional.c.

141{
143
144 return s == IFSTATE_NONE || s == IFSTATE_TRUE || s == IFSTATE_ELSE_TRUE;
145}
ifState conditional_stack_peek(ConditionalStack cstack)

References conditional_stack_peek(), IFSTATE_ELSE_TRUE, IFSTATE_NONE, and IFSTATE_TRUE.

Referenced by advanceConnectionState(), exec_command(), exec_command_if(), get_prompt(), HandleSlashCmds(), MainLoop(), and psql_get_variable().

◆ conditional_stack_create()

ConditionalStack conditional_stack_create ( void  )
extern

Definition at line 18 of file conditional.c.

19{
21
22 cstack->head = NULL;
23 return cstack;
24}
void * pg_malloc(size_t size)
Definition fe_memutils.c:47
static int fb(int x)
IfStackElem * head
Definition conditional.h:68

References fb(), ConditionalStackData::head, and pg_malloc().

Referenced by CheckConditional(), main(), main(), and MainLoop().

◆ conditional_stack_depth()

int conditional_stack_depth ( ConditionalStack  cstack)
extern

Definition at line 84 of file conditional.c.

85{
86 if (cstack == NULL)
87 return -1;
88 else
89 {
90 IfStackElem *p = cstack->head;
91 int depth = 0;
92
93 while (p != NULL)
94 {
95 depth++;
96 p = p->next;
97 }
98 return depth;
99 }
100}
struct IfStackElem * next
Definition conditional.h:63

References fb(), ConditionalStackData::head, and IfStackElem::next.

◆ conditional_stack_destroy()

void conditional_stack_destroy ( ConditionalStack  cstack)
extern

Definition at line 43 of file conditional.c.

44{
46 free(cstack);
47}
void conditional_stack_reset(ConditionalStack cstack)
Definition conditional.c:30
#define free(a)

References conditional_stack_reset(), and free.

Referenced by CheckConditional(), main(), and MainLoop().

◆ conditional_stack_empty()

◆ conditional_stack_get_paren_depth()

int conditional_stack_get_paren_depth ( ConditionalStack  cstack)
extern

Definition at line 184 of file conditional.c.

185{
186 if (conditional_stack_empty(cstack))
187 return -1;
188 return cstack->head->paren_depth;
189}
bool conditional_stack_empty(ConditionalStack cstack)

References conditional_stack_empty(), ConditionalStackData::head, and IfStackElem::paren_depth.

Referenced by discard_query_text().

◆ conditional_stack_get_query_len()

int conditional_stack_get_query_len ( ConditionalStack  cstack)
extern

Definition at line 162 of file conditional.c.

163{
164 if (conditional_stack_empty(cstack))
165 return -1;
166 return cstack->head->query_len;
167}

References conditional_stack_empty(), ConditionalStackData::head, and IfStackElem::query_len.

Referenced by discard_query_text().

◆ conditional_stack_peek()

◆ conditional_stack_poke()

bool conditional_stack_poke ( ConditionalStack  cstack,
ifState  new_state 
)
extern

◆ conditional_stack_pop()

bool conditional_stack_pop ( ConditionalStack  cstack)
extern

Definition at line 69 of file conditional.c.

70{
71 IfStackElem *p = cstack->head;
72
73 if (!p)
74 return false;
75 cstack->head = cstack->head->next;
76 free(p);
77 return true;
78}

References free, ConditionalStackData::head, and IfStackElem::next.

Referenced by advanceConnectionState(), CheckConditional(), conditional_stack_reset(), exec_command_endif(), executeMetaCommand(), HandleSlashCmds(), and MainLoop().

◆ conditional_stack_push()

void conditional_stack_push ( ConditionalStack  cstack,
ifState  new_state 
)
extern

◆ conditional_stack_reset()

void conditional_stack_reset ( ConditionalStack  cstack)
extern

Definition at line 30 of file conditional.c.

31{
32 if (!cstack)
33 return; /* nothing to do here */
34
35 while (conditional_stack_pop(cstack))
36 continue;
37}
bool conditional_stack_pop(ConditionalStack cstack)
Definition conditional.c:69

References conditional_stack_pop().

Referenced by advanceConnectionState(), and conditional_stack_destroy().

◆ conditional_stack_set_paren_depth()

void conditional_stack_set_paren_depth ( ConditionalStack  cstack,
int  depth 
)
extern

Definition at line 173 of file conditional.c.

174{
176 cstack->head->paren_depth = depth;
177}
#define Assert(condition)
Definition c.h:873

References Assert, conditional_stack_empty(), ConditionalStackData::head, and IfStackElem::paren_depth.

Referenced by save_query_text_state().

◆ conditional_stack_set_query_len()

void conditional_stack_set_query_len ( ConditionalStack  cstack,
int  len 
)
extern

Definition at line 151 of file conditional.c.

152{
154 cstack->head->query_len = len;
155}
const void size_t len

References Assert, conditional_stack_empty(), ConditionalStackData::head, len, and IfStackElem::query_len.

Referenced by save_query_text_state().