ANGLE | Compiler - implement the ternary operator
TRAC #11421
Doesn't take short-circuiting behavior into account yet.
Author: Nicolas Capens
Signed-off-by: Andrew Lewycky
Signed-off-by: Daniel Koch
git-svn-id: https://angleproject.googlecode.com/svn/trunk@51 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/compiler/OutputHLSL.cpp b/src/compiler/OutputHLSL.cpp
index ea8502f..f17f086 100644
--- a/src/compiler/OutputHLSL.cpp
+++ b/src/compiler/OutputHLSL.cpp
@@ -943,25 +943,38 @@
{
TInfoSinkBase &out = context.infoSink.obj;
- out << "if(";
-
- node->getCondition()->traverse(this);
-
- out << ")\n"
- "{\n";
-
- node->getTrueBlock()->traverse(this);
-
- out << ";}\n";
-
- if (node->getFalseBlock())
+ if(node->getType().getBasicType() == EbtVoid) // if/else statement
{
- out << "else\n"
+ out << "if(";
+
+ node->getCondition()->traverse(this);
+
+ out << ")\n"
"{\n";
- node->getFalseBlock()->traverse(this);
+ node->getTrueBlock()->traverse(this);
out << ";}\n";
+
+ if (node->getFalseBlock())
+ {
+ out << "else\n"
+ "{\n";
+
+ node->getFalseBlock()->traverse(this);
+
+ out << ";}\n";
+ }
+ }
+ else // Ternary operator expression
+ {
+ out << "(";
+ node->getCondition()->traverse(this);
+ out << ") ? (";
+ node->getTrueBlock()->traverse(this);
+ out << ") : (";
+ node->getFalseBlock()->traverse(this);
+ out << ")\n";
}
return false;