27#define ASSERT_STTYPE_NOT_REACHED(st) \
28 ws_error("Invalid syntax node type '%s'.", sttype_name(st))
30#define ASSERT_STNODE_OP_NOT_REACHED(op) \
31 ws_error("Invalid stnode op '%s'.", stnode_op_name(op))
61typedef void *(*STTypeNewFunc)(
void *data);
68typedef void *(*STTypeDupFunc)(
const void *data);
82typedef char *(*STTypeToStrFunc)(
const void *data,
bool pretty);
109#define STFLAG_UNPARSED (1 << 0)
478#define stnode_todisplay(node) stnode_tostr(node, true)
488#define stnode_todebug(node) stnode_tostr(node, false)
502 const char *file,
int line,
const char *func,
517 const char *file,
int line,
const char *func,
521#define log_node(node) \
522 log_node_full(LOG_LEVEL_NOISY, __FILE__, __LINE__, __func__, node, #node)
523#define log_test(node) \
524 log_test_full(LOG_LEVEL_NOISY, __FILE__, __LINE__, __func__, node, #node)
525#define LOG_NODE(node) \
527 if (stnode_type_id(node) == STTYPE_TEST) \
533#define log_node(node) (void)0
534#define log_test(node) (void)0
535#define LOG_NODE(node) (void)0
559#define ws_assert_magic(obj, mnum) \
562 if ((obj)->magic != (mnum)) { \
563 ws_log_full(LOG_DOMAIN_DFILTER, LOG_LEVEL_ERROR, \
564 __FILE__, __LINE__, __func__, \
565 "Magic num is 0x%08" PRIx32", " \
566 "but should be 0x%08" PRIx32, \
567 (obj)->magic, (mnum)); \
571#define ws_assert_magic(obj, mnum) (void)0
Represents a location (column start and length) within a display filter string.
Definition dfilter-loc.h:19
A single node instance in the display filter syntax tree.
Definition syntax-tree.h:115
df_loc_t location
Definition syntax-tree.h:121
uint16_t flags
Definition syntax-tree.h:122
void * data
Definition syntax-tree.h:117
char * repr_debug
Definition syntax-tree.h:120
char * repr_token
Definition syntax-tree.h:118
char * repr_display
Definition syntax-tree.h:119
sttype_t * type
Definition syntax-tree.h:116
Describes a syntax tree node type, including its lifecycle and serialization callbacks.
Definition syntax-tree.h:88
sttype_id_t id
Definition syntax-tree.h:89
STTypeToStrFunc func_tostr
Definition syntax-tree.h:93
STTypeNewFunc func_new
Definition syntax-tree.h:90
STTypeFreeFunc func_free
Definition syntax-tree.h:91
STTypeDupFunc func_dup
Definition syntax-tree.h:92
void sttype_cleanup(void)
Cleans up resources associated with the syntax tree types.
Definition syntax-tree.c:38
WS_DLL_PUBLIC void stnode_init(stnode_t *node, sttype_id_t type_id, void *data, char *token, df_loc_t loc)
Initialize a syntax tree node.
Definition syntax-tree.c:206
WS_DLL_PUBLIC void stnode_set_location(stnode_t *node, df_loc_t loc)
Set the location for a syntax tree node.
Definition syntax-tree.c:351
void log_test_full(enum ws_log_level level, const char *file, int line, const char *func, stnode_t *node, const char *msg)
Logs a full test message for a syntax tree node.
Definition syntax-tree.c:475
WS_DLL_PUBLIC void stnode_set_flags(stnode_t *node, uint16_t flags)
Sets flags for a syntax tree node.
Definition syntax-tree.c:363
void sttype_register_set(void)
Register the set type in the syntax tree type system.
Definition sttype-set.c:92
void sttype_register(sttype_t *type)
Registers a syntax tree type.
Definition syntax-tree.c:45
WS_DLL_PUBLIC void stnode_free(stnode_t *node)
Frees a syntax tree node.
Definition syntax-tree.c:295
WS_DLL_PUBLIC stnode_t * stnode_new_empty(sttype_id_t type_id)
Creates a new empty syntax tree node.
Definition syntax-tree.c:265
void sttype_register_slice(void)
Register the slice type in the syntax tree type system.
Definition sttype-slice.c:168
void sttype_init(void)
Initialize the syntax tree types.
Definition syntax-tree.c:25
WS_DLL_PUBLIC const char * sttype_name(const sttype_id_t type)
Get the name of a syntax tree type.
Definition syntax-tree.c:77
WS_DLL_PUBLIC void stnode_mutate(stnode_t *node, sttype_id_t type_id)
Mutates the type of a syntax tree node.
Definition syntax-tree.c:249
stnumber_t
Numeric sub-type tag for STTYPE_NUMBER nodes.
Definition syntax-tree.h:100
@ STNUM_FLOAT
Definition syntax-tree.h:104
@ STNUM_NONE
Definition syntax-tree.h:101
@ STNUM_UNSIGNED
Definition syntax-tree.h:103
@ STNUM_INTEGER
Definition syntax-tree.h:102
void log_syntax_tree(enum ws_log_level level, stnode_t *root, const char *msg, char **cache_ptr)
Logs a syntax tree with an optional message and caches the result.
Definition syntax-tree.c:593
stmatch_t
Quantifier controlling how many field values must satisfy a match condition.
Definition syntax-tree.h:159
@ STNODE_MATCH_ANY
Definition syntax-tree.h:161
@ STNODE_MATCH_DEF
Definition syntax-tree.h:160
@ STNODE_MATCH_ALL
Definition syntax-tree.h:162
WS_DLL_PUBLIC const char * stnode_tostr(stnode_t *node, bool pretty)
Convert a syntax tree node to a string representation.
Definition syntax-tree.c:414
WS_DLL_PUBLIC stnode_t * stnode_dup(const stnode_t *org)
Duplicates a syntax tree node.
Definition syntax-tree.c:272
sttype_id_t
Type identifier tags for syntax tree nodes in the display filter compiler.
Definition syntax-tree.h:36
@ STTYPE_SET
Definition syntax-tree.h:49
@ STTYPE_PCRE
Definition syntax-tree.h:50
@ STTYPE_SLICE
Definition syntax-tree.h:47
@ STTYPE_STRING
Definition syntax-tree.h:42
@ STTYPE_UNINITIALIZED
Definition syntax-tree.h:37
@ STTYPE_CHARCONST
Definition syntax-tree.h:43
@ STTYPE_NUM_TYPES
Definition syntax-tree.h:52
@ STTYPE_TEST
Definition syntax-tree.h:38
@ STTYPE_REFERENCE
Definition syntax-tree.h:41
@ STTYPE_FUNCTION
Definition syntax-tree.h:48
@ STTYPE_LITERAL
Definition syntax-tree.h:40
@ STTYPE_FIELD
Definition syntax-tree.h:45
@ STTYPE_NUMBER
Definition syntax-tree.h:44
@ STTYPE_ARITHMETIC
Definition syntax-tree.h:51
@ STTYPE_FVALUE
Definition syntax-tree.h:46
@ STTYPE_UNPARSED
Definition syntax-tree.h:39
WS_DLL_PUBLIC GString * stnode_string(stnode_t *node)
Retrieves the string data from a syntax tree node.
Definition syntax-tree.c:323
void sttype_register_pointer(void)
Register the pointer type in the syntax tree type system.
Definition sttype-pointer.c:125
WS_DLL_PUBLIC const char * stnode_token(const stnode_t *node)
Retrieves the token representation of a syntax tree node.
Definition syntax-tree.c:339
void *(* STTypeNewFunc)(void *data)
Allocates and initializes type-specific data for a syntax tree node.
Definition syntax-tree.h:61
WS_DLL_PUBLIC void stnode_clear(stnode_t *node)
Clears the contents of a syntax tree node.
Definition syntax-tree.c:181
WS_DLL_PUBLIC bool stnode_get_flags(stnode_t *node, uint16_t flags)
Get flags from a syntax tree node.
Definition syntax-tree.c:357
void sttype_register_string(void)
Register the string type in the syntax tree type system.
Definition sttype-string.c:53
WS_DLL_PUBLIC void * stnode_data(stnode_t *node)
Retrieves the data associated with a syntax tree node.
Definition syntax-tree.c:317
void log_node_full(enum ws_log_level level, const char *file, int line, const char *func, stnode_t *node, const char *msg)
Logs a full message with detailed information about a syntax tree node.
Definition syntax-tree.c:453
WS_DLL_PUBLIC sttype_id_t stnode_type_id(const stnode_t *node)
Retrieves the type ID of a syntax tree node.
Definition syntax-tree.c:308
char *(* STTypeToStrFunc)(const void *data, bool pretty)
Converts type-specific node data to a human-readable string.
Definition syntax-tree.h:82
void sttype_register_number(void)
Register the number type in the syntax tree type system.
Definition sttype-number.c:146
void sttype_register_opers(void)
Register the operator types in the syntax tree type system.
Definition sttype-op.c:304
void sttype_register_field(void)
Register the field type in the syntax tree type system.
Definition sttype-field.c:229
WS_DLL_PUBLIC void stnode_replace(stnode_t *node, sttype_id_t type_id, void *data)
Replaces a node in the syntax tree with a new type and data.
Definition syntax-tree.c:238
void sttype_register_function(void)
Register the function type in the syntax tree type system.
Definition sttype-function.c:151
WS_DLL_PUBLIC const char * stnode_type_name(const stnode_t *node)
Get the type name of a syntax tree node.
Definition syntax-tree.c:302
void *(* STTypeDupFunc)(const void *data)
Performs a deep copy of type-specific node data.
Definition syntax-tree.h:68
WS_DLL_PUBLIC df_loc_t stnode_location(const stnode_t *node)
Get the location of a syntax tree node.
Definition syntax-tree.c:345
void stnode_merge_location(stnode_t *dst, stnode_t *n1, stnode_t *n2)
Merges location information from two syntax tree nodes into a destination node.
Definition syntax-tree.c:372
char * dump_syntax_tree_str(stnode_t *root)
Dumps a syntax tree to a string.
Definition syntax-tree.c:584
struct stnode stnode_t
A single node instance in the display filter syntax tree.
stnode_op_t
Operator types for test and arithmetic syntax tree nodes.
Definition syntax-tree.h:129
@ STNODE_OP_ALL_NE
Definition syntax-tree.h:136
@ STNODE_OP_MULTIPLY
Definition syntax-tree.h:150
@ STNODE_OP_UNARY_MINUS
Definition syntax-tree.h:147
@ STNODE_OP_SUBTRACT
Definition syntax-tree.h:149
@ STNODE_OP_OR
Definition syntax-tree.h:133
@ STNODE_OP_GT
Definition syntax-tree.h:138
@ STNODE_OP_BITWISE_AND
Definition syntax-tree.h:146
@ STNODE_OP_DIVIDE
Definition syntax-tree.h:151
@ STNODE_OP_LT
Definition syntax-tree.h:140
@ STNODE_OP_NOT
Definition syntax-tree.h:131
@ STNODE_OP_AND
Definition syntax-tree.h:132
@ STNODE_OP_MATCHES
Definition syntax-tree.h:143
@ STNODE_OP_MODULO
Definition syntax-tree.h:152
@ STNODE_OP_CONTAINS
Definition syntax-tree.h:142
@ STNODE_OP_LE
Definition syntax-tree.h:141
@ STNODE_OP_IN
Definition syntax-tree.h:144
@ STNODE_OP_ANY_NE
Definition syntax-tree.h:137
@ STNODE_OP_UNINITIALIZED
Definition syntax-tree.h:130
@ STNODE_OP_GE
Definition syntax-tree.h:139
@ STNODE_OP_ADD
Definition syntax-tree.h:148
@ STNODE_OP_NOT_IN
Definition syntax-tree.h:145
@ STNODE_OP_ANY_EQ
Definition syntax-tree.h:135
@ STNODE_OP_ALL_EQ
Definition syntax-tree.h:134
WS_DLL_PUBLIC stnode_t * stnode_new(sttype_id_t type_id, void *data, char *token, df_loc_t loc)
Creates a new syntax tree node with the given type ID, data, token, and location.
Definition syntax-tree.c:257
WS_DLL_PUBLIC const char * stnode_op_name(const stnode_op_t op)
Get the name of an operation based on its type.
Definition syntax-tree.c:101
void(* STTypeFreeFunc)(void *data)
Releases type-specific data associated with a syntax tree node.
Definition syntax-tree.h:74
WS_DLL_PUBLIC void * stnode_steal_data(stnode_t *node)
Steals and returns the data associated with a syntax tree node.
Definition syntax-tree.c:330