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)) {
98 static int nan_value(yyscan_t scanner)
100 YYSTYPE *yylval = expr_get_lval(scanner);
107 number ([0-9]+\.?[0-9]*|[0-9]*\.?[0-9]+)(e-?[0-9]+)?
111 sym [0-9a-zA-Z_\.:@?]+
112 symbol ({spec}|{sym})+
113 literal #[0-9a-zA-Z_\.\-]+
116 struct expr_scanner_ctx *sctx = expr_get_extra(yyscanner);
118 d_ratio { return D_RATIO; }
122 else { return ELSE; }
123 source_count { return SOURCE_COUNT; }
124 has_event { return HAS_EVENT; }
125 strcmp_cpuid_str { return STRCMP_CPUID_STR; }
126 NaN { return nan_value(yyscanner); }
127 {literal} { return literal(yyscanner, sctx); }
128 {number} { return value(yyscanner); }
129 {symbol} { return str(yyscanner, ID, sctx->runtime); }
146 int expr_wrap(void *scanner __maybe_unused)