.. | .. |
---|
2 | 2 | #ifndef PARSE_CTX_H |
---|
3 | 3 | #define PARSE_CTX_H 1 |
---|
4 | 4 | |
---|
5 | | -#define EXPR_MAX_OTHER 15 |
---|
6 | | -#define MAX_PARSE_ID EXPR_MAX_OTHER |
---|
| 5 | +// There are fixes that need to land upstream before we can use libbpf's headers, |
---|
| 6 | +// for now use our copy uncoditionally, since the data structures at this point |
---|
| 7 | +// are exactly the same, no problem. |
---|
| 8 | +//#ifdef HAVE_LIBBPF_SUPPORT |
---|
| 9 | +//#include <bpf/hashmap.h> |
---|
| 10 | +//#else |
---|
| 11 | +#include "util/hashmap.h" |
---|
| 12 | +//#endif |
---|
7 | 13 | |
---|
8 | | -struct parse_id { |
---|
9 | | - const char *name; |
---|
10 | | - double val; |
---|
| 14 | +struct metric_ref; |
---|
| 15 | + |
---|
| 16 | +struct expr_id { |
---|
| 17 | + char *id; |
---|
| 18 | + struct expr_id *parent; |
---|
11 | 19 | }; |
---|
12 | 20 | |
---|
13 | | -struct parse_ctx { |
---|
14 | | - int num_ids; |
---|
15 | | - struct parse_id ids[MAX_PARSE_ID]; |
---|
| 21 | +struct expr_parse_ctx { |
---|
| 22 | + struct hashmap ids; |
---|
| 23 | + struct expr_id *parent; |
---|
16 | 24 | }; |
---|
17 | 25 | |
---|
18 | | -void expr__ctx_init(struct parse_ctx *ctx); |
---|
19 | | -void expr__add_id(struct parse_ctx *ctx, const char *id, double val); |
---|
20 | | -#ifndef IN_EXPR_Y |
---|
21 | | -int expr__parse(double *final_val, struct parse_ctx *ctx, const char **pp); |
---|
22 | | -#endif |
---|
23 | | -int expr__find_other(const char *p, const char *one, const char ***other, |
---|
24 | | - int *num_other); |
---|
| 26 | +struct expr_id_data { |
---|
| 27 | + union { |
---|
| 28 | + double val; |
---|
| 29 | + struct { |
---|
| 30 | + const char *metric_name; |
---|
| 31 | + const char *metric_expr; |
---|
| 32 | + bool counted; |
---|
| 33 | + } ref; |
---|
| 34 | + struct expr_id *parent; |
---|
| 35 | + }; |
---|
| 36 | + |
---|
| 37 | + bool is_ref; |
---|
| 38 | +}; |
---|
| 39 | + |
---|
| 40 | +struct expr_scanner_ctx { |
---|
| 41 | + int start_token; |
---|
| 42 | + int runtime; |
---|
| 43 | +}; |
---|
| 44 | + |
---|
| 45 | +void expr__ctx_init(struct expr_parse_ctx *ctx); |
---|
| 46 | +void expr__ctx_clear(struct expr_parse_ctx *ctx); |
---|
| 47 | +void expr__del_id(struct expr_parse_ctx *ctx, const char *id); |
---|
| 48 | +int expr__add_id(struct expr_parse_ctx *ctx, const char *id); |
---|
| 49 | +int expr__add_id_val(struct expr_parse_ctx *ctx, const char *id, double val); |
---|
| 50 | +int expr__add_ref(struct expr_parse_ctx *ctx, struct metric_ref *ref); |
---|
| 51 | +int expr__get_id(struct expr_parse_ctx *ctx, const char *id, |
---|
| 52 | + struct expr_id_data **data); |
---|
| 53 | +int expr__resolve_id(struct expr_parse_ctx *ctx, const char *id, |
---|
| 54 | + struct expr_id_data **datap); |
---|
| 55 | +int expr__parse(double *final_val, struct expr_parse_ctx *ctx, |
---|
| 56 | + const char *expr, int runtime); |
---|
| 57 | +int expr__find_other(const char *expr, const char *one, |
---|
| 58 | + struct expr_parse_ctx *ids, int runtime); |
---|
25 | 59 | |
---|
26 | 60 | #endif |
---|