[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] D65030: [clang-doc] Add second index for sections within info's content

2019-08-07 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added a comment.

LGTM


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-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] 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] 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] D65030: [clang-doc] Add second index for sections within info's content

2019-08-05 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added inline comments.



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

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.


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-08-02 Thread Jake Ehrlich via Phabricator via cfe-commits
jakehehrlich accepted this revision.
jakehehrlich added a comment.
This revision is now accepted and ready to land.

This looks awesome!




Comment at: clang-tools-extra/clang-doc/HTMLGenerator.cpp:257
+genTypeReference(const Reference , StringRef CurrentDirectory,
+ StringRef JumpToSection = "") {
+  if (Type.Path.empty()) {

Use an optional StringRef instead


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-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] D65030: [clang-doc] Add second index for sections within info's content

2019-07-25 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added a comment.

Looks mostly good to me, with a small formatting thing




Comment at: clang-tools-extra/clang-doc/HTMLGenerator.cpp:490
   Out.emplace_back(llvm::make_unique(HTMLTag::TAG_H3, I.Name));
+  Out.back()->Attributes.try_emplace("id",
+ llvm::toHex(llvm::toStringRef(I.USR)));

Comment here that you're using USR instead of name to disambiguate function 
overloads (mostly because I asked the question and had to think about why for a 
second, so might as well document it)



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

Formatting is a bit weird for sublists


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-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;