0001
0002 #ifndef PARSE_CTX_H
0003 #define PARSE_CTX_H 1
0004
0005
0006
0007
0008
0009
0010
0011 #include "util/hashmap.h"
0012
0013
0014 struct metric_ref;
0015
0016 struct expr_parse_ctx {
0017 struct hashmap *ids;
0018 int runtime;
0019 };
0020
0021 struct expr_id_data;
0022
0023 struct expr_scanner_ctx {
0024 int runtime;
0025 };
0026
0027 struct hashmap *ids__new(void);
0028 void ids__free(struct hashmap *ids);
0029 int ids__insert(struct hashmap *ids, const char *id);
0030
0031
0032
0033
0034 struct hashmap *ids__union(struct hashmap *ids1, struct hashmap *ids2);
0035
0036 struct expr_parse_ctx *expr__ctx_new(void);
0037 void expr__ctx_clear(struct expr_parse_ctx *ctx);
0038 void expr__ctx_free(struct expr_parse_ctx *ctx);
0039
0040 void expr__del_id(struct expr_parse_ctx *ctx, const char *id);
0041 int expr__add_id(struct expr_parse_ctx *ctx, const char *id);
0042 int expr__add_id_val(struct expr_parse_ctx *ctx, const char *id, double val);
0043 int expr__add_id_val_source_count(struct expr_parse_ctx *ctx, const char *id,
0044 double val, int source_count);
0045 int expr__add_ref(struct expr_parse_ctx *ctx, struct metric_ref *ref);
0046 int expr__get_id(struct expr_parse_ctx *ctx, const char *id,
0047 struct expr_id_data **data);
0048 bool expr__subset_of_ids(struct expr_parse_ctx *haystack,
0049 struct expr_parse_ctx *needles);
0050 int expr__resolve_id(struct expr_parse_ctx *ctx, const char *id,
0051 struct expr_id_data **datap);
0052
0053 int expr__parse(double *final_val, struct expr_parse_ctx *ctx,
0054 const char *expr);
0055
0056 int expr__find_ids(const char *expr, const char *one,
0057 struct expr_parse_ctx *ids);
0058
0059 double expr_id_data__value(const struct expr_id_data *data);
0060 double expr_id_data__source_count(const struct expr_id_data *data);
0061 double expr__get_literal(const char *literal);
0062
0063 #endif