@@ -431,7 +431,7 @@ struct MappedLoc {
431
431
class IndexSwiftASTWalker : public SourceEntityWalker {
432
432
IndexDataConsumer &IdxConsumer;
433
433
SourceManager &SrcMgr;
434
- unsigned BufferID;
434
+ std::optional< unsigned > BufferID;
435
435
bool enableWarnings;
436
436
437
437
ModuleDecl *CurrentModule = nullptr ;
@@ -592,7 +592,7 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
592
592
IndexSwiftASTWalker (IndexDataConsumer &IdxConsumer, ASTContext &Ctx,
593
593
SourceFile *SF = nullptr )
594
594
: IdxConsumer(IdxConsumer), SrcMgr(Ctx.SourceMgr),
595
- BufferID (SF ? SF->getBufferID () : -1 ),
595
+ BufferID (SF ? std::optional( SF->getBufferID ()) : std::nullopt ),
596
596
enableWarnings(IdxConsumer.enableWarnings()) {}
597
597
598
598
~IndexSwiftASTWalker () override {
@@ -1066,19 +1066,19 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
1066
1066
// \c None if \p loc is otherwise invalid or its original location isn't
1067
1067
// contained within the current buffer.
1068
1068
std::optional<MappedLoc> getMappedLocation (SourceLoc loc) {
1069
- if (loc.isInvalid ()) {
1069
+ if (loc.isInvalid () || !BufferID. has_value () ) {
1070
1070
if (IsModuleFile)
1071
1071
return {{0 , 0 , false }};
1072
1072
return std::nullopt;
1073
1073
}
1074
1074
1075
+ auto bufferID = BufferID.value ();
1075
1076
bool inGeneratedBuffer =
1076
- !SrcMgr.rangeContainsTokenLoc (SrcMgr.getRangeForBuffer (BufferID ), loc);
1077
+ !SrcMgr.rangeContainsTokenLoc (SrcMgr.getRangeForBuffer (bufferID ), loc);
1077
1078
1078
- auto bufferID = BufferID;
1079
1079
if (inGeneratedBuffer) {
1080
1080
std::tie (bufferID, loc) = CurrentModule->getOriginalLocation (loc);
1081
- if (BufferID != bufferID) {
1081
+ if (BufferID. value () != bufferID) {
1082
1082
assert (false && " Location is not within file being indexed" );
1083
1083
return std::nullopt;
1084
1084
}
0 commit comments