|
3 | 3 | #define YYDEBUG 1
|
4 | 4 | #include <assert.h>
|
5 | 5 | #include <math.h>
|
| 6 | +#include <stdlib.h> |
6 | 7 | #include "util/debug.h"
|
7 | 8 | #define IN_EXPR_Y 1
|
8 | 9 | #include "expr.h"
|
@@ -82,6 +83,39 @@ static struct ids union_expr(struct ids ids1, struct ids ids2)
|
82 | 83 | return result;
|
83 | 84 | }
|
84 | 85 |
|
| 86 | +static struct ids handle_id(struct expr_parse_ctx *ctx, char *id, |
| 87 | + bool compute_ids) |
| 88 | +{ |
| 89 | + struct ids result; |
| 90 | + |
| 91 | + if (!compute_ids) { |
| 92 | + /* |
| 93 | + * Compute the event's value from ID. If the ID isn't known then |
| 94 | + * it isn't used to compute the formula so set to NAN. |
| 95 | + */ |
| 96 | + struct expr_id_data *data; |
| 97 | + |
| 98 | + result.val = NAN; |
| 99 | + if (expr__resolve_id(ctx, id, &data) == 0) |
| 100 | + result.val = expr_id_data__value(data); |
| 101 | + |
| 102 | + result.ids = NULL; |
| 103 | + free(id); |
| 104 | + } else { |
| 105 | + /* |
| 106 | + * Set the value to BOTTOM to show that any value is possible |
| 107 | + * when the event is computed. Create a set of just the ID. |
| 108 | + */ |
| 109 | + result.val = BOTTOM; |
| 110 | + result.ids = ids__new(); |
| 111 | + if (!result.ids || ids__insert(result.ids, id)) { |
| 112 | + pr_err("Error creating IDs for '%s'", id); |
| 113 | + free(id); |
| 114 | + } |
| 115 | + } |
| 116 | + return result; |
| 117 | +} |
| 118 | + |
85 | 119 | /*
|
86 | 120 | * If we're not computing ids or $1 and $3 are constants, compute the new
|
87 | 121 | * constant value using OP. Its invariant that there are no ids. If computing
|
@@ -167,32 +201,7 @@ expr: NUMBER
|
167 | 201 | $$.val = $1;
|
168 | 202 | $$.ids = NULL;
|
169 | 203 | }
|
170 |
| -| ID |
171 |
| -{ |
172 |
| - if (!compute_ids) { |
173 |
| - /* |
174 |
| - * Compute the event's value from ID. If the ID isn't known then |
175 |
| - * it isn't used to compute the formula so set to NAN. |
176 |
| - */ |
177 |
| - struct expr_id_data *data; |
178 |
| - |
179 |
| - $$.val = NAN; |
180 |
| - if (expr__resolve_id(ctx, $1, &data) == 0) |
181 |
| - $$.val = expr_id_data__value(data); |
182 |
| - |
183 |
| - $$.ids = NULL; |
184 |
| - free($1); |
185 |
| - } else { |
186 |
| - /* |
187 |
| - * Set the value to BOTTOM to show that any value is possible |
188 |
| - * when the event is computed. Create a set of just the ID. |
189 |
| - */ |
190 |
| - $$.val = BOTTOM; |
191 |
| - $$.ids = ids__new(); |
192 |
| - if (!$$.ids || ids__insert($$.ids, $1)) |
193 |
| - YYABORT; |
194 |
| - } |
195 |
| -} |
| 204 | +| ID { $$ = handle_id(ctx, $1, compute_ids); } |
196 | 205 | | expr '|' expr { BINARY_LONG_OP($$, |, $1, $3); }
|
197 | 206 | | expr '&' expr { BINARY_LONG_OP($$, &, $1, $3); }
|
198 | 207 | | expr '^' expr { BINARY_LONG_OP($$, ^, $1, $3); }
|
|
0 commit comments