6 #include <linux/compiler.h>
8 #include "expr-bison.h"
11 char *expr_get_text(yyscan_t yyscanner);
12 YYSTYPE *expr_get_lval(yyscan_t yyscanner);
14 static double __value(YYSTYPE *yylval, char *str, int token)
19 num = strtod(str, NULL);
27 static int value(yyscan_t scanner)
29 YYSTYPE *yylval = expr_get_lval(scanner);
30 char *text = expr_get_text(scanner);
32 return __value(yylval, text, NUMBER);
36 * Allow @ instead of / to be able to specify pmu/event/ without
37 * conflicts with normal division.
39 static char *normalize(char *str, int runtime)
50 else if (*str == '?') {
53 int size = asprintf(¶mval, "%d", runtime);
59 *dst++ = paramval[i++];
72 static int str(yyscan_t scanner, int token, int runtime)
74 YYSTYPE *yylval = expr_get_lval(scanner);
75 char *text = expr_get_text(scanner);
77 yylval->str = normalize(strdup(text), runtime);
81 yylval->str = normalize(yylval->str, runtime);
85 static int literal(yyscan_t scanner, const struct expr_scanner_ctx *sctx)
87 YYSTYPE *yylval = expr_get_lval(scanner);
89 yylval->num = expr__get_literal(expr_get_text(scanner), sctx);
90 if (isnan(yylval->num)) {
99 number ([0-9]+\.?[0-9]*|[0-9]*\.?[0-9]+)(e-?[0-9]+)?
103 sym [0-9a-zA-Z_\.:@?]+
104 symbol ({spec}|{sym})+
105 literal #[0-9a-zA-Z_\.\-]+
108 struct expr_scanner_ctx *sctx = expr_get_extra(yyscanner);
110 d_ratio { return D_RATIO; }
114 else { return ELSE; }
115 source_count { return SOURCE_COUNT; }
116 has_event { return HAS_EVENT; }
117 strcmp_cpuid_str { return STRCMP_CPUID_STR; }
118 {literal} { return literal(yyscanner, sctx); }
119 {number} { return value(yyscanner); }
120 {symbol} { return str(yyscanner, ID, sctx->runtime); }
137 int expr_wrap(void *scanner __maybe_unused)