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"
@@ -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 getSelectorFamily (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 getSelectorFamily (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 getSelectorFamily (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:
@@ -1811,10 +1773,10 @@ static SelectorFamily getSelectorFamily(SILDeclRef c) {
1811
1773
namespace {
1812
1774
1813
1775
class SelectorFamilyConventions : public Conventions {
1814
- SelectorFamily Family;
1776
+ ObjCSelectorFamily Family;
1815
1777
1816
1778
public:
1817
- SelectorFamilyConventions (SelectorFamily family)
1779
+ SelectorFamilyConventions (ObjCSelectorFamily family)
1818
1780
: Conventions(ConventionsKind::SelectorFamily), Family(family) {}
1819
1781
1820
1782
ParameterConvention getIndirectParameter (unsigned index,
@@ -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
}
@@ -1879,7 +1841,7 @@ class SelectorFamilyConventions : public Conventions {
1879
1841
} // end anonymous namespace
1880
1842
1881
1843
static CanSILFunctionType
1882
- getSILFunctionTypeForSelectorFamily (SILModule &M, SelectorFamily family,
1844
+ getSILFunctionTypeForSelectorFamily (SILModule &M, ObjCSelectorFamily family,
1883
1845
CanAnyFunctionType origType,
1884
1846
CanAnyFunctionType substInterfaceType,
1885
1847
AnyFunctionType::ExtInfo extInfo,
0 commit comments