forked from facebook/watchman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
watchman_query.h
182 lines (144 loc) · 4 KB
/
watchman_query.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/* Copyright 2012-present Facebook, Inc.
* Licensed under the Apache License, Version 2.0 */
#ifndef WATCHMAN_QUERY_H
#define WATCHMAN_QUERY_H
#ifdef __cplusplus
extern "C" {
#endif
struct w_query;
typedef struct w_query w_query;
struct w_query_expr;
typedef struct w_query_expr w_query_expr;
// Holds state for the execution of a query
struct w_query_ctx {
struct w_query *query;
w_root_t *root;
struct watchman_file *file;
w_string_t *wholename;
struct w_query_since since;
struct watchman_rule_match *results;
uint32_t num_results;
uint32_t num_allocd;
};
struct w_query_path {
w_string_t *name;
int depth;
};
typedef bool (*w_query_expr_eval_func)(
struct w_query_ctx *ctx,
struct watchman_file *file,
void *data
);
typedef void (*w_query_expr_dispose_func)(
void *data
);
struct w_query_expr {
int refcnt;
w_query_expr_eval_func evaluate;
w_query_expr_dispose_func dispose;
void *data;
};
struct w_query {
int refcnt;
bool case_sensitive;
struct w_query_path *paths;
uint32_t npaths;
w_string_t **suffixes;
uint32_t nsuffixes;
uint32_t sync_timeout;
bool empty_on_fresh_instance;
// We can't (and mustn't!) evaluate the clockspec
// fully until we execute query, because we have
// to evaluate named cursors and determine fresh
// instance at the time we execute
struct w_clockspec *since_spec;
w_query_expr *expr;
// Error message placeholder while parsing
char *errmsg;
};
typedef w_query_expr *(*w_query_expr_parser)(
w_query *query,
json_t *term
);
bool w_query_register_expression_parser(
const char *term,
w_query_expr_parser parser);
w_query *w_query_parse(w_root_t *root, json_t *query, char **errmsg);
void w_query_delref(w_query *query);
w_query_expr *w_query_expr_parse(w_query *query, json_t *term);
void w_query_expr_delref(w_query_expr *expr);
void w_query_expr_addref(w_query_expr *expr);
w_query_expr *w_query_expr_new(
w_query_expr_eval_func evaluate,
w_query_expr_dispose_func dispose,
void *data
);
// Allows a generator to process a file node
// through the query engine
bool w_query_process_file(
w_query *query,
struct w_query_ctx *ctx,
struct watchman_file *file);
// Generator callback, used to plug in an alternate
// generator when used in triggers or subscriptions
typedef bool (*w_query_generator)(
w_query *query,
w_root_t *root,
struct w_query_ctx *ctx,
void *gendata
);
struct w_query_result {
bool is_fresh_instance;
uint32_t num_results;
struct watchman_rule_match *results;
uint32_t root_number;
uint32_t ticks;
char *errmsg;
};
typedef struct w_query_result w_query_res;
void w_query_result_free(w_query_res *res);
bool w_query_execute(
w_query *query,
w_root_t *root,
w_query_res *results,
w_query_generator generator,
void *gendata
);
// Returns a shared reference to the wholename
// of the file. The caller must not delref
// the reference.
w_string_t *w_query_ctx_get_wholename(
struct w_query_ctx *ctx
);
bool w_query_expr_evaluate(
w_query_expr *expr,
struct w_query_ctx *ctx,
struct watchman_file *file);
struct w_query_field_renderer;
struct w_query_field_list {
unsigned int num_fields;
struct w_query_field_renderer *fields[32];
};
// parse the old style since and find queries
w_query *w_query_parse_legacy(w_root_t *root, json_t *args, char **errmsg,
int start, uint32_t *next_arg, const char *clockspec, json_t **expr_p);
bool w_query_legacy_field_list(struct w_query_field_list *flist);
json_t *w_query_results_to_json(
struct w_query_field_list *field_list,
uint32_t num_results,
struct watchman_rule_match *results);
void w_query_init_all(void);
bool parse_field_list(json_t *field_list,
struct w_query_field_list *selected,
char **errmsg);
#define W_TERM_PARSER(name, func) \
static __attribute__((constructor)) \
void w_gen_symbol(w_term_register_)(void) { \
w_query_register_expression_parser(name, func); \
}
#ifdef __cplusplus
}
#endif
#endif
/* vim:ts=2:sw=2:et:
*/