Skip to content

Commit 81e5847

Browse files
committed
correctly handle files included through symlinks
1 parent f5cf9d8 commit 81e5847

File tree

7 files changed

+29
-45
lines changed

7 files changed

+29
-45
lines changed

src/lib/AST/ASTVisitor.cpp

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3114,25 +3114,18 @@ ASTVisitor::
31143114
findFileInfo(clang::SourceLocation const loc)
31153115
{
31163116
MRDOCS_CHECK_OR(!loc.isInvalid(), nullptr);
3117-
3118-
// KRYSTIAN FIXME: we really should not be calling getPresumedLoc this often,
3119-
// it's quite expensive
3120-
auto const presumed = source_.getPresumedLoc(loc, false);
3121-
MRDOCS_CHECK_OR(!presumed.isInvalid(), nullptr);
3122-
3123-
FileEntry const* entry = source_.getFileEntryForID( presumed.getFileID());
3124-
MRDOCS_CHECK_OR(entry, nullptr);
3117+
// Find the presumed location, ignoring #line directives
3118+
PresumedLoc presumed = source_.getPresumedLoc(loc, false);
3119+
FileID id = presumed.getFileID();
3120+
if(id.isInvalid())
3121+
return nullptr;
31253122

31263123
// Find in the cache
3127-
if (auto const it = files_.find(entry); it != files_.end())
3128-
{
3124+
if(auto const it = files_.find(id); it != files_.end())
31293125
return std::addressof(it->second);
3130-
}
31313126

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));
3127+
auto [it, inserted] = files_.try_emplace(
3128+
id, buildFileInfo(presumed.getFilename()));
31363129
return std::addressof(it->second);
31373130
}
31383131

@@ -3148,15 +3141,6 @@ findFileInfo(Decl const* D)
31483141
return findFileInfo(Loc);
31493142
}
31503143

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-
31603144
ASTVisitor::FileInfo
31613145
ASTVisitor::
31623146
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
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/** A brief.
2+
*/
3+
4+
void f();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
= Reference
2+
:mrdocs:
3+
4+
[#index]
5+
== Global namespace
6+
7+
8+
9+
10+
11+
[.small]#Created with https://www.mrdocs.com[MrDocs]#
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "included.hpp"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Exclude excluded.hpp
2+
exclude:
3+
- 'excluded.hpp'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
excluded.hpp

0 commit comments

Comments
 (0)