• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef __SQLHIST_PARSE_H
2 #define __SQLHIST_PARSE_H
3 
4 #include <stdarg.h>
5 #include <tracefs.h>
6 
7 #include <tracefs-local.h>
8 
9 struct str_hash;
10 
11 struct sql_table;
12 
13 struct sqlhist_bison {
14 	void			*scanner;
15 	const char		*buffer;
16 	size_t			buffer_size;
17 	size_t			buffer_idx;
18 	int			line_no;
19 	int			line_idx;
20 	struct sql_table	*table;
21 	char			*parse_error_str;
22 	struct str_hash         *str_hash[1 << HASH_BITS];
23 };
24 
25 #include "sqlhist.tab.h"
26 
27 enum filter_type {
28 	FILTER_GROUP,
29 	FILTER_NOT_GROUP,
30 	FILTER_EQ,
31 	FILTER_NE,
32 	FILTER_LE,
33 	FILTER_LT,
34 	FILTER_GE,
35 	FILTER_GT,
36 	FILTER_BIN_AND,
37 	FILTER_STR_CMP,
38 	FILTER_AND,
39 	FILTER_OR,
40 };
41 
42 enum compare_type {
43 	COMPARE_GROUP,
44 	COMPARE_ADD,
45 	COMPARE_SUB,
46 	COMPARE_MUL,
47 	COMPARE_DIV,
48 	COMPARE_BIN_AND,
49 	COMPARE_BIN_OR,
50 	COMPARE_AND,
51 	COMPARE_OR,
52 };
53 
54 char * store_str(struct sqlhist_bison *sb, const char *str);
55 
56 int table_start(struct sqlhist_bison *sb);
57 
58 void *add_field(struct sqlhist_bison *sb, const char *field, const char *label);
59 
60 void *add_filter(struct sqlhist_bison *sb, void *A, void *B, enum filter_type op);
61 
62 int add_match(struct sqlhist_bison *sb, void *A, void *B);
63 void *add_compare(struct sqlhist_bison *sb, void *A, void *B, enum compare_type type);
64 int add_where(struct sqlhist_bison *sb, void *expr);
65 
66 int add_selection(struct sqlhist_bison *sb, void *item, const char *label);
67 int add_from(struct sqlhist_bison *sb, void *item);
68 int add_to(struct sqlhist_bison *sb, void *item);
69 void *add_cast(struct sqlhist_bison *sb, void *field, const char *type);
70 
71 void *add_string(struct sqlhist_bison *sb, const char *str);
72 void *add_number(struct sqlhist_bison *sb, long val);
73 
74 extern void sql_parse_error(struct sqlhist_bison *sb, const char *text,
75 			    const char *fmt, va_list ap);
76 
77 #endif
78