@@ -188,13 +188,15 @@ class Identifier {
188
188
};
189
189
190
190
class DeclName ;
191
+ class DeclNameRef ;
191
192
class ObjCSelector ;
192
193
193
194
} // end namespace swift
194
195
195
196
namespace llvm {
196
197
raw_ostream &operator <<(raw_ostream &OS, swift::Identifier I);
197
198
raw_ostream &operator <<(raw_ostream &OS, swift::DeclName I);
199
+ raw_ostream &operator <<(raw_ostream &OS, swift::DeclNameRef I);
198
200
raw_ostream &operator <<(raw_ostream &OS, swift::ObjCSelector S);
199
201
200
202
// Identifiers hash just like pointers.
@@ -546,7 +548,7 @@ class DeclName {
546
548
// The names don't match.
547
549
return false ;
548
550
}
549
-
551
+
550
552
// / Add a DeclName to a lookup table so that it can be found by its simple
551
553
// / name or its compound name.
552
554
template <typename LookupTable, typename Element>
@@ -622,6 +624,193 @@ class DeclName {
622
624
623
625
void simple_display (llvm::raw_ostream &out, DeclName name);
624
626
627
+ // / An in-source reference to another declaration, including qualification
628
+ // / information.
629
+ class DeclNameRef {
630
+ DeclName FullName;
631
+
632
+ public:
633
+ static DeclNameRef createSubscript ();
634
+ static DeclNameRef createConstructor ();
635
+
636
+ DeclNameRef () : FullName() { }
637
+
638
+ void *getOpaqueValue () const { return FullName.getOpaqueValue (); }
639
+ static DeclNameRef getFromOpaqueValue (void *p);
640
+
641
+ // *** TRANSITIONAL CODE STARTS HERE ***
642
+
643
+ // We want all DeclNameRef constructions to be explicit, but they need to be
644
+ // threaded through large portions of the compiler, so that would be
645
+ // difficult. Instead, we will make uses of DeclNameRef(...) implicit but
646
+ // deprecated, and use DeclNameRef_(...) as a stand-in for intentional calls
647
+ // to the constructors. The deprecations and DeclNameRef_ function will go
648
+ // away before we merge any of this into master.
649
+
650
+ [[deprecated]] DeclNameRef(DeclName FullName)
651
+ : FullName(FullName) { }
652
+
653
+ [[deprecated]] DeclNameRef(DeclBaseName BaseName)
654
+ : FullName(BaseName) { }
655
+
656
+ [[deprecated]] DeclNameRef(Identifier BaseName)
657
+ : FullName(BaseName) { }
658
+
659
+ // *** TRANSITIONAL CODE ENDS HERE ***
660
+
661
+ // / The name of the declaration being referenced.
662
+ DeclName getFullName () const {
663
+ return FullName;
664
+ }
665
+
666
+ DeclName &getFullName () {
667
+ return FullName;
668
+ }
669
+
670
+ // / The base name of the declaration being referenced.
671
+ DeclBaseName getBaseName () const {
672
+ return FullName.getBaseName ();
673
+ }
674
+
675
+ Identifier getBaseIdentifier () const {
676
+ return FullName.getBaseIdentifier ();
677
+ }
678
+
679
+ ArrayRef<Identifier> getArgumentNames () const {
680
+ return FullName.getArgumentNames ();
681
+ }
682
+
683
+ bool isSimpleName () const {
684
+ return FullName.isSimpleName ();
685
+ }
686
+
687
+ bool isSimpleName (DeclBaseName name) const {
688
+ return FullName.isSimpleName (name);
689
+ }
690
+
691
+ bool isSimpleName (StringRef name) const {
692
+ return FullName.isSimpleName (name);
693
+ }
694
+
695
+ bool isSpecial () const {
696
+ return FullName.isSpecial ();
697
+ }
698
+
699
+ bool isOperator () const {
700
+ return FullName.isOperator ();
701
+ }
702
+
703
+ bool isCompoundName () const {
704
+ return FullName.isCompoundName ();
705
+ }
706
+
707
+ explicit operator bool () const {
708
+ return (bool )FullName;
709
+ }
710
+
711
+ // / Compare two declaration names, producing -1 if \c *this comes before
712
+ // / \c other, 1 if \c *this comes after \c other, and 0 if they are equal.
713
+ // /
714
+ // / Null declaration names come after all other declaration names.
715
+ int compare (DeclNameRef other) const {
716
+ return getFullName ().compare (other.getFullName ());
717
+ }
718
+
719
+ friend bool operator ==(DeclNameRef lhs, DeclNameRef rhs) {
720
+ return lhs.getOpaqueValue () == rhs.getOpaqueValue ();
721
+ }
722
+
723
+ friend bool operator !=(DeclNameRef lhs, DeclNameRef rhs) {
724
+ return !(lhs == rhs);
725
+ }
726
+
727
+ friend llvm::hash_code hash_value (DeclNameRef name) {
728
+ using llvm::hash_value;
729
+ return hash_value (name.getFullName ().getOpaqueValue ());
730
+ }
731
+
732
+ friend bool operator <(DeclNameRef lhs, DeclNameRef rhs) {
733
+ return lhs.compare (rhs) < 0 ;
734
+ }
735
+
736
+ friend bool operator <=(DeclNameRef lhs, DeclNameRef rhs) {
737
+ return lhs.compare (rhs) <= 0 ;
738
+ }
739
+
740
+ friend bool operator >(DeclNameRef lhs, DeclNameRef rhs) {
741
+ return lhs.compare (rhs) > 0 ;
742
+ }
743
+
744
+ friend bool operator >=(DeclNameRef lhs, DeclNameRef rhs) {
745
+ return lhs.compare (rhs) >= 0 ;
746
+ }
747
+
748
+ DeclNameRef withoutArgumentLabels () const ;
749
+ DeclNameRef withArgumentLabels (ASTContext &C,
750
+ ArrayRef<Identifier> argumentNames) const ;
751
+
752
+ // / Get a string representation of the name,
753
+ // /
754
+ // / \param scratch Scratch space to use.
755
+ StringRef getString (llvm::SmallVectorImpl<char > &scratch,
756
+ bool skipEmptyArgumentNames = false ) const ;
757
+
758
+ // / Print the representation of this declaration name to the given
759
+ // / stream.
760
+ // /
761
+ // / \param skipEmptyArgumentNames When true, don't print the argument labels
762
+ // / if they are all empty.
763
+ llvm::raw_ostream &print (llvm::raw_ostream &os,
764
+ bool skipEmptyArgumentNames = false ) const ;
765
+
766
+ // / Print a "pretty" representation of this declaration name to the given
767
+ // / stream.
768
+ // /
769
+ // / This is the name used for diagnostics; it is not necessarily the
770
+ // / fully-specified name that would be written in the source.
771
+ llvm::raw_ostream &printPretty (llvm::raw_ostream &os) const ;
772
+
773
+ // / Dump this name to standard error.
774
+ LLVM_ATTRIBUTE_DEPRECATED (void dump () const LLVM_ATTRIBUTE_USED,
775
+ "only for use within the debugger");
776
+ };
777
+
778
+ // *** TRANSITIONAL CODE STARTS HERE ***
779
+
780
+ template <typename T>
781
+ static DeclNameRef DeclNameRef_ (T name) {
782
+ #pragma clang diagnostic push
783
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
784
+ return DeclNameRef (name);
785
+ #pragma clang diagnostic pop
786
+ }
787
+
788
+ // *** TRANSITIONAL CODE ENDS HERE ***
789
+
790
+ inline DeclNameRef DeclNameRef::getFromOpaqueValue (void *p) {
791
+ return DeclNameRef_ (DeclName::getFromOpaqueValue (p));
792
+ }
793
+
794
+ inline DeclNameRef DeclNameRef::withoutArgumentLabels () const {
795
+ return DeclNameRef_ (getBaseName ());
796
+ }
797
+
798
+ inline DeclNameRef DeclNameRef::withArgumentLabels (
799
+ ASTContext &C, ArrayRef<Identifier> argumentNames) const {
800
+ return DeclNameRef_ (DeclName (C, getBaseName (), argumentNames));
801
+ }
802
+
803
+
804
+ inline DeclNameRef DeclNameRef::createSubscript () {
805
+ return DeclNameRef_ (DeclBaseName::createSubscript ());
806
+ }
807
+
808
+ inline DeclNameRef DeclNameRef::createConstructor () {
809
+ return DeclNameRef_ (DeclBaseName::createConstructor ());
810
+ }
811
+
812
+ void simple_display (llvm::raw_ostream &out, DeclNameRef name);
813
+
625
814
enum class ObjCSelectorFamily : unsigned {
626
815
None,
627
816
#define OBJC_SELECTOR_FAMILY (LABEL, PREFIX ) LABEL,
@@ -766,6 +955,37 @@ namespace llvm {
766
955
}
767
956
};
768
957
958
+ // A DeclNameRef is "pointer like" just like DeclNames.
959
+ template <typename T> struct PointerLikeTypeTraits ;
960
+ template <>
961
+ struct PointerLikeTypeTraits <swift::DeclNameRef> {
962
+ public:
963
+ static inline void *getAsVoidPointer (swift::DeclNameRef name) {
964
+ return name.getOpaqueValue ();
965
+ }
966
+ static inline swift::DeclNameRef getFromVoidPointer (void *ptr) {
967
+ return swift::DeclNameRef::getFromOpaqueValue (ptr);
968
+ }
969
+ enum { NumLowBitsAvailable = PointerLikeTypeTraits<swift::DeclName>::NumLowBitsAvailable };
970
+ };
971
+
972
+ // DeclNameRefs hash just like DeclNames.
973
+ template <> struct DenseMapInfo <swift::DeclNameRef> {
974
+ static swift::DeclNameRef getEmptyKey () {
975
+ return DeclNameRef_ (DenseMapInfo<swift::DeclName>::getEmptyKey ());
976
+ }
977
+ static swift::DeclNameRef getTombstoneKey () {
978
+ return DeclNameRef_ (DenseMapInfo<swift::DeclName>::getTombstoneKey ());
979
+ }
980
+ static unsigned getHashValue (swift::DeclNameRef Val) {
981
+ return DenseMapInfo<swift::DeclName>::getHashValue (Val.getFullName ());
982
+ }
983
+ static bool isEqual (swift::DeclNameRef LHS, swift::DeclNameRef RHS) {
984
+ return DenseMapInfo<swift::DeclName>::isEqual (LHS.getFullName (),
985
+ RHS.getFullName ());
986
+ }
987
+ };
988
+
769
989
// An ObjCSelector is "pointer like".
770
990
template <typename T> struct PointerLikeTypeTraits ;
771
991
template <>
0 commit comments