Skip to content

Commit 113a57e

Browse files
committed
getPrimaryLocation depends on InfoKind
#refactor
1 parent ca8bbbe commit 113a57e

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

include/mrdocs/Metadata/Info.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,15 @@ tag_invoke(
355355
});
356356
}
357357

358+
inline
359+
OptionalLocation
360+
getPrimaryLocation(Info const& I)
361+
{
362+
return getPrimaryLocation(
363+
dynamic_cast<SourceInfo const&>(I),
364+
I.isRecord() || I.isEnum());
365+
}
366+
358367
} // clang::mrdocs
359368

360369
#endif

include/mrdocs/Metadata/Source.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ merge(SourceInfo& I, SourceInfo&& Other);
144144

145145
MRDOCS_DECL
146146
OptionalLocation
147-
getPrimaryLocation(SourceInfo const& I);
147+
getPrimaryLocation(SourceInfo const& I, bool preferDefinition);
148148

149149
void
150150
tag_invoke(

src/lib/Metadata/Source.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,27 +81,21 @@ merge(SourceInfo& I, SourceInfo&& Other)
8181
}
8282

8383
OptionalLocation
84-
getPrimaryLocation(SourceInfo const& I)
84+
getPrimaryLocation(SourceInfo const& I, bool const preferDefinition)
8585
{
86-
OptionalLocation primaryLoc;
87-
if (I.DefLoc)
86+
if (I.Loc.empty() ||
87+
(preferDefinition &&
88+
I.DefLoc))
8889
{
89-
primaryLoc = *I.DefLoc;
90+
return I.DefLoc;
9091
}
91-
else if (!I.Loc.empty())
92-
{
93-
auto const documentedIt = std::ranges::find_if(
92+
auto const documentedIt = std::ranges::find_if(
9493
I.Loc, &Location::Documented);
95-
if (documentedIt != I.Loc.end())
96-
{
97-
primaryLoc = *documentedIt;
98-
}
99-
else
100-
{
101-
primaryLoc = I.Loc.front();
102-
}
94+
if (documentedIt != I.Loc.end())
95+
{
96+
return OptionalLocation(*documentedIt);
10397
}
104-
return primaryLoc;
98+
return OptionalLocation(I.Loc.front());
10599
}
106100

107101
template <class IO>

0 commit comments

Comments
 (0)