[PATCH] D66502: [clang-doc] Switch Generator::CreateResources to use llvm::Error

2019-08-21 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran accepted this revision.
DiegoAstiazaran added a comment.
This revision is now accepted and ready to land.

LGTM


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66502/new/

https://reviews.llvm.org/D66502



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


[PATCH] D66378: [clang-doc] Fix casting not working in gcc 5.4.0

2019-08-16 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL369182: [clang-doc] Fix casting not working in gcc 5.4.0 
(authored by DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66378?vs=215730=215732#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66378/new/

https://reviews.llvm.org/D66378

Files:
  clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp


Index: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
@@ -89,7 +89,7 @@
 
   HTMLTag Tag; // Name of HTML Tag (p, div, h1)
   std::vector> Children; // List of child nodes
-  std::vector, llvm::SmallString<16>>>
+  std::vector>
   Attributes; // List of key-value attributes for tag
 
   void Render(llvm::raw_ostream , int IndentationLevel) override;
@@ -278,7 +278,7 @@
 llvm::sys::path::filename(FilePath));
 // Paths in HTML must be in posix-style
 llvm::sys::path::native(StylesheetPath, llvm::sys::path::Style::posix);
-LinkNode->Attributes.emplace_back("href", StylesheetPath);
+LinkNode->Attributes.emplace_back("href", StylesheetPath.str());
 Out.emplace_back(std::move(LinkNode));
   }
   return Out;
@@ -293,7 +293,7 @@
 llvm::sys::path::append(ScriptPath, llvm::sys::path::filename(FilePath));
 // Paths in HTML must be in posix-style
 llvm::sys::path::native(ScriptPath, llvm::sys::path::Style::posix);
-ScriptNode->Attributes.emplace_back("src", ScriptPath);
+ScriptNode->Attributes.emplace_back("src", ScriptPath.str());
 Out.emplace_back(std::move(ScriptNode));
   }
   return Out;
@@ -454,7 +454,7 @@
   Node->Children.emplace_back(std::make_unique(" of file "));
   auto LocFileNode = std::make_unique(
   HTMLTag::TAG_A, llvm::sys::path::filename(FileURL));
-  LocFileNode->Attributes.emplace_back("href", FileURL);
+  LocFileNode->Attributes.emplace_back("href", FileURL.str());
   Node->Children.emplace_back(std::move(LocFileNode));
   return Node;
 }


Index: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
@@ -89,7 +89,7 @@
 
   HTMLTag Tag; // Name of HTML Tag (p, div, h1)
   std::vector> Children; // List of child nodes
-  std::vector, llvm::SmallString<16>>>
+  std::vector>
   Attributes; // List of key-value attributes for tag
 
   void Render(llvm::raw_ostream , int IndentationLevel) override;
@@ -278,7 +278,7 @@
 llvm::sys::path::filename(FilePath));
 // Paths in HTML must be in posix-style
 llvm::sys::path::native(StylesheetPath, llvm::sys::path::Style::posix);
-LinkNode->Attributes.emplace_back("href", StylesheetPath);
+LinkNode->Attributes.emplace_back("href", StylesheetPath.str());
 Out.emplace_back(std::move(LinkNode));
   }
   return Out;
@@ -293,7 +293,7 @@
 llvm::sys::path::append(ScriptPath, llvm::sys::path::filename(FilePath));
 // Paths in HTML must be in posix-style
 llvm::sys::path::native(ScriptPath, llvm::sys::path::Style::posix);
-ScriptNode->Attributes.emplace_back("src", ScriptPath);
+ScriptNode->Attributes.emplace_back("src", ScriptPath.str());
 Out.emplace_back(std::move(ScriptNode));
   }
   return Out;
@@ -454,7 +454,7 @@
   Node->Children.emplace_back(std::make_unique(" of file "));
   auto LocFileNode = std::make_unique(
   HTMLTag::TAG_A, llvm::sys::path::filename(FileURL));
-  LocFileNode->Attributes.emplace_back("href", FileURL);
+  LocFileNode->Attributes.emplace_back("href", FileURL.str());
   Node->Children.emplace_back(std::move(LocFileNode));
   return Node;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D66378: [clang-doc] Fix casting not working in gcc 5.4.0

2019-08-16 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran created this revision.
DiegoAstiazaran added a project: clang-tools-extra.

An implicit cast of std::string to llvm::SmallString<> was breaking GCC 5.4.0 
builder.
A pair using llvm::SmallString<> now uses std::string.


https://reviews.llvm.org/D66378

Files:
  clang-tools-extra/clang-doc/HTMLGenerator.cpp


Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -89,7 +89,7 @@
 
   HTMLTag Tag; // Name of HTML Tag (p, div, h1)
   std::vector> Children; // List of child nodes
-  std::vector, llvm::SmallString<16>>>
+  std::vector>
   Attributes; // List of key-value attributes for tag
 
   void Render(llvm::raw_ostream , int IndentationLevel) override;
@@ -278,7 +278,7 @@
 llvm::sys::path::filename(FilePath));
 // Paths in HTML must be in posix-style
 llvm::sys::path::native(StylesheetPath, llvm::sys::path::Style::posix);
-LinkNode->Attributes.emplace_back("href", StylesheetPath);
+LinkNode->Attributes.emplace_back("href", StylesheetPath.str());
 Out.emplace_back(std::move(LinkNode));
   }
   return Out;
@@ -293,7 +293,7 @@
 llvm::sys::path::append(ScriptPath, llvm::sys::path::filename(FilePath));
 // Paths in HTML must be in posix-style
 llvm::sys::path::native(ScriptPath, llvm::sys::path::Style::posix);
-ScriptNode->Attributes.emplace_back("src", ScriptPath);
+ScriptNode->Attributes.emplace_back("src", ScriptPath.str());
 Out.emplace_back(std::move(ScriptNode));
   }
   return Out;
@@ -454,7 +454,7 @@
   Node->Children.emplace_back(std::make_unique(" of file "));
   auto LocFileNode = std::make_unique(
   HTMLTag::TAG_A, llvm::sys::path::filename(FileURL));
-  LocFileNode->Attributes.emplace_back("href", FileURL);
+  LocFileNode->Attributes.emplace_back("href", FileURL.str());
   Node->Children.emplace_back(std::move(LocFileNode));
   return Node;
 }


Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -89,7 +89,7 @@
 
   HTMLTag Tag; // Name of HTML Tag (p, div, h1)
   std::vector> Children; // List of child nodes
-  std::vector, llvm::SmallString<16>>>
+  std::vector>
   Attributes; // List of key-value attributes for tag
 
   void Render(llvm::raw_ostream , int IndentationLevel) override;
@@ -278,7 +278,7 @@
 llvm::sys::path::filename(FilePath));
 // Paths in HTML must be in posix-style
 llvm::sys::path::native(StylesheetPath, llvm::sys::path::Style::posix);
-LinkNode->Attributes.emplace_back("href", StylesheetPath);
+LinkNode->Attributes.emplace_back("href", StylesheetPath.str());
 Out.emplace_back(std::move(LinkNode));
   }
   return Out;
@@ -293,7 +293,7 @@
 llvm::sys::path::append(ScriptPath, llvm::sys::path::filename(FilePath));
 // Paths in HTML must be in posix-style
 llvm::sys::path::native(ScriptPath, llvm::sys::path::Style::posix);
-ScriptNode->Attributes.emplace_back("src", ScriptPath);
+ScriptNode->Attributes.emplace_back("src", ScriptPath.str());
 Out.emplace_back(std::move(ScriptNode));
   }
   return Out;
@@ -454,7 +454,7 @@
   Node->Children.emplace_back(std::make_unique(" of file "));
   auto LocFileNode = std::make_unique(
   HTMLTag::TAG_A, llvm::sys::path::filename(FileURL));
-  LocFileNode->Attributes.emplace_back("href", FileURL);
+  LocFileNode->Attributes.emplace_back("href", FileURL.str());
   Node->Children.emplace_back(std::move(LocFileNode));
   return Node;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D66353: [clang-doc] Redesign of generated HTML files

2019-08-16 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL369139: [clang-doc] Redesign of generated HTML files 
(authored by DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66353?vs=215642=215649#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66353/new/

https://reviews.llvm.org/D66353

Files:
  clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/trunk/clang-doc/Representation.cpp
  clang-tools-extra/trunk/clang-doc/Representation.h
  clang-tools-extra/trunk/clang-doc/assets/clang-doc-default-stylesheet.css
  clang-tools-extra/trunk/clang-doc/assets/index.js
  clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/trunk/docs/clang-doc.rst
  clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp

Index: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -10,11 +10,15 @@
 #include "Generators.h"
 #include "Representation.h"
 #include "Serialize.h"
+#include "clang/Basic/Version.h"
 #include "gtest/gtest.h"
 
 namespace clang {
 namespace doc {
 
+static const std::string ClangDocVersion =
+clang::getClangToolFullVersion("clang-doc");
+
 std::unique_ptr getHTMLGenerator() {
   auto G = doc::findGeneratorByName("html");
   if (!G)
@@ -25,7 +29,8 @@
 ClangDocContext
 getClangDocContext(std::vector UserStylesheets = {},
StringRef RepositoryUrl = "") {
-  ClangDocContext CDCtx{{}, {}, {}, {}, RepositoryUrl, UserStylesheets, {}};
+  ClangDocContext CDCtx{
+  {}, "test-project", {}, {}, {}, RepositoryUrl, UserStylesheets, {}};
   CDCtx.UserStylesheets.insert(
   CDCtx.UserStylesheets.begin(),
   "../share/clang/clang-doc-default-stylesheet.css");
@@ -61,67 +66,76 @@
 
 
 
-
-
-  
-
-  Namespaces
-
-  
-  
-
-  Records
-
-  
-  
-
-  Functions
-
+test-project
+
+  
+  
+namespace Namespace
+Namespaces
 
   
-
-  OneFunction
-
+ChildNamespace
   
 
-  
-  
-
-  Enums
-
+Records
 
   
-
-  OneEnum
-
+ChildStruct
   
 
-  
-
-
-  namespace Namespace
-  Namespaces
-  
-
-  ChildNamespace
-
-  
-  Records
-  
-
-  ChildStruct
-
-  
-  Functions
-  
-OneFunction
-OneFunction()
+Functions
+
+  OneFunction
+  OneFunction()
+
+Enums
+
+  enum OneEnum
+
   
-  Enums
-  
-enum OneEnum
+  
+
+  
+
+  Namespaces
+
+  
+  
+
+  Records
+
+  
+  
+
+  Functions
+
+
+  
+
+  OneFunction
+
+  
+
+  
+  
+
+  Enums
+
+
+  
+
+  OneEnum
+
+  
+
+  
+
   
-
+
+
+  )raw" +
+ ClangDocVersion + R"raw(
+
 )raw";
 
   EXPECT_EQ(Expected, Actual.str());
@@ -162,80 +176,89 @@
 class r
 
 
-
-
-  
-
-  Members
-
-  
-  
-
-  Records
-
-  
-  
-
-  Functions
-
+test-project
+
+  
+  
+class r
+
+  Defined at line 
+  http://www.repository.com/dir/test.cpp#10;>10
+   of file 
+  http://www.repository.com/dir/test.cpp;>test.cpp
+
+
+  Inherits from 
+  F
+  , G
+
+Members
 
   
-
-  OneFunction
-
+private 
+int
+ X
   
 
-  
-  
-
-  Enums
-
+Records
 
   
-
-  OneEnum
-
+ChildStruct
   
 
-  
-
-
-  class r
-  
-Defined at line 
-http://www.repository.com/dir/test.cpp#10;>10
- of file 
-http://www.repository.com/dir/test.cpp;>test.cpp
-  
-  
-Inherits from 
-F
-, G
-  
-  Members
-  
-
-  private 
-  int
-   X
-
-  
-  Records
-  
-
-  ChildStruct
-
-  
-  Functions
-  
-OneFunction
-public OneFunction()
+Functions
+
+  OneFunction
+  public OneFunction()
+
+Enums
+
+  enum OneEnum
+
   
-  Enums
-  
-enum OneEnum
+  
+
+  
+
+  Members
+
+  
+  
+
+  Records
+
+  
+  
+
+  Functions
+
+
+  
+
+  OneFunction
+
+  
+
+  
+  
+
+  Enums
+
+
+  
+
+  OneEnum
+
+  
+
+ 

[PATCH] D66353: [clang-doc] Redesign of generated HTML files

2019-08-16 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 215642.
DiegoAstiazaran marked 3 inline comments as done.
DiegoAstiazaran added a comment.

Add comments.
Fix clang-doc version.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66353/new/

https://reviews.llvm.org/D66353

Files:
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/Representation.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/assets/clang-doc-default-stylesheet.css
  clang-tools-extra/clang-doc/assets/index.js
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/docs/clang-doc.rst
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -10,11 +10,15 @@
 #include "Generators.h"
 #include "Representation.h"
 #include "Serialize.h"
+#include "clang/Basic/Version.h"
 #include "gtest/gtest.h"
 
 namespace clang {
 namespace doc {
 
+static const std::string ClangDocVersion =
+clang::getClangToolFullVersion("clang-doc");
+
 std::unique_ptr getHTMLGenerator() {
   auto G = doc::findGeneratorByName("html");
   if (!G)
@@ -25,7 +29,8 @@
 ClangDocContext
 getClangDocContext(std::vector UserStylesheets = {},
StringRef RepositoryUrl = "") {
-  ClangDocContext CDCtx{{}, {}, {}, {}, RepositoryUrl, UserStylesheets, {}};
+  ClangDocContext CDCtx{
+  {}, "test-project", {}, {}, {}, RepositoryUrl, UserStylesheets, {}};
   CDCtx.UserStylesheets.insert(
   CDCtx.UserStylesheets.begin(),
   "../share/clang/clang-doc-default-stylesheet.css");
@@ -61,67 +66,76 @@
 
 
 
-
-
-  
-
-  Namespaces
-
-  
-  
-
-  Records
-
-  
-  
-
-  Functions
-
+test-project
+
+  
+  
+namespace Namespace
+Namespaces
 
   
-
-  OneFunction
-
+ChildNamespace
   
 
-  
-  
-
-  Enums
-
+Records
 
   
-
-  OneEnum
-
+ChildStruct
   
 
-  
-
-
-  namespace Namespace
-  Namespaces
-  
-
-  ChildNamespace
-
-  
-  Records
-  
-
-  ChildStruct
-
-  
-  Functions
-  
-OneFunction
-OneFunction()
+Functions
+
+  OneFunction
+  OneFunction()
+
+Enums
+
+  enum OneEnum
+
   
-  Enums
-  
-enum OneEnum
+  
+
+  
+
+  Namespaces
+
+  
+  
+
+  Records
+
+  
+  
+
+  Functions
+
+
+  
+
+  OneFunction
+
+  
+
+  
+  
+
+  Enums
+
+
+  
+
+  OneEnum
+
+  
+
+  
+
   
-
+
+
+  )raw" +
+ ClangDocVersion + R"raw(
+
 )raw";
 
   EXPECT_EQ(Expected, Actual.str());
@@ -162,80 +176,89 @@
 class r
 
 
-
-
-  
-
-  Members
-
-  
-  
-
-  Records
-
-  
-  
-
-  Functions
-
+test-project
+
+  
+  
+class r
+
+  Defined at line 
+  http://www.repository.com/dir/test.cpp#10;>10
+   of file 
+  http://www.repository.com/dir/test.cpp;>test.cpp
+
+
+  Inherits from 
+  F
+  , G
+
+Members
 
   
-
-  OneFunction
-
+private 
+int
+ X
   
 
-  
-  
-
-  Enums
-
+Records
 
   
-
-  OneEnum
-
+ChildStruct
   
 
-  
-
-
-  class r
-  
-Defined at line 
-http://www.repository.com/dir/test.cpp#10;>10
- of file 
-http://www.repository.com/dir/test.cpp;>test.cpp
-  
-  
-Inherits from 
-F
-, G
-  
-  Members
-  
-
-  private 
-  int
-   X
-
-  
-  Records
-  
-
-  ChildStruct
-
-  
-  Functions
-  
-OneFunction
-public OneFunction()
+Functions
+
+  OneFunction
+  public OneFunction()
+
+Enums
+
+  enum OneEnum
+
   
-  Enums
-  
-enum OneEnum
+  
+
+  
+
+  Members
+
+  
+  
+
+  Records
+
+  
+  
+
+  Functions
+
+
+  
+
+  OneFunction
+
+  
+
+  
+  
+
+  Enums
+
+
+  
+
+  OneEnum
+
+  
+
+  
+
   
-
+
+
+  )raw" +
+ ClangDocVersion + R"raw(
+
 )raw";
 
   EXPECT_EQ(Expected, Actual.str());
@@ -270,17 +293,25 @@
 
 
 
-
-
-  f
-  
-float
- f(
-int
- P)
-  
-  Defined at line 10 of file dir/test.cpp
-

[PATCH] D66353: [clang-doc] Redesign of generated HTML files

2019-08-16 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 215624.
DiegoAstiazaran added a comment.

Run clang-format


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66353/new/

https://reviews.llvm.org/D66353

Files:
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/Representation.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/assets/clang-doc-default-stylesheet.css
  clang-tools-extra/clang-doc/assets/index.js
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/docs/clang-doc.rst
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -25,7 +25,8 @@
 ClangDocContext
 getClangDocContext(std::vector UserStylesheets = {},
StringRef RepositoryUrl = "") {
-  ClangDocContext CDCtx{{}, {}, {}, {}, RepositoryUrl, UserStylesheets, {}};
+  ClangDocContext CDCtx{
+  {}, "test-project", {}, {}, {}, RepositoryUrl, UserStylesheets, {}};
   CDCtx.UserStylesheets.insert(
   CDCtx.UserStylesheets.begin(),
   "../share/clang/clang-doc-default-stylesheet.css");
@@ -61,67 +62,75 @@
 
 
 
-
-
-  
-
-  Namespaces
-
-  
-  
-
-  Records
-
-  
-  
-
-  Functions
-
+test-project
+
+  
+  
+namespace Namespace
+Namespaces
 
   
-
-  OneFunction
-
+ChildNamespace
   
 
-  
-  
-
-  Enums
-
+Records
 
   
-
-  OneEnum
-
+ChildStruct
   
 
-  
-
-
-  namespace Namespace
-  Namespaces
-  
-
-  ChildNamespace
-
-  
-  Records
-  
-
-  ChildStruct
-
-  
-  Functions
-  
-OneFunction
-OneFunction()
+Functions
+
+  OneFunction
+  OneFunction()
+
+Enums
+
+  enum OneEnum
+
   
-  Enums
-  
-enum OneEnum
+  
+
+  
+
+  Namespaces
+
+  
+  
+
+  Records
+
+  
+  
+
+  Functions
+
+
+  
+
+  OneFunction
+
+  
+
+  
+  
+
+  Enums
+
+
+  
+
+  OneEnum
+
+  
+
+  
+
   
-
+
+
+  clang-doc version unknown
+
 )raw";
 
   EXPECT_EQ(Expected, Actual.str());
@@ -162,80 +171,88 @@
 class r
 
 
-
-
-  
-
-  Members
-
-  
-  
-
-  Records
-
-  
-  
-
-  Functions
-
+test-project
+
+  
+  
+class r
+
+  Defined at line 
+  http://www.repository.com/dir/test.cpp#10;>10
+   of file 
+  http://www.repository.com/dir/test.cpp;>test.cpp
+
+
+  Inherits from 
+  F
+  , G
+
+Members
 
   
-
-  OneFunction
-
+private 
+int
+ X
   
 
-  
-  
-
-  Enums
-
+Records
 
   
-
-  OneEnum
-
+ChildStruct
   
 
-  
-
-
-  class r
-  
-Defined at line 
-http://www.repository.com/dir/test.cpp#10;>10
- of file 
-http://www.repository.com/dir/test.cpp;>test.cpp
-  
-  
-Inherits from 
-F
-, G
-  
-  Members
-  
-
-  private 
-  int
-   X
-
-  
-  Records
-  
-
-  ChildStruct
-
-  
-  Functions
-  
-OneFunction
-public OneFunction()
+Functions
+
+  OneFunction
+  public OneFunction()
+
+Enums
+
+  enum OneEnum
+
   
-  Enums
-  
-enum OneEnum
+  
+
+  
+
+  Members
+
+  
+  
+
+  Records
+
+  
+  
+
+  Functions
+
+
+  
+
+  OneFunction
+
+  
+
+  
+  
+
+  Enums
+
+
+  
+
+  OneEnum
+
+  
+
+  
+
   
-
+
+
+  clang-doc version unknown
+
 )raw";
 
   EXPECT_EQ(Expected, Actual.str());
@@ -270,17 +287,24 @@
 
 
 
-
-
-  f
-  
-float
- f(
-int
- P)
-  
-  Defined at line 10 of file dir/test.cpp
-
+test-project
+
+  
+  
+f
+
+  float
+   f(
+  int
+   P)
+
+Defined at line 10 of file dir/test.cpp
+  
+  
+
+
+  clang-doc version unknown
+
 )raw";
 
   EXPECT_EQ(Expected, Actual.str());
@@ -309,19 +333,26 @@
 
 
 
-
-
-  enum class e
-  
-X
-  
-  
-Defined at line 
-https://www.repository.com/test.cpp#10;>10
- of file 
-https://www.repository.com/test.cpp;>test.cpp
-  
-
+test-project
+
+  
+  
+enum class e
+
+  X
+
+
+  Defined at 

[PATCH] D66298: [clang-doc] Fix records in global namespace

2019-08-16 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL369123: [clang-doc] Fix records in global namespace 
(authored by DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66298?vs=215537=215618#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66298/new/

https://reviews.llvm.org/D66298

Files:
  clang-tools-extra/trunk/clang-doc/Serialize.cpp
  clang-tools-extra/trunk/test/clang-doc/single-file-public.cpp
  clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp

Index: clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp
@@ -137,7 +137,9 @@
10, /*Public=*/false, Infos);
 
   RecordInfo *E = InfoAsRecord(Infos[0].get());
-  RecordInfo ExpectedE(EmptySID, "E");
+  RecordInfo ExpectedE(EmptySID, /*Name=*/"E", /*Path=*/"GlobalNamespace");
+  ExpectedE.Namespace.emplace_back(EmptySID, "GlobalNamespace",
+   InfoType::IT_namespace);
   ExpectedE.TagType = TagTypeKind::TTK_Class;
   ExpectedE.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
   CheckRecordInfo(, E);
@@ -150,6 +152,8 @@
   EConstructor.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
   EConstructor.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
   EConstructor.Namespace.emplace_back(EmptySID, "E", InfoType::IT_record);
+  EConstructor.Namespace.emplace_back(EmptySID, "GlobalNamespace",
+  InfoType::IT_namespace);
   EConstructor.Access = AccessSpecifier::AS_public;
   EConstructor.IsMethod = true;
   ExpectedRecordWithEConstructor.ChildFunctions.emplace_back(
@@ -164,13 +168,17 @@
   Method.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
   Method.Loc.emplace_back(0, llvm::SmallString<16>{"test.cpp"});
   Method.Namespace.emplace_back(EmptySID, "E", InfoType::IT_record);
+  Method.Namespace.emplace_back(EmptySID, "GlobalNamespace",
+InfoType::IT_namespace);
   Method.Access = AccessSpecifier::AS_protected;
   Method.IsMethod = true;
   ExpectedRecordWithMethod.ChildFunctions.emplace_back(std::move(Method));
   CheckRecordInfo(, RecordWithMethod);
 
   RecordInfo *F = InfoAsRecord(Infos[4].get());
-  RecordInfo ExpectedF(EmptySID, "F");
+  RecordInfo ExpectedF(EmptySID, /*Name=*/"F", /*Path=*/"GlobalNamespace");
+  ExpectedF.Namespace.emplace_back(EmptySID, "GlobalNamespace",
+   InfoType::IT_namespace);
   ExpectedF.TagType = TagTypeKind::TTK_Struct;
   ExpectedF.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
   CheckRecordInfo(, F);
@@ -183,6 +191,8 @@
   TemplateMethod.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
   TemplateMethod.Loc.emplace_back(0, llvm::SmallString<16>{"test.cpp"});
   TemplateMethod.Namespace.emplace_back(EmptySID, "F", InfoType::IT_record);
+  TemplateMethod.Namespace.emplace_back(EmptySID, "GlobalNamespace",
+InfoType::IT_namespace);
   TemplateMethod.Access = AccessSpecifier::AS_public;
   TemplateMethod.IsMethod = true;
   ExpectedRecordWithTemplateMethod.ChildFunctions.emplace_back(
@@ -201,6 +211,8 @@
  llvm::SmallString<16>{"test.cpp"});
   SpecializedTemplateMethod.Namespace.emplace_back(EmptySID, "F",
InfoType::IT_record);
+  SpecializedTemplateMethod.Namespace.emplace_back(EmptySID, "GlobalNamespace",
+   InfoType::IT_namespace);
   SpecializedTemplateMethod.Access = AccessSpecifier::AS_public;
   SpecializedTemplateMethod.IsMethod = true;
   ExpectedTemplatedRecord.ChildFunctions.emplace_back(
@@ -208,7 +220,9 @@
   CheckRecordInfo(, TemplatedRecord);
 
   RecordInfo *G = InfoAsRecord(Infos[8].get());
-  RecordInfo ExpectedG(EmptySID, "G");
+  RecordInfo ExpectedG(EmptySID, /*Name=*/"G", /*Path=*/"GlobalNamespace");
+  ExpectedG.Namespace.emplace_back(EmptySID, "GlobalNamespace",
+   InfoType::IT_namespace);
   ExpectedG.TagType = TagTypeKind::TTK_Struct;
   ExpectedG.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
   ExpectedG.IsTypeDef = true;
@@ -248,7 +262,9 @@
   ExtractInfosFromCode("class E;", 2, /*Public=*/false, Infos);
 
   RecordInfo *E = InfoAsRecord(Infos[0].get());
-  RecordInfo ExpectedE(EmptySID, "E");
+  RecordInfo ExpectedE(EmptySID, /*Name=*/"E", /*Path=*/"GlobalNamespace");
+  ExpectedE.Namespace.emplace_back(EmptySID, "GlobalNamespace",
+   InfoType::IT_namespace);
   ExpectedE.TagType = TagTypeKind::TTK_Class;
   

[PATCH] D66298: [clang-doc] Fix records in global namespace

2019-08-15 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 215537.
DiegoAstiazaran marked 2 inline comments as done.
DiegoAstiazaran added a comment.

Fix tests that were going to fail in Windows.
Fix tests broken after rebasing.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66298/new/

https://reviews.llvm.org/D66298

Files:
  clang-tools-extra/clang-doc/Serialize.cpp
  clang-tools-extra/test/clang-doc/single-file-public.cpp
  clang-tools-extra/unittests/clang-doc/SerializeTest.cpp

Index: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -137,7 +137,9 @@
10, /*Public=*/false, Infos);
 
   RecordInfo *E = InfoAsRecord(Infos[0].get());
-  RecordInfo ExpectedE(EmptySID, "E");
+  RecordInfo ExpectedE(EmptySID, /*Name=*/"E", /*Path=*/"GlobalNamespace");
+  ExpectedE.Namespace.emplace_back(EmptySID, "GlobalNamespace",
+   InfoType::IT_namespace);
   ExpectedE.TagType = TagTypeKind::TTK_Class;
   ExpectedE.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
   CheckRecordInfo(, E);
@@ -150,6 +152,8 @@
   EConstructor.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
   EConstructor.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
   EConstructor.Namespace.emplace_back(EmptySID, "E", InfoType::IT_record);
+  EConstructor.Namespace.emplace_back(EmptySID, "GlobalNamespace",
+  InfoType::IT_namespace);
   EConstructor.Access = AccessSpecifier::AS_public;
   EConstructor.IsMethod = true;
   ExpectedRecordWithEConstructor.ChildFunctions.emplace_back(
@@ -164,13 +168,17 @@
   Method.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
   Method.Loc.emplace_back(0, llvm::SmallString<16>{"test.cpp"});
   Method.Namespace.emplace_back(EmptySID, "E", InfoType::IT_record);
+  Method.Namespace.emplace_back(EmptySID, "GlobalNamespace",
+InfoType::IT_namespace);
   Method.Access = AccessSpecifier::AS_protected;
   Method.IsMethod = true;
   ExpectedRecordWithMethod.ChildFunctions.emplace_back(std::move(Method));
   CheckRecordInfo(, RecordWithMethod);
 
   RecordInfo *F = InfoAsRecord(Infos[4].get());
-  RecordInfo ExpectedF(EmptySID, "F");
+  RecordInfo ExpectedF(EmptySID, /*Name=*/"F", /*Path=*/"GlobalNamespace");
+  ExpectedF.Namespace.emplace_back(EmptySID, "GlobalNamespace",
+   InfoType::IT_namespace);
   ExpectedF.TagType = TagTypeKind::TTK_Struct;
   ExpectedF.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
   CheckRecordInfo(, F);
@@ -183,6 +191,8 @@
   TemplateMethod.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
   TemplateMethod.Loc.emplace_back(0, llvm::SmallString<16>{"test.cpp"});
   TemplateMethod.Namespace.emplace_back(EmptySID, "F", InfoType::IT_record);
+  TemplateMethod.Namespace.emplace_back(EmptySID, "GlobalNamespace",
+InfoType::IT_namespace);
   TemplateMethod.Access = AccessSpecifier::AS_public;
   TemplateMethod.IsMethod = true;
   ExpectedRecordWithTemplateMethod.ChildFunctions.emplace_back(
@@ -201,6 +211,8 @@
  llvm::SmallString<16>{"test.cpp"});
   SpecializedTemplateMethod.Namespace.emplace_back(EmptySID, "F",
InfoType::IT_record);
+  SpecializedTemplateMethod.Namespace.emplace_back(EmptySID, "GlobalNamespace",
+   InfoType::IT_namespace);
   SpecializedTemplateMethod.Access = AccessSpecifier::AS_public;
   SpecializedTemplateMethod.IsMethod = true;
   ExpectedTemplatedRecord.ChildFunctions.emplace_back(
@@ -208,7 +220,9 @@
   CheckRecordInfo(, TemplatedRecord);
 
   RecordInfo *G = InfoAsRecord(Infos[8].get());
-  RecordInfo ExpectedG(EmptySID, "G");
+  RecordInfo ExpectedG(EmptySID, /*Name=*/"G", /*Path=*/"GlobalNamespace");
+  ExpectedG.Namespace.emplace_back(EmptySID, "GlobalNamespace",
+   InfoType::IT_namespace);
   ExpectedG.TagType = TagTypeKind::TTK_Struct;
   ExpectedG.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
   ExpectedG.IsTypeDef = true;
@@ -248,7 +262,9 @@
   ExtractInfosFromCode("class E;", 2, /*Public=*/false, Infos);
 
   RecordInfo *E = InfoAsRecord(Infos[0].get());
-  RecordInfo ExpectedE(EmptySID, "E");
+  RecordInfo ExpectedE(EmptySID, /*Name=*/"E", /*Path=*/"GlobalNamespace");
+  ExpectedE.Namespace.emplace_back(EmptySID, "GlobalNamespace",
+   InfoType::IT_namespace);
   ExpectedE.TagType = TagTypeKind::TTK_Class;
   ExpectedE.Loc.emplace_back(0, llvm::SmallString<16>{"test.cpp"});
   CheckRecordInfo(, E);
@@ -259,7 +275,9 @@
   ExtractInfosFromCode("struct E { int I; };", 2, /*Public=*/false, Infos);
 
   

[PATCH] D66238: [clang-doc] Serialize inherited attributes and methods

2019-08-15 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL369075: [clang-doc] Serialize inherited attributes and 
methods (authored by DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66238?vs=215506=215513#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66238/new/

https://reviews.llvm.org/D66238

Files:
  clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp
  clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
  clang-tools-extra/trunk/clang-doc/BitcodeWriter.h
  clang-tools-extra/trunk/clang-doc/Representation.cpp
  clang-tools-extra/trunk/clang-doc/Representation.h
  clang-tools-extra/trunk/clang-doc/Serialize.cpp
  clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/trunk/unittests/clang-doc/BitcodeTest.cpp
  clang-tools-extra/trunk/unittests/clang-doc/ClangDocTest.cpp
  clang-tools-extra/trunk/unittests/clang-doc/ClangDocTest.h
  clang-tools-extra/trunk/unittests/clang-doc/MergeTest.cpp
  clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp
  clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp

Index: clang-tools-extra/trunk/unittests/clang-doc/ClangDocTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/ClangDocTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/ClangDocTest.cpp
@@ -6,6 +6,7 @@
 //
 //===--===//
 
+#include "ClangDocTest.h"
 #include "Representation.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "gtest/gtest.h"
@@ -168,6 +169,10 @@
   for (size_t Idx = 0; Idx < Actual->VirtualParents.size(); ++Idx)
 CheckReference(Expected->VirtualParents[Idx], Actual->VirtualParents[Idx]);
 
+  ASSERT_EQ(Expected->Bases.size(), Actual->Bases.size());
+  for (size_t Idx = 0; Idx < Actual->Bases.size(); ++Idx)
+CheckBaseRecordInfo(>Bases[Idx], >Bases[Idx]);
+
   ASSERT_EQ(Expected->ChildRecords.size(), Actual->ChildRecords.size());
   for (size_t Idx = 0; Idx < Actual->ChildRecords.size(); ++Idx)
 CheckReference(Expected->ChildRecords[Idx], Actual->ChildRecords[Idx]);
@@ -182,6 +187,14 @@
 CheckEnumInfo(>ChildEnums[Idx], >ChildEnums[Idx]);
 }
 
+void CheckBaseRecordInfo(BaseRecordInfo *Expected, BaseRecordInfo *Actual) {
+  CheckRecordInfo(Expected, Actual);
+
+  EXPECT_EQ(Expected->IsVirtual, Actual->IsVirtual);
+  EXPECT_EQ(Expected->Access, Actual->Access);
+  EXPECT_EQ(Expected->IsParent, Actual->IsParent);
+}
+
 void CheckIndex(Index , Index ) {
   CheckReference(Expected, Actual);
   ASSERT_EQ(Expected.Children.size(), Actual.Children.size());
Index: clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -84,6 +84,12 @@
   I.Members.emplace_back("int", "path/to/int", "X",
  AccessSpecifier::AS_private);
   I.TagType = TagTypeKind::TTK_Class;
+  I.Bases.emplace_back(EmptySID, "F", "path/to/F", true,
+   AccessSpecifier::AS_public, true);
+  I.Bases.back().ChildFunctions.emplace_back();
+  I.Bases.back().ChildFunctions.back().Name = "InheritedFunctionOne";
+  I.Bases.back().Members.emplace_back("int", "path/to/int", "N",
+  AccessSpecifier::AS_private);
   // F is in the global namespace
   I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record, "");
   I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record,
@@ -123,6 +129,24 @@
   Path:'path/to/int'
 Name:'X'
 Access:  Private
+Bases:
+  - USR: ''
+Name:'F'
+Path:'path/to/F'
+Members:
+  - Type:
+  Name:'int'
+  Path:'path/to/int'
+Name:'N'
+Access:  Private
+ChildFunctions:
+  - USR: ''
+Name:'InheritedFunctionOne'
+ReturnType:  {}
+Access:  Public
+IsVirtual:   true
+Access:  Public
+IsParent:true
 Parents:
   - Type:Record
 Name:'F'
Index: clang-tools-extra/trunk/unittests/clang-doc/BitcodeTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/BitcodeTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/BitcodeTest.cpp
@@ -81,6 +81,10 @@
   I.Members.emplace_back("int", "X", AccessSpecifier::AS_private);
   I.TagType = TagTypeKind::TTK_Class;
   I.IsTypeDef = true;
+  I.Bases.emplace_back(EmptySID, "F", 

[PATCH] D66238: [clang-doc] Serialize inherited attributes and methods

2019-08-15 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 215506.
DiegoAstiazaran added a comment.

Rebase to master


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66238/new/

https://reviews.llvm.org/D66238

Files:
  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/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/MergeTest.cpp
  clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
  clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -84,6 +84,12 @@
   I.Members.emplace_back("int", "path/to/int", "X",
  AccessSpecifier::AS_private);
   I.TagType = TagTypeKind::TTK_Class;
+  I.Bases.emplace_back(EmptySID, "F", "path/to/F", true,
+   AccessSpecifier::AS_public, true);
+  I.Bases.back().ChildFunctions.emplace_back();
+  I.Bases.back().ChildFunctions.back().Name = "InheritedFunctionOne";
+  I.Bases.back().Members.emplace_back("int", "path/to/int", "N",
+  AccessSpecifier::AS_private);
   // F is in the global namespace
   I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record, "");
   I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record,
@@ -123,6 +129,24 @@
   Path:'path/to/int'
 Name:'X'
 Access:  Private
+Bases:
+  - USR: ''
+Name:'F'
+Path:'path/to/F'
+Members:
+  - Type:
+  Name:'int'
+  Path:'path/to/int'
+Name:'N'
+Access:  Private
+ChildFunctions:
+  - USR: ''
+Name:'InheritedFunctionOne'
+ReturnType:  {}
+Access:  Public
+IsVirtual:   true
+Access:  Public
+IsParent:true
 Parents:
   - Type:Record
 Name:'F'
Index: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -321,15 +321,16 @@
   CheckNamespaceInfo(, BWithFunction);
 }
 
-TEST(SerializeTest, ) {
+TEST(SerializeTest, emitInheritedRecordInfo) {
   EmittedInfoList Infos;
-  ExtractInfosFromCode(R"raw(class F {};
-class G {} ;
+  ExtractInfosFromCode(R"raw(class F { protected: void set(int N); };
+class G { public: int get() { return 1; } protected: int I; };
 class E : public F, virtual private G {};
+class H : private E {};
 template 
-class H {} ;
-class I : public H {} ;)raw",
-   10, /*Public=*/false, Infos);
+class I {} ;
+class J : public I {} ;)raw",
+   14, /*Public=*/false, Infos);
 
   RecordInfo *F = InfoAsRecord(Infos[0].get());
   RecordInfo ExpectedF(EmptySID, "F");
@@ -337,32 +338,91 @@
   ExpectedF.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
   CheckRecordInfo(, F);
 
-  RecordInfo *G = InfoAsRecord(Infos[2].get());
+  RecordInfo *G = InfoAsRecord(Infos[3].get());
   RecordInfo ExpectedG(EmptySID, "G");
   ExpectedG.TagType = TagTypeKind::TTK_Class;
   ExpectedG.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
+  ExpectedG.Members.emplace_back("int", "I", AccessSpecifier::AS_protected);
   CheckRecordInfo(, G);
 
-  RecordInfo *E = InfoAsRecord(Infos[4].get());
+  RecordInfo *E = InfoAsRecord(Infos[6].get());
   RecordInfo ExpectedE(EmptySID, "E");
   ExpectedE.Parents.emplace_back(EmptySID, "F", InfoType::IT_record);
   ExpectedE.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record);
+  ExpectedE.Bases.emplace_back(EmptySID, "F", "", false,
+   AccessSpecifier::AS_public, true);
+  FunctionInfo FunctionSet;
+  FunctionSet.Name = "set";
+  FunctionSet.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
+  FunctionSet.Loc.emplace_back();
+  FunctionSet.Params.emplace_back("int", "N");
+  FunctionSet.Namespace.emplace_back(EmptySID, "F", InfoType::IT_record);
+  FunctionSet.Access = AccessSpecifier::AS_protected;
+  FunctionSet.IsMethod = true;
+  ExpectedE.Bases.back().ChildFunctions.emplace_back(std::move(FunctionSet));
+  ExpectedE.Bases.emplace_back(EmptySID, "G", 

[PATCH] D66299: [clang-doc] Sort index elements case insensitive

2019-08-15 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL369068: [clang-doc] Sort index elements case insensitive 
(authored by DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66299?vs=215407=215500#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66299/new/

https://reviews.llvm.org/D66299

Files:
  clang-tools-extra/trunk/clang-doc/Representation.cpp
  clang-tools-extra/trunk/clang-doc/Representation.h
  clang-tools-extra/trunk/unittests/clang-doc/GeneratorTest.cpp


Index: clang-tools-extra/trunk/clang-doc/Representation.h
===
--- clang-tools-extra/trunk/clang-doc/Representation.h
+++ clang-tools-extra/trunk/clang-doc/Representation.h
@@ -292,7 +292,8 @@
   SymbolInfo(InfoType IT) : Info(IT) {}
   SymbolInfo(InfoType IT, SymbolID USR) : Info(IT, USR) {}
   SymbolInfo(InfoType IT, SymbolID USR, StringRef Name) : Info(IT, USR, Name) 
{}
-  SymbolInfo(InfoType IT, SymbolID USR, StringRef Name, StringRef Path) : 
Info(IT, USR, Name, Path) {}
+  SymbolInfo(InfoType IT, SymbolID USR, StringRef Name, StringRef Path)
+  : Info(IT, USR, Name, Path) {}
 
   void merge(SymbolInfo &);
 
@@ -368,13 +369,14 @@
 
 struct Index : public Reference {
   Index() = default;
+  Index(StringRef Name) : Reference(Name) {}
   Index(StringRef Name, StringRef JumpToSection)
   : Reference(Name), JumpToSection(JumpToSection) {}
   Index(SymbolID USR, StringRef Name, InfoType IT, StringRef Path)
   : Reference(USR, Name, IT, Path) {}
   // This is used to look for a USR in a vector of Indexes using std::find
   bool operator==(const SymbolID ) const { return USR == Other; }
-  bool operator<(const Index ) const { return Name < Other.Name; }
+  bool operator<(const Index ) const;
 
   llvm::Optional> JumpToSection;
   std::vector Children;
Index: clang-tools-extra/trunk/clang-doc/Representation.cpp
===
--- clang-tools-extra/trunk/clang-doc/Representation.cpp
+++ clang-tools-extra/trunk/clang-doc/Representation.cpp
@@ -245,6 +245,26 @@
   return llvm::SmallString<16>("");
 }
 
+// Order is based on the Name attribute: case insensitive order
+bool Index::operator<(const Index ) const {
+  // Loop through each character of both strings
+  for (unsigned I = 0; I < Name.size() && I < Other.Name.size(); ++I) {
+// Compare them after converting both to lower case
+int D = tolower(Name[I]) - tolower(Other.Name[I]);
+if (D == 0)
+  continue;
+return D < 0;
+  }
+  // If both strings have the size it means they would be equal if changed to
+  // lower case. In here, lower case will be smaller than upper case
+  // Example: string < stRing = true
+  // This is the opposite of how operator < handles strings
+  if (Name.size() == Other.Name.size())
+return Name > Other.Name;
+  // If they are not the same size; the shorter string is smaller
+  return Name.size() < Other.Name.size();
+}
+
 void Index::sort() {
   std::sort(Children.begin(), Children.end());
   for (auto  : Children)
Index: clang-tools-extra/trunk/unittests/clang-doc/GeneratorTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/GeneratorTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/GeneratorTest.cpp
@@ -70,5 +70,24 @@
   CheckIndex(ExpectedIdx, Idx);
 }
 
+TEST(GeneratorTest, sortIndex) {
+  Index Idx;
+  Idx.Children.emplace_back("b");
+  Idx.Children.emplace_back("aA");
+  Idx.Children.emplace_back("aa");
+  Idx.Children.emplace_back("A");
+  Idx.Children.emplace_back("a");
+  Idx.sort();
+
+  Index ExpectedIdx;
+  ExpectedIdx.Children.emplace_back("a");
+  ExpectedIdx.Children.emplace_back("A");
+  ExpectedIdx.Children.emplace_back("aa");
+  ExpectedIdx.Children.emplace_back("aA");
+  ExpectedIdx.Children.emplace_back("b");
+
+  CheckIndex(ExpectedIdx, Idx);
+}
+
 } // namespace doc
 } // namespace clang


Index: clang-tools-extra/trunk/clang-doc/Representation.h
===
--- clang-tools-extra/trunk/clang-doc/Representation.h
+++ clang-tools-extra/trunk/clang-doc/Representation.h
@@ -292,7 +292,8 @@
   SymbolInfo(InfoType IT) : Info(IT) {}
   SymbolInfo(InfoType IT, SymbolID USR) : Info(IT, USR) {}
   SymbolInfo(InfoType IT, SymbolID USR, StringRef Name) : Info(IT, USR, Name) {}
-  SymbolInfo(InfoType IT, SymbolID USR, StringRef Name, StringRef Path) : Info(IT, USR, Name, Path) {}
+  SymbolInfo(InfoType IT, SymbolID USR, StringRef Name, StringRef Path)
+  : Info(IT, USR, Name, Path) {}
 
   void merge(SymbolInfo &);
 
@@ -368,13 +369,14 @@
 
 struct Index : public Reference {
   Index() = default;
+  Index(StringRef Name) : Reference(Name) {}
   Index(StringRef Name, StringRef JumpToSection)
 

[PATCH] D66268: [clang-doc] Fix use of source-root flag

2019-08-15 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL369065: [clang-doc] Fix use of source-root flag (authored by 
DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66268?vs=215302=215497#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66268/new/

https://reviews.llvm.org/D66268

Files:
  clang-tools-extra/trunk/clang-doc/Representation.cpp
  clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp


Index: clang-tools-extra/trunk/clang-doc/Representation.cpp
===
--- clang-tools-extra/trunk/clang-doc/Representation.cpp
+++ clang-tools-extra/trunk/clang-doc/Representation.cpp
@@ -257,8 +257,12 @@
  std::vector UserStylesheets,
  std::vector JsScripts)
 : ECtx(ECtx), PublicOnly(PublicOnly), OutDirectory(OutDirectory),
-  SourceRoot(SourceRoot), UserStylesheets(UserStylesheets),
-  JsScripts(JsScripts) {
+  UserStylesheets(UserStylesheets), JsScripts(JsScripts) {
+  llvm::SmallString<128> SourceRootDir(SourceRoot);
+  if (SourceRoot.empty())
+// If no SourceRoot was provided the current path is used as the default
+llvm::sys::fs::current_path(SourceRootDir);
+  this->SourceRoot = SourceRootDir.str();
   if (!RepositoryUrl.empty()) {
 this->RepositoryUrl = RepositoryUrl;
 if (!RepositoryUrl.empty() && RepositoryUrl.find("http://;) != 0 &&
Index: clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
@@ -203,17 +203,11 @@
   tooling::ArgumentInsertPosition::END),
 ArgAdjuster);
 
-  llvm::SmallString<128> SourceRootDir;
-  // Check if the --source-root flag has a value
-  if (SourceRoot.empty())
-// If it's empty the current path is used as the default
-llvm::sys::fs::current_path(SourceRootDir);
-
   clang::doc::ClangDocContext CDCtx = {
   Exec->get()->getExecutionContext(),
   PublicOnly,
   OutDirectory,
-  SourceRootDir.str(),
+  SourceRoot,
   RepositoryUrl,
   {UserStylesheets.begin(), UserStylesheets.end()},
   {"index.js", "index_json.js"}};


Index: clang-tools-extra/trunk/clang-doc/Representation.cpp
===
--- clang-tools-extra/trunk/clang-doc/Representation.cpp
+++ clang-tools-extra/trunk/clang-doc/Representation.cpp
@@ -257,8 +257,12 @@
  std::vector UserStylesheets,
  std::vector JsScripts)
 : ECtx(ECtx), PublicOnly(PublicOnly), OutDirectory(OutDirectory),
-  SourceRoot(SourceRoot), UserStylesheets(UserStylesheets),
-  JsScripts(JsScripts) {
+  UserStylesheets(UserStylesheets), JsScripts(JsScripts) {
+  llvm::SmallString<128> SourceRootDir(SourceRoot);
+  if (SourceRoot.empty())
+// If no SourceRoot was provided the current path is used as the default
+llvm::sys::fs::current_path(SourceRootDir);
+  this->SourceRoot = SourceRootDir.str();
   if (!RepositoryUrl.empty()) {
 this->RepositoryUrl = RepositoryUrl;
 if (!RepositoryUrl.empty() && RepositoryUrl.find("http://;) != 0 &&
Index: clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
@@ -203,17 +203,11 @@
   tooling::ArgumentInsertPosition::END),
 ArgAdjuster);
 
-  llvm::SmallString<128> SourceRootDir;
-  // Check if the --source-root flag has a value
-  if (SourceRoot.empty())
-// If it's empty the current path is used as the default
-llvm::sys::fs::current_path(SourceRootDir);
-
   clang::doc::ClangDocContext CDCtx = {
   Exec->get()->getExecutionContext(),
   PublicOnly,
   OutDirectory,
-  SourceRootDir.str(),
+  SourceRoot,
   RepositoryUrl,
   {UserStylesheets.begin(), UserStylesheets.end()},
   {"index.js", "index_json.js"}};
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D66151: [clang-doc] Fix bitcode writer

2019-08-15 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL369063: [clang-doc] Fix bitcode writer for access specifiers 
(authored by DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66151?vs=215193=215491#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66151/new/

https://reviews.llvm.org/D66151

Files:
  clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
  clang-tools-extra/trunk/clang-doc/Representation.h
  clang-tools-extra/trunk/clang-doc/Serialize.cpp
  clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/trunk/test/clang-doc/single-file-public.cpp
  clang-tools-extra/trunk/unittests/clang-doc/BitcodeTest.cpp
  clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
  clang-tools-extra/trunk/unittests/clang-doc/MDGeneratorTest.cpp
  clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp
  clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp

Index: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -43,6 +43,7 @@
   I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record,
   "Namespace");
   I.ChildFunctions.emplace_back();
+  I.ChildFunctions.back().Access = AccessSpecifier::AS_none;
   I.ChildFunctions.back().Name = "OneFunction";
   I.ChildEnums.emplace_back();
   I.ChildEnums.back().Name = "OneEnum";
@@ -228,7 +229,7 @@
   Functions
   
 OneFunction
-OneFunction()
+public OneFunction()
   
   Enums
   
@@ -248,6 +249,8 @@
   I.DefLoc = Location(10, llvm::SmallString<16>{"dir/test.cpp"}, false);
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
+  I.Access = AccessSpecifier::AS_none;
+
   SmallString<16> PathTo;
   llvm::sys::path::native("path/to", PathTo);
   I.ReturnType = TypeInfo(EmptySID, "float", InfoType::IT_default, PathTo);
@@ -331,6 +334,7 @@
   I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
   I.Params.emplace_back("int", "I");
   I.Params.emplace_back("int", "J");
+  I.Access = AccessSpecifier::AS_none;
 
   CommentInfo Top;
   Top.Kind = "FullComment";
Index: clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -34,6 +34,7 @@
   "path/to/A/Namespace");
   I.ChildFunctions.emplace_back();
   I.ChildFunctions.back().Name = "OneFunction";
+  I.ChildFunctions.back().Access = AccessSpecifier::AS_none;
   I.ChildEnums.emplace_back();
   I.ChildEnums.back().Name = "OneEnum";
 
@@ -138,6 +139,7 @@
   - USR: ''
 Name:'OneFunction'
 ReturnType:  {}
+Access:  Public
 ChildEnums:
   - USR: ''
 Name:'OneEnum'
@@ -154,6 +156,8 @@
   I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
+  I.Access = AccessSpecifier::AS_none;
+
   I.ReturnType =
   TypeInfo(EmptySID, "void", InfoType::IT_default, "path/to/void");
   I.Params.emplace_back("int", "path/to/int", "P");
@@ -242,6 +246,7 @@
   I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
   I.Params.emplace_back("int", "I");
   I.Params.emplace_back("int", "J");
+  I.Access = AccessSpecifier::AS_none;
 
   CommentInfo Top;
   Top.Kind = "FullComment";
Index: clang-tools-extra/trunk/unittests/clang-doc/BitcodeTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/BitcodeTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/BitcodeTest.cpp
@@ -106,6 +106,8 @@
   I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
   I.Params.emplace_back("int", "P");
 
+  I.Access = AccessSpecifier::AS_none;
+
   std::string WriteResult = writeInfo();
   EXPECT_TRUE(WriteResult.size() > 0);
   std::vector> ReadResults = readInfo(WriteResult, 1);
@@ -126,8 +128,7 @@
   I.IsMethod = true;
   I.Parent = Reference(EmptySID, "Parent", InfoType::IT_record);
 
-  // TODO: fix access
-  // I.Access = AccessSpecifier::AS_private;
+  I.Access = AccessSpecifier::AS_public;
 
   std::string WriteResult = writeInfo();
   EXPECT_TRUE(WriteResult.size() > 0);
Index: clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp
+++ 

[PATCH] D66299: [clang-doc] Sort index elements case insensitive

2019-08-15 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran created this revision.
DiegoAstiazaran added reviewers: juliehockett, jakehehrlich.
DiegoAstiazaran added a project: clang-tools-extra.
Herald added a subscriber: arphaman.

Implement logic to compare the references of the index case insensitive.


https://reviews.llvm.org/D66299

Files:
  clang-tools-extra/clang-doc/Representation.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp


Index: clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp
@@ -70,5 +70,24 @@
   CheckIndex(ExpectedIdx, Idx);
 }
 
+TEST(GeneratorTest, sortIndex) {
+  Index Idx;
+  Idx.Children.emplace_back("b");
+  Idx.Children.emplace_back("aA");
+  Idx.Children.emplace_back("aa");
+  Idx.Children.emplace_back("A");
+  Idx.Children.emplace_back("a");
+  Idx.sort();
+
+  Index ExpectedIdx;
+  ExpectedIdx.Children.emplace_back("a");
+  ExpectedIdx.Children.emplace_back("A");
+  ExpectedIdx.Children.emplace_back("aa");
+  ExpectedIdx.Children.emplace_back("aA");
+  ExpectedIdx.Children.emplace_back("b");
+
+  CheckIndex(ExpectedIdx, Idx);
+}
+
 } // namespace doc
 } // namespace clang
Index: clang-tools-extra/clang-doc/Representation.h
===
--- clang-tools-extra/clang-doc/Representation.h
+++ clang-tools-extra/clang-doc/Representation.h
@@ -291,7 +291,8 @@
   SymbolInfo(InfoType IT) : Info(IT) {}
   SymbolInfo(InfoType IT, SymbolID USR) : Info(IT, USR) {}
   SymbolInfo(InfoType IT, SymbolID USR, StringRef Name) : Info(IT, USR, Name) 
{}
-  SymbolInfo(InfoType IT, SymbolID USR, StringRef Name, StringRef Path) : 
Info(IT, USR, Name, Path) {}
+  SymbolInfo(InfoType IT, SymbolID USR, StringRef Name, StringRef Path)
+  : Info(IT, USR, Name, Path) {}
 
   void merge(SymbolInfo &);
 
@@ -364,13 +365,14 @@
 
 struct Index : public Reference {
   Index() = default;
+  Index(StringRef Name) : Reference(Name) {}
   Index(StringRef Name, StringRef JumpToSection)
   : Reference(Name), JumpToSection(JumpToSection) {}
   Index(SymbolID USR, StringRef Name, InfoType IT, StringRef Path)
   : Reference(USR, Name, IT, Path) {}
   // This is used to look for a USR in a vector of Indexes using std::find
   bool operator==(const SymbolID ) const { return USR == Other; }
-  bool operator<(const Index ) const { return Name < Other.Name; }
+  bool operator<(const Index ) const;
 
   llvm::Optional> JumpToSection;
   std::vector Children;
Index: clang-tools-extra/clang-doc/Representation.cpp
===
--- clang-tools-extra/clang-doc/Representation.cpp
+++ clang-tools-extra/clang-doc/Representation.cpp
@@ -245,6 +245,26 @@
   return llvm::SmallString<16>("");
 }
 
+// Order is based on the Name attribute: case insensitive order
+bool Index::operator<(const Index ) const {
+  // Loop through each character of both strings
+  for (unsigned I = 0; I < Name.size() && I < Other.Name.size(); ++I) {
+// Compare them after converting both to lower case
+int D = tolower(Name[I]) - tolower(Other.Name[I]);
+if (D == 0)
+  continue;
+return D < 0;
+  }
+  // If both strings have the size it means they would be equal if changed to
+  // lower case. In here, lower case will be smaller than upper case
+  // Example: string < stRing = true
+  // This is the opposite of how operator < handles strings
+  if (Name.size() == Other.Name.size())
+return Name > Other.Name;
+  // If they are not the same size; the shorter string is smaller
+  return Name.size() < Other.Name.size();
+}
+
 void Index::sort() {
   std::sort(Children.begin(), Children.end());
   for (auto  : Children)


Index: clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp
@@ -70,5 +70,24 @@
   CheckIndex(ExpectedIdx, Idx);
 }
 
+TEST(GeneratorTest, sortIndex) {
+  Index Idx;
+  Idx.Children.emplace_back("b");
+  Idx.Children.emplace_back("aA");
+  Idx.Children.emplace_back("aa");
+  Idx.Children.emplace_back("A");
+  Idx.Children.emplace_back("a");
+  Idx.sort();
+
+  Index ExpectedIdx;
+  ExpectedIdx.Children.emplace_back("a");
+  ExpectedIdx.Children.emplace_back("A");
+  ExpectedIdx.Children.emplace_back("aa");
+  ExpectedIdx.Children.emplace_back("aA");
+  ExpectedIdx.Children.emplace_back("b");
+
+  CheckIndex(ExpectedIdx, Idx);
+}
+
 } // namespace doc
 } // namespace clang
Index: clang-tools-extra/clang-doc/Representation.h
===
--- clang-tools-extra/clang-doc/Representation.h
+++ clang-tools-extra/clang-doc/Representation.h
@@ -291,7 +291,8 @@
   

[PATCH] D66298: [clang-doc] Fix records in global namespace

2019-08-15 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran created this revision.
DiegoAstiazaran added reviewers: juliehockett, jakehehrlich.
DiegoAstiazaran added a project: clang-tools-extra.

When a Record is declared in the global namespace, clang-doc serializes it as a 
child of the global namespace, so the global namespace is now one if its parent 
namespaces. This namespace was not being included in the list of namespaces of 
the Info causing paths to be incorrect and the index rendered incorrectly.
Affected tests have been fixed.


https://reviews.llvm.org/D66298

Files:
  clang-tools-extra/clang-doc/Serialize.cpp
  clang-tools-extra/test/clang-doc/single-file-public.cpp
  clang-tools-extra/unittests/clang-doc/SerializeTest.cpp

Index: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -136,7 +136,9 @@
10, /*Public=*/false, Infos);
 
   RecordInfo *E = InfoAsRecord(Infos[0].get());
-  RecordInfo ExpectedE(EmptySID, "E");
+  RecordInfo ExpectedE(EmptySID, /*Name=*/"E", /*Path=*/"GlobalNamespace");
+  ExpectedE.Namespace.emplace_back(EmptySID, "GlobalNamespace",
+   InfoType::IT_namespace);
   ExpectedE.TagType = TagTypeKind::TTK_Class;
   ExpectedE.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
   CheckRecordInfo(, E);
@@ -149,6 +151,8 @@
   EConstructor.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
   EConstructor.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
   EConstructor.Namespace.emplace_back(EmptySID, "E", InfoType::IT_record);
+  EConstructor.Namespace.emplace_back(EmptySID, "GlobalNamespace",
+  InfoType::IT_namespace);
   EConstructor.Access = AccessSpecifier::AS_public;
   EConstructor.IsMethod = true;
   ExpectedRecordWithEConstructor.ChildFunctions.emplace_back(
@@ -163,13 +167,17 @@
   Method.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
   Method.Loc.emplace_back(0, llvm::SmallString<16>{"test.cpp"});
   Method.Namespace.emplace_back(EmptySID, "E", InfoType::IT_record);
+  Method.Namespace.emplace_back(EmptySID, "GlobalNamespace",
+InfoType::IT_namespace);
   Method.Access = AccessSpecifier::AS_protected;
   Method.IsMethod = true;
   ExpectedRecordWithMethod.ChildFunctions.emplace_back(std::move(Method));
   CheckRecordInfo(, RecordWithMethod);
 
   RecordInfo *F = InfoAsRecord(Infos[4].get());
-  RecordInfo ExpectedF(EmptySID, "F");
+  RecordInfo ExpectedF(EmptySID, /*Name=*/"F", /*Path=*/"GlobalNamespace");
+  ExpectedF.Namespace.emplace_back(EmptySID, "GlobalNamespace",
+   InfoType::IT_namespace);
   ExpectedF.TagType = TagTypeKind::TTK_Struct;
   ExpectedF.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
   CheckRecordInfo(, F);
@@ -182,6 +190,8 @@
   TemplateMethod.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
   TemplateMethod.Loc.emplace_back(0, llvm::SmallString<16>{"test.cpp"});
   TemplateMethod.Namespace.emplace_back(EmptySID, "F", InfoType::IT_record);
+  TemplateMethod.Namespace.emplace_back(EmptySID, "GlobalNamespace",
+InfoType::IT_namespace);
   TemplateMethod.Access = AccessSpecifier::AS_public;
   TemplateMethod.IsMethod = true;
   ExpectedRecordWithTemplateMethod.ChildFunctions.emplace_back(
@@ -200,6 +210,8 @@
  llvm::SmallString<16>{"test.cpp"});
   SpecializedTemplateMethod.Namespace.emplace_back(EmptySID, "F",
InfoType::IT_record);
+  SpecializedTemplateMethod.Namespace.emplace_back(EmptySID, "GlobalNamespace",
+   InfoType::IT_namespace);
   SpecializedTemplateMethod.Access = AccessSpecifier::AS_public;
   SpecializedTemplateMethod.IsMethod = true;
   ExpectedTemplatedRecord.ChildFunctions.emplace_back(
@@ -207,7 +219,9 @@
   CheckRecordInfo(, TemplatedRecord);
 
   RecordInfo *G = InfoAsRecord(Infos[8].get());
-  RecordInfo ExpectedG(EmptySID, "G");
+  RecordInfo ExpectedG(EmptySID, /*Name=*/"G", /*Path=*/"GlobalNamespace");
+  ExpectedG.Namespace.emplace_back(EmptySID, "GlobalNamespace",
+   InfoType::IT_namespace);
   ExpectedG.TagType = TagTypeKind::TTK_Struct;
   ExpectedG.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
   ExpectedG.IsTypeDef = true;
@@ -247,7 +261,9 @@
   ExtractInfosFromCode("class E;", 2, /*Public=*/false, Infos);
 
   RecordInfo *E = InfoAsRecord(Infos[0].get());
-  RecordInfo ExpectedE(EmptySID, "E");
+  RecordInfo ExpectedE(EmptySID, /*Name=*/"E", /*Path=*/"GlobalNamespace");
+  ExpectedE.Namespace.emplace_back(EmptySID, "GlobalNamespace",
+   InfoType::IT_namespace);
   ExpectedE.TagType = 

[PATCH] D66238: [clang-doc] Serialize inherited attributes and methods

2019-08-14 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran added inline comments.



Comment at: clang-tools-extra/clang-doc/Serialize.cpp:436
+  if (const CXXRecordDecl *Base =
+  cast_or_null(Ty->getDecl()->getDefinition())) {
+bool IsVirtual = false;

juliehockett wrote:
> Will `getDecl()` always return a non-null pointer? In the normal case I'd 
> assume so, but the `cast_or_null` will only catch a null coming out of 
> `getDefinition()` or the cast, not `getDecl`, so just want to check.
I got this logic from 
https://clang.llvm.org/doxygen/CXXInheritance_8cpp_source.html#l00150 so it 
should probably work as you said, `getDecl()` always returns a non-null pointer.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66238/new/

https://reviews.llvm.org/D66238



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


[PATCH] D66238: [clang-doc] Serialize inherited attributes and methods

2019-08-14 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 215304.
DiegoAstiazaran marked 11 inline comments as done.
DiegoAstiazaran added a comment.

Increase version number of clang-doc bitcode.
Rename `documentInfo` function to `shouldSerializeInfo`.
In new `parseBases` a BaseRecordInfo object is created and then added to Bases 
of main RecordInfo.
Fix comments.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66238/new/

https://reviews.llvm.org/D66238

Files:
  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/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/MergeTest.cpp
  clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
  clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -84,6 +84,12 @@
   I.Members.emplace_back("int", "path/to/int", "X",
  AccessSpecifier::AS_private);
   I.TagType = TagTypeKind::TTK_Class;
+  I.Bases.emplace_back(EmptySID, "F", "path/to/F", true,
+   AccessSpecifier::AS_public, true);
+  I.Bases.back().ChildFunctions.emplace_back();
+  I.Bases.back().ChildFunctions.back().Name = "InheritedFunctionOne";
+  I.Bases.back().Members.emplace_back("int", "path/to/int", "N",
+  AccessSpecifier::AS_private);
   // F is in the global namespace
   I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record, "");
   I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record,
@@ -123,6 +129,24 @@
   Path:'path/to/int'
 Name:'X'
 Access:  Private
+Bases:
+  - USR: ''
+Name:'F'
+Path:'path/to/F'
+Members:
+  - Type:
+  Name:'int'
+  Path:'path/to/int'
+Name:'N'
+Access:  Private
+ChildFunctions:
+  - USR: ''
+Name:'InheritedFunctionOne'
+ReturnType:  {}
+Access:  Public
+IsVirtual:   true
+Access:  Public
+IsParent:true
 Parents:
   - Type:Record
 Name:'F'
Index: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -321,15 +321,16 @@
   CheckNamespaceInfo(, BWithFunction);
 }
 
-TEST(SerializeTest, ) {
+TEST(SerializeTest, emitInheritedRecordInfo) {
   EmittedInfoList Infos;
-  ExtractInfosFromCode(R"raw(class F {};
-class G {} ;
+  ExtractInfosFromCode(R"raw(class F { protected: void set(int N); };
+class G { public: int get() { return 1; } protected: int I; };
 class E : public F, virtual private G {};
+class H : private E {};
 template 
-class H {} ;
-class I : public H {} ;)raw",
-   10, /*Public=*/false, Infos);
+class I {} ;
+class J : public I {} ;)raw",
+   14, /*Public=*/false, Infos);
 
   RecordInfo *F = InfoAsRecord(Infos[0].get());
   RecordInfo ExpectedF(EmptySID, "F");
@@ -337,32 +338,91 @@
   ExpectedF.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
   CheckRecordInfo(, F);
 
-  RecordInfo *G = InfoAsRecord(Infos[2].get());
+  RecordInfo *G = InfoAsRecord(Infos[3].get());
   RecordInfo ExpectedG(EmptySID, "G");
   ExpectedG.TagType = TagTypeKind::TTK_Class;
   ExpectedG.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
+  ExpectedG.Members.emplace_back("int", "I", AccessSpecifier::AS_protected);
   CheckRecordInfo(, G);
 
-  RecordInfo *E = InfoAsRecord(Infos[4].get());
+  RecordInfo *E = InfoAsRecord(Infos[6].get());
   RecordInfo ExpectedE(EmptySID, "E");
   ExpectedE.Parents.emplace_back(EmptySID, "F", InfoType::IT_record);
   ExpectedE.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record);
+  ExpectedE.Bases.emplace_back(EmptySID, "F", "", false,
+   AccessSpecifier::AS_public, true);
+  FunctionInfo FunctionSet;
+  FunctionSet.Name = "set";
+  FunctionSet.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
+  FunctionSet.Loc.emplace_back();
+  FunctionSet.Params.emplace_back("int", "N");
+  

[PATCH] D66268: [clang-doc] Fix use of source-root flag

2019-08-14 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran created this revision.
DiegoAstiazaran added reviewers: jakehehrlich, juliehockett.
DiegoAstiazaran added a project: clang-tools-extra.
Herald added subscribers: kadircet, arphaman, ilya-biryukov.

The value, if any, of --source-root flag was not being used.
This has been fixed and the logic was moved to the ClangDocContext contructor.


https://reviews.llvm.org/D66268

Files:
  clang-tools-extra/clang-doc/Representation.cpp
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp


Index: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -203,17 +203,11 @@
   tooling::ArgumentInsertPosition::END),
 ArgAdjuster);
 
-  llvm::SmallString<128> SourceRootDir;
-  // Check if the --source-root flag has a value
-  if (SourceRoot.empty())
-// If it's empty the current path is used as the default
-llvm::sys::fs::current_path(SourceRootDir);
-
   clang::doc::ClangDocContext CDCtx = {
   Exec->get()->getExecutionContext(),
   PublicOnly,
   OutDirectory,
-  SourceRootDir.str(),
+  SourceRoot,
   RepositoryUrl,
   {UserStylesheets.begin(), UserStylesheets.end()},
   {"index.js", "index_json.js"}};
Index: clang-tools-extra/clang-doc/Representation.cpp
===
--- clang-tools-extra/clang-doc/Representation.cpp
+++ clang-tools-extra/clang-doc/Representation.cpp
@@ -257,8 +257,12 @@
  std::vector UserStylesheets,
  std::vector JsScripts)
 : ECtx(ECtx), PublicOnly(PublicOnly), OutDirectory(OutDirectory),
-  SourceRoot(SourceRoot), UserStylesheets(UserStylesheets),
-  JsScripts(JsScripts) {
+  UserStylesheets(UserStylesheets), JsScripts(JsScripts) {
+  llvm::SmallString<128> SourceRootDir(SourceRoot);
+  if (SourceRoot.empty())
+// If no SourceRoot was provided the current path is used as the default
+llvm::sys::fs::current_path(SourceRootDir);
+  this->SourceRoot = SourceRootDir.str();
   if (!RepositoryUrl.empty()) {
 this->RepositoryUrl = RepositoryUrl;
 if (!RepositoryUrl.empty() && RepositoryUrl.find("http://;) != 0 &&


Index: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -203,17 +203,11 @@
   tooling::ArgumentInsertPosition::END),
 ArgAdjuster);
 
-  llvm::SmallString<128> SourceRootDir;
-  // Check if the --source-root flag has a value
-  if (SourceRoot.empty())
-// If it's empty the current path is used as the default
-llvm::sys::fs::current_path(SourceRootDir);
-
   clang::doc::ClangDocContext CDCtx = {
   Exec->get()->getExecutionContext(),
   PublicOnly,
   OutDirectory,
-  SourceRootDir.str(),
+  SourceRoot,
   RepositoryUrl,
   {UserStylesheets.begin(), UserStylesheets.end()},
   {"index.js", "index_json.js"}};
Index: clang-tools-extra/clang-doc/Representation.cpp
===
--- clang-tools-extra/clang-doc/Representation.cpp
+++ clang-tools-extra/clang-doc/Representation.cpp
@@ -257,8 +257,12 @@
  std::vector UserStylesheets,
  std::vector JsScripts)
 : ECtx(ECtx), PublicOnly(PublicOnly), OutDirectory(OutDirectory),
-  SourceRoot(SourceRoot), UserStylesheets(UserStylesheets),
-  JsScripts(JsScripts) {
+  UserStylesheets(UserStylesheets), JsScripts(JsScripts) {
+  llvm::SmallString<128> SourceRootDir(SourceRoot);
+  if (SourceRoot.empty())
+// If no SourceRoot was provided the current path is used as the default
+llvm::sys::fs::current_path(SourceRootDir);
+  this->SourceRoot = SourceRootDir.str();
   if (!RepositoryUrl.empty()) {
 this->RepositoryUrl = RepositoryUrl;
 if (!RepositoryUrl.empty() && RepositoryUrl.find("http://;) != 0 &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D66124: [clang-doc] Add missing check in tests

2019-08-14 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL368912: [clang-doc] Add missing check in tests (authored by 
DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66124?vs=214749=215221#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66124/new/

https://reviews.llvm.org/D66124

Files:
  clang-tools-extra/trunk/clang-doc/Representation.h
  clang-tools-extra/trunk/unittests/clang-doc/ClangDocTest.cpp
  clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp


Index: clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp
@@ -91,7 +91,7 @@
   CheckNamespaceInfo(, A);
 
   NamespaceInfo *B = InfoAsNamespace(Infos[2].get());
-  NamespaceInfo ExpectedB(EmptySID, "B");
+  NamespaceInfo ExpectedB(EmptySID, /*Name=*/"B", /*Path=*/"A");
   ExpectedB.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
   CheckNamespaceInfo(, B);
 
@@ -276,7 +276,7 @@
   CheckRecordInfo(, E);
 
   RecordInfo *G = InfoAsRecord(Infos[2].get());
-  RecordInfo ExpectedG(EmptySID, "G");
+  RecordInfo ExpectedG(EmptySID, /*Name=*/"G", /*Path=*/"E");
   ExpectedG.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
   ExpectedG.TagType = TagTypeKind::TTK_Class;
   ExpectedG.Namespace.emplace_back(EmptySID, "E", InfoType::IT_record);
Index: clang-tools-extra/trunk/unittests/clang-doc/ClangDocTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/ClangDocTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/ClangDocTest.cpp
@@ -83,6 +83,7 @@
 void CheckBaseInfo(Info *Expected, Info *Actual) {
   EXPECT_EQ(size_t(20), Actual->USR.size());
   EXPECT_EQ(Expected->Name, Actual->Name);
+  EXPECT_EQ(Expected->Path, Actual->Path);
   ASSERT_EQ(Expected->Namespace.size(), Actual->Namespace.size());
   for (size_t Idx = 0; Idx < Actual->Namespace.size(); ++Idx)
 CheckReference(Expected->Namespace[Idx], Actual->Namespace[Idx]);
Index: clang-tools-extra/trunk/clang-doc/Representation.h
===
--- clang-tools-extra/trunk/clang-doc/Representation.h
+++ clang-tools-extra/trunk/clang-doc/Representation.h
@@ -238,6 +238,8 @@
   Info(InfoType IT, SymbolID USR) : USR(USR), IT(IT) {}
   Info(InfoType IT, SymbolID USR, StringRef Name)
   : USR(USR), IT(IT), Name(Name) {}
+  Info(InfoType IT, SymbolID USR, StringRef Name, StringRef Path)
+  : USR(USR), IT(IT), Name(Name), Path(Path) {}
   Info(const Info ) = delete;
   Info(Info &) = default;
 
@@ -269,6 +271,8 @@
   NamespaceInfo(SymbolID USR) : Info(InfoType::IT_namespace, USR) {}
   NamespaceInfo(SymbolID USR, StringRef Name)
   : Info(InfoType::IT_namespace, USR, Name) {}
+  NamespaceInfo(SymbolID USR, StringRef Name, StringRef Path)
+  : Info(InfoType::IT_namespace, USR, Name, Path) {}
 
   void merge(NamespaceInfo &);
 
@@ -287,6 +291,7 @@
   SymbolInfo(InfoType IT) : Info(IT) {}
   SymbolInfo(InfoType IT, SymbolID USR) : Info(IT, USR) {}
   SymbolInfo(InfoType IT, SymbolID USR, StringRef Name) : Info(IT, USR, Name) 
{}
+  SymbolInfo(InfoType IT, SymbolID USR, StringRef Name, StringRef Path) : 
Info(IT, USR, Name, Path) {}
 
   void merge(SymbolInfo &);
 
@@ -318,6 +323,8 @@
   RecordInfo(SymbolID USR) : SymbolInfo(InfoType::IT_record, USR) {}
   RecordInfo(SymbolID USR, StringRef Name)
   : SymbolInfo(InfoType::IT_record, USR, Name) {}
+  RecordInfo(SymbolID USR, StringRef Name, StringRef Path)
+  : SymbolInfo(InfoType::IT_record, USR, Name, Path) {}
 
   void merge(RecordInfo &);
 


Index: clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp
@@ -91,7 +91,7 @@
   CheckNamespaceInfo(, A);
 
   NamespaceInfo *B = InfoAsNamespace(Infos[2].get());
-  NamespaceInfo ExpectedB(EmptySID, "B");
+  NamespaceInfo ExpectedB(EmptySID, /*Name=*/"B", /*Path=*/"A");
   ExpectedB.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
   CheckNamespaceInfo(, B);
 
@@ -276,7 +276,7 @@
   CheckRecordInfo(, E);
 
   RecordInfo *G = InfoAsRecord(Infos[2].get());
-  RecordInfo ExpectedG(EmptySID, "G");
+  RecordInfo ExpectedG(EmptySID, /*Name=*/"G", /*Path=*/"E");
   ExpectedG.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
   ExpectedG.TagType = TagTypeKind::TTK_Class;
   ExpectedG.Namespace.emplace_back(EmptySID, "E", InfoType::IT_record);
Index: clang-tools-extra/trunk/unittests/clang-doc/ClangDocTest.cpp

[PATCH] D66238: [clang-doc] Serialize inherited attributes and methods

2019-08-14 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran created this revision.
DiegoAstiazaran added reviewers: juliehockett, jakehehrlich.
DiegoAstiazaran added a project: clang-tools-extra.
Herald added subscribers: kadircet, arphaman.

clang-doc now serializes the inherited attributes and methods, not only the 
name of the base class.
All inherited are tracked, if B:A and C:B, info of A is included in C.
This data is stored in attribute Bases in a RecordInfo.
Previously tracked inheritance data, stored in Parents and VParents, hasn't 
been removed to reduce review load.


https://reviews.llvm.org/D66238

Files:
  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/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/MergeTest.cpp
  clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
  clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -84,6 +84,12 @@
   I.Members.emplace_back("int", "path/to/int", "X",
  AccessSpecifier::AS_private);
   I.TagType = TagTypeKind::TTK_Class;
+  I.Bases.emplace_back(EmptySID, "F", "path/to/F", true,
+   AccessSpecifier::AS_public, true);
+  I.Bases.back().ChildFunctions.emplace_back();
+  I.Bases.back().ChildFunctions.back().Name = "InheritedFunctionOne";
+  I.Bases.back().Members.emplace_back("int", "path/to/int", "X",
+  AccessSpecifier::AS_private);
   // F is in the global namespace
   I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record, "");
   I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record,
@@ -123,6 +129,24 @@
   Path:'path/to/int'
 Name:'X'
 Access:  Private
+Bases:
+  - USR: ''
+Name:'F'
+Path:'path/to/F'
+Members:
+  - Type:
+  Name:'int'
+  Path:'path/to/int'
+Name:'X'
+Access:  Private
+ChildFunctions:
+  - USR: ''
+Name:'InheritedFunctionOne'
+ReturnType:  {}
+Access:  Public
+IsVirtual:   true
+Access:  Public
+IsParent:true
 Parents:
   - Type:Record
 Name:'F'
Index: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -321,15 +321,16 @@
   CheckNamespaceInfo(, BWithFunction);
 }
 
-TEST(SerializeTest, ) {
+TEST(SerializeTest, emitInheritedRecordInfo) {
   EmittedInfoList Infos;
-  ExtractInfosFromCode(R"raw(class F {};
-class G {} ;
+  ExtractInfosFromCode(R"raw(class F { protected: void set(int N); };
+class G { public: int get() { return 1; } protected: int I; };
 class E : public F, virtual private G {};
+class H : private E {};
 template 
-class H {} ;
-class I : public H {} ;)raw",
-   10, /*Public=*/false, Infos);
+class I {} ;
+class J : public I {} ;)raw",
+   14, /*Public=*/false, Infos);
 
   RecordInfo *F = InfoAsRecord(Infos[0].get());
   RecordInfo ExpectedF(EmptySID, "F");
@@ -337,32 +338,91 @@
   ExpectedF.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
   CheckRecordInfo(, F);
 
-  RecordInfo *G = InfoAsRecord(Infos[2].get());
+  RecordInfo *G = InfoAsRecord(Infos[3].get());
   RecordInfo ExpectedG(EmptySID, "G");
   ExpectedG.TagType = TagTypeKind::TTK_Class;
   ExpectedG.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
+  ExpectedG.Members.emplace_back("int", "I", AccessSpecifier::AS_protected);
   CheckRecordInfo(, G);
 
-  RecordInfo *E = InfoAsRecord(Infos[4].get());
+  RecordInfo *E = InfoAsRecord(Infos[6].get());
   RecordInfo ExpectedE(EmptySID, "E");
   ExpectedE.Parents.emplace_back(EmptySID, "F", InfoType::IT_record);
   ExpectedE.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record);
+  ExpectedE.Bases.emplace_back(EmptySID, "F", "", false,
+   AccessSpecifier::AS_public, true);
+  FunctionInfo FunctionSet;
+  FunctionSet.Name = "set";
+  FunctionSet.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
+ 

[PATCH] D66151: [clang-doc] Fix bitcode writer

2019-08-14 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 215193.
DiegoAstiazaran marked an inline comment as done.
DiegoAstiazaran added a comment.

Use getAccess() instead of getAccessUnsafe() for CXXMethodDecl.
Add comments in YAML generator to specify that AS_none is used as the default 
here because it's the AS that shouldn't be part of the output. Even though 
AS_public is the default in the struct, it should be displayed in the YAML 
output.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66151/new/

https://reviews.llvm.org/D66151

Files:
  clang-tools-extra/clang-doc/BitcodeWriter.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/unittests/clang-doc/BitcodeTest.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
  clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
  clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
  clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -34,6 +34,7 @@
   "path/to/A/Namespace");
   I.ChildFunctions.emplace_back();
   I.ChildFunctions.back().Name = "OneFunction";
+  I.ChildFunctions.back().Access = AccessSpecifier::AS_none;
   I.ChildEnums.emplace_back();
   I.ChildEnums.back().Name = "OneEnum";
 
@@ -138,6 +139,7 @@
   - USR: ''
 Name:'OneFunction'
 ReturnType:  {}
+Access:  Public
 ChildEnums:
   - USR: ''
 Name:'OneEnum'
@@ -154,6 +156,8 @@
   I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
+  I.Access = AccessSpecifier::AS_none;
+
   I.ReturnType =
   TypeInfo(EmptySID, "void", InfoType::IT_default, "path/to/void");
   I.Params.emplace_back("int", "path/to/int", "P");
@@ -242,6 +246,7 @@
   I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
   I.Params.emplace_back("int", "I");
   I.Params.emplace_back("int", "J");
+  I.Access = AccessSpecifier::AS_none;
 
   CommentInfo Top;
   Top.Kind = "FullComment";
Index: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -103,6 +103,7 @@
   F.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
   F.Namespace.emplace_back(EmptySID, "B", InfoType::IT_namespace);
   F.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
+  F.Access = AccessSpecifier::AS_none;
   ExpectedBWithFunction.ChildFunctions.emplace_back(std::move(F));
   CheckNamespaceInfo(, BWithFunction);
 }
@@ -299,6 +300,7 @@
   F.Name = "F";
   F.ReturnType = TypeInfo(EmptySID, "int", InfoType::IT_default);
   F.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
+  F.Access = AccessSpecifier::AS_none;
   ExpectedBWithFunction.ChildFunctions.emplace_back(std::move(F));
   CheckNamespaceInfo(, BWithFunction);
 }
@@ -314,6 +316,7 @@
   F.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
   F.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
   F.Params.emplace_back("int", "I");
+  F.Access = AccessSpecifier::AS_none;
   ExpectedBWithFunction.ChildFunctions.emplace_back(std::move(F));
   CheckNamespaceInfo(, BWithFunction);
 }
@@ -379,6 +382,7 @@
   F.ReturnType = TypeInfo(EmptySID, "int", InfoType::IT_default);
   F.Loc.emplace_back(0, llvm::SmallString<16>{"test.cpp"});
   F.Params.emplace_back("int", "x");
+  F.Access = AccessSpecifier::AS_none;
   ExpectedBWithFunction.ChildFunctions.emplace_back(std::move(F));
   CheckNamespaceInfo(, BWithFunction);
 
@@ -389,6 +393,7 @@
   ExportedF.ReturnType = TypeInfo(EmptySID, "double", InfoType::IT_default);
   ExportedF.Loc.emplace_back(0, llvm::SmallString<16>{"test.cpp"});
   ExportedF.Params.emplace_back("double", "y");
+  ExportedF.Access = AccessSpecifier::AS_none;
   ExpectedBWithExportedFunction.ChildFunctions.emplace_back(
   std::move(ExportedF));
   CheckNamespaceInfo(, BWithExportedFunction);
Index: clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
@@ -31,6 +31,7 @@
   I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record);
   I.ChildFunctions.emplace_back();
   I.ChildFunctions.back().Name = "OneFunction";
+  

[PATCH] D66151: [clang-doc] Fix bitcode writer

2019-08-13 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 214923.
DiegoAstiazaran edited the summary of this revision.
DiegoAstiazaran added a comment.

Default value of AccessSpecifier attributes is now AS_public.
Multiple tests modified.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66151/new/

https://reviews.llvm.org/D66151

Files:
  clang-tools-extra/clang-doc/BitcodeWriter.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/Serialize.cpp
  clang-tools-extra/test/clang-doc/single-file-public.cpp
  clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
  clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
  clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
  clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -34,6 +34,7 @@
   "path/to/A/Namespace");
   I.ChildFunctions.emplace_back();
   I.ChildFunctions.back().Name = "OneFunction";
+  I.ChildFunctions.back().Access = AccessSpecifier::AS_none;
   I.ChildEnums.emplace_back();
   I.ChildEnums.back().Name = "OneEnum";
 
@@ -138,6 +139,7 @@
   - USR: ''
 Name:'OneFunction'
 ReturnType:  {}
+Access:  Public
 ChildEnums:
   - USR: ''
 Name:'OneEnum'
@@ -154,6 +156,8 @@
   I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
+  I.Access = AccessSpecifier::AS_none;
+
   I.ReturnType =
   TypeInfo(EmptySID, "void", InfoType::IT_default, "path/to/void");
   I.Params.emplace_back("int", "path/to/int", "P");
@@ -242,6 +246,7 @@
   I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
   I.Params.emplace_back("int", "I");
   I.Params.emplace_back("int", "J");
+  I.Access = AccessSpecifier::AS_none;
 
   CommentInfo Top;
   Top.Kind = "FullComment";
Index: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -103,6 +103,7 @@
   F.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
   F.Namespace.emplace_back(EmptySID, "B", InfoType::IT_namespace);
   F.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
+  F.Access = AccessSpecifier::AS_none;
   ExpectedBWithFunction.ChildFunctions.emplace_back(std::move(F));
   CheckNamespaceInfo(, BWithFunction);
 }
@@ -299,6 +300,7 @@
   F.Name = "F";
   F.ReturnType = TypeInfo(EmptySID, "int", InfoType::IT_default);
   F.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
+  F.Access = AccessSpecifier::AS_none;
   ExpectedBWithFunction.ChildFunctions.emplace_back(std::move(F));
   CheckNamespaceInfo(, BWithFunction);
 }
@@ -314,6 +316,7 @@
   F.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
   F.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
   F.Params.emplace_back("int", "I");
+  F.Access = AccessSpecifier::AS_none;
   ExpectedBWithFunction.ChildFunctions.emplace_back(std::move(F));
   CheckNamespaceInfo(, BWithFunction);
 }
@@ -379,6 +382,7 @@
   F.ReturnType = TypeInfo(EmptySID, "int", InfoType::IT_default);
   F.Loc.emplace_back(0, llvm::SmallString<16>{"test.cpp"});
   F.Params.emplace_back("int", "x");
+  F.Access = AccessSpecifier::AS_none;
   ExpectedBWithFunction.ChildFunctions.emplace_back(std::move(F));
   CheckNamespaceInfo(, BWithFunction);
 
@@ -389,6 +393,7 @@
   ExportedF.ReturnType = TypeInfo(EmptySID, "double", InfoType::IT_default);
   ExportedF.Loc.emplace_back(0, llvm::SmallString<16>{"test.cpp"});
   ExportedF.Params.emplace_back("double", "y");
+  ExportedF.Access = AccessSpecifier::AS_none;
   ExpectedBWithExportedFunction.ChildFunctions.emplace_back(
   std::move(ExportedF));
   CheckNamespaceInfo(, BWithExportedFunction);
Index: clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
@@ -31,6 +31,7 @@
   I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record);
   I.ChildFunctions.emplace_back();
   I.ChildFunctions.back().Name = "OneFunction";
+  I.ChildFunctions.back().Access = AccessSpecifier::AS_none;
   I.ChildEnums.emplace_back();
   I.ChildEnums.back().Name = "OneEnum";
 
@@ -127,7 +128,7 @@
 
 ### OneFunction
 
-* OneFunction()*
+*public  OneFunction()*
 
 
 
@@ -153,6 +154,8 @@
   I.DefLoc = Location(10, 

[PATCH] D66151: [clang-doc] Fix bitcode writer

2019-08-13 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran created this revision.
DiegoAstiazaran added reviewers: jakehehrlich, juliehockett.
DiegoAstiazaran added a project: clang-tools-extra.

Bitcode writer was not emitting the corresponding record for the Access 
attribute of a FunctionInfo.
This is added and corresponding test is included.


https://reviews.llvm.org/D66151

Files:
  clang-tools-extra/clang-doc/BitcodeWriter.cpp
  clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp


Index: clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
@@ -126,8 +126,7 @@
   I.IsMethod = true;
   I.Parent = Reference(EmptySID, "Parent", InfoType::IT_record);
 
-  // TODO: fix access
-  // I.Access = AccessSpecifier::AS_private;
+  I.Access = AccessSpecifier::AS_private;
 
   std::string WriteResult = writeInfo();
   EXPECT_TRUE(WriteResult.size() > 0);
Index: clang-tools-extra/clang-doc/BitcodeWriter.cpp
===
--- clang-tools-extra/clang-doc/BitcodeWriter.cpp
+++ clang-tools-extra/clang-doc/BitcodeWriter.cpp
@@ -510,6 +510,7 @@
 emitBlock(N, FieldId::F_namespace);
   for (const auto  : I.Description)
 emitBlock(CI);
+  emitRecord(I.Access, FUNCTION_ACCESS);
   emitRecord(I.IsMethod, FUNCTION_IS_METHOD);
   if (I.DefLoc)
 emitRecord(I.DefLoc.getValue(), FUNCTION_DEFLOCATION);


Index: clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
@@ -126,8 +126,7 @@
   I.IsMethod = true;
   I.Parent = Reference(EmptySID, "Parent", InfoType::IT_record);
 
-  // TODO: fix access
-  // I.Access = AccessSpecifier::AS_private;
+  I.Access = AccessSpecifier::AS_private;
 
   std::string WriteResult = writeInfo();
   EXPECT_TRUE(WriteResult.size() > 0);
Index: clang-tools-extra/clang-doc/BitcodeWriter.cpp
===
--- clang-tools-extra/clang-doc/BitcodeWriter.cpp
+++ clang-tools-extra/clang-doc/BitcodeWriter.cpp
@@ -510,6 +510,7 @@
 emitBlock(N, FieldId::F_namespace);
   for (const auto  : I.Description)
 emitBlock(CI);
+  emitRecord(I.Access, FUNCTION_ACCESS);
   emitRecord(I.IsMethod, FUNCTION_IS_METHOD);
   if (I.DefLoc)
 emitRecord(I.DefLoc.getValue(), FUNCTION_DEFLOCATION);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D66124: [clang-doc] Add missing check in tests

2019-08-12 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran created this revision.
DiegoAstiazaran added reviewers: juliehockett, jakehehrlich.
DiegoAstiazaran added a project: clang-tools-extra.
Herald added subscribers: kadircet, arphaman.

Path is now checked when comparing two Infos in the unit tests.


https://reviews.llvm.org/D66124

Files:
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
  clang-tools-extra/unittests/clang-doc/SerializeTest.cpp


Index: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -91,7 +91,7 @@
   CheckNamespaceInfo(, A);
 
   NamespaceInfo *B = InfoAsNamespace(Infos[2].get());
-  NamespaceInfo ExpectedB(EmptySID, "B");
+  NamespaceInfo ExpectedB(EmptySID, /*Name=*/"B", /*Path=*/"A");
   ExpectedB.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
   CheckNamespaceInfo(, B);
 
@@ -276,7 +276,7 @@
   CheckRecordInfo(, E);
 
   RecordInfo *G = InfoAsRecord(Infos[2].get());
-  RecordInfo ExpectedG(EmptySID, "G");
+  RecordInfo ExpectedG(EmptySID, /*Name=*/"G", /*Path=*/"E");
   ExpectedG.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
   ExpectedG.TagType = TagTypeKind::TTK_Class;
   ExpectedG.Namespace.emplace_back(EmptySID, "E", InfoType::IT_record);
Index: clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
+++ clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
@@ -83,6 +83,7 @@
 void CheckBaseInfo(Info *Expected, Info *Actual) {
   EXPECT_EQ(size_t(20), Actual->USR.size());
   EXPECT_EQ(Expected->Name, Actual->Name);
+  EXPECT_EQ(Expected->Path, Actual->Path);
   ASSERT_EQ(Expected->Namespace.size(), Actual->Namespace.size());
   for (size_t Idx = 0; Idx < Actual->Namespace.size(); ++Idx)
 CheckReference(Expected->Namespace[Idx], Actual->Namespace[Idx]);
Index: clang-tools-extra/clang-doc/Representation.h
===
--- clang-tools-extra/clang-doc/Representation.h
+++ clang-tools-extra/clang-doc/Representation.h
@@ -238,6 +238,8 @@
   Info(InfoType IT, SymbolID USR) : USR(USR), IT(IT) {}
   Info(InfoType IT, SymbolID USR, StringRef Name)
   : USR(USR), IT(IT), Name(Name) {}
+  Info(InfoType IT, SymbolID USR, StringRef Name, StringRef Path)
+  : USR(USR), IT(IT), Name(Name), Path(Path) {}
   Info(const Info ) = delete;
   Info(Info &) = default;
 
@@ -269,6 +271,8 @@
   NamespaceInfo(SymbolID USR) : Info(InfoType::IT_namespace, USR) {}
   NamespaceInfo(SymbolID USR, StringRef Name)
   : Info(InfoType::IT_namespace, USR, Name) {}
+  NamespaceInfo(SymbolID USR, StringRef Name, StringRef Path)
+  : Info(InfoType::IT_namespace, USR, Name, Path) {}
 
   void merge(NamespaceInfo &);
 
@@ -287,6 +291,7 @@
   SymbolInfo(InfoType IT) : Info(IT) {}
   SymbolInfo(InfoType IT, SymbolID USR) : Info(IT, USR) {}
   SymbolInfo(InfoType IT, SymbolID USR, StringRef Name) : Info(IT, USR, Name) 
{}
+  SymbolInfo(InfoType IT, SymbolID USR, StringRef Name, StringRef Path) : 
Info(IT, USR, Name, Path) {}
 
   void merge(SymbolInfo &);
 
@@ -318,6 +323,8 @@
   RecordInfo(SymbolID USR) : SymbolInfo(InfoType::IT_record, USR) {}
   RecordInfo(SymbolID USR, StringRef Name)
   : SymbolInfo(InfoType::IT_record, USR, Name) {}
+  RecordInfo(SymbolID USR, StringRef Name, StringRef Path)
+  : SymbolInfo(InfoType::IT_record, USR, Name, Path) {}
 
   void merge(RecordInfo &);
 


Index: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -91,7 +91,7 @@
   CheckNamespaceInfo(, A);
 
   NamespaceInfo *B = InfoAsNamespace(Infos[2].get());
-  NamespaceInfo ExpectedB(EmptySID, "B");
+  NamespaceInfo ExpectedB(EmptySID, /*Name=*/"B", /*Path=*/"A");
   ExpectedB.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
   CheckNamespaceInfo(, B);
 
@@ -276,7 +276,7 @@
   CheckRecordInfo(, E);
 
   RecordInfo *G = InfoAsRecord(Infos[2].get());
-  RecordInfo ExpectedG(EmptySID, "G");
+  RecordInfo ExpectedG(EmptySID, /*Name=*/"G", /*Path=*/"E");
   ExpectedG.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
   ExpectedG.TagType = TagTypeKind::TTK_Class;
   ExpectedG.Namespace.emplace_back(EmptySID, "E", InfoType::IT_record);
Index: clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
+++ clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
@@ -83,6 +83,7 @@
 void CheckBaseInfo(Info *Expected, Info *Actual) {
   EXPECT_EQ(size_t(20), 

[PATCH] D65987: [clang-doc] Generate HTML links for children namespaces/records

2019-08-12 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL368602: [clang-doc] Generate HTML links for children 
namespaces/records (authored by DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65987?vs=21=214677#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65987/new/

https://reviews.llvm.org/D65987

Files:
  clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/trunk/clang-doc/Representation.cpp
  clang-tools-extra/trunk/clang-doc/Representation.h
  clang-tools-extra/trunk/clang-doc/Serialize.cpp
  clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
  clang-tools-extra/trunk/unittests/clang-doc/MergeTest.cpp
  clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp
  clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp

Index: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -39,8 +39,9 @@
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
 
   I.ChildNamespaces.emplace_back(EmptySID, "ChildNamespace",
- InfoType::IT_namespace);
-  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record);
+ InfoType::IT_namespace, "Namespace");
+  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record,
+  "Namespace");
   I.ChildFunctions.emplace_back();
   I.ChildFunctions.back().Name = "OneFunction";
   I.ChildEnums.emplace_back();
@@ -100,11 +101,15 @@
   namespace Namespace
   Namespaces
   
-ChildNamespace
+
+  ChildNamespace
+
   
   Records
   
-ChildStruct
+
+  ChildStruct
+
   
   Functions
   
@@ -137,7 +142,8 @@
   I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record, PathTo);
   I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record);
 
-  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record);
+  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record,
+  "X/Y/Z/r");
   I.ChildFunctions.emplace_back();
   I.ChildFunctions.back().Name = "OneFunction";
   I.ChildEnums.emplace_back();
@@ -215,7 +221,9 @@
   
   Records
   
-ChildStruct
+
+  ChildStruct
+
   
   Functions
   
Index: clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -29,8 +29,9 @@
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
 
   I.ChildNamespaces.emplace_back(EmptySID, "ChildNamespace",
- InfoType::IT_namespace);
-  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record);
+ InfoType::IT_namespace, "path/to/A/Namespace");
+  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record,
+  "path/to/A/Namespace");
   I.ChildFunctions.emplace_back();
   I.ChildFunctions.back().Name = "OneFunction";
   I.ChildEnums.emplace_back();
@@ -53,9 +54,11 @@
 ChildNamespaces:
   - Type:Namespace
 Name:'ChildNamespace'
+Path:'path/to/A/Namespace'
 ChildRecords:
   - Type:Record
 Name:'ChildStruct'
+Path:'path/to/A/Namespace'
 ChildFunctions:
   - USR: ''
 Name:'OneFunction'
@@ -71,7 +74,7 @@
 TEST(YAMLGeneratorTest, emitRecordYAML) {
   RecordInfo I;
   I.Name = "r";
-  I.Path = "path/to/r";
+  I.Path = "path/to/A";
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
 
   I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
@@ -85,7 +88,8 @@
   I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record,
 "path/to/G");
 
-  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record);
+  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record,
+  "path/to/A/r");
   I.ChildFunctions.emplace_back();
   I.ChildFunctions.back().Name = "OneFunction";
   I.ChildEnums.emplace_back();
@@ -101,7 +105,7 @@
   R"raw(---
 USR: ''
 Name:'r'
-Path:'path/to/r'
+Path:'path/to/A'
 Namespace:
   - Type:Namespace
 Name:'A'
@@ -129,6 +133,7 @@
 ChildRecords:
   - Type:Record
 Name:

[PATCH] D65918: [clang-doc] Generate an HTML index file

2019-08-09 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL368484: [clang-doc] Generate an HTML index file (authored by 
DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65918?vs=214050=214445#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65918/new/

https://reviews.llvm.org/D65918

Files:
  clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp


Index: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
@@ -813,6 +813,24 @@
   return true;
 }
 
+static bool GenIndex(const ClangDocContext ) {
+  std::error_code FileErr, OK;
+  llvm::SmallString<128> IndexPath;
+  llvm::sys::path::native(CDCtx.OutDirectory, IndexPath);
+  llvm::sys::path::append(IndexPath, "index.html");
+  llvm::raw_fd_ostream IndexOS(IndexPath, FileErr, llvm::sys::fs::F_None);
+  if (FileErr != OK) {
+llvm::errs() << "Error creating main index: " << FileErr.message() << "\n";
+return false;
+  }
+  HTMLFile F;
+  std::vector> BasicNodes =
+  genCommonFileNodes("Index", "", CDCtx);
+  AppendVector(std::move(BasicNodes), F.Children);
+  F.Render(IndexOS);
+  return true;
+}
+
 static bool CopyFile(StringRef FilePath, StringRef OutDirectory) {
   llvm::SmallString<128> PathWrite;
   llvm::sys::path::native(OutDirectory, PathWrite);
@@ -831,7 +849,7 @@
 }
 
 bool HTMLGenerator::createResources(ClangDocContext ) {
-  if (!SerializeIndex(CDCtx))
+  if (!SerializeIndex(CDCtx) || !GenIndex(CDCtx))
 return false;
   for (const auto  : CDCtx.UserStylesheets)
 if (!CopyFile(FilePath, CDCtx.OutDirectory))


Index: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
@@ -813,6 +813,24 @@
   return true;
 }
 
+static bool GenIndex(const ClangDocContext ) {
+  std::error_code FileErr, OK;
+  llvm::SmallString<128> IndexPath;
+  llvm::sys::path::native(CDCtx.OutDirectory, IndexPath);
+  llvm::sys::path::append(IndexPath, "index.html");
+  llvm::raw_fd_ostream IndexOS(IndexPath, FileErr, llvm::sys::fs::F_None);
+  if (FileErr != OK) {
+llvm::errs() << "Error creating main index: " << FileErr.message() << "\n";
+return false;
+  }
+  HTMLFile F;
+  std::vector> BasicNodes =
+  genCommonFileNodes("Index", "", CDCtx);
+  AppendVector(std::move(BasicNodes), F.Children);
+  F.Render(IndexOS);
+  return true;
+}
+
 static bool CopyFile(StringRef FilePath, StringRef OutDirectory) {
   llvm::SmallString<128> PathWrite;
   llvm::sys::path::native(OutDirectory, PathWrite);
@@ -831,7 +849,7 @@
 }
 
 bool HTMLGenerator::createResources(ClangDocContext ) {
-  if (!SerializeIndex(CDCtx))
+  if (!SerializeIndex(CDCtx) || !GenIndex(CDCtx))
 return false;
   for (const auto  : CDCtx.UserStylesheets)
 if (!CopyFile(FilePath, CDCtx.OutDirectory))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65987: [clang-doc] Generate HTML links for children namespaces/records

2019-08-09 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 21.
DiegoAstiazaran added a comment.

Change the implementation of computeRelativePath


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65987/new/

https://reviews.llvm.org/D65987

Files:
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/Representation.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/Serialize.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.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

Index: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -29,8 +29,9 @@
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
 
   I.ChildNamespaces.emplace_back(EmptySID, "ChildNamespace",
- InfoType::IT_namespace);
-  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record);
+ InfoType::IT_namespace, "path/to/A/Namespace");
+  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record,
+  "path/to/A/Namespace");
   I.ChildFunctions.emplace_back();
   I.ChildFunctions.back().Name = "OneFunction";
   I.ChildEnums.emplace_back();
@@ -53,9 +54,11 @@
 ChildNamespaces:
   - Type:Namespace
 Name:'ChildNamespace'
+Path:'path/to/A/Namespace'
 ChildRecords:
   - Type:Record
 Name:'ChildStruct'
+Path:'path/to/A/Namespace'
 ChildFunctions:
   - USR: ''
 Name:'OneFunction'
@@ -71,7 +74,7 @@
 TEST(YAMLGeneratorTest, emitRecordYAML) {
   RecordInfo I;
   I.Name = "r";
-  I.Path = "path/to/r";
+  I.Path = "path/to/A";
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
 
   I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
@@ -85,7 +88,8 @@
   I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record,
 "path/to/G");
 
-  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record);
+  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record,
+  "path/to/A/r");
   I.ChildFunctions.emplace_back();
   I.ChildFunctions.back().Name = "OneFunction";
   I.ChildEnums.emplace_back();
@@ -101,7 +105,7 @@
   R"raw(---
 USR: ''
 Name:'r'
-Path:'path/to/r'
+Path:'path/to/A'
 Namespace:
   - Type:Namespace
 Name:'A'
@@ -129,6 +133,7 @@
 ChildRecords:
   - Type:Record
 Name:'ChildStruct'
+Path:'path/to/A/r'
 ChildFunctions:
   - USR: ''
 Name:'OneFunction'
Index: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -407,12 +407,14 @@
 
   RecordInfo *ParentB = InfoAsRecord(Infos[3].get());
   RecordInfo ExpectedParentB(EmptySID);
-  ExpectedParentB.ChildRecords.emplace_back(EmptySID, "B", InfoType::IT_record);
+  ExpectedParentB.ChildRecords.emplace_back(EmptySID, "B", InfoType::IT_record,
+"A");
   CheckRecordInfo(, ParentB);
 
   NamespaceInfo *ParentC = InfoAsNamespace(Infos[7].get());
   NamespaceInfo ExpectedParentC(EmptySID);
-  ExpectedParentC.ChildRecords.emplace_back(EmptySID, "C", InfoType::IT_record);
+  ExpectedParentC.ChildRecords.emplace_back(EmptySID, "C", InfoType::IT_record,
+"@nonymous_namespace");
   CheckNamespaceInfo(, ParentC);
 }
 
@@ -431,7 +433,7 @@
   NamespaceInfo *ParentB = InfoAsNamespace(Infos[3].get());
   NamespaceInfo ExpectedParentB(EmptySID);
   ExpectedParentB.ChildNamespaces.emplace_back(EmptySID, "B",
-   InfoType::IT_namespace);
+   InfoType::IT_namespace, "A");
   CheckNamespaceInfo(, ParentB);
 }
 
Index: clang-tools-extra/unittests/clang-doc/MergeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/MergeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/MergeTest.cpp
@@ -87,7 +87,7 @@
   One.Parents.emplace_back(EmptySID, "F", InfoType::IT_record);
   One.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record);
 
-  One.ChildRecords.emplace_back(NonEmptySID, 

[PATCH] D65987: [clang-doc] Generate HTML links for children namespaces/records

2019-08-09 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran marked 2 inline comments as done.
DiegoAstiazaran added inline comments.



Comment at: clang-tools-extra/clang-doc/HTMLGenerator.cpp:250
+  // The resulting path is "../../../A/B/D" instead of a "../D". It is correct
+  // but it would be better to have the shorter version.
   StringRef Dir = Directory;

DiegoAstiazaran wrote:
> juliehockett wrote:
> > Would `llvm::sys::path::remove_dots()` do this? It might not, but is worth 
> > investigating.
> `llvm::sys::path::remove_dots()` removes all `../` (except for leading `../`) 
> so the resulting path in the example would be `../A/B/D`, which is not 
> correct.
Sorry about that, I was incorrect. `llvm::sys::path::remove_dots()` do what we 
want but from the right side of the path, not the left side.
For `A/B/C/../..` it changes it to `A`. So it still does not work for us.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65987/new/

https://reviews.llvm.org/D65987



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


[PATCH] D65987: [clang-doc] Generate HTML links for children namespaces/records

2019-08-09 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran marked 2 inline comments as done.
DiegoAstiazaran added inline comments.



Comment at: clang-tools-extra/clang-doc/HTMLGenerator.cpp:250
+  // The resulting path is "../../../A/B/D" instead of a "../D". It is correct
+  // but it would be better to have the shorter version.
   StringRef Dir = Directory;

juliehockett wrote:
> Would `llvm::sys::path::remove_dots()` do this? It might not, but is worth 
> investigating.
`llvm::sys::path::remove_dots()` removes all `../` (except for leading `../`) 
so the resulting path in the example would be `../A/B/D`, which is not correct.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65987/new/

https://reviews.llvm.org/D65987



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


[PATCH] D65483: [clang-doc] Add link to source code in file definitions

2019-08-09 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL368460: [clang-format] Add link to source code in file 
definitions (authored by DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65483?vs=214004=214404#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65483/new/

https://reviews.llvm.org/D65483

Files:
  clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp
  clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
  clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/trunk/clang-doc/Mapper.cpp
  clang-tools-extra/trunk/clang-doc/Mapper.h
  clang-tools-extra/trunk/clang-doc/Representation.cpp
  clang-tools-extra/trunk/clang-doc/Representation.h
  clang-tools-extra/trunk/clang-doc/Serialize.cpp
  clang-tools-extra/trunk/clang-doc/Serialize.h
  clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/trunk/docs/clang-doc.rst
  clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
  clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp

Index: clang-tools-extra/trunk/docs/clang-doc.rst
===
--- clang-tools-extra/trunk/docs/clang-doc.rst
+++ clang-tools-extra/trunk/docs/clang-doc.rst
@@ -66,7 +66,7 @@
 
 .. code-block:: console
 
-	$ clang-doc --help
+  $ clang-doc --help
   USAGE: clang-doc [options]  [... ]
 
   OPTIONS:
@@ -79,17 +79,27 @@
 
   clang-doc options:
 
--doxygen   - Use only doxygen-style comments to generate docs.
--dump  - Dump intermediate results to bitcode file.
--extra-arg=- Additional argument to append to the compiler command line
--extra-arg-before= - Additional argument to prepend to the compiler command line
---format=   - Format for outputted docs.
-  =yaml-   Documentation in YAML format.
-  =md  -   Documentation in MD format.
-  =html-   Documentation in HTML format.
--output=   - Directory for outputting generated files.
--p=- Build path
---public   - Document only public declarations.
---stylesheets= - CSS stylesheets to extend the default styles.
-
-``stylesheets`` should only be used if ``format`` is set to ``html``.
+--doxygen   - Use only doxygen-style comments to generate docs.
+--extra-arg=- Additional argument to append to the compiler command line
+--extra-arg-before= - Additional argument to prepend to the compiler command line
+--format=- Format for outputted docs.
+  =yaml -   Documentation in YAML format.
+  =md   -   Documentation in MD format.
+  =html -   Documentation in HTML format.
+--ignore-map-errors - Continue if files are not mapped correctly.
+--output=   - Directory for outputting generated files.
+-p= - Build path
+--public- Document only public declarations.
+--repository=   -
+  URL of repository that hosts code.
+  Used for links to definition locations.
+--source-root=  -
+  Directory where processed files are stored.
+  Links to definition locations will only be
+  generated if the file is in this dir.
+--stylesheets=  - CSS stylesheets to extend the default styles.
+
+The following flags shoud only be used if ``format`` is set to ``html``:
+- ``repository``
+- ``source-root``
+- ``stylesheets``
Index: clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
===
--- clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
+++ clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
@@ -77,10 +77,13 @@
   {// 0. Fixed-size integer (line number)
llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
  BitCodeConstants::LineNumberSize),
-   // 1. Fixed-size integer (length of the following string (filename))
+   // 1. Boolean (IsFileInRootDir)
+   llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
+ BitCodeConstants::BoolSize),
+   // 2. Fixed-size integer (length of the following string (filename))
llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
  BitCodeConstants::StringLengthSize),
-   // 2. The string blob
+   // 3. The string blob
llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)});
 }
 
@@ -316,6 +319,7 @@
   // FIXME: Assert that the line number is of the appropriate size.
   

[PATCH] D65987: [clang-doc] Generate HTML links for children namespaces/records

2019-08-08 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran created this revision.
DiegoAstiazaran added reviewers: juliehockett, jakehehrlich.
DiegoAstiazaran added a project: clang-tools-extra.

Path is now stored in the references to the child while serializing, then this 
path is used to generate the relative path in the HTML generator.
Now some references have paths and some don't so in the reducing phase, 
references are now properly merged checking for empty attributes.
Tests added for HTML and YAML generators, merging and serializing.
computeRelativePath function had a bug when the filepath is part of the given 
directory; it returned a path that starts with a separator. This has been fixed.


https://reviews.llvm.org/D65987

Files:
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/Representation.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/Serialize.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.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

Index: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -29,8 +29,9 @@
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
 
   I.ChildNamespaces.emplace_back(EmptySID, "ChildNamespace",
- InfoType::IT_namespace);
-  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record);
+ InfoType::IT_namespace, "path/to/A/Namespace");
+  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record,
+  "path/to/A/Namespace");
   I.ChildFunctions.emplace_back();
   I.ChildFunctions.back().Name = "OneFunction";
   I.ChildEnums.emplace_back();
@@ -53,9 +54,11 @@
 ChildNamespaces:
   - Type:Namespace
 Name:'ChildNamespace'
+Path:'path/to/A/Namespace'
 ChildRecords:
   - Type:Record
 Name:'ChildStruct'
+Path:'path/to/A/Namespace'
 ChildFunctions:
   - USR: ''
 Name:'OneFunction'
@@ -71,7 +74,7 @@
 TEST(YAMLGeneratorTest, emitRecordYAML) {
   RecordInfo I;
   I.Name = "r";
-  I.Path = "path/to/r";
+  I.Path = "path/to/A";
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
 
   I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
@@ -85,7 +88,8 @@
   I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record,
 "path/to/G");
 
-  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record);
+  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record,
+  "path/to/A/r");
   I.ChildFunctions.emplace_back();
   I.ChildFunctions.back().Name = "OneFunction";
   I.ChildEnums.emplace_back();
@@ -101,7 +105,7 @@
   R"raw(---
 USR: ''
 Name:'r'
-Path:'path/to/r'
+Path:'path/to/A'
 Namespace:
   - Type:Namespace
 Name:'A'
@@ -129,6 +133,7 @@
 ChildRecords:
   - Type:Record
 Name:'ChildStruct'
+Path:'path/to/A/r'
 ChildFunctions:
   - USR: ''
 Name:'OneFunction'
Index: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -407,12 +407,14 @@
 
   RecordInfo *ParentB = InfoAsRecord(Infos[3].get());
   RecordInfo ExpectedParentB(EmptySID);
-  ExpectedParentB.ChildRecords.emplace_back(EmptySID, "B", InfoType::IT_record);
+  ExpectedParentB.ChildRecords.emplace_back(EmptySID, "B", InfoType::IT_record,
+"A");
   CheckRecordInfo(, ParentB);
 
   NamespaceInfo *ParentC = InfoAsNamespace(Infos[7].get());
   NamespaceInfo ExpectedParentC(EmptySID);
-  ExpectedParentC.ChildRecords.emplace_back(EmptySID, "C", InfoType::IT_record);
+  ExpectedParentC.ChildRecords.emplace_back(EmptySID, "C", InfoType::IT_record,
+"@nonymous_namespace");
   CheckNamespaceInfo(, ParentC);
 }
 
@@ -431,7 +433,7 @@
   NamespaceInfo *ParentB = InfoAsNamespace(Infos[3].get());
   NamespaceInfo ExpectedParentB(EmptySID);
   ExpectedParentB.ChildNamespaces.emplace_back(EmptySID, "B",
-   InfoType::IT_namespace);
+   InfoType::IT_namespace, "A");
   

[PATCH] D65915: [clang-doc] Protect Index with mutex during reducing and generation stage

2019-08-08 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL368313: [clang-doc] Protect Index with mutex during reducing 
and generation stage (authored by DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65915?vs=214047=214178#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65915/new/

https://reviews.llvm.org/D65915

Files:
  clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp


Index: clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
@@ -36,6 +36,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Mutex.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Signals.h"
@@ -246,6 +247,7 @@
   llvm::outs() << "Reducing " << USRToBitcode.size() << " infos...\n";
   std::atomic Error;
   Error = false;
+  llvm::sys::Mutex IndexMutex;
   // ExecutorConcurrency is a flag exposed by AllTUsExecution.h
   llvm::ThreadPool Pool(ExecutorConcurrency == 0 ? llvm::hardware_concurrency()
  : ExecutorConcurrency);
@@ -289,8 +291,10 @@
 return;
   }
 
+  IndexMutex.lock();
   // Add a reference to this Info in the Index
   clang::doc::Generator::addInfoToIndex(CDCtx.Idx, I);
+  IndexMutex.unlock();
 
   if (auto Err = G->get()->generateDocForInfo(I, InfoOS, CDCtx))
 llvm::errs() << toString(std::move(Err)) << "\n";


Index: clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
@@ -36,6 +36,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Mutex.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Signals.h"
@@ -246,6 +247,7 @@
   llvm::outs() << "Reducing " << USRToBitcode.size() << " infos...\n";
   std::atomic Error;
   Error = false;
+  llvm::sys::Mutex IndexMutex;
   // ExecutorConcurrency is a flag exposed by AllTUsExecution.h
   llvm::ThreadPool Pool(ExecutorConcurrency == 0 ? llvm::hardware_concurrency()
  : ExecutorConcurrency);
@@ -289,8 +291,10 @@
 return;
   }
 
+  IndexMutex.lock();
   // Add a reference to this Info in the Index
   clang::doc::Generator::addInfoToIndex(CDCtx.Idx, I);
+  IndexMutex.unlock();
 
   if (auto Err = G->get()->generateDocForInfo(I, InfoOS, CDCtx))
 llvm::errs() << toString(std::move(Err)) << "\n";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65918: [clang-doc] Generate an HTML index file

2019-08-07 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran created this revision.
DiegoAstiazaran added reviewers: juliehockett, jakehehrlich.
DiegoAstiazaran added a project: clang-tools-extra.
Herald added a subscriber: arphaman.

clang-doc now generates a file that contains only an index to all the infos 
that can be used as the landing page for the generated website.


https://reviews.llvm.org/D65918

Files:
  clang-tools-extra/clang-doc/HTMLGenerator.cpp


Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -693,6 +693,24 @@
   return true;
 }
 
+static bool GenIndex(const ClangDocContext ) {
+  std::error_code FileErr, OK;
+  llvm::SmallString<128> IndexPath;
+  llvm::sys::path::native(CDCtx.OutDirectory, IndexPath);
+  llvm::sys::path::append(IndexPath, "index.html");
+  llvm::raw_fd_ostream IndexOS(IndexPath, FileErr, llvm::sys::fs::F_None);
+  if (FileErr != OK) {
+llvm::errs() << "Error creating main index: " << FileErr.message() << "\n";
+return false;
+  }
+  HTMLFile F;
+  std::vector> BasicNodes =
+  genCommonFileNodes("Index", "", CDCtx);
+  AppendVector(std::move(BasicNodes), F.Children);
+  F.Render(IndexOS);
+  return true;
+}
+
 static bool CopyFile(StringRef FilePath, StringRef OutDirectory) {
   llvm::SmallString<128> PathWrite;
   llvm::sys::path::native(OutDirectory, PathWrite);
@@ -711,7 +729,7 @@
 }
 
 bool HTMLGenerator::createResources(ClangDocContext ) {
-  if (!SerializeIndex(CDCtx))
+  if (!SerializeIndex(CDCtx) || !GenIndex(CDCtx))
 return false;
   for (const auto  : CDCtx.UserStylesheets)
 if (!CopyFile(FilePath, CDCtx.OutDirectory))


Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -693,6 +693,24 @@
   return true;
 }
 
+static bool GenIndex(const ClangDocContext ) {
+  std::error_code FileErr, OK;
+  llvm::SmallString<128> IndexPath;
+  llvm::sys::path::native(CDCtx.OutDirectory, IndexPath);
+  llvm::sys::path::append(IndexPath, "index.html");
+  llvm::raw_fd_ostream IndexOS(IndexPath, FileErr, llvm::sys::fs::F_None);
+  if (FileErr != OK) {
+llvm::errs() << "Error creating main index: " << FileErr.message() << "\n";
+return false;
+  }
+  HTMLFile F;
+  std::vector> BasicNodes =
+  genCommonFileNodes("Index", "", CDCtx);
+  AppendVector(std::move(BasicNodes), F.Children);
+  F.Render(IndexOS);
+  return true;
+}
+
 static bool CopyFile(StringRef FilePath, StringRef OutDirectory) {
   llvm::SmallString<128> PathWrite;
   llvm::sys::path::native(OutDirectory, PathWrite);
@@ -711,7 +729,7 @@
 }
 
 bool HTMLGenerator::createResources(ClangDocContext ) {
-  if (!SerializeIndex(CDCtx))
+  if (!SerializeIndex(CDCtx) || !GenIndex(CDCtx))
 return false;
   for (const auto  : CDCtx.UserStylesheets)
 if (!CopyFile(FilePath, CDCtx.OutDirectory))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65915: [clang-doc] Protect Index with mutex during reducing and generation stage

2019-08-07 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran created this revision.
DiegoAstiazaran added a reviewer: juliehockett.
DiegoAstiazaran added a project: clang-tools-extra.
Herald added subscribers: kadircet, arphaman, ilya-biryukov.

Idx in ClangDocContext instance was being modified by multiple threads causing 
a seg fault.
A mutex is added to avoid this.


https://reviews.llvm.org/D65915

Files:
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp


Index: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -36,6 +36,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Mutex.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Signals.h"
@@ -246,6 +247,7 @@
   llvm::outs() << "Reducing " << USRToBitcode.size() << " infos...\n";
   std::atomic Error;
   Error = false;
+  llvm::sys::Mutex IndexMutex;
   // ExecutorConcurrency is a flag exposed by AllTUsExecution.h
   llvm::ThreadPool Pool(ExecutorConcurrency == 0 ? llvm::hardware_concurrency()
  : ExecutorConcurrency);
@@ -289,8 +291,10 @@
 return;
   }
 
+  IndexMutex.lock();
   // Add a reference to this Info in the Index
   clang::doc::Generator::addInfoToIndex(CDCtx.Idx, I);
+  IndexMutex.unlock();
 
   if (auto Err = G->get()->generateDocForInfo(I, InfoOS, CDCtx))
 llvm::errs() << toString(std::move(Err)) << "\n";


Index: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -36,6 +36,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Mutex.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Signals.h"
@@ -246,6 +247,7 @@
   llvm::outs() << "Reducing " << USRToBitcode.size() << " infos...\n";
   std::atomic Error;
   Error = false;
+  llvm::sys::Mutex IndexMutex;
   // ExecutorConcurrency is a flag exposed by AllTUsExecution.h
   llvm::ThreadPool Pool(ExecutorConcurrency == 0 ? llvm::hardware_concurrency()
  : ExecutorConcurrency);
@@ -289,8 +291,10 @@
 return;
   }
 
+  IndexMutex.lock();
   // Add a reference to this Info in the Index
   clang::doc::Generator::addInfoToIndex(CDCtx.Idx, I);
+  IndexMutex.unlock();
 
   if (auto Err = G->get()->generateDocForInfo(I, InfoOS, CDCtx))
 llvm::errs() << toString(std::move(Err)) << "\n";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65483: [clang-doc] Add link to source code in file definitions

2019-08-07 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 214004.
DiegoAstiazaran added a comment.

Rebase to master


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65483/new/

https://reviews.llvm.org/D65483

Files:
  clang-tools-extra/clang-doc/BitcodeReader.cpp
  clang-tools-extra/clang-doc/BitcodeWriter.cpp
  clang-tools-extra/clang-doc/HTMLGenerator.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/tool/ClangDocMain.cpp
  clang-tools-extra/docs/clang-doc.rst
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
  clang-tools-extra/unittests/clang-doc/SerializeTest.cpp

Index: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -37,7 +37,7 @@
 
   template  bool mapDecl(const T *D) {
 auto I = serialize::emitInfo(D, getComment(D), /*Line=*/0,
- /*File=*/"test.cpp", Public);
+ /*File=*/"test.cpp", true, Public);
 if (I.first)
   EmittedInfos.emplace_back(std::move(I.first));
 if (I.second)
Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -23,9 +23,9 @@
 }
 
 ClangDocContext
-getClangDocContext(std::vector UserStylesheets = {}) {
-  ClangDocContext CDCtx;
-  CDCtx.UserStylesheets = {UserStylesheets.begin(), UserStylesheets.end()};
+getClangDocContext(std::vector UserStylesheets = {},
+   StringRef RepositoryUrl = "") {
+  ClangDocContext CDCtx{{}, {}, {}, {}, RepositoryUrl, UserStylesheets, {}};
   CDCtx.UserStylesheets.insert(
   CDCtx.UserStylesheets.begin(),
   "../share/clang/clang-doc-default-stylesheet.css");
@@ -127,7 +127,7 @@
   I.Path = "X/Y/Z";
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
 
-  I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
+  I.DefLoc = Location(10, llvm::SmallString<16>{"dir/test.cpp"}, true);
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
   SmallString<16> PathTo;
@@ -147,7 +147,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  ClangDocContext CDCtx = getClangDocContext();
+  ClangDocContext CDCtx = getClangDocContext({}, "http://www.repository.com;);
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
   std::string Expected = R"raw(
@@ -194,7 +194,12 @@
 
 
   class r
-  Defined at line 10 of test.cpp
+  
+Defined at line 
+http://www.repository.com/dir/test.cpp#10;>10
+ of file 
+http://www.repository.com/dir/test.cpp;>test.cpp
+  
   
 Inherits from 
 F
@@ -232,7 +237,7 @@
   I.Name = "f";
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
 
-  I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
+  I.DefLoc = Location(10, llvm::SmallString<16>{"dir/test.cpp"}, false);
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
   SmallString<16> PathTo;
@@ -246,7 +251,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  ClangDocContext CDCtx = getClangDocContext();
+  ClangDocContext CDCtx = getClangDocContext({}, "https://www.repository.com;);
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
   std::string Expected = R"raw(
@@ -263,7 +268,7 @@
 int
  P)
   
-  Defined at line 10 of test.cpp
+  Defined at line 10 of file dir/test.cpp
 
 )raw";
 
@@ -275,7 +280,7 @@
   I.Name = "e";
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
 
-  I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
+  I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"}, true);
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
   I.Members.emplace_back("X");
@@ -285,7 +290,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  ClangDocContext CDCtx = getClangDocContext();
+  ClangDocContext CDCtx = getClangDocContext({}, "www.repository.com");
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
   std::string Expected = R"raw(
@@ -299,7 +304,12 @@
   
 X
   
-  Defined at line 10 of test.cpp
+  
+Defined at line 
+https://www.repository.com/test.cpp#10;>10
+ of file 
+https://www.repository.com/test.cpp;>test.cpp
+  
 
 )raw";
 
@@ -368,7 +378,7 @@
 
   f
   void f(int I, int J)
-  Defined at line 10 of test.cpp
+  Defined at line 10 of file test.cpp
   
 
Brief description.
Index: 

[PATCH] D65483: [clang-doc] Add link to source code in file definitions

2019-08-07 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 214000.
DiegoAstiazaran marked 2 inline comments as done.
DiegoAstiazaran added a comment.

Add comments.
Move definition of ClangDocContext constructor to .cpp file.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65483/new/

https://reviews.llvm.org/D65483

Files:
  clang-tools-extra/clang-doc/BitcodeReader.cpp
  clang-tools-extra/clang-doc/BitcodeWriter.cpp
  clang-tools-extra/clang-doc/HTMLGenerator.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/tool/ClangDocMain.cpp
  clang-tools-extra/docs/clang-doc.rst
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
  clang-tools-extra/unittests/clang-doc/SerializeTest.cpp

Index: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -37,7 +37,7 @@
 
   template  bool mapDecl(const T *D) {
 auto I = serialize::emitInfo(D, getComment(D), /*Line=*/0,
- /*File=*/"test.cpp", Public);
+ /*File=*/"test.cpp", true, Public);
 if (I.first)
   EmittedInfos.emplace_back(std::move(I.first));
 if (I.second)
Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -22,9 +22,9 @@
 }
 
 ClangDocContext
-getClangDocContext(std::vector UserStylesheets = {}) {
-  ClangDocContext CDCtx;
-  CDCtx.UserStylesheets = {UserStylesheets.begin(), UserStylesheets.end()};
+getClangDocContext(std::vector UserStylesheets = {},
+   StringRef RepositoryUrl = "") {
+  ClangDocContext CDCtx{{}, {}, {}, {}, RepositoryUrl, UserStylesheets, {}};
   CDCtx.UserStylesheets.insert(
   CDCtx.UserStylesheets.begin(),
   "../share/clang/clang-doc-default-stylesheet.css");
@@ -90,7 +90,7 @@
   I.Path = "X/Y/Z";
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
 
-  I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
+  I.DefLoc = Location(10, llvm::SmallString<16>{"dir/test.cpp"}, true);
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
   SmallString<16> PathTo;
@@ -110,7 +110,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  ClangDocContext CDCtx = getClangDocContext();
+  ClangDocContext CDCtx = getClangDocContext({}, "http://www.repository.com;);
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
   std::string Expected = R"raw(
@@ -121,7 +121,12 @@
 
 
   class r
-  Defined at line 10 of test.cpp
+  
+Defined at line 
+http://www.repository.com/dir/test.cpp#10;>10
+ of file 
+http://www.repository.com/dir/test.cpp;>test.cpp
+  
   
 Inherits from 
 F
@@ -159,7 +164,7 @@
   I.Name = "f";
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
 
-  I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
+  I.DefLoc = Location(10, llvm::SmallString<16>{"dir/test.cpp"}, false);
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
   SmallString<16> PathTo;
@@ -173,7 +178,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  ClangDocContext CDCtx = getClangDocContext();
+  ClangDocContext CDCtx = getClangDocContext({}, "https://www.repository.com;);
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
   std::string Expected = R"raw(
@@ -190,7 +195,7 @@
 int
  P)
   
-  Defined at line 10 of test.cpp
+  Defined at line 10 of file dir/test.cpp
 
 )raw";
 
@@ -202,7 +207,7 @@
   I.Name = "e";
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
 
-  I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
+  I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"}, true);
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
   I.Members.emplace_back("X");
@@ -212,7 +217,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  ClangDocContext CDCtx = getClangDocContext();
+  ClangDocContext CDCtx = getClangDocContext({}, "www.repository.com");
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
   std::string Expected = R"raw(
@@ -226,7 +231,12 @@
   
 X
   
-  Defined at line 10 of test.cpp
+  
+Defined at line 
+https://www.repository.com/test.cpp#10;>10
+ of file 
+https://www.repository.com/test.cpp;>test.cpp
+  
 
 )raw";
 
@@ -295,7 +305,7 @@
 
   f
   void f(int I, int J)
-  Defined at line 10 

[PATCH] D65030: [clang-doc] Add second index for sections within info's content

2019-08-07 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL368209: [clang-doc] Add second index for sections within 
infos content (authored by DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65030?vs=213991=213992#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65030/new/

https://reviews.llvm.org/D65030

Files:
  clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/trunk/clang-doc/Representation.h
  clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp

Index: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
@@ -270,15 +270,22 @@
   return LinkNode;
 }
 
-static std::unique_ptr genTypeReference(const Reference ,
-  StringRef CurrentDirectory) {
-  if (Type.Path.empty() && !Type.IsInGlobalNamespace)
-return llvm::make_unique(Type.Name);
+static std::unique_ptr
+genTypeReference(const Reference , StringRef CurrentDirectory,
+ llvm::Optional JumpToSection = None) {
+  if (Type.Path.empty() && !Type.IsInGlobalNamespace) {
+if (!JumpToSection)
+  return llvm::make_unique(Type.Name);
+else
+  return genLink(Type.Name, "#" + JumpToSection.getValue());
+  }
   llvm::SmallString<128> Path =
   computeRelativePath(Type.Path, CurrentDirectory);
   llvm::sys::path::append(Path, Type.Name + ".html");
   // Paths in HTML must be in posix-style
   llvm::sys::path::native(Path, llvm::sys::path::Style::posix);
+  if (JumpToSection)
+Path += ("#" + JumpToSection.getValue()).str();
   return genLink(Type.Name, Path);
 }
 
@@ -305,6 +312,7 @@
 
   std::vector> Out;
   Out.emplace_back(llvm::make_unique(HTMLTag::TAG_H2, "Enums"));
+  Out.back()->Attributes.try_emplace("id", "Enums");
   Out.emplace_back(llvm::make_unique(HTMLTag::TAG_DIV));
   auto  = Out.back();
   for (const auto  : Enums) {
@@ -333,6 +341,7 @@
 
   std::vector> Out;
   Out.emplace_back(llvm::make_unique(HTMLTag::TAG_H2, "Functions"));
+  Out.back()->Attributes.try_emplace("id", "Functions");
   Out.emplace_back(llvm::make_unique(HTMLTag::TAG_DIV));
   auto  = Out.back();
   for (const auto  : Functions) {
@@ -350,6 +359,7 @@
 
   std::vector> Out;
   Out.emplace_back(llvm::make_unique(HTMLTag::TAG_H2, "Members"));
+  Out.back()->Attributes.try_emplace("id", "Members");
   Out.emplace_back(llvm::make_unique(HTMLTag::TAG_UL));
   auto  = Out.back();
   for (const auto  : Members) {
@@ -373,6 +383,7 @@
 
   std::vector> Out;
   Out.emplace_back(llvm::make_unique(HTMLTag::TAG_H2, Title));
+  Out.back()->Attributes.try_emplace("id", Title);
   Out.emplace_back(llvm::make_unique(HTMLTag::TAG_UL));
   auto  = Out.back();
   for (const auto  : References)
@@ -409,6 +420,41 @@
   return Out;
 }
 
+template ::value>>
+static Index genInfoIndexItem(const std::vector , StringRef Title) {
+  Index Idx(Title, Title);
+  for (const auto  : Infos)
+Idx.Children.emplace_back(C.extractName(),
+  llvm::toHex(llvm::toStringRef(C.USR)));
+  return Idx;
+}
+
+static std::vector> genHTML(const Index ,
+ StringRef InfoPath) {
+  std::vector> Out;
+  if (!Index.Name.empty()) {
+Out.emplace_back(llvm::make_unique(HTMLTag::TAG_SPAN));
+auto  = Out.back();
+if (!Index.JumpToSection)
+  SpanBody->Children.emplace_back(genTypeReference(Index, InfoPath));
+else
+  SpanBody->Children.emplace_back(genTypeReference(
+  Index, InfoPath, StringRef{Index.JumpToSection.getValue()}));
+  }
+  if (Index.Children.empty())
+return Out;
+  Out.emplace_back(llvm::make_unique(HTMLTag::TAG_UL));
+  const auto  = Out.back();
+  for (const auto  : Index.Children) {
+auto LiBody = llvm::make_unique(HTMLTag::TAG_LI);
+std::vector> Nodes = genHTML(C, InfoPath);
+AppendVector(std::move(Nodes), LiBody->Children);
+UlBody->Children.emplace_back(std::move(LiBody));
+  }
+  return Out;
+}
+
 static std::unique_ptr genHTML(const CommentInfo ) {
   if (I.Kind == "FullComment") {
 auto FullComment = llvm::make_unique(HTMLTag::TAG_DIV);
@@ -455,6 +501,8 @@
 
   Out.emplace_back(
   llvm::make_unique(HTMLTag::TAG_H3, EnumType + I.Name));
+  Out.back()->Attributes.try_emplace("id",
+ llvm::toHex(llvm::toStringRef(I.USR)));
 
   std::unique_ptr Node = genEnumMembersBlock(I.Members);
   if (Node)
@@ -474,6 +522,10 @@
  StringRef ParentInfoDir) {
   std::vector> Out;
   Out.emplace_back(llvm::make_unique(HTMLTag::TAG_H3, I.Name));
+  // USR is used as id for functions instead of name to disambiguate function
+  // 

[PATCH] D65030: [clang-doc] Add second index for sections within info's content

2019-08-07 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 213991.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65030/new/

https://reviews.llvm.org/D65030

Files:
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -9,6 +9,7 @@
 #include "ClangDocTest.h"
 #include "Generators.h"
 #include "Representation.h"
+#include "Serialize.h"
 #include "gtest/gtest.h"
 
 namespace clang {
@@ -59,24 +60,60 @@
 
 
 
+
+  
+
+  Namespaces
+
+  
+  
+
+  Records
+
+  
+  
+
+  Functions
+
+
+  
+
+  OneFunction
+
+  
+
+  
+  
+
+  Enums
+
+
+  
+
+  OneEnum
+
+  
+
+  
+
 
   namespace Namespace
-  Namespaces
+  Namespaces
   
 ChildNamespace
   
-  Records
+  Records
   
 ChildStruct
   
-  Functions
+  Functions
   
-OneFunction
+OneFunction
 OneFunction()
   
-  Enums
+  Enums
   
-enum OneEnum
+enum OneEnum
   
 
 )raw";
@@ -119,6 +156,42 @@
 
 
 
+
+  
+
+  Members
+
+  
+  
+
+  Records
+
+  
+  
+
+  Functions
+
+
+  
+
+  OneFunction
+
+  
+
+  
+  
+
+  Enums
+
+
+  
+
+  OneEnum
+
+  
+
+  
+
 
   class r
   Defined at line 10 of test.cpp
@@ -127,7 +200,7 @@
 F
 , G
   
-  Members
+  Members
   
 
   private 
@@ -135,18 +208,18 @@
X
 
   
-  Records
+  Records
   
 ChildStruct
   
-  Functions
+  Functions
   
-OneFunction
+OneFunction
 OneFunction()
   
-  Enums
+  Enums
   
-enum OneEnum
+enum OneEnum
   
 
 )raw";
@@ -183,7 +256,7 @@
 
 
 
-  f
+  f
   
 float
  f(
@@ -222,7 +295,7 @@
 
 
 
-  enum class e
+  enum class e
   
 X
   
@@ -293,7 +366,7 @@
 
 
 
-  f
+  f
   void f(int I, int J)
   Defined at line 10 of test.cpp
   
Index: clang-tools-extra/clang-doc/Representation.h
===
--- clang-tools-extra/clang-doc/Representation.h
+++ clang-tools-extra/clang-doc/Representation.h
@@ -350,12 +350,15 @@
 
 struct Index : public Reference {
   Index() = default;
+  Index(StringRef Name, StringRef JumpToSection)
+  : Reference(Name), JumpToSection(JumpToSection) {}
   Index(SymbolID USR, StringRef Name, InfoType IT, StringRef Path)
   : Reference(USR, Name, IT, Path) {}
   // This is used to look for a USR in a vector of Indexes using std::find
   bool operator==(const SymbolID ) const { return USR == Other; }
   bool operator<(const Index ) const { return Name < Other.Name; }
 
+  llvm::Optional> JumpToSection;
   std::vector Children;
 
   void sort();
Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -270,15 +270,22 @@
   return LinkNode;
 }
 
-static std::unique_ptr genTypeReference(const Reference ,
-  StringRef CurrentDirectory) {
-  if (Type.Path.empty() && !Type.IsInGlobalNamespace)
-return llvm::make_unique(Type.Name);
+static std::unique_ptr
+genTypeReference(const Reference , StringRef CurrentDirectory,
+ llvm::Optional JumpToSection = None) {
+  if (Type.Path.empty() && !Type.IsInGlobalNamespace) {
+if (!JumpToSection)
+  return llvm::make_unique(Type.Name);
+else
+  return genLink(Type.Name, "#" + JumpToSection.getValue());
+  }
   llvm::SmallString<128> Path =
   computeRelativePath(Type.Path, CurrentDirectory);
   llvm::sys::path::append(Path, Type.Name + ".html");
   // Paths in HTML must be in posix-style
   llvm::sys::path::native(Path, llvm::sys::path::Style::posix);
+  if (JumpToSection)
+Path += ("#" + JumpToSection.getValue()).str();
   return genLink(Type.Name, Path);
 }
 
@@ -305,6 +312,7 @@
 
   std::vector> Out;
   Out.emplace_back(llvm::make_unique(HTMLTag::TAG_H2, "Enums"));
+  Out.back()->Attributes.try_emplace("id", "Enums");
   Out.emplace_back(llvm::make_unique(HTMLTag::TAG_DIV));
   auto  = Out.back();
   for (const auto  : Enums) {
@@ -333,6 +341,7 @@
 
   std::vector> Out;
   Out.emplace_back(llvm::make_unique(HTMLTag::TAG_H2, "Functions"));
+  Out.back()->Attributes.try_emplace("id", "Functions");
   Out.emplace_back(llvm::make_unique(HTMLTag::TAG_DIV));
   auto  = Out.back();
   for (const auto  : Functions) {
@@ -350,6 +359,7 @@
 
   std::vector> Out;
   Out.emplace_back(llvm::make_unique(HTMLTag::TAG_H2, "Members"));
+  

[PATCH] D65628: [clang-doc] Parallelize reducing phase

2019-08-07 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL368206: [clang-doc] Parallelize reducing phase (authored by 
DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65628?vs=213986=213988#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65628/new/

https://reviews.llvm.org/D65628

Files:
  clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp

Index: clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
@@ -28,6 +28,7 @@
 #include "clang/ASTMatchers/ASTMatchersInternal.h"
 #include "clang/Driver/Options.h"
 #include "clang/Frontend/FrontendActions.h"
+#include "clang/Tooling/AllTUsExecution.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/Execution.h"
 #include "clang/Tooling/Tooling.h"
@@ -38,7 +39,9 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Signals.h"
+#include "llvm/Support/ThreadPool.h"
 #include "llvm/Support/raw_ostream.h"
+#include 
 #include 
 
 using namespace clang::ast_matchers;
@@ -158,30 +161,6 @@
   return Path;
 }
 
-// Iterate through tool results and build string map of info vectors from the
-// encoded bitstreams.
-bool bitcodeResultsToInfos(
-tooling::ToolResults ,
-llvm::StringMap>> ) {
-  bool Err = false;
-  Results.forEachResult([&](StringRef Key, StringRef Value) {
-llvm::BitstreamCursor Stream(Value);
-doc::ClangDocBitcodeReader Reader(Stream);
-auto Infos = Reader.readBitcode();
-if (!Infos) {
-  llvm::errs() << toString(Infos.takeError()) << "\n";
-  Err = true;
-  return;
-}
-for (auto  : Infos.get()) {
-  auto R =
-  Output.try_emplace(Key, std::vector>());
-  R.first->second.emplace_back(std::move(I));
-}
-  });
-  return Err;
-}
-
 int main(int argc, const char **argv) {
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
   std::error_code OK;
@@ -256,40 +235,72 @@
   // In ToolResults, the Key is the hashed USR and the value is the
   // bitcode-encoded representation of the Info object.
   llvm::outs() << "Collecting infos...\n";
-  llvm::StringMap>> USRToInfos;
-  if (bitcodeResultsToInfos(*Exec->get()->getToolResults(), USRToInfos))
-return 1;
+  llvm::StringMap> USRToBitcode;
+  Exec->get()->getToolResults()->forEachResult(
+  [&](StringRef Key, StringRef Value) {
+auto R = USRToBitcode.try_emplace(Key, std::vector());
+R.first->second.emplace_back(Value);
+  });
 
   // First reducing phase (reduce all decls into one info per decl).
-  llvm::outs() << "Reducing " << USRToInfos.size() << " infos...\n";
-  for (auto  : USRToInfos) {
-auto Reduced = doc::mergeInfos(Group.getValue());
-if (!Reduced) {
-  llvm::errs() << llvm::toString(Reduced.takeError());
-  continue;
-}
-
-doc::Info *I = Reduced.get().get();
-auto InfoPath = getInfoOutputFile(OutDirectory, I->Path, I->extractName(),
-  "." + Format);
-if (!InfoPath) {
-  llvm::errs() << toString(InfoPath.takeError()) << "\n";
-  return 1;
-}
-std::error_code FileErr;
-llvm::raw_fd_ostream InfoOS(InfoPath.get(), FileErr,
-llvm::sys::fs::OF_None);
-if (FileErr != OK) {
-  llvm::errs() << "Error opening info file: " << FileErr.message() << "\n";
-  continue;
-}
+  llvm::outs() << "Reducing " << USRToBitcode.size() << " infos...\n";
+  std::atomic Error;
+  Error = false;
+  // ExecutorConcurrency is a flag exposed by AllTUsExecution.h
+  llvm::ThreadPool Pool(ExecutorConcurrency == 0 ? llvm::hardware_concurrency()
+ : ExecutorConcurrency);
+  for (auto  : USRToBitcode) {
+Pool.async([&]() {
+  std::vector> Infos;
+
+  for (auto  : Group.getValue()) {
+llvm::BitstreamCursor Stream(Bitcode);
+doc::ClangDocBitcodeReader Reader(Stream);
+auto ReadInfos = Reader.readBitcode();
+if (!ReadInfos) {
+  llvm::errs() << toString(ReadInfos.takeError()) << "\n";
+  Error = true;
+  return;
+}
+std::move(ReadInfos->begin(), ReadInfos->end(),
+  std::back_inserter(Infos));
+  }
+
+  auto Reduced = doc::mergeInfos(Infos);
+  if (!Reduced) {
+llvm::errs() << llvm::toString(Reduced.takeError());
+return;
+  }
+
+  doc::Info *I = Reduced.get().get();
+  auto InfoPath = getInfoOutputFile(OutDirectory, I->Path, I->extractName(),
+"." + Format);
+  if (!InfoPath) {
+llvm::errs() << toString(InfoPath.takeError()) << "\n";
+Error = 

[PATCH] D65628: [clang-doc] Parallelize reducing phase

2019-08-07 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 213986.
DiegoAstiazaran marked an inline comment as done.
DiegoAstiazaran added a comment.

Add comment


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65628/new/

https://reviews.llvm.org/D65628

Files:
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp

Index: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -28,6 +28,7 @@
 #include "clang/ASTMatchers/ASTMatchersInternal.h"
 #include "clang/Driver/Options.h"
 #include "clang/Frontend/FrontendActions.h"
+#include "clang/Tooling/AllTUsExecution.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/Execution.h"
 #include "clang/Tooling/Tooling.h"
@@ -38,7 +39,9 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Signals.h"
+#include "llvm/Support/ThreadPool.h"
 #include "llvm/Support/raw_ostream.h"
+#include 
 #include 
 
 using namespace clang::ast_matchers;
@@ -158,30 +161,6 @@
   return Path;
 }
 
-// Iterate through tool results and build string map of info vectors from the
-// encoded bitstreams.
-bool bitcodeResultsToInfos(
-tooling::ToolResults ,
-llvm::StringMap>> ) {
-  bool Err = false;
-  Results.forEachResult([&](StringRef Key, StringRef Value) {
-llvm::BitstreamCursor Stream(Value);
-doc::ClangDocBitcodeReader Reader(Stream);
-auto Infos = Reader.readBitcode();
-if (!Infos) {
-  llvm::errs() << toString(Infos.takeError()) << "\n";
-  Err = true;
-  return;
-}
-for (auto  : Infos.get()) {
-  auto R =
-  Output.try_emplace(Key, std::vector>());
-  R.first->second.emplace_back(std::move(I));
-}
-  });
-  return Err;
-}
-
 int main(int argc, const char **argv) {
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
   std::error_code OK;
@@ -256,41 +235,73 @@
   // In ToolResults, the Key is the hashed USR and the value is the
   // bitcode-encoded representation of the Info object.
   llvm::outs() << "Collecting infos...\n";
-  llvm::StringMap>> USRToInfos;
-  if (bitcodeResultsToInfos(*Exec->get()->getToolResults(), USRToInfos))
-return 1;
+  llvm::StringMap> USRToBitcode;
+  Exec->get()->getToolResults()->forEachResult(
+  [&](StringRef Key, StringRef Value) {
+auto R = USRToBitcode.try_emplace(Key, std::vector());
+R.first->second.emplace_back(Value);
+  });
 
   // First reducing phase (reduce all decls into one info per decl).
-  llvm::outs() << "Reducing " << USRToInfos.size() << " infos...\n";
-  for (auto  : USRToInfos) {
-auto Reduced = doc::mergeInfos(Group.getValue());
-if (!Reduced) {
-  llvm::errs() << llvm::toString(Reduced.takeError());
-  continue;
-}
+  llvm::outs() << "Reducing " << USRToBitcode.size() << " infos...\n";
+  std::atomic Error;
+  Error = false;
+  // ExecutorConcurrency is a flag exposed by AllTUsExecution.h
+  llvm::ThreadPool Pool(ExecutorConcurrency == 0 ? llvm::hardware_concurrency()
+ : ExecutorConcurrency);
+  for (auto  : USRToBitcode) {
+Pool.async([&]() {
+  std::vector> Infos;
 
-doc::Info *I = Reduced.get().get();
-auto InfoPath = getInfoOutputFile(OutDirectory, I->Path, I->extractName(),
-  "." + Format);
-if (!InfoPath) {
-  llvm::errs() << toString(InfoPath.takeError()) << "\n";
-  return 1;
-}
-std::error_code FileErr;
-llvm::raw_fd_ostream InfoOS(InfoPath.get(), FileErr,
-llvm::sys::fs::OF_None);
-if (FileErr != OK) {
-  llvm::errs() << "Error opening info file: " << FileErr.message() << "\n";
-  continue;
-}
+  for (auto  : Group.getValue()) {
+llvm::BitstreamCursor Stream(Bitcode);
+doc::ClangDocBitcodeReader Reader(Stream);
+auto ReadInfos = Reader.readBitcode();
+if (!ReadInfos) {
+  llvm::errs() << toString(ReadInfos.takeError()) << "\n";
+  Error = true;
+  return;
+}
+std::move(ReadInfos->begin(), ReadInfos->end(),
+  std::back_inserter(Infos));
+  }
 
-// Add a reference to this Info in the Index
-clang::doc::Generator::addInfoToIndex(CDCtx.Idx, I);
+  auto Reduced = doc::mergeInfos(Infos);
+  if (!Reduced) {
+llvm::errs() << llvm::toString(Reduced.takeError());
+return;
+  }
 
-if (auto Err = G->get()->generateDocForInfo(I, InfoOS, CDCtx))
-  llvm::errs() << toString(std::move(Err)) << "\n";
+  doc::Info *I = Reduced.get().get();
+  auto InfoPath = getInfoOutputFile(OutDirectory, I->Path, I->extractName(),
+"." + Format);
+  if (!InfoPath) {
+llvm::errs() << toString(InfoPath.takeError()) << "\n";
+Error = true;
+  

[PATCH] D65628: [clang-doc] Parallelize reducing phase

2019-08-07 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran added inline comments.



Comment at: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp:72
 
+static llvm::cl::opt ThreadCount(
+"thread-count",

juliehockett wrote:
> Can we use the pre-existing concurrency flag instead 
> (https://github.com/llvm/llvm-project/blob/91e5cdfc93729c61c757db4efd4a82670ac7f929/clang/lib/Tooling/AllTUsExecution.cpp#L150)?
>  It seems counterintuitive to have to set two different concurrency flags for 
> one tool.
> 
> You'll have to put up a separate patch to expose that flag in the AllTUs 
> header, so that you can access it (see rL344335, as an example). 
Done in D65833.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65628/new/

https://reviews.llvm.org/D65628



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


[PATCH] D65628: [clang-doc] Parallelize reducing phase

2019-08-07 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 213968.
DiegoAstiazaran marked 2 inline comments as done.
DiegoAstiazaran added a comment.

Use pre-existing concurrency flag `--execute-concurrency` instead implementing 
a new one.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65628/new/

https://reviews.llvm.org/D65628

Files:
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp

Index: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -28,6 +28,7 @@
 #include "clang/ASTMatchers/ASTMatchersInternal.h"
 #include "clang/Driver/Options.h"
 #include "clang/Frontend/FrontendActions.h"
+#include "clang/Tooling/AllTUsExecution.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/Execution.h"
 #include "clang/Tooling/Tooling.h"
@@ -38,7 +39,9 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Signals.h"
+#include "llvm/Support/ThreadPool.h"
 #include "llvm/Support/raw_ostream.h"
+#include 
 #include 
 
 using namespace clang::ast_matchers;
@@ -158,30 +161,6 @@
   return Path;
 }
 
-// Iterate through tool results and build string map of info vectors from the
-// encoded bitstreams.
-bool bitcodeResultsToInfos(
-tooling::ToolResults ,
-llvm::StringMap>> ) {
-  bool Err = false;
-  Results.forEachResult([&](StringRef Key, StringRef Value) {
-llvm::BitstreamCursor Stream(Value);
-doc::ClangDocBitcodeReader Reader(Stream);
-auto Infos = Reader.readBitcode();
-if (!Infos) {
-  llvm::errs() << toString(Infos.takeError()) << "\n";
-  Err = true;
-  return;
-}
-for (auto  : Infos.get()) {
-  auto R =
-  Output.try_emplace(Key, std::vector>());
-  R.first->second.emplace_back(std::move(I));
-}
-  });
-  return Err;
-}
-
 int main(int argc, const char **argv) {
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
   std::error_code OK;
@@ -256,41 +235,72 @@
   // In ToolResults, the Key is the hashed USR and the value is the
   // bitcode-encoded representation of the Info object.
   llvm::outs() << "Collecting infos...\n";
-  llvm::StringMap>> USRToInfos;
-  if (bitcodeResultsToInfos(*Exec->get()->getToolResults(), USRToInfos))
-return 1;
+  llvm::StringMap> USRToBitcode;
+  Exec->get()->getToolResults()->forEachResult(
+  [&](StringRef Key, StringRef Value) {
+auto R = USRToBitcode.try_emplace(Key, std::vector());
+R.first->second.emplace_back(Value);
+  });
 
   // First reducing phase (reduce all decls into one info per decl).
-  llvm::outs() << "Reducing " << USRToInfos.size() << " infos...\n";
-  for (auto  : USRToInfos) {
-auto Reduced = doc::mergeInfos(Group.getValue());
-if (!Reduced) {
-  llvm::errs() << llvm::toString(Reduced.takeError());
-  continue;
-}
+  llvm::outs() << "Reducing " << USRToBitcode.size() << " infos...\n";
+  std::atomic Error;
+  Error = false;
+  llvm::ThreadPool Pool(ExecutorConcurrency == 0 ? llvm::hardware_concurrency()
+ : ExecutorConcurrency);
+  for (auto  : USRToBitcode) {
+Pool.async([&]() {
+  std::vector> Infos;
 
-doc::Info *I = Reduced.get().get();
-auto InfoPath = getInfoOutputFile(OutDirectory, I->Path, I->extractName(),
-  "." + Format);
-if (!InfoPath) {
-  llvm::errs() << toString(InfoPath.takeError()) << "\n";
-  return 1;
-}
-std::error_code FileErr;
-llvm::raw_fd_ostream InfoOS(InfoPath.get(), FileErr,
-llvm::sys::fs::OF_None);
-if (FileErr != OK) {
-  llvm::errs() << "Error opening info file: " << FileErr.message() << "\n";
-  continue;
-}
+  for (auto  : Group.getValue()) {
+llvm::BitstreamCursor Stream(Bitcode);
+doc::ClangDocBitcodeReader Reader(Stream);
+auto ReadInfos = Reader.readBitcode();
+if (!ReadInfos) {
+  llvm::errs() << toString(ReadInfos.takeError()) << "\n";
+  Error = true;
+  return;
+}
+std::move(ReadInfos->begin(), ReadInfos->end(),
+  std::back_inserter(Infos));
+  }
 
-// Add a reference to this Info in the Index
-clang::doc::Generator::addInfoToIndex(CDCtx.Idx, I);
+  auto Reduced = doc::mergeInfos(Infos);
+  if (!Reduced) {
+llvm::errs() << llvm::toString(Reduced.takeError());
+return;
+  }
 
-if (auto Err = G->get()->generateDocForInfo(I, InfoOS, CDCtx))
-  llvm::errs() << toString(std::move(Err)) << "\n";
+  doc::Info *I = Reduced.get().get();
+  auto InfoPath = getInfoOutputFile(OutDirectory, I->Path, I->extractName(),
+"." + Format);
+  if (!InfoPath) {
+llvm::errs() << toString(InfoPath.takeError()) << "\n";
+

[PATCH] D65833: [Tooling] Expose ExecutorConcurrency option.

2019-08-07 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL368196: [Tooling] Expose ExecutorConcurrency option. 
(authored by DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65833?vs=213745=213959#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65833/new/

https://reviews.llvm.org/D65833

Files:
  cfe/trunk/include/clang/Tooling/AllTUsExecution.h
  cfe/trunk/lib/Tooling/AllTUsExecution.cpp


Index: cfe/trunk/include/clang/Tooling/AllTUsExecution.h
===
--- cfe/trunk/include/clang/Tooling/AllTUsExecution.h
+++ cfe/trunk/include/clang/Tooling/AllTUsExecution.h
@@ -71,6 +71,7 @@
   unsigned ThreadCount;
 };
 
+extern llvm::cl::opt ExecutorConcurrency;
 extern llvm::cl::opt Filter;
 
 } // end namespace tooling
Index: cfe/trunk/lib/Tooling/AllTUsExecution.cpp
===
--- cfe/trunk/lib/Tooling/AllTUsExecution.cpp
+++ cfe/trunk/lib/Tooling/AllTUsExecution.cpp
@@ -147,7 +147,7 @@
   return llvm::Error::success();
 }
 
-static llvm::cl::opt ExecutorConcurrency(
+llvm::cl::opt ExecutorConcurrency(
 "execute-concurrency",
 llvm::cl::desc("The number of threads used to process all files in "
"parallel. Set to 0 for hardware concurrency. "


Index: cfe/trunk/include/clang/Tooling/AllTUsExecution.h
===
--- cfe/trunk/include/clang/Tooling/AllTUsExecution.h
+++ cfe/trunk/include/clang/Tooling/AllTUsExecution.h
@@ -71,6 +71,7 @@
   unsigned ThreadCount;
 };
 
+extern llvm::cl::opt ExecutorConcurrency;
 extern llvm::cl::opt Filter;
 
 } // end namespace tooling
Index: cfe/trunk/lib/Tooling/AllTUsExecution.cpp
===
--- cfe/trunk/lib/Tooling/AllTUsExecution.cpp
+++ cfe/trunk/lib/Tooling/AllTUsExecution.cpp
@@ -147,7 +147,7 @@
   return llvm::Error::success();
 }
 
-static llvm::cl::opt ExecutorConcurrency(
+llvm::cl::opt ExecutorConcurrency(
 "execute-concurrency",
 llvm::cl::desc("The number of threads used to process all files in "
"parallel. Set to 0 for hardware concurrency. "
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65483: [clang-doc] Add link to source code in file definitions

2019-08-06 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 213776.
DiegoAstiazaran added a comment.

Remove unnecessary type casting.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65483/new/

https://reviews.llvm.org/D65483

Files:
  clang-tools-extra/clang-doc/BitcodeReader.cpp
  clang-tools-extra/clang-doc/BitcodeWriter.cpp
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/Mapper.cpp
  clang-tools-extra/clang-doc/Mapper.h
  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/tool/ClangDocMain.cpp
  clang-tools-extra/docs/clang-doc.rst
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
  clang-tools-extra/unittests/clang-doc/SerializeTest.cpp

Index: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -37,7 +37,7 @@
 
   template  bool mapDecl(const T *D) {
 auto I = serialize::emitInfo(D, getComment(D), /*Line=*/0,
- /*File=*/"test.cpp", Public);
+ /*File=*/"test.cpp", true, Public);
 if (I.first)
   EmittedInfos.emplace_back(std::move(I.first));
 if (I.second)
Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -22,9 +22,9 @@
 }
 
 ClangDocContext
-getClangDocContext(std::vector UserStylesheets = {}) {
-  ClangDocContext CDCtx;
-  CDCtx.UserStylesheets = {UserStylesheets.begin(), UserStylesheets.end()};
+getClangDocContext(std::vector UserStylesheets = {},
+   StringRef RepositoryUrl = "") {
+  ClangDocContext CDCtx{{}, {}, {}, {}, RepositoryUrl, UserStylesheets, {}};
   CDCtx.UserStylesheets.insert(
   CDCtx.UserStylesheets.begin(),
   "../share/clang/clang-doc-default-stylesheet.css");
@@ -90,7 +90,7 @@
   I.Path = "X/Y/Z";
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
 
-  I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
+  I.DefLoc = Location(10, llvm::SmallString<16>{"dir/test.cpp"}, true);
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
   SmallString<16> PathTo;
@@ -110,7 +110,8 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  ClangDocContext CDCtx = getClangDocContext();
+  ClangDocContext CDCtx =
+  getClangDocContext({}, "http://www.repository.com;);
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
   std::string Expected = R"raw(
@@ -121,7 +122,12 @@
 
 
   class r
-  Defined at line 10 of test.cpp
+  
+Defined at line 
+http://www.repository.com/dir/test.cpp#10;>10
+ of file 
+http://www.repository.com/dir/test.cpp;>test.cpp
+  
   
 Inherits from 
 F
@@ -159,7 +165,7 @@
   I.Name = "f";
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
 
-  I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
+  I.DefLoc = Location(10, llvm::SmallString<16>{"dir/test.cpp"}, false);
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
   SmallString<16> PathTo;
@@ -173,7 +179,8 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  ClangDocContext CDCtx = getClangDocContext();
+  ClangDocContext CDCtx =
+  getClangDocContext({}, "https://www.repository.com;);
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
   std::string Expected = R"raw(
@@ -190,7 +197,7 @@
 int
  P)
   
-  Defined at line 10 of test.cpp
+  Defined at line 10 of file dir/test.cpp
 
 )raw";
 
@@ -202,7 +209,7 @@
   I.Name = "e";
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
 
-  I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
+  I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"}, true);
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
   I.Members.emplace_back("X");
@@ -212,7 +219,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  ClangDocContext CDCtx = getClangDocContext();
+  ClangDocContext CDCtx = getClangDocContext({}, "www.repository.com");
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
   std::string Expected = R"raw(
@@ -226,7 +233,12 @@
   
 X
   
-  Defined at line 10 of test.cpp
+  
+Defined at line 
+https://www.repository.com/test.cpp#10;>10
+ of file 
+https://www.repository.com/test.cpp;>test.cpp
+  
 
 )raw";
 
@@ -295,7 +307,7 @@
 
   f
   void f(int I, int J)
-  Defined at line 10 of test.cpp
+  Defined at line 10 of file test.cpp
   
 
Brief description.
Index: 

[PATCH] D65483: [clang-doc] Add link to source code in file definitions

2019-08-06 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran added inline comments.



Comment at: clang-tools-extra/docs/clang-doc.rst:93
+--public- Document only public declarations.
+--repository=   -
+  URL of repository that hosts code.

juliehockett wrote:
> Formatting here is a bit weird
Do you mean the almost empty line that's only "-"? This is because the 
description of the flag starts with \n.
```R"(
URL of repository that hosts code.
Used for links to definition locations.)"```
I used the same format used by [[ https://clang.llvm.org/extra/clang-tidy/ | 
clang-tidy ]], it has this format for all the multi-line flag descriptions.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65483/new/

https://reviews.llvm.org/D65483



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


[PATCH] D65483: [clang-doc] Add link to source code in file definitions

2019-08-06 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 213772.
DiegoAstiazaran marked 7 inline comments as done.
DiegoAstiazaran edited the summary of this revision.
DiegoAstiazaran added a comment.

Add comments.
Change name of flag; `root-directory` -> `--source-root`
Moved fixing of repository link to ClangDocContext constructor and add test 
where the prefix is omitted.
RepositoryLink in ClangDocContext struct and writeFileDefinition function is 
now llvm::Optional<>


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65483/new/

https://reviews.llvm.org/D65483

Files:
  clang-tools-extra/clang-doc/BitcodeReader.cpp
  clang-tools-extra/clang-doc/BitcodeWriter.cpp
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/Mapper.cpp
  clang-tools-extra/clang-doc/Mapper.h
  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/tool/ClangDocMain.cpp
  clang-tools-extra/docs/clang-doc.rst
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
  clang-tools-extra/unittests/clang-doc/SerializeTest.cpp

Index: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -37,7 +37,7 @@
 
   template  bool mapDecl(const T *D) {
 auto I = serialize::emitInfo(D, getComment(D), /*Line=*/0,
- /*File=*/"test.cpp", Public);
+ /*File=*/"test.cpp", true, Public);
 if (I.first)
   EmittedInfos.emplace_back(std::move(I.first));
 if (I.second)
Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -22,9 +22,9 @@
 }
 
 ClangDocContext
-getClangDocContext(std::vector UserStylesheets = {}) {
-  ClangDocContext CDCtx;
-  CDCtx.UserStylesheets = {UserStylesheets.begin(), UserStylesheets.end()};
+getClangDocContext(std::vector UserStylesheets = {},
+   StringRef RepositoryUrl = "") {
+  ClangDocContext CDCtx{{}, {}, {}, {}, RepositoryUrl, UserStylesheets, {}};
   CDCtx.UserStylesheets.insert(
   CDCtx.UserStylesheets.begin(),
   "../share/clang/clang-doc-default-stylesheet.css");
@@ -90,7 +90,7 @@
   I.Path = "X/Y/Z";
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
 
-  I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
+  I.DefLoc = Location(10, llvm::SmallString<16>{"dir/test.cpp"}, true);
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
   SmallString<16> PathTo;
@@ -110,7 +110,8 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  ClangDocContext CDCtx = getClangDocContext();
+  ClangDocContext CDCtx =
+  getClangDocContext({}, StringRef{"http://www.repository.com"});
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
   std::string Expected = R"raw(
@@ -121,7 +122,12 @@
 
 
   class r
-  Defined at line 10 of test.cpp
+  
+Defined at line 
+http://www.repository.com/dir/test.cpp#10;>10
+ of file 
+http://www.repository.com/dir/test.cpp;>test.cpp
+  
   
 Inherits from 
 F
@@ -159,7 +165,7 @@
   I.Name = "f";
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
 
-  I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
+  I.DefLoc = Location(10, llvm::SmallString<16>{"dir/test.cpp"}, false);
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
   SmallString<16> PathTo;
@@ -173,7 +179,8 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  ClangDocContext CDCtx = getClangDocContext();
+  ClangDocContext CDCtx =
+  getClangDocContext({}, StringRef{"https://www.repository.com"});
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
   std::string Expected = R"raw(
@@ -190,7 +197,7 @@
 int
  P)
   
-  Defined at line 10 of test.cpp
+  Defined at line 10 of file dir/test.cpp
 
 )raw";
 
@@ -202,7 +209,7 @@
   I.Name = "e";
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
 
-  I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
+  I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"}, true);
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
   I.Members.emplace_back("X");
@@ -212,7 +219,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  ClangDocContext CDCtx = getClangDocContext();
+  ClangDocContext CDCtx = getClangDocContext({}, "www.repository.com");
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
   std::string Expected = R"raw(
@@ -226,7 +233,12 @@
   
 X
   
-  Defined at line 10 

[PATCH] D65833: [Tooling] Expose ExecutorConcurrency option.

2019-08-06 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran created this revision.
DiegoAstiazaran added a reviewer: juliehockett.

https://reviews.llvm.org/D65833

Files:
  clang/include/clang/Tooling/AllTUsExecution.h
  clang/lib/Tooling/AllTUsExecution.cpp


Index: clang/lib/Tooling/AllTUsExecution.cpp
===
--- clang/lib/Tooling/AllTUsExecution.cpp
+++ clang/lib/Tooling/AllTUsExecution.cpp
@@ -147,7 +147,7 @@
   return llvm::Error::success();
 }
 
-static llvm::cl::opt ExecutorConcurrency(
+llvm::cl::opt ExecutorConcurrency(
 "execute-concurrency",
 llvm::cl::desc("The number of threads used to process all files in "
"parallel. Set to 0 for hardware concurrency. "
Index: clang/include/clang/Tooling/AllTUsExecution.h
===
--- clang/include/clang/Tooling/AllTUsExecution.h
+++ clang/include/clang/Tooling/AllTUsExecution.h
@@ -71,6 +71,7 @@
   unsigned ThreadCount;
 };
 
+extern llvm::cl::opt ExecutorConcurrency;
 extern llvm::cl::opt Filter;
 
 } // end namespace tooling


Index: clang/lib/Tooling/AllTUsExecution.cpp
===
--- clang/lib/Tooling/AllTUsExecution.cpp
+++ clang/lib/Tooling/AllTUsExecution.cpp
@@ -147,7 +147,7 @@
   return llvm::Error::success();
 }
 
-static llvm::cl::opt ExecutorConcurrency(
+llvm::cl::opt ExecutorConcurrency(
 "execute-concurrency",
 llvm::cl::desc("The number of threads used to process all files in "
"parallel. Set to 0 for hardware concurrency. "
Index: clang/include/clang/Tooling/AllTUsExecution.h
===
--- clang/include/clang/Tooling/AllTUsExecution.h
+++ clang/include/clang/Tooling/AllTUsExecution.h
@@ -71,6 +71,7 @@
   unsigned ThreadCount;
 };
 
+extern llvm::cl::opt ExecutorConcurrency;
 extern llvm::cl::opt Filter;
 
 } // end namespace tooling
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65827: [clang-doc] Fix paths of js in import tags

2019-08-06 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL368087: [clang-doc] Fix paths of js in import tags (authored 
by DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65827?vs=213710=213714#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65827/new/

https://reviews.llvm.org/D65827

Files:
  clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp


Index: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
@@ -256,6 +256,8 @@
 auto ScriptNode = llvm::make_unique(HTMLTag::TAG_SCRIPT);
 SmallString<128> ScriptPath = computeRelativePath("", InfoPath);
 llvm::sys::path::append(ScriptPath, llvm::sys::path::filename(FilePath));
+// Paths in HTML must be in posix-style
+llvm::sys::path::native(ScriptPath, llvm::sys::path::Style::posix);
 ScriptNode->Attributes.try_emplace("src", ScriptPath);
 Out.emplace_back(std::move(ScriptNode));
   }


Index: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
@@ -256,6 +256,8 @@
 auto ScriptNode = llvm::make_unique(HTMLTag::TAG_SCRIPT);
 SmallString<128> ScriptPath = computeRelativePath("", InfoPath);
 llvm::sys::path::append(ScriptPath, llvm::sys::path::filename(FilePath));
+// Paths in HTML must be in posix-style
+llvm::sys::path::native(ScriptPath, llvm::sys::path::Style::posix);
 ScriptNode->Attributes.try_emplace("src", ScriptPath);
 Out.emplace_back(std::move(ScriptNode));
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65827: [clang-doc] Fix paths of js in import tags

2019-08-06 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran created this revision.
DiegoAstiazaran added a reviewer: juliehockett.
DiegoAstiazaran added a project: clang-tools-extra.
juliehockett accepted this revision.
juliehockett added a comment.
This revision is now accepted and ready to land.

LGTM (let's make sure we double check this next time)


HTML requires posix-style paths.


https://reviews.llvm.org/D65827

Files:
  clang-tools-extra/clang-doc/HTMLGenerator.cpp


Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -256,6 +256,8 @@
 auto ScriptNode = llvm::make_unique(HTMLTag::TAG_SCRIPT);
 SmallString<128> ScriptPath = computeRelativePath("", InfoPath);
 llvm::sys::path::append(ScriptPath, llvm::sys::path::filename(FilePath));
+// Paths in HTML must be in posix-style
+llvm::sys::path::native(ScriptPath, llvm::sys::path::Style::posix);
 ScriptNode->Attributes.try_emplace("src", ScriptPath);
 Out.emplace_back(std::move(ScriptNode));
   }


Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -256,6 +256,8 @@
 auto ScriptNode = llvm::make_unique(HTMLTag::TAG_SCRIPT);
 SmallString<128> ScriptPath = computeRelativePath("", InfoPath);
 llvm::sys::path::append(ScriptPath, llvm::sys::path::filename(FilePath));
+// Paths in HTML must be in posix-style
+llvm::sys::path::native(ScriptPath, llvm::sys::path::Style::posix);
 ScriptNode->Attributes.try_emplace("src", ScriptPath);
 Out.emplace_back(std::move(ScriptNode));
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65030: [clang-doc] Add second index for sections within info's content

2019-08-06 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 213706.
DiegoAstiazaran added a comment.

Changed `JumpToSection` in Index struct and `genHTML(const Index , ...)` 
function to `llvm::Optional`.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65030/new/

https://reviews.llvm.org/D65030

Files:
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -9,6 +9,7 @@
 #include "ClangDocTest.h"
 #include "Generators.h"
 #include "Representation.h"
+#include "Serialize.h"
 #include "gtest/gtest.h"
 
 namespace clang {
@@ -59,24 +60,60 @@
 
 
 
+
+  
+
+  Namespaces
+
+  
+  
+
+  Records
+
+  
+  
+
+  Functions
+
+
+  
+
+  OneFunction
+
+  
+
+  
+  
+
+  Enums
+
+
+  
+
+  OneEnum
+
+  
+
+  
+
 
   namespace Namespace
-  Namespaces
+  Namespaces
   
 ChildNamespace
   
-  Records
+  Records
   
 ChildStruct
   
-  Functions
+  Functions
   
-OneFunction
+OneFunction
 OneFunction()
   
-  Enums
+  Enums
   
-enum OneEnum
+enum OneEnum
   
 
 )raw";
@@ -119,6 +156,42 @@
 
 
 
+
+  
+
+  Members
+
+  
+  
+
+  Records
+
+  
+  
+
+  Functions
+
+
+  
+
+  OneFunction
+
+  
+
+  
+  
+
+  Enums
+
+
+  
+
+  OneEnum
+
+  
+
+  
+
 
   class r
   Defined at line 10 of test.cpp
@@ -127,7 +200,7 @@
 F
 , G
   
-  Members
+  Members
   
 
   private 
@@ -135,18 +208,18 @@
X
 
   
-  Records
+  Records
   
 ChildStruct
   
-  Functions
+  Functions
   
-OneFunction
+OneFunction
 OneFunction()
   
-  Enums
+  Enums
   
-enum OneEnum
+enum OneEnum
   
 
 )raw";
@@ -155,26 +228,39 @@
 }
 
 TEST(HTMLGeneratorTest, emitFunctionHTML) {
+  llvm::errs() << "1\n";
   FunctionInfo I;
+  llvm::errs() << "2\n";
   I.Name = "f";
+  llvm::errs() << "3\n";
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
 
+  llvm::errs() << "4\n";
   I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
+  llvm::errs() << "5\n";
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
-
+  llvm::errs() << "6\n";
   SmallString<16> PathTo;
+  llvm::errs() << "7\n";
   llvm::sys::path::native("path/to", PathTo);
+  llvm::errs() << "8\n";
   I.ReturnType = TypeInfo(EmptySID, "float", InfoType::IT_default, PathTo);
+  llvm::errs() << "9\n";
   I.Params.emplace_back("int", PathTo, "P");
+  llvm::errs() << "1\n";
   I.IsMethod = true;
+  llvm::errs() << "2\n";
   I.Parent = Reference(EmptySID, "Parent", InfoType::IT_record);
+  llvm::errs() << "3\n";
 
   auto G = getHTMLGenerator();
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
   ClangDocContext CDCtx = getClangDocContext();
+  llvm::errs() << "4\n";
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
+  llvm::errs() << "5\n";
   assert(!Err);
   std::string Expected = R"raw(
 
@@ -183,7 +269,7 @@
 
 
 
-  f
+  f
   
 float
  f(
@@ -193,8 +279,10 @@
   Defined at line 10 of test.cpp
 
 )raw";
+  llvm::errs() << "6\n";
 
   EXPECT_EQ(Expected, Actual.str());
+  llvm::errs() << "7\n";
 }
 
 TEST(HTMLGeneratorTest, emitEnumHTML) {
@@ -222,7 +310,7 @@
 
 
 
-  enum class e
+  enum class e
   
 X
   
@@ -293,7 +381,7 @@
 
 
 
-  f
+  f
   void f(int I, int J)
   Defined at line 10 of test.cpp
   
Index: clang-tools-extra/clang-doc/Representation.h
===
--- clang-tools-extra/clang-doc/Representation.h
+++ clang-tools-extra/clang-doc/Representation.h
@@ -350,12 +350,15 @@
 
 struct Index : public Reference {
   Index() = default;
+  Index(StringRef Name, StringRef JumpToSection)
+  : Reference(Name), JumpToSection(JumpToSection) {}
   Index(SymbolID USR, StringRef Name, InfoType IT, StringRef Path)
   : Reference(USR, Name, IT, Path) {}
   // This is used to look for a USR in a vector of Indexes using std::find
   bool operator==(const SymbolID ) const { return USR == Other; }
   bool operator<(const Index ) const { return Name < Other.Name; }
 
+  llvm::Optional> JumpToSection;
   std::vector Children;
 
   void sort();
Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -268,15 +268,22 @@
   return LinkNode;
 }
 
-static std::unique_ptr genTypeReference(const Reference ,
-  

[PATCH] D65690: [clang-doc] Add index in each info html file

2019-08-06 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL368070: [clang-doc] Add index in each info html file 
(authored by DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65690?vs=213513=213669#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65690/new/

https://reviews.llvm.org/D65690

Files:
  clang-tools-extra/trunk/clang-doc/Generators.cpp
  clang-tools-extra/trunk/clang-doc/Generators.h
  clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/trunk/clang-doc/MDGenerator.cpp
  clang-tools-extra/trunk/clang-doc/Representation.cpp
  clang-tools-extra/trunk/clang-doc/Representation.h
  clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/trunk/clang-doc/assets/clang-doc-default-stylesheet.css
  clang-tools-extra/trunk/clang-doc/assets/index.js
  clang-tools-extra/trunk/clang-doc/stylesheets/clang-doc-default-stylesheet.css
  clang-tools-extra/trunk/clang-doc/tool/CMakeLists.txt
  clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/trunk/unittests/clang-doc/CMakeLists.txt
  clang-tools-extra/trunk/unittests/clang-doc/ClangDocTest.cpp
  clang-tools-extra/trunk/unittests/clang-doc/ClangDocTest.h
  clang-tools-extra/trunk/unittests/clang-doc/GeneratorTest.cpp
  clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp

Index: clang-tools-extra/trunk/clang-doc/assets/clang-doc-default-stylesheet.css
===
--- clang-tools-extra/trunk/clang-doc/assets/clang-doc-default-stylesheet.css
+++ clang-tools-extra/trunk/clang-doc/assets/clang-doc-default-stylesheet.css
@@ -0,0 +1,205 @@
+body,div {
+  margin: 0;
+  padding: 0;
+}
+
+body[no-overflow] {
+  overflow: hidden;
+}
+
+li>p:first-child {
+  margin-top: 0;
+}
+
+li>p:last-child {
+  margin-bottom: 0;
+}
+
+html {
+  -webkit-box-sizing: border-box;
+  box-sizing: border-box;
+}
+
+*,*::before,*::after {
+  -webkit-box-sizing: inherit;
+  box-sizing: inherit;
+}
+
+body,html {
+  color: #202124;
+  font: 400 16px/24px Roboto,sans-serif;
+  -moz-osx-font-smoothing: grayscale;
+  -webkit-font-smoothing: antialiased;
+  height: 100%;
+  margin: 36px;
+  -webkit-text-size-adjust: 100%;
+  -moz-text-size-adjust: 100%;
+  -ms-text-size-adjust: 100%;
+  text-size-adjust: 100%;
+}
+
+body[devsite-framebox] {
+  overflow: hidden;
+  padding: 20px;
+}
+
+body[sitemask--active] {
+  overflow: hidden;
+}
+
+p {
+  margin: 16px 0;
+  padding: 0;
+}
+
+:link,:visited {
+  color: #039be5;
+  outline: 0;
+  text-decoration: none;
+}
+
+ul {
+  margin: 0;
+  padding-left: 40px;
+}
+
+ul {
+  list-style: disc outside;
+}
+
+li,li p {
+  margin: 12px 0;
+  padding: 0;
+}
+
+*[visually-hidden] {
+  opacity: 0 !important;
+  pointer-events: none !important;
+  visibility: hidden !important;
+}
+
+*[hidden] {
+  display: none !important;
+}
+
+[render-hidden] {
+  display: inline !important;
+  position: absolute !important;
+  visibility: hidden !important;
+}
+
+*[no-scroll] {
+  overflow: hidden;
+}
+
+@supports (display: flex) {
+  body[ready] .devsite-wrapper {
+display: -webkit-box;
+display: -ms-flexbox;
+display: flex;
+-webkit-box-orient: vertical;
+-webkit-box-direction: normal;
+-ms-flex-direction: column;
+flex-direction: column;
+  }
+}
+
+@media screen and (max-width: 840px) {
+  body[devsite-book-nav--open] {
+overflow: hidden;
+  }
+}
+
+h1,h2,h3,h4,h5,h6 {
+  overflow: hidden;
+  padding: 0;
+  text-overflow: ellipsis;
+}
+
+h1 {
+  color: #80868b;
+  font: 300 34px/40px Roboto,sans-serif;
+  letter-spacing: -0.01em;
+  margin: 40px 0 20px;
+}
+
+[layout=docs] h2 {
+  border-bottom: 1px solid #e8eaed;
+  padding-bottom: 3px;
+}
+
+h2 {
+  font: 300 24px/32px Roboto,sans-serif;
+  letter-spacing: -0.01em;
+  margin: 40px 0 20px;
+}
+
+h3 {
+  font: 400 20px/32px Roboto,sans-serif;
+  margin: 32px 0 16px;
+}
+
+h4,h5,h6 {
+  margin: 32px 0 16px;
+}
+
+h4 {
+  font: 500 16px/24px Roboto,sans-serif;
+}
+
+h5 {
+  font: 700 14px/24px Roboto,sans-serif;
+}
+
+h6 {
+  font: 500 14px/24px Roboto,sans-serif;
+}
+
+h1+h1,h1+h2,h1+h3,h1+h4,h1+h5,h1+h6,h2+h1,h2+h2,h2+h3,h2+h4,h2+h5,h2+h6,h3+h1,h3+h2,h3+h3,h3+h4,h3+h5,h3+h6,h4+h1,h4+h2,h4+h3,h4+h4,h4+h5,h4+h6,h5+h1,h5+h2,h5+h3,h5+h4,h5+h5,h5+h6,h6+h1,h6+h2,h6+h3,h6+h4,h6+h5,h6+h6 {
+  margin-top: 0;
+}
+
+@media screen and (max-width: 600px) {
+  h1 {
+font: 300 24px/32px Roboto,sans-serif;
+  }
+}
+
+[scrollbars]::-webkit-scrollbar {
+  height: 8px;
+  width: 8px;
+}
+
+[scrollbars]::-webkit-scrollbar-thumb {
+  background: rgba(128,134,139,.26);
+  border-radius: 8px;
+}
+
+[no-horizontal-scrollbars]::-webkit-scrollbar {
+  height: 0;
+  width: 0;
+}
+
+[scrollbars]::-webkit-scrollbar-corner {
+  background: 0;
+}
+
+[background] h2 {
+  color: #fff;
+}
+
+@media print {
+  body,  html,  

[PATCH] D65690: [clang-doc] Add index in each info html file

2019-08-05 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran added inline comments.



Comment at: clang-tools-extra/clang-doc/Generators.cpp:79
+
+bool Generator::createResources(ClangDocContext ) {
+  std::error_code OK;

juliehockett wrote:
> Why is this implementation in the generic Generator? It's fairly 
> HTML-specific -- neither of the other generators are able to parse and 
> include Javascript (since this does include the `var JsonIndex` bit).
Moved to HTMLGenerator.cpp; it was there because I was first writing a JSON 
file which could be used for any generator.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65690/new/

https://reviews.llvm.org/D65690



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


[PATCH] D65030: [clang-doc] Add second index for sections within info's content

2019-08-05 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran added inline comments.



Comment at: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp:47-52
+
+  Namespaces
+  Records
+  Functions
+  OneFunction
+

juliehockett wrote:
> DiegoAstiazaran wrote:
> > juliehockett wrote:
> > > Formatting is a bit weird for sublists
> > Fixed by D65005. It will be properly formatted after rebasing.
> This formatting is still a bit weird :( The inner `ul` didn't get its own 
> newline, so it's hard to tell which list each item is part of. Not a huge 
> problem, but if it's a reasonably small fix I'd love to see it cleaned up.
I had not rebased.
I rebased in the last version of this patch and the index is rendered as D65005.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65030/new/

https://reviews.llvm.org/D65030



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


[PATCH] D65690: [clang-doc] Add index in each info html file

2019-08-05 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 213513.
DiegoAstiazaran marked 3 inline comments as done.
DiegoAstiazaran added a comment.

Moved serialization of Index to HTML generator.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65690/new/

https://reviews.llvm.org/D65690

Files:
  clang-tools-extra/clang-doc/Generators.cpp
  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/Representation.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/clang-doc/assets/clang-doc-default-stylesheet.css
  clang-tools-extra/clang-doc/assets/index.js
  clang-tools-extra/clang-doc/stylesheets/clang-doc-default-stylesheet.css
  clang-tools-extra/clang-doc/tool/CMakeLists.txt
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/unittests/clang-doc/CMakeLists.txt
  clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
  clang-tools-extra/unittests/clang-doc/ClangDocTest.h
  clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -28,6 +28,7 @@
   CDCtx.UserStylesheets.insert(
   CDCtx.UserStylesheets.begin(),
   "../share/clang/clang-doc-default-stylesheet.css");
+  CDCtx.JsScripts.emplace_back("index.js");
   return CDCtx;
 }
 
@@ -56,6 +57,8 @@
 namespace Namespace
 
 
+
+
 
   namespace Namespace
   Namespaces
@@ -114,6 +117,8 @@
 
 class r
 
+
+
 
   class r
   Defined at line 10 of test.cpp
@@ -175,6 +180,8 @@
 
 
 
+
+
 
   f
   
@@ -212,6 +219,8 @@
 
 
 
+
+
 
   enum class e
   
@@ -281,6 +290,8 @@
 
 
 
+
+
 
   f
   void f(int I, int J)
Index: clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp
@@ -0,0 +1,74 @@
+//===-- clang-doc/GeneratorTest.cpp ---===//
+//
+// 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
+//
+//===--===//
+
+#include "ClangDocTest.h"
+#include "Generators.h"
+#include "Representation.h"
+#include "Serialize.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace doc {
+
+TEST(GeneratorTest, emitIndex) {
+  Index Idx;
+  auto InfoA = llvm::make_unique();
+  InfoA->Name = "A";
+  InfoA->USR = serialize::hashUSR("1");
+  Generator::addInfoToIndex(Idx, InfoA.get());
+  auto InfoC = llvm::make_unique();
+  InfoC->Name = "C";
+  InfoC->USR = serialize::hashUSR("3");
+  Reference RefB = Reference("B");
+  RefB.USR = serialize::hashUSR("2");
+  InfoC->Namespace = {std::move(RefB)};
+  Generator::addInfoToIndex(Idx, InfoC.get());
+  auto InfoD = llvm::make_unique();
+  InfoD->Name = "D";
+  InfoD->USR = serialize::hashUSR("4");
+  auto InfoF = llvm::make_unique();
+  InfoF->Name = "F";
+  InfoF->USR = serialize::hashUSR("6");
+  Reference RefD = Reference("D");
+  RefD.USR = serialize::hashUSR("4");
+  Reference RefE = Reference("E");
+  RefE.USR = serialize::hashUSR("5");
+  InfoF->Namespace = {std::move(RefE), std::move(RefD)};
+  Generator::addInfoToIndex(Idx, InfoF.get());
+  auto InfoG = llvm::make_unique(InfoType::IT_namespace);
+  Generator::addInfoToIndex(Idx, InfoG.get());
+
+  Index ExpectedIdx;
+  Index IndexA;
+  IndexA.Name = "A";
+  ExpectedIdx.Children.emplace_back(std::move(IndexA));
+  Index IndexB;
+  IndexB.Name = "B";
+  Index IndexC;
+  IndexC.Name = "C";
+  IndexB.Children.emplace_back(std::move(IndexC));
+  ExpectedIdx.Children.emplace_back(std::move(IndexB));
+  Index IndexD;
+  IndexD.Name = "D";
+  Index IndexE;
+  IndexE.Name = "E";
+  Index IndexF;
+  IndexF.Name = "F";
+  IndexE.Children.emplace_back(std::move(IndexF));
+  IndexD.Children.emplace_back(std::move(IndexE));
+  ExpectedIdx.Children.emplace_back(std::move(IndexD));
+  Index IndexG;
+  IndexG.Name = "GlobalNamespace";
+  IndexG.RefType = InfoType::IT_namespace;
+  ExpectedIdx.Children.emplace_back(std::move(IndexG));
+
+  CheckIndex(ExpectedIdx, Idx);
+}
+
+} // namespace doc
+} // namespace clang
Index: clang-tools-extra/unittests/clang-doc/ClangDocTest.h
===
--- clang-tools-extra/unittests/clang-doc/ClangDocTest.h
+++ clang-tools-extra/unittests/clang-doc/ClangDocTest.h
@@ -44,6 +44,8 @@
 void CheckNamespaceInfo(NamespaceInfo *Expected, NamespaceInfo *Actual);
 void CheckRecordInfo(RecordInfo *Expected, 

[PATCH] D65030: [clang-doc] Add second index for sections within info's content

2019-08-05 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 213509.
DiegoAstiazaran marked 2 inline comments as done.
DiegoAstiazaran edited the summary of this revision.
DiegoAstiazaran added a parent revision: D65690: [clang-doc] Add index in each 
info html file.
DiegoAstiazaran added a comment.

Changed dependency of commit, D65003  was 
abandoned and replaced by D65690 .
Rebased to latest commit so HTML is now rendered correctly.
`genHTML(const Index , ...)` was originally implemented by D65003 
 but it is now part of this commit.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65030/new/

https://reviews.llvm.org/D65030

Files:
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -9,6 +9,7 @@
 #include "ClangDocTest.h"
 #include "Generators.h"
 #include "Representation.h"
+#include "Serialize.h"
 #include "gtest/gtest.h"
 
 namespace clang {
@@ -59,24 +60,60 @@
 
 
 
+
+  
+
+  Namespaces
+
+  
+  
+
+  Records
+
+  
+  
+
+  Functions
+
+
+  
+
+  OneFunction
+
+  
+
+  
+  
+
+  Enums
+
+
+  
+
+  OneEnum
+
+  
+
+  
+
 
   namespace Namespace
-  Namespaces
+  Namespaces
   
 ChildNamespace
   
-  Records
+  Records
   
 ChildStruct
   
-  Functions
+  Functions
   
-OneFunction
+OneFunction
 OneFunction()
   
-  Enums
+  Enums
   
-enum OneEnum
+enum OneEnum
   
 
 )raw";
@@ -119,6 +156,42 @@
 
 
 
+
+  
+
+  Members
+
+  
+  
+
+  Records
+
+  
+  
+
+  Functions
+
+
+  
+
+  OneFunction
+
+  
+
+  
+  
+
+  Enums
+
+
+  
+
+  OneEnum
+
+  
+
+  
+
 
   class r
   Defined at line 10 of test.cpp
@@ -127,7 +200,7 @@
 F
 , G
   
-  Members
+  Members
   
 
   private 
@@ -135,18 +208,18 @@
X
 
   
-  Records
+  Records
   
 ChildStruct
   
-  Functions
+  Functions
   
-OneFunction
+OneFunction
 OneFunction()
   
-  Enums
+  Enums
   
-enum OneEnum
+enum OneEnum
   
 
 )raw";
@@ -183,7 +256,7 @@
 
 
 
-  f
+  f
   
 float
  f(
@@ -222,7 +295,7 @@
 
 
 
-  enum class e
+  enum class e
   
 X
   
@@ -293,7 +366,7 @@
 
 
 
-  f
+  f
   void f(int I, int J)
   Defined at line 10 of test.cpp
   
Index: clang-tools-extra/clang-doc/Representation.h
===
--- clang-tools-extra/clang-doc/Representation.h
+++ clang-tools-extra/clang-doc/Representation.h
@@ -350,12 +350,15 @@
 
 struct Index : public Reference {
   Index() = default;
+  Index(StringRef Name, StringRef JumpToSection)
+  : Reference(Name), JumpToSection(JumpToSection) {}
   Index(SymbolID USR, StringRef Name, InfoType IT, StringRef Path)
   : Reference(USR, Name, IT, Path) {}
   // This is used to look for a USR in a vector of Indexes using std::find
   bool operator==(const SymbolID ) const { return USR == Other; }
   bool operator<(const Index ) const { return Name < Other.Name; }
 
+  SmallString<16> JumpToSection;
   std::vector Children;
 
   void sort();
Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -266,15 +266,22 @@
   return LinkNode;
 }
 
-static std::unique_ptr genTypeReference(const Reference ,
-  StringRef CurrentDirectory) {
-  if (Type.Path.empty() && !Type.IsInGlobalNamespace)
-return llvm::make_unique(Type.Name);
+static std::unique_ptr
+genTypeReference(const Reference , StringRef CurrentDirectory,
+ StringRef JumpToSection = "") {
+  if (Type.Path.empty() && !Type.IsInGlobalNamespace) {
+if (JumpToSection.empty())
+  return llvm::make_unique(Type.Name);
+else
+  return genLink(Type.Name, "#" + JumpToSection);
+  }
   llvm::SmallString<128> Path =
   computeRelativePath(Type.Path, CurrentDirectory);
   llvm::sys::path::append(Path, Type.Name + ".html");
   // Paths in HTML must be in posix-style
   llvm::sys::path::native(Path, llvm::sys::path::Style::posix);
+  if (!JumpToSection.empty())
+Path += ("#" + JumpToSection).str();
   return genLink(Type.Name, Path);
 }
 
@@ -301,6 +308,7 @@
 
   std::vector> Out;
   Out.emplace_back(llvm::make_unique(HTMLTag::TAG_H2, "Enums"));
+  

[PATCH] D65003: [clang-doc] Add index in each info html file

2019-08-05 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran abandoned this revision.
DiegoAstiazaran added a comment.

D65690  replaces this revision.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65003/new/

https://reviews.llvm.org/D65003



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


[PATCH] D64958: [clang-doc] Fix link generation

2019-08-05 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL367958: [clang-doc] Fix link generation (authored by 
DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64958?vs=213498=213499#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64958/new/

https://reviews.llvm.org/D64958

Files:
  clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp
  clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
  clang-tools-extra/trunk/clang-doc/BitcodeWriter.h
  clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/trunk/clang-doc/Representation.h
  clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp

Index: clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
===
--- clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
+++ clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
@@ -172,6 +172,8 @@
   {REFERENCE_NAME, {"Name", }},
   {REFERENCE_TYPE, {"RefType", }},
   {REFERENCE_PATH, {"Path", }},
+  {REFERENCE_IS_IN_GLOBAL_NAMESPACE,
+   {"IsInGlobalNamespace", }},
   {REFERENCE_FIELD, {"Field", }}};
   assert(Inits.size() == RecordIdCount);
   for (const auto  : Inits) {
@@ -215,7 +217,7 @@
 // Reference Block
 {BI_REFERENCE_BLOCK_ID,
  {REFERENCE_USR, REFERENCE_NAME, REFERENCE_TYPE, REFERENCE_PATH,
-  REFERENCE_FIELD}}};
+  REFERENCE_IS_IN_GLOBAL_NAMESPACE, REFERENCE_FIELD}}};
 
 // AbbreviationMap
 
@@ -387,6 +389,7 @@
   emitRecord(R.Name, REFERENCE_NAME);
   emitRecord((unsigned)R.RefType, REFERENCE_TYPE);
   emitRecord(R.Path, REFERENCE_PATH);
+  emitRecord(R.IsInGlobalNamespace, REFERENCE_IS_IN_GLOBAL_NAMESPACE);
   emitRecord((unsigned)Field, REFERENCE_FIELD);
 }
 
Index: clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp
===
--- clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp
+++ clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp
@@ -292,6 +292,8 @@
 return decodeRecord(R, I->RefType, Blob);
   case REFERENCE_PATH:
 return decodeRecord(R, I->Path, Blob);
+  case REFERENCE_IS_IN_GLOBAL_NAMESPACE:
+return decodeRecord(R, I->IsInGlobalNamespace, Blob);
   case REFERENCE_FIELD:
 return decodeRecord(R, F, Blob);
   default:
Index: clang-tools-extra/trunk/clang-doc/BitcodeWriter.h
===
--- clang-tools-extra/trunk/clang-doc/BitcodeWriter.h
+++ clang-tools-extra/trunk/clang-doc/BitcodeWriter.h
@@ -109,6 +109,7 @@
   REFERENCE_NAME,
   REFERENCE_TYPE,
   REFERENCE_PATH,
+  REFERENCE_IS_IN_GLOBAL_NAMESPACE,
   REFERENCE_FIELD,
   RI_LAST,
   RI_FIRST = VERSION
Index: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
@@ -247,7 +247,7 @@
 
 static std::unique_ptr genTypeReference(const Reference ,
   StringRef CurrentDirectory) {
-  if (Type.Path.empty())
+  if (Type.Path.empty() && !Type.IsInGlobalNamespace)
 return llvm::make_unique(Type.Name);
   llvm::SmallString<128> Path =
   computeRelativePath(Type.Path, CurrentDirectory);
Index: clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp
===
--- clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp
+++ clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp
@@ -156,6 +156,7 @@
 IO.mapOptional("Name", Ref.Name, SmallString<16>());
 IO.mapOptional("USR", Ref.USR, SymbolID());
 IO.mapOptional("Path", Ref.Path, SmallString<128>());
+IO.mapOptional("IsInGlobalNamespace", Ref.IsInGlobalNamespace, false);
   }
 };
 
Index: clang-tools-extra/trunk/clang-doc/Representation.h
===
--- clang-tools-extra/trunk/clang-doc/Representation.h
+++ clang-tools-extra/trunk/clang-doc/Representation.h
@@ -114,11 +114,17 @@
 struct Reference {
   Reference() = default;
   Reference(llvm::StringRef Name) : Name(Name) {}
-  Reference(llvm::StringRef Name, StringRef Path) : Name(Name), Path(Path) {}
+  // An empty path means the info is in the global namespace because the path is
+  // a composite of the parent namespaces.
+  Reference(llvm::StringRef Name, StringRef Path)
+  : Name(Name), Path(Path), IsInGlobalNamespace(Path.empty()) {}
   Reference(SymbolID USR, StringRef Name, InfoType IT)
   : USR(USR), Name(Name), RefType(IT) {}
+  // An empty path means the info is in the global namespace because the path is
+  // a composite of the parent namespaces.
   

[PATCH] D64958: [clang-doc] Fix link generation

2019-08-05 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 213498.
DiegoAstiazaran marked 2 inline comments as done.
DiegoAstiazaran added a comment.

Fix comments.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64958/new/

https://reviews.llvm.org/D64958

Files:
  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/Representation.h
  clang-tools-extra/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -80,7 +80,8 @@
   I.Members.emplace_back("int", "path/to/int", "X",
  AccessSpecifier::AS_private);
   I.TagType = TagTypeKind::TTK_Class;
-  I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record, "path/to/F");
+  // F is in the global namespace
+  I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record, "");
   I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record,
 "path/to/G");
 
@@ -120,7 +121,7 @@
 Parents:
   - Type:Record
 Name:'F'
-Path:'path/to/F'
+IsInGlobalNamespace: true
 VirtualParents:
   - Type:Record
 Name:'G'
Index: clang-tools-extra/clang-doc/YAMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/YAMLGenerator.cpp
+++ clang-tools-extra/clang-doc/YAMLGenerator.cpp
@@ -156,6 +156,7 @@
 IO.mapOptional("Name", Ref.Name, SmallString<16>());
 IO.mapOptional("USR", Ref.USR, SymbolID());
 IO.mapOptional("Path", Ref.Path, SmallString<128>());
+IO.mapOptional("IsInGlobalNamespace", Ref.IsInGlobalNamespace, false);
   }
 };
 
Index: clang-tools-extra/clang-doc/Representation.h
===
--- clang-tools-extra/clang-doc/Representation.h
+++ clang-tools-extra/clang-doc/Representation.h
@@ -114,11 +114,17 @@
 struct Reference {
   Reference() = default;
   Reference(llvm::StringRef Name) : Name(Name) {}
-  Reference(llvm::StringRef Name, StringRef Path) : Name(Name), Path(Path) {}
+  // An empty path means the info is in the global namespace because the path is
+  // a composite of the parent namespaces.
+  Reference(llvm::StringRef Name, StringRef Path)
+  : Name(Name), Path(Path), IsInGlobalNamespace(Path.empty()) {}
   Reference(SymbolID USR, StringRef Name, InfoType IT)
   : USR(USR), Name(Name), RefType(IT) {}
+  // An empty path means the info is in the global namespace because the path is
+  // a composite of the parent namespaces.
   Reference(SymbolID USR, StringRef Name, InfoType IT, StringRef Path)
-  : USR(USR), Name(Name), RefType(IT), Path(Path) {}
+  : USR(USR), Name(Name), RefType(IT), Path(Path),
+IsInGlobalNamespace(Path.empty()) {}
 
   bool operator==(const Reference ) const {
 return std::tie(USR, Name, RefType) ==
@@ -130,8 +136,12 @@
   InfoType RefType = InfoType::IT_default; // Indicates the type of this
// Reference (namespace, record,
// function, enum, default).
-  llvm::SmallString<128> Path; // Path of directory where the clang-doc
-   // generated file will be saved
+  // Path of directory where the clang-doc generated file will be saved
+  // (possibly unresolved)
+  llvm::SmallString<128> Path;
+  // Indicates if the info's parent is the global namespace, or if the info is
+  // the global namespace
+  bool IsInGlobalNamespace = false;
 };
 
 // A base struct for TypeInfos
Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -245,7 +245,7 @@
 
 static std::unique_ptr genTypeReference(const Reference ,
   StringRef CurrentDirectory) {
-  if (Type.Path.empty())
+  if (Type.Path.empty() && !Type.IsInGlobalNamespace)
 return llvm::make_unique(Type.Name);
   llvm::SmallString<128> Path =
   computeRelativePath(Type.Path, CurrentDirectory);
Index: clang-tools-extra/clang-doc/BitcodeWriter.h
===
--- clang-tools-extra/clang-doc/BitcodeWriter.h
+++ clang-tools-extra/clang-doc/BitcodeWriter.h
@@ -109,6 +109,7 @@
   REFERENCE_NAME,
   REFERENCE_TYPE,
   REFERENCE_PATH,
+  REFERENCE_IS_IN_GLOBAL_NAMESPACE,
   REFERENCE_FIELD,
   RI_LAST,
   RI_FIRST = VERSION
Index: clang-tools-extra/clang-doc/BitcodeWriter.cpp

[PATCH] D65628: [clang-doc] Parallelize reducing phase

2019-08-05 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 213425.
DiegoAstiazaran marked 2 inline comments as done.
DiegoAstiazaran added a comment.
Herald added a subscriber: jfb.

Fix atomicity issues.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65628/new/

https://reviews.llvm.org/D65628

Files:
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp

Index: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -38,7 +38,9 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Signals.h"
+#include "llvm/Support/ThreadPool.h"
 #include "llvm/Support/raw_ostream.h"
+#include 
 #include 
 
 using namespace clang::ast_matchers;
@@ -67,6 +69,12 @@
 llvm::cl::desc("CSS stylesheets to extend the default styles."),
 llvm::cl::cat(ClangDocCategory));
 
+static llvm::cl::opt ThreadCount(
+"thread-count",
+llvm::cl::desc("Threads to use for collecting and reducing infos."),
+llvm::cl::init(llvm::hardware_concurrency()),
+llvm::cl::cat(ClangDocCategory));
+
 enum OutputFormatTy {
   md,
   yaml,
@@ -153,30 +161,6 @@
   return Path;
 }
 
-// Iterate through tool results and build string map of info vectors from the
-// encoded bitstreams.
-bool bitcodeResultsToInfos(
-tooling::ToolResults ,
-llvm::StringMap>> ) {
-  bool Err = false;
-  Results.forEachResult([&](StringRef Key, StringRef Value) {
-llvm::BitstreamCursor Stream(Value);
-doc::ClangDocBitcodeReader Reader(Stream);
-auto Infos = Reader.readBitcode();
-if (!Infos) {
-  llvm::errs() << toString(Infos.takeError()) << "\n";
-  Err = true;
-  return;
-}
-for (auto  : Infos.get()) {
-  auto R =
-  Output.try_emplace(Key, std::vector>());
-  R.first->second.emplace_back(std::move(I));
-}
-  });
-  return Err;
-}
-
 int main(int argc, const char **argv) {
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
   std::error_code OK;
@@ -237,37 +221,68 @@
   // In ToolResults, the Key is the hashed USR and the value is the
   // bitcode-encoded representation of the Info object.
   llvm::outs() << "Collecting infos...\n";
-  llvm::StringMap>> USRToInfos;
-  if (bitcodeResultsToInfos(*Exec->get()->getToolResults(), USRToInfos))
-return 1;
+  llvm::StringMap> USRToBitcode;
+  Exec->get()->getToolResults()->forEachResult(
+  [&](StringRef Key, StringRef Value) {
+auto R = USRToBitcode.try_emplace(Key, std::vector());
+R.first->second.emplace_back(Value);
+  });
 
   // First reducing phase (reduce all decls into one info per decl).
-  llvm::outs() << "Reducing " << USRToInfos.size() << " infos...\n";
-  for (auto  : USRToInfos) {
-auto Reduced = doc::mergeInfos(Group.getValue());
-if (!Reduced) {
-  llvm::errs() << llvm::toString(Reduced.takeError());
-  continue;
-}
+  llvm::outs() << "Reducing " << USRToBitcode.size() << " infos...\n";
+  std::atomic Error;
+  Error = false;
+  llvm::ThreadPool Pool(ThreadCount);
+  for (auto  : USRToBitcode) {
+Pool.async([&]() {
+  std::vector> Infos;
 
-doc::Info *I = Reduced.get().get();
-auto InfoPath = getInfoOutputFile(OutDirectory, I->Path, I->extractName(),
-  "." + Format);
-if (!InfoPath) {
-  llvm::errs() << toString(InfoPath.takeError()) << "\n";
-  return 1;
-}
-std::error_code FileErr;
-llvm::raw_fd_ostream InfoOS(InfoPath.get(), FileErr, llvm::sys::fs::F_None);
-if (FileErr != OK) {
-  llvm::errs() << "Error opening info file: " << FileErr.message() << "\n";
-  continue;
-}
+  for (auto  : Group.getValue()) {
+llvm::BitstreamCursor Stream(Bitcode);
+doc::ClangDocBitcodeReader Reader(Stream);
+auto ReadInfos = Reader.readBitcode();
+if (!ReadInfos) {
+  llvm::errs() << toString(ReadInfos.takeError()) << "\n";
+  Error = true;
+  return;
+}
+std::move(ReadInfos->begin(), ReadInfos->end(),
+  std::back_inserter(Infos));
+  }
+
+  auto Reduced = doc::mergeInfos(Infos);
+  if (!Reduced) {
+llvm::errs() << llvm::toString(Reduced.takeError());
+return;
+  }
+
+  doc::Info *I = Reduced.get().get();
+  auto InfoPath = getInfoOutputFile(OutDirectory, I->Path, I->extractName(),
+"." + Format);
+  if (!InfoPath) {
+llvm::errs() << toString(InfoPath.takeError()) << "\n";
+Error = true;
+return;
+  }
+  std::error_code FileErr;
+  llvm::raw_fd_ostream InfoOS(InfoPath.get(), FileErr,
+  llvm::sys::fs::F_None);
+  if (FileErr != OK) {
+llvm::errs() << "Error opening info file: " << FileErr.message()
+ << "\n";
+return;
+  

[PATCH] D65483: [clang-doc] Add link to source code in file definitions

2019-08-02 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran added a subscriber: phosek.
DiegoAstiazaran added inline comments.



Comment at: clang-tools-extra/clang-doc/HTMLGenerator.cpp:377-378
+  "href", (FileURL + "#" + std::to_string(L.LineNumber)).str());
+  Node->Children.emplace_back(std::move(LocNumberNode));
+  Node->Children.emplace_back(llvm::make_unique(" of file "));
+  auto LocFileNode = llvm::make_unique(

jakehehrlich wrote:
> Can you put these in the link so that the link is larger than a single 
> number? e.g. "303 of file foo.c" should be linkified rather than just "303" 
> which is how I read the code now.
"303" is linkified to the specific line in the source code but also "foo.c" is 
linkified to the top of the source code page.
This is how it is done in Doxygen documentation.
I think it would look weird to have " of file " linkified. But talking to 
@phosek, we agreed that it would be better to remove the whole "Defined at ..." 
and make the info name linkified to the definition, with a tooltip that shows 
"foo.c:303".
So I think we could leave it like this for now and later, in another patch 
(this will require some CSS), do what I just mentioned. What do you think?



Comment at: clang-tools-extra/clang-doc/Mapper.cpp:103-104
+  llvm::SmallString<128> Prefix(RootDir);
+  if (!llvm::sys::path::is_separator(Prefix.back()))
+Prefix += llvm::sys::path::get_separator();
+  llvm::sys::path::replace_path_prefix(File, Prefix, "");

jakehehrlich wrote:
> Do you actually need to do this? Feels like a bug in replace_path_prefix per 
> its own documentation if you do.
`replace_path_prefix` simply calls substr() on the path so if the prefix does 
not include the separator at the end, the resulting path will have it at the 
beginning.



Comment at: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp:228
+  RepositoryUrl.find("https://;) != 0)
+RepositoryUrl.insert(0, "http://;);
+

jakehehrlich wrote:
> 1) Do we need to add this for the user?
> 2) Can we use https by default if we need this?
Not required but I consider it'd be nice to have it.
You're right, https should be the default.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65483/new/

https://reviews.llvm.org/D65483



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


[PATCH] D65690: [clang-doc] Add index in each info html file

2019-08-02 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 213171.
DiegoAstiazaran marked 2 inline comments as done.
DiegoAstiazaran added a comment.

Fix format of index.js file


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65690/new/

https://reviews.llvm.org/D65690

Files:
  clang-tools-extra/clang-doc/Generators.cpp
  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/Representation.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/clang-doc/assets/clang-doc-default-stylesheet.css
  clang-tools-extra/clang-doc/assets/index.js
  clang-tools-extra/clang-doc/stylesheets/clang-doc-default-stylesheet.css
  clang-tools-extra/clang-doc/tool/CMakeLists.txt
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/unittests/clang-doc/CMakeLists.txt
  clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
  clang-tools-extra/unittests/clang-doc/ClangDocTest.h
  clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -28,6 +28,7 @@
   CDCtx.UserStylesheets.insert(
   CDCtx.UserStylesheets.begin(),
   "../share/clang/clang-doc-default-stylesheet.css");
+  CDCtx.JsScripts.emplace_back("index.js");
   return CDCtx;
 }
 
@@ -56,6 +57,8 @@
 namespace Namespace
 
 
+
+
 
   namespace Namespace
   Namespaces
@@ -114,6 +117,8 @@
 
 class r
 
+
+
 
   class r
   Defined at line 10 of test.cpp
@@ -175,6 +180,8 @@
 
 
 
+
+
 
   f
   
@@ -212,6 +219,8 @@
 
 
 
+
+
 
   enum class e
   
@@ -281,6 +290,8 @@
 
 
 
+
+
 
   f
   void f(int I, int J)
Index: clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp
@@ -0,0 +1,74 @@
+//===-- clang-doc/GeneratorTest.cpp ---===//
+//
+// 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
+//
+//===--===//
+
+#include "ClangDocTest.h"
+#include "Generators.h"
+#include "Representation.h"
+#include "Serialize.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace doc {
+
+TEST(GeneratorTest, emitIndex) {
+  Index Idx;
+  auto InfoA = llvm::make_unique();
+  InfoA->Name = "A";
+  InfoA->USR = serialize::hashUSR("1");
+  Generator::addInfoToIndex(Idx, InfoA.get());
+  auto InfoC = llvm::make_unique();
+  InfoC->Name = "C";
+  InfoC->USR = serialize::hashUSR("3");
+  Reference RefB = Reference("B");
+  RefB.USR = serialize::hashUSR("2");
+  InfoC->Namespace = {std::move(RefB)};
+  Generator::addInfoToIndex(Idx, InfoC.get());
+  auto InfoD = llvm::make_unique();
+  InfoD->Name = "D";
+  InfoD->USR = serialize::hashUSR("4");
+  auto InfoF = llvm::make_unique();
+  InfoF->Name = "F";
+  InfoF->USR = serialize::hashUSR("6");
+  Reference RefD = Reference("D");
+  RefD.USR = serialize::hashUSR("4");
+  Reference RefE = Reference("E");
+  RefE.USR = serialize::hashUSR("5");
+  InfoF->Namespace = {std::move(RefE), std::move(RefD)};
+  Generator::addInfoToIndex(Idx, InfoF.get());
+  auto InfoG = llvm::make_unique(InfoType::IT_namespace);
+  Generator::addInfoToIndex(Idx, InfoG.get());
+
+  Index ExpectedIdx;
+  Index IndexA;
+  IndexA.Name = "A";
+  ExpectedIdx.Children.emplace_back(std::move(IndexA));
+  Index IndexB;
+  IndexB.Name = "B";
+  Index IndexC;
+  IndexC.Name = "C";
+  IndexB.Children.emplace_back(std::move(IndexC));
+  ExpectedIdx.Children.emplace_back(std::move(IndexB));
+  Index IndexD;
+  IndexD.Name = "D";
+  Index IndexE;
+  IndexE.Name = "E";
+  Index IndexF;
+  IndexF.Name = "F";
+  IndexE.Children.emplace_back(std::move(IndexF));
+  IndexD.Children.emplace_back(std::move(IndexE));
+  ExpectedIdx.Children.emplace_back(std::move(IndexD));
+  Index IndexG;
+  IndexG.Name = "GlobalNamespace";
+  IndexG.RefType = InfoType::IT_namespace;
+  ExpectedIdx.Children.emplace_back(std::move(IndexG));
+
+  CheckIndex(ExpectedIdx, Idx);
+}
+
+} // namespace doc
+} // namespace clang
Index: clang-tools-extra/unittests/clang-doc/ClangDocTest.h
===
--- clang-tools-extra/unittests/clang-doc/ClangDocTest.h
+++ clang-tools-extra/unittests/clang-doc/ClangDocTest.h
@@ -44,6 +44,8 @@
 void CheckNamespaceInfo(NamespaceInfo *Expected, NamespaceInfo *Actual);
 void CheckRecordInfo(RecordInfo *Expected, RecordInfo *Actual);
 

[PATCH] D65690: [clang-doc] Add index in each info html file

2019-08-02 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran added inline comments.



Comment at: clang-tools-extra/clang-doc/assets/index.js:17
+  return FilePath.substring(Path.length + 1)
+  Path = Path.substring(0, Path.lastIndexOf("/"));
+  }

phosek wrote:
> Wrong indentation?
Yes, clang-format "missed" that because I forgot the semicolon in the previous 
line.
Thanks, it has been fixed.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65690/new/

https://reviews.llvm.org/D65690



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


[PATCH] D65483: [clang-doc] Add link to source code in file definitions

2019-08-02 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 213169.
DiegoAstiazaran marked 7 inline comments as done.
DiegoAstiazaran added a comment.

Change http to https as the default fix to the repository link.
Add new flags to clang-doc documentation.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65483/new/

https://reviews.llvm.org/D65483

Files:
  clang-tools-extra/clang-doc/BitcodeReader.cpp
  clang-tools-extra/clang-doc/BitcodeWriter.cpp
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/Mapper.cpp
  clang-tools-extra/clang-doc/Mapper.h
  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/tool/ClangDocMain.cpp
  clang-tools-extra/docs/clang-doc.rst
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
  clang-tools-extra/unittests/clang-doc/SerializeTest.cpp

Index: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -37,7 +37,7 @@
 
   template  bool mapDecl(const T *D) {
 auto I = serialize::emitInfo(D, getComment(D), /*Line=*/0,
- /*File=*/"test.cpp", Public);
+ /*File=*/"test.cpp", true, Public);
 if (I.first)
   EmittedInfos.emplace_back(std::move(I.first));
 if (I.second)
Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -22,12 +22,14 @@
 }
 
 ClangDocContext
-getClangDocContext(std::vector UserStylesheets = {}) {
+getClangDocContext(std::vector UserStylesheets = {},
+   StringRef RepositoryUrl = "") {
   ClangDocContext CDCtx;
   CDCtx.UserStylesheets = {UserStylesheets.begin(), UserStylesheets.end()};
   CDCtx.UserStylesheets.insert(
   CDCtx.UserStylesheets.begin(),
   "../share/clang/clang-doc-default-stylesheet.css");
+  CDCtx.RepositoryUrl = RepositoryUrl;
   return CDCtx;
 }
 
@@ -87,7 +89,7 @@
   I.Path = "X/Y/Z";
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
 
-  I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
+  I.DefLoc = Location(10, llvm::SmallString<16>{"dir/test.cpp"}, true);
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
   SmallString<16> PathTo;
@@ -107,7 +109,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  ClangDocContext CDCtx = getClangDocContext();
+  ClangDocContext CDCtx = getClangDocContext({}, "https://www.repository.com;);
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
   std::string Expected = R"raw(
@@ -116,7 +118,12 @@
 
 
   class r
-  Defined at line 10 of test.cpp
+  
+Defined at line 
+https://www.repository.com/dir/test.cpp#10;>10
+ of file 
+https://www.repository.com/dir/test.cpp;>test.cpp
+  
   
 Inherits from 
 F
@@ -154,7 +161,7 @@
   I.Name = "f";
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
 
-  I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
+  I.DefLoc = Location(10, llvm::SmallString<16>{"dir/test.cpp"}, false);
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
   SmallString<16> PathTo;
@@ -168,7 +175,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  ClangDocContext CDCtx = getClangDocContext();
+  ClangDocContext CDCtx = getClangDocContext({}, "https://www.repository.com;);
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
   std::string Expected = R"raw(
@@ -183,7 +190,7 @@
 int
  P)
   
-  Defined at line 10 of test.cpp
+  Defined at line 10 of file dir/test.cpp
 
 )raw";
 
@@ -217,7 +224,7 @@
   
 X
   
-  Defined at line 10 of test.cpp
+  Defined at line 10 of file test.cpp
 
 )raw";
 
@@ -284,7 +291,7 @@
 
   f
   void f(int I, int J)
-  Defined at line 10 of test.cpp
+  Defined at line 10 of file test.cpp
   
 
Brief description.
Index: clang-tools-extra/docs/clang-doc.rst
===
--- clang-tools-extra/docs/clang-doc.rst
+++ clang-tools-extra/docs/clang-doc.rst
@@ -79,17 +79,27 @@
 
   clang-doc options:
 
--doxygen   - Use only doxygen-style comments to generate docs.
--dump  - Dump intermediate results to bitcode file.
--extra-arg=- Additional argument to append to the compiler command line
--extra-arg-before= - Additional argument to prepend to the compiler command line
---format=   - Format for outputted docs.
-  =yaml-   Documentation in YAML format.
-  =md

[PATCH] D65622: [clang-doc] Update documentation

2019-08-02 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL367743: [clang-doc] Update documentation (authored by 
DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65622?vs=213162=213165#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65622/new/

https://reviews.llvm.org/D65622

Files:
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  clang-tools-extra/trunk/docs/clang-doc.rst


Index: clang-tools-extra/trunk/docs/clang-doc.rst
===
--- clang-tools-extra/trunk/docs/clang-doc.rst
+++ clang-tools-extra/trunk/docs/clang-doc.rst
@@ -17,7 +17,7 @@
 there.
 
 Use
-=
+===
 
 :program:`clang-doc` is a `LibTooling
 `_-based tool, and so requires a
@@ -25,19 +25,42 @@
 see `How To Setup Tooling For LLVM
 `_).
 
-The tool can be used on a single file or multiple files as defined in 
-the compile commands database:
+By default, the tool will run on all files listed in the given compile commands
+database:
 
 .. code-block:: console
 
-  $ clang-doc /path/to/file.cpp -p /path/to/compile/commands
+  $ clang-doc /path/to/compile_commands.json
 
-This generates an intermediate representation of the declarations and their
-associated information in the specified TUs, serialized to LLVM bitcode.
+The tool can also be used on a single file or multiple files if a build path is
+passed with the ``-p`` flag.
 
-As currently implemented, the tool is only able to parse TUs that can be 
-stored in-memory. Future additions will extend the current framework to use
-map-reduce frameworks to allow for use with large codebases.
+.. code-block:: console
+
+  $ clang-doc /path/to/file.cpp -p /path/to/build
+
+Output
+==
+
+:program:`clang-doc` produces a directory of documentation. One file is 
produced
+for each namespace and record in the project source code, containing all
+documentation (including contained functions, methods, and enums) for that 
item.
+
+The top-level directory is configurable through the ``output`` flag:
+
+.. code-block:: console
+
+  $ clang-doc -output=output/directory/ compile_commands.json
+
+Configuration
+=
+
+Configuration for :program:`clang-doc` is currently limited to command-line 
options.
+In the future, it may develop the ability to use a configuration file, but no 
such
+efforts are currently in progress.
+
+Options
+---
 
 :program:`clang-doc` offers the following options:
 
@@ -60,6 +83,13 @@
 -dump  - Dump intermediate results to bitcode file.
 -extra-arg=- Additional argument to append to the compiler 
command line
 -extra-arg-before= - Additional argument to prepend to the 
compiler command line
--omit-filenames- Omit filenames in output.
+--format=   - Format for outputted docs.
+  =yaml-   Documentation in YAML format.
+  =md  -   Documentation in MD format.
+  =html-   Documentation in HTML format.
 -output=   - Directory for outputting generated files.
 -p=- Build path
+--public   - Document only public declarations.
+--stylesheets= - CSS stylesheets to extend the default styles.
+
+``stylesheets`` should only be used if ``format`` is set to ``html``.
Index: clang-tools-extra/trunk/docs/ReleaseNotes.rst
===
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst
@@ -52,7 +52,7 @@
 Improvements to clang-doc
 -
 
-The improvements are...
+- :doc:`clang-doc ` now generates documentation in HTML format.
 
 Improvements to clang-query
 ---


Index: clang-tools-extra/trunk/docs/clang-doc.rst
===
--- clang-tools-extra/trunk/docs/clang-doc.rst
+++ clang-tools-extra/trunk/docs/clang-doc.rst
@@ -17,7 +17,7 @@
 there.
 
 Use
-=
+===
 
 :program:`clang-doc` is a `LibTooling
 `_-based tool, and so requires a
@@ -25,19 +25,42 @@
 see `How To Setup Tooling For LLVM
 `_).
 
-The tool can be used on a single file or multiple files as defined in 
-the compile commands database:
+By default, the tool will run on all files listed in the given compile commands
+database:
 
 .. code-block:: console
 
-  $ clang-doc /path/to/file.cpp -p /path/to/compile/commands
+  $ clang-doc /path/to/compile_commands.json
 
-This generates an intermediate representation of the declarations and their
-associated information in the specified TUs, 

[PATCH] D65622: [clang-doc] Update documentation

2019-08-02 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 213162.
DiegoAstiazaran added a comment.

Specify that `stylesheets` flag is only required for html format.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65622/new/

https://reviews.llvm.org/D65622

Files:
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-doc.rst


Index: clang-tools-extra/docs/clang-doc.rst
===
--- clang-tools-extra/docs/clang-doc.rst
+++ clang-tools-extra/docs/clang-doc.rst
@@ -17,7 +17,7 @@
 there.
 
 Use
-=
+===
 
 :program:`clang-doc` is a `LibTooling
 `_-based tool, and so requires a
@@ -25,19 +25,42 @@
 see `How To Setup Tooling For LLVM
 `_).
 
-The tool can be used on a single file or multiple files as defined in 
-the compile commands database:
+By default, the tool will run on all files listed in the given compile commands
+database:
 
 .. code-block:: console
 
-  $ clang-doc /path/to/file.cpp -p /path/to/compile/commands
+  $ clang-doc /path/to/compile_commands.json
 
-This generates an intermediate representation of the declarations and their
-associated information in the specified TUs, serialized to LLVM bitcode.
+The tool can also be used on a single file or multiple files if a build path is
+passed with the ``-p`` flag.
 
-As currently implemented, the tool is only able to parse TUs that can be 
-stored in-memory. Future additions will extend the current framework to use
-map-reduce frameworks to allow for use with large codebases.
+.. code-block:: console
+
+  $ clang-doc /path/to/file.cpp -p /path/to/build
+
+Output
+==
+
+:program:`clang-doc` produces a directory of documentation. One file is 
produced
+for each namespace and record in the project source code, containing all
+documentation (including contained functions, methods, and enums) for that 
item.
+
+The top-level directory is configurable through the ``output`` flag:
+
+.. code-block:: console
+
+  $ clang-doc -output=output/directory/ compile_commands.json
+
+Configuration
+=
+
+Configuration for :program:`clang-doc` is currently limited to command-line 
options.
+In the future, it may develop the ability to use a configuration file, but no 
such
+efforts are currently in progress.
+
+Options
+---
 
 :program:`clang-doc` offers the following options:
 
@@ -60,6 +83,13 @@
 -dump  - Dump intermediate results to bitcode file.
 -extra-arg=- Additional argument to append to the compiler 
command line
 -extra-arg-before= - Additional argument to prepend to the 
compiler command line
--omit-filenames- Omit filenames in output.
+--format=   - Format for outputted docs.
+  =yaml-   Documentation in YAML format.
+  =md  -   Documentation in MD format.
+  =html-   Documentation in HTML format.
 -output=   - Directory for outputting generated files.
 -p=- Build path
+--public   - Document only public declarations.
+--stylesheets= - CSS stylesheets to extend the default styles.
+
+``stylesheets`` should only be used if ``format`` is set to ``html``.
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -52,7 +52,7 @@
 Improvements to clang-doc
 -
 
-The improvements are...
+- :doc:`clang-doc ` now generates documentation in HTML format.
 
 Improvements to clang-query
 ---


Index: clang-tools-extra/docs/clang-doc.rst
===
--- clang-tools-extra/docs/clang-doc.rst
+++ clang-tools-extra/docs/clang-doc.rst
@@ -17,7 +17,7 @@
 there.
 
 Use
-=
+===
 
 :program:`clang-doc` is a `LibTooling
 `_-based tool, and so requires a
@@ -25,19 +25,42 @@
 see `How To Setup Tooling For LLVM
 `_).
 
-The tool can be used on a single file or multiple files as defined in 
-the compile commands database:
+By default, the tool will run on all files listed in the given compile commands
+database:
 
 .. code-block:: console
 
-  $ clang-doc /path/to/file.cpp -p /path/to/compile/commands
+  $ clang-doc /path/to/compile_commands.json
 
-This generates an intermediate representation of the declarations and their
-associated information in the specified TUs, serialized to LLVM bitcode.
+The tool can also be used on a single file or multiple files if a build path is
+passed with the ``-p`` flag.
 
-As currently implemented, the tool is only able to parse TUs that can be 
-stored in-memory. Future additions will extend the 

[PATCH] D65690: [clang-doc] Add index in each info html file

2019-08-02 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran created this revision.
DiegoAstiazaran added reviewers: jakehehrlich, juliehockett, phosek.
DiegoAstiazaran added a project: clang-tools-extra.
Herald added subscribers: kadircet, arphaman, mgrang, mgorny.

An index structure is created while generating the output file for each info. 
This structure is parsed to JSON and written to a file in the output directory. 
The html for the index is not rendered by clang-doc. A Javascript file is 
included in the output directory, this will read the JSON and insert HTML 
elements into the file.


https://reviews.llvm.org/D65690

Files:
  clang-tools-extra/clang-doc/Generators.cpp
  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/Representation.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/clang-doc/assets/clang-doc-default-stylesheet.css
  clang-tools-extra/clang-doc/assets/index.js
  clang-tools-extra/clang-doc/stylesheets/clang-doc-default-stylesheet.css
  clang-tools-extra/clang-doc/tool/CMakeLists.txt
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/unittests/clang-doc/CMakeLists.txt
  clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
  clang-tools-extra/unittests/clang-doc/ClangDocTest.h
  clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -28,6 +28,7 @@
   CDCtx.UserStylesheets.insert(
   CDCtx.UserStylesheets.begin(),
   "../share/clang/clang-doc-default-stylesheet.css");
+  CDCtx.JsScripts.emplace_back("index.js");
   return CDCtx;
 }
 
@@ -56,6 +57,8 @@
 namespace Namespace
 
 
+
+
 
   namespace Namespace
   Namespaces
@@ -114,6 +117,8 @@
 
 class r
 
+
+
 
   class r
   Defined at line 10 of test.cpp
@@ -175,6 +180,8 @@
 
 
 
+
+
 
   f
   
@@ -212,6 +219,8 @@
 
 
 
+
+
 
   enum class e
   
@@ -281,6 +290,8 @@
 
 
 
+
+
 
   f
   void f(int I, int J)
Index: clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp
@@ -0,0 +1,74 @@
+//===-- clang-doc/GeneratorTest.cpp ---===//
+//
+// 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
+//
+//===--===//
+
+#include "ClangDocTest.h"
+#include "Generators.h"
+#include "Representation.h"
+#include "Serialize.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace doc {
+
+TEST(GeneratorTest, emitIndex) {
+  Index Idx;
+  auto InfoA = llvm::make_unique();
+  InfoA->Name = "A";
+  InfoA->USR = serialize::hashUSR("1");
+  Generator::addInfoToIndex(Idx, InfoA.get());
+  auto InfoC = llvm::make_unique();
+  InfoC->Name = "C";
+  InfoC->USR = serialize::hashUSR("3");
+  Reference RefB = Reference("B");
+  RefB.USR = serialize::hashUSR("2");
+  InfoC->Namespace = {std::move(RefB)};
+  Generator::addInfoToIndex(Idx, InfoC.get());
+  auto InfoD = llvm::make_unique();
+  InfoD->Name = "D";
+  InfoD->USR = serialize::hashUSR("4");
+  auto InfoF = llvm::make_unique();
+  InfoF->Name = "F";
+  InfoF->USR = serialize::hashUSR("6");
+  Reference RefD = Reference("D");
+  RefD.USR = serialize::hashUSR("4");
+  Reference RefE = Reference("E");
+  RefE.USR = serialize::hashUSR("5");
+  InfoF->Namespace = {std::move(RefE), std::move(RefD)};
+  Generator::addInfoToIndex(Idx, InfoF.get());
+  auto InfoG = llvm::make_unique(InfoType::IT_namespace);
+  Generator::addInfoToIndex(Idx, InfoG.get());
+
+  Index ExpectedIdx;
+  Index IndexA;
+  IndexA.Name = "A";
+  ExpectedIdx.Children.emplace_back(std::move(IndexA));
+  Index IndexB;
+  IndexB.Name = "B";
+  Index IndexC;
+  IndexC.Name = "C";
+  IndexB.Children.emplace_back(std::move(IndexC));
+  ExpectedIdx.Children.emplace_back(std::move(IndexB));
+  Index IndexD;
+  IndexD.Name = "D";
+  Index IndexE;
+  IndexE.Name = "E";
+  Index IndexF;
+  IndexF.Name = "F";
+  IndexE.Children.emplace_back(std::move(IndexF));
+  IndexD.Children.emplace_back(std::move(IndexE));
+  ExpectedIdx.Children.emplace_back(std::move(IndexD));
+  Index IndexG;
+  IndexG.Name = "GlobalNamespace";
+  IndexG.RefType = InfoType::IT_namespace;
+  ExpectedIdx.Children.emplace_back(std::move(IndexG));
+
+  CheckIndex(ExpectedIdx, Idx);
+}
+
+} // namespace doc
+} // namespace clang
Index: clang-tools-extra/unittests/clang-doc/ClangDocTest.h

[PATCH] D65627: [clang-doc] Add flag to continue after mapping errors

2019-08-02 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL367729: [clang-doc] Add flag to continue after mapping 
errors (authored by DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65627?vs=213126=213135#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65627/new/

https://reviews.llvm.org/D65627

Files:
  clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp


Index: clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
@@ -48,6 +48,11 @@
 static llvm::cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
 static llvm::cl::OptionCategory ClangDocCategory("clang-doc options");
 
+static llvm::cl::opt IgnoreMappingFailures(
+"ignore-map-errors",
+llvm::cl::desc("Continue if files are not mapped correctly."),
+llvm::cl::init(true), llvm::cl::cat(ClangDocCategory));
+
 static llvm::cl::opt
 OutDirectory("output",
  llvm::cl::desc("Directory for outputting generated files."),
@@ -229,8 +234,14 @@
   auto Err =
   Exec->get()->execute(doc::newMapperActionFactory(CDCtx), ArgAdjuster);
   if (Err) {
-llvm::errs() << toString(std::move(Err)) << "\n";
-return 1;
+if (IgnoreMappingFailures)
+  llvm::errs() << "Error mapping decls in files. Clang-doc will ignore "
+  "these files and continue:\n"
+   << toString(std::move(Err)) << "\n";
+else {
+  llvm::errs() << toString(std::move(Err)) << "\n";
+  return 1;
+}
   }
 
   // Collect values into output by key.


Index: clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
@@ -48,6 +48,11 @@
 static llvm::cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
 static llvm::cl::OptionCategory ClangDocCategory("clang-doc options");
 
+static llvm::cl::opt IgnoreMappingFailures(
+"ignore-map-errors",
+llvm::cl::desc("Continue if files are not mapped correctly."),
+llvm::cl::init(true), llvm::cl::cat(ClangDocCategory));
+
 static llvm::cl::opt
 OutDirectory("output",
  llvm::cl::desc("Directory for outputting generated files."),
@@ -229,8 +234,14 @@
   auto Err =
   Exec->get()->execute(doc::newMapperActionFactory(CDCtx), ArgAdjuster);
   if (Err) {
-llvm::errs() << toString(std::move(Err)) << "\n";
-return 1;
+if (IgnoreMappingFailures)
+  llvm::errs() << "Error mapping decls in files. Clang-doc will ignore "
+  "these files and continue:\n"
+   << toString(std::move(Err)) << "\n";
+else {
+  llvm::errs() << toString(std::move(Err)) << "\n";
+  return 1;
+}
   }
 
   // Collect values into output by key.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64958: [clang-doc] Fix link generation

2019-08-02 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 213128.
DiegoAstiazaran marked 3 inline comments as done.
DiegoAstiazaran added a comment.

Fix comments


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64958/new/

https://reviews.llvm.org/D64958

Files:
  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/Representation.h
  clang-tools-extra/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -80,7 +80,8 @@
   I.Members.emplace_back("int", "path/to/int", "X",
  AccessSpecifier::AS_private);
   I.TagType = TagTypeKind::TTK_Class;
-  I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record, "path/to/F");
+  // F is in the global namespace
+  I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record, "");
   I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record,
 "path/to/G");
 
@@ -120,7 +121,7 @@
 Parents:
   - Type:Record
 Name:'F'
-Path:'path/to/F'
+IsInGlobalNamespace: true
 VirtualParents:
   - Type:Record
 Name:'G'
Index: clang-tools-extra/clang-doc/YAMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/YAMLGenerator.cpp
+++ clang-tools-extra/clang-doc/YAMLGenerator.cpp
@@ -156,6 +156,7 @@
 IO.mapOptional("Name", Ref.Name, SmallString<16>());
 IO.mapOptional("USR", Ref.USR, SymbolID());
 IO.mapOptional("Path", Ref.Path, SmallString<128>());
+IO.mapOptional("IsInGlobalNamespace", Ref.IsInGlobalNamespace, false);
   }
 };
 
Index: clang-tools-extra/clang-doc/Representation.h
===
--- clang-tools-extra/clang-doc/Representation.h
+++ clang-tools-extra/clang-doc/Representation.h
@@ -114,11 +114,17 @@
 struct Reference {
   Reference() = default;
   Reference(llvm::StringRef Name) : Name(Name) {}
-  Reference(llvm::StringRef Name, StringRef Path) : Name(Name), Path(Path) {}
+  // An empty path means the info is in the globalnamespace because the path is
+  // a composite of the parent namespaces.
+  Reference(llvm::StringRef Name, StringRef Path)
+  : Name(Name), Path(Path), IsInGlobalNamespace(Path.empty()) {}
   Reference(SymbolID USR, StringRef Name, InfoType IT)
   : USR(USR), Name(Name), RefType(IT) {}
+  // An empty path means the info is in the globalnamespace because the path is
+  // a composite of the parent namespaces.
   Reference(SymbolID USR, StringRef Name, InfoType IT, StringRef Path)
-  : USR(USR), Name(Name), RefType(IT), Path(Path) {}
+  : USR(USR), Name(Name), RefType(IT), Path(Path),
+IsInGlobalNamespace(Path.empty()) {}
 
   bool operator==(const Reference ) const {
 return std::tie(USR, Name, RefType) ==
@@ -130,8 +136,12 @@
   InfoType RefType = InfoType::IT_default; // Indicates the type of this
// Reference (namespace, record,
// function, enum, default).
-  llvm::SmallString<128> Path; // Path of directory where the clang-doc
-   // generated file will be saved
+  // Path of directory where the clang-doc generated file will be saved
+  // (possibly unresolved)
+  llvm::SmallString<128> Path;
+  // Indicates if the info's parent is the global namespace, or if the info is
+  // the global namespace
+  bool IsInGlobalNamespace = false;
 };
 
 // A base struct for TypeInfos
Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -245,7 +245,7 @@
 
 static std::unique_ptr genTypeReference(const Reference ,
   StringRef CurrentDirectory) {
-  if (Type.Path.empty())
+  if (Type.Path.empty() && !Type.IsInGlobalNamespace)
 return llvm::make_unique(Type.Name);
   llvm::SmallString<128> Path =
   computeRelativePath(Type.Path, CurrentDirectory);
Index: clang-tools-extra/clang-doc/BitcodeWriter.h
===
--- clang-tools-extra/clang-doc/BitcodeWriter.h
+++ clang-tools-extra/clang-doc/BitcodeWriter.h
@@ -109,6 +109,7 @@
   REFERENCE_NAME,
   REFERENCE_TYPE,
   REFERENCE_PATH,
+  REFERENCE_IS_IN_GLOBAL_NAMESPACE,
   REFERENCE_FIELD,
   RI_LAST,
   RI_FIRST = VERSION
Index: clang-tools-extra/clang-doc/BitcodeWriter.cpp

[PATCH] D65627: [clang-doc] Add flag to continue after mapping errors

2019-08-02 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 213126.
DiegoAstiazaran retitled this revision from "[clang-doc] Continue after mapping 
error" to "[clang-doc] Add flag to continue after mapping errors".
DiegoAstiazaran edited the summary of this revision.
DiegoAstiazaran added a comment.

A flag has been added to decide if the tool should continue after an error 
occurs in the mapping phase.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65627/new/

https://reviews.llvm.org/D65627

Files:
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp


Index: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -48,6 +48,11 @@
 static llvm::cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
 static llvm::cl::OptionCategory ClangDocCategory("clang-doc options");
 
+static llvm::cl::opt IgnoreMappingFailures(
+"ignore-map-errors",
+llvm::cl::desc("Continue if files are not mapped correctly."),
+llvm::cl::init(true), llvm::cl::cat(ClangDocCategory));
+
 static llvm::cl::opt
 OutDirectory("output",
  llvm::cl::desc("Directory for outputting generated files."),
@@ -229,8 +234,14 @@
   auto Err =
   Exec->get()->execute(doc::newMapperActionFactory(CDCtx), ArgAdjuster);
   if (Err) {
-llvm::errs() << toString(std::move(Err)) << "\n";
-return 1;
+if (IgnoreMappingFailures)
+  llvm::errs() << "Error mapping decls in files. Clang-doc will ignore "
+  "these files and continue:\n"
+   << toString(std::move(Err)) << "\n";
+else {
+  llvm::errs() << toString(std::move(Err)) << "\n";
+  return 1;
+}
   }
 
   // Collect values into output by key.


Index: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -48,6 +48,11 @@
 static llvm::cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
 static llvm::cl::OptionCategory ClangDocCategory("clang-doc options");
 
+static llvm::cl::opt IgnoreMappingFailures(
+"ignore-map-errors",
+llvm::cl::desc("Continue if files are not mapped correctly."),
+llvm::cl::init(true), llvm::cl::cat(ClangDocCategory));
+
 static llvm::cl::opt
 OutDirectory("output",
  llvm::cl::desc("Directory for outputting generated files."),
@@ -229,8 +234,14 @@
   auto Err =
   Exec->get()->execute(doc::newMapperActionFactory(CDCtx), ArgAdjuster);
   if (Err) {
-llvm::errs() << toString(std::move(Err)) << "\n";
-return 1;
+if (IgnoreMappingFailures)
+  llvm::errs() << "Error mapping decls in files. Clang-doc will ignore "
+  "these files and continue:\n"
+   << toString(std::move(Err)) << "\n";
+else {
+  llvm::errs() << toString(std::move(Err)) << "\n";
+  return 1;
+}
   }
 
   // Collect values into output by key.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65628: [clang-doc] Parallelize reducing phase

2019-08-01 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran created this revision.
DiegoAstiazaran added reviewers: jakehehrlich, juliehockett.
DiegoAstiazaran added a project: clang-tools-extra.
Herald added subscribers: kadircet, arphaman.

Reduce phase has been parallelized and a execution time was reduced by 60% with 
this.
The reading of bitcode (bitcode -> Info) was moved to this segment of code 
parallelized so it now happens just before reducing.


https://reviews.llvm.org/D65628

Files:
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp

Index: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -38,6 +38,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Signals.h"
+#include "llvm/Support/ThreadPool.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 
@@ -67,6 +68,12 @@
 llvm::cl::desc("CSS stylesheets to extend the default styles."),
 llvm::cl::cat(ClangDocCategory));
 
+static llvm::cl::opt ThreadCount(
+"thread-count",
+llvm::cl::desc("Threads to use for collecting and reducing infos."),
+llvm::cl::init(llvm::hardware_concurrency()),
+llvm::cl::cat(ClangDocCategory));
+
 enum OutputFormatTy {
   md,
   yaml,
@@ -153,30 +160,6 @@
   return Path;
 }
 
-// Iterate through tool results and build string map of info vectors from the
-// encoded bitstreams.
-bool bitcodeResultsToInfos(
-tooling::ToolResults ,
-llvm::StringMap>> ) {
-  bool Err = false;
-  Results.forEachResult([&](StringRef Key, StringRef Value) {
-llvm::BitstreamCursor Stream(Value);
-doc::ClangDocBitcodeReader Reader(Stream);
-auto Infos = Reader.readBitcode();
-if (!Infos) {
-  llvm::errs() << toString(Infos.takeError()) << "\n";
-  Err = true;
-  return;
-}
-for (auto  : Infos.get()) {
-  auto R =
-  Output.try_emplace(Key, std::vector>());
-  R.first->second.emplace_back(std::move(I));
-}
-  });
-  return Err;
-}
-
 int main(int argc, const char **argv) {
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
   std::error_code OK;
@@ -237,37 +220,67 @@
   // In ToolResults, the Key is the hashed USR and the value is the
   // bitcode-encoded representation of the Info object.
   llvm::outs() << "Collecting infos...\n";
-  llvm::StringMap>> USRToInfos;
-  if (bitcodeResultsToInfos(*Exec->get()->getToolResults(), USRToInfos))
-return 1;
+  llvm::StringMap> USRToBitcode;
+  Exec->get()->getToolResults()->forEachResult(
+  [&](StringRef Key, StringRef Value) {
+auto R = USRToBitcode.try_emplace(Key, std::vector());
+R.first->second.emplace_back(Value);
+  });
 
   // First reducing phase (reduce all decls into one info per decl).
-  llvm::outs() << "Reducing " << USRToInfos.size() << " infos...\n";
-  for (auto  : USRToInfos) {
-auto Reduced = doc::mergeInfos(Group.getValue());
-if (!Reduced) {
-  llvm::errs() << llvm::toString(Reduced.takeError());
-  continue;
-}
+  llvm::outs() << "Reducing " << USRToBitcode.size() << " infos...\n";
+  bool Error = false;
+  llvm::ThreadPool Pool(ThreadCount);
+  for (auto  : USRToBitcode) {
+Pool.async([&]() {
+  std::vector> Infos;
 
-doc::Info *I = Reduced.get().get();
-auto InfoPath = getInfoOutputFile(OutDirectory, I->Path, I->extractName(),
-  "." + Format);
-if (!InfoPath) {
-  llvm::errs() << toString(InfoPath.takeError()) << "\n";
-  return 1;
-}
-std::error_code FileErr;
-llvm::raw_fd_ostream InfoOS(InfoPath.get(), FileErr, llvm::sys::fs::F_None);
-if (FileErr != OK) {
-  llvm::errs() << "Error opening info file: " << FileErr.message() << "\n";
-  continue;
-}
+  for (auto  : Group.getValue()) {
+llvm::BitstreamCursor Stream(Bitcode);
+doc::ClangDocBitcodeReader Reader(Stream);
+auto ReadInfos = Reader.readBitcode();
+if (!ReadInfos) {
+  llvm::errs() << toString(ReadInfos.takeError()) << "\n";
+  Error = true;
+  return;
+}
+std::move(ReadInfos->begin(), ReadInfos->end(),
+  std::back_inserter(Infos));
+  }
+
+  auto Reduced = doc::mergeInfos(Infos);
+  if (!Reduced) {
+llvm::errs() << llvm::toString(Reduced.takeError());
+return;
+  }
+
+  doc::Info *I = Reduced.get().get();
+  auto InfoPath = getInfoOutputFile(OutDirectory, I->Path, I->extractName(),
+"." + Format);
+  if (!InfoPath) {
+llvm::errs() << toString(InfoPath.takeError()) << "\n";
+Error = true;
+return;
+  }
+  std::error_code FileErr;
+  llvm::raw_fd_ostream InfoOS(InfoPath.get(), FileErr,
+  llvm::sys::fs::F_None);
+  if (FileErr != OK) {
+llvm::errs() << "Error 

[PATCH] D65627: [clang-doc] Continue after mapping error

2019-08-01 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran created this revision.
DiegoAstiazaran added reviewers: jakehehrlich, juliehockett.
DiegoAstiazaran added a project: clang-tools-extra.
Herald added subscribers: kadircet, arphaman.

The tool used to stop execution if there was an error in the mapping phase. It 
will now show the error but continue with the files that were mapped correctly.


https://reviews.llvm.org/D65627

Files:
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp


Index: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -228,10 +228,10 @@
   llvm::outs() << "Mapping decls...\n";
   auto Err =
   Exec->get()->execute(doc::newMapperActionFactory(CDCtx), ArgAdjuster);
-  if (Err) {
-llvm::errs() << toString(std::move(Err)) << "\n";
-return 1;
-  }
+  if (Err)
+llvm::errs() << "Error mapping decls in files. Clang-doc will ignore these 
"
+"files and continue:\n"
+ << toString(std::move(Err)) << "\n";
 
   // Collect values into output by key.
   // In ToolResults, the Key is the hashed USR and the value is the


Index: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -228,10 +228,10 @@
   llvm::outs() << "Mapping decls...\n";
   auto Err =
   Exec->get()->execute(doc::newMapperActionFactory(CDCtx), ArgAdjuster);
-  if (Err) {
-llvm::errs() << toString(std::move(Err)) << "\n";
-return 1;
-  }
+  if (Err)
+llvm::errs() << "Error mapping decls in files. Clang-doc will ignore these "
+"files and continue:\n"
+ << toString(std::move(Err)) << "\n";
 
   // Collect values into output by key.
   // In ToolResults, the Key is the hashed USR and the value is the
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65622: [clang-doc] Update documentation

2019-08-01 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran created this revision.
DiegoAstiazaran added reviewers: jakehehrlich, juliehockett.
DiegoAstiazaran added a project: clang-tools-extra.

HTML generator has been included in clang-tools-extra release notes.
clang-doc documentation file has been updated.


https://reviews.llvm.org/D65622

Files:
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-doc.rst


Index: clang-tools-extra/docs/clang-doc.rst
===
--- clang-tools-extra/docs/clang-doc.rst
+++ clang-tools-extra/docs/clang-doc.rst
@@ -17,7 +17,7 @@
 there.
 
 Use
-=
+===
 
 :program:`clang-doc` is a `LibTooling
 `_-based tool, and so requires a
@@ -25,19 +25,42 @@
 see `How To Setup Tooling For LLVM
 `_).
 
-The tool can be used on a single file or multiple files as defined in 
-the compile commands database:
+By default, the tool will run on all files listed in the given compile commands
+database:
 
 .. code-block:: console
 
-  $ clang-doc /path/to/file.cpp -p /path/to/compile/commands
+  $ clang-doc /path/to/compile_commands.json
 
-This generates an intermediate representation of the declarations and their
-associated information in the specified TUs, serialized to LLVM bitcode.
+The tool can also be used on a single file or multiple files if a build path is
+passed with the ``-p`` flag.
 
-As currently implemented, the tool is only able to parse TUs that can be 
-stored in-memory. Future additions will extend the current framework to use
-map-reduce frameworks to allow for use with large codebases.
+.. code-block:: console
+
+  $ clang-doc /path/to/file.cpp -p /path/to/build
+
+Output
+==
+
+:program:`clang-doc` produces a directory of documentation. One file is 
produced
+for each namespace and record in the project source code, containing all
+documentation (including contained functions, methods, and enums) for that 
item.
+
+The top-level directory is configurable through the ``output`` flag:
+
+.. code-block:: console
+
+  $ clang-doc -output=output/directory/ compile_commands.json
+
+Configuration
+=
+
+Configuration for :program:`clang-doc` is currently limited to command-line 
options.
+In the future, it may develop the ability to use a configuration file, but no 
such
+efforts are currently in progress.
+
+Options
+---
 
 :program:`clang-doc` offers the following options:
 
@@ -60,6 +83,11 @@
 -dump  - Dump intermediate results to bitcode file.
 -extra-arg=- Additional argument to append to the compiler 
command line
 -extra-arg-before= - Additional argument to prepend to the 
compiler command line
--omit-filenames- Omit filenames in output.
+--format=   - Format for outputted docs.
+  =yaml-   Documentation in YAML format.
+  =md  -   Documentation in MD format.
+  =html-   Documentation in HTML format.
 -output=   - Directory for outputting generated files.
 -p=- Build path
+--public   - Document only public declarations.
+--stylesheets= - CSS stylesheets to extend the default styles.
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -52,7 +52,7 @@
 Improvements to clang-doc
 -
 
-The improvements are...
+- :doc:`clang-doc ` now generates documentation in HTML format.
 
 Improvements to clang-query
 ---


Index: clang-tools-extra/docs/clang-doc.rst
===
--- clang-tools-extra/docs/clang-doc.rst
+++ clang-tools-extra/docs/clang-doc.rst
@@ -17,7 +17,7 @@
 there.
 
 Use
-=
+===
 
 :program:`clang-doc` is a `LibTooling
 `_-based tool, and so requires a
@@ -25,19 +25,42 @@
 see `How To Setup Tooling For LLVM
 `_).
 
-The tool can be used on a single file or multiple files as defined in 
-the compile commands database:
+By default, the tool will run on all files listed in the given compile commands
+database:
 
 .. code-block:: console
 
-  $ clang-doc /path/to/file.cpp -p /path/to/compile/commands
+  $ clang-doc /path/to/compile_commands.json
 
-This generates an intermediate representation of the declarations and their
-associated information in the specified TUs, serialized to LLVM bitcode.
+The tool can also be used on a single file or multiple files if a build path is
+passed with the ``-p`` flag.
 
-As currently implemented, the tool is only able to parse TUs that can be 
-stored in-memory. Future additions will extend the current framework to use

[PATCH] D65483: [clang-format] Add link to source code in file definitions

2019-07-30 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran created this revision.
DiegoAstiazaran added reviewers: juliehockett, jakehehrlich, lebedev.ri.
DiegoAstiazaran added a project: clang-tools-extra.
Herald added subscribers: kadircet, arphaman.

Two command line options have been added to clang-doc.

  --repository=   - URL of repository that hosts code; used for 
links to definition locations.
  --root-directory=   - Directory where processed files are stored. 
Links to definition locations will only be generated if the file is in this dir.

If the file is in the root-directory and a repository options is passed; a link 
to the source code will be rendered by the HTML generator.


https://reviews.llvm.org/D65483

Files:
  clang-tools-extra/clang-doc/BitcodeReader.cpp
  clang-tools-extra/clang-doc/BitcodeWriter.cpp
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/Mapper.cpp
  clang-tools-extra/clang-doc/Mapper.h
  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/tool/ClangDocMain.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
  clang-tools-extra/unittests/clang-doc/SerializeTest.cpp

Index: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -37,7 +37,7 @@
 
   template  bool mapDecl(const T *D) {
 auto I = serialize::emitInfo(D, getComment(D), /*Line=*/0,
- /*File=*/"test.cpp", Public);
+ /*File=*/"test.cpp", true, Public);
 if (I.first)
   EmittedInfos.emplace_back(std::move(I.first));
 if (I.second)
Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -22,12 +22,14 @@
 }
 
 ClangDocContext
-getClangDocContext(std::vector UserStylesheets = {}) {
+getClangDocContext(std::vector UserStylesheets = {},
+   StringRef RepositoryUrl = "") {
   ClangDocContext CDCtx;
   CDCtx.UserStylesheets = {UserStylesheets.begin(), UserStylesheets.end()};
   CDCtx.UserStylesheets.insert(
   CDCtx.UserStylesheets.begin(),
   "../share/clang/clang-doc-default-stylesheet.css");
+  CDCtx.RepositoryUrl = RepositoryUrl;
   return CDCtx;
 }
 
@@ -87,7 +89,7 @@
   I.Path = "X/Y/Z";
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
 
-  I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
+  I.DefLoc = Location(10, llvm::SmallString<16>{"dir/test.cpp"}, true);
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
   SmallString<16> PathTo;
@@ -107,7 +109,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  ClangDocContext CDCtx = getClangDocContext();
+  ClangDocContext CDCtx = getClangDocContext({}, "https://www.repository.com;);
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
   std::string Expected = R"raw(
@@ -116,7 +118,12 @@
 
 
   class r
-  Defined at line 10 of test.cpp
+  
+Defined at line 
+https://www.repository.com/dir/test.cpp#10;>10
+ of file 
+https://www.repository.com/dir/test.cpp;>test.cpp
+  
   
 Inherits from 
 F
@@ -154,7 +161,7 @@
   I.Name = "f";
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
 
-  I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
+  I.DefLoc = Location(10, llvm::SmallString<16>{"dir/test.cpp"}, false);
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
   SmallString<16> PathTo;
@@ -168,7 +175,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  ClangDocContext CDCtx = getClangDocContext();
+  ClangDocContext CDCtx = getClangDocContext({}, "https://www.repository.com;);
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
   std::string Expected = R"raw(
@@ -183,7 +190,7 @@
 int
  P)
   
-  Defined at line 10 of test.cpp
+  Defined at line 10 of file dir/test.cpp
 
 )raw";
 
@@ -217,7 +224,7 @@
   
 X
   
-  Defined at line 10 of test.cpp
+  Defined at line 10 of file test.cpp
 
 )raw";
 
@@ -284,7 +291,7 @@
 
   f
   void f(int I, int J)
-  Defined at line 10 of test.cpp
+  Defined at line 10 of file test.cpp
   
 
Brief description.
Index: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -67,6 +67,19 @@
 llvm::cl::desc("CSS stylesheets to extend the default styles."),
 llvm::cl::cat(ClangDocCategory));
 
+static llvm::cl::opt RootDirectory(

[PATCH] D65425: [clang-doc] Fix expected output in tests

2019-07-29 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL367279: [clang-doc] Fix expected output in tests (authored 
by DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65425?vs=212248=212255#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65425/new/

https://reviews.llvm.org/D65425

Files:
  clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp


Index: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -171,10 +171,6 @@
   ClangDocContext CDCtx = getClangDocContext();
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
-  SmallString<16> PathToFloat;
-  llvm::sys::path::native("path/to/float.html", PathToFloat);
-  SmallString<16> PathToInt;
-  llvm::sys::path::native("path/to/int.html", PathToInt);
   std::string Expected = R"raw(
 
 
@@ -182,11 +178,9 @@
 
   f
   
-float
+float
  f(
-int
+int
  P)
   
   Defined at line 10 of test.cpp


Index: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -171,10 +171,6 @@
   ClangDocContext CDCtx = getClangDocContext();
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
-  SmallString<16> PathToFloat;
-  llvm::sys::path::native("path/to/float.html", PathToFloat);
-  SmallString<16> PathToInt;
-  llvm::sys::path::native("path/to/int.html", PathToInt);
   std::string Expected = R"raw(
 
 
@@ -182,11 +178,9 @@
 
   f
   
-float
+float
  f(
-int
+int
  P)
   
   Defined at line 10 of test.cpp
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65425: [clang-doc] Fix expected output in tests

2019-07-29 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran created this revision.
DiegoAstiazaran added a reviewer: juliehockett.
DiegoAstiazaran added a project: clang-tools-extra.

Removes conversion of html paths in output. These will always be in posix-style 
paths.


https://reviews.llvm.org/D65425

Files:
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp


Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -171,10 +171,6 @@
   ClangDocContext CDCtx = getClangDocContext();
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
-  SmallString<16> PathToFloat;
-  llvm::sys::path::native("path/to/float.html", PathToFloat);
-  SmallString<16> PathToInt;
-  llvm::sys::path::native("path/to/int.html", PathToInt);
   std::string Expected = R"raw(
 
 
@@ -182,11 +178,9 @@
 
   f
   
-float
+float
  f(
-int
+int
  P)
   
   Defined at line 10 of test.cpp


Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -171,10 +171,6 @@
   ClangDocContext CDCtx = getClangDocContext();
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
-  SmallString<16> PathToFloat;
-  llvm::sys::path::native("path/to/float.html", PathToFloat);
-  SmallString<16> PathToInt;
-  llvm::sys::path::native("path/to/int.html", PathToInt);
   std::string Expected = R"raw(
 
 
@@ -182,11 +178,9 @@
 
   f
   
-float
+float
  f(
-int
+int
  P)
   
   Defined at line 10 of test.cpp
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65419: [clang-doc] Fix failing tests on Windows

2019-07-29 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL367264: [clang-doc] Fix failing tests on Windows (authored 
by DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65419?vs=212225=212234#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65419/new/

https://reviews.llvm.org/D65419

Files:
  clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp


Index: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
@@ -252,6 +252,8 @@
   llvm::SmallString<128> Path =
   computeRelativePath(Type.Path, CurrentDirectory);
   llvm::sys::path::append(Path, Type.Name + ".html");
+  // Paths in HTML must be in posix-style
+  llvm::sys::path::native(Path, llvm::sys::path::Style::posix);
   return genLink(Type.Name, Path);
 }
 


Index: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
@@ -252,6 +252,8 @@
   llvm::SmallString<128> Path =
   computeRelativePath(Type.Path, CurrentDirectory);
   llvm::sys::path::append(Path, Type.Name + ".html");
+  // Paths in HTML must be in posix-style
+  llvm::sys::path::native(Path, llvm::sys::path::Style::posix);
   return genLink(Type.Name, Path);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65419: [clang-doc] Fix failing tests on Windows

2019-07-29 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran created this revision.
DiegoAstiazaran added a reviewer: juliehockett.
DiegoAstiazaran added a project: clang-tools-extra.

Tests on Windows were failing due to path separator differences.
Links in HTML should use posix-style paths.


https://reviews.llvm.org/D65419

Files:
  clang-tools-extra/clang-doc/HTMLGenerator.cpp


Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -252,6 +252,8 @@
   llvm::SmallString<128> Path =
   computeRelativePath(Type.Path, CurrentDirectory);
   llvm::sys::path::append(Path, Type.Name + ".html");
+  // Paths in HTML must be in posix-style
+  llvm::sys::path::native(Path, llvm::sys::path::Style::posix);
   return genLink(Type.Name, Path);
 }
 


Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -252,6 +252,8 @@
   llvm::SmallString<128> Path =
   computeRelativePath(Type.Path, CurrentDirectory);
   llvm::sys::path::append(Path, Type.Name + ".html");
+  // Paths in HTML must be in posix-style
+  llvm::sys::path::native(Path, llvm::sys::path::Style::posix);
   return genLink(Type.Name, Path);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64958: [clang-doc] Fix link generation

2019-07-26 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 211979.
DiegoAstiazaran edited the summary of this revision.
DiegoAstiazaran added a comment.

Change attribute used to check special case of global namespace; IsPathValid 
changed to IsInGlobalNamespace. This attribute is true when its first parent is 
the global namespace or if the info is the global namespace,


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64958/new/

https://reviews.llvm.org/D64958

Files:
  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/Representation.h
  clang-tools-extra/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -80,7 +80,8 @@
   I.Members.emplace_back("int", "path/to/int", "X",
  AccessSpecifier::AS_private);
   I.TagType = TagTypeKind::TTK_Class;
-  I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record, "path/to/F");
+  I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record,
+ ""); // F is in the global namespace
   I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record,
 "path/to/G");
 
@@ -120,7 +121,7 @@
 Parents:
   - Type:Record
 Name:'F'
-Path:'path/to/F'
+IsInGlobalNamespace: true
 VirtualParents:
   - Type:Record
 Name:'G'
Index: clang-tools-extra/clang-doc/YAMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/YAMLGenerator.cpp
+++ clang-tools-extra/clang-doc/YAMLGenerator.cpp
@@ -156,6 +156,7 @@
 IO.mapOptional("Name", Ref.Name, SmallString<16>());
 IO.mapOptional("USR", Ref.USR, SymbolID());
 IO.mapOptional("Path", Ref.Path, SmallString<128>());
+IO.mapOptional("IsInGlobalNamespace", Ref.IsInGlobalNamespace, false);
   }
 };
 
Index: clang-tools-extra/clang-doc/Representation.h
===
--- clang-tools-extra/clang-doc/Representation.h
+++ clang-tools-extra/clang-doc/Representation.h
@@ -114,11 +114,17 @@
 struct Reference {
   Reference() = default;
   Reference(llvm::StringRef Name) : Name(Name) {}
-  Reference(llvm::StringRef Name, StringRef Path) : Name(Name), Path(Path) {}
+  // An empty path means the info is in the globalnamespace because the path is
+  // a composite of the parent namespaces.
+  Reference(llvm::StringRef Name, StringRef Path)
+  : Name(Name), Path(Path), IsInGlobalNamespace(Path.empty()) {}
   Reference(SymbolID USR, StringRef Name, InfoType IT)
   : USR(USR), Name(Name), RefType(IT) {}
+  // An empty path means the info is in the globalnamespace because the path is
+  // a composite of the parent namespaces.
   Reference(SymbolID USR, StringRef Name, InfoType IT, StringRef Path)
-  : USR(USR), Name(Name), RefType(IT), Path(Path) {}
+  : USR(USR), Name(Name), RefType(IT), Path(Path),
+IsInGlobalNamespace(Path.empty()) {}
 
   bool operator==(const Reference ) const {
 return std::tie(USR, Name, RefType) ==
@@ -130,8 +136,12 @@
   InfoType RefType = InfoType::IT_default; // Indicates the type of this
// Reference (namespace, record,
// function, enum, default).
-  llvm::SmallString<128> Path; // Path of directory where the clang-doc
-   // generated file will be saved
+  llvm::SmallString<128>
+  Path; // Path of directory where the clang-doc generated file will be
+// saved (possibly unresolved)
+  bool IsInGlobalNamespace =
+  false; // Indicates if the info's parent is the global namespace, or if
+ // the info is the global namespace
 };
 
 // A base struct for TypeInfos
Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -245,7 +245,7 @@
 
 static std::unique_ptr genTypeReference(const Reference ,
   StringRef CurrentDirectory) {
-  if (Type.Path.empty())
+  if (Type.Path.empty() && !Type.IsInGlobalNamespace)
 return llvm::make_unique(Type.Name);
   llvm::SmallString<128> Path =
   computeRelativePath(Type.Path, CurrentDirectory);
Index: clang-tools-extra/clang-doc/BitcodeWriter.h
===
--- clang-tools-extra/clang-doc/BitcodeWriter.h
+++ 

[PATCH] D65309: [clang-format] Fix style of css file paths

2019-07-26 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL367137: [clang-format] Fix style of css file paths (authored 
by DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65309?vs=211971=211972#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65309/new/

https://reviews.llvm.org/D65309

Files:
  clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp


Index: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -110,34 +110,23 @@
   ClangDocContext CDCtx = getClangDocContext();
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
-  SmallString<16> PathToF;
-  llvm::sys::path::native("../../../path/to/F.html", PathToF);
-  SmallString<16> PathToInt;
-  llvm::sys::path::native("../int.html", PathToInt);
-  SmallString<16> PathToSylesheet;
-  llvm::sys::path::native("../../../clang-doc-default-stylesheet.css",
-  PathToSylesheet);
   std::string Expected = R"raw(
 
 class r
-
+
 
   class r
   Defined at line 10 of test.cpp
   
 Inherits from 
-F
+F
 , G
   
   Members
   
 
   private 
-  int
+  int
X
 
   
Index: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
@@ -231,6 +231,8 @@
 SmallString<128> StylesheetPath = computeRelativePath("", InfoPath);
 llvm::sys::path::append(StylesheetPath,
 llvm::sys::path::filename(FilePath));
+// Paths in HTML must be in posix-style
+llvm::sys::path::native(StylesheetPath, llvm::sys::path::Style::posix);
 LinkNode->Attributes.try_emplace("href", StylesheetPath);
 Out.emplace_back(std::move(LinkNode));
   }


Index: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -110,34 +110,23 @@
   ClangDocContext CDCtx = getClangDocContext();
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
-  SmallString<16> PathToF;
-  llvm::sys::path::native("../../../path/to/F.html", PathToF);
-  SmallString<16> PathToInt;
-  llvm::sys::path::native("../int.html", PathToInt);
-  SmallString<16> PathToSylesheet;
-  llvm::sys::path::native("../../../clang-doc-default-stylesheet.css",
-  PathToSylesheet);
   std::string Expected = R"raw(
 
 class r
-
+
 
   class r
   Defined at line 10 of test.cpp
   
 Inherits from 
-F
+F
 , G
   
   Members
   
 
   private 
-  int
+  int
X
 
   
Index: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
@@ -231,6 +231,8 @@
 SmallString<128> StylesheetPath = computeRelativePath("", InfoPath);
 llvm::sys::path::append(StylesheetPath,
 llvm::sys::path::filename(FilePath));
+// Paths in HTML must be in posix-style
+llvm::sys::path::native(StylesheetPath, llvm::sys::path::Style::posix);
 LinkNode->Attributes.try_emplace("href", StylesheetPath);
 Out.emplace_back(std::move(LinkNode));
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65309: [clang-format] Fix style of css file paths

2019-07-26 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 211971.
DiegoAstiazaran added a comment.

Add comment.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65309/new/

https://reviews.llvm.org/D65309

Files:
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp


Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -110,34 +110,23 @@
   ClangDocContext CDCtx = getClangDocContext();
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
-  SmallString<16> PathToF;
-  llvm::sys::path::native("../../../path/to/F.html", PathToF);
-  SmallString<16> PathToInt;
-  llvm::sys::path::native("../int.html", PathToInt);
-  SmallString<16> PathToSylesheet;
-  llvm::sys::path::native("../../../clang-doc-default-stylesheet.css",
-  PathToSylesheet);
   std::string Expected = R"raw(
 
 class r
-
+
 
   class r
   Defined at line 10 of test.cpp
   
 Inherits from 
-F
+F
 , G
   
   Members
   
 
   private 
-  int
+  int
X
 
   
Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -231,6 +231,8 @@
 SmallString<128> StylesheetPath = computeRelativePath("", InfoPath);
 llvm::sys::path::append(StylesheetPath,
 llvm::sys::path::filename(FilePath));
+// Paths in HTML must be in posix-style
+llvm::sys::path::native(StylesheetPath, llvm::sys::path::Style::posix);
 LinkNode->Attributes.try_emplace("href", StylesheetPath);
 Out.emplace_back(std::move(LinkNode));
   }


Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -110,34 +110,23 @@
   ClangDocContext CDCtx = getClangDocContext();
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
-  SmallString<16> PathToF;
-  llvm::sys::path::native("../../../path/to/F.html", PathToF);
-  SmallString<16> PathToInt;
-  llvm::sys::path::native("../int.html", PathToInt);
-  SmallString<16> PathToSylesheet;
-  llvm::sys::path::native("../../../clang-doc-default-stylesheet.css",
-  PathToSylesheet);
   std::string Expected = R"raw(
 
 class r
-
+
 
   class r
   Defined at line 10 of test.cpp
   
 Inherits from 
-F
+F
 , G
   
   Members
   
 
   private 
-  int
+  int
X
 
   
Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -231,6 +231,8 @@
 SmallString<128> StylesheetPath = computeRelativePath("", InfoPath);
 llvm::sys::path::append(StylesheetPath,
 llvm::sys::path::filename(FilePath));
+// Paths in HTML must be in posix-style
+llvm::sys::path::native(StylesheetPath, llvm::sys::path::Style::posix);
 LinkNode->Attributes.try_emplace("href", StylesheetPath);
 Out.emplace_back(std::move(LinkNode));
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65030: [clang-doc] Add second index for sections within info's content

2019-07-26 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran added inline comments.



Comment at: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp:47-52
+
+  Namespaces
+  Records
+  Functions
+  OneFunction
+

juliehockett wrote:
> Formatting is a bit weird for sublists
Fixed by D65005. It will be properly formatted after rebasing.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65030/new/

https://reviews.llvm.org/D65030



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


[PATCH] D65030: [clang-doc] Add second index for sections within info's content

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 211869.
DiegoAstiazaran marked 3 inline comments as done.
DiegoAstiazaran added a comment.

Add comment.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65030/new/

https://reviews.llvm.org/D65030

Files:
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/Representation.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -44,26 +44,36 @@
   std::string Expected = R"raw(
 
 namespace Namespace
+
+  Namespaces
+  Records
+  Functions
+  OneFunction
+
+  Enums
+  OneEnum
+
+
 
   namespace Namespace
-  Namespaces
+  Namespaces
   
 ChildNamespace
   
-  Records
+  Records
   
 ChildStruct
   
-  Functions
+  Functions
   
-OneFunction
+OneFunction
 
   OneFunction()
 
   
-  Enums
+  Enums
   
-enum OneEnum
+enum OneEnum
   
 
 )raw";
@@ -106,6 +116,16 @@
   std::string Expected = R"raw(
 
 class r
+
+  Members
+  Records
+  Functions
+  OneFunction
+
+  Enums
+  OneEnum
+
+
 
   class r
   
@@ -117,25 +137,25 @@
  R"raw(">F
 , G
   
-  Members
+  Members
   
 private int X
   
-  Records
+  Records
   
 ChildStruct
   
-  Functions
+  Functions
   
-OneFunction
+OneFunction
 
   OneFunction()
 
   
-  Enums
+  Enums
   
-enum OneEnum
+enum OneEnum
   
 
 )raw";
@@ -172,7 +192,7 @@
 
 
 
-  f
+  f
   
 float
@@ -211,7 +231,7 @@
 
 
 
-  enum class e
+  enum class e
   
 X
   
@@ -271,7 +291,7 @@
 
 
 
-  f
+  f
   
 void f(int I, int J)
   
Index: clang-tools-extra/clang-doc/Representation.h
===
--- clang-tools-extra/clang-doc/Representation.h
+++ clang-tools-extra/clang-doc/Representation.h
@@ -239,7 +239,7 @@
   void mergeBase(Info &);
   bool mergeable(const Info );
 
-  llvm::SmallString<16> extractName();
+  llvm::SmallString<16> extractName() const;
 
   // Returns a reference to the parent scope (that is, the immediate parent
   // namespace or class in which this decl resides).
@@ -340,11 +340,14 @@
 
 struct Index : public Reference {
   Index() = default;
+  Index(StringRef Name, StringRef JumpToSection)
+  : Reference(Name), JumpToSection(JumpToSection) {}
   Index(SymbolID USR, StringRef Name, InfoType IT, StringRef Path)
   : Reference(USR, Name, IT, Path) {}
   bool operator==(const SymbolID ) const { return USR == Other; }
   bool operator<(const Index ) const { return Name < Other.Name; }
 
+  SmallString<16> JumpToSection;
   std::vector Children;
 
   void sort();
Index: clang-tools-extra/clang-doc/Representation.cpp
===
--- clang-tools-extra/clang-doc/Representation.cpp
+++ clang-tools-extra/clang-doc/Representation.cpp
@@ -197,7 +197,7 @@
   SymbolInfo::merge(std::move(Other));
 }
 
-llvm::SmallString<16> Info::extractName() {
+llvm::SmallString<16> Info::extractName() const {
   if (!Name.empty())
 return Name;
 
Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -252,13 +252,20 @@
   return LinkNode;
 }
 
-static std::unique_ptr genTypeReference(const Reference ,
-  StringRef CurrentDirectory) {
-  if (Type.Path.empty())
-return llvm::make_unique(Type.Name);
+static std::unique_ptr
+genTypeReference(const Reference , StringRef CurrentDirectory,
+ StringRef JumpToSection = "") {
+  if (Type.Path.empty()) {
+if (JumpToSection.empty())
+  return llvm::make_unique(Type.Name);
+else
+  return genLink(Type.Name, "#" + JumpToSection);
+  }
   llvm::SmallString<128> Path =
   computeRelativePath(Type.Path, CurrentDirectory);
   llvm::sys::path::append(Path, Type.Name + ".html");
+  if (!JumpToSection.empty())
+Path += ("#" + JumpToSection).str();
   return genLink(Type.Name, Path);
 }
 
@@ -285,6 +292,7 @@
 
   std::vector> Out;
   Out.emplace_back(llvm::make_unique(HTMLTag::TAG_H2, "Enums"));
+  Out.back()->Attributes.try_emplace("id", "Enums");
   Out.emplace_back(llvm::make_unique(HTMLTag::TAG_DIV));
   auto  = Out.back();
   for (const auto  : Enums) {
@@ -313,6 +321,7 @@
 
   std::vector> Out;
   Out.emplace_back(llvm::make_unique(HTMLTag::TAG_H2, "Functions"));
+  Out.back()->Attributes.try_emplace("id", "Functions");
   Out.emplace_back(llvm::make_unique(HTMLTag::TAG_DIV));
   auto  = Out.back();
   for (const auto  : Functions) {
@@ -330,6 +339,7 @@
 
   std::vector> Out;
   

[PATCH] D65003: [clang-doc] Add index in each info html file

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran added inline comments.



Comment at: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp:337-346
+
+  A
+  B
+  C
+
+  D
+  E

juliehockett wrote:
> The indentation here seems a bit off
Fixed by D65005.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65003/new/

https://reviews.llvm.org/D65003



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


[PATCH] D65003: [clang-doc] Add index in each info html file

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 211866.
DiegoAstiazaran marked 3 inline comments as done.
DiegoAstiazaran added a comment.

Rebase and add comments.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65003/new/

https://reviews.llvm.org/D65003

Files:
  clang-tools-extra/clang-doc/Generators.cpp
  clang-tools-extra/clang-doc/Generators.h
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/Representation.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/unittests/clang-doc/CMakeLists.txt
  clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
  clang-tools-extra/unittests/clang-doc/ClangDocTest.h
  clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -9,6 +9,7 @@
 #include "ClangDocTest.h"
 #include "Generators.h"
 #include "Representation.h"
+#include "Serialize.h"
 #include "gtest/gtest.h"
 
 namespace clang {
@@ -315,5 +316,79 @@
   EXPECT_EQ(Expected, Actual.str());
 }
 
+TEST(HTMLGeneratorTest, emitIndexHTML) {
+  RecordInfo I;
+  I.Path = "";
+  ClangDocContext CDCtx;
+  std::vector> Infos;
+  Infos.emplace_back(llvm::make_unique());
+  Info *InfoA = Infos.back().get();
+  InfoA->Name = "A";
+  InfoA->USR = serialize::hashUSR("1");
+  Infos.emplace_back(llvm::make_unique());
+  Info *InfoC = Infos.back().get();
+  InfoC->Name = "C";
+  InfoC->USR = serialize::hashUSR("3");
+  Reference RefB = Reference("B");
+  RefB.USR = serialize::hashUSR("2");
+  InfoC->Namespace = {std::move(RefB)};
+  Infos.emplace_back(llvm::make_unique());
+  Info *InfoD = Infos.back().get();
+  InfoD->Name = "D";
+  InfoD->USR = serialize::hashUSR("4");
+  Infos.emplace_back(llvm::make_unique());
+  Info *InfoF = Infos.back().get();
+  InfoF->Name = "F";
+  InfoF->USR = serialize::hashUSR("6");
+  Reference RefD = Reference("D");
+  RefD.USR = serialize::hashUSR("4");
+  Reference RefE = Reference("E");
+  RefE.USR = serialize::hashUSR("5");
+  InfoF->Namespace = {std::move(RefE), std::move(RefD)};
+  CDCtx.Idx = Generator::genIndex(Infos);
+
+  auto G = getHTMLGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(, Actual, CDCtx);
+  assert(!Err);
+  std::string Expected = R"raw(
+
+struct 
+
+  
+A
+  
+  
+B
+
+  
+C
+  
+
+  
+  
+D
+
+  
+E
+
+  
+F
+  
+
+  
+
+  
+
+
+  struct 
+
+)raw";
+
+  EXPECT_EQ(Expected, Actual.str());
+}
+
 } // namespace doc
 } // namespace clang
Index: clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp
@@ -0,0 +1,70 @@
+//===-- clang-doc/GeneratorTest.cpp ---===//
+//
+// 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
+//
+//===--===//
+
+#include "ClangDocTest.h"
+#include "Generators.h"
+#include "Representation.h"
+#include "Serialize.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace doc {
+
+TEST(GeneratorTest, emitIndex) {
+  std::vector> Infos;
+  Infos.emplace_back(llvm::make_unique());
+  Info *InfoA = Infos.back().get();
+  InfoA->Name = "A";
+  InfoA->USR = serialize::hashUSR("1");
+  Infos.emplace_back(llvm::make_unique());
+  Info *InfoC = Infos.back().get();
+  InfoC->Name = "C";
+  InfoC->USR = serialize::hashUSR("3");
+  Reference RefB = Reference("B");
+  RefB.USR = serialize::hashUSR("2");
+  InfoC->Namespace = {std::move(RefB)};
+  Infos.emplace_back(llvm::make_unique());
+  Info *InfoD = Infos.back().get();
+  InfoD->Name = "D";
+  InfoD->USR = serialize::hashUSR("4");
+  Infos.emplace_back(llvm::make_unique());
+  Info *InfoF = Infos.back().get();
+  InfoF->Name = "F";
+  InfoF->USR = serialize::hashUSR("6");
+  Reference RefD = Reference("D");
+  RefD.USR = serialize::hashUSR("4");
+  Reference RefE = Reference("E");
+  RefE.USR = serialize::hashUSR("5");
+  InfoF->Namespace = {std::move(RefE), std::move(RefD)};
+  Index Idx = Generator::genIndex(Infos);
+
+  Index ExpectedIdx;
+  Index IndexA;
+  IndexA.Name = "A";
+  ExpectedIdx.Children.emplace_back(std::move(IndexA));
+  Index IndexB;
+  IndexB.Name = "B";
+  Index IndexC;
+  IndexC.Name = "C";
+  IndexB.Children.emplace_back(std::move(IndexC));
+  

[PATCH] D65309: [clang-format] Fix style of css file paths

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran created this revision.
DiegoAstiazaran added reviewers: juliehockett, jakehehrlich.
DiegoAstiazaran added a project: clang-tools-extra.

CSS files included in HTML should have a path in posix style, it should not be 
different for Windows.


https://reviews.llvm.org/D65309

Files:
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp


Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -110,34 +110,23 @@
   ClangDocContext CDCtx = getClangDocContext();
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
-  SmallString<16> PathToF;
-  llvm::sys::path::native("../../../path/to/F.html", PathToF);
-  SmallString<16> PathToInt;
-  llvm::sys::path::native("../int.html", PathToInt);
-  SmallString<16> PathToSylesheet;
-  llvm::sys::path::native("../../../clang-doc-default-stylesheet.css",
-  PathToSylesheet);
   std::string Expected = R"raw(
 
 class r
-
+
 
   class r
   Defined at line 10 of test.cpp
   
 Inherits from 
-F
+F
 , G
   
   Members
   
 
   private 
-  int
+  int
X
 
   
Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -231,6 +231,7 @@
 SmallString<128> StylesheetPath = computeRelativePath("", InfoPath);
 llvm::sys::path::append(StylesheetPath,
 llvm::sys::path::filename(FilePath));
+llvm::sys::path::native(StylesheetPath, llvm::sys::path::Style::posix);
 LinkNode->Attributes.try_emplace("href", StylesheetPath);
 Out.emplace_back(std::move(LinkNode));
   }


Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -110,34 +110,23 @@
   ClangDocContext CDCtx = getClangDocContext();
   auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
-  SmallString<16> PathToF;
-  llvm::sys::path::native("../../../path/to/F.html", PathToF);
-  SmallString<16> PathToInt;
-  llvm::sys::path::native("../int.html", PathToInt);
-  SmallString<16> PathToSylesheet;
-  llvm::sys::path::native("../../../clang-doc-default-stylesheet.css",
-  PathToSylesheet);
   std::string Expected = R"raw(
 
 class r
-
+
 
   class r
   Defined at line 10 of test.cpp
   
 Inherits from 
-F
+F
 , G
   
   Members
   
 
   private 
-  int
+  int
X
 
   
Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -231,6 +231,7 @@
 SmallString<128> StylesheetPath = computeRelativePath("", InfoPath);
 llvm::sys::path::append(StylesheetPath,
 llvm::sys::path::filename(FilePath));
+llvm::sys::path::native(StylesheetPath, llvm::sys::path::Style::posix);
 LinkNode->Attributes.try_emplace("href", StylesheetPath);
 Out.emplace_back(std::move(LinkNode));
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65306: [clang-doc] Fix failing tests on Windows

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL367074: [clang-doc] Fix failing tests on Windows (authored 
by DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65306?vs=211848=211854#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65306/new/

https://reviews.llvm.org/D65306

Files:
  clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp


Index: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -114,10 +114,15 @@
   llvm::sys::path::native("../../../path/to/F.html", PathToF);
   SmallString<16> PathToInt;
   llvm::sys::path::native("../int.html", PathToInt);
+  SmallString<16> PathToSylesheet;
+  llvm::sys::path::native("../../../clang-doc-default-stylesheet.css",
+  PathToSylesheet);
   std::string Expected = R"raw(
 
 class r
-
+
 
   class r
   Defined at line 10 of test.cpp


Index: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -114,10 +114,15 @@
   llvm::sys::path::native("../../../path/to/F.html", PathToF);
   SmallString<16> PathToInt;
   llvm::sys::path::native("../int.html", PathToInt);
+  SmallString<16> PathToSylesheet;
+  llvm::sys::path::native("../../../clang-doc-default-stylesheet.css",
+  PathToSylesheet);
   std::string Expected = R"raw(
 
 class r
-
+
 
   class r
   Defined at line 10 of test.cpp
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65306: [clang-doc] Fix failing tests on Windows

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran created this revision.
DiegoAstiazaran added a reviewer: juliehockett.
DiegoAstiazaran added a project: clang-tools-extra.
juliehockett accepted this revision.
juliehockett added a comment.
This revision is now accepted and ready to land.

Make sure you update the other stylesheet patch, as well, before landing that.


Tests on Windows were failing due to path separator differences.
 '/' was being used as separator in the expected output, paths in expected 
output are now changed to their native form before comparing them to the actual 
output.


https://reviews.llvm.org/D65306

Files:
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp


Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -114,10 +114,15 @@
   llvm::sys::path::native("../../../path/to/F.html", PathToF);
   SmallString<16> PathToInt;
   llvm::sys::path::native("../int.html", PathToInt);
+  SmallString<16> PathToSylesheet;
+  llvm::sys::path::native("../../../clang-doc-default-stylesheet.css",
+  PathToSylesheet);
   std::string Expected = R"raw(
 
 class r
-
+
 
   class r
   Defined at line 10 of test.cpp


Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -114,10 +114,15 @@
   llvm::sys::path::native("../../../path/to/F.html", PathToF);
   SmallString<16> PathToInt;
   llvm::sys::path::native("../int.html", PathToInt);
+  SmallString<16> PathToSylesheet;
+  llvm::sys::path::native("../../../clang-doc-default-stylesheet.css",
+  PathToSylesheet);
   std::string Expected = R"raw(
 
 class r
-
+
 
   class r
   Defined at line 10 of test.cpp
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64938: [clang-doc] Add option for user provided stylesheets

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL367072: [clang-doc] Add option for user provided stylesheets 
(authored by DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64938?vs=211841=211846#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64938/new/

https://reviews.llvm.org/D64938

Files:
  clang-tools-extra/trunk/clang-doc/Generators.h
  clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/trunk/clang-doc/MDGenerator.cpp
  clang-tools-extra/trunk/clang-doc/Representation.h
  clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
  clang-tools-extra/trunk/unittests/clang-doc/MDGeneratorTest.cpp
  clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp

Index: clang-tools-extra/trunk/unittests/clang-doc/MDGeneratorTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/MDGeneratorTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/MDGeneratorTest.cpp
@@ -38,7 +38,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected = R"raw(# namespace Namespace
 
@@ -101,7 +101,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected = R"raw(# class r
 
@@ -162,7 +162,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected = R"raw(### f
 
@@ -190,7 +190,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected = R"raw(| enum class e |
 
@@ -320,7 +320,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected =
   R"raw(### f
Index: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -21,6 +21,16 @@
   return std::move(G.get());
 }
 
+ClangDocContext
+getClangDocContext(std::vector UserStylesheets = {}) {
+  ClangDocContext CDCtx;
+  CDCtx.UserStylesheets = {UserStylesheets.begin(), UserStylesheets.end()};
+  CDCtx.UserStylesheets.insert(
+  CDCtx.UserStylesheets.begin(),
+  "../share/clang/clang-doc-default-stylesheet.css");
+  return CDCtx;
+}
+
 TEST(HTMLGeneratorTest, emitNamespaceHTML) {
   NamespaceInfo I;
   I.Name = "Namespace";
@@ -38,12 +48,14 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  ClangDocContext CDCtx = getClangDocContext({"user-provided-stylesheet.css"});
+  auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
   std::string Expected = R"raw(
 
 namespace Namespace
 
+
 
   namespace Namespace
   Namespaces
@@ -95,7 +107,8 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  ClangDocContext CDCtx = getClangDocContext();
+  auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
   SmallString<16> PathToF;
   llvm::sys::path::native("../../../path/to/F.html", PathToF);
@@ -161,7 +174,8 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  ClangDocContext CDCtx = getClangDocContext();
+  auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
   SmallString<16> PathToFloat;
   llvm::sys::path::native("path/to/float.html", PathToFloat);
@@ -203,7 +217,8 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  ClangDocContext CDCtx = getClangDocContext();
+  auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
   std::string Expected = R"raw(
 
@@ -271,7 +286,8 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  

[PATCH] D64938: [clang-doc] Add option for user provided stylesheets

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 211841.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64938/new/

https://reviews.llvm.org/D64938

Files:
  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/Representation.h
  clang-tools-extra/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
  clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
  clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -40,7 +40,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected =
   R"raw(---
@@ -94,7 +94,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected =
   R"raw(---
@@ -158,7 +158,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected =
   R"raw(---
@@ -206,7 +206,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected =
   R"raw(---
@@ -343,7 +343,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected =
   R"raw(---
Index: clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
@@ -38,7 +38,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected = R"raw(# namespace Namespace
 
@@ -101,7 +101,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected = R"raw(# class r
 
@@ -162,7 +162,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected = R"raw(### f
 
@@ -190,7 +190,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected = R"raw(| enum class e |
 
@@ -320,7 +320,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected =
   R"raw(### f
Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -21,6 +21,16 @@
   return std::move(G.get());
 }
 
+ClangDocContext
+getClangDocContext(std::vector UserStylesheets = {}) {
+  ClangDocContext CDCtx;
+  CDCtx.UserStylesheets = {UserStylesheets.begin(), UserStylesheets.end()};
+  CDCtx.UserStylesheets.insert(
+  CDCtx.UserStylesheets.begin(),
+  "../share/clang/clang-doc-default-stylesheet.css");
+  return CDCtx;
+}
+
 TEST(HTMLGeneratorTest, emitNamespaceHTML) {
   NamespaceInfo I;
   I.Name = "Namespace";
@@ -38,12 +48,14 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  ClangDocContext CDCtx = getClangDocContext({"user-provided-stylesheet.css"});
+  auto Err = G->generateDocForInfo(, Actual, CDCtx);
   assert(!Err);
   std::string Expected = R"raw(
 
 namespace Namespace
 

[PATCH] D64539: [clang-doc] Add stylesheet to generated html docs

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdb5d8e3db253: [clang-doc] Add stylesheet to generated html 
docs (authored by DiegoAstiazaran).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64539/new/

https://reviews.llvm.org/D64539

Files:
  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/Representation.h
  clang-tools-extra/clang-doc/Serialize.cpp
  clang-tools-extra/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/clang-doc/stylesheets/clang-doc-default-stylesheet.css
  clang-tools-extra/clang-doc/tool/CMakeLists.txt
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -43,6 +43,7 @@
   std::string Expected = R"raw(
 
 namespace Namespace
+
 
   namespace Namespace
   Namespaces
@@ -103,6 +104,7 @@
   std::string Expected = R"raw(
 
 class r
+
 
   class r
   Defined at line 10 of test.cpp
@@ -168,6 +170,7 @@
   std::string Expected = R"raw(
 
 
+
 
   f
   
@@ -205,6 +208,7 @@
   std::string Expected = R"raw(
 
 
+
 
   enum class e
   
@@ -272,6 +276,7 @@
   std::string Expected = R"raw(
 
 
+
 
   f
   void f(int I, int J)
Index: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -91,6 +91,15 @@
   llvm_unreachable("Unknown OutputFormatTy");
 }
 
+// This function isn't referenced outside its translation unit, but it
+// can't use the "static" keyword because its address is used for
+// GetMainExecutable (since some platforms don't support taking the
+// address of main, and some platforms can't implement GetMainExecutable
+// without being given the address of a function in the main executable).
+std::string GetExecutablePath(const char *Argv0, void *MainAddr) {
+  return llvm::sys::fs::getMainExecutable(Argv0, MainAddr);
+}
+
 bool CreateDirectory(const Twine , bool ClearDirectory = false) {
   std::error_code OK;
   llvm::SmallString<128> DocsRootPath;
@@ -129,7 +138,6 @@
  StringRef RelativePath,
  StringRef Name,
  StringRef Ext) {
-  std::error_code OK;
   llvm::SmallString<128> Path;
   llvm::sys::path::native(Root, Path);
   llvm::sys::path::append(Path, RelativePath);
@@ -195,8 +203,10 @@
 
   // Mapping phase
   llvm::outs() << "Mapping decls...\n";
+  void *MainAddr = (void *)(intptr_t)GetExecutablePath;
+  std::string ClangDocPath = GetExecutablePath(argv[0], MainAddr);
   clang::doc::ClangDocContext CDCtx = {Exec->get()->getExecutionContext(),
-   PublicOnly};
+   PublicOnly, OutDirectory, ClangDocPath};
   auto Err =
   Exec->get()->execute(doc::newMapperActionFactory(CDCtx), ArgAdjuster);
   if (Err) {
@@ -239,5 +249,8 @@
   llvm::errs() << toString(std::move(Err)) << "\n";
   }
 
+  if (!G->get()->createResources(CDCtx))
+return 1;
+
   return 0;
 }
Index: clang-tools-extra/clang-doc/tool/CMakeLists.txt
===
--- clang-tools-extra/clang-doc/tool/CMakeLists.txt
+++ clang-tools-extra/clang-doc/tool/CMakeLists.txt
@@ -14,4 +14,7 @@
   clangTooling
   clangToolingCore
   )
-  
\ No newline at end of file
+
+install(FILES ../stylesheets/clang-doc-default-stylesheet.css
+  DESTINATION share/clang
+  COMPONENT clang-doc)
Index: clang-tools-extra/clang-doc/stylesheets/clang-doc-default-stylesheet.css
===
--- /dev/null
+++ clang-tools-extra/clang-doc/stylesheets/clang-doc-default-stylesheet.css
@@ -0,0 +1,205 @@
+body,div {
+  margin: 0;
+  padding: 0;
+}
+
+body[no-overflow] {
+  overflow: hidden;
+}
+
+li>p:first-child {
+  margin-top: 0;
+}
+
+li>p:last-child {
+  margin-bottom: 0;
+}
+
+html {
+  -webkit-box-sizing: border-box;
+  box-sizing: border-box;
+}
+
+*,*::before,*::after {
+  -webkit-box-sizing: inherit;
+  box-sizing: inherit;
+}
+
+body,html {
+  color: #202124;
+  font: 400 16px/24px Roboto,sans-serif;
+  -moz-osx-font-smoothing: grayscale;
+  -webkit-font-smoothing: antialiased;
+  height: 100%;
+  margin: 36px;
+  -webkit-text-size-adjust: 100%;
+  -moz-text-size-adjust: 100%;
+  -ms-text-size-adjust: 100%;
+  text-size-adjust: 100%;
+}
+
+body[devsite-framebox] {
+  

[PATCH] D64539: [clang-doc] Add stylesheet to generated html docs

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 211820.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64539/new/

https://reviews.llvm.org/D64539

Files:
  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/Representation.h
  clang-tools-extra/clang-doc/Serialize.cpp
  clang-tools-extra/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/clang-doc/stylesheets/clang-doc-default-stylesheet.css
  clang-tools-extra/clang-doc/tool/CMakeLists.txt
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -43,6 +43,7 @@
   std::string Expected = R"raw(
 
 namespace Namespace
+
 
   namespace Namespace
   Namespaces
@@ -103,6 +104,7 @@
   std::string Expected = R"raw(
 
 class r
+
 
   class r
   Defined at line 10 of test.cpp
@@ -168,6 +170,7 @@
   std::string Expected = R"raw(
 
 
+
 
   f
   
@@ -205,6 +208,7 @@
   std::string Expected = R"raw(
 
 
+
 
   enum class e
   
@@ -272,6 +276,7 @@
   std::string Expected = R"raw(
 
 
+
 
   f
   void f(int I, int J)
Index: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
===
--- clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -91,6 +91,15 @@
   llvm_unreachable("Unknown OutputFormatTy");
 }
 
+// This function isn't referenced outside its translation unit, but it
+// can't use the "static" keyword because its address is used for
+// GetMainExecutable (since some platforms don't support taking the
+// address of main, and some platforms can't implement GetMainExecutable
+// without being given the address of a function in the main executable).
+std::string GetExecutablePath(const char *Argv0, void *MainAddr) {
+  return llvm::sys::fs::getMainExecutable(Argv0, MainAddr);
+}
+
 bool CreateDirectory(const Twine , bool ClearDirectory = false) {
   std::error_code OK;
   llvm::SmallString<128> DocsRootPath;
@@ -129,7 +138,6 @@
  StringRef RelativePath,
  StringRef Name,
  StringRef Ext) {
-  std::error_code OK;
   llvm::SmallString<128> Path;
   llvm::sys::path::native(Root, Path);
   llvm::sys::path::append(Path, RelativePath);
@@ -195,8 +203,10 @@
 
   // Mapping phase
   llvm::outs() << "Mapping decls...\n";
+  void *MainAddr = (void *)(intptr_t)GetExecutablePath;
+  std::string ClangDocPath = GetExecutablePath(argv[0], MainAddr);
   clang::doc::ClangDocContext CDCtx = {Exec->get()->getExecutionContext(),
-   PublicOnly};
+   PublicOnly, OutDirectory, ClangDocPath};
   auto Err =
   Exec->get()->execute(doc::newMapperActionFactory(CDCtx), ArgAdjuster);
   if (Err) {
@@ -239,5 +249,8 @@
   llvm::errs() << toString(std::move(Err)) << "\n";
   }
 
+  if (!G->get()->createResources(CDCtx))
+return 1;
+
   return 0;
 }
Index: clang-tools-extra/clang-doc/tool/CMakeLists.txt
===
--- clang-tools-extra/clang-doc/tool/CMakeLists.txt
+++ clang-tools-extra/clang-doc/tool/CMakeLists.txt
@@ -14,4 +14,7 @@
   clangTooling
   clangToolingCore
   )
-  
\ No newline at end of file
+
+install(FILES ../stylesheets/clang-doc-default-stylesheet.css
+  DESTINATION share/clang
+  COMPONENT clang-doc)
Index: clang-tools-extra/clang-doc/stylesheets/clang-doc-default-stylesheet.css
===
--- /dev/null
+++ clang-tools-extra/clang-doc/stylesheets/clang-doc-default-stylesheet.css
@@ -0,0 +1,205 @@
+body,div {
+  margin: 0;
+  padding: 0;
+}
+
+body[no-overflow] {
+  overflow: hidden;
+}
+
+li>p:first-child {
+  margin-top: 0;
+}
+
+li>p:last-child {
+  margin-bottom: 0;
+}
+
+html {
+  -webkit-box-sizing: border-box;
+  box-sizing: border-box;
+}
+
+*,*::before,*::after {
+  -webkit-box-sizing: inherit;
+  box-sizing: inherit;
+}
+
+body,html {
+  color: #202124;
+  font: 400 16px/24px Roboto,sans-serif;
+  -moz-osx-font-smoothing: grayscale;
+  -webkit-font-smoothing: antialiased;
+  height: 100%;
+  margin: 36px;
+  -webkit-text-size-adjust: 100%;
+  -moz-text-size-adjust: 100%;
+  -ms-text-size-adjust: 100%;
+  text-size-adjust: 100%;
+}
+
+body[devsite-framebox] {
+  overflow: hidden;
+  padding: 20px;
+}
+
+body[sitemask--active] {
+  overflow: hidden;
+}
+
+p {
+  margin: 16px 0;
+  padding: 0;
+}
+
+:link,:visited {
+  color: #039be5;
+  outline: 0;
+  text-decoration: 

[PATCH] D65005: [clang-doc] Fix output format of html

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL367050: [clang-doc] Fix output format of html (authored by 
DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65005?vs=211812=211814#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65005/new/

https://reviews.llvm.org/D65005

Files:
  clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp

Index: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -56,9 +56,7 @@
   Functions
   
 OneFunction
-
-  OneFunction()
-
+OneFunction()
   
   Enums
   
@@ -107,9 +105,7 @@
 class r
 
   class r
-  
-Defined at line 10 of test.cpp
-  
+  Defined at line 10 of test.cpp
   
 Inherits from 
 
   Members
   
-private int X
+
+  private 
+  int
+   X
+
   
   Records
   
@@ -128,9 +128,7 @@
   Functions
   
 OneFunction
-
-  OneFunction()
-
+OneFunction()
   
   Enums
   
@@ -180,9 +178,7 @@
  R"raw(">int
  P)
   
-  
-Defined at line 10 of test.cpp
-  
+  Defined at line 10 of test.cpp
 
 )raw";
 
@@ -214,9 +210,7 @@
   
 X
   
-  
-Defined at line 10 of test.cpp
-  
+  Defined at line 10 of test.cpp
 
 )raw";
 
@@ -280,23 +274,13 @@
 
 
   f
-  
-void f(int I, int J)
-  
-  
-Defined at line 10 of test.cpp
-  
+  void f(int I, int J)
+  Defined at line 10 of test.cpp
   
 
-  
- Brief description.
-  
-  
- Extended description that continues onto the next line.
-  
-  
- Comment with html entities: , , , , .
-  
+   Brief description.
+   Extended description that continues onto the next line.
+   Comment with html entities: , , , , .
 
   
 
Index: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
@@ -44,9 +44,6 @@
   operator bool() = delete;
 
   bool IsSelfClosing() const;
-
-  bool HasInlineChildren() const;
-
   llvm::SmallString<16> ToString() const;
 
 private:
@@ -67,29 +64,20 @@
 };
 
 struct TextNode : public HTMLNode {
-  TextNode(const Twine , bool Indented = true)
-  : HTMLNode(NodeType::NODE_TEXT), Text(Text.str()), Indented(Indented) {}
+  TextNode(const Twine )
+  : HTMLNode(NodeType::NODE_TEXT), Text(Text.str()) {}
 
   std::string Text; // Content of node
-  bool Indented; // Indicates if an indentation must be rendered before the text
   void Render(llvm::raw_ostream , int IndentationLevel) override;
 };
 
 struct TagNode : public HTMLNode {
-  TagNode(HTMLTag Tag)
-  : HTMLNode(NodeType::NODE_TAG), Tag(Tag),
-InlineChildren(Tag.HasInlineChildren()),
-SelfClosing(Tag.IsSelfClosing()) {}
+  TagNode(HTMLTag Tag) : HTMLNode(NodeType::NODE_TAG), Tag(Tag) {}
   TagNode(HTMLTag Tag, const Twine ) : TagNode(Tag) {
-Children.emplace_back(
-llvm::make_unique(Text.str(), !InlineChildren));
+Children.emplace_back(llvm::make_unique(Text.str()));
   }
 
-  HTMLTag Tag; // Name of HTML Tag (p, div, h1)
-  bool InlineChildren; // Indicates if children nodes are rendered in the same
-   // line as itself or if children must rendered in the
-   // next line and with additional indentation
-  bool SelfClosing;// Indicates if tag is self-closing
+  HTMLTag Tag; // Name of HTML Tag (p, div, h1)
   std::vector> Children; // List of child nodes
   llvm::StringMap>
   Attributes; // List of key-value attributes for tag
@@ -130,24 +118,6 @@
   llvm_unreachable("Unhandled HTMLTag::TagType");
 }
 
-bool HTMLTag::HasInlineChildren() const {
-  switch (Value) {
-  case HTMLTag::TAG_META:
-  case HTMLTag::TAG_TITLE:
-  case HTMLTag::TAG_H1:
-  case HTMLTag::TAG_H2:
-  case HTMLTag::TAG_H3:
-  case HTMLTag::TAG_LI:
-  case HTMLTag::TAG_A:
-return true;
-  case HTMLTag::TAG_DIV:
-  case HTMLTag::TAG_P:
-  case HTMLTag::TAG_UL:
-return false;
-  }
-  llvm_unreachable("Unhandled HTMLTag::TagType");
-}
-
 llvm::SmallString<16> HTMLTag::ToString() const {
   switch (Value) {
   case HTMLTag::TAG_META:
@@ -175,17 +145,23 @@
 }
 
 void TextNode::Render(llvm::raw_ostream , int IndentationLevel) {
-  if (Indented)
-OS.indent(IndentationLevel * 2);
+  OS.indent(IndentationLevel * 2);
   printHTMLEscaped(Text, OS);
 }
 
 void TagNode::Render(llvm::raw_ostream , int IndentationLevel) {
+  // Children nodes are rendered in the same line if all of 

[PATCH] D65005: [clang-doc] Fix output format of html

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 211812.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65005/new/

https://reviews.llvm.org/D65005

Files:
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -56,9 +56,7 @@
   Functions
   
 OneFunction
-
-  OneFunction()
-
+OneFunction()
   
   Enums
   
@@ -107,9 +105,7 @@
 class r
 
   class r
-  
-Defined at line 10 of test.cpp
-  
+  Defined at line 10 of test.cpp
   
 Inherits from 
 
   Members
   
-private int X
+
+  private 
+  int
+   X
+
   
   Records
   
@@ -128,9 +128,7 @@
   Functions
   
 OneFunction
-
-  OneFunction()
-
+OneFunction()
   
   Enums
   
@@ -180,9 +178,7 @@
  R"raw(">int
  P)
   
-  
-Defined at line 10 of test.cpp
-  
+  Defined at line 10 of test.cpp
 
 )raw";
 
@@ -214,9 +210,7 @@
   
 X
   
-  
-Defined at line 10 of test.cpp
-  
+  Defined at line 10 of test.cpp
 
 )raw";
 
@@ -280,23 +274,13 @@
 
 
   f
-  
-void f(int I, int J)
-  
-  
-Defined at line 10 of test.cpp
-  
+  void f(int I, int J)
+  Defined at line 10 of test.cpp
   
 
-  
- Brief description.
-  
-  
- Extended description that continues onto the next line.
-  
-  
- Comment with html entities: , , , , .
-  
+   Brief description.
+   Extended description that continues onto the next line.
+   Comment with html entities: , , , , .
 
   
 
Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -44,9 +44,6 @@
   operator bool() = delete;
 
   bool IsSelfClosing() const;
-
-  bool HasInlineChildren() const;
-
   llvm::SmallString<16> ToString() const;
 
 private:
@@ -67,29 +64,20 @@
 };
 
 struct TextNode : public HTMLNode {
-  TextNode(const Twine , bool Indented = true)
-  : HTMLNode(NodeType::NODE_TEXT), Text(Text.str()), Indented(Indented) {}
+  TextNode(const Twine )
+  : HTMLNode(NodeType::NODE_TEXT), Text(Text.str()) {}
 
   std::string Text; // Content of node
-  bool Indented; // Indicates if an indentation must be rendered before the text
   void Render(llvm::raw_ostream , int IndentationLevel) override;
 };
 
 struct TagNode : public HTMLNode {
-  TagNode(HTMLTag Tag)
-  : HTMLNode(NodeType::NODE_TAG), Tag(Tag),
-InlineChildren(Tag.HasInlineChildren()),
-SelfClosing(Tag.IsSelfClosing()) {}
+  TagNode(HTMLTag Tag) : HTMLNode(NodeType::NODE_TAG), Tag(Tag) {}
   TagNode(HTMLTag Tag, const Twine ) : TagNode(Tag) {
-Children.emplace_back(
-llvm::make_unique(Text.str(), !InlineChildren));
+Children.emplace_back(llvm::make_unique(Text.str()));
   }
 
-  HTMLTag Tag; // Name of HTML Tag (p, div, h1)
-  bool InlineChildren; // Indicates if children nodes are rendered in the same
-   // line as itself or if children must rendered in the
-   // next line and with additional indentation
-  bool SelfClosing;// Indicates if tag is self-closing
+  HTMLTag Tag; // Name of HTML Tag (p, div, h1)
   std::vector> Children; // List of child nodes
   llvm::StringMap>
   Attributes; // List of key-value attributes for tag
@@ -130,24 +118,6 @@
   llvm_unreachable("Unhandled HTMLTag::TagType");
 }
 
-bool HTMLTag::HasInlineChildren() const {
-  switch (Value) {
-  case HTMLTag::TAG_META:
-  case HTMLTag::TAG_TITLE:
-  case HTMLTag::TAG_H1:
-  case HTMLTag::TAG_H2:
-  case HTMLTag::TAG_H3:
-  case HTMLTag::TAG_LI:
-  case HTMLTag::TAG_A:
-return true;
-  case HTMLTag::TAG_DIV:
-  case HTMLTag::TAG_P:
-  case HTMLTag::TAG_UL:
-return false;
-  }
-  llvm_unreachable("Unhandled HTMLTag::TagType");
-}
-
 llvm::SmallString<16> HTMLTag::ToString() const {
   switch (Value) {
   case HTMLTag::TAG_META:
@@ -175,17 +145,23 @@
 }
 
 void TextNode::Render(llvm::raw_ostream , int IndentationLevel) {
-  if (Indented)
-OS.indent(IndentationLevel * 2);
+  OS.indent(IndentationLevel * 2);
   printHTMLEscaped(Text, OS);
 }
 
 void TagNode::Render(llvm::raw_ostream , int IndentationLevel) {
+  // Children nodes are rendered in the same line if all of them are text nodes
+  bool InlineChildren = true;
+  for (const auto  : Children)
+if (C->Type == NodeType::NODE_TAG) {
+  InlineChildren = false;
+  break;
+}
   OS.indent(IndentationLevel * 2);
   OS << "<" << Tag.ToString();
   for (const auto  : Attributes)
 OS << " " << A.getKey() << "=\"" << A.getValue() << "\"";
-  if 

[PATCH] D65107: [clang-doc] Fix html entities in rendered text

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL367045: [clang-doc] Fix html entities in rendered text 
(authored by DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65107?vs=211201=211806#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65107/new/

https://reviews.llvm.org/D65107

Files:
  clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp


Index: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -258,6 +258,15 @@
   Extended->Children.back()->Kind = "TextComment";
   Extended->Children.back()->Text = " continues onto the next line.";
 
+  Top.Children.emplace_back(llvm::make_unique());
+  CommentInfo *Entities = Top.Children.back().get();
+  Entities->Kind = "ParagraphComment";
+  Entities->Children.emplace_back(llvm::make_unique());
+  Entities->Children.back()->Kind = "TextComment";
+  Entities->Children.back()->Name = "ParagraphComment";
+  Entities->Children.back()->Text =
+  " Comment with html entities: &, <, >, \", \'.";
+
   I.Description.emplace_back(std::move(Top));
 
   auto G = getHTMLGenerator();
@@ -285,6 +294,9 @@
   
  Extended description that continues onto the next line.
   
+  
+ Comment with html entities: , , , , .
+  
 
   
 
Index: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
@@ -8,6 +8,7 @@
 
 #include "Generators.h"
 #include "Representation.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
@@ -176,7 +177,7 @@
 void TextNode::Render(llvm::raw_ostream , int IndentationLevel) {
   if (Indented)
 OS.indent(IndentationLevel * 2);
-  OS << Text;
+  printHTMLEscaped(Text, OS);
 }
 
 void TagNode::Render(llvm::raw_ostream , int IndentationLevel) {


Index: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -258,6 +258,15 @@
   Extended->Children.back()->Kind = "TextComment";
   Extended->Children.back()->Text = " continues onto the next line.";
 
+  Top.Children.emplace_back(llvm::make_unique());
+  CommentInfo *Entities = Top.Children.back().get();
+  Entities->Kind = "ParagraphComment";
+  Entities->Children.emplace_back(llvm::make_unique());
+  Entities->Children.back()->Kind = "TextComment";
+  Entities->Children.back()->Name = "ParagraphComment";
+  Entities->Children.back()->Text =
+  " Comment with html entities: &, <, >, \", \'.";
+
   I.Description.emplace_back(std::move(Top));
 
   auto G = getHTMLGenerator();
@@ -285,6 +294,9 @@
   
  Extended description that continues onto the next line.
   
+  
+ Comment with html entities: , , , , .
+  
 
   
 
Index: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
@@ -8,6 +8,7 @@
 
 #include "Generators.h"
 #include "Representation.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
@@ -176,7 +177,7 @@
 void TextNode::Render(llvm::raw_ostream , int IndentationLevel) {
   if (Indented)
 OS.indent(IndentationLevel * 2);
-  OS << Text;
+  printHTMLEscaped(Text, OS);
 }
 
 void TagNode::Render(llvm::raw_ostream , int IndentationLevel) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64958: [clang-doc] Fix link generation

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran added a comment.

In D64958#1601228 , @juliehockett 
wrote:

> Under what circumstances, exactly, is the path not set where you would need 
> to create a link despite that? Is it only in the global namespace case? If 
> so, could you special-case that and ignore other empty paths?


It's not specifically in the GlobalNamespace info file. It happens in that one 
but also in any info whose parent namespace is the global namespace.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64958/new/

https://reviews.llvm.org/D64958



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


[PATCH] D64958: [clang-doc] Fix link generation

2019-07-25 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran marked an inline comment as done.
DiegoAstiazaran added inline comments.



Comment at: clang-tools-extra/clang-doc/Representation.h:137
+// saved (possibly unresolved)
+  bool IsPathValid = false; // Indicates if a value has been assigned to Path,
+// it could be an empty string

juliehockett wrote:
> Is this field actually set anywhere? 
Yes, in the constructors where a path is assigned.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64958/new/

https://reviews.llvm.org/D64958



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


[PATCH] D64938: [clang-doc] Add option for user provided stylesheets

2019-07-23 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 211362.
DiegoAstiazaran marked an inline comment as done.
DiegoAstiazaran added a comment.

Add a second CSS file to one of the tests in HTMLGeneratorTest.cpp


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64938/new/

https://reviews.llvm.org/D64938

Files:
  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/Representation.h
  clang-tools-extra/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
  clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
  clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -40,7 +40,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected =
   R"raw(---
@@ -94,7 +94,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected =
   R"raw(---
@@ -158,7 +158,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected =
   R"raw(---
@@ -206,7 +206,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected =
   R"raw(---
@@ -343,7 +343,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected =
   R"raw(---
Index: clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
@@ -38,7 +38,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected = R"raw(# namespace Namespace
 
@@ -101,7 +101,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected = R"raw(# class r
 
@@ -162,7 +162,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected = R"raw(### f
 
@@ -190,7 +190,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected = R"raw(| enum class e |
 
@@ -320,7 +320,7 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
   assert(!Err);
   std::string Expected =
   R"raw(### f
Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -21,6 +21,16 @@
   return std::move(G.get());
 }
 
+ClangDocContext
+getClangDocContext(std::vector UserStylesheets = {}) {
+  ClangDocContext CDCtx;
+  CDCtx.UserStylesheets = {UserStylesheets.begin(), UserStylesheets.end()};
+  CDCtx.UserStylesheets.insert(
+  CDCtx.UserStylesheets.begin(),
+  "../share/clang/clang-doc-default-stylesheet.css");
+  return CDCtx;
+}
+
 TEST(HTMLGeneratorTest, emitNamespaceHTML) {
   NamespaceInfo I;
   I.Name = "Namespace";
@@ -38,12 +48,14 @@
   assert(G);
   std::string Buffer;
   llvm::raw_string_ostream Actual(Buffer);
-  auto Err = G->generateDocForInfo(, Actual);
+  ClangDocContext CDCtx = 

[PATCH] D65107: [clang-doc] Fix html entities in rendered text

2019-07-22 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran updated this revision to Diff 211201.
DiegoAstiazaran marked an inline comment as done.
DiegoAstiazaran edited the summary of this revision.
DiegoAstiazaran added a comment.

Use printHTMLEscaped() in ADT/StringExtras.h to write HTML entities.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65107/new/

https://reviews.llvm.org/D65107

Files:
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp


Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -258,6 +258,15 @@
   Extended->Children.back()->Kind = "TextComment";
   Extended->Children.back()->Text = " continues onto the next line.";
 
+  Top.Children.emplace_back(llvm::make_unique());
+  CommentInfo *Entities = Top.Children.back().get();
+  Entities->Kind = "ParagraphComment";
+  Entities->Children.emplace_back(llvm::make_unique());
+  Entities->Children.back()->Kind = "TextComment";
+  Entities->Children.back()->Name = "ParagraphComment";
+  Entities->Children.back()->Text =
+  " Comment with html entities: &, <, >, \", \'.";
+
   I.Description.emplace_back(std::move(Top));
 
   auto G = getHTMLGenerator();
@@ -285,6 +294,9 @@
   
  Extended description that continues onto the next line.
   
+  
+ Comment with html entities: , , , , .
+  
 
   
 
Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -8,6 +8,7 @@
 
 #include "Generators.h"
 #include "Representation.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
@@ -176,7 +177,7 @@
 void TextNode::Render(llvm::raw_ostream , int IndentationLevel) {
   if (Indented)
 OS.indent(IndentationLevel * 2);
-  OS << Text;
+  printHTMLEscaped(Text, OS);
 }
 
 void TagNode::Render(llvm::raw_ostream , int IndentationLevel) {


Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -258,6 +258,15 @@
   Extended->Children.back()->Kind = "TextComment";
   Extended->Children.back()->Text = " continues onto the next line.";
 
+  Top.Children.emplace_back(llvm::make_unique());
+  CommentInfo *Entities = Top.Children.back().get();
+  Entities->Kind = "ParagraphComment";
+  Entities->Children.emplace_back(llvm::make_unique());
+  Entities->Children.back()->Kind = "TextComment";
+  Entities->Children.back()->Name = "ParagraphComment";
+  Entities->Children.back()->Text =
+  " Comment with html entities: &, <, >, \", \'.";
+
   I.Description.emplace_back(std::move(Top));
 
   auto G = getHTMLGenerator();
@@ -285,6 +294,9 @@
   
  Extended description that continues onto the next line.
   
+  
+ Comment with html entities: , , , , .
+  
 
   
 
Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -8,6 +8,7 @@
 
 #include "Generators.h"
 #include "Representation.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
@@ -176,7 +177,7 @@
 void TextNode::Render(llvm::raw_ostream , int IndentationLevel) {
   if (Indented)
 OS.indent(IndentationLevel * 2);
-  OS << Text;
+  printHTMLEscaped(Text, OS);
 }
 
 void TagNode::Render(llvm::raw_ostream , int IndentationLevel) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65107: [clang-doc] Fix html entities in rendered text

2019-07-22 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran created this revision.
DiegoAstiazaran added reviewers: jakehehrlich, juliehockett.
DiegoAstiazaran added a project: clang-tools-extra.

Replace <, > and " with its corresponding html entities before rendering text 
nodes.


https://reviews.llvm.org/D65107

Files:
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp


Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -258,6 +258,14 @@
   Extended->Children.back()->Kind = "TextComment";
   Extended->Children.back()->Text = " continues onto the next line.";
 
+  Top.Children.emplace_back(llvm::make_unique());
+  CommentInfo *Entities = Top.Children.back().get();
+  Entities->Kind = "ParagraphComment";
+  Entities->Children.emplace_back(llvm::make_unique());
+  Entities->Children.back()->Kind = "TextComment";
+  Entities->Children.back()->Name = "ParagraphComment";
+  Entities->Children.back()->Text = " Comment with html entities: <, > and 
\".";
+
   I.Description.emplace_back(std::move(Top));
 
   auto G = getHTMLGenerator();
@@ -285,6 +293,9 @@
   
  Extended description that continues onto the next line.
   
+  
+ Comment with html entities: ,  and .
+  
 
   
 
Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -71,7 +71,12 @@
 
   std::string Text; // Content of node
   bool Indented; // Indicates if an indentation must be rendered before the 
text
+
+  void FixText();
   void Render(llvm::raw_ostream , int IndentationLevel) override;
+
+private:
+  std::string getHTMLEntity(const char );
 };
 
 struct TagNode : public HTMLNode {
@@ -173,7 +178,30 @@
   llvm_unreachable("Unhandled HTMLTag::TagType");
 }
 
+std::string TextNode::getHTMLEntity(const char ) {
+  switch (C) {
+  case '<':
+return "";
+  case '>':
+return "";
+  case '"':
+return "";
+  default:
+return std::string(, 1);
+  }
+}
+
+void TextNode::FixText() {
+  static const std::string CharactersToReplace = "<>\"";
+  std::size_t found = Text.find_first_of(CharactersToReplace);
+  while (found != std::string::npos) {
+Text.replace(found, 1, getHTMLEntity(Text[found]));
+found = Text.find_first_of(CharactersToReplace, found + 1);
+  }
+}
+
 void TextNode::Render(llvm::raw_ostream , int IndentationLevel) {
+  FixText();
   if (Indented)
 OS.indent(IndentationLevel * 2);
   OS << Text;


Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -258,6 +258,14 @@
   Extended->Children.back()->Kind = "TextComment";
   Extended->Children.back()->Text = " continues onto the next line.";
 
+  Top.Children.emplace_back(llvm::make_unique());
+  CommentInfo *Entities = Top.Children.back().get();
+  Entities->Kind = "ParagraphComment";
+  Entities->Children.emplace_back(llvm::make_unique());
+  Entities->Children.back()->Kind = "TextComment";
+  Entities->Children.back()->Name = "ParagraphComment";
+  Entities->Children.back()->Text = " Comment with html entities: <, > and \".";
+
   I.Description.emplace_back(std::move(Top));
 
   auto G = getHTMLGenerator();
@@ -285,6 +293,9 @@
   
  Extended description that continues onto the next line.
   
+  
+ Comment with html entities: ,  and .
+  
 
   
 
Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -71,7 +71,12 @@
 
   std::string Text; // Content of node
   bool Indented; // Indicates if an indentation must be rendered before the text
+
+  void FixText();
   void Render(llvm::raw_ostream , int IndentationLevel) override;
+
+private:
+  std::string getHTMLEntity(const char );
 };
 
 struct TagNode : public HTMLNode {
@@ -173,7 +178,30 @@
   llvm_unreachable("Unhandled HTMLTag::TagType");
 }
 
+std::string TextNode::getHTMLEntity(const char ) {
+  switch (C) {
+  case '<':
+return "";
+  case '>':
+return "";
+  case '"':
+return "";
+  default:
+return std::string(, 1);
+  }
+}
+
+void TextNode::FixText() {
+  static const std::string CharactersToReplace = "<>\"";
+  std::size_t found = Text.find_first_of(CharactersToReplace);
+  while (found != std::string::npos) {
+Text.replace(found, 1, getHTMLEntity(Text[found]));
+found = Text.find_first_of(CharactersToReplace, found + 1);
+  }
+}
+
 void 

[PATCH] D65030: [clang-doc] Add second index for sections within info's content

2019-07-19 Thread Diego Astiazarán via Phabricator via cfe-commits
DiegoAstiazaran created this revision.
DiegoAstiazaran added reviewers: juliehockett, jakehehrlich, lebedev.ri.
DiegoAstiazaran added a project: clang-tools-extra.
Herald added a subscriber: arphaman.

This new index contains links to the main section of infos: Namespaces, 
Records, Functions, Enums, Members.
Also to each child function or enum.
Index is currently rendered on top of the info content, this will be fixed 
later with CSS.

  

Depends on D65003 


https://reviews.llvm.org/D65030

Files:
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/Representation.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
@@ -44,26 +44,36 @@
   std::string Expected = R"raw(
 
 namespace Namespace
+
+  Namespaces
+  Records
+  Functions
+  OneFunction
+
+  Enums
+  OneEnum
+
+
 
   namespace Namespace
-  Namespaces
+  Namespaces
   
 ChildNamespace
   
-  Records
+  Records
   
 ChildStruct
   
-  Functions
+  Functions
   
-OneFunction
+OneFunction
 
   OneFunction()
 
   
-  Enums
+  Enums
   
-enum OneEnum
+enum OneEnum
   
 
 )raw";
@@ -106,6 +116,16 @@
   std::string Expected = R"raw(
 
 class r
+
+  Members
+  Records
+  Functions
+  OneFunction
+
+  Enums
+  OneEnum
+
+
 
   class r
   
@@ -117,25 +137,25 @@
  R"raw(">F
 , G
   
-  Members
+  Members
   
 private int X
   
-  Records
+  Records
   
 ChildStruct
   
-  Functions
+  Functions
   
-OneFunction
+OneFunction
 
   OneFunction()
 
   
-  Enums
+  Enums
   
-enum OneEnum
+enum OneEnum
   
 
 )raw";
@@ -172,7 +192,7 @@
 
 
 
-  f
+  f
   
 float
@@ -211,7 +231,7 @@
 
 
 
-  enum class e
+  enum class e
   
 X
   
@@ -271,7 +291,7 @@
 
 
 
-  f
+  f
   
 void f(int I, int J)
   
Index: clang-tools-extra/clang-doc/Representation.h
===
--- clang-tools-extra/clang-doc/Representation.h
+++ clang-tools-extra/clang-doc/Representation.h
@@ -239,7 +239,7 @@
   void mergeBase(Info &);
   bool mergeable(const Info );
 
-  llvm::SmallString<16> extractName();
+  llvm::SmallString<16> extractName() const;
 
   // Returns a reference to the parent scope (that is, the immediate parent
   // namespace or class in which this decl resides).
@@ -340,11 +340,14 @@
 
 struct Index : public Reference {
   Index() = default;
+  Index(StringRef Name, StringRef JumpToSection)
+  : Reference(Name), JumpToSection(JumpToSection) {}
   Index(SymbolID USR, StringRef Name, InfoType IT, StringRef Path)
   : Reference(USR, Name, IT, Path) {}
   bool operator==(const SymbolID ) const { return USR == Other; }
   bool operator<(const Index ) const { return Name < Other.Name; }
 
+  SmallString<16> JumpToSection;
   std::vector Children;
 
   void sort();
Index: clang-tools-extra/clang-doc/Representation.cpp
===
--- clang-tools-extra/clang-doc/Representation.cpp
+++ clang-tools-extra/clang-doc/Representation.cpp
@@ -197,7 +197,7 @@
   SymbolInfo::merge(std::move(Other));
 }
 
-llvm::SmallString<16> Info::extractName() {
+llvm::SmallString<16> Info::extractName() const {
   if (!Name.empty())
 return Name;
 
Index: clang-tools-extra/clang-doc/HTMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -252,13 +252,20 @@
   return LinkNode;
 }
 
-static std::unique_ptr genTypeReference(const Reference ,
-  StringRef CurrentDirectory) {
-  if (Type.Path.empty())
-return llvm::make_unique(Type.Name);
+static std::unique_ptr
+genTypeReference(const Reference , StringRef CurrentDirectory,
+ StringRef JumpToSection = "") {
+  if (Type.Path.empty()) {
+if (JumpToSection.empty())
+  return llvm::make_unique(Type.Name);
+else
+  return genLink(Type.Name, "#" + JumpToSection);
+  }
   llvm::SmallString<128> Path =
   computeRelativePath(Type.Path, CurrentDirectory);
   llvm::sys::path::append(Path, Type.Name + ".html");
+  if (!JumpToSection.empty())
+Path += ("#" + JumpToSection).str();
   return genLink(Type.Name, Path);
 }
 
@@ -285,6 +292,7 @@
 
   std::vector> Out;
   Out.emplace_back(llvm::make_unique(HTMLTag::TAG_H2, "Enums"));
+  Out.back()->Attributes.try_emplace("id", "Enums");
   Out.emplace_back(llvm::make_unique(HTMLTag::TAG_DIV));
   auto  = Out.back();
   for (const auto  : Enums) {
@@ -313,6 +321,7 @@
 
   std::vector> Out;
   

  1   2   >