1#ifndef __query__ 2#define __query__ 3 4typedef enum 5{ 6 /* node opcodes */ 7 qot_empty, 8 9 /* conjunctions */ 10 qot_and, 11 qot_or, 12 13 /* negation */ 14 qot_not, 15 16 /* arithmetic */ 17 qot_eq, 18 qot_ne, 19 qot_le, 20 qot_lt, 21 qot_ge, 22 qot_gt, 23 24 /* string */ 25 qot_is, 26 qot_begins, 27 qot_ends, 28 qot_contains, 29 30 /* constant opcode */ 31 qot_const, 32 33 /* field types */ 34 qft_i32, 35 qft_i64, 36 qft_string 37 38} query_type_t; 39 40typedef struct query_field_ query_field_t; 41struct query_field_ 42{ 43 query_type_t type; 44 const char* name; 45 int offset; 46}; 47 48typedef struct query_node_ query_node_t; 49struct query_node_ 50{ 51 query_type_t type; 52 union { 53 query_node_t* node; 54 const query_field_t* field; 55 int constant; 56 } left; 57 union { 58 query_node_t* node; 59 int i32; 60 long long i64; 61 char* str; 62 } right; 63}; 64 65query_node_t* query_build(const char* query, 66 const query_field_t* fields); 67int query_test(query_node_t* query, void* target); 68void query_free(query_node_t* query); 69void query_dump(FILE* fp, query_node_t* query, int depth); 70 71#endif 72