Skip to content

Commit

Permalink
[FOLD]
Browse files Browse the repository at this point in the history
  • Loading branch information
sdkrystian committed Oct 30, 2023
1 parent 2f42c8e commit 8de57e2
Show file tree
Hide file tree
Showing 7 changed files with 744 additions and 105 deletions.
20 changes: 19 additions & 1 deletion src/lib/-adoc/AdocCorpus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class DocVisitor
void operator()(doc::Styled const& I);
void operator()(doc::TParam const& I);
void operator()(doc::Reference const& I);
void operator()(doc::Copied const& I);

std::size_t measureLeftMargin(
doc::List<doc::Text> const& list);
Expand Down Expand Up @@ -243,16 +244,33 @@ operator()(doc::TParam const& I)
{
//dest_ += I.string;
}

void
DocVisitor::
operator()(doc::Reference const& I)
{
//dest_ += I.string;
#if 0
MRDOCS_ASSERT(! I.string.empty());
if(I.id == SymbolID::zero)
return (*this)(static_cast<const doc::Text&>(I));

MRDOCS_ASSERT(corpus_.getCorpus().exists(I.id));
fmt::format_to(std::back_inserter(dest_), "xref:{}[{}]",
corpus_.getXref(I.id), I.string);
#endif
if(I.id == SymbolID::zero)
return (*this)(static_cast<const doc::Text&>(I));

report::info("Emitting reference to '{}' (ID = {}, exists = {})",
I.string, toBase16(I.id), corpus_.getCorpus().exists(I.id));
// return (*this)(static_cast<const doc::Text&>(I));
}

void
DocVisitor::
operator()(doc::Copied const& I)
{
return (*this)(static_cast<const doc::Reference&>(I));
}

std::size_t
Expand Down
193 changes: 92 additions & 101 deletions src/lib/AST/BitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,35 +877,26 @@ emitBlock(
StreamSubBlockGuard Block(
Stream, BI_JAVADOC_NODE_BLOCK_ID);
emitRecord(I.kind, JAVADOC_NODE_KIND);
doc::visit(I.kind,
[&]<class T>()
visit(I, [&]<typename NodeTy>(const NodeTy& J)
{
if constexpr(! std::is_void_v<T>)
{
auto const& J = static_cast<T const&>(I);
if constexpr(requires { J.href; })
emitRecord(J.href, JAVADOC_NODE_HREF);
if constexpr(requires { J.string; })
emitRecord(J.string, JAVADOC_NODE_STRING);
if constexpr(requires { J.style; })
emitRecord(J.style, JAVADOC_NODE_STYLE);
if constexpr(requires { J.admonish; })
emitRecord(J.admonish, JAVADOC_NODE_ADMONISH);
if constexpr(requires { J.direction; })
emitRecord(J.direction, JAVADOC_PARAM_DIRECTION);
if constexpr(requires { J.parts; })
emitRecord(J.parts, JAVADOC_NODE_PART);
if constexpr(requires { J.id; })
emitRecord(J.id, JAVADOC_NODE_SYMBOLREF);
if constexpr(requires { J.name; })
emitRecord(J.name, JAVADOC_NODE_STRING);
if constexpr(requires { J.children; })
emitBlock(J.children);
}
else
{
MRDOCS_UNREACHABLE();
}
if constexpr(requires { J.href; })
emitRecord(J.href, JAVADOC_NODE_HREF);
if constexpr(requires { J.string; })
emitRecord(J.string, JAVADOC_NODE_STRING);
if constexpr(requires { J.style; })
emitRecord(J.style, JAVADOC_NODE_STYLE);
if constexpr(requires { J.admonish; })
emitRecord(J.admonish, JAVADOC_NODE_ADMONISH);
if constexpr(requires { J.direction; })
emitRecord(J.direction, JAVADOC_PARAM_DIRECTION);
if constexpr(requires { J.parts; })
emitRecord(J.parts, JAVADOC_NODE_PART);
if constexpr(requires { J.id; })
emitRecord(J.id, JAVADOC_NODE_SYMBOLREF);
if constexpr(requires { J.name; })
emitRecord(J.name, JAVADOC_NODE_STRING);
if constexpr(requires { J.children; })
emitBlock(J.children);
});
}

Expand Down Expand Up @@ -951,42 +942,42 @@ emitBlock(
emitRecord(TI->Kind, TYPEINFO_KIND);
emitRecord(TI->IsPackExpansion, TYPEINFO_IS_PACK);
visit(*TI, [&]<typename T>(const T& t)
{
if constexpr(requires { t.id; })
emitRecord(t.id, TYPEINFO_ID);
if constexpr(requires { t.Name; })
emitRecord(t.Name, TYPEINFO_NAME);
if constexpr(requires { t.CVQualifiers; })
emitRecord(t.CVQualifiers, TYPEINFO_CVQUAL);

if constexpr(T::isSpecialization())
{
if constexpr(requires { t.id; })
emitRecord(t.id, TYPEINFO_ID);
if constexpr(requires { t.Name; })
emitRecord(t.Name, TYPEINFO_NAME);
if constexpr(requires { t.CVQualifiers; })
emitRecord(t.CVQualifiers, TYPEINFO_CVQUAL);

if constexpr(T::isSpecialization())
{
for(const auto& targ : t.TemplateArgs)
emitBlock(targ);
}

if constexpr(requires { t.ParentType; })
emitBlock(t.ParentType, BI_TYPEINFO_PARENT_BLOCK_ID);

if constexpr(requires { t.PointeeType; })
emitBlock(t.PointeeType, BI_TYPEINFO_CHILD_BLOCK_ID);

if constexpr(T::isArray())
{
emitBlock(t.ElementType, BI_TYPEINFO_CHILD_BLOCK_ID);
emitBlock(t.Bounds);
}

if constexpr(T::isFunction())
{
emitBlock(t.ReturnType, BI_TYPEINFO_CHILD_BLOCK_ID);
for(const auto& P : t.ParamTypes)
emitBlock(P, BI_TYPEINFO_PARAM_BLOCK_ID);

emitRecord(t.RefQualifier, TYPEINFO_REFQUAL);
emitRecord(t.ExceptionSpec, TYPEINFO_EXCEPTION_SPEC);
}
});
for(const auto& targ : t.TemplateArgs)
emitBlock(targ);
}

if constexpr(requires { t.ParentType; })
emitBlock(t.ParentType, BI_TYPEINFO_PARENT_BLOCK_ID);

if constexpr(requires { t.PointeeType; })
emitBlock(t.PointeeType, BI_TYPEINFO_CHILD_BLOCK_ID);

if constexpr(T::isArray())
{
emitBlock(t.ElementType, BI_TYPEINFO_CHILD_BLOCK_ID);
emitBlock(t.Bounds);
}

if constexpr(T::isFunction())
{
emitBlock(t.ReturnType, BI_TYPEINFO_CHILD_BLOCK_ID);
for(const auto& P : t.ParamTypes)
emitBlock(P, BI_TYPEINFO_PARAM_BLOCK_ID);

emitRecord(t.RefQualifier, TYPEINFO_REFQUAL);
emitRecord(t.ExceptionSpec, TYPEINFO_EXCEPTION_SPEC);
}
});
}

void
Expand Down Expand Up @@ -1062,28 +1053,28 @@ emitBlock(
{
StreamSubBlockGuard Block(Stream, BI_TEMPLATE_PARAM_BLOCK_ID);
visit(*T, [&]<typename T>(const T& P)
{
emitRecord(P.Kind, TEMPLATE_PARAM_KIND);
emitRecord(P.Name, TEMPLATE_PARAM_NAME);
emitRecord(P.IsParameterPack, TEMPLATE_PARAM_IS_PACK);

if(P.Default)
emitBlock(P.Default);

if constexpr(T::isType())
{
emitRecord(P.Kind, TEMPLATE_PARAM_KIND);
emitRecord(P.Name, TEMPLATE_PARAM_NAME);
emitRecord(P.IsParameterPack, TEMPLATE_PARAM_IS_PACK);

if(P.Default)
emitBlock(P.Default);

if constexpr(T::isType())
{
emitRecord(P.KeyKind, TEMPLATE_PARAM_KEY_KIND);
}
if constexpr(T::isNonType())
{
emitBlock(P.Type);
}
if constexpr(T::isTemplate())
{
for(const auto& P : P.Params)
emitBlock(P);
}
});
emitRecord(P.KeyKind, TEMPLATE_PARAM_KEY_KIND);
}
if constexpr(T::isNonType())
{
emitBlock(P.Type);
}
if constexpr(T::isTemplate())
{
for(const auto& P : P.Params)
emitBlock(P);
}
});
}

void
Expand All @@ -1093,24 +1084,24 @@ emitBlock(
{
StreamSubBlockGuard Block(Stream, BI_TEMPLATE_ARG_BLOCK_ID);
visit(*T, [&]<typename T>(const T& A)
{
emitRecord(A.Kind, TEMPLATE_ARG_KIND);
emitRecord(A.IsPackExpansion, TEMPLATE_ARG_IS_PACK);

if constexpr(T::isType())
{
emitRecord(A.Kind, TEMPLATE_ARG_KIND);
emitRecord(A.IsPackExpansion, TEMPLATE_ARG_IS_PACK);

if constexpr(T::isType())
{
emitBlock(A.Type);
}
else if constexpr(T::isNonType())
{
emitBlock(A.Value);
}
else if constexpr(T::isTemplate())
{
emitRecord(A.Template, TEMPLATE_ARG_TEMPLATE);
emitRecord(A.Name, TEMPLATE_ARG_NAME);
}
});
emitBlock(A.Type);
}
else if constexpr(T::isNonType())
{
emitBlock(A.Value);
}
else if constexpr(T::isTemplate())
{
emitRecord(A.Template, TEMPLATE_ARG_TEMPLATE);
emitRecord(A.Name, TEMPLATE_ARG_NAME);
}
});
}

void
Expand Down
16 changes: 15 additions & 1 deletion src/lib/Metadata/Finalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ class Finalizer
{
auto parse_result = parseIdExpression(ref.string);
if(! parse_result)
false;
return false;

if(parse_result->name.empty())
return false;

const Info* found = nullptr;
if(parse_result->qualified)
Expand All @@ -47,7 +50,10 @@ class Finalizer
for(auto& part : parse_result->qualifier)
qualifier.push_back(part);
if(parse_result->qualifier.empty())
{
MRDOCS_ASSERT(info_.find(SymbolID::zero) != info_.end());
context = info_.find(SymbolID::zero)->get();
}
found = lookup_.lookupQualified(
context, qualifier, parse_result->name);
}
Expand All @@ -57,6 +63,11 @@ class Finalizer
current_, parse_result->name);
}

// prevent recursive documentation copies
if(ref.kind == doc::Kind::copied &&
found && found->id == current_->id)
return false;

// if we found a symbol, replace the reference
// ID with the SymbolID of that symbol
if(found)
Expand Down Expand Up @@ -305,7 +316,10 @@ void finalize(InfoSet& Info, SymbolLookup& Lookup)
{
Finalizer visitor(Info, Lookup);
for(auto& I : Info)
{
MRDOCS_ASSERT(I);
visitor.finalize(*I);
}
}

} // mrdocs
Expand Down
1 change: 1 addition & 0 deletions src/lib/Metadata/Javadoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ makeOverview(
for(auto it = list.begin();
it != list.end(); ++it)
{
MRDOCS_ASSERT(*it);
switch((*it)->kind)
{
case doc::Kind::brief:
Expand Down
5 changes: 3 additions & 2 deletions src/lib/Support/NameParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ class IdExpressionParser
case '(':
case '[':
{
++s_;
commit();
char close = first == '(' ? ')' : ']';
if(skipWhitespace() || *s_ != close)
Expand Down Expand Up @@ -484,19 +485,19 @@ parseIdExpression(
bool allow_wildcards)
{
MRDOCS_ASSERT(! str.empty());
ParseResult result;
try
{
ParseResult result;
if(allow_wildcards)
IdExpressionParser<true>(str, result).parse();
else
IdExpressionParser<false>(str, result).parse();
return std::move(result);
}
catch(const Exception& ex)
{
return Unexpected(ex.error());
}
return result;
}

} // mrdocs
Expand Down
Loading

0 comments on commit 8de57e2

Please sign in to comment.