1/*-------------------------------------------------------------------------
2 * A stack of automaton states to handle nested conditionals.
4 * This file describes a stack of automaton states which
5 * allow a manage nested conditionals.
8 * - "psql" interpreter for handling \if ... \endif
9 * - "pgbench" interpreter for handling \if ... \endif
10 * - "pgbench" syntax checker to test for proper nesting
12 * The stack holds the state of enclosing conditionals (are we in
13 * a true branch? in a false branch? have we already encountered
14 * a true branch?) so that the interpreter knows whether to execute
15 * code and whether to evaluate conditions.
17 * Copyright (c) 2000-2025, PostgreSQL Global Development Group
19 * src/include/fe_utils/conditional.h
21 *-------------------------------------------------------------------------
27 * Possible states of a single level of \if block.
33 * and all parent branches (if any) are true */
35 * but no true branch has yet been seen, and
36 * all parent branches (if any) are true */
38 * branch, or the whole \if is a child of a
39 * false parent branch */
41 * parent branches (if any) are true */
47 * The state of nested \ifs is stored in a stack.
49 * query_len is used to determine what accumulated text to throw away at the
50 * end of an inactive branch. (We could, perhaps, teach the lexer to not add
51 * stuff to the query buffer in the first place when inside an inactive branch;
52 * but that would be very invasive.) We also need to save and restore the
53 * lexer's parenthesis nesting depth when throwing away text. (We don't need
54 * to save and restore any of its other state, such as comment nesting depth,
55 * because a backslash command could never appear inside a comment or SQL
61 int query_len;
/* length of query_buf at last branch start */
102#endif /* CONDITIONAL_H */
struct ConditionalStackData ConditionalStackData
void conditional_stack_set_paren_depth(ConditionalStack cstack, int depth)
ifState conditional_stack_peek(ConditionalStack cstack)
struct IfStackElem IfStackElem
void conditional_stack_push(ConditionalStack cstack, ifState new_state)
ConditionalStack conditional_stack_create(void)
int conditional_stack_depth(ConditionalStack cstack)
bool conditional_stack_pop(ConditionalStack cstack)
void conditional_stack_destroy(ConditionalStack cstack)
struct ConditionalStackData * ConditionalStack
void conditional_stack_set_query_len(ConditionalStack cstack, int len)
int conditional_stack_get_query_len(ConditionalStack cstack)
bool conditional_active(ConditionalStack cstack)
void conditional_stack_reset(ConditionalStack cstack)
int conditional_stack_get_paren_depth(ConditionalStack cstack)
bool conditional_stack_poke(ConditionalStack cstack, ifState new_state)
bool conditional_stack_empty(ConditionalStack cstack)
struct IfStackElem * next