Skip to content

Commit 51a889d

Browse files
committed
Add a last line (ll) field to def refs
Identifies the line number until which the definition spans to be able to fetch fetch the function body.
1 parent 18a2c05 commit 51a889d

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

generator/annotator.cpp

+16-9
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,15 @@ bool Annotator::generate(clang::Sema &Sema, bool WasInDatabase)
328328
}
329329
#endif
330330
for (const auto &it2 : it.second) {
331-
clang::SourceLocation loc = it2.loc;
331+
clang::SourceRange loc = it2.loc;
332332
clang::SourceManager &sm = getSourceMgr();
333-
clang::SourceLocation exp = sm.getExpansionLoc(loc);
334-
std::string fn = htmlNameForFile(sm.getFileID(exp));
333+
clang::SourceLocation expBegin = sm.getExpansionLoc(loc.getBegin());
334+
clang::SourceLocation expEnd = sm.getExpansionLoc(loc.getEnd());
335+
std::string fn = htmlNameForFile(sm.getFileID(expBegin));
335336
if (fn.empty())
336337
continue;
337-
clang::PresumedLoc fixed = sm.getPresumedLoc(exp);
338+
clang::PresumedLoc fixedBegin = sm.getPresumedLoc(expBegin);
339+
clang::PresumedLoc fixedEnd = sm.getPresumedLoc(expEnd);
338340
const char *tag = "";
339341
char usetype = '\0';
340342
switch(it2.what) {
@@ -375,8 +377,10 @@ bool Annotator::generate(clang::Sema &Sema, bool WasInDatabase)
375377
}
376378
myfile << "<" << tag << " f='";
377379
Generator::escapeAttr(myfile, fn);
378-
myfile << "' l='"<< fixed.getLine() <<"'";
379-
if (loc.isMacroID()) myfile << " macro='1'";
380+
myfile << "' l='"<< fixedBegin.getLine() <<"'";
381+
if (fixedBegin.getLine() != fixedEnd.getLine())
382+
myfile << " ll='"<< fixedEnd.getLine() <<"'";
383+
if (loc.getBegin().isMacroID()) myfile << " macro='1'";
380384
if (!WasInDatabase) myfile << " brk='1'";
381385
if (usetype) myfile << " u='" << usetype << "'";
382386
const auto &refType = it2.typeOrContext;
@@ -597,7 +601,7 @@ void Annotator::registerReference(clang::NamedDecl* decl, clang::SourceRange ran
597601
if (usedContext && typeText.empty() && declType == Use) {
598602
typeText = getContextStr(usedContext);
599603
}
600-
addReference(getReferenceAndTitle(decl).first, range.getBegin(), type, declType, typeText, decl);
604+
addReference(getReferenceAndTitle(decl).first, range, type, declType, typeText, decl);
601605
}
602606
return;
603607
}
@@ -643,7 +647,10 @@ void Annotator::registerReference(clang::NamedDecl* decl, clang::SourceRange ran
643647
typeText = getContextStr(usedContext);
644648
}
645649

646-
addReference(ref, range.getBegin(), type, declType, typeText, decl);
650+
clang::SourceRange definitionRange = range;
651+
if (declType == Definition)
652+
definitionRange = decl->getSourceRange();
653+
addReference(ref, definitionRange, type, declType, typeText, decl);
647654

648655
if (declType == Definition && ref.find('{') >= ref.size()) {
649656
if (clang::FunctionDecl* fun = llvm::dyn_cast<clang::FunctionDecl>(decl)) {
@@ -749,7 +756,7 @@ void Annotator::registerReference(clang::NamedDecl* decl, clang::SourceRange ran
749756
}
750757
}
751758

752-
void Annotator::addReference(const std::string &ref, clang::SourceLocation refLoc, TokenType type,
759+
void Annotator::addReference(const std::string &ref, clang::SourceRange refLoc, TokenType type,
753760
DeclType dt, const std::string &typeRef, clang::Decl *decl)
754761
{
755762
if (type == Ref || type == Member || type == Decl || type == Call || type == EnumDecl

generator/annotator.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ class Annotator {
8181

8282
std::string htmlNameForFile(clang::FileID id); // keep a cache;
8383

84-
void addReference(const std::string& ref, clang::SourceLocation refLoc, Annotator::TokenType type,
84+
void addReference(const std::string& ref, clang::SourceRange refLoc, Annotator::TokenType type,
8585
Annotator::DeclType dt, const std::string &typeRef, clang::Decl *decl);
8686

8787
struct Reference {
8888
DeclType what;
89-
clang::SourceLocation loc;
89+
clang::SourceRange loc;
9090
std::string typeOrContext;
9191
};
9292
std::map<std::string, std::vector<Reference>> references;

0 commit comments

Comments
 (0)