expr.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef PARSE_CTX_H
  3. #define PARSE_CTX_H 1
  4. // There are fixes that need to land upstream before we can use libbpf's headers,
  5. // for now use our copy uncoditionally, since the data structures at this point
  6. // are exactly the same, no problem.
  7. //#ifdef HAVE_LIBBPF_SUPPORT
  8. //#include <bpf/hashmap.h>
  9. //#else
  10. #include "util/hashmap.h"
  11. //#endif
  12. struct metric_ref;
  13. struct expr_id {
  14. char *id;
  15. struct expr_id *parent;
  16. };
  17. struct expr_parse_ctx {
  18. struct hashmap ids;
  19. struct expr_id *parent;
  20. };
  21. struct expr_id_data {
  22. union {
  23. double val;
  24. struct {
  25. const char *metric_name;
  26. const char *metric_expr;
  27. bool counted;
  28. } ref;
  29. struct expr_id *parent;
  30. };
  31. bool is_ref;
  32. };
  33. struct expr_scanner_ctx {
  34. int start_token;
  35. int runtime;
  36. };
  37. void expr__ctx_init(struct expr_parse_ctx *ctx);
  38. void expr__ctx_clear(struct expr_parse_ctx *ctx);
  39. void expr__del_id(struct expr_parse_ctx *ctx, const char *id);
  40. int expr__add_id(struct expr_parse_ctx *ctx, const char *id);
  41. int expr__add_id_val(struct expr_parse_ctx *ctx, const char *id, double val);
  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. int expr__resolve_id(struct expr_parse_ctx *ctx, const char *id,
  46. struct expr_id_data **datap);
  47. int expr__parse(double *final_val, struct expr_parse_ctx *ctx,
  48. const char *expr, int runtime);
  49. int expr__find_other(const char *expr, const char *one,
  50. struct expr_parse_ctx *ids, int runtime);
  51. #endif