|
@@ -1123,57 +1123,56 @@ QualType QualType::substObjCTypeArgs(
|
|
|
// Replace an Objective-C type parameter reference with the corresponding
|
|
|
// type argument.
|
|
|
if (const auto *OTPTy = dyn_cast<ObjCTypeParamType>(splitType.Ty)) {
|
|
|
- if (auto *typeParam = dyn_cast<ObjCTypeParamDecl>(OTPTy->getDecl())) {
|
|
|
- // If we have type arguments, use them.
|
|
|
- if (!typeArgs.empty()) {
|
|
|
- QualType argType = typeArgs[typeParam->getIndex()];
|
|
|
- if (OTPTy->qual_empty())
|
|
|
- return ctx.getQualifiedType(argType, splitType.Quals);
|
|
|
-
|
|
|
- // Apply protocol lists if exists.
|
|
|
- bool hasError;
|
|
|
- SmallVector<ObjCProtocolDecl*, 8> protocolsVec;
|
|
|
- protocolsVec.append(OTPTy->qual_begin(),
|
|
|
- OTPTy->qual_end());
|
|
|
- ArrayRef<ObjCProtocolDecl *> protocolsToApply = protocolsVec;
|
|
|
- QualType resultTy = ctx.applyObjCProtocolQualifiers(argType,
|
|
|
- protocolsToApply, hasError, true/*allowOnPointerType*/);
|
|
|
-
|
|
|
- return ctx.getQualifiedType(resultTy, splitType.Quals);
|
|
|
- }
|
|
|
+ ObjCTypeParamDecl *typeParam = OTPTy->getDecl();
|
|
|
+ // If we have type arguments, use them.
|
|
|
+ if (!typeArgs.empty()) {
|
|
|
+ QualType argType = typeArgs[typeParam->getIndex()];
|
|
|
+ if (OTPTy->qual_empty())
|
|
|
+ return ctx.getQualifiedType(argType, splitType.Quals);
|
|
|
+
|
|
|
+ // Apply protocol lists if exists.
|
|
|
+ bool hasError;
|
|
|
+ SmallVector<ObjCProtocolDecl*, 8> protocolsVec;
|
|
|
+ protocolsVec.append(OTPTy->qual_begin(),
|
|
|
+ OTPTy->qual_end());
|
|
|
+ ArrayRef<ObjCProtocolDecl *> protocolsToApply = protocolsVec;
|
|
|
+ QualType resultTy = ctx.applyObjCProtocolQualifiers(argType,
|
|
|
+ protocolsToApply, hasError, true/*allowOnPointerType*/);
|
|
|
+
|
|
|
+ return ctx.getQualifiedType(resultTy, splitType.Quals);
|
|
|
+ }
|
|
|
|
|
|
- switch (context) {
|
|
|
- case ObjCSubstitutionContext::Ordinary:
|
|
|
- case ObjCSubstitutionContext::Parameter:
|
|
|
- case ObjCSubstitutionContext::Superclass:
|
|
|
- // Substitute the bound.
|
|
|
+ switch (context) {
|
|
|
+ case ObjCSubstitutionContext::Ordinary:
|
|
|
+ case ObjCSubstitutionContext::Parameter:
|
|
|
+ case ObjCSubstitutionContext::Superclass:
|
|
|
+ // Substitute the bound.
|
|
|
+ return ctx.getQualifiedType(typeParam->getUnderlyingType(),
|
|
|
+ splitType.Quals);
|
|
|
+
|
|
|
+ case ObjCSubstitutionContext::Result:
|
|
|
+ case ObjCSubstitutionContext::Property: {
|
|
|
+ // Substitute the __kindof form of the underlying type.
|
|
|
+ const auto *objPtr = typeParam->getUnderlyingType()
|
|
|
+ ->castAs<ObjCObjectPointerType>();
|
|
|
+
|
|
|
+ // __kindof types, id, and Class don't need an additional
|
|
|
+ // __kindof.
|
|
|
+ if (objPtr->isKindOfType() || objPtr->isObjCIdOrClassType())
|
|
|
return ctx.getQualifiedType(typeParam->getUnderlyingType(),
|
|
|
splitType.Quals);
|
|
|
|
|
|
- case ObjCSubstitutionContext::Result:
|
|
|
- case ObjCSubstitutionContext::Property: {
|
|
|
- // Substitute the __kindof form of the underlying type.
|
|
|
- const auto *objPtr = typeParam->getUnderlyingType()
|
|
|
- ->castAs<ObjCObjectPointerType>();
|
|
|
-
|
|
|
- // __kindof types, id, and Class don't need an additional
|
|
|
- // __kindof.
|
|
|
- if (objPtr->isKindOfType() || objPtr->isObjCIdOrClassType())
|
|
|
- return ctx.getQualifiedType(typeParam->getUnderlyingType(),
|
|
|
- splitType.Quals);
|
|
|
-
|
|
|
- // Add __kindof.
|
|
|
- const auto *obj = objPtr->getObjectType();
|
|
|
- QualType resultTy = ctx.getObjCObjectType(obj->getBaseType(),
|
|
|
- obj->getTypeArgsAsWritten(),
|
|
|
- obj->getProtocols(),
|
|
|
- /*isKindOf=*/true);
|
|
|
-
|
|
|
- // Rebuild object pointer type.
|
|
|
- resultTy = ctx.getObjCObjectPointerType(resultTy);
|
|
|
- return ctx.getQualifiedType(resultTy, splitType.Quals);
|
|
|
- }
|
|
|
- }
|
|
|
+ // Add __kindof.
|
|
|
+ const auto *obj = objPtr->getObjectType();
|
|
|
+ QualType resultTy = ctx.getObjCObjectType(obj->getBaseType(),
|
|
|
+ obj->getTypeArgsAsWritten(),
|
|
|
+ obj->getProtocols(),
|
|
|
+ /*isKindOf=*/true);
|
|
|
+
|
|
|
+ // Rebuild object pointer type.
|
|
|
+ resultTy = ctx.getObjCObjectPointerType(resultTy);
|
|
|
+ return ctx.getQualifiedType(resultTy, splitType.Quals);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1593,7 +1592,7 @@ CXXRecordDecl *Type::getAsCXXRecordDecl() const {
|
|
|
|
|
|
TagDecl *Type::getAsTagDecl() const {
|
|
|
if (const auto *TT = getAs<TagType>())
|
|
|
- return cast<TagDecl>(TT->getDecl());
|
|
|
+ return TT->getDecl();
|
|
|
if (const auto *Injected = getAs<InjectedClassNameType>())
|
|
|
return Injected->getDecl();
|
|
|
|