Commit 1283ef62 by Jamie Madill Committed by Commit Bot

translator: Add TIntermPreprocessorDirective.

This new node type can be used to inject preprocessor directives into the intermediate tree. Outputting the preprocessor directive is easy for the GLSL back-end. This can be used to implement workarounds such as the OpenGL line rasterization rules on Vulkan. Also fixes the build that was broken on Win/x64 with a prior change and makes more methods in IntermNode.h const. Bug: angleproject:2598 Change-Id: Ifd6d0ac7912ccf2137997bb9a0187fd063023d5e Reviewed-on: https://chromium-review.googlesource.com/1133420Reviewed-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 9ff9c773
...@@ -202,34 +202,34 @@ void TIntermExpression::setTypePreservePrecision(const TType &t) ...@@ -202,34 +202,34 @@ void TIntermExpression::setTypePreservePrecision(const TType &t)
return true; \ return true; \
} }
unsigned int TIntermSymbol::getChildCount() size_t TIntermSymbol::getChildCount() const
{ {
return 0; return 0;
} }
TIntermNode *TIntermSymbol::getChildNode(unsigned int index) TIntermNode *TIntermSymbol::getChildNode(size_t index) const
{ {
UNREACHABLE(); UNREACHABLE();
return nullptr; return nullptr;
} }
unsigned int TIntermConstantUnion::getChildCount() size_t TIntermConstantUnion::getChildCount() const
{ {
return 0; return 0;
} }
TIntermNode *TIntermConstantUnion::getChildNode(unsigned int index) TIntermNode *TIntermConstantUnion::getChildNode(size_t index) const
{ {
UNREACHABLE(); UNREACHABLE();
return nullptr; return nullptr;
} }
unsigned int TIntermLoop::getChildCount() size_t TIntermLoop::getChildCount() const
{ {
return (mInit ? 1 : 0) + (mCond ? 1 : 0) + (mExpr ? 1 : 0) + (mBody ? 1 : 0); return (mInit ? 1 : 0) + (mCond ? 1 : 0) + (mExpr ? 1 : 0) + (mBody ? 1 : 0);
} }
TIntermNode *TIntermLoop::getChildNode(unsigned int index) TIntermNode *TIntermLoop::getChildNode(size_t index) const
{ {
TIntermNode *children[4]; TIntermNode *children[4];
unsigned int childIndex = 0; unsigned int childIndex = 0;
...@@ -267,12 +267,12 @@ bool TIntermLoop::replaceChildNode(TIntermNode *original, TIntermNode *replaceme ...@@ -267,12 +267,12 @@ bool TIntermLoop::replaceChildNode(TIntermNode *original, TIntermNode *replaceme
return false; return false;
} }
unsigned int TIntermBranch::getChildCount() size_t TIntermBranch::getChildCount() const
{ {
return (mExpression ? 1 : 0); return (mExpression ? 1 : 0);
} }
TIntermNode *TIntermBranch::getChildNode(unsigned int index) TIntermNode *TIntermBranch::getChildNode(size_t index) const
{ {
ASSERT(mExpression); ASSERT(mExpression);
ASSERT(index == 0); ASSERT(index == 0);
...@@ -285,12 +285,12 @@ bool TIntermBranch::replaceChildNode(TIntermNode *original, TIntermNode *replace ...@@ -285,12 +285,12 @@ bool TIntermBranch::replaceChildNode(TIntermNode *original, TIntermNode *replace
return false; return false;
} }
unsigned int TIntermSwizzle::getChildCount() size_t TIntermSwizzle::getChildCount() const
{ {
return 1; return 1;
} }
TIntermNode *TIntermSwizzle::getChildNode(unsigned int index) TIntermNode *TIntermSwizzle::getChildNode(size_t index) const
{ {
ASSERT(mOperand); ASSERT(mOperand);
ASSERT(index == 0); ASSERT(index == 0);
...@@ -304,12 +304,12 @@ bool TIntermSwizzle::replaceChildNode(TIntermNode *original, TIntermNode *replac ...@@ -304,12 +304,12 @@ bool TIntermSwizzle::replaceChildNode(TIntermNode *original, TIntermNode *replac
return false; return false;
} }
unsigned int TIntermBinary::getChildCount() size_t TIntermBinary::getChildCount() const
{ {
return 2; return 2;
} }
TIntermNode *TIntermBinary::getChildNode(unsigned int index) TIntermNode *TIntermBinary::getChildNode(size_t index) const
{ {
ASSERT(index < 2); ASSERT(index < 2);
if (index == 0) if (index == 0)
...@@ -326,12 +326,12 @@ bool TIntermBinary::replaceChildNode(TIntermNode *original, TIntermNode *replace ...@@ -326,12 +326,12 @@ bool TIntermBinary::replaceChildNode(TIntermNode *original, TIntermNode *replace
return false; return false;
} }
unsigned int TIntermUnary::getChildCount() size_t TIntermUnary::getChildCount() const
{ {
return 1; return 1;
} }
TIntermNode *TIntermUnary::getChildNode(unsigned int index) TIntermNode *TIntermUnary::getChildNode(size_t index) const
{ {
ASSERT(mOperand); ASSERT(mOperand);
ASSERT(index == 0); ASSERT(index == 0);
...@@ -345,12 +345,12 @@ bool TIntermUnary::replaceChildNode(TIntermNode *original, TIntermNode *replacem ...@@ -345,12 +345,12 @@ bool TIntermUnary::replaceChildNode(TIntermNode *original, TIntermNode *replacem
return false; return false;
} }
unsigned int TIntermInvariantDeclaration::getChildCount() size_t TIntermInvariantDeclaration::getChildCount() const
{ {
return 1; return 1;
} }
TIntermNode *TIntermInvariantDeclaration::getChildNode(unsigned int index) TIntermNode *TIntermInvariantDeclaration::getChildNode(size_t index) const
{ {
ASSERT(mSymbol); ASSERT(mSymbol);
ASSERT(index == 0); ASSERT(index == 0);
...@@ -363,12 +363,12 @@ bool TIntermInvariantDeclaration::replaceChildNode(TIntermNode *original, TInter ...@@ -363,12 +363,12 @@ bool TIntermInvariantDeclaration::replaceChildNode(TIntermNode *original, TInter
return false; return false;
} }
unsigned int TIntermFunctionDefinition::getChildCount() size_t TIntermFunctionDefinition::getChildCount() const
{ {
return 2; return 2;
} }
TIntermNode *TIntermFunctionDefinition::getChildNode(unsigned int index) TIntermNode *TIntermFunctionDefinition::getChildNode(size_t index) const
{ {
ASSERT(index < 2); ASSERT(index < 2);
if (index == 0) if (index == 0)
...@@ -385,12 +385,12 @@ bool TIntermFunctionDefinition::replaceChildNode(TIntermNode *original, TIntermN ...@@ -385,12 +385,12 @@ bool TIntermFunctionDefinition::replaceChildNode(TIntermNode *original, TIntermN
return false; return false;
} }
unsigned int TIntermAggregate::getChildCount() size_t TIntermAggregate::getChildCount() const
{ {
return mArguments.size(); return mArguments.size();
} }
TIntermNode *TIntermAggregate::getChildNode(unsigned int index) TIntermNode *TIntermAggregate::getChildNode(size_t index) const
{ {
return mArguments[index]; return mArguments[index];
} }
...@@ -400,12 +400,12 @@ bool TIntermAggregate::replaceChildNode(TIntermNode *original, TIntermNode *repl ...@@ -400,12 +400,12 @@ bool TIntermAggregate::replaceChildNode(TIntermNode *original, TIntermNode *repl
return replaceChildNodeInternal(original, replacement); return replaceChildNodeInternal(original, replacement);
} }
unsigned int TIntermBlock::getChildCount() size_t TIntermBlock::getChildCount() const
{ {
return mStatements.size(); return mStatements.size();
} }
TIntermNode *TIntermBlock::getChildNode(unsigned int index) TIntermNode *TIntermBlock::getChildNode(size_t index) const
{ {
return mStatements[index]; return mStatements[index];
} }
...@@ -415,12 +415,12 @@ bool TIntermBlock::replaceChildNode(TIntermNode *original, TIntermNode *replacem ...@@ -415,12 +415,12 @@ bool TIntermBlock::replaceChildNode(TIntermNode *original, TIntermNode *replacem
return replaceChildNodeInternal(original, replacement); return replaceChildNodeInternal(original, replacement);
} }
unsigned int TIntermFunctionPrototype::getChildCount() size_t TIntermFunctionPrototype::getChildCount() const
{ {
return 0; return 0;
} }
TIntermNode *TIntermFunctionPrototype::getChildNode(unsigned int index) TIntermNode *TIntermFunctionPrototype::getChildNode(size_t index) const
{ {
UNREACHABLE(); UNREACHABLE();
return nullptr; return nullptr;
...@@ -431,12 +431,12 @@ bool TIntermFunctionPrototype::replaceChildNode(TIntermNode *original, TIntermNo ...@@ -431,12 +431,12 @@ bool TIntermFunctionPrototype::replaceChildNode(TIntermNode *original, TIntermNo
return false; return false;
} }
unsigned int TIntermDeclaration::getChildCount() size_t TIntermDeclaration::getChildCount() const
{ {
return mDeclarators.size(); return mDeclarators.size();
} }
TIntermNode *TIntermDeclaration::getChildNode(unsigned int index) TIntermNode *TIntermDeclaration::getChildNode(size_t index) const
{ {
return mDeclarators[index]; return mDeclarators[index];
} }
...@@ -874,12 +874,12 @@ void TIntermDeclaration::appendDeclarator(TIntermTyped *declarator) ...@@ -874,12 +874,12 @@ void TIntermDeclaration::appendDeclarator(TIntermTyped *declarator)
mDeclarators.push_back(declarator); mDeclarators.push_back(declarator);
} }
unsigned int TIntermTernary::getChildCount() size_t TIntermTernary::getChildCount() const
{ {
return 3; return 3;
} }
TIntermNode *TIntermTernary::getChildNode(unsigned int index) TIntermNode *TIntermTernary::getChildNode(size_t index) const
{ {
ASSERT(index < 3); ASSERT(index < 3);
if (index == 0) if (index == 0)
...@@ -901,12 +901,12 @@ bool TIntermTernary::replaceChildNode(TIntermNode *original, TIntermNode *replac ...@@ -901,12 +901,12 @@ bool TIntermTernary::replaceChildNode(TIntermNode *original, TIntermNode *replac
return false; return false;
} }
unsigned int TIntermIfElse::getChildCount() size_t TIntermIfElse::getChildCount() const
{ {
return 1 + (mTrueBlock ? 1 : 0) + (mFalseBlock ? 1 : 0); return 1 + (mTrueBlock ? 1 : 0) + (mFalseBlock ? 1 : 0);
} }
TIntermNode *TIntermIfElse::getChildNode(unsigned int index) TIntermNode *TIntermIfElse::getChildNode(size_t index) const
{ {
if (index == 0) if (index == 0)
{ {
...@@ -927,12 +927,12 @@ bool TIntermIfElse::replaceChildNode(TIntermNode *original, TIntermNode *replace ...@@ -927,12 +927,12 @@ bool TIntermIfElse::replaceChildNode(TIntermNode *original, TIntermNode *replace
return false; return false;
} }
unsigned int TIntermSwitch::getChildCount() size_t TIntermSwitch::getChildCount() const
{ {
return 2; return 2;
} }
TIntermNode *TIntermSwitch::getChildNode(unsigned int index) TIntermNode *TIntermSwitch::getChildNode(size_t index) const
{ {
ASSERT(index < 2); ASSERT(index < 2);
if (index == 0) if (index == 0)
...@@ -950,12 +950,12 @@ bool TIntermSwitch::replaceChildNode(TIntermNode *original, TIntermNode *replace ...@@ -950,12 +950,12 @@ bool TIntermSwitch::replaceChildNode(TIntermNode *original, TIntermNode *replace
return false; return false;
} }
unsigned int TIntermCase::getChildCount() size_t TIntermCase::getChildCount() const
{ {
return (mCondition ? 1 : 0); return (mCondition ? 1 : 0);
} }
TIntermNode *TIntermCase::getChildNode(unsigned int index) TIntermNode *TIntermCase::getChildNode(size_t index) const
{ {
ASSERT(index == 0); ASSERT(index == 0);
ASSERT(mCondition); ASSERT(mCondition);
...@@ -3739,4 +3739,23 @@ TConstantUnion *TIntermConstantUnion::FoldAggregateBuiltIn(TIntermAggregate *agg ...@@ -3739,4 +3739,23 @@ TConstantUnion *TIntermConstantUnion::FoldAggregateBuiltIn(TIntermAggregate *agg
return resultArray; return resultArray;
} }
// TIntermPreprocessorDirective implementation.
TIntermPreprocessorDirective::TIntermPreprocessorDirective(PreprocessorDirective directive,
ImmutableString command)
: mDirective(directive), mCommand(std::move(command))
{
}
TIntermPreprocessorDirective::~TIntermPreprocessorDirective() = default;
size_t TIntermPreprocessorDirective::getChildCount() const
{
return 0;
}
TIntermNode *TIntermPreprocessorDirective::getChildNode(size_t index) const
{
UNREACHABLE();
return nullptr;
}
} // namespace sh } // namespace sh
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "common/angleutils.h" #include "common/angleutils.h"
#include "compiler/translator/Common.h" #include "compiler/translator/Common.h"
#include "compiler/translator/ConstantUnion.h" #include "compiler/translator/ConstantUnion.h"
#include "compiler/translator/ImmutableString.h"
#include "compiler/translator/Operator.h" #include "compiler/translator/Operator.h"
#include "compiler/translator/SymbolUniqueId.h" #include "compiler/translator/SymbolUniqueId.h"
#include "compiler/translator/Types.h" #include "compiler/translator/Types.h"
...@@ -32,8 +33,6 @@ ...@@ -32,8 +33,6 @@
namespace sh namespace sh
{ {
class ImmutableString;
class TDiagnostics; class TDiagnostics;
class TIntermTraverser; class TIntermTraverser;
...@@ -57,6 +56,7 @@ class TIntermLoop; ...@@ -57,6 +56,7 @@ class TIntermLoop;
class TInfoSink; class TInfoSink;
class TInfoSinkBase; class TInfoSinkBase;
class TIntermBranch; class TIntermBranch;
class TIntermPreprocessorDirective;
class TSymbolTable; class TSymbolTable;
class TFunction; class TFunction;
...@@ -84,27 +84,28 @@ class TIntermNode : angle::NonCopyable ...@@ -84,27 +84,28 @@ class TIntermNode : angle::NonCopyable
virtual void traverse(TIntermTraverser *it); virtual void traverse(TIntermTraverser *it);
virtual bool visit(Visit visit, TIntermTraverser *it) = 0; virtual bool visit(Visit visit, TIntermTraverser *it) = 0;
virtual TIntermTyped *getAsTyped() { return 0; } virtual TIntermTyped *getAsTyped() { return nullptr; }
virtual TIntermConstantUnion *getAsConstantUnion() { return 0; } virtual TIntermConstantUnion *getAsConstantUnion() { return nullptr; }
virtual TIntermFunctionDefinition *getAsFunctionDefinition() { return nullptr; } virtual TIntermFunctionDefinition *getAsFunctionDefinition() { return nullptr; }
virtual TIntermAggregate *getAsAggregate() { return 0; } virtual TIntermAggregate *getAsAggregate() { return nullptr; }
virtual TIntermBlock *getAsBlock() { return nullptr; } virtual TIntermBlock *getAsBlock() { return nullptr; }
virtual TIntermFunctionPrototype *getAsFunctionPrototypeNode() { return nullptr; } virtual TIntermFunctionPrototype *getAsFunctionPrototypeNode() { return nullptr; }
virtual TIntermInvariantDeclaration *getAsInvariantDeclarationNode() { return nullptr; } virtual TIntermInvariantDeclaration *getAsInvariantDeclarationNode() { return nullptr; }
virtual TIntermDeclaration *getAsDeclarationNode() { return nullptr; } virtual TIntermDeclaration *getAsDeclarationNode() { return nullptr; }
virtual TIntermSwizzle *getAsSwizzleNode() { return nullptr; } virtual TIntermSwizzle *getAsSwizzleNode() { return nullptr; }
virtual TIntermBinary *getAsBinaryNode() { return 0; } virtual TIntermBinary *getAsBinaryNode() { return nullptr; }
virtual TIntermUnary *getAsUnaryNode() { return 0; } virtual TIntermUnary *getAsUnaryNode() { return nullptr; }
virtual TIntermTernary *getAsTernaryNode() { return nullptr; } virtual TIntermTernary *getAsTernaryNode() { return nullptr; }
virtual TIntermIfElse *getAsIfElseNode() { return nullptr; } virtual TIntermIfElse *getAsIfElseNode() { return nullptr; }
virtual TIntermSwitch *getAsSwitchNode() { return 0; } virtual TIntermSwitch *getAsSwitchNode() { return nullptr; }
virtual TIntermCase *getAsCaseNode() { return 0; } virtual TIntermCase *getAsCaseNode() { return nullptr; }
virtual TIntermSymbol *getAsSymbolNode() { return 0; } virtual TIntermSymbol *getAsSymbolNode() { return nullptr; }
virtual TIntermLoop *getAsLoopNode() { return 0; } virtual TIntermLoop *getAsLoopNode() { return nullptr; }
virtual TIntermBranch *getAsBranchNode() { return 0; } virtual TIntermBranch *getAsBranchNode() { return nullptr; }
virtual TIntermPreprocessorDirective *getAsPreprocessorDirective() { return nullptr; }
virtual unsigned int getChildCount() = 0;
virtual TIntermNode *getChildNode(unsigned int index) = 0; virtual size_t getChildCount() const = 0;
virtual TIntermNode *getChildNode(size_t index) const = 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.
virtual bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) = 0; virtual bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) = 0;
...@@ -195,8 +196,8 @@ class TIntermLoop : public TIntermNode ...@@ -195,8 +196,8 @@ class TIntermLoop : public TIntermNode
void traverse(TIntermTraverser *it) final; void traverse(TIntermTraverser *it) final;
bool visit(Visit visit, TIntermTraverser *it) final; bool visit(Visit visit, TIntermTraverser *it) final;
unsigned int getChildCount() final; size_t getChildCount() const final;
TIntermNode *getChildNode(unsigned int index) final; TIntermNode *getChildNode(size_t index) const final;
bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override; bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override;
TLoopType getType() const { return mType; } TLoopType getType() const { return mType; }
...@@ -229,8 +230,8 @@ class TIntermBranch : public TIntermNode ...@@ -229,8 +230,8 @@ class TIntermBranch : public TIntermNode
TIntermBranch *getAsBranchNode() override { return this; } TIntermBranch *getAsBranchNode() override { return this; }
bool visit(Visit visit, TIntermTraverser *it) final; bool visit(Visit visit, TIntermTraverser *it) final;
unsigned int getChildCount() final; size_t getChildCount() const final;
TIntermNode *getChildNode(unsigned int index) final; TIntermNode *getChildNode(size_t index) const final;
bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override; bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override;
TOperator getFlowOp() { return mFlowOp; } TOperator getFlowOp() { return mFlowOp; }
...@@ -266,8 +267,8 @@ class TIntermSymbol : public TIntermTyped ...@@ -266,8 +267,8 @@ class TIntermSymbol : public TIntermTyped
void traverse(TIntermTraverser *it) final; void traverse(TIntermTraverser *it) final;
bool visit(Visit visit, TIntermTraverser *it) final; bool visit(Visit visit, TIntermTraverser *it) final;
unsigned int getChildCount() final; size_t getChildCount() const final;
TIntermNode *getChildNode(unsigned int index) final; TIntermNode *getChildNode(size_t index) const final;
bool replaceChildNode(TIntermNode *, TIntermNode *) override { return false; } bool replaceChildNode(TIntermNode *, TIntermNode *) override { return false; }
private: private:
...@@ -337,8 +338,8 @@ class TIntermConstantUnion : public TIntermExpression ...@@ -337,8 +338,8 @@ class TIntermConstantUnion : public TIntermExpression
void traverse(TIntermTraverser *it) final; void traverse(TIntermTraverser *it) final;
bool visit(Visit visit, TIntermTraverser *it) final; bool visit(Visit visit, TIntermTraverser *it) final;
unsigned int getChildCount() final; size_t getChildCount() const final;
TIntermNode *getChildNode(unsigned int index) final; TIntermNode *getChildNode(size_t index) const final;
bool replaceChildNode(TIntermNode *, TIntermNode *) override { return false; } bool replaceChildNode(TIntermNode *, TIntermNode *) override { return false; }
TConstantUnion *foldUnaryNonComponentWise(TOperator op); TConstantUnion *foldUnaryNonComponentWise(TOperator op);
...@@ -410,8 +411,8 @@ class TIntermSwizzle : public TIntermExpression ...@@ -410,8 +411,8 @@ class TIntermSwizzle : public TIntermExpression
TIntermSwizzle *getAsSwizzleNode() override { return this; }; TIntermSwizzle *getAsSwizzleNode() override { return this; };
bool visit(Visit visit, TIntermTraverser *it) final; bool visit(Visit visit, TIntermTraverser *it) final;
unsigned int getChildCount() final; size_t getChildCount() const final;
TIntermNode *getChildNode(unsigned int index) final; TIntermNode *getChildNode(size_t index) const final;
bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override; bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override;
bool hasSideEffects() const override { return mOperand->hasSideEffects(); } bool hasSideEffects() const override { return mOperand->hasSideEffects(); }
...@@ -459,8 +460,8 @@ class TIntermBinary : public TIntermOperator ...@@ -459,8 +460,8 @@ class TIntermBinary : public TIntermOperator
void traverse(TIntermTraverser *it) final; void traverse(TIntermTraverser *it) final;
bool visit(Visit visit, TIntermTraverser *it) final; bool visit(Visit visit, TIntermTraverser *it) final;
unsigned int getChildCount() final; size_t getChildCount() const final;
TIntermNode *getChildNode(unsigned int index) final; TIntermNode *getChildNode(size_t index) const final;
bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override; bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override;
bool hasSideEffects() const override bool hasSideEffects() const override
...@@ -509,8 +510,8 @@ class TIntermUnary : public TIntermOperator ...@@ -509,8 +510,8 @@ class TIntermUnary : public TIntermOperator
void traverse(TIntermTraverser *it) final; void traverse(TIntermTraverser *it) final;
bool visit(Visit visit, TIntermTraverser *it) final; bool visit(Visit visit, TIntermTraverser *it) final;
unsigned int getChildCount() final; size_t getChildCount() const final;
TIntermNode *getChildNode(unsigned int index) final; TIntermNode *getChildNode(size_t index) const final;
bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override; bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override;
bool hasSideEffects() const override { return isAssignment() || mOperand->hasSideEffects(); } bool hasSideEffects() const override { return isAssignment() || mOperand->hasSideEffects(); }
...@@ -589,8 +590,8 @@ class TIntermAggregate : public TIntermOperator, public TIntermAggregateBase ...@@ -589,8 +590,8 @@ class TIntermAggregate : public TIntermOperator, public TIntermAggregateBase
void traverse(TIntermTraverser *it) final; void traverse(TIntermTraverser *it) final;
bool visit(Visit visit, TIntermTraverser *it) final; bool visit(Visit visit, TIntermTraverser *it) final;
unsigned int getChildCount() final; size_t getChildCount() const final;
TIntermNode *getChildNode(unsigned int index) final; TIntermNode *getChildNode(size_t index) const final;
bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override; bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override;
bool hasSideEffects() const override; bool hasSideEffects() const override;
...@@ -658,8 +659,8 @@ class TIntermBlock : public TIntermNode, public TIntermAggregateBase ...@@ -658,8 +659,8 @@ class TIntermBlock : public TIntermNode, public TIntermAggregateBase
void traverse(TIntermTraverser *it) final; void traverse(TIntermTraverser *it) final;
bool visit(Visit visit, TIntermTraverser *it) final; bool visit(Visit visit, TIntermTraverser *it) final;
unsigned int getChildCount() final; size_t getChildCount() const final;
TIntermNode *getChildNode(unsigned int index) final; TIntermNode *getChildNode(size_t index) const final;
bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override; bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override;
// Only intended for initially building the block. // Only intended for initially building the block.
...@@ -684,8 +685,8 @@ class TIntermFunctionPrototype : public TIntermTyped ...@@ -684,8 +685,8 @@ class TIntermFunctionPrototype : public TIntermTyped
void traverse(TIntermTraverser *it) final; void traverse(TIntermTraverser *it) final;
bool visit(Visit visit, TIntermTraverser *it) final; bool visit(Visit visit, TIntermTraverser *it) final;
unsigned int getChildCount() final; size_t getChildCount() const final;
TIntermNode *getChildNode(unsigned int index) final; TIntermNode *getChildNode(size_t index) const final;
bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override; bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override;
const TType &getType() const override; const TType &getType() const override;
...@@ -723,8 +724,8 @@ class TIntermFunctionDefinition : public TIntermNode ...@@ -723,8 +724,8 @@ class TIntermFunctionDefinition : public TIntermNode
void traverse(TIntermTraverser *it) final; void traverse(TIntermTraverser *it) final;
bool visit(Visit visit, TIntermTraverser *it) final; bool visit(Visit visit, TIntermTraverser *it) final;
unsigned int getChildCount() final; size_t getChildCount() const final;
TIntermNode *getChildNode(unsigned int index) final; TIntermNode *getChildNode(size_t index) const final;
bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override; bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override;
TIntermFunctionPrototype *getFunctionPrototype() const { return mPrototype; } TIntermFunctionPrototype *getFunctionPrototype() const { return mPrototype; }
...@@ -747,8 +748,8 @@ class TIntermDeclaration : public TIntermNode, public TIntermAggregateBase ...@@ -747,8 +748,8 @@ class TIntermDeclaration : public TIntermNode, public TIntermAggregateBase
TIntermDeclaration *getAsDeclarationNode() override { return this; } TIntermDeclaration *getAsDeclarationNode() override { return this; }
bool visit(Visit visit, TIntermTraverser *it) final; bool visit(Visit visit, TIntermTraverser *it) final;
unsigned int getChildCount() final; size_t getChildCount() const final;
TIntermNode *getChildNode(unsigned int index) final; TIntermNode *getChildNode(size_t index) const final;
bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override; bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override;
// Only intended for initially building the declaration. // Only intended for initially building the declaration.
...@@ -773,8 +774,8 @@ class TIntermInvariantDeclaration : public TIntermNode ...@@ -773,8 +774,8 @@ class TIntermInvariantDeclaration : public TIntermNode
TIntermSymbol *getSymbol() { return mSymbol; } TIntermSymbol *getSymbol() { return mSymbol; }
unsigned int getChildCount() final; size_t getChildCount() const final;
TIntermNode *getChildNode(unsigned int index) final; TIntermNode *getChildNode(size_t index) const final;
bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override; bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override;
private: private:
...@@ -790,8 +791,8 @@ class TIntermTernary : public TIntermExpression ...@@ -790,8 +791,8 @@ class TIntermTernary : public TIntermExpression
TIntermTernary *getAsTernaryNode() override { return this; } TIntermTernary *getAsTernaryNode() override { return this; }
bool visit(Visit visit, TIntermTraverser *it) final; bool visit(Visit visit, TIntermTraverser *it) final;
unsigned int getChildCount() final; size_t getChildCount() const final;
TIntermNode *getChildNode(unsigned int index) final; TIntermNode *getChildNode(size_t index) const final;
bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override; bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override;
TIntermTyped *getCondition() const { return mCondition; } TIntermTyped *getCondition() const { return mCondition; }
...@@ -828,8 +829,8 @@ class TIntermIfElse : public TIntermNode ...@@ -828,8 +829,8 @@ class TIntermIfElse : public TIntermNode
TIntermIfElse *getAsIfElseNode() override { return this; } TIntermIfElse *getAsIfElseNode() override { return this; }
bool visit(Visit visit, TIntermTraverser *it) final; bool visit(Visit visit, TIntermTraverser *it) final;
unsigned int getChildCount() final; size_t getChildCount() const final;
TIntermNode *getChildNode(unsigned int index) final; TIntermNode *getChildNode(size_t index) const final;
bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override; bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override;
TIntermTyped *getCondition() const { return mCondition; } TIntermTyped *getCondition() const { return mCondition; }
...@@ -853,8 +854,8 @@ class TIntermSwitch : public TIntermNode ...@@ -853,8 +854,8 @@ class TIntermSwitch : public TIntermNode
TIntermSwitch *getAsSwitchNode() override { return this; } TIntermSwitch *getAsSwitchNode() override { return this; }
bool visit(Visit visit, TIntermTraverser *it) final; bool visit(Visit visit, TIntermTraverser *it) final;
unsigned int getChildCount() final; size_t getChildCount() const final;
TIntermNode *getChildNode(unsigned int index) final; TIntermNode *getChildNode(size_t index) const final;
bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override; bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override;
TIntermTyped *getInit() { return mInit; } TIntermTyped *getInit() { return mInit; }
...@@ -879,8 +880,8 @@ class TIntermCase : public TIntermNode ...@@ -879,8 +880,8 @@ class TIntermCase : public TIntermNode
TIntermCase *getAsCaseNode() override { return this; } TIntermCase *getAsCaseNode() override { return this; }
bool visit(Visit visit, TIntermTraverser *it) final; bool visit(Visit visit, TIntermTraverser *it) final;
unsigned int getChildCount() final; size_t getChildCount() const final;
TIntermNode *getChildNode(unsigned int index) final; TIntermNode *getChildNode(size_t index) const final;
bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override; bool replaceChildNode(TIntermNode *original, TIntermNode *replacement) override;
bool hasCondition() const { return mCondition != nullptr; } bool hasCondition() const { return mCondition != nullptr; }
...@@ -890,6 +891,42 @@ class TIntermCase : public TIntermNode ...@@ -890,6 +891,42 @@ class TIntermCase : public TIntermNode
TIntermTyped *mCondition; TIntermTyped *mCondition;
}; };
//
// Preprocessor Directive.
// #ifdef, #define, #if, #endif, etc.
//
enum class PreprocessorDirective
{
Define,
Ifdef,
If,
Endif,
};
class TIntermPreprocessorDirective : public TIntermNode
{
public:
// This could also take an ImmutbleString as an argument.
TIntermPreprocessorDirective(PreprocessorDirective directive, ImmutableString command);
~TIntermPreprocessorDirective() final;
void traverse(TIntermTraverser *it) final;
bool visit(Visit visit, TIntermTraverser *it) final;
bool replaceChildNode(TIntermNode *, TIntermNode *) final { return false; }
TIntermPreprocessorDirective *getAsPreprocessorDirective() final { return this; }
size_t getChildCount() const final;
TIntermNode *getChildNode(size_t index) const final;
PreprocessorDirective getDirective() const { return mDirective; }
const ImmutableString &getCommand() const { return mCommand; }
private:
PreprocessorDirective mDirective;
ImmutableString mCommand;
};
} // namespace sh } // namespace sh
#endif // COMPILER_TRANSLATOR_INTERMNODE_H_ #endif // COMPILER_TRANSLATOR_INTERMNODE_H_
...@@ -46,6 +46,10 @@ bool isSingleStatement(TIntermNode *node) ...@@ -46,6 +46,10 @@ bool isSingleStatement(TIntermNode *node)
{ {
return false; return false;
} }
else if (node->getAsPreprocessorDirective())
{
return false;
}
return true; return true;
} }
...@@ -1113,6 +1117,40 @@ void TOutputGLSLBase::visitCodeBlock(TIntermBlock *node) ...@@ -1113,6 +1117,40 @@ void TOutputGLSLBase::visitCodeBlock(TIntermBlock *node)
} }
} }
void TOutputGLSLBase::visitPreprocessorDirective(TIntermPreprocessorDirective *node)
{
TInfoSinkBase &out = objSink();
out << "\n";
switch (node->getDirective())
{
case PreprocessorDirective::Define:
out << "#define";
break;
case PreprocessorDirective::Endif:
out << "#endif";
break;
case PreprocessorDirective::If:
out << "#if";
break;
case PreprocessorDirective::Ifdef:
out << "#ifdef";
break;
default:
UNREACHABLE();
break;
}
if (!node->getCommand().empty())
{
out << " " << node->getCommand();
}
out << "\n";
}
ImmutableString TOutputGLSLBase::getTypeName(const TType &type) ImmutableString TOutputGLSLBase::getTypeName(const TType &type)
{ {
return GetTypeName(type, mHashFunction, &mNameMap); return GetTypeName(type, mHashFunction, &mNameMap);
......
...@@ -66,6 +66,7 @@ class TOutputGLSLBase : public TIntermTraverser ...@@ -66,6 +66,7 @@ class TOutputGLSLBase : public TIntermTraverser
bool visitDeclaration(Visit visit, TIntermDeclaration *node) override; bool visitDeclaration(Visit visit, TIntermDeclaration *node) override;
bool visitLoop(Visit visit, TIntermLoop *node) override; bool visitLoop(Visit visit, TIntermLoop *node) override;
bool visitBranch(Visit visit, TIntermBranch *node) override; bool visitBranch(Visit visit, TIntermBranch *node) override;
void visitPreprocessorDirective(TIntermPreprocessorDirective *node) override;
void visitCodeBlock(TIntermBlock *node); void visitCodeBlock(TIntermBlock *node);
......
...@@ -32,8 +32,8 @@ void TIntermTraverser::traverse(T *node) ...@@ -32,8 +32,8 @@ void TIntermTraverser::traverse(T *node)
if (visit) if (visit)
{ {
unsigned int childIndex = 0; size_t childIndex = 0;
unsigned int childCount = node->getChildCount(); size_t childCount = node->getChildCount();
while (childIndex < childCount && visit) while (childIndex < childCount && visit)
{ {
...@@ -103,6 +103,11 @@ void TIntermLoop::traverse(TIntermTraverser *it) ...@@ -103,6 +103,11 @@ void TIntermLoop::traverse(TIntermTraverser *it)
it->traverseLoop(this); it->traverseLoop(this);
} }
void TIntermPreprocessorDirective::traverse(TIntermTraverser *it)
{
it->visitPreprocessorDirective(this);
}
bool TIntermSymbol::visit(Visit visit, TIntermTraverser *it) bool TIntermSymbol::visit(Visit visit, TIntermTraverser *it)
{ {
it->visitSymbol(this); it->visitSymbol(this);
...@@ -191,6 +196,12 @@ bool TIntermCase::visit(Visit visit, TIntermTraverser *it) ...@@ -191,6 +196,12 @@ bool TIntermCase::visit(Visit visit, TIntermTraverser *it)
return it->visitCase(visit, this); return it->visitCase(visit, this);
} }
bool TIntermPreprocessorDirective::visit(Visit visit, TIntermTraverser *it)
{
it->visitPreprocessorDirective(this);
return false;
}
TIntermTraverser::TIntermTraverser(bool preVisit, TIntermTraverser::TIntermTraverser(bool preVisit,
bool inVisit, bool inVisit,
bool postVisit, bool postVisit,
...@@ -614,5 +625,4 @@ void TIntermTraverser::traverseLoop(TIntermLoop *node) ...@@ -614,5 +625,4 @@ void TIntermTraverser::traverseLoop(TIntermLoop *node)
{ {
traverse(node); traverse(node);
} }
} // namespace sh } // namespace sh
...@@ -63,6 +63,7 @@ class TIntermTraverser : angle::NonCopyable ...@@ -63,6 +63,7 @@ class TIntermTraverser : angle::NonCopyable
virtual bool visitDeclaration(Visit visit, TIntermDeclaration *node) { return true; } virtual bool visitDeclaration(Visit visit, TIntermDeclaration *node) { return true; }
virtual bool visitLoop(Visit visit, TIntermLoop *node) { return true; } virtual bool visitLoop(Visit visit, TIntermLoop *node) { return true; }
virtual bool visitBranch(Visit visit, TIntermBranch *node) { return true; } virtual bool visitBranch(Visit visit, TIntermBranch *node) { return true; }
virtual void visitPreprocessorDirective(TIntermPreprocessorDirective *node) {}
// The traverse functions contain logic for iterating over the children of the node // The traverse functions contain logic for iterating over the children of the node
// and calling the visit functions in the appropriate places. They also track some // and calling the visit functions in the appropriate places. They also track some
......
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