Skip to content

Commit 39aa2eb

Browse files
committed
correctly handle files included through symlinks
1 parent f5cf9d8 commit 39aa2eb

File tree

2 files changed

+6
-39
lines changed

2 files changed

+6
-39
lines changed

src/lib/AST/ASTVisitor.cpp

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3117,22 +3117,18 @@ findFileInfo(clang::SourceLocation const loc)
31173117

31183118
// KRYSTIAN FIXME: we really should not be calling getPresumedLoc this often,
31193119
// it's quite expensive
3120-
auto const presumed = source_.getPresumedLoc(loc, false);
3120+
auto const presumed = source_.getPresumedLoc(loc);
31213121
MRDOCS_CHECK_OR(!presumed.isInvalid(), nullptr);
31223122

3123-
FileEntry const* entry = source_.getFileEntryForID( presumed.getFileID());
3124-
MRDOCS_CHECK_OR(entry, nullptr);
3125-
3123+
FileID id = presumed.getFileID();
31263124
// Find in the cache
3127-
if (auto const it = files_.find(entry); it != files_.end())
3125+
if (auto const it = files_.find(id); it != files_.end())
31283126
{
31293127
return std::addressof(it->second);
31303128
}
31313129

3132-
// Build FileInfo
3133-
auto const FI = buildFileInfo(entry);
3134-
MRDOCS_CHECK_OR(FI, nullptr);
3135-
auto [it, inserted] = files_.try_emplace(entry, std::move(*FI));
3130+
auto [it, inserted] = files_.try_emplace(
3131+
id, buildFileInfo(presumed.getFilename()));
31363132
return std::addressof(it->second);
31373133
}
31383134

@@ -3148,15 +3144,6 @@ findFileInfo(Decl const* D)
31483144
return findFileInfo(Loc);
31493145
}
31503146

3151-
std::optional<ASTVisitor::FileInfo>
3152-
ASTVisitor::
3153-
buildFileInfo(FileEntry const* entry)
3154-
{
3155-
std::string_view const file_path = entry->tryGetRealPathName();
3156-
MRDOCS_CHECK_OR(!file_path.empty(), std::nullopt);
3157-
return buildFileInfo(file_path);
3158-
}
3159-
31603147
ASTVisitor::FileInfo
31613148
ASTVisitor::
31623149
buildFileInfo(std::string_view const file_path)

src/lib/AST/ASTVisitor.hpp

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class ASTVisitor
138138
if a file should be extracted or to add the
139139
SourceInfo to an Info object.
140140
*/
141-
std::unordered_map<FileEntry const*, FileInfo> files_;
141+
llvm::DenseMap<FileID, FileInfo> files_;
142142

143143
/* Determine how a Decl matched the filters
144144
*/
@@ -1112,26 +1112,6 @@ class ASTVisitor
11121112
FileInfo*
11131113
findFileInfo(Decl const* D);
11141114

1115-
/* Build a FileInfo for a FileEntry
1116-
1117-
This function will build a FileInfo object for a
1118-
given Clang FileEntry object.
1119-
1120-
The function will extract the full path and short
1121-
path of the file, and store the information in the
1122-
FileInfo object.
1123-
1124-
This function is used as an auxiliary function to
1125-
`findFileInfo` when the FileInfo object does not
1126-
exist in the cache.
1127-
1128-
@param file The Clang FileEntry object to build the FileInfo for.
1129-
@return the FileInfo object.
1130-
1131-
*/
1132-
std::optional<FileInfo>
1133-
buildFileInfo(FileEntry const* entry);
1134-
11351115
/* Build a FileInfo for a string path
11361116
11371117
This function will build a FileInfo object for a

0 commit comments

Comments
 (0)