Support multiple nested ternary operators per statement

TRAC #18382
ANGLEBUG=203,208
Signed-off-by: Daniel Koch
Author: Nicolas Capens

- by incrementing the temporary index, adding 1 for every nesting level, and rewinding it after each traverse.
Also fixed multiple ternary operator unfolding for loops.

git-svn-id: https://angleproject.googlecode.com/svn/trunk@784 736b8ea6-26fd-11df-bfd4-992fa37f6226
This commit is contained in:
daniel@transgaming.com 2011-10-04 18:43:40 +00:00
Родитель c0d73ed808
Коммит ccb384171a
4 изменённых файлов: 40 добавлений и 23 удалений

Просмотреть файл

@ -1,7 +1,7 @@
#define MAJOR_VERSION 0
#define MINOR_VERSION 0
#define BUILD_VERSION 0
#define BUILD_REVISION 783
#define BUILD_REVISION 784
#define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x)

Просмотреть файл

@ -1503,7 +1503,7 @@ bool OutputHLSL::visitSelection(Visit visit, TIntermSelection *node)
if (node->usesTernaryOperator())
{
out << "s" << mUnfoldSelect->getTemporaryIndex();
out << "s" << mUnfoldSelect->getNextTemporaryIndex();
}
else // if/else statement
{
@ -1567,21 +1567,6 @@ bool OutputHLSL::visitLoop(Visit visit, TIntermLoop *node)
}
else
{
if (node->getInit())
{
mUnfoldSelect->traverse(node->getInit());
}
if (node->getCondition())
{
mUnfoldSelect->traverse(node->getCondition());
}
if (node->getExpression())
{
mUnfoldSelect->traverse(node->getExpression());
}
out << "for(";
if (node->getInit())

Просмотреть файл

@ -20,8 +20,9 @@ UnfoldSelect::UnfoldSelect(TParseContext &context, OutputHLSL *outputHLSL) : mCo
void UnfoldSelect::traverse(TIntermNode *node)
{
mTemporaryIndex++;
int rewindIndex = mTemporaryIndex;
node->traverse(this);
mTemporaryIndex = rewindIndex;
}
bool UnfoldSelect::visitSelection(Visit visit, TIntermSelection *node)
@ -30,36 +31,66 @@ bool UnfoldSelect::visitSelection(Visit visit, TIntermSelection *node)
if (node->usesTernaryOperator())
{
int i = mTemporaryIndex++;
int i = mTemporaryIndex;
out << mOutputHLSL->typeString(node->getType()) << " s" << i << ";\n";
mTemporaryIndex = i + 1;
node->getCondition()->traverse(this);
out << "if(";
mTemporaryIndex = i + 1;
node->getCondition()->traverse(mOutputHLSL);
out << ")\n"
"{\n";
mTemporaryIndex = i + 1;
node->getTrueBlock()->traverse(this);
out << " s" << i << " = ";
mTemporaryIndex = i + 1;
node->getTrueBlock()->traverse(mOutputHLSL);
out << ";\n"
"}\n"
"else\n"
"{\n";
mTemporaryIndex = i + 1;
node->getFalseBlock()->traverse(this);
out << " s" << i << " = ";
mTemporaryIndex = i + 1;
node->getFalseBlock()->traverse(mOutputHLSL);
out << ";\n"
"}\n";
mTemporaryIndex--;
mTemporaryIndex = i + 1;
}
return false;
}
int UnfoldSelect::getTemporaryIndex()
bool UnfoldSelect::visitLoop(Visit visit, TIntermLoop *node)
{
return mTemporaryIndex;
int rewindIndex = mTemporaryIndex;
if (node->getInit())
{
node->getInit()->traverse(this);
}
if (node->getCondition())
{
node->getCondition()->traverse(this);
}
if (node->getExpression())
{
node->getExpression()->traverse(this);
}
mTemporaryIndex = rewindIndex;
return false;
}
int UnfoldSelect::getNextTemporaryIndex()
{
return mTemporaryIndex++;
}
}

Просмотреть файл

@ -23,8 +23,9 @@ class UnfoldSelect : public TIntermTraverser
void traverse(TIntermNode *node);
bool visitSelection(Visit visit, TIntermSelection *node);
bool visitLoop(Visit visit, TIntermLoop *node);
int getTemporaryIndex();
int getNextTemporaryIndex();
protected:
TParseContext &mContext;