Improve error checking for unsized arrays.

Added support for resolving dimensions of multi-dimensional unsized arrays
from their initializer exprerssions (previously, only the first dimension
would be resolved.)

Added checks to make sure that no unsized array dimensions remain after
doing this (except for the first dimensision of array parameters to
functions.)
This commit is contained in:
Matt Pharr
2011-11-21 09:16:29 -08:00
parent 068ea3e4c4
commit d3e6879223
13 changed files with 140 additions and 29 deletions

View File

@@ -272,11 +272,24 @@ Declarator::GetType(const Type *base, DeclSpecs *ds) const {
}
}
// Arrays are passed by reference, so convert array
// parameters to be references here.
if (dynamic_cast<const ArrayType *>(sym->type) != NULL)
const ArrayType *at = dynamic_cast<const ArrayType *>(sym->type);
if (at != NULL) {
// Arrays are passed by reference, so convert array
// parameters to be references here.
sym->type = new ReferenceType(sym->type, sym->type->IsConstType());
// Make sure there are no unsized arrays (other than the
// first dimension) in function parameter lists.
at = dynamic_cast<const ArrayType *>(at->GetElementType());
while (at != NULL) {
if (at->GetElementCount() == 0)
Error(sym->pos, "Arrays with unsized dimensions in "
"dimensions after the first one are illegal in "
"function parameter lists.");
at = dynamic_cast<const ArrayType *>(at->GetElementType());
}
}
args.push_back(sym->type);
argNames.push_back(sym->name);
argPos.push_back(sym->pos);