[PATCH] D43424: [clang-doc] Implement a (simple) Markdown generator

2018-09-11 Thread Julie Hockett via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE341955: Reland Implement a (simple) Markdown 
generator (authored by juliehockett, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43424?vs=161123=164903#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D43424

Files:
  clang-doc/CMakeLists.txt
  clang-doc/Generators.cpp
  clang-doc/Generators.h
  clang-doc/MDGenerator.cpp
  clang-doc/Representation.h
  clang-doc/YAMLGenerator.cpp
  clang-doc/gen_tests.py
  clang-doc/tool/ClangDocMain.cpp
  test/clang-doc/md-comment.cpp
  test/clang-doc/md-linkage.cpp
  test/clang-doc/md-module.cpp
  test/clang-doc/md-namespace.cpp
  test/clang-doc/md-record.cpp

Index: clang-doc/Generators.h
===
--- clang-doc/Generators.h
+++ clang-doc/Generators.h
@@ -27,7 +27,7 @@
   virtual ~Generator() = default;
 
   // Write out the decl info in the specified format.
-  virtual bool generateDocForInfo(Info *I, llvm::raw_ostream ) = 0;
+  virtual llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream ) = 0;
 };
 
 typedef llvm::Registry GeneratorRegistry;
Index: clang-doc/YAMLGenerator.cpp
===
--- clang-doc/YAMLGenerator.cpp
+++ clang-doc/YAMLGenerator.cpp
@@ -242,12 +242,12 @@
 public:
   static const char *Format;
 
-  bool generateDocForInfo(Info *I, llvm::raw_ostream ) override;
+  llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream ) override;
 };
 
 const char *YAMLGenerator::Format = "yaml";
 
-bool YAMLGenerator::generateDocForInfo(Info *I, llvm::raw_ostream ) {
+llvm::Error YAMLGenerator::generateDocForInfo(Info *I, llvm::raw_ostream ) {
   llvm::yaml::Output InfoYAML(OS);
   switch (I->IT) {
   case InfoType::IT_namespace:
@@ -263,10 +263,10 @@
 InfoYAML << *static_cast(I);
 break;
   case InfoType::IT_default:
-llvm::errs() << "Unexpected info type in index.\n";
-return true;
+return llvm::make_error("Unexpected info type.\n",
+   llvm::inconvertibleErrorCode());
   }
-  return false;
+  return llvm::Error::success();
 }
 
 static GeneratorRegistry::Add YAML(YAMLGenerator::Format,
Index: clang-doc/Generators.cpp
===
--- clang-doc/Generators.cpp
+++ clang-doc/Generators.cpp
@@ -29,8 +29,11 @@
 // This anchor is used to force the linker to link in the generated object file
 // and thus register the generators.
 extern volatile int YAMLGeneratorAnchorSource;
+extern volatile int MDGeneratorAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED YAMLGeneratorAnchorDest =
 YAMLGeneratorAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED MDGeneratorAnchorDest =
+MDGeneratorAnchorSource;
 
 } // namespace doc
 } // namespace clang
Index: clang-doc/Representation.h
===
--- clang-doc/Representation.h
+++ clang-doc/Representation.h
@@ -48,13 +48,14 @@
   CommentInfo(CommentInfo ) = delete;
   CommentInfo(CommentInfo &) = default;
 
-  SmallString<16> Kind; // Kind of comment (TextComment, InlineCommandComment,
-// HTMLStartTagComment, HTMLEndTagComment,
-// BlockCommandComment, ParamCommandComment,
-// TParamCommandComment, VerbatimBlockComment,
-// VerbatimBlockLineComment, VerbatimLineComment).
-  SmallString<64> Text; // Text of the comment.
-  SmallString<16> Name; // Name of the comment (for Verbatim and HTML).
+  SmallString<16>
+  Kind; // Kind of comment (FullComment, ParagraphComment, TextComment,
+// InlineCommandComment, HTMLStartTagComment, HTMLEndTagComment,
+// BlockCommandComment, ParamCommandComment,
+// TParamCommandComment, VerbatimBlockComment,
+// VerbatimBlockLineComment, VerbatimLineComment).
+  SmallString<64> Text;  // Text of the comment.
+  SmallString<16> Name;  // Name of the comment (for Verbatim and HTML).
   SmallString<8> Direction;  // Parameter direction (for (T)ParamCommand).
   SmallString<16> ParamName; // Parameter name (for (T)ParamCommand).
   SmallString<16> CloseName; // Closing tag name (for VerbatimBlock).
Index: clang-doc/MDGenerator.cpp
===
--- clang-doc/MDGenerator.cpp
+++ clang-doc/MDGenerator.cpp
@@ -0,0 +1,312 @@
+//===-- MDGenerator.cpp - Markdown Generator *- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "Generators.h"
+#include "Representation.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FileSystem.h"

[PATCH] D43424: [clang-doc] Implement a (simple) Markdown generator

2018-09-11 Thread Julie Hockett via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL341955: Reland Implement a (simple) Markdown 
generator (authored by juliehockett, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D43424?vs=161123=164902#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D43424

Files:
  clang-tools-extra/trunk/clang-doc/CMakeLists.txt
  clang-tools-extra/trunk/clang-doc/Generators.cpp
  clang-tools-extra/trunk/clang-doc/Generators.h
  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/gen_tests.py
  clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/trunk/test/clang-doc/md-comment.cpp
  clang-tools-extra/trunk/test/clang-doc/md-linkage.cpp
  clang-tools-extra/trunk/test/clang-doc/md-module.cpp
  clang-tools-extra/trunk/test/clang-doc/md-namespace.cpp
  clang-tools-extra/trunk/test/clang-doc/md-record.cpp

Index: clang-tools-extra/trunk/clang-doc/Generators.cpp
===
--- clang-tools-extra/trunk/clang-doc/Generators.cpp
+++ clang-tools-extra/trunk/clang-doc/Generators.cpp
@@ -29,8 +29,11 @@
 // This anchor is used to force the linker to link in the generated object file
 // and thus register the generators.
 extern volatile int YAMLGeneratorAnchorSource;
+extern volatile int MDGeneratorAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED YAMLGeneratorAnchorDest =
 YAMLGeneratorAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED MDGeneratorAnchorDest =
+MDGeneratorAnchorSource;
 
 } // namespace doc
 } // namespace clang
Index: clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp
===
--- clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp
+++ clang-tools-extra/trunk/clang-doc/YAMLGenerator.cpp
@@ -242,12 +242,12 @@
 public:
   static const char *Format;
 
-  bool generateDocForInfo(Info *I, llvm::raw_ostream ) override;
+  llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream ) override;
 };
 
 const char *YAMLGenerator::Format = "yaml";
 
-bool YAMLGenerator::generateDocForInfo(Info *I, llvm::raw_ostream ) {
+llvm::Error YAMLGenerator::generateDocForInfo(Info *I, llvm::raw_ostream ) {
   llvm::yaml::Output InfoYAML(OS);
   switch (I->IT) {
   case InfoType::IT_namespace:
@@ -263,10 +263,10 @@
 InfoYAML << *static_cast(I);
 break;
   case InfoType::IT_default:
-llvm::errs() << "Unexpected info type in index.\n";
-return true;
+return llvm::make_error("Unexpected info type.\n",
+   llvm::inconvertibleErrorCode());
   }
-  return false;
+  return llvm::Error::success();
 }
 
 static GeneratorRegistry::Add YAML(YAMLGenerator::Format,
Index: clang-tools-extra/trunk/clang-doc/Representation.h
===
--- clang-tools-extra/trunk/clang-doc/Representation.h
+++ clang-tools-extra/trunk/clang-doc/Representation.h
@@ -48,13 +48,14 @@
   CommentInfo(CommentInfo ) = delete;
   CommentInfo(CommentInfo &) = default;
 
-  SmallString<16> Kind; // Kind of comment (TextComment, InlineCommandComment,
-// HTMLStartTagComment, HTMLEndTagComment,
-// BlockCommandComment, ParamCommandComment,
-// TParamCommandComment, VerbatimBlockComment,
-// VerbatimBlockLineComment, VerbatimLineComment).
-  SmallString<64> Text; // Text of the comment.
-  SmallString<16> Name; // Name of the comment (for Verbatim and HTML).
+  SmallString<16>
+  Kind; // Kind of comment (FullComment, ParagraphComment, TextComment,
+// InlineCommandComment, HTMLStartTagComment, HTMLEndTagComment,
+// BlockCommandComment, ParamCommandComment,
+// TParamCommandComment, VerbatimBlockComment,
+// VerbatimBlockLineComment, VerbatimLineComment).
+  SmallString<64> Text;  // Text of the comment.
+  SmallString<16> Name;  // Name of the comment (for Verbatim and HTML).
   SmallString<8> Direction;  // Parameter direction (for (T)ParamCommand).
   SmallString<16> ParamName; // Parameter name (for (T)ParamCommand).
   SmallString<16> CloseName; // Closing tag name (for VerbatimBlock).
Index: clang-tools-extra/trunk/clang-doc/MDGenerator.cpp
===
--- clang-tools-extra/trunk/clang-doc/MDGenerator.cpp
+++ clang-tools-extra/trunk/clang-doc/MDGenerator.cpp
@@ -0,0 +1,312 @@
+//===-- MDGenerator.cpp - Markdown Generator *- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//

[PATCH] D43424: [clang-doc] Implement a (simple) Markdown generator

2018-08-21 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett reopened this revision.
juliehockett added a comment.
This revision is now accepted and ready to land.
Herald added a subscriber: kadircet.

Reopening because it was reverted and I haven't had time to look into it yet


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43424



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


[PATCH] D43424: [clang-doc] Implement a (simple) Markdown generator

2018-08-16 Thread Julie Hockett via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
juliehockett marked an inline comment as done.
Closed by commit rCTE339948: Implement a (simple) Markdown generator (authored 
by juliehockett, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43424?vs=159091=161123#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43424

Files:
  clang-doc/CMakeLists.txt
  clang-doc/Generators.cpp
  clang-doc/Generators.h
  clang-doc/MDGenerator.cpp
  clang-doc/Representation.h
  clang-doc/YAMLGenerator.cpp
  clang-doc/gen_tests.py
  clang-doc/tool/ClangDocMain.cpp
  test/clang-doc/md-comment.cpp
  test/clang-doc/md-linkage.cpp
  test/clang-doc/md-module.cpp
  test/clang-doc/md-namespace.cpp
  test/clang-doc/md-record.cpp

Index: clang-doc/gen_tests.py
===
--- clang-doc/gen_tests.py
+++ clang-doc/gen_tests.py
@@ -18,16 +18,19 @@
 
 To generate all current tests:
 - Generate mapper tests:
-python gen_tests.py -flag='--dump-mapper' -flag='--doxygen' -flag='--extra-arg=-fmodules-ts' -prefix mapper
+python gen_tests.py -flag='--dump-mapper' -flag='--doxygen' -flag='--extra-arg=-fmodules-ts' -prefix mapper -use-check-next
 
 - Generate reducer tests:
-python gen_tests.py -flag='--dump-intermediate' -flag='--doxygen' -flag='--extra-arg=-fmodules-ts' -prefix bc
+python gen_tests.py -flag='--dump-intermediate' -flag='--doxygen' -flag='--extra-arg=-fmodules-ts' -prefix bc -use-check-next
 
 - Generate yaml tests:
-python gen_tests.py -flag='--format=yaml' -flag='--doxygen' -flag='--extra-arg=-fmodules-ts' -prefix yaml
+python gen_tests.py -flag='--format=yaml' -flag='--doxygen' -flag='--extra-arg=-fmodules-ts' -prefix yaml -use-check-next
 
 - Generate public decl tests:
-python gen_tests.py -flag='--format=yaml' -flag='--doxygen' -flag='--public' -flag='--extra-arg=-fmodules-ts' -prefix public
+python gen_tests.py -flag='--format=yaml' -flag='--doxygen' -flag='--public' -flag='--extra-arg=-fmodules-ts' -prefix public -use-check-next
+
+- Generate Markdown tests:
+python gen_tests.py -flag='--format=md' -flag='--doxygen' -flag='--public' -flag='--extra-arg=-fmodules-ts' -prefix md
 
 This script was written on/for Linux, and has not been tested on any other
 platform and so it may not work.
@@ -95,7 +98,8 @@
 return code
 
 
-def get_output(root, out_file, case_out_path, flags, checkname, bcanalyzer):
+def get_output(root, out_file, case_out_path, flags, checkname, bcanalyzer,
+check_next=True):
 output = ''
 run_cmd = ''
 if '--dump-mapper' in flags or '--dump-intermediate' in flags:
@@ -119,8 +123,14 @@
 output = re.sub(YAML_USR_REGEX, YAML_USR, output)
 output = re.sub(BITCODE_USR_REGEX, BITCODE_USR, output)
 output = CHECK.format(checkname) + output.rstrip()
-output = run_cmd + output.replace('\n',
-  '\n' + CHECK_NEXT.format(checkname))
+
+if check_next:
+  check_comment = CHECK_NEXT.format(checkname)
+else:
+  check_comment = CHECK.format(checkname)
+
+output = output.replace('\n', '\n' + check_comment)
+output = run_cmd + output.replace('%s\n' % check_comment, "")
 
 return output + '\n'
 
@@ -151,6 +161,12 @@
 metavar="PATH",
 default='llvm-bcanalyzer',
 help='path to llvm-bcanalyzer binary')
+parser.add_argument(
+'-use-check-next',
+dest='check_next',
+default=False,
+action='store_true',
+help='Whether or not to use CHECK-NEXT in the resulting tests.')
 args = parser.parse_args()
 
 flags = ' '.join(args.flags)
@@ -188,7 +204,8 @@
 if len(usr) < 2:
 continue
 all_output += get_output(root, out_file, out_dir, args.flags,
- num_outputs, args.bcanalyzer)
+ num_outputs, args.bcanalyzer, 
+ args.check_next)
 num_outputs += 1
 
 # Add test case code to test
Index: clang-doc/CMakeLists.txt
===
--- clang-doc/CMakeLists.txt
+++ clang-doc/CMakeLists.txt
@@ -10,6 +10,7 @@
   ClangDoc.cpp
   Generators.cpp
   Mapper.cpp
+  MDGenerator.cpp
   Representation.cpp
   Serialize.cpp
   YAMLGenerator.cpp
Index: clang-doc/tool/ClangDocMain.cpp
===
--- clang-doc/tool/ClangDocMain.cpp
+++ clang-doc/tool/ClangDocMain.cpp
@@ -34,6 +34,7 @@
 #include "clang/Tooling/StandaloneExecution.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/APFloat.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
@@ -69,13 +70,18 @@
llvm::cl::init(false), 

[PATCH] D43424: [clang-doc] Implement a (simple) Markdown generator

2018-08-09 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan accepted this revision.
leonardchan added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clang-doc/MDGenerator.cpp:79
+
+void writeHeader(const Twine , int Num, raw_ostream ) {
+  OS << std::string(Num, '#') + " " + Text << "\n";

nit: make `Num` unsigned since the `std::string` fill ctor takes an unsigned 
value


https://reviews.llvm.org/D43424



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


[PATCH] D43424: [clang-doc] Implement a (simple) Markdown generator

2018-08-03 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 159091.
juliehockett marked an inline comment as done.
juliehockett added a comment.
Herald added a subscriber: arphaman.

Updating based on recent landed patches & updated tests


https://reviews.llvm.org/D43424

Files:
  clang-tools-extra/clang-doc/CMakeLists.txt
  clang-tools-extra/clang-doc/Generators.cpp
  clang-tools-extra/clang-doc/Generators.h
  clang-tools-extra/clang-doc/MDGenerator.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/clang-doc/gen_tests.py
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/test/clang-doc/md-comment.cpp
  clang-tools-extra/test/clang-doc/md-linkage.cpp
  clang-tools-extra/test/clang-doc/md-module.cpp
  clang-tools-extra/test/clang-doc/md-namespace.cpp
  clang-tools-extra/test/clang-doc/md-record.cpp

Index: clang-tools-extra/test/clang-doc/md-record.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-doc/md-record.cpp
@@ -0,0 +1,97 @@
+// THIS IS A GENERATED TEST. DO NOT EDIT.
+// To regenerate, see clang-doc/gen_test.py docstring.
+//
+// This test requires Linux due to system-dependent USR for the inner class.
+// REQUIRES: system-linux
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+
+void H() {
+  class I {};
+}
+
+union A { int X; int Y; };
+
+enum B { X, Y };
+
+enum class Bc { A, B };
+
+struct C { int i; };
+
+class D {};
+
+class E {
+public:
+  E() {}
+  ~E() {}
+
+protected:
+  void ProtectedMethod();
+};
+
+void E::ProtectedMethod() {}
+
+class F : virtual private D, public E {};
+
+class X {
+  class Y {};
+};
+
+// RUN: clang-doc --format=md --doxygen --public --extra-arg=-fmodules-ts -p %t %t/test.cpp -output=%t/docs
+
+
+// RUN: cat %t/docs/./F.md | FileCheck %s --check-prefix CHECK-0
+// CHECK-0: # class F
+// CHECK-0: *Defined at line 36 of test*
+// CHECK-0: Inherits from E, D
+
+// RUN: cat %t/docs/./D.md | FileCheck %s --check-prefix CHECK-1
+// CHECK-1: # class D
+// CHECK-1: *Defined at line 23 of test*
+
+// RUN: cat %t/docs/./GlobalNamespace.md | FileCheck %s --check-prefix CHECK-2
+// CHECK-2: # Global Namespace
+// CHECK-2: ## Functions
+// CHECK-2: ### void H()
+// CHECK-2: *Defined at line 11 of test*
+// CHECK-2: ## Enums
+// CHECK-2: | enum B |
+// CHECK-2: --
+// CHECK-2: | X |
+// CHECK-2: | Y |
+// CHECK-2: *Defined at line 17 of test*
+// CHECK-2: | enum class Bc |
+// CHECK-2: --
+// CHECK-2: | A |
+// CHECK-2: | B |
+// CHECK-2: *Defined at line 19 of test*
+
+// RUN: cat %t/docs/./E.md | FileCheck %s --check-prefix CHECK-3
+// CHECK-3: # class E
+// CHECK-3: *Defined at line 25 of test*
+// CHECK-3: ## Functions
+// CHECK-3: ### void E()
+// CHECK-3: *Defined at line 27 of test*
+// CHECK-3: ### void ~E()
+// CHECK-3: *Defined at line 28 of test*
+// CHECK-3: ### void ProtectedMethod()
+// CHECK-3: *Defined at line 34 of test*
+
+// RUN: cat %t/docs/./C.md | FileCheck %s --check-prefix CHECK-4
+// CHECK-4: # struct C
+// CHECK-4: *Defined at line 21 of test*
+// CHECK-4: ## Members
+// CHECK-4: int i
+
+// RUN: cat %t/docs/./X.md | FileCheck %s --check-prefix CHECK-5
+// CHECK-5: # class X
+// CHECK-5: *Defined at line 38 of test*
+
+// RUN: cat %t/docs/./A.md | FileCheck %s --check-prefix CHECK-6
+// CHECK-6: # union A
+// CHECK-6: *Defined at line 15 of test*
+// CHECK-6: ## Members
+// CHECK-6: int X
+// CHECK-6: int Y
Index: clang-tools-extra/test/clang-doc/md-namespace.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-doc/md-namespace.cpp
@@ -0,0 +1,46 @@
+// THIS IS A GENERATED TEST. DO NOT EDIT.
+// To regenerate, see clang-doc/gen_test.py docstring.
+//
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+
+namespace A {
+  
+void f();
+
+}  // namespace A
+
+namespace A {
+
+void f(){};
+
+namespace B {
+
+enum E { X };
+
+E func(int i) { return X; }
+
+}  // namespace B
+}  // namespace A
+
+// RUN: clang-doc --format=md --doxygen --public --extra-arg=-fmodules-ts -p %t %t/test.cpp -output=%t/docs
+
+
+// RUN: cat %t/docs/./A.md | FileCheck %s --check-prefix CHECK-0
+// CHECK-0: # namespace A
+// CHECK-0: ## Functions
+// CHECK-0: ### void f()
+// CHECK-0: *Defined at line 17 of test*
+
+// RUN: cat %t/docs/A/B.md | FileCheck %s --check-prefix CHECK-1
+// CHECK-1: # namespace B
+// CHECK-1: ## Functions
+// CHECK-1: ### enum A::B::E func(int i)
+// CHECK-1: *Defined at line 23 of test*
+// CHECK-1: ## Enums
+// CHECK-1: | enum E |
+// CHECK-1: --
+// CHECK-1: | X |
+// CHECK-1: *Defined at line 21 of test*
Index: clang-tools-extra/test/clang-doc/md-module.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-doc/md-module.cpp
@@ -0,0 +1,24 @@
+// THIS IS A GENERATED TEST. DO 

[PATCH] D43424: [clang-doc] Implement a (simple) Markdown generator

2018-06-20 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/clang-doc/MDGenerator.cpp:33
+  case AccessSpecifier::AS_none:
+return "";
+  }

return {};


https://reviews.llvm.org/D43424



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


[PATCH] D43424: [clang-doc] Implement a (simple) Markdown generator

2018-06-20 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 152135.
juliehockett added a comment.

Updating to reflect changes to the framework (and make it work).


https://reviews.llvm.org/D43424

Files:
  clang-tools-extra/clang-doc/CMakeLists.txt
  clang-tools-extra/clang-doc/Generators.cpp
  clang-tools-extra/clang-doc/Generators.h
  clang-tools-extra/clang-doc/MDGenerator.cpp
  clang-tools-extra/clang-doc/Representation.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/test/clang-doc/md-comments.cpp
  clang-tools-extra/test/clang-doc/md-namespace.cpp
  clang-tools-extra/test/clang-doc/md-record.cpp

Index: clang-tools-extra/test/clang-doc/md-record.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-doc/md-record.cpp
@@ -0,0 +1,101 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc -doxygen -format=md -p %t %t/test.cpp -output=%t/docs
+// RUN: cat %t/docs/A.md | FileCheck %s --check-prefix=CHECK-A
+// RUN: cat %t/docs/Bc.md | FileCheck %s --check-prefix=CHECK-BC
+// RUN: cat %t/docs/B.md | FileCheck %s --check-prefix=CHECK-B
+// RUN: cat %t/docs/C.md | FileCheck %s --check-prefix=CHECK-C
+// RUN: cat %t/docs/D.md | FileCheck %s --check-prefix=CHECK-D
+// RUN: cat %t/docs/E.md | FileCheck %s --check-prefix=CHECK-E
+// RUN: cat %t/docs/E/ProtectedMethod.md | FileCheck %s --check-prefix=CHECK-EPM
+// RUN: cat %t/docs/E/E.md | FileCheck %s --check-prefix=CHECK-ECON
+// RUN: cat %t/docs/E/'~E.md' | FileCheck %s --check-prefix=CHECK-EDES
+// RUN: cat %t/docs/F.md | FileCheck %s --check-prefix=CHECK-F
+// RUN: cat %t/docs/X.md | FileCheck %s --check-prefix=CHECK-X
+// RUN: cat %t/docs/X/Y.md | FileCheck %s --check-prefix=CHECK-Y
+// RUN: cat %t/docs/H.md | FileCheck %s --check-prefix=CHECK-H
+// RUN: cat %t/docs/H/I.md | FileCheck %s --check-prefix=CHECK-I
+
+union A { int X; int Y; };
+
+// CHECK-A: # union A
+// CHECK-A-NEXT: *Defined at line 21 of {{.*}}*
+// CHECK-A: ## Members 
+// CHECK-A-NEXT: int X
+// CHECK-A-NEXT: int Y
+
+enum B { X, Y };
+
+// CHECK-B: | enum B |
+// CHECK-B-NEXT: --
+// CHECK-B-NEXT: | X |
+// CHECK-B-NEXT: | Y |
+
+enum class Bc { A, B };
+
+// CHECK-BC: | enum class Bc |
+// CHECK-BC-NEXT: --
+// CHECK-BC-NEXT: | A |
+// CHECK-BC-NEXT: | B |
+
+struct C { int i; };
+
+// CHECK-C: # struct C
+// CHECK-C-NEXT: *Defined at line 43 of {{.*}}*
+// CHECK-C: ## Members 
+// CHECK-C-NEXT: int i
+
+class D {};
+
+// CHECK-D: # class D
+// CHECK-D-NEXT: *Defined at line 50 of {{.*}}*
+
+class E {
+public:
+  E() {}
+  ~E() {}
+
+protected:
+  void ProtectedMethod();
+};
+
+// CHECK-E: # class E
+// CHECK-E-NEXT: *Defined at line 55 of {{.*}}*
+
+// CHECK-ECON: ## void E()
+// CHECK-ECON-NEXT: *Defined at line 57 of {{.*}}*
+
+// CHECK-EDES: ## void ~E()
+// CHECK-EDES-NEXT: *Defined at line 58 of {{.*}}*
+
+void E::ProtectedMethod() {}
+
+// CHECK-EPM: ## void ProtectedMethod()
+// CHECK-EPM-NEXT: *Defined at line 73 of {{.*}}*
+
+class F : virtual private D, public E {};
+
+// CHECK-F: # class F
+// CHECK-F-NEXT: *Defined at line 78 of {{.*}}*
+
+class X {
+  class Y {};
+};
+
+// CHECK-X: # class X
+// CHECK-X-NEXT: *Defined at line 83 of {{.*}}*
+
+// CHECK-Y: # class Y
+// CHECK-Y-NEXT: *Defined at line 84 of {{.*}}*
+
+void H() {
+  class I {};
+}
+
+// CHECK-H: ## void H()
+// CHECK-H-NEXT: *Defined at line 93 of {{.*}}*
+
+// CHECK-I: # class I
+// CHECK-I-NEXT: *Defined at line 94 of {{.*}}*
Index: clang-tools-extra/test/clang-doc/md-namespace.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-doc/md-namespace.cpp
@@ -0,0 +1,43 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc -doxygen -format=md -p %t %t/test.cpp -output=%t/docs
+// RUN: cat %t/docs/A.md | FileCheck %s --check-prefix=CHECK-A
+// RUN: cat %t/docs/A/B.md | FileCheck %s --check-prefix=CHECK-B
+// RUN: cat %t/docs/A/f.md | FileCheck %s --check-prefix=CHECK-F
+// RUN: cat %t/docs/A/B/E.md | FileCheck %s --check-prefix=CHECK-E
+// RUN: cat %t/docs/A/B/func.md | FileCheck %s --check-prefix=CHECK-FUNC
+
+namespace A {
+  
+// CHECK-A: # namespace A
+
+void f();
+
+}  // namespace A
+
+namespace A {
+
+void f(){};
+
+// CHECK-F: ## void f()
+// CHECK-F-NEXT: *Defined at line 22 of {{.*}}*
+
+namespace B {
+
+// CHECK-B: # namespace B
+
+enum E { X };
+
+// CHECK-E:  | enum E |
+// CHECK-E-NEXT: --
+// CHECK-E-NEXT: | X |
+
+E func(int i) { return X; }
+
+// CHECK-FUNC: enum A::B::E func(int i)
+// CHECK-FUNC-NEXT: *Defined at line 37 of {{.*}}*
+
+}  // namespace B
+}  // namespace A
Index: clang-tools-extra/test/clang-doc/md-comments.cpp
===
--- /dev/null
+++ 

[PATCH] D43424: [clang-doc] Implement a (simple) Markdown generator

2018-05-17 Thread Joe via Phabricator via cfe-commits
rja added inline comments.



Comment at: clang-doc/generators/MDGenerator.cpp:57
+  sys::path::native(NamespacesPath, Path);
+  // for (const auto  : I->Namespace)
+  //   sys::path::append(Path, IS->find(Namespace)->Name);

remove commented code?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43424



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


[PATCH] D43424: [clang-doc] Implement a (simple) Markdown generator

2018-05-17 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: clang-doc/generators/Generators.h:44
 
+class MDGenerator : public Generator {
+public:

Could you add high-level comment on what this does? This seems to build up some 
directory structure and write different infos into different sub-directories. 
Could you elaborate a bit on this?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43424



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


[PATCH] D43424: [clang-doc] Implement a (simple) Markdown generator

2018-02-23 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

Please run Clang-format and Clang-tidy modernize.




Comment at: clang-doc/generators/Generators.h:46
+public:
+  MDGenerator(std::unique_ptr , StringRef Root, StringRef Format) 
: Generator(IS, Root, Format) {};
+  virtual ~MDGenerator() {};

Please remove semicolon after constructor body. Please enable CLang's 
-Wextra-semi.



Comment at: clang-doc/generators/Generators.h:47
+  MDGenerator(std::unique_ptr , StringRef Root, StringRef Format) 
: Generator(IS, Root, Format) {};
+  virtual ~MDGenerator() {};
+  

Please use = default;


https://reviews.llvm.org/D43424



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


[PATCH] D43424: [clang-doc] Implement a (simple) Markdown generator

2018-02-22 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 135583.
juliehockett added a comment.

Updating based on parent revision changes -- still rough, will continue to 
improve.


https://reviews.llvm.org/D43424

Files:
  clang-doc/generators/CMakeLists.txt
  clang-doc/generators/Generators.h
  clang-doc/generators/MDGenerator.cpp
  clang-doc/tool/ClangDocMain.cpp

Index: clang-doc/tool/ClangDocMain.cpp
===
--- clang-doc/tool/ClangDocMain.cpp
+++ clang-doc/tool/ClangDocMain.cpp
@@ -49,7 +49,7 @@
 cl::init("docs"), cl::cat(ClangDocCategory));
 
 static cl::opt Format(
-"format", cl::desc("Format for outputted docs (Current options are yaml)."),
+"format", cl::desc("Format for outputted docs (Current options are yaml, md)."),
 cl::init("yaml"), cl::cat(ClangDocCategory));
 
 static cl::opt DumpResult(
Index: clang-doc/generators/MDGenerator.cpp
===
--- /dev/null
+++ clang-doc/generators/MDGenerator.cpp
@@ -0,0 +1,366 @@
+//===-- MDGenerator.cpp - Markdown Generator *- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "../Representation.h"
+#include "Generators.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
+
+using namespace llvm;
+
+namespace clang {
+namespace doc {
+
+int MDGenerator::generate() {
+  if (buildDirTree() && writeNamespaces() && writeClasses()) return 0;
+  return 1;
+}
+
+// File creation and I/O
+
+int MDGenerator::buildDirTree() {
+  removeExistingDirectory(Root);
+  sys::path::native(Root, NamespacesPath);
+  sys::path::append(NamespacesPath, "namespaces");
+  sys::path::native(Root, ClassPath);
+  sys::path::append(ClassPath, "classes");
+  return buildDirectory(NamespacesPath) && buildDirectory(ClassPath);
+}
+
+// Documentation generation
+
+bool MDGenerator::writeNamespaces() {
+  // TODO: Generate summary page
+  bool Success = true;
+  for (const auto  : IS->getNamespaceInfos()) Success = writeNamespacePage(I);
+  return Success;
+}
+
+bool MDGenerator::writeClasses() {
+  bool Success = true;
+  for (const auto  : IS->getRecordInfos()) {
+if (I->TagType == TagTypeKind::TTK_Class) Success = writeClassPage(I);
+  }
+  return Success;
+}
+
+bool MDGenerator::writeNamespacePage(const std::unique_ptr ) {
+  SmallString<128> Path;
+  sys::path::native(NamespacesPath, Path);
+  // for (const auto  : I->Namespace)
+  //   sys::path::append(Path, IS->find(Namespace)->Name);
+  // std::error_code DirectoryStatus = sys::fs::create_directories(Path);
+  // if (DirectoryStatus != OK) {
+  //   errs() << "Unable to create class directories.\n";
+  //   return 1;
+  // }
+  sys::path::append(Path, I->Name + ".md");
+  std::error_code OutErrorInfo;
+  raw_fd_ostream OS(Path, OutErrorInfo, sys::fs::F_None);
+  if (OutErrorInfo != OK) {
+errs() << "Error opening class file.\n";
+return false;
+  }
+
+  writeLine(genH1("namespace " + I->Name), OS);
+  writeBlankLine(OS);
+
+  for (const auto  : I->Description) writeDescription(C, OS);
+
+  // TODO: Write subnamespaces
+
+  // Write functions.
+  bool wroteFunctionHeader = false;
+  for (const auto  : IS->getFunctionInfos()) {
+if (!F->Namespace.empty() && F->Namespace[0] == I->Name) {
+  if (!wroteFunctionHeader) {
+wroteFunctionHeader = true;
+writeLine(genH2("Functions"), OS);
+  }
+  writeFunction(F, OS);
+  writeBlankLine(OS);
+}
+  }
+
+  // Fetch and sort records.
+  llvm::SmallVector Structs;
+  llvm::SmallVector Classes;
+  llvm::SmallVector Unions;
+  for (const auto  : IS->getRecordInfos()) {
+if (!R->Namespace.empty() && R->Namespace[0] == I->Name) {
+  switch (R->TagType) {
+case TagTypeKind::TTK_Class:
+  Classes.push_back(R.get());
+  break;
+case TagTypeKind::TTK_Struct:
+  Structs.push_back(R.get());
+  break;
+case TagTypeKind::TTK_Union:
+  Unions.push_back(R.get());
+  break;
+default:
+  continue;
+  }
+}
+  }
+
+  // Write structs.
+  bool wroteHeader = false;
+  sortRecordInfos(Structs);
+  for (const auto  : Structs) {
+if (!wroteHeader) {
+  wroteHeader = true;
+  writeLine(genH2("Structs"), OS);
+}
+writeRecordSummary(*S, OS);
+writeBlankLine(OS);
+  }
+
+  // Write classes.
+  wroteHeader = false;
+  sortRecordInfos(Classes);
+  for (const auto  : Classes) {
+if (!wroteHeader) {
+  wroteHeader = true;
+  writeLine(genH2("Classes"), OS);
+}
+writeRecordSummary(*C, OS);
+writeBlankLine(OS);
+  }
+
+  // Write unions.
+  wroteHeader = false;
+  sortRecordInfos(Unions);
+  for 

[PATCH] D43424: [clang-doc] Implement a (simple) Markdown generator

2018-02-17 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

It will be good to have the tests for generators.




Comment at: clang-doc/generators/Generators.h:28
+public:
+  Generator(std::unique_ptr , StringRef Root, StringRef Format) : 
IS(IS), Root(Root), Format(Format) {};
+  virtual ~Generator() {};

Is this code (and the code in two parent Differentials) formatted with 
`clang-format`?
This line is certainly longer than 80 columns.


https://reviews.llvm.org/D43424



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


[PATCH] D43424: [clang-doc] Implement a (simple) Markdown generator

2018-02-16 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett created this revision.
juliehockett added reviewers: klimek, jakehehrlich, sammccall.
juliehockett added a project: clang-tools-extra.
Herald added subscribers: mgrang, mgorny.
juliehockett added a dependency: D43341: [clang-doc] Implement reducer portion 
of the frontend framework.

Implementing a simple Markdown generator from the emitted bitcode summary of 
declarations. Very primitive at this point, but will be expanded. Currently 
emits an .md file for each class and namespace, listing its contents.

For a more detailed overview of the tool, see the design document on the 
mailing list: http://lists.llvm.org/pipermail/cfe-dev/2017-December/056203.html


https://reviews.llvm.org/D43424

Files:
  clang-doc/CMakeLists.txt
  clang-doc/generators/CMakeLists.txt
  clang-doc/generators/GeneratorBase.cpp
  clang-doc/generators/Generators.h
  clang-doc/generators/MDGenerator.cpp
  clang-doc/tool/CMakeLists.txt
  clang-doc/tool/ClangDocMain.cpp

Index: clang-doc/tool/ClangDocMain.cpp
===
--- clang-doc/tool/ClangDocMain.cpp
+++ clang-doc/tool/ClangDocMain.cpp
@@ -11,6 +11,7 @@
 #include "ClangDoc.h"
 #include "ClangDocBinary.h"
 #include "ClangDocReducer.h"
+#include "generators/Generators.h"
 #include "clang/AST/AST.h"
 #include "clang/AST/Decl.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -127,5 +128,17 @@
 OS.close();
   }
 
-  return 0;
+  errs() << "Generating docs...\n";
+  SmallString<128> DocsRootPath;
+  sys::path::native(OutDirectory, DocsRootPath);
+  sys::path::append(DocsRootPath, Format);
+  std::error_code DirectoryStatus = sys::fs::create_directories(DocsRootPath);
+  if (DirectoryStatus != OK) {
+errs() << "Unable to create documentation directories.\n";
+return 1;
+  }
+  std::unique_ptr G =
+  doc::GeneratorFactory::create(Infos, DocsRootPath, Format);
+  if (!G) return 1;
+  return G->generate();
 }
Index: clang-doc/tool/CMakeLists.txt
===
--- clang-doc/tool/CMakeLists.txt
+++ clang-doc/tool/CMakeLists.txt
@@ -11,6 +11,7 @@
   clangBasic
   clangFrontend
   clangDoc
+  clangDocGenerators
   clangTooling
   clangToolingCore
   )
Index: clang-doc/generators/MDGenerator.cpp
===
--- /dev/null
+++ clang-doc/generators/MDGenerator.cpp
@@ -0,0 +1,341 @@
+//===-- MDGenerator.cpp - Markdown Generator *- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "../ClangDocRepresentation.h"
+#include "Generators.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace llvm;
+
+namespace clang {
+namespace doc {
+
+int MDGenerator::generate() {
+  if (!buildDirTree() || !writeNamespaces() || !writeClasses()) return 1;
+  return 0;
+}
+
+// File creation and I/O
+
+int MDGenerator::buildDirTree() {
+  removeExistingDirectory(Root);
+  sys::path::native(Root, NamespacesPath);
+  sys::path::append(NamespacesPath, "namespaces");
+  sys::path::native(Root, ClassPath);
+  sys::path::append(ClassPath, "classes");
+  return buildDirectory(NamespacesPath) && buildDirectory(ClassPath);
+}
+
+// Documentation generation
+
+bool MDGenerator::writeNamespaces() {
+  // TODO: Generate summary page
+  bool Success = true;
+  for (const auto  : IS->getNamespaceInfos()) Success = writeNamespacePage(I);
+
+  return Success;
+}
+
+bool MDGenerator::writeClasses() {
+  bool Success = true;
+  for (const auto  : IS->getRecordInfos()) {
+if (I.TagType == TagTypeKind::TTK_Class) Success = writeClassPage(I);
+  }
+  return Success;
+}
+
+bool MDGenerator::writeNamespacePage(const NamespaceInfo ) {
+  SmallString<128> Path;
+  sys::path::native(NamespacesPath, Path);
+  sys::path::append(Path, I.FullyQualifiedName + ".md");
+  std::error_code OutErrorInfo;
+  raw_fd_ostream OS(Path, OutErrorInfo, sys::fs::F_None);
+  if (OutErrorInfo != OK) {
+errs() << "Error creating class file.\n";
+return false;
+  }
+
+  writeLine(genH1("namespace " + I.SimpleName), OS);
+  writeBlankLine(OS);
+
+  // TODO: Write comment description
+
+  // TODO: Write subnamespaces
+
+  // Write functions.
+  bool wroteFunctionHeader = false;
+  for (const auto  : IS->getFunctionInfos()) {
+if (F.Namespace == I.SimpleName) {
+  if (!wroteFunctionHeader) {
+wroteFunctionHeader = true;
+writeLine(genH2("Functions"), OS);
+  }
+  writeFunction(F, OS);
+  writeBlankLine(OS);
+}
+  }
+
+  // Fetch and sort records.
+  llvm::SmallVector Structs;
+  llvm::SmallVector Classes;
+  llvm::SmallVector Unions;
+  for (const auto  :