HLSL: Implicit bool conversions for conditional expressions and related.

Covers if(cond), while(cond), do-while(cond), for(;cond;), and (cond ? :).
Fixes #778.
This commit is contained in:
John Kessenich
2017-03-30 22:09:30 -06:00
parent 8f9fdc986a
commit 7e997e2612
12 changed files with 887 additions and 263 deletions

View File

@@ -4285,6 +4285,18 @@ void HlslParseContext::handleRegister(const TSourceLoc& loc, TQualifier& qualifi
}
}
// Convert to a scalar boolean, or if not allowed by HLSL semantics,
// report an error and return nullptr.
TIntermTyped* HlslParseContext::convertConditionalExpression(const TSourceLoc& loc, TIntermTyped* condition)
{
if (!condition->getType().isScalarOrVec1()) {
error(loc, "requires a scalar", "conditional expression", "");
return nullptr;
}
return intermediate.addConversion(EOpConstructBool, TType(EbtBool), condition);
}
//
// Same error message for all places assignments don't work.
//
@@ -4607,13 +4619,6 @@ bool HlslParseContext::voidErrorCheck(const TSourceLoc& loc, const TString& iden
return false;
}
// Checks to see if the node (for the expression) contains a scalar boolean expression or not
void HlslParseContext::boolCheck(const TSourceLoc& loc, const TIntermTyped* type)
{
if (type->getBasicType() != EbtBool || type->isArray() || type->isMatrix() || type->isVector())
error(loc, "boolean expression expected", "", "");
}
//
// Fix just a full qualifier (no variables or types yet, but qualifier is complete) at global level.
//