18
18
#include " swift/Basic/Debug.h"
19
19
#include " swift/Basic/LLVM.h"
20
20
#include " swift/Basic/OptionSet.h"
21
+ #include " swift/Basic/StringExtras.h"
21
22
#include " swift/Frontend/Frontend.h"
22
23
#include " llvm/ADT/ArrayRef.h"
23
24
#include " llvm/ADT/StringMap.h"
@@ -717,9 +718,9 @@ class ContextFreeCodeCompletionResult {
717
718
718
719
bool IsSystem : 1 ;
719
720
CodeCompletionString *CompletionString;
720
- StringRef ModuleName;
721
- StringRef BriefDocComment;
722
- ArrayRef<StringRef > AssociatedUSRs;
721
+ NullTerminatedStringRef ModuleName;
722
+ NullTerminatedStringRef BriefDocComment;
723
+ ArrayRef<NullTerminatedStringRef > AssociatedUSRs;
723
724
CodeCompletionResultType ResultType;
724
725
725
726
ContextFreeNotRecommendedReason NotRecommended : 3 ;
@@ -728,8 +729,8 @@ class ContextFreeCodeCompletionResult {
728
729
CodeCompletionDiagnosticSeverity DiagnosticSeverity : 3 ;
729
730
static_assert (int (CodeCompletionDiagnosticSeverity::MAX_VALUE) < 1 << 3 , " " );
730
731
731
- StringRef DiagnosticMessage;
732
- StringRef FilterName;
732
+ NullTerminatedStringRef DiagnosticMessage;
733
+ NullTerminatedStringRef FilterName;
733
734
734
735
public:
735
736
// / Memberwise initializer. \p AssociatedKInd is opaque and will be
@@ -743,12 +744,15 @@ class ContextFreeCodeCompletionResult {
743
744
ContextFreeCodeCompletionResult (
744
745
CodeCompletionResultKind Kind, uint8_t AssociatedKind,
745
746
CodeCompletionOperatorKind KnownOperatorKind, bool IsSystem,
746
- CodeCompletionString *CompletionString, StringRef ModuleName,
747
- StringRef BriefDocComment, ArrayRef<StringRef> AssociatedUSRs,
747
+ CodeCompletionString *CompletionString,
748
+ NullTerminatedStringRef ModuleName,
749
+ NullTerminatedStringRef BriefDocComment,
750
+ ArrayRef<NullTerminatedStringRef> AssociatedUSRs,
748
751
CodeCompletionResultType ResultType,
749
752
ContextFreeNotRecommendedReason NotRecommended,
750
753
CodeCompletionDiagnosticSeverity DiagnosticSeverity,
751
- StringRef DiagnosticMessage, StringRef FilterName)
754
+ NullTerminatedStringRef DiagnosticMessage,
755
+ NullTerminatedStringRef FilterName)
752
756
: Kind(Kind), KnownOperatorKind(KnownOperatorKind), IsSystem(IsSystem),
753
757
CompletionString (CompletionString), ModuleName(ModuleName),
754
758
BriefDocComment(BriefDocComment), AssociatedUSRs(AssociatedUSRs),
@@ -780,21 +784,24 @@ class ContextFreeCodeCompletionResult {
780
784
static ContextFreeCodeCompletionResult *createPatternOrBuiltInOperatorResult (
781
785
llvm::BumpPtrAllocator &Allocator, CodeCompletionResultKind Kind,
782
786
CodeCompletionString *CompletionString,
783
- CodeCompletionOperatorKind KnownOperatorKind, StringRef BriefDocComment,
787
+ CodeCompletionOperatorKind KnownOperatorKind,
788
+ NullTerminatedStringRef BriefDocComment,
784
789
CodeCompletionResultType ResultType,
785
790
ContextFreeNotRecommendedReason NotRecommended,
786
791
CodeCompletionDiagnosticSeverity DiagnosticSeverity,
787
- StringRef DiagnosticMessage);
792
+ NullTerminatedStringRef DiagnosticMessage);
788
793
789
794
// / Constructs a \c Keyword result.
790
795
// /
791
796
// / \note The caller must ensure that the \p CompletionString and
792
797
// / \p BriefDocComment outlive this result, typically by storing them in
793
798
// / the same \c CodeCompletionResultSink as the result itself.
794
- static ContextFreeCodeCompletionResult *createKeywordResult (
795
- llvm::BumpPtrAllocator &Allocator, CodeCompletionKeywordKind Kind,
796
- CodeCompletionString *CompletionString, StringRef BriefDocComment,
797
- CodeCompletionResultType ResultType);
799
+ static ContextFreeCodeCompletionResult *
800
+ createKeywordResult (llvm::BumpPtrAllocator &Allocator,
801
+ CodeCompletionKeywordKind Kind,
802
+ CodeCompletionString *CompletionString,
803
+ NullTerminatedStringRef BriefDocComment,
804
+ CodeCompletionResultType ResultType);
798
805
799
806
// / Constructs a \c Literal result.
800
807
// /
@@ -814,12 +821,13 @@ class ContextFreeCodeCompletionResult {
814
821
// / \c CodeCompletionResultSink as the result itself.
815
822
static ContextFreeCodeCompletionResult *createDeclResult (
816
823
llvm::BumpPtrAllocator &Allocator, CodeCompletionString *CompletionString,
817
- const Decl *AssociatedDecl, StringRef ModuleName,
818
- StringRef BriefDocComment, ArrayRef<StringRef> AssociatedUSRs,
824
+ const Decl *AssociatedDecl, NullTerminatedStringRef ModuleName,
825
+ NullTerminatedStringRef BriefDocComment,
826
+ ArrayRef<NullTerminatedStringRef> AssociatedUSRs,
819
827
CodeCompletionResultType ResultType,
820
828
ContextFreeNotRecommendedReason NotRecommended,
821
829
CodeCompletionDiagnosticSeverity DiagnosticSeverity,
822
- StringRef DiagnosticMessage);
830
+ NullTerminatedStringRef DiagnosticMessage);
823
831
824
832
CodeCompletionResultKind getKind () const { return Kind; }
825
833
@@ -849,11 +857,13 @@ class ContextFreeCodeCompletionResult {
849
857
850
858
CodeCompletionString *getCompletionString () const { return CompletionString; }
851
859
852
- StringRef getModuleName () const { return ModuleName; }
860
+ NullTerminatedStringRef getModuleName () const { return ModuleName; }
853
861
854
- StringRef getBriefDocComment () const { return BriefDocComment; }
862
+ NullTerminatedStringRef getBriefDocComment () const { return BriefDocComment; }
855
863
856
- ArrayRef<StringRef> getAssociatedUSRs () const { return AssociatedUSRs; }
864
+ ArrayRef<NullTerminatedStringRef> getAssociatedUSRs () const {
865
+ return AssociatedUSRs;
866
+ }
857
867
858
868
const CodeCompletionResultType &getResultType () const { return ResultType; }
859
869
@@ -864,9 +874,11 @@ class ContextFreeCodeCompletionResult {
864
874
CodeCompletionDiagnosticSeverity getDiagnosticSeverity () const {
865
875
return DiagnosticSeverity;
866
876
}
867
- StringRef getDiagnosticMessage () const { return DiagnosticMessage; }
877
+ NullTerminatedStringRef getDiagnosticMessage () const {
878
+ return DiagnosticMessage;
879
+ }
868
880
869
- StringRef getFilterName () const { return FilterName; }
881
+ NullTerminatedStringRef getFilterName () const { return FilterName; }
870
882
871
883
bool isOperator () const {
872
884
if (getKind () == CodeCompletionResultKind::Declaration) {
@@ -908,7 +920,7 @@ class CodeCompletionResult {
908
920
CodeCompletionDiagnosticSeverity DiagnosticSeverity : 3 ;
909
921
static_assert (int (CodeCompletionDiagnosticSeverity::MAX_VALUE) < 1 << 3 , " " );
910
922
911
- StringRef DiagnosticMessage;
923
+ NullTerminatedStringRef DiagnosticMessage;
912
924
913
925
// / The number of bytes to the left of the code completion point that
914
926
// / should be erased first if this completion string is inserted in the
@@ -932,7 +944,7 @@ class CodeCompletionResult {
932
944
CodeCompletionResultTypeRelation TypeDistance,
933
945
ContextualNotRecommendedReason NotRecommended,
934
946
CodeCompletionDiagnosticSeverity DiagnosticSeverity,
935
- StringRef DiagnosticMessage)
947
+ NullTerminatedStringRef DiagnosticMessage)
936
948
: ContextFree(ContextFree), SemanticContext(SemanticContext),
937
949
Flair (Flair.toRaw()), NotRecommended(NotRecommended),
938
950
DiagnosticSeverity(DiagnosticSeverity),
@@ -954,7 +966,7 @@ class CodeCompletionResult {
954
966
const DeclContext *DC,
955
967
ContextualNotRecommendedReason NotRecommended,
956
968
CodeCompletionDiagnosticSeverity DiagnosticSeverity,
957
- StringRef DiagnosticMessage);
969
+ NullTerminatedStringRef DiagnosticMessage);
958
970
959
971
const ContextFreeCodeCompletionResult &getContextFreeResult () const {
960
972
return ContextFree;
@@ -1063,15 +1075,15 @@ class CodeCompletionResult {
1063
1075
return getContextFreeResult ().getCompletionString ();
1064
1076
}
1065
1077
1066
- StringRef getModuleName () const {
1078
+ NullTerminatedStringRef getModuleName () const {
1067
1079
return getContextFreeResult ().getModuleName ();
1068
1080
}
1069
1081
1070
- StringRef getBriefDocComment () const {
1082
+ NullTerminatedStringRef getBriefDocComment () const {
1071
1083
return getContextFreeResult ().getBriefDocComment ();
1072
1084
}
1073
1085
1074
- ArrayRef<StringRef > getAssociatedUSRs () const {
1086
+ ArrayRef<NullTerminatedStringRef > getAssociatedUSRs () const {
1075
1087
return getContextFreeResult ().getAssociatedUSRs ();
1076
1088
}
1077
1089
@@ -1083,7 +1095,9 @@ class CodeCompletionResult {
1083
1095
1084
1096
// / Get the contextual diagnostic message. This disregards context-free
1085
1097
// / diagnostics.
1086
- StringRef getContextualDiagnosticMessage () const { return DiagnosticMessage; }
1098
+ NullTerminatedStringRef getContextualDiagnosticMessage () const {
1099
+ return DiagnosticMessage;
1100
+ }
1087
1101
1088
1102
// / Return the contextual diagnostic severity if there was a contextual
1089
1103
// / diagnostic. If there is no contextual diagnostic, return the context-free
@@ -1099,15 +1113,15 @@ class CodeCompletionResult {
1099
1113
// / Return the contextual diagnostic message if there was a contextual
1100
1114
// / diagnostic. If there is no contextual diagnostic, return the context-free
1101
1115
// / diagnostic message.
1102
- StringRef getDiagnosticMessage () const {
1116
+ NullTerminatedStringRef getDiagnosticMessage () const {
1103
1117
if (NotRecommended != ContextualNotRecommendedReason::None) {
1104
1118
return DiagnosticMessage;
1105
1119
} else {
1106
1120
return getContextFreeResult ().getDiagnosticMessage ();
1107
1121
}
1108
1122
}
1109
1123
1110
- StringRef getFilterName () const {
1124
+ NullTerminatedStringRef getFilterName () const {
1111
1125
return getContextFreeResult ().getFilterName ();
1112
1126
}
1113
1127
@@ -1146,7 +1160,7 @@ struct CodeCompletionResultSink {
1146
1160
1147
1161
// / A single-element cache for module names stored in Allocator, keyed by a
1148
1162
// / clang::Module * or swift::ModuleDecl *.
1149
- std::pair<void *, StringRef > LastModule;
1163
+ std::pair<void *, NullTerminatedStringRef > LastModule;
1150
1164
1151
1165
CodeCompletionResultSink ()
1152
1166
: Allocator(std::make_shared<llvm::BumpPtrAllocator>()) {}
0 commit comments