From 1ec97632e68aa8f658c2c83a34ca53ac9f524fd0 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 18 Jan 2025 23:13:55 +0900 Subject: [PATCH] [qfcc] Handle general types in boolean expressions Probably need language-specific checks (eg, glsl doesn't accept anything but bool for && etc). --- tools/qfcc/source/expr_binary.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tools/qfcc/source/expr_binary.c b/tools/qfcc/source/expr_binary.c index c7c1a7640..53c81b25f 100644 --- a/tools/qfcc/source/expr_binary.c +++ b/tools/qfcc/source/expr_binary.c @@ -436,6 +436,21 @@ dot_product_expr (int op, const expr_t *a, const expr_t *b) return e; } +static const expr_t * +boolean_op (int op, const expr_t *a, const expr_t *b) +{ + if (!is_boolean (get_type (a))) { + a = test_expr (a); + } + if (!is_boolean (get_type (b))) { + b = test_expr (b); + } + promote_exprs (&a, &b); + auto type = base_type (get_type (a)); + auto e = typed_binary_expr (type, op, a, b); + return e; +} + static const type_t * bool_result (const type_t *a, const type_t *b) { @@ -666,6 +681,8 @@ static expr_type_t bit_ops[] = { static expr_type_t bool_ops[] = { { .match_a = is_boolean, .match_b = is_boolean, }, + { .match_a = is_scalar, .match_b = is_scalar, + .process = boolean_op }, {} };