18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef PARSE_CTX_H 38c2ecf20Sopenharmony_ci#define PARSE_CTX_H 1 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci// There are fixes that need to land upstream before we can use libbpf's headers, 68c2ecf20Sopenharmony_ci// for now use our copy uncoditionally, since the data structures at this point 78c2ecf20Sopenharmony_ci// are exactly the same, no problem. 88c2ecf20Sopenharmony_ci//#ifdef HAVE_LIBBPF_SUPPORT 98c2ecf20Sopenharmony_ci//#include <bpf/hashmap.h> 108c2ecf20Sopenharmony_ci//#else 118c2ecf20Sopenharmony_ci#include "util/hashmap.h" 128c2ecf20Sopenharmony_ci//#endif 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_cistruct metric_ref; 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_cistruct expr_id { 178c2ecf20Sopenharmony_ci char *id; 188c2ecf20Sopenharmony_ci struct expr_id *parent; 198c2ecf20Sopenharmony_ci}; 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_cistruct expr_parse_ctx { 228c2ecf20Sopenharmony_ci struct hashmap ids; 238c2ecf20Sopenharmony_ci struct expr_id *parent; 248c2ecf20Sopenharmony_ci}; 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_cistruct expr_id_data { 278c2ecf20Sopenharmony_ci union { 288c2ecf20Sopenharmony_ci double val; 298c2ecf20Sopenharmony_ci struct { 308c2ecf20Sopenharmony_ci const char *metric_name; 318c2ecf20Sopenharmony_ci const char *metric_expr; 328c2ecf20Sopenharmony_ci bool counted; 338c2ecf20Sopenharmony_ci } ref; 348c2ecf20Sopenharmony_ci struct expr_id *parent; 358c2ecf20Sopenharmony_ci }; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci bool is_ref; 388c2ecf20Sopenharmony_ci}; 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_cistruct expr_scanner_ctx { 418c2ecf20Sopenharmony_ci int start_token; 428c2ecf20Sopenharmony_ci int runtime; 438c2ecf20Sopenharmony_ci}; 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_civoid expr__ctx_init(struct expr_parse_ctx *ctx); 468c2ecf20Sopenharmony_civoid expr__ctx_clear(struct expr_parse_ctx *ctx); 478c2ecf20Sopenharmony_civoid expr__del_id(struct expr_parse_ctx *ctx, const char *id); 488c2ecf20Sopenharmony_ciint expr__add_id(struct expr_parse_ctx *ctx, const char *id); 498c2ecf20Sopenharmony_ciint expr__add_id_val(struct expr_parse_ctx *ctx, const char *id, double val); 508c2ecf20Sopenharmony_ciint expr__add_ref(struct expr_parse_ctx *ctx, struct metric_ref *ref); 518c2ecf20Sopenharmony_ciint expr__get_id(struct expr_parse_ctx *ctx, const char *id, 528c2ecf20Sopenharmony_ci struct expr_id_data **data); 538c2ecf20Sopenharmony_ciint expr__resolve_id(struct expr_parse_ctx *ctx, const char *id, 548c2ecf20Sopenharmony_ci struct expr_id_data **datap); 558c2ecf20Sopenharmony_ciint expr__parse(double *final_val, struct expr_parse_ctx *ctx, 568c2ecf20Sopenharmony_ci const char *expr, int runtime); 578c2ecf20Sopenharmony_ciint expr__find_other(const char *expr, const char *one, 588c2ecf20Sopenharmony_ci struct expr_parse_ctx *ids, int runtime); 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci#endif 61