Use addArrayDimension instead of manually creating array type.

Just noticed one more spot in the code where an array type was being
hand-assembled.

Change-Id: I3c9d931caee3dc8e03b3eb016af5fa0a36064d57
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/340660
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2020-12-03 14:38:12 -05:00 committed by Skia Commit-Bot
parent a217950930
commit e766cb8c1d

View File

@ -2457,7 +2457,7 @@ std::unique_ptr<Expression> IRGenerator::convertPrefixExpression(const ASTNode&
std::unique_ptr<Expression> IRGenerator::convertIndex(std::unique_ptr<Expression> base,
const ASTNode& index) {
if (base->kind() == Expression::Kind::kTypeReference) {
if (base->is<TypeReference>()) {
if (index.fKind == ASTNode::Kind::kInt) {
const Type* type = &base->as<TypeReference>().value();
type = fSymbolTable->addArrayDimension(type, index.getInt());
@ -2753,11 +2753,11 @@ std::unique_ptr<Expression> IRGenerator::convertIndexExpression(const ASTNode& i
}
if (iter != index.end()) {
return this->convertIndex(std::move(base), *(iter++));
} else if (base->kind() == Expression::Kind::kTypeReference) {
const Type& oldType = base->as<TypeReference>().value();
const Type* newType = fSymbolTable->takeOwnershipOfSymbol(std::make_unique<Type>(
oldType.name() + "[]", Type::TypeKind::kArray, oldType, Type::kUnsizedArray));
return std::make_unique<TypeReference>(fContext, base->fOffset, newType);
}
if (base->is<TypeReference>()) {
const Type* type = &base->as<TypeReference>().value();
type = fSymbolTable->addArrayDimension(type, Type::kUnsizedArray);
return std::make_unique<TypeReference>(fContext, base->fOffset, type);
}
fErrors.error(index.fOffset, "'[]' must follow a type name");
return nullptr;