Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
logic: Fixed multiple main declarations not shown as separate symbols…
Browse files Browse the repository at this point in the history
… when declaring file has same name (#950)

regards #233
  • Loading branch information
egraether authored Mar 30, 2020
1 parent f37716d commit 31cbf6c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/lib_cxx/data/parser/cxx/CanonicalFilePathCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,23 @@ Id CanonicalFilePathCache::getFileSymbolId(const std::wstring& path)
return 0;
}

std::wstring CanonicalFilePathCache::getDeclarationFileName(const clang::Decl* declaration)
FilePath CanonicalFilePathCache::getDeclarationFilePath(const clang::Decl* declaration)
{
const clang::SourceManager& sourceManager = declaration->getASTContext().getSourceManager();
const clang::FileID fileId = sourceManager.getFileID(declaration->getBeginLoc());
const clang::FileEntry* fileEntry = sourceManager.getFileEntryForID(fileId);
if (fileEntry != nullptr && fileEntry->isValid())
{
return getCanonicalFilePath(fileId, sourceManager).fileName();
return getCanonicalFilePath(fileId, sourceManager);
}
return getCanonicalFilePath(
utility::decodeFromUtf8(
sourceManager.getPresumedLoc(declaration->getBeginLoc()).getFilename()))
.fileName();
sourceManager.getPresumedLoc(declaration->getBeginLoc()).getFilename()));
}

std::wstring CanonicalFilePathCache::getDeclarationFileName(const clang::Decl* declaration)
{
return getDeclarationFilePath(declaration).fileName();
}

bool CanonicalFilePathCache::isProjectFile(
Expand Down
1 change: 1 addition & 0 deletions src/lib_cxx/data/parser/cxx/CanonicalFilePathCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class CanonicalFilePathCache
Id getFileSymbolId(const clang::FileEntry* entry);
Id getFileSymbolId(const std::wstring& path);

FilePath getDeclarationFilePath(const clang::Decl* declaration);
std::wstring getDeclarationFileName(const clang::Decl* declaration);

bool isProjectFile(const clang::FileID& fileId, const clang::SourceManager& sourceManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ Id CxxAstVisitorComponentIndexer::getOrCreateSymbolId(const clang::NamedDecl* de
symbolName.pop();
symbolName.push(NameElement(
L".:main:." +
getAstVisitor()->getCanonicalFilePathCache()->getDeclarationFileName(decl),
getAstVisitor()->getCanonicalFilePathCache()->getDeclarationFilePath(decl).wstr(),
sig.getPrefix(),
sig.getPostfix()));
}
Expand Down

0 comments on commit 31cbf6c

Please sign in to comment.