[clang-tools-extra] r369182 - [clang-doc] Fix casting not working in gcc 5.4.0

2019-08-16 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Fri Aug 16 18:45:03 2019
New Revision: 369182

URL: http://llvm.org/viewvc/llvm-project?rev=369182=rev
Log:
[clang-doc] Fix casting not working in gcc 5.4.0

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.

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

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

Modified: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp?rev=369182=369181=369182=diff
==
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp Fri Aug 16 18:45:03 2019
@@ -89,7 +89,7 @@ struct TagNode : public HTMLNode {
 
   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 @@ genStylesheetsHTML(StringRef InfoPath, c
 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 @@ genJsScriptsHTML(StringRef InfoPath, con
 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 @@ writeFileDefinition(const Location ,
   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


[clang-tools-extra] r369139 - [clang-doc] Redesign of generated HTML files

2019-08-16 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Fri Aug 16 11:38:11 2019
New Revision: 369139

URL: http://llvm.org/viewvc/llvm-project?rev=369139=rev
Log:
[clang-doc] Redesign of generated HTML files

The new design includes a header (contains the project name), a main section, 
and a footer.
The main section is divided into three subsections. Left, middle, right. The 
left section contains the general index, the middle contains the info's data, 
and the right contains the index for the info's content.
The CSS has been updated.
A flag --project-name is added.
The Attributes attribute of the TagNode struct is now a vector of pairs because 
these attributes should be rendered in the insertion order.
The functions (cpp and js) that converts an Index tree structure into HTML were 
slightly modified; the first ul tag created is now a ol tag. The inner lists 
are still ul.

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

Modified:
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

Modified: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp?rev=369139=369138=369139=diff
==
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp Fri Aug 16 11:38:11 2019
@@ -8,6 +8,7 @@
 
 #include "Generators.h"
 #include "Representation.h"
+#include "clang/Basic/Version.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/FileSystem.h"
@@ -29,12 +30,16 @@ public:
   enum TagType {
 TAG_A,
 TAG_DIV,
+TAG_FOOTER,
 TAG_H1,
 TAG_H2,
 TAG_H3,
+TAG_HEADER,
 TAG_LI,
 TAG_LINK,
+TAG_MAIN,
 TAG_META,
+TAG_OL,
 TAG_P,
 TAG_SCRIPT,
 TAG_SPAN,
@@ -84,7 +89,7 @@ struct TagNode : public HTMLNode {
 
   HTMLTag Tag; // Name of HTML Tag (p, div, h1)
   std::vector> Children; // List of child nodes
-  llvm::StringMap>
+  std::vector, llvm::SmallString<16>>>
   Attributes; // List of key-value attributes for tag
 
   void Render(llvm::raw_ostream , int IndentationLevel) override;
@@ -112,10 +117,14 @@ bool HTMLTag::IsSelfClosing() const {
 return true;
   case HTMLTag::TAG_A:
   case HTMLTag::TAG_DIV:
+  case HTMLTag::TAG_FOOTER:
   case HTMLTag::TAG_H1:
   case HTMLTag::TAG_H2:
   case HTMLTag::TAG_H3:
+  case HTMLTag::TAG_HEADER:
   case HTMLTag::TAG_LI:
+  case HTMLTag::TAG_MAIN:
+  case HTMLTag::TAG_OL:
   case HTMLTag::TAG_P:
   case HTMLTag::TAG_SCRIPT:
   case HTMLTag::TAG_SPAN:
@@ -132,18 +141,26 @@ llvm::SmallString<16> HTMLTag::ToString(
 return llvm::SmallString<16>("a");
   case HTMLTag::TAG_DIV:
 return llvm::SmallString<16>("div");
+  case HTMLTag::TAG_FOOTER:
+return llvm::SmallString<16>("footer");
   case HTMLTag::TAG_H1:
 return llvm::SmallString<16>("h1");
   case HTMLTag::TAG_H2:
 return llvm::SmallString<16>("h2");
   case HTMLTag::TAG_H3:
 return llvm::SmallString<16>("h3");
+  case HTMLTag::TAG_HEADER:
+return llvm::SmallString<16>("header");
   case HTMLTag::TAG_LI:
 return llvm::SmallString<16>("li");
   case HTMLTag::TAG_LINK:
 return llvm::SmallString<16>("link");
+  case HTMLTag::TAG_MAIN:
+return llvm::SmallString<16>("main");
   case HTMLTag::TAG_META:
 return llvm::SmallString<16>("meta");
+  case HTMLTag::TAG_OL:
+return llvm::SmallString<16>("ol");
   case HTMLTag::TAG_P:
 return llvm::SmallString<16>("p");
   case HTMLTag::TAG_SCRIPT:
@@ -174,7 +191,7 @@ void TagNode::Render(llvm::raw_ostream &
   OS.indent(IndentationLevel * 2);
   OS << "<" << Tag.ToString();
   for (const auto  : Attributes)
-OS << " " << A.getKey() << "=\"" << A.getValue() << "\"";
+OS << " " << A.first << "=\"" << A.second << "\"";
   if (Tag.IsSelfClosing()) {
 OS << "/>";
 return;
@@ -255,13 +272,13 @@ genStylesheetsHTML(StringRef InfoPath, c
   std::vector> Out;
   for (const auto  : CDCtx.UserStylesheets) {
 auto LinkNode = std::make_unique(HTMLTag::TAG_LINK);
-LinkNode->Attributes.try_emplace("rel", "stylesheet");
+LinkNode->Attributes.emplace_back("rel", "stylesheet");
 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);
-

[clang-tools-extra] r369123 - [clang-doc] Fix records in global namespace

2019-08-16 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Fri Aug 16 09:10:32 2019
New Revision: 369123

URL: http://llvm.org/viewvc/llvm-project?rev=369123=rev
Log:
[clang-doc] Fix records in global namespace

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.

Differential revision: https://reviews.llvm.org/D66298

Modified:
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

Modified: clang-tools-extra/trunk/clang-doc/Serialize.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/Serialize.cpp?rev=369123=369122=369123=diff
==
--- clang-tools-extra/trunk/clang-doc/Serialize.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/Serialize.cpp Fri Aug 16 09:10:32 2019
@@ -378,6 +378,14 @@ populateParentNamespaces(llvm::SmallVect
   Namespaces.emplace_back(getUSRForDecl(N), N->getNameAsString(),
   InfoType::IT_enum);
   }
+  // The global namespace should be added to the list of namespaces if the decl
+  // corresponds to a Record and if it doesn't have any namespace (because this
+  // means it's in the global namespace). Also if its outermost namespace is a
+  // record because that record matches the previous condition mentioned.
+  if ((Namespaces.empty() && dyn_cast(D)) ||
+  (!Namespaces.empty() && Namespaces.back().RefType == 
InfoType::IT_record))
+Namespaces.emplace_back(SymbolID(), "GlobalNamespace",
+InfoType::IT_namespace);
 }
 
 template 
@@ -528,16 +536,6 @@ emitInfo(const RecordDecl *D, const Full
   }
   I->Path = getInfoRelativePath(I->Namespace);
 
-  if (I->Namespace.empty()) {
-auto ParentI = std::make_unique();
-ParentI->USR = SymbolID();
-ParentI->ChildRecords.emplace_back(I->USR, I->Name, InfoType::IT_record,
-   getInfoRelativePath(I->Namespace));
-ParentI->Path = getInfoRelativePath(ParentI->Namespace);
-return {std::unique_ptr{std::move(I)},
-std::unique_ptr{std::move(ParentI)}};
-  }
-
   switch (I->Namespace[0].RefType) {
   case InfoType::IT_namespace: {
 auto ParentI = std::make_unique();
@@ -611,8 +609,6 @@ emitInfo(const CXXMethodDecl *D, const F
   // Wrap in enclosing scope
   auto ParentI = std::make_unique();
   ParentI->USR = ParentUSR;
-  if (Func.Namespace.empty())
-ParentI->Path = getInfoRelativePath(ParentI->Namespace);
   ParentI->ChildFunctions.emplace_back(std::move(Func));
   // Info is wrapped in its parent scope so it's returned in the second 
position
   return {nullptr, std::unique_ptr{std::move(ParentI)}};

Modified: clang-tools-extra/trunk/test/clang-doc/single-file-public.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-doc/single-file-public.cpp?rev=369123=369122=369123=diff
==
--- clang-tools-extra/trunk/test/clang-doc/single-file-public.cpp (original)
+++ clang-tools-extra/trunk/test/clang-doc/single-file-public.cpp Fri Aug 16 
09:10:32 2019
@@ -3,7 +3,7 @@
 // RUN: echo "" > %t/compile_flags.txt
 // RUN: cp "%s" "%t/test.cpp"
 // RUN: clang-doc --doxygen --public --executor=standalone -p %t %t/test.cpp 
-output=%t/docs
-// RUN: cat %t/docs/Record.yaml | FileCheck %s --check-prefix=CHECK
+// RUN: cat %t/docs/GlobalNamespace/Record.yaml | FileCheck %s 
--check-prefix=CHECK
 // RUN: rm -rf %t
 
 class Record {
@@ -21,8 +21,12 @@ void Record::function_public() {}
 // CHECK: ---
 // CHECK-NEXT: USR: 
'{{[0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z]}}'
 // CHECK-NEXT: Name:'Record'
+// CHECK-NEXT: Path:'GlobalNamespace'
+// CHECK-NEXT: Namespace:
+// CHECK-NEXT:   - Type: Namespace
+// CHECK-NEXT: Name: 'GlobalNamespace'
 // CHECK-NEXT: DefLocation:
-// CHECK-NEXT:   LineNumber:  [[@LINE-16]]
+// CHECK-NEXT:   LineNumber:  [[@LINE-20]]
 // CHECK-NEXT:   Filename:'{{.*}}'
 // CHECK-NEXT: TagType: Class
 // CHECK-NEXT: ChildFunctions:
@@ -32,11 +36,13 @@ void Record::function_public() {}
 // CHECK-NEXT:   - Type:Record
 // CHECK-NEXT: Name:'Record'
 // CHECK-NEXT: USR: 

[clang-tools-extra] r369075 - [clang-doc] Serialize inherited attributes and methods

2019-08-15 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Thu Aug 15 17:10:49 2019
New Revision: 369075

URL: http://llvm.org/viewvc/llvm-project?rev=369075=rev
Log:
[clang-doc] Serialize inherited attributes and methods

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.

Differential revision: https://reviews.llvm.org/D66238

Modified:
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

Modified: clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp?rev=369075=369074=369075=diff
==
--- clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp Thu Aug 15 17:10:49 2019
@@ -180,6 +180,29 @@ llvm::Error parseRecord(Record R, unsign
 }
 
 llvm::Error parseRecord(Record R, unsigned ID, llvm::StringRef Blob,
+BaseRecordInfo *I) {
+  switch (ID) {
+  case BASE_RECORD_USR:
+return decodeRecord(R, I->USR, Blob);
+  case BASE_RECORD_NAME:
+return decodeRecord(R, I->Name, Blob);
+  case BASE_RECORD_PATH:
+return decodeRecord(R, I->Path, Blob);
+  case BASE_RECORD_TAG_TYPE:
+return decodeRecord(R, I->TagType, Blob);
+  case BASE_RECORD_IS_VIRTUAL:
+return decodeRecord(R, I->IsVirtual, Blob);
+  case BASE_RECORD_ACCESS:
+return decodeRecord(R, I->Access, Blob);
+  case BASE_RECORD_IS_PARENT:
+return decodeRecord(R, I->IsParent, Blob);
+  default:
+return llvm::make_error(
+"Invalid field for BaseRecordInfo.\n", llvm::inconvertibleErrorCode());
+  }
+}
+
+llvm::Error parseRecord(Record R, unsigned ID, llvm::StringRef Blob,
 EnumInfo *I) {
   switch (ID) {
   case ENUM_USR:
@@ -350,6 +373,11 @@ template <> llvm::Error addTypeInfo(Reco
   return llvm::Error::success();
 }
 
+template <> llvm::Error addTypeInfo(BaseRecordInfo *I, MemberTypeInfo &) {
+  I->Members.emplace_back(std::move(T));
+  return llvm::Error::success();
+}
+
 template <> llvm::Error addTypeInfo(FunctionInfo *I, TypeInfo &) {
   I->ReturnType = std::move(T);
   return llvm::Error::success();
@@ -494,6 +522,14 @@ template <> void addChild(RecordInfo *I,
   I->ChildEnums.emplace_back(std::move(R));
 }
 
+template <> void addChild(RecordInfo *I, BaseRecordInfo &) {
+  I->Bases.emplace_back(std::move(R));
+}
+
+template <> void addChild(BaseRecordInfo *I, FunctionInfo &) {
+  I->ChildFunctions.emplace_back(std::move(R));
+}
+
 // Read records from bitcode into a given info.
 template 
 llvm::Error ClangDocBitcodeReader::readRecord(unsigned ID, T I) {
@@ -598,6 +634,13 @@ llvm::Error ClangDocBitcodeReader::readS
 addChild(I, std::move(F));
 return llvm::Error::success();
   }
+  case BI_BASE_RECORD_BLOCK_ID: {
+BaseRecordInfo BR;
+if (auto Err = readBlock(ID, ))
+  return Err;
+addChild(I, std::move(BR));
+return llvm::Error::success();
+  }
   case BI_ENUM_BLOCK_ID: {
 EnumInfo E;
 if (auto Err = readBlock(ID, ))

Modified: clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp?rev=369075=369074=369075=diff
==
--- clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp Thu Aug 15 17:10:49 2019
@@ -116,6 +116,7 @@ static const llvm::IndexedMaphttp://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeWriter.h?rev=369075=369074=369075=diff
==
--- clang-tools-extra/trunk/clang-doc/BitcodeWriter.h (original)
+++ clang-tools-extra/trunk/clang-doc/BitcodeWriter.h Thu Aug 15 17:10:49 2019
@@ -30,7 +30,7 @@ namespace doc {
 // Current version number of clang-doc bitcode.
 // Should be bumped when removing or changing BlockIds, 

[clang-tools-extra] r369068 - [clang-doc] Sort index elements case insensitive

2019-08-15 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Thu Aug 15 16:32:12 2019
New Revision: 369068

URL: http://llvm.org/viewvc/llvm-project?rev=369068=rev
Log:
[clang-doc] Sort index elements case insensitive

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

Differential revision: https://reviews.llvm.org/D66299

Modified:
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

Modified: clang-tools-extra/trunk/clang-doc/Representation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/Representation.cpp?rev=369068=369067=369068=diff
==
--- clang-tools-extra/trunk/clang-doc/Representation.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/Representation.cpp Thu Aug 15 16:32:12 
2019
@@ -245,6 +245,26 @@ llvm::SmallString<16> Info::extractName(
   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)

Modified: clang-tools-extra/trunk/clang-doc/Representation.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/Representation.h?rev=369068=369067=369068=diff
==
--- clang-tools-extra/trunk/clang-doc/Representation.h (original)
+++ clang-tools-extra/trunk/clang-doc/Representation.h Thu Aug 15 16:32:12 2019
@@ -292,7 +292,8 @@ struct SymbolInfo : public Info {
   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 EnumInfo : public SymbolInfo {
 
 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;

Modified: clang-tools-extra/trunk/unittests/clang-doc/GeneratorTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-doc/GeneratorTest.cpp?rev=369068=369067=369068=diff
==
--- clang-tools-extra/trunk/unittests/clang-doc/GeneratorTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-doc/GeneratorTest.cpp Thu Aug 15 
16:32:12 2019
@@ -70,5 +70,24 @@ TEST(GeneratorTest, emitIndex) {
   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


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


[clang-tools-extra] r369065 - [clang-doc] Fix use of source-root flag

2019-08-15 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Thu Aug 15 16:20:42 2019
New Revision: 369065

URL: http://llvm.org/viewvc/llvm-project?rev=369065=rev
Log:
[clang-doc] Fix use of source-root flag

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.

Differential revision: https://reviews.llvm.org/D66268

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

Modified: clang-tools-extra/trunk/clang-doc/Representation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/Representation.cpp?rev=369065=369064=369065=diff
==
--- clang-tools-extra/trunk/clang-doc/Representation.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/Representation.cpp Thu Aug 15 16:20:42 
2019
@@ -257,8 +257,12 @@ ClangDocContext::ClangDocContext(tooling
  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 &&

Modified: clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp?rev=369065=369064=369065=diff
==
--- clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp Thu Aug 15 16:20:42 
2019
@@ -203,17 +203,11 @@ int main(int argc, const char **argv) {
   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


[clang-tools-extra] r369063 - [clang-doc] Fix bitcode writer for access specifiers

2019-08-15 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Thu Aug 15 16:04:27 2019
New Revision: 369063

URL: http://llvm.org/viewvc/llvm-project?rev=369063=rev
Log:
[clang-doc] Fix bitcode writer for access specifiers

Bitcode writer was not emitting the corresponding record for the Access 
attribute of a FunctionInfo. This has been added.
AS_none was being used as the default value for any AcesssSpecifier attribute
(in FunctionInfo and MemberTypeInfo), this has been changed to AS_public
because this is the enum value that evaluates to 0.
The bitcode writer doesn't write values that are 0 so if an attribute
was set to AS_public, this value is not written and after reading the
bitcode it would have the default value which is AS_none. This is why
the default value is now AS_public.

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

Modified:
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

Modified: clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp?rev=369063=369062=369063=diff
==
--- clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp Thu Aug 15 16:04:27 2019
@@ -510,6 +510,7 @@ void ClangDocBitcodeWriter::emitBlock(co
 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);

Modified: clang-tools-extra/trunk/clang-doc/Representation.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/Representation.h?rev=369063=369062=369063=diff
==
--- clang-tools-extra/trunk/clang-doc/Representation.h (original)
+++ clang-tools-extra/trunk/clang-doc/Representation.h Thu Aug 15 16:04:27 2019
@@ -198,10 +198,11 @@ struct MemberTypeInfo : public FieldType
std::tie(Other.Type, Other.Name, Other.Access);
   }
 
-  AccessSpecifier Access = AccessSpecifier::AS_none; // Access level associated
- // with this info (public,
- // protected, private,
- // none).
+  // Access level associated with this info (public, protected, private, none).
+  // AS_public is set as default because the bitcode writer requires the enum
+  // with value 0 to be used as the default.
+  // (AS_public = 0, AS_protected = 1, AS_private = 2, AS_none = 3)
+  AccessSpecifier Access = AccessSpecifier::AS_public;
 };
 
 struct Location {
@@ -312,7 +313,10 @@ struct FunctionInfo : public SymbolInfo
   TypeInfo ReturnType;   // Info about the return type of this function.
   llvm::SmallVector Params; // List of parameters.
   // Access level for this method (public, private, protected, none).
-  AccessSpecifier Access = AccessSpecifier::AS_none;
+  // AS_public is set as default because the bitcode writer requires the enum
+  // with value 0 to be used as the default.
+  // (AS_public = 0, AS_protected = 1, AS_private = 2, AS_none = 3)
+  AccessSpecifier Access = AccessSpecifier::AS_public;
 };
 
 // TODO: Expand to allow for documenting templating, inheritance access,

Modified: clang-tools-extra/trunk/clang-doc/Serialize.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/Serialize.cpp?rev=369063=369062=369063=diff
==
--- clang-tools-extra/trunk/clang-doc/Serialize.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/Serialize.cpp Thu Aug 15 16:04:27 2019
@@ -463,12 +463,11 @@ emitInfo(const FunctionDecl *D, const Fu
   bool IsInAnonymousNamespace = false;
   populateFunctionInfo(Func, D, FC, LineNumber, File, IsFileInRootDir,
IsInAnonymousNamespace);
+  Func.Access = clang::AccessSpecifier::AS_none;
   if (PublicOnly && ((IsInAnonymousNamespace ||
   !isPublic(D->getAccess(), D->getLinkageInternal()
 return {};
 
-  Func.Access = clang::AccessSpecifier::AS_none;
-
   // Wrap in enclosing scope
   auto ParentI = std::make_unique();
   if 

[clang-tools-extra] r368912 - [clang-doc] Add missing check in tests

2019-08-14 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Wed Aug 14 13:19:33 2019
New Revision: 368912

URL: http://llvm.org/viewvc/llvm-project?rev=368912=rev
Log:
[clang-doc] Add missing check in tests

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

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

Modified:
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

Modified: clang-tools-extra/trunk/clang-doc/Representation.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/Representation.h?rev=368912=368911=368912=diff
==
--- clang-tools-extra/trunk/clang-doc/Representation.h (original)
+++ clang-tools-extra/trunk/clang-doc/Representation.h Wed Aug 14 13:19:33 2019
@@ -238,6 +238,8 @@ struct Info {
   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 @@ struct NamespaceInfo : public Info {
   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 @@ struct SymbolInfo : public Info {
   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 @@ struct RecordInfo : public SymbolInfo {
   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 &);
 

Modified: clang-tools-extra/trunk/unittests/clang-doc/ClangDocTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-doc/ClangDocTest.cpp?rev=368912=368911=368912=diff
==
--- clang-tools-extra/trunk/unittests/clang-doc/ClangDocTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-doc/ClangDocTest.cpp Wed Aug 14 
13:19:33 2019
@@ -83,6 +83,7 @@ void CheckMemberTypeInfo(MemberTypeInfo
 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]);

Modified: clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp?rev=368912=368911=368912=diff
==
--- clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp Wed Aug 14 
13:19:33 2019
@@ -91,7 +91,7 @@ TEST(SerializeTest, emitNamespaceInfo) {
   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 @@ TEST(SerializeTest, emitInternalRecordIn
   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);


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


[clang-tools-extra] r368602 - [clang-doc] Generate HTML links for children namespaces/records

2019-08-12 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Mon Aug 12 11:42:46 2019
New Revision: 368602

URL: http://llvm.org/viewvc/llvm-project?rev=368602=rev
Log:
[clang-doc] Generate HTML links for children namespaces/records

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.

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

Modified:
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

Modified: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp?rev=368602=368601=368602=diff
==
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp Mon Aug 12 11:42:46 2019
@@ -207,26 +207,44 @@ static void AppendVector(std::vector computeRelativePath(StringRef FilePath,
-StringRef Directory) {
-  StringRef Path = FilePath;
-  while (!Path.empty()) {
-if (Directory == Path)
-  return FilePath.substr(Path.size());
-Path = llvm::sys::path::parent_path(Path);
-  }
-
-  StringRef Dir = Directory;
-  SmallString<128> Result;
-  while (!Dir.empty()) {
-if (Dir == FilePath)
-  break;
-Dir = llvm::sys::path::parent_path(Dir);
+// Compute the relative path from an Origin directory to a Destination 
directory
+static SmallString<128> computeRelativePath(StringRef Destination,
+StringRef Origin) {
+  // If Origin is empty, the relative path to the Destination is its complete
+  // path.
+  if (Origin.empty())
+return Destination;
+
+  // The relative path is an empty path if both directories are the same.
+  if (Destination == Origin)
+return {};
+
+  // These iterators iterate through each of their parent directories
+  llvm::sys::path::const_iterator FileI = llvm::sys::path::begin(Destination);
+  llvm::sys::path::const_iterator FileE = llvm::sys::path::end(Destination);
+  llvm::sys::path::const_iterator DirI = llvm::sys::path::begin(Origin);
+  llvm::sys::path::const_iterator DirE = llvm::sys::path::end(Origin);
+  // Advance both iterators until the paths differ. Example:
+  //Destination = A/B/C/D
+  //Origin  = A/B/E/F
+  // FileI will point to C and DirI to E. The directories behind them is the
+  // directory they share (A/B).
+  while (FileI != FileE && DirI != DirE && *FileI == *DirI) {
+++FileI;
+++DirI;
+  }
+  SmallString<128> Result; // This will hold the resulting path.
+  // Result has to go up one directory for each of the remaining directories in
+  // Origin
+  while (DirI != DirE) {
 llvm::sys::path::append(Result, "..");
+++DirI;
+  }
+  // Result has to append each of the remaining directories in Destination
+  while (FileI != FileE) {
+llvm::sys::path::append(Result, *FileI);
+++FileI;
   }
-  llvm::sys::path::append(Result, FilePath.substr(Dir.size()));
   return Result;
 }
 
@@ -271,8 +289,8 @@ static std::unique_ptr genLink(
 }
 
 static std::unique_ptr
-genTypeReference(const Reference , StringRef CurrentDirectory,
- llvm::Optional JumpToSection = None) {
+genReference(const Reference , StringRef CurrentDirectory,
+ llvm::Optional JumpToSection = None) {
   if (Type.Path.empty() && !Type.IsInGlobalNamespace) {
 if (!JumpToSection)
   return llvm::make_unique(Type.Name);
@@ -296,7 +314,7 @@ genReferenceList(const llvm::SmallVector
   for (const auto  : Refs) {
 if ( != Refs.begin())
   Out.emplace_back(llvm::make_unique(", "));
-Out.emplace_back(genTypeReference(R, CurrentDirectory));
+Out.emplace_back(genReference(R, CurrentDirectory));
   }
   return Out;
 }
@@ -372,7 +390,7 @@ genRecordMembersBlock(const llvm::SmallV
   Access = Access + " ";
 auto LIBody = llvm::make_unique(HTMLTag::TAG_LI);
 LIBody->Children.emplace_back(llvm::make_unique(Access));
-LIBody->Children.emplace_back(genTypeReference(M.Type, ParentInfoDir));
+LIBody->Children.emplace_back(genReference(M.Type, 

[clang-tools-extra] r368484 - [clang-doc] Generate an HTML index file

2019-08-09 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Fri Aug  9 13:52:28 2019
New Revision: 368484

URL: http://llvm.org/viewvc/llvm-project?rev=368484=rev
Log:
[clang-doc] Generate an HTML index file

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.

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

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

Modified: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp?rev=368484=368483=368484=diff
==
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp Fri Aug  9 13:52:28 2019
@@ -813,6 +813,24 @@ static bool SerializeIndex(ClangDocConte
   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 @@ static bool CopyFile(StringRef FilePath,
 }
 
 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


[clang-tools-extra] r368460 - [clang-format] Add link to source code in file definitions

2019-08-09 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Fri Aug  9 10:49:41 2019
New Revision: 368460

URL: http://llvm.org/viewvc/llvm-project?rev=368460=rev
Log:
[clang-format] Add link to source code in file definitions

Two command line options have been added to clang-doc.
  --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.

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

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

Modified:
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

Modified: clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp?rev=368460=368459=368460=diff
==
--- clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp Fri Aug  9 10:49:41 2019
@@ -83,7 +83,7 @@ llvm::Error decodeRecord(Record R, llvm:
   if (R[0] > INT_MAX)
 return llvm::make_error("Integer too large to parse.\n",
llvm::inconvertibleErrorCode());
-  Field.emplace((int)R[0], Blob);
+  Field.emplace((int)R[0], Blob, (bool)R[1]);
   return llvm::Error::success();
 }
 
@@ -129,7 +129,7 @@ llvm::Error decodeRecord(Record R, llvm:
   if (R[0] > INT_MAX)
 return llvm::make_error("Integer too large to parse.\n",
llvm::inconvertibleErrorCode());
-  Field.emplace_back((int)R[0], Blob);
+  Field.emplace_back((int)R[0], Blob, (bool)R[1]);
   return llvm::Error::success();
 }
 

Modified: clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp?rev=368460=368459=368460=diff
==
--- clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp Fri Aug  9 10:49:41 2019
@@ -77,10 +77,13 @@ static void LocationAbbrev(std::shared_p
   {// 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 @@ void ClangDocBitcodeWriter::emitRecord(c
   // FIXME: Assert that the line number is of the appropriate size.
   Record.push_back(Loc.LineNumber);
   assert(Loc.Filename.size() < (1U << BitCodeConstants::StringLengthSize));
+  Record.push_back(Loc.IsFileInRootDir);
   Record.push_back(Loc.Filename.size());
   Stream.EmitRecordWithBlob(Abbrevs.get(ID), Record, Loc.Filename);
 }

Modified: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp?rev=368460=368459=368460=diff
==
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp Fri Aug  9 10:49:41 2019
@@ -301,12 +301,15 @@ genReferenceList(const llvm::SmallVector
   return Out;
 }
 
-static std::vector> genHTML(const EnumInfo );
-static std::vector> genHTML(const FunctionInfo ,
- StringRef ParentInfoDir);
+static std::vector>
+genHTML(const EnumInfo , const ClangDocContext );
+static std::vector>
+genHTML(const FunctionInfo , const ClangDocContext ,
+

[clang-tools-extra] r368313 - [clang-doc] Protect Index with mutex during reducing and generation stage

2019-08-08 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Thu Aug  8 10:14:17 2019
New Revision: 368313

URL: http://llvm.org/viewvc/llvm-project?rev=368313=rev
Log:
[clang-doc] Protect Index with mutex during reducing and generation stage

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

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

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

Modified: clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp?rev=368313=368312=368313=diff
==
--- clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp Thu Aug  8 10:14:17 
2019
@@ -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 @@ int main(int argc, const char **argv) {
   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 @@ int main(int argc, const char **argv) {
 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


[clang-tools-extra] r368209 - [clang-doc] Add second index for sections within info's content

2019-08-07 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Wed Aug  7 14:04:52 2019
New Revision: 368209

URL: http://llvm.org/viewvc/llvm-project?rev=368209=rev
Log:
[clang-doc] Add second index for sections within info's content

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 D65690.

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

Modified:
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

Modified: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp?rev=368209=368208=368209=diff
==
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp Wed Aug  7 14:04:52 2019
@@ -270,15 +270,22 @@ static std::unique_ptr genLink(
   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 @@ genEnumsBlock(const 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 @@ genFunctionsBlock(const 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 @@ genRecordMembersBlock(const llvm::SmallV
 
   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 @@ genReferencesBlock(const 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 @@ genCommonFileNodes(StringRef Title, Stri
   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 @@ static std::vector(HTMLTag::TAG_H3, EnumType + I.Name));
+  Out.back()->Attributes.try_emplace("id",
+ 

[clang-tools-extra] r368206 - [clang-doc] Parallelize reducing phase

2019-08-07 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Wed Aug  7 13:54:26 2019
New Revision: 368206

URL: http://llvm.org/viewvc/llvm-project?rev=368206=rev
Log:
[clang-doc] Parallelize reducing phase

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.

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

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

Modified: clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp?rev=368206=368205=368206=diff
==
--- clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp Wed Aug  7 13:54:26 
2019
@@ -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 @@ llvm::Expected> g
   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 @@ int main(int argc, const char **argv) {
   // 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 

r368196 - [Tooling] Expose ExecutorConcurrency option.

2019-08-07 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Wed Aug  7 11:35:28 2019
New Revision: 368196

URL: http://llvm.org/viewvc/llvm-project?rev=368196=rev
Log:
[Tooling] Expose ExecutorConcurrency option.

D65628 requires a flag to specify the number of threads for a clang-doc step. 
It would be good to use ExecutorConcurrency after exposing it instead of 
creating a new one that has the same purpose.

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

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

Modified: cfe/trunk/include/clang/Tooling/AllTUsExecution.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/AllTUsExecution.h?rev=368196=368195=368196=diff
==
--- cfe/trunk/include/clang/Tooling/AllTUsExecution.h (original)
+++ cfe/trunk/include/clang/Tooling/AllTUsExecution.h Wed Aug  7 11:35:28 2019
@@ -71,6 +71,7 @@ private:
   unsigned ThreadCount;
 };
 
+extern llvm::cl::opt ExecutorConcurrency;
 extern llvm::cl::opt Filter;
 
 } // end namespace tooling

Modified: cfe/trunk/lib/Tooling/AllTUsExecution.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/AllTUsExecution.cpp?rev=368196=368195=368196=diff
==
--- cfe/trunk/lib/Tooling/AllTUsExecution.cpp (original)
+++ cfe/trunk/lib/Tooling/AllTUsExecution.cpp Wed Aug  7 11:35:28 2019
@@ -147,7 +147,7 @@ llvm::Error AllTUsToolExecutor::execute(
   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


[clang-tools-extra] r368087 - [clang-doc] Fix paths of js in import tags

2019-08-06 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Tue Aug  6 13:59:14 2019
New Revision: 368087

URL: http://llvm.org/viewvc/llvm-project?rev=368087=rev
Log:
[clang-doc] Fix paths of js in import tags

HTML requires posix-style paths.

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

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

Modified: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp?rev=368087=368086=368087=diff
==
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp Tue Aug  6 13:59:14 2019
@@ -256,6 +256,8 @@ genJsScriptsHTML(StringRef InfoPath, con
 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


[clang-tools-extra] r368070 - [clang-doc] Add index in each info html file

2019-08-06 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Tue Aug  6 11:31:46 2019
New Revision: 368070

URL: http://llvm.org/viewvc/llvm-project?rev=368070=rev
Log:
[clang-doc] Add index in each info html file

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 the JSON
file and insert HTML elements into the file.

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

Added:
clang-tools-extra/trunk/clang-doc/assets/
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/unittests/clang-doc/GeneratorTest.cpp
Removed:
clang-tools-extra/trunk/clang-doc/stylesheets/
Modified:
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/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/HTMLGeneratorTest.cpp

Modified: clang-tools-extra/trunk/clang-doc/Generators.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/Generators.cpp?rev=368070=368069=368070=diff
==
--- clang-tools-extra/trunk/clang-doc/Generators.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/Generators.cpp Tue Aug  6 11:31:46 2019
@@ -57,6 +57,57 @@ std::string getTagType(TagTypeKind AS) {
   llvm_unreachable("Unknown TagTypeKind");
 }
 
+bool Generator::createResources(ClangDocContext ) { return true; }
+
+// A function to add a reference to Info in Idx.
+// Given an Info X with the following namespaces: [B,A]; a reference to X will
+// be added in the children of a reference to B, which should be also a child 
of
+// a reference to A, where A is a child of Idx.
+//   Idx
+//|-- A
+//|--B
+//   |--X
+// If the references to the namespaces do not exist, they will be created. If
+// the references already exist, the same one will be used.
+void Generator::addInfoToIndex(Index , const doc::Info *Info) {
+  // Index pointer that will be moving through Idx until the first parent
+  // namespace of Info (where the reference has to be inserted) is found.
+  Index *I = 
+  // The Namespace vector includes the upper-most namespace at the end so the
+  // loop will start from the end to find each of the namespaces.
+  for (const auto  : llvm::reverse(Info->Namespace)) {
+// Look for the current namespace in the children of the index I is
+// pointing.
+auto It = std::find(I->Children.begin(), I->Children.end(), R.USR);
+if (It != I->Children.end()) {
+  // If it is found, just change I to point the namespace refererence 
found.
+  I = &*It;
+} else {
+  // If it is not found a new reference is created
+  I->Children.emplace_back(R.USR, R.Name, R.RefType, R.Path);
+  // I is updated with the reference of the new namespace reference
+  I = >Children.back();
+}
+  }
+  // Look for Info in the vector where it is supposed to be; it could already
+  // exist if it is a parent namespace of an Info already passed to this
+  // function.
+  auto It = std::find(I->Children.begin(), I->Children.end(), Info->USR);
+  if (It == I->Children.end()) {
+// If it is not in the vector it is inserted
+I->Children.emplace_back(Info->USR, Info->extractName(), Info->IT,
+ Info->Path);
+  } else {
+// If it not in the vector we only check if Path and Name are not empty
+// because if the Info was included by a namespace it may not have those
+// values.
+if (It->Path.empty())
+  It->Path = Info->Path;
+if (It->Name.empty())
+  It->Name = Info->extractName();
+  }
+}
+
 // This anchor is used to force the linker to link in the generated object file
 // and thus register the generators.
 extern volatile int YAMLGeneratorAnchorSource;

Modified: clang-tools-extra/trunk/clang-doc/Generators.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/Generators.h?rev=368070=368069=368070=diff
==
--- clang-tools-extra/trunk/clang-doc/Generators.h (original)
+++ clang-tools-extra/trunk/clang-doc/Generators.h Tue Aug  6 11:31:46 2019

[clang-tools-extra] r367958 - [clang-doc] Fix link generation

2019-08-05 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Mon Aug  5 17:11:34 2019
New Revision: 367958

URL: http://llvm.org/viewvc/llvm-project?rev=367958=rev
Log:
[clang-doc] Fix link generation

Before making a link to a reference it is required to check that the
reference has a path (eg. primitives won't have paths).
This was done by checking if the path was empty; that worked because
when generating paths the outdirectory was included, so if the path was
assigned it had that outdirectory at least.
The path generation was changed, it's now only the composite of the
namespaces without the outdirectory. So if the info is in the global
namespace the path would be empty and the old check wouldn't work as expected.
A new attribute has been added to the Reference struct that indicates if
the info's parent is the global namespace.
Paths generation now fails if the path is empty and if the info
is not in the global namespace.

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

Modified:
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

Modified: clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp?rev=367958=367957=367958=diff
==
--- clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp Mon Aug  5 17:11:34 2019
@@ -292,6 +292,8 @@ llvm::Error parseRecord(Record R, unsign
 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:

Modified: clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp?rev=367958=367957=367958=diff
==
--- clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp Mon Aug  5 17:11:34 2019
@@ -172,6 +172,8 @@ static const llvm::IndexedMaphttp://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeWriter.h?rev=367958=367957=367958=diff
==
--- clang-tools-extra/trunk/clang-doc/BitcodeWriter.h (original)
+++ clang-tools-extra/trunk/clang-doc/BitcodeWriter.h Mon Aug  5 17:11:34 2019
@@ -109,6 +109,7 @@ enum RecordId {
   REFERENCE_NAME,
   REFERENCE_TYPE,
   REFERENCE_PATH,
+  REFERENCE_IS_IN_GLOBAL_NAMESPACE,
   REFERENCE_FIELD,
   RI_LAST,
   RI_FIRST = VERSION

Modified: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp?rev=367958=367957=367958=diff
==
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp Mon Aug  5 17:11:34 2019
@@ -247,7 +247,7 @@ static std::unique_ptr genLink(
 
 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);

Modified: clang-tools-extra/trunk/clang-doc/Representation.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/Representation.h?rev=367958=367957=367958=diff
==
--- clang-tools-extra/trunk/clang-doc/Representation.h (original)
+++ clang-tools-extra/trunk/clang-doc/Representation.h Mon Aug  5 17:11:34 2019
@@ -114,11 +114,17 @@ struct CommentInfo {
 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 

[clang-tools-extra] r367743 - [clang-doc] Update documentation

2019-08-02 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Fri Aug  2 19:18:06 2019
New Revision: 367743

URL: http://llvm.org/viewvc/llvm-project?rev=367743=rev
Log:
[clang-doc] Update documentation

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

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

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

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=367743=367742=367743=diff
==
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Fri Aug  2 19:18:06 2019
@@ -52,7 +52,7 @@ The improvements are...
 Improvements to clang-doc
 -
 
-The improvements are...
+- :doc:`clang-doc ` now generates documentation in HTML format.
 
 Improvements to clang-query
 ---

Modified: clang-tools-extra/trunk/docs/clang-doc.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-doc.rst?rev=367743=367742=367743=diff
==
--- clang-tools-extra/trunk/docs/clang-doc.rst (original)
+++ clang-tools-extra/trunk/docs/clang-doc.rst Fri Aug  2 19:18:06 2019
@@ -17,7 +17,7 @@ project. If you have any ideas or sugges
 there.
 
 Use
-=
+===
 
 :program:`clang-doc` is a `LibTooling
 `_-based tool, and so requires a
@@ -25,19 +25,42 @@ compile command database for your projec
 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 @@ map-reduce frameworks to allow for use w
 -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``.


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


[clang-tools-extra] r367729 - [clang-doc] Add flag to continue after mapping errors

2019-08-02 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Fri Aug  2 15:02:36 2019
New Revision: 367729

URL: http://llvm.org/viewvc/llvm-project?rev=367729=rev
Log:
[clang-doc] Add flag to continue after mapping errors

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 if the flag is true.

Differential revision: https://reviews.llvm.org/D65627

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

Modified: clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp?rev=367729=367728=367729=diff
==
--- clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp Fri Aug  2 15:02:36 
2019
@@ -48,6 +48,11 @@ using namespace clang;
 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 @@ int main(int argc, const char **argv) {
   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


[clang-tools-extra] r367279 - [clang-doc] Fix expected output in tests

2019-07-29 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Mon Jul 29 17:07:34 2019
New Revision: 367279

URL: http://llvm.org/viewvc/llvm-project?rev=367279=rev
Log:
[clang-doc] Fix expected output in tests

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

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

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

Modified: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp?rev=367279=367278=367279=diff
==
--- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp Mon Jul 
29 17:07:34 2019
@@ -171,10 +171,6 @@ TEST(HTMLGeneratorTest, emitFunctionHTML
   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 @@ TEST(HTMLGeneratorTest, emitFunctionHTML
 
   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


[clang-tools-extra] r367264 - [clang-doc] Fix failing tests on Windows

2019-07-29 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Mon Jul 29 15:03:39 2019
New Revision: 367264

URL: http://llvm.org/viewvc/llvm-project?rev=367264=rev
Log:
[clang-doc] Fix failing tests on Windows

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

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

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

Modified: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp?rev=367264=367263=367264=diff
==
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp Mon Jul 29 15:03:39 2019
@@ -252,6 +252,8 @@ static std::unique_ptr genType
   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


[clang-tools-extra] r367137 - [clang-format] Fix style of css file paths

2019-07-26 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Fri Jul 26 11:02:42 2019
New Revision: 367137

URL: http://llvm.org/viewvc/llvm-project?rev=367137=rev
Log:
[clang-format] Fix style of css file paths

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

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

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

Modified: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp?rev=367137=367136=367137=diff
==
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp Fri Jul 26 11:02:42 2019
@@ -231,6 +231,8 @@ genStylesheetsHTML(StringRef InfoPath, c
 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));
   }

Modified: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp?rev=367137=367136=367137=diff
==
--- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp Fri Jul 
26 11:02:42 2019
@@ -110,34 +110,23 @@ TEST(HTMLGeneratorTest, emitRecordHTML)
   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
 
   


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


[clang-tools-extra] r367074 - [clang-doc] Fix failing tests on Windows

2019-07-25 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Thu Jul 25 16:22:55 2019
New Revision: 367074

URL: http://llvm.org/viewvc/llvm-project?rev=367074=rev
Log:
[clang-doc] Fix failing tests on Windows

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.

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

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

Modified: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp?rev=367074=367073=367074=diff
==
--- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp Thu Jul 
25 16:22:55 2019
@@ -114,10 +114,15 @@ TEST(HTMLGeneratorTest, emitRecordHTML)
   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


[clang-tools-extra] r367072 - [clang-doc] Add option for user provided stylesheets

2019-07-25 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Thu Jul 25 15:46:40 2019
New Revision: 367072

URL: http://llvm.org/viewvc/llvm-project?rev=367072=rev
Log:
[clang-doc] Add option for user provided stylesheets

An option has been added to clang-doc to provide a list of css stylesheets that 
the user wants to use for the generated html docs.

Depends on D64539.

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

Modified:
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

Modified: clang-tools-extra/trunk/clang-doc/Generators.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/Generators.h?rev=367072=367071=367072=diff
==
--- clang-tools-extra/trunk/clang-doc/Generators.h (original)
+++ clang-tools-extra/trunk/clang-doc/Generators.h Thu Jul 25 15:46:40 2019
@@ -26,7 +26,8 @@ public:
   virtual ~Generator() = default;
 
   // Write out the decl info in the specified format.
-  virtual llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream ) = 0;
+  virtual llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream ,
+ const ClangDocContext ) = 0;
   virtual bool createResources(ClangDocContext CDCtx) = 0;
 };
 

Modified: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp?rev=367072=367071=367072=diff
==
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp Thu Jul 25 15:46:40 2019
@@ -222,6 +222,21 @@ static SmallString<128> computeRelativeP
 
 // HTML generation
 
+std::vector>
+genStylesheetsHTML(StringRef InfoPath, const ClangDocContext ) {
+  std::vector> Out;
+  for (const auto  : CDCtx.UserStylesheets) {
+auto LinkNode = llvm::make_unique(HTMLTag::TAG_LINK);
+LinkNode->Attributes.try_emplace("rel", "stylesheet");
+SmallString<128> StylesheetPath = computeRelativePath("", InfoPath);
+llvm::sys::path::append(StylesheetPath,
+llvm::sys::path::filename(FilePath));
+LinkNode->Attributes.try_emplace("href", StylesheetPath);
+Out.emplace_back(std::move(LinkNode));
+  }
+  return Out;
+}
+
 static std::unique_ptr genLink(const Twine , const Twine ) {
   auto LinkNode = llvm::make_unique(HTMLTag::TAG_A, Text);
   LinkNode->Attributes.try_emplace("href", Link.str());
@@ -529,13 +544,15 @@ class HTMLGenerator : public Generator {
 public:
   static const char *Format;
 
-  llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream ) override;
+  llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream ,
+ const ClangDocContext ) override;
   bool createResources(ClangDocContext CDCtx) override;
 };
 
 const char *HTMLGenerator::Format = "html";
 
-llvm::Error HTMLGenerator::generateDocForInfo(Info *I, llvm::raw_ostream ) {
+llvm::Error HTMLGenerator::generateDocForInfo(Info *I, llvm::raw_ostream ,
+  const ClangDocContext ) {
   HTMLFile F;
 
   auto MetaNode = llvm::make_unique(HTMLTag::TAG_META);
@@ -577,12 +594,9 @@ llvm::Error HTMLGenerator::generateDocFo
 
   F.Children.emplace_back(
   llvm::make_unique(HTMLTag::TAG_TITLE, InfoTitle));
-  auto LinkNode = llvm::make_unique(HTMLTag::TAG_LINK);
-  LinkNode->Attributes.try_emplace("rel", "stylesheet");
-  SmallString<128> StylesheetPath = computeRelativePath("", I->Path);
-  llvm::sys::path::append(StylesheetPath, "clang-doc-default-stylesheet.css");
-  LinkNode->Attributes.try_emplace("href", StylesheetPath);
-  F.Children.emplace_back(std::move(LinkNode));
+  std::vector> StylesheetsNodes =
+  genStylesheetsHTML(I->Path, CDCtx);
+  AppendVector(std::move(StylesheetsNodes), F.Children);
   F.Children.emplace_back(std::move(MainContentNode));
   F.Render(OS);
 
@@ -591,22 +605,22 @@ llvm::Error HTMLGenerator::generateDocFo
 
 bool HTMLGenerator::createResources(ClangDocContext CDCtx) {
   llvm::outs() << "Generating stylesheet for docs...\n";
-  llvm::SmallString<128> StylesheetPathWrite;
-  llvm::sys::path::native(CDCtx.OutDirectory, StylesheetPathWrite);
-  llvm::sys::path::append(StylesheetPathWrite,
-  "clang-doc-default-stylesheet.css");
-  llvm::SmallString<128> StylesheetPathRead;
-  llvm::sys::path::native(CDCtx.ClangDocPath, StylesheetPathRead);
-  

[clang-tools-extra] r367056 - [clang-doc] Add stylesheet to generated html docs

2019-07-25 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Thu Jul 25 14:27:50 2019
New Revision: 367056

URL: http://llvm.org/viewvc/llvm-project?rev=367056=rev
Log:
[clang-doc] Add stylesheet to generated html docs

A default css stylesheet is included for docs generated in html format.

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

Added:
clang-tools-extra/trunk/clang-doc/stylesheets/

clang-tools-extra/trunk/clang-doc/stylesheets/clang-doc-default-stylesheet.css
Modified:
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/Serialize.cpp
clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp
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/HTMLGeneratorTest.cpp

Modified: clang-tools-extra/trunk/clang-doc/Generators.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/Generators.h?rev=367056=367055=367056=diff
==
--- clang-tools-extra/trunk/clang-doc/Generators.h (original)
+++ clang-tools-extra/trunk/clang-doc/Generators.h Thu Jul 25 14:27:50 2019
@@ -27,6 +27,7 @@ public:
 
   // Write out the decl info in the specified format.
   virtual llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream ) = 0;
+  virtual bool createResources(ClangDocContext CDCtx) = 0;
 };
 
 typedef llvm::Registry GeneratorRegistry;

Modified: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp?rev=367056=367055=367056=diff
==
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp Thu Jul 25 14:27:50 2019
@@ -35,6 +35,7 @@ public:
 TAG_UL,
 TAG_LI,
 TAG_A,
+TAG_LINK,
   };
 
   HTMLTag() = default;
@@ -103,6 +104,7 @@ struct HTMLFile {
 bool HTMLTag::IsSelfClosing() const {
   switch (Value) {
   case HTMLTag::TAG_META:
+  case HTMLTag::TAG_LINK:
 return true;
   case HTMLTag::TAG_TITLE:
   case HTMLTag::TAG_DIV:
@@ -140,6 +142,8 @@ llvm::SmallString<16> HTMLTag::ToString(
 return llvm::SmallString<16>("li");
   case HTMLTag::TAG_A:
 return llvm::SmallString<16>("a");
+  case HTMLTag::TAG_LINK:
+return llvm::SmallString<16>("link");
   }
   llvm_unreachable("Unhandled HTMLTag::TagType");
 }
@@ -526,6 +530,7 @@ public:
   static const char *Format;
 
   llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream ) override;
+  bool createResources(ClangDocContext CDCtx) override;
 };
 
 const char *HTMLGenerator::Format = "html";
@@ -572,12 +577,40 @@ llvm::Error HTMLGenerator::generateDocFo
 
   F.Children.emplace_back(
   llvm::make_unique(HTMLTag::TAG_TITLE, InfoTitle));
+  auto LinkNode = llvm::make_unique(HTMLTag::TAG_LINK);
+  LinkNode->Attributes.try_emplace("rel", "stylesheet");
+  SmallString<128> StylesheetPath = computeRelativePath("", I->Path);
+  llvm::sys::path::append(StylesheetPath, "clang-doc-default-stylesheet.css");
+  LinkNode->Attributes.try_emplace("href", StylesheetPath);
+  F.Children.emplace_back(std::move(LinkNode));
   F.Children.emplace_back(std::move(MainContentNode));
   F.Render(OS);
 
   return llvm::Error::success();
 }
 
+bool HTMLGenerator::createResources(ClangDocContext CDCtx) {
+  llvm::outs() << "Generating stylesheet for docs...\n";
+  llvm::SmallString<128> StylesheetPathWrite;
+  llvm::sys::path::native(CDCtx.OutDirectory, StylesheetPathWrite);
+  llvm::sys::path::append(StylesheetPathWrite,
+  "clang-doc-default-stylesheet.css");
+  llvm::SmallString<128> StylesheetPathRead;
+  llvm::sys::path::native(CDCtx.ClangDocPath, StylesheetPathRead);
+  StylesheetPathRead = llvm::sys::path::parent_path(StylesheetPathRead);
+  llvm::sys::path::append(StylesheetPathRead, "..", "share", "clang",
+  "clang-doc-default-stylesheet.css");
+  std::error_code OK;
+  std::error_code FileErr =
+  llvm::sys::fs::copy_file(StylesheetPathRead, StylesheetPathWrite);
+  if (FileErr != OK) {
+llvm::errs() << "Error creating stylesheet file: " << FileErr.message()
+ << "\n";
+return false;
+  }
+  return true;
+}
+
 static GeneratorRegistry::Add HTML(HTMLGenerator::Format,
   "Generator for HTML 
output.");
 

Modified: clang-tools-extra/trunk/clang-doc/MDGenerator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/MDGenerator.cpp?rev=367056=367055=367056=diff
==
--- clang-tools-extra/trunk/clang-doc/MDGenerator.cpp 

[clang-tools-extra] r367050 - [clang-doc] Fix output format of html

2019-07-25 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Thu Jul 25 13:49:00 2019
New Revision: 367050

URL: http://llvm.org/viewvc/llvm-project?rev=367050=rev
Log:
[clang-doc] Fix output format of html

The children of a TagNode are rendered in the same line as the parent only if 
they are all TextNodes.
When children are not inline; two text nodes that are adjacent won't have a new 
line between them, each tag node is rendered in its own line.

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

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

Modified: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp?rev=367050=367049=367050=diff
==
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp Thu Jul 25 13:49:00 2019
@@ -44,9 +44,6 @@ public:
   operator bool() = delete;
 
   bool IsSelfClosing() const;
-
-  bool HasInlineChildren() const;
-
   llvm::SmallString<16> ToString() const;
 
 private:
@@ -67,29 +64,20 @@ struct HTMLNode {
 };
 
 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 @@ bool HTMLTag::IsSelfClosing() const {
   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 @@ llvm::SmallString<16> HTMLTag::ToString(
 }
 
 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 (SelfClosing) {
+  if (Tag.IsSelfClosing()) {
 OS << "/>";
 return;
   }
@@ -385,7 +361,7 @@ static std::unique_ptr genHTML
   } else if (I.Kind == "TextComment") {
 if (I.Text == "")
   return nullptr;
-return llvm::make_unique(I.Text, true);
+return llvm::make_unique(I.Text);
   }
   return nullptr;
 }

Modified: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp?rev=367050=367049=367050=diff
==
--- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp Thu Jul 
25 13:49:00 2019
@@ -56,9 +56,7 @@ TEST(HTMLGeneratorTest, emitNamespaceHTM
   Functions
   
 OneFunction
-
-  OneFunction()
-
+ 

[clang-tools-extra] r367045 - [clang-doc] Fix html entities in rendered text

2019-07-25 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Thu Jul 25 13:14:45 2019
New Revision: 367045

URL: http://llvm.org/viewvc/llvm-project?rev=367045=rev
Log:
[clang-doc] Fix html entities in rendered text

Replace &, <, >, ", and ' with their corresponding html entities in text 
rendered
by HTML generator.

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

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

Modified: clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp?rev=367045=367044=367045=diff
==
--- clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/HTMLGenerator.cpp Thu Jul 25 13:14:45 2019
@@ -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 @@ llvm::SmallString<16> HTMLTag::ToString(
 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) {

Modified: clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp?rev=367045=367044=367045=diff
==
--- clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-doc/HTMLGeneratorTest.cpp Thu Jul 
25 13:14:45 2019
@@ -258,6 +258,15 @@ TEST(HTMLGeneratorTest, emitCommentHTML)
   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 @@ TEST(HTMLGeneratorTest, emitCommentHTML)
   
  Extended description that continues onto the next line.
   
+  
+ Comment with html entities: , , , , .
+  
 
   
 


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