1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef PARSE_CTX_H 3 #define PARSE_CTX_H 1 4 5 #ifdef HAVE_LIBBPF_SUPPORT 6 #include <bpf/hashmap.h> 7 #else 8 #include "util/hashmap.h" 9 #endif 10 11 struct metric_ref; 12 13 struct expr_parse_ctx { 14 struct hashmap *ids; 15 int runtime; 16 }; 17 18 struct expr_id_data; 19 20 struct expr_scanner_ctx { 21 int runtime; 22 }; 23 24 struct hashmap *ids__new(void); 25 void ids__free(struct hashmap *ids); 26 int ids__insert(struct hashmap *ids, const char *id); 27 /* 28 * Union two sets of ids (hashmaps) and construct a third, freeing ids1 and 29 * ids2. 30 */ 31 struct hashmap *ids__union(struct hashmap *ids1, struct hashmap *ids2); 32 33 struct expr_parse_ctx *expr__ctx_new(void); 34 void expr__ctx_clear(struct expr_parse_ctx *ctx); 35 void expr__ctx_free(struct expr_parse_ctx *ctx); 36 37 void expr__del_id(struct expr_parse_ctx *ctx, const char *id); 38 int expr__add_id(struct expr_parse_ctx *ctx, const char *id); 39 int expr__add_id_val(struct expr_parse_ctx *ctx, const char *id, double val); 40 int expr__add_id_val_source_count(struct expr_parse_ctx *ctx, const char *id, 41 double val, int source_count); 42 int expr__add_ref(struct expr_parse_ctx *ctx, struct metric_ref *ref); 43 int expr__get_id(struct expr_parse_ctx *ctx, const char *id, 44 struct expr_id_data **data); 45 bool expr__subset_of_ids(struct expr_parse_ctx *haystack, 46 struct expr_parse_ctx *needles); 47 int expr__resolve_id(struct expr_parse_ctx *ctx, const char *id, 48 struct expr_id_data **datap); 49 50 int expr__parse(double *final_val, struct expr_parse_ctx *ctx, 51 const char *expr); 52 53 int expr__find_ids(const char *expr, const char *one, 54 struct expr_parse_ctx *ids); 55 56 double expr_id_data__value(const struct expr_id_data *data); 57 double expr_id_data__source_count(const struct expr_id_data *data); 58 double expr__get_literal(const char *literal); 59 60 #endif 61