Commit 0e99b7a3 by Olli Etuaho Committed by Commit Bot

Prevent changing AST expression type from outside

TIntermNode classes now contain all the logic for setting node types. Changing the constant values of constant union nodes from outside is also not necessary anymore. BUG=angleproject:2267 TEST=angle_unittests Change-Id: Ic10d41b1e5f93152df440a655057591dc1b783b0 Reviewed-on: https://chromium-review.googlesource.com/863626Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 3c424b48
...@@ -1089,6 +1089,15 @@ TIntermBinary::TIntermBinary(TOperator op, TIntermTyped *left, TIntermTyped *rig ...@@ -1089,6 +1089,15 @@ TIntermBinary::TIntermBinary(TOperator op, TIntermTyped *left, TIntermTyped *rig
promote(); promote();
} }
TIntermBinary *TIntermBinary::CreateComma(TIntermTyped *left,
TIntermTyped *right,
int shaderVersion)
{
TIntermBinary *node = new TIntermBinary(EOpComma, left, right);
node->getTypePointer()->setQualifier(GetCommaQualifier(shaderVersion, left, right));
return node;
}
TIntermInvariantDeclaration::TIntermInvariantDeclaration(TIntermSymbol *symbol, const TSourceLoc &line) TIntermInvariantDeclaration::TIntermInvariantDeclaration(TIntermSymbol *symbol, const TSourceLoc &line)
: TIntermNode(), mSymbol(symbol) : TIntermNode(), mSymbol(symbol)
{ {
......
...@@ -268,9 +268,9 @@ class TIntermExpression : public TIntermTyped ...@@ -268,9 +268,9 @@ class TIntermExpression : public TIntermTyped
TIntermExpression(const TType &t); TIntermExpression(const TType &t);
const TType &getType() const override { return mType; } const TType &getType() const override { return mType; }
TType *getTypePointer() { return &mType; }
protected: protected:
TType *getTypePointer() { return &mType; }
void setType(const TType &t) { mType = t; } void setType(const TType &t) { mType = t; }
void setTypePreservePrecision(const TType &t); void setTypePreservePrecision(const TType &t);
...@@ -349,13 +349,6 @@ class TIntermConstantUnion : public TIntermExpression ...@@ -349,13 +349,6 @@ class TIntermConstantUnion : public TIntermExpression
return mUnionArrayPointer ? mUnionArrayPointer[index].getBConst() : false; return mUnionArrayPointer ? mUnionArrayPointer[index].getBConst() : false;
} }
void replaceConstantUnion(const TConstantUnion *safeConstantUnion)
{
ASSERT(safeConstantUnion);
// Previous union pointer freed on pool deallocation.
mUnionArrayPointer = safeConstantUnion;
}
TIntermConstantUnion *getAsConstantUnion() override { return this; } TIntermConstantUnion *getAsConstantUnion() override { return this; }
void traverse(TIntermTraverser *it) override; void traverse(TIntermTraverser *it) override;
bool replaceChildNode(TIntermNode *, TIntermNode *) override { return false; } bool replaceChildNode(TIntermNode *, TIntermNode *) override { return false; }
...@@ -458,6 +451,8 @@ class TIntermBinary : public TIntermOperator ...@@ -458,6 +451,8 @@ class TIntermBinary : public TIntermOperator
public: public:
// This constructor determines the type of the binary node based on the operands and op. // This constructor determines the type of the binary node based on the operands and op.
TIntermBinary(TOperator op, TIntermTyped *left, TIntermTyped *right); TIntermBinary(TOperator op, TIntermTyped *left, TIntermTyped *right);
// Comma qualifier depends on the shader version, so use this to create comma nodes:
static TIntermBinary *CreateComma(TIntermTyped *left, TIntermTyped *right, int shaderVersion);
TIntermTyped *deepCopy() const override { return new TIntermBinary(*this); } TIntermTyped *deepCopy() const override { return new TIntermBinary(*this); }
...@@ -466,9 +461,6 @@ class TIntermBinary : public TIntermOperator ...@@ -466,9 +461,6 @@ class TIntermBinary : public TIntermOperator
static TOperator GetMulOpBasedOnOperands(const TType &left, const TType &right); static TOperator GetMulOpBasedOnOperands(const TType &left, const TType &right);
static TOperator GetMulAssignOpBasedOnOperands(const TType &left, const TType &right); static TOperator GetMulAssignOpBasedOnOperands(const TType &left, const TType &right);
static TQualifier GetCommaQualifier(int shaderVersion,
const TIntermTyped *left,
const TIntermTyped *right);
TIntermBinary *getAsBinaryNode() override { return this; }; TIntermBinary *getAsBinaryNode() override { return this; };
void traverse(TIntermTraverser *it) override; void traverse(TIntermTraverser *it) override;
...@@ -496,6 +488,10 @@ class TIntermBinary : public TIntermOperator ...@@ -496,6 +488,10 @@ class TIntermBinary : public TIntermOperator
private: private:
void promote(); void promote();
static TQualifier GetCommaQualifier(int shaderVersion,
const TIntermTyped *left,
const TIntermTyped *right);
TIntermBinary(const TIntermBinary &node); // Note: not deleted, just private! TIntermBinary(const TIntermBinary &node); // Note: not deleted, just private!
}; };
......
...@@ -4054,8 +4054,9 @@ TIntermTyped *TParseContext::addIndexExpression(TIntermTyped *baseExpression, ...@@ -4054,8 +4054,9 @@ TIntermTyped *TParseContext::addIndexExpression(TIntermTyped *baseExpression,
{ {
TConstantUnion *safeConstantUnion = new TConstantUnion(); TConstantUnion *safeConstantUnion = new TConstantUnion();
safeConstantUnion->setIConst(safeIndex); safeConstantUnion->setIConst(safeIndex);
indexConstantUnion->replaceConstantUnion(safeConstantUnion); indexExpression = new TIntermConstantUnion(
indexConstantUnion->getTypePointer()->setBasicType(EbtInt); safeConstantUnion, TType(EbtInt, indexExpression->getPrecision(),
indexExpression->getQualifier()));
} }
TIntermBinary *node = TIntermBinary *node =
...@@ -5435,9 +5436,7 @@ TIntermTyped *TParseContext::addComma(TIntermTyped *left, ...@@ -5435,9 +5436,7 @@ TIntermTyped *TParseContext::addComma(TIntermTyped *left,
","); ",");
} }
TIntermBinary *commaNode = new TIntermBinary(EOpComma, left, right); TIntermBinary *commaNode = TIntermBinary::CreateComma(left, right, mShaderVersion);
TQualifier resultQualifier = TIntermBinary::GetCommaQualifier(mShaderVersion, left, right);
commaNode->getTypePointer()->setQualifier(resultQualifier);
return expressionOrFoldedResult(commaNode); return expressionOrFoldedResult(commaNode);
} }
......
...@@ -88,8 +88,8 @@ bool Traverser::visitUnary(Visit visit, TIntermUnary *node) ...@@ -88,8 +88,8 @@ bool Traverser::visitUnary(Visit visit, TIntermUnary *node)
{ {
one->setUConst(1u); one->setUConst(1u);
} }
TIntermConstantUnion *oneNode = new TIntermConstantUnion(one, opr->getType()); TIntermConstantUnion *oneNode =
oneNode->getTypePointer()->setQualifier(EvqConst); new TIntermConstantUnion(one, TType(opr->getBasicType(), opr->getPrecision(), EvqConst));
oneNode->setLine(opr->getLine()); oneNode->setLine(opr->getLine());
// ~(int) + 1 // ~(int) + 1
......
...@@ -204,8 +204,10 @@ void VectorizeVectorScalarArithmeticTraverser::replaceAssignInsideConstructor( ...@@ -204,8 +204,10 @@ void VectorizeVectorScalarArithmeticTraverser::replaceAssignInsideConstructor(
TIntermBinary *replacementSequenceLeft = TIntermBinary *replacementSequenceLeft =
new TIntermBinary(EOpComma, replacementCompoundAssignment, replacementAssignBackToTarget); new TIntermBinary(EOpComma, replacementCompoundAssignment, replacementAssignBackToTarget);
// (s0 *= b, a = s0.x), s0 // (s0 *= b, a = s0.x), s0
TIntermBinary *replacementSequence = new TIntermBinary( // Note that the created comma node is not const qualified in any case, so we can always pass
EOpComma, replacementSequenceLeft, CreateTempSymbolNode(tempAssignmentTarget)); // shader version 300 here.
TIntermBinary *replacementSequence = TIntermBinary::CreateComma(
replacementSequenceLeft, CreateTempSymbolNode(tempAssignmentTarget), 300);
insertStatementInParentBlock(tempAssignmentTargetDeclaration); insertStatementInParentBlock(tempAssignmentTargetDeclaration);
queueReplacement(replacementSequence, OriginalNode::IS_DROPPED); queueReplacement(replacementSequence, OriginalNode::IS_DROPPED);
......
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