From f65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Tue, 29 Oct 2024 14:49:26 +0800 Subject: format * format * Minor test fixes * enable checking cpp format in ci --- source/slang/slang-doc-markdown-writer.cpp | 512 ++++++++++++++++++----------- 1 file changed, 315 insertions(+), 197 deletions(-) (limited to 'source/slang/slang-doc-markdown-writer.cpp') diff --git a/source/slang/slang-doc-markdown-writer.cpp b/source/slang/slang-doc-markdown-writer.cpp index 79bec1402..2c0e6a040 100644 --- a/source/slang/slang-doc-markdown-writer.cpp +++ b/source/slang/slang-doc-markdown-writer.cpp @@ -1,20 +1,20 @@ // slang-doc-markdown-writer.cpp #include "slang-doc-markdown-writer.h" -#include "../core/slang-string-util.h" -#include "../core/slang-type-text-util.h" #include "../core/slang-char-util.h" +#include "../core/slang-string-util.h" #include "../core/slang-token-reader.h" - +#include "../core/slang-type-text-util.h" #include "slang-ast-builder.h" #include "slang-lookup.h" -namespace Slang { +namespace Slang +{ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DocMarkDownWriter !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ -template +template static void _getDecls(ContainerDecl* containerDecl, List& out) { for (Decl* decl : containerDecl->members) @@ -26,8 +26,11 @@ static void _getDecls(ContainerDecl* containerDecl, List& out) } } -template -static void _getDeclsOfType(DocMarkdownWriter* writer, ContainerDecl* containerDecl, List& out) +template +static void _getDeclsOfType( + DocMarkdownWriter* writer, + ContainerDecl* containerDecl, + List& out) { for (Decl* decl : containerDecl->members) { @@ -49,7 +52,7 @@ static void _getDeclsOfType(DocMarkdownWriter* writer, ContainerDecl* containerD } } -template +template static void _getDeclsOfType(DocMarkdownWriter* writer, DocumentPage* page, List& out) { // Collect all decls of type T from all entries for the page. @@ -70,10 +73,11 @@ static void _getDeclsOfType(DocMarkdownWriter* writer, DocumentPage* page, List< if (pair.first) out.add(pair.second); } - out.sort([](Decl* a, Decl* b) -> bool { return getText(a->getName()) < getText(b->getName()); }); + out.sort( + [](Decl* a, Decl* b) -> bool { return getText(a->getName()) < getText(b->getName()); }); } -template +template static void _toList(FilteredMemberList& list, List& out) { for (Decl* decl : list) @@ -96,7 +100,10 @@ String getDocPath(const DocumentationConfig& config, String path) return config.rootDir + Path::getPathWithoutExt(path); } -void DocMarkdownWriter::_appendAsBullets(const List& values, bool insertLinkForName, char wrapChar) +void DocMarkdownWriter::_appendAsBullets( + const List& values, + bool insertLinkForName, + char wrapChar) { auto& out = *m_builder; for (const auto& value : values) @@ -114,7 +121,7 @@ void DocMarkdownWriter::_appendAsBullets(const List& values, bool i } out.appendChar(wrapChar); out << name; - out.appendChar(wrapChar); + out.appendChar(wrapChar); if (path.getLength()) { out << "](" << getDocPath(m_config, path) << ")"; @@ -340,7 +347,9 @@ String DocMarkdownWriter::_getName(InheritanceDecl* decl) return buf.produceString(); } -DocMarkdownWriter::NameAndText DocMarkdownWriter::_getNameAndText(ASTMarkup::Entry* entry, Decl* decl) +DocMarkdownWriter::NameAndText DocMarkdownWriter::_getNameAndText( + ASTMarkup::Entry* entry, + Decl* decl) { NameAndText nameAndText; @@ -459,7 +468,7 @@ void DocMarkdownWriter::_appendCommaList(const List& strings, char wrapC } } -/* static */void DocMarkdownWriter::getSignature(const List& parts, Signature& outSig) +/* static */ void DocMarkdownWriter::getSignature(const List& parts, Signature& outSig) { const Index count = parts.getCount(); for (Index i = 0; i < count; ++i) @@ -467,7 +476,7 @@ void DocMarkdownWriter::_appendCommaList(const List& strings, char wrapC const auto& part = parts[i]; switch (part.type) { - case Part::Type::ParamType: + case Part::Type::ParamType: { PartPair pair; pair.first = part; @@ -479,22 +488,22 @@ void DocMarkdownWriter::_appendCommaList(const List& strings, char wrapC outSig.params.add(pair); break; } - case Part::Type::ReturnType: + case Part::Type::ReturnType: { outSig.returnType = part; break; } - case Part::Type::DeclPath: + case Part::Type::DeclPath: { outSig.name = part; break; } - case Part::Type::GenericParamValue: - case Part::Type::GenericParamType: + case Part::Type::GenericParamValue: + case Part::Type::GenericParamType: { Signature::GenericParam genericParam; genericParam.name = part; - + if ((i + 1) < count && parts[i + 1].type == Part::Type::GenericParamValueType) { genericParam.type = parts[i + 1]; @@ -505,7 +514,7 @@ void DocMarkdownWriter::_appendCommaList(const List& strings, char wrapC break; } - default: break; + default: break; } } } @@ -520,7 +529,7 @@ void escapeHTMLContent(StringBuilder& sb, UnownedStringSlice str) case '>': sb << ">"; break; case '&': sb << "&"; break; case '"': sb << """; break; - default: sb.appendChar(ch); break; + default: sb.appendChar(ch); break; } } } @@ -528,7 +537,7 @@ void escapeHTMLContent(StringBuilder& sb, UnownedStringSlice str) void DocMarkdownWriter::writeVar(const ASTMarkup::Entry& entry, VarDecl* varDecl) { auto& out = *m_builder; - + ASTPrinter printer(m_astBuilder); printer.addDeclPath(DeclRef(varDecl)); @@ -618,7 +627,7 @@ void DocMarkdownWriter::writeProperty(const ASTMarkup::Entry& entry, PropertyDec } } out << "}\n\n\n"; - + declDoc.writeSection(out, this, propertyDecl, DocPageSection::ReturnInfo); declDoc.writeSection(out, this, propertyDecl, DocPageSection::Remarks); declDoc.writeSection(out, this, propertyDecl, DocPageSection::Example); @@ -633,7 +642,7 @@ void DocMarkdownWriter::writeTypeDef(const ASTMarkup::Entry& entry, TypeDefDecl* ASTMarkup::Entry newEntry = entry; _appendAggTypeName(newEntry, typeDefDecl); out << toSlice("\n\n"); - + DeclDocumentation declDoc; declDoc.parse(entry.m_markup.getUnownedSlice()); registerCategory(m_currentPage, declDoc); @@ -728,7 +737,11 @@ void DocMarkdownWriter::writeAttribute(const ASTMarkup::Entry& entry, AttributeD declDoc.writeSection(out, this, attributeDecl, DocPageSection::SeeAlso); } -void DocMarkdownWriter::writeExtensionConditions(StringBuilder& out, ExtensionDecl* extensionDecl, const char* prefix, bool isHtml) +void DocMarkdownWriter::writeExtensionConditions( + StringBuilder& out, + ExtensionDecl* extensionDecl, + const char* prefix, + bool isHtml) { // Synthesize `where` clause for things defined in an extension. auto targetTypeDeclRef = isDeclRefTypeOf(extensionDecl->targetType); @@ -753,7 +766,8 @@ void DocMarkdownWriter::writeExtensionConditions(StringBuilder& out, ExtensionDe // Locate the original generic parameter defined on the type being extended. Decl* originalParamDecl = nullptr; - if (auto targetTypeParentGenericDecl = as(targetTypeDeclRef.getDecl()->parentDecl)) + if (auto targetTypeParentGenericDecl = + as(targetTypeDeclRef.getDecl()->parentDecl)) { for (auto member : targetTypeParentGenericDecl->members) { @@ -784,16 +798,18 @@ void DocMarkdownWriter::writeExtensionConditions(StringBuilder& out, ExtensionDe Val* constraintVal = nullptr; if (genericParamDecl) { - // If we have `TargetType` the member belongs to `extension TargetType`, - // We want to print a synthesized `where T : C` clause. - // Here `extTypeParamDecl` is a reference to `X`, so we need to find the corresponding `T`. + // If we have `TargetType` the member belongs to `extension + // TargetType`, We want to print a synthesized `where T : C` clause. Here + // `extTypeParamDecl` is a reference to `X`, so we need to find the corresponding + // `T`. // Find constraints on the originalParamDecl. for (auto member : genericParamDecl->parentDecl->members) { if (auto typeConstraint = as(member)) { - if (isDeclRefTypeOf(typeConstraint->sub.type).getDecl() == genericParamDecl) + if (isDeclRefTypeOf(typeConstraint->sub.type).getDecl() == + genericParamDecl) { if (typeConstraint->isEqualityConstraint) { @@ -807,9 +823,9 @@ void DocMarkdownWriter::writeExtensionConditions(StringBuilder& out, ExtensionDe } else { - // If we have `extension TargetType` where `Y` does not name a generic parameter defined - // on the extension itself, we want to print a synthesized `where T == Y` clause, where - // `T` is the original generic parameter on the target type. + // If we have `extension TargetType` where `Y` does not name a generic parameter + // defined on the extension itself, we want to print a synthesized `where T == Y` + // clause, where `T` is the original generic parameter on the target type. isEqualityConstraint = true; constraintVal = arg; } @@ -817,7 +833,9 @@ void DocMarkdownWriter::writeExtensionConditions(StringBuilder& out, ExtensionDe { out << prefix; if (isHtml) - out << translateToHTMLWithLinks(originalParamDecl, originalParamDecl->getName()->text); + out << translateToHTMLWithLinks( + originalParamDecl, + originalParamDecl->getName()->text); else out << translateToMarkdownWithLinks(originalParamDecl->getName()->text); if (isEqualityConstraint) @@ -843,8 +861,11 @@ void DocMarkdownWriter::writeSignature(CallableDecl* callableDecl) } List parts; - - ASTPrinter printer(m_astBuilder, ASTPrinter::OptionFlag::ParamNames | ASTPrinter::OptionFlag::NoSpecializedExtensionTypeName, &parts); + + ASTPrinter printer( + m_astBuilder, + ASTPrinter::OptionFlag::ParamNames | ASTPrinter::OptionFlag::NoSpecializedExtensionTypeName, + &parts); printer.addDeclSignature(makeDeclRef(callableDecl)); Signature signature; @@ -865,20 +886,21 @@ void DocMarkdownWriter::writeSignature(CallableDecl* callableDecl) switch (paramCount) { - case 0: + case 0: { // Has no parameters out << toSlice("()"); break; } - case 1: + case 1: { if (signature.name.end - signature.name.start < 40) { // Place all on single line out.appendChar('('); const auto& param = signature.params[0]; - out << translateToHTMLWithLinks(callableDecl, printer.getPartSlice(param.first)) << toSlice(" "); + out << translateToHTMLWithLinks(callableDecl, printer.getPartSlice(param.first)) + << toSlice(" "); out << translateToHTMLWithLinks(callableDecl, printer.getPartSlice(param.second)); out << ")"; break; @@ -886,7 +908,7 @@ void DocMarkdownWriter::writeSignature(CallableDecl* callableDecl) // If the name is already long, fall through to default. [[fallthrough]]; } - default: + default: { // Put each parameter on a line on it's own out << toSlice("(\n"); @@ -896,7 +918,8 @@ void DocMarkdownWriter::writeSignature(CallableDecl* callableDecl) const auto& param = signature.params[i]; line.clear(); - line << " " << translateToHTMLWithLinks(callableDecl, printer.getPartSlice(param.first)); + line << " " + << translateToHTMLWithLinks(callableDecl, printer.getPartSlice(param.first)); line.appendChar(' '); line << translateToHTMLWithLinks(callableDecl, printer.getPartSlice(param.second)); @@ -922,8 +945,13 @@ void DocMarkdownWriter::writeSignature(CallableDecl* callableDecl) // Synthesize `where` clause for things defined in an extension. if (auto targetTypeDeclRef = isDeclRefTypeOf(extensionDecl->targetType)) { - writeExtensionConditions(out, extensionDecl, "\n where ", true); - // We need to follow the parent of the target type instead of the parent of the extension decl. + writeExtensionConditions( + out, + extensionDecl, + "\n where ", + true); + // We need to follow the parent of the target type instead of the parent of the + // extension decl. parentDecl = getParentDecl(targetTypeDeclRef.getDecl()); continue; } @@ -936,12 +964,16 @@ void DocMarkdownWriter::writeSignature(CallableDecl* callableDecl) if (auto typeConstraint = as(member)) { out << toSlice("\n where "); - out << translateToHTMLWithLinks(parentDecl, getSub(m_astBuilder, typeConstraint)->toString()); + out << translateToHTMLWithLinks( + parentDecl, + getSub(m_astBuilder, typeConstraint)->toString()); if (typeConstraint->isEqualityConstraint) out << " == "; else out << toSlice(" : "); - out << translateToHTMLWithLinks(parentDecl, getSup(m_astBuilder, typeConstraint)->toString()); + out << translateToHTMLWithLinks( + parentDecl, + getSup(m_astBuilder, typeConstraint)->toString()); } } } @@ -950,7 +982,9 @@ void DocMarkdownWriter::writeSignature(CallableDecl* callableDecl) out << ";\n"; } -List DocMarkdownWriter::_getUniqueParams(const List& decls, DeclDocumentation* funcDoc) +List DocMarkdownWriter::_getUniqueParams( + const List& decls, + DeclDocumentation* funcDoc) { List out; @@ -1000,7 +1034,9 @@ List DocMarkdownWriter::_getUniqueParams(const L return out; } -static Index _addRequirement(const DocMarkdownWriter::Requirement& req, List& ioReqs) +static Index _addRequirement( + const DocMarkdownWriter::Requirement& req, + List& ioReqs) { auto index = ioReqs.indexOf(req); if (index < 0) @@ -1013,7 +1049,7 @@ static Index _addRequirement(const DocMarkdownWriter::Requirement& req, List& ioReqs) { - return _addRequirement(DocMarkdownWriter::Requirement{ set }, ioReqs); + return _addRequirement(DocMarkdownWriter::Requirement{set}, ioReqs); } static Index _addRequirements(Decl* decl, List& ioReqs) @@ -1102,15 +1138,17 @@ void DocMarkdownWriter::_appendRequirements(const Requirement& requirement) m_builder->append("\n"); - // TODO: We should probably print the capabilities for each stage set if the requirements differ between - // different stages, but for now we'll just print the first one, assuming the rest are the same. - // This is currently true for most if not all of our core module decls. + // TODO: We should probably print the capabilities for each stage set if the requirements + // differ between different stages, but for now we'll just print the first one, assuming the + // rest are the same. This is currently true for most if not all of our core module decls. // if (targetSet.second.shaderStageSets.getCount() > 0 && targetSet.second.shaderStageSets.begin()->second.atomSet.has_value()) { List capabilities; - auto atomSet = targetSet.second.shaderStageSets.begin()->second.atomSet.value().newSetWithoutImpliedAtoms(); + auto atomSet = targetSet.second.shaderStageSets.begin() + ->second.atomSet.value() + .newSetWithoutImpliedAtoms(); for (auto atom : atomSet) { // If the requirement atom is the target or stage atom, don't repeat ourselves. @@ -1141,28 +1179,30 @@ void DocMarkdownWriter::_appendRequirements(const Requirement& requirement) } } -void DocMarkdownWriter::_maybeAppendRequirements(const UnownedStringSlice& title, const List& uniqueRequirements) +void DocMarkdownWriter::_maybeAppendRequirements( + const UnownedStringSlice& title, + const List& uniqueRequirements) { - auto& out = *m_builder; - const Index uniqueCount = uniqueRequirements.getCount(); + auto& out = *m_builder; + const Index uniqueCount = uniqueRequirements.getCount(); - if (uniqueCount <= 0) - { - return; - } + if (uniqueCount <= 0) + { + return; + } - if (uniqueCount == 1) - { - const auto& reqs = uniqueRequirements[0]; + if (uniqueCount == 1) + { + const auto& reqs = uniqueRequirements[0]; - out << title; + out << title; - _appendRequirements(reqs); - out << toSlice("\n"); - } - else - { - out << title; + _appendRequirements(reqs); + out << toSlice("\n"); + } + else + { + out << title; for (Index i = 0; i < uniqueCount; ++i) { @@ -1170,9 +1210,9 @@ void DocMarkdownWriter::_maybeAppendRequirements(const UnownedStringSlice& title _appendRequirements(uniqueRequirements[i]); out << toSlice("\n"); } - } + } - out << toSlice("\n"); + out << toSlice("\n"); } static Decl* _getSameNameDecl(ContainerDecl* parentDecl, Decl* decl) @@ -1204,14 +1244,15 @@ void ParsedDescription::write(DocMarkdownWriter* writer, Decl* decl, StringBuild { switch (span.kind) { - case DocumentationSpanKind::OrdinaryText: + case DocumentationSpanKind::OrdinaryText: { out << span.text; break; } - case DocumentationSpanKind::InlineCode: + case DocumentationSpanKind::InlineCode: { - out << "" << writer->translateToHTMLWithLinks(decl, span.text) << ""; + out << "" << writer->translateToHTMLWithLinks(decl, span.text) + << ""; break; } } @@ -1233,8 +1274,8 @@ void ParsedDescription::parse(UnownedStringSlice text) if (line.startsWith("```")) { isInCodeBlock = !isInCodeBlock; - spans.add({ line, DocumentationSpanKind::OrdinaryText}); - spans.add({ toSlice("\n"), DocumentationSpanKind::OrdinaryText }); + spans.add({line, DocumentationSpanKind::OrdinaryText}); + spans.add({toSlice("\n"), DocumentationSpanKind::OrdinaryText}); codeBlockIndent = originalLine.indexOf('`'); continue; } @@ -1250,9 +1291,10 @@ void ParsedDescription::parse(UnownedStringSlice text) { if (currentSpanEnd > currentSpanStart) { - spans.add({ - UnownedStringSlice(currentSpanStart, line.begin() + i), - isInCode ? DocumentationSpanKind::InlineCode : DocumentationSpanKind::OrdinaryText }); + spans.add( + {UnownedStringSlice(currentSpanStart, line.begin() + i), + isInCode ? DocumentationSpanKind::InlineCode + : DocumentationSpanKind::OrdinaryText}); currentSpanEnd = currentSpanStart = line.begin() + i + 1; } isInCode = !isInCode; @@ -1264,10 +1306,11 @@ void ParsedDescription::parse(UnownedStringSlice text) } if (currentSpanEnd > currentSpanStart) { - spans.add({ UnownedStringSlice(currentSpanStart, currentSpanEnd), - DocumentationSpanKind::OrdinaryText }); + spans.add( + {UnownedStringSlice(currentSpanStart, currentSpanEnd), + DocumentationSpanKind::OrdinaryText}); } - spans.add({ toSlice("\n"), DocumentationSpanKind::OrdinaryText }); + spans.add({toSlice("\n"), DocumentationSpanKind::OrdinaryText}); } else { @@ -1283,8 +1326,8 @@ void ParsedDescription::parse(UnownedStringSlice text) break; } } - spans.add({ line, DocumentationSpanKind::OrdinaryText }); - spans.add({ toSlice("\n"), DocumentationSpanKind::OrdinaryText }); + spans.add({line, DocumentationSpanKind::OrdinaryText}); + spans.add({toSlice("\n"), DocumentationSpanKind::OrdinaryText}); } } } @@ -1407,9 +1450,7 @@ void DeclDocumentation::parse(const UnownedStringSlice& text) { case DocPageSection::ExperimentalCallout: case DocPageSection::InternalCallout: - case DocPageSection::DeprecatedCallout: - currentSection = DocPageSection::Description; - break; + case DocPageSection::DeprecatedCallout: currentSection = DocPageSection::Description; break; } } for (auto& kv : sectionBuilders) @@ -1418,7 +1459,10 @@ void DeclDocumentation::parse(const UnownedStringSlice& text) } } -void DocMarkdownWriter::writeCallableOverridable(DocumentPage* page, const ASTMarkup::Entry& primaryEntry, CallableDecl* callableDecl) +void DocMarkdownWriter::writeCallableOverridable( + DocumentPage* page, + const ASTMarkup::Entry& primaryEntry, + CallableDecl* callableDecl) { SLANG_UNUSED(primaryEntry); @@ -1449,7 +1493,10 @@ void DocMarkdownWriter::writeCallableOverridable(DocumentPage* page, const ASTMa if (!descriptionSB.toString().startsWith(markup)) { auto decl = as(entry->m_node); - m_sink->diagnose(decl->loc, Diagnostics::ignoredDocumentationOnOverloadCandidate, decl); + m_sink->diagnose( + decl->loc, + Diagnostics::ignoredDocumentationOnOverloadCandidate, + decl); } } else @@ -1478,9 +1525,12 @@ void DocMarkdownWriter::writeCallableOverridable(DocumentPage* page, const ASTMa { for (auto& entry : page->entries) { - Decl* sameNameDecl = _getSameNameDecl(as(getParentDecl((Decl*)entry->m_node)), callableDecl); + Decl* sameNameDecl = _getSameNameDecl( + as(getParentDecl((Decl*)entry->m_node)), + callableDecl); - for (Decl* curDecl = sameNameDecl; curDecl; curDecl = curDecl->nextInContainerWithSameName) + for (Decl* curDecl = sameNameDecl; curDecl; + curDecl = curDecl->nextInContainerWithSameName) { CallableDecl* sig = nullptr; if (GenericDecl* genericDecl = as(curDecl)) @@ -1507,7 +1557,9 @@ void DocMarkdownWriter::writeCallableOverridable(DocumentPage* page, const ASTMa } // Lets put back into source order - sigs.sort([](CallableDecl* a, CallableDecl* b) -> bool { return a->loc.getRaw() < b->loc.getRaw(); }); + sigs.sort( + [](CallableDecl* a, CallableDecl* b) -> bool + { return a->loc.getRaw() < b->loc.getRaw(); }); } // Maps a sig index to a unique requirements set @@ -1525,13 +1577,13 @@ void DocMarkdownWriter::writeCallableOverridable(DocumentPage* page, const ASTMa } // Output the signature - { + { out << toSlice("## Signature \n\n"); out << toSlice("
\n");
 
         const Int sigCount = sigs.getCount();
         for (Index i = 0; i < sigCount; ++i)
-        {            
+        {
             auto sig = sigs[i];
             // Get the requirements index for this sig
             const Index requirementsIndex = requirementsMap[i];
@@ -1539,7 +1591,8 @@ void DocMarkdownWriter::writeCallableOverridable(DocumentPage* page, const ASTMa
             // Output if needs unique requirements
             if (requirements.getCount() > 1 && requirementsIndex != -1)
             {
-                out << toSlice("/// Requires Capability Set ") << (requirementsIndex + 1) << toSlice(":\n");
+                out << toSlice("/// Requires Capability Set ") << (requirementsIndex + 1)
+                    << toSlice(":\n");
             }
 
             writeSignature(sig);
@@ -1559,16 +1612,15 @@ void DocMarkdownWriter::writeCallableOverridable(DocumentPage* page, const ASTMa
                 GenericDecl* genericDecl = as(sig->parentDecl);
 
                 // NOTE!
-                // Here we assume the names of generic parameters are such that they are 
+                // Here we assume the names of generic parameters are such that they are
 
-                // We list generic parameters, as types of parameters, if they are directly associated with this
-                // callable.
+                // We list generic parameters, as types of parameters, if they are directly
+                // associated with this callable.
                 if (genericDecl)
                 {
                     for (Decl* decl : genericDecl->members)
                     {
-                        if (as(decl) ||
-                            as(decl))
+                        if (as(decl) || as(decl))
                         {
                             genericDecls.add(decl);
                         }
@@ -1654,7 +1706,7 @@ void DocMarkdownWriter::writeEnum(const ASTMarkup::Entry& entry, EnumDecl* enumD
     out << toSlice("## Values \n\n");
 
     _appendAsBullets(_getAsNameAndTextList(enumDecl->getMembersOfType()), false, '_');
-    
+
     declDoc.writeSection(out, this, enumDecl, DocPageSection::Remarks);
     declDoc.writeSection(out, this, enumDecl, DocPageSection::Example);
     declDoc.writeSection(out, this, enumDecl, DocPageSection::SeeAlso);
@@ -1666,7 +1718,7 @@ void DocMarkdownWriter::_appendEscaped(const UnownedStringSlice& text)
 
     const char* start = text.begin();
     const char* cur = start;
-    const char*const end = text.end();
+    const char* const end = text.end();
 
     for (; cur < end; ++cur)
     {
@@ -1674,25 +1726,25 @@ void DocMarkdownWriter::_appendEscaped(const UnownedStringSlice& text)
 
         switch (c)
         {
-            case '<':
-            case '>':
-            case '&':
-            case '"':
-            case '_':
+        case '<':
+        case '>':
+        case '&':
+        case '"':
+        case '_':
             {
                 // Flush if any before
                 if (cur > start)
                 {
                     out.append(start, cur);
                 }
-                // Prefix with the 
+                // Prefix with the
                 out.appendChar('\\');
 
                 // Start will still include the char, for later flushing
                 start = cur;
                 break;
             }
-            default: break;
+        default: break;
         }
     }
 
@@ -1704,7 +1756,9 @@ void DocMarkdownWriter::_appendEscaped(const UnownedStringSlice& text)
 }
 
 
-void DocMarkdownWriter::_appendDerivedFrom(const UnownedStringSlice& prefix, AggTypeDeclBase* aggTypeDecl)
+void DocMarkdownWriter::_appendDerivedFrom(
+    const UnownedStringSlice& prefix,
+    AggTypeDeclBase* aggTypeDecl)
 {
     auto& out = *m_builder;
 
@@ -1774,7 +1828,8 @@ void DocMarkdownWriter::_appendAggTypeName(const ASTMarkup::Entry& entry, Decl*
     }
     else if (as(aggTypeDecl))
     {
-        out << toSlice("interface ") << escapeMarkdownText(printer.getStringBuilder().produceString());
+        out << toSlice("interface ")
+            << escapeMarkdownText(printer.getStringBuilder().produceString());
     }
     else if (ExtensionDecl* extensionDecl = as(aggTypeDecl))
     {
@@ -1783,7 +1838,8 @@ void DocMarkdownWriter::_appendAggTypeName(const ASTMarkup::Entry& entry, Decl*
     }
     else if (as(aggTypeDecl))
     {
-        out << toSlice("typealias ") << escapeMarkdownText(printer.getStringBuilder().produceString());
+        out << toSlice("typealias ")
+            << escapeMarkdownText(printer.getStringBuilder().produceString());
     }
     else
     {
@@ -1791,7 +1847,10 @@ void DocMarkdownWriter::_appendAggTypeName(const ASTMarkup::Entry& entry, Decl*
     }
 }
 
-void DocMarkdownWriter::writeAggType(DocumentPage* page, const ASTMarkup::Entry& primaryEntry, AggTypeDeclBase* aggTypeDecl)
+void DocMarkdownWriter::writeAggType(
+    DocumentPage* page,
+    const ASTMarkup::Entry& primaryEntry,
+    AggTypeDeclBase* aggTypeDecl)
 {
     auto& out = *m_builder;
 
@@ -1875,9 +1934,11 @@ void DocMarkdownWriter::writeAggType(DocumentPage* page, const ASTMarkup::Entry&
                     for (auto inheritanceDecl : inheritanceDecls)
                     {
                         out << "  - ";
-                        out << escapeMarkdownText(getSub(m_astBuilder, inheritanceDecl)->toString());
+                        out << escapeMarkdownText(
+                            getSub(m_astBuilder, inheritanceDecl)->toString());
                         out << " : ";
-                        out << escapeMarkdownText(getSup(m_astBuilder, inheritanceDecl)->toString());
+                        out << escapeMarkdownText(
+                            getSup(m_astBuilder, inheritanceDecl)->toString());
                         out << toSlice("\n");
                     }
                 }
@@ -1915,7 +1976,8 @@ void DocMarkdownWriter::writeAggType(DocumentPage* page, const ASTMarkup::Entry&
         if (uniqueMethods.getCount())
         {
             // Put in source definition order
-            uniqueMethods.sort([](Decl* a, Decl* b) -> bool { return a->loc.getRaw() < b->loc.getRaw(); });
+            uniqueMethods.sort(
+                [](Decl* a, Decl* b) -> bool { return a->loc.getRaw() < b->loc.getRaw(); });
 
             out << "## Methods\n\n";
             _appendAsBullets(_getAsStringList(uniqueMethods), 0);
@@ -1951,7 +2013,7 @@ void DocMarkdownWriter::writeAggType(DocumentPage* page, const ASTMarkup::Entry&
                 out << escapeMarkdownText(inheritanceDecl->base.type->toString());
                 if (nonEmptyLines.getCount() != 0)
                 {
-                    out << "` when the following conditions are met:\n\n";    
+                    out << "` when the following conditions are met:\n\n";
                     for (auto condition : nonEmptyLines)
                     {
                         out << "  * " << condition << "\n";
@@ -1990,9 +2052,7 @@ String DocMarkdownWriter::escapeMarkdownText(String text)
             sb << '\\';
             sb.appendChar(c);
             break;
-        default:
-            sb.appendChar(c);
-            break;
+        default: sb.appendChar(c); break;
         }
     }
     return sb.produceString();
@@ -2011,10 +2071,14 @@ Slang::Misc::Token treatLiteralsAsIdentifier(Slang::Misc::Token token)
     {
         token.Type = Slang::Misc::TokenType::Identifier;
         StringBuilder stringSB;
-        StringEscapeUtil::appendQuoted(StringEscapeUtil::getHandler(StringEscapeUtil::Style::Cpp), token.Content.getUnownedSlice(), stringSB);
+        StringEscapeUtil::appendQuoted(
+            StringEscapeUtil::getHandler(StringEscapeUtil::Style::Cpp),
+            token.Content.getUnownedSlice(),
+            stringSB);
         token.Content = stringSB.produceString();
     }
-    else if (token.Type == Slang::Misc::TokenType::IntLiteral ||
+    else if (
+        token.Type == Slang::Misc::TokenType::IntLiteral ||
         token.Type == Slang::Misc::TokenType::DoubleLiteral)
     {
         token.Type = Slang::Misc::TokenType::Identifier;
@@ -2030,7 +2094,7 @@ String DocMarkdownWriter::translateToMarkdownWithLinks(String text, bool strictC
     Slang::Misc::TokenReader reader(text);
     bool requireSpaceBeforeNextToken = false;
     bool isFirstToken = true;
-    for (; !reader.IsEnd(); )
+    for (; !reader.IsEnd();)
     {
         auto token = treatLiteralsAsIdentifier(reader.ReadToken());
 
@@ -2055,12 +2119,14 @@ String DocMarkdownWriter::translateToMarkdownWithLinks(String text, bool strictC
             }
             String sectionName;
             Decl* referencedDecl = nullptr;
-            auto page = findPageForToken(currentPage.getLast(), tokenContent, sectionName, referencedDecl);
+            auto page =
+                findPageForToken(currentPage.getLast(), tokenContent, sectionName, referencedDecl);
 
             if (isFirstToken && strictChildLookup && page && page->parentPage != m_currentPage)
             {
-                // If we are performing a strict child lookup (for displaying the member list of an agg type),
-                // then we want to ignore any lookup results that refer to a different parent page.
+                // If we are performing a strict child lookup (for displaying the member list of an
+                // agg type), then we want to ignore any lookup results that refer to a different
+                // parent page.
                 page = nullptr;
             }
 
@@ -2088,9 +2154,7 @@ String DocMarkdownWriter::translateToMarkdownWithLinks(String text, bool strictC
             case Slang::Misc::TokenType::Comma:
             case Slang::Misc::TokenType::Dot:
             case Slang::Misc::TokenType::IntLiteral:
-            case Slang::Misc::TokenType::Semicolon:
-                requireSpaceBeforeNextToken = false;
-                break;
+            case Slang::Misc::TokenType::Semicolon:  requireSpaceBeforeNextToken = false; break;
             default:
                 requireSpaceBeforeNextToken = true;
                 sb.appendChar(' ');
@@ -2124,7 +2188,8 @@ bool isKeyword(const UnownedStringSlice& slice)
 {
     if (isDeclKeyword(slice))
         return true;
-    static const char* knownTypeNames[] = { "int", "float", "half", "double", "bool", "void", "uint" };
+    static const char* knownTypeNames[] =
+        {"int", "float", "half", "double", "bool", "void", "uint"};
     for (auto typeName : knownTypeNames)
     {
         if (slice == typeName)
@@ -2141,7 +2206,7 @@ String DocMarkdownWriter::translateToHTMLWithLinks(Decl* decl, String text)
     currentPage.add(m_currentPage);
     Slang::Misc::TokenReader reader(text);
     bool prevIsIdentifier = false;
-    for (; !reader.IsEnd(); )
+    for (; !reader.IsEnd();)
     {
         auto token = treatLiteralsAsIdentifier(reader.ReadToken());
 
@@ -2151,7 +2216,8 @@ String DocMarkdownWriter::translateToHTMLWithLinks(Decl* decl, String text)
                 sb.append(' ');
             String sectionName;
             Decl* referencedDecl = nullptr;
-            auto page = findPageForToken(currentPage.getLast(), token.Content, sectionName, referencedDecl);
+            auto page =
+                findPageForToken(currentPage.getLast(), token.Content, sectionName, referencedDecl);
             if (page)
             {
                 sb.append("(referencedDecl) ||
-                    as(referencedDecl))
+                else if (as(referencedDecl) || as(referencedDecl))
                     sb.append(" class=\"code_type\"");
                 else if (as(referencedDecl))
                     sb.append(" class=\"code_param\"");
@@ -2223,12 +2288,12 @@ const char* getSectionTitle(DocPageSection section)
     switch (section)
     {
     case DocPageSection::Description: return "Description";
-    case DocPageSection::Parameter: return "Parameters";
-    case DocPageSection::ReturnInfo: return "Return value";
-    case DocPageSection::Remarks: return "Remarks";
-    case DocPageSection::Example: return "Example";
-    case DocPageSection::SeeAlso: return "See also";
-    default: return "";
+    case DocPageSection::Parameter:   return "Parameters";
+    case DocPageSection::ReturnInfo:  return "Return value";
+    case DocPageSection::Remarks:     return "Remarks";
+    case DocPageSection::Example:     return "Example";
+    case DocPageSection::SeeAlso:     return "See also";
+    default:                          return "";
     }
 }
 
@@ -2243,7 +2308,10 @@ void DeclDocumentation::writeDescription(StringBuilder& out, DocMarkdownWriter*
     writeSection(out, writer, decl, DocPageSection::Description);
 }
 
-void DeclDocumentation::writeGenericParameters(StringBuilder& out, DocMarkdownWriter* writer, Decl* decl)
+void DeclDocumentation::writeGenericParameters(
+    StringBuilder& out,
+    DocMarkdownWriter* writer,
+    Decl* decl)
 {
     GenericDecl* genericDecl = as(decl->parentDecl);
     if (!genericDecl)
@@ -2253,8 +2321,7 @@ void DeclDocumentation::writeGenericParameters(StringBuilder& out, DocMarkdownWr
     List params;
     for (Decl* member : genericDecl->members)
     {
-        if (as(member) ||
-            as(member))
+        if (as(member) || as(member))
         {
             params.add(member);
         }
@@ -2285,7 +2352,11 @@ void DeclDocumentation::writeGenericParameters(StringBuilder& out, DocMarkdownWr
     }
 }
 
-void DeclDocumentation::writeSection(StringBuilder& out, DocMarkdownWriter* writer, Decl* decl, DocPageSection section)
+void DeclDocumentation::writeSection(
+    StringBuilder& out,
+    DocMarkdownWriter* writer,
+    Decl* decl,
+    DocPageSection section)
 {
     SLANG_UNUSED(decl);
     ParsedDescription* sectionDoc = sections.tryGetValue(section);
@@ -2296,20 +2367,26 @@ void DeclDocumentation::writeSection(StringBuilder& out, DocMarkdownWriter* writ
     {
     case DocPageSection::DeprecatedCallout:
         out << "> #### Deprecated Feature\n";
-        out << "> The feature described in this page is marked as deprecated, and may be removed in a future release.\n";
-        out << "> Users are advised to avoid using this feature, and to migrate to a newer alternative.\n";
+        out << "> The feature described in this page is marked as deprecated, and may be "
+               "removed in a future release.\n";
+        out << "> Users are advised to avoid using this feature, and to migrate to a newer "
+               "alternative.\n";
         out << "\n";
         return;
     case DocPageSection::ExperimentalCallout:
         out << "> #### Experimental Feature\n";
-        out << "> The feature described in this page is marked as experimental, and may be subject to change in future releases.\n";
-        out << "> Users are advised that any code that depend on this feature may not be compilable by future versions of the compiler.\n";
+        out << "> The feature described in this page is marked as experimental, and may be "
+               "subject to change in future releases.\n";
+        out << "> Users are advised that any code that depend on this feature may not be "
+               "compilable by future versions of the compiler.\n";
         out << "\n";
         return;
     case DocPageSection::InternalCallout:
         out << "> #### Internal Feature\n";
-        out << "> The feature described in this page is marked as an internal implementation detail, and is not intended for use by end-users.\n";
-        out << "> Users are advised to avoid using this declaration directly, as it may be removed or changed in future releases.\n";
+        out << "> The feature described in this page is marked as an internal implementation "
+               "detail, and is not intended for use by end-users.\n";
+        out << "> Users are advised to avoid using this declaration directly, as it may be "
+               "removed or changed in future releases.\n";
         out << "\n";
         return;
     }
@@ -2323,14 +2400,10 @@ void DeclDocumentation::writeSection(StringBuilder& out, DocMarkdownWriter* writ
 void DocMarkdownWriter::createPage(ASTMarkup::Entry& entry, Decl* decl)
 {
     // Skip these they will be output as part of their respective 'containers'
-    if (as(decl) ||
-        as(decl) ||
-        as(decl) ||
-        as(decl) ||
-        as(decl) ||
-        as(decl))
+    if (as(decl) || as(decl) || as(decl) ||
+        as(decl) || as(decl) || as(decl))
     {
-        return; 
+        return;
     }
 
     if (CallableDecl* callableDecl = as(decl))
@@ -2387,11 +2460,15 @@ void DocMarkdownWriter::registerCategory(DocumentPage* page, DeclDocumentation&
 
 bool DocMarkdownWriter::isVisible(const Name* name)
 {
-    return name == nullptr || !name->text.startsWith(toSlice("__"))
-        || m_config.visibleDeclNames.contains(getText((Name*)name));
+    return name == nullptr || !name->text.startsWith(toSlice("__")) ||
+           m_config.visibleDeclNames.contains(getText((Name*)name));
 }
 
-DocumentPage* DocMarkdownWriter::findPageForToken(DocumentPage* currentPage, String token, String& outSectionName, Decl*& outDecl)
+DocumentPage* DocMarkdownWriter::findPageForToken(
+    DocumentPage* currentPage,
+    String token,
+    String& outSectionName,
+    Decl*& outDecl)
 {
     while (currentPage)
     {
@@ -2532,7 +2609,7 @@ void DocumentationConfig::parse(UnownedStringSlice config)
     List lines;
     StringUtil::calcLines(config, lines);
     Index ptr = 0;
-    for (;ptr < lines.getCount(); ptr++)
+    for (; ptr < lines.getCount(); ptr++)
     {
         auto line = lines[ptr];
         if (line.startsWith(toSlice("@preamble:")))
@@ -2578,7 +2655,8 @@ void DocumentationConfig::parse(UnownedStringSlice config)
 
 void sortPages(DocumentPage* page)
 {
-    page->children.sort([](DocumentPage* a, DocumentPage* b) -> bool { return a->shortName < b->shortName; });
+    page->children.sort(
+        [](DocumentPage* a, DocumentPage* b) -> bool { return a->shortName < b->shortName; });
 }
 
 void DocMarkdownWriter::generateSectionIndexPage(DocumentPage* page)
@@ -2594,7 +2672,8 @@ void DocMarkdownWriter::generateSectionIndexPage(DocumentPage* page)
 
     for (auto child : page->children)
     {
-        sb << "- [" << escapeMarkdownText(child->shortName) << "](" << getDocPath(m_config, child->path) << ")\n";
+        sb << "- [" << escapeMarkdownText(child->shortName) << "]("
+           << getDocPath(m_config, child->path) << ")\n";
     }
 }
 
@@ -2602,34 +2681,57 @@ DocumentPage* DocMarkdownWriter::writeAll(UnownedStringSlice configStr)
 {
     m_config.parse(configStr);
 
-    auto addBuiltinPage = [&](DocumentPage* parent, UnownedStringSlice path, UnownedStringSlice title, UnownedStringSlice shortTitle)
+    auto addBuiltinPage = [&](DocumentPage* parent,
+                              UnownedStringSlice path,
+                              UnownedStringSlice title,
+                              UnownedStringSlice shortTitle)
+    {
+        RefPtr page = new DocumentPage();
+        page->title = title;
+        page->path = path;
+        page->shortName = shortTitle;
+        page->decl = nullptr;
+        if (parent)
         {
-            RefPtr page = new DocumentPage();
-            page->title = title;
-            page->path = path;
-            page->shortName = shortTitle;
-            page->decl = nullptr;
-            if (parent)
-            {
-                parent->children.add(page);
-            }
-            m_output[page->path] = page;
-            return page.get();
-        };
-    m_rootPage = addBuiltinPage(nullptr, toSlice("index.md"), m_config.title.getUnownedSlice(), toSlice("Core Module Reference"));
+            parent->children.add(page);
+        }
+        m_output[page->path] = page;
+        return page.get();
+    };
+    m_rootPage = addBuiltinPage(
+        nullptr,
+        toSlice("index.md"),
+        m_config.title.getUnownedSlice(),
+        toSlice("Core Module Reference"));
     m_rootPage->skipWrite = true;
 
-    m_interfacesPage = addBuiltinPage(m_rootPage.get(), toSlice("interfaces/index.md"), toSlice("Interfaces"), toSlice("Interfaces"));
-    m_typesPage = addBuiltinPage(m_rootPage.get(), toSlice("types/index.md"), toSlice("Types"), toSlice("Types"));
-    m_attributesPage = addBuiltinPage(m_rootPage.get(), toSlice("attributes/index.md"), toSlice("Attributes"), toSlice("Attributes"));
-    m_globalDeclsPage = addBuiltinPage(m_rootPage.get(), toSlice("global-decls/index.md"), toSlice("Global Declarations"), toSlice("Global Declarations"));
+    m_interfacesPage = addBuiltinPage(
+        m_rootPage.get(),
+        toSlice("interfaces/index.md"),
+        toSlice("Interfaces"),
+        toSlice("Interfaces"));
+    m_typesPage = addBuiltinPage(
+        m_rootPage.get(),
+        toSlice("types/index.md"),
+        toSlice("Types"),
+        toSlice("Types"));
+    m_attributesPage = addBuiltinPage(
+        m_rootPage.get(),
+        toSlice("attributes/index.md"),
+        toSlice("Attributes"),
+        toSlice("Attributes"));
+    m_globalDeclsPage = addBuiltinPage(
+        m_rootPage.get(),
+        toSlice("global-decls/index.md"),
+        toSlice("Global Declarations"),
+        toSlice("Global Declarations"));
 
     // In the first pass, we create all the pages so we can reference them
     // when writing the content.
     for (auto& entry : m_markup->getEntries())
     {
         Decl* decl = as(entry.m_node);
-    
+
         if (decl && isVisible(entry))
         {
             createPage(entry, decl);
@@ -2652,7 +2754,7 @@ void DocMarkdownWriter::writePage(DocumentPage* page)
         return;
     if (page->entries.getCount() == 0)
         return;
-    
+
     m_currentPage = page;
     m_builder = &(page->get());
 
@@ -2710,14 +2812,23 @@ void DocMarkdownWriter::writePageRecursive(DocumentPage* page)
     }
 }
 
-void writeTOCImpl(StringBuilder& sb, DocMarkdownWriter* writer, DocumentationConfig& config, DocumentPage* page);
+void writeTOCImpl(
+    StringBuilder& sb,
+    DocMarkdownWriter* writer,
+    DocumentationConfig& config,
+    DocumentPage* page);
 
-void writeTOCChildren(StringBuilder& sb, DocMarkdownWriter* writer, DocumentationConfig& config, DocumentPage* page)
+void writeTOCChildren(
+    StringBuilder& sb,
+    DocMarkdownWriter* writer,
+    DocumentationConfig& config,
+    DocumentPage* page)
 {
     if (page->children.getCount() == 0)
         return;
 
-    sb << R"(
    )" << "\n"; + sb << R"(
      )" + << "\n"; // Don't sort the root page. if (page->path != "index.md") @@ -2760,11 +2871,12 @@ void writeTOCChildren(StringBuilder& sb, DocMarkdownWriter* writer, Documentatio landingPage->decl = nullptr; landingPage->parentPage = page; landingPage->contentSB << config.preamble; - landingPage->contentSB << "# " << landingPage->title << "\n\nThis category contains the following declarations:\n\n"; + landingPage->contentSB << "# " << landingPage->title + << "\n\nThis category contains the following declarations:\n\n"; for (auto child : categories[cat]) { - landingPage->contentSB << "#### [" << writer->escapeMarkdownText(child->title) << "](" << - getDocPath(config, child->path) << ")\n\n"; + landingPage->contentSB << "#### [" << writer->escapeMarkdownText(child->title) << "](" + << getDocPath(config, child->path) << ")\n\n"; } page->children.add(landingPage); } @@ -2776,7 +2888,11 @@ void writeTOCChildren(StringBuilder& sb, DocMarkdownWriter* writer, Documentatio sb << "
    \n"; } -void writeTOCImpl(StringBuilder& sb, DocMarkdownWriter* writer, DocumentationConfig& config, DocumentPage* page) +void writeTOCImpl( + StringBuilder& sb, + DocMarkdownWriter* writer, + DocumentationConfig& config, + DocumentPage* page) { sb << R"(
  • path) << R"(">)"; escapeHTMLContent(sb, page->shortName.getUnownedSlice()); @@ -2788,9 +2904,8 @@ void writeTOCImpl(StringBuilder& sb, DocMarkdownWriter* writer, DocumentationCon String DocMarkdownWriter::writeTOC() { StringBuilder sb; - sb << R"(
    • )" - << m_config.title << "\n"; + sb << R"(
      • )" + << m_config.title << "\n"; writeTOCChildren(sb, this, m_config, m_rootPage); sb << "
      \n"; return sb.produceString(); @@ -2900,9 +3015,12 @@ void DocumentPage::writeSummary(UnownedStringSlice fileName) _collectStats(stats, this); StringBuilder sb; sb << "documented pages: " << stats.documentedPageCount << "\n"; - sb << "undocumented pages: " << stats.undocumentedPages.getCount() <<"(" - << String(stats.undocumentedPages.getCount() / (float)(stats.documentedPageCount + stats.undocumentedPages.getCount()) * 100, "%.1f") - << "%)\n\n"; + sb << "undocumented pages: " << stats.undocumentedPages.getCount() << "(" + << String( + stats.undocumentedPages.getCount() / + (float)(stats.documentedPageCount + stats.undocumentedPages.getCount()) * 100, + "%.1f") + << "%)\n\n"; for (auto page : stats.undocumentedPages) sb << page << "\n"; File::writeAllText(fileName, sb.produceString()); -- cgit v1.2.3