Commit 6ed7bbe8 by Olli Etuaho

Clean up arrayErrorCheck

Remove some unnecessary TPublicType/TType conversions from the code, and clean up code style. voidErrorCheck is changed to take TBasicType so that it can be used with both TType and TPublicType. TEST=angle_unittests BUG=angleproject:941 Change-Id: I6f6cbc0761a4fc971299bad48864309009c54e7f Reviewed-on: https://chromium-review.googlesource.com/264673Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com>
parent 43ce600c
...@@ -568,12 +568,13 @@ bool TParseContext::constructorErrorCheck(const TSourceLoc& line, TIntermNode* n ...@@ -568,12 +568,13 @@ bool TParseContext::constructorErrorCheck(const TSourceLoc& line, TIntermNode* n
// //
// returns true in case of an error // returns true in case of an error
// //
bool TParseContext::voidErrorCheck(const TSourceLoc& line, const TString& identifier, const TPublicType& pubType) bool TParseContext::voidErrorCheck(const TSourceLoc &line, const TString &identifier, const TBasicType &type)
{ {
if (pubType.type == EbtVoid) { if (type == EbtVoid)
{
error(line, "illegal use of type 'void'", identifier.c_str()); error(line, "illegal use of type 'void'", identifier.c_str());
return true; return true;
} }
return false; return false;
} }
...@@ -784,25 +785,31 @@ bool TParseContext::arrayTypeErrorCheck(const TSourceLoc& line, TPublicType type ...@@ -784,25 +785,31 @@ bool TParseContext::arrayTypeErrorCheck(const TSourceLoc& line, TPublicType type
// Do all the semantic checking for declaring an array, // Do all the semantic checking for declaring an array,
// and make the right changes to the symbol table. // and make the right changes to the symbol table.
// //
// size == 0 means no specified size.
//
// Returns true if there was an error. // Returns true if there was an error.
// //
bool TParseContext::arrayErrorCheck(const TSourceLoc& line, const TString& identifier, const TPublicType &type, TVariable*& variable) bool TParseContext::arrayErrorCheck(const TSourceLoc &line, const TString &identifier, const TType &type,
TVariable **variable)
{ {
bool builtIn = false;
bool sameScope = false; bool sameScope = false;
TSymbol* symbol = symbolTable.find(identifier, 0, &builtIn, &sameScope); TSymbol *symbol = symbolTable.find(identifier, 0, nullptr, &sameScope);
if (symbol == 0 || !sameScope) { if (symbol == 0 || !sameScope)
{
bool needsReservedErrorCheck = true; bool needsReservedErrorCheck = true;
// gl_LastFragData may be redeclared with a new precision qualifier // gl_LastFragData may be redeclared with a new precision qualifier
if (identifier.compare(0, 15, "gl_LastFragData") == 0) { if (identifier.compare(0, 15, "gl_LastFragData") == 0)
if (type.arraySize == static_cast<const TVariable*>(symbolTable.findBuiltIn("gl_MaxDrawBuffers", shaderVersion))->getConstPointer()->getIConst()) { {
if (TSymbol* builtInSymbol = symbolTable.findBuiltIn(identifier, shaderVersion)) { const TVariable *maxDrawBuffers =
static_cast<const TVariable *>(symbolTable.findBuiltIn("gl_MaxDrawBuffers", shaderVersion));
if (type.getArraySize() == maxDrawBuffers->getConstPointer()->getIConst())
{
if (TSymbol *builtInSymbol = symbolTable.findBuiltIn(identifier, shaderVersion))
{
needsReservedErrorCheck = extensionErrorCheck(line, builtInSymbol->getExtension()); needsReservedErrorCheck = extensionErrorCheck(line, builtInSymbol->getExtension());
} }
} else { }
else
{
error(line, "redeclaration of array with size != gl_MaxDrawBuffers", identifier.c_str()); error(line, "redeclaration of array with size != gl_MaxDrawBuffers", identifier.c_str());
return true; return true;
} }
...@@ -812,13 +819,11 @@ bool TParseContext::arrayErrorCheck(const TSourceLoc& line, const TString& ident ...@@ -812,13 +819,11 @@ bool TParseContext::arrayErrorCheck(const TSourceLoc& line, const TString& ident
if (reservedErrorCheck(line, identifier)) if (reservedErrorCheck(line, identifier))
return true; return true;
variable = new TVariable(&identifier, TType(type)); (*variable) = new TVariable(&identifier, type);
if (type.arraySize)
variable->getType().setArraySize(type.arraySize);
if (! symbolTable.declare(variable)) { if (!symbolTable.declare(*variable))
delete variable; {
delete (*variable);
error(line, "INTERNAL ERROR inserting new symbol", identifier.c_str()); error(line, "INTERNAL ERROR inserting new symbol", identifier.c_str());
return true; return true;
} }
...@@ -829,7 +834,7 @@ bool TParseContext::arrayErrorCheck(const TSourceLoc& line, const TString& ident ...@@ -829,7 +834,7 @@ bool TParseContext::arrayErrorCheck(const TSourceLoc& line, const TString& ident
return true; return true;
} }
if (voidErrorCheck(line, identifier, type)) if (voidErrorCheck(line, identifier, type.getBasicType()))
return true; return true;
return false; return false;
...@@ -884,7 +889,7 @@ bool TParseContext::nonInitErrorCheck(const TSourceLoc& line, const TString& ide ...@@ -884,7 +889,7 @@ bool TParseContext::nonInitErrorCheck(const TSourceLoc& line, const TString& ide
return true; return true;
} }
if (voidErrorCheck(line, identifier, type)) if (voidErrorCheck(line, identifier, type.type))
return true; return true;
return false; return false;
...@@ -1113,7 +1118,7 @@ bool TParseContext::executeInitializer(const TSourceLoc& line, const TString& id ...@@ -1113,7 +1118,7 @@ bool TParseContext::executeInitializer(const TSourceLoc& line, const TString& id
if (reservedErrorCheck(line, identifier)) if (reservedErrorCheck(line, identifier))
return true; return true;
if (voidErrorCheck(line, identifier, pType)) if (voidErrorCheck(line, identifier, pType.type))
return true; return true;
// //
...@@ -1313,7 +1318,7 @@ TIntermAggregate* TParseContext::parseSingleArrayDeclaration(TPublicType &public ...@@ -1313,7 +1318,7 @@ TIntermAggregate* TParseContext::parseSingleArrayDeclaration(TPublicType &public
recover(); recover();
} }
TPublicType arrayType = publicType; TType arrayType(publicType);
int size; int size;
if (arraySizeErrorCheck(identifierLocation, indexExpression, size)) if (arraySizeErrorCheck(identifierLocation, indexExpression, size))
...@@ -1325,11 +1330,11 @@ TIntermAggregate* TParseContext::parseSingleArrayDeclaration(TPublicType &public ...@@ -1325,11 +1330,11 @@ TIntermAggregate* TParseContext::parseSingleArrayDeclaration(TPublicType &public
arrayType.setArraySize(size); arrayType.setArraySize(size);
} }
TIntermSymbol* symbol = intermediate.addSymbol(0, identifier, TType(arrayType), identifierLocation); TIntermSymbol *symbol = intermediate.addSymbol(0, identifier, arrayType, identifierLocation);
TIntermAggregate* aggregate = intermediate.makeAggregate(symbol, identifierLocation); TIntermAggregate* aggregate = intermediate.makeAggregate(symbol, identifierLocation);
TVariable* variable = 0; TVariable* variable = 0;
if (arrayErrorCheck(identifierLocation, identifier, arrayType, variable)) if (arrayErrorCheck(identifierLocation, identifier, arrayType, &variable))
recover(); recover();
if (variable && symbol) if (variable && symbol)
...@@ -1442,18 +1447,21 @@ TIntermAggregate* TParseContext::parseArrayDeclarator(TPublicType &publicType, c ...@@ -1442,18 +1447,21 @@ TIntermAggregate* TParseContext::parseArrayDeclarator(TPublicType &publicType, c
int size; int size;
if (arraySizeErrorCheck(arrayLocation, indexExpression, size)) if (arraySizeErrorCheck(arrayLocation, indexExpression, size))
recover(); recover();
TPublicType arrayType(publicType); TType arrayType = TType(publicType);
arrayType.setArraySize(size); arrayType.setArraySize(size);
TVariable* variable = NULL; TVariable *variable = nullptr;
if (arrayErrorCheck(arrayLocation, identifier, arrayType, variable)) if (arrayErrorCheck(arrayLocation, identifier, arrayType, &variable))
recover(); recover();
TType type = TType(arrayType);
type.setArraySize(size);
return intermediate.growAggregate(declaratorList, intermediate.addSymbol(variable ? variable->getUniqueId() : 0, identifier, type, identifierLocation), identifierLocation); TIntermSymbol *symbol = intermediate.addSymbol(0, identifier, arrayType, identifierLocation);
if (variable && symbol)
{
symbol->setId(variable->getUniqueId());
}
return intermediate.growAggregate(declaratorList, symbol, identifierLocation);
} }
return NULL; return nullptr;
} }
TIntermAggregate* TParseContext::parseInitDeclarator(TPublicType &publicType, TIntermAggregate *declaratorList, const TSourceLoc& identifierLocation, const TString &identifier, const TSourceLoc& initLocation, TIntermTyped *initializer) TIntermAggregate* TParseContext::parseInitDeclarator(TPublicType &publicType, TIntermAggregate *declaratorList, const TSourceLoc& identifierLocation, const TString &identifier, const TSourceLoc& initLocation, TIntermTyped *initializer)
...@@ -2513,7 +2521,8 @@ TPublicType TParseContext::joinInterpolationQualifiers(const TSourceLoc &interpo ...@@ -2513,7 +2521,8 @@ TPublicType TParseContext::joinInterpolationQualifiers(const TSourceLoc &interpo
TFieldList *TParseContext::addStructDeclaratorList(const TPublicType& typeSpecifier, TFieldList *fieldList) TFieldList *TParseContext::addStructDeclaratorList(const TPublicType& typeSpecifier, TFieldList *fieldList)
{ {
if (voidErrorCheck(typeSpecifier.line, (*fieldList)[0]->name(), typeSpecifier)) { if (voidErrorCheck(typeSpecifier.line, (*fieldList)[0]->name(), typeSpecifier.type))
{
recover(); recover();
} }
......
...@@ -97,8 +97,8 @@ struct TParseContext { ...@@ -97,8 +97,8 @@ struct TParseContext {
bool arraySizeErrorCheck(const TSourceLoc& line, TIntermTyped* expr, int& size); bool arraySizeErrorCheck(const TSourceLoc& line, TIntermTyped* expr, int& size);
bool arrayQualifierErrorCheck(const TSourceLoc &line, const TPublicType &type); bool arrayQualifierErrorCheck(const TSourceLoc &line, const TPublicType &type);
bool arrayTypeErrorCheck(const TSourceLoc& line, TPublicType type); bool arrayTypeErrorCheck(const TSourceLoc& line, TPublicType type);
bool arrayErrorCheck(const TSourceLoc& line, const TString& identifier, const TPublicType &type, TVariable*& variable); bool arrayErrorCheck(const TSourceLoc &line, const TString &identifier, const TType &type, TVariable **variable);
bool voidErrorCheck(const TSourceLoc&, const TString&, const TPublicType&); bool voidErrorCheck(const TSourceLoc &line, const TString &identifier, const TBasicType &type);
bool boolErrorCheck(const TSourceLoc&, const TIntermTyped*); bool boolErrorCheck(const TSourceLoc&, const TIntermTyped*);
bool boolErrorCheck(const TSourceLoc&, const TPublicType&); bool boolErrorCheck(const TSourceLoc&, const TPublicType&);
bool samplerErrorCheck(const TSourceLoc& line, const TPublicType& pType, const char* reason); bool samplerErrorCheck(const TSourceLoc& line, const TPublicType& pType, const char* reason);
......
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