30
30
#include " llvm/ADT/SmallVector.h"
31
31
#include " llvm/Support/ErrorHandling.h"
32
32
#include " llvm/Support/FileSystem.h"
33
+ #include < tuple>
33
34
34
35
using namespace swift ;
35
36
using namespace swift ::index;
@@ -472,8 +473,7 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
472
473
return true ;
473
474
474
475
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);
477
477
Info.roles |= (unsigned )SymbolRole::Reference;
478
478
Info.symInfo = getSymbolInfoForModule (Mod);
479
479
getModuleNameAndUSR (Mod, Info.name , Info.USR );
@@ -585,16 +585,12 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
585
585
586
586
bool indexComment (const Decl *D);
587
587
588
- std::pair <unsigned , unsigned > getLineCol (SourceLoc Loc) {
588
+ std::tuple <unsigned , unsigned , unsigned > getLineColAndOffset (SourceLoc Loc) {
589
589
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);
598
594
}
599
595
600
596
bool shouldIndex (ValueDecl *D, bool IsRef) const {
@@ -1231,8 +1227,7 @@ bool IndexSwiftASTWalker::initIndexSymbol(ValueDecl *D, SourceLoc Loc,
1231
1227
if (getNameAndUSR (D, /* ExtD=*/ nullptr , Info.name , Info.USR ))
1232
1228
return true ;
1233
1229
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);
1236
1231
if (!IsRef) {
1237
1232
if (auto Group = D->getGroupName ())
1238
1233
Info.group = Group.getValue ();
@@ -1253,8 +1248,7 @@ bool IndexSwiftASTWalker::initIndexSymbol(ExtensionDecl *ExtD, ValueDecl *Extend
1253
1248
if (getNameAndUSR (ExtendedD, ExtD, Info.name , Info.USR ))
1254
1249
return true ;
1255
1250
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);
1258
1252
if (auto Group = ExtD->getGroupName ())
1259
1253
Info.group = Group.getValue ();
1260
1254
return false ;
@@ -1461,8 +1455,7 @@ bool IndexSwiftASTWalker::indexComment(const Decl *D) {
1461
1455
OS << " t:" << tagName;
1462
1456
Info.USR = stringStorage.copyString (OS.str ());
1463
1457
}
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);
1466
1459
if (!IdxConsumer.startSourceEntity (Info) || !IdxConsumer.finishSourceEntity (Info.symInfo , Info.roles )) {
1467
1460
Cancelled = true ;
1468
1461
break ;
0 commit comments