static inline EVAL_NODE *parse_one_full_operand(const char **string, int *error);
static inline calculated_number eval_node(EVAL_EXPRESSION *exp, EVAL_NODE *op, int *error);
static inline void print_parsed_as_node(BUFFER *out, EVAL_NODE *op, int *error);
+static inline void print_parsed_as_constant(BUFFER *out, calculated_number n);
// ----------------------------------------------------------------------------
// evaluation of expressions
}
static inline calculated_number eval_variable(EVAL_EXPRESSION *exp, EVAL_VARIABLE *v, int *error) {
- // FIXME: do the variable look up here
+ static uint32_t this_hash = 0;
+
+ if(unlikely(this_hash == 0))
+ this_hash = simple_hash("this");
+
+ if(exp->this && v->hash == this_hash && !strcmp(v->name, "this")) {
+ buffer_strcat(exp->error_msg, "[ $this = ");
+ print_parsed_as_constant(exp->error_msg, *exp->this);
+ buffer_strcat(exp->error_msg, " ] ");
+ return *exp->this;
+ }
+
+ calculated_number n;
+ if(exp->rrdcalc && health_variable_lookup(v->name, v->hash, exp->rrdcalc, &n)) {
+ buffer_sprintf(exp->error_msg, "[ $%s = ", v->name);
+ print_parsed_as_constant(exp->error_msg, n);
+ buffer_strcat(exp->error_msg, " ] ");
+ return n;
+ }
-// if(!exp->data) {
*error = EVAL_ERROR_UNKNOWN_VARIABLE;
buffer_sprintf(exp->error_msg, "unknown variable '%s'", v->name);
-// }
-
return 0;
}
}
static inline void print_parsed_as_constant(BUFFER *out, calculated_number n) {
+ if(unlikely(isnan(n))) {
+ buffer_strcat(out, "NaN");
+ return;
+ }
+
+ if(unlikely(isinf(n))) {
+ buffer_strcat(out, "INFINITE");
+ return;
+ }
+
char b[100+1], *s;
snprintfz(b, 100, CALCULATED_NUMBER_FORMAT, n);
op->ops[pos].type = EVAL_VALUE_VARIABLE;
op->ops[pos].variable = callocz(1, sizeof(EVAL_VARIABLE));
op->ops[pos].variable->name = strdupz(variable);
+ op->ops[pos].variable->hash = simple_hash(op->ops[pos].variable->name);
}
static inline void eval_variable_free(EVAL_VARIABLE *v) {
return "wrong number of operands for operation - internal error";
case EVAL_ERROR_VALUE_IS_NAN:
- return "value or variable is missing or is not a number";
+ return "value is unset";
case EVAL_ERROR_VALUE_IS_INFINITE:
return "computed value is infinite";