[llvm-branch-commits] [clang-tools-extra] [clang-doc] Precommit friends test (PR #146164)
https://github.com/evelez7 created https://github.com/llvm/llvm-project/pull/146164 None >From bf66a99ae2cb8ae90be8b905fedc60d4e10d3c5e Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Thu, 26 Jun 2025 20:51:33 -0700 Subject: [PATCH] [clang-doc] Precommit friends test --- .../test/clang-doc/json/class.cpp | 41 +++ 1 file changed, 41 insertions(+) diff --git a/clang-tools-extra/test/clang-doc/json/class.cpp b/clang-tools-extra/test/clang-doc/json/class.cpp index bd82b8159e2f9..0715fcefbb785 100644 --- a/clang-tools-extra/test/clang-doc/json/class.cpp +++ b/clang-tools-extra/test/clang-doc/json/class.cpp @@ -23,6 +23,9 @@ struct MyClass { typedef int MyTypedef; class NestedClass; + + friend struct Foo; + template friend void friendFunction(int); protected: int protectedMethod(); @@ -86,6 +89,44 @@ struct MyClass { // CHECK-NEXT:"USR": "{{[0-9A-F]*}}" // CHECK-NEXT: } // CHECK-NEXT:], +// CHECK-NOT: "Friends": [ +// CHECK-NOT: { +// CHECK-NOT: "IsClass": false, +// CHECK-NOT: "Params": [ +// CHECK-NOT: { +// CHECK-NOT: "Name": "", +// CHECK-NOT: "Type": "int" +// CHECK-NOT: } +// CHECK-NOT: ], +// CHECK-NOT: "Reference": { +// CHECK-NOT: "Name": "friendFunction", +// CHECK-NOT: "Path": "", +// CHECK-NOT: "QualName": "friendFunction", +// CHECK-NOT: "USR": "{{[0-9A-F]*}}" +// CHECK-NOT: }, +// CHECK-NOT: "ReturnType": { +// CHECK-NOT: "IsBuiltIn": true, +// CHECK-NOT: "IsTemplate": false, +// CHECK-NOT: "Name": "void", +// CHECK-NOT: "QualName": "void", +// CHECK-NOT: "USR": "" +// CHECK-NOT: }, +// CHECK-NOT: "Template": { +// CHECK-NOT: "Parameters": [ +// CHECK-NOT: "typename T" +// CHECK-NOT: ] +// CHECK-NOT: } +// CHECK-NOT: }, +// CHECK-NOT: { +// CHECK-NOT: "IsClass": true, +// CHECK-NOT: "Reference": { +// CHECK-NOT: "Name": "Foo", +// CHECK-NOT: "Path": "GlobalNamespace", +// CHECK-NOT: "QualName": "Foo", +// CHECK-NOT: "USR": "{{[0-9A-F]*}}" +// CHECK-NOT: }, +// CHECK-NOT: }, +// CHECK-NOT:], // COM: FIXME: FullName is not emitted correctly. // CHECK-NEXT:"FullName": "", // CHECK-NEXT:"IsTypedef": false, ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] serialize friends (PR #146165)
https://github.com/evelez7 created https://github.com/llvm/llvm-project/pull/146165 None >From a373ecb94c6137fb8de62226b9cfbfe8c8840564 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Thu, 26 Jun 2025 20:54:03 -0700 Subject: [PATCH] [clang-doc] serialize friends --- clang-tools-extra/clang-doc/BitcodeReader.cpp | 46 +++ clang-tools-extra/clang-doc/BitcodeWriter.cpp | 27 ++- clang-tools-extra/clang-doc/BitcodeWriter.h | 6 +- clang-tools-extra/clang-doc/HTMLGenerator.cpp | 3 + .../clang-doc/HTMLMustacheGenerator.cpp | 1 + clang-tools-extra/clang-doc/JSONGenerator.cpp | 23 +- clang-tools-extra/clang-doc/MDGenerator.cpp | 4 + .../clang-doc/Representation.cpp | 16 clang-tools-extra/clang-doc/Representation.h | 21 - clang-tools-extra/clang-doc/Serialize.cpp | 53 + clang-tools-extra/clang-doc/YAMLGenerator.cpp | 1 + .../test/clang-doc/json/class.cpp | 76 +-- .../unittests/clang-doc/BitcodeTest.cpp | 2 + 13 files changed, 234 insertions(+), 45 deletions(-) diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp b/clang-tools-extra/clang-doc/BitcodeReader.cpp index fd6f40cff1a4e..2cbf8bf6b2879 100644 --- a/clang-tools-extra/clang-doc/BitcodeReader.cpp +++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp @@ -94,6 +94,7 @@ static llvm::Error decodeRecord(const Record &R, InfoType &Field, case InfoType::IT_typedef: case InfoType::IT_concept: case InfoType::IT_variable: + case InfoType::IT_friend: Field = IT; return llvm::Error::success(); } @@ -111,6 +112,7 @@ static llvm::Error decodeRecord(const Record &R, FieldId &Field, case FieldId::F_child_namespace: case FieldId::F_child_record: case FieldId::F_concept: + case FieldId::F_friend: case FieldId::F_default: Field = F; return llvm::Error::success(); @@ -450,6 +452,15 @@ static llvm::Error parseRecord(const Record &R, unsigned ID, } } +static llvm::Error parseRecord(const Record &R, unsigned ID, StringRef Blob, + FriendInfo *F) { + if (ID == FRIEND_IS_CLASS) { +return decodeRecord(R, F->IsClass, Blob); + } + return llvm::createStringError(llvm::inconvertibleErrorCode(), + "invalid field for Friend"); +} + template static llvm::Expected getCommentInfo(T I) { return llvm::createStringError(llvm::inconvertibleErrorCode(), "invalid type cannot contain CommentInfo"); @@ -525,6 +536,18 @@ template <> llvm::Error addTypeInfo(FunctionInfo *I, FieldTypeInfo &&T) { return llvm::Error::success(); } +template <> llvm::Error addTypeInfo(FriendInfo *I, FieldTypeInfo &&T) { + if (!I->Params) +I->Params.emplace(); + I->Params->emplace_back(std::move(T)); + return llvm::Error::success(); +} + +template <> llvm::Error addTypeInfo(FriendInfo *I, TypeInfo &&T) { + I->ReturnType.emplace(std::move(T)); + return llvm::Error::success(); +} + template <> llvm::Error addTypeInfo(EnumInfo *I, TypeInfo &&T) { I->BaseType = std::move(T); return llvm::Error::success(); @@ -667,6 +690,16 @@ llvm::Error addReference(ConstraintInfo *I, Reference &&R, FieldId F) { "ConstraintInfo cannot contain this Reference"); } +template <> +llvm::Error addReference(FriendInfo *Friend, Reference &&R, FieldId F) { + if (F == FieldId::F_friend) { +Friend->Ref = std::move(R); +return llvm::Error::success(); + } + return llvm::createStringError(llvm::inconvertibleErrorCode(), + "Friend cannot contain this Reference"); +} + template static void addChild(T I, ChildInfoType &&R) { llvm::errs() << "invalid child type for info"; @@ -700,6 +733,9 @@ template <> void addChild(RecordInfo *I, EnumInfo &&R) { template <> void addChild(RecordInfo *I, TypedefInfo &&R) { I->Children.Typedefs.emplace_back(std::move(R)); } +template <> void addChild(RecordInfo *I, FriendInfo &&R) { + I->Friends.emplace_back(std::move(R)); +} // Other types of children: template <> void addChild(EnumInfo *I, EnumValueInfo &&R) { @@ -741,6 +777,9 @@ template <> void addTemplate(FunctionInfo *I, TemplateInfo &&P) { template <> void addTemplate(ConceptInfo *I, TemplateInfo &&P) { I->Template = std::move(P); } +template <> void addTemplate(FriendInfo *I, TemplateInfo &&P) { + I->Template.emplace(std::move(P)); +} // Template specializations go only into template records. template @@ -921,6 +960,10 @@ llvm::Error ClangDocBitcodeReader::readSubBlock(unsigned ID, T I) { case BI_VAR_BLOCK_ID: { return handleSubBlock(ID, I, CreateAddFunc(addChild)); } + case BI_FRIEND_BLOCK_ID: { +return handleSubBlock(ID, I, + CreateAddFunc(addChild)); + } default: return llvm::createStringError(llvm::inconvertibleErrorCode(), "invalid subblock type"); @@ -1032,6 +1075,8 @@ ClangDocBitc
[llvm-branch-commits] [clang-tools-extra] [clang-doc] Precommit friends test (PR #146164)
evelez7 wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.dev/github/pr/llvm/llvm-project/146164?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#146165** https://app.graphite.dev/github/pr/llvm/llvm-project/146165?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#146164** https://app.graphite.dev/github/pr/llvm/llvm-project/146164?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/146164?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#146149** https://app.graphite.dev/github/pr/llvm/llvm-project/146149?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/146164 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] serialize friends (PR #146165)
evelez7 wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.dev/github/pr/llvm/llvm-project/146165?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#146165** https://app.graphite.dev/github/pr/llvm/llvm-project/146165?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/146165?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#146164** https://app.graphite.dev/github/pr/llvm/llvm-project/146164?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#146149** https://app.graphite.dev/github/pr/llvm/llvm-project/146149?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/146165 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] serialize friends (PR #146165)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/146165 >From 8dd16ca8d38692a5d60227bd5a4a133972dac9f6 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Thu, 26 Jun 2025 20:54:03 -0700 Subject: [PATCH] [clang-doc] serialize friends --- clang-tools-extra/clang-doc/BitcodeReader.cpp | 46 +++ clang-tools-extra/clang-doc/BitcodeWriter.cpp | 27 ++- clang-tools-extra/clang-doc/BitcodeWriter.h | 6 +- clang-tools-extra/clang-doc/HTMLGenerator.cpp | 3 + .../clang-doc/HTMLMustacheGenerator.cpp | 1 + clang-tools-extra/clang-doc/JSONGenerator.cpp | 23 +- clang-tools-extra/clang-doc/MDGenerator.cpp | 4 + .../clang-doc/Representation.cpp | 16 clang-tools-extra/clang-doc/Representation.h | 21 - clang-tools-extra/clang-doc/Serialize.cpp | 53 + clang-tools-extra/clang-doc/YAMLGenerator.cpp | 1 + .../test/clang-doc/json/class.cpp | 76 +-- .../unittests/clang-doc/BitcodeTest.cpp | 2 + 13 files changed, 234 insertions(+), 45 deletions(-) diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp b/clang-tools-extra/clang-doc/BitcodeReader.cpp index fd6f40cff1a4e..2cbf8bf6b2879 100644 --- a/clang-tools-extra/clang-doc/BitcodeReader.cpp +++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp @@ -94,6 +94,7 @@ static llvm::Error decodeRecord(const Record &R, InfoType &Field, case InfoType::IT_typedef: case InfoType::IT_concept: case InfoType::IT_variable: + case InfoType::IT_friend: Field = IT; return llvm::Error::success(); } @@ -111,6 +112,7 @@ static llvm::Error decodeRecord(const Record &R, FieldId &Field, case FieldId::F_child_namespace: case FieldId::F_child_record: case FieldId::F_concept: + case FieldId::F_friend: case FieldId::F_default: Field = F; return llvm::Error::success(); @@ -450,6 +452,15 @@ static llvm::Error parseRecord(const Record &R, unsigned ID, } } +static llvm::Error parseRecord(const Record &R, unsigned ID, StringRef Blob, + FriendInfo *F) { + if (ID == FRIEND_IS_CLASS) { +return decodeRecord(R, F->IsClass, Blob); + } + return llvm::createStringError(llvm::inconvertibleErrorCode(), + "invalid field for Friend"); +} + template static llvm::Expected getCommentInfo(T I) { return llvm::createStringError(llvm::inconvertibleErrorCode(), "invalid type cannot contain CommentInfo"); @@ -525,6 +536,18 @@ template <> llvm::Error addTypeInfo(FunctionInfo *I, FieldTypeInfo &&T) { return llvm::Error::success(); } +template <> llvm::Error addTypeInfo(FriendInfo *I, FieldTypeInfo &&T) { + if (!I->Params) +I->Params.emplace(); + I->Params->emplace_back(std::move(T)); + return llvm::Error::success(); +} + +template <> llvm::Error addTypeInfo(FriendInfo *I, TypeInfo &&T) { + I->ReturnType.emplace(std::move(T)); + return llvm::Error::success(); +} + template <> llvm::Error addTypeInfo(EnumInfo *I, TypeInfo &&T) { I->BaseType = std::move(T); return llvm::Error::success(); @@ -667,6 +690,16 @@ llvm::Error addReference(ConstraintInfo *I, Reference &&R, FieldId F) { "ConstraintInfo cannot contain this Reference"); } +template <> +llvm::Error addReference(FriendInfo *Friend, Reference &&R, FieldId F) { + if (F == FieldId::F_friend) { +Friend->Ref = std::move(R); +return llvm::Error::success(); + } + return llvm::createStringError(llvm::inconvertibleErrorCode(), + "Friend cannot contain this Reference"); +} + template static void addChild(T I, ChildInfoType &&R) { llvm::errs() << "invalid child type for info"; @@ -700,6 +733,9 @@ template <> void addChild(RecordInfo *I, EnumInfo &&R) { template <> void addChild(RecordInfo *I, TypedefInfo &&R) { I->Children.Typedefs.emplace_back(std::move(R)); } +template <> void addChild(RecordInfo *I, FriendInfo &&R) { + I->Friends.emplace_back(std::move(R)); +} // Other types of children: template <> void addChild(EnumInfo *I, EnumValueInfo &&R) { @@ -741,6 +777,9 @@ template <> void addTemplate(FunctionInfo *I, TemplateInfo &&P) { template <> void addTemplate(ConceptInfo *I, TemplateInfo &&P) { I->Template = std::move(P); } +template <> void addTemplate(FriendInfo *I, TemplateInfo &&P) { + I->Template.emplace(std::move(P)); +} // Template specializations go only into template records. template @@ -921,6 +960,10 @@ llvm::Error ClangDocBitcodeReader::readSubBlock(unsigned ID, T I) { case BI_VAR_BLOCK_ID: { return handleSubBlock(ID, I, CreateAddFunc(addChild)); } + case BI_FRIEND_BLOCK_ID: { +return handleSubBlock(ID, I, + CreateAddFunc(addChild)); + } default: return llvm::createStringError(llvm::inconvertibleErrorCode(), "invalid subblock type"); @@ -1032,6 +1075,8 @@ ClangDocBitcodeRea
[llvm-branch-commits] [clang-tools-extra] [clang-doc] enable comments in class templates (PR #149565)
@@ -60,6 +60,17 @@ HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: class Shape +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: Abstract base class for shapes. +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: Provides a common interface for different types of shapes. +HTML-SHAPE: +HTML-SHAPE: evelez7 wrote: This only happens in the comment partial. I'm pretty sure it's something in the mustache library because all other templates handle their whitespace fine. I also haven't tested it but the comment partial is the only one that templates itself recursively, so that might have something to do with it. https://github.com/llvm/llvm-project/pull/149565 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] integrate JSON as the source for Mustache templates (PR #149589)
https://github.com/evelez7 created https://github.com/llvm/llvm-project/pull/149589 None >From b36a2d4bc00eee19dae7bd0eaaf08a3b4d8a70a2 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Fri, 18 Jul 2025 13:59:44 -0700 Subject: [PATCH] [clang-doc] integrate JSON as the source for Mustache templates --- .../clang-doc/HTMLMustacheGenerator.cpp | 487 +++--- .../clang-doc/assets/class-template.mustache | 62 +-- .../clang-doc/assets/enum-template.mustache | 12 +- .../assets/function-template.mustache | 2 +- .../assets/namespace-template.mustache| 45 +- .../clang-doc/basic-project.mustache.test | 70 +-- .../test/clang-doc/mustache-index.cpp | 14 +- .../clang-doc/mustache-separate-namespace.cpp | 8 +- .../clang-doc/HTMLMustacheGeneratorTest.cpp | 129 - 9 files changed, 173 insertions(+), 656 deletions(-) diff --git a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp index 7aeaa1b7cf67d..98e2935a8aada 100644 --- a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp +++ b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp @@ -27,6 +27,9 @@ using namespace llvm::mustache; namespace clang { namespace doc { +static Error generateDocForJSON(json::Value &JSON, StringRef Filename, +StringRef Path, raw_fd_ostream &OS, +const ClangDocContext &CDCtx); static Error createFileOpenError(StringRef FileName, std::error_code EC) { return createFileError("cannot open file " + FileName, EC); @@ -132,404 +135,65 @@ Error MustacheHTMLGenerator::generateDocs( return Err; } - // Track which directories we already tried to create. - StringSet<> CreatedDirs; - // Collect all output by file name and create the necessary directories. - StringMap> FileToInfos; - for (const auto &Group : Infos) { -llvm::TimeTraceScope TS("setup directories"); -doc::Info *Info = Group.getValue().get(); - -SmallString<128> Path; -sys::path::native(RootDir, Path); -sys::path::append(Path, Info->getRelativeFilePath("")); -if (!CreatedDirs.contains(Path)) { - if (std::error_code EC = sys::fs::create_directories(Path)) -return createStringError(EC, "failed to create directory '%s'.", - Path.c_str()); - CreatedDirs.insert(Path); -} - -sys::path::append(Path, Info->getFileBaseName() + ".html"); -FileToInfos[Path].push_back(Info); + { +llvm::TimeTraceScope TS("Generate JSON for Mustache"); +if (auto JSONGenerator = findGeneratorByName("json")) { + if (Error Err = JSONGenerator.get()->generateDocs( + RootDir, std::move(Infos), CDCtx)) +return Err; +} else + return JSONGenerator.takeError(); } + StringMap JSONFileMap; { -llvm::TimeTraceScope TS("Generate Docs"); -for (const auto &Group : FileToInfos) { - llvm::TimeTraceScope TS("Info to Doc"); +llvm::TimeTraceScope TS("Iterate JSON files"); +std::error_code EC; +sys::fs::directory_iterator JSONIter(RootDir, EC); +std::vector JSONFiles; +JSONFiles.reserve(Infos.size()); +if (EC) + return createStringError("Failed to create directory iterator."); + +while (JSONIter != sys::fs::directory_iterator()) { + if (EC) +return createStringError(EC, "Failed to iterate directory"); + + auto Path = StringRef(JSONIter->path()); + if (!Path.ends_with(".json")) { +JSONIter.increment(EC); +continue; + } + + auto File = MemoryBuffer::getFile(Path); + if ((EC = File.getError())) +continue; + + auto Parsed = json::parse((*File)->getBuffer()); + if (!Parsed) +return Parsed.takeError(); + std::error_code FileErr; - raw_fd_ostream InfoOS(Group.getKey(), FileErr, sys::fs::OF_None); + SmallString<16> HTMLPath(Path.begin(), Path.end()); + sys::path::replace_extension(HTMLPath, "html"); + raw_fd_ostream InfoOS(HTMLPath, FileErr, sys::fs::OF_None); if (FileErr) -return createFileOpenError(Group.getKey(), FileErr); +return createFileOpenError(Path, FileErr); - for (const auto &Info : Group.getValue()) -if (Error Err = generateDocForInfo(Info, InfoOS, CDCtx)) - return Err; + if (Error Err = generateDocForJSON(*Parsed, sys::path::stem(HTMLPath), + HTMLPath, InfoOS, CDCtx)) +return Err; + JSONIter.increment(EC); } } - return Error::success(); -} - -static json::Value -extractValue(const Location &L, - std::optional RepositoryUrl = std::nullopt) { - Object Obj = Object(); - // TODO: Consider using both Start/End line numbers to improve location report - Obj.insert({"LineNumber", L.StartLineNumber}); - Obj.insert({"Filename", L.Filename}); - - if (!L.IsFileInRootDir || !RepositoryUrl) -return Obj; -
[llvm-branch-commits] [clang-tools-extra] [clang-doc] integrate JSON as the source for Mustache templates (PR #149589)
evelez7 wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.dev/github/pr/llvm/llvm-project/149589?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#149589** https://app.graphite.dev/github/pr/llvm/llvm-project/149589?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/149589?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#149588** https://app.graphite.dev/github/pr/llvm/llvm-project/149588?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/149589 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] enable comments in class templates (PR #149565)
https://github.com/evelez7 closed https://github.com/llvm/llvm-project/pull/149565 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] separate comments into categories (PR #149590)
https://github.com/evelez7 created https://github.com/llvm/llvm-project/pull/149590 Comment categories will allow better comment organization in HTML. Before, comments would just be serialized in whatever order they were written, so groups like params or notes wouldn't be in the same sections. >From e3d56c05866222064ac73da6b93771b7f474f4bc Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Thu, 17 Jul 2025 15:04:20 -0700 Subject: [PATCH] [clang-doc] separate comments into categories Comment categories will allow better comment organization in HTML. Before, comments would just be serialized in whatever order they were written, so groups like params or notes wouldn't be in the same sections. --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 42 +++ .../test/clang-doc/json/class.cpp | 51 +-- .../test/clang-doc/json/concept.cpp | 15 +++--- 3 files changed, 63 insertions(+), 45 deletions(-) diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index 908e23d24d079..d39077583b2e1 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -83,7 +83,21 @@ serializeLocation(const Location &Loc, return LocationObj; } -static json::Value serializeComment(const CommentInfo &I) { +static void insertComment(Object &Description, json::Value &Comment, + std::string Key) { + auto *CommentArray = Description.getArray(Key); + if (!CommentArray) { +auto CommentsArray = json::Array(); +CommentsArray.push_back(Comment); +Description[Key] = std::move(CommentsArray); +Description["Has" + Key] = true; + } else { +CommentArray->push_back(Comment); +Description[Key] = std::move(*CommentArray); + } +} + +static Object serializeComment(const CommentInfo &I, Object &Description) { // taken from PR #142273 Object Obj = Object(); @@ -94,7 +108,7 @@ static json::Value serializeComment(const CommentInfo &I) { auto &CARef = *ChildArr.getAsArray(); CARef.reserve(I.Children.size()); for (const auto &C : I.Children) -CARef.emplace_back(serializeComment(*C)); +CARef.emplace_back(serializeComment(*C, Description)); switch (I.Kind) { case CommentKind::CK_TextComment: { @@ -106,6 +120,8 @@ static json::Value serializeComment(const CommentInfo &I) { Child.insert({"Command", I.Name}); Child.insert({"Children", ChildArr}); Obj.insert({commentKindToString(I.Kind), ChildVal}); +if (I.Name == "brief") + insertComment(Description, ChildVal, "BriefComments"); return Obj; } @@ -137,7 +153,10 @@ static json::Value serializeComment(const CommentInfo &I) { if (!I.CloseName.empty()) Child.insert({"CloseName", I.CloseName}); Child.insert({"Children", ChildArr}); -Obj.insert({commentKindToString(I.Kind), ChildVal}); +if (I.CloseName == "endcode") + insertComment(Description, ChildVal, "CodeComments"); +else if (I.CloseName == "endverbatim") + insertComment(Description, ChildVal, "VerbatimComments"); return Obj; } @@ -210,12 +229,17 @@ serializeCommonAttributes(const Info &I, json::Object &Obj, } if (!I.Description.empty()) { -json::Value DescArray = json::Array(); -auto &DescArrayRef = *DescArray.getAsArray(); -DescArrayRef.reserve(I.Description.size()); -for (const auto &Comment : I.Description) - DescArrayRef.push_back(serializeComment(Comment)); -Obj["Description"] = DescArray; +Object Description = Object(); +// Skip straight to the FullComment's children +auto &Comments = I.Description.at(0).Children; +for (const auto &CommentInfo : Comments) { + json::Value Comment = serializeComment(*CommentInfo, Description); + // Paragraph comments might not be children + if (auto *ParagraphComment = + Comment.getAsObject()->get("ParagraphComment")) +insertComment(Description, *ParagraphComment, "ParagraphComments"); +} +Obj["Description"] = std::move(Description); } // Namespaces aren't SymbolInfos, so they dont have a DefLoc diff --git a/clang-tools-extra/test/clang-doc/json/class.cpp b/clang-tools-extra/test/clang-doc/json/class.cpp index a36358982b019..e8fafca28a956 100644 --- a/clang-tools-extra/test/clang-doc/json/class.cpp +++ b/clang-tools-extra/test/clang-doc/json/class.cpp @@ -33,33 +33,30 @@ struct MyClass { }; // CHECK: { -// CHECK-NEXT:"Description": [ -// CHECK-NEXT: { -// CHECK-NEXT: "FullComment": { -// CHECK-NEXT: "Children": [ -// CHECK-NEXT: { -// CHECK-NEXT: "ParagraphComment": { -// CHECK-NEXT: "Children": [ -// CHECK-NEXT: { -// CHECK-NEXT: "TextComment": " This is a nice class." -// CHECK-NEXT: }, -// CHECK-NEXT: { -// CHECK-NEXT: "TextComment": " It has some
[llvm-branch-commits] [clang-tools-extra] [clang-doc] separate comments into categories (PR #149590)
evelez7 wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.dev/github/pr/llvm/llvm-project/149590?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#149590** https://app.graphite.dev/github/pr/llvm/llvm-project/149590?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/149590?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#149589** https://app.graphite.dev/github/pr/llvm/llvm-project/149589?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#149588** https://app.graphite.dev/github/pr/llvm/llvm-project/149588?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/149590 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] integrate JSON as the source for Mustache templates (PR #149589)
https://github.com/evelez7 edited https://github.com/llvm/llvm-project/pull/149589 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] separate comments into categories (PR #149564)
https://github.com/evelez7 closed https://github.com/llvm/llvm-project/pull/149564 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] integrate JSON as the source for Mustache templates (PR #149589)
https://github.com/evelez7 ready_for_review https://github.com/llvm/llvm-project/pull/149589 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] separate comments into categories (PR #149564)
@@ -210,12 +229,17 @@ serializeCommonAttributes(const Info &I, json::Object &Obj, } if (!I.Description.empty()) { -json::Value DescArray = json::Array(); -auto &DescArrayRef = *DescArray.getAsArray(); -DescArrayRef.reserve(I.Description.size()); -for (const auto &Comment : I.Description) - DescArrayRef.push_back(serializeComment(Comment)); -Obj["Description"] = DescArray; +Object Description = Object(); +// Skip straight to the FullComment's children +auto &Comments = I.Description.at(0).Children; +for (const auto &CommentInfo : Comments) { + json::Value Comment = serializeComment(*CommentInfo, Description); + // Paragraph comments might not be children + if (auto *ParagraphComment = + Comment.getAsObject()->get("ParagraphComment")) +insertComment(Description, *ParagraphComment, "ParagraphComments"); evelez7 wrote: Not really, because all paragraph comments were previously handled. This is meant to signal that there are top level `ParagraphComment`s that can be returned from `serializeComment` that need to be manually inserted into `Description` with this modified scheme. They can't be added like brief comments now are because we can't be sure if the `ParagraphComment` is nested (the text of a brief command is a paragraph comment). So, if the returned comment is a `ParagraphComment`, then it must be a top-level, standalone comment without a command. Maybe this comment could use a revision. https://github.com/llvm/llvm-project/pull/149564 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] separate comments into categories (PR #149564)
https://github.com/evelez7 edited https://github.com/llvm/llvm-project/pull/149564 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] serialize friends (PR #146165)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/146165 >From 318f0c85b9f984ba22873ee76a0e610b07d443e9 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Thu, 26 Jun 2025 20:54:03 -0700 Subject: [PATCH] [clang-doc] serialize friends --- clang-tools-extra/clang-doc/BitcodeReader.cpp | 46 +++ clang-tools-extra/clang-doc/BitcodeWriter.cpp | 27 ++- clang-tools-extra/clang-doc/BitcodeWriter.h | 6 +- clang-tools-extra/clang-doc/HTMLGenerator.cpp | 3 + .../clang-doc/HTMLMustacheGenerator.cpp | 1 + clang-tools-extra/clang-doc/JSONGenerator.cpp | 23 +- clang-tools-extra/clang-doc/MDGenerator.cpp | 4 + .../clang-doc/Representation.cpp | 16 clang-tools-extra/clang-doc/Representation.h | 21 - clang-tools-extra/clang-doc/Serialize.cpp | 55 ++ clang-tools-extra/clang-doc/YAMLGenerator.cpp | 1 + .../test/clang-doc/json/class.cpp | 76 +-- .../unittests/clang-doc/BitcodeTest.cpp | 2 + 13 files changed, 236 insertions(+), 45 deletions(-) diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp b/clang-tools-extra/clang-doc/BitcodeReader.cpp index fd6f40cff1a4e..2cbf8bf6b2879 100644 --- a/clang-tools-extra/clang-doc/BitcodeReader.cpp +++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp @@ -94,6 +94,7 @@ static llvm::Error decodeRecord(const Record &R, InfoType &Field, case InfoType::IT_typedef: case InfoType::IT_concept: case InfoType::IT_variable: + case InfoType::IT_friend: Field = IT; return llvm::Error::success(); } @@ -111,6 +112,7 @@ static llvm::Error decodeRecord(const Record &R, FieldId &Field, case FieldId::F_child_namespace: case FieldId::F_child_record: case FieldId::F_concept: + case FieldId::F_friend: case FieldId::F_default: Field = F; return llvm::Error::success(); @@ -450,6 +452,15 @@ static llvm::Error parseRecord(const Record &R, unsigned ID, } } +static llvm::Error parseRecord(const Record &R, unsigned ID, StringRef Blob, + FriendInfo *F) { + if (ID == FRIEND_IS_CLASS) { +return decodeRecord(R, F->IsClass, Blob); + } + return llvm::createStringError(llvm::inconvertibleErrorCode(), + "invalid field for Friend"); +} + template static llvm::Expected getCommentInfo(T I) { return llvm::createStringError(llvm::inconvertibleErrorCode(), "invalid type cannot contain CommentInfo"); @@ -525,6 +536,18 @@ template <> llvm::Error addTypeInfo(FunctionInfo *I, FieldTypeInfo &&T) { return llvm::Error::success(); } +template <> llvm::Error addTypeInfo(FriendInfo *I, FieldTypeInfo &&T) { + if (!I->Params) +I->Params.emplace(); + I->Params->emplace_back(std::move(T)); + return llvm::Error::success(); +} + +template <> llvm::Error addTypeInfo(FriendInfo *I, TypeInfo &&T) { + I->ReturnType.emplace(std::move(T)); + return llvm::Error::success(); +} + template <> llvm::Error addTypeInfo(EnumInfo *I, TypeInfo &&T) { I->BaseType = std::move(T); return llvm::Error::success(); @@ -667,6 +690,16 @@ llvm::Error addReference(ConstraintInfo *I, Reference &&R, FieldId F) { "ConstraintInfo cannot contain this Reference"); } +template <> +llvm::Error addReference(FriendInfo *Friend, Reference &&R, FieldId F) { + if (F == FieldId::F_friend) { +Friend->Ref = std::move(R); +return llvm::Error::success(); + } + return llvm::createStringError(llvm::inconvertibleErrorCode(), + "Friend cannot contain this Reference"); +} + template static void addChild(T I, ChildInfoType &&R) { llvm::errs() << "invalid child type for info"; @@ -700,6 +733,9 @@ template <> void addChild(RecordInfo *I, EnumInfo &&R) { template <> void addChild(RecordInfo *I, TypedefInfo &&R) { I->Children.Typedefs.emplace_back(std::move(R)); } +template <> void addChild(RecordInfo *I, FriendInfo &&R) { + I->Friends.emplace_back(std::move(R)); +} // Other types of children: template <> void addChild(EnumInfo *I, EnumValueInfo &&R) { @@ -741,6 +777,9 @@ template <> void addTemplate(FunctionInfo *I, TemplateInfo &&P) { template <> void addTemplate(ConceptInfo *I, TemplateInfo &&P) { I->Template = std::move(P); } +template <> void addTemplate(FriendInfo *I, TemplateInfo &&P) { + I->Template.emplace(std::move(P)); +} // Template specializations go only into template records. template @@ -921,6 +960,10 @@ llvm::Error ClangDocBitcodeReader::readSubBlock(unsigned ID, T I) { case BI_VAR_BLOCK_ID: { return handleSubBlock(ID, I, CreateAddFunc(addChild)); } + case BI_FRIEND_BLOCK_ID: { +return handleSubBlock(ID, I, + CreateAddFunc(addChild)); + } default: return llvm::createStringError(llvm::inconvertibleErrorCode(), "invalid subblock type"); @@ -1032,6 +1075,8 @@ ClangDocBitcodeRe
[llvm-branch-commits] [clang-tools-extra] [clang-doc] serialize friends (PR #146165)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/146165 >From 318f0c85b9f984ba22873ee76a0e610b07d443e9 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Thu, 26 Jun 2025 20:54:03 -0700 Subject: [PATCH] [clang-doc] serialize friends --- clang-tools-extra/clang-doc/BitcodeReader.cpp | 46 +++ clang-tools-extra/clang-doc/BitcodeWriter.cpp | 27 ++- clang-tools-extra/clang-doc/BitcodeWriter.h | 6 +- clang-tools-extra/clang-doc/HTMLGenerator.cpp | 3 + .../clang-doc/HTMLMustacheGenerator.cpp | 1 + clang-tools-extra/clang-doc/JSONGenerator.cpp | 23 +- clang-tools-extra/clang-doc/MDGenerator.cpp | 4 + .../clang-doc/Representation.cpp | 16 clang-tools-extra/clang-doc/Representation.h | 21 - clang-tools-extra/clang-doc/Serialize.cpp | 55 ++ clang-tools-extra/clang-doc/YAMLGenerator.cpp | 1 + .../test/clang-doc/json/class.cpp | 76 +-- .../unittests/clang-doc/BitcodeTest.cpp | 2 + 13 files changed, 236 insertions(+), 45 deletions(-) diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp b/clang-tools-extra/clang-doc/BitcodeReader.cpp index fd6f40cff1a4e..2cbf8bf6b2879 100644 --- a/clang-tools-extra/clang-doc/BitcodeReader.cpp +++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp @@ -94,6 +94,7 @@ static llvm::Error decodeRecord(const Record &R, InfoType &Field, case InfoType::IT_typedef: case InfoType::IT_concept: case InfoType::IT_variable: + case InfoType::IT_friend: Field = IT; return llvm::Error::success(); } @@ -111,6 +112,7 @@ static llvm::Error decodeRecord(const Record &R, FieldId &Field, case FieldId::F_child_namespace: case FieldId::F_child_record: case FieldId::F_concept: + case FieldId::F_friend: case FieldId::F_default: Field = F; return llvm::Error::success(); @@ -450,6 +452,15 @@ static llvm::Error parseRecord(const Record &R, unsigned ID, } } +static llvm::Error parseRecord(const Record &R, unsigned ID, StringRef Blob, + FriendInfo *F) { + if (ID == FRIEND_IS_CLASS) { +return decodeRecord(R, F->IsClass, Blob); + } + return llvm::createStringError(llvm::inconvertibleErrorCode(), + "invalid field for Friend"); +} + template static llvm::Expected getCommentInfo(T I) { return llvm::createStringError(llvm::inconvertibleErrorCode(), "invalid type cannot contain CommentInfo"); @@ -525,6 +536,18 @@ template <> llvm::Error addTypeInfo(FunctionInfo *I, FieldTypeInfo &&T) { return llvm::Error::success(); } +template <> llvm::Error addTypeInfo(FriendInfo *I, FieldTypeInfo &&T) { + if (!I->Params) +I->Params.emplace(); + I->Params->emplace_back(std::move(T)); + return llvm::Error::success(); +} + +template <> llvm::Error addTypeInfo(FriendInfo *I, TypeInfo &&T) { + I->ReturnType.emplace(std::move(T)); + return llvm::Error::success(); +} + template <> llvm::Error addTypeInfo(EnumInfo *I, TypeInfo &&T) { I->BaseType = std::move(T); return llvm::Error::success(); @@ -667,6 +690,16 @@ llvm::Error addReference(ConstraintInfo *I, Reference &&R, FieldId F) { "ConstraintInfo cannot contain this Reference"); } +template <> +llvm::Error addReference(FriendInfo *Friend, Reference &&R, FieldId F) { + if (F == FieldId::F_friend) { +Friend->Ref = std::move(R); +return llvm::Error::success(); + } + return llvm::createStringError(llvm::inconvertibleErrorCode(), + "Friend cannot contain this Reference"); +} + template static void addChild(T I, ChildInfoType &&R) { llvm::errs() << "invalid child type for info"; @@ -700,6 +733,9 @@ template <> void addChild(RecordInfo *I, EnumInfo &&R) { template <> void addChild(RecordInfo *I, TypedefInfo &&R) { I->Children.Typedefs.emplace_back(std::move(R)); } +template <> void addChild(RecordInfo *I, FriendInfo &&R) { + I->Friends.emplace_back(std::move(R)); +} // Other types of children: template <> void addChild(EnumInfo *I, EnumValueInfo &&R) { @@ -741,6 +777,9 @@ template <> void addTemplate(FunctionInfo *I, TemplateInfo &&P) { template <> void addTemplate(ConceptInfo *I, TemplateInfo &&P) { I->Template = std::move(P); } +template <> void addTemplate(FriendInfo *I, TemplateInfo &&P) { + I->Template.emplace(std::move(P)); +} // Template specializations go only into template records. template @@ -921,6 +960,10 @@ llvm::Error ClangDocBitcodeReader::readSubBlock(unsigned ID, T I) { case BI_VAR_BLOCK_ID: { return handleSubBlock(ID, I, CreateAddFunc(addChild)); } + case BI_FRIEND_BLOCK_ID: { +return handleSubBlock(ID, I, + CreateAddFunc(addChild)); + } default: return llvm::createStringError(llvm::inconvertibleErrorCode(), "invalid subblock type"); @@ -1032,6 +1075,8 @@ ClangDocBitcodeRe
[llvm-branch-commits] [clang-tools-extra] [clang-doc] serialize friends (PR #146165)
https://github.com/evelez7 ready_for_review https://github.com/llvm/llvm-project/pull/146165 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] integrate the JSON generator with Mustache templates (PR #149006)
https://github.com/evelez7 created https://github.com/llvm/llvm-project/pull/149006 This patch changes the HTML Mustache generator to use the JSON generator and consume its output to generate its templates. >From 9f050635fe7181dc08a81cce6f6eb0033051badd Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Thu, 10 Jul 2025 11:40:30 -0700 Subject: [PATCH] [clang-doc] integrate the JSON generator with Mustache templates This patch changes the HTML Mustache generator to use the JSON generator and consume its output to generate its templates. --- clang-tools-extra/clang-doc/BitcodeReader.cpp | 2 + clang-tools-extra/clang-doc/BitcodeWriter.cpp | 4 +- clang-tools-extra/clang-doc/BitcodeWriter.h | 1 + .../clang-doc/HTMLMustacheGenerator.cpp | 474 +++--- clang-tools-extra/clang-doc/JSONGenerator.cpp | 69 ++- .../clang-doc/Representation.cpp | 9 +- clang-tools-extra/clang-doc/Representation.h | 15 + clang-tools-extra/clang-doc/Serialize.cpp | 8 +- .../clang-doc/assets/class-template.mustache | 128 ++--- .../clang-doc/assets/enum-template.mustache | 30 +- .../assets/function-template.mustache | 2 +- .../assets/namespace-template.mustache| 45 +- .../clang-doc/basic-project.mustache.test | 96 ++-- .../test/clang-doc/json/class-requires.cpp| 1 + .../test/clang-doc/json/class-template.cpp| 1 + .../test/clang-doc/json/class.cpp | 21 + .../clang-doc/json/compound-constraints.cpp | 4 + .../test/clang-doc/json/concept.cpp | 2 + .../test/clang-doc/json/function-requires.cpp | 7 + .../test/clang-doc/json/method-template.cpp | 2 + .../test/clang-doc/json/namespace.cpp | 18 + .../test/clang-doc/json/nested-namespace.cpp | 4 + .../test/clang-doc/mustache-index.cpp | 14 +- .../clang-doc/mustache-separate-namespace.cpp | 8 +- .../clang-doc/HTMLMustacheGeneratorTest.cpp | 129 - .../unittests/clang-doc/JSONGeneratorTest.cpp | 26 + 26 files changed, 407 insertions(+), 713 deletions(-) diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp b/clang-tools-extra/clang-doc/BitcodeReader.cpp index dce34a8434ff8..4efbbd34730cf 100644 --- a/clang-tools-extra/clang-doc/BitcodeReader.cpp +++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp @@ -384,6 +384,8 @@ static llvm::Error parseRecord(const Record &R, unsigned ID, return decodeRecord(R, I->Path, Blob); case REFERENCE_FIELD: return decodeRecord(R, F, Blob); + case REFERENCE_FILE: +return decodeRecord(R, I->DocumentationFileName, Blob); default: return llvm::createStringError(llvm::inconvertibleErrorCode(), "invalid field for Reference"); diff --git a/clang-tools-extra/clang-doc/BitcodeWriter.cpp b/clang-tools-extra/clang-doc/BitcodeWriter.cpp index eed23726e17bf..e23511bf63690 100644 --- a/clang-tools-extra/clang-doc/BitcodeWriter.cpp +++ b/clang-tools-extra/clang-doc/BitcodeWriter.cpp @@ -210,6 +210,7 @@ static const llvm::IndexedMap {REFERENCE_TYPE, {"RefType", &genIntAbbrev}}, {REFERENCE_PATH, {"Path", &genStringAbbrev}}, {REFERENCE_FIELD, {"Field", &genIntAbbrev}}, + {REFERENCE_FILE, {"File", &genStringAbbrev}}, {TEMPLATE_PARAM_CONTENTS, {"Contents", &genStringAbbrev}}, {TEMPLATE_SPECIALIZATION_OF, {"SpecializationOf", &genSymbolIdAbbrev}}, @@ -286,7 +287,7 @@ static const std::vector>> // Reference Block {BI_REFERENCE_BLOCK_ID, {REFERENCE_USR, REFERENCE_NAME, REFERENCE_QUAL_NAME, REFERENCE_TYPE, - REFERENCE_PATH, REFERENCE_FIELD}}, + REFERENCE_PATH, REFERENCE_FIELD, REFERENCE_FILE}}, // Template Blocks. {BI_TEMPLATE_BLOCK_ID, {}}, {BI_TEMPLATE_PARAM_BLOCK_ID, {TEMPLATE_PARAM_CONTENTS}}, @@ -479,6 +480,7 @@ void ClangDocBitcodeWriter::emitBlock(const Reference &R, FieldId Field) { emitRecord((unsigned)R.RefType, REFERENCE_TYPE); emitRecord(R.Path, REFERENCE_PATH); emitRecord((unsigned)Field, REFERENCE_FIELD); + emitRecord(R.DocumentationFileName, REFERENCE_FILE); } void ClangDocBitcodeWriter::emitBlock(const FriendInfo &R) { diff --git a/clang-tools-extra/clang-doc/BitcodeWriter.h b/clang-tools-extra/clang-doc/BitcodeWriter.h index 501af12582a8e..688f886b45308 100644 --- a/clang-tools-extra/clang-doc/BitcodeWriter.h +++ b/clang-tools-extra/clang-doc/BitcodeWriter.h @@ -140,6 +140,7 @@ enum RecordId { REFERENCE_TYPE, REFERENCE_PATH, REFERENCE_FIELD, + REFERENCE_FILE, TEMPLATE_PARAM_CONTENTS, TEMPLATE_SPECIALIZATION_OF, TYPEDEF_USR, diff --git a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp index 7aeaa1b7cf67d..a6839edcfe23f 100644 --- a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp +++ b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp @@ -27,6 +27,7 @@ using namespace llvm::mustach
[llvm-branch-commits] [clang-tools-extra] [clang-doc] integrate the JSON generator with Mustache templates (PR #149006)
evelez7 wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.dev/github/pr/llvm/llvm-project/149006?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#149006** https://app.graphite.dev/github/pr/llvm/llvm-project/149006?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/149006?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#148923** https://app.graphite.dev/github/pr/llvm/llvm-project/148923?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/149006 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] separate comments into categories (PR #149564)
evelez7 wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.dev/github/pr/llvm/llvm-project/149564?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#149565** https://app.graphite.dev/github/pr/llvm/llvm-project/149565?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#149564** https://app.graphite.dev/github/pr/llvm/llvm-project/149564?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/149564?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#149006** https://app.graphite.dev/github/pr/llvm/llvm-project/149006?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#148923** https://app.graphite.dev/github/pr/llvm/llvm-project/148923?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/149564 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] enable comments in class templates (PR #149565)
evelez7 wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.dev/github/pr/llvm/llvm-project/149565?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#149565** https://app.graphite.dev/github/pr/llvm/llvm-project/149565?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/149565?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#149564** https://app.graphite.dev/github/pr/llvm/llvm-project/149564?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#149006** https://app.graphite.dev/github/pr/llvm/llvm-project/149006?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#148923** https://app.graphite.dev/github/pr/llvm/llvm-project/148923?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/149565 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] separate comments into categories (PR #149564)
https://github.com/evelez7 created https://github.com/llvm/llvm-project/pull/149564 Comment categories will allow better comment organization in HTML. Before, comments would just be serialized in whatever order they were written, so groups like params or notes wouldn't be in the same sections. >From 959b0786ee630b9258729905edb712ed05b06b08 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Thu, 17 Jul 2025 15:04:20 -0700 Subject: [PATCH] [clang-doc] separate comments into categories Comment categories will allow better comment organization in HTML. Before, comments would just be serialized in whatever order they were written, so groups like params or notes wouldn't be in the same sections. --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 41 +++ .../test/clang-doc/json/class.cpp | 51 +-- .../test/clang-doc/json/concept.cpp | 15 +++--- 3 files changed, 62 insertions(+), 45 deletions(-) diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index 908e23d24d079..5c2cb1c75cfee 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -83,7 +83,20 @@ serializeLocation(const Location &Loc, return LocationObj; } -static json::Value serializeComment(const CommentInfo &I) { +static void insertComment(Object &Description, json::Value &Comment, std::string Key) { + auto *CommentArray = Description.getArray(Key); + if (!CommentArray) { +auto CommentsArray= json::Array(); +CommentsArray.push_back(Comment); +Description[Key] = std::move(CommentsArray); +Description["Has" + Key] = true; + } else { +CommentArray->push_back(Comment); +Description[Key] = std::move(*CommentArray); + } +} + +static Object serializeComment(const CommentInfo &I, Object &Description) { // taken from PR #142273 Object Obj = Object(); @@ -94,7 +107,7 @@ static json::Value serializeComment(const CommentInfo &I) { auto &CARef = *ChildArr.getAsArray(); CARef.reserve(I.Children.size()); for (const auto &C : I.Children) -CARef.emplace_back(serializeComment(*C)); +CARef.emplace_back(serializeComment(*C, Description)); switch (I.Kind) { case CommentKind::CK_TextComment: { @@ -106,6 +119,8 @@ static json::Value serializeComment(const CommentInfo &I) { Child.insert({"Command", I.Name}); Child.insert({"Children", ChildArr}); Obj.insert({commentKindToString(I.Kind), ChildVal}); +if (I.Name == "brief") + insertComment(Description, ChildVal, "BriefComments"); return Obj; } @@ -137,7 +152,10 @@ static json::Value serializeComment(const CommentInfo &I) { if (!I.CloseName.empty()) Child.insert({"CloseName", I.CloseName}); Child.insert({"Children", ChildArr}); -Obj.insert({commentKindToString(I.Kind), ChildVal}); +if (I.CloseName == "endcode") + insertComment(Description, ChildVal, "CodeComments"); +else if (I.CloseName == "endverbatim") + insertComment(Description, ChildVal, "VerbatimComments"); return Obj; } @@ -210,12 +228,17 @@ serializeCommonAttributes(const Info &I, json::Object &Obj, } if (!I.Description.empty()) { -json::Value DescArray = json::Array(); -auto &DescArrayRef = *DescArray.getAsArray(); -DescArrayRef.reserve(I.Description.size()); -for (const auto &Comment : I.Description) - DescArrayRef.push_back(serializeComment(Comment)); -Obj["Description"] = DescArray; +Object Description = Object(); +// Skip straight to the FullComment's children +auto &Comments = I.Description.at(0).Children; +for (const auto &CommentInfo: Comments) +{ + json::Value Comment = serializeComment(*CommentInfo, Description); + // Paragraph comments might not be children + if (auto *ParagraphComment = Comment.getAsObject()->get("ParagraphComment")) +insertComment(Description, *ParagraphComment, "ParagraphComments"); +} +Obj["Description"] = std::move(Description); } // Namespaces aren't SymbolInfos, so they dont have a DefLoc diff --git a/clang-tools-extra/test/clang-doc/json/class.cpp b/clang-tools-extra/test/clang-doc/json/class.cpp index a36358982b019..e8fafca28a956 100644 --- a/clang-tools-extra/test/clang-doc/json/class.cpp +++ b/clang-tools-extra/test/clang-doc/json/class.cpp @@ -33,33 +33,30 @@ struct MyClass { }; // CHECK: { -// CHECK-NEXT:"Description": [ -// CHECK-NEXT: { -// CHECK-NEXT: "FullComment": { -// CHECK-NEXT: "Children": [ -// CHECK-NEXT: { -// CHECK-NEXT: "ParagraphComment": { -// CHECK-NEXT: "Children": [ -// CHECK-NEXT: { -// CHECK-NEXT: "TextComment": " This is a nice class." -// CHECK-NEXT: }, -// CHECK-NEXT: { -// CHECK-NEXT: "TextComment": " It has some nice methods and fields." -// CHECK-
[llvm-branch-commits] [clang-tools-extra] [clang-doc] enable comments in class templates (PR #149565)
https://github.com/evelez7 created https://github.com/llvm/llvm-project/pull/149565 The Mustache basic project has comments in its headers but the comments were not serialized. Now we serialize @brief and paragraph comments for classes and add that output to the basic project test. >From 5c0f49388a7bf1e4e783b897aa1b6a6e8c9553a2 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Fri, 18 Jul 2025 12:04:20 -0700 Subject: [PATCH] [clang-doc] enable comments in class templates The Mustache basic project has comments in its headers but the comments were not serialized. Now we serialize @brief and paragraph comments for classes and add that output to the basic project test. --- .../clang-doc/assets/class-template.mustache | 4 +- .../assets/comment-template.mustache | 9 +++- .../clang-doc/basic-project.mustache.test | 43 +++ 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/class-template.mustache b/clang-tools-extra/clang-doc/assets/class-template.mustache index a4077323f29e2..b1a7470f7c33a 100644 --- a/clang-tools-extra/clang-doc/assets/class-template.mustache +++ b/clang-tools-extra/clang-doc/assets/class-template.mustache @@ -128,11 +128,11 @@ {{TagType}} {{Name}} -{{#RecordComments}} +{{#Description}} {{>Comments}} -{{/RecordComments}} +{{/Description}} {{#HasPublicMembers}} diff --git a/clang-tools-extra/clang-doc/assets/comment-template.mustache b/clang-tools-extra/clang-doc/assets/comment-template.mustache index 723ace7a0eed1..b793bad55cf6c 100644 --- a/clang-tools-extra/clang-doc/assets/comment-template.mustache +++ b/clang-tools-extra/clang-doc/assets/comment-template.mustache @@ -5,11 +5,16 @@ This file defines templates for generating comments }} -{{#FullComment}} +{{#BriefComments}} {{#Children}} {{>Comments}} {{/Children}} -{{/FullComment}} +{{/BriefComments}} +{{#ParagraphComments}} +{{#Children}} +{{>Comments}} +{{/Children}} +{{/ParagraphComments}} {{#ParagraphComment}} {{#Children}} {{>Comments}} diff --git a/clang-tools-extra/test/clang-doc/basic-project.mustache.test b/clang-tools-extra/test/clang-doc/basic-project.mustache.test index 4dd6f4165f65e..4fb38e2b32fcb 100644 --- a/clang-tools-extra/test/clang-doc/basic-project.mustache.test +++ b/clang-tools-extra/test/clang-doc/basic-project.mustache.test @@ -60,6 +60,17 @@ HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: class Shape +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: Abstract base class for shapes. +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: Provides a common interface for different types of shapes. +HTML-SHAPE: +HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: @@ -172,6 +183,16 @@ HTML-CALC: HTML-CALC: HTML-CALC: HTML-CALC: class Calculator +HTML-CALC: +HTML-CALC: A simple calculator class. +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: Provides basic arithmetic operations. +HTML-CALC: +HTML-CALC: HTML-CALC: HTML-CALC: HTML-CALC: @@ -300,6 +321,17 @@ HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE: class Rectangle +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: Rectangle class derived from Shape. +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: Represents a rectangle with a given width and height. +H
[llvm-branch-commits] [clang-tools-extra] [clang-doc] enable comments in class templates (PR #149565)
https://github.com/evelez7 ready_for_review https://github.com/llvm/llvm-project/pull/149565 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] separate comments into categories (PR #149564)
https://github.com/evelez7 ready_for_review https://github.com/llvm/llvm-project/pull/149564 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] separate comments into categories (PR #149564)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/149564 >From 0e6eaa381028afbf23a29aa952da606abd3472bb Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Thu, 17 Jul 2025 15:04:20 -0700 Subject: [PATCH] [clang-doc] separate comments into categories Comment categories will allow better comment organization in HTML. Before, comments would just be serialized in whatever order they were written, so groups like params or notes wouldn't be in the same sections. --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 42 +++ .../test/clang-doc/json/class.cpp | 51 +-- .../test/clang-doc/json/concept.cpp | 15 +++--- 3 files changed, 63 insertions(+), 45 deletions(-) diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index 908e23d24d079..d39077583b2e1 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -83,7 +83,21 @@ serializeLocation(const Location &Loc, return LocationObj; } -static json::Value serializeComment(const CommentInfo &I) { +static void insertComment(Object &Description, json::Value &Comment, + std::string Key) { + auto *CommentArray = Description.getArray(Key); + if (!CommentArray) { +auto CommentsArray = json::Array(); +CommentsArray.push_back(Comment); +Description[Key] = std::move(CommentsArray); +Description["Has" + Key] = true; + } else { +CommentArray->push_back(Comment); +Description[Key] = std::move(*CommentArray); + } +} + +static Object serializeComment(const CommentInfo &I, Object &Description) { // taken from PR #142273 Object Obj = Object(); @@ -94,7 +108,7 @@ static json::Value serializeComment(const CommentInfo &I) { auto &CARef = *ChildArr.getAsArray(); CARef.reserve(I.Children.size()); for (const auto &C : I.Children) -CARef.emplace_back(serializeComment(*C)); +CARef.emplace_back(serializeComment(*C, Description)); switch (I.Kind) { case CommentKind::CK_TextComment: { @@ -106,6 +120,8 @@ static json::Value serializeComment(const CommentInfo &I) { Child.insert({"Command", I.Name}); Child.insert({"Children", ChildArr}); Obj.insert({commentKindToString(I.Kind), ChildVal}); +if (I.Name == "brief") + insertComment(Description, ChildVal, "BriefComments"); return Obj; } @@ -137,7 +153,10 @@ static json::Value serializeComment(const CommentInfo &I) { if (!I.CloseName.empty()) Child.insert({"CloseName", I.CloseName}); Child.insert({"Children", ChildArr}); -Obj.insert({commentKindToString(I.Kind), ChildVal}); +if (I.CloseName == "endcode") + insertComment(Description, ChildVal, "CodeComments"); +else if (I.CloseName == "endverbatim") + insertComment(Description, ChildVal, "VerbatimComments"); return Obj; } @@ -210,12 +229,17 @@ serializeCommonAttributes(const Info &I, json::Object &Obj, } if (!I.Description.empty()) { -json::Value DescArray = json::Array(); -auto &DescArrayRef = *DescArray.getAsArray(); -DescArrayRef.reserve(I.Description.size()); -for (const auto &Comment : I.Description) - DescArrayRef.push_back(serializeComment(Comment)); -Obj["Description"] = DescArray; +Object Description = Object(); +// Skip straight to the FullComment's children +auto &Comments = I.Description.at(0).Children; +for (const auto &CommentInfo : Comments) { + json::Value Comment = serializeComment(*CommentInfo, Description); + // Paragraph comments might not be children + if (auto *ParagraphComment = + Comment.getAsObject()->get("ParagraphComment")) +insertComment(Description, *ParagraphComment, "ParagraphComments"); +} +Obj["Description"] = std::move(Description); } // Namespaces aren't SymbolInfos, so they dont have a DefLoc diff --git a/clang-tools-extra/test/clang-doc/json/class.cpp b/clang-tools-extra/test/clang-doc/json/class.cpp index a36358982b019..e8fafca28a956 100644 --- a/clang-tools-extra/test/clang-doc/json/class.cpp +++ b/clang-tools-extra/test/clang-doc/json/class.cpp @@ -33,33 +33,30 @@ struct MyClass { }; // CHECK: { -// CHECK-NEXT:"Description": [ -// CHECK-NEXT: { -// CHECK-NEXT: "FullComment": { -// CHECK-NEXT: "Children": [ -// CHECK-NEXT: { -// CHECK-NEXT: "ParagraphComment": { -// CHECK-NEXT: "Children": [ -// CHECK-NEXT: { -// CHECK-NEXT: "TextComment": " This is a nice class." -// CHECK-NEXT: }, -// CHECK-NEXT: { -// CHECK-NEXT: "TextComment": " It has some nice methods and fields." -// CHECK-NEXT: }, -// CHECK-NEXT: { -// CHECK-NEXT: "TextComment": "" -// CHECK-NEXT: } -// CHECK-NEXT:
[llvm-branch-commits] [clang-tools-extra] [clang-doc] enable comments in class templates (PR #149565)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/149565 >From 4a076eab44ff05fec172a3c3a94332a19927d9d6 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Fri, 18 Jul 2025 12:04:20 -0700 Subject: [PATCH] [clang-doc] enable comments in class templates The Mustache basic project has comments in its headers but the comments were not serialized. Now we serialize @brief and paragraph comments for classes and add that output to the basic project test. --- .../clang-doc/assets/class-template.mustache | 4 +- .../assets/comment-template.mustache | 9 +++- .../clang-doc/basic-project.mustache.test | 43 +++ 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/class-template.mustache b/clang-tools-extra/clang-doc/assets/class-template.mustache index a4077323f29e2..b1a7470f7c33a 100644 --- a/clang-tools-extra/clang-doc/assets/class-template.mustache +++ b/clang-tools-extra/clang-doc/assets/class-template.mustache @@ -128,11 +128,11 @@ {{TagType}} {{Name}} -{{#RecordComments}} +{{#Description}} {{>Comments}} -{{/RecordComments}} +{{/Description}} {{#HasPublicMembers}} diff --git a/clang-tools-extra/clang-doc/assets/comment-template.mustache b/clang-tools-extra/clang-doc/assets/comment-template.mustache index 723ace7a0eed1..b793bad55cf6c 100644 --- a/clang-tools-extra/clang-doc/assets/comment-template.mustache +++ b/clang-tools-extra/clang-doc/assets/comment-template.mustache @@ -5,11 +5,16 @@ This file defines templates for generating comments }} -{{#FullComment}} +{{#BriefComments}} {{#Children}} {{>Comments}} {{/Children}} -{{/FullComment}} +{{/BriefComments}} +{{#ParagraphComments}} +{{#Children}} +{{>Comments}} +{{/Children}} +{{/ParagraphComments}} {{#ParagraphComment}} {{#Children}} {{>Comments}} diff --git a/clang-tools-extra/test/clang-doc/basic-project.mustache.test b/clang-tools-extra/test/clang-doc/basic-project.mustache.test index 4dd6f4165f65e..4fb38e2b32fcb 100644 --- a/clang-tools-extra/test/clang-doc/basic-project.mustache.test +++ b/clang-tools-extra/test/clang-doc/basic-project.mustache.test @@ -60,6 +60,17 @@ HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: class Shape +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: Abstract base class for shapes. +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: Provides a common interface for different types of shapes. +HTML-SHAPE: +HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: @@ -172,6 +183,16 @@ HTML-CALC: HTML-CALC: HTML-CALC: HTML-CALC: class Calculator +HTML-CALC: +HTML-CALC: A simple calculator class. +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: Provides basic arithmetic operations. +HTML-CALC: +HTML-CALC: HTML-CALC: HTML-CALC: HTML-CALC: @@ -300,6 +321,17 @@ HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE: class Rectangle +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: Rectangle class derived from Shape. +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: Represents a rectangle with a given width and height. +HTML-RECTANGLE: +HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE:
[llvm-branch-commits] [clang-tools-extra] [clang-doc] enable comments in class templates (PR #149565)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/149565 >From 4a076eab44ff05fec172a3c3a94332a19927d9d6 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Fri, 18 Jul 2025 12:04:20 -0700 Subject: [PATCH] [clang-doc] enable comments in class templates The Mustache basic project has comments in its headers but the comments were not serialized. Now we serialize @brief and paragraph comments for classes and add that output to the basic project test. --- .../clang-doc/assets/class-template.mustache | 4 +- .../assets/comment-template.mustache | 9 +++- .../clang-doc/basic-project.mustache.test | 43 +++ 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/class-template.mustache b/clang-tools-extra/clang-doc/assets/class-template.mustache index a4077323f29e2..b1a7470f7c33a 100644 --- a/clang-tools-extra/clang-doc/assets/class-template.mustache +++ b/clang-tools-extra/clang-doc/assets/class-template.mustache @@ -128,11 +128,11 @@ {{TagType}} {{Name}} -{{#RecordComments}} +{{#Description}} {{>Comments}} -{{/RecordComments}} +{{/Description}} {{#HasPublicMembers}} diff --git a/clang-tools-extra/clang-doc/assets/comment-template.mustache b/clang-tools-extra/clang-doc/assets/comment-template.mustache index 723ace7a0eed1..b793bad55cf6c 100644 --- a/clang-tools-extra/clang-doc/assets/comment-template.mustache +++ b/clang-tools-extra/clang-doc/assets/comment-template.mustache @@ -5,11 +5,16 @@ This file defines templates for generating comments }} -{{#FullComment}} +{{#BriefComments}} {{#Children}} {{>Comments}} {{/Children}} -{{/FullComment}} +{{/BriefComments}} +{{#ParagraphComments}} +{{#Children}} +{{>Comments}} +{{/Children}} +{{/ParagraphComments}} {{#ParagraphComment}} {{#Children}} {{>Comments}} diff --git a/clang-tools-extra/test/clang-doc/basic-project.mustache.test b/clang-tools-extra/test/clang-doc/basic-project.mustache.test index 4dd6f4165f65e..4fb38e2b32fcb 100644 --- a/clang-tools-extra/test/clang-doc/basic-project.mustache.test +++ b/clang-tools-extra/test/clang-doc/basic-project.mustache.test @@ -60,6 +60,17 @@ HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: class Shape +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: Abstract base class for shapes. +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: Provides a common interface for different types of shapes. +HTML-SHAPE: +HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: @@ -172,6 +183,16 @@ HTML-CALC: HTML-CALC: HTML-CALC: HTML-CALC: class Calculator +HTML-CALC: +HTML-CALC: A simple calculator class. +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: Provides basic arithmetic operations. +HTML-CALC: +HTML-CALC: HTML-CALC: HTML-CALC: HTML-CALC: @@ -300,6 +321,17 @@ HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE: class Rectangle +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: Rectangle class derived from Shape. +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: Represents a rectangle with a given width and height. +HTML-RECTANGLE: +HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE:
[llvm-branch-commits] [clang-tools-extra] [clang-doc] separate comments into categories (PR #149590)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/149590 >From eb171f6b28eac5e7458c1472645d64be9ffb056f Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Thu, 17 Jul 2025 15:04:20 -0700 Subject: [PATCH] [clang-doc] separate comments into categories Comment categories will allow better comment organization in HTML. Before, comments would just be serialized in whatever order they were written, so groups like params or notes wouldn't be in the same sections. --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 43 .../test/clang-doc/json/class.cpp | 51 +-- .../test/clang-doc/json/concept.cpp | 15 +++--- 3 files changed, 64 insertions(+), 45 deletions(-) diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index 908e23d24d079..5e2d60a8427e1 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -83,7 +83,21 @@ serializeLocation(const Location &Loc, return LocationObj; } -static json::Value serializeComment(const CommentInfo &I) { +static void insertComment(Object &Description, json::Value &Comment, + std::string Key) { + auto *CommentArray = Description.getArray(Key); + if (!CommentArray) { +auto CommentsArray = json::Array(); +CommentsArray.push_back(Comment); +Description[Key] = std::move(CommentsArray); +Description["Has" + Key] = true; + } else { +CommentArray->push_back(Comment); +Description[Key] = std::move(*CommentArray); + } +} + +static Object serializeComment(const CommentInfo &I, Object &Description) { // taken from PR #142273 Object Obj = Object(); @@ -94,7 +108,7 @@ static json::Value serializeComment(const CommentInfo &I) { auto &CARef = *ChildArr.getAsArray(); CARef.reserve(I.Children.size()); for (const auto &C : I.Children) -CARef.emplace_back(serializeComment(*C)); +CARef.emplace_back(serializeComment(*C, Description)); switch (I.Kind) { case CommentKind::CK_TextComment: { @@ -106,6 +120,8 @@ static json::Value serializeComment(const CommentInfo &I) { Child.insert({"Command", I.Name}); Child.insert({"Children", ChildArr}); Obj.insert({commentKindToString(I.Kind), ChildVal}); +if (I.Name == "brief") + insertComment(Description, ChildVal, "BriefComments"); return Obj; } @@ -137,7 +153,10 @@ static json::Value serializeComment(const CommentInfo &I) { if (!I.CloseName.empty()) Child.insert({"CloseName", I.CloseName}); Child.insert({"Children", ChildArr}); -Obj.insert({commentKindToString(I.Kind), ChildVal}); +if (I.CloseName == "endcode") + insertComment(Description, ChildVal, "CodeComments"); +else if (I.CloseName == "endverbatim") + insertComment(Description, ChildVal, "VerbatimComments"); return Obj; } @@ -210,12 +229,18 @@ serializeCommonAttributes(const Info &I, json::Object &Obj, } if (!I.Description.empty()) { -json::Value DescArray = json::Array(); -auto &DescArrayRef = *DescArray.getAsArray(); -DescArrayRef.reserve(I.Description.size()); -for (const auto &Comment : I.Description) - DescArrayRef.push_back(serializeComment(Comment)); -Obj["Description"] = DescArray; +Object Description = Object(); +// Skip straight to the FullComment's children +auto &Comments = I.Description.at(0).Children; +for (const auto &CommentInfo : Comments) { + json::Value Comment = serializeComment(*CommentInfo, Description); + // if a ParagraphComment is returned, then it is a top-level comment that + // needs to be inserted manually. + if (auto *ParagraphComment = + Comment.getAsObject()->get("ParagraphComment")) +insertComment(Description, *ParagraphComment, "ParagraphComments"); +} +Obj["Description"] = std::move(Description); } // Namespaces aren't SymbolInfos, so they dont have a DefLoc diff --git a/clang-tools-extra/test/clang-doc/json/class.cpp b/clang-tools-extra/test/clang-doc/json/class.cpp index a36358982b019..e8fafca28a956 100644 --- a/clang-tools-extra/test/clang-doc/json/class.cpp +++ b/clang-tools-extra/test/clang-doc/json/class.cpp @@ -33,33 +33,30 @@ struct MyClass { }; // CHECK: { -// CHECK-NEXT:"Description": [ -// CHECK-NEXT: { -// CHECK-NEXT: "FullComment": { -// CHECK-NEXT: "Children": [ -// CHECK-NEXT: { -// CHECK-NEXT: "ParagraphComment": { -// CHECK-NEXT: "Children": [ -// CHECK-NEXT: { -// CHECK-NEXT: "TextComment": " This is a nice class." -// CHECK-NEXT: }, -// CHECK-NEXT: { -// CHECK-NEXT: "TextComment": " It has some nice methods and fields." -// CHECK-NEXT: }, -// CHECK-NEXT: { -// CHECK-NEXT: "TextComme
[llvm-branch-commits] [clang-tools-extra] [clang-doc] separate comments into categories (PR #149590)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/149590 >From eb171f6b28eac5e7458c1472645d64be9ffb056f Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Thu, 17 Jul 2025 15:04:20 -0700 Subject: [PATCH] [clang-doc] separate comments into categories Comment categories will allow better comment organization in HTML. Before, comments would just be serialized in whatever order they were written, so groups like params or notes wouldn't be in the same sections. --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 43 .../test/clang-doc/json/class.cpp | 51 +-- .../test/clang-doc/json/concept.cpp | 15 +++--- 3 files changed, 64 insertions(+), 45 deletions(-) diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index 908e23d24d079..5e2d60a8427e1 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -83,7 +83,21 @@ serializeLocation(const Location &Loc, return LocationObj; } -static json::Value serializeComment(const CommentInfo &I) { +static void insertComment(Object &Description, json::Value &Comment, + std::string Key) { + auto *CommentArray = Description.getArray(Key); + if (!CommentArray) { +auto CommentsArray = json::Array(); +CommentsArray.push_back(Comment); +Description[Key] = std::move(CommentsArray); +Description["Has" + Key] = true; + } else { +CommentArray->push_back(Comment); +Description[Key] = std::move(*CommentArray); + } +} + +static Object serializeComment(const CommentInfo &I, Object &Description) { // taken from PR #142273 Object Obj = Object(); @@ -94,7 +108,7 @@ static json::Value serializeComment(const CommentInfo &I) { auto &CARef = *ChildArr.getAsArray(); CARef.reserve(I.Children.size()); for (const auto &C : I.Children) -CARef.emplace_back(serializeComment(*C)); +CARef.emplace_back(serializeComment(*C, Description)); switch (I.Kind) { case CommentKind::CK_TextComment: { @@ -106,6 +120,8 @@ static json::Value serializeComment(const CommentInfo &I) { Child.insert({"Command", I.Name}); Child.insert({"Children", ChildArr}); Obj.insert({commentKindToString(I.Kind), ChildVal}); +if (I.Name == "brief") + insertComment(Description, ChildVal, "BriefComments"); return Obj; } @@ -137,7 +153,10 @@ static json::Value serializeComment(const CommentInfo &I) { if (!I.CloseName.empty()) Child.insert({"CloseName", I.CloseName}); Child.insert({"Children", ChildArr}); -Obj.insert({commentKindToString(I.Kind), ChildVal}); +if (I.CloseName == "endcode") + insertComment(Description, ChildVal, "CodeComments"); +else if (I.CloseName == "endverbatim") + insertComment(Description, ChildVal, "VerbatimComments"); return Obj; } @@ -210,12 +229,18 @@ serializeCommonAttributes(const Info &I, json::Object &Obj, } if (!I.Description.empty()) { -json::Value DescArray = json::Array(); -auto &DescArrayRef = *DescArray.getAsArray(); -DescArrayRef.reserve(I.Description.size()); -for (const auto &Comment : I.Description) - DescArrayRef.push_back(serializeComment(Comment)); -Obj["Description"] = DescArray; +Object Description = Object(); +// Skip straight to the FullComment's children +auto &Comments = I.Description.at(0).Children; +for (const auto &CommentInfo : Comments) { + json::Value Comment = serializeComment(*CommentInfo, Description); + // if a ParagraphComment is returned, then it is a top-level comment that + // needs to be inserted manually. + if (auto *ParagraphComment = + Comment.getAsObject()->get("ParagraphComment")) +insertComment(Description, *ParagraphComment, "ParagraphComments"); +} +Obj["Description"] = std::move(Description); } // Namespaces aren't SymbolInfos, so they dont have a DefLoc diff --git a/clang-tools-extra/test/clang-doc/json/class.cpp b/clang-tools-extra/test/clang-doc/json/class.cpp index a36358982b019..e8fafca28a956 100644 --- a/clang-tools-extra/test/clang-doc/json/class.cpp +++ b/clang-tools-extra/test/clang-doc/json/class.cpp @@ -33,33 +33,30 @@ struct MyClass { }; // CHECK: { -// CHECK-NEXT:"Description": [ -// CHECK-NEXT: { -// CHECK-NEXT: "FullComment": { -// CHECK-NEXT: "Children": [ -// CHECK-NEXT: { -// CHECK-NEXT: "ParagraphComment": { -// CHECK-NEXT: "Children": [ -// CHECK-NEXT: { -// CHECK-NEXT: "TextComment": " This is a nice class." -// CHECK-NEXT: }, -// CHECK-NEXT: { -// CHECK-NEXT: "TextComment": " It has some nice methods and fields." -// CHECK-NEXT: }, -// CHECK-NEXT: { -// CHECK-NEXT: "TextComme
[llvm-branch-commits] [clang-tools-extra] [clang-doc] integrate JSON as the source for Mustache templates (PR #149589)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/149589 >From c9f121abb503e121a6ab346e992a2f5673a3b235 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Fri, 18 Jul 2025 13:59:44 -0700 Subject: [PATCH] [clang-doc] integrate JSON as the source for Mustache templates --- .../clang-doc/HTMLMustacheGenerator.cpp | 487 +++--- .../clang-doc/assets/class-template.mustache | 62 +-- .../clang-doc/assets/enum-template.mustache | 12 +- .../assets/function-template.mustache | 2 +- .../assets/namespace-template.mustache| 45 +- .../clang-doc/basic-project.mustache.test | 70 +-- .../test/clang-doc/mustache-index.cpp | 10 +- .../clang-doc/mustache-separate-namespace.cpp | 8 +- .../clang-doc/HTMLMustacheGeneratorTest.cpp | 129 - 9 files changed, 171 insertions(+), 654 deletions(-) diff --git a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp index 7aeaa1b7cf67d..98e2935a8aada 100644 --- a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp +++ b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp @@ -27,6 +27,9 @@ using namespace llvm::mustache; namespace clang { namespace doc { +static Error generateDocForJSON(json::Value &JSON, StringRef Filename, +StringRef Path, raw_fd_ostream &OS, +const ClangDocContext &CDCtx); static Error createFileOpenError(StringRef FileName, std::error_code EC) { return createFileError("cannot open file " + FileName, EC); @@ -132,404 +135,65 @@ Error MustacheHTMLGenerator::generateDocs( return Err; } - // Track which directories we already tried to create. - StringSet<> CreatedDirs; - // Collect all output by file name and create the necessary directories. - StringMap> FileToInfos; - for (const auto &Group : Infos) { -llvm::TimeTraceScope TS("setup directories"); -doc::Info *Info = Group.getValue().get(); - -SmallString<128> Path; -sys::path::native(RootDir, Path); -sys::path::append(Path, Info->getRelativeFilePath("")); -if (!CreatedDirs.contains(Path)) { - if (std::error_code EC = sys::fs::create_directories(Path)) -return createStringError(EC, "failed to create directory '%s'.", - Path.c_str()); - CreatedDirs.insert(Path); -} - -sys::path::append(Path, Info->getFileBaseName() + ".html"); -FileToInfos[Path].push_back(Info); + { +llvm::TimeTraceScope TS("Generate JSON for Mustache"); +if (auto JSONGenerator = findGeneratorByName("json")) { + if (Error Err = JSONGenerator.get()->generateDocs( + RootDir, std::move(Infos), CDCtx)) +return Err; +} else + return JSONGenerator.takeError(); } + StringMap JSONFileMap; { -llvm::TimeTraceScope TS("Generate Docs"); -for (const auto &Group : FileToInfos) { - llvm::TimeTraceScope TS("Info to Doc"); +llvm::TimeTraceScope TS("Iterate JSON files"); +std::error_code EC; +sys::fs::directory_iterator JSONIter(RootDir, EC); +std::vector JSONFiles; +JSONFiles.reserve(Infos.size()); +if (EC) + return createStringError("Failed to create directory iterator."); + +while (JSONIter != sys::fs::directory_iterator()) { + if (EC) +return createStringError(EC, "Failed to iterate directory"); + + auto Path = StringRef(JSONIter->path()); + if (!Path.ends_with(".json")) { +JSONIter.increment(EC); +continue; + } + + auto File = MemoryBuffer::getFile(Path); + if ((EC = File.getError())) +continue; + + auto Parsed = json::parse((*File)->getBuffer()); + if (!Parsed) +return Parsed.takeError(); + std::error_code FileErr; - raw_fd_ostream InfoOS(Group.getKey(), FileErr, sys::fs::OF_None); + SmallString<16> HTMLPath(Path.begin(), Path.end()); + sys::path::replace_extension(HTMLPath, "html"); + raw_fd_ostream InfoOS(HTMLPath, FileErr, sys::fs::OF_None); if (FileErr) -return createFileOpenError(Group.getKey(), FileErr); +return createFileOpenError(Path, FileErr); - for (const auto &Info : Group.getValue()) -if (Error Err = generateDocForInfo(Info, InfoOS, CDCtx)) - return Err; + if (Error Err = generateDocForJSON(*Parsed, sys::path::stem(HTMLPath), + HTMLPath, InfoOS, CDCtx)) +return Err; + JSONIter.increment(EC); } } - return Error::success(); -} - -static json::Value -extractValue(const Location &L, - std::optional RepositoryUrl = std::nullopt) { - Object Obj = Object(); - // TODO: Consider using both Start/End line numbers to improve location report - Obj.insert({"LineNumber", L.StartLineNumber}); - Obj.insert({"Filename", L.Filename}); - - if (!L.IsFileInRootDir || !RepositoryUrl) -return Obj; - SmallS
[llvm-branch-commits] [clang-tools-extra] [clang-doc] enable comments in class templates (PR #149848)
evelez7 wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.dev/github/pr/llvm/llvm-project/149848?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#149848** https://app.graphite.dev/github/pr/llvm/llvm-project/149848?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/149848?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#149590** https://app.graphite.dev/github/pr/llvm/llvm-project/149590?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#149589** https://app.graphite.dev/github/pr/llvm/llvm-project/149589?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#149588** https://app.graphite.dev/github/pr/llvm/llvm-project/149588?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/149848 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] enable comments in class templates (PR #149848)
https://github.com/evelez7 ready_for_review https://github.com/llvm/llvm-project/pull/149848 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] separate comments into categories (PR #149590)
https://github.com/evelez7 ready_for_review https://github.com/llvm/llvm-project/pull/149590 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] enable comments in class templates (PR #149848)
https://github.com/evelez7 created https://github.com/llvm/llvm-project/pull/149848 The Mustache basic project has comments in its headers but the comments were not serialized. Now we serialize @brief and paragraph comments for classes and add that output to the basic project test. >From f52930a1b4f3c725b6233f65f76a9b984a7a617a Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Fri, 18 Jul 2025 12:04:20 -0700 Subject: [PATCH] [clang-doc] enable comments in class templates The Mustache basic project has comments in its headers but the comments were not serialized. Now we serialize @brief and paragraph comments for classes and add that output to the basic project test. --- .../clang-doc/assets/class-template.mustache | 4 +- .../assets/comment-template.mustache | 9 +++- .../clang-doc/basic-project.mustache.test | 43 +++ 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/class-template.mustache b/clang-tools-extra/clang-doc/assets/class-template.mustache index a4077323f29e2..b1a7470f7c33a 100644 --- a/clang-tools-extra/clang-doc/assets/class-template.mustache +++ b/clang-tools-extra/clang-doc/assets/class-template.mustache @@ -128,11 +128,11 @@ {{TagType}} {{Name}} -{{#RecordComments}} +{{#Description}} {{>Comments}} -{{/RecordComments}} +{{/Description}} {{#HasPublicMembers}} diff --git a/clang-tools-extra/clang-doc/assets/comment-template.mustache b/clang-tools-extra/clang-doc/assets/comment-template.mustache index 723ace7a0eed1..b793bad55cf6c 100644 --- a/clang-tools-extra/clang-doc/assets/comment-template.mustache +++ b/clang-tools-extra/clang-doc/assets/comment-template.mustache @@ -5,11 +5,16 @@ This file defines templates for generating comments }} -{{#FullComment}} +{{#BriefComments}} {{#Children}} {{>Comments}} {{/Children}} -{{/FullComment}} +{{/BriefComments}} +{{#ParagraphComments}} +{{#Children}} +{{>Comments}} +{{/Children}} +{{/ParagraphComments}} {{#ParagraphComment}} {{#Children}} {{>Comments}} diff --git a/clang-tools-extra/test/clang-doc/basic-project.mustache.test b/clang-tools-extra/test/clang-doc/basic-project.mustache.test index 4dd6f4165f65e..4fb38e2b32fcb 100644 --- a/clang-tools-extra/test/clang-doc/basic-project.mustache.test +++ b/clang-tools-extra/test/clang-doc/basic-project.mustache.test @@ -60,6 +60,17 @@ HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: class Shape +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: Abstract base class for shapes. +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: Provides a common interface for different types of shapes. +HTML-SHAPE: +HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: @@ -172,6 +183,16 @@ HTML-CALC: HTML-CALC: HTML-CALC: HTML-CALC: class Calculator +HTML-CALC: +HTML-CALC: A simple calculator class. +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: Provides basic arithmetic operations. +HTML-CALC: +HTML-CALC: HTML-CALC: HTML-CALC: HTML-CALC: @@ -300,6 +321,17 @@ HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE: class Rectangle +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: Rectangle class derived from Shape. +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: Represents a rectangle with a given width and height. +H
[llvm-branch-commits] [clang-tools-extra] [clang-doc] enable comments in class templates (PR #149848)
https://github.com/evelez7 edited https://github.com/llvm/llvm-project/pull/149848 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add support for concepts (PR #144430)
https://github.com/evelez7 ready_for_review https://github.com/llvm/llvm-project/pull/144430 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add support for concepts (PR #144430)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/144430 >From 2febdc89f0c2b2f9abe47415f5c115ad8305ed2d Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Mon, 16 Jun 2025 10:50:35 -0700 Subject: [PATCH] add serializeArray for infos with URLs --- clang-tools-extra/clang-doc/BitcodeReader.cpp | 72 +++ clang-tools-extra/clang-doc/BitcodeWriter.cpp | 44 ++- clang-tools-extra/clang-doc/BitcodeWriter.h | 12 +- clang-tools-extra/clang-doc/HTMLGenerator.cpp | 4 + .../clang-doc/HTMLMustacheGenerator.cpp | 2 + clang-tools-extra/clang-doc/JSONGenerator.cpp | 50 clang-tools-extra/clang-doc/MDGenerator.cpp | 5 + clang-tools-extra/clang-doc/Mapper.cpp| 4 + clang-tools-extra/clang-doc/Mapper.h | 1 + .../clang-doc/Representation.cpp | 20 +++ clang-tools-extra/clang-doc/Representation.h | 26 +++- clang-tools-extra/clang-doc/Serialize.cpp | 90 + clang-tools-extra/clang-doc/Serialize.h | 4 + clang-tools-extra/clang-doc/YAMLGenerator.cpp | 2 + .../test/clang-doc/json/class-requires.cpp| 18 +-- .../clang-doc/json/compound-constraints.cpp | 121 ++ .../test/clang-doc/json/concept.cpp | 48 +++ .../test/clang-doc/json/function-requires.cpp | 36 +++--- .../unittests/clang-doc/BitcodeTest.cpp | 2 + 19 files changed, 505 insertions(+), 56 deletions(-) create mode 100644 clang-tools-extra/test/clang-doc/json/compound-constraints.cpp diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp b/clang-tools-extra/clang-doc/BitcodeReader.cpp index 35058abab0663..5b70280e7dba8 100644 --- a/clang-tools-extra/clang-doc/BitcodeReader.cpp +++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp @@ -92,6 +92,7 @@ static llvm::Error decodeRecord(const Record &R, InfoType &Field, case InfoType::IT_default: case InfoType::IT_enum: case InfoType::IT_typedef: + case InfoType::IT_concept: Field = IT; return llvm::Error::success(); } @@ -108,6 +109,7 @@ static llvm::Error decodeRecord(const Record &R, FieldId &Field, case FieldId::F_type: case FieldId::F_child_namespace: case FieldId::F_child_record: + case FieldId::F_concept: case FieldId::F_default: Field = F; return llvm::Error::success(); @@ -391,6 +393,29 @@ static llvm::Error parseRecord(const Record &R, unsigned ID, "invalid field for TemplateParamInfo"); } +static llvm::Error parseRecord(const Record &R, unsigned ID, + llvm::StringRef Blob, ConceptInfo *I) { + switch (ID) { + case CONCEPT_USR: +return decodeRecord(R, I->USR, Blob); + case CONCEPT_NAME: +return decodeRecord(R, I->Name, Blob); + case CONCEPT_IS_TYPE: +return decodeRecord(R, I->IsType, Blob); + case CONCEPT_CONSTRAINT_EXPRESSION: +return decodeRecord(R, I->ConstraintExpression, Blob); + } + llvm_unreachable("invalid field for ConceptInfo"); +} + +static llvm::Error parseRecord(const Record &R, unsigned ID, + llvm::StringRef Blob, ConstraintInfo *I) { + if (ID == CONSTRAINT_EXPRESSION) +return decodeRecord(R, I->Expression, Blob); + return llvm::createStringError(llvm::inconvertibleErrorCode(), + "invalid field for ConstraintInfo"); +} + template static llvm::Expected getCommentInfo(T I) { return llvm::createStringError(llvm::inconvertibleErrorCode(), "invalid type cannot contain CommentInfo"); @@ -429,6 +454,10 @@ template <> llvm::Expected getCommentInfo(CommentInfo *I) { return I->Children.back().get(); } +template <> llvm::Expected getCommentInfo(ConceptInfo *I) { + return &I->Description.emplace_back(); +} + // When readSubBlock encounters a TypeInfo sub-block, it calls addTypeInfo on // the parent block to set it. The template specializations define what to do // for each supported parent block. @@ -584,6 +613,18 @@ template <> llvm::Error addReference(RecordInfo *I, Reference &&R, FieldId F) { } } +template <> +llvm::Error addReference(ConstraintInfo *I, Reference &&R, FieldId F) { + switch (F) { + case FieldId::F_concept: +I->ConceptRef = std::move(R); +return llvm::Error::success(); + default: +return llvm::createStringError(llvm::inconvertibleErrorCode(), + "invalid type cannot contain Reference"); + } +} + template static void addChild(T I, ChildInfoType &&R) { llvm::errs() << "invalid child type for info"; @@ -600,6 +641,9 @@ template <> void addChild(NamespaceInfo *I, EnumInfo &&R) { template <> void addChild(NamespaceInfo *I, TypedefInfo &&R) { I->Children.Typedefs.emplace_back(std::move(R)); } +template <> void addChild(NamespaceInfo *I, ConceptInfo &&R) { + I->Children.Concepts.emplace_back(std::move(R)); +} // Record children: template <> void addChild(RecordInfo *I, FunctionInfo &&R) { @@ -
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add support for concepts (PR #144430)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/144430 >From 9754f70f3255e250c51c177bb00ef955e8d92f9c Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Mon, 16 Jun 2025 10:50:35 -0700 Subject: [PATCH] add serializeArray for infos with URLs --- clang-tools-extra/clang-doc/BitcodeReader.cpp | 72 +++ clang-tools-extra/clang-doc/BitcodeWriter.cpp | 44 ++- clang-tools-extra/clang-doc/BitcodeWriter.h | 12 +- clang-tools-extra/clang-doc/HTMLGenerator.cpp | 4 + .../clang-doc/HTMLMustacheGenerator.cpp | 2 + clang-tools-extra/clang-doc/JSONGenerator.cpp | 54 clang-tools-extra/clang-doc/MDGenerator.cpp | 5 + clang-tools-extra/clang-doc/Mapper.cpp| 4 + clang-tools-extra/clang-doc/Mapper.h | 1 + .../clang-doc/Representation.cpp | 13 ++ clang-tools-extra/clang-doc/Representation.h | 26 +++- clang-tools-extra/clang-doc/Serialize.cpp | 90 + clang-tools-extra/clang-doc/Serialize.h | 4 + clang-tools-extra/clang-doc/YAMLGenerator.cpp | 2 + .../test/clang-doc/json/class-requires.cpp| 18 +-- .../clang-doc/json/compound-constraints.cpp | 121 ++ .../test/clang-doc/json/concept.cpp | 48 +++ .../test/clang-doc/json/function-requires.cpp | 36 +++--- .../unittests/clang-doc/BitcodeTest.cpp | 2 + 19 files changed, 502 insertions(+), 56 deletions(-) create mode 100644 clang-tools-extra/test/clang-doc/json/compound-constraints.cpp diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp b/clang-tools-extra/clang-doc/BitcodeReader.cpp index 35058abab0663..5b70280e7dba8 100644 --- a/clang-tools-extra/clang-doc/BitcodeReader.cpp +++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp @@ -92,6 +92,7 @@ static llvm::Error decodeRecord(const Record &R, InfoType &Field, case InfoType::IT_default: case InfoType::IT_enum: case InfoType::IT_typedef: + case InfoType::IT_concept: Field = IT; return llvm::Error::success(); } @@ -108,6 +109,7 @@ static llvm::Error decodeRecord(const Record &R, FieldId &Field, case FieldId::F_type: case FieldId::F_child_namespace: case FieldId::F_child_record: + case FieldId::F_concept: case FieldId::F_default: Field = F; return llvm::Error::success(); @@ -391,6 +393,29 @@ static llvm::Error parseRecord(const Record &R, unsigned ID, "invalid field for TemplateParamInfo"); } +static llvm::Error parseRecord(const Record &R, unsigned ID, + llvm::StringRef Blob, ConceptInfo *I) { + switch (ID) { + case CONCEPT_USR: +return decodeRecord(R, I->USR, Blob); + case CONCEPT_NAME: +return decodeRecord(R, I->Name, Blob); + case CONCEPT_IS_TYPE: +return decodeRecord(R, I->IsType, Blob); + case CONCEPT_CONSTRAINT_EXPRESSION: +return decodeRecord(R, I->ConstraintExpression, Blob); + } + llvm_unreachable("invalid field for ConceptInfo"); +} + +static llvm::Error parseRecord(const Record &R, unsigned ID, + llvm::StringRef Blob, ConstraintInfo *I) { + if (ID == CONSTRAINT_EXPRESSION) +return decodeRecord(R, I->Expression, Blob); + return llvm::createStringError(llvm::inconvertibleErrorCode(), + "invalid field for ConstraintInfo"); +} + template static llvm::Expected getCommentInfo(T I) { return llvm::createStringError(llvm::inconvertibleErrorCode(), "invalid type cannot contain CommentInfo"); @@ -429,6 +454,10 @@ template <> llvm::Expected getCommentInfo(CommentInfo *I) { return I->Children.back().get(); } +template <> llvm::Expected getCommentInfo(ConceptInfo *I) { + return &I->Description.emplace_back(); +} + // When readSubBlock encounters a TypeInfo sub-block, it calls addTypeInfo on // the parent block to set it. The template specializations define what to do // for each supported parent block. @@ -584,6 +613,18 @@ template <> llvm::Error addReference(RecordInfo *I, Reference &&R, FieldId F) { } } +template <> +llvm::Error addReference(ConstraintInfo *I, Reference &&R, FieldId F) { + switch (F) { + case FieldId::F_concept: +I->ConceptRef = std::move(R); +return llvm::Error::success(); + default: +return llvm::createStringError(llvm::inconvertibleErrorCode(), + "invalid type cannot contain Reference"); + } +} + template static void addChild(T I, ChildInfoType &&R) { llvm::errs() << "invalid child type for info"; @@ -600,6 +641,9 @@ template <> void addChild(NamespaceInfo *I, EnumInfo &&R) { template <> void addChild(NamespaceInfo *I, TypedefInfo &&R) { I->Children.Typedefs.emplace_back(std::move(R)); } +template <> void addChild(NamespaceInfo *I, ConceptInfo &&R) { + I->Children.Concepts.emplace_back(std::move(R)); +} // Record children: template <> void addChild(RecordInfo *I, FunctionInfo &&R) { @@ -6
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add support for concepts (PR #144430)
https://github.com/evelez7 converted_to_draft https://github.com/llvm/llvm-project/pull/144430 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] document global variables (PR #145070)
https://github.com/evelez7 edited https://github.com/llvm/llvm-project/pull/145070 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] document global variables (PR #145070)
https://github.com/evelez7 created https://github.com/llvm/llvm-project/pull/145070 None >From 7c0658cc9cbf5d28125ecbfed4b95667cb1ccecf Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Wed, 18 Jun 2025 16:36:49 -0700 Subject: [PATCH] [clang-doc] document global variables --- clang-tools-extra/clang-doc/BitcodeReader.cpp | 40 ++ clang-tools-extra/clang-doc/BitcodeWriter.cpp | 32 +-- clang-tools-extra/clang-doc/BitcodeWriter.h | 6 +++ clang-tools-extra/clang-doc/HTMLGenerator.cpp | 3 ++ .../clang-doc/HTMLMustacheGenerator.cpp | 2 + clang-tools-extra/clang-doc/JSONGenerator.cpp | 14 +++ clang-tools-extra/clang-doc/MDGenerator.cpp | 4 ++ clang-tools-extra/clang-doc/Mapper.cpp| 6 +++ clang-tools-extra/clang-doc/Mapper.h | 1 + .../clang-doc/Representation.cpp | 16 clang-tools-extra/clang-doc/Representation.h | 14 ++- clang-tools-extra/clang-doc/Serialize.cpp | 27 clang-tools-extra/clang-doc/Serialize.h | 4 ++ clang-tools-extra/clang-doc/YAMLGenerator.cpp | 1 + .../test/clang-doc/json/namespace.cpp | 41 +-- .../unittests/clang-doc/BitcodeTest.cpp | 2 + 16 files changed, 188 insertions(+), 25 deletions(-) diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp b/clang-tools-extra/clang-doc/BitcodeReader.cpp index 5b70280e7dba8..063d19f64 100644 --- a/clang-tools-extra/clang-doc/BitcodeReader.cpp +++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp @@ -93,6 +93,7 @@ static llvm::Error decodeRecord(const Record &R, InfoType &Field, case InfoType::IT_enum: case InfoType::IT_typedef: case InfoType::IT_concept: + case InfoType::IT_variable: Field = IT; return llvm::Error::success(); } @@ -416,6 +417,23 @@ static llvm::Error parseRecord(const Record &R, unsigned ID, "invalid field for ConstraintInfo"); } +static llvm::Error parseRecord(const Record &R, unsigned ID, + llvm::StringRef Blob, VarInfo *I) { + switch (ID) { + case VAR_USR: +return decodeRecord(R, I->USR, Blob); + case VAR_NAME: +return decodeRecord(R, I->Name, Blob); + case VAR_DEFLOCATION: +return decodeRecord(R, I->DefLoc, Blob); + case VAR_IS_STATIC: +return decodeRecord(R, I->IsStatic, Blob); + default: +return llvm::createStringError(llvm::inconvertibleErrorCode(), + "invalid field for VarInfo"); + } +} + template static llvm::Expected getCommentInfo(T I) { return llvm::createStringError(llvm::inconvertibleErrorCode(), "invalid type cannot contain CommentInfo"); @@ -458,6 +476,10 @@ template <> llvm::Expected getCommentInfo(ConceptInfo *I) { return &I->Description.emplace_back(); } +template <> Expected getCommentInfo(VarInfo *I) { + return &I->Description.emplace_back(); +} + // When readSubBlock encounters a TypeInfo sub-block, it calls addTypeInfo on // the parent block to set it. The template specializations define what to do // for each supported parent block. @@ -497,6 +519,11 @@ template <> llvm::Error addTypeInfo(TypedefInfo *I, TypeInfo &&T) { return llvm::Error::success(); } +template <> llvm::Error addTypeInfo(VarInfo *I, TypeInfo &&T) { + I->Type = std::move(T); + return llvm::Error::success(); +} + template static llvm::Error addReference(T I, Reference &&R, FieldId F) { return llvm::createStringError(llvm::inconvertibleErrorCode(), @@ -644,6 +671,9 @@ template <> void addChild(NamespaceInfo *I, TypedefInfo &&R) { template <> void addChild(NamespaceInfo *I, ConceptInfo &&R) { I->Children.Concepts.emplace_back(std::move(R)); } +template <> void addChild(NamespaceInfo *I, VarInfo &&R) { + I->Children.Variables.emplace_back(std::move(R)); +} // Record children: template <> void addChild(RecordInfo *I, FunctionInfo &&R) { @@ -886,6 +916,13 @@ llvm::Error ClangDocBitcodeReader::readSubBlock(unsigned ID, T I) { addChild(I, std::move(CI)); return llvm::Error::success(); } + case BI_VAR_BLOCK_ID: { +VarInfo VI; +if (auto Err = readBlock(ID, &VI)) + return Err; +addChild(I, std::move(VI)); +return llvm::Error::success(); + } default: return llvm::createStringError(llvm::inconvertibleErrorCode(), "invalid subblock type"); @@ -995,6 +1032,8 @@ ClangDocBitcodeReader::readBlockToInfo(unsigned ID) { return createInfo(ID); case BI_FUNCTION_BLOCK_ID: return createInfo(ID); + case BI_VAR_BLOCK_ID: +return createInfo(ID); default: return llvm::createStringError(llvm::inconvertibleErrorCode(), "cannot create info"); @@ -1034,6 +1073,7 @@ ClangDocBitcodeReader::readBitcode() { case BI_ENUM_BLOCK_ID: case BI_TYPEDEF_BLOCK_ID: case BI_CONCEPT_BLOCK_ID: +case BI_VAR_BLOCK_ID: case BI_FUNCTION_BLOCK_
[llvm-branch-commits] [clang-tools-extra] [clang-doc] document global variables (PR #145070)
evelez7 wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.dev/github/pr/llvm/llvm-project/145070?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#145070** https://app.graphite.dev/github/pr/llvm/llvm-project/145070?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/145070?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#145069** https://app.graphite.dev/github/pr/llvm/llvm-project/145069?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#144430** https://app.graphite.dev/github/pr/llvm/llvm-project/144430?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#144160** https://app.graphite.dev/github/pr/llvm/llvm-project/144160?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/145070 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] Precommit test for global variables (PR #145069)
evelez7 wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.dev/github/pr/llvm/llvm-project/145069?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#145070** https://app.graphite.dev/github/pr/llvm/llvm-project/145070?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#145069** https://app.graphite.dev/github/pr/llvm/llvm-project/145069?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/145069?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#144430** https://app.graphite.dev/github/pr/llvm/llvm-project/144430?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#144160** https://app.graphite.dev/github/pr/llvm/llvm-project/144160?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/145069 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] Precommit test for global variables (PR #145069)
https://github.com/evelez7 created https://github.com/llvm/llvm-project/pull/145069 None >From f572cfc62317c37510288a63cb0fccb6a3a1f000 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Thu, 19 Jun 2025 21:25:13 -0700 Subject: [PATCH] [clang-doc] Precommit test for global variables --- .../test/clang-doc/json/namespace.cpp | 20 ++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/test/clang-doc/json/namespace.cpp b/clang-tools-extra/test/clang-doc/json/namespace.cpp index 928864be1feb0..248d47351bd38 100644 --- a/clang-tools-extra/test/clang-doc/json/namespace.cpp +++ b/clang-tools-extra/test/clang-doc/json/namespace.cpp @@ -103,5 +103,23 @@ typedef int MyTypedef; // CHECK-NEXT: } // CHECK-NEXT:], // CHECK-NEXT:"USR": "" -// CHECK-NOT: "Variables": [ +// CHECK-NOT:"Variables": [ +// CHECK-NOT: { +// CHECK-NOT:"IsStatic": true, +// CHECK-NOT:"Location": { +// CHECK-NOT: "Filename": "{{.*}}namespace.cpp", +// CHECK-NOT: "LineNumber": 13 +// CHECK-NOT:}, +// CHECK-NOT:"Name": "Global", +// CHECK-NOT:"Type": { +// COM:FIXME: IsBuiltIn emits as its default value +// CHECK-NOT: "IsBuiltIn": false, +// CHECK-NOT: "IsTemplate": false, +// CHECK-NOT: "Name": "int", +// CHECK-NOT: "QualName": "int", +// CHECK-NOT: "USR": "" +// CHECK-NOT:}, +// CHECK-NOT:"USR": "{{[0-9A-F]*}}" +// CHECK-NOT: } +// CHECK-NOT:] // CHECK-NEXT: } ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] document global variables (PR #145070)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/145070 >From fa5f1cb09df62f018e5b7b53ccec4b77d94d1828 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Wed, 18 Jun 2025 16:36:49 -0700 Subject: [PATCH] [clang-doc] document global variables --- clang-tools-extra/clang-doc/BitcodeReader.cpp | 40 ++ clang-tools-extra/clang-doc/BitcodeWriter.cpp | 32 +-- clang-tools-extra/clang-doc/BitcodeWriter.h | 6 +++ clang-tools-extra/clang-doc/HTMLGenerator.cpp | 3 ++ .../clang-doc/HTMLMustacheGenerator.cpp | 2 + clang-tools-extra/clang-doc/JSONGenerator.cpp | 14 +++ clang-tools-extra/clang-doc/MDGenerator.cpp | 4 ++ clang-tools-extra/clang-doc/Mapper.cpp| 6 +++ clang-tools-extra/clang-doc/Mapper.h | 1 + .../clang-doc/Representation.cpp | 16 clang-tools-extra/clang-doc/Representation.h | 14 ++- clang-tools-extra/clang-doc/Serialize.cpp | 27 clang-tools-extra/clang-doc/Serialize.h | 4 ++ clang-tools-extra/clang-doc/YAMLGenerator.cpp | 1 + .../test/clang-doc/json/namespace.cpp | 41 +-- .../unittests/clang-doc/BitcodeTest.cpp | 2 + 16 files changed, 188 insertions(+), 25 deletions(-) diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp b/clang-tools-extra/clang-doc/BitcodeReader.cpp index 66852931226bf..cbdd5d245b8de 100644 --- a/clang-tools-extra/clang-doc/BitcodeReader.cpp +++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp @@ -93,6 +93,7 @@ static llvm::Error decodeRecord(const Record &R, InfoType &Field, case InfoType::IT_enum: case InfoType::IT_typedef: case InfoType::IT_concept: + case InfoType::IT_variable: Field = IT; return llvm::Error::success(); } @@ -416,6 +417,23 @@ static llvm::Error parseRecord(const Record &R, unsigned ID, "invalid field for ConstraintInfo"); } +static llvm::Error parseRecord(const Record &R, unsigned ID, + llvm::StringRef Blob, VarInfo *I) { + switch (ID) { + case VAR_USR: +return decodeRecord(R, I->USR, Blob); + case VAR_NAME: +return decodeRecord(R, I->Name, Blob); + case VAR_DEFLOCATION: +return decodeRecord(R, I->DefLoc, Blob); + case VAR_IS_STATIC: +return decodeRecord(R, I->IsStatic, Blob); + default: +return llvm::createStringError(llvm::inconvertibleErrorCode(), + "invalid field for VarInfo"); + } +} + template static llvm::Expected getCommentInfo(T I) { return llvm::createStringError(llvm::inconvertibleErrorCode(), "invalid type cannot contain CommentInfo"); @@ -458,6 +476,10 @@ template <> llvm::Expected getCommentInfo(ConceptInfo *I) { return &I->Description.emplace_back(); } +template <> Expected getCommentInfo(VarInfo *I) { + return &I->Description.emplace_back(); +} + // When readSubBlock encounters a TypeInfo sub-block, it calls addTypeInfo on // the parent block to set it. The template specializations define what to do // for each supported parent block. @@ -497,6 +519,11 @@ template <> llvm::Error addTypeInfo(TypedefInfo *I, TypeInfo &&T) { return llvm::Error::success(); } +template <> llvm::Error addTypeInfo(VarInfo *I, TypeInfo &&T) { + I->Type = std::move(T); + return llvm::Error::success(); +} + template static llvm::Error addReference(T I, Reference &&R, FieldId F) { return llvm::createStringError(llvm::inconvertibleErrorCode(), @@ -643,6 +670,9 @@ template <> void addChild(NamespaceInfo *I, TypedefInfo &&R) { template <> void addChild(NamespaceInfo *I, ConceptInfo &&R) { I->Children.Concepts.emplace_back(std::move(R)); } +template <> void addChild(NamespaceInfo *I, VarInfo &&R) { + I->Children.Variables.emplace_back(std::move(R)); +} // Record children: template <> void addChild(RecordInfo *I, FunctionInfo &&R) { @@ -887,6 +917,13 @@ llvm::Error ClangDocBitcodeReader::readSubBlock(unsigned ID, T I) { addChild(I, std::move(CI)); return llvm::Error::success(); } + case BI_VAR_BLOCK_ID: { +VarInfo VI; +if (auto Err = readBlock(ID, &VI)) + return Err; +addChild(I, std::move(VI)); +return llvm::Error::success(); + } default: return llvm::createStringError(llvm::inconvertibleErrorCode(), "invalid subblock type"); @@ -996,6 +1033,8 @@ ClangDocBitcodeReader::readBlockToInfo(unsigned ID) { return createInfo(ID); case BI_FUNCTION_BLOCK_ID: return createInfo(ID); + case BI_VAR_BLOCK_ID: +return createInfo(ID); default: return llvm::createStringError(llvm::inconvertibleErrorCode(), "cannot create info"); @@ -1035,6 +1074,7 @@ ClangDocBitcodeReader::readBitcode() { case BI_ENUM_BLOCK_ID: case BI_TYPEDEF_BLOCK_ID: case BI_CONCEPT_BLOCK_ID: +case BI_VAR_BLOCK_ID: case BI_FUNCTION_BLOCK_ID: {
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add support for concepts (PR #144430)
@@ -248,6 +257,27 @@ static void serializeCommonChildren(const ScopeChildren &Children, } } +template +static void serializeArray(const std::vector &Records, Object &Obj, + const std::string &Key, + SerializationFunc serializeInfo) { + json::Value RecordsArray = Array(); + auto &RecordsArrayRef = *RecordsArray.getAsArray(); + RecordsArrayRef.reserve(Records.size()); + for (const auto &Item : Records) { +json::Value ItemVal = Object(); +auto &ItemObj = *ItemVal.getAsObject(); +serializeInfo(Item, ItemObj); +RecordsArrayRef.push_back(ItemVal); + } evelez7 wrote: I'm going to refactor a lot of the code in here later to call this function for arrays. And I'll probably make a similar one for objects that just get a value declared and passed to `serializeInfo`. https://github.com/llvm/llvm-project/pull/144430 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add support for concepts (PR #144430)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/144430 >From 63143f08d0044e11562ce142060cb1f2234c9a36 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Mon, 16 Jun 2025 10:50:35 -0700 Subject: [PATCH] add serializeArray for infos with URLs --- clang-tools-extra/clang-doc/BitcodeReader.cpp | 73 +++ clang-tools-extra/clang-doc/BitcodeWriter.cpp | 44 ++- clang-tools-extra/clang-doc/BitcodeWriter.h | 12 +- clang-tools-extra/clang-doc/HTMLGenerator.cpp | 4 + .../clang-doc/HTMLMustacheGenerator.cpp | 2 + clang-tools-extra/clang-doc/JSONGenerator.cpp | 50 clang-tools-extra/clang-doc/MDGenerator.cpp | 5 + clang-tools-extra/clang-doc/Mapper.cpp| 4 + clang-tools-extra/clang-doc/Mapper.h | 1 + .../clang-doc/Representation.cpp | 20 +++ clang-tools-extra/clang-doc/Representation.h | 26 +++- clang-tools-extra/clang-doc/Serialize.cpp | 90 + clang-tools-extra/clang-doc/Serialize.h | 4 + clang-tools-extra/clang-doc/YAMLGenerator.cpp | 2 + .../test/clang-doc/json/class-requires.cpp| 18 +-- .../clang-doc/json/compound-constraints.cpp | 121 ++ .../test/clang-doc/json/concept.cpp | 49 +++ .../test/clang-doc/json/function-requires.cpp | 36 +++--- .../unittests/clang-doc/BitcodeTest.cpp | 2 + 19 files changed, 507 insertions(+), 56 deletions(-) create mode 100644 clang-tools-extra/test/clang-doc/json/compound-constraints.cpp diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp b/clang-tools-extra/clang-doc/BitcodeReader.cpp index 35058abab0663..66852931226bf 100644 --- a/clang-tools-extra/clang-doc/BitcodeReader.cpp +++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp @@ -92,6 +92,7 @@ static llvm::Error decodeRecord(const Record &R, InfoType &Field, case InfoType::IT_default: case InfoType::IT_enum: case InfoType::IT_typedef: + case InfoType::IT_concept: Field = IT; return llvm::Error::success(); } @@ -108,6 +109,7 @@ static llvm::Error decodeRecord(const Record &R, FieldId &Field, case FieldId::F_type: case FieldId::F_child_namespace: case FieldId::F_child_record: + case FieldId::F_concept: case FieldId::F_default: Field = F; return llvm::Error::success(); @@ -391,6 +393,29 @@ static llvm::Error parseRecord(const Record &R, unsigned ID, "invalid field for TemplateParamInfo"); } +static llvm::Error parseRecord(const Record &R, unsigned ID, + llvm::StringRef Blob, ConceptInfo *I) { + switch (ID) { + case CONCEPT_USR: +return decodeRecord(R, I->USR, Blob); + case CONCEPT_NAME: +return decodeRecord(R, I->Name, Blob); + case CONCEPT_IS_TYPE: +return decodeRecord(R, I->IsType, Blob); + case CONCEPT_CONSTRAINT_EXPRESSION: +return decodeRecord(R, I->ConstraintExpression, Blob); + } + llvm_unreachable("invalid field for ConceptInfo"); +} + +static llvm::Error parseRecord(const Record &R, unsigned ID, + llvm::StringRef Blob, ConstraintInfo *I) { + if (ID == CONSTRAINT_EXPRESSION) +return decodeRecord(R, I->ConstraintExpr, Blob); + return llvm::createStringError(llvm::inconvertibleErrorCode(), + "invalid field for ConstraintInfo"); +} + template static llvm::Expected getCommentInfo(T I) { return llvm::createStringError(llvm::inconvertibleErrorCode(), "invalid type cannot contain CommentInfo"); @@ -429,6 +454,10 @@ template <> llvm::Expected getCommentInfo(CommentInfo *I) { return I->Children.back().get(); } +template <> llvm::Expected getCommentInfo(ConceptInfo *I) { + return &I->Description.emplace_back(); +} + // When readSubBlock encounters a TypeInfo sub-block, it calls addTypeInfo on // the parent block to set it. The template specializations define what to do // for each supported parent block. @@ -584,6 +613,17 @@ template <> llvm::Error addReference(RecordInfo *I, Reference &&R, FieldId F) { } } +template <> +llvm::Error addReference(ConstraintInfo *I, Reference &&R, FieldId F) { + if (F == FieldId::F_concept) { +I->ConceptRef = std::move(R); +return llvm::Error::success(); + } + return llvm::createStringError( + llvm::inconvertibleErrorCode(), + "ConstraintInfo cannot contain this Reference"); +} + template static void addChild(T I, ChildInfoType &&R) { llvm::errs() << "invalid child type for info"; @@ -600,6 +640,9 @@ template <> void addChild(NamespaceInfo *I, EnumInfo &&R) { template <> void addChild(NamespaceInfo *I, TypedefInfo &&R) { I->Children.Typedefs.emplace_back(std::move(R)); } +template <> void addChild(NamespaceInfo *I, ConceptInfo &&R) { + I->Children.Concepts.emplace_back(std::move(R)); +} // Record children: template <> void addChild(RecordInfo *I, FunctionInfo &&R) { @@ -649,6 +692,9 @@ template <> void a
[llvm-branch-commits] [clang-tools-extra] [clang-doc] document global variables (PR #145070)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/145070 >From 87a27c94b00fd8b196eed657056cebe41c314d7d Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Wed, 18 Jun 2025 16:36:49 -0700 Subject: [PATCH] [clang-doc] document global variables --- clang-tools-extra/clang-doc/BitcodeReader.cpp | 40 ++ clang-tools-extra/clang-doc/BitcodeWriter.cpp | 32 +-- clang-tools-extra/clang-doc/BitcodeWriter.h | 6 +++ clang-tools-extra/clang-doc/HTMLGenerator.cpp | 3 ++ .../clang-doc/HTMLMustacheGenerator.cpp | 2 + clang-tools-extra/clang-doc/JSONGenerator.cpp | 14 +++ clang-tools-extra/clang-doc/MDGenerator.cpp | 4 ++ clang-tools-extra/clang-doc/Mapper.cpp| 6 +++ clang-tools-extra/clang-doc/Mapper.h | 1 + .../clang-doc/Representation.cpp | 16 clang-tools-extra/clang-doc/Representation.h | 14 ++- clang-tools-extra/clang-doc/Serialize.cpp | 27 clang-tools-extra/clang-doc/Serialize.h | 4 ++ clang-tools-extra/clang-doc/YAMLGenerator.cpp | 1 + .../test/clang-doc/json/namespace.cpp | 41 +-- .../unittests/clang-doc/BitcodeTest.cpp | 2 + 16 files changed, 188 insertions(+), 25 deletions(-) diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp b/clang-tools-extra/clang-doc/BitcodeReader.cpp index 66852931226bf..cbdd5d245b8de 100644 --- a/clang-tools-extra/clang-doc/BitcodeReader.cpp +++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp @@ -93,6 +93,7 @@ static llvm::Error decodeRecord(const Record &R, InfoType &Field, case InfoType::IT_enum: case InfoType::IT_typedef: case InfoType::IT_concept: + case InfoType::IT_variable: Field = IT; return llvm::Error::success(); } @@ -416,6 +417,23 @@ static llvm::Error parseRecord(const Record &R, unsigned ID, "invalid field for ConstraintInfo"); } +static llvm::Error parseRecord(const Record &R, unsigned ID, + llvm::StringRef Blob, VarInfo *I) { + switch (ID) { + case VAR_USR: +return decodeRecord(R, I->USR, Blob); + case VAR_NAME: +return decodeRecord(R, I->Name, Blob); + case VAR_DEFLOCATION: +return decodeRecord(R, I->DefLoc, Blob); + case VAR_IS_STATIC: +return decodeRecord(R, I->IsStatic, Blob); + default: +return llvm::createStringError(llvm::inconvertibleErrorCode(), + "invalid field for VarInfo"); + } +} + template static llvm::Expected getCommentInfo(T I) { return llvm::createStringError(llvm::inconvertibleErrorCode(), "invalid type cannot contain CommentInfo"); @@ -458,6 +476,10 @@ template <> llvm::Expected getCommentInfo(ConceptInfo *I) { return &I->Description.emplace_back(); } +template <> Expected getCommentInfo(VarInfo *I) { + return &I->Description.emplace_back(); +} + // When readSubBlock encounters a TypeInfo sub-block, it calls addTypeInfo on // the parent block to set it. The template specializations define what to do // for each supported parent block. @@ -497,6 +519,11 @@ template <> llvm::Error addTypeInfo(TypedefInfo *I, TypeInfo &&T) { return llvm::Error::success(); } +template <> llvm::Error addTypeInfo(VarInfo *I, TypeInfo &&T) { + I->Type = std::move(T); + return llvm::Error::success(); +} + template static llvm::Error addReference(T I, Reference &&R, FieldId F) { return llvm::createStringError(llvm::inconvertibleErrorCode(), @@ -643,6 +670,9 @@ template <> void addChild(NamespaceInfo *I, TypedefInfo &&R) { template <> void addChild(NamespaceInfo *I, ConceptInfo &&R) { I->Children.Concepts.emplace_back(std::move(R)); } +template <> void addChild(NamespaceInfo *I, VarInfo &&R) { + I->Children.Variables.emplace_back(std::move(R)); +} // Record children: template <> void addChild(RecordInfo *I, FunctionInfo &&R) { @@ -887,6 +917,13 @@ llvm::Error ClangDocBitcodeReader::readSubBlock(unsigned ID, T I) { addChild(I, std::move(CI)); return llvm::Error::success(); } + case BI_VAR_BLOCK_ID: { +VarInfo VI; +if (auto Err = readBlock(ID, &VI)) + return Err; +addChild(I, std::move(VI)); +return llvm::Error::success(); + } default: return llvm::createStringError(llvm::inconvertibleErrorCode(), "invalid subblock type"); @@ -996,6 +1033,8 @@ ClangDocBitcodeReader::readBlockToInfo(unsigned ID) { return createInfo(ID); case BI_FUNCTION_BLOCK_ID: return createInfo(ID); + case BI_VAR_BLOCK_ID: +return createInfo(ID); default: return llvm::createStringError(llvm::inconvertibleErrorCode(), "cannot create info"); @@ -1035,6 +1074,7 @@ ClangDocBitcodeReader::readBitcode() { case BI_ENUM_BLOCK_ID: case BI_TYPEDEF_BLOCK_ID: case BI_CONCEPT_BLOCK_ID: +case BI_VAR_BLOCK_ID: case BI_FUNCTION_BLOCK_ID: {
[llvm-branch-commits] [clang-tools-extra] [clang-doc] Precommit test for global variables (PR #145069)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/145069 >From f056f70ece95baae3ee245276ece0378f58a21e5 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Thu, 19 Jun 2025 21:25:13 -0700 Subject: [PATCH] [clang-doc] Precommit test for global variables --- .../test/clang-doc/json/namespace.cpp | 20 ++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/test/clang-doc/json/namespace.cpp b/clang-tools-extra/test/clang-doc/json/namespace.cpp index 928864be1feb0..248d47351bd38 100644 --- a/clang-tools-extra/test/clang-doc/json/namespace.cpp +++ b/clang-tools-extra/test/clang-doc/json/namespace.cpp @@ -103,5 +103,23 @@ typedef int MyTypedef; // CHECK-NEXT: } // CHECK-NEXT:], // CHECK-NEXT:"USR": "" -// CHECK-NOT: "Variables": [ +// CHECK-NOT:"Variables": [ +// CHECK-NOT: { +// CHECK-NOT:"IsStatic": true, +// CHECK-NOT:"Location": { +// CHECK-NOT: "Filename": "{{.*}}namespace.cpp", +// CHECK-NOT: "LineNumber": 13 +// CHECK-NOT:}, +// CHECK-NOT:"Name": "Global", +// CHECK-NOT:"Type": { +// COM:FIXME: IsBuiltIn emits as its default value +// CHECK-NOT: "IsBuiltIn": false, +// CHECK-NOT: "IsTemplate": false, +// CHECK-NOT: "Name": "int", +// CHECK-NOT: "QualName": "int", +// CHECK-NOT: "USR": "" +// CHECK-NOT:}, +// CHECK-NOT:"USR": "{{[0-9A-F]*}}" +// CHECK-NOT: } +// CHECK-NOT:] // CHECK-NEXT: } ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add support for concepts (PR #144430)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/144430 >From 63143f08d0044e11562ce142060cb1f2234c9a36 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Mon, 16 Jun 2025 10:50:35 -0700 Subject: [PATCH] add serializeArray for infos with URLs --- clang-tools-extra/clang-doc/BitcodeReader.cpp | 73 +++ clang-tools-extra/clang-doc/BitcodeWriter.cpp | 44 ++- clang-tools-extra/clang-doc/BitcodeWriter.h | 12 +- clang-tools-extra/clang-doc/HTMLGenerator.cpp | 4 + .../clang-doc/HTMLMustacheGenerator.cpp | 2 + clang-tools-extra/clang-doc/JSONGenerator.cpp | 50 clang-tools-extra/clang-doc/MDGenerator.cpp | 5 + clang-tools-extra/clang-doc/Mapper.cpp| 4 + clang-tools-extra/clang-doc/Mapper.h | 1 + .../clang-doc/Representation.cpp | 20 +++ clang-tools-extra/clang-doc/Representation.h | 26 +++- clang-tools-extra/clang-doc/Serialize.cpp | 90 + clang-tools-extra/clang-doc/Serialize.h | 4 + clang-tools-extra/clang-doc/YAMLGenerator.cpp | 2 + .../test/clang-doc/json/class-requires.cpp| 18 +-- .../clang-doc/json/compound-constraints.cpp | 121 ++ .../test/clang-doc/json/concept.cpp | 49 +++ .../test/clang-doc/json/function-requires.cpp | 36 +++--- .../unittests/clang-doc/BitcodeTest.cpp | 2 + 19 files changed, 507 insertions(+), 56 deletions(-) create mode 100644 clang-tools-extra/test/clang-doc/json/compound-constraints.cpp diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp b/clang-tools-extra/clang-doc/BitcodeReader.cpp index 35058abab0663..66852931226bf 100644 --- a/clang-tools-extra/clang-doc/BitcodeReader.cpp +++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp @@ -92,6 +92,7 @@ static llvm::Error decodeRecord(const Record &R, InfoType &Field, case InfoType::IT_default: case InfoType::IT_enum: case InfoType::IT_typedef: + case InfoType::IT_concept: Field = IT; return llvm::Error::success(); } @@ -108,6 +109,7 @@ static llvm::Error decodeRecord(const Record &R, FieldId &Field, case FieldId::F_type: case FieldId::F_child_namespace: case FieldId::F_child_record: + case FieldId::F_concept: case FieldId::F_default: Field = F; return llvm::Error::success(); @@ -391,6 +393,29 @@ static llvm::Error parseRecord(const Record &R, unsigned ID, "invalid field for TemplateParamInfo"); } +static llvm::Error parseRecord(const Record &R, unsigned ID, + llvm::StringRef Blob, ConceptInfo *I) { + switch (ID) { + case CONCEPT_USR: +return decodeRecord(R, I->USR, Blob); + case CONCEPT_NAME: +return decodeRecord(R, I->Name, Blob); + case CONCEPT_IS_TYPE: +return decodeRecord(R, I->IsType, Blob); + case CONCEPT_CONSTRAINT_EXPRESSION: +return decodeRecord(R, I->ConstraintExpression, Blob); + } + llvm_unreachable("invalid field for ConceptInfo"); +} + +static llvm::Error parseRecord(const Record &R, unsigned ID, + llvm::StringRef Blob, ConstraintInfo *I) { + if (ID == CONSTRAINT_EXPRESSION) +return decodeRecord(R, I->ConstraintExpr, Blob); + return llvm::createStringError(llvm::inconvertibleErrorCode(), + "invalid field for ConstraintInfo"); +} + template static llvm::Expected getCommentInfo(T I) { return llvm::createStringError(llvm::inconvertibleErrorCode(), "invalid type cannot contain CommentInfo"); @@ -429,6 +454,10 @@ template <> llvm::Expected getCommentInfo(CommentInfo *I) { return I->Children.back().get(); } +template <> llvm::Expected getCommentInfo(ConceptInfo *I) { + return &I->Description.emplace_back(); +} + // When readSubBlock encounters a TypeInfo sub-block, it calls addTypeInfo on // the parent block to set it. The template specializations define what to do // for each supported parent block. @@ -584,6 +613,17 @@ template <> llvm::Error addReference(RecordInfo *I, Reference &&R, FieldId F) { } } +template <> +llvm::Error addReference(ConstraintInfo *I, Reference &&R, FieldId F) { + if (F == FieldId::F_concept) { +I->ConceptRef = std::move(R); +return llvm::Error::success(); + } + return llvm::createStringError( + llvm::inconvertibleErrorCode(), + "ConstraintInfo cannot contain this Reference"); +} + template static void addChild(T I, ChildInfoType &&R) { llvm::errs() << "invalid child type for info"; @@ -600,6 +640,9 @@ template <> void addChild(NamespaceInfo *I, EnumInfo &&R) { template <> void addChild(NamespaceInfo *I, TypedefInfo &&R) { I->Children.Typedefs.emplace_back(std::move(R)); } +template <> void addChild(NamespaceInfo *I, ConceptInfo &&R) { + I->Children.Concepts.emplace_back(std::move(R)); +} // Record children: template <> void addChild(RecordInfo *I, FunctionInfo &&R) { @@ -649,6 +692,9 @@ template <> void a
[llvm-branch-commits] [clang-tools-extra] [clang-doc] Precommit test for global variables (PR #145069)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/145069 >From f056f70ece95baae3ee245276ece0378f58a21e5 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Thu, 19 Jun 2025 21:25:13 -0700 Subject: [PATCH] [clang-doc] Precommit test for global variables --- .../test/clang-doc/json/namespace.cpp | 20 ++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/test/clang-doc/json/namespace.cpp b/clang-tools-extra/test/clang-doc/json/namespace.cpp index 928864be1feb0..248d47351bd38 100644 --- a/clang-tools-extra/test/clang-doc/json/namespace.cpp +++ b/clang-tools-extra/test/clang-doc/json/namespace.cpp @@ -103,5 +103,23 @@ typedef int MyTypedef; // CHECK-NEXT: } // CHECK-NEXT:], // CHECK-NEXT:"USR": "" -// CHECK-NOT: "Variables": [ +// CHECK-NOT:"Variables": [ +// CHECK-NOT: { +// CHECK-NOT:"IsStatic": true, +// CHECK-NOT:"Location": { +// CHECK-NOT: "Filename": "{{.*}}namespace.cpp", +// CHECK-NOT: "LineNumber": 13 +// CHECK-NOT:}, +// CHECK-NOT:"Name": "Global", +// CHECK-NOT:"Type": { +// COM:FIXME: IsBuiltIn emits as its default value +// CHECK-NOT: "IsBuiltIn": false, +// CHECK-NOT: "IsTemplate": false, +// CHECK-NOT: "Name": "int", +// CHECK-NOT: "QualName": "int", +// CHECK-NOT: "USR": "" +// CHECK-NOT:}, +// CHECK-NOT:"USR": "{{[0-9A-F]*}}" +// CHECK-NOT: } +// CHECK-NOT:] // CHECK-NEXT: } ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] document global variables (PR #145070)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/145070 >From 87a27c94b00fd8b196eed657056cebe41c314d7d Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Wed, 18 Jun 2025 16:36:49 -0700 Subject: [PATCH] [clang-doc] document global variables --- clang-tools-extra/clang-doc/BitcodeReader.cpp | 40 ++ clang-tools-extra/clang-doc/BitcodeWriter.cpp | 32 +-- clang-tools-extra/clang-doc/BitcodeWriter.h | 6 +++ clang-tools-extra/clang-doc/HTMLGenerator.cpp | 3 ++ .../clang-doc/HTMLMustacheGenerator.cpp | 2 + clang-tools-extra/clang-doc/JSONGenerator.cpp | 14 +++ clang-tools-extra/clang-doc/MDGenerator.cpp | 4 ++ clang-tools-extra/clang-doc/Mapper.cpp| 6 +++ clang-tools-extra/clang-doc/Mapper.h | 1 + .../clang-doc/Representation.cpp | 16 clang-tools-extra/clang-doc/Representation.h | 14 ++- clang-tools-extra/clang-doc/Serialize.cpp | 27 clang-tools-extra/clang-doc/Serialize.h | 4 ++ clang-tools-extra/clang-doc/YAMLGenerator.cpp | 1 + .../test/clang-doc/json/namespace.cpp | 41 +-- .../unittests/clang-doc/BitcodeTest.cpp | 2 + 16 files changed, 188 insertions(+), 25 deletions(-) diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp b/clang-tools-extra/clang-doc/BitcodeReader.cpp index 66852931226bf..cbdd5d245b8de 100644 --- a/clang-tools-extra/clang-doc/BitcodeReader.cpp +++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp @@ -93,6 +93,7 @@ static llvm::Error decodeRecord(const Record &R, InfoType &Field, case InfoType::IT_enum: case InfoType::IT_typedef: case InfoType::IT_concept: + case InfoType::IT_variable: Field = IT; return llvm::Error::success(); } @@ -416,6 +417,23 @@ static llvm::Error parseRecord(const Record &R, unsigned ID, "invalid field for ConstraintInfo"); } +static llvm::Error parseRecord(const Record &R, unsigned ID, + llvm::StringRef Blob, VarInfo *I) { + switch (ID) { + case VAR_USR: +return decodeRecord(R, I->USR, Blob); + case VAR_NAME: +return decodeRecord(R, I->Name, Blob); + case VAR_DEFLOCATION: +return decodeRecord(R, I->DefLoc, Blob); + case VAR_IS_STATIC: +return decodeRecord(R, I->IsStatic, Blob); + default: +return llvm::createStringError(llvm::inconvertibleErrorCode(), + "invalid field for VarInfo"); + } +} + template static llvm::Expected getCommentInfo(T I) { return llvm::createStringError(llvm::inconvertibleErrorCode(), "invalid type cannot contain CommentInfo"); @@ -458,6 +476,10 @@ template <> llvm::Expected getCommentInfo(ConceptInfo *I) { return &I->Description.emplace_back(); } +template <> Expected getCommentInfo(VarInfo *I) { + return &I->Description.emplace_back(); +} + // When readSubBlock encounters a TypeInfo sub-block, it calls addTypeInfo on // the parent block to set it. The template specializations define what to do // for each supported parent block. @@ -497,6 +519,11 @@ template <> llvm::Error addTypeInfo(TypedefInfo *I, TypeInfo &&T) { return llvm::Error::success(); } +template <> llvm::Error addTypeInfo(VarInfo *I, TypeInfo &&T) { + I->Type = std::move(T); + return llvm::Error::success(); +} + template static llvm::Error addReference(T I, Reference &&R, FieldId F) { return llvm::createStringError(llvm::inconvertibleErrorCode(), @@ -643,6 +670,9 @@ template <> void addChild(NamespaceInfo *I, TypedefInfo &&R) { template <> void addChild(NamespaceInfo *I, ConceptInfo &&R) { I->Children.Concepts.emplace_back(std::move(R)); } +template <> void addChild(NamespaceInfo *I, VarInfo &&R) { + I->Children.Variables.emplace_back(std::move(R)); +} // Record children: template <> void addChild(RecordInfo *I, FunctionInfo &&R) { @@ -887,6 +917,13 @@ llvm::Error ClangDocBitcodeReader::readSubBlock(unsigned ID, T I) { addChild(I, std::move(CI)); return llvm::Error::success(); } + case BI_VAR_BLOCK_ID: { +VarInfo VI; +if (auto Err = readBlock(ID, &VI)) + return Err; +addChild(I, std::move(VI)); +return llvm::Error::success(); + } default: return llvm::createStringError(llvm::inconvertibleErrorCode(), "invalid subblock type"); @@ -996,6 +1033,8 @@ ClangDocBitcodeReader::readBlockToInfo(unsigned ID) { return createInfo(ID); case BI_FUNCTION_BLOCK_ID: return createInfo(ID); + case BI_VAR_BLOCK_ID: +return createInfo(ID); default: return llvm::createStringError(llvm::inconvertibleErrorCode(), "cannot create info"); @@ -1035,6 +1074,7 @@ ClangDocBitcodeReader::readBitcode() { case BI_ENUM_BLOCK_ID: case BI_TYPEDEF_BLOCK_ID: case BI_CONCEPT_BLOCK_ID: +case BI_VAR_BLOCK_ID: case BI_FUNCTION_BLOCK_ID: {
[llvm-branch-commits] [clang-tools-extra] [clang-doc] document global variables (PR #145070)
https://github.com/evelez7 ready_for_review https://github.com/llvm/llvm-project/pull/145070 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] Precommit test for global variables (PR #145069)
https://github.com/evelez7 ready_for_review https://github.com/llvm/llvm-project/pull/145069 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add support for concepts (PR #144430)
https://github.com/evelez7 edited https://github.com/llvm/llvm-project/pull/144430 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add support for concepts (PR #144430)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/144430 >From 72e4a2441b93546c3e275078d1525ae01e73e361 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Mon, 16 Jun 2025 10:50:35 -0700 Subject: [PATCH] remove extraneous change --- clang-tools-extra/clang-doc/BitcodeReader.cpp | 72 +++ clang-tools-extra/clang-doc/BitcodeWriter.cpp | 44 ++- clang-tools-extra/clang-doc/BitcodeWriter.h | 12 +- clang-tools-extra/clang-doc/HTMLGenerator.cpp | 4 + .../clang-doc/HTMLMustacheGenerator.cpp | 2 + clang-tools-extra/clang-doc/JSONGenerator.cpp | 46 +++ clang-tools-extra/clang-doc/MDGenerator.cpp | 5 + clang-tools-extra/clang-doc/Mapper.cpp| 4 + clang-tools-extra/clang-doc/Mapper.h | 1 + .../clang-doc/Representation.cpp | 13 ++ clang-tools-extra/clang-doc/Representation.h | 26 +++- clang-tools-extra/clang-doc/Serialize.cpp | 90 + clang-tools-extra/clang-doc/Serialize.h | 4 + clang-tools-extra/clang-doc/YAMLGenerator.cpp | 2 + .../test/clang-doc/json/class-requires.cpp| 18 +-- .../clang-doc/json/compound-constraints.cpp | 121 ++ .../test/clang-doc/json/concept.cpp | 48 +++ .../test/clang-doc/json/function-requires.cpp | 36 +++--- .../unittests/clang-doc/BitcodeTest.cpp | 2 + 19 files changed, 494 insertions(+), 56 deletions(-) create mode 100644 clang-tools-extra/test/clang-doc/json/compound-constraints.cpp diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp b/clang-tools-extra/clang-doc/BitcodeReader.cpp index 35058abab0663..5b70280e7dba8 100644 --- a/clang-tools-extra/clang-doc/BitcodeReader.cpp +++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp @@ -92,6 +92,7 @@ static llvm::Error decodeRecord(const Record &R, InfoType &Field, case InfoType::IT_default: case InfoType::IT_enum: case InfoType::IT_typedef: + case InfoType::IT_concept: Field = IT; return llvm::Error::success(); } @@ -108,6 +109,7 @@ static llvm::Error decodeRecord(const Record &R, FieldId &Field, case FieldId::F_type: case FieldId::F_child_namespace: case FieldId::F_child_record: + case FieldId::F_concept: case FieldId::F_default: Field = F; return llvm::Error::success(); @@ -391,6 +393,29 @@ static llvm::Error parseRecord(const Record &R, unsigned ID, "invalid field for TemplateParamInfo"); } +static llvm::Error parseRecord(const Record &R, unsigned ID, + llvm::StringRef Blob, ConceptInfo *I) { + switch (ID) { + case CONCEPT_USR: +return decodeRecord(R, I->USR, Blob); + case CONCEPT_NAME: +return decodeRecord(R, I->Name, Blob); + case CONCEPT_IS_TYPE: +return decodeRecord(R, I->IsType, Blob); + case CONCEPT_CONSTRAINT_EXPRESSION: +return decodeRecord(R, I->ConstraintExpression, Blob); + } + llvm_unreachable("invalid field for ConceptInfo"); +} + +static llvm::Error parseRecord(const Record &R, unsigned ID, + llvm::StringRef Blob, ConstraintInfo *I) { + if (ID == CONSTRAINT_EXPRESSION) +return decodeRecord(R, I->Expression, Blob); + return llvm::createStringError(llvm::inconvertibleErrorCode(), + "invalid field for ConstraintInfo"); +} + template static llvm::Expected getCommentInfo(T I) { return llvm::createStringError(llvm::inconvertibleErrorCode(), "invalid type cannot contain CommentInfo"); @@ -429,6 +454,10 @@ template <> llvm::Expected getCommentInfo(CommentInfo *I) { return I->Children.back().get(); } +template <> llvm::Expected getCommentInfo(ConceptInfo *I) { + return &I->Description.emplace_back(); +} + // When readSubBlock encounters a TypeInfo sub-block, it calls addTypeInfo on // the parent block to set it. The template specializations define what to do // for each supported parent block. @@ -584,6 +613,18 @@ template <> llvm::Error addReference(RecordInfo *I, Reference &&R, FieldId F) { } } +template <> +llvm::Error addReference(ConstraintInfo *I, Reference &&R, FieldId F) { + switch (F) { + case FieldId::F_concept: +I->ConceptRef = std::move(R); +return llvm::Error::success(); + default: +return llvm::createStringError(llvm::inconvertibleErrorCode(), + "invalid type cannot contain Reference"); + } +} + template static void addChild(T I, ChildInfoType &&R) { llvm::errs() << "invalid child type for info"; @@ -600,6 +641,9 @@ template <> void addChild(NamespaceInfo *I, EnumInfo &&R) { template <> void addChild(NamespaceInfo *I, TypedefInfo &&R) { I->Children.Typedefs.emplace_back(std::move(R)); } +template <> void addChild(NamespaceInfo *I, ConceptInfo &&R) { + I->Children.Concepts.emplace_back(std::move(R)); +} // Record children: template <> void addChild(RecordInfo *I, FunctionInfo &&R) { @@ -649,6 +693,9 @@
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add support for concepts (PR #144430)
evelez7 wrote: Linux CI shows failing but looks like all tests passed despite that. Added compound constraint support which just goes through the nested expressions until it reaches the constraint. https://github.com/llvm/llvm-project/pull/144430 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add support for concepts (PR #144430)
https://github.com/evelez7 ready_for_review https://github.com/llvm/llvm-project/pull/144430 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add namespaces to JSON generator (PR #143209)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/143209 >From 979bfbf20654c7814a607201827ecc9f327e8b74 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Tue, 3 Jun 2025 11:39:48 -0700 Subject: [PATCH] [clang-doc] add namespaces to JSON generator --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 36 ++ clang-tools-extra/clang-doc/Serialize.cpp | 1 + .../clang-doc/json/function-specifiers.cpp| 25 .../test/clang-doc/json/namespace.cpp | 108 ++ .../unittests/clang-doc/JSONGeneratorTest.cpp | 73 5 files changed, 243 insertions(+) create mode 100644 clang-tools-extra/test/clang-doc/json/function-specifiers.cpp create mode 100644 clang-tools-extra/test/clang-doc/json/namespace.cpp diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index ef9c147f1a5e2..93c73acb4cb64 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -446,6 +446,41 @@ static void serializeInfo(const RecordInfo &I, json::Object &Obj, serializeCommonChildren(I.Children, Obj, RepositoryUrl); } +static void serializeInfo(const NamespaceInfo &I, json::Object &Obj, + std::optional RepositoryUrl) { + serializeCommonAttributes(I, Obj, RepositoryUrl); + SmallString<64> BasePath = I.getRelativeFilePath(""); + Obj["NamespacePath"] = BasePath; + + if (!I.Children.Namespaces.empty()) { +json::Value NamespacesArray = Array(); +auto &NamespacesArrayRef = *NamespacesArray.getAsArray(); +NamespacesArrayRef.reserve(I.Children.Namespaces.size()); +for (auto &Namespace : I.Children.Namespaces) { + json::Value NamespaceVal = Object(); + auto &NamespaceObj = *NamespaceVal.getAsObject(); + serializeReference(Namespace, NamespaceObj, BasePath); + NamespacesArrayRef.push_back(NamespaceVal); +} +Obj["Namespaces"] = NamespacesArray; + } + + if (!I.Children.Functions.empty()) { +json::Value FunctionsArray = Array(); +auto &FunctionsArrayRef = *FunctionsArray.getAsArray(); +FunctionsArrayRef.reserve(I.Children.Functions.size()); +for (const auto &Function : I.Children.Functions) { + json::Value FunctionVal = Object(); + auto &FunctionObj = *FunctionVal.getAsObject(); + serializeInfo(Function, FunctionObj, RepositoryUrl); + FunctionsArrayRef.push_back(FunctionVal); +} +Obj["Functions"] = FunctionsArray; + } + + serializeCommonChildren(I.Children, Obj, RepositoryUrl); +} + Error JSONGenerator::generateDocs( StringRef RootDir, llvm::StringMap> Infos, const ClangDocContext &CDCtx) { @@ -488,6 +523,7 @@ Error JSONGenerator::generateDocForInfo(Info *I, raw_ostream &OS, switch (I->IT) { case InfoType::IT_namespace: +serializeInfo(*static_cast(I), Obj, CDCtx.RepositoryUrl); break; case InfoType::IT_record: serializeInfo(*static_cast(I), Obj, CDCtx.RepositoryUrl); diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp index 462001b3f3027..3cda38115ff7f 100644 --- a/clang-tools-extra/clang-doc/Serialize.cpp +++ b/clang-tools-extra/clang-doc/Serialize.cpp @@ -742,6 +742,7 @@ static void populateFunctionInfo(FunctionInfo &I, const FunctionDecl *D, I.ReturnType = getTypeInfoForType(D->getReturnType(), LO); I.Prototype = getFunctionPrototype(D); parseParameters(I, D); + I.IsStatic = D->isStatic(); populateTemplateParameters(I.Template, D); diff --git a/clang-tools-extra/test/clang-doc/json/function-specifiers.cpp b/clang-tools-extra/test/clang-doc/json/function-specifiers.cpp new file mode 100644 index 0..7005fb7b3e66e --- /dev/null +++ b/clang-tools-extra/test/clang-doc/json/function-specifiers.cpp @@ -0,0 +1,25 @@ +// RUN: rm -rf %t && mkdir -p %t +// RUN: clang-doc --output=%t --format=json --executor=standalone %s +// RUN: FileCheck %s < %t/GlobalNamespace/index.json + +static void myFunction() {} + +void noExceptFunction() noexcept {} + +inline void inlineFunction() {} + +extern void externFunction() {} + +constexpr void constexprFunction() {} + +// CHECK: "Functions": [ +// CHECK-NEXT: { +// CHECK: "IsStatic": true, +// COM:FIXME: Emit ExceptionSpecificationType +// CHECK-NOT: "ExceptionSpecifcation" : "noexcept", +// COM:FIXME: Emit inline +// CHECK-NOT: "IsInline": true, +// COM:FIXME: Emit extern +// CHECK-NOT: "IsExtern": true, +// COM:FIXME: Emit constexpr +// CHECK-NOT: "IsConstexpr": true, diff --git a/clang-tools-extra/test/clang-doc/json/namespace.cpp b/clang-tools-extra/test/clang-doc/json/namespace.cpp new file mode 100644 index 0..885dbd841ac2e --- /dev/null +++ b/clang-tools-extra/test/clang-doc/json/namespace.cpp @@ -0,0 +1,108 @@ +// RUN: rm -rf %t && mkdir -p %t +// RUN: clang
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add namespaces to JSON generator (PR #143209)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/143209 >From dd5653605e838e7df8ade308f0cfff1d0113790a Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Tue, 3 Jun 2025 11:39:48 -0700 Subject: [PATCH] [clang-doc] add namespaces to JSON generator --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 34 ++ clang-tools-extra/clang-doc/Serialize.cpp | 1 + .../clang-doc/json/function-specifiers.cpp| 25 .../test/clang-doc/json/namespace.cpp | 107 ++ .../unittests/clang-doc/JSONGeneratorTest.cpp | 72 5 files changed, 239 insertions(+) create mode 100644 clang-tools-extra/test/clang-doc/json/function-specifiers.cpp create mode 100644 clang-tools-extra/test/clang-doc/json/namespace.cpp diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index 086da09165329..0f7cbafcf5135 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -440,6 +440,39 @@ static void serializeInfo(const RecordInfo &I, json::Object &Obj, serializeCommonChildren(I.Children, Obj, RepositoryUrl); } +static void serializeInfo(const NamespaceInfo &I, json::Object &Obj, + std::optional RepositoryUrl) { + serializeCommonAttributes(I, Obj, RepositoryUrl); + + if (!I.Children.Namespaces.empty()) { +json::Value NamespacesArray = Array(); +auto &NamespacesArrayRef = *NamespacesArray.getAsArray(); +NamespacesArrayRef.reserve(I.Children.Namespaces.size()); +for (auto &Namespace : I.Children.Namespaces) { + json::Value NamespaceVal = Object(); + auto &NamespaceObj = *NamespaceVal.getAsObject(); + serializeReference(Namespace, NamespaceObj); + NamespacesArrayRef.push_back(NamespaceVal); +} +Obj["Namespaces"] = NamespacesArray; + } + + if (!I.Children.Functions.empty()) { +json::Value FunctionsArray = Array(); +auto &FunctionsArrayRef = *FunctionsArray.getAsArray(); +FunctionsArrayRef.reserve(I.Children.Functions.size()); +for (const auto &Function : I.Children.Functions) { + json::Value FunctionVal = Object(); + auto &FunctionObj = *FunctionVal.getAsObject(); + serializeInfo(Function, FunctionObj, RepositoryUrl); + FunctionsArrayRef.push_back(FunctionVal); +} +Obj["Functions"] = FunctionsArray; + } + + serializeCommonChildren(I.Children, Obj, RepositoryUrl); +} + Error JSONGenerator::generateDocs( StringRef RootDir, llvm::StringMap> Infos, const ClangDocContext &CDCtx) { @@ -482,6 +515,7 @@ Error JSONGenerator::generateDocForInfo(Info *I, raw_ostream &OS, switch (I->IT) { case InfoType::IT_namespace: +serializeInfo(*static_cast(I), Obj, CDCtx.RepositoryUrl); break; case InfoType::IT_record: serializeInfo(*static_cast(I), Obj, CDCtx.RepositoryUrl); diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp index 462001b3f3027..3cda38115ff7f 100644 --- a/clang-tools-extra/clang-doc/Serialize.cpp +++ b/clang-tools-extra/clang-doc/Serialize.cpp @@ -742,6 +742,7 @@ static void populateFunctionInfo(FunctionInfo &I, const FunctionDecl *D, I.ReturnType = getTypeInfoForType(D->getReturnType(), LO); I.Prototype = getFunctionPrototype(D); parseParameters(I, D); + I.IsStatic = D->isStatic(); populateTemplateParameters(I.Template, D); diff --git a/clang-tools-extra/test/clang-doc/json/function-specifiers.cpp b/clang-tools-extra/test/clang-doc/json/function-specifiers.cpp new file mode 100644 index 0..7005fb7b3e66e --- /dev/null +++ b/clang-tools-extra/test/clang-doc/json/function-specifiers.cpp @@ -0,0 +1,25 @@ +// RUN: rm -rf %t && mkdir -p %t +// RUN: clang-doc --output=%t --format=json --executor=standalone %s +// RUN: FileCheck %s < %t/GlobalNamespace/index.json + +static void myFunction() {} + +void noExceptFunction() noexcept {} + +inline void inlineFunction() {} + +extern void externFunction() {} + +constexpr void constexprFunction() {} + +// CHECK: "Functions": [ +// CHECK-NEXT: { +// CHECK: "IsStatic": true, +// COM:FIXME: Emit ExceptionSpecificationType +// CHECK-NOT: "ExceptionSpecifcation" : "noexcept", +// COM:FIXME: Emit inline +// CHECK-NOT: "IsInline": true, +// COM:FIXME: Emit extern +// CHECK-NOT: "IsExtern": true, +// COM:FIXME: Emit constexpr +// CHECK-NOT: "IsConstexpr": true, diff --git a/clang-tools-extra/test/clang-doc/json/namespace.cpp b/clang-tools-extra/test/clang-doc/json/namespace.cpp new file mode 100644 index 0..928864be1feb0 --- /dev/null +++ b/clang-tools-extra/test/clang-doc/json/namespace.cpp @@ -0,0 +1,107 @@ +// RUN: rm -rf %t && mkdir -p %t +// RUN: clang-doc --output=%t --format=json --executor=standalone %s +// RUN: FileCheck %s < %t/GlobalNamespace/inde
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add namespaces to JSON generator (PR #143209)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/143209 >From dd5653605e838e7df8ade308f0cfff1d0113790a Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Tue, 3 Jun 2025 11:39:48 -0700 Subject: [PATCH] [clang-doc] add namespaces to JSON generator --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 34 ++ clang-tools-extra/clang-doc/Serialize.cpp | 1 + .../clang-doc/json/function-specifiers.cpp| 25 .../test/clang-doc/json/namespace.cpp | 107 ++ .../unittests/clang-doc/JSONGeneratorTest.cpp | 72 5 files changed, 239 insertions(+) create mode 100644 clang-tools-extra/test/clang-doc/json/function-specifiers.cpp create mode 100644 clang-tools-extra/test/clang-doc/json/namespace.cpp diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index 086da09165329..0f7cbafcf5135 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -440,6 +440,39 @@ static void serializeInfo(const RecordInfo &I, json::Object &Obj, serializeCommonChildren(I.Children, Obj, RepositoryUrl); } +static void serializeInfo(const NamespaceInfo &I, json::Object &Obj, + std::optional RepositoryUrl) { + serializeCommonAttributes(I, Obj, RepositoryUrl); + + if (!I.Children.Namespaces.empty()) { +json::Value NamespacesArray = Array(); +auto &NamespacesArrayRef = *NamespacesArray.getAsArray(); +NamespacesArrayRef.reserve(I.Children.Namespaces.size()); +for (auto &Namespace : I.Children.Namespaces) { + json::Value NamespaceVal = Object(); + auto &NamespaceObj = *NamespaceVal.getAsObject(); + serializeReference(Namespace, NamespaceObj); + NamespacesArrayRef.push_back(NamespaceVal); +} +Obj["Namespaces"] = NamespacesArray; + } + + if (!I.Children.Functions.empty()) { +json::Value FunctionsArray = Array(); +auto &FunctionsArrayRef = *FunctionsArray.getAsArray(); +FunctionsArrayRef.reserve(I.Children.Functions.size()); +for (const auto &Function : I.Children.Functions) { + json::Value FunctionVal = Object(); + auto &FunctionObj = *FunctionVal.getAsObject(); + serializeInfo(Function, FunctionObj, RepositoryUrl); + FunctionsArrayRef.push_back(FunctionVal); +} +Obj["Functions"] = FunctionsArray; + } + + serializeCommonChildren(I.Children, Obj, RepositoryUrl); +} + Error JSONGenerator::generateDocs( StringRef RootDir, llvm::StringMap> Infos, const ClangDocContext &CDCtx) { @@ -482,6 +515,7 @@ Error JSONGenerator::generateDocForInfo(Info *I, raw_ostream &OS, switch (I->IT) { case InfoType::IT_namespace: +serializeInfo(*static_cast(I), Obj, CDCtx.RepositoryUrl); break; case InfoType::IT_record: serializeInfo(*static_cast(I), Obj, CDCtx.RepositoryUrl); diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp index 462001b3f3027..3cda38115ff7f 100644 --- a/clang-tools-extra/clang-doc/Serialize.cpp +++ b/clang-tools-extra/clang-doc/Serialize.cpp @@ -742,6 +742,7 @@ static void populateFunctionInfo(FunctionInfo &I, const FunctionDecl *D, I.ReturnType = getTypeInfoForType(D->getReturnType(), LO); I.Prototype = getFunctionPrototype(D); parseParameters(I, D); + I.IsStatic = D->isStatic(); populateTemplateParameters(I.Template, D); diff --git a/clang-tools-extra/test/clang-doc/json/function-specifiers.cpp b/clang-tools-extra/test/clang-doc/json/function-specifiers.cpp new file mode 100644 index 0..7005fb7b3e66e --- /dev/null +++ b/clang-tools-extra/test/clang-doc/json/function-specifiers.cpp @@ -0,0 +1,25 @@ +// RUN: rm -rf %t && mkdir -p %t +// RUN: clang-doc --output=%t --format=json --executor=standalone %s +// RUN: FileCheck %s < %t/GlobalNamespace/index.json + +static void myFunction() {} + +void noExceptFunction() noexcept {} + +inline void inlineFunction() {} + +extern void externFunction() {} + +constexpr void constexprFunction() {} + +// CHECK: "Functions": [ +// CHECK-NEXT: { +// CHECK: "IsStatic": true, +// COM:FIXME: Emit ExceptionSpecificationType +// CHECK-NOT: "ExceptionSpecifcation" : "noexcept", +// COM:FIXME: Emit inline +// CHECK-NOT: "IsInline": true, +// COM:FIXME: Emit extern +// CHECK-NOT: "IsExtern": true, +// COM:FIXME: Emit constexpr +// CHECK-NOT: "IsConstexpr": true, diff --git a/clang-tools-extra/test/clang-doc/json/namespace.cpp b/clang-tools-extra/test/clang-doc/json/namespace.cpp new file mode 100644 index 0..928864be1feb0 --- /dev/null +++ b/clang-tools-extra/test/clang-doc/json/namespace.cpp @@ -0,0 +1,107 @@ +// RUN: rm -rf %t && mkdir -p %t +// RUN: clang-doc --output=%t --format=json --executor=standalone %s +// RUN: FileCheck %s < %t/GlobalNamespace/inde
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add namespaces to JSON generator (PR #143209)
@@ -0,0 +1,108 @@ +// RUN: rm -rf %t && mkdir -p %t +// RUN: clang-doc --output=%t --format=json --executor=standalone %s +// RUN: FileCheck %s < %t/GlobalNamespace/index.json + +class MyClass {}; + +void myFunction(int Param); + +namespace NestedNamespace { +} // namespace NestedNamespace + +// FIXME: Global variables are not mapped or serialized. +static int Global; + +enum Color { + RED, + GREEN, + BLUE = 5 +}; + +typedef int MyTypedef; + +// CHECK: { +// CHECK-NEXT:"Enums": [ +// CHECK-NEXT: { +// CHECK-NEXT:"Location": { +// CHECK-NEXT: "Filename": "{{.*}}namespace.cpp", +// CHECK-NEXT: "LineNumber": 15 +// CHECK-NEXT:}, +// CHECK-NEXT:"Members": [ +// CHECK-NEXT: { +// CHECK-NEXT:"Name": "RED", +// CHECK-NEXT:"Value": "0" +// CHECK-NEXT: }, +// CHECK-NEXT: { +// CHECK-NEXT:"Name": "GREEN", +// CHECK-NEXT:"Value": "1" +// CHECK-NEXT: }, +// CHECK-NEXT: { +// CHECK-NEXT:"Name": "BLUE", +// CHECK-NEXT:"ValueExpr": "5" +// CHECK-NEXT: } +// CHECK-NEXT:], +// CHECK-NEXT:"Name": "Color", +// CHECK-NEXT:"Scoped": false, +// CHECK-NEXT:"USR": "{{[0-9A-F]*}}" +// CHECK-NEXT: } +// CHECK-NEXT:], +// CHECK-NEXT: "Functions": [ +// CHECK-NEXT: { +// CHECK-NEXT: "IsStatic": false, +// CHECK-NEXT: "Name": "myFunction", +// CHECK-NEXT: "Params": [ +// CHECK-NEXT: { +// CHECK-NEXT: "Name": "Param", +// CHECK-NEXT: "Type": "int" +// CHECK-NEXT: } +// CHECK-NEXT: ], +// CHECK-NEXT: "ReturnType": { +// CHECK-NEXT: "IsBuiltIn": false, +// CHECK-NEXT: "IsTemplate": false, +// CHECK-NEXT: "Name": "void", +// CHECK-NEXT: "QualName": "void", +// CHECK-NEXT: "USR": "" evelez7 wrote: Yes those USRs are fixed. `IsBuiltIn` is set in Serialize.cpp and I just checked in gdb. `IsBuiltIn` is true for `void` but it gets emitted to its default value. I'm not sure how it works but I have a feeling the bitcode reader doesn't properly serialize everything. https://github.com/llvm/llvm-project/pull/143209 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add namespaces to JSON generator (PR #143209)
@@ -0,0 +1,25 @@ +// RUN: rm -rf %t && mkdir -p %t +// RUN: clang-doc --output=%t --format=json --executor=standalone %s +// RUN: FileCheck %s < %t/GlobalNamespace/index.json + +static void myFunction() {} + +void noExceptFunction() noexcept {} + +inline void inlineFunction() {} + +extern void externFunction() {} + +constexpr void constexprFunction() {} + +// CHECK: "Functions": [ +// CHECK-NEXT: { +// CHECK: "IsStatic": true, evelez7 wrote: Yeah this was motivated by convenience. The functions are serialized in order, so I know that the first entry to be checked will be the static function. Hence, the `"IsStatic": true` check. The contents of an object are serialized alphabetically, so I haven't figured how to check the name first, since that comes after all the `Is` fields. That would be useful. I can investigate this more. https://github.com/llvm/llvm-project/pull/143209 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add namespaces to JSON generator (PR #143209)
@@ -171,5 +171,78 @@ TEST(JSONGeneratorTest, emitRecordJSON) { })raw"; EXPECT_EQ(Expected, Actual.str()); } + +TEST(JSONGeneratorTest, emitNamespaceJSON) { + NamespaceInfo I; + I.Name = "Namespace"; + I.Path = "path/to/A"; + I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace); + + I.Children.Namespaces.emplace_back( + EmptySID, "ChildNamespace", InfoType::IT_namespace, + "path::to::A::Namespace::ChildNamespace", "path/to/A/Namespace"); + I.Children.Records.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record, + "path::to::A::Namespace::ChildStruct", + "path/to/A/Namespace"); + I.Children.Functions.emplace_back(); + I.Children.Functions.back().Name = "OneFunction"; + I.Children.Functions.back().Access = AccessSpecifier::AS_none; + I.Children.Enums.emplace_back(); + I.Children.Enums.back().Name = "OneEnum"; + + auto G = getJSONGenerator(); + assert(G); + std::string Buffer; + llvm::raw_string_ostream Actual(Buffer); + auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext()); + assert(!Err); + std::string Expected = R"raw({ + "Enums": [ +{ + "Name": "OneEnum", + "Scoped": false, + "USR": "" +} + ], + "Functions": [ +{ + "IsStatic": false, + "Name": "OneFunction", + "ReturnType": { +"IsBuiltIn": false, +"IsTemplate": false, +"Name": "", +"QualName": "", +"USR": "" + }, + "USR": "" +} + ], + "Name": "Namespace", + "Namespace": [ +"A" + ], + "NamespacePath": "path/to/A/Namespace", evelez7 wrote: I've been trying to figure this out and I am inclined to remove this field altogether (in fact I have the changes staged right now). I copied the Mustache behavior from here: https://github.com/llvm/llvm-project/blob/4e6896244f4129a22e311f7f6290a595b6f03b75/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp#L473-L475 And I use this behavior in the initial JSON generator patch as well because Mustache does it for all entities: https://github.com/llvm/llvm-project/blob/b567c6cc7c80ca567bf664ded8ead0a744813e52/clang-tools-extra/clang-doc/JSONGenerator.cpp#L201-L203 I think this behavior is **incorrect** for the JSON generator and a mistake on my part. References already have their own Path fields and I think that's what should be emitted, not a relative file path for linking documents. If the JSON ends up being fed to an HTML generator, then I think the HTML generator should construct its own paths for linking. @ilovepi It was also incorrect because instead of checking for the proper `path/to/A/r`, the test was emitting checking for the filename link (something like `../index.json`) which was again an oversight by me. As for Windows, yes it's particularly nasty for unit tests because I can't use the nice regex stuff (`{{[.*]}}` in there, so I'm figuring that out. I don't know how YAML solved it. https://github.com/llvm/llvm-project/pull/143209 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add namespaces to JSON generator (PR #143209)
@@ -171,5 +171,78 @@ TEST(JSONGeneratorTest, emitRecordJSON) { })raw"; EXPECT_EQ(Expected, Actual.str()); } + +TEST(JSONGeneratorTest, emitNamespaceJSON) { + NamespaceInfo I; + I.Name = "Namespace"; + I.Path = "path/to/A"; + I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace); + + I.Children.Namespaces.emplace_back( + EmptySID, "ChildNamespace", InfoType::IT_namespace, + "path::to::A::Namespace::ChildNamespace", "path/to/A/Namespace"); + I.Children.Records.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record, + "path::to::A::Namespace::ChildStruct", + "path/to/A/Namespace"); + I.Children.Functions.emplace_back(); + I.Children.Functions.back().Name = "OneFunction"; + I.Children.Functions.back().Access = AccessSpecifier::AS_none; + I.Children.Enums.emplace_back(); + I.Children.Enums.back().Name = "OneEnum"; + + auto G = getJSONGenerator(); + assert(G); + std::string Buffer; + llvm::raw_string_ostream Actual(Buffer); + auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext()); + assert(!Err); + std::string Expected = R"raw({ + "Enums": [ +{ + "Name": "OneEnum", + "Scoped": false, + "USR": "" +} + ], + "Functions": [ +{ + "IsStatic": false, + "Name": "OneFunction", + "ReturnType": { +"IsBuiltIn": false, +"IsTemplate": false, +"Name": "", +"QualName": "", +"USR": "" + }, + "USR": "" +} + ], + "Name": "Namespace", + "Namespace": [ +"A" + ], + "NamespacePath": "path/to/A/Namespace", evelez7 wrote: Also this "NamespacePath" is not generated by any other generator besides Mustache and it's not currently used in any Mustache templates. https://github.com/llvm/llvm-project/pull/143209 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add namespaces to JSON generator (PR #143209)
https://github.com/evelez7 edited https://github.com/llvm/llvm-project/pull/143209 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add namespaces to JSON generator (PR #143209)
https://github.com/evelez7 edited https://github.com/llvm/llvm-project/pull/143209 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] refactor BitcodeReader::readSubBlock (PR #145835)
https://github.com/evelez7 created https://github.com/llvm/llvm-project/pull/145835 None >From c15962ea2a37f3d9896fa77914aee67ccf3b5d3f Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Tue, 24 Jun 2025 21:08:36 -0700 Subject: [PATCH] [clang-doc] refactor BitcodeReader::readSubBlock --- clang-tools-extra/clang-doc/BitcodeReader.cpp | 129 -- clang-tools-extra/clang-doc/BitcodeReader.h | 7 + 2 files changed, 61 insertions(+), 75 deletions(-) diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp b/clang-tools-extra/clang-doc/BitcodeReader.cpp index cbdd5d245b8de..437599b879748 100644 --- a/clang-tools-extra/clang-doc/BitcodeReader.cpp +++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp @@ -800,11 +800,37 @@ llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, T I) { } } -// TODO: Create a helper that can receive a function to reduce repetition for -// most blocks. +template +llvm::Error ClangDocBitcodeReader::handleSubBlock(unsigned ID, T Parent, + Callback Function) { + InfoType Info; + if (auto Err = readBlock(ID, &Info)) +return Err; + Function(Parent, std::move(Info)); + return llvm::Error::success(); +} + +template +llvm::Error ClangDocBitcodeReader::handleTypeSubBlock(unsigned ID, T Parent, + Callback Function) { + InfoType Info; + if (auto Err = readBlock(ID, &Info)) +return Err; + if (auto Err = Function(Parent, std::move(Info))) +return Err; + return llvm::Error::success(); +} + template llvm::Error ClangDocBitcodeReader::readSubBlock(unsigned ID, T I) { llvm::TimeTraceScope("Reducing infos", "readSubBlock"); + + static auto CreateAddFunc = [](auto AddFunc) { +return [AddFunc](auto Parent, auto Child) { + return AddFunc(Parent, std::move(Child)); +}; + }; + switch (ID) { // Blocks can only have certain types of sub blocks. case BI_COMMENT_BLOCK_ID: { @@ -816,28 +842,16 @@ llvm::Error ClangDocBitcodeReader::readSubBlock(unsigned ID, T I) { return llvm::Error::success(); } case BI_TYPE_BLOCK_ID: { -TypeInfo TI; -if (auto Err = readBlock(ID, &TI)) - return Err; -if (auto Err = addTypeInfo(I, std::move(TI))) - return Err; -return llvm::Error::success(); +return handleTypeSubBlock( +ID, I, CreateAddFunc(addTypeInfo)); } case BI_FIELD_TYPE_BLOCK_ID: { -FieldTypeInfo TI; -if (auto Err = readBlock(ID, &TI)) - return Err; -if (auto Err = addTypeInfo(I, std::move(TI))) - return Err; -return llvm::Error::success(); +return handleTypeSubBlock( +ID, I, CreateAddFunc(addTypeInfo)); } case BI_MEMBER_TYPE_BLOCK_ID: { -MemberTypeInfo TI; -if (auto Err = readBlock(ID, &TI)) - return Err; -if (auto Err = addTypeInfo(I, std::move(TI))) - return Err; -return llvm::Error::success(); +return handleTypeSubBlock( +ID, I, CreateAddFunc(addTypeInfo)); } case BI_REFERENCE_BLOCK_ID: { Reference R; @@ -848,81 +862,46 @@ llvm::Error ClangDocBitcodeReader::readSubBlock(unsigned ID, T I) { return llvm::Error::success(); } case BI_FUNCTION_BLOCK_ID: { -FunctionInfo F; -if (auto Err = readBlock(ID, &F)) - return Err; -addChild(I, std::move(F)); -return llvm::Error::success(); +return handleSubBlock( +ID, I, CreateAddFunc(addChild)); } case BI_BASE_RECORD_BLOCK_ID: { -BaseRecordInfo BR; -if (auto Err = readBlock(ID, &BR)) - return Err; -addChild(I, std::move(BR)); -return llvm::Error::success(); +return handleSubBlock( +ID, I, CreateAddFunc(addChild)); } case BI_ENUM_BLOCK_ID: { -EnumInfo E; -if (auto Err = readBlock(ID, &E)) - return Err; -addChild(I, std::move(E)); -return llvm::Error::success(); +return handleSubBlock(ID, I, +CreateAddFunc(addChild)); } case BI_ENUM_VALUE_BLOCK_ID: { -EnumValueInfo EV; -if (auto Err = readBlock(ID, &EV)) - return Err; -addChild(I, std::move(EV)); -return llvm::Error::success(); +return handleSubBlock( +ID, I, CreateAddFunc(addChild)); } case BI_TEMPLATE_BLOCK_ID: { -TemplateInfo TI; -if (auto Err = readBlock(ID, &TI)) - return Err; -addTemplate(I, std::move(TI)); -return llvm::Error::success(); +return handleSubBlock(ID, I, CreateAddFunc(addTemplate)); } case BI_TEMPLATE_SPECIALIZATION_BLOCK_ID: { -TemplateSpecializationInfo TSI; -if (auto Err = readBlock(ID, &TSI)) - return Err; -addTemplateSpecialization(I, std::move(TSI)); -return llvm::Error::success(); +return handleSubBlock( +ID, I, CreateAddFunc(addTemplateSpecialization)); } case BI_TEMPLATE_PARAM_BLOCK_ID: { -TemplateParamInfo TPI; -if (auto Err = readBlock(ID, &TPI)) - return Err; -addTemplateParam(I, std::move(TPI));
[llvm-branch-commits] [clang-tools-extra] [clang-doc] refactor BitcodeReader::readSubBlock (PR #145835)
evelez7 wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.dev/github/pr/llvm/llvm-project/145835?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#145835** https://app.graphite.dev/github/pr/llvm/llvm-project/145835?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/145835?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#145595** https://app.graphite.dev/github/pr/llvm/llvm-project/145595?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/145835 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] refactor BitcodeReader::readSubBlock (PR #145835)
https://github.com/evelez7 edited https://github.com/llvm/llvm-project/pull/145835 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] enable comments in class templates (PR #149848)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/149848 >From 9e0ab6804aebd778c36985dd9561f9233d3c4ec5 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Fri, 18 Jul 2025 12:04:20 -0700 Subject: [PATCH] [clang-doc] enable comments in class templates The Mustache basic project has comments in its headers but the comments were not serialized. Now we serialize @brief and paragraph comments for classes and add that output to the basic project test. --- .../clang-doc/assets/class-template.mustache | 4 +- .../assets/comment-template.mustache | 9 +++- .../clang-doc/basic-project.mustache.test | 43 +++ 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/class-template.mustache b/clang-tools-extra/clang-doc/assets/class-template.mustache index a4077323f29e2..b1a7470f7c33a 100644 --- a/clang-tools-extra/clang-doc/assets/class-template.mustache +++ b/clang-tools-extra/clang-doc/assets/class-template.mustache @@ -128,11 +128,11 @@ {{TagType}} {{Name}} -{{#RecordComments}} +{{#Description}} {{>Comments}} -{{/RecordComments}} +{{/Description}} {{#HasPublicMembers}} diff --git a/clang-tools-extra/clang-doc/assets/comment-template.mustache b/clang-tools-extra/clang-doc/assets/comment-template.mustache index 723ace7a0eed1..b793bad55cf6c 100644 --- a/clang-tools-extra/clang-doc/assets/comment-template.mustache +++ b/clang-tools-extra/clang-doc/assets/comment-template.mustache @@ -5,11 +5,16 @@ This file defines templates for generating comments }} -{{#FullComment}} +{{#BriefComments}} {{#Children}} {{>Comments}} {{/Children}} -{{/FullComment}} +{{/BriefComments}} +{{#ParagraphComments}} +{{#Children}} +{{>Comments}} +{{/Children}} +{{/ParagraphComments}} {{#ParagraphComment}} {{#Children}} {{>Comments}} diff --git a/clang-tools-extra/test/clang-doc/basic-project.mustache.test b/clang-tools-extra/test/clang-doc/basic-project.mustache.test index 4dd6f4165f65e..4fb38e2b32fcb 100644 --- a/clang-tools-extra/test/clang-doc/basic-project.mustache.test +++ b/clang-tools-extra/test/clang-doc/basic-project.mustache.test @@ -60,6 +60,17 @@ HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: class Shape +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: Abstract base class for shapes. +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: Provides a common interface for different types of shapes. +HTML-SHAPE: +HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: @@ -172,6 +183,16 @@ HTML-CALC: HTML-CALC: HTML-CALC: HTML-CALC: class Calculator +HTML-CALC: +HTML-CALC: A simple calculator class. +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: Provides basic arithmetic operations. +HTML-CALC: +HTML-CALC: HTML-CALC: HTML-CALC: HTML-CALC: @@ -300,6 +321,17 @@ HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE: class Rectangle +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: Rectangle class derived from Shape. +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: Represents a rectangle with a given width and height. +HTML-RECTANGLE: +HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE:
[llvm-branch-commits] [clang-tools-extra] [clang-doc] separate comments into categories (PR #149590)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/149590 >From d82ff8ec74627a17d4fbc2ee88c7d58ca8a5c293 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Thu, 17 Jul 2025 15:04:20 -0700 Subject: [PATCH] [clang-doc] separate comments into categories Comment categories will allow better comment organization in HTML. Before, comments would just be serialized in whatever order they were written, so groups like params or notes wouldn't be in the same sections. --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 46 + .../test/clang-doc/json/class.cpp | 51 +-- .../test/clang-doc/json/concept.cpp | 15 +++--- 3 files changed, 67 insertions(+), 45 deletions(-) diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index 30243c9f3df5c..75302b0dc3264 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -83,7 +83,21 @@ serializeLocation(const Location &Loc, return LocationObj; } -static json::Value serializeComment(const CommentInfo &I) { +static void insertComment(Object &Description, json::Value &Comment, + StringRef Key) { + auto DescriptionIt = Description.find(Key); + + if (DescriptionIt == Description.end()) { +auto CommentsArray = json::Array(); +CommentsArray.push_back(Comment); +Description[Key] = std::move(CommentsArray); +Description["Has" + Key.str()] = true; + } else { +DescriptionIt->getSecond().getAsArray()->push_back(Comment); + } +} + +static Object serializeComment(const CommentInfo &I, Object &Description) { // taken from PR #142273 Object Obj = Object(); @@ -94,7 +108,7 @@ static json::Value serializeComment(const CommentInfo &I) { auto &CARef = *ChildArr.getAsArray(); CARef.reserve(I.Children.size()); for (const auto &C : I.Children) -CARef.emplace_back(serializeComment(*C)); +CARef.emplace_back(serializeComment(*C, Description)); switch (I.Kind) { case CommentKind::CK_TextComment: { @@ -104,8 +118,13 @@ static json::Value serializeComment(const CommentInfo &I) { case CommentKind::CK_BlockCommandComment: { Child.insert({"Command", I.Name}); +// TODO: The "Children" level of nesting isn't needed for comments that +// don't hold additional information at the top level. BriefComments can +// just be an array of ParagraphComments. Child.insert({"Children", ChildArr}); Obj.insert({commentKindToString(I.Kind), ChildVal}); +if (I.Name == "brief") + insertComment(Description, ChildVal, "BriefComments"); return Obj; } @@ -137,7 +156,10 @@ static json::Value serializeComment(const CommentInfo &I) { if (!I.CloseName.empty()) Child.insert({"CloseName", I.CloseName}); Child.insert({"Children", ChildArr}); -Obj.insert({commentKindToString(I.Kind), ChildVal}); +if (I.CloseName == "endcode") + insertComment(Description, ChildVal, "CodeComments"); +else if (I.CloseName == "endverbatim") + insertComment(Description, ChildVal, "VerbatimComments"); return Obj; } @@ -210,12 +232,18 @@ serializeCommonAttributes(const Info &I, json::Object &Obj, } if (!I.Description.empty()) { -json::Value DescArray = json::Array(); -auto &DescArrayRef = *DescArray.getAsArray(); -DescArrayRef.reserve(I.Description.size()); -for (const auto &Comment : I.Description) - DescArrayRef.push_back(serializeComment(Comment)); -Obj["Description"] = DescArray; +Object Description = Object(); +// Skip straight to the FullComment's children +auto &Comments = I.Description.at(0).Children; +for (const auto &CommentInfo : Comments) { + json::Value Comment = serializeComment(*CommentInfo, Description); + // if a ParagraphComment is returned, then it is a top-level comment that + // needs to be inserted manually. + if (auto *ParagraphComment = + Comment.getAsObject()->get("ParagraphComment")) +insertComment(Description, *ParagraphComment, "ParagraphComments"); +} +Obj["Description"] = std::move(Description); } // Namespaces aren't SymbolInfos, so they dont have a DefLoc diff --git a/clang-tools-extra/test/clang-doc/json/class.cpp b/clang-tools-extra/test/clang-doc/json/class.cpp index a36358982b019..e8fafca28a956 100644 --- a/clang-tools-extra/test/clang-doc/json/class.cpp +++ b/clang-tools-extra/test/clang-doc/json/class.cpp @@ -33,33 +33,30 @@ struct MyClass { }; // CHECK: { -// CHECK-NEXT:"Description": [ -// CHECK-NEXT: { -// CHECK-NEXT: "FullComment": { -// CHECK-NEXT: "Children": [ -// CHECK-NEXT: { -// CHECK-NEXT: "ParagraphComment": { -// CHECK-NEXT: "Children": [ -// CHECK-NEXT: { -// CHECK-NEXT: "TextComment": " This is a nice class." -// CHECK-NEXT:
[llvm-branch-commits] [clang-tools-extra] [clang-doc] enable comments in class templates (PR #149848)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/149848 >From 9e0ab6804aebd778c36985dd9561f9233d3c4ec5 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Fri, 18 Jul 2025 12:04:20 -0700 Subject: [PATCH] [clang-doc] enable comments in class templates The Mustache basic project has comments in its headers but the comments were not serialized. Now we serialize @brief and paragraph comments for classes and add that output to the basic project test. --- .../clang-doc/assets/class-template.mustache | 4 +- .../assets/comment-template.mustache | 9 +++- .../clang-doc/basic-project.mustache.test | 43 +++ 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/class-template.mustache b/clang-tools-extra/clang-doc/assets/class-template.mustache index a4077323f29e2..b1a7470f7c33a 100644 --- a/clang-tools-extra/clang-doc/assets/class-template.mustache +++ b/clang-tools-extra/clang-doc/assets/class-template.mustache @@ -128,11 +128,11 @@ {{TagType}} {{Name}} -{{#RecordComments}} +{{#Description}} {{>Comments}} -{{/RecordComments}} +{{/Description}} {{#HasPublicMembers}} diff --git a/clang-tools-extra/clang-doc/assets/comment-template.mustache b/clang-tools-extra/clang-doc/assets/comment-template.mustache index 723ace7a0eed1..b793bad55cf6c 100644 --- a/clang-tools-extra/clang-doc/assets/comment-template.mustache +++ b/clang-tools-extra/clang-doc/assets/comment-template.mustache @@ -5,11 +5,16 @@ This file defines templates for generating comments }} -{{#FullComment}} +{{#BriefComments}} {{#Children}} {{>Comments}} {{/Children}} -{{/FullComment}} +{{/BriefComments}} +{{#ParagraphComments}} +{{#Children}} +{{>Comments}} +{{/Children}} +{{/ParagraphComments}} {{#ParagraphComment}} {{#Children}} {{>Comments}} diff --git a/clang-tools-extra/test/clang-doc/basic-project.mustache.test b/clang-tools-extra/test/clang-doc/basic-project.mustache.test index 4dd6f4165f65e..4fb38e2b32fcb 100644 --- a/clang-tools-extra/test/clang-doc/basic-project.mustache.test +++ b/clang-tools-extra/test/clang-doc/basic-project.mustache.test @@ -60,6 +60,17 @@ HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: class Shape +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: Abstract base class for shapes. +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: Provides a common interface for different types of shapes. +HTML-SHAPE: +HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: @@ -172,6 +183,16 @@ HTML-CALC: HTML-CALC: HTML-CALC: HTML-CALC: class Calculator +HTML-CALC: +HTML-CALC: A simple calculator class. +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: Provides basic arithmetic operations. +HTML-CALC: +HTML-CALC: HTML-CALC: HTML-CALC: HTML-CALC: @@ -300,6 +321,17 @@ HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE: class Rectangle +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: Rectangle class derived from Shape. +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: Represents a rectangle with a given width and height. +HTML-RECTANGLE: +HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE:
[llvm-branch-commits] [clang-tools-extra] [clang-doc] separate comments into categories (PR #149590)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/149590 >From a4bb77235ee210cdacb502fdc57f8e14eed2150d Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Thu, 17 Jul 2025 15:04:20 -0700 Subject: [PATCH] [clang-doc] separate comments into categories Comment categories will allow better comment organization in HTML. Before, comments would just be serialized in whatever order they were written, so groups like params or notes wouldn't be in the same sections. --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 46 + .../test/clang-doc/json/class.cpp | 51 +-- .../test/clang-doc/json/concept.cpp | 15 +++--- 3 files changed, 67 insertions(+), 45 deletions(-) diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index 30243c9f3df5c..75302b0dc3264 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -83,7 +83,21 @@ serializeLocation(const Location &Loc, return LocationObj; } -static json::Value serializeComment(const CommentInfo &I) { +static void insertComment(Object &Description, json::Value &Comment, + StringRef Key) { + auto DescriptionIt = Description.find(Key); + + if (DescriptionIt == Description.end()) { +auto CommentsArray = json::Array(); +CommentsArray.push_back(Comment); +Description[Key] = std::move(CommentsArray); +Description["Has" + Key.str()] = true; + } else { +DescriptionIt->getSecond().getAsArray()->push_back(Comment); + } +} + +static Object serializeComment(const CommentInfo &I, Object &Description) { // taken from PR #142273 Object Obj = Object(); @@ -94,7 +108,7 @@ static json::Value serializeComment(const CommentInfo &I) { auto &CARef = *ChildArr.getAsArray(); CARef.reserve(I.Children.size()); for (const auto &C : I.Children) -CARef.emplace_back(serializeComment(*C)); +CARef.emplace_back(serializeComment(*C, Description)); switch (I.Kind) { case CommentKind::CK_TextComment: { @@ -104,8 +118,13 @@ static json::Value serializeComment(const CommentInfo &I) { case CommentKind::CK_BlockCommandComment: { Child.insert({"Command", I.Name}); +// TODO: The "Children" level of nesting isn't needed for comments that +// don't hold additional information at the top level. BriefComments can +// just be an array of ParagraphComments. Child.insert({"Children", ChildArr}); Obj.insert({commentKindToString(I.Kind), ChildVal}); +if (I.Name == "brief") + insertComment(Description, ChildVal, "BriefComments"); return Obj; } @@ -137,7 +156,10 @@ static json::Value serializeComment(const CommentInfo &I) { if (!I.CloseName.empty()) Child.insert({"CloseName", I.CloseName}); Child.insert({"Children", ChildArr}); -Obj.insert({commentKindToString(I.Kind), ChildVal}); +if (I.CloseName == "endcode") + insertComment(Description, ChildVal, "CodeComments"); +else if (I.CloseName == "endverbatim") + insertComment(Description, ChildVal, "VerbatimComments"); return Obj; } @@ -210,12 +232,18 @@ serializeCommonAttributes(const Info &I, json::Object &Obj, } if (!I.Description.empty()) { -json::Value DescArray = json::Array(); -auto &DescArrayRef = *DescArray.getAsArray(); -DescArrayRef.reserve(I.Description.size()); -for (const auto &Comment : I.Description) - DescArrayRef.push_back(serializeComment(Comment)); -Obj["Description"] = DescArray; +Object Description = Object(); +// Skip straight to the FullComment's children +auto &Comments = I.Description.at(0).Children; +for (const auto &CommentInfo : Comments) { + json::Value Comment = serializeComment(*CommentInfo, Description); + // if a ParagraphComment is returned, then it is a top-level comment that + // needs to be inserted manually. + if (auto *ParagraphComment = + Comment.getAsObject()->get("ParagraphComment")) +insertComment(Description, *ParagraphComment, "ParagraphComments"); +} +Obj["Description"] = std::move(Description); } // Namespaces aren't SymbolInfos, so they dont have a DefLoc diff --git a/clang-tools-extra/test/clang-doc/json/class.cpp b/clang-tools-extra/test/clang-doc/json/class.cpp index a36358982b019..e8fafca28a956 100644 --- a/clang-tools-extra/test/clang-doc/json/class.cpp +++ b/clang-tools-extra/test/clang-doc/json/class.cpp @@ -33,33 +33,30 @@ struct MyClass { }; // CHECK: { -// CHECK-NEXT:"Description": [ -// CHECK-NEXT: { -// CHECK-NEXT: "FullComment": { -// CHECK-NEXT: "Children": [ -// CHECK-NEXT: { -// CHECK-NEXT: "ParagraphComment": { -// CHECK-NEXT: "Children": [ -// CHECK-NEXT: { -// CHECK-NEXT: "TextComment": " This is a nice class." -// CHECK-NEXT:
[llvm-branch-commits] [clang-tools-extra] [clang-doc] generate comments for functions (PR #150468)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/150468 >From b388252f5857e5004cfd26ab05037f13df66657b Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Fri, 18 Jul 2025 13:03:07 -0700 Subject: [PATCH] [clang-doc] generate comments for functions Change the function partial to enable comments to be generated for functions. This only enables the brief comments in the basic project. --- .../assets/function-template.mustache | 4 +- .../clang-doc/basic-project.mustache.test | 302 +- 2 files changed, 153 insertions(+), 153 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/function-template.mustache b/clang-tools-extra/clang-doc/assets/function-template.mustache index 6683afa03ea43..2510a4de2cd68 100644 --- a/clang-tools-extra/clang-doc/assets/function-template.mustache +++ b/clang-tools-extra/clang-doc/assets/function-template.mustache @@ -14,10 +14,10 @@ {{! Function Comments }} -{{#FunctionComments}} +{{#Description}} {{>Comments}} -{{/FunctionComments}} +{{/Description}} diff --git a/clang-tools-extra/test/clang-doc/basic-project.mustache.test b/clang-tools-extra/test/clang-doc/basic-project.mustache.test index 7cc32b9d8f08a..4cf8bad32fd9d 100644 --- a/clang-tools-extra/test/clang-doc/basic-project.mustache.test +++ b/clang-tools-extra/test/clang-doc/basic-project.mustache.test @@ -83,17 +83,17 @@ HTML-SHAPE: HTML-SHAPE: double area () HTML-SHAPE: HTML-SHAPE: -HTML-SHAPE-NOT: -HTML-SHAPE-NOT: -HTML-SHAPE-NOT: Calculates the area of the shape. -HTML-SHAPE-NOT: -HTML-SHAPE-NOT: -HTML-SHAPE-NOT: -HTML-SHAPE-NOT: -HTML-SHAPE-NOT: -HTML-SHAPE-NOT: -HTML-SHAPE-NOT: -HTML-SHAPE-NOT: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: Calculates the area of the shape. +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: @@ -103,17 +103,17 @@ HTML-SHAPE: HTML-SHAPE: double perimeter () HTML-SHAPE: HTML-SHAPE: -HTML-SHAPE-NOT: -HTML-SHAPE-NOT: -HTML-SHAPE-NOT: Calculates the perimeter of the shape. -HTML-SHAPE-NOT: -HTML-SHAPE-NOT: -HTML-SHAPE-NOT: -HTML-SHAPE-NOT: -HTML-SHAPE-NOT: -HTML-SHAPE-NOT: -HTML-SHAPE-NOT: -HTML-SHAPE-NOT: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: Calculates the perimeter of the shape. +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: @@ -123,14 +123,14 @@ HTML-SHAPE: HTML-SHAPE: void ~Shape () HTML-SHAPE: HTML-SHAPE: -HTML-SHAPE-NOT: -HTML-SHAPE-NOT: -HTML-SHAPE-NOT: Virtual destructor. -HTML-SHAPE-NOT: -HTML-SHAPE-NOT: -HTML-SHAPE-NOT: -HTML-SHAPE-NOT: -HTML-SHAPE-NOT: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: Virtual destructor. +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: @@ -250,17 +250,17 @@ HTML-CALC: HTML-CALC: int add (int a, int b) HTML-CALC: HTML-CALC: -HTML-CALC-NOT: -HTML-CALC-NOT: -HTML-CALC-NOT: Adds two integers. -HTML-CALC-NOT: -HTML-CALC-NOT: -HTML-CALC-NOT: -HTML-CALC-NOT: -HTML-CALC-NOT: -HTML-CALC-NOT: -HTML-CALC-NOT: -HTML-CALC-NOT:
[llvm-branch-commits] [clang-tools-extra] [clang-doc] Precommit param comment test changes (PR #150469)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/150469 >From 6f213799caf42bb3ba0c00822cef55a2e2948cb4 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Tue, 22 Jul 2025 21:49:57 -0700 Subject: [PATCH] [clang-doc] Precommit param comment test changes --- .../clang-doc/basic-project.mustache.test | 92 ++- 1 file changed, 90 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/test/clang-doc/basic-project.mustache.test b/clang-tools-extra/test/clang-doc/basic-project.mustache.test index 4cf8bad32fd9d..807ba1319e393 100644 --- a/clang-tools-extra/test/clang-doc/basic-project.mustache.test +++ b/clang-tools-extra/test/clang-doc/basic-project.mustache.test @@ -259,7 +259,24 @@ HTML-CALC: HTML-CALC: HTML-CALC: HTML-CALC: -HTML-CALC: +HTML-CALC-NOT: +HTML-CALC-NOT:Parameters +HTML-CALC-NOT: +HTML-CALC-NOT:a +HTML-CALC-NOT: First integer. +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT:b +HTML-CALC-NOT: Second integer. +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT: HTML-CALC: HTML-CALC: HTML-CALC: @@ -299,7 +316,24 @@ HTML-CALC: HTML-CALC: HTML-CALC: HTML-CALC: -HTML-CALC: +HTML-CALC-NOT: +HTML-CALC-NOT:Parameters +HTML-CALC-NOT: +HTML-CALC-NOT:a +HTML-CALC-NOT: First integer. +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT:b +HTML-CALC-NOT: Second integer. +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT: HTML-CALC: HTML-CALC: HTML-CALC: @@ -319,6 +353,23 @@ HTML-CALC: HTML-CALC: HTML-CALC: HTML-CALC: +HTML-CALC-NOT: +HTML-CALC-NOT:Parameters +HTML-CALC-NOT: +HTML-CALC-NOT:a +HTML-CALC-NOT: First integer. +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT:b +HTML-CALC-NOT: Second integer. +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT: HTML-CALC: HTML-CALC: HTML-CALC: @@ -339,6 +390,23 @@ HTML-CALC: HTML-CALC: HTML-CALC: HTML-CALC: +HTML-CALC-NOT: +HTML-CALC-NOT:Parameters +HTML-CALC-NOT: +HTML-CALC-NOT:a +HTML-CALC-NOT: First integer. +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT:b +HTML-CALC-NOT: Second integer. +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT: +HTML-CALC-NOT: HTML-CALC: HTML-CALC: HTML-CALC: @@ -438,6 +506,20 @@ HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE: +HTML-RECTANGLE-NOT: +HTML-RECTANGLE-NOT:Parameters +HTML-RECTANGLE-NOT: +HTML-RECTANGLE-NOT:width +HTML-RECTANGLE-NOT: Width of the rectan
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add param comments to comment template (PR #150470)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/150470 >From 98172493abfb2c93caefe2424dd17b93d32c17a0 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Tue, 22 Jul 2025 21:15:36 -0700 Subject: [PATCH] [clang-doc] add param comments to comment template --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 6 +- .../assets/comment-template.mustache | 8 + .../clang-doc/basic-project.mustache.test | 180 +- 3 files changed, 102 insertions(+), 92 deletions(-) diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index 92a4117c4e534..5fc28406ee870 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -147,8 +147,10 @@ static Object serializeComment(const CommentInfo &I, Object &Description) { Child.insert({"ParamName", I.ParamName}); Child.insert({"Direction", I.Direction}); Child.insert({"Explicit", I.Explicit}); -Child.insert({"Children", ChildArr}); -Obj.insert({commentKindToString(I.Kind), ChildVal}); +auto TextCommentsArray = extractTextComments(CARef.front().getAsObject()); +Child.insert({"Children", TextCommentsArray}); +if (I.Kind == CommentKind::CK_ParamCommandComment) + insertComment(Description, ChildVal, "ParamComments"); return Obj; } diff --git a/clang-tools-extra/clang-doc/assets/comment-template.mustache b/clang-tools-extra/clang-doc/assets/comment-template.mustache index f2edb1b2eb9ac..d55a53194ee5c 100644 --- a/clang-tools-extra/clang-doc/assets/comment-template.mustache +++ b/clang-tools-extra/clang-doc/assets/comment-template.mustache @@ -24,6 +24,14 @@ {{>Comments}} {{/Children}} {{/ParagraphComment}} +{{#HasParamComments}} +Parameters +{{#ParamComments}} + +{{ParamName}} {{#Explicit}}{{Direction}}{{/Explicit}} {{#Children}}{{>Comments}}{{/Children}} + +{{/ParamComments}} +{{/HasParamComments}} {{#BlockCommandComment}} diff --git a/clang-tools-extra/test/clang-doc/basic-project.mustache.test b/clang-tools-extra/test/clang-doc/basic-project.mustache.test index 807ba1319e393..b55e0abe2cdef 100644 --- a/clang-tools-extra/test/clang-doc/basic-project.mustache.test +++ b/clang-tools-extra/test/clang-doc/basic-project.mustache.test @@ -259,24 +259,24 @@ HTML-CALC: HTML-CALC: HTML-CALC: HTML-CALC: -HTML-CALC-NOT: -HTML-CALC-NOT:Parameters -HTML-CALC-NOT: -HTML-CALC-NOT:a -HTML-CALC-NOT: First integer. -HTML-CALC-NOT: -HTML-CALC-NOT: -HTML-CALC-NOT: -HTML-CALC-NOT: -HTML-CALC-NOT: -HTML-CALC-NOT: -HTML-CALC-NOT:b -HTML-CALC-NOT: Second integer. -HTML-CALC-NOT: -HTML-CALC-NOT: -HTML-CALC-NOT: -HTML-CALC-NOT: -HTML-CALC-NOT: +HTML-CALC: +HTML-CALC:Parameters +HTML-CALC: +HTML-CALC:a +HTML-CALC: First integer. +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC:b +HTML-CALC: Second integer. +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: HTML-CALC: HTML-CALC: HTML-CALC: @@ -316,24 +316,24 @@ HTML-CALC: HTML-CALC: HTML-CALC: HTML-CALC: -HTML-CALC-NOT: -HTML-CALC-NOT:Parameters -HTML-CALC-NOT: -HTML-CALC-NOT:a -HTML-CALC-NOT: First integer. -HTML-CALC-NOT: -HTML-CALC-NOT: -HTML-CALC-NOT: -HTML-CALC-NOT: -HTML-CALC-NOT: -HTML-CALC-NOT: -HTML-CALC-NOT:b -HTML-CALC-NOT: Second integer. -HTML-CALC-NOT: -HTML-CALC-NOT: -HTML-CALC-NOT: -HTML-CALC-NOT: -HTML-CALC-NOT: +HTML-CALC: +HTML-CALC:Parameters +HTML-CALC: +HTML-CALC:
[llvm-branch-commits] [clang-tools-extra] [clang-doc] generate comments for functions (PR #150468)
https://github.com/evelez7 closed https://github.com/llvm/llvm-project/pull/150468 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add param comments to comment template (PR #150470)
https://github.com/evelez7 closed https://github.com/llvm/llvm-project/pull/150470 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add param comments to comment template (PR #150470)
https://github.com/evelez7 reopened https://github.com/llvm/llvm-project/pull/150470 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] generate comments for functions (PR #150468)
https://github.com/evelez7 closed https://github.com/llvm/llvm-project/pull/150468 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add param comments to comment template (PR #150470)
https://github.com/evelez7 closed https://github.com/llvm/llvm-project/pull/150470 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] Precommit param comment test changes (PR #150469)
https://github.com/evelez7 closed https://github.com/llvm/llvm-project/pull/150469 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] generate comments for functions (PR #150468)
https://github.com/evelez7 reopened https://github.com/llvm/llvm-project/pull/150468 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] separate comments into categories (PR #149590)
@@ -83,7 +83,21 @@ serializeLocation(const Location &Loc, return LocationObj; } -static json::Value serializeComment(const CommentInfo &I) { +static void insertComment(Object &Description, json::Value &Comment, + std::string Key) { + auto *CommentArray = Description.getArray(Key); + if (!CommentArray) { +auto CommentsArray = json::Array(); +CommentsArray.push_back(Comment); +Description[Key] = std::move(CommentsArray); +Description["Has" + Key] = true; + } else { +CommentArray->push_back(Comment); +Description[Key] = std::move(*CommentArray); + } evelez7 wrote: Since the array that might exist at `Description[Key]` is returned as a pointer, allocating it via `new` means deleting it after the move, but then that's a bad free if the array existed. ASan doesn't like this approach but this could be better. https://github.com/llvm/llvm-project/pull/149590 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] enable comments in class templates (PR #149848)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/149848 >From fc9e1e850cd6139888f5dbd9798a997f927d4fb9 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Fri, 18 Jul 2025 12:04:20 -0700 Subject: [PATCH] [clang-doc] enable comments in class templates The Mustache basic project has comments in its headers but the comments were not serialized. Now we serialize @brief and paragraph comments for classes and add that output to the basic project test. --- .../clang-doc/assets/class-template.mustache | 4 +- .../assets/comment-template.mustache | 9 +++- .../clang-doc/basic-project.mustache.test | 43 +++ 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/class-template.mustache b/clang-tools-extra/clang-doc/assets/class-template.mustache index a4077323f29e2..b1a7470f7c33a 100644 --- a/clang-tools-extra/clang-doc/assets/class-template.mustache +++ b/clang-tools-extra/clang-doc/assets/class-template.mustache @@ -128,11 +128,11 @@ {{TagType}} {{Name}} -{{#RecordComments}} +{{#Description}} {{>Comments}} -{{/RecordComments}} +{{/Description}} {{#HasPublicMembers}} diff --git a/clang-tools-extra/clang-doc/assets/comment-template.mustache b/clang-tools-extra/clang-doc/assets/comment-template.mustache index 723ace7a0eed1..b793bad55cf6c 100644 --- a/clang-tools-extra/clang-doc/assets/comment-template.mustache +++ b/clang-tools-extra/clang-doc/assets/comment-template.mustache @@ -5,11 +5,16 @@ This file defines templates for generating comments }} -{{#FullComment}} +{{#BriefComments}} {{#Children}} {{>Comments}} {{/Children}} -{{/FullComment}} +{{/BriefComments}} +{{#ParagraphComments}} +{{#Children}} +{{>Comments}} +{{/Children}} +{{/ParagraphComments}} {{#ParagraphComment}} {{#Children}} {{>Comments}} diff --git a/clang-tools-extra/test/clang-doc/basic-project.mustache.test b/clang-tools-extra/test/clang-doc/basic-project.mustache.test index 4dd6f4165f65e..4fb38e2b32fcb 100644 --- a/clang-tools-extra/test/clang-doc/basic-project.mustache.test +++ b/clang-tools-extra/test/clang-doc/basic-project.mustache.test @@ -60,6 +60,17 @@ HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: class Shape +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: Abstract base class for shapes. +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: Provides a common interface for different types of shapes. +HTML-SHAPE: +HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: @@ -172,6 +183,16 @@ HTML-CALC: HTML-CALC: HTML-CALC: HTML-CALC: class Calculator +HTML-CALC: +HTML-CALC: A simple calculator class. +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: Provides basic arithmetic operations. +HTML-CALC: +HTML-CALC: HTML-CALC: HTML-CALC: HTML-CALC: @@ -300,6 +321,17 @@ HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE: class Rectangle +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: Rectangle class derived from Shape. +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: Represents a rectangle with a given width and height. +HTML-RECTANGLE: +HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE:
[llvm-branch-commits] [clang-tools-extra] [clang-doc] integrate JSON as the source for Mustache templates (PR #149589)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/149589 >From bc443f0743080af8102372da7e844d599586e250 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Fri, 18 Jul 2025 13:59:44 -0700 Subject: [PATCH] [clang-doc] integrate JSON as the source for Mustache templates --- .../clang-doc/HTMLMustacheGenerator.cpp | 489 +++--- .../clang-doc/assets/class-template.mustache | 62 +-- .../clang-doc/assets/enum-template.mustache | 12 +- .../assets/function-template.mustache | 2 +- .../assets/namespace-template.mustache| 45 +- .../clang-doc/basic-project.mustache.test | 70 +-- .../test/clang-doc/mustache-index.cpp | 10 +- .../clang-doc/mustache-separate-namespace.cpp | 8 +- .../clang-doc/HTMLMustacheGeneratorTest.cpp | 129 - 9 files changed, 173 insertions(+), 654 deletions(-) diff --git a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp index 7aeaa1b7cf67d..a64cb5ea26a79 100644 --- a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp +++ b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp @@ -27,6 +27,9 @@ using namespace llvm::mustache; namespace clang { namespace doc { +static Error generateDocForJSON(json::Value &JSON, StringRef Filename, +StringRef Path, raw_fd_ostream &OS, +const ClangDocContext &CDCtx); static Error createFileOpenError(StringRef FileName, std::error_code EC) { return createFileError("cannot open file " + FileName, EC); @@ -132,404 +135,68 @@ Error MustacheHTMLGenerator::generateDocs( return Err; } - // Track which directories we already tried to create. - StringSet<> CreatedDirs; - // Collect all output by file name and create the necessary directories. - StringMap> FileToInfos; - for (const auto &Group : Infos) { -llvm::TimeTraceScope TS("setup directories"); -doc::Info *Info = Group.getValue().get(); - -SmallString<128> Path; -sys::path::native(RootDir, Path); -sys::path::append(Path, Info->getRelativeFilePath("")); -if (!CreatedDirs.contains(Path)) { - if (std::error_code EC = sys::fs::create_directories(Path)) -return createStringError(EC, "failed to create directory '%s'.", - Path.c_str()); - CreatedDirs.insert(Path); -} - -sys::path::append(Path, Info->getFileBaseName() + ".html"); -FileToInfos[Path].push_back(Info); + { +llvm::TimeTraceScope TS("Generate JSON for Mustache"); +if (auto JSONGenerator = findGeneratorByName("json")) { + if (Error Err = JSONGenerator.get()->generateDocs( + RootDir, std::move(Infos), CDCtx)) +return Err; +} else + return JSONGenerator.takeError(); } + StringMap JSONFileMap; { -llvm::TimeTraceScope TS("Generate Docs"); -for (const auto &Group : FileToInfos) { - llvm::TimeTraceScope TS("Info to Doc"); +llvm::TimeTraceScope TS("Iterate JSON files"); +std::error_code EC; +sys::fs::directory_iterator JSONIter(RootDir, EC); +std::vector JSONFiles; +JSONFiles.reserve(Infos.size()); +if (EC) + return createStringError("Failed to create directory iterator."); + +while (JSONIter != sys::fs::directory_iterator()) { + if (EC) +return createFileError("Failed to iterate: " + JSONIter->path(), EC); + + auto Path = StringRef(JSONIter->path()); + if (!Path.ends_with(".json")) { +JSONIter.increment(EC); +continue; + } + + auto File = MemoryBuffer::getFile(Path); + if (EC = File.getError(); EC) +// TODO: Buffer errors to report later, look into using Clang +// diagnostics. +llvm::errs() << "Failed to open file: " << Path << " " << EC.message() + << '\n'; + + auto Parsed = json::parse((*File)->getBuffer()); + if (!Parsed) +return Parsed.takeError(); + std::error_code FileErr; - raw_fd_ostream InfoOS(Group.getKey(), FileErr, sys::fs::OF_None); + SmallString<16> HTMLPath(Path.begin(), Path.end()); + sys::path::replace_extension(HTMLPath, "html"); + raw_fd_ostream InfoOS(HTMLPath, FileErr, sys::fs::OF_None); if (FileErr) -return createFileOpenError(Group.getKey(), FileErr); +return createFileOpenError(Path, FileErr); - for (const auto &Info : Group.getValue()) -if (Error Err = generateDocForInfo(Info, InfoOS, CDCtx)) - return Err; + if (Error Err = generateDocForJSON(*Parsed, sys::path::stem(HTMLPath), + HTMLPath, InfoOS, CDCtx)) +return Err; + JSONIter.increment(EC); } } - return Error::success(); -} - -static json::Value -extractValue(const Location &L, - std::optional RepositoryUrl = std::nullopt) { - Object Obj = Object(); - // TODO: Consider using both Start/End line n
[llvm-branch-commits] [clang-tools-extra] [clang-doc] enable comments in class templates (PR #149848)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/149848 >From fc9e1e850cd6139888f5dbd9798a997f927d4fb9 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Fri, 18 Jul 2025 12:04:20 -0700 Subject: [PATCH] [clang-doc] enable comments in class templates The Mustache basic project has comments in its headers but the comments were not serialized. Now we serialize @brief and paragraph comments for classes and add that output to the basic project test. --- .../clang-doc/assets/class-template.mustache | 4 +- .../assets/comment-template.mustache | 9 +++- .../clang-doc/basic-project.mustache.test | 43 +++ 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/clang-tools-extra/clang-doc/assets/class-template.mustache b/clang-tools-extra/clang-doc/assets/class-template.mustache index a4077323f29e2..b1a7470f7c33a 100644 --- a/clang-tools-extra/clang-doc/assets/class-template.mustache +++ b/clang-tools-extra/clang-doc/assets/class-template.mustache @@ -128,11 +128,11 @@ {{TagType}} {{Name}} -{{#RecordComments}} +{{#Description}} {{>Comments}} -{{/RecordComments}} +{{/Description}} {{#HasPublicMembers}} diff --git a/clang-tools-extra/clang-doc/assets/comment-template.mustache b/clang-tools-extra/clang-doc/assets/comment-template.mustache index 723ace7a0eed1..b793bad55cf6c 100644 --- a/clang-tools-extra/clang-doc/assets/comment-template.mustache +++ b/clang-tools-extra/clang-doc/assets/comment-template.mustache @@ -5,11 +5,16 @@ This file defines templates for generating comments }} -{{#FullComment}} +{{#BriefComments}} {{#Children}} {{>Comments}} {{/Children}} -{{/FullComment}} +{{/BriefComments}} +{{#ParagraphComments}} +{{#Children}} +{{>Comments}} +{{/Children}} +{{/ParagraphComments}} {{#ParagraphComment}} {{#Children}} {{>Comments}} diff --git a/clang-tools-extra/test/clang-doc/basic-project.mustache.test b/clang-tools-extra/test/clang-doc/basic-project.mustache.test index 4dd6f4165f65e..4fb38e2b32fcb 100644 --- a/clang-tools-extra/test/clang-doc/basic-project.mustache.test +++ b/clang-tools-extra/test/clang-doc/basic-project.mustache.test @@ -60,6 +60,17 @@ HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: class Shape +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: Abstract base class for shapes. +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: Provides a common interface for different types of shapes. +HTML-SHAPE: +HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: @@ -172,6 +183,16 @@ HTML-CALC: HTML-CALC: HTML-CALC: HTML-CALC: class Calculator +HTML-CALC: +HTML-CALC: A simple calculator class. +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: +HTML-CALC: Provides basic arithmetic operations. +HTML-CALC: +HTML-CALC: HTML-CALC: HTML-CALC: HTML-CALC: @@ -300,6 +321,17 @@ HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE: class Rectangle +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: Rectangle class derived from Shape. +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: +HTML-RECTANGLE: Represents a rectangle with a given width and height. +HTML-RECTANGLE: +HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE: HTML-RECTANGLE:
[llvm-branch-commits] [clang-tools-extra] [clang-doc] integrate JSON as the source for Mustache templates (PR #149589)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/149589 >From bc443f0743080af8102372da7e844d599586e250 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Fri, 18 Jul 2025 13:59:44 -0700 Subject: [PATCH] [clang-doc] integrate JSON as the source for Mustache templates --- .../clang-doc/HTMLMustacheGenerator.cpp | 489 +++--- .../clang-doc/assets/class-template.mustache | 62 +-- .../clang-doc/assets/enum-template.mustache | 12 +- .../assets/function-template.mustache | 2 +- .../assets/namespace-template.mustache| 45 +- .../clang-doc/basic-project.mustache.test | 70 +-- .../test/clang-doc/mustache-index.cpp | 10 +- .../clang-doc/mustache-separate-namespace.cpp | 8 +- .../clang-doc/HTMLMustacheGeneratorTest.cpp | 129 - 9 files changed, 173 insertions(+), 654 deletions(-) diff --git a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp index 7aeaa1b7cf67d..a64cb5ea26a79 100644 --- a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp +++ b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp @@ -27,6 +27,9 @@ using namespace llvm::mustache; namespace clang { namespace doc { +static Error generateDocForJSON(json::Value &JSON, StringRef Filename, +StringRef Path, raw_fd_ostream &OS, +const ClangDocContext &CDCtx); static Error createFileOpenError(StringRef FileName, std::error_code EC) { return createFileError("cannot open file " + FileName, EC); @@ -132,404 +135,68 @@ Error MustacheHTMLGenerator::generateDocs( return Err; } - // Track which directories we already tried to create. - StringSet<> CreatedDirs; - // Collect all output by file name and create the necessary directories. - StringMap> FileToInfos; - for (const auto &Group : Infos) { -llvm::TimeTraceScope TS("setup directories"); -doc::Info *Info = Group.getValue().get(); - -SmallString<128> Path; -sys::path::native(RootDir, Path); -sys::path::append(Path, Info->getRelativeFilePath("")); -if (!CreatedDirs.contains(Path)) { - if (std::error_code EC = sys::fs::create_directories(Path)) -return createStringError(EC, "failed to create directory '%s'.", - Path.c_str()); - CreatedDirs.insert(Path); -} - -sys::path::append(Path, Info->getFileBaseName() + ".html"); -FileToInfos[Path].push_back(Info); + { +llvm::TimeTraceScope TS("Generate JSON for Mustache"); +if (auto JSONGenerator = findGeneratorByName("json")) { + if (Error Err = JSONGenerator.get()->generateDocs( + RootDir, std::move(Infos), CDCtx)) +return Err; +} else + return JSONGenerator.takeError(); } + StringMap JSONFileMap; { -llvm::TimeTraceScope TS("Generate Docs"); -for (const auto &Group : FileToInfos) { - llvm::TimeTraceScope TS("Info to Doc"); +llvm::TimeTraceScope TS("Iterate JSON files"); +std::error_code EC; +sys::fs::directory_iterator JSONIter(RootDir, EC); +std::vector JSONFiles; +JSONFiles.reserve(Infos.size()); +if (EC) + return createStringError("Failed to create directory iterator."); + +while (JSONIter != sys::fs::directory_iterator()) { + if (EC) +return createFileError("Failed to iterate: " + JSONIter->path(), EC); + + auto Path = StringRef(JSONIter->path()); + if (!Path.ends_with(".json")) { +JSONIter.increment(EC); +continue; + } + + auto File = MemoryBuffer::getFile(Path); + if (EC = File.getError(); EC) +// TODO: Buffer errors to report later, look into using Clang +// diagnostics. +llvm::errs() << "Failed to open file: " << Path << " " << EC.message() + << '\n'; + + auto Parsed = json::parse((*File)->getBuffer()); + if (!Parsed) +return Parsed.takeError(); + std::error_code FileErr; - raw_fd_ostream InfoOS(Group.getKey(), FileErr, sys::fs::OF_None); + SmallString<16> HTMLPath(Path.begin(), Path.end()); + sys::path::replace_extension(HTMLPath, "html"); + raw_fd_ostream InfoOS(HTMLPath, FileErr, sys::fs::OF_None); if (FileErr) -return createFileOpenError(Group.getKey(), FileErr); +return createFileOpenError(Path, FileErr); - for (const auto &Info : Group.getValue()) -if (Error Err = generateDocForInfo(Info, InfoOS, CDCtx)) - return Err; + if (Error Err = generateDocForJSON(*Parsed, sys::path::stem(HTMLPath), + HTMLPath, InfoOS, CDCtx)) +return Err; + JSONIter.increment(EC); } } - return Error::success(); -} - -static json::Value -extractValue(const Location &L, - std::optional RepositoryUrl = std::nullopt) { - Object Obj = Object(); - // TODO: Consider using both Start/End line n
[llvm-branch-commits] [clang-tools-extra] [clang-doc] separate comments into categories (PR #149590)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/149590 >From b4b103d007b171ff56cdb06dfc7ec4f6ef996789 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Thu, 17 Jul 2025 15:04:20 -0700 Subject: [PATCH] [clang-doc] separate comments into categories Comment categories will allow better comment organization in HTML. Before, comments would just be serialized in whatever order they were written, so groups like params or notes wouldn't be in the same sections. --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 46 + .../test/clang-doc/json/class.cpp | 51 +-- .../test/clang-doc/json/concept.cpp | 15 +++--- 3 files changed, 67 insertions(+), 45 deletions(-) diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index 30243c9f3df5c..08363dd70d32d 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -83,7 +83,21 @@ serializeLocation(const Location &Loc, return LocationObj; } -static json::Value serializeComment(const CommentInfo &I) { +static void insertComment(Object &Description, json::Value &Comment, + StringRef Key) { + auto *CommentArray = Description.getArray(Key); + if (!CommentArray) { +auto CommentsArray = json::Array(); +CommentsArray.push_back(Comment); +Description[Key] = std::move(CommentsArray); +Description["Has" + Key.str()] = true; + } else { +CommentArray->push_back(Comment); +Description[Key] = std::move(*CommentArray); + } +} + +static Object serializeComment(const CommentInfo &I, Object &Description) { // taken from PR #142273 Object Obj = Object(); @@ -94,7 +108,7 @@ static json::Value serializeComment(const CommentInfo &I) { auto &CARef = *ChildArr.getAsArray(); CARef.reserve(I.Children.size()); for (const auto &C : I.Children) -CARef.emplace_back(serializeComment(*C)); +CARef.emplace_back(serializeComment(*C, Description)); switch (I.Kind) { case CommentKind::CK_TextComment: { @@ -104,8 +118,13 @@ static json::Value serializeComment(const CommentInfo &I) { case CommentKind::CK_BlockCommandComment: { Child.insert({"Command", I.Name}); +// TODO: The "Children" level of nesting isn't needed for comments that +// don't hold additional information at the top level. BriefComments can +// just be an array of ParagraphComments. Child.insert({"Children", ChildArr}); Obj.insert({commentKindToString(I.Kind), ChildVal}); +if (I.Name == "brief") + insertComment(Description, ChildVal, "BriefComments"); return Obj; } @@ -137,7 +156,10 @@ static json::Value serializeComment(const CommentInfo &I) { if (!I.CloseName.empty()) Child.insert({"CloseName", I.CloseName}); Child.insert({"Children", ChildArr}); -Obj.insert({commentKindToString(I.Kind), ChildVal}); +if (I.CloseName == "endcode") + insertComment(Description, ChildVal, "CodeComments"); +else if (I.CloseName == "endverbatim") + insertComment(Description, ChildVal, "VerbatimComments"); return Obj; } @@ -210,12 +232,18 @@ serializeCommonAttributes(const Info &I, json::Object &Obj, } if (!I.Description.empty()) { -json::Value DescArray = json::Array(); -auto &DescArrayRef = *DescArray.getAsArray(); -DescArrayRef.reserve(I.Description.size()); -for (const auto &Comment : I.Description) - DescArrayRef.push_back(serializeComment(Comment)); -Obj["Description"] = DescArray; +Object Description = Object(); +// Skip straight to the FullComment's children +auto &Comments = I.Description.at(0).Children; +for (const auto &CommentInfo : Comments) { + json::Value Comment = serializeComment(*CommentInfo, Description); + // if a ParagraphComment is returned, then it is a top-level comment that + // needs to be inserted manually. + if (auto *ParagraphComment = + Comment.getAsObject()->get("ParagraphComment")) +insertComment(Description, *ParagraphComment, "ParagraphComments"); +} +Obj["Description"] = std::move(Description); } // Namespaces aren't SymbolInfos, so they dont have a DefLoc diff --git a/clang-tools-extra/test/clang-doc/json/class.cpp b/clang-tools-extra/test/clang-doc/json/class.cpp index a36358982b019..e8fafca28a956 100644 --- a/clang-tools-extra/test/clang-doc/json/class.cpp +++ b/clang-tools-extra/test/clang-doc/json/class.cpp @@ -33,33 +33,30 @@ struct MyClass { }; // CHECK: { -// CHECK-NEXT:"Description": [ -// CHECK-NEXT: { -// CHECK-NEXT: "FullComment": { -// CHECK-NEXT: "Children": [ -// CHECK-NEXT: { -// CHECK-NEXT: "ParagraphComment": { -// CHECK-NEXT: "Children": [ -// CHECK-NEXT: { -// CHECK-NEXT: "TextComment": " This is a nice class." -// CHECK-NEXT:
[llvm-branch-commits] [clang-tools-extra] [clang-doc] separate comments into categories (PR #149590)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/149590 >From b4b103d007b171ff56cdb06dfc7ec4f6ef996789 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Thu, 17 Jul 2025 15:04:20 -0700 Subject: [PATCH] [clang-doc] separate comments into categories Comment categories will allow better comment organization in HTML. Before, comments would just be serialized in whatever order they were written, so groups like params or notes wouldn't be in the same sections. --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 46 + .../test/clang-doc/json/class.cpp | 51 +-- .../test/clang-doc/json/concept.cpp | 15 +++--- 3 files changed, 67 insertions(+), 45 deletions(-) diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index 30243c9f3df5c..08363dd70d32d 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -83,7 +83,21 @@ serializeLocation(const Location &Loc, return LocationObj; } -static json::Value serializeComment(const CommentInfo &I) { +static void insertComment(Object &Description, json::Value &Comment, + StringRef Key) { + auto *CommentArray = Description.getArray(Key); + if (!CommentArray) { +auto CommentsArray = json::Array(); +CommentsArray.push_back(Comment); +Description[Key] = std::move(CommentsArray); +Description["Has" + Key.str()] = true; + } else { +CommentArray->push_back(Comment); +Description[Key] = std::move(*CommentArray); + } +} + +static Object serializeComment(const CommentInfo &I, Object &Description) { // taken from PR #142273 Object Obj = Object(); @@ -94,7 +108,7 @@ static json::Value serializeComment(const CommentInfo &I) { auto &CARef = *ChildArr.getAsArray(); CARef.reserve(I.Children.size()); for (const auto &C : I.Children) -CARef.emplace_back(serializeComment(*C)); +CARef.emplace_back(serializeComment(*C, Description)); switch (I.Kind) { case CommentKind::CK_TextComment: { @@ -104,8 +118,13 @@ static json::Value serializeComment(const CommentInfo &I) { case CommentKind::CK_BlockCommandComment: { Child.insert({"Command", I.Name}); +// TODO: The "Children" level of nesting isn't needed for comments that +// don't hold additional information at the top level. BriefComments can +// just be an array of ParagraphComments. Child.insert({"Children", ChildArr}); Obj.insert({commentKindToString(I.Kind), ChildVal}); +if (I.Name == "brief") + insertComment(Description, ChildVal, "BriefComments"); return Obj; } @@ -137,7 +156,10 @@ static json::Value serializeComment(const CommentInfo &I) { if (!I.CloseName.empty()) Child.insert({"CloseName", I.CloseName}); Child.insert({"Children", ChildArr}); -Obj.insert({commentKindToString(I.Kind), ChildVal}); +if (I.CloseName == "endcode") + insertComment(Description, ChildVal, "CodeComments"); +else if (I.CloseName == "endverbatim") + insertComment(Description, ChildVal, "VerbatimComments"); return Obj; } @@ -210,12 +232,18 @@ serializeCommonAttributes(const Info &I, json::Object &Obj, } if (!I.Description.empty()) { -json::Value DescArray = json::Array(); -auto &DescArrayRef = *DescArray.getAsArray(); -DescArrayRef.reserve(I.Description.size()); -for (const auto &Comment : I.Description) - DescArrayRef.push_back(serializeComment(Comment)); -Obj["Description"] = DescArray; +Object Description = Object(); +// Skip straight to the FullComment's children +auto &Comments = I.Description.at(0).Children; +for (const auto &CommentInfo : Comments) { + json::Value Comment = serializeComment(*CommentInfo, Description); + // if a ParagraphComment is returned, then it is a top-level comment that + // needs to be inserted manually. + if (auto *ParagraphComment = + Comment.getAsObject()->get("ParagraphComment")) +insertComment(Description, *ParagraphComment, "ParagraphComments"); +} +Obj["Description"] = std::move(Description); } // Namespaces aren't SymbolInfos, so they dont have a DefLoc diff --git a/clang-tools-extra/test/clang-doc/json/class.cpp b/clang-tools-extra/test/clang-doc/json/class.cpp index a36358982b019..e8fafca28a956 100644 --- a/clang-tools-extra/test/clang-doc/json/class.cpp +++ b/clang-tools-extra/test/clang-doc/json/class.cpp @@ -33,33 +33,30 @@ struct MyClass { }; // CHECK: { -// CHECK-NEXT:"Description": [ -// CHECK-NEXT: { -// CHECK-NEXT: "FullComment": { -// CHECK-NEXT: "Children": [ -// CHECK-NEXT: { -// CHECK-NEXT: "ParagraphComment": { -// CHECK-NEXT: "Children": [ -// CHECK-NEXT: { -// CHECK-NEXT: "TextComment": " This is a nice class." -// CHECK-NEXT:
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add throws comments to comment template (PR #150649)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/150649 >From eb95d560a94f49531ad98389184036726494a016 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Thu, 24 Jul 2025 22:10:51 -0700 Subject: [PATCH] [clang-doc] add throws comments to comment template Serialize throw Doxygen comments for exceptions. Accepts both \throw and \throws. --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 7 +++ .../clang-doc/assets/comment-template.mustache| 8 .../test/clang-doc/basic-project.mustache.test| 4 3 files changed, 19 insertions(+) diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index 599b381cea60d..2db6451259f60 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -140,6 +140,13 @@ static Object serializeComment(const CommentInfo &I, Object &Description) { insertComment(Description, TextCommentsArray, "BriefComments"); else if (I.Name == "return") insertComment(Description, TextCommentsArray, "ReturnComments"); +else if (I.Name == "throws" || I.Name == "throw") { + json::Value ThrowsVal = Object(); + auto &ThrowsObj = *ThrowsVal.getAsObject(); + ThrowsObj["Exception"] = I.Args.front(); + ThrowsObj["Children"] = TextCommentsArray; + insertComment(Description, ThrowsVal, "ThrowsComments"); +} return Obj; } diff --git a/clang-tools-extra/clang-doc/assets/comment-template.mustache b/clang-tools-extra/clang-doc/assets/comment-template.mustache index 4e38e5fb92d18..60a4c70ec0dc4 100644 --- a/clang-tools-extra/clang-doc/assets/comment-template.mustache +++ b/clang-tools-extra/clang-doc/assets/comment-template.mustache @@ -54,6 +54,14 @@ {{/CodeComments}} {{/HasCodeComments}} +{{#HasThrowsComments}} +Throws +{{#ThrowsComments}} + +{{ThrowName}} {{#Children}}{{>Comments}}{{/Children}} + +{{/ThrowsComments}} +{{/HasThrowsComments}} {{#BlockCommandComment}} diff --git a/clang-tools-extra/test/clang-doc/basic-project.mustache.test b/clang-tools-extra/test/clang-doc/basic-project.mustache.test index e2d9da60183fa..88317393bb26c 100644 --- a/clang-tools-extra/test/clang-doc/basic-project.mustache.test +++ b/clang-tools-extra/test/clang-doc/basic-project.mustache.test @@ -384,6 +384,10 @@ HTML-CALC: HTML-CALC:Returns HTML-CALC: double The result of a / b. HTML-CALC: +HTML-CALC:Throws +HTML-CALC: +HTML-CALC: +HTML-CALC:if b is zero. HTML-CALC: HTML-CALC: HTML-CALC: ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add code comments to comment template (PR #150648)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/150648 >From 2101340494a046e3472d7a6d2cf08b23416b84cc Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Wed, 23 Jul 2025 12:49:01 -0700 Subject: [PATCH 1/2] [clang-doc] precommit code comments --- .../test/clang-doc/basic-project.mustache.test | 9 + 1 file changed, 9 insertions(+) diff --git a/clang-tools-extra/test/clang-doc/basic-project.mustache.test b/clang-tools-extra/test/clang-doc/basic-project.mustache.test index 2c87fe2533195..7a81c95b7194d 100644 --- a/clang-tools-extra/test/clang-doc/basic-project.mustache.test +++ b/clang-tools-extra/test/clang-doc/basic-project.mustache.test @@ -729,6 +729,15 @@ HTML-CIRCLE: HTML-CIRCLE: HTML-CIRCLE:Returns HTML-CIRCLE: double The perimeter of the circle. +HTML-CIRCLE-NOT:Code +HTML-CIRCLE-NOT: +HTML-CIRCLE-NOT: +HTML-CIRCLE-NOT: +HTML-CIRCLE-NOT:Circle circle(5.0); +HTML-CIRCLE-NOT:double perimeter = circle.perimeter(); +HTML-CIRCLE-NOT: +HTML-CIRCLE-NOT: +HTML-CIRCLE-NOT: HTML-CIRCLE: HTML-CIRCLE: HTML-CIRCLE: >From e8795d0285332a268592323693710ed7005c7e2f Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Wed, 23 Jul 2025 12:47:04 -0700 Subject: [PATCH 2/2] [clang-doc] add code comments to comment template Serializes Doxygen code comments in HTML templates. Modifies the basic-project to add a code example. --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 24 +-- .../clang-doc/assets/clang-doc-mustache.css | 4 .../assets/comment-template.mustache | 14 +++ .../Inputs/basic-project/include/Circle.h | 4 .../clang-doc/basic-project.mustache.test | 18 +++--- 5 files changed, 48 insertions(+), 16 deletions(-) diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index cae1a686266c6..599b381cea60d 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -103,6 +103,18 @@ static json::Value extractTextComments(Object *ParagraphComment) { return *ParagraphComment->get("Children"); } +static json::Value extractVerbatimComments(json::Array VerbatimLines) { + json::Value TextArray = json::Array(); + auto &TextArrayRef = *TextArray.getAsArray(); + for (auto &Line : VerbatimLines) +TextArrayRef.push_back(*Line.getAsObject() +->get("VerbatimBlockLineComment") +->getAsObject() +->get("Text")); + + return TextArray; +} + static Object serializeComment(const CommentInfo &I, Object &Description) { // taken from PR #142273 Object Obj = Object(); @@ -157,13 +169,11 @@ static Object serializeComment(const CommentInfo &I, Object &Description) { } case CommentKind::CK_VerbatimBlockComment: { -Child.insert({"Text", I.Text}); -if (!I.CloseName.empty()) - Child.insert({"CloseName", I.CloseName}); -Child.insert({"Children", ChildArr}); -if (I.CloseName == "endcode") - insertComment(Description, ChildVal, "CodeComments"); -else if (I.CloseName == "endverbatim") +if (I.CloseName == "endcode") { + // We don't support \code language specification + auto TextCommentsArray = extractVerbatimComments(CARef); + insertComment(Description, TextCommentsArray, "CodeComments"); +} else if (I.CloseName == "endverbatim") insertComment(Description, ChildVal, "VerbatimComments"); return Obj; } diff --git a/clang-tools-extra/clang-doc/assets/clang-doc-mustache.css b/clang-tools-extra/clang-doc/assets/clang-doc-mustache.css index a885a36cb4a3d..e555ee7c370f7 100644 --- a/clang-tools-extra/clang-doc/assets/clang-doc-mustache.css +++ b/clang-tools-extra/clang-doc/assets/clang-doc-mustache.css @@ -469,3 +469,7 @@ a, a:visited, a:hover, a:active { text-decoration: none; color: inherit; } + +.code-block { + white-space: pre-line; +} diff --git a/clang-tools-extra/clang-doc/assets/comment-template.mustache b/clang-tools-extra/clang-doc/assets/comment-template.mustache index 89c48d26278c0..4e38e5fb92d18 100644 --- a/clang-tools-extra/clang-doc/assets/comment-template.mustache +++ b/clang-tools-extra/clang-doc/assets/comment-template.mustache @@ -40,6 +40,20 @@ {{/.}} {{/ReturnComments}} {{/HasReturnComments}} +{{#HasCodeComments}} +Code +{{#CodeComments}} + + + +{{#.}} +{{.}} +{{/.}} + + + +{{/CodeComments}} +{{/HasCodeComments}} {{#BlockCommandComment}} diff
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add throws comments to comment template (PR #150649)
https://github.com/evelez7 unassigned https://github.com/llvm/llvm-project/pull/150649 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add throws comments to comment template (PR #150649)
https://github.com/evelez7 unassigned https://github.com/llvm/llvm-project/pull/150649 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add throws comments to comment template (PR #150649)
https://github.com/evelez7 updated https://github.com/llvm/llvm-project/pull/150649 >From e736a45c736753ef6b2643bab71bcc818d49a368 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Thu, 24 Jul 2025 22:10:51 -0700 Subject: [PATCH] [clang-doc] add throws comments to comment template Serialize throw Doxygen comments for exceptions. Accepts both \throw and \throws. --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 7 +++ .../clang-doc/assets/comment-template.mustache| 8 .../test/clang-doc/basic-project.mustache.test| 4 3 files changed, 19 insertions(+) diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index 599b381cea60d..2db6451259f60 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -140,6 +140,13 @@ static Object serializeComment(const CommentInfo &I, Object &Description) { insertComment(Description, TextCommentsArray, "BriefComments"); else if (I.Name == "return") insertComment(Description, TextCommentsArray, "ReturnComments"); +else if (I.Name == "throws" || I.Name == "throw") { + json::Value ThrowsVal = Object(); + auto &ThrowsObj = *ThrowsVal.getAsObject(); + ThrowsObj["Exception"] = I.Args.front(); + ThrowsObj["Children"] = TextCommentsArray; + insertComment(Description, ThrowsVal, "ThrowsComments"); +} return Obj; } diff --git a/clang-tools-extra/clang-doc/assets/comment-template.mustache b/clang-tools-extra/clang-doc/assets/comment-template.mustache index 4e38e5fb92d18..60a4c70ec0dc4 100644 --- a/clang-tools-extra/clang-doc/assets/comment-template.mustache +++ b/clang-tools-extra/clang-doc/assets/comment-template.mustache @@ -54,6 +54,14 @@ {{/CodeComments}} {{/HasCodeComments}} +{{#HasThrowsComments}} +Throws +{{#ThrowsComments}} + +{{ThrowName}} {{#Children}}{{>Comments}}{{/Children}} + +{{/ThrowsComments}} +{{/HasThrowsComments}} {{#BlockCommandComment}} diff --git a/clang-tools-extra/test/clang-doc/basic-project.mustache.test b/clang-tools-extra/test/clang-doc/basic-project.mustache.test index e2d9da60183fa..88317393bb26c 100644 --- a/clang-tools-extra/test/clang-doc/basic-project.mustache.test +++ b/clang-tools-extra/test/clang-doc/basic-project.mustache.test @@ -384,6 +384,10 @@ HTML-CALC: HTML-CALC:Returns HTML-CALC: double The result of a / b. HTML-CALC: +HTML-CALC:Throws +HTML-CALC: +HTML-CALC: +HTML-CALC:if b is zero. HTML-CALC: HTML-CALC: HTML-CALC: ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] add param comments to comment template (PR #150470)
https://github.com/evelez7 edited https://github.com/llvm/llvm-project/pull/150470 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits