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)
symbolTable.push(); // ESSL3_1_BUILTINS
TPublicType integer;
integer.type = EbtInt;
integer.primarySize = 1;
integer.secondarySize = 1;
integer.setBasicType(EbtInt);
integer.initializeSizeForScalarTypes();
integer.array = false;
TPublicType floatingPoint;
floatingPoint.type = EbtFloat;
floatingPoint.primarySize = 1;
floatingPoint.secondarySize = 1;
floatingPoint.setBasicType(EbtFloat);
floatingPoint.initializeSizeForScalarTypes();
floatingPoint.array = false;
switch(shaderType)
......@@ -493,10 +491,9 @@ void TCompiler::initSamplerDefaultPrecision(TBasicType samplerType)
{
ASSERT(samplerType > EbtGuardSamplerBegin && samplerType < EbtGuardSamplerEnd);
TPublicType sampler;
sampler.primarySize = 1;
sampler.secondarySize = 1;
sampler.initializeSizeForScalarTypes();
sampler.setBasicType(samplerType);
sampler.array = false;
sampler.type = samplerType;
symbolTable.setDefaultPrecision(sampler, EbpLow);
}
......
......@@ -160,7 +160,9 @@ class TParseContext : angle::NonCopyable
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 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 checkLocationIsNotSpecified(const TSourceLoc &location,
const TLayoutQualifier &layoutQualifier);
......@@ -298,10 +300,10 @@ class TParseContext : angle::NonCopyable
TPublicType *typeSpecifier,
TFieldList *fieldList);
TFieldList *addStructDeclaratorList(const TPublicType &typeSpecifier, TFieldList *fieldList);
TPublicType addStructure(const TSourceLoc &structLine,
const TSourceLoc &nameLine,
const TString *structName,
TFieldList *fieldList);
TTypeSpecifierNonArray addStructure(const TSourceLoc &structLine,
const TSourceLoc &nameLine,
const TString *structName,
TFieldList *fieldList);
TIntermAggregate *addInterfaceBlock(const TTypeQualifierBuilder &typeQualifierBuilder,
const TSourceLoc &nameLine,
......
......@@ -471,15 +471,15 @@ class TSymbolTable : angle::NonCopyable
bool setDefaultPrecision(const TPublicType &type, TPrecision prec)
{
if (!SupportsPrecision(type.type))
if (!SupportsPrecision(type.getBasicType()))
return false;
if (type.type == EbtUInt)
if (type.getBasicType() == EbtUInt)
return false; // ESSL 3.00.4 section 4.5.4
if (type.isAggregate())
return false; // Not allowed to set for aggregate types
int indexOfLastElement = static_cast<int>(precisionStack.size()) - 1;
// Uses map operator [], overwrites the current value
(*precisionStack[indexOfLastElement])[type.type] = prec;
(*precisionStack[indexOfLastElement])[type.getBasicType()] = prec;
return true;
}
......
......@@ -48,12 +48,20 @@ const char* getBasicString(TBasicType t)
}
TType::TType(const TPublicType &p)
: type(p.type), precision(p.precision), qualifier(p.qualifier), invariant(p.invariant),
layoutQualifier(p.layoutQualifier), primarySize(p.primarySize), secondarySize(p.secondarySize),
array(p.array), arraySize(p.arraySize), interfaceBlock(0), structure(0)
: type(p.getBasicType()),
precision(p.precision),
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)
structure = p.userDef->getStruct();
if (p.getUserDef())
structure = p.getUserDef()->getStruct();
}
bool TStructure::equals(const TStructure &other) const
......
......@@ -594,44 +594,25 @@ class TType
mutable TString mangled;
};
//
// 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 stores all of the necessary fields for type_specifier_nonarray from the
// grammar
struct TTypeSpecifierNonArray
{
TBasicType type;
TLayoutQualifier layoutQualifier;
TQualifier qualifier;
bool invariant;
TPrecision precision;
unsigned char primarySize; // size of vector or cols of matrix
unsigned char secondarySize; // rows of matrix
bool array;
int arraySize;
TType *userDef;
TSourceLoc line;
// true if the type was defined by a struct specifier rather than a reference to a type name.
bool isStructSpecifier;
void setBasic(TBasicType bt, TQualifier q, const TSourceLoc &ln)
void initialize(TBasicType bt, const TSourceLoc &ln)
{
type = bt;
layoutQualifier = TLayoutQualifier::create();
qualifier = q;
invariant = false;
precision = EbpUndefined;
primarySize = 1;
secondarySize = 1;
array = false;
arraySize = 0;
userDef = 0;
userDef = nullptr;
line = ln;
isStructSpecifier = false;
}
......@@ -641,78 +622,99 @@ struct TPublicType
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);
primarySize = c;
secondarySize = r;
ASSERT(columns > 1 && rows > 1 && columns <= 4 && rows <= 4);
primarySize = columns;
secondarySize = rows;
}
bool isUnsizedArray() const
{
return array && arraySize == 0;
}
void setArraySize(int s)
bool isMatrix() const { return primarySize > 1 && secondarySize > 1; }
bool isVector() const { return primarySize > 1 && secondarySize == 1; }
};
//
// 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;
arraySize = s;
typeSpecifierNonArray = typeSpecifier;
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;
arraySize = 0;
typeSpecifierNonArray.primarySize = 1;
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
{
if (!userDef)
if (!typeSpecifierNonArray.userDef)
{
return false;
}
return userDef->isStructureContainingArrays();
return typeSpecifierNonArray.userDef->isStructureContainingArrays();
}
bool isStructureContainingType(TBasicType t) const
{
if (!userDef)
if (!typeSpecifierNonArray.userDef)
{
return false;
}
return 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;
return typeSpecifierNonArray.userDef->isStructureContainingType(t);
}
int getRows() const
bool isUnsizedArray() const { return array && arraySize == 0; }
void setArraySize(int s)
{
ASSERT(isMatrix());
return secondarySize;
array = true;
arraySize = s;
}
int getNominalSize() const
void clearArrayness()
{
return primarySize;
array = false;
arraySize = 0;
}
bool isAggregate() const
{
return array || isMatrix() || isVector();
return array || typeSpecifierNonArray.isMatrix() || typeSpecifierNonArray.isVector();
}
};
......
......@@ -208,6 +208,7 @@ union YYSTYPE
TIntermCase* intermCase;
};
union {
TTypeSpecifierNonArray typeSpecifierNonArray;
TPublicType type;
TPrecision precision;
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