Commit 4a9cd800 by Martin Radev Committed by Commit Bot

Refactor type_specifier_nonarray parsing to reduce code repetition

When type_specifier_nonarray gets parsed the scope gets saved into TType and the code becomes repetitive. Setting of the scope is moved to type_specifier_no_prec as it occurs less times. BUG=angleproject:911 TEST=angle_unittests TEST=angle_end2end_tests Change-Id: I6da5fe7bc2d60ba2996221af71b719b818f5e9b1 Reviewed-on: https://chromium-review.googlesource.com/380535 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 5b46a680
...@@ -445,15 +445,13 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources) ...@@ -445,15 +445,13 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources)
symbolTable.push(); // ESSL3_1_BUILTINS symbolTable.push(); // ESSL3_1_BUILTINS
TPublicType integer; TPublicType integer;
integer.type = EbtInt; integer.setBasicType(EbtInt);
integer.primarySize = 1; integer.initializeSizeForScalarTypes();
integer.secondarySize = 1;
integer.array = false; integer.array = false;
TPublicType floatingPoint; TPublicType floatingPoint;
floatingPoint.type = EbtFloat; floatingPoint.setBasicType(EbtFloat);
floatingPoint.primarySize = 1; floatingPoint.initializeSizeForScalarTypes();
floatingPoint.secondarySize = 1;
floatingPoint.array = false; floatingPoint.array = false;
switch(shaderType) switch(shaderType)
...@@ -493,10 +491,9 @@ void TCompiler::initSamplerDefaultPrecision(TBasicType samplerType) ...@@ -493,10 +491,9 @@ void TCompiler::initSamplerDefaultPrecision(TBasicType samplerType)
{ {
ASSERT(samplerType > EbtGuardSamplerBegin && samplerType < EbtGuardSamplerEnd); ASSERT(samplerType > EbtGuardSamplerBegin && samplerType < EbtGuardSamplerEnd);
TPublicType sampler; TPublicType sampler;
sampler.primarySize = 1; sampler.initializeSizeForScalarTypes();
sampler.secondarySize = 1; sampler.setBasicType(samplerType);
sampler.array = false; sampler.array = false;
sampler.type = samplerType;
symbolTable.setDefaultPrecision(sampler, EbpLow); symbolTable.setDefaultPrecision(sampler, EbpLow);
} }
......
...@@ -160,7 +160,9 @@ class TParseContext : angle::NonCopyable ...@@ -160,7 +160,9 @@ class TParseContext : angle::NonCopyable
bool checkIsNonVoid(const TSourceLoc &line, const TString &identifier, const TBasicType &type); bool checkIsNonVoid(const TSourceLoc &line, const TString &identifier, const TBasicType &type);
void checkIsScalarBool(const TSourceLoc &line, const TIntermTyped *type); void checkIsScalarBool(const TSourceLoc &line, const TIntermTyped *type);
void checkIsScalarBool(const TSourceLoc &line, const TPublicType &pType); void checkIsScalarBool(const TSourceLoc &line, const TPublicType &pType);
bool checkIsNotSampler(const TSourceLoc &line, const TPublicType &pType, const char *reason); bool checkIsNotSampler(const TSourceLoc &line,
const TTypeSpecifierNonArray &pType,
const char *reason);
void checkDeclaratorLocationIsNotSpecified(const TSourceLoc &line, const TPublicType &pType); void checkDeclaratorLocationIsNotSpecified(const TSourceLoc &line, const TPublicType &pType);
void checkLocationIsNotSpecified(const TSourceLoc &location, void checkLocationIsNotSpecified(const TSourceLoc &location,
const TLayoutQualifier &layoutQualifier); const TLayoutQualifier &layoutQualifier);
...@@ -298,10 +300,10 @@ class TParseContext : angle::NonCopyable ...@@ -298,10 +300,10 @@ class TParseContext : angle::NonCopyable
TPublicType *typeSpecifier, TPublicType *typeSpecifier,
TFieldList *fieldList); TFieldList *fieldList);
TFieldList *addStructDeclaratorList(const TPublicType &typeSpecifier, TFieldList *fieldList); TFieldList *addStructDeclaratorList(const TPublicType &typeSpecifier, TFieldList *fieldList);
TPublicType addStructure(const TSourceLoc &structLine, TTypeSpecifierNonArray addStructure(const TSourceLoc &structLine,
const TSourceLoc &nameLine, const TSourceLoc &nameLine,
const TString *structName, const TString *structName,
TFieldList *fieldList); TFieldList *fieldList);
TIntermAggregate *addInterfaceBlock(const TTypeQualifierBuilder &typeQualifierBuilder, TIntermAggregate *addInterfaceBlock(const TTypeQualifierBuilder &typeQualifierBuilder,
const TSourceLoc &nameLine, const TSourceLoc &nameLine,
......
...@@ -471,15 +471,15 @@ class TSymbolTable : angle::NonCopyable ...@@ -471,15 +471,15 @@ class TSymbolTable : angle::NonCopyable
bool setDefaultPrecision(const TPublicType &type, TPrecision prec) bool setDefaultPrecision(const TPublicType &type, TPrecision prec)
{ {
if (!SupportsPrecision(type.type)) if (!SupportsPrecision(type.getBasicType()))
return false; return false;
if (type.type == EbtUInt) if (type.getBasicType() == EbtUInt)
return false; // ESSL 3.00.4 section 4.5.4 return false; // ESSL 3.00.4 section 4.5.4
if (type.isAggregate()) if (type.isAggregate())
return false; // Not allowed to set for aggregate types return false; // Not allowed to set for aggregate types
int indexOfLastElement = static_cast<int>(precisionStack.size()) - 1; int indexOfLastElement = static_cast<int>(precisionStack.size()) - 1;
// Uses map operator [], overwrites the current value // Uses map operator [], overwrites the current value
(*precisionStack[indexOfLastElement])[type.type] = prec; (*precisionStack[indexOfLastElement])[type.getBasicType()] = prec;
return true; return true;
} }
......
...@@ -48,12 +48,20 @@ const char* getBasicString(TBasicType t) ...@@ -48,12 +48,20 @@ const char* getBasicString(TBasicType t)
} }
TType::TType(const TPublicType &p) TType::TType(const TPublicType &p)
: type(p.type), precision(p.precision), qualifier(p.qualifier), invariant(p.invariant), : type(p.getBasicType()),
layoutQualifier(p.layoutQualifier), primarySize(p.primarySize), secondarySize(p.secondarySize), precision(p.precision),
array(p.array), arraySize(p.arraySize), interfaceBlock(0), structure(0) qualifier(p.qualifier),
invariant(p.invariant),
layoutQualifier(p.layoutQualifier),
primarySize(p.getPrimarySize()),
secondarySize(p.getSecondarySize()),
array(p.array),
arraySize(p.arraySize),
interfaceBlock(0),
structure(0)
{ {
if (p.userDef) if (p.getUserDef())
structure = p.userDef->getStruct(); structure = p.getUserDef()->getStruct();
} }
bool TStructure::equals(const TStructure &other) const bool TStructure::equals(const TStructure &other) const
......
...@@ -594,44 +594,25 @@ class TType ...@@ -594,44 +594,25 @@ class TType
mutable TString mangled; mutable TString mangled;
}; };
// // TTypeSpecifierNonArray stores all of the necessary fields for type_specifier_nonarray from the
// This is a workaround for a problem with the yacc stack, It can't have // grammar
// types that it thinks have non-trivial constructors. It should struct TTypeSpecifierNonArray
// just be used while recognizing the grammar, not anything else. Pointers
// could be used, but also trying to avoid lots of memory management overhead.
//
// Not as bad as it looks, there is no actual assumption that the fields
// match up or are name the same or anything like that.
//
struct TPublicType
{ {
TBasicType type; TBasicType type;
TLayoutQualifier layoutQualifier;
TQualifier qualifier;
bool invariant;
TPrecision precision;
unsigned char primarySize; // size of vector or cols of matrix unsigned char primarySize; // size of vector or cols of matrix
unsigned char secondarySize; // rows of matrix unsigned char secondarySize; // rows of matrix
bool array;
int arraySize;
TType *userDef; TType *userDef;
TSourceLoc line; TSourceLoc line;
// true if the type was defined by a struct specifier rather than a reference to a type name. // true if the type was defined by a struct specifier rather than a reference to a type name.
bool isStructSpecifier; bool isStructSpecifier;
void setBasic(TBasicType bt, TQualifier q, const TSourceLoc &ln) void initialize(TBasicType bt, const TSourceLoc &ln)
{ {
type = bt; type = bt;
layoutQualifier = TLayoutQualifier::create();
qualifier = q;
invariant = false;
precision = EbpUndefined;
primarySize = 1; primarySize = 1;
secondarySize = 1; secondarySize = 1;
array = false; userDef = nullptr;
arraySize = 0;
userDef = 0;
line = ln; line = ln;
isStructSpecifier = false; isStructSpecifier = false;
} }
...@@ -641,78 +622,99 @@ struct TPublicType ...@@ -641,78 +622,99 @@ struct TPublicType
primarySize = size; primarySize = size;
} }
void setMatrix(unsigned char c, unsigned char r) void setMatrix(unsigned char columns, unsigned char rows)
{ {
ASSERT(c > 1 && r > 1 && c <= 4 && r <= 4); ASSERT(columns > 1 && rows > 1 && columns <= 4 && rows <= 4);
primarySize = c; primarySize = columns;
secondarySize = r; secondarySize = rows;
} }
bool isUnsizedArray() const bool isMatrix() const { return primarySize > 1 && secondarySize > 1; }
{
return array && arraySize == 0; bool isVector() const { return primarySize > 1 && secondarySize == 1; }
} };
void setArraySize(int s)
//
// This is a workaround for a problem with the yacc stack, It can't have
// types that it thinks have non-trivial constructors. It should
// just be used while recognizing the grammar, not anything else. Pointers
// could be used, but also trying to avoid lots of memory management overhead.
//
// Not as bad as it looks, there is no actual assumption that the fields
// match up or are name the same or anything like that.
//
struct TPublicType
{
TTypeSpecifierNonArray typeSpecifierNonArray;
TLayoutQualifier layoutQualifier;
TQualifier qualifier;
bool invariant;
TPrecision precision;
bool array;
int arraySize;
void initialize(const TTypeSpecifierNonArray &typeSpecifier, TQualifier q)
{ {
array = true; typeSpecifierNonArray = typeSpecifier;
arraySize = s; layoutQualifier = TLayoutQualifier::create();
qualifier = q;
invariant = false;
precision = EbpUndefined;
array = false;
arraySize = 0;
} }
void clearArrayness()
TBasicType getBasicType() const { return typeSpecifierNonArray.type; }
void setBasicType(TBasicType basicType) { typeSpecifierNonArray.type = basicType; }
unsigned char getPrimarySize() const { return typeSpecifierNonArray.primarySize; }
unsigned char getSecondarySize() const { return typeSpecifierNonArray.secondarySize; }
void initializeSizeForScalarTypes()
{ {
array = false; typeSpecifierNonArray.primarySize = 1;
arraySize = 0; typeSpecifierNonArray.secondarySize = 1;
} }
const TType *getUserDef() const { return typeSpecifierNonArray.userDef; }
const TSourceLoc &getLine() const { return typeSpecifierNonArray.line; }
bool isStructSpecifier() const { return typeSpecifierNonArray.isStructSpecifier; }
bool isStructureContainingArrays() const bool isStructureContainingArrays() const
{ {
if (!userDef) if (!typeSpecifierNonArray.userDef)
{ {
return false; return false;
} }
return userDef->isStructureContainingArrays(); return typeSpecifierNonArray.userDef->isStructureContainingArrays();
} }
bool isStructureContainingType(TBasicType t) const bool isStructureContainingType(TBasicType t) const
{ {
if (!userDef) if (!typeSpecifierNonArray.userDef)
{ {
return false; return false;
} }
return userDef->isStructureContainingType(t); return typeSpecifierNonArray.userDef->isStructureContainingType(t);
}
bool isMatrix() const
{
return primarySize > 1 && secondarySize > 1;
}
bool isVector() const
{
return primarySize > 1 && secondarySize == 1;
}
int getCols() const
{
ASSERT(isMatrix());
return primarySize;
} }
int getRows() const bool isUnsizedArray() const { return array && arraySize == 0; }
void setArraySize(int s)
{ {
ASSERT(isMatrix()); array = true;
return secondarySize; arraySize = s;
} }
void clearArrayness()
int getNominalSize() const
{ {
return primarySize; array = false;
arraySize = 0;
} }
bool isAggregate() const bool isAggregate() const
{ {
return array || isMatrix() || isVector(); return array || typeSpecifierNonArray.isMatrix() || typeSpecifierNonArray.isVector();
} }
}; };
......
...@@ -208,6 +208,7 @@ union YYSTYPE ...@@ -208,6 +208,7 @@ union YYSTYPE
TIntermCase* intermCase; TIntermCase* intermCase;
}; };
union { union {
TTypeSpecifierNonArray typeSpecifierNonArray;
TPublicType type; TPublicType type;
TPrecision precision; TPrecision precision;
TLayoutQualifier layoutQualifier; TLayoutQualifier layoutQualifier;
......
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