Commit a7ecec38 by Olli Etuaho Committed by Commit Bot

GLSL: Simplify constructor parsing

Constructor argument checking rules are reorganized to make them easier to understand and constructor node creation is made simpler. This removes usage of constructor op codes from ParseContext. This paves the way for getting rid of constructor op codes entirely, which will remove duplicate information from the AST and simplify lots of code. This refactoring will make adding arrays of arrays slightly easier. BUG=angleproject:1490 TEST=angle_unittests Change-Id: I4053afec55111b629353b4ff7cb0451c1ae3511c Reviewed-on: https://chromium-review.googlesource.com/498767 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 73fa4b83
...@@ -304,10 +304,10 @@ TIntermAggregate *TIntermAggregate::CreateBuiltInFunctionCall(const TFunction &f ...@@ -304,10 +304,10 @@ TIntermAggregate *TIntermAggregate::CreateBuiltInFunctionCall(const TFunction &f
} }
TIntermAggregate *TIntermAggregate::CreateConstructor(const TType &type, TIntermAggregate *TIntermAggregate::CreateConstructor(const TType &type,
TOperator op,
TIntermSequence *arguments) TIntermSequence *arguments)
{ {
TIntermAggregate *constructorNode = new TIntermAggregate(type, op, arguments); TIntermAggregate *constructorNode =
new TIntermAggregate(type, sh::TypeToConstructorOperator(type), arguments);
ASSERT(constructorNode->isConstructor()); ASSERT(constructorNode->isConstructor());
return constructorNode; return constructorNode;
} }
...@@ -630,8 +630,7 @@ TIntermTyped *TIntermTyped::CreateZero(const TType &type) ...@@ -630,8 +630,7 @@ TIntermTyped *TIntermTyped::CreateZero(const TType &type)
} }
} }
return TIntermAggregate::CreateConstructor(constType, sh::TypeToConstructorOperator(type), return TIntermAggregate::CreateConstructor(constType, arguments);
arguments);
} }
// static // static
...@@ -777,9 +776,7 @@ bool TIntermOperator::isMultiplication() const ...@@ -777,9 +776,7 @@ bool TIntermOperator::isMultiplication() const
} }
} }
// // Returns true if the operator is for one of the constructors.
// returns true if the operator is for one of the constructors
//
bool TIntermOperator::isConstructor() const bool TIntermOperator::isConstructor() const
{ {
switch (mOp) switch (mOp)
...@@ -812,6 +809,8 @@ bool TIntermOperator::isConstructor() const ...@@ -812,6 +809,8 @@ bool TIntermOperator::isConstructor() const
case EOpConstructStruct: case EOpConstructStruct:
return true; return true;
default: default:
// EOpConstruct is not supposed to be used in the AST.
ASSERT(mOp != EOpConstruct);
return false; return false;
} }
} }
......
...@@ -604,7 +604,6 @@ class TIntermAggregate : public TIntermOperator, public TIntermAggregateBase ...@@ -604,7 +604,6 @@ class TIntermAggregate : public TIntermOperator, public TIntermAggregateBase
static TIntermAggregate *CreateBuiltInFunctionCall(const TFunction &func, static TIntermAggregate *CreateBuiltInFunctionCall(const TFunction &func,
TIntermSequence *arguments); TIntermSequence *arguments);
static TIntermAggregate *CreateConstructor(const TType &type, static TIntermAggregate *CreateConstructor(const TType &type,
TOperator op,
TIntermSequence *arguments); TIntermSequence *arguments);
static TIntermAggregate *Create(const TType &type, TOperator op, TIntermSequence *arguments); static TIntermAggregate *Create(const TType &type, TOperator op, TIntermSequence *arguments);
~TIntermAggregate() {} ~TIntermAggregate() {}
......
...@@ -205,6 +205,10 @@ enum TOperator ...@@ -205,6 +205,10 @@ enum TOperator
// Constructors // Constructors
// //
// Used by ParseContext to denote any constructor.
EOpConstruct,
// In the AST, constructors are stored using the below more specific op codes.
EOpConstructInt, EOpConstructInt,
EOpConstructUInt, EOpConstructUInt,
EOpConstructBool, EOpConstructBool,
......
...@@ -113,7 +113,6 @@ class TParseContext : angle::NonCopyable ...@@ -113,7 +113,6 @@ class TParseContext : angle::NonCopyable
bool checkIsAtGlobalLevel(const TSourceLoc &line, const char *token); bool checkIsAtGlobalLevel(const TSourceLoc &line, const char *token);
bool checkConstructorArguments(const TSourceLoc &line, bool checkConstructorArguments(const TSourceLoc &line,
const TIntermSequence *arguments, const TIntermSequence *arguments,
TOperator op,
const TType &type); const TType &type);
// Returns a sanitized array size to use (the size is at least 1). // Returns a sanitized array size to use (the size is at least 1).
...@@ -415,7 +414,6 @@ class TParseContext : angle::NonCopyable ...@@ -415,7 +414,6 @@ class TParseContext : angle::NonCopyable
TIntermNode *thisNode, TIntermNode *thisNode,
const TSourceLoc &loc); const TSourceLoc &loc);
TIntermTyped *addConstructor(TIntermSequence *arguments, TIntermTyped *addConstructor(TIntermSequence *arguments,
TOperator op,
TType type, TType type,
const TSourceLoc &line); const TSourceLoc &line);
TIntermTyped *addNonConstructorFunctionCall(TFunction *fnCall, TIntermTyped *addNonConstructorFunctionCall(TFunction *fnCall,
......
...@@ -110,7 +110,7 @@ TIntermTyped *EnsureSignedInt(TIntermTyped *node) ...@@ -110,7 +110,7 @@ TIntermTyped *EnsureSignedInt(TIntermTyped *node)
TIntermSequence *arguments = new TIntermSequence(); TIntermSequence *arguments = new TIntermSequence();
arguments->push_back(node); arguments->push_back(node);
return TIntermAggregate::CreateConstructor(TType(EbtInt), EOpConstructInt, arguments); return TIntermAggregate::CreateConstructor(TType(EbtInt), arguments);
} }
TType GetFieldType(const TType &indexedType) TType GetFieldType(const TType &indexedType)
......
...@@ -110,7 +110,7 @@ bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -110,7 +110,7 @@ bool Traverser::visitAggregate(Visit visit, TIntermAggregate *node)
TIntermTyped *zeroNode = TIntermTyped::CreateZero(TType(EbtInt)); TIntermTyped *zeroNode = TIntermTyped::CreateZero(TType(EbtInt));
constructOffsetIvecArguments->push_back(zeroNode); constructOffsetIvecArguments->push_back(zeroNode);
offsetNode = TIntermAggregate::CreateConstructor(texCoordNode->getType(), EOpConstructIVec3, offsetNode = TIntermAggregate::CreateConstructor(texCoordNode->getType(),
constructOffsetIvecArguments); constructOffsetIvecArguments);
offsetNode->setLine(texCoordNode->getLine()); offsetNode->setLine(texCoordNode->getLine());
} }
......
...@@ -125,6 +125,8 @@ TType::TType(const TPublicType &p) ...@@ -125,6 +125,8 @@ TType::TType(const TPublicType &p)
interfaceBlock(0), interfaceBlock(0),
structure(0) structure(0)
{ {
ASSERT(primarySize <= 4);
ASSERT(secondarySize <= 4);
if (p.getUserDef()) if (p.getUserDef())
structure = p.getUserDef()->getStruct(); structure = p.getUserDef()->getStruct();
} }
...@@ -134,6 +136,21 @@ bool TStructure::equals(const TStructure &other) const ...@@ -134,6 +136,21 @@ bool TStructure::equals(const TStructure &other) const
return (uniqueId() == other.uniqueId()); return (uniqueId() == other.uniqueId());
} }
bool TType::canBeConstructed() const
{
switch (type)
{
case EbtFloat:
case EbtInt:
case EbtUInt:
case EbtBool:
case EbtStruct:
return true;
default:
return false;
}
}
const char *TType::getBuiltInTypeNameString() const const char *TType::getBuiltInTypeNameString() const
{ {
if (isMatrix()) if (isMatrix())
......
...@@ -318,6 +318,7 @@ class TType ...@@ -318,6 +318,7 @@ class TType
{ {
if (primarySize != ps) if (primarySize != ps)
{ {
ASSERT(ps <= 4);
primarySize = ps; primarySize = ps;
invalidateMangledName(); invalidateMangledName();
} }
...@@ -326,6 +327,7 @@ class TType ...@@ -326,6 +327,7 @@ class TType
{ {
if (secondarySize != ss) if (secondarySize != ss)
{ {
ASSERT(ss <= 4);
secondarySize = ss; secondarySize = ss;
invalidateMangledName(); invalidateMangledName();
} }
...@@ -377,6 +379,8 @@ class TType ...@@ -377,6 +379,8 @@ class TType
bool isScalarFloat() const { return isScalar() && type == EbtFloat; } bool isScalarFloat() const { return isScalar() && type == EbtFloat; }
bool isScalarInt() const { return isScalar() && (type == EbtInt || type == EbtUInt); } bool isScalarInt() const { return isScalar() && (type == EbtInt || type == EbtUInt); }
bool canBeConstructed() const;
TStructure *getStruct() const { return structure; } TStructure *getStruct() const { return structure; }
void setStruct(TStructure *s) void setStruct(TStructure *s)
{ {
......
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