@@ -735,7 +735,7 @@ swift::collectExpressionType(SourceFile &SF,
735
735
// / declaration.
736
736
class VariableTypeCollector : public SourceEntityWalker {
737
737
private:
738
- SourceManager &SM;
738
+ const SourceManager &SM;
739
739
unsigned int BufferId;
740
740
741
741
// / The range in which variable types are to be collected.
@@ -746,23 +746,23 @@ class VariableTypeCollector : public SourceEntityWalker {
746
746
747
747
// / We print all types into a single output stream (e.g. into a string buffer)
748
748
// / and provide offsets into this string buffer to describe individual types,
749
- // / i.e. `OS` builds a string that contains all null-terminated printed type
749
+ // / i.e. \c OS builds a string that contains all null-terminated printed type
750
750
// / strings. When referring to one of these types, we can use the offsets at
751
- // / which it starts in the `OS` .
751
+ // / which it starts in the \c OS .
752
752
llvm::raw_ostream &OS;
753
753
754
- // / Map from a printed type to the offset in OS where the type starts.
754
+ // / Map from a printed type to the offset in \c OS where the type starts.
755
755
llvm::StringMap<uint32_t > TypeOffsets;
756
756
757
- // / Returns the start and end offset of this string in `OS` . If ` PrintedType`
758
- // / hasn't been printed to `OS` yet, this function will do so.
759
- std::pair< uint32_t , uint32_t > getTypeOffsets (StringRef PrintedType) {
757
+ // / Returns the start offset of this string in \c OS . If \c PrintedType
758
+ // / hasn't been printed to \c OS yet, this function will do so.
759
+ uint32_t getTypeOffset (StringRef PrintedType) {
760
760
auto It = TypeOffsets.find (PrintedType);
761
761
if (It == TypeOffsets.end ()) {
762
762
TypeOffsets[PrintedType] = OS.tell ();
763
763
OS << PrintedType << ' \0 ' ;
764
764
}
765
- return { TypeOffsets[PrintedType], PrintedType. size ()} ;
765
+ return TypeOffsets[PrintedType];
766
766
}
767
767
768
768
// / Checks whether the given range overlaps the total range in which we
@@ -772,44 +772,44 @@ class VariableTypeCollector : public SourceEntityWalker {
772
772
}
773
773
774
774
public:
775
- VariableTypeCollector (SourceFile &SF, SourceRange Range,
775
+ VariableTypeCollector (const SourceFile &SF, SourceRange Range,
776
776
std::vector<VariableTypeInfo> &Results,
777
777
llvm::raw_ostream &OS)
778
778
: SM(SF.getASTContext().SourceMgr), BufferId(*SF.getBufferID()),
779
779
TotalRange (Range), Results(Results), OS(OS) {}
780
780
781
- bool walkToDeclPre (Decl *D, CharSourceRange DeclRange ) override {
782
- if (DeclRange .isInvalid ()) {
783
- return false ;
781
+ bool walkToDeclPre (Decl *D, CharSourceRange DeclNameRange ) override {
782
+ if (DeclNameRange .isInvalid ()) {
783
+ return true ;
784
784
}
785
785
// Skip this declaration and its subtree if outside the range
786
786
if (!overlapsTotalRange (D->getSourceRange ())) {
787
787
return false ;
788
788
}
789
789
if (auto VD = dyn_cast<VarDecl>(D)) {
790
790
unsigned VarOffset =
791
- SM.getLocOffsetInBuffer (DeclRange .getStart (), BufferId);
792
- unsigned VarLength = DeclRange .getByteLength ();
791
+ SM.getLocOffsetInBuffer (DeclNameRange .getStart (), BufferId);
792
+ unsigned VarLength = DeclNameRange .getByteLength ();
793
793
// Print the type to a temporary buffer
794
794
SmallString<64 > Buffer;
795
795
{
796
796
llvm::raw_svector_ostream OS (Buffer);
797
797
PrintOptions Options;
798
798
Options.SynthesizeSugarOnTypes = true ;
799
799
auto Ty = VD->getType ();
800
- // Skip this declaration if the type is an error type.
800
+ // Skip this declaration and its children if the type is an error type.
801
801
if (Ty->is <ErrorType>()) {
802
802
return false ;
803
803
}
804
804
Ty->print (OS, Options);
805
805
}
806
- // Transfer the type to `OS` if needed and get the offsets of this string
806
+ // Transfer the type to `OS` if needed and get the offset of this string
807
807
// in `OS`.
808
- auto TyOffsets = getTypeOffsets (Buffer.str ());
808
+ auto TyOffset = getTypeOffset (Buffer.str ());
809
809
bool HasExplicitType =
810
810
VD->getTypeReprOrParentPatternTypeRepr () != nullptr ;
811
811
// Add the type information to the result list.
812
- Results.emplace_back (VarOffset, VarLength, HasExplicitType, TyOffsets. first );
812
+ Results.emplace_back (VarOffset, VarLength, HasExplicitType, TyOffset );
813
813
}
814
814
return true ;
815
815
}
@@ -835,10 +835,10 @@ VariableTypeInfo::VariableTypeInfo(uint32_t Offset, uint32_t Length,
835
835
: Offset(Offset), Length(Length), HasExplicitType(HasExplicitType),
836
836
TypeOffset(TypeOffset) {}
837
837
838
- void swift::collectVariableType (SourceFile &SF, SourceRange Range,
839
- std::vector<VariableTypeInfo> &Scratch ,
840
- llvm::raw_ostream &OS) {
841
- VariableTypeCollector Walker (SF, Range, Scratch , OS);
838
+ void swift::collectVariableType (
839
+ SourceFile &SF, SourceRange Range ,
840
+ std::vector<VariableTypeInfo> &VariableTypeInfos, llvm::raw_ostream &OS) {
841
+ VariableTypeCollector Walker (SF, Range, VariableTypeInfos , OS);
842
842
Walker.walk (SF);
843
843
}
844
844
0 commit comments