29
29
#include " clang/AST/Attr.h"
30
30
#include " clang/AST/DeclObjC.h"
31
31
#include " clang/Analysis/DomainSpecific/CocoaConventions.h"
32
- #include " clang/Basic/CharInfo.h"
33
32
#include " llvm/Support/CommandLine.h"
34
33
#include " llvm/Support/Compiler.h"
35
34
#include " llvm/Support/Debug.h"
@@ -221,7 +220,7 @@ enum class ConventionsKind : uint8_t {
221
220
ObjCMethod = 2 ,
222
221
CFunctionType = 3 ,
223
222
CFunction = 4 ,
224
- SelectorFamily = 5 ,
223
+ ObjCSelectorFamily = 5 ,
225
224
Deallocator = 6 ,
226
225
Capture = 7 ,
227
226
};
@@ -1710,64 +1709,27 @@ static const clang::Decl *findClangMethod(ValueDecl *method) {
1710
1709
// Selector Family SILFunctionTypes
1711
1710
// ===----------------------------------------------------------------------===//
1712
1711
1713
- // / Apply a macro FAMILY(Name, Prefix) to all ObjC selector families.
1714
- #define FOREACH_FAMILY (FAMILY ) \
1715
- FAMILY (Alloc, " alloc" ) \
1716
- FAMILY(Copy, " copy" ) \
1717
- FAMILY(Init, " init" ) \
1718
- FAMILY(MutableCopy, " mutableCopy" ) \
1719
- FAMILY(New, " new" )
1720
-
1721
- namespace {
1722
- enum class SelectorFamily : unsigned {
1723
- None,
1724
- #define GET_LABEL (LABEL, PREFIX ) LABEL,
1725
- FOREACH_FAMILY (GET_LABEL)
1726
- #undef GET_LABEL
1727
- };
1728
- } // end anonymous namespace
1729
-
1730
1712
// / Derive the ObjC selector family from an identifier.
1731
1713
// /
1732
1714
// / Note that this will never derive the Init family, which is too dangerous
1733
1715
// / to leave to chance. Swift functions starting with "init" are always
1734
1716
// / emitted as if they are part of the "none" family.
1735
- static SelectorFamily getSelectorFamily (Identifier name) {
1736
- StringRef text = name.get ();
1737
- while (!text.empty () && text[0 ] == ' _' ) text = text.substr (1 );
1738
-
1739
- // Does the given selector start with the given string as a prefix, in the
1740
- // sense of the selector naming conventions?
1741
- // This implementation matches the one used by
1742
- // clang::Selector::getMethodFamily, to make sure we behave the same as Clang
1743
- // ARC. We're not just calling that method here because it means allocating a
1744
- // clang::IdentifierInfo, which requires a Clang ASTContext.
1745
- auto hasPrefix = [](StringRef text, StringRef prefix) {
1746
- if (!text.startswith (prefix)) return false ;
1747
- if (text.size () == prefix.size ()) return true ;
1748
- assert (text.size () > prefix.size ());
1749
- return !clang::isLowercase (text[prefix.size ()]);
1750
- };
1751
-
1752
- auto result = SelectorFamily::None;
1753
- if (false ) /* for #define purposes*/ ;
1754
- #define CHECK_PREFIX (LABEL, PREFIX ) \
1755
- else if (hasPrefix (text, PREFIX)) result = SelectorFamily::LABEL;
1756
- FOREACH_FAMILY (CHECK_PREFIX)
1757
- #undef CHECK_PREFIX
1758
-
1759
- if (result == SelectorFamily::Init)
1760
- return SelectorFamily::None;
1717
+ static ObjCSelectorFamily getObjCSelectorFamily (ObjCSelector name) {
1718
+ auto result = name.getSelectorFamily ();
1719
+
1720
+ if (result == ObjCSelectorFamily::Init)
1721
+ return ObjCSelectorFamily::None;
1722
+
1761
1723
return result;
1762
1724
}
1763
1725
1764
1726
// / Get the ObjC selector family a foreign SILDeclRef belongs to.
1765
- static SelectorFamily getSelectorFamily (SILDeclRef c) {
1727
+ static ObjCSelectorFamily getObjCSelectorFamily (SILDeclRef c) {
1766
1728
assert (c.isForeign );
1767
1729
switch (c.kind ) {
1768
1730
case SILDeclRef::Kind::Func: {
1769
1731
if (!c.hasDecl ())
1770
- return SelectorFamily ::None;
1732
+ return ObjCSelectorFamily ::None;
1771
1733
1772
1734
auto *FD = cast<FuncDecl>(c.getDecl ());
1773
1735
if (auto accessor = dyn_cast<AccessorDecl>(FD)) {
@@ -1783,11 +1745,11 @@ static SelectorFamily getSelectorFamily(SILDeclRef c) {
1783
1745
}
1784
1746
}
1785
1747
1786
- return getSelectorFamily (FD->getObjCSelector (). getSelectorPieces (). front ());
1748
+ return getObjCSelectorFamily (FD->getObjCSelector ());
1787
1749
}
1788
1750
case SILDeclRef::Kind::Initializer:
1789
1751
case SILDeclRef::Kind::IVarInitializer:
1790
- return SelectorFamily ::Init;
1752
+ return ObjCSelectorFamily ::Init;
1791
1753
1792
1754
// / Currently IRGen wraps alloc/init methods into Swift constructors
1793
1755
// / with Swift conventions.
@@ -1796,7 +1758,7 @@ static SelectorFamily getSelectorFamily(SILDeclRef c) {
1796
1758
case SILDeclRef::Kind::Destroyer:
1797
1759
case SILDeclRef::Kind::Deallocator:
1798
1760
case SILDeclRef::Kind::IVarDestroyer:
1799
- return SelectorFamily ::None;
1761
+ return ObjCSelectorFamily ::None;
1800
1762
1801
1763
case SILDeclRef::Kind::EnumElement:
1802
1764
case SILDeclRef::Kind::GlobalAccessor:
@@ -1810,12 +1772,12 @@ static SelectorFamily getSelectorFamily(SILDeclRef c) {
1810
1772
1811
1773
namespace {
1812
1774
1813
- class SelectorFamilyConventions : public Conventions {
1814
- SelectorFamily Family;
1775
+ class ObjCSelectorFamilyConventions : public Conventions {
1776
+ ObjCSelectorFamily Family;
1815
1777
1816
1778
public:
1817
- SelectorFamilyConventions (SelectorFamily family)
1818
- : Conventions(ConventionsKind::SelectorFamily ), Family(family) {}
1779
+ ObjCSelectorFamilyConventions (ObjCSelectorFamily family)
1780
+ : Conventions(ConventionsKind::ObjCSelectorFamily ), Family(family) {}
1819
1781
1820
1782
ParameterConvention getIndirectParameter (unsigned index,
1821
1783
const AbstractionPattern &type,
@@ -1836,14 +1798,14 @@ class SelectorFamilyConventions : public Conventions {
1836
1798
1837
1799
ResultConvention getResult (const TypeLowering &tl) const override {
1838
1800
switch (Family) {
1839
- case SelectorFamily ::Alloc:
1840
- case SelectorFamily ::Copy:
1841
- case SelectorFamily ::Init:
1842
- case SelectorFamily ::MutableCopy:
1843
- case SelectorFamily ::New:
1801
+ case ObjCSelectorFamily ::Alloc:
1802
+ case ObjCSelectorFamily ::Copy:
1803
+ case ObjCSelectorFamily ::Init:
1804
+ case ObjCSelectorFamily ::MutableCopy:
1805
+ case ObjCSelectorFamily ::New:
1844
1806
return ResultConvention::Owned;
1845
1807
1846
- case SelectorFamily ::None:
1808
+ case ObjCSelectorFamily ::None:
1847
1809
// Defaults below.
1848
1810
break ;
1849
1811
}
@@ -1860,7 +1822,7 @@ class SelectorFamilyConventions : public Conventions {
1860
1822
1861
1823
ParameterConvention
1862
1824
getDirectSelfParameter (const AbstractionPattern &type) const override {
1863
- if (Family == SelectorFamily ::Init)
1825
+ if (Family == ObjCSelectorFamily ::Init)
1864
1826
return ParameterConvention::Direct_Owned;
1865
1827
return ObjCSelfConvention;
1866
1828
}
@@ -1872,21 +1834,21 @@ class SelectorFamilyConventions : public Conventions {
1872
1834
}
1873
1835
1874
1836
static bool classof (const Conventions *C) {
1875
- return C->getKind () == ConventionsKind::SelectorFamily ;
1837
+ return C->getKind () == ConventionsKind::ObjCSelectorFamily ;
1876
1838
}
1877
1839
};
1878
1840
1879
1841
} // end anonymous namespace
1880
1842
1881
1843
static CanSILFunctionType
1882
- getSILFunctionTypeForSelectorFamily (SILModule &M, SelectorFamily family,
1883
- CanAnyFunctionType origType,
1884
- CanAnyFunctionType substInterfaceType,
1885
- AnyFunctionType::ExtInfo extInfo,
1886
- const ForeignInfo &foreignInfo,
1887
- Optional<SILDeclRef> constant) {
1844
+ getSILFunctionTypeForObjCSelectorFamily (SILModule &M, ObjCSelectorFamily family,
1845
+ CanAnyFunctionType origType,
1846
+ CanAnyFunctionType substInterfaceType,
1847
+ AnyFunctionType::ExtInfo extInfo,
1848
+ const ForeignInfo &foreignInfo,
1849
+ Optional<SILDeclRef> constant) {
1888
1850
return getSILFunctionType (M, AbstractionPattern (origType), substInterfaceType,
1889
- extInfo, SelectorFamilyConventions (family),
1851
+ extInfo, ObjCSelectorFamilyConventions (family),
1890
1852
foreignInfo, constant, constant,
1891
1853
/* requirement subs*/ None,
1892
1854
/* witnessMethodConformance=*/ None);
@@ -1967,10 +1929,10 @@ getUncachedSILFunctionTypeForConstant(SILModule &M,
1967
1929
1968
1930
// If the decl belongs to an ObjC method family, use that family's
1969
1931
// ownership conventions.
1970
- return getSILFunctionTypeForSelectorFamily (M, getSelectorFamily (constant),
1971
- origLoweredInterfaceType ,
1972
- origLoweredInterfaceType,
1973
- extInfo, foreignInfo, constant);
1932
+ return getSILFunctionTypeForObjCSelectorFamily (
1933
+ M, getObjCSelectorFamily (constant) ,
1934
+ origLoweredInterfaceType, origLoweredInterfaceType,
1935
+ extInfo, foreignInfo, constant);
1974
1936
}
1975
1937
1976
1938
CanSILFunctionType TypeConverter::
0 commit comments