Beispiel #1
0
static int __convert_dup(struct parse_context *ctx, struct expression *value)
{
	struct expression *dup;

	dup = get_pure_expr(ctx, value);

	convert_expression(ctx, dup);
	convert_expression(ctx, dup_expr(ctx, expr_get(dup)));

	return 0;
}
Beispiel #2
0
int convert_swap(struct parse_context *ctx)
{
	void *v1, *v2;

	v1 = stack_pop(ctx->bb->mimic_stack);
	v2 = stack_pop(ctx->bb->mimic_stack);

	convert_expression(ctx, v1);
	convert_expression(ctx, v2);

	return 0;
}
Beispiel #3
0
static int __convert_dup2(struct parse_context *ctx, struct expression *value1, struct expression *value2)
{
	struct expression *dup, *dup2;

	dup = get_pure_expr(ctx, value1);
	dup2 = get_pure_expr(ctx, value2);

	convert_expression(ctx, dup2);
	convert_expression(ctx, dup);
	convert_expression(ctx, dup_expr(ctx, expr_get(dup2)));
	convert_expression(ctx, dup_expr(ctx, expr_get(dup)));

	return 0;
}
Beispiel #4
0
/******************************************************************************
 *                                                                            *
 * Function: convert_triggers_expression                                      *
 *                                                                            *
 * Purpose: convert trigger expressions to new node ID                        *
 *                                                                            *
 * Parameters: old_id - old id, new_id - new node id                          *
 *                                                                            *
 * Author: Alexander Vladishev                                                *
 *                                                                            *
 * Comments:                                                                  *
 *                                                                            *
 ******************************************************************************/
static void	convert_triggers_expression(int old_id, int new_id)
{
	zbx_uint64_t	prefix;
	const ZBX_TABLE	*r_table;
	DB_RESULT	result;
	DB_ROW		row;
	char		new_expression[MAX_STRING_LEN], *new_expression_esc;

	r_table = DBget_table("functions");
	assert(NULL != r_table);

	prefix = (zbx_uint64_t)__UINT64_C(100000000000000) * (zbx_uint64_t)new_id;
	if (0 != (r_table->flags & ZBX_SYNC))
		prefix += (zbx_uint64_t)__UINT64_C(100000000000) * (zbx_uint64_t)new_id;

	result = DBselect("select expression,triggerid from triggers");

	while (NULL != (row = DBfetch(result)))
	{
		memset(new_expression, 0, sizeof(new_expression));
		convert_expression(old_id, new_id, prefix, row[0], new_expression);

		new_expression_esc = DBdyn_escape_string_len(new_expression, TRIGGER_EXPRESSION_LEN);
		DBexecute("update triggers set expression='%s' where triggerid=%s",
				new_expression_esc, row[1]);
		zbx_free(new_expression_esc);
	}
	DBfree_result(result);
}
Beispiel #5
0
static int convert_conversion(struct parse_context *ctx, enum vm_type to_type)
{
    struct expression *from_expression, *conversion_expression;
    enum vm_type from_type;

    from_expression = stack_pop(ctx->bb->mimic_stack);
    from_type = from_expression->vm_type;

    if (from_type == J_DOUBLE && to_type == J_FLOAT)
        conversion_expression = conversion_double_to_float_expr(from_expression);
    else if (from_type == J_FLOAT && to_type == J_DOUBLE)
        conversion_expression = conversion_float_to_double_expr(from_expression);
    else if (to_type == J_FLOAT)
        conversion_expression = conversion_to_float_expr(to_type, from_expression);
    else if (from_type == J_FLOAT)
        conversion_expression = conversion_from_float_expr(to_type, from_expression);
    else if (to_type == J_DOUBLE)
        conversion_expression = conversion_to_double_expr(to_type, from_expression);
    else if (from_type == J_DOUBLE)
        conversion_expression = conversion_from_double_expr(to_type, from_expression);
    else
        conversion_expression = conversion_expr(to_type, from_expression);

    if (!conversion_expression)
        return warn("out of memory"), -ENOMEM;

    convert_expression(ctx, conversion_expression);
    return 0;
}
Beispiel #6
0
static int convert_unary_op(struct parse_context *ctx, enum vm_type vm_type,
			    enum unary_operator unary_operator)
{
	struct expression *expression, *expr;

	expression = stack_pop(ctx->bb->mimic_stack);

	expr = unary_op_expr(vm_type, unary_operator, expression);
	if (!expr)
		return warn("out of memory"), -ENOMEM;

	convert_expression(ctx, expr);
	return 0;
}
Beispiel #7
0
static int convert_truncation(struct parse_context *ctx, enum vm_type to_type)
{
    struct expression *from_expression, *expr;

    from_expression = stack_pop(ctx->bb->mimic_stack);
    assert(from_expression->vm_type == J_INT);

    expr = truncation_expr(to_type, from_expression);
    if (!expr)
        return warn("out of memory"), -ENOMEM;

    convert_expression(ctx, expr);
    return 0;
}
Beispiel #8
0
static int convert_binop(struct parse_context *ctx, enum vm_type vm_type,
			 enum binary_operator binary_operator)
{
	struct expression *left, *right, *expr;

	right = stack_pop(ctx->bb->mimic_stack);
	left = stack_pop(ctx->bb->mimic_stack);

	expr = binop_expr(vm_type, binary_operator, left, right);
	if (!expr)
		return warn("out of memory"), -ENOMEM;

	convert_expression(ctx, expr);
	return 0;
}
Beispiel #9
0
static int convert_conversion(struct parse_context *ctx, enum vm_type to_type)
{
	struct expression *from_expression, *conversion_expression;

	from_expression = stack_pop(ctx->bb->mimic_stack);

	if (to_type == J_FLOAT)
		conversion_expression = conversion_to_float_expr(to_type, from_expression);
	else if (from_expression->vm_type == J_FLOAT)
		conversion_expression = conversion_from_float_expr(to_type, from_expression);
	else
		conversion_expression = conversion_expr(to_type, from_expression);

	if (!conversion_expression)
		return -ENOMEM;

	convert_expression(ctx, conversion_expression);
	return 0;
}