Refactor array element type checks
Remove checks that would never fail, and refactor the functions into
more self-contained checks. For example, it doesn't make sense to
check the qualifier from the part of the type that doesn't contain the
qualifier.
This prepares for adding the parsing of arrays of arrays.
BUG=angleproject:2125
TEST=angle_unittests
Change-Id: I1144bee35d2b04c7cb22e2bb7e17307298e35f8c
Reviewed-on: https://chromium-review.googlesource.com/629016
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/translator/ParseContext.cpp b/src/compiler/translator/ParseContext.cpp
index f422f04..a1c12f3 100644
--- a/src/compiler/translator/ParseContext.cpp
+++ b/src/compiler/translator/ParseContext.cpp
@@ -968,40 +968,42 @@
}
// See if this element type can be formed into an array.
-bool TParseContext::checkIsValidTypeForArray(const TSourceLoc &line, const TPublicType &elementType)
+bool TParseContext::checkArrayElementIsNotArray(const TSourceLoc &line,
+ const TPublicType &elementType)
{
- //
- // Can the type be an array?
- //
if (elementType.array)
{
error(line, "cannot declare arrays of arrays",
TType(elementType).getCompleteString().c_str());
return false;
}
+ return true;
+}
+
+// Check if this qualified element type can be formed into an array. This is only called when array
+// brackets are associated with an identifier in a declaration, like this:
+// float a[2];
+// Similar checks are done in addFullySpecifiedType for array declarations where the array brackets
+// are associated with the type, like this:
+// float[2] a;
+bool TParseContext::checkIsValidTypeAndQualifierForArray(const TSourceLoc &indexLocation,
+ const TPublicType &elementType)
+{
+ if (!checkArrayElementIsNotArray(indexLocation, elementType))
+ {
+ return false;
+ }
// In ESSL1.00 shaders, structs cannot be varying (section 4.3.5). This is checked elsewhere.
// In ESSL3.00 shaders, struct inputs/outputs are allowed but not arrays of structs (section
// 4.3.4).
if (mShaderVersion >= 300 && elementType.getBasicType() == EbtStruct &&
sh::IsVarying(elementType.qualifier))
{
- error(line, "cannot declare arrays of structs of this qualifier",
+ error(indexLocation, "cannot declare arrays of structs of this qualifier",
TType(elementType).getCompleteString().c_str());
return false;
}
-
- return true;
-}
-
-// Check if this qualified element type can be formed into an array.
-bool TParseContext::checkIsValidTypeAndQualifierForArray(const TSourceLoc &indexLocation,
- const TPublicType &elementType)
-{
- if (checkIsValidTypeForArray(indexLocation, elementType))
- {
- return checkIsValidQualifierForArray(indexLocation, elementType);
- }
- return false;
+ return checkIsValidQualifierForArray(indexLocation, elementType);
}
// Enforce non-initializer type/qualifier rules.
@@ -3345,7 +3347,7 @@
const TSourceLoc &arrayLoc,
TPublicType *type)
{
- checkIsValidTypeForArray(arrayLoc, *type);
+ checkArrayElementIsNotArray(arrayLoc, *type);
unsigned int size = checkIsValidArraySize(arrayLoc, arraySize);
type->setArraySize(size);
return parseParameterDeclarator(*type, identifier, identifierLoc);
@@ -4528,7 +4530,7 @@
// don't allow arrays of arrays
if (!declaratorArraySizes.empty())
{
- checkIsValidTypeForArray(typeSpecifier.getLine(), typeSpecifier);
+ checkArrayElementIsNotArray(typeSpecifier.getLine(), typeSpecifier);
}
TType *type = (*declaratorList)[i]->type();