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
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)
: TIntermNode(), mSymbol(symbol)
{
......
......@@ -268,9 +268,9 @@ class TIntermExpression : public TIntermTyped
TIntermExpression(const TType &t);
const TType &getType() const override { return mType; }
TType *getTypePointer() { return &mType; }
protected:
TType *getTypePointer() { return &mType; }
void setType(const TType &t) { mType = t; }
void setTypePreservePrecision(const TType &t);
......@@ -349,13 +349,6 @@ class TIntermConstantUnion : public TIntermExpression
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; }
void traverse(TIntermTraverser *it) override;
bool replaceChildNode(TIntermNode *, TIntermNode *) override { return false; }
......@@ -458,6 +451,8 @@ class TIntermBinary : public TIntermOperator
public:
// This constructor determines the type of the binary node based on the operands and op.
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); }
......@@ -466,9 +461,6 @@ class TIntermBinary : public TIntermOperator
static TOperator GetMulOpBasedOnOperands(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; };
void traverse(TIntermTraverser *it) override;
......@@ -496,6 +488,10 @@ class TIntermBinary : public TIntermOperator
private:
void promote();
static TQualifier GetCommaQualifier(int shaderVersion,
const TIntermTyped *left,
const TIntermTyped *right);
TIntermBinary(const TIntermBinary &node); // Note: not deleted, just private!
};
......
......@@ -4054,8 +4054,9 @@ TIntermTyped *TParseContext::addIndexExpression(TIntermTyped *baseExpression,
{
TConstantUnion *safeConstantUnion = new TConstantUnion();
safeConstantUnion->setIConst(safeIndex);
indexConstantUnion->replaceConstantUnion(safeConstantUnion);
indexConstantUnion->getTypePointer()->setBasicType(EbtInt);
indexExpression = new TIntermConstantUnion(
safeConstantUnion, TType(EbtInt, indexExpression->getPrecision(),
indexExpression->getQualifier()));
}
TIntermBinary *node =
......@@ -5435,9 +5436,7 @@ TIntermTyped *TParseContext::addComma(TIntermTyped *left,
",");
}
TIntermBinary *commaNode = new TIntermBinary(EOpComma, left, right);
TQualifier resultQualifier = TIntermBinary::GetCommaQualifier(mShaderVersion, left, right);
commaNode->getTypePointer()->setQualifier(resultQualifier);
TIntermBinary *commaNode = TIntermBinary::CreateComma(left, right, mShaderVersion);
return expressionOrFoldedResult(commaNode);
}
......
......@@ -88,8 +88,8 @@ bool Traverser::visitUnary(Visit visit, TIntermUnary *node)
{
one->setUConst(1u);
}
TIntermConstantUnion *oneNode = new TIntermConstantUnion(one, opr->getType());
oneNode->getTypePointer()->setQualifier(EvqConst);
TIntermConstantUnion *oneNode =
new TIntermConstantUnion(one, TType(opr->getBasicType(), opr->getPrecision(), EvqConst));
oneNode->setLine(opr->getLine());
// ~(int) + 1
......
......@@ -204,8 +204,10 @@ void VectorizeVectorScalarArithmeticTraverser::replaceAssignInsideConstructor(
TIntermBinary *replacementSequenceLeft =
new TIntermBinary(EOpComma, replacementCompoundAssignment, replacementAssignBackToTarget);
// (s0 *= b, a = s0.x), s0
TIntermBinary *replacementSequence = new TIntermBinary(
EOpComma, replacementSequenceLeft, CreateTempSymbolNode(tempAssignmentTarget));
// Note that the created comma node is not const qualified in any case, so we can always pass
// shader version 300 here.
TIntermBinary *replacementSequence = TIntermBinary::CreateComma(
replacementSequenceLeft, CreateTempSymbolNode(tempAssignmentTarget), 300);
insertStatementInParentBlock(tempAssignmentTargetDeclaration);
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