Commit cfc1867c by Jamie Madill

Add a new TIntermRaw node type to translator.

This raw node stores text strings that we directly copy to the output. This allows for more tricky substitutions that don't fit in to the HLSL/GLSL shared parsing model. BUG=346463 Change-Id: I83661f7db82336f3817114eec96a98bc2d395b87 Reviewed-on: https://chromium-review.googlesource.com/187846Reviewed-by: 's avatarNicolas Capens <nicolascapens@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/189081Reviewed-by: 's avatarShannon Woods <shannonwoods@chromium.org>
parent 117186e5
...@@ -257,3 +257,7 @@ void TIntermBranch::traverse(TIntermTraverser *it) ...@@ -257,3 +257,7 @@ void TIntermBranch::traverse(TIntermTraverser *it)
it->visitBranch(PostVisit, this); it->visitBranch(PostVisit, this);
} }
void TIntermRaw::traverse(TIntermTraverser *it)
{
it->visitRaw(this);
}
...@@ -1111,6 +1111,11 @@ void OutputHLSL::visitSymbol(TIntermSymbol *node) ...@@ -1111,6 +1111,11 @@ void OutputHLSL::visitSymbol(TIntermSymbol *node)
} }
} }
void OutputHLSL::visitRaw(TIntermRaw *node)
{
mBody << node->getRawText();
}
bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node) bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node)
{ {
TInfoSinkBase &out = mBody; TInfoSinkBase &out = mBody;
......
...@@ -47,6 +47,7 @@ class OutputHLSL : public TIntermTraverser ...@@ -47,6 +47,7 @@ class OutputHLSL : public TIntermTraverser
// Visit AST nodes and output their code to the body stream // Visit AST nodes and output their code to the body stream
void visitSymbol(TIntermSymbol*); void visitSymbol(TIntermSymbol*);
void visitRaw(TIntermRaw*);
void visitConstantUnion(TIntermConstantUnion*); void visitConstantUnion(TIntermConstantUnion*);
bool visitBinary(Visit visit, TIntermBinary*); bool visitBinary(Visit visit, TIntermBinary*);
bool visitUnary(Visit visit, TIntermUnary*); bool visitUnary(Visit visit, TIntermUnary*);
......
...@@ -199,6 +199,7 @@ class TIntermTyped; ...@@ -199,6 +199,7 @@ class TIntermTyped;
class TIntermSymbol; class TIntermSymbol;
class TIntermLoop; class TIntermLoop;
class TInfoSink; class TInfoSink;
class TIntermRaw;
// //
// Base class for the tree nodes // Base class for the tree nodes
...@@ -226,6 +227,7 @@ public: ...@@ -226,6 +227,7 @@ public:
virtual TIntermSelection* getAsSelectionNode() { return 0; } virtual TIntermSelection* getAsSelectionNode() { return 0; }
virtual TIntermSymbol* getAsSymbolNode() { return 0; } virtual TIntermSymbol* getAsSymbolNode() { return 0; }
virtual TIntermLoop* getAsLoopNode() { return 0; } virtual TIntermLoop* getAsLoopNode() { return 0; }
virtual TIntermRaw* getAsRawNode() { return 0; }
// Replace a child node. Return true if |original| is a child // Replace a child node. Return true if |original| is a child
// node and it is replaced; otherwise, return false. // node and it is replaced; otherwise, return false.
...@@ -376,6 +378,28 @@ protected: ...@@ -376,6 +378,28 @@ protected:
TString originalSymbol; TString originalSymbol;
}; };
// A Raw node stores raw code, that the translator will insert verbatim
// into the output stream. Useful for transformation operations that make
// complex code that might not fit naturally into the GLSL model.
class TIntermRaw : public TIntermTyped {
public:
TIntermRaw(const TType &t, const TString &rawTextIn)
: TIntermTyped(t), rawText(rawTextIn)
{}
virtual bool hasSideEffects() const { return false; }
TString getRawText() const { return rawText; }
virtual void traverse(TIntermTraverser*);
virtual TIntermRaw* getAsRawNode() { return this; }
virtual bool replaceChildNode(TIntermNode *, TIntermNode *) { return false; }
protected:
TString rawText;
};
class TIntermConstantUnion : public TIntermTyped { class TIntermConstantUnion : public TIntermTyped {
public: public:
TIntermConstantUnion(ConstantUnion *unionPointer, const TType& t) : TIntermTyped(t), unionArrayPointer(unionPointer) { } TIntermConstantUnion(ConstantUnion *unionPointer, const TType& t) : TIntermTyped(t), unionArrayPointer(unionPointer) { }
...@@ -587,6 +611,7 @@ public: ...@@ -587,6 +611,7 @@ public:
virtual ~TIntermTraverser() {} virtual ~TIntermTraverser() {}
virtual void visitSymbol(TIntermSymbol*) {} virtual void visitSymbol(TIntermSymbol*) {}
virtual void visitRaw(TIntermRaw*) {}
virtual void visitConstantUnion(TIntermConstantUnion*) {} virtual void visitConstantUnion(TIntermConstantUnion*) {}
virtual bool visitBinary(Visit visit, TIntermBinary*) {return true;} virtual bool visitBinary(Visit visit, TIntermBinary*) {return true;}
virtual bool visitUnary(Visit visit, TIntermUnary*) {return true;} virtual bool visitUnary(Visit visit, TIntermUnary*) {return true;}
......
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