@@ -1496,9 +1496,9 @@ static bool isObjCMethodResultAudited(const clang::Decl *decl) {
1496
1496
decl->hasAttr <clang::ObjCReturnsInnerPointerAttr>());
1497
1497
}
1498
1498
1499
- // / Determine whether this is the name of an Objective-C collection
1500
- // / with a single element type.
1501
- static bool isObjCCollectionName (StringRef typeName) {
1499
+ // / Determine whether this is the name of a collection with a single
1500
+ // / element type.
1501
+ static bool isCollectionName (StringRef typeName) {
1502
1502
auto lastWord = camel_case::getLastWord (typeName);
1503
1503
return lastWord == " Array" || lastWord == " Set" ;
1504
1504
}
@@ -1555,12 +1555,31 @@ OmissionTypeName ClangImporter::Implementation::getClangTypeNameForOmission(
1555
1555
if (name == " NSInteger" || name == " NSUInteger" || name == " CGFloat" )
1556
1556
return name;
1557
1557
1558
+ // If it's a collection name and of pointer type, call it an
1559
+ // array of the pointee type.
1560
+ if (isCollectionName (name)) {
1561
+ if (auto ptrType = type->getAs <clang::PointerType>()) {
1562
+ return OmissionTypeName (
1563
+ name, None,
1564
+ getClangTypeNameForOmission (ctx, ptrType->getPointeeType ())
1565
+ .Name );
1566
+ }
1567
+ }
1568
+
1558
1569
// Otherwise, desugar one level...
1559
1570
lastTypedefName = name;
1560
1571
type = typedefType->getDecl ()->getUnderlyingType ();
1561
1572
continue ;
1562
1573
}
1563
1574
1575
+ // For array types, convert the element type and treat this an as array.
1576
+ if (auto arrayType = dyn_cast<clang::ArrayType>(typePtr)) {
1577
+ return OmissionTypeName (
1578
+ " Array" , None,
1579
+ getClangTypeNameForOmission (ctx, arrayType->getElementType ())
1580
+ .Name );
1581
+ }
1582
+
1564
1583
// Look through reference types.
1565
1584
if (auto refType = dyn_cast<clang::ReferenceType>(typePtr)) {
1566
1585
type = refType->getPointeeTypeAsWritten ();
@@ -1594,9 +1613,18 @@ OmissionTypeName ClangImporter::Implementation::getClangTypeNameForOmission(
1594
1613
if (objcClass) {
1595
1614
// If this isn't the name of an Objective-C collection, we're done.
1596
1615
auto className = objcClass->getName ();
1597
- if (!isObjCCollectionName (className))
1616
+ if (!isCollectionName (className))
1598
1617
return className;
1599
1618
1619
+ // If we don't have type parameters, use the prefix of the type
1620
+ // name as the collection element type.
1621
+ if (objcClass && !objcClass->getTypeParamList ()) {
1622
+ unsigned lastWordSize = camel_case::getLastWord (className).size ();
1623
+ StringRef elementName =
1624
+ className.substr (0 , className.size () - lastWordSize);
1625
+ return OmissionTypeName (className, None, elementName);
1626
+ }
1627
+
1600
1628
// If we don't have type arguments, the collection element type
1601
1629
// is "Object".
1602
1630
auto typeArgs = objcObjectPtr->getTypeArgs ();
@@ -1803,7 +1831,8 @@ bool ClangImporter::Implementation::omitNeedlessWordsInFunctionName(
1803
1831
SwiftContext.getIdentifier (baseName), numParams,
1804
1832
argumentName, isLastParameter) != DefaultArgumentKind::None;
1805
1833
1806
- paramTypes.push_back (getClangTypeNameForOmission (clangCtx, param->getType ())
1834
+ paramTypes.push_back (getClangTypeNameForOmission (clangCtx,
1835
+ param->getOriginalType ())
1807
1836
.withDefaultArgument (hasDefaultArg));
1808
1837
}
1809
1838
0 commit comments