-

enum class e

-
    -
  • X
  • -
+ + + + + + + + + + + + +
enum class e
X0

Defined at line 10 From 28fb40f0cdbe37257d8aea9f05519519d9f2c470 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Mon, 12 Aug 2024 17:12:48 -0400 Subject: [PATCH 04/79] [clang-doc] address pr comments --- clang-tools-extra/clang-doc/HTMLGenerator.cpp | 38 ++++++++----------- .../clang-doc/Representation.cpp | 2 +- clang-tools-extra/clang-doc/Representation.h | 4 +- clang-tools-extra/clang-doc/Serialize.cpp | 8 ++-- 4 files changed, 23 insertions(+), 29 deletions(-) diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp index a37192d6ceb9b..ad7e08667e5cb 100644 --- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp +++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp @@ -397,8 +397,7 @@ genEnumsBlock(const std::vector &Enums, } static std::unique_ptr -genEnumMembersBlock(const llvm::SmallVector &Members, - bool HasComments) { +genEnumMembersBlock(const llvm::SmallVector &Members) { if (Members.empty()) return nullptr; @@ -416,8 +415,7 @@ genEnumMembersBlock(const llvm::SmallVector &Members, TRNode->Children.emplace_back( std::make_unique(HTMLTag::TAG_TD, M.Value)); } - - if (HasComments) { + if (M.Description.empty()) { auto TD = std::make_unique(HTMLTag::TAG_TD); TD->Children.emplace_back(genHTML(M.Description)); TRNode->Children.emplace_back(std::move(TD)); @@ -663,7 +661,7 @@ static std::unique_ptr genHTML(const CommentInfo &I) { } return std::move(FullComment); } - + if (I.Kind == "ParagraphComment") { auto ParagraphComment = std::make_unique(HTMLTag::TAG_P); for (const auto &Child : I.Children) { @@ -698,16 +696,12 @@ genHTML(const EnumInfo &I, const ClangDocContext &CDCtx) { std::vector> Out; std::string EnumType = I.Scoped ? "enum class " : "enum "; // Determine if enum members have comments attached - bool HasComments = false; - for (const auto &M : I.Members) { - if (!M.Description.empty()) { - HasComments = true; - break; - } - } + bool HasComments = + std::any_of(I.Members.begin(), I.Members.end(), + [](const EnumValueInfo &M) { return M.Description.empty(); }); std::unique_ptr Table = std::make_unique(HTMLTag::TAG_TABLE); - std::unique_ptr Thead = + std::unique_ptr THead = std::make_unique(HTMLTag::TAG_THEAD); std::unique_ptr TRow = std::make_unique(HTMLTag::TAG_TR); std::unique_ptr TD = @@ -717,10 +711,10 @@ genHTML(const EnumInfo &I, const ClangDocContext &CDCtx) { Table->Attributes.emplace_back("id", llvm::toHex(llvm::toStringRef(I.USR))); TRow->Children.emplace_back(std::move(TD)); - Thead->Children.emplace_back(std::move(TRow)); - Table->Children.emplace_back(std::move(Thead)); + THead->Children.emplace_back(std::move(TRow)); + Table->Children.emplace_back(std::move(THead)); - std::unique_ptr Node = genEnumMembersBlock(I.Members, HasComments); + std::unique_ptr Node = genEnumMembersBlock(I.Members); if (Node) Table->Children.emplace_back(std::move(Node)); @@ -731,8 +725,8 @@ genHTML(const EnumInfo &I, const ClangDocContext &CDCtx) { if (!CDCtx.RepositoryUrl) Out.emplace_back(writeFileDefinition(*I.DefLoc)); else - Out.emplace_back(writeFileDefinition( - *I.DefLoc, StringRef{*CDCtx.RepositoryUrl})); + Out.emplace_back( + writeFileDefinition(*I.DefLoc, StringRef{*CDCtx.RepositoryUrl})); } std::string Description; @@ -780,8 +774,8 @@ genHTML(const FunctionInfo &I, const ClangDocContext &CDCtx, if (!CDCtx.RepositoryUrl) Out.emplace_back(writeFileDefinition(*I.DefLoc)); else - Out.emplace_back(writeFileDefinition( - *I.DefLoc, StringRef{*CDCtx.RepositoryUrl})); + Out.emplace_back( + writeFileDefinition(*I.DefLoc, StringRef{*CDCtx.RepositoryUrl})); } std::string Description; @@ -847,8 +841,8 @@ genHTML(const RecordInfo &I, Index &InfoIndex, const ClangDocContext &CDCtx, if (!CDCtx.RepositoryUrl) Out.emplace_back(writeFileDefinition(*I.DefLoc)); else - Out.emplace_back(writeFileDefinition( - *I.DefLoc, StringRef{*CDCtx.RepositoryUrl})); + Out.emplace_back( + writeFileDefinition(*I.DefLoc, StringRef{*CDCtx.RepositoryUrl})); } std::string Description; diff --git a/clang-tools-extra/clang-doc/Representation.cpp b/clang-tools-extra/clang-doc/Representation.cpp index d08afbb962189..da948ee74c9d6 100644 --- a/clang-tools-extra/clang-doc/Representation.cpp +++ b/clang-tools-extra/clang-doc/Representation.cpp @@ -221,7 +221,7 @@ void SymbolInfo::merge(SymbolInfo &&Other) { } NamespaceInfo::NamespaceInfo(SymbolID USR, StringRef Name, StringRef Path) - : Info(InfoType::IT_namespace, USR, Name, Path) {} + : Info(InfoType::IT_namespace, USR, Name, Path) {} void NamespaceInfo::merge(NamespaceInfo &&Other) { assert(mergeable(Other)); diff --git a/clang-tools-extra/clang-doc/Representation.h b/clang-tools-extra/clang-doc/Representation.h index bd5254b0a8465..873ac72806626 100644 --- a/clang-tools-extra/clang-doc/Representation.h +++ b/clang-tools-extra/clang-doc/Representation.h @@ -48,7 +48,7 @@ enum class InfoType { // A representation of a parsed comment. struct CommentInfo { CommentInfo() = default; - CommentInfo(CommentInfo &Other) = delete; + CommentInfo(CommentInfo &Other) = default; CommentInfo(CommentInfo &&Other) = default; CommentInfo &operator=(CommentInfo &&Other) = default; @@ -432,7 +432,7 @@ struct EnumValueInfo { // constant. This will be empty for implicit enumeration values. SmallString<16> ValueExpr; - std::vector Description; // Comment description of this field. + std::vector Description; /// Comment description of this field. }; // TODO: Expand to allow for documenting templating. diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp index 78b7041368d6d..273bc10d3b55d 100644 --- a/clang-tools-extra/clang-doc/Serialize.cpp +++ b/clang-tools-extra/clang-doc/Serialize.cpp @@ -398,8 +398,8 @@ static void parseEnumerators(EnumInfo &I, const EnumDecl *D) { E->getInitVal().toString(ValueStr); I.Members.emplace_back(E->getNameAsString(), ValueStr.str(), ValueExpr); ASTContext &Context = E->getASTContext(); - RawComment *Comment = E->getASTContext().getRawCommentForDeclNoCache(E); - if (Comment) { + if (RawComment *Comment = + E->getASTContext().getRawCommentForDeclNoCache(E)) { CommentInfo CInfo; Comment->setAttached(); if (comments::FullComment *Fc = Comment->parse(Context, nullptr, E)) { @@ -568,7 +568,7 @@ static void populateFunctionInfo(FunctionInfo &I, const FunctionDecl *D, static void populateMemberTypeInfo(MemberTypeInfo &I, const FieldDecl *D) { assert(D && "Expect non-null FieldDecl in populateMemberTypeInfo"); - ASTContext& Context = D->getASTContext(); + ASTContext &Context = D->getASTContext(); // TODO investigate whether we can use ASTContext::getCommentForDecl instead // of this logic. See also similar code in Mapper.cpp. RawComment *Comment = Context.getRawCommentForDeclNoCache(D); @@ -576,7 +576,7 @@ static void populateMemberTypeInfo(MemberTypeInfo &I, const FieldDecl *D) { return; Comment->setAttached(); - if (comments::FullComment* fc = Comment->parse(Context, nullptr, D)) { + if (comments::FullComment *fc = Comment->parse(Context, nullptr, D)) { I.Description.emplace_back(); parseFullComment(fc, I.Description.back()); } From 0d150ea08af767017e108096533f0c0d8b31668a Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Mon, 12 Aug 2024 17:24:55 -0400 Subject: [PATCH 05/79] [clang-doc] revert CommentInfo change --- clang-tools-extra/clang-doc/Representation.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-doc/Representation.h b/clang-tools-extra/clang-doc/Representation.h index 873ac72806626..8f2bba786316f 100644 --- a/clang-tools-extra/clang-doc/Representation.h +++ b/clang-tools-extra/clang-doc/Representation.h @@ -48,7 +48,7 @@ enum class InfoType { // A representation of a parsed comment. struct CommentInfo { CommentInfo() = default; - CommentInfo(CommentInfo &Other) = default; + CommentInfo(CommentInfo &Other) = delete; CommentInfo(CommentInfo &&Other) = default; CommentInfo &operator=(CommentInfo &&Other) = default; From e5e70b87003e4e7b8e68d23fc89f7edd6961764f Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Mon, 12 Aug 2024 18:29:39 -0400 Subject: [PATCH 06/79] [clang-doc] fix test --- clang-tools-extra/clang-doc/HTMLGenerator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp index ad7e08667e5cb..00f94788ced44 100644 --- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp +++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp @@ -415,7 +415,7 @@ genEnumMembersBlock(const llvm::SmallVector &Members) { TRNode->Children.emplace_back( std::make_unique(HTMLTag::TAG_TD, M.Value)); } - if (M.Description.empty()) { + if (!M.Description.empty()) { auto TD = std::make_unique(HTMLTag::TAG_TD); TD->Children.emplace_back(genHTML(M.Description)); TRNode->Children.emplace_back(std::move(TD)); From 1c4f631df65c1560523ea63c82229102f3d99f54 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Mon, 12 Aug 2024 19:19:39 -0400 Subject: [PATCH 07/79] [clang-doc] fix unittest --- clang-tools-extra/clang-doc/HTMLGenerator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp index 00f94788ced44..6baed082af4a8 100644 --- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp +++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp @@ -698,7 +698,7 @@ genHTML(const EnumInfo &I, const ClangDocContext &CDCtx) { // Determine if enum members have comments attached bool HasComments = std::any_of(I.Members.begin(), I.Members.end(), - [](const EnumValueInfo &M) { return M.Description.empty(); }); + [](const EnumValueInfo &M) { return !M.Description.empty(); }); std::unique_ptr Table = std::make_unique(HTMLTag::TAG_TABLE); std::unique_ptr THead = From b8f3f9c97ccd503c07387f1364cb3b357fa92821 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Mon, 12 Aug 2024 19:35:15 -0400 Subject: [PATCH 08/79] [clang-doc] address pr comments --- clang-tools-extra/clang-doc/HTMLGenerator.cpp | 20 +++++++++---------- clang-tools-extra/clang-doc/Serialize.cpp | 2 +- clang-tools-extra/test/clang-doc/enum.cpp | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp index 6baed082af4a8..5b023a409c364 100644 --- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp +++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp @@ -696,9 +696,9 @@ genHTML(const EnumInfo &I, const ClangDocContext &CDCtx) { std::vector> Out; std::string EnumType = I.Scoped ? "enum class " : "enum "; // Determine if enum members have comments attached - bool HasComments = - std::any_of(I.Members.begin(), I.Members.end(), - [](const EnumValueInfo &M) { return !M.Description.empty(); }); + bool HasComments = std::any_of( + I.Members.begin(), I.Members.end(), + [](const EnumValueInfo &M) { return !M.Description.empty(); }); std::unique_ptr Table = std::make_unique(HTMLTag::TAG_TABLE); std::unique_ptr THead = @@ -713,10 +713,8 @@ genHTML(const EnumInfo &I, const ClangDocContext &CDCtx) { TRow->Children.emplace_back(std::move(TD)); THead->Children.emplace_back(std::move(TRow)); Table->Children.emplace_back(std::move(THead)); - - std::unique_ptr Node = genEnumMembersBlock(I.Members); - - if (Node) + + if (std::unique_ptr Node = genEnumMembersBlock(I.Members)) Table->Children.emplace_back(std::move(Node)); Out.emplace_back(std::move(Table)); @@ -774,8 +772,8 @@ genHTML(const FunctionInfo &I, const ClangDocContext &CDCtx, if (!CDCtx.RepositoryUrl) Out.emplace_back(writeFileDefinition(*I.DefLoc)); else - Out.emplace_back( - writeFileDefinition(*I.DefLoc, StringRef{*CDCtx.RepositoryUrl})); + Out.emplace_back(writeFileDefinition( + *I.DefLoc, StringRef{*CDCtx.RepositoryUrl})); } std::string Description; @@ -841,8 +839,8 @@ genHTML(const RecordInfo &I, Index &InfoIndex, const ClangDocContext &CDCtx, if (!CDCtx.RepositoryUrl) Out.emplace_back(writeFileDefinition(*I.DefLoc)); else - Out.emplace_back( - writeFileDefinition(*I.DefLoc, StringRef{*CDCtx.RepositoryUrl})); + Out.emplace_back(writeFileDefinition( + *I.DefLoc, StringRef{*CDCtx.RepositoryUrl})); } std::string Description; diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp index 273bc10d3b55d..b9db78cf7d688 100644 --- a/clang-tools-extra/clang-doc/Serialize.cpp +++ b/clang-tools-extra/clang-doc/Serialize.cpp @@ -568,7 +568,7 @@ static void populateFunctionInfo(FunctionInfo &I, const FunctionDecl *D, static void populateMemberTypeInfo(MemberTypeInfo &I, const FieldDecl *D) { assert(D && "Expect non-null FieldDecl in populateMemberTypeInfo"); - ASTContext &Context = D->getASTContext(); + ASTContext& Context = D->getASTContext(); // TODO investigate whether we can use ASTContext::getCommentForDecl instead // of this logic. See also similar code in Mapper.cpp. RawComment *Comment = Context.getRawCommentForDeclNoCache(D); diff --git a/clang-tools-extra/test/clang-doc/enum.cpp b/clang-tools-extra/test/clang-doc/enum.cpp index fd7bbcb53f2d2..ef768e33b4566 100644 --- a/clang-tools-extra/test/clang-doc/enum.cpp +++ b/clang-tools-extra/test/clang-doc/enum.cpp @@ -178,4 +178,4 @@ enum ColorUserSpecified { // HTML-INDEX: GreenUserSpecified // HTML-INDEX: 2 // HTML-INDEX: BlueUserSpecified -// HTML-INDEX: 'C' \ No newline at end of file +// HTML-INDEX: 'C' From bb98aad362353e44267f2df6ffb985005e67f147 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Mon, 12 Aug 2024 19:45:02 -0400 Subject: [PATCH 09/79] [clang-doc] clang-format --- clang-tools-extra/clang-doc/HTMLGenerator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp index 5b023a409c364..0ced83f91724f 100644 --- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp +++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp @@ -713,7 +713,7 @@ genHTML(const EnumInfo &I, const ClangDocContext &CDCtx) { TRow->Children.emplace_back(std::move(TD)); THead->Children.emplace_back(std::move(TRow)); Table->Children.emplace_back(std::move(THead)); - + if (std::unique_ptr Node = genEnumMembersBlock(I.Members)) Table->Children.emplace_back(std::move(Node)); From c60e2b505e27cebffac27b0085fee12d68bbedf7 Mon Sep 17 00:00:00 2001 From: PeterChou1 Date: Fri, 23 Aug 2024 17:39:16 -0400 Subject: [PATCH 10/79] [llvm] implement support for mustache template language --- llvm/include/llvm/Support/Mustache.h | 109 ++++++++++ llvm/lib/Support/CMakeLists.txt | 1 + llvm/lib/Support/Mustache.cpp | 276 ++++++++++++++++++++++++ llvm/unittests/Support/CMakeLists.txt | 1 + llvm/unittests/Support/MustacheTest.cpp | 135 ++++++++++++ 5 files changed, 522 insertions(+) create mode 100644 llvm/include/llvm/Support/Mustache.h create mode 100644 llvm/lib/Support/Mustache.cpp create mode 100644 llvm/unittests/Support/MustacheTest.cpp diff --git a/llvm/include/llvm/Support/Mustache.h b/llvm/include/llvm/Support/Mustache.h new file mode 100644 index 0000000000000..a1ce9d945a37c --- /dev/null +++ b/llvm/include/llvm/Support/Mustache.h @@ -0,0 +1,109 @@ +//===--- Mustache.h ---------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Implementation of the Mustache templating language supports version 1.4.2 +// (https://mustache.github.io/mustache.5.html). +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_SUPPORT_MUSTACHE +#define LLVM_SUPPORT_MUSTACHE + +#include "Error.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/Support/JSON.h" +#include +#include +#include + +namespace llvm { +namespace mustache { + +using Accessor = std::vector; + +class Token { +public: + enum class Type { + Text, + Variable, + Partial, + SectionOpen, + SectionClose, + InvertSectionOpen, + UnescapeVariable, + Comment, + }; + + Token(std::string Str); + + Token(std::string Str, char Identifier); + + std::string getTokenBody() const { return TokenBody; }; + + Accessor getAccessor() const { return Accessor; }; + + Type getType() const { return TokenType; }; + +private: + Type TokenType; + Accessor Accessor; + std::string TokenBody; +}; + +class ASTNode { +public: + enum Type { + Root, + Text, + Partial, + Variable, + UnescapeVariable, + Section, + InvertSection, + }; + + ASTNode() : T(Type::Root), LocalContext(nullptr){}; + + ASTNode(std::string Body, std::shared_ptr Parent) + : T(Type::Text), Body(Body), Parent(Parent), LocalContext(nullptr){}; + + // Constructor for Section/InvertSection/Variable/UnescapeVariable + ASTNode(Type T, Accessor Accessor, std::shared_ptr Parent) + : T(T), Accessor(Accessor), Parent(Parent), LocalContext(nullptr), + Children({}){}; + + void addChild(std::shared_ptr Child) { + Children.emplace_back(Child); + }; + + std::string render(llvm::json::Value Data); + + llvm::json::Value findContext(); + + Type T; + std::string Body; + std::weak_ptr Parent; + std::vector> Children; + Accessor Accessor; + llvm::json::Value LocalContext; +}; + +class Template { +public: + static Expected