diff options
author | Brian <brian@yutani.localnet.net> | 2007-03-28 10:44:38 -0600 |
---|---|---|
committer | Brian <brian@yutani.localnet.net> | 2007-03-28 10:44:38 -0600 |
commit | 59f7f6dbe9e197482f6b5e50c6a910f86c4f6694 (patch) | |
tree | 7dd6765b9dc781d81dcd2d9644f5c9810e321fe0 /src/mesa/shader/slang/slang_codegen.c | |
parent | 20d85c609a86146b2992a05a26603c8de4a2a4f0 (diff) |
check that if/while/do-while condition is boolean or scalar
Diffstat (limited to 'src/mesa/shader/slang/slang_codegen.c')
-rw-r--r-- | src/mesa/shader/slang/slang_codegen.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c index cf3569c3b0..bd403b7c30 100644 --- a/src/mesa/shader/slang/slang_codegen.c +++ b/src/mesa/shader/slang/slang_codegen.c @@ -1363,6 +1363,22 @@ _slang_is_constant_cond(const slang_operation *oper, GLboolean *value) } +/** + * Test if an operation is a scalar or boolean. + */ +static GLboolean +_slang_is_scalar_or_boolean(slang_assemble_ctx *A, slang_operation *oper) +{ + slang_typeinfo type; + GLint size; + + slang_typeinfo_construct(&type); + _slang_typeof_operation(A, oper, &type); + size = _slang_sizeof_type_specifier(&type.spec); + slang_typeinfo_destruct(&type); + return size == 1; +} + /** * Generate loop code using high-level IR_LOOP instruction @@ -1378,6 +1394,12 @@ _slang_gen_while(slang_assemble_ctx * A, const slang_operation *oper) slang_ir_node *prevLoop, *loop, *cond, *breakIf, *body; GLboolean isConst, constTrue; + /* type-check expression */ + if (!_slang_is_scalar_or_boolean(A, &oper->children[0])) { + slang_info_log_error(A->log, "scalar/boolean expression expected for 'while'"); + return NULL; + } + /* Check if loop condition is a constant */ isConst = _slang_is_constant_cond(&oper->children[0], &constTrue); @@ -1434,6 +1456,12 @@ _slang_gen_do(slang_assemble_ctx * A, const slang_operation *oper) slang_ir_node *prevLoop, *loop, *cond; GLboolean isConst, constTrue; + /* type-check expression */ + if (!_slang_is_scalar_or_boolean(A, &oper->children[1])) { + slang_info_log_error(A->log, "scalar/boolean expression expected for 'do/while'"); + return NULL; + } + loop = new_loop(NULL); /* save old, push new loop */ @@ -1556,6 +1584,12 @@ _slang_gen_if(slang_assemble_ctx * A, const slang_operation *oper) slang_ir_node *ifNode, *cond, *ifBody, *elseBody; GLboolean isConst, constTrue; + /* type-check expression */ + if (!_slang_is_scalar_or_boolean(A, &oper->children[0])) { + slang_info_log_error(A->log, "scalar/boolean expression expected for 'if'"); + return NULL; + } + isConst = _slang_is_constant_cond(&oper->children[0], &constTrue); if (isConst) { if (constTrue) { |