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:
@@ -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.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user