34
34
#include " clang/AST/Decl.h"
35
35
#include " clang/AST/DeclObjC.h"
36
36
#include " clang/AST/TypeVisitor.h"
37
- #include " llvm/ADT/SmallBitVector.h"
38
37
#include " llvm/ADT/SmallString.h"
39
38
#include " llvm/ADT/StringExtras.h"
40
39
@@ -1246,9 +1245,9 @@ Type ClangImporter::Implementation::importPropertyType(
1246
1245
1247
1246
// / Get a bit vector indicating which arguments are non-null for a
1248
1247
// / given function or method.
1249
- static llvm::SmallBitVector getNonNullArgs (
1250
- const clang::Decl *decl,
1251
- ArrayRef<const clang::ParmVarDecl *> params) {
1248
+ llvm::SmallBitVector ClangImporter::Implementation:: getNonNullArgs (
1249
+ const clang::Decl *decl,
1250
+ ArrayRef<const clang::ParmVarDecl *> params) {
1252
1251
llvm::SmallBitVector result;
1253
1252
if (!decl)
1254
1253
return result;
@@ -1705,27 +1704,18 @@ OmissionTypeName ClangImporter::Implementation::getClangTypeNameForOmission(
1705
1704
}
1706
1705
1707
1706
// / Attempt to omit needless words from the given function name.
1708
- DeclName ClangImporter::Implementation::omitNeedlessWordsInFunctionName (
1709
- DeclName name,
1710
- ArrayRef<const clang::ParmVarDecl *> params,
1711
- clang::QualType resultType,
1712
- const clang::DeclContext *dc,
1713
- const llvm::SmallBitVector &nonNullArgs,
1714
- const Optional<api_notes::ObjCMethodInfo> &knownMethod,
1715
- Optional<unsigned > errorParamIndex,
1716
- bool returnsSelf,
1717
- bool isInstanceMethod) {
1718
- ASTContext &ctx = SwiftContext;
1719
-
1720
- // Collect the argument names.
1721
- SmallVector<StringRef, 4 > argNames;
1722
- for (auto arg : name.getArgumentNames ()) {
1723
- if (arg.empty ())
1724
- argNames.push_back (" " );
1725
- else
1726
- argNames.push_back (arg.str ());
1727
- }
1728
-
1707
+ bool ClangImporter::Implementation::omitNeedlessWordsInFunctionName (
1708
+ StringRef &baseName,
1709
+ SmallVectorImpl<StringRef> &argumentNames,
1710
+ ArrayRef<const clang::ParmVarDecl *> params,
1711
+ clang::QualType resultType,
1712
+ const clang::DeclContext *dc,
1713
+ const llvm::SmallBitVector &nonNullArgs,
1714
+ const Optional<api_notes::ObjCMethodInfo> &knownMethod,
1715
+ Optional<unsigned > errorParamIndex,
1716
+ bool returnsSelf,
1717
+ bool isInstanceMethod,
1718
+ StringScratchSpace &scratch) {
1729
1719
// Collect the parameter type names.
1730
1720
StringRef firstParamName;
1731
1721
SmallVector<OmissionTypeName, 4 > paramTypes;
@@ -1752,21 +1742,17 @@ DeclName ClangImporter::Implementation::omitNeedlessWordsInFunctionName(
1752
1742
param->getType (),
1753
1743
getParamOptionality (param,
1754
1744
!nonNullArgs.empty () && nonNullArgs[i],
1755
- knownMethod
1745
+ knownMethod && knownMethod-> NullabilityAudited
1756
1746
? Optional<clang::NullabilityKind>(
1757
1747
knownMethod->getParamTypeInfo (i))
1758
1748
: None),
1759
- name. getBaseName ( ), numParams,
1749
+ SwiftContext. getIdentifier (baseName ), numParams,
1760
1750
isLastParameter);
1761
1751
1762
1752
paramTypes.push_back (getClangTypeNameForOmission (param->getType ())
1763
1753
.withDefaultArgument (hasDefaultArg));
1764
1754
}
1765
1755
1766
- // Omit needless words.
1767
- StringRef baseName = name.getBaseName ().str ();
1768
- StringScratchSpace scratch;
1769
-
1770
1756
// Find the property names.
1771
1757
const InheritedNameSet *allPropertyNames = nullptr ;
1772
1758
auto contextType = getClangDeclContextType (dc);
@@ -1777,35 +1763,12 @@ DeclName ClangImporter::Implementation::omitNeedlessWordsInFunctionName(
1777
1763
isInstanceMethod);
1778
1764
}
1779
1765
1780
- if (!omitNeedlessWords (baseName, argNames, firstParamName,
1781
- getClangTypeNameForOmission (resultType),
1782
- getClangTypeNameForOmission (contextType),
1783
- paramTypes, returnsSelf, /* isProperty=*/ false ,
1784
- allPropertyNames, scratch))
1785
- return name;
1786
-
1787
- // / Retrieve a replacement identifier.
1788
- auto getReplacementIdentifier = [&](StringRef name,
1789
- Identifier old) -> Identifier{
1790
- if (name.empty ())
1791
- return Identifier ();
1792
-
1793
- if (!old.empty () && name == old.str ())
1794
- return old;
1795
-
1796
- return ctx.getIdentifier (name);
1797
- };
1798
-
1799
- Identifier newBaseName = getReplacementIdentifier (baseName,
1800
- name.getBaseName ());
1801
- SmallVector<Identifier, 4 > newArgNames;
1802
- auto oldArgNames = name.getArgumentNames ();
1803
- for (unsigned i = 0 , n = argNames.size (); i != n; ++i) {
1804
- newArgNames.push_back (getReplacementIdentifier (argNames[i],
1805
- oldArgNames[i]));
1806
- }
1807
-
1808
- return DeclName (ctx, newBaseName, newArgNames);
1766
+ // Omit needless words.
1767
+ return omitNeedlessWords (baseName, argumentNames, firstParamName,
1768
+ getClangTypeNameForOmission (resultType),
1769
+ getClangTypeNameForOmission (contextType),
1770
+ paramTypes, returnsSelf, /* isProperty=*/ false ,
1771
+ allPropertyNames, scratch);
1809
1772
}
1810
1773
1811
1774
// / Retrieve the instance type of the given Clang declaration context.
@@ -2035,20 +1998,6 @@ Type ClangImporter::Implementation::importMethodType(
2035
1998
2036
1999
llvm::SmallBitVector nonNullArgs = getNonNullArgs (clangDecl, params);
2037
2000
2038
- // If we should omit needless words and don't have a custom name, do so.
2039
- if (OmitNeedlessWords && !importedName.HasCustomName && clangDecl &&
2040
- (kind == SpecialMethodKind::Regular ||
2041
- kind == SpecialMethodKind::Constructor)) {
2042
- methodName = omitNeedlessWordsInFunctionName (
2043
- methodName, params, resultType,
2044
- clangDecl->getDeclContext (),
2045
- nonNullArgs,
2046
- knownMethod,
2047
- errorInfo ? Optional<unsigned >(errorInfo->ParamIndex ) : None,
2048
- clangDecl->hasRelatedResultType (),
2049
- clangDecl->isInstanceMethod ());
2050
- }
2051
-
2052
2001
// Import the parameters.
2053
2002
SmallVector<TupleTypeElt, 4 > swiftArgParams;
2054
2003
SmallVector<TupleTypeElt, 4 > swiftBodyParams;
0 commit comments