Skip to content

Commit 82c3ae5

Browse files
committed
corpus lookup matches template arguments
#feat
1 parent d6d4839 commit 82c3ae5

11 files changed

+1310
-24
lines changed

mrdocs.rnc

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ grammar
3737
attribute is-anonymous { "1" }?,
3838
Javadoc?,
3939
element using-directive { ID } *,
40-
Scope
40+
(NamespaceAlias | Scope)*
4141
}
4242

4343
#---------------------------------------------
@@ -153,6 +153,7 @@ grammar
153153
Name,
154154
ID,
155155
Location *,
156+
Javadoc ?,
156157
TypeInfo
157158
} |
158159
element typedef

src/lib/AST/ParseJavadoc.cpp

+1-9
Original file line numberDiff line numberDiff line change
@@ -1089,14 +1089,6 @@ fixReference(std::string& ref)
10891089
return text;
10901090
};
10911091

1092-
// If the ref is only "operator", the next text comment
1093-
// might contain a simple operator name/type, or a
1094-
// full operator overload.
1095-
// In this case, we need to include the next text comments
1096-
// until we find this operator identifier/type or until
1097-
// we find an unbalanced '('.
1098-
// Simply including the next text comment is enough
1099-
// for the next step.
11001092
ParsedRef v;
11011093
while (true)
11021094
{
@@ -1118,7 +1110,7 @@ fixReference(std::string& ref)
11181110
continue;
11191111
}
11201112

1121-
// The ref is fully parsed
1113+
// The ref is not fully parsed
11221114
if (pres.ptr != last)
11231115
{
11241116
// The ref didn't consume all the text, so we need to

src/lib/Lib/CorpusImpl.cpp

+53-14
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,33 @@ isDecayedEqual(
311311
{
312312
return isDecayedEqualImpl<false>(lhs, rhs, context, corpus);
313313
}
314+
315+
bool
316+
isDecayedEqual(
317+
Polymorphic<TArg> const& lhs,
318+
Polymorphic<TArg> const& rhs,
319+
Info const& context,
320+
CorpusImpl const& corpus)
321+
{
322+
if (lhs->Kind != rhs->Kind)
323+
{
324+
return false;
325+
}
326+
if (lhs->isType())
327+
{
328+
return isDecayedEqualImpl<true>(
329+
get<TypeTArg>(lhs).Type,
330+
get<TypeTArg>(rhs).Type,
331+
context, corpus);
332+
}
333+
if (lhs->isNonType())
334+
{
335+
return
336+
trim(get<NonTypeTArg>(lhs).Value.Written) ==
337+
trim(get<NonTypeTArg>(rhs).Value.Written);
338+
}
339+
return false;
340+
}
314341
}
315342

316343
Expected<std::reference_wrapper<Info const>>
@@ -353,7 +380,7 @@ lookupImpl(Self&& self, SymbolID const& contextId0, std::string_view name)
353380
}
354381
return std::cref(*info);
355382
}
356-
Expected<ParsedRef> const expRef = parseRef(name);
383+
auto const expRef = parse<ParsedRef>(name);
357384
if (!expRef)
358385
{
359386
return Unexpected(formatError("Failed to parse '{}'\n {}", name, expRef.error().reason()));
@@ -494,7 +521,7 @@ lookupImpl(
494521
};
495522
auto const highestMatchLevel =
496523
!checkParameters || !ref.HasFunctionParameters ?
497-
MatchLevel::TemplateArgsSize :
524+
MatchLevel::TemplateArgs :
498525
MatchLevel::Qualifiers;
499526
auto matchLevel = MatchLevel::None;
500527
Info const* res = nullptr;
@@ -535,29 +562,41 @@ lookupImpl(
535562
}
536563
matchRes = MatchLevel::Name;
537564

538-
// Template arguments match
539-
if constexpr (requires { M.Template; })
540-
{
541-
std::optional<TemplateInfo> const& templateInfo = M.Template;
542-
if (component.TemplateArguments.empty())
565+
// Template arguments size match
566+
TemplateInfo const* templateInfo = [&]() -> TemplateInfo const* {
567+
if constexpr (requires { M.Template; })
543568
{
544-
MRDOCS_CHECK_OR(
545-
!templateInfo.has_value() ||
546-
templateInfo->Args.empty(), matchRes);
569+
std::optional<TemplateInfo> const& OTI = M.Template;
570+
MRDOCS_CHECK_OR(OTI, nullptr);
571+
TemplateInfo const& TI = *OTI;
572+
return &TI;
547573
}
548574
else
549575
{
550-
MRDOCS_CHECK_OR(
551-
templateInfo.has_value() &&
552-
templateInfo->Args.size() == component.TemplateArguments.size(), matchRes);
576+
return nullptr;
553577
}
578+
}();
579+
if (!templateInfo)
580+
{
581+
MRDOCS_CHECK_OR(!component.HasTemplateArguments, matchRes);
554582
}
555583
else
556584
{
557-
MRDOCS_CHECK_OR(component.TemplateArguments.empty(), matchRes);
585+
MRDOCS_CHECK_OR(templateInfo->Args.size() == component.TemplateArguments.size(), matchRes);
558586
}
559587
matchRes = MatchLevel::TemplateArgsSize;
560588

589+
if (templateInfo)
590+
{
591+
for (std::size_t i = 0; i < templateInfo->Args.size(); ++i)
592+
{
593+
auto& lhsType = templateInfo->Args[i];
594+
auto& rhsType = component.TemplateArguments[i];
595+
MRDOCS_CHECK_OR(isDecayedEqual(lhsType, rhsType, context, *this), matchRes);
596+
}
597+
}
598+
matchRes = MatchLevel::TemplateArgs;
599+
561600
// Function parameters size match
562601
MRDOCS_CHECK_OR(checkParameters && ref.HasFunctionParameters, matchRes);
563602
MRDOCS_CHECK_OR(MInfoTy::isFunction(), matchRes);

0 commit comments

Comments
 (0)