Commit e01c02b6 by Olli Etuaho Committed by Commit Bot

Clean up ternary op validation

Use "?:" as the operator string to make the error message clearer. Update some comments to refer to specific revisions of the spec, since there have been some spec changes in this area. BUG=angleproject:2032 Change-Id: Ic5d128391bfa46187ad335228077f5eab9eac349 Reviewed-on: https://chromium-review.googlesource.com/500270Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 764a1e76
...@@ -4523,32 +4523,35 @@ TIntermTyped *TParseContext::addTernarySelection(TIntermTyped *cond, ...@@ -4523,32 +4523,35 @@ TIntermTyped *TParseContext::addTernarySelection(TIntermTyped *cond,
if (trueExpression->getType() != falseExpression->getType()) if (trueExpression->getType() != falseExpression->getType())
{ {
binaryOpError(loc, ":", trueExpression->getCompleteString(), binaryOpError(loc, "?:", trueExpression->getCompleteString(),
falseExpression->getCompleteString()); falseExpression->getCompleteString());
return falseExpression; return falseExpression;
} }
if (IsOpaqueType(trueExpression->getBasicType())) if (IsOpaqueType(trueExpression->getBasicType()))
{ {
// ESSL 1.00 section 4.1.7 // ESSL 1.00 section 4.1.7
// ESSL 3.00 section 4.1.7 // ESSL 3.00.6 section 4.1.7
// Opaque/sampler types are not allowed in most types of expressions, including ternary. // Opaque/sampler types are not allowed in most types of expressions, including ternary.
// Note that structs containing opaque types don't need to be checked as structs are // Note that structs containing opaque types don't need to be checked as structs are
// forbidden below. // forbidden below.
error(loc, "ternary operator is not allowed for opaque types", ":"); error(loc, "ternary operator is not allowed for opaque types", "?:");
return falseExpression; return falseExpression;
} }
// ESSL1 sections 5.2 and 5.7: // ESSL 1.00.17 sections 5.2 and 5.7:
// ESSL3 section 5.7:
// Ternary operator is not among the operators allowed for structures/arrays. // Ternary operator is not among the operators allowed for structures/arrays.
// ESSL 3.00.6 section 5.7:
// Ternary operator support is optional for arrays. No certainty that it works across all
// devices with struct either, so we err on the side of caution here. TODO (oetuaho@nvidia.com):
// Would be nice to make the spec and implementation agree completely here.
if (trueExpression->isArray() || trueExpression->getBasicType() == EbtStruct) if (trueExpression->isArray() || trueExpression->getBasicType() == EbtStruct)
{ {
error(loc, "ternary operator is not allowed for structures or arrays", ":"); error(loc, "ternary operator is not allowed for structures or arrays", "?:");
return falseExpression; return falseExpression;
} }
if (trueExpression->getBasicType() == EbtInterfaceBlock) if (trueExpression->getBasicType() == EbtInterfaceBlock)
{ {
error(loc, "ternary operator is not allowed for interface blocks", ":"); error(loc, "ternary operator is not allowed for interface blocks", "?:");
return falseExpression; return falseExpression;
} }
...@@ -4556,7 +4559,7 @@ TIntermTyped *TParseContext::addTernarySelection(TIntermTyped *cond, ...@@ -4556,7 +4559,7 @@ TIntermTyped *TParseContext::addTernarySelection(TIntermTyped *cond,
// "Ternary operator applied to void, arrays, or structs containing arrays" // "Ternary operator applied to void, arrays, or structs containing arrays"
if (mShaderSpec == SH_WEBGL2_SPEC && trueExpression->getBasicType() == EbtVoid) if (mShaderSpec == SH_WEBGL2_SPEC && trueExpression->getBasicType() == EbtVoid)
{ {
error(loc, "ternary operator is not allowed for void", ":"); error(loc, "ternary operator is not allowed for void", "?:");
return falseExpression; return falseExpression;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment