[clang-tools-extra] 7231c99 - [clang-doc] Fix typedef/using output.

2022-10-25 Thread Brett Wilson via cfe-commits

Author: Brett Wilson
Date: 2022-10-25T13:47:24-07:00
New Revision: 7231c9966e523a6fa20aa63b9a9245aff49cf881

URL: 
https://github.com/llvm/llvm-project/commit/7231c9966e523a6fa20aa63b9a9245aff49cf881
DIFF: 
https://github.com/llvm/llvm-project/commit/7231c9966e523a6fa20aa63b9a9245aff49cf881.diff

LOG: [clang-doc] Fix typedef/using output.

Provides an initializer for the TypedefInfo.IsUsing member. Previously
this member was uninitialized and would produce random output.

Adds the Description (code comments) to the bitcode reader/writer.
Previously the typedef/using descriptions were lost during the bitcode
round-trip. Adds a test for this.

Differential Revision: https://reviews.llvm.org/D136638

Added: 


Modified: 
clang-tools-extra/clang-doc/BitcodeReader.cpp
clang-tools-extra/clang-doc/BitcodeWriter.cpp
clang-tools-extra/clang-doc/Representation.h
clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp 
b/clang-tools-extra/clang-doc/BitcodeReader.cpp
index 8e1db35532a05..524b82d9fcc53 100644
--- a/clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -368,28 +368,27 @@ template  llvm::Expected 
getCommentInfo(T I) {
 }
 
 template <> llvm::Expected getCommentInfo(FunctionInfo *I) {
-  I->Description.emplace_back();
-  return &I->Description.back();
+  return &I->Description.emplace_back();
 }
 
 template <> llvm::Expected getCommentInfo(NamespaceInfo *I) {
-  I->Description.emplace_back();
-  return &I->Description.back();
+  return &I->Description.emplace_back();
 }
 
 template <> llvm::Expected getCommentInfo(RecordInfo *I) {
-  I->Description.emplace_back();
-  return &I->Description.back();
+  return &I->Description.emplace_back();
 }
 
 template <> llvm::Expected getCommentInfo(MemberTypeInfo *I) {
-  I->Description.emplace_back();
-  return &I->Description.back();
+  return &I->Description.emplace_back();
 }
 
 template <> llvm::Expected getCommentInfo(EnumInfo *I) {
-  I->Description.emplace_back();
-  return &I->Description.back();
+  return &I->Description.emplace_back();
+}
+
+template <> llvm::Expected getCommentInfo(TypedefInfo *I) {
+  return &I->Description.emplace_back();
 }
 
 template <> llvm::Expected getCommentInfo(CommentInfo *I) {

diff  --git a/clang-tools-extra/clang-doc/BitcodeWriter.cpp 
b/clang-tools-extra/clang-doc/BitcodeWriter.cpp
index 7768f4b06519b..bb0698a5a4028 100644
--- a/clang-tools-extra/clang-doc/BitcodeWriter.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeWriter.cpp
@@ -432,6 +432,8 @@ void ClangDocBitcodeWriter::emitBlock(const TypedefInfo &T) 
{
   emitRecord(T.Name, TYPEDEF_NAME);
   for (const auto &N : T.Namespace)
 emitBlock(N, FieldId::F_namespace);
+  for (const auto &CI : T.Description)
+emitBlock(CI);
   if (T.DefLoc)
 emitRecord(*T.DefLoc, TYPEDEF_DEFLOCATION);
   emitRecord(T.IsUsing, TYPEDEF_IS_USING);

diff  --git a/clang-tools-extra/clang-doc/Representation.h 
b/clang-tools-extra/clang-doc/Representation.h
index d416306704611..7d76844462885 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -365,7 +365,7 @@ struct TypedefInfo : public SymbolInfo {
   //   using MyVector = std::vector
   // False means it's a C-style typedef:
   //   typedef std::vector MyVector;
-  bool IsUsing;
+  bool IsUsing = false;
 };
 
 struct BaseRecordInfo : public RecordInfo {

diff  --git a/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp 
b/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
index db6569419d579..53e84b1814453 100644
--- a/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
+++ b/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
@@ -183,11 +183,33 @@ TEST(BitcodeTest, emitTypedefInfoBitcode) {
   I.Underlying = TypeInfo("unsigned");
   I.IsUsing = true;
 
+  CommentInfo Top;
+  Top.Kind = "FullComment";
+
+  Top.Children.emplace_back(std::make_unique());
+  CommentInfo *BlankLine = Top.Children.back().get();
+  BlankLine->Kind = "ParagraphComment";
+  BlankLine->Children.emplace_back(std::make_unique());
+  BlankLine->Children.back()->Kind = "TextComment";
+
+  I.Description.emplace_back(std::move(Top));
+
   std::string WriteResult = writeInfo(&I);
   EXPECT_TRUE(WriteResult.size() > 0);
   std::vector> ReadResults = readInfo(WriteResult, 1);
 
   CheckTypedefInfo(&I, InfoAsTypedef(ReadResults[0].get()));
+
+  // Check one with no IsUsing set, no description, and no definition location.
+  TypedefInfo I2;
+  I2.Name = "SomethingElse";
+  I2.IsUsing = false;
+  I2.Underlying = TypeInfo("int");
+
+  WriteResult = writeInfo(&I2);
+  EXPECT_TRUE(WriteResult.size() > 0);
+  ReadResults = readInfo(WriteResult, 1);
+  CheckTypedefInfo(&I2, InfoAsTypedef(ReadResults[0].get()));
 }
 
 TEST(SerializeTest, emitInfoWithCommentBitcode) {



__

Re: [PATCH] D134235: [clang-doc] Clean up *Info constructors.

2022-09-26 Thread Brett Wilson via cfe-commits
On Mon, Sep 26, 2022 at 1:42 PM Haowei Wu via Phabricator <
revi...@reviews.llvm.org> wrote:

> haowei added a comment.
>
> @brettw Thanks for the clarification. I was oncall for buildgardener last
> week and got quite busy due to breakages.
>
> Thanks for your clarification, that is really helpful to understand the
> your intent. While I still don't see the way these constructors are
> implemented is an issue. I don't have a strong opinions on this and OK with
> your refactors.
>
> "semantically equivalent" means these test code should have same
> input/output, performance same routines of task and use same amount of
> memory. Before your change, these typeinfo's symbolID in the test are
> always pointing to a constant EmptySID, after your change, some of these
> typeinfo points to an empty symbol ID in allocated in memory when typeinfo
> is created. While the output is the same, they are not equivalent. For
> refactor changes, I would prefer to avoid introducing such changes.
>
> I have one question about deleting the IsInGlobalNamespace. I understand
> it is not well implemented and has a bug in its constructor, but I don't
> think we should simply delete it just because it is buggy and not well
> used. It is part of C++ and commonly used. Do you have any plan to add it
> back after all the refactor work finishes?
>

I guess I'll ask you: what does this boolean mean and why do we need it?
This flag was only ever derived from the "path" which is just a member in
the same class. Users already have the full namespace information as far as
I can tell.

Brett
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 21fb70c - [clang-doc] Add typedef/using information.

2022-10-14 Thread Brett Wilson via cfe-commits

Author: Brett Wilson
Date: 2022-10-14T14:59:29-07:00
New Revision: 21fb70c6ab3b25fe8f5f8384714a9a359b4b5a54

URL: 
https://github.com/llvm/llvm-project/commit/21fb70c6ab3b25fe8f5f8384714a9a359b4b5a54
DIFF: 
https://github.com/llvm/llvm-project/commit/21fb70c6ab3b25fe8f5f8384714a9a359b4b5a54.diff

LOG: [clang-doc] Add typedef/using information.

Read typedef and "using" type alias declarations and serialize into the
internal structures. Emit this information in the YAML output. The HTML
and MD generators are unchanged.

Separate out the logic to create the parent namespace or record object
and insert the newly created child into it. This logic was previously
duplicated for every "info" type and is now shared.

To help this, a struct containing the child vectors was separated out so
children can be added generically and without having too many templates.

A small change was made to populateParentNamespaces() to allow using
types that aren't themselves DeclContexts (typedefs are the first
example of this).

Differential Revision: https://reviews.llvm.org/D134371

Added: 


Modified: 
clang-tools-extra/clang-doc/BitcodeReader.cpp
clang-tools-extra/clang-doc/BitcodeWriter.cpp
clang-tools-extra/clang-doc/BitcodeWriter.h
clang-tools-extra/clang-doc/HTMLGenerator.cpp
clang-tools-extra/clang-doc/MDGenerator.cpp
clang-tools-extra/clang-doc/Mapper.cpp
clang-tools-extra/clang-doc/Mapper.h
clang-tools-extra/clang-doc/Representation.cpp
clang-tools-extra/clang-doc/Representation.h
clang-tools-extra/clang-doc/Serialize.cpp
clang-tools-extra/clang-doc/Serialize.h
clang-tools-extra/clang-doc/YAMLGenerator.cpp
clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
clang-tools-extra/unittests/clang-doc/ClangDocTest.h
clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
clang-tools-extra/unittests/clang-doc/MergeTest.cpp
clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp 
b/clang-tools-extra/clang-doc/BitcodeReader.cpp
index 027272691d03..8e1db35532a0 100644
--- a/clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -24,12 +24,6 @@ llvm::Error decodeRecord(const Record &R, 
llvm::SmallVectorImpl &Field,
   return llvm::Error::success();
 }
 
-llvm::Error decodeRecord(const Record &R, std::string &Field,
- llvm::StringRef Blob) {
-  Field.assign(Blob.begin(), Blob.end());
-  return llvm::Error::success();
-}
-
 llvm::Error decodeRecord(const Record &R, SymbolID &Field,
  llvm::StringRef Blob) {
   if (R[0] != BitCodeConstants::USRHashSize)
@@ -104,6 +98,7 @@ llvm::Error decodeRecord(const Record &R, InfoType &Field,
   case InfoType::IT_function:
   case InfoType::IT_default:
   case InfoType::IT_enum:
+  case InfoType::IT_typedef:
 Field = IT;
 return llvm::Error::success();
   }
@@ -233,6 +228,23 @@ llvm::Error parseRecord(const Record &R, unsigned ID, 
llvm::StringRef Blob,
   }
 }
 
+llvm::Error parseRecord(const Record &R, unsigned ID, llvm::StringRef Blob,
+TypedefInfo *I) {
+  switch (ID) {
+  case TYPEDEF_USR:
+return decodeRecord(R, I->USR, Blob);
+  case TYPEDEF_NAME:
+return decodeRecord(R, I->Name, Blob);
+  case TYPEDEF_DEFLOCATION:
+return decodeRecord(R, I->DefLoc, Blob);
+  case TYPEDEF_IS_USING:
+return decodeRecord(R, I->IsUsing, Blob);
+  default:
+return llvm::createStringError(llvm::inconvertibleErrorCode(),
+   "invalid field for TypedefInfo");
+  }
+}
+
 llvm::Error parseRecord(const Record &R, unsigned ID, llvm::StringRef Blob,
 EnumValueInfo *I) {
   switch (ID) {
@@ -424,6 +436,11 @@ template <> llvm::Error addTypeInfo(EnumInfo *I, TypeInfo 
&&T) {
   return llvm::Error::success();
 }
 
+template <> llvm::Error addTypeInfo(TypedefInfo *I, TypeInfo &&T) {
+  I->Underlying = std::move(T);
+  return llvm::Error::success();
+}
+
 template  llvm::Error addReference(T I, Reference &&R, FieldId F) {
   return llvm::createStringError(llvm::inconvertibleErrorCode(),
  "invalid type cannot contain Reference");
@@ -475,6 +492,17 @@ template <> llvm::Error addReference(EnumInfo *I, 
Reference &&R, FieldId F) {
   }
 }
 
+template <> llvm::Error addReference(TypedefInfo *I, Reference &&R, FieldId F) 
{
+  switch (F) {
+  case FieldId::F_namespace:
+I->Namespace.emplace_back(std::move(R));
+return llvm::Error::success();
+  default:
+return llvm::createStringError(llvm::inconvertibleErrorCode(),
+   "invalid type cannot 

[clang-tools-extra] f8a469f - [clang-doc] Move file layout to the generators.

2022-11-22 Thread Brett Wilson via cfe-commits

Author: Brett Wilson
Date: 2022-11-22T10:27:29-08:00
New Revision: f8a469fc572778d05b72f34a772082cf3abd3cda

URL: 
https://github.com/llvm/llvm-project/commit/f8a469fc572778d05b72f34a772082cf3abd3cda
DIFF: 
https://github.com/llvm/llvm-project/commit/f8a469fc572778d05b72f34a772082cf3abd3cda.diff

LOG: [clang-doc] Move file layout to the generators.

Previously file naming and directory layout was handled on a per Info
object basis by ClangDocMain and the generators blindly wrote to the
files given. This means all generators must use the same file layout and
caused problems where multiple objects mapped to the same file. The
object collision problem happens most easily with template
specializations because the template parameters are not part of the
"name".

This patch moves the responsibility for output file organization to the
generators. Currently HTML and MD use the same structure as before. But
they now collect all objects that map to a given file and combine them,
avoiding the corruption problems.

Converts the YAML generator to naming files based on USR in one
directory. This is easier for downstream tools to manage and avoids
the naming problems with template specializations. Since this change
requires backward-incompatible output changes to referenced files anyway
(since each one is now an array), this is a good time to introduce this
change.

Differential Revision: https://reviews.llvm.org/D138073

Added: 


Modified: 
clang-tools-extra/clang-doc/Generators.h
clang-tools-extra/clang-doc/HTMLGenerator.cpp
clang-tools-extra/clang-doc/MDGenerator.cpp
clang-tools-extra/clang-doc/YAMLGenerator.cpp
clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
clang-tools-extra/test/clang-doc/single-file-public.cpp
clang-tools-extra/test/clang-doc/single-file.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-doc/Generators.h 
b/clang-tools-extra/clang-doc/Generators.h
index 89c6b34c43844..ba0ef64d3d0f5 100644
--- a/clang-tools-extra/clang-doc/Generators.h
+++ b/clang-tools-extra/clang-doc/Generators.h
@@ -25,15 +25,23 @@ class Generator {
 public:
   virtual ~Generator() = default;
 
-  // Write out the decl info in the specified format.
-  virtual llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream &OS,
- const ClangDocContext &CDCtx) = 0;
+  // Write out the decl info for the objects in the given map in the specified
+  // format.
+  virtual llvm::Error
+  generateDocs(StringRef RootDir,
+   llvm::StringMap> Infos,
+   const ClangDocContext &CDCtx) = 0;
+
   // This function writes a file with the index previously constructed.
   // It can be overwritten by any of the inherited generators.
   // If the override method wants to run this it should call
   // Generator::createResources(CDCtx);
   virtual llvm::Error createResources(ClangDocContext &CDCtx);
 
+  // Write out one specific decl info to the destination stream.
+  virtual llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream &OS,
+ const ClangDocContext &CDCtx) = 0;
+
   static void addInfoToIndex(Index &Idx, const doc::Info *Info);
 };
 

diff  --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp 
b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index 6f1d45551bc78..11a78ba60e35c 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -11,6 +11,7 @@
 #include "clang/Basic/Version.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSet.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/Path.h"
@@ -839,13 +840,69 @@ class HTMLGenerator : public Generator {
 public:
   static const char *Format;
 
+  llvm::Error generateDocs(StringRef RootDir,
+   llvm::StringMap> Infos,
+   const ClangDocContext &CDCtx) override;
+  llvm::Error createResources(ClangDocContext &CDCtx) override;
   llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream &OS,
  const ClangDocContext &CDCtx) override;
-  llvm::Error createResources(ClangDocContext &CDCtx) override;
 };
 
 const char *HTMLGenerator::Format = "html";
 
+llvm::Error
+HTMLGenerator::generateDocs(StringRef RootDir,
+llvm::StringMap> Infos,
+const ClangDocContext &CDCtx) {
+  // Track which directories we already tried to create.
+  llvm::StringSet<> CreatedDirs;
+
+  // Collect all output by file name and create the nexessary directories.
+  llvm::StringMap> FileToInfos;
+  for (const auto &Group : Infos) {
+doc::Info *Info = Group.getValue().get();
+
+llvm::SmallString<128> Path;
+llvm::sys::path::native(RootDir, Path);
+llvm::sys::path::append(Path, Info->getRelativeFilePath(""));

[clang-tools-extra] 7b8c7e0 - [clang-doc] Move file layout to the generators.

2022-11-29 Thread Brett Wilson via cfe-commits

Author: Brett Wilson
Date: 2022-11-29T14:40:58-08:00
New Revision: 7b8c7e02122a2ea392b371e3e39b405bc98146de

URL: 
https://github.com/llvm/llvm-project/commit/7b8c7e02122a2ea392b371e3e39b405bc98146de
DIFF: 
https://github.com/llvm/llvm-project/commit/7b8c7e02122a2ea392b371e3e39b405bc98146de.diff

LOG: [clang-doc] Move file layout to the generators.

Previously file naming and directory layout was handled on a per Info
object basis by ClangDocMain and the generators blindly wrote to the
files given. This means all generators must use the same file layout and
caused problems where multiple objects mapped to the same file. The
object collision problem happens most easily with template
specializations because the template parameters are not part of the
"name".

This patch moves the responsibility for output file organization to the
generators. Currently HTML and MD use the same structure as before. But
they now collect all objects that map to a given file and combine them,
avoiding the corruption problems.

Converts the YAML generator to naming files based on USR in one
directory. This is easier for downstream tools to manage and avoids the
naming problems with template specializations. Since this change
requires backward-incompatible output changes to referenced files anyway
(since each one is now an array), this is a good time to introduce this
change.

Differential Revision: https://reviews.llvm.org/D138073

Added: 


Modified: 
clang-tools-extra/clang-doc/Generators.h
clang-tools-extra/clang-doc/HTMLGenerator.cpp
clang-tools-extra/clang-doc/MDGenerator.cpp
clang-tools-extra/clang-doc/YAMLGenerator.cpp
clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
clang-tools-extra/test/clang-doc/single-file-public.cpp
clang-tools-extra/test/clang-doc/single-file.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-doc/Generators.h 
b/clang-tools-extra/clang-doc/Generators.h
index 89c6b34c4384..ba0ef64d3d0f 100644
--- a/clang-tools-extra/clang-doc/Generators.h
+++ b/clang-tools-extra/clang-doc/Generators.h
@@ -25,15 +25,23 @@ class Generator {
 public:
   virtual ~Generator() = default;
 
-  // Write out the decl info in the specified format.
-  virtual llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream &OS,
- const ClangDocContext &CDCtx) = 0;
+  // Write out the decl info for the objects in the given map in the specified
+  // format.
+  virtual llvm::Error
+  generateDocs(StringRef RootDir,
+   llvm::StringMap> Infos,
+   const ClangDocContext &CDCtx) = 0;
+
   // This function writes a file with the index previously constructed.
   // It can be overwritten by any of the inherited generators.
   // If the override method wants to run this it should call
   // Generator::createResources(CDCtx);
   virtual llvm::Error createResources(ClangDocContext &CDCtx);
 
+  // Write out one specific decl info to the destination stream.
+  virtual llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream &OS,
+ const ClangDocContext &CDCtx) = 0;
+
   static void addInfoToIndex(Index &Idx, const doc::Info *Info);
 };
 

diff  --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp 
b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index 6f1d45551bc7..11a78ba60e35 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -11,6 +11,7 @@
 #include "clang/Basic/Version.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSet.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/Path.h"
@@ -839,13 +840,69 @@ class HTMLGenerator : public Generator {
 public:
   static const char *Format;
 
+  llvm::Error generateDocs(StringRef RootDir,
+   llvm::StringMap> Infos,
+   const ClangDocContext &CDCtx) override;
+  llvm::Error createResources(ClangDocContext &CDCtx) override;
   llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream &OS,
  const ClangDocContext &CDCtx) override;
-  llvm::Error createResources(ClangDocContext &CDCtx) override;
 };
 
 const char *HTMLGenerator::Format = "html";
 
+llvm::Error
+HTMLGenerator::generateDocs(StringRef RootDir,
+llvm::StringMap> Infos,
+const ClangDocContext &CDCtx) {
+  // Track which directories we already tried to create.
+  llvm::StringSet<> CreatedDirs;
+
+  // Collect all output by file name and create the nexessary directories.
+  llvm::StringMap> FileToInfos;
+  for (const auto &Group : Infos) {
+doc::Info *Info = Group.getValue().get();
+
+llvm::SmallString<128> Path;
+llvm::sys::path::native(RootDir, Path);
+llvm::sys::path::append(Path, Info->getRelativeFilePath(""));
+   

[clang-tools-extra] 0f6dbb5 - [clang-doc] Add template support.

2022-12-07 Thread Brett Wilson via cfe-commits

Author: Brett Wilson
Date: 2022-12-07T09:48:13-08:00
New Revision: 0f6dbb5f164662c3e6a167a89e7a89f07c60e32b

URL: 
https://github.com/llvm/llvm-project/commit/0f6dbb5f164662c3e6a167a89e7a89f07c60e32b
DIFF: 
https://github.com/llvm/llvm-project/commit/0f6dbb5f164662c3e6a167a89e7a89f07c60e32b.diff

LOG: [clang-doc] Add template support.

Reads template information from the AST and adds template parameters and
specialization information to the corresponding clang-doc structures.

Add a "QualName" to the Reference struct which includes the full
qualified type name. The Reference object represents a link in the
HTML/MD generators so is based on the unqualified name. But this does
not encode C-V qualifiers or template information that decorate the
name. The new QualName member encodes all of this information and also
makes it easier for the generators or downsteam YAML consumers to
generate the full name (before they had to process the "Path").

In test code that was changed, remove made-up paths to built-in types
like "int". In addition to slightnly cleaning up the code, these types
do not have paths in real execution, and generating incorrect references
to nonexistant data may complicate future changes in the generators.

Differential Revision: https://reviews.llvm.org/D139154

Added: 
clang-tools-extra/test/clang-doc/templates.cpp

Modified: 
clang-tools-extra/clang-doc/BitcodeReader.cpp
clang-tools-extra/clang-doc/BitcodeWriter.cpp
clang-tools-extra/clang-doc/BitcodeWriter.h
clang-tools-extra/clang-doc/Representation.cpp
clang-tools-extra/clang-doc/Representation.h
clang-tools-extra/clang-doc/Serialize.cpp
clang-tools-extra/clang-doc/YAMLGenerator.cpp
clang-tools-extra/test/clang-doc/single-file-public.cpp
clang-tools-extra/test/clang-doc/single-file.cpp
clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp 
b/clang-tools-extra/clang-doc/BitcodeReader.cpp
index 072011448330e..3fb85056cee8f 100644
--- a/clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -351,6 +351,8 @@ llvm::Error parseRecord(const Record &R, unsigned ID, 
llvm::StringRef Blob,
 return decodeRecord(R, I->USR, Blob);
   case REFERENCE_NAME:
 return decodeRecord(R, I->Name, Blob);
+  case REFERENCE_QUAL_NAME:
+return decodeRecord(R, I->QualName, Blob);
   case REFERENCE_TYPE:
 return decodeRecord(R, I->RefType, Blob);
   case REFERENCE_PATH:
@@ -363,6 +365,29 @@ llvm::Error parseRecord(const Record &R, unsigned ID, 
llvm::StringRef Blob,
   }
 }
 
+llvm::Error parseRecord(const Record &R, unsigned ID, llvm::StringRef Blob,
+TemplateInfo *I) {
+  // Currently there are no child records of TemplateInfo (only child blocks).
+  return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "invalid field for TemplateParamInfo");
+}
+
+llvm::Error parseRecord(const Record &R, unsigned ID, llvm::StringRef Blob,
+TemplateSpecializationInfo *I) {
+  if (ID == TEMPLATE_SPECIALIZATION_OF)
+return decodeRecord(R, I->SpecializationOf, Blob);
+  return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "invalid field for TemplateParamInfo");
+}
+
+llvm::Error parseRecord(const Record &R, unsigned ID, llvm::StringRef Blob,
+TemplateParamInfo *I) {
+  if (ID == TEMPLATE_PARAM_CONTENTS)
+return decodeRecord(R, I->Contents, Blob);
+  return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "invalid field for TemplateParamInfo");
+}
+
 template  llvm::Expected getCommentInfo(T I) {
   return llvm::createStringError(llvm::inconvertibleErrorCode(),
  "invalid type cannot contain CommentInfo");
@@ -595,6 +620,45 @@ template <> void addChild(BaseRecordInfo *I, FunctionInfo 
&&R) {
   I->Children.Functions.emplace_back(std::move(R));
 }
 
+// TemplateParam children. These go into either a TemplateInfo (for template
+// parameters) or TemplateSpecializationInfo (for the specialization's
+// parameters).
+template  void addTemplateParam(T I, TemplateParamInfo &&P) {
+  llvm::errs() << "invalid container for template parameter";
+  exit(1);
+}
+template <> void addTemplateParam(TemplateInfo *I, TemplateParamInfo &&P) {
+  I->Params.emplace_back(std::move(P));
+}
+template <>
+void addTemplateParam(TemplateSpecializationInfo *I, TemplateParamInfo &&P) {
+  I->Params.emplace_back(std::move(P));
+}
+
+// Template info. These apply to either records or functions.
+template  void addTemplate(T I, TemplateInfo &&P) {
+  llvm::errs() << "invalid container for tem

[clang-tools-extra] 91b38c6 - Revert "[clang-doc] Add template support."

2022-12-07 Thread Brett Wilson via cfe-commits

Author: Brett Wilson
Date: 2022-12-07T10:22:51-08:00
New Revision: 91b38c6aaddefabad2a4c959ea3865e356761ed5

URL: 
https://github.com/llvm/llvm-project/commit/91b38c6aaddefabad2a4c959ea3865e356761ed5
DIFF: 
https://github.com/llvm/llvm-project/commit/91b38c6aaddefabad2a4c959ea3865e356761ed5.diff

LOG: Revert "[clang-doc] Add template support."

Causes a build failure in YAML specializations.

This reverts commit 0f6dbb5f164662c3e6a167a89e7a89f07c60e32b.

Added: 


Modified: 
clang-tools-extra/clang-doc/BitcodeReader.cpp
clang-tools-extra/clang-doc/BitcodeWriter.cpp
clang-tools-extra/clang-doc/BitcodeWriter.h
clang-tools-extra/clang-doc/Representation.cpp
clang-tools-extra/clang-doc/Representation.h
clang-tools-extra/clang-doc/Serialize.cpp
clang-tools-extra/clang-doc/YAMLGenerator.cpp
clang-tools-extra/test/clang-doc/single-file-public.cpp
clang-tools-extra/test/clang-doc/single-file.cpp
clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Removed: 
clang-tools-extra/test/clang-doc/templates.cpp



diff  --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp 
b/clang-tools-extra/clang-doc/BitcodeReader.cpp
index 3fb85056cee8f..072011448330e 100644
--- a/clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -351,8 +351,6 @@ llvm::Error parseRecord(const Record &R, unsigned ID, 
llvm::StringRef Blob,
 return decodeRecord(R, I->USR, Blob);
   case REFERENCE_NAME:
 return decodeRecord(R, I->Name, Blob);
-  case REFERENCE_QUAL_NAME:
-return decodeRecord(R, I->QualName, Blob);
   case REFERENCE_TYPE:
 return decodeRecord(R, I->RefType, Blob);
   case REFERENCE_PATH:
@@ -365,29 +363,6 @@ llvm::Error parseRecord(const Record &R, unsigned ID, 
llvm::StringRef Blob,
   }
 }
 
-llvm::Error parseRecord(const Record &R, unsigned ID, llvm::StringRef Blob,
-TemplateInfo *I) {
-  // Currently there are no child records of TemplateInfo (only child blocks).
-  return llvm::createStringError(llvm::inconvertibleErrorCode(),
- "invalid field for TemplateParamInfo");
-}
-
-llvm::Error parseRecord(const Record &R, unsigned ID, llvm::StringRef Blob,
-TemplateSpecializationInfo *I) {
-  if (ID == TEMPLATE_SPECIALIZATION_OF)
-return decodeRecord(R, I->SpecializationOf, Blob);
-  return llvm::createStringError(llvm::inconvertibleErrorCode(),
- "invalid field for TemplateParamInfo");
-}
-
-llvm::Error parseRecord(const Record &R, unsigned ID, llvm::StringRef Blob,
-TemplateParamInfo *I) {
-  if (ID == TEMPLATE_PARAM_CONTENTS)
-return decodeRecord(R, I->Contents, Blob);
-  return llvm::createStringError(llvm::inconvertibleErrorCode(),
- "invalid field for TemplateParamInfo");
-}
-
 template  llvm::Expected getCommentInfo(T I) {
   return llvm::createStringError(llvm::inconvertibleErrorCode(),
  "invalid type cannot contain CommentInfo");
@@ -620,45 +595,6 @@ template <> void addChild(BaseRecordInfo *I, FunctionInfo 
&&R) {
   I->Children.Functions.emplace_back(std::move(R));
 }
 
-// TemplateParam children. These go into either a TemplateInfo (for template
-// parameters) or TemplateSpecializationInfo (for the specialization's
-// parameters).
-template  void addTemplateParam(T I, TemplateParamInfo &&P) {
-  llvm::errs() << "invalid container for template parameter";
-  exit(1);
-}
-template <> void addTemplateParam(TemplateInfo *I, TemplateParamInfo &&P) {
-  I->Params.emplace_back(std::move(P));
-}
-template <>
-void addTemplateParam(TemplateSpecializationInfo *I, TemplateParamInfo &&P) {
-  I->Params.emplace_back(std::move(P));
-}
-
-// Template info. These apply to either records or functions.
-template  void addTemplate(T I, TemplateInfo &&P) {
-  llvm::errs() << "invalid container for template info";
-  exit(1);
-}
-template <> void addTemplate(RecordInfo *I, TemplateInfo &&P) {
-  I->Template.emplace(std::move(P));
-}
-template <> void addTemplate(FunctionInfo *I, TemplateInfo &&P) {
-  I->Template.emplace(std::move(P));
-}
-
-// Template specializations go only into template records.
-template 
-void addTemplateSpecialization(T I, TemplateSpecializationInfo &&TSI) {
-  llvm::errs() << "invalid container for template specialization info";
-  exit(1);
-}
-template <>
-void addTemplateSpecialization(TemplateInfo *I,
-   TemplateSpecializationInfo &&TSI) {
-  I->Specialization.emplace(std::move(TSI));
-}
-
 // Read records from bitcode into a given info.
 template 
 llvm::Error ClangDocBitcodeReader::readRecord(unsigned ID, T I) {
@@ -783,27 +719,6 @@ llvm::Error ClangDocBitcodeRead

[clang-tools-extra] 4a68bab - [clang-doc] Add template support.

2022-12-08 Thread Brett Wilson via cfe-commits

Author: Brett Wilson
Date: 2022-12-08T08:02:02-08:00
New Revision: 4a68babd9973f043fd3e40f159fbb990880606a6

URL: 
https://github.com/llvm/llvm-project/commit/4a68babd9973f043fd3e40f159fbb990880606a6
DIFF: 
https://github.com/llvm/llvm-project/commit/4a68babd9973f043fd3e40f159fbb990880606a6.diff

LOG: [clang-doc] Add template support.

Reads template information from the AST and adds template parameters and
specialization information to the corresponding clang-doc structures.

Add a "QualName" to the Reference struct which includes the full
qualified type name. The Reference object represents a link in the
HTML/MD generators so is based on the unqualified name. But this does
not encode C-V qualifiers or template information that decorate the
name. The new QualName member encodes all of this information and also
makes it easier for the generators or downsteam YAML consumers to
generate the full name (before they had to process the "Path").

In test code that was changed, remove made-up paths to built-in types
like "int". In addition to slightnly cleaning up the code, these types
do not have paths in real execution, and generating incorrect references
to nonexistant data may complicate future changes in the generators.

Convert llvm::Optional to std::optional (YAML library requires this for
the new usage, and this makes everything consistent according to the
llvm::Optional -> std::optional transition).

Differential Revision: https://reviews.llvm.org/D139154

Added: 
clang-tools-extra/test/clang-doc/templates.cpp

Modified: 
clang-tools-extra/clang-doc/BitcodeReader.cpp
clang-tools-extra/clang-doc/BitcodeWriter.cpp
clang-tools-extra/clang-doc/BitcodeWriter.h
clang-tools-extra/clang-doc/Representation.cpp
clang-tools-extra/clang-doc/Representation.h
clang-tools-extra/clang-doc/Serialize.cpp
clang-tools-extra/clang-doc/YAMLGenerator.cpp
clang-tools-extra/test/clang-doc/single-file-public.cpp
clang-tools-extra/test/clang-doc/single-file.cpp
clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp 
b/clang-tools-extra/clang-doc/BitcodeReader.cpp
index c6928f60f3970..9ac60fa73a782 100644
--- a/clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -350,6 +350,8 @@ llvm::Error parseRecord(const Record &R, unsigned ID, 
llvm::StringRef Blob,
 return decodeRecord(R, I->USR, Blob);
   case REFERENCE_NAME:
 return decodeRecord(R, I->Name, Blob);
+  case REFERENCE_QUAL_NAME:
+return decodeRecord(R, I->QualName, Blob);
   case REFERENCE_TYPE:
 return decodeRecord(R, I->RefType, Blob);
   case REFERENCE_PATH:
@@ -362,6 +364,29 @@ llvm::Error parseRecord(const Record &R, unsigned ID, 
llvm::StringRef Blob,
   }
 }
 
+llvm::Error parseRecord(const Record &R, unsigned ID, llvm::StringRef Blob,
+TemplateInfo *I) {
+  // Currently there are no child records of TemplateInfo (only child blocks).
+  return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "invalid field for TemplateParamInfo");
+}
+
+llvm::Error parseRecord(const Record &R, unsigned ID, llvm::StringRef Blob,
+TemplateSpecializationInfo *I) {
+  if (ID == TEMPLATE_SPECIALIZATION_OF)
+return decodeRecord(R, I->SpecializationOf, Blob);
+  return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "invalid field for TemplateParamInfo");
+}
+
+llvm::Error parseRecord(const Record &R, unsigned ID, llvm::StringRef Blob,
+TemplateParamInfo *I) {
+  if (ID == TEMPLATE_PARAM_CONTENTS)
+return decodeRecord(R, I->Contents, Blob);
+  return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "invalid field for TemplateParamInfo");
+}
+
 template  llvm::Expected getCommentInfo(T I) {
   return llvm::createStringError(llvm::inconvertibleErrorCode(),
  "invalid type cannot contain CommentInfo");
@@ -594,6 +619,45 @@ template <> void addChild(BaseRecordInfo *I, FunctionInfo 
&&R) {
   I->Children.Functions.emplace_back(std::move(R));
 }
 
+// TemplateParam children. These go into either a TemplateInfo (for template
+// parameters) or TemplateSpecializationInfo (for the specialization's
+// parameters).
+template  void addTemplateParam(T I, TemplateParamInfo &&P) {
+  llvm::errs() << "invalid container for template parameter";
+  exit(1);
+}
+template <> void addTemplateParam(TemplateInfo *I, TemplateParamInfo &&P) {
+  I->Params.emplace_back(std::move(P));
+}
+template <>
+void addTemplateParam(TemplateSpecializationInfo *I, TemplateParamInfo &&P) {
+  I->Params.emplace