Implement logical operators.
authorEric Anholt <eric@anholt.net>
Wed, 31 Mar 2010 19:11:39 +0000 (09:11 -1000)
committerEric Anholt <eric@anholt.net>
Wed, 31 Mar 2010 19:17:39 +0000 (09:17 -1000)
Fixes parser9.frag.

ast_to_hir.cpp

index 708656a6fce085e2e4f2ca1c5119fc9081fb29db..1ebcf45e701207ec8cdcb0d5bc6711cfbb13c759 100644 (file)
@@ -691,7 +691,25 @@ ast_expression::hir(exec_list *instructions,
    case ast_logic_xor:
    case ast_logic_or:
    case ast_logic_not:
-      /* FINISHME: Implement logical operators. */
+      op[0] = this->subexpressions[0]->hir(instructions, state);
+      op[1] = this->subexpressions[1]->hir(instructions, state);
+
+      if (!op[0]->type->is_boolean() || !op[0]->type->is_scalar()) {
+        YYLTYPE loc = this->subexpressions[0]->get_location();
+
+        _mesa_glsl_error(& loc, state, "LHS of `%s' must be scalar boolean",
+                         operator_string(this->oper));
+      }
+
+      if (!op[1]->type->is_boolean() || !op[1]->type->is_scalar()) {
+        YYLTYPE loc = this->subexpressions[1]->get_location();
+
+        _mesa_glsl_error(& loc, state, "RHS of `%s' must be scalar boolean",
+                         operator_string(this->oper));
+      }
+
+      result = new ir_expression(operations[this->oper], glsl_type::bool_type,
+                                op[0], op[1]);
       break;
 
    case ast_mul_assign: