Commit 856c497e by Olli Etuaho Committed by Commit Bot

Clarify error checking function names in the GLSL parser

Most error checking functions in ParseContext used to follow a format like <property>ErrorCheck. Sometimes this function would check that the node/value would have <property>, sometimes it would check that the node/value would not have it, which was confusing. Change most of these functions to use a lot more descriptive names, which clearly communicate what they are checking for. Also includes a bit of refactoring in constructorErrorCheck(), so that the function only checks for errors rather than also setting the type of the constructor node. Also make TType::arraySize unsigned, and return a sanitized size from checkIsValidArraySize() instead of using an output parameter. BUG=angleproject:911 TEST=angle_unittests Change-Id: Id9767b8c79594ad3f782f801ea68eb96df721a31 Reviewed-on: https://chromium-review.googlesource.com/367070Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 9371f7ab
...@@ -153,7 +153,7 @@ class TIntermTyped : public TIntermNode ...@@ -153,7 +153,7 @@ class TIntermTyped : public TIntermNode
const char *getBasicString() const { return mType.getBasicString(); } const char *getBasicString() const { return mType.getBasicString(); }
TString getCompleteString() const { return mType.getCompleteString(); } TString getCompleteString() const { return mType.getCompleteString(); }
int getArraySize() const { return mType.getArraySize(); } unsigned int getArraySize() const { return mType.getArraySize(); }
bool isConstructorWithOnlyConstantUnionParameters(); bool isConstructorWithOnlyConstantUnionParameters();
......
...@@ -357,7 +357,7 @@ bool TOutputGLSLBase::visitBinary(Visit visit, TIntermBinary *node) ...@@ -357,7 +357,7 @@ bool TOutputGLSLBase::visitBinary(Visit visit, TIntermBinary *node)
if (left->isArray()) if (left->isArray())
{ {
// The shader will fail validation if the array length is not > 0. // The shader will fail validation if the array length is not > 0.
maxSize = leftType.getArraySize() - 1; maxSize = static_cast<int>(leftType.getArraySize()) - 1;
} }
else else
{ {
......
...@@ -224,7 +224,7 @@ const std::map<std::string, unsigned int> &OutputHLSL::getUniformRegisterMap() c ...@@ -224,7 +224,7 @@ const std::map<std::string, unsigned int> &OutputHLSL::getUniformRegisterMap() c
int OutputHLSL::vectorSize(const TType &type) const int OutputHLSL::vectorSize(const TType &type) const
{ {
int elementSize = type.isMatrix() ? type.getCols() : 1; int elementSize = type.isMatrix() ? type.getCols() : 1;
int arraySize = type.isArray() ? type.getArraySize() : 1; unsigned int arraySize = type.isArray() ? type.getArraySize() : 1u;
return elementSize * arraySize; return elementSize * arraySize;
} }
...@@ -1711,7 +1711,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1711,7 +1711,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
TVector<TIntermSymbol *> samplerSymbols; TVector<TIntermSymbol *> samplerSymbols;
TString structName = samplerNamePrefixFromStruct(typedArg); TString structName = samplerNamePrefixFromStruct(typedArg);
argType.createSamplerSymbols("angle_" + structName, "", argType.createSamplerSymbols("angle_" + structName, "",
argType.isArray() ? argType.getArraySize() : 0, argType.isArray() ? argType.getArraySize() : 0u,
&samplerSymbols, nullptr); &samplerSymbols, nullptr);
for (const TIntermSymbol *sampler : samplerSymbols) for (const TIntermSymbol *sampler : samplerSymbols)
{ {
...@@ -2502,7 +2502,7 @@ TString OutputHLSL::argumentString(const TIntermSymbol *symbol) ...@@ -2502,7 +2502,7 @@ TString OutputHLSL::argumentString(const TIntermSymbol *symbol)
{ {
ASSERT(qualifier != EvqOut && qualifier != EvqInOut); ASSERT(qualifier != EvqOut && qualifier != EvqInOut);
TVector<TIntermSymbol *> samplerSymbols; TVector<TIntermSymbol *> samplerSymbols;
type.createSamplerSymbols("angle" + nameStr, "", 0, &samplerSymbols, nullptr); type.createSamplerSymbols("angle" + nameStr, "", 0u, &samplerSymbols, nullptr);
for (const TIntermSymbol *sampler : samplerSymbols) for (const TIntermSymbol *sampler : samplerSymbols)
{ {
if (mOutputType == SH_HLSL_4_1_OUTPUT) if (mOutputType == SH_HLSL_4_1_OUTPUT)
...@@ -2870,14 +2870,14 @@ TString OutputHLSL::addArrayConstructIntoFunction(const TType& type) ...@@ -2870,14 +2870,14 @@ TString OutputHLSL::addArrayConstructIntoFunction(const TType& type)
fnOut << "void " << function.functionName << "(out " fnOut << "void " << function.functionName << "(out "
<< typeName << " a[" << type.getArraySize() << "]"; << typeName << " a[" << type.getArraySize() << "]";
for (int i = 0; i < type.getArraySize(); ++i) for (unsigned int i = 0u; i < type.getArraySize(); ++i)
{ {
fnOut << ", " << typeName << " b" << i; fnOut << ", " << typeName << " b" << i;
} }
fnOut << ")\n" fnOut << ")\n"
"{\n"; "{\n";
for (int i = 0; i < type.getArraySize(); ++i) for (unsigned int i = 0u; i < type.getArraySize(); ++i)
{ {
fnOut << " a[" << i << "] = b" << i << ";\n"; fnOut << " a[" << i << "] = b" << i << ";\n";
} }
......
...@@ -126,50 +126,55 @@ class TParseContext : angle::NonCopyable ...@@ -126,50 +126,55 @@ class TParseContext : angle::NonCopyable
bool parseVectorFields(const TString&, int vecSize, TVectorFields&, const TSourceLoc &line); bool parseVectorFields(const TString&, int vecSize, TVectorFields&, const TSourceLoc &line);
bool reservedErrorCheck(const TSourceLoc &line, const TString &identifier);
void assignError(const TSourceLoc &line, const char *op, TString left, TString right); void assignError(const TSourceLoc &line, const char *op, TString left, TString right);
void unaryOpError(const TSourceLoc &line, const char *op, TString operand); void unaryOpError(const TSourceLoc &line, const char *op, TString operand);
void binaryOpError(const TSourceLoc &line, const char *op, TString left, TString right); void binaryOpError(const TSourceLoc &line, const char *op, TString left, TString right);
void precisionErrorCheck(const TSourceLoc &line, TPrecision precision, TBasicType type);
bool lValueErrorCheck(const TSourceLoc &line, const char *op, TIntermTyped*); bool checkIsNotReserved(const TSourceLoc &line, const TString &identifier);
void constErrorCheck(TIntermTyped *node); void checkPrecisionSpecified(const TSourceLoc &line, TPrecision precision, TBasicType type);
void integerErrorCheck(TIntermTyped *node, const char *token); bool checkCanBeLValue(const TSourceLoc &line, const char *op, TIntermTyped *node);
void globalErrorCheck(const TSourceLoc &line, bool global, const char *token); void checkIsConst(TIntermTyped *node);
bool constructorErrorCheck(const TSourceLoc &line, void checkIsScalarInteger(TIntermTyped *node, const char *token);
TIntermNode *argumentsNode, void checkIsAtGlobalLevel(const TSourceLoc &line, const char *token);
TFunction &function, bool checkConstructorArguments(const TSourceLoc &line,
TOperator op, TIntermNode *argumentsNode,
TType *type); const TFunction &function,
void arraySizeErrorCheck(const TSourceLoc &line, TIntermTyped *expr, int &size); TOperator op,
bool arrayQualifierErrorCheck(const TSourceLoc &line, const TPublicType &type); const TType &type);
bool arrayTypeErrorCheck(const TSourceLoc &line, const TPublicType &type);
bool voidErrorCheck(const TSourceLoc &line, const TString &identifier, const TBasicType &type); // Returns a sanitized array size to use (the size is at least 1).
void boolErrorCheck(const TSourceLoc &, const TIntermTyped *); unsigned int checkIsValidArraySize(const TSourceLoc &line, TIntermTyped *expr);
void boolErrorCheck(const TSourceLoc &, const TPublicType &); bool checkIsValidQualifierForArray(const TSourceLoc &line, const TPublicType &type);
bool samplerErrorCheck(const TSourceLoc &line, const TPublicType &pType, const char *reason); bool checkIsValidTypeForArray(const TSourceLoc &line, const TPublicType &type);
void locationDeclaratorListCheck(const TSourceLoc &line, const TPublicType &pType); bool checkIsNonVoid(const TSourceLoc &line, const TString &identifier, const TBasicType &type);
void parameterSamplerErrorCheck(const TSourceLoc &line, void checkIsScalarBool(const TSourceLoc &line, const TIntermTyped *type);
TQualifier qualifier, void checkIsScalarBool(const TSourceLoc &line, const TPublicType &pType);
const TType &type); bool checkIsNotSampler(const TSourceLoc &line, const TPublicType &pType, const char *reason);
void paramErrorCheck(const TSourceLoc &line, void checkDeclaratorLocationIsNotSpecified(const TSourceLoc &line, const TPublicType &pType);
TQualifier qualifier, void checkLocationIsNotSpecified(const TSourceLoc &location,
TQualifier paramQualifier, const TLayoutQualifier &layoutQualifier);
TType *type); void checkOutParameterIsNotSampler(const TSourceLoc &line,
bool extensionErrorCheck(const TSourceLoc &line, const TString&); TQualifier qualifier,
const TType &type);
void checkIsParameterQualifierValid(const TSourceLoc &line,
TQualifier qualifier,
TQualifier paramQualifier,
TType *type);
bool checkCanUseExtension(const TSourceLoc &line, const TString &extension);
void singleDeclarationErrorCheck(const TPublicType &publicType, void singleDeclarationErrorCheck(const TPublicType &publicType,
const TSourceLoc &identifierLocation); const TSourceLoc &identifierLocation);
void layoutLocationErrorCheck(const TSourceLoc &location, void checkLayoutQualifierSupported(const TSourceLoc &location,
const TLayoutQualifier &layoutQualifier); const TString &layoutQualifierName,
void layoutSupportedErrorCheck(const TSourceLoc &location, int versionRequired);
const TString &layoutQualifierName, bool checkWorkGroupSizeIsNotSpecified(const TSourceLoc &location,
int versionRequired); const TLayoutQualifier &layoutQualifier);
bool layoutWorkGroupSizeErrorCheck(const TSourceLoc &location,
const TLayoutQualifier &layoutQualifier); void functionCallLValueErrorCheck(const TFunction *fnCandidate, TIntermAggregate *fnCall);
void functionCallLValueErrorCheck(const TFunction *fnCandidate, TIntermAggregate *); void checkInvariantIsOutVariableES3(const TQualifier qualifier,
void es3InvariantErrorCheck(const TQualifier qualifier, const TSourceLoc &invariantLocation); const TSourceLoc &invariantLocation);
void es3InputOutputTypeCheck(const TQualifier qualifier, void checkInputOutputTypeIsValidES3(const TQualifier qualifier,
const TPublicType &type, const TPublicType &type,
const TSourceLoc &qualifierLocation); const TSourceLoc &qualifierLocation);
const TPragma &pragma() const { return mDirectiveHandler.pragma(); } const TPragma &pragma() const { return mDirectiveHandler.pragma(); }
const TExtensionBehavior &extensionBehavior() const { return mDirectiveHandler.extensionBehavior(); } const TExtensionBehavior &extensionBehavior() const { return mDirectiveHandler.extensionBehavior(); }
...@@ -265,7 +270,6 @@ class TParseContext : angle::NonCopyable ...@@ -265,7 +270,6 @@ class TParseContext : angle::NonCopyable
const TSourceLoc &location); const TSourceLoc &location);
TFunction *addConstructorFunc(const TPublicType &publicType); TFunction *addConstructorFunc(const TPublicType &publicType);
TIntermTyped *addConstructor(TIntermNode *arguments, TIntermTyped *addConstructor(TIntermNode *arguments,
TType *type,
TOperator op, TOperator op,
TFunction *fnCall, TFunction *fnCall,
const TSourceLoc &line); const TSourceLoc &line);
...@@ -375,7 +379,9 @@ class TParseContext : angle::NonCopyable ...@@ -375,7 +379,9 @@ class TParseContext : angle::NonCopyable
bool declareVariable(const TSourceLoc &line, const TString &identifier, const TType &type, TVariable **variable); bool declareVariable(const TSourceLoc &line, const TString &identifier, const TType &type, TVariable **variable);
void nonInitErrorCheck(const TSourceLoc &line, const TString &identifier, TPublicType *type); void checkCanBeDeclaredWithoutInitializer(const TSourceLoc &line,
const TString &identifier,
TPublicType *type);
TIntermTyped *addBinaryMathInternal( TIntermTyped *addBinaryMathInternal(
TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc); TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
......
...@@ -318,7 +318,6 @@ size_t TType::getObjectSize() const ...@@ -318,7 +318,6 @@ size_t TType::getObjectSize() const
if (isArray()) if (isArray())
{ {
// TODO: getArraySize() returns an int, not a size_t
size_t currentArraySize = getArraySize(); size_t currentArraySize = getArraySize();
if (currentArraySize > INT_MAX / totalSize) if (currentArraySize > INT_MAX / totalSize)
totalSize = INT_MAX; totalSize = INT_MAX;
...@@ -364,7 +363,7 @@ bool TStructure::containsSamplers() const ...@@ -364,7 +363,7 @@ bool TStructure::containsSamplers() const
void TStructure::createSamplerSymbols(const TString &structName, void TStructure::createSamplerSymbols(const TString &structName,
const TString &structAPIName, const TString &structAPIName,
const int arrayOfStructsSize, const unsigned int arrayOfStructsSize,
TVector<TIntermSymbol *> *outputSymbols, TVector<TIntermSymbol *> *outputSymbols,
TMap<TIntermSymbol *, TString> *outputSymbolsToAPINames) const TMap<TIntermSymbol *, TString> *outputSymbolsToAPINames) const
{ {
...@@ -373,9 +372,9 @@ void TStructure::createSamplerSymbols(const TString &structName, ...@@ -373,9 +372,9 @@ void TStructure::createSamplerSymbols(const TString &structName,
const TType *fieldType = field->type(); const TType *fieldType = field->type();
if (IsSampler(fieldType->getBasicType())) if (IsSampler(fieldType->getBasicType()))
{ {
if (arrayOfStructsSize > 0) if (arrayOfStructsSize > 0u)
{ {
for (int arrayIndex = 0; arrayIndex < arrayOfStructsSize; ++arrayIndex) for (unsigned int arrayIndex = 0u; arrayIndex < arrayOfStructsSize; ++arrayIndex)
{ {
TStringStream name; TStringStream name;
name << structName << "_" << arrayIndex << "_" << field->name(); name << structName << "_" << arrayIndex << "_" << field->name();
...@@ -405,10 +404,11 @@ void TStructure::createSamplerSymbols(const TString &structName, ...@@ -405,10 +404,11 @@ void TStructure::createSamplerSymbols(const TString &structName,
} }
else if (fieldType->isStructureContainingSamplers()) else if (fieldType->isStructureContainingSamplers())
{ {
int nestedArrayOfStructsSize = fieldType->isArray() ? fieldType->getArraySize() : 0; unsigned int nestedArrayOfStructsSize =
fieldType->isArray() ? fieldType->getArraySize() : 0u;
if (arrayOfStructsSize > 0) if (arrayOfStructsSize > 0)
{ {
for (int arrayIndex = 0; arrayIndex < arrayOfStructsSize; ++arrayIndex) for (unsigned int arrayIndex = 0u; arrayIndex < arrayOfStructsSize; ++arrayIndex)
{ {
TStringStream fieldName; TStringStream fieldName;
fieldName << structName << "_" << arrayIndex << "_" << field->name(); fieldName << structName << "_" << arrayIndex << "_" << field->name();
......
...@@ -123,7 +123,7 @@ class TStructure : public TFieldListCollection ...@@ -123,7 +123,7 @@ class TStructure : public TFieldListCollection
void createSamplerSymbols(const TString &structName, void createSamplerSymbols(const TString &structName,
const TString &structAPIName, const TString &structAPIName,
const int arrayOfStructsSize, const unsigned int arrayOfStructsSize,
TVector<TIntermSymbol *> *outputSymbols, TVector<TIntermSymbol *> *outputSymbols,
TMap<TIntermSymbol *, TString> *outputSymbolsToAPINames) const; TMap<TIntermSymbol *, TString> *outputSymbolsToAPINames) const;
...@@ -387,13 +387,10 @@ class TType ...@@ -387,13 +387,10 @@ class TType
} }
bool isUnsizedArray() const bool isUnsizedArray() const
{ {
return array && arraySize == 0; return array && arraySize == 0u;
} }
int getArraySize() const unsigned int getArraySize() const { return arraySize; }
{ void setArraySize(unsigned int s)
return arraySize;
}
void setArraySize(int s)
{ {
if (!array || arraySize != s) if (!array || arraySize != s)
{ {
...@@ -407,7 +404,7 @@ class TType ...@@ -407,7 +404,7 @@ class TType
if (array) if (array)
{ {
array = false; array = false;
arraySize = 0; arraySize = 0u;
invalidateMangledName(); invalidateMangledName();
} }
} }
...@@ -556,7 +553,7 @@ class TType ...@@ -556,7 +553,7 @@ class TType
void createSamplerSymbols(const TString &structName, void createSamplerSymbols(const TString &structName,
const TString &structAPIName, const TString &structAPIName,
const int arrayOfStructsSize, const unsigned int arrayOfStructsSize,
TVector<TIntermSymbol *> *outputSymbols, TVector<TIntermSymbol *> *outputSymbols,
TMap<TIntermSymbol *, TString> *outputSymbolsToAPINames) const TMap<TIntermSymbol *, TString> *outputSymbolsToAPINames) const
{ {
...@@ -584,7 +581,7 @@ class TType ...@@ -584,7 +581,7 @@ class TType
unsigned char primarySize; // size of vector or cols matrix unsigned char primarySize; // size of vector or cols matrix
unsigned char secondarySize; // rows of a matrix unsigned char secondarySize; // rows of a matrix
bool array; bool array;
int arraySize; unsigned int arraySize;
// 0 unless this is an interface block, or interface block member variable // 0 unless this is an interface block, or interface block member variable
TInterfaceBlock *interfaceBlock; TInterfaceBlock *interfaceBlock;
......
...@@ -128,7 +128,7 @@ unsigned int UniformHLSL::assignSamplerInStructUniformRegister(const TType &type ...@@ -128,7 +128,7 @@ unsigned int UniformHLSL::assignSamplerInStructUniformRegister(const TType &type
ASSERT(IsSampler(type.getBasicType())); ASSERT(IsSampler(type.getBasicType()));
unsigned int registerIndex = mSamplerRegister; unsigned int registerIndex = mSamplerRegister;
mUniformRegisterMap[std::string(name.c_str())] = registerIndex; mUniformRegisterMap[std::string(name.c_str())] = registerIndex;
unsigned int registerCount = type.isArray() ? type.getArraySize() : 1; unsigned int registerCount = type.isArray() ? type.getArraySize() : 1u;
mSamplerRegister += registerCount; mSamplerRegister += registerCount;
if (outRegisterCount) if (outRegisterCount)
{ {
...@@ -175,9 +175,9 @@ void UniformHLSL::outputHLSLSamplerUniformGroup( ...@@ -175,9 +175,9 @@ void UniformHLSL::outputHLSLSamplerUniformGroup(
{ {
out << "static const uint " << DecorateIfNeeded(uniform->getName()) << ArrayString(type) out << "static const uint " << DecorateIfNeeded(uniform->getName()) << ArrayString(type)
<< " = {"; << " = {";
for (int i = 0; i < type.getArraySize(); ++i) for (unsigned int i = 0u; i < type.getArraySize(); ++i)
{ {
if (i > 0) if (i > 0u)
out << ", "; out << ", ";
out << (samplerArrayIndex + i); out << (samplerArrayIndex + i);
} }
...@@ -281,7 +281,7 @@ void UniformHLSL::uniformsHeader(TInfoSinkBase &out, ...@@ -281,7 +281,7 @@ void UniformHLSL::uniformsHeader(TInfoSinkBase &out,
{ {
TVector<TIntermSymbol *> samplerSymbols; TVector<TIntermSymbol *> samplerSymbols;
TMap<TIntermSymbol *, TString> symbolsToAPINames; TMap<TIntermSymbol *, TString> symbolsToAPINames;
int arrayOfStructsSize = type.isArray() ? type.getArraySize() : 0; unsigned int arrayOfStructsSize = type.isArray() ? type.getArraySize() : 0u;
type.createSamplerSymbols("angle_" + name.getString(), name.getString(), type.createSamplerSymbols("angle_" + name.getString(), name.getString(),
arrayOfStructsSize, &samplerSymbols, &symbolsToAPINames); arrayOfStructsSize, &samplerSymbols, &symbolsToAPINames);
for (TIntermSymbol *sampler : samplerSymbols) for (TIntermSymbol *sampler : samplerSymbols)
......
...@@ -60,7 +60,7 @@ int ValidateOutputs::validateAndCountErrors(TInfoSinkBase &sink) const ...@@ -60,7 +60,7 @@ int ValidateOutputs::validateAndCountErrors(TInfoSinkBase &sink) const
for (const auto &symbol : mOutputs) for (const auto &symbol : mOutputs)
{ {
const TType &type = symbol->getType(); const TType &type = symbol->getType();
const size_t elementCount = static_cast<size_t>(type.isArray() ? type.getArraySize() : 1); const size_t elementCount = static_cast<size_t>(type.isArray() ? type.getArraySize() : 1u);
const size_t location = static_cast<size_t>(type.getLayoutQualifier().location); const size_t location = static_cast<size_t>(type.getLayoutQualifier().location);
ASSERT(type.getLayoutQualifier().location != -1); ASSERT(type.getLayoutQualifier().location != -1);
......
...@@ -477,7 +477,7 @@ void CollectVariables::visitVariable(const TIntermSymbol *variable, ...@@ -477,7 +477,7 @@ void CollectVariables::visitVariable(const TIntermSymbol *variable,
attribute.type = GLVariableType(type); attribute.type = GLVariableType(type);
attribute.precision = GLVariablePrecision(type); attribute.precision = GLVariablePrecision(type);
attribute.name = variable->getSymbol().c_str(); attribute.name = variable->getSymbol().c_str();
attribute.arraySize = static_cast<unsigned int>(type.getArraySize()); attribute.arraySize = type.getArraySize();
attribute.mappedName = TIntermTraverser::hash(variable->getSymbol(), mHashFunction).c_str(); attribute.mappedName = TIntermTraverser::hash(variable->getSymbol(), mHashFunction).c_str();
attribute.location = variable->getType().getLayoutQualifier().location; attribute.location = variable->getType().getLayoutQualifier().location;
...@@ -497,7 +497,7 @@ void CollectVariables::visitVariable(const TIntermSymbol *variable, ...@@ -497,7 +497,7 @@ void CollectVariables::visitVariable(const TIntermSymbol *variable,
attribute.type = GLVariableType(type); attribute.type = GLVariableType(type);
attribute.precision = GLVariablePrecision(type); attribute.precision = GLVariablePrecision(type);
attribute.name = variable->getSymbol().c_str(); attribute.name = variable->getSymbol().c_str();
attribute.arraySize = static_cast<unsigned int>(type.getArraySize()); attribute.arraySize = type.getArraySize();
attribute.mappedName = TIntermTraverser::hash(variable->getSymbol(), mHashFunction).c_str(); attribute.mappedName = TIntermTraverser::hash(variable->getSymbol(), mHashFunction).c_str();
attribute.location = variable->getType().getLayoutQualifier().location; attribute.location = variable->getType().getLayoutQualifier().location;
......
...@@ -290,7 +290,7 @@ postfix_expression ...@@ -290,7 +290,7 @@ postfix_expression
integer_expression integer_expression
: expression { : expression {
context->integerErrorCheck($1, "[]"); context->checkIsScalarInteger($1, "[]");
$$ = $1; $$ = $1;
} }
; ;
...@@ -369,13 +369,13 @@ function_identifier ...@@ -369,13 +369,13 @@ function_identifier
$$ = context->addConstructorFunc($1); $$ = context->addConstructorFunc($1);
} }
| IDENTIFIER { | IDENTIFIER {
context->reservedErrorCheck(@1, *$1.string); context->checkIsNotReserved(@1, *$1.string);
const TType *type = TCache::getType(EbtVoid, EbpUndefined); const TType *type = TCache::getType(EbtVoid, EbpUndefined);
TFunction *function = new TFunction($1.string, type); TFunction *function = new TFunction($1.string, type);
$$ = function; $$ = function;
} }
| FIELD_SELECTION { | FIELD_SELECTION {
context->reservedErrorCheck(@1, *$1.string); context->checkIsNotReserved(@1, *$1.string);
const TType *type = TCache::getType(EbtVoid, EbpUndefined); const TType *type = TCache::getType(EbtVoid, EbpUndefined);
TFunction *function = new TFunction($1.string, type); TFunction *function = new TFunction($1.string, type);
$$ = function; $$ = function;
...@@ -529,7 +529,7 @@ conditional_expression ...@@ -529,7 +529,7 @@ conditional_expression
assignment_expression assignment_expression
: conditional_expression { $$ = $1; } : conditional_expression { $$ = $1; }
| unary_expression assignment_operator assignment_expression { | unary_expression assignment_operator assignment_expression {
context->lValueErrorCheck(@2, "assign", $1); context->checkCanBeLValue(@2, "assign", $1);
$$ = context->addAssign($2.op, $1, $3, @2); $$ = context->addAssign($2.op, $1, $3, @2);
} }
; ;
...@@ -577,7 +577,7 @@ expression ...@@ -577,7 +577,7 @@ expression
constant_expression constant_expression
: conditional_expression { : conditional_expression {
context->constErrorCheck($1); context->checkIsConst($1);
$$ = $1; $$ = $1;
} }
; ;
...@@ -684,18 +684,17 @@ parameter_declarator ...@@ -684,18 +684,17 @@ parameter_declarator
if ($1.type == EbtVoid) { if ($1.type == EbtVoid) {
context->error(@2, "illegal use of type 'void'", $2.string->c_str()); context->error(@2, "illegal use of type 'void'", $2.string->c_str());
} }
context->reservedErrorCheck(@2, *$2.string); context->checkIsNotReserved(@2, *$2.string);
TParameter param = {$2.string, new TType($1)}; TParameter param = {$2.string, new TType($1)};
$$.param = param; $$.param = param;
} }
| type_specifier identifier LEFT_BRACKET constant_expression RIGHT_BRACKET { | type_specifier identifier LEFT_BRACKET constant_expression RIGHT_BRACKET {
// Check that we can make an array out of this type // Check that we can make an array out of this type
context->arrayTypeErrorCheck(@3, $1); context->checkIsValidTypeForArray(@3, $1);
context->reservedErrorCheck(@2, *$2.string); context->checkIsNotReserved(@2, *$2.string);
int size; unsigned int size = context->checkIsValidArraySize(@3, $4);
context->arraySizeErrorCheck(@3, $4, size);
$1.setArraySize(size); $1.setArraySize(size);
...@@ -716,24 +715,24 @@ parameter_declaration ...@@ -716,24 +715,24 @@ parameter_declaration
// //
: parameter_type_qualifier parameter_qualifier parameter_declarator { : parameter_type_qualifier parameter_qualifier parameter_declarator {
$$ = $3; $$ = $3;
context->paramErrorCheck(@3, $1, $2, $$.param.type); context->checkIsParameterQualifierValid(@3, $1, $2, $$.param.type);
} }
| parameter_qualifier parameter_declarator { | parameter_qualifier parameter_declarator {
$$ = $2; $$ = $2;
context->parameterSamplerErrorCheck(@2, $1, *$2.param.type); context->checkOutParameterIsNotSampler(@2, $1, *$2.param.type);
context->paramErrorCheck(@2, EvqTemporary, $1, $$.param.type); context->checkIsParameterQualifierValid(@2, EvqTemporary, $1, $$.param.type);
} }
// //
// Only type // Only type
// //
| parameter_type_qualifier parameter_qualifier parameter_type_specifier { | parameter_type_qualifier parameter_qualifier parameter_type_specifier {
$$ = $3; $$ = $3;
context->paramErrorCheck(@3, $1, $2, $$.param.type); context->checkIsParameterQualifierValid(@3, $1, $2, $$.param.type);
} }
| parameter_qualifier parameter_type_specifier { | parameter_qualifier parameter_type_specifier {
$$ = $2; $$ = $2;
context->parameterSamplerErrorCheck(@2, $1, *$2.param.type); context->checkOutParameterIsNotSampler(@2, $1, *$2.param.type);
context->paramErrorCheck(@2, EvqTemporary, $1, $$.param.type); context->checkIsParameterQualifierValid(@2, EvqTemporary, $1, $$.param.type);
} }
; ;
...@@ -855,12 +854,12 @@ type_qualifier ...@@ -855,12 +854,12 @@ type_qualifier
: ATTRIBUTE { : ATTRIBUTE {
VERTEX_ONLY("attribute", @1); VERTEX_ONLY("attribute", @1);
ES2_ONLY("attribute", @1); ES2_ONLY("attribute", @1);
context->globalErrorCheck(@1, context->symbolTable.atGlobalLevel(), "attribute"); context->checkIsAtGlobalLevel(@1, "attribute");
$$.setBasic(EbtVoid, EvqAttribute, @1); $$.setBasic(EbtVoid, EvqAttribute, @1);
} }
| VARYING { | VARYING {
ES2_ONLY("varying", @1); ES2_ONLY("varying", @1);
context->globalErrorCheck(@1, context->symbolTable.atGlobalLevel(), "varying"); context->checkIsAtGlobalLevel(@1, "varying");
if (context->getShaderType() == GL_VERTEX_SHADER) if (context->getShaderType() == GL_VERTEX_SHADER)
$$.setBasic(EbtVoid, EvqVaryingOut, @1); $$.setBasic(EbtVoid, EvqVaryingOut, @1);
else else
...@@ -868,7 +867,7 @@ type_qualifier ...@@ -868,7 +867,7 @@ type_qualifier
} }
| INVARIANT VARYING { | INVARIANT VARYING {
ES2_ONLY("varying", @1); ES2_ONLY("varying", @1);
context->globalErrorCheck(@1, context->symbolTable.atGlobalLevel(), "invariant varying"); context->checkIsAtGlobalLevel(@1, "invariant varying");
if (context->getShaderType() == GL_VERTEX_SHADER) if (context->getShaderType() == GL_VERTEX_SHADER)
$$.setBasic(EbtVoid, EvqVaryingOut, @1); $$.setBasic(EbtVoid, EvqVaryingOut, @1);
else else
...@@ -900,12 +899,12 @@ type_qualifier ...@@ -900,12 +899,12 @@ type_qualifier
$$.layoutQualifier = $1; $$.layoutQualifier = $1;
} }
| INVARIANT storage_qualifier { | INVARIANT storage_qualifier {
context->es3InvariantErrorCheck($2.qualifier, @1); context->checkInvariantIsOutVariableES3($2.qualifier, @1);
$$.setBasic(EbtVoid, $2.qualifier, @2); $$.setBasic(EbtVoid, $2.qualifier, @2);
$$.invariant = true; $$.invariant = true;
} }
| INVARIANT interpolation_qualifier storage_qualifier { | INVARIANT interpolation_qualifier storage_qualifier {
context->es3InvariantErrorCheck($3.qualifier, @1); context->checkInvariantIsOutVariableES3($3.qualifier, @1);
$$ = context->joinInterpolationQualifiers(@2, $2.qualifier, @3, $3.qualifier); $$ = context->joinInterpolationQualifiers(@2, $2.qualifier, @3, $3.qualifier);
$$.invariant = true; $$.invariant = true;
} }
...@@ -947,7 +946,7 @@ storage_qualifier ...@@ -947,7 +946,7 @@ storage_qualifier
$$.qualifier = EvqCentroidOut; $$.qualifier = EvqCentroidOut;
} }
| UNIFORM { | UNIFORM {
context->globalErrorCheck(@1, context->symbolTable.atGlobalLevel(), "uniform"); context->checkIsAtGlobalLevel(@1, "uniform");
$$.qualifier = EvqUniform; $$.qualifier = EvqUniform;
} }
; ;
...@@ -958,7 +957,7 @@ type_specifier ...@@ -958,7 +957,7 @@ type_specifier
if ($$.precision == EbpUndefined) { if ($$.precision == EbpUndefined) {
$$.precision = context->symbolTable.getDefaultPrecision($1.type); $$.precision = context->symbolTable.getDefaultPrecision($1.type);
context->precisionErrorCheck(@1, $$.precision, $1.type); context->checkPrecisionSpecified(@1, $$.precision, $1.type);
} }
} }
| precision_qualifier type_specifier_no_prec { | precision_qualifier type_specifier_no_prec {
...@@ -1023,10 +1022,9 @@ type_specifier_no_prec ...@@ -1023,10 +1022,9 @@ type_specifier_no_prec
| type_specifier_nonarray LEFT_BRACKET constant_expression RIGHT_BRACKET { | type_specifier_nonarray LEFT_BRACKET constant_expression RIGHT_BRACKET {
$$ = $1; $$ = $1;
if (!context->arrayTypeErrorCheck(@2, $1)) if (!context->checkIsValidTypeForArray(@2, $1))
{ {
int size; unsigned int size = context->checkIsValidArraySize(@2, $3);
context->arraySizeErrorCheck(@2, $3, size);
$$.setArraySize(size); $$.setArraySize(size);
} }
} }
...@@ -1300,17 +1298,16 @@ struct_declarator_list ...@@ -1300,17 +1298,16 @@ struct_declarator_list
struct_declarator struct_declarator
: identifier { : identifier {
context->reservedErrorCheck(@1, *$1.string); context->checkIsNotReserved(@1, *$1.string);
TType* type = new TType(EbtVoid, EbpUndefined); TType* type = new TType(EbtVoid, EbpUndefined);
$$ = new TField(type, $1.string, @1); $$ = new TField(type, $1.string, @1);
} }
| identifier LEFT_BRACKET constant_expression RIGHT_BRACKET { | identifier LEFT_BRACKET constant_expression RIGHT_BRACKET {
context->reservedErrorCheck(@1, *$1.string); context->checkIsNotReserved(@1, *$1.string);
TType* type = new TType(EbtVoid, EbpUndefined); TType* type = new TType(EbtVoid, EbpUndefined);
int size; unsigned int size = context->checkIsValidArraySize(@3, $3);
context->arraySizeErrorCheck(@3, $3, size);
type->setArraySize(size); type->setArraySize(size);
$$ = new TField(type, $1.string, @1); $$ = new TField(type, $1.string, @1);
...@@ -1393,7 +1390,7 @@ expression_statement ...@@ -1393,7 +1390,7 @@ expression_statement
selection_statement selection_statement
: IF LEFT_PAREN expression RIGHT_PAREN selection_rest_statement { : IF LEFT_PAREN expression RIGHT_PAREN selection_rest_statement {
context->boolErrorCheck(@1, $3); context->checkIsScalarBool(@1, $3);
$$ = context->intermediate.addSelection($3, $5, @1); $$ = context->intermediate.addSelection($3, $5, @1);
} }
; ;
...@@ -1429,11 +1426,11 @@ condition ...@@ -1429,11 +1426,11 @@ condition
// In 1996 c++ draft, conditions can include single declarations // In 1996 c++ draft, conditions can include single declarations
: expression { : expression {
$$ = $1; $$ = $1;
context->boolErrorCheck($1->getLine(), $1); context->checkIsScalarBool($1->getLine(), $1);
} }
| fully_specified_type identifier EQUAL initializer { | fully_specified_type identifier EQUAL initializer {
TIntermNode *intermNode; TIntermNode *intermNode;
context->boolErrorCheck(@2, $1); context->checkIsScalarBool(@2, $1);
if (!context->executeInitializer(@2, *$2.string, $1, $4, &intermNode)) if (!context->executeInitializer(@2, *$2.string, $1, $4, &intermNode))
$$ = $4; $$ = $4;
...@@ -1450,7 +1447,7 @@ iteration_statement ...@@ -1450,7 +1447,7 @@ iteration_statement
context->decrLoopNestingLevel(); context->decrLoopNestingLevel();
} }
| DO { context->incrLoopNestingLevel(); } statement_with_scope WHILE LEFT_PAREN expression RIGHT_PAREN SEMICOLON { | DO { context->incrLoopNestingLevel(); } statement_with_scope WHILE LEFT_PAREN expression RIGHT_PAREN SEMICOLON {
context->boolErrorCheck(@8, $6); context->checkIsScalarBool(@8, $6);
$$ = context->intermediate.addLoop(ELoopDoWhile, 0, $6, 0, $3, @4); $$ = context->intermediate.addLoop(ELoopDoWhile, 0, $6, 0, $3, @4);
context->decrLoopNestingLevel(); context->decrLoopNestingLevel();
......
...@@ -504,7 +504,7 @@ void GetVariableTraverser::traverse(const TType &type, ...@@ -504,7 +504,7 @@ void GetVariableTraverser::traverse(const TType &type,
VarT variable; VarT variable;
variable.name = name.c_str(); variable.name = name.c_str();
variable.arraySize = static_cast<unsigned int>(type.getArraySize()); variable.arraySize = type.getArraySize();
if (!structure) if (!structure)
{ {
......
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