Commit 5eb4609c by alokp@chromium.org

Encapsulate expressions with ternary operators with brackets. This preserves the…

Encapsulate expressions with ternary operators with brackets. This preserves the order of precedence when ternary expressions are used in a compound expression. BUG=20 Review URL: http://codereview.appspot.com/1894041 git-svn-id: https://angleproject.googlecode.com/svn/trunk@352 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent e4249f02
...@@ -391,13 +391,17 @@ bool TOutputGLSL::visitSelection(Visit visit, TIntermSelection* node) ...@@ -391,13 +391,17 @@ bool TOutputGLSL::visitSelection(Visit visit, TIntermSelection* node)
if (node->usesTernaryOperator()) if (node->usesTernaryOperator())
{ {
out << "("; // Notice two brackets at the beginning and end. The outer ones
// encapsulate the whole ternary expression. This preserves the
// order of precedence when ternary expressions are used in a
// compound expression, i.e., c = 2 * (a < b ? 1 : 2).
out << "((";
node->getCondition()->traverse(this); node->getCondition()->traverse(this);
out << ") ? ("; out << ") ? (";
node->getTrueBlock()->traverse(this); node->getTrueBlock()->traverse(this);
out << ") : ("; out << ") : (";
node->getFalseBlock()->traverse(this); node->getFalseBlock()->traverse(this);
out << ")"; out << "))";
} }
else else
{ {
......
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