Skip to content

Commit bd10f2a

Browse files
committed
Address PR feedback. IndexSymbol.offset is now an llvm::Optional<unsigned>, getOffsetInBuffer is now replaced by returning a tuple with the offset from getLineColAndOffset (renamed from getLineCol).
1 parent 9c3c542 commit bd10f2a

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

include/swift/Index/IndexSymbol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct IndexSymbol : IndexRelation {
6666
SmallVector<IndexRelation, 3> Relations;
6767
unsigned line = 0;
6868
unsigned column = 0;
69-
unsigned offset = 0;
69+
llvm::Optional<unsigned> offset;
7070

7171
IndexSymbol() = default;
7272

lib/Index/Index.cpp

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "llvm/ADT/SmallVector.h"
3131
#include "llvm/Support/ErrorHandling.h"
3232
#include "llvm/Support/FileSystem.h"
33+
#include <tuple>
3334

3435
using namespace swift;
3536
using namespace swift::index;
@@ -472,8 +473,7 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
472473
return true;
473474

474475
IndexSymbol Info;
475-
std::tie(Info.line, Info.column) = getLineCol(Loc);
476-
Info.offset = getOffsetInBuffer(Loc);
476+
std::tie(Info.line, Info.column, Info.offset) = getLineColAndOffset(Loc);
477477
Info.roles |= (unsigned)SymbolRole::Reference;
478478
Info.symInfo = getSymbolInfoForModule(Mod);
479479
getModuleNameAndUSR(Mod, Info.name, Info.USR);
@@ -585,16 +585,12 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
585585

586586
bool indexComment(const Decl *D);
587587

588-
std::pair<unsigned, unsigned> getLineCol(SourceLoc Loc) {
588+
std::tuple<unsigned, unsigned, unsigned> getLineColAndOffset(SourceLoc Loc) {
589589
if (Loc.isInvalid())
590-
return std::make_pair(0, 0);
591-
return SrcMgr.getLineAndColumn(Loc, BufferID);
592-
}
593-
594-
unsigned getOffsetInBuffer(SourceLoc Loc) {
595-
if (Loc.isInvalid())
596-
return 0;
597-
return SrcMgr.getLocOffsetInBuffer(Loc, BufferID);
590+
return std::make_tuple(0, 0, 0);
591+
auto lineAndColumn = SrcMgr.getLineAndColumn(Loc, BufferID);
592+
unsigned offset = SrcMgr.getLocOffsetInBuffer(Loc, BufferID);
593+
return std::make_tuple(lineAndColumn.first, lineAndColumn.second, offset);
598594
}
599595

600596
bool shouldIndex(ValueDecl *D, bool IsRef) const {
@@ -1231,8 +1227,7 @@ bool IndexSwiftASTWalker::initIndexSymbol(ValueDecl *D, SourceLoc Loc,
12311227
if (getNameAndUSR(D, /*ExtD=*/nullptr, Info.name, Info.USR))
12321228
return true;
12331229

1234-
std::tie(Info.line, Info.column) = getLineCol(Loc);
1235-
Info.offset = getOffsetInBuffer(Loc);
1230+
std::tie(Info.line, Info.column, Info.offset) = getLineColAndOffset(Loc);
12361231
if (!IsRef) {
12371232
if (auto Group = D->getGroupName())
12381233
Info.group = Group.getValue();
@@ -1253,8 +1248,7 @@ bool IndexSwiftASTWalker::initIndexSymbol(ExtensionDecl *ExtD, ValueDecl *Extend
12531248
if (getNameAndUSR(ExtendedD, ExtD, Info.name, Info.USR))
12541249
return true;
12551250

1256-
std::tie(Info.line, Info.column) = getLineCol(Loc);
1257-
Info.offset = getOffsetInBuffer(Loc);
1251+
std::tie(Info.line, Info.column, Info.offset) = getLineColAndOffset(Loc);
12581252
if (auto Group = ExtD->getGroupName())
12591253
Info.group = Group.getValue();
12601254
return false;
@@ -1461,8 +1455,7 @@ bool IndexSwiftASTWalker::indexComment(const Decl *D) {
14611455
OS << "t:" << tagName;
14621456
Info.USR = stringStorage.copyString(OS.str());
14631457
}
1464-
std::tie(Info.line, Info.column) = getLineCol(loc);
1465-
Info.offset = getOffsetInBuffer(loc);
1458+
std::tie(Info.line, Info.column, Info.offset) = getLineColAndOffset(loc);
14661459
if (!IdxConsumer.startSourceEntity(Info) || !IdxConsumer.finishSourceEntity(Info.symInfo, Info.roles)) {
14671460
Cancelled = true;
14681461
break;

0 commit comments

Comments
 (0)