Define new variables after evaluating the initialization expression.

TRAC #13627 GLSL allows to write things like "float x = x;" where a new variable x is defined and the value of an existing variable x is assigned. HLSL uses C semantics (the new variable is created before the assignment is evaluated), so we need to convert this to "float t = x, x = t;". Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@478 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 1f29954d
...@@ -64,7 +64,7 @@ OutputHLSL::OutputHLSL(TParseContext &context) : TIntermTraverser(true, true, tr ...@@ -64,7 +64,7 @@ OutputHLSL::OutputHLSL(TParseContext &context) : TIntermTraverser(true, true, tr
mScopeDepth = 0; mScopeDepth = 0;
mArgumentIndex = 0; mUniqueIndex = 0;
} }
OutputHLSL::~OutputHLSL() OutputHLSL::~OutputHLSL()
...@@ -653,7 +653,26 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node) ...@@ -653,7 +653,26 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node)
switch (node->getOp()) switch (node->getOp())
{ {
case EOpAssign: outputTriplet(visit, "(", " = ", ")"); break; case EOpAssign: outputTriplet(visit, "(", " = ", ")"); break;
case EOpInitialize: outputTriplet(visit, "", " = ", ""); break; case EOpInitialize:
if (visit == PreVisit)
{
// GLSL allows to write things like "float x = x;" where a new variable x is defined
// and the value of an existing variable x is assigned. HLSL uses C semantics (the
// new variable is created before the assignment is evaluated), so we need to convert
// this to "float t = x, x = t;".
// Type already printed
out << "t" + str(mUniqueIndex) + " = ";
node->getRight()->traverse(this);
out << ", ";
node->getLeft()->traverse(this);
out << " = t" + str(mUniqueIndex);
mUniqueIndex++;
return false;
}
break;
case EOpAddAssign: outputTriplet(visit, "(", " += ", ")"); break; case EOpAddAssign: outputTriplet(visit, "(", " += ", ")"); break;
case EOpSubAssign: outputTriplet(visit, "(", " -= ", ")"); break; case EOpSubAssign: outputTriplet(visit, "(", " -= ", ")"); break;
case EOpMulAssign: outputTriplet(visit, "(", " *= ", ")"); break; case EOpMulAssign: outputTriplet(visit, "(", " *= ", ")"); break;
...@@ -1711,7 +1730,7 @@ TString OutputHLSL::argumentString(const TIntermSymbol *symbol) ...@@ -1711,7 +1730,7 @@ TString OutputHLSL::argumentString(const TIntermSymbol *symbol)
if (name.empty()) // HLSL demands named arguments, also for prototypes if (name.empty()) // HLSL demands named arguments, also for prototypes
{ {
name = "x" + str(mArgumentIndex++); name = "x" + str(mUniqueIndex++);
} }
else else
{ {
......
...@@ -120,7 +120,7 @@ class OutputHLSL : public TIntermTraverser ...@@ -120,7 +120,7 @@ class OutputHLSL : public TIntermTraverser
ScopeBracket mScopeBracket; ScopeBracket mScopeBracket;
unsigned int mScopeDepth; unsigned int mScopeDepth;
int mArgumentIndex; // For creating unique argument names int mUniqueIndex; // For creating unique names
}; };
} }
......
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