Ternary selection cleanup

Moved the ternary selection code to TParseContext
where checks were added to make sure arrays and
structs can't use it.

Change-Id: If3c007820870276cdf540005e095d89d54949bc4
Reviewed-on: https://swiftshader-review.googlesource.com/3669
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
diff --git a/src/OpenGL/compiler/ParseHelper.cpp b/src/OpenGL/compiler/ParseHelper.cpp
index 899bac2..e75f0ba 100644
--- a/src/OpenGL/compiler/ParseHelper.cpp
+++ b/src/OpenGL/compiler/ParseHelper.cpp
@@ -3403,6 +3403,29 @@
 	return callNode;
 }
 
+TIntermTyped *TParseContext::addTernarySelection(TIntermTyped *cond, TIntermTyped *trueBlock, TIntermTyped *falseBlock, const TSourceLoc &loc)
+{
+	if(boolErrorCheck(loc, cond))
+		recover();
+
+	if(trueBlock->getType() != falseBlock->getType())
+	{
+		binaryOpError(loc, ":", trueBlock->getCompleteString(), falseBlock->getCompleteString());
+		recover();
+		return falseBlock;
+	}
+	// ESSL1 sections 5.2 and 5.7:
+	// ESSL3 section 5.7:
+	// Ternary operator is not among the operators allowed for structures/arrays.
+	if(trueBlock->isArray() || trueBlock->getBasicType() == EbtStruct)
+	{
+		error(loc, "ternary operator is not allowed for structures or arrays", ":");
+		recover();
+		return falseBlock;
+	}
+	return intermediate.addSelection(cond, trueBlock, falseBlock, loc);
+}
+
 //
 // Parse an array of strings using yyparse.
 //