PostgreSQL Source Code  git master
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_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

Definition at line 71 of file conditional.h.

◆ ConditionalStackData

◆ IfStackElem

typedef struct IfStackElem IfStackElem

◆ ifState

typedef enum ifState ifState

Enumeration Type Documentation

◆ ifState

enum 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)

Definition at line 128 of file conditional.c.

129 {
130  ifState s = conditional_stack_peek(cstack);
131 
132  return s == IFSTATE_NONE || s == IFSTATE_TRUE || s == IFSTATE_ELSE_TRUE;
133 }
ifState conditional_stack_peek(ConditionalStack cstack)
Definition: conditional.c:94

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  )

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
IfStackElem * head
Definition: conditional.h:68

References ConditionalStackData::head, and pg_malloc().

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

◆ conditional_stack_depth()

int conditional_stack_depth ( ConditionalStack  cstack)

Definition at line 72 of file conditional.c.

73 {
74  if (cstack == NULL)
75  return -1;
76  else
77  {
78  IfStackElem *p = cstack->head;
79  int depth = 0;
80 
81  while (p != NULL)
82  {
83  depth++;
84  p = p->next;
85  }
86  return depth;
87  }
88 }
struct IfStackElem * next
Definition: conditional.h:63

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

◆ conditional_stack_destroy()

void conditional_stack_destroy ( ConditionalStack  cstack)

Definition at line 30 of file conditional.c.

31 {
32  while (conditional_stack_pop(cstack))
33  continue;
34  free(cstack);
35 }
bool conditional_stack_pop(ConditionalStack cstack)
Definition: conditional.c:57
#define free(a)
Definition: header.h:65

References conditional_stack_pop(), and free.

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

◆ conditional_stack_empty()

◆ conditional_stack_get_paren_depth()

int conditional_stack_get_paren_depth ( ConditionalStack  cstack)

Definition at line 172 of file conditional.c.

173 {
174  if (conditional_stack_empty(cstack))
175  return -1;
176  return cstack->head->paren_depth;
177 }
bool conditional_stack_empty(ConditionalStack cstack)
Definition: conditional.c:118
int paren_depth
Definition: conditional.h:62

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)

Definition at line 150 of file conditional.c.

151 {
152  if (conditional_stack_empty(cstack))
153  return -1;
154  return cstack->head->query_len;
155 }

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 
)

Definition at line 106 of file conditional.c.

107 {
108  if (conditional_stack_empty(cstack))
109  return false;
110  cstack->head->if_state = new_state;
111  return true;
112 }

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

Referenced by advanceConnectionState(), CheckConditional(), exec_command_elif(), exec_command_else(), exec_command_if(), and executeMetaCommand().

◆ conditional_stack_pop()

bool conditional_stack_pop ( ConditionalStack  cstack)

Definition at line 57 of file conditional.c.

58 {
59  IfStackElem *p = cstack->head;
60 
61  if (!p)
62  return false;
63  cstack->head = cstack->head->next;
64  free(p);
65  return true;
66 }

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

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

◆ conditional_stack_push()

void conditional_stack_push ( ConditionalStack  cstack,
ifState  new_state 
)

Definition at line 41 of file conditional.c.

42 {
43  IfStackElem *p = (IfStackElem *) pg_malloc(sizeof(IfStackElem));
44 
45  p->if_state = new_state;
46  p->query_len = -1;
47  p->paren_depth = -1;
48  p->next = cstack->head;
49  cstack->head = p;
50 }

References ConditionalStackData::head, IfStackElem::if_state, IfStackElem::next, IfStackElem::paren_depth, pg_malloc(), and IfStackElem::query_len.

Referenced by advanceConnectionState(), CheckConditional(), exec_command_if(), executeMetaCommand(), and HandleSlashCmds().

◆ conditional_stack_set_paren_depth()

void conditional_stack_set_paren_depth ( ConditionalStack  cstack,
int  depth 
)

Definition at line 161 of file conditional.c.

162 {
164  cstack->head->paren_depth = depth;
165 }
Assert(fmt[strlen(fmt) - 1] !='\n')

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 
)

Definition at line 139 of file conditional.c.

140 {
142  cstack->head->query_len = len;
143 }
const void size_t len

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

Referenced by save_query_text_state().