[PATCH] D48909: [clang-doc] Update BitcodeReader to use llvm::Error

2018-08-09 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett marked 2 inline comments as done.
juliehockett added inline comments.



Comment at: clang-tools-extra/clang-doc/BitcodeReader.cpp:308
-  llvm::errs() << "Invalid type for info.\n";
-  exit(1);
 }

leonardchan wrote:
> Probably not important or it's just me being picky/dumb, but is this exit the 
> intended behavior of this program when reaching this function? If so, should 
> the exit also be expected even when using llvm::Error?
> 
> This also applies to the other times exit() is called in these add functions.
Yes, the point of this change is to get rid of that behavior and return a 
useful error. That's why we change it to return that error instead of void



Comment at: clang-tools-extra/clang-doc/BitcodeReader.cpp:311
 
-template <> void addTypeInfo(RecordInfo *I, MemberTypeInfo &&T) {
   I->Members.emplace_back(std::move(T));

leonardchan wrote:
> Is it necessary to change the return value to llvm::Error for what were 
> originally void functions?
See above


https://reviews.llvm.org/D48909



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


[PATCH] D48909: [clang-doc] Update BitcodeReader to use llvm::Error

2018-08-09 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett marked 2 inline comments as done.
juliehockett added a comment.

In https://reviews.llvm.org/D48909#1194501, @leonardchan wrote:

> Should there be any tests associated with these changes?


There are, this is just supposed to be a NFC so the tests don't need to change. 
They all pass :)


https://reviews.llvm.org/D48909



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


[PATCH] D48908: [clang-doc] Pass over function-internal declarations

2018-08-13 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett closed this revision.
juliehockett added a comment.

Closed in https://reviews.llvm.org/rL339592.


https://reviews.llvm.org/D48908



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


[PATCH] D48909: [clang-doc] Update BitcodeReader to use llvm::Error

2018-08-13 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett closed this revision.
juliehockett added a comment.

Closed in https://reviews.llvm.org/rL339617.


https://reviews.llvm.org/D48909



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


[PATCH] D50709: [clang-doc] Fix unused var

2018-08-14 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett created this revision.
juliehockett added reviewers: leonardchan, jakehehrlich, lebedev.ri.
juliehockett added a project: clang-tools-extra.

https://reviews.llvm.org/D50709

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


Index: clang-tools-extra/clang-doc/Mapper.cpp
===
--- clang-tools-extra/clang-doc/Mapper.cpp
+++ clang-tools-extra/clang-doc/Mapper.cpp
@@ -30,7 +30,7 @@
 return true;
 
   // Skip function-internal decls.
-  if (const DeclContext *F = D->getParentFunctionOrMethod())
+  if (D->getParentFunctionOrMethod())
 return true;
 
   llvm::SmallString<128> USR;


Index: clang-tools-extra/clang-doc/Mapper.cpp
===
--- clang-tools-extra/clang-doc/Mapper.cpp
+++ clang-tools-extra/clang-doc/Mapper.cpp
@@ -30,7 +30,7 @@
 return true;
 
   // Skip function-internal decls.
-  if (const DeclContext *F = D->getParentFunctionOrMethod())
+  if (D->getParentFunctionOrMethod())
 return true;
 
   llvm::SmallString<128> USR;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50709: [clang-doc] Fix unused var

2018-08-14 Thread Julie Hockett via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL339685: [clang-doc] Fix unused variable (authored by 
juliehockett, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D50709?vs=160593&id=160600#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D50709

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


Index: clang-tools-extra/trunk/clang-doc/Mapper.cpp
===
--- clang-tools-extra/trunk/clang-doc/Mapper.cpp
+++ clang-tools-extra/trunk/clang-doc/Mapper.cpp
@@ -30,7 +30,7 @@
 return true;
 
   // Skip function-internal decls.
-  if (const DeclContext *F = D->getParentFunctionOrMethod())
+  if (D->getParentFunctionOrMethod())
 return true;
 
   llvm::SmallString<128> USR;


Index: clang-tools-extra/trunk/clang-doc/Mapper.cpp
===
--- clang-tools-extra/trunk/clang-doc/Mapper.cpp
+++ clang-tools-extra/trunk/clang-doc/Mapper.cpp
@@ -30,7 +30,7 @@
 return true;
 
   // Skip function-internal decls.
-  if (const DeclContext *F = D->getParentFunctionOrMethod())
+  if (D->getParentFunctionOrMethod())
 return true;
 
   llvm::SmallString<128> USR;
___
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&id=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), llvm::cl::cat(ClangDo

[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] D51137: [clang-doc] Fix memory leaks

2018-08-22 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett created this revision.
juliehockett added reviewers: leonardchan, jakehehrlich, lebedev.ri.

Adds a virtual destructor to the base Info class.


https://reviews.llvm.org/D51137

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


Index: clang-tools-extra/clang-doc/Serialize.cpp
===
--- clang-tools-extra/clang-doc/Serialize.cpp
+++ clang-tools-extra/clang-doc/Serialize.cpp
@@ -361,7 +361,7 @@
 I->USR = Func.Namespace[0].USR;
   else
 I->USR = SymbolID();
-  I->ChildFunctions.push_back(std::move(Func));
+  I->ChildFunctions.emplace_back(std::move(Func));
   return std::unique_ptr{std::move(I)};
 }
 
@@ -382,7 +382,7 @@
   // Wrap in enclosing scope
   auto I = llvm::make_unique();
   I->USR = ParentUSR;
-  I->ChildFunctions.push_back(std::move(Func));
+  I->ChildFunctions.emplace_back(std::move(Func));
   return std::unique_ptr{std::move(I)};
 }
 
@@ -402,13 +402,13 @@
 case InfoType::IT_namespace: {
   auto I = llvm::make_unique();
   I->USR = Enum.Namespace[0].USR;
-  I->ChildEnums.push_back(std::move(Enum));
+  I->ChildEnums.emplace_back(std::move(Enum));
   return std::unique_ptr{std::move(I)};
 }
 case InfoType::IT_record: {
   auto I = llvm::make_unique();
   I->USR = Enum.Namespace[0].USR;
-  I->ChildEnums.push_back(std::move(Enum));
+  I->ChildEnums.emplace_back(std::move(Enum));
   return std::unique_ptr{std::move(I)};
 }
 default:
@@ -419,7 +419,7 @@
   // Put in global namespace
   auto I = llvm::make_unique();
   I->USR = SymbolID();
-  I->ChildEnums.push_back(std::move(Enum));
+  I->ChildEnums.emplace_back(std::move(Enum));
   return std::unique_ptr{std::move(I)};
 }
 
Index: clang-tools-extra/clang-doc/Representation.h
===
--- clang-tools-extra/clang-doc/Representation.h
+++ clang-tools-extra/clang-doc/Representation.h
@@ -162,6 +162,8 @@
   Info(const Info &Other) = delete;
   Info(Info &&Other) = default;
 
+  virtual ~Info() = default;
+
   SymbolID USR =
   SymbolID(); // Unique identifier for the decl described by this Info.
   const InfoType IT = InfoType::IT_default; // InfoType of this particular 
Info.


Index: clang-tools-extra/clang-doc/Serialize.cpp
===
--- clang-tools-extra/clang-doc/Serialize.cpp
+++ clang-tools-extra/clang-doc/Serialize.cpp
@@ -361,7 +361,7 @@
 I->USR = Func.Namespace[0].USR;
   else
 I->USR = SymbolID();
-  I->ChildFunctions.push_back(std::move(Func));
+  I->ChildFunctions.emplace_back(std::move(Func));
   return std::unique_ptr{std::move(I)};
 }
 
@@ -382,7 +382,7 @@
   // Wrap in enclosing scope
   auto I = llvm::make_unique();
   I->USR = ParentUSR;
-  I->ChildFunctions.push_back(std::move(Func));
+  I->ChildFunctions.emplace_back(std::move(Func));
   return std::unique_ptr{std::move(I)};
 }
 
@@ -402,13 +402,13 @@
 case InfoType::IT_namespace: {
   auto I = llvm::make_unique();
   I->USR = Enum.Namespace[0].USR;
-  I->ChildEnums.push_back(std::move(Enum));
+  I->ChildEnums.emplace_back(std::move(Enum));
   return std::unique_ptr{std::move(I)};
 }
 case InfoType::IT_record: {
   auto I = llvm::make_unique();
   I->USR = Enum.Namespace[0].USR;
-  I->ChildEnums.push_back(std::move(Enum));
+  I->ChildEnums.emplace_back(std::move(Enum));
   return std::unique_ptr{std::move(I)};
 }
 default:
@@ -419,7 +419,7 @@
   // Put in global namespace
   auto I = llvm::make_unique();
   I->USR = SymbolID();
-  I->ChildEnums.push_back(std::move(Enum));
+  I->ChildEnums.emplace_back(std::move(Enum));
   return std::unique_ptr{std::move(I)};
 }
 
Index: clang-tools-extra/clang-doc/Representation.h
===
--- clang-tools-extra/clang-doc/Representation.h
+++ clang-tools-extra/clang-doc/Representation.h
@@ -162,6 +162,8 @@
   Info(const Info &Other) = delete;
   Info(Info &&Other) = default;
 
+  virtual ~Info() = default;
+
   SymbolID USR =
   SymbolID(); // Unique identifier for the decl described by this Info.
   const InfoType IT = InfoType::IT_default; // InfoType of this particular Info.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43778: [clang-tidy] Adding RestrictIncludes check to Fuchsia module

2018-05-08 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 145788.
juliehockett marked 10 inline comments as done.
juliehockett added a comment.

Made the check for system headers more comprehensive & fixed newline issues


https://reviews.llvm.org/D43778

Files:
  clang-tidy/fuchsia/CMakeLists.txt
  clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp
  clang-tidy/fuchsia/RestrictSystemIncludesCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/fuchsia-restrict-system-includes.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/a.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/j.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/r.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/s.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/t.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/transitive.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/transitive2.h
  test/clang-tidy/fuchsia-restrict-system-includes-headers.cpp
  test/clang-tidy/fuchsia-restrict-system-includes.cpp

Index: test/clang-tidy/fuchsia-restrict-system-includes.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-restrict-system-includes.cpp
@@ -0,0 +1,25 @@
+// RUN: %check_clang_tidy %s fuchsia-restrict-system-includes %t \
+// RUN:		-- -config="{CheckOptions: [{key: fuchsia-restrict-system-includes.Includes, value: 's.h'}]}" \
+// RUN:   -- -std=c++11 -I %S/Inputs/fuchsia-restrict-system-includes -isystem %S/Inputs/fuchsia-restrict-system-includes/system
+
+#include "a.h"
+
+#include 
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include t.h not allowed
+// CHECK-FIXES-NOT: #include 
+
+#include "s.h"
+#include "t.h"
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include t.h not allowed
+// CHECK-FIXES-NOT: #include "t.h"
+
+#define foo 
+
+#include foo
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include j.h not allowed
+// CHECK-FIXES-NOT: #include foo
+
+#/* comment */ include /* comment */ foo
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include j.h not allowed
+// CHECK-FIXES-NOT: # /* comment */ include /* comment */ foo
Index: test/clang-tidy/fuchsia-restrict-system-includes-headers.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-restrict-system-includes-headers.cpp
@@ -0,0 +1,20 @@
+// RUN: cp -r %S/Inputs/fuchsia-restrict-system-includes %T/Inputs
+// RUN: %check_clang_tidy %s fuchsia-restrict-system-includes %t \
+// RUN:		-- -config="{CheckOptions: [{key: fuchsia-restrict-system-includes.Includes, value: 'transitive.h;s.h'}]}" \
+// RUN:   -system-headers -header-filter=.* \
+// RUN:   -- -std=c++11 -I %T/Inputs/fuchsia-restrict-system-includes -isystem %T/Inputs/fuchsia-restrict-system-includes/system
+// RUN: FileCheck -input-file=%T/Inputs/transitive2.h %s -check-prefix=CHECK-HEADER-FIXES
+
+// transitive.h includes  and 
+#include 
+// CHECK-MESSAGES: :1:1: warning: system include r.h not allowed, transitively included from {{(.*\/)*}}Inputs/fuchsia-restrict-system-includes/system/transitive.h
+// CHECK-MESSAGES: :2:1: warning: system include t.h not allowed, transitively included from {{(.*\/)*}}Inputs/fuchsia-restrict-system-includes/system/transitive.h
+
+// transitive.h includes  and 
+#include "transitive2.h"
+// CHECK-MESSAGES: :2:1: warning: system include t.h not allowed, transitively included from {{(.*\/)*}}Inputs/fuchsia-restrict-system-includes/transitive2.h
+// CHECK-HEADER-FIXES-NOT: #include 
+
+int main() {
+  // f() is declared in r.h
+}
Index: test/clang-tidy/Inputs/fuchsia-restrict-system-includes/transitive2.h
===
--- /dev/null
+++ test/clang-tidy/Inputs/fuchsia-restrict-system-includes/transitive2.h
@@ -0,0 +1,2 @@
+#include 
+#include 
Index: test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/transitive.h
===
--- /dev/null
+++ test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/transitive.h
@@ -0,0 +1,3 @@
+#include 
+#include 
+#include 
Index: test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/r.h
===
--- /dev/null
+++ test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/r.h
@@ -0,0 +1 @@
+void f() {}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -95,6 +95,7 @@
fuchsia-default-arguments
fuchsia-multiple-inheritance
fuchsia-overloaded-operator
+   fuchsia-restrict-system-includes
fuchsia-statically-constructed-objects
fuchsia-trailing-return
fuchsia-virtual-inheritance
Index: docs/cla

[PATCH] D46614: [clang] Adding CharacteristicKind to PPCallbacks::InclusionDirective

2018-05-08 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett created this revision.
juliehockett added a reviewer: aaron.ballman.
juliehockett added a project: clang.
Herald added subscribers: kbarton, nemanjai.

Adding a SrcMgr::CharacteristicKind parameter to the InclusionDirective in 
PPCallbacks, and updating calls to that function. This will be useful in 
https://reviews.llvm.org/D43778 to determine which includes are system headers.


https://reviews.llvm.org/D46614

Files:
  include/clang/Lex/PPCallbacks.h
  include/clang/Lex/PreprocessingRecord.h
  lib/CodeGen/MacroPPCallbacks.cpp
  lib/CodeGen/MacroPPCallbacks.h
  lib/Frontend/DependencyFile.cpp
  lib/Frontend/DependencyGraph.cpp
  lib/Frontend/ModuleDependencyCollector.cpp
  lib/Frontend/PrintPreprocessedOutput.cpp
  lib/Frontend/Rewrite/InclusionRewriter.cpp
  lib/Lex/PPDirectives.cpp
  lib/Lex/PreprocessingRecord.cpp
  tools/libclang/Indexing.cpp
  unittests/Lex/PPCallbacksTest.cpp

Index: unittests/Lex/PPCallbacksTest.cpp
===
--- unittests/Lex/PPCallbacksTest.cpp
+++ unittests/Lex/PPCallbacksTest.cpp
@@ -39,16 +39,18 @@
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported) override {
-  this->HashLoc = HashLoc;
-  this->IncludeTok = IncludeTok;
-  this->FileName = FileName.str();
-  this->IsAngled = IsAngled;
-  this->FilenameRange = FilenameRange;
-  this->File = File;
-  this->SearchPath = SearchPath.str();
-  this->RelativePath = RelativePath.str();
-  this->Imported = Imported;
+  const Module *Imported,
+  SrcMgr::CharacteristicKind FileType) override {
+this->HashLoc = HashLoc;
+this->IncludeTok = IncludeTok;
+this->FileName = FileName.str();
+this->IsAngled = IsAngled;
+this->FilenameRange = FilenameRange;
+this->File = File;
+this->SearchPath = SearchPath.str();
+this->RelativePath = RelativePath.str();
+this->Imported = Imported;
+this->FileType = FileType;
   }
 
   SourceLocation HashLoc;
@@ -60,6 +62,7 @@
   SmallString<16> SearchPath;
   SmallString<16> RelativePath;
   const Module* Imported;
+  SrcMgr::CharacteristicKind FileType;
 };
 
 // Stub to collect data from PragmaOpenCLExtension callbacks.
Index: tools/libclang/Indexing.cpp
===
--- tools/libclang/Indexing.cpp
+++ tools/libclang/Indexing.cpp
@@ -249,7 +249,8 @@
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported) override {
+  const Module *Imported,
+  SrcMgr::CharacteristicKind FileType) override {
 bool isImport = (IncludeTok.is(tok::identifier) &&
 IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import);
 DataConsumer.ppIncludedFile(HashLoc, FileName, File, isImport, IsAngled,
Index: lib/Lex/PreprocessingRecord.cpp
===
--- lib/Lex/PreprocessingRecord.cpp
+++ lib/Lex/PreprocessingRecord.cpp
@@ -471,7 +471,8 @@
 const FileEntry *File,
 StringRef SearchPath,
 StringRef RelativePath,
-const Module *Imported) {
+const Module *Imported, 
+SrcMgr::CharacteristicKind FileType) {
   InclusionDirective::InclusionKind Kind = InclusionDirective::Include;
   
   switch (IncludeTok.getIdentifierInfo()->getPPKeywordID()) {
Index: lib/Lex/PPDirectives.cpp
===
--- lib/Lex/PPDirectives.cpp
+++ lib/Lex/PPDirectives.cpp
@@ -1968,7 +1968,7 @@
 HashLoc, IncludeTok,
 LangOpts.MSVCCompat ? NormalizedPath.c_str() : Filename, isAngled,
 FilenameRange, File, SearchPath, RelativePath,
-ShouldEnter ? nullptr : SuggestedModule.getModule());
+ShouldEnter ? nullptr : SuggestedModule.getModule(), FileCharacter);
 if (SkipHeader && !SuggestedModule.getModule())
   Callbacks->FileSkipped(*File, FilenameTok, FileCharacter);
   }
Index: lib/Frontend/Rewrite/InclusionRewriter.cpp
===
--- lib/Frontend/Rewrite/InclusionRewriter.cpp
+++ lib/Frontend/Rewrite/InclusionRewriter.cpp
@@ -77,7 +77,8 @@
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported) override;
+  const Module *Imported,
+  SrcMgr

[PATCH] D46615: [tools] Updating PPCallbacks::InclusionDirective calls

2018-05-08 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett created this revision.
juliehockett added a reviewer: aaron.ballman.
juliehockett added a project: clang-tools-extra.
Herald added subscribers: jkorous, kbarton, ioeric, nemanjai.

[[ https://reviews.llvm.org/D46614 | [https://reviews.llvm.org/D46614]  ]] adds 
SrcMgr::CharacteristicKind to the InclusionDirective callback, this patch 
updates instances of it in clang-tools-extra.


https://reviews.llvm.org/D46615

Files:
  clang-move/ClangMove.cpp
  clang-tidy/llvm/IncludeOrderCheck.cpp
  clang-tidy/modernize/DeprecatedHeadersCheck.cpp
  clang-tidy/utils/IncludeInserter.cpp
  clangd/ClangdUnit.cpp
  clangd/Headers.cpp
  modularize/CoverageChecker.cpp
  modularize/PreprocessorTracker.cpp
  pp-trace/PPCallbacksTracker.cpp
  pp-trace/PPCallbacksTracker.h

Index: pp-trace/PPCallbacksTracker.h
===
--- pp-trace/PPCallbacksTracker.h
+++ pp-trace/PPCallbacksTracker.h
@@ -102,7 +102,8 @@
   const clang::FileEntry *File,
   llvm::StringRef SearchPath,
   llvm::StringRef RelativePath,
-  const clang::Module *Imported) override;
+  const clang::Module *Imported,
+  SrcMgr::CharacteristicKind FileType) override;
   void moduleImport(clang::SourceLocation ImportLoc, clang::ModuleIdPath Path,
 const clang::Module *Imported) override;
   void EndOfMainFile() override;
Index: pp-trace/PPCallbacksTracker.cpp
===
--- pp-trace/PPCallbacksTracker.cpp
+++ pp-trace/PPCallbacksTracker.cpp
@@ -139,7 +139,7 @@
 llvm::StringRef FileName, bool IsAngled,
 clang::CharSourceRange FilenameRange, const clang::FileEntry *File,
 llvm::StringRef SearchPath, llvm::StringRef RelativePath,
-const clang::Module *Imported) {
+const clang::Module *Imported, SrcMgr::CharacteristicKind FileType) {
   beginCallback("InclusionDirective");
   appendArgument("IncludeTok", IncludeTok);
   appendFilePathArgument("FileName", FileName);
@@ -149,6 +149,7 @@
   appendFilePathArgument("SearchPath", SearchPath);
   appendFilePathArgument("RelativePath", RelativePath);
   appendArgument("Imported", Imported);
+  appendArgument("FileType", FileType);
 }
 
 // Callback invoked whenever there was an explicit module-import
Index: modularize/PreprocessorTracker.cpp
===
--- modularize/PreprocessorTracker.cpp
+++ modularize/PreprocessorTracker.cpp
@@ -750,7 +750,8 @@
   const clang::FileEntry *File,
   llvm::StringRef SearchPath,
   llvm::StringRef RelativePath,
-  const clang::Module *Imported) override;
+  const clang::Module *Imported,
+  SrcMgr::CharacteristicKind FileType) override;
   void FileChanged(clang::SourceLocation Loc,
clang::PPCallbacks::FileChangeReason Reason,
clang::SrcMgr::CharacteristicKind FileType,
@@ -1289,7 +1290,7 @@
 llvm::StringRef FileName, bool IsAngled,
 clang::CharSourceRange FilenameRange, const clang::FileEntry *File,
 llvm::StringRef SearchPath, llvm::StringRef RelativePath,
-const clang::Module *Imported) {
+const clang::Module *Imported, SrcMgr::CharacteristicKind FileType) {
   int DirectiveLine, DirectiveColumn;
   std::string HeaderPath = getSourceLocationFile(PP, HashLoc);
   getSourceLocationLineAndColumn(PP, HashLoc, DirectiveLine, DirectiveColumn);
Index: modularize/CoverageChecker.cpp
===
--- modularize/CoverageChecker.cpp
+++ modularize/CoverageChecker.cpp
@@ -90,7 +90,8 @@
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported) override {
+  const Module *Imported,
+  SrcMgr::CharacteristicKind FileType) override {
 Checker.collectUmbrellaHeaderHeader(File->getName());
   }
 
Index: clangd/Headers.cpp
===
--- clangd/Headers.cpp
+++ clangd/Headers.cpp
@@ -34,7 +34,8 @@
   CharSourceRange /*FilenameRange*/,
   const FileEntry *File, llvm::StringRef /*SearchPath*/,
   llvm::StringRef /*RelativePath*/,
-  const Module * /*Imported*/) override {
+  const Module * /*Imported*/,
+  SrcMgr::CharacteristicKind FileType) override {
 WrittenHeaders.insert(
 (IsAngled ? "<" + FileName + ">" : "\"" + FileName + "\"").

[PATCH] D46614: [clang] Adding CharacteristicKind to PPCallbacks::InclusionDirective

2018-05-09 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 145934.
juliehockett added a comment.

Adding test


https://reviews.llvm.org/D46614

Files:
  include/clang/Lex/PPCallbacks.h
  include/clang/Lex/PreprocessingRecord.h
  lib/CodeGen/MacroPPCallbacks.cpp
  lib/CodeGen/MacroPPCallbacks.h
  lib/Frontend/DependencyFile.cpp
  lib/Frontend/DependencyGraph.cpp
  lib/Frontend/ModuleDependencyCollector.cpp
  lib/Frontend/PrintPreprocessedOutput.cpp
  lib/Frontend/Rewrite/InclusionRewriter.cpp
  lib/Lex/PPDirectives.cpp
  lib/Lex/PreprocessingRecord.cpp
  tools/libclang/Indexing.cpp
  unittests/Lex/PPCallbacksTest.cpp

Index: unittests/Lex/PPCallbacksTest.cpp
===
--- unittests/Lex/PPCallbacksTest.cpp
+++ unittests/Lex/PPCallbacksTest.cpp
@@ -39,16 +39,18 @@
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported) override {
-  this->HashLoc = HashLoc;
-  this->IncludeTok = IncludeTok;
-  this->FileName = FileName.str();
-  this->IsAngled = IsAngled;
-  this->FilenameRange = FilenameRange;
-  this->File = File;
-  this->SearchPath = SearchPath.str();
-  this->RelativePath = RelativePath.str();
-  this->Imported = Imported;
+  const Module *Imported,
+  SrcMgr::CharacteristicKind FileType) override {
+this->HashLoc = HashLoc;
+this->IncludeTok = IncludeTok;
+this->FileName = FileName.str();
+this->IsAngled = IsAngled;
+this->FilenameRange = FilenameRange;
+this->File = File;
+this->SearchPath = SearchPath.str();
+this->RelativePath = RelativePath.str();
+this->Imported = Imported;
+this->FileType = FileType;
   }
 
   SourceLocation HashLoc;
@@ -60,6 +62,7 @@
   SmallString<16> SearchPath;
   SmallString<16> RelativePath;
   const Module* Imported;
+  SrcMgr::CharacteristicKind FileType;
 };
 
 // Stub to collect data from PragmaOpenCLExtension callbacks.
@@ -136,8 +139,9 @@
 
   // Run lexer over SourceText and collect FilenameRange from
   // the InclusionDirective callback.
-  CharSourceRange InclusionDirectiveFilenameRange(const char* SourceText, 
-  const char* HeaderPath, bool SystemHeader) {
+  InclusionDirectiveCallbacks *
+  InclusionDirectiveCallback(const char *SourceText,
+  const char *HeaderPath, bool SystemHeader) {
 std::unique_ptr Buf =
 llvm::MemoryBuffer::getMemBuffer(SourceText);
 SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
@@ -168,7 +172,7 @@
 }
 
 // Callbacks have been executed at this point -- return filename range.
-return Callbacks->FilenameRange;
+return Callbacks;
   }
 
   PragmaOpenCLExtensionCallbacks::CallbackParameters 
@@ -222,12 +226,21 @@
   }
 };
 
+TEST_F(PPCallbacksTest, UserFileCharacteristics) {
+  const char *Source = "#include \"quoted.h\"\n";
+
+  SrcMgr::CharacteristicKind Kind =
+  InclusionDirectiveCallback(Source, "/quoted.h", false)->FileType;
+
+  ASSERT_EQ(SrcMgr::CharacteristicKind::C_User, Kind);
+}
+
 TEST_F(PPCallbacksTest, QuotedFilename) {
   const char* Source =
 "#include \"quoted.h\"\n";
 
   CharSourceRange Range =
-InclusionDirectiveFilenameRange(Source, "/quoted.h", false);
+InclusionDirectiveCallback(Source, "/quoted.h", false)->FilenameRange;
 
   ASSERT_EQ("\"quoted.h\"", GetSourceString(Range));
 }
@@ -237,7 +250,7 @@
 "#include \n";
 
   CharSourceRange Range =
-InclusionDirectiveFilenameRange(Source, "/angled.h", true);
+InclusionDirectiveCallback(Source, "/angled.h", true)->FilenameRange;
 
   ASSERT_EQ("", GetSourceString(Range));
 }
@@ -248,7 +261,7 @@
 "#include MACRO_QUOTED\n";
 
   CharSourceRange Range =
-InclusionDirectiveFilenameRange(Source, "/quoted.h", false);
+InclusionDirectiveCallback(Source, "/quoted.h", false)->FilenameRange;
 
   ASSERT_EQ("\"quoted.h\"", GetSourceString(Range));
 }
@@ -259,7 +272,7 @@
 "#include MACRO_ANGLED\n";
 
   CharSourceRange Range =
-InclusionDirectiveFilenameRange(Source, "/angled.h", true);
+InclusionDirectiveCallback(Source, "/angled.h", true)->FilenameRange;
 
   ASSERT_EQ("", GetSourceString(Range));
 }
@@ -270,7 +283,7 @@
 "#include MACRO_STRINGIZED(quoted.h)\n";
 
   CharSourceRange Range =
-InclusionDirectiveFilenameRange(Source, "/quoted.h", false);
+InclusionDirectiveCallback(Source, "/quoted.h", false)->FilenameRange;
 
   ASSERT_EQ("\"quoted.h\"", GetSourceString(Range));
 }
@@ -282,7 +295,7 @@
 "#include MACRO_CONCAT(MACRO, ANGLED)\n";
 
   CharSourceRange Range =
-InclusionDirectiveFilenameRange(Source, "/angled.h", false);
+InclusionDirectiveCallback(Source, "/angled.h", false)->FilenameRange;
 
   ASSERT_EQ("", GetSourceString(Range));
 }
@@ -292

[PATCH] D46614: [clang] Adding CharacteristicKind to PPCallbacks::InclusionDirective

2018-05-09 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 145941.
juliehockett marked 3 inline comments as done.
juliehockett added a comment.

Fixing formatting and tests.


https://reviews.llvm.org/D46614

Files:
  include/clang/Lex/PPCallbacks.h
  include/clang/Lex/PreprocessingRecord.h
  lib/CodeGen/MacroPPCallbacks.cpp
  lib/CodeGen/MacroPPCallbacks.h
  lib/Frontend/DependencyFile.cpp
  lib/Frontend/DependencyGraph.cpp
  lib/Frontend/ModuleDependencyCollector.cpp
  lib/Frontend/PrintPreprocessedOutput.cpp
  lib/Frontend/Rewrite/InclusionRewriter.cpp
  lib/Lex/PPDirectives.cpp
  lib/Lex/PreprocessingRecord.cpp
  tools/libclang/Indexing.cpp
  unittests/Lex/PPCallbacksTest.cpp

Index: unittests/Lex/PPCallbacksTest.cpp
===
--- unittests/Lex/PPCallbacksTest.cpp
+++ unittests/Lex/PPCallbacksTest.cpp
@@ -39,16 +39,18 @@
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported) override {
-  this->HashLoc = HashLoc;
-  this->IncludeTok = IncludeTok;
-  this->FileName = FileName.str();
-  this->IsAngled = IsAngled;
-  this->FilenameRange = FilenameRange;
-  this->File = File;
-  this->SearchPath = SearchPath.str();
-  this->RelativePath = RelativePath.str();
-  this->Imported = Imported;
+  const Module *Imported,
+  SrcMgr::CharacteristicKind FileType) override {
+this->HashLoc = HashLoc;
+this->IncludeTok = IncludeTok;
+this->FileName = FileName.str();
+this->IsAngled = IsAngled;
+this->FilenameRange = FilenameRange;
+this->File = File;
+this->SearchPath = SearchPath.str();
+this->RelativePath = RelativePath.str();
+this->Imported = Imported;
+this->FileType = FileType;
   }
 
   SourceLocation HashLoc;
@@ -60,6 +62,7 @@
   SmallString<16> SearchPath;
   SmallString<16> RelativePath;
   const Module* Imported;
+  SrcMgr::CharacteristicKind FileType;
 };
 
 // Stub to collect data from PragmaOpenCLExtension callbacks.
@@ -138,6 +141,13 @@
   // the InclusionDirective callback.
   CharSourceRange InclusionDirectiveFilenameRange(const char* SourceText, 
   const char* HeaderPath, bool SystemHeader) {
+return InclusionDirectiveCallback(SourceText, HeaderPath, SystemHeader)
+->FilenameRange;
+  }
+
+  InclusionDirectiveCallbacks *
+  InclusionDirectiveCallback(const char *SourceText, const char *HeaderPath,
+ bool SystemHeader) {
 std::unique_ptr Buf =
 llvm::MemoryBuffer::getMemBuffer(SourceText);
 SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
@@ -168,7 +178,7 @@
 }
 
 // Callbacks have been executed at this point -- return filename range.
-return Callbacks->FilenameRange;
+return Callbacks;
   }
 
   PragmaOpenCLExtensionCallbacks::CallbackParameters 
@@ -222,6 +232,15 @@
   }
 };
 
+TEST_F(PPCallbacksTest, UserFileCharacteristics) {
+  const char *Source = "#include \"quoted.h\"\n";
+
+  SrcMgr::CharacteristicKind Kind =
+  InclusionDirectiveCallback(Source, "/quoted.h", false)->FileType;
+
+  ASSERT_EQ(SrcMgr::CharacteristicKind::C_User, Kind);
+}
+
 TEST_F(PPCallbacksTest, QuotedFilename) {
   const char* Source =
 "#include \"quoted.h\"\n";
Index: tools/libclang/Indexing.cpp
===
--- tools/libclang/Indexing.cpp
+++ tools/libclang/Indexing.cpp
@@ -249,7 +249,8 @@
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported) override {
+  const Module *Imported,
+  SrcMgr::CharacteristicKind FileType) override {
 bool isImport = (IncludeTok.is(tok::identifier) &&
 IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import);
 DataConsumer.ppIncludedFile(HashLoc, FileName, File, isImport, IsAngled,
Index: lib/Lex/PreprocessingRecord.cpp
===
--- lib/Lex/PreprocessingRecord.cpp
+++ lib/Lex/PreprocessingRecord.cpp
@@ -471,7 +471,8 @@
 const FileEntry *File,
 StringRef SearchPath,
 StringRef RelativePath,
-const Module *Imported) {
+const Module *Imported, 
+SrcMgr::CharacteristicKind FileType) {
   InclusionDirective::InclusionKind Kind = InclusionDirective::Include;
   
   switch (IncludeTok.getIdentifierInfo()->getPPKeywordID()) {
Index: lib/Lex/PPDirectives.cpp
===
--- lib/Lex/PPDirectives.cpp
+++ lib/Lex/PPDirectives.cpp
@@ -1968,7 +1968,7 @@
 

[PATCH] D43341: [clang-doc] Implement reducer portion of the frontend framework

2018-05-09 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added a comment.

This will break things in clang-tools-extra without 
https://reviews.llvm.org/D46615, so I'm going to hold off landing this until 
that goes through


https://reviews.llvm.org/D43341



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


[PATCH] D43341: [clang-doc] Implement reducer portion of the frontend framework

2018-05-09 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added a comment.

In https://reviews.llvm.org/D43341#1093117, @juliehockett wrote:

> This will break things in clang-tools-extra without 
> https://reviews.llvm.org/D46615, so I'm going to hold off landing this until 
> that goes through


Oops wrong patch disregard


https://reviews.llvm.org/D43341



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


[PATCH] D46614: [clang] Adding CharacteristicKind to PPCallbacks::InclusionDirective

2018-05-09 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added a comment.

This will break things in clang-tools-extra without 
https://reviews.llvm.org/D46615, so I'm going to hold off landing this until 
that goes through


https://reviews.llvm.org/D46614



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


[PATCH] D46614: [clang] Adding CharacteristicKind to PPCallbacks::InclusionDirective

2018-05-09 Thread Julie Hockett via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL331904: [clang] Adding CharacteristicKind to 
PPCallbacks::InclusionDirective (authored by juliehockett, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46614?vs=145941&id=145971#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46614

Files:
  cfe/trunk/include/clang/Lex/PPCallbacks.h
  cfe/trunk/include/clang/Lex/PreprocessingRecord.h
  cfe/trunk/lib/CodeGen/MacroPPCallbacks.cpp
  cfe/trunk/lib/CodeGen/MacroPPCallbacks.h
  cfe/trunk/lib/Frontend/DependencyFile.cpp
  cfe/trunk/lib/Frontend/DependencyGraph.cpp
  cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp
  cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
  cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp
  cfe/trunk/lib/Lex/PPDirectives.cpp
  cfe/trunk/lib/Lex/PreprocessingRecord.cpp
  cfe/trunk/tools/libclang/Indexing.cpp
  cfe/trunk/unittests/Lex/PPCallbacksTest.cpp

Index: cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp
===
--- cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp
+++ cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp
@@ -50,7 +50,8 @@
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported) override {
+  const Module *Imported,
+  SrcMgr::CharacteristicKind FileType) override {
 if (!File)
   return;
 Collector.addFile(File->getName());
Index: cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp
===
--- cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp
+++ cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp
@@ -77,7 +77,8 @@
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported) override;
+  const Module *Imported,
+  SrcMgr::CharacteristicKind FileType) override;
   void WriteLineInfo(StringRef Filename, int Line,
  SrcMgr::CharacteristicKind FileType,
  StringRef Extra = StringRef());
@@ -192,7 +193,8 @@
const FileEntry * /*File*/,
StringRef /*SearchPath*/,
StringRef /*RelativePath*/,
-   const Module *Imported) {
+   const Module *Imported,
+   SrcMgr::CharacteristicKind FileType){
   if (Imported) {
 auto P = ModuleIncludes.insert(
 std::make_pair(HashLoc.getRawEncoding(), Imported));
Index: cfe/trunk/lib/Frontend/DependencyGraph.cpp
===
--- cfe/trunk/lib/Frontend/DependencyGraph.cpp
+++ cfe/trunk/lib/Frontend/DependencyGraph.cpp
@@ -50,7 +50,8 @@
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported) override;
+  const Module *Imported,
+  SrcMgr::CharacteristicKind FileType) override;
 
   void EndOfMainFile() override {
 OutputGraphFile();
@@ -65,15 +66,17 @@
SysRoot));
 }
 
-void DependencyGraphCallback::InclusionDirective(SourceLocation HashLoc,
- const Token &IncludeTok,
- StringRef FileName,
- bool IsAngled,
- CharSourceRange FilenameRange,
- const FileEntry *File,
- StringRef SearchPath,
- StringRef RelativePath,
- const Module *Imported) {
+void DependencyGraphCallback::InclusionDirective(
+SourceLocation HashLoc,
+const Token &IncludeTok,
+StringRef FileName,
+bool IsAngled,
+CharSourceRange FilenameRange,
+const FileEntry *File,
+StringRef SearchPath,
+StringRef RelativePath,
+const Module *Imported, 
+SrcMgr::CharacteristicKind FileType) {
   if (!File)
 return;
   
Index: cfe/trunk/lib/Fro

[PATCH] D46615: [tools] Updating PPCallbacks::InclusionDirective calls

2018-05-09 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 rL331905: [tools] Updating PPCallbacks::InclusionDirective 
calls (authored by juliehockett, committed by ).
Herald added subscribers: llvm-commits, ilya-biryukov, klimek.

Changed prior to commit:
  https://reviews.llvm.org/D46615?vs=145823&id=145972#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46615

Files:
  clang-tools-extra/trunk/clang-move/ClangMove.cpp
  clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp
  clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
  clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.cpp
  clang-tools-extra/trunk/clangd/ClangdUnit.cpp
  clang-tools-extra/trunk/clangd/Headers.cpp
  clang-tools-extra/trunk/modularize/CoverageChecker.cpp
  clang-tools-extra/trunk/modularize/PreprocessorTracker.cpp
  clang-tools-extra/trunk/pp-trace/PPCallbacksTracker.cpp
  clang-tools-extra/trunk/pp-trace/PPCallbacksTracker.h

Index: clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/llvm/IncludeOrderCheck.cpp
@@ -28,7 +28,8 @@
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported) override;
+  const Module *Imported,
+  SrcMgr::CharacteristicKind FileType) override;
   void EndOfMainFile() override;
 
 private:
@@ -76,7 +77,8 @@
 void IncludeOrderPPCallbacks::InclusionDirective(
 SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
 bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File,
-StringRef SearchPath, StringRef RelativePath, const Module *Imported) {
+StringRef SearchPath, StringRef RelativePath, const Module *Imported,
+SrcMgr::CharacteristicKind FileType) {
   // We recognize the first include as a special main module header and want
   // to leave it in the top position.
   IncludeDirective ID = {HashLoc, FilenameRange, FileName, IsAngled, false};
Index: clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.cpp
===
--- clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.cpp
+++ clang-tools-extra/trunk/clang-tidy/utils/IncludeInserter.cpp
@@ -25,7 +25,8 @@
   bool IsAngled, CharSourceRange FileNameRange,
   const FileEntry * /*IncludedFile*/,
   StringRef /*SearchPath*/, StringRef /*RelativePath*/,
-  const Module * /*ImportedModule*/) override {
+  const Module * /*ImportedModule*/,
+  SrcMgr::CharacteristicKind /*FileType*/) override {
 Inserter->AddInclude(FileNameRef, IsAngled, HashLocation,
  IncludeToken.getEndLoc());
   }
Index: clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
@@ -30,7 +30,8 @@
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported) override;
+  const Module *Imported,
+  SrcMgr::CharacteristicKind FileType) override;
 
 private:
   ClangTidyCheck &Check;
@@ -94,7 +95,8 @@
 void IncludeModernizePPCallbacks::InclusionDirective(
 SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
 bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File,
-StringRef SearchPath, StringRef RelativePath, const Module *Imported) {
+StringRef SearchPath, StringRef RelativePath, const Module *Imported,
+SrcMgr::CharacteristicKind FileType) {
   // FIXME: Take care of library symbols from the global namespace.
   //
   // Reasonable options for the check:
Index: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp
@@ -93,7 +93,8 @@
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module 

[PATCH] D43778: [clang-tidy] Adding RestrictIncludes check to Fuchsia module

2018-05-09 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added inline comments.



Comment at: docs/ReleaseNotes.rst:116
+
+  Checks for allowed system includes and suggests removal of any others. If no
+  includes are specified, the check will exit without issuing any warnings.

Eugene.Zelenko wrote:
> Is it necessary to highlight that warnings will not be emitted in case of 
> disallowed headers are not found? Same in documentation.
I'm not sure I understand what you're saying...are you saying if the 
documentation should not include anything about  what happens in the case of no 
headers?



Comment at: docs/clang-tidy/checks/fuchsia-restrict-system-includes.rst:32
+   A string containing a semi-colon separated list of allowed include 
filenames.
+   The default is an empty string, which allows all includes.

aaron.ballman wrote:
> This default seems a bit odd to me, but perhaps it's fine. What's novel is 
> that the check is a no-op by default, so how do Fuchsia developers get the 
> correct list? Or is there no canonical list and developers are expected to 
> populate their own manually?
The idea is that it's a case-by-case basis -- this may change at some point in 
the future if we decide there's a standard whitelist of system includes across 
the board, but at the moment the thought is to allow everything in some places, 
and use this check to limit them in others. It'll need to be populated on a 
case-by-case basis, since different directories will have different 
requirements.


https://reviews.llvm.org/D43778



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


[PATCH] D43778: [clang-tidy] Adding RestrictIncludes check to Fuchsia module

2018-05-09 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 145978.
juliehockett marked 3 inline comments as done.
juliehockett added a comment.

Updating the inclusiondirective to filter out non-system files


https://reviews.llvm.org/D43778

Files:
  clang-tidy/fuchsia/CMakeLists.txt
  clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp
  clang-tidy/fuchsia/RestrictSystemIncludesCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/fuchsia-restrict-system-includes.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/a.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/j.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/r.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/s.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/t.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/transitive.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/transitive2.h
  test/clang-tidy/fuchsia-restrict-system-includes-headers.cpp
  test/clang-tidy/fuchsia-restrict-system-includes.cpp

Index: test/clang-tidy/fuchsia-restrict-system-includes.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-restrict-system-includes.cpp
@@ -0,0 +1,25 @@
+// RUN: %check_clang_tidy %s fuchsia-restrict-system-includes %t \
+// RUN:		-- -config="{CheckOptions: [{key: fuchsia-restrict-system-includes.Includes, value: 's.h'}]}" \
+// RUN:   -- -std=c++11 -I %S/Inputs/fuchsia-restrict-system-includes -isystem %S/Inputs/fuchsia-restrict-system-includes/system
+
+#include "a.h"
+
+#include 
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include t.h not allowed
+// CHECK-FIXES-NOT: #include 
+
+#include "s.h"
+#include "t.h"
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include t.h not allowed
+// CHECK-FIXES-NOT: #include "t.h"
+
+#define foo 
+
+#include foo
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include j.h not allowed
+// CHECK-FIXES-NOT: #include foo
+
+#/* comment */ include /* comment */ foo
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include j.h not allowed
+// CHECK-FIXES-NOT: # /* comment */ include /* comment */ foo
Index: test/clang-tidy/fuchsia-restrict-system-includes-headers.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-restrict-system-includes-headers.cpp
@@ -0,0 +1,20 @@
+// RUN: cp -r %S/Inputs/fuchsia-restrict-system-includes %T/Inputs
+// RUN: %check_clang_tidy %s fuchsia-restrict-system-includes %t \
+// RUN:		-- -config="{CheckOptions: [{key: fuchsia-restrict-system-includes.Includes, value: 'transitive.h;s.h'}]}" \
+// RUN:   -system-headers -header-filter=.* \
+// RUN:   -- -std=c++11 -I %T/Inputs/fuchsia-restrict-system-includes -isystem %T/Inputs/fuchsia-restrict-system-includes/system
+// RUN: FileCheck -input-file=%T/Inputs/transitive2.h %s -check-prefix=CHECK-HEADER-FIXES
+
+// transitive.h includes  and 
+#include 
+// CHECK-MESSAGES: :1:1: warning: system include r.h not allowed, transitively included from {{(.*\/)*}}Inputs/fuchsia-restrict-system-includes/system/transitive.h
+// CHECK-MESSAGES: :2:1: warning: system include t.h not allowed, transitively included from {{(.*\/)*}}Inputs/fuchsia-restrict-system-includes/system/transitive.h
+
+// transitive.h includes  and 
+#include "transitive2.h"
+// CHECK-MESSAGES: :2:1: warning: system include t.h not allowed, transitively included from {{(.*\/)*}}Inputs/fuchsia-restrict-system-includes/transitive2.h
+// CHECK-HEADER-FIXES-NOT: #include 
+
+int main() {
+  // f() is declared in r.h
+}
Index: test/clang-tidy/Inputs/fuchsia-restrict-system-includes/transitive2.h
===
--- /dev/null
+++ test/clang-tidy/Inputs/fuchsia-restrict-system-includes/transitive2.h
@@ -0,0 +1,2 @@
+#include 
+#include 
Index: test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/transitive.h
===
--- /dev/null
+++ test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/transitive.h
@@ -0,0 +1,3 @@
+#include 
+#include 
+#include 
Index: test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/r.h
===
--- /dev/null
+++ test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/r.h
@@ -0,0 +1 @@
+void f() {}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -95,6 +95,7 @@
fuchsia-default-arguments
fuchsia-multiple-inheritance
fuchsia-overloaded-operator
+   fuchsia-restrict-system-includes
fuchsia-statically-constructed-objects
fuchsia-trailing-return
fuchsia-virtual-inheritance
Index: docs/clang-tidy/checks

[PATCH] D43778: [clang-tidy] Adding RestrictIncludes check to Fuchsia module

2018-05-09 Thread Julie Hockett via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE331930: [clang-tidy] Adding RestrictSystemIncludes check 
to Fuchsia module (authored by juliehockett, committed by ).

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43778

Files:
  clang-tidy/fuchsia/CMakeLists.txt
  clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp
  clang-tidy/fuchsia/RestrictSystemIncludesCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/fuchsia-restrict-system-includes.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/a.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/j.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/r.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/s.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/t.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/transitive.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/transitive2.h
  test/clang-tidy/fuchsia-restrict-system-includes-headers.cpp
  test/clang-tidy/fuchsia-restrict-system-includes.cpp

Index: clang-tidy/fuchsia/RestrictSystemIncludesCheck.h
===
--- clang-tidy/fuchsia/RestrictSystemIncludesCheck.h
+++ clang-tidy/fuchsia/RestrictSystemIncludesCheck.h
@@ -0,0 +1,46 @@
+//===--- RestrictSystemIncludesCheck.h - clang-tidy-- *- C++-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_RESTRICTINCLUDESSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_RESTRICTINCLUDESSCHECK_H
+
+#include "../ClangTidy.h"
+#include "../utils/OptionsUtils.h"
+
+namespace clang {
+namespace tidy {
+namespace fuchsia {
+
+/// Checks for allowed includes and suggests removal of any others. If no
+/// includes are specified, the check will exit without issuing any warnings.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia-restrict-system-includes.html
+class RestrictSystemIncludesCheck : public ClangTidyCheck {
+public:
+  RestrictSystemIncludesCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context),
+AllowedIncludes(
+utils::options::parseStringList(Options.get("Includes", ""))) {}
+
+  void registerPPCallbacks(CompilerInstance &Compiler) override;
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
+  const std::vector &getAllowedIncludes() const {
+return AllowedIncludes;
+  }
+
+private:
+  std::vector AllowedIncludes;
+};
+
+} // namespace fuchsia
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_RESTRICTINCLUDESSCHECK_H
Index: clang-tidy/fuchsia/CMakeLists.txt
===
--- clang-tidy/fuchsia/CMakeLists.txt
+++ clang-tidy/fuchsia/CMakeLists.txt
@@ -5,6 +5,7 @@
   FuchsiaTidyModule.cpp
   MultipleInheritanceCheck.cpp
   OverloadedOperatorCheck.cpp
+  RestrictSystemIncludesCheck.cpp
   StaticallyConstructedObjectsCheck.cpp
   TrailingReturnCheck.cpp
   VirtualInheritanceCheck.cpp
Index: clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp
===
--- clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp
+++ clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp
@@ -0,0 +1,126 @@
+//===--- RestrictSystemIncludesCheck.cpp - clang-tidy--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "RestrictSystemIncludesCheck.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/HeaderSearch.h"
+#include "clang/Lex/PPCallbacks.h"
+#include "clang/Lex/Preprocessor.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/Path.h"
+#include 
+
+namespace clang {
+namespace tidy {
+namespace fuchsia {
+
+class RestrictedIncludesPPCallbacks : public PPCallbacks {
+public:
+  explicit RestrictedIncludesPPCallbacks(RestrictSystemIncludesCheck &Check,
+ SourceManager &SM)
+  : Check(Check), SM(SM) {}
+
+  void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
+  StringRef FileName, bool IsAngled,
+  CharSourceRange FilenameRange, con

[PATCH] D43778: [clang-tidy] Adding RestrictIncludes check to Fuchsia module

2018-05-09 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett reopened this revision.
juliehockett added a comment.

Sorry, branches got crossed. Reverted and reopened.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43778



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


[PATCH] D46614: [clang] Adding CharacteristicKind to PPCallbacks::InclusionDirective

2018-05-09 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 146032.
juliehockett added a comment.

Reverted because of memory leak in PPCallbacksTest, this fixes it.


https://reviews.llvm.org/D46614

Files:
  include/clang/Lex/PPCallbacks.h
  include/clang/Lex/PreprocessingRecord.h
  lib/CodeGen/MacroPPCallbacks.cpp
  lib/CodeGen/MacroPPCallbacks.h
  lib/Frontend/DependencyFile.cpp
  lib/Frontend/DependencyGraph.cpp
  lib/Frontend/ModuleDependencyCollector.cpp
  lib/Frontend/PrintPreprocessedOutput.cpp
  lib/Frontend/Rewrite/InclusionRewriter.cpp
  lib/Lex/PPDirectives.cpp
  lib/Lex/PreprocessingRecord.cpp
  tools/libclang/Indexing.cpp
  unittests/Lex/PPCallbacksTest.cpp

Index: unittests/Lex/PPCallbacksTest.cpp
===
--- unittests/Lex/PPCallbacksTest.cpp
+++ unittests/Lex/PPCallbacksTest.cpp
@@ -39,16 +39,18 @@
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported) override {
-  this->HashLoc = HashLoc;
-  this->IncludeTok = IncludeTok;
-  this->FileName = FileName.str();
-  this->IsAngled = IsAngled;
-  this->FilenameRange = FilenameRange;
-  this->File = File;
-  this->SearchPath = SearchPath.str();
-  this->RelativePath = RelativePath.str();
-  this->Imported = Imported;
+  const Module *Imported,
+  SrcMgr::CharacteristicKind FileType) override {
+this->HashLoc = HashLoc;
+this->IncludeTok = IncludeTok;
+this->FileName = FileName.str();
+this->IsAngled = IsAngled;
+this->FilenameRange = FilenameRange;
+this->File = File;
+this->SearchPath = SearchPath.str();
+this->RelativePath = RelativePath.str();
+this->Imported = Imported;
+this->FileType = FileType;
   }
 
   SourceLocation HashLoc;
@@ -60,6 +62,7 @@
   SmallString<16> SearchPath;
   SmallString<16> RelativePath;
   const Module* Imported;
+  SrcMgr::CharacteristicKind FileType;
 };
 
 // Stub to collect data from PragmaOpenCLExtension callbacks.
@@ -134,10 +137,34 @@
 return StringRef(B, E - B);
   }
 
+  std::unique_ptr getPreprocessor(const char *SourceText,
+const char *HeaderPath,
+bool SystemHeader) {
+std::unique_ptr Buf =
+llvm::MemoryBuffer::getMemBuffer(SourceText);
+SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
+
+TrivialModuleLoader ModLoader;
+MemoryBufferCache PCMCache;
+
+HeaderSearch HeaderInfo(std::make_shared(), SourceMgr,
+Diags, LangOpts, Target.get());
+AddFakeHeader(HeaderInfo, HeaderPath, SystemHeader);
+
+std::unique_ptr PP = llvm::make_unique(
+std::make_shared(), Diags, LangOpts, SourceMgr,
+PCMCache, HeaderInfo, ModLoader,
+/*IILookup =*/nullptr,
+/*OwnsHeaderSearch =*/false);
+PP->Initialize(*Target);
+return PP;
+  }
+
   // Run lexer over SourceText and collect FilenameRange from
   // the InclusionDirective callback.
-  CharSourceRange InclusionDirectiveFilenameRange(const char* SourceText, 
-  const char* HeaderPath, bool SystemHeader) {
+  CharSourceRange InclusionDirectiveFilenameRange(const char *SourceText,
+  const char *HeaderPath,
+  bool SystemHeader) {
 std::unique_ptr Buf =
 llvm::MemoryBuffer::getMemBuffer(SourceText);
 SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
@@ -149,26 +176,52 @@
 Diags, LangOpts, Target.get());
 AddFakeHeader(HeaderInfo, HeaderPath, SystemHeader);
 
-Preprocessor PP(std::make_shared(), Diags, LangOpts,
-SourceMgr, PCMCache, HeaderInfo, ModLoader,
-/*IILookup =*/nullptr,
-/*OwnsHeaderSearch =*/false);
-PP.Initialize(*Target);
-InclusionDirectiveCallbacks* Callbacks = new InclusionDirectiveCallbacks;
-PP.addPPCallbacks(std::unique_ptr(Callbacks));
+std::unique_ptr PP = llvm::make_unique(
+std::make_shared(), Diags, LangOpts, SourceMgr,
+PCMCache, HeaderInfo, ModLoader,
+/*IILookup =*/nullptr,
+/*OwnsHeaderSearch =*/false);
+return InclusionDirectiveCallback(PP.get())->FilenameRange;
+  }
 
+  SrcMgr::CharacteristicKind InclusionDirectiveCharacteristicKind(
+  const char *SourceText, const char *HeaderPath, bool SystemHeader) {
+std::unique_ptr Buf =
+llvm::MemoryBuffer::getMemBuffer(SourceText);
+SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
+
+TrivialModuleLoader ModLoader;
+MemoryBufferCache PCMCache;
+
+HeaderSearch HeaderInfo(std::make_shared(), SourceMgr,

[PATCH] D46614: [clang] Adding CharacteristicKind to PPCallbacks::InclusionDirective

2018-05-10 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 146158.
juliehockett marked 3 inline comments as done.
juliehockett added a comment.

Removing unused function


https://reviews.llvm.org/D46614

Files:
  include/clang/Lex/PPCallbacks.h
  include/clang/Lex/PreprocessingRecord.h
  lib/CodeGen/MacroPPCallbacks.cpp
  lib/CodeGen/MacroPPCallbacks.h
  lib/Frontend/DependencyFile.cpp
  lib/Frontend/DependencyGraph.cpp
  lib/Frontend/ModuleDependencyCollector.cpp
  lib/Frontend/PrintPreprocessedOutput.cpp
  lib/Frontend/Rewrite/InclusionRewriter.cpp
  lib/Lex/PPDirectives.cpp
  lib/Lex/PreprocessingRecord.cpp
  tools/libclang/Indexing.cpp
  unittests/Lex/PPCallbacksTest.cpp

Index: unittests/Lex/PPCallbacksTest.cpp
===
--- unittests/Lex/PPCallbacksTest.cpp
+++ unittests/Lex/PPCallbacksTest.cpp
@@ -39,16 +39,18 @@
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported) override {
-  this->HashLoc = HashLoc;
-  this->IncludeTok = IncludeTok;
-  this->FileName = FileName.str();
-  this->IsAngled = IsAngled;
-  this->FilenameRange = FilenameRange;
-  this->File = File;
-  this->SearchPath = SearchPath.str();
-  this->RelativePath = RelativePath.str();
-  this->Imported = Imported;
+  const Module *Imported,
+  SrcMgr::CharacteristicKind FileType) override {
+this->HashLoc = HashLoc;
+this->IncludeTok = IncludeTok;
+this->FileName = FileName.str();
+this->IsAngled = IsAngled;
+this->FilenameRange = FilenameRange;
+this->File = File;
+this->SearchPath = SearchPath.str();
+this->RelativePath = RelativePath.str();
+this->Imported = Imported;
+this->FileType = FileType;
   }
 
   SourceLocation HashLoc;
@@ -60,6 +62,7 @@
   SmallString<16> SearchPath;
   SmallString<16> RelativePath;
   const Module* Imported;
+  SrcMgr::CharacteristicKind FileType;
 };
 
 // Stub to collect data from PragmaOpenCLExtension callbacks.
@@ -149,26 +152,52 @@
 Diags, LangOpts, Target.get());
 AddFakeHeader(HeaderInfo, HeaderPath, SystemHeader);
 
-Preprocessor PP(std::make_shared(), Diags, LangOpts,
-SourceMgr, PCMCache, HeaderInfo, ModLoader,
-/*IILookup =*/nullptr,
-/*OwnsHeaderSearch =*/false);
-PP.Initialize(*Target);
-InclusionDirectiveCallbacks* Callbacks = new InclusionDirectiveCallbacks;
-PP.addPPCallbacks(std::unique_ptr(Callbacks));
+std::unique_ptr PP = llvm::make_unique(
+std::make_shared(), Diags, LangOpts, SourceMgr,
+PCMCache, HeaderInfo, ModLoader,
+/*IILookup =*/nullptr,
+/*OwnsHeaderSearch =*/false);
+return InclusionDirectiveCallback(PP.get())->FilenameRange;
+  }
+
+  SrcMgr::CharacteristicKind InclusionDirectiveCharacteristicKind(
+  const char *SourceText, const char *HeaderPath, bool SystemHeader) {
+std::unique_ptr Buf =
+llvm::MemoryBuffer::getMemBuffer(SourceText);
+SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
+
+TrivialModuleLoader ModLoader;
+MemoryBufferCache PCMCache;
 
+HeaderSearch HeaderInfo(std::make_shared(), SourceMgr,
+Diags, LangOpts, Target.get());
+AddFakeHeader(HeaderInfo, HeaderPath, SystemHeader);
+
+std::unique_ptr PP = llvm::make_unique(
+std::make_shared(), Diags, LangOpts, SourceMgr,
+PCMCache, HeaderInfo, ModLoader,
+/*IILookup =*/nullptr,
+/*OwnsHeaderSearch =*/false);
+return InclusionDirectiveCallback(PP.get())->FileType;
+  }
+
+  InclusionDirectiveCallbacks *InclusionDirectiveCallback(Preprocessor *PP) {
+PP->Initialize(*Target);
+InclusionDirectiveCallbacks* Callbacks = new InclusionDirectiveCallbacks;
+PP->addPPCallbacks(std::unique_ptr(Callbacks));
+
 // Lex source text.
-PP.EnterMainSourceFile();
+PP->EnterMainSourceFile();
 
 while (true) {
   Token Tok;
-  PP.Lex(Tok);
+  PP->Lex(Tok);
   if (Tok.is(tok::eof))
 break;
 }
 
 // Callbacks have been executed at this point -- return filename range.
-return Callbacks->FilenameRange;
+return Callbacks;
   }
 
   PragmaOpenCLExtensionCallbacks::CallbackParameters 
@@ -222,6 +251,15 @@
   }
 };
 
+TEST_F(PPCallbacksTest, UserFileCharacteristics) {
+  const char *Source = "#include \"quoted.h\"\n";
+
+  SrcMgr::CharacteristicKind Kind =
+  InclusionDirectiveCharacteristicKind(Source, "/quoted.h", false);
+
+  ASSERT_EQ(SrcMgr::CharacteristicKind::C_User, Kind);
+}
+
 TEST_F(PPCallbacksTest, QuotedFilename) {
   const char* Source =
 "#include \"quoted.h\"\n";
Index: tools/libclang/Indexing.cpp

[PATCH] D46614: [clang] Adding CharacteristicKind to PPCallbacks::InclusionDirective

2018-05-10 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 146175.

https://reviews.llvm.org/D46614

Files:
  include/clang/Lex/PPCallbacks.h
  include/clang/Lex/PreprocessingRecord.h
  lib/CodeGen/MacroPPCallbacks.cpp
  lib/CodeGen/MacroPPCallbacks.h
  lib/Frontend/DependencyFile.cpp
  lib/Frontend/DependencyGraph.cpp
  lib/Frontend/ModuleDependencyCollector.cpp
  lib/Frontend/PrintPreprocessedOutput.cpp
  lib/Frontend/Rewrite/InclusionRewriter.cpp
  lib/Lex/PPDirectives.cpp
  lib/Lex/PreprocessingRecord.cpp
  tools/libclang/Indexing.cpp
  unittests/Lex/PPCallbacksTest.cpp

Index: unittests/Lex/PPCallbacksTest.cpp
===
--- unittests/Lex/PPCallbacksTest.cpp
+++ unittests/Lex/PPCallbacksTest.cpp
@@ -39,16 +39,18 @@
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported) override {
-  this->HashLoc = HashLoc;
-  this->IncludeTok = IncludeTok;
-  this->FileName = FileName.str();
-  this->IsAngled = IsAngled;
-  this->FilenameRange = FilenameRange;
-  this->File = File;
-  this->SearchPath = SearchPath.str();
-  this->RelativePath = RelativePath.str();
-  this->Imported = Imported;
+  const Module *Imported,
+  SrcMgr::CharacteristicKind FileType) override {
+this->HashLoc = HashLoc;
+this->IncludeTok = IncludeTok;
+this->FileName = FileName.str();
+this->IsAngled = IsAngled;
+this->FilenameRange = FilenameRange;
+this->File = File;
+this->SearchPath = SearchPath.str();
+this->RelativePath = RelativePath.str();
+this->Imported = Imported;
+this->FileType = FileType;
   }
 
   SourceLocation HashLoc;
@@ -60,6 +62,7 @@
   SmallString<16> SearchPath;
   SmallString<16> RelativePath;
   const Module* Imported;
+  SrcMgr::CharacteristicKind FileType;
 };
 
 // Stub to collect data from PragmaOpenCLExtension callbacks.
@@ -153,6 +156,30 @@
 SourceMgr, PCMCache, HeaderInfo, ModLoader,
 /*IILookup =*/nullptr,
 /*OwnsHeaderSearch =*/false);
+return InclusionDirectiveCallback(PP)->FilenameRange;
+  }
+
+  SrcMgr::CharacteristicKind InclusionDirectiveCharacteristicKind(
+  const char *SourceText, const char *HeaderPath, bool SystemHeader) {
+std::unique_ptr Buf =
+llvm::MemoryBuffer::getMemBuffer(SourceText);
+SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
+
+TrivialModuleLoader ModLoader;
+MemoryBufferCache PCMCache;
+
+HeaderSearch HeaderInfo(std::make_shared(), SourceMgr,
+Diags, LangOpts, Target.get());
+AddFakeHeader(HeaderInfo, HeaderPath, SystemHeader);
+
+Preprocessor PP(std::make_shared(), Diags, LangOpts,
+SourceMgr, PCMCache, HeaderInfo, ModLoader,
+/*IILookup =*/nullptr,
+/*OwnsHeaderSearch =*/false);
+return InclusionDirectiveCallback(PP)->FileType;
+  }
+
+  InclusionDirectiveCallbacks *InclusionDirectiveCallback(Preprocessor &PP) {
 PP.Initialize(*Target);
 InclusionDirectiveCallbacks* Callbacks = new InclusionDirectiveCallbacks;
 PP.addPPCallbacks(std::unique_ptr(Callbacks));
@@ -168,7 +195,7 @@
 }
 
 // Callbacks have been executed at this point -- return filename range.
-return Callbacks->FilenameRange;
+return Callbacks;
   }
 
   PragmaOpenCLExtensionCallbacks::CallbackParameters 
@@ -222,6 +249,15 @@
   }
 };
 
+TEST_F(PPCallbacksTest, UserFileCharacteristics) {
+  const char *Source = "#include \"quoted.h\"\n";
+
+  SrcMgr::CharacteristicKind Kind =
+  InclusionDirectiveCharacteristicKind(Source, "/quoted.h", false);
+
+  ASSERT_EQ(SrcMgr::CharacteristicKind::C_User, Kind);
+}
+
 TEST_F(PPCallbacksTest, QuotedFilename) {
   const char* Source =
 "#include \"quoted.h\"\n";
Index: tools/libclang/Indexing.cpp
===
--- tools/libclang/Indexing.cpp
+++ tools/libclang/Indexing.cpp
@@ -249,7 +249,8 @@
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported) override {
+  const Module *Imported,
+  SrcMgr::CharacteristicKind FileType) override {
 bool isImport = (IncludeTok.is(tok::identifier) &&
 IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import);
 DataConsumer.ppIncludedFile(HashLoc, FileName, File, isImport, IsAngled,
Index: lib/Lex/PreprocessingRecord.cpp
===
--- lib/Lex

[PATCH] D46614: [clang] Adding CharacteristicKind to PPCallbacks::InclusionDirective

2018-05-10 Thread Julie Hockett via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC332021: Reland '[clang] Adding CharacteristicKind to 
PPCallbacks::InclusionDirective' (authored by juliehockett, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D46614

Files:
  include/clang/Lex/PPCallbacks.h
  include/clang/Lex/PreprocessingRecord.h
  lib/CodeGen/MacroPPCallbacks.cpp
  lib/CodeGen/MacroPPCallbacks.h
  lib/Frontend/DependencyFile.cpp
  lib/Frontend/DependencyGraph.cpp
  lib/Frontend/ModuleDependencyCollector.cpp
  lib/Frontend/PrintPreprocessedOutput.cpp
  lib/Frontend/Rewrite/InclusionRewriter.cpp
  lib/Lex/PPDirectives.cpp
  lib/Lex/PreprocessingRecord.cpp
  tools/libclang/Indexing.cpp
  unittests/Lex/PPCallbacksTest.cpp

Index: include/clang/Lex/PreprocessingRecord.h
===
--- include/clang/Lex/PreprocessingRecord.h
+++ include/clang/Lex/PreprocessingRecord.h
@@ -532,8 +532,8 @@
 StringRef FileName, bool IsAngled,
 CharSourceRange FilenameRange,
 const FileEntry *File, StringRef SearchPath,
-StringRef RelativePath,
-const Module *Imported) override;
+StringRef RelativePath, const Module *Imported,
+SrcMgr::CharacteristicKind FileType) override;
 void Ifdef(SourceLocation Loc, const Token &MacroNameTok,
const MacroDefinition &MD) override;
 void Ifndef(SourceLocation Loc, const Token &MacroNameTok,
Index: include/clang/Lex/PPCallbacks.h
===
--- include/clang/Lex/PPCallbacks.h
+++ include/clang/Lex/PPCallbacks.h
@@ -117,15 +117,20 @@
   /// \param Imported The module, whenever an inclusion directive was
   /// automatically turned into a module import or null otherwise.
   ///
+  /// \param FileType The characteristic kind, indicates whether a file or
+  /// directory holds normal user code, system code, or system code which is
+  /// implicitly 'extern "C"' in C++ mode.
+  ///
   virtual void InclusionDirective(SourceLocation HashLoc,
   const Token &IncludeTok,
   StringRef FileName,
   bool IsAngled,
   CharSourceRange FilenameRange,
   const FileEntry *File,
   StringRef SearchPath,
   StringRef RelativePath,
-  const Module *Imported) {
+  const Module *Imported,
+  SrcMgr::CharacteristicKind FileType) {
   }
 
   /// Callback invoked whenever there was an explicit module-import
@@ -367,13 +372,14 @@
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported) override {
+  const Module *Imported,
+  SrcMgr::CharacteristicKind FileType) override {
 First->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled,
   FilenameRange, File, SearchPath, RelativePath,
-  Imported);
+  Imported, FileType);
 Second->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled,
FilenameRange, File, SearchPath, RelativePath,
-   Imported);
+   Imported, FileType);
   }
 
   void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path,
Index: lib/CodeGen/MacroPPCallbacks.h
===
--- lib/CodeGen/MacroPPCallbacks.h
+++ lib/CodeGen/MacroPPCallbacks.h
@@ -101,7 +101,8 @@
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
   StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported) override;
+  const Module *Imported,
+  SrcMgr::CharacteristicKind FileType) override;
 
   /// Hook called whenever a macro definition is seen.
   void MacroDefined(const Token &MacroNameTok,
Index: lib/CodeGen/MacroPPCallbacks.cpp
===
--- lib/CodeGen/MacroPPCallbacks.cpp
+++ lib/CodeGen/MacroPPCallbacks.cpp
@@ -178,7 +178,8 @@
 void MacroPPCallbacks::InclusionDirective(
 SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
 bool IsAngled, CharSourceRange FilenameRange, const FileEntry

[PATCH] D43778: [clang-tidy] Adding RestrictIncludes check to Fuchsia module

2018-05-11 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 146349.
juliehockett added a comment.

Updating parameter list to be a glob-style list.


https://reviews.llvm.org/D43778

Files:
  clang-tidy/fuchsia/CMakeLists.txt
  clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp
  clang-tidy/fuchsia/RestrictSystemIncludesCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/fuchsia-restrict-system-includes.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/a.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/cstdarg.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/cstdlib.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/j.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/r.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/s.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/t.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/transitive.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/transitive2.h
  test/clang-tidy/fuchsia-restrict-system-includes-all.cpp
  test/clang-tidy/fuchsia-restrict-system-includes-glob.cpp
  test/clang-tidy/fuchsia-restrict-system-includes-headers.cpp
  test/clang-tidy/fuchsia-restrict-system-includes.cpp

Index: test/clang-tidy/fuchsia-restrict-system-includes.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-restrict-system-includes.cpp
@@ -0,0 +1,25 @@
+// RUN: %check_clang_tidy %s fuchsia-restrict-system-includes %t \
+// RUN:		-- -config="{CheckOptions: [{key: fuchsia-restrict-system-includes.Includes, value: 's.h'}]}" \
+// RUN:   -- -std=c++11 -I %S/Inputs/fuchsia-restrict-system-includes -isystem %S/Inputs/fuchsia-restrict-system-includes/system
+
+#include "a.h"
+
+#include 
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include t.h not allowed
+// CHECK-FIXES-NOT: #include 
+
+#include "s.h"
+#include "t.h"
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include t.h not allowed
+// CHECK-FIXES-NOT: #include "t.h"
+
+#define foo 
+
+#include foo
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include j.h not allowed
+// CHECK-FIXES-NOT: #include foo
+
+#/* comment */ include /* comment */ foo
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include j.h not allowed
+// CHECK-FIXES-NOT: # /* comment */ include /* comment */ foo
Index: test/clang-tidy/fuchsia-restrict-system-includes-headers.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-restrict-system-includes-headers.cpp
@@ -0,0 +1,20 @@
+// RUN: cp -r %S/Inputs/fuchsia-restrict-system-includes %T/Inputs
+// RUN: %check_clang_tidy %s fuchsia-restrict-system-includes %t \
+// RUN:		-- -config="{CheckOptions: [{key: fuchsia-restrict-system-includes.Includes, value: 'transitive.h,s.h'}]}" \
+// RUN:   -system-headers -header-filter=.* \
+// RUN:   -- -std=c++11 -I %T/Inputs/fuchsia-restrict-system-includes -isystem %T/Inputs/fuchsia-restrict-system-includes/system
+// RUN: FileCheck -input-file=%T/Inputs/transitive2.h %s -check-prefix=CHECK-HEADER-FIXES
+
+// transitive.h includes  and 
+#include 
+// CHECK-MESSAGES: :1:1: warning: system include r.h not allowed, transitively included from {{(.*\/)*}}Inputs/fuchsia-restrict-system-includes/system/transitive.h
+// CHECK-MESSAGES: :2:1: warning: system include t.h not allowed, transitively included from {{(.*\/)*}}Inputs/fuchsia-restrict-system-includes/system/transitive.h
+
+// transitive.h includes  and 
+#include "transitive2.h"
+// CHECK-MESSAGES: :2:1: warning: system include t.h not allowed, transitively included from {{(.*\/)*}}Inputs/fuchsia-restrict-system-includes/transitive2.h
+// CHECK-HEADER-FIXES-NOT: #include 
+
+int main() {
+  // f() is declared in r.h
+}
Index: test/clang-tidy/fuchsia-restrict-system-includes-glob.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-restrict-system-includes-glob.cpp
@@ -0,0 +1,9 @@
+// RUN: %check_clang_tidy %s fuchsia-restrict-system-includes %t \
+// RUN:		-- -config="{CheckOptions: [{key: fuchsia-restrict-system-includes.Includes, value: 'cstd*'}]}" \
+// RUN:   -- -std=c++11 -I %S/Inputs/fuchsia-restrict-system-includes -isystem %S/Inputs/fuchsia-restrict-system-includes/system
+
+#include 
+#include 
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include t.h not allowed
+// CHECK-FIXES-NOT: #include 
Index: test/clang-tidy/fuchsia-restrict-system-includes-all.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-restrict-system-includes-all.cpp
@@ -0,0 +1,10 @@
+// RUN: %check_clang_tidy %s fuchsia-restrict-system-includes %t \
+// RUN:		-- -config="{CheckOptions: [{key: fuchsia-restrict-system-includes.Includes, value: ''}]}" \
+// 

[PATCH] D43778: [clang-tidy] Adding RestrictIncludes check to Fuchsia module

2018-05-11 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added inline comments.



Comment at: clang-tidy/fuchsia/RestrictSystemIncludesCheck.h:35
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
+  bool contains(StringRef FileName) {
+return AllowedIncludesGlobList.contains(FileName);

aaron.ballman wrote:
> Function can be marked `const`.
GlobList::contains isn't `const`, so it can't...


https://reviews.llvm.org/D43778



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


[PATCH] D43778: [clang-tidy] Adding RestrictIncludes check to Fuchsia module

2018-05-11 Thread Julie Hockett via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL332125: [clang-tidy] Adding RestrictSystemIncludes check to 
Fuchsia module (authored by juliehockett, committed by ).
Herald added subscribers: llvm-commits, klimek.

Changed prior to commit:
  https://reviews.llvm.org/D43778?vs=146349&id=146382#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D43778

Files:
  clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp
  clang-tools-extra/trunk/clang-tidy/fuchsia/RestrictSystemIncludesCheck.h
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-restrict-system-includes.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/trunk/test/clang-tidy/Inputs/fuchsia-restrict-system-includes/a.h
  
clang-tools-extra/trunk/test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/cstdarg.h
  
clang-tools-extra/trunk/test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/cstdlib.h
  
clang-tools-extra/trunk/test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/j.h
  
clang-tools-extra/trunk/test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/r.h
  
clang-tools-extra/trunk/test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/s.h
  
clang-tools-extra/trunk/test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/t.h
  
clang-tools-extra/trunk/test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/transitive.h
  
clang-tools-extra/trunk/test/clang-tidy/Inputs/fuchsia-restrict-system-includes/transitive2.h
  
clang-tools-extra/trunk/test/clang-tidy/fuchsia-restrict-system-includes-all.cpp
  
clang-tools-extra/trunk/test/clang-tidy/fuchsia-restrict-system-includes-glob.cpp
  
clang-tools-extra/trunk/test/clang-tidy/fuchsia-restrict-system-includes-headers.cpp
  clang-tools-extra/trunk/test/clang-tidy/fuchsia-restrict-system-includes.cpp

Index: clang-tools-extra/trunk/docs/ReleaseNotes.rst
===
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst
@@ -110,8 +110,13 @@
   Checks whether a ``std::string::find()`` result is compared with 0, and
   suggests replacing with ``absl::StartsWith()``.
 
-- New :doc:`fuchsia-statically-constructed-objects
-  ` check.
+- New `fuchsia-restrict-system-includes
+  `_ check
+
+  Checks for allowed system includes and suggests removal of any others.
+
+- New `fuchsia-statically-constructed-objects
+  `_ check
 
   Warns if global, non-trivial objects with static storage are constructed,
   unless the object is statically initialized with a ``constexpr`` constructor
Index: clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
@@ -95,6 +95,7 @@
fuchsia-default-arguments
fuchsia-multiple-inheritance
fuchsia-overloaded-operator
+   fuchsia-restrict-system-includes
fuchsia-statically-constructed-objects
fuchsia-trailing-return
fuchsia-virtual-inheritance
Index: clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-restrict-system-includes.rst
===
--- clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-restrict-system-includes.rst
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-restrict-system-includes.rst
@@ -0,0 +1,32 @@
+.. title:: clang-tidy - fuchsia-restrict-system-includes
+
+fuchsia-restrict-system-includes
+
+
+Checks for allowed system includes and suggests removal of any others.
+
+It is important to note that running this check with fixes may break code, as
+the fix removes headers. Fixes are applied to source and header files, but not
+to system headers.
+
+For example, given the allowed system includes 'a.h,b*':
+
+.. code-block:: c++
+
+  #include 
+  #include 
+  #include 
+  #include // Warning, as c.h is not explicitly allowed
+  
+All system includes can be allowed with '*', and all can be disallowed with an
+empty string ('').
+  
+Options
+---
+
+.. option:: Includes
+
+   A string containing a comma separated glob list of allowed include filenames.
+   Similar to the -checks glob list for running clang-tidy itself, the two
+   wildcard characters are '*' and '-', to include and exclude globs,
+   respectively.The default is '*', which allows all includes.
Index: clang-tools-extra/trunk/test/clang-tidy/fuchsia-restrict-system-includes.cpp
===

[PATCH] D43341: [clang-doc] Implement reducer portion of the frontend framework

2018-05-14 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added a comment.

Pingany more thoughts?


https://reviews.llvm.org/D43341



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


[PATCH] D43667: [clang-doc] Implement a YAML generator

2018-05-18 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 147606.
juliehockett marked 11 inline comments as done.
juliehockett edited the summary of this revision.
juliehockett added a comment.

Updating for better integration with MR framework, the generator now takes in 
an info and an output stream and emits the YAML to that stream. Each info is 
emitted to its own YAML file.


https://reviews.llvm.org/D43667

Files:
  clang-doc/CMakeLists.txt
  clang-doc/Representation.h
  clang-doc/generators/CMakeLists.txt
  clang-doc/generators/Generators.h
  clang-doc/generators/YAMLGenerator.cpp
  clang-doc/tool/CMakeLists.txt
  clang-doc/tool/ClangDocMain.cpp
  test/clang-doc/yaml-comments.cpp
  test/clang-doc/yaml-namespace.cpp
  test/clang-doc/yaml-record.cpp

Index: test/clang-doc/yaml-record.cpp
===
--- /dev/null
+++ test/clang-doc/yaml-record.cpp
@@ -0,0 +1,212 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: cat %t/docs/yaml/docs.yaml | FileCheck %s
+
+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 {};
+};
+
+void H() {
+  class I {};
+}
+
+// CHECK: ---
+// CHECK-NEXT: Records: 
+// CHECK-NEXT:   - USR: 'ACE81AFA6627B4CEF2B456FB6E1252925674AF7E'
+// CHECK-NEXT: Name:'A'
+// CHECK-NEXT: DefLocation: 
+// CHECK-NEXT:   LineNumber:  8
+// CHECK-NEXT:   Filename:'{{.*}}'
+// CHECK-NEXT: TagType: Union
+// CHECK-NEXT: Members: 
+// CHECK-NEXT:   - Type:
+// CHECK-NEXT:   UnresolvedName:  'int'
+// CHECK-NEXT: Name:'A::X'
+// CHECK-NEXT:   - Type:
+// CHECK-NEXT:   UnresolvedName:  'int'
+// CHECK-NEXT: Name:'A::Y'
+// CHECK-NEXT:   - USR: '06B5F6A19BA9F6A832E127C9968282B94619B210'
+// CHECK-NEXT: Name:'C'
+// CHECK-NEXT: DefLocation: 
+// CHECK-NEXT:   LineNumber:  14
+// CHECK-NEXT:   Filename:'{{.*}}'
+// CHECK-NEXT: Members: 
+// CHECK-NEXT:   - Type:
+// CHECK-NEXT:   UnresolvedName:  'int'
+// CHECK-NEXT: Name:'C::i'
+// CHECK-NEXT:   - USR: '0921737541208B8FA9BB42B60F78AC1D779AA054'
+// CHECK-NEXT: Name:'D'
+// CHECK-NEXT: Records: 
+// CHECK-NEXT:   - Type:Record
+// CHECK-NEXT: USR: 'E3B54702FABFF4037025BA194FC27C47006330B5'
+// CHECK-NEXT: DefLocation: 
+// CHECK-NEXT:   LineNumber:  16
+// CHECK-NEXT:   Filename:'{{.*}}'
+// CHECK-NEXT: TagType: Class
+// CHECK-NEXT:   - USR: '289584A8E0FF4178A794622A547AA622503967A1'
+// CHECK-NEXT: Name:'E'
+// CHECK-NEXT: Records: 
+// CHECK-NEXT:   - Type:Record
+// CHECK-NEXT: USR: 'E3B54702FABFF4037025BA194FC27C47006330B5'
+// CHECK-NEXT: Functions:   
+// CHECK-NEXT:   - Type:Function
+// CHECK-NEXT: USR: 'DEB4AC1CD9253CD9EF7FBE6BCAC506D77984ABD4'
+// CHECK-NEXT:   - Type:Function
+// CHECK-NEXT: USR: 'DEB4AC1CD9253CD9EF7FBE6BCAC506D77984ABD4'
+// CHECK-NEXT:   - Type:Function
+// CHECK-NEXT: USR: 'BD2BDEBD423F80BACCEA75DE6D6622D355FC2D17'
+// CHECK-NEXT:   - Type:Function
+// CHECK-NEXT: USR: 'BD2BDEBD423F80BACCEA75DE6D6622D355FC2D17'
+// CHECK-NEXT:   - Type:Function
+// CHECK-NEXT: USR: '5093D428CDC62096A67547BA52566E4FB9404EEE'
+// CHECK-NEXT:   - Type:Function
+// CHECK-NEXT: USR: '5093D428CDC62096A67547BA52566E4FB9404EEE'
+// CHECK-NEXT: DefLocation: 
+// CHECK-NEXT:   LineNumber:  18
+// CHECK-NEXT:   Filename:'{{.*}}'
+// CHECK-NEXT: TagType: Class
+// CHECK-NEXT:   - USR: 'E3B54702FABFF4037025BA194FC27C47006330B5'
+// CHECK-NEXT: Name:'F'
+// CHECK-NEXT: DefLocation: 
+// CHECK-NEXT:   LineNumber:  29
+// CHECK-NEXT:   Filename:'{{.*}}'
+// CHECK-NEXT: TagType: Class
+// CHECK-NEXT: Parents: 
+// CHECK-NEXT:   - Type:Record
+// CHECK-NEXT: USR: '289584A8E0FF4178A794622A547AA622503967A1'
+// CHECK-NEXT: VirtualParents:  
+// CHECK-NEXT:   - Type:Record
+// CHECK-NEXT: USR: '0921737541208B8FA9BB42B60F78AC1D779AA054'
+// CHECK-NEXT:   - USR:   

[PATCH] D43667: [clang-doc] Implement a YAML generator

2018-05-18 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added inline comments.



Comment at: clang-doc/generators/Generators.h:49
+
+class GeneratorFactory {
+public:

ioeric wrote:
> ioeric wrote:
> > Please add documentation and explain why this is needed. 
> If you plan to plugin in more generators (e.g. in your customized build of 
> clang-doc), consider using `llvm::Registry` which allows you to link in new 
> generators without having to modify code. See 
> `clang::clangd::URISchemeRegistry` for sample usage.
Oh cool -- didn't know about that. Thanks!



Comment at: clang-doc/generators/YAMLGenerator.cpp:223
+
+template <> struct MappingTraits> {
+  static void mapping(IO &IO, std::unique_ptr &I) {

ioeric wrote:
> YAML mapping for `unique_ptr` is a bit unusual. I wonder whether this would 
> work all the time e.g. if the unique_ptr has not been allocated. 
Mmm yes it's a little weird -- that said, is there a better way emit the info 
given a pointer?


https://reviews.llvm.org/D43667



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


[PATCH] D43341: [clang-doc] Implement reducer portion of the frontend framework

2018-05-22 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added a comment.

ping


https://reviews.llvm.org/D43341



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


[PATCH] D43341: [clang-doc] Implement reducer portion of the frontend framework

2018-05-25 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 148678.
juliehockett marked 11 inline comments as done.
juliehockett added a comment.

Reworking the reducer interface a bit to address comments.


https://reviews.llvm.org/D43341

Files:
  clang-doc/BitcodeReader.cpp
  clang-doc/BitcodeReader.h
  clang-doc/BitcodeWriter.cpp
  clang-doc/BitcodeWriter.h
  clang-doc/CMakeLists.txt
  clang-doc/Reducer.cpp
  clang-doc/Reducer.h
  clang-doc/Representation.cpp
  clang-doc/Representation.h
  clang-doc/tool/ClangDocMain.cpp
  docs/ReleaseNotes.rst
  test/clang-doc/bc-comment.cpp
  test/clang-doc/bc-namespace.cpp
  test/clang-doc/bc-record.cpp

Index: test/clang-doc/bc-record.cpp
===
--- /dev/null
+++ test/clang-doc/bc-record.cpp
@@ -0,0 +1,254 @@
+// This test requires Linux due to the system-dependent USR for the
+// inner class in function H.
+// REQUIRES: system-linux
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump-intermediate -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/bc/ACE81AFA6627B4CEF2B456FB6E1252925674AF7E.bc --dump | FileCheck %s --check-prefix CHECK-A
+// RUN: llvm-bcanalyzer %t/docs/bc/FC07BD34D5E77782C263FA97929EA8753740.bc --dump | FileCheck %s --check-prefix CHECK-B
+// RUN: llvm-bcanalyzer %t/docs/bc/1E3438A08BA22025C0B46289FF0686F92C8924C5.bc --dump | FileCheck %s --check-prefix CHECK-BC
+// RUN: llvm-bcanalyzer %t/docs/bc/06B5F6A19BA9F6A832E127C9968282B94619B210.bc --dump | FileCheck %s --check-prefix CHECK-C
+// RUN: llvm-bcanalyzer %t/docs/bc/0921737541208B8FA9BB42B60F78AC1D779AA054.bc --dump | FileCheck %s --check-prefix CHECK-D
+// RUN: llvm-bcanalyzer %t/docs/bc/289584A8E0FF4178A794622A547AA622503967A1.bc --dump | FileCheck %s --check-prefix CHECK-E
+// RUN: llvm-bcanalyzer %t/docs/bc/DEB4AC1CD9253CD9EF7FBE6BCAC506D77984ABD4.bc --dump | FileCheck %s --check-prefix CHECK-ECON
+// RUN: llvm-bcanalyzer %t/docs/bc/BD2BDEBD423F80BACCEA75DE6D6622D355FC2D17.bc --dump | FileCheck %s --check-prefix CHECK-EDES
+// RUN: llvm-bcanalyzer %t/docs/bc/E3B54702FABFF4037025BA194FC27C47006330B5.bc --dump | FileCheck %s --check-prefix CHECK-F
+// RUN: llvm-bcanalyzer %t/docs/bc/B6AC4C5C9F2EA3F2B3ECE1A33D349F4EE502B24E.bc --dump | FileCheck %s --check-prefix CHECK-H
+// RUN: llvm-bcanalyzer %t/docs/bc/6BA1EE2B3DAEACF6E4306F10AF44908F4807927C.bc --dump | FileCheck %s --check-prefix CHECK-I
+// RUN: llvm-bcanalyzer %t/docs/bc/5093D428CDC62096A67547BA52566E4FB9404EEE.bc --dump | FileCheck %s --check-prefix CHECK-PM
+// RUN: llvm-bcanalyzer %t/docs/bc/CA7C7935730B5EACD25F080E9C83FA087CCDC75E.bc --dump | FileCheck %s --check-prefix CHECK-X
+// RUN: llvm-bcanalyzer %t/docs/bc/641AB4A3D36399954ACDE29C7A8833032BF40472.bc --dump | FileCheck %s --check-prefix CHECK-Y
+
+void H() {
+  class I {};
+}
+// CHECK-H: 
+  // CHECK-H-NEXT: 
+  // CHECK-H-NEXT:  blob data = 'H'
+  // CHECK-H-NEXT:  blob data = '{{.*}}'
+  // CHECK-H-NEXT: 
+// CHECK-H-NEXT: 
+  // CHECK-H-NEXT:  blob data = 'void'
+  // CHECK-H-NEXT: 
+// CHECK-H-NEXT: 
+  // CHECK-H-NEXT: 
+// CHECK-H-NEXT: 
+
+
+// CHECK-I: 
+  // CHECK-I-NEXT: 
+  // CHECK-I-NEXT:  blob data = 'I'
+  // CHECK-I-NEXT: 
+// CHECK-I-NEXT: 
+// CHECK-I-NEXT:  blob data = 'H'
+// CHECK-I-NEXT: 
+// CHECK-I-NEXT: 
+  // CHECK-I-NEXT: 
+  // CHECK-I-NEXT:  blob data = '{{.*}}'
+  // CHECK-I-NEXT: 
+// CHECK-I-NEXT: 
+
+union A { int X; int Y; };
+// CHECK-A: 
+  // CHECK-A-NEXT: 
+  // CHECK-A-NEXT:  blob data = 'A'
+  // CHECK-A-NEXT:  blob data = '{{.*}}'
+  // CHECK-A-NEXT: 
+  // CHECK-A-NEXT: 
+// CHECK-A-NEXT: 
+  // CHECK-A-NEXT:  blob data = 'int'
+  // CHECK-A-NEXT: 
+// CHECK-A-NEXT: 
+// CHECK-A-NEXT:  blob data = 'X'
+// CHECK-A-NEXT: 
+  // CHECK-A-NEXT: 
+  // CHECK-A-NEXT: 
+// CHECK-A-NEXT: 
+  // CHECK-A-NEXT:  blob data = 'int'
+  // CHECK-A-NEXT: 
+// CHECK-A-NEXT: 
+// CHECK-A-NEXT:  blob data = 'Y'
+// CHECK-A-NEXT: 
+  // CHECK-A-NEXT: 
+// CHECK-A-NEXT: 
+
+enum B { X, Y };
+// CHECK-B: 
+  // CHECK-B-NEXT: 
+  // CHECK-B-NEXT:  blob data = 'B'
+  // CHECK-B-NEXT:  blob data = '{{.*}}'
+  // CHECK-B-NEXT:  blob data = 'X'
+  // CHECK-B-NEXT:  blob data = 'Y'
+// CHECK-B-NEXT: 
+
+enum class Bc { A, B };
+// CHECK-BC: 
+  // CHECK-BC-NEXT: 
+  // CHECK-BC-NEXT:  blob data = 'Bc'
+  // CHECK-BC-NEXT:  blob data = '{{.*}}'
+  // CHECK-BC-NEXT: 
+  // CHECK-BC-NEXT:  blob data = 'A'
+  // CHECK-BC-NEXT:  blob data = 'B'
+// CHECK-BC-NEXT: 
+
+struct C { int i; };
+// CHECK-C: 
+  // CHECK-C-NEXT: 
+  // CHECK-C-NEXT:  blob data = 'C'
+  // CHECK-C-NEXT:  blob data = '{{.*}}'
+  // CHECK-C-NEXT: 
+// CHECK-C-NEXT: 
+  // CHECK-C-NEXT:  blob data = 'int'
+  // CHECK-C-NEXT: 
+// CHECK-C-NEXT: 
+// CHECK-C-NEXT:  blob data = 'i'
+// CHECK-C-NEXT: 
+  // CHECK-C-NEXT: 
+// CHECK-C-NEXT: 
+
+

[PATCH] D43341: [clang-doc] Implement reducer portion of the frontend framework

2018-05-25 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added inline comments.



Comment at: clang-doc/Representation.h:138
+  SymbolID USR =
+  SymbolID(); // Unique identifier for the decl described by this Info.
+  const InfoType IT = InfoType::IT_default; // InfoType of this particular 
Info.

ioeric wrote:
> Shouldn't USR be `SymbolID()` by default?
It actually is garbage by default -- doing this zeroed it out.



Comment at: clang-doc/Representation.h:146
+protected:
+  bool mergeBase(Info &&I);
 };

ioeric wrote:
> It's a bit awkward that users have to dispatch from info types to the 
> corresponding `merge` function (as in `Reducer.cpp`). I think it would make 
> users' life easier if the library handles the dispatching.
> 
> I wonder if something like the following would be better:
> ```
> struct Info {
> std::unique_ptr merge(const Indo& LHS, const Info& RHS);
> };
> // A standalone function.
> std::unique_ptr mergeInfo(const Info &LHS, const Info& RHS) {
>   // merge base info.
>   ...
>   // merge subclass infos.
>   assert(LHS.IT == RHS.IT); // or return nullptr
>   switch (LHS.IT) {
>... 
> return Namespace::merge(LHS, RHS);
>   } 
> }
> 
> struct NamespaceInfo : public Info {
>   std::unique_ptr merge(LHS, RHS);
> };
> 
> ```
> 
> The unhandled switch case warning in compiler would help you catch 
> unimplemented `merge` when new info types are added.
Sort of addressed in this update. There's an issue with where we allocate the 
return pointer, because we need to know the type of info at allocation time -- 
let me know if what's here now is too far off of what you were suggesting.



Comment at: clang-doc/tool/ClangDocMain.cpp:181
+doc::writeInfo(I.get(), Buffer);
+  if (DumpResultToFile("bc", Group.getKey() + ".bc", Buffer))
+return 1;

ioeric wrote:
> (Sorry that I might be missing context here.)
> 
> Could you please explain the incentive for dumping each info group to one bc 
> file? If the key identifies a symbol (e.g. USR), wouldn't this result in a 
> bitcode file being created for each symbol? This doesn't seem very scalable.  
Yes, it would. This is mostly for debugging, since there's not really any tools 
outside the clang system that would actually want/be able to use this 
information.


https://reviews.llvm.org/D43341



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


[PATCH] D51137: [clang-doc] Fix memory leaks

2018-08-24 Thread Julie Hockett via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL340620: [clang-doc] Fix memory leaks (authored by 
juliehockett, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D51137?vs=162081&id=162399#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D51137

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


Index: clang-tools-extra/trunk/clang-doc/Representation.h
===
--- clang-tools-extra/trunk/clang-doc/Representation.h
+++ clang-tools-extra/trunk/clang-doc/Representation.h
@@ -162,6 +162,8 @@
   Info(const Info &Other) = delete;
   Info(Info &&Other) = default;
 
+  virtual ~Info() = default;
+
   SymbolID USR =
   SymbolID(); // Unique identifier for the decl described by this Info.
   const InfoType IT = InfoType::IT_default; // InfoType of this particular 
Info.
Index: clang-tools-extra/trunk/clang-doc/Serialize.cpp
===
--- clang-tools-extra/trunk/clang-doc/Serialize.cpp
+++ clang-tools-extra/trunk/clang-doc/Serialize.cpp
@@ -361,7 +361,7 @@
 I->USR = Func.Namespace[0].USR;
   else
 I->USR = SymbolID();
-  I->ChildFunctions.push_back(std::move(Func));
+  I->ChildFunctions.emplace_back(std::move(Func));
   return std::unique_ptr{std::move(I)};
 }
 
@@ -382,7 +382,7 @@
   // Wrap in enclosing scope
   auto I = llvm::make_unique();
   I->USR = ParentUSR;
-  I->ChildFunctions.push_back(std::move(Func));
+  I->ChildFunctions.emplace_back(std::move(Func));
   return std::unique_ptr{std::move(I)};
 }
 
@@ -402,13 +402,13 @@
 case InfoType::IT_namespace: {
   auto I = llvm::make_unique();
   I->USR = Enum.Namespace[0].USR;
-  I->ChildEnums.push_back(std::move(Enum));
+  I->ChildEnums.emplace_back(std::move(Enum));
   return std::unique_ptr{std::move(I)};
 }
 case InfoType::IT_record: {
   auto I = llvm::make_unique();
   I->USR = Enum.Namespace[0].USR;
-  I->ChildEnums.push_back(std::move(Enum));
+  I->ChildEnums.emplace_back(std::move(Enum));
   return std::unique_ptr{std::move(I)};
 }
 default:
@@ -419,7 +419,7 @@
   // Put in global namespace
   auto I = llvm::make_unique();
   I->USR = SymbolID();
-  I->ChildEnums.push_back(std::move(Enum));
+  I->ChildEnums.emplace_back(std::move(Enum));
   return std::unique_ptr{std::move(I)};
 }
 


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
@@ -162,6 +162,8 @@
   Info(const Info &Other) = delete;
   Info(Info &&Other) = default;
 
+  virtual ~Info() = default;
+
   SymbolID USR =
   SymbolID(); // Unique identifier for the decl described by this Info.
   const InfoType IT = InfoType::IT_default; // InfoType of this particular Info.
Index: clang-tools-extra/trunk/clang-doc/Serialize.cpp
===
--- clang-tools-extra/trunk/clang-doc/Serialize.cpp
+++ clang-tools-extra/trunk/clang-doc/Serialize.cpp
@@ -361,7 +361,7 @@
 I->USR = Func.Namespace[0].USR;
   else
 I->USR = SymbolID();
-  I->ChildFunctions.push_back(std::move(Func));
+  I->ChildFunctions.emplace_back(std::move(Func));
   return std::unique_ptr{std::move(I)};
 }
 
@@ -382,7 +382,7 @@
   // Wrap in enclosing scope
   auto I = llvm::make_unique();
   I->USR = ParentUSR;
-  I->ChildFunctions.push_back(std::move(Func));
+  I->ChildFunctions.emplace_back(std::move(Func));
   return std::unique_ptr{std::move(I)};
 }
 
@@ -402,13 +402,13 @@
 case InfoType::IT_namespace: {
   auto I = llvm::make_unique();
   I->USR = Enum.Namespace[0].USR;
-  I->ChildEnums.push_back(std::move(Enum));
+  I->ChildEnums.emplace_back(std::move(Enum));
   return std::unique_ptr{std::move(I)};
 }
 case InfoType::IT_record: {
   auto I = llvm::make_unique();
   I->USR = Enum.Namespace[0].USR;
-  I->ChildEnums.push_back(std::move(Enum));
+  I->ChildEnums.emplace_back(std::move(Enum));
   return std::unique_ptr{std::move(I)};
 }
 default:
@@ -419,7 +419,7 @@
   // Put in global namespace
   auto I = llvm::make_unique();
   I->USR = SymbolID();
-  I->ChildEnums.push_back(std::move(Enum));
+  I->ChildEnums.emplace_back(std::move(Enum));
   return std::unique_ptr{std::move(I)};
 }
 
___
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-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&id=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 &OS) override;
+  llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream &OS) override;
 };
 
 const char *YAMLGenerator::Format = "yaml";
 
-bool YAMLGenerator::generateDocForInfo(Info *I, llvm::raw_ostream &OS) {
+llvm::Error YAMLGenerator::generateDocForInfo(Info *I, llvm::raw_ostream &OS) {
   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 &Other) = delete;
   CommentInfo(CommentInfo &&Other) = 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-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&id=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 &OS) = 0;
+  virtual llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream &OS) = 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 &OS) override;
+  llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream &OS) override;
 };
 
 const char *YAMLGenerator::Format = "yaml";
 
-bool YAMLGenerator::generateDocForInfo(Info *I, llvm::raw_ostream &OS) {
+llvm::Error YAMLGenerator::generateDocForInfo(Info *I, llvm::raw_ostream &OS) {
   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 &Other) = delete;
   CommentInfo(CommentInfo &&Other) = 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"
+#i

[PATCH] D48341: [clang-doc] Refactoring mapper to map by scope

2018-07-19 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added inline comments.
Herald added a subscriber: arphaman.



Comment at: clang-tools-extra/test/clang-doc/yaml-record.cpp:44
+// CHECK-0: ---
+// CHECK-0-NEXT: USR: '06B5F6A19BA9F6A832E127C9968282B94619B210'
+// CHECK-0-NEXT: Name:'C'

ioeric wrote:
> > Yes, in most regex worlds, but it doesn't work in FileCheck regex 
> > (complains about unbalanced braces).
> Forgot this was `FileCheck` ;) Have you tried `[0-9A-Z]{{n}}`? If nothing 
> works, I'd probably just  check length of one USR and use `{{.*}}` to match 
> the rest of USRs in all tests.
I can't wholly eliminate USRs from the tests (the bitcode ones use them as 
filenames), and so would the script I'm going to land from D49268 be 
sufficient? That way if the USR spec ever changes, it's fairly trivial to regen 
them all. 


https://reviews.llvm.org/D48341



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


[PATCH] D48395: Added PublicOnly flag

2018-07-20 Thread Julie Hockett via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE337602: [clang-doc] Adding PublicOnly flag (authored by 
juliehockett, committed by ).
Herald added a subscriber: arphaman.

Changed prior to commit:
  https://reviews.llvm.org/D48395?vs=154470&id=156562#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48395

Files:
  clang-doc/ClangDoc.cpp
  clang-doc/ClangDoc.h
  clang-doc/Mapper.cpp
  clang-doc/Mapper.h
  clang-doc/Representation.cpp
  clang-doc/Representation.h
  clang-doc/Serialize.cpp
  clang-doc/Serialize.h
  clang-doc/tool/ClangDocMain.cpp
  test/clang-doc/module.cpp
  test/clang-doc/public-module.cpp
  test/clang-doc/public-records.cpp

Index: clang-doc/Representation.cpp
===
--- clang-doc/Representation.cpp
+++ clang-doc/Representation.cpp
@@ -42,7 +42,7 @@
 mergeInfos(std::vector> &Values) {
   if (Values.empty())
 return llvm::make_error("No info values to merge.\n",
- llvm::inconvertibleErrorCode());
+   llvm::inconvertibleErrorCode());
 
   switch (Values[0]->IT) {
   case InfoType::IT_namespace:
Index: clang-doc/Serialize.h
===
--- clang-doc/Serialize.h
+++ clang-doc/Serialize.h
@@ -29,15 +29,15 @@
 namespace serialize {
 
 std::string emitInfo(const NamespaceDecl *D, const FullComment *FC,
- int LineNumber, StringRef File);
+ int LineNumber, StringRef File, bool PublicOnly);
 std::string emitInfo(const RecordDecl *D, const FullComment *FC, int LineNumber,
- StringRef File);
+ StringRef File, bool PublicOnly);
 std::string emitInfo(const EnumDecl *D, const FullComment *FC, int LineNumber,
- StringRef File);
+ StringRef File, bool PublicOnly);
 std::string emitInfo(const FunctionDecl *D, const FullComment *FC,
- int LineNumber, StringRef File);
+ int LineNumber, StringRef File, bool PublicOnly);
 std::string emitInfo(const CXXMethodDecl *D, const FullComment *FC,
- int LineNumber, StringRef File);
+ int LineNumber, StringRef File, bool PublicOnly);
 
 // Function to hash a given USR value for storage.
 // As USRs (Unified Symbol Resolution) could be large, especially for functions
Index: clang-doc/tool/ClangDocMain.cpp
===
--- clang-doc/tool/ClangDocMain.cpp
+++ clang-doc/tool/ClangDocMain.cpp
@@ -64,6 +64,10 @@
 llvm::cl::desc("Dump intermediate results to bitcode file."),
 llvm::cl::init(false), llvm::cl::cat(ClangDocCategory));
 
+static llvm::cl::opt
+PublicOnly("public", llvm::cl::desc("Document only public declarations."),
+   llvm::cl::init(false), llvm::cl::cat(ClangDocCategory));
+
 enum OutputFormatTy {
   yaml,
 };
@@ -171,9 +175,10 @@
 
   // Mapping phase
   llvm::outs() << "Mapping decls...\n";
-  auto Err = Exec->get()->execute(
-  doc::newMapperActionFactory(Exec->get()->getExecutionContext()),
-  ArgAdjuster);
+  clang::doc::ClangDocContext CDCtx = {Exec->get()->getExecutionContext(),
+   PublicOnly};
+  auto Err =
+  Exec->get()->execute(doc::newMapperActionFactory(CDCtx), ArgAdjuster);
   if (Err) {
 llvm::errs() << toString(std::move(Err)) << "\n";
 return 1;
Index: clang-doc/Mapper.h
===
--- clang-doc/Mapper.h
+++ clang-doc/Mapper.h
@@ -18,6 +18,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_MAPPER_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_MAPPER_H
 
+#include "Representation.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Tooling/Execution.h"
 
@@ -30,8 +31,8 @@
 class MapASTVisitor : public clang::RecursiveASTVisitor,
   public ASTConsumer {
 public:
-  explicit MapASTVisitor(ASTContext *Ctx, ExecutionContext *ECtx)
-  : ECtx(ECtx) {}
+  explicit MapASTVisitor(ASTContext *Ctx, ClangDocContext CDCtx)
+  : CDCtx(CDCtx) {}
 
   void HandleTranslationUnit(ASTContext &Context) override;
   bool VisitNamespaceDecl(const NamespaceDecl *D);
@@ -48,7 +49,7 @@
   comments::FullComment *getComment(const NamedDecl *D,
 const ASTContext &Context) const;
 
-  ExecutionContext *ECtx;
+  ClangDocContext CDCtx;
 };
 
 } // namespace doc
Index: clang-doc/Serialize.cpp
===
--- clang-doc/Serialize.cpp
+++ clang-doc/Serialize.cpp
@@ -171,8 +171,20 @@
   return Ty->getDecl()->getDefinition();
 }
 
-static void parseFields(RecordInfo &I, const RecordDecl *D) {
+static bool isPublic(const clang::AccessSpecifier AS,
+ const clang::Linkage Link) {
+  if 

[PATCH] D49158: [clang-tidy] Fixing segfault when there's no IdentifierInfo

2018-07-23 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added a comment.

In https://reviews.llvm.org/D49158#1159882, @hokein wrote:

> In https://reviews.llvm.org/D49158#1158327, @JonasToth wrote:
>
> > Is there a way to add a test, that would trigger the old segfault and show 
> > that it does not happen anymore with this fix?
>
>
> +1, we should have a minimal test case for this fix, 
> https://bugs.llvm.org/show_bug.cgi?id=36150 provides a case, but we need to 
> reduce it (getting rid of the STD header).


Does anyone know of a case where the base would not be a CXXRecordDecl that 
doesn't involve std::functional? (for background, I could only reproduce the 
error in the test case in https://bugs.llvm.org/show_bug.cgi?id=36150 on a Mac)


https://reviews.llvm.org/D49158



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


[PATCH] D48341: [clang-doc] Refactoring mapper to map by scope

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

ping


https://reviews.llvm.org/D48341



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


[PATCH] D48341: [clang-doc] Refactoring mapper to map by scope

2018-07-27 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added a comment.

any further thoughts on this?


https://reviews.llvm.org/D48341



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


[PATCH] D48341: [clang-doc] Refactoring mapper to map by scope

2018-07-31 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added inline comments.



Comment at: clang-tools-extra/clang-doc/Representation.h:246
+
+  std::vector ChildNamespaces;
+  std::vector ChildRecords;

ioeric wrote:
> Would a record ever have namespace children? Maybe we should assert that this 
> doesn't happen?
You're right, that's actually not valid in C++. Removed the field.



Comment at: clang-tools-extra/test/clang-doc/bc-linkage.cpp:106
+// CHECK-0-NEXT: 
+// CHECK-0-NEXT:   
+// CHECK-0-NEXT:blob data = 'InnerClass'

ioeric wrote:
> I'm still a bit concerned about hardcoding a lot of USRs in tests. They are 
> not interpretable and generally not interesting for testing. Also as they are 
> auto-generated,   it's hard to tell whether they are actually the desired 
> USRs. I'm concerned because the maintenance is getting higher as number of 
> tests grows - everyone changing USR semantics in the future has to know to 
> regenerate clang-doc tests, this can be annoying and potentially unmanageable 
> when a small change in clang USR requires changes to many test files in 
> clang-tools-extra :( Comparing to the value it brings to test USRs in all 
> tests, I'd still suggest  simply matching them with a `{{.*}}`and only test 
> USRs in few tests where you are actually interested in them.
Okay, I updated it to only check the length -- is that reasonable?


https://reviews.llvm.org/D48341



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


[PATCH] D48341: [clang-doc] Refactoring mapper to map by scope

2018-08-02 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett marked 2 inline comments as done.
juliehockett added inline comments.



Comment at: clang-tools-extra/test/clang-doc/bc-linkage.cpp:106
+// CHECK-0-NEXT: 
+// CHECK-0-NEXT:   
+// CHECK-0-NEXT:blob data = 'InnerClass'

ioeric wrote:
> juliehockett wrote:
> > ioeric wrote:
> > > I'm still a bit concerned about hardcoding a lot of USRs in tests. They 
> > > are not interpretable and generally not interesting for testing. Also as 
> > > they are auto-generated,   it's hard to tell whether they are actually 
> > > the desired USRs. I'm concerned because the maintenance is getting higher 
> > > as number of tests grows - everyone changing USR semantics in the future 
> > > has to know to regenerate clang-doc tests, this can be annoying and 
> > > potentially unmanageable when a small change in clang USR requires 
> > > changes to many test files in clang-tools-extra :( Comparing to the value 
> > > it brings to test USRs in all tests, I'd still suggest  simply matching 
> > > them with a `{{.*}}`and only test USRs in few tests where you are 
> > > actually interested in them.
> > Okay, I updated it to only check the length -- is that reasonable?
> Thanks! 
> 
> FWIW, I wouldn't check the length either as it seems to add too much 
> overhead; I think checking length/USR in one test should get it well covered. 
Possibly for the YAML tests, but for the bitcode ones I also want to check the 
ops, so it's not just the USR text. It's also autogenerated, so the overhead is 
minimal. 

Also, just to reiterate, you'll still likely have to regenerate these if you 
dramatically change the USR spec. The bitcode tests all rely on USRs to write 
to files, and if those USRs change the name of the file the test needs to read 
will also change.


https://reviews.llvm.org/D48341



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


[PATCH] D50208: [clang-doc] Fix unique_ptr error on bots

2018-08-02 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett created this revision.
juliehockett added reviewers: ioeric, lebedev.ri, jakehehrlich, leonardchan.
juliehockett added a project: clang-tools-extra.

Explicitly declare the return unique_ptr instead of using auto type deduction, 
as some of the bots' older compilers don't support some C++11 type deduction 
features.


https://reviews.llvm.org/D50208

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


Index: clang-tools-extra/clang-doc/Serialize.cpp
===
--- clang-tools-extra/clang-doc/Serialize.cpp
+++ clang-tools-extra/clang-doc/Serialize.cpp
@@ -327,23 +327,25 @@
   if (PublicOnly && ((D->isAnonymousNamespace()) ||
  !isPublic(D->getAccess(), D->getLinkageInternal(
 return nullptr;
-  auto I = llvm::make_unique();
+  std::unique_ptr IPtr = llvm::make_unique();
+  NamespaceInfo *I = static_cast(IPtr.get());
   populateInfo(*I, D, FC);
-  return I;
+  return IPtr;
 }
 
 std::unique_ptr emitInfo(const RecordDecl *D, const FullComment *FC,
int LineNumber, llvm::StringRef File,
bool PublicOnly) {
   if (PublicOnly && !isPublic(D->getAccess(), D->getLinkageInternal()))
 return nullptr;
-  auto I = llvm::make_unique();
+  std::unique_ptr IPtr = llvm::make_unique();
+  RecordInfo *I = static_cast(IPtr.get());
   populateSymbolInfo(*I, D, FC, LineNumber, File);
   I->TagType = D->getTagKind();
   parseFields(*I, D, PublicOnly);
   if (const auto *C = dyn_cast(D))
 parseBases(*I, C);
-  return I;
+  return IPtr;
 }
 
 std::unique_ptr emitInfo(const FunctionDecl *D, const FullComment *FC,
@@ -356,13 +358,14 @@
   Func.Access = clang::AccessSpecifier::AS_none;
 
   // Wrap in enclosing scope
-  auto I = llvm::make_unique();
+  std::unique_ptr IPtr = llvm::make_unique();
+  NamespaceInfo *I = static_cast(IPtr.get());
   if (!Func.Namespace.empty())
 I->USR = Func.Namespace[0].USR;
   else
 I->USR = SymbolID();
   I->ChildFunctions.push_back(std::move(Func));
-  return I;
+  return IPtr;
 }
 
 std::unique_ptr emitInfo(const CXXMethodDecl *D, const FullComment *FC,
@@ -380,10 +383,11 @@
   Func.Access = D->getAccess();
 
   // Wrap in enclosing scope
-  auto I = llvm::make_unique();
+  std::unique_ptr IPtr = llvm::make_unique();
+  RecordInfo *I = static_cast(IPtr.get());
   I->USR = ParentUSR;
   I->ChildFunctions.push_back(std::move(Func));
-  return I;
+  return IPtr;
 }
 
 std::unique_ptr emitInfo(const EnumDecl *D, const FullComment *FC,
@@ -419,10 +423,11 @@
   }
 
   // Put in global namespace
-  auto I = llvm::make_unique();
+  std::unique_ptr IPtr = llvm::make_unique();
+  NamespaceInfo *I = static_cast(IPtr.get());
   I->USR = SymbolID();
   I->ChildEnums.push_back(std::move(Enum));
-  return I;
+  return IPtr;
 }
 
 } // namespace serialize


Index: clang-tools-extra/clang-doc/Serialize.cpp
===
--- clang-tools-extra/clang-doc/Serialize.cpp
+++ clang-tools-extra/clang-doc/Serialize.cpp
@@ -327,23 +327,25 @@
   if (PublicOnly && ((D->isAnonymousNamespace()) ||
  !isPublic(D->getAccess(), D->getLinkageInternal(
 return nullptr;
-  auto I = llvm::make_unique();
+  std::unique_ptr IPtr = llvm::make_unique();
+  NamespaceInfo *I = static_cast(IPtr.get());
   populateInfo(*I, D, FC);
-  return I;
+  return IPtr;
 }
 
 std::unique_ptr emitInfo(const RecordDecl *D, const FullComment *FC,
int LineNumber, llvm::StringRef File,
bool PublicOnly) {
   if (PublicOnly && !isPublic(D->getAccess(), D->getLinkageInternal()))
 return nullptr;
-  auto I = llvm::make_unique();
+  std::unique_ptr IPtr = llvm::make_unique();
+  RecordInfo *I = static_cast(IPtr.get());
   populateSymbolInfo(*I, D, FC, LineNumber, File);
   I->TagType = D->getTagKind();
   parseFields(*I, D, PublicOnly);
   if (const auto *C = dyn_cast(D))
 parseBases(*I, C);
-  return I;
+  return IPtr;
 }
 
 std::unique_ptr emitInfo(const FunctionDecl *D, const FullComment *FC,
@@ -356,13 +358,14 @@
   Func.Access = clang::AccessSpecifier::AS_none;
 
   // Wrap in enclosing scope
-  auto I = llvm::make_unique();
+  std::unique_ptr IPtr = llvm::make_unique();
+  NamespaceInfo *I = static_cast(IPtr.get());
   if (!Func.Namespace.empty())
 I->USR = Func.Namespace[0].USR;
   else
 I->USR = SymbolID();
   I->ChildFunctions.push_back(std::move(Func));
-  return I;
+  return IPtr;
 }
 
 std::unique_ptr emitInfo(const CXXMethodDecl *D, const FullComment *FC,
@@ -380,10 +383,11 @@
   Func.Access = D->getAccess();
 
   // Wrap in enclosing scope
-  auto I = llvm::make_unique();
+  std::unique_ptr IPtr = llvm::make_unique();
+  RecordInfo *I = static_cast(IPtr.get());
   I->USR = ParentUSR;
   I->ChildFunctions.push_back(std::move(Func));
-  return I;
+  return IPtr;
 }
 
 std::unique_ptr emitInfo(const EnumDecl *D, const Fu

[PATCH] D50208: [clang-doc] Fix unique_ptr error on bots

2018-08-02 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 158872.

https://reviews.llvm.org/D50208

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


Index: clang-tools-extra/clang-doc/Serialize.cpp
===
--- clang-tools-extra/clang-doc/Serialize.cpp
+++ clang-tools-extra/clang-doc/Serialize.cpp
@@ -329,7 +329,7 @@
 return nullptr;
   auto I = llvm::make_unique();
   populateInfo(*I, D, FC);
-  return I;
+  return std::unique_ptr{std::move(I)};
 }
 
 std::unique_ptr emitInfo(const RecordDecl *D, const FullComment *FC,
@@ -343,7 +343,7 @@
   parseFields(*I, D, PublicOnly);
   if (const auto *C = dyn_cast(D))
 parseBases(*I, C);
-  return I;
+  return std::unique_ptr{std::move(I)};
 }
 
 std::unique_ptr emitInfo(const FunctionDecl *D, const FullComment *FC,
@@ -362,7 +362,7 @@
   else
 I->USR = SymbolID();
   I->ChildFunctions.push_back(std::move(Func));
-  return I;
+  return std::unique_ptr{std::move(I)};
 }
 
 std::unique_ptr emitInfo(const CXXMethodDecl *D, const FullComment *FC,
@@ -383,7 +383,7 @@
   auto I = llvm::make_unique();
   I->USR = ParentUSR;
   I->ChildFunctions.push_back(std::move(Func));
-  return I;
+  return std::unique_ptr{std::move(I)};
 }
 
 std::unique_ptr emitInfo(const EnumDecl *D, const FullComment *FC,
@@ -400,18 +400,16 @@
   if (!Enum.Namespace.empty()) {
 switch (Enum.Namespace[0].RefType) {
 case InfoType::IT_namespace: {
-  std::unique_ptr IPtr = llvm::make_unique();
-  NamespaceInfo *I = static_cast(IPtr.get());
+  auto I = llvm::make_unique();
   I->USR = Enum.Namespace[0].USR;
   I->ChildEnums.push_back(std::move(Enum));
-  return IPtr;
+  return std::unique_ptr{std::move(I)};
 }
 case InfoType::IT_record: {
-  std::unique_ptr IPtr = llvm::make_unique();
-  RecordInfo *I = static_cast(IPtr.get());
+  auto I = llvm::make_unique();
   I->USR = Enum.Namespace[0].USR;
   I->ChildEnums.push_back(std::move(Enum));
-  return IPtr;
+  return std::unique_ptr{std::move(I)};
 }
 default:
   break;
@@ -422,7 +420,7 @@
   auto I = llvm::make_unique();
   I->USR = SymbolID();
   I->ChildEnums.push_back(std::move(Enum));
-  return I;
+  return std::unique_ptr{std::move(I)};
 }
 
 } // namespace serialize


Index: clang-tools-extra/clang-doc/Serialize.cpp
===
--- clang-tools-extra/clang-doc/Serialize.cpp
+++ clang-tools-extra/clang-doc/Serialize.cpp
@@ -329,7 +329,7 @@
 return nullptr;
   auto I = llvm::make_unique();
   populateInfo(*I, D, FC);
-  return I;
+  return std::unique_ptr{std::move(I)};
 }
 
 std::unique_ptr emitInfo(const RecordDecl *D, const FullComment *FC,
@@ -343,7 +343,7 @@
   parseFields(*I, D, PublicOnly);
   if (const auto *C = dyn_cast(D))
 parseBases(*I, C);
-  return I;
+  return std::unique_ptr{std::move(I)};
 }
 
 std::unique_ptr emitInfo(const FunctionDecl *D, const FullComment *FC,
@@ -362,7 +362,7 @@
   else
 I->USR = SymbolID();
   I->ChildFunctions.push_back(std::move(Func));
-  return I;
+  return std::unique_ptr{std::move(I)};
 }
 
 std::unique_ptr emitInfo(const CXXMethodDecl *D, const FullComment *FC,
@@ -383,7 +383,7 @@
   auto I = llvm::make_unique();
   I->USR = ParentUSR;
   I->ChildFunctions.push_back(std::move(Func));
-  return I;
+  return std::unique_ptr{std::move(I)};
 }
 
 std::unique_ptr emitInfo(const EnumDecl *D, const FullComment *FC,
@@ -400,18 +400,16 @@
   if (!Enum.Namespace.empty()) {
 switch (Enum.Namespace[0].RefType) {
 case InfoType::IT_namespace: {
-  std::unique_ptr IPtr = llvm::make_unique();
-  NamespaceInfo *I = static_cast(IPtr.get());
+  auto I = llvm::make_unique();
   I->USR = Enum.Namespace[0].USR;
   I->ChildEnums.push_back(std::move(Enum));
-  return IPtr;
+  return std::unique_ptr{std::move(I)};
 }
 case InfoType::IT_record: {
-  std::unique_ptr IPtr = llvm::make_unique();
-  RecordInfo *I = static_cast(IPtr.get());
+  auto I = llvm::make_unique();
   I->USR = Enum.Namespace[0].USR;
   I->ChildEnums.push_back(std::move(Enum));
-  return IPtr;
+  return std::unique_ptr{std::move(I)};
 }
 default:
   break;
@@ -422,7 +420,7 @@
   auto I = llvm::make_unique();
   I->USR = SymbolID();
   I->ChildEnums.push_back(std::move(Enum));
-  return I;
+  return std::unique_ptr{std::move(I)};
 }
 
 } // namespace serialize
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50208: [clang-doc] Fix unique_ptr error on bots

2018-08-02 Thread Julie Hockett via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE338796: [clang-doc] Fix unique_ptr error on bots (authored 
by juliehockett, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D50208?vs=158872&id=158874#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50208

Files:
  clang-doc/Serialize.cpp


Index: clang-doc/Serialize.cpp
===
--- clang-doc/Serialize.cpp
+++ clang-doc/Serialize.cpp
@@ -329,7 +329,7 @@
 return nullptr;
   auto I = llvm::make_unique();
   populateInfo(*I, D, FC);
-  return I;
+  return std::unique_ptr{std::move(I)};
 }
 
 std::unique_ptr emitInfo(const RecordDecl *D, const FullComment *FC,
@@ -343,7 +343,7 @@
   parseFields(*I, D, PublicOnly);
   if (const auto *C = dyn_cast(D))
 parseBases(*I, C);
-  return I;
+  return std::unique_ptr{std::move(I)};
 }
 
 std::unique_ptr emitInfo(const FunctionDecl *D, const FullComment *FC,
@@ -362,7 +362,7 @@
   else
 I->USR = SymbolID();
   I->ChildFunctions.push_back(std::move(Func));
-  return I;
+  return std::unique_ptr{std::move(I)};
 }
 
 std::unique_ptr emitInfo(const CXXMethodDecl *D, const FullComment *FC,
@@ -383,7 +383,7 @@
   auto I = llvm::make_unique();
   I->USR = ParentUSR;
   I->ChildFunctions.push_back(std::move(Func));
-  return I;
+  return std::unique_ptr{std::move(I)};
 }
 
 std::unique_ptr emitInfo(const EnumDecl *D, const FullComment *FC,
@@ -400,18 +400,16 @@
   if (!Enum.Namespace.empty()) {
 switch (Enum.Namespace[0].RefType) {
 case InfoType::IT_namespace: {
-  std::unique_ptr IPtr = llvm::make_unique();
-  NamespaceInfo *I = static_cast(IPtr.get());
+  auto I = llvm::make_unique();
   I->USR = Enum.Namespace[0].USR;
   I->ChildEnums.push_back(std::move(Enum));
-  return IPtr;
+  return std::unique_ptr{std::move(I)};
 }
 case InfoType::IT_record: {
-  std::unique_ptr IPtr = llvm::make_unique();
-  RecordInfo *I = static_cast(IPtr.get());
+  auto I = llvm::make_unique();
   I->USR = Enum.Namespace[0].USR;
   I->ChildEnums.push_back(std::move(Enum));
-  return IPtr;
+  return std::unique_ptr{std::move(I)};
 }
 default:
   break;
@@ -422,7 +420,7 @@
   auto I = llvm::make_unique();
   I->USR = SymbolID();
   I->ChildEnums.push_back(std::move(Enum));
-  return I;
+  return std::unique_ptr{std::move(I)};
 }
 
 } // namespace serialize


Index: clang-doc/Serialize.cpp
===
--- clang-doc/Serialize.cpp
+++ clang-doc/Serialize.cpp
@@ -329,7 +329,7 @@
 return nullptr;
   auto I = llvm::make_unique();
   populateInfo(*I, D, FC);
-  return I;
+  return std::unique_ptr{std::move(I)};
 }
 
 std::unique_ptr emitInfo(const RecordDecl *D, const FullComment *FC,
@@ -343,7 +343,7 @@
   parseFields(*I, D, PublicOnly);
   if (const auto *C = dyn_cast(D))
 parseBases(*I, C);
-  return I;
+  return std::unique_ptr{std::move(I)};
 }
 
 std::unique_ptr emitInfo(const FunctionDecl *D, const FullComment *FC,
@@ -362,7 +362,7 @@
   else
 I->USR = SymbolID();
   I->ChildFunctions.push_back(std::move(Func));
-  return I;
+  return std::unique_ptr{std::move(I)};
 }
 
 std::unique_ptr emitInfo(const CXXMethodDecl *D, const FullComment *FC,
@@ -383,7 +383,7 @@
   auto I = llvm::make_unique();
   I->USR = ParentUSR;
   I->ChildFunctions.push_back(std::move(Func));
-  return I;
+  return std::unique_ptr{std::move(I)};
 }
 
 std::unique_ptr emitInfo(const EnumDecl *D, const FullComment *FC,
@@ -400,18 +400,16 @@
   if (!Enum.Namespace.empty()) {
 switch (Enum.Namespace[0].RefType) {
 case InfoType::IT_namespace: {
-  std::unique_ptr IPtr = llvm::make_unique();
-  NamespaceInfo *I = static_cast(IPtr.get());
+  auto I = llvm::make_unique();
   I->USR = Enum.Namespace[0].USR;
   I->ChildEnums.push_back(std::move(Enum));
-  return IPtr;
+  return std::unique_ptr{std::move(I)};
 }
 case InfoType::IT_record: {
-  std::unique_ptr IPtr = llvm::make_unique();
-  RecordInfo *I = static_cast(IPtr.get());
+  auto I = llvm::make_unique();
   I->USR = Enum.Namespace[0].USR;
   I->ChildEnums.push_back(std::move(Enum));
-  return IPtr;
+  return std::unique_ptr{std::move(I)};
 }
 default:
   break;
@@ -422,7 +420,7 @@
   auto I = llvm::make_unique();
   I->USR = SymbolID();
   I->ChildEnums.push_back(std::move(Enum));
-  return I;
+  return std::unique_ptr{std::move(I)};
 }
 
 } // namespace serialize
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48909: [clang-doc] Update BitcodeReader to use llvm::Error

2018-08-03 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 159070.

https://reviews.llvm.org/D48909

Files:
  clang-tools-extra/clang-doc/BitcodeReader.cpp
  clang-tools-extra/clang-doc/BitcodeReader.h

Index: clang-tools-extra/clang-doc/BitcodeReader.h
===
--- clang-tools-extra/clang-doc/BitcodeReader.h
+++ clang-tools-extra/clang-doc/BitcodeReader.h
@@ -38,30 +38,31 @@
   enum class Cursor { BadBlock = 1, Record, BlockEnd, BlockBegin };
 
   // Top level parsing
-  bool validateStream();
-  bool readVersion();
-  bool readBlockInfoBlock();
+  llvm::Error validateStream();
+  llvm::Error readVersion();
+  llvm::Error readBlockInfoBlock();
 
   // Read a block of records into a single Info struct, calls readRecord on each
   // record found.
-  template  bool readBlock(unsigned ID, T I);
+  template  llvm::Error readBlock(unsigned ID, T I);
 
   // Step through a block of records to find the next data field.
-  template  bool readSubBlock(unsigned ID, T I);
+  template  llvm::Error readSubBlock(unsigned ID, T I);
 
   // Read record data into the given Info data field, calling the appropriate
   // parseRecord functions to parse and store the data.
-  template  bool readRecord(unsigned ID, T I);
+  template  llvm::Error readRecord(unsigned ID, T I);
 
   // Allocate the relevant type of info and add read data to the object.
-  template  std::unique_ptr createInfo(unsigned ID);
+  template 
+  llvm::Expected> createInfo(unsigned ID);
 
   // Helper function to step through blocks to find and dispatch the next record
   // or block to be read.
   Cursor skipUntilRecordOrBlock(unsigned &BlockOrRecordID);
 
   // Helper function to set up the approriate type of Info.
-  std::unique_ptr readBlockToInfo(unsigned ID);
+  llvm::Expected> readBlockToInfo(unsigned ID);
 
   llvm::BitstreamCursor &Stream;
   Optional BlockInfo;
Index: clang-tools-extra/clang-doc/BitcodeReader.cpp
===
--- clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -17,84 +17,91 @@
 
 using Record = llvm::SmallVector;
 
-bool decodeRecord(Record R, llvm::SmallVectorImpl &Field,
-  llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, llvm::SmallVectorImpl &Field,
+ llvm::StringRef Blob) {
   Field.assign(Blob.begin(), Blob.end());
-  return true;
+  return llvm::Error::success();
 }
 
-bool decodeRecord(Record R, SymbolID &Field, llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, SymbolID &Field, llvm::StringRef Blob) {
   if (R[0] != BitCodeConstants::USRHashSize)
-return false;
+return llvm::make_error("Incorrect USR size.\n",
+   llvm::inconvertibleErrorCode());
 
   // First position in the record is the length of the following array, so we
   // copy the following elements to the field.
   for (int I = 0, E = R[0]; I < E; ++I)
 Field[I] = R[I + 1];
-  return true;
+  return llvm::Error::success();
 }
 
-bool decodeRecord(Record R, bool &Field, llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, bool &Field, llvm::StringRef Blob) {
   Field = R[0] != 0;
-  return true;
+  return llvm::Error::success();
 }
 
-bool decodeRecord(Record R, int &Field, llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, int &Field, llvm::StringRef Blob) {
   if (R[0] > INT_MAX)
-return false;
+return llvm::make_error("Integer too large to parse.\n",
+   llvm::inconvertibleErrorCode());
   Field = (int)R[0];
-  return true;
+  return llvm::Error::success();
 }
 
-bool decodeRecord(Record R, AccessSpecifier &Field, llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, AccessSpecifier &Field,
+ llvm::StringRef Blob) {
   switch (R[0]) {
   case AS_public:
   case AS_private:
   case AS_protected:
   case AS_none:
 Field = (AccessSpecifier)R[0];
-return true;
+return llvm::Error::success();
   default:
-return false;
+return llvm::make_error(
+"Invalid value for AccessSpecifier.\n", llvm::inconvertibleErrorCode());
   }
 }
 
-bool decodeRecord(Record R, TagTypeKind &Field, llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, TagTypeKind &Field, llvm::StringRef Blob) {
   switch (R[0]) {
   case TTK_Struct:
   case TTK_Interface:
   case TTK_Union:
   case TTK_Class:
   case TTK_Enum:
 Field = (TagTypeKind)R[0];
-return true;
+return llvm::Error::success();
   default:
-return false;
+return llvm::make_error(
+"Invalid value for TagTypeKind.\n", llvm::inconvertibleErrorCode());
   }
 }
 
-bool decodeRecord(Record R, llvm::Optional &Field,
-  llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, llvm::Optional &Field,
+ llvm::StringRef Blob) {
   if (R[0] > INT_MAX)
-return false;
+return ll

[PATCH] D48909: [clang-doc] Update BitcodeReader to use llvm::Error

2018-08-03 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 159071.
juliehockett marked 2 inline comments as done.

https://reviews.llvm.org/D48909

Files:
  clang-tools-extra/clang-doc/BitcodeReader.cpp
  clang-tools-extra/clang-doc/BitcodeReader.h

Index: clang-tools-extra/clang-doc/BitcodeReader.h
===
--- clang-tools-extra/clang-doc/BitcodeReader.h
+++ clang-tools-extra/clang-doc/BitcodeReader.h
@@ -22,6 +22,7 @@
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Bitcode/BitstreamReader.h"
+#include "llvm/Support/Error.h"
 
 namespace clang {
 namespace doc {
@@ -38,30 +39,31 @@
   enum class Cursor { BadBlock = 1, Record, BlockEnd, BlockBegin };
 
   // Top level parsing
-  bool validateStream();
-  bool readVersion();
-  bool readBlockInfoBlock();
+  llvm::Error validateStream();
+  llvm::Error readVersion();
+  llvm::Error readBlockInfoBlock();
 
   // Read a block of records into a single Info struct, calls readRecord on each
   // record found.
-  template  bool readBlock(unsigned ID, T I);
+  template  llvm::Error readBlock(unsigned ID, T I);
 
   // Step through a block of records to find the next data field.
-  template  bool readSubBlock(unsigned ID, T I);
+  template  llvm::Error readSubBlock(unsigned ID, T I);
 
   // Read record data into the given Info data field, calling the appropriate
   // parseRecord functions to parse and store the data.
-  template  bool readRecord(unsigned ID, T I);
+  template  llvm::Error readRecord(unsigned ID, T I);
 
   // Allocate the relevant type of info and add read data to the object.
-  template  std::unique_ptr createInfo(unsigned ID);
+  template 
+  llvm::Expected> createInfo(unsigned ID);
 
   // Helper function to step through blocks to find and dispatch the next record
   // or block to be read.
   Cursor skipUntilRecordOrBlock(unsigned &BlockOrRecordID);
 
   // Helper function to set up the approriate type of Info.
-  std::unique_ptr readBlockToInfo(unsigned ID);
+  llvm::Expected> readBlockToInfo(unsigned ID);
 
   llvm::BitstreamCursor &Stream;
   Optional BlockInfo;
Index: clang-tools-extra/clang-doc/BitcodeReader.cpp
===
--- clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -10,91 +10,99 @@
 #include "BitcodeReader.h"
 #include "llvm/ADT/IndexedMap.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace clang {
 namespace doc {
 
 using Record = llvm::SmallVector;
 
-bool decodeRecord(Record R, llvm::SmallVectorImpl &Field,
-  llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, llvm::SmallVectorImpl &Field,
+ llvm::StringRef Blob) {
   Field.assign(Blob.begin(), Blob.end());
-  return true;
+  return llvm::Error::success();
 }
 
-bool decodeRecord(Record R, SymbolID &Field, llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, SymbolID &Field, llvm::StringRef Blob) {
   if (R[0] != BitCodeConstants::USRHashSize)
-return false;
+return llvm::make_error("Incorrect USR size.\n",
+   llvm::inconvertibleErrorCode());
 
   // First position in the record is the length of the following array, so we
   // copy the following elements to the field.
   for (int I = 0, E = R[0]; I < E; ++I)
 Field[I] = R[I + 1];
-  return true;
+  return llvm::Error::success();
 }
 
-bool decodeRecord(Record R, bool &Field, llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, bool &Field, llvm::StringRef Blob) {
   Field = R[0] != 0;
-  return true;
+  return llvm::Error::success();
 }
 
-bool decodeRecord(Record R, int &Field, llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, int &Field, llvm::StringRef Blob) {
   if (R[0] > INT_MAX)
-return false;
+return llvm::make_error("Integer too large to parse.\n",
+   llvm::inconvertibleErrorCode());
   Field = (int)R[0];
-  return true;
+  return llvm::Error::success();
 }
 
-bool decodeRecord(Record R, AccessSpecifier &Field, llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, AccessSpecifier &Field,
+ llvm::StringRef Blob) {
   switch (R[0]) {
   case AS_public:
   case AS_private:
   case AS_protected:
   case AS_none:
 Field = (AccessSpecifier)R[0];
-return true;
+return llvm::Error::success();
   default:
-return false;
+return llvm::make_error(
+"Invalid value for AccessSpecifier.\n", llvm::inconvertibleErrorCode());
   }
 }
 
-bool decodeRecord(Record R, TagTypeKind &Field, llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, TagTypeKind &Field, llvm::StringRef Blob) {
   switch (R[0]) {
   case TTK_Struct:
   case TTK_Interface:
   case TTK_Union:
   case TTK_Class:
   case TTK_Enum:
 Field = (TagTypeKind)R[0];
-return t

[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 N

[PATCH] D41102: Setup clang-doc frontend framework

2018-02-06 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 133108.
juliehockett marked 27 inline comments as done.
juliehockett edited the summary of this revision.
juliehockett edited projects, added clang-tools-extra; removed clang.
juliehockett added a comment.

  1. Moved the tool to clang-tools-extra
1. Refactored tool to have two stages to the frontend parsing: the mapping 
stage (this patch), which uses ASTMatchers to extract declarations and 
serialize each into an individual key-value pair in the ExecutionContext, and 
the reducing stage (next patch, not yet implemented), which will take the 
records in the ExecutionContext and reduce them by key to produce and write the 
final output of the frontend.
  1. Replaced the YAML serialization with bitcode serialization. Will update 
again with tests once I've implemented a simple decoder for the serial bitcode 
format.
  2. Streamlined the emit*Info function call path.
  3. Introduced a new layer into the Info inheritance to better represent each 
level.


https://reviews.llvm.org/D41102

Files:
  CMakeLists.txt
  clang-doc/CMakeLists.txt
  clang-doc/ClangDoc.cpp
  clang-doc/ClangDoc.h
  clang-doc/ClangDocBinary.cpp
  clang-doc/ClangDocBinary.h
  clang-doc/ClangDocMapper.cpp
  clang-doc/ClangDocMapper.h
  clang-doc/tool/CMakeLists.txt
  clang-doc/tool/ClangDocMain.cpp
  docs/clang-doc.rst

Index: docs/clang-doc.rst
===
--- /dev/null
+++ docs/clang-doc.rst
@@ -0,0 +1,13 @@
+===
+Clang-Doc
+===
+
+.. contents::
+
+Intro
+
+Setup
+=
+
+Use
+
Index: clang-doc/tool/ClangDocMain.cpp
===
--- /dev/null
+++ clang-doc/tool/ClangDocMain.cpp
@@ -0,0 +1,88 @@
+//===-- ClangDocMain.cpp - Clangdoc -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ClangDoc.h"
+#include "clang/AST/AST.h"
+#include "clang/AST/Decl.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchersInternal.h"
+#include "clang/Driver/Options.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Execution.h"
+#include "clang/Tooling/StandaloneExecution.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/APFloat.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Process.h"
+#include "llvm/Support/Signals.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace clang::ast_matchers;
+using namespace clang::tooling;
+using namespace clang;
+using namespace llvm;
+
+namespace {
+
+static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
+static cl::OptionCategory ClangDocCategory("clang-doc options");
+
+static cl::opt DumpResult("dump", cl::desc("Dump results to stdout."),
+cl::init(false), cl::cat(ClangDocCategory));
+
+static cl::opt OmitFilenames("omit-filenames", cl::desc("Omit filenames in output."),
+   cl::init(false), cl::cat(ClangDocCategory));
+
+static cl::opt DoxygenOnly("doxygen", cl::desc("Use only doxygen-style comments to generate docs."),
+cl::init(false), cl::cat(ClangDocCategory));
+
+} // namespace
+
+int main(int argc, const char **argv) {
+  sys::PrintStackTraceOnErrorSignal(argv[0]);
+
+  auto Exec = clang::tooling::createExecutorFromCommandLineArgs(
+argc, argv, ClangDocCategory);
+
+  if (!Exec) {
+errs() << toString(Exec.takeError()) << "\n";
+return 1;
+  }
+
+  MatchFinder Finder;
+  ExecutionContext *ECtx = Exec->get()->getExecutionContext();
+  
+  doc::ClangDocCallback NCallback("namespace", *ECtx, OmitFilenames);
+  Finder.addMatcher(namespaceDecl().bind("namespace"), &NCallback);
+  doc::ClangDocCallback RCallback("record", *ECtx, OmitFilenames);
+  Finder.addMatcher(recordDecl().bind("record"), &RCallback);
+  doc::ClangDocCallback ECallback("enum", *ECtx, OmitFilenames);
+  Finder.addMatcher(enumDecl().bind("enum"), &ECallback);
+  doc::ClangDocCallback MCallback("method", *ECtx, OmitFilenames);
+  Finder.addMatcher(cxxMethodDecl(isUserProvided()).bind("method"), &MCallback);
+  doc::ClangDocCallback FCallback("function", *ECtx, OmitFilenames);
+  Finder.addMatcher(functionDecl(unless(cxxMethodDecl())).bind("function"), &FCallback);
+  
+  ArgumentsAdjuster ArgAdjuster;
+  if (!DoxygenOnly)
+ArgAdjuster = combineAdjusters(getInsertArgumentAdjuster("-fparse-all-comments", tooling::ArgumentInsertPosition::BEGIN), ArgAdjuster);
+  auto Err = Exec->get()->execute(newFrontendActionFactory(&Finder), ArgAdjuster);
+  if (Err)
+errs() << toString(std::move(Err)) << "\n";
+
+  if (DumpResult)
+Exec->get()->g

[PATCH] D41102: Setup clang-doc frontend framework

2018-02-06 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added inline comments.



Comment at: tools/clang-doc/ClangDoc.h:29
+struct ClangDocContext {
+  // Which format in which to emit representation.
+  OutFormat EmitFormat;

sammccall wrote:
> juliehockett wrote:
> > sammccall wrote:
> > > Is this the intermediate representation referred to in the design doc, or 
> > > the final output format?
> > > 
> > > If the former, why two formats rather than picking one?
> > > YAML is nice for being usable by out-of-tree tools (though not as nice as 
> > > JSON). But it seems like providing YAML as a trivial backend format would 
> > > fit well?
> > > Bitcode is presumably more space-efficient - if this is significant in 
> > > practice it seems like a better choice.
> > That's the idea -- for developing purposes, I wrote up the YAML output 
> > first for this patch, and there will be a follow-on patch expanding the 
> > bitcode/binary output. I've updated the flags to default to the binary, 
> > with an option to dump the yaml (rather than the other way around).
> What's still not clear to me is: is YAML a) a "real" intermediate format, or 
> b) just a debug representation?
> 
> I would suggest for orthogonality that there only be one intermediate format, 
> and that any debug version be generated from it. In practice I guess this 
> means:
>  - the reporter builds the in-memory representation
>  - you can serialize/deserialize memory representation to the IR (bitcode)
>  - you can serialize memory representation to debug representation (YAML) but 
> not parse
>  - maybe the clang-doc core should *only* know about IR, and YAML should be 
> produced in the same way e.g. HTML would be?
> 
> This does pose a short-term problem: the canonical IR is bitcode, we need 
> YAML for the lit tests, and we don't have the decoder/transformer part yet. 
> This could be solved either by using YAML as the IR *for now* and switching 
> later, or by adding a simple decoder now.
> Either way it points to the *reporter* not having an output format option, 
> and having to support two formats.
> 
> WDYT? I might be missing something here.
The mapper now only has the ability to write to bitcode -- I'm working on 
writing up a simple decoder to use for testing and will update the patch again 
once that's working. Once that's in place, that will also serve the purpose of 
being the foundation for how we're going to read the bitcode into the backend 
to produce actual docs. Does that make sense?



Comment at: tools/clang-doc/ClangDoc.h:33
+
+class ClangDocVisitor : public RecursiveASTVisitor {
+public:

sammccall wrote:
> juliehockett wrote:
> > jakehehrlich wrote:
> > > sammccall wrote:
> > > > This API makes essentially everything public. Is that the intent?
> > > > 
> > > > It seems like `ClangDocVisitor` is a detail, and the operation you want 
> > > > to expose is "extract doc from this AST into this reporter" or maybe 
> > > > "create an AST consumer that feeds this reporter".
> > > > 
> > > > It would be useful to have an API to extract documentation from 
> > > > individual AST nodes (e.g. a Decl). But I'd be nervous about trying to 
> > > > use the classes exposed here to do that. If it's efficiently possible, 
> > > > it'd be nice to expose a function.
> > > > (one use case for this is clangd)
> > > Correct me if I'm wrong but I believe that everything needs to be public 
> > > in this case because the base class needs to be able to call them. So the 
> > > visit methods all need to be public.
> > Yes to the `Visit*Decl` methods being public because of the base class.
> > 
> > That said, I shifted a few things around here and implemented it as a 
> > `MatcherFinder` instead of a `RecursiveASTVisitor`. The change will allow 
> > us to make most of the methods private, and have the ability to fairly 
> > easily implement an API for pulling a specific node (e.g. by name or by 
> > decl type). As far as I understand (and please correct me if I'm wrong), 
> > the matcher traverses the tree in a similar way. This will also make 
> > mapping through individual nodes easier.
> Sorry for being vague - yes overridden or "CRTP-overridden" methods may need 
> to be public.
> I meant that the classes themselves don't need to be exposed, I think. (The 
> header could just expose a function to create the needed ones, that returns 
> `unique_ptr`
> 
> There are now fewer classes exposed here, but I think most/all of them can 
> still reasonably be hidden.
So I've restructured this again and collapsed all of the tooling things into to 
ExecutionContext. The only thing exposed here now is the callback, which is 
registered on the matcher. Is there anything else I'm missing?



Comment at: tools/clang-doc/ClangDocReporter.h:87
   std::string MangledName;
   std::string DefinitionFile;
   std::string ReturnType;

Athosvk wrote:
> Seems common to almost all Info structs, so you can probably mov

[PATCH] D42918: [clang-tidy] Update fuchsia-multiple-inheritance to check for templates

2018-02-06 Thread Julie Hockett via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL324432: [clang-tidy] Update fuchsia-multiple-inheritance to 
check for templates (authored by juliehockett, committed by ).
Herald added subscribers: llvm-commits, klimek.

Changed prior to commit:
  https://reviews.llvm.org/D42918?vs=132860&id=133112#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D42918

Files:
  clang-tools-extra/trunk/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/fuchsia-multiple-inheritance.cpp


Index: clang-tools-extra/trunk/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
@@ -64,7 +64,7 @@
 
   // To be an interface, all base classes must be interfaces as well.
   for (const auto &I : Node->bases()) {
-if (I.isVirtual()) continue;  
+if (I.isVirtual()) continue;
 const auto *Ty = I.getType()->getAs();
 assert(Ty && "RecordType of base class is unknown");
 const RecordDecl *D = Ty->getDecl()->getDefinition();
@@ -96,7 +96,7 @@
 // concrete classes
 unsigned NumConcrete = 0;
 for (const auto &I : D->bases()) {
-  if (I.isVirtual()) continue;
+  if (I.isVirtual() || I.getType()->getAs()) 
continue;
   const auto *Ty = I.getType()->getAs();
   assert(Ty && "RecordType of base class is unknown");
   const auto *Base = cast(Ty->getDecl()->getDefinition());
Index: clang-tools-extra/trunk/test/clang-tidy/fuchsia-multiple-inheritance.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/fuchsia-multiple-inheritance.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/fuchsia-multiple-inheritance.cpp
@@ -129,3 +129,5 @@
 struct V14 : virtual Static_Base_2 { static void g(); };
 struct D8 : V13, V14 {};
 
+template struct A : T {};
+template struct B : virtual T {};


Index: clang-tools-extra/trunk/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
@@ -64,7 +64,7 @@
 
   // To be an interface, all base classes must be interfaces as well.
   for (const auto &I : Node->bases()) {
-if (I.isVirtual()) continue;  
+if (I.isVirtual()) continue;
 const auto *Ty = I.getType()->getAs();
 assert(Ty && "RecordType of base class is unknown");
 const RecordDecl *D = Ty->getDecl()->getDefinition();
@@ -96,7 +96,7 @@
 // concrete classes
 unsigned NumConcrete = 0;
 for (const auto &I : D->bases()) {
-  if (I.isVirtual()) continue;
+  if (I.isVirtual() || I.getType()->getAs()) continue;
   const auto *Ty = I.getType()->getAs();
   assert(Ty && "RecordType of base class is unknown");
   const auto *Base = cast(Ty->getDecl()->getDefinition());
Index: clang-tools-extra/trunk/test/clang-tidy/fuchsia-multiple-inheritance.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/fuchsia-multiple-inheritance.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/fuchsia-multiple-inheritance.cpp
@@ -129,3 +129,5 @@
 struct V14 : virtual Static_Base_2 { static void g(); };
 struct D8 : V13, V14 {};
 
+template struct A : T {};
+template struct B : virtual T {};
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41102: Setup clang-doc frontend framework

2018-02-09 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 133714.
juliehockett marked 6 inline comments as done.
juliehockett added a comment.

1. Implementing the bitstream decoder (and fixing the encoder)
2. Setting up new tests for the mapper output
3. Fixing comments


https://reviews.llvm.org/D41102

Files:
  CMakeLists.txt
  clang-doc/CMakeLists.txt
  clang-doc/ClangDoc.cpp
  clang-doc/ClangDoc.h
  clang-doc/ClangDocBinary.cpp
  clang-doc/ClangDocBinary.h
  clang-doc/ClangDocMapper.cpp
  clang-doc/ClangDocMapper.h
  clang-doc/ClangDocRepresentation.h
  clang-doc/tool/CMakeLists.txt
  clang-doc/tool/ClangDocMain.cpp
  docs/clang-doc.rst
  test/CMakeLists.txt
  test/clang-doc/Inputs/enum_test.cpp
  test/clang-doc/Inputs/namespace_test.cpp
  test/clang-doc/Inputs/record_test.cpp
  test/clang-doc/mapper-namespace.cpp
  test/clang-doc/mapper-type.cpp

Index: test/clang-doc/mapper-type.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-type.cpp
@@ -0,0 +1,137 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc  --dump --omit-filenames -doxygen -p %t %t/test.cpp | FileCheck %s
+
+union A { int X; int Y; };
+// CHECK: ---
+// CHECK: KEY: A
+// CHECK: FullyQualifiedName: A
+// CHECK: Name: A
+// CHECK: TagType: 2
+// CHECK: ID: Member
+// CHECK: Type: int
+// CHECK: Name: A::X
+// CHECK: Access: 3
+// CHECK: ID: Member
+// CHECK: Type: int
+// CHECK: Name: A::Y
+// CHECK: Access: 3
+// CHECK: ---
+// CHECK: KEY: A::A
+// CHECK: FullyQualifiedName: A::A
+// CHECK: Name: A
+// CHECK: Namespace: A
+
+enum B { X, Y };
+// CHECK: ---
+// CHECK: KEY: B
+// CHECK: FullyQualifiedName: B
+// CHECK: Name: B
+// CHECK: ID: Member
+// CHECK: Type: X
+// CHECK: Access: 3
+// CHECK: ID: Member
+// CHECK: Type: Y
+// CHECK: Access: 3
+
+struct C { int i; };
+// CHECK: ---
+// CHECK: KEY: C
+// CHECK: FullyQualifiedName: C
+// CHECK: Name: C
+// CHECK: ID: Member
+// CHECK: Type: int
+// CHECK: Name: C::i
+// CHECK: Access: 3
+// CHECK: ---
+// CHECK: KEY: C::C
+// CHECK: FullyQualifiedName: C::C
+// CHECK: Name: C
+// CHECK: Namespace: C
+
+class D {};
+// CHECK: ---
+// CHECK: KEY: D
+// CHECK: FullyQualifiedName: D
+// CHECK: Name: D
+// CHECK: TagType: 3
+// CHECK: ---
+// CHECK: KEY: D::D
+// CHECK: FullyQualifiedName: D::D
+// CHECK: Name: D
+// CHECK: Namespace: D
+
+class E {
+// CHECK: ---
+// CHECK: KEY: E
+// CHECK: FullyQualifiedName: E
+// CHECK: Name: E
+// CHECK: TagType: 3
+// CHECK: ---
+// CHECK: KEY: E::E
+// CHECK: FullyQualifiedName: E::E
+// CHECK: Name: E
+// CHECK: Namespace: E
+
+public:
+	E() {}
+// CHECK: ---
+// CHECK: KEY: _ZN1EC1Ev
+// CHECK: FullyQualifiedName: E::E
+// CHECK: Name: E
+// CHECK: Namespace: E
+// CHECK: MangledName: _ZN1EC1Ev
+// CHECK: Parent: E
+// CHECK: ID: Return
+// CHECK: Type: void
+// CHECK: Access: 3
+
+	 ~E() {}
+// CHECK: ---
+// CHECK: KEY: _ZN1ED1Ev
+// CHECK: FullyQualifiedName: E::~E
+// CHECK: Name: ~E
+// CHECK: Namespace: E
+// CHECK: MangledName: _ZN1ED1Ev
+// CHECK: Parent: E
+// CHECK: ID: Return
+// CHECK: Type: void
+// CHECK: Access: 3
+
+protected:
+	void ProtectedMethod();
+// CHECK:  ---
+// CHECK: KEY: _ZN1E15ProtectedMethodEv
+// CHECK: FullyQualifiedName: _ZN1E15ProtectedMethodEv
+// CHECK: Name: ProtectedMethod
+// CHECK: Namespace: E
+};
+
+void E::ProtectedMethod() {}
+// CHECK: ---
+// CHECK: KEY: _ZN1E15ProtectedMethodEv
+// CHECK: FullyQualifiedName: E::ProtectedMethod
+// CHECK: Name: ProtectedMethod
+// CHECK: Namespace: E
+// CHECK: MangledName: _ZN1E15ProtectedMethodEv
+// CHECK: Parent: E
+// CHECK: ID: Return
+// CHECK: Type: void
+// CHECK: Access: 3
+// CHECK: Access: 1
+
+class F : virtual private D, public E {};
+// CHECK: ---
+// CHECK: KEY: F
+// CHECK: FullyQualifiedName: F
+// CHECK: Name: F
+// CHECK: TagType: 3
+// CHECK: Parent: class E
+// CHECK: VParent: class D
+// CHECK: ---
+// CHECK: KEY: F::F
+// CHECK: FullyQualifiedName: F::F
+// CHECK: Name: F
+// CHECK: Namespace: F
Index: test/clang-doc/mapper-namespace.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-namespace.cpp
@@ -0,0 +1,70 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp | FileCheck %s
+
+namespace A {
+// CHECK: ---
+// CHECK: KEY: A
+// CHECK: FullyQualifiedName: A
+// CHECK: Name: A
+
+void f() {};
+// CHECK: ---
+// CHECK: KEY: _ZN1A1fEv
+// CHECK: FullyQualifiedName: A::f
+// CHECK: Name: f
+// CHECK: Namespace: A
+// CHECK: MangledName: _ZN1A1fEv
+// CHECK: ID: Return
+// CHECK: Type: void
+// CHECK: Access: 3
+// CHECK: Access: 3
+
+} // A
+
+namespace A {
+// CHECK: ---
+// CHECK: KEY: A
+// CHECK: FullyQualifiedName: A
+// CHECK: Name: A
+
+namespace B {
+// CHECK: ---
+// CHECK: KEY: A::B
+// CHECK: FullyQualifiedName: A::B
+// CHECK: 

[PATCH] D41102: Setup clang-doc frontend framework

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

Updating documentation


https://reviews.llvm.org/D41102

Files:
  CMakeLists.txt
  clang-doc/CMakeLists.txt
  clang-doc/ClangDoc.cpp
  clang-doc/ClangDoc.h
  clang-doc/ClangDocBinary.cpp
  clang-doc/ClangDocBinary.h
  clang-doc/ClangDocMapper.cpp
  clang-doc/ClangDocMapper.h
  clang-doc/ClangDocRepresentation.h
  clang-doc/tool/CMakeLists.txt
  clang-doc/tool/ClangDocMain.cpp
  docs/clang-doc.rst
  test/CMakeLists.txt
  test/clang-doc/mapper-namespace.cpp
  test/clang-doc/mapper-type.cpp

Index: test/clang-doc/mapper-type.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-type.cpp
@@ -0,0 +1,137 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc  --dump --omit-filenames -doxygen -p %t %t/test.cpp | FileCheck %s
+
+union A { int X; int Y; };
+// CHECK: ---
+// CHECK: KEY: A
+// CHECK: FullyQualifiedName: A
+// CHECK: Name: A
+// CHECK: TagType: 2
+// CHECK: ID: Member
+// CHECK: Type: int
+// CHECK: Name: A::X
+// CHECK: Access: 3
+// CHECK: ID: Member
+// CHECK: Type: int
+// CHECK: Name: A::Y
+// CHECK: Access: 3
+// CHECK: ---
+// CHECK: KEY: A::A
+// CHECK: FullyQualifiedName: A::A
+// CHECK: Name: A
+// CHECK: Namespace: A
+
+enum B { X, Y };
+// CHECK: ---
+// CHECK: KEY: B
+// CHECK: FullyQualifiedName: B
+// CHECK: Name: B
+// CHECK: ID: Member
+// CHECK: Type: X
+// CHECK: Access: 3
+// CHECK: ID: Member
+// CHECK: Type: Y
+// CHECK: Access: 3
+
+struct C { int i; };
+// CHECK: ---
+// CHECK: KEY: C
+// CHECK: FullyQualifiedName: C
+// CHECK: Name: C
+// CHECK: ID: Member
+// CHECK: Type: int
+// CHECK: Name: C::i
+// CHECK: Access: 3
+// CHECK: ---
+// CHECK: KEY: C::C
+// CHECK: FullyQualifiedName: C::C
+// CHECK: Name: C
+// CHECK: Namespace: C
+
+class D {};
+// CHECK: ---
+// CHECK: KEY: D
+// CHECK: FullyQualifiedName: D
+// CHECK: Name: D
+// CHECK: TagType: 3
+// CHECK: ---
+// CHECK: KEY: D::D
+// CHECK: FullyQualifiedName: D::D
+// CHECK: Name: D
+// CHECK: Namespace: D
+
+class E {
+// CHECK: ---
+// CHECK: KEY: E
+// CHECK: FullyQualifiedName: E
+// CHECK: Name: E
+// CHECK: TagType: 3
+// CHECK: ---
+// CHECK: KEY: E::E
+// CHECK: FullyQualifiedName: E::E
+// CHECK: Name: E
+// CHECK: Namespace: E
+
+public:
+	E() {}
+// CHECK: ---
+// CHECK: KEY: _ZN1EC1Ev
+// CHECK: FullyQualifiedName: E::E
+// CHECK: Name: E
+// CHECK: Namespace: E
+// CHECK: MangledName: _ZN1EC1Ev
+// CHECK: Parent: E
+// CHECK: ID: Return
+// CHECK: Type: void
+// CHECK: Access: 3
+
+	 ~E() {}
+// CHECK: ---
+// CHECK: KEY: _ZN1ED1Ev
+// CHECK: FullyQualifiedName: E::~E
+// CHECK: Name: ~E
+// CHECK: Namespace: E
+// CHECK: MangledName: _ZN1ED1Ev
+// CHECK: Parent: E
+// CHECK: ID: Return
+// CHECK: Type: void
+// CHECK: Access: 3
+
+protected:
+	void ProtectedMethod();
+// CHECK:  ---
+// CHECK: KEY: _ZN1E15ProtectedMethodEv
+// CHECK: FullyQualifiedName: _ZN1E15ProtectedMethodEv
+// CHECK: Name: ProtectedMethod
+// CHECK: Namespace: E
+};
+
+void E::ProtectedMethod() {}
+// CHECK: ---
+// CHECK: KEY: _ZN1E15ProtectedMethodEv
+// CHECK: FullyQualifiedName: E::ProtectedMethod
+// CHECK: Name: ProtectedMethod
+// CHECK: Namespace: E
+// CHECK: MangledName: _ZN1E15ProtectedMethodEv
+// CHECK: Parent: E
+// CHECK: ID: Return
+// CHECK: Type: void
+// CHECK: Access: 3
+// CHECK: Access: 1
+
+class F : virtual private D, public E {};
+// CHECK: ---
+// CHECK: KEY: F
+// CHECK: FullyQualifiedName: F
+// CHECK: Name: F
+// CHECK: TagType: 3
+// CHECK: Parent: class E
+// CHECK: VParent: class D
+// CHECK: ---
+// CHECK: KEY: F::F
+// CHECK: FullyQualifiedName: F::F
+// CHECK: Name: F
+// CHECK: Namespace: F
Index: test/clang-doc/mapper-namespace.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-namespace.cpp
@@ -0,0 +1,70 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp | FileCheck %s
+
+namespace A {
+// CHECK: ---
+// CHECK: KEY: A
+// CHECK: FullyQualifiedName: A
+// CHECK: Name: A
+
+void f() {};
+// CHECK: ---
+// CHECK: KEY: _ZN1A1fEv
+// CHECK: FullyQualifiedName: A::f
+// CHECK: Name: f
+// CHECK: Namespace: A
+// CHECK: MangledName: _ZN1A1fEv
+// CHECK: ID: Return
+// CHECK: Type: void
+// CHECK: Access: 3
+// CHECK: Access: 3
+
+} // A
+
+namespace A {
+// CHECK: ---
+// CHECK: KEY: A
+// CHECK: FullyQualifiedName: A
+// CHECK: Name: A
+
+namespace B {
+// CHECK: ---
+// CHECK: KEY: A::B
+// CHECK: FullyQualifiedName: A::B
+// CHECK: Name: B
+// CHECK: Namespace: A
+
+enum E { X };
+// CHECK: ---
+// CHECK: KEY: A::B::E
+// CHECK: FullyQualifiedName: A::B::E
+// CHECK: Name: E
+// CHECK: Namespace: A::B
+// CHECK: ID: Member
+// CHECK: Type: A::B::X
+// CHECK: Access: 3
+
+E func(int i) { 
+	return X;

[PATCH] D43223: [clang-tidy] Update fuchsia-multiple-inheritance to not fail

2018-02-12 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett created this revision.
juliehockett added reviewers: aaron.ballman, hokein, alexfh.
juliehockett added a project: clang-tools-extra.
Herald added a subscriber: xazax.hun.

Updating the fuchsia-multiple-inheritance to gracefully handle unknown record 
types (e.g. templatized classes) by simply continuing, rather than asserting 
and failing.

Fixes PR36052.


https://reviews.llvm.org/D43223

Files:
  clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
  test/clang-tidy/fuchsia-multiple-inheritance.cpp


Index: test/clang-tidy/fuchsia-multiple-inheritance.cpp
===
--- test/clang-tidy/fuchsia-multiple-inheritance.cpp
+++ test/clang-tidy/fuchsia-multiple-inheritance.cpp
@@ -131,3 +131,6 @@
 
 template struct A : T {};
 template struct B : virtual T {};
+
+template struct C {};
+template struct D : C {};
Index: clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
===
--- clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
+++ clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
@@ -66,7 +66,7 @@
   for (const auto &I : Node->bases()) {
 if (I.isVirtual()) continue;
 const auto *Ty = I.getType()->getAs();
-assert(Ty && "RecordType of base class is unknown");
+if (!Ty) continue;
 const RecordDecl *D = Ty->getDecl()->getDefinition();
 if (!D) continue;
 const auto *Base = cast(D);
@@ -96,18 +96,18 @@
 // concrete classes
 unsigned NumConcrete = 0;
 for (const auto &I : D->bases()) {
-  if (I.isVirtual() || I.getType()->getAs()) 
continue;
+  if (I.isVirtual()) continue;
   const auto *Ty = I.getType()->getAs();
-  assert(Ty && "RecordType of base class is unknown");
+  if (!Ty) continue;
   const auto *Base = cast(Ty->getDecl()->getDefinition());
   if (!isInterface(Base)) NumConcrete++;
 }
 
 // Check virtual bases to see if there is more than one concrete 
 // non-virtual base.
 for (const auto &V : D->vbases()) {
   const auto *Ty = V.getType()->getAs();
-  assert(Ty && "RecordType of base class is unknown");
+  if (!Ty) continue;
   const auto *Base = cast(Ty->getDecl()->getDefinition());
   if (!isInterface(Base)) NumConcrete++;
 }


Index: test/clang-tidy/fuchsia-multiple-inheritance.cpp
===
--- test/clang-tidy/fuchsia-multiple-inheritance.cpp
+++ test/clang-tidy/fuchsia-multiple-inheritance.cpp
@@ -131,3 +131,6 @@
 
 template struct A : T {};
 template struct B : virtual T {};
+
+template struct C {};
+template struct D : C {};
Index: clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
===
--- clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
+++ clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
@@ -66,7 +66,7 @@
   for (const auto &I : Node->bases()) {
 if (I.isVirtual()) continue;
 const auto *Ty = I.getType()->getAs();
-assert(Ty && "RecordType of base class is unknown");
+if (!Ty) continue;
 const RecordDecl *D = Ty->getDecl()->getDefinition();
 if (!D) continue;
 const auto *Base = cast(D);
@@ -96,18 +96,18 @@
 // concrete classes
 unsigned NumConcrete = 0;
 for (const auto &I : D->bases()) {
-  if (I.isVirtual() || I.getType()->getAs()) continue;
+  if (I.isVirtual()) continue;
   const auto *Ty = I.getType()->getAs();
-  assert(Ty && "RecordType of base class is unknown");
+  if (!Ty) continue;
   const auto *Base = cast(Ty->getDecl()->getDefinition());
   if (!isInterface(Base)) NumConcrete++;
 }
 
 // Check virtual bases to see if there is more than one concrete 
 // non-virtual base.
 for (const auto &V : D->vbases()) {
   const auto *Ty = V.getType()->getAs();
-  assert(Ty && "RecordType of base class is unknown");
+  if (!Ty) continue;
   const auto *Base = cast(Ty->getDecl()->getDefinition());
   if (!isInterface(Base)) NumConcrete++;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43223: [clang-tidy] Update fuchsia-multiple-inheritance to not fail

2018-02-13 Thread Julie Hockett via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE325015: [clang-tidy] Update fuchsia-multiple-inheritance 
to not fail (authored by juliehockett, committed by ).

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43223

Files:
  clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
  test/clang-tidy/fuchsia-multiple-inheritance.cpp


Index: clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
===
--- clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
+++ clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
@@ -66,7 +66,7 @@
   for (const auto &I : Node->bases()) {
 if (I.isVirtual()) continue;
 const auto *Ty = I.getType()->getAs();
-assert(Ty && "RecordType of base class is unknown");
+if (!Ty) continue;
 const RecordDecl *D = Ty->getDecl()->getDefinition();
 if (!D) continue;
 const auto *Base = cast(D);
@@ -96,18 +96,18 @@
 // concrete classes
 unsigned NumConcrete = 0;
 for (const auto &I : D->bases()) {
-  if (I.isVirtual() || I.getType()->getAs()) 
continue;
+  if (I.isVirtual()) continue;
   const auto *Ty = I.getType()->getAs();
-  assert(Ty && "RecordType of base class is unknown");
+  if (!Ty) continue;
   const auto *Base = cast(Ty->getDecl()->getDefinition());
   if (!isInterface(Base)) NumConcrete++;
 }
 
 // Check virtual bases to see if there is more than one concrete 
 // non-virtual base.
 for (const auto &V : D->vbases()) {
   const auto *Ty = V.getType()->getAs();
-  assert(Ty && "RecordType of base class is unknown");
+  if (!Ty) continue;
   const auto *Base = cast(Ty->getDecl()->getDefinition());
   if (!isInterface(Base)) NumConcrete++;
 }
Index: test/clang-tidy/fuchsia-multiple-inheritance.cpp
===
--- test/clang-tidy/fuchsia-multiple-inheritance.cpp
+++ test/clang-tidy/fuchsia-multiple-inheritance.cpp
@@ -131,3 +131,6 @@
 
 template struct A : T {};
 template struct B : virtual T {};
+
+template struct C {};
+template struct D : C {};


Index: clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
===
--- clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
+++ clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
@@ -66,7 +66,7 @@
   for (const auto &I : Node->bases()) {
 if (I.isVirtual()) continue;
 const auto *Ty = I.getType()->getAs();
-assert(Ty && "RecordType of base class is unknown");
+if (!Ty) continue;
 const RecordDecl *D = Ty->getDecl()->getDefinition();
 if (!D) continue;
 const auto *Base = cast(D);
@@ -96,18 +96,18 @@
 // concrete classes
 unsigned NumConcrete = 0;
 for (const auto &I : D->bases()) {
-  if (I.isVirtual() || I.getType()->getAs()) continue;
+  if (I.isVirtual()) continue;
   const auto *Ty = I.getType()->getAs();
-  assert(Ty && "RecordType of base class is unknown");
+  if (!Ty) continue;
   const auto *Base = cast(Ty->getDecl()->getDefinition());
   if (!isInterface(Base)) NumConcrete++;
 }
 
 // Check virtual bases to see if there is more than one concrete 
 // non-virtual base.
 for (const auto &V : D->vbases()) {
   const auto *Ty = V.getType()->getAs();
-  assert(Ty && "RecordType of base class is unknown");
+  if (!Ty) continue;
   const auto *Base = cast(Ty->getDecl()->getDefinition());
   if (!isInterface(Base)) NumConcrete++;
 }
Index: test/clang-tidy/fuchsia-multiple-inheritance.cpp
===
--- test/clang-tidy/fuchsia-multiple-inheritance.cpp
+++ test/clang-tidy/fuchsia-multiple-inheritance.cpp
@@ -131,3 +131,6 @@
 
 template struct A : T {};
 template struct B : virtual T {};
+
+template struct C {};
+template struct D : C {};
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43341: [clang-doc] Implement reducer portion of the frontend framework

2018-02-15 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett created this revision.
juliehockett added reviewers: klimek, sammccall, jakehehrlich.
juliehockett added a project: clang-tools-extra.
Herald added a subscriber: mgorny.
juliehockett added a dependency: D41102: Setup clang-doc frontend framework.

Implements a simple, in-memory reducer for the mapped output of the initial 
tool. This creates a collection object for storing the deduplicated infos on 
each declaration, and populates that from the mapper output. The collection 
object is serialized to LLVM bitstream. On reading each serialized output, it 
checks to see if a merge is necessary and if so, merges the new info with the 
existing info (prefering the existing one if conflicts exist).

For a more detailed overview of the tool, see the design document on the 
mailing list: RFC: clang-doc proposal 



https://reviews.llvm.org/D43341

Files:
  clang-doc/CMakeLists.txt
  clang-doc/ClangDocBinary.cpp
  clang-doc/ClangDocBinary.h
  clang-doc/ClangDocMapper.cpp
  clang-doc/ClangDocMapper.h
  clang-doc/ClangDocReducer.cpp
  clang-doc/ClangDocReducer.h
  clang-doc/ClangDocRepresentation.cpp
  clang-doc/ClangDocRepresentation.h
  clang-doc/tool/ClangDocMain.cpp
  test/clang-doc/mapper-namespace.cpp
  test/clang-doc/mapper-type.cpp

Index: test/clang-doc/mapper-type.cpp
===
--- test/clang-doc/mapper-type.cpp
+++ test/clang-doc/mapper-type.cpp
@@ -2,136 +2,154 @@
 // RUN: mkdir %t
 // RUN: echo "" > %t/compile_flags.txt
 // RUN: cp "%s" "%t/test.cpp"
-// RUN: clang-doc  --dump --omit-filenames -doxygen -p %t %t/test.cpp | FileCheck %s
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp > %t/info.bc
+// RUN llvm-bcanalyzer %t/info.bc --dump | FileCheck %s
 
 union A { int X; int Y; };
-// CHECK: ---
-// CHECK: KEY: A
-// CHECK: FullyQualifiedName: A
-// CHECK: Name: A
-// CHECK: TagType: 2
-// CHECK: ID: Member
-// CHECK: Type: int
-// CHECK: Name: A::X
-// CHECK: Access: 3
-// CHECK: ID: Member
-// CHECK: Type: int
-// CHECK: Name: A::Y
-// CHECK: Access: 3
-// CHECK: ---
-// CHECK: KEY: A::A
-// CHECK: FullyQualifiedName: A::A
-// CHECK: Name: A
-// CHECK: Namespace: A
 
 enum B { X, Y };
-// CHECK: ---
-// CHECK: KEY: B
-// CHECK: FullyQualifiedName: B
-// CHECK: Name: B
-// CHECK: ID: Member
-// CHECK: Type: X
-// CHECK: Access: 3
-// CHECK: ID: Member
-// CHECK: Type: Y
-// CHECK: Access: 3
 
 struct C { int i; };
-// CHECK: ---
-// CHECK: KEY: C
-// CHECK: FullyQualifiedName: C
-// CHECK: Name: C
-// CHECK: ID: Member
-// CHECK: Type: int
-// CHECK: Name: C::i
-// CHECK: Access: 3
-// CHECK: ---
-// CHECK: KEY: C::C
-// CHECK: FullyQualifiedName: C::C
-// CHECK: Name: C
-// CHECK: Namespace: C
 
 class D {};
-// CHECK: ---
-// CHECK: KEY: D
-// CHECK: FullyQualifiedName: D
-// CHECK: Name: D
-// CHECK: TagType: 3
-// CHECK: ---
-// CHECK: KEY: D::D
-// CHECK: FullyQualifiedName: D::D
-// CHECK: Name: D
-// CHECK: Namespace: D
 
 class E {
-// CHECK: ---
-// CHECK: KEY: E
-// CHECK: FullyQualifiedName: E
-// CHECK: Name: E
-// CHECK: TagType: 3
-// CHECK: ---
-// CHECK: KEY: E::E
-// CHECK: FullyQualifiedName: E::E
-// CHECK: Name: E
-// CHECK: Namespace: E
-
 public:
 	E() {}
-// CHECK: ---
-// CHECK: KEY: _ZN1EC1Ev
-// CHECK: FullyQualifiedName: E::E
-// CHECK: Name: E
-// CHECK: Namespace: E
-// CHECK: MangledName: _ZN1EC1Ev
-// CHECK: Parent: E
-// CHECK: ID: Return
-// CHECK: Type: void
-// CHECK: Access: 3
-
-	 ~E() {}
-// CHECK: ---
-// CHECK: KEY: _ZN1ED1Ev
-// CHECK: FullyQualifiedName: E::~E
-// CHECK: Name: ~E
-// CHECK: Namespace: E
-// CHECK: MangledName: _ZN1ED1Ev
-// CHECK: Parent: E
-// CHECK: ID: Return
-// CHECK: Type: void
-// CHECK: Access: 3
+	~E() {}
 
 protected:
 	void ProtectedMethod();
-// CHECK:  ---
-// CHECK: KEY: _ZN1E15ProtectedMethodEv
-// CHECK: FullyQualifiedName: _ZN1E15ProtectedMethodEv
-// CHECK: Name: ProtectedMethod
-// CHECK: Namespace: E
 };
 
 void E::ProtectedMethod() {}
-// CHECK: ---
-// CHECK: KEY: _ZN1E15ProtectedMethodEv
-// CHECK: FullyQualifiedName: E::ProtectedMethod
-// CHECK: Name: ProtectedMethod
-// CHECK: Namespace: E
-// CHECK: MangledName: _ZN1E15ProtectedMethodEv
-// CHECK: Parent: E
-// CHECK: ID: Return
-// CHECK: Type: void
-// CHECK: Access: 3
-// CHECK: Access: 1
 
 class F : virtual private D, public E {};
-// CHECK: ---
-// CHECK: KEY: F
-// CHECK: FullyQualifiedName: F
-// CHECK: Name: F
-// CHECK: TagType: 3
-// CHECK: Parent: class E
-// CHECK: VParent: class D
-// CHECK: ---
-// CHECK: KEY: F::F
-// CHECK: FullyQualifiedName: F::F
-// CHECK: Name: F
-// CHECK: Namespace: F
+
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'E::E'
+  // CHECK:  blob data = 'E'
+  // CHECK:  blob data = 'E'
+  // CHECK:  blob data = '_ZN1EC1Ev'
+  // CHECK:  blob data = 'E'
+  // CHECK: 
+// CHECK: 
+// CHECK:  blob data = 'void'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // 

[PATCH] D41102: Setup clang-doc frontend framework

2018-02-15 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 134544.
juliehockett edited the summary of this revision.
juliehockett added a comment.

Updating tests and moving the bitcode reader out (to the next patch)


https://reviews.llvm.org/D41102

Files:
  CMakeLists.txt
  clang-doc/CMakeLists.txt
  clang-doc/ClangDoc.cpp
  clang-doc/ClangDoc.h
  clang-doc/ClangDocBinary.cpp
  clang-doc/ClangDocBinary.h
  clang-doc/ClangDocMapper.cpp
  clang-doc/ClangDocMapper.h
  clang-doc/ClangDocRepresentation.h
  clang-doc/tool/CMakeLists.txt
  clang-doc/tool/ClangDocMain.cpp
  docs/clang-doc.rst
  test/CMakeLists.txt
  test/clang-doc/mapper-class.cpp
  test/clang-doc/mapper-enum.cpp
  test/clang-doc/mapper-namespace.cpp
  test/clang-doc/mapper-struct.cpp
  test/clang-doc/mapper-union.cpp

Index: test/clang-doc/mapper-union.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-union.cpp
@@ -0,0 +1,26 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -docs=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/A.bc --dump | FileCheck %s
+
+union A { int X; int Y; };
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'A'
+  // CHECK:  blob data = 'A'
+  // CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'A::X'
+// CHECK: 
+  // CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'A::Y'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
Index: test/clang-doc/mapper-struct.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-struct.cpp
@@ -0,0 +1,19 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -docs=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/C.bc --dump | FileCheck %s
+
+struct C { int i; };
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'C'
+  // CHECK:  blob data = 'C'
+  // CHECK: 
+// CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'C::i'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
Index: test/clang-doc/mapper-namespace.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-namespace.cpp
@@ -0,0 +1,13 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -docs=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/A.bc --dump | FileCheck %s
+
+namespace A {}
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'A'
+  // CHECK:  blob data = 'A'
+// CHECK: 
Index: test/clang-doc/mapper-enum.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-enum.cpp
@@ -0,0 +1,23 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -docs=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/B.bc --dump | FileCheck %s
+
+enum B { X, Y };
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'B'
+  // CHECK:  blob data = 'B'
+  // CHECK: 
+// CHECK: 
+// CHECK:  blob data = 'X'
+// CHECK: 
+  // CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK:  blob data = 'Y'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
Index: test/clang-doc/mapper-class.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-class.cpp
@@ -0,0 +1,14 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -docs=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/E.bc --dump | FileCheck %s
+
+class E {};
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'E'
+  // CHECK:  blob data = 'E'
+  // CHECK: 
+// CHECK: 
Index: test/CMakeLists.txt
===
--- test/CMakeLists.txt
+++ test/CMakeLists.txt
@@ -41,6 +41,7 @@
   clang-apply-replacements
   clang-change-namespace
   clangd
+  clang-doc
   clang-include-fixer
   clang-move
   clang-query
Index: docs/clang-doc.rst
===
--- /dev/null
+++ docs/clang-doc.rst
@@ -0,0 +1,62 @@
+===
+Clang-Doc
+===
+
+.. contents::
+
+:program:`clang-doc` is a tool for generating C and C++ documenation from 
+source code and comments. 
+
+The tool is in a very early development stage, so you might encounter bugs and
+crashes. Submitting reports with information about how to reproduce the issue
+to `the LLVM bugtracker `_ will definitely help the
+project. If you have any ideas or suggestions, 

[PATCH] D43341: [clang-doc] Implement reducer portion of the frontend framework

2018-02-15 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 134546.
juliehockett edited the summary of this revision.
juliehockett added a comment.

Moving the entire implementation of the bitcode reader to this patch (from the 
mapper patch, here ) and cleaning up 
implementation


https://reviews.llvm.org/D43341

Files:
  clang-doc/CMakeLists.txt
  clang-doc/ClangDocBinary.cpp
  clang-doc/ClangDocBinary.h
  clang-doc/ClangDocReducer.cpp
  clang-doc/ClangDocReducer.h
  clang-doc/ClangDocRepresentation.cpp
  clang-doc/ClangDocRepresentation.h
  clang-doc/tool/ClangDocMain.cpp
  test/clang-doc/mapper-class.cpp
  test/clang-doc/mapper-enum.cpp
  test/clang-doc/mapper-namespace.cpp
  test/clang-doc/mapper-record.cpp
  test/clang-doc/mapper-struct.cpp
  test/clang-doc/mapper-union.cpp

Index: test/clang-doc/mapper-union.cpp
===
--- test/clang-doc/mapper-union.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-// RUN: rm -rf %t
-// RUN: mkdir %t
-// RUN: echo "" > %t/compile_flags.txt
-// RUN: cp "%s" "%t/test.cpp"
-// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -docs=%t/docs
-// RUN: llvm-bcanalyzer %t/docs/A.bc --dump | FileCheck %s
-
-union A { int X; int Y; };
-// CHECK: 
-// CHECK: 
-  // CHECK:  blob data = 'A'
-  // CHECK:  blob data = 'A'
-  // CHECK: 
-  // CHECK: 
-// CHECK: 
-// CHECK:  blob data = 'int'
-// CHECK:  blob data = 'A::X'
-// CHECK: 
-  // CHECK: 
-  // CHECK: 
-// CHECK: 
-// CHECK:  blob data = 'int'
-// CHECK:  blob data = 'A::Y'
-// CHECK: 
-  // CHECK: 
-// CHECK: 
Index: test/clang-doc/mapper-struct.cpp
===
--- test/clang-doc/mapper-struct.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-// RUN: rm -rf %t
-// RUN: mkdir %t
-// RUN: echo "" > %t/compile_flags.txt
-// RUN: cp "%s" "%t/test.cpp"
-// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -docs=%t/docs
-// RUN: llvm-bcanalyzer %t/docs/C.bc --dump | FileCheck %s
-
-struct C { int i; };
-// CHECK: 
-// CHECK: 
-  // CHECK:  blob data = 'C'
-  // CHECK:  blob data = 'C'
-  // CHECK: 
-// CHECK: 
-// CHECK:  blob data = 'int'
-// CHECK:  blob data = 'C::i'
-// CHECK: 
-  // CHECK: 
-// CHECK: 
Index: test/clang-doc/mapper-record.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-record.cpp
@@ -0,0 +1,155 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -docs=%t/docs
+// RUN llvm-bcanalyzer %t/docs/docs.bc --dump | FileCheck %s
+
+union A { int X; int Y; };
+
+enum B { X, Y };
+
+struct C { int i; };
+
+class D {};
+
+class E {
+public:
+	E() {}
+	~E() {}
+
+protected:
+	void ProtectedMethod();
+};
+
+void E::ProtectedMethod() {}
+
+class F : virtual private D, public E {};
+
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'E::E'
+  // CHECK:  blob data = 'E'
+  // CHECK:  blob data = 'E'
+  // CHECK:  blob data = '_ZN1EC1Ev'
+  // CHECK:  blob data = 'E'
+  // CHECK: 
+// CHECK: 
+// CHECK:  blob data = 'void'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'E::~E'
+  // CHECK:  blob data = '~E'
+  // CHECK:  blob data = 'E'
+  // CHECK:  blob data = '_ZN1ED1Ev'
+  // CHECK:  blob data = 'E'
+  // CHECK: 
+// CHECK: 
+// CHECK:  blob data = 'void'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'E::ProtectedMethod'
+  // CHECK:  blob data = 'ProtectedMethod'
+  // CHECK:  blob data = 'E'
+  // CHECK:  blob data = '_ZN1E15ProtectedMethodEv'
+  // CHECK:  blob data = 'E'
+  // CHECK: 
+// CHECK: 
+// CHECK:  blob data = 'void'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'A'
+  // CHECK:  blob data = 'A'
+  // CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'A::X'
+// CHECK: 
+  // CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'A::Y'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'C'
+  // CHECK:  blob data = 'C'
+  // CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'C::i'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'D'
+  // CHECK:  blob data = 'D'
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'E'
+  // CHECK:  blob data = 'E'
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'F'
+  // CHECK:  blob data = 'F'
+  // CHECK: 
+  // CHECK:  blob data = 'class E'
+  // CHECK:  blob data = 'class D'
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'B'
+  // CHECK:  blob data = 'B'
+  // CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK:  blob data = 'X'
+// CHE

[PATCH] D43392: [clang-tidy] Add Fuchsia checker for visibility attributes

2018-02-16 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett created this revision.
juliehockett added reviewers: aaron.ballman, hokein, alexfh.
juliehockett added a project: clang-tools-extra.
Herald added subscribers: xazax.hun, mgorny.

Adding a checker to find a function given its name and add a visibility 
attribute if none is present (i.e. `__attribute__((visibility("hidden")))`.


https://reviews.llvm.org/D43392

Files:
  clang-tidy/fuchsia/AddVisibilityCheck.cpp
  clang-tidy/fuchsia/AddVisibilityCheck.h
  clang-tidy/fuchsia/CMakeLists.txt
  clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/fuchsia-add-visibility.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/fuchsia-add-visibility.cpp

Index: test/clang-tidy/fuchsia-add-visibility.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-add-visibility.cpp
@@ -0,0 +1,10 @@
+// RUN: %check_clang_tidy %s fuchsia-add-visibility %t -- \
+// RUN:   -config="{CheckOptions: [{key: fuchsia-add-visibility.Name, value: 'foo'}]}" \
+// RUN:   -- -std=c++11
+
+void foo();
+
+void foo() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: set visibility attr to hidden
+// CHECK-FIXES: __attribute__((visibility("hidden")))
+
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -71,6 +71,7 @@
cppcoreguidelines-pro-type-vararg
cppcoreguidelines-slicing
cppcoreguidelines-special-member-functions
+   fuchsia-add-visibility
fuchsia-default-arguments
fuchsia-multiple-inheritance
fuchsia-overloaded-operator
Index: docs/clang-tidy/checks/fuchsia-add-visibility.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/fuchsia-add-visibility.rst
@@ -0,0 +1,21 @@
+.. title:: clang-tidy - fuchsia-add-visibility
+
+fuchsia-add-visibility
+==
+
+Check to find a given named function and suggest a fix to add
+a `__attribute__((visibility("hidden")))` to its definition.
+
+For example, given the name 'func':
+
+.. code-block:: c++
+
+  void func() {}
+
+would be changed to 
+
+.. code-block:: c++
+
+  __attribute__((visibility("hidden")))
+  void func() {}
+  
\ No newline at end of file
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,12 @@
 Improvements to clang-tidy
 --
 
+- New `fuchsia-add-visibility
+  `_ check
+
+  Check to find a given named function and suggest a fix to add a
+  `__attribute__((visibility("hidden")))` to its definition.
+
 - The 'misc-incorrect-roundings' check was renamed to `bugprone-incorrect-roundings
   `_
 
Index: clang-tidy/fuchsia/FuchsiaTidyModule.cpp
===
--- clang-tidy/fuchsia/FuchsiaTidyModule.cpp
+++ clang-tidy/fuchsia/FuchsiaTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "AddVisibilityCheck.h"
 #include "DefaultArgumentsCheck.h"
 #include "MultipleInheritanceCheck.h"
 #include "OverloadedOperatorCheck.h"
@@ -27,6 +28,8 @@
 class FuchsiaModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck(
+"fuchsia-add-visibility");
 CheckFactories.registerCheck(
 "fuchsia-default-arguments");
 CheckFactories.registerCheck(
Index: clang-tidy/fuchsia/CMakeLists.txt
===
--- clang-tidy/fuchsia/CMakeLists.txt
+++ clang-tidy/fuchsia/CMakeLists.txt
@@ -1,6 +1,7 @@
 set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyFuchsiaModule
+  AddVisibilityCheck.cpp
   DefaultArgumentsCheck.cpp
   FuchsiaTidyModule.cpp
   MultipleInheritanceCheck.cpp
Index: clang-tidy/fuchsia/AddVisibilityCheck.h
===
--- /dev/null
+++ clang-tidy/fuchsia/AddVisibilityCheck.h
@@ -0,0 +1,42 @@
+//===--- AddVisibilityCheck.h - clang-tidy---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_ADDVISIBILITYCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_ADDVISIBILITYCHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace fuchsia {
+
+/// Check to find a given named function and 

[PATCH] D43392: [clang-tidy] Add Fuchsia checker for visibility attributes

2018-02-16 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 134684.
juliehockett marked 7 inline comments as done.
juliehockett edited the summary of this revision.
juliehockett added a comment.

1. Added visibility parameter
2. Updated Name parameter to be a list of names, as opposed to a single name
3. Fixed comments and documentation


https://reviews.llvm.org/D43392

Files:
  clang-tidy/fuchsia/AddVisibilityCheck.cpp
  clang-tidy/fuchsia/AddVisibilityCheck.h
  clang-tidy/fuchsia/CMakeLists.txt
  clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/fuchsia-add-visibility.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/fuchsia-add-visibility.cpp

Index: test/clang-tidy/fuchsia-add-visibility.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-add-visibility.cpp
@@ -0,0 +1,18 @@
+// RUN: %check_clang_tidy %s fuchsia-add-visibility %t -- \
+// RUN:   -config="{CheckOptions: [{key: fuchsia-add-visibility.Names, value: 'foo,bar,baz'}, \
+// RUN:{key: fuchsia-add-visibility.Visibility, value: 'hidden'}]}" \
+// RUN:   -- -std=c++11
+
+void foo();
+
+void foo() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: visibility attribute not set for specified function
+// CHECK-FIXES: __attribute__((visibility("hidden")))
+
+__attribute__((visibility("internal")))
+void bar() {}
+
+__attribute__((visibility("protected")))
+void baz();
+
+void baz() {}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -71,6 +71,7 @@
cppcoreguidelines-pro-type-vararg
cppcoreguidelines-slicing
cppcoreguidelines-special-member-functions
+   fuchsia-add-visibility
fuchsia-default-arguments
fuchsia-multiple-inheritance
fuchsia-overloaded-operator
Index: docs/clang-tidy/checks/fuchsia-add-visibility.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/fuchsia-add-visibility.rst
@@ -0,0 +1,34 @@
+.. title:: clang-tidy - fuchsia-add-visibility
+
+fuchsia-add-visibility
+==
+
+Finds functions given a list of names and suggests a fix to add
+an _`_attribute__((visibility("VISIBILITY")))` to their definitions,
+if they do not already have a visibility attribute.
+
+For example, given the name 'func':
+
+.. code-block:: c++
+
+  void func() {}
+
+would be changed to 
+
+.. code-block:: c++
+
+  __attribute__((visibility("hidden")))
+  void func() {}
+  
+Options
+---
+
+.. option:: Names
+
+   A string containing a comma-separated list of function names to check for
+   a visibilit attribute. Default is an empty string.
+
+.. option:: Visibility
+
+   A string specifying what visibility attribute to set, `hidden`, `default`,
+   `internal`, or `protected`. Default is `hidden`.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -70,6 +70,13 @@
   with looping constructs. Every backward jump is rejected. Forward jumps are
   only allowed in nested loops.
 
+- New `fuchsia-add-visibility
+  `_ check
+
+  Finds functions given a list of names and suggests a fix to add
+  an _`_attribute__((visibility("VISIBILITY")))` to their definitions,
+  if they do not already have a visibility attribute.
+
 - New `fuchsia-multiple-inheritance
   `_ check
 
Index: clang-tidy/fuchsia/FuchsiaTidyModule.cpp
===
--- clang-tidy/fuchsia/FuchsiaTidyModule.cpp
+++ clang-tidy/fuchsia/FuchsiaTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "AddVisibilityCheck.h"
 #include "DefaultArgumentsCheck.h"
 #include "MultipleInheritanceCheck.h"
 #include "OverloadedOperatorCheck.h"
@@ -27,6 +28,8 @@
 class FuchsiaModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck(
+"fuchsia-add-visibility");
 CheckFactories.registerCheck(
 "fuchsia-default-arguments");
 CheckFactories.registerCheck(
Index: clang-tidy/fuchsia/CMakeLists.txt
===
--- clang-tidy/fuchsia/CMakeLists.txt
+++ clang-tidy/fuchsia/CMakeLists.txt
@@ -1,6 +1,7 @@
 set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyFuchsiaModule
+  AddVisibilityCheck.cpp
   DefaultArgumentsCheck.cpp
   FuchsiaTidyModule.cpp
   MultipleInheritanceCheck.cpp
Index: clang-tidy/fuchsia/AddVisibilityCheck.h
===
--- /dev/null
+++ clang-tidy/fuchsia/Add

[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 &I : IS->getNamespaceInfos()) Success = writeNamespacePage(I);
+
+  return Success;
+}
+
+bool MDGenerator::writeClasses() {
+  bool Success = true;
+  for (const auto &I : IS->getRecordInfos()) {
+if (I.TagType == TagTypeKind::TTK_Class) Success = writeClassPage(I);
+  }
+  return Success;
+}
+
+bool MDGenerator::writeNamespacePage(const NamespaceInfo &I) {
+  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 &F : 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 &R 

[PATCH] D41102: Setup clang-doc frontend framework

2018-02-18 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added inline comments.



Comment at: clang-doc/ClangDocBinary.cpp:88
+  Stream.Emit((unsigned)'C', 8);
+  Stream.Emit((unsigned)'S', 8);
+}

lebedev.ri wrote:
> General comment: shouldn't the bitcode be versioned?
Possibly? My understanding of the versioning (which could be incorrect) was 
that it was for the LLVM IR and how it is written in the given file -- I'm not 
writing to LLVM IR here, just using it as a data storage format, and so didn't 
think it was necessary. Happy to add it in though, but which version number 
should I use?


https://reviews.llvm.org/D41102



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


[PATCH] D41102: Setup clang-doc frontend framework

2018-02-18 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 134855.
juliehockett marked 14 inline comments as done.
juliehockett added a comment.

1. Fixing docs
2. Adding static map from bitcode block/record id to block/record name
3. Pulling magic numbers into one struct
4. Cleaning up and clarifying command line options
5. Adding tests for functions and methods


https://reviews.llvm.org/D41102

Files:
  CMakeLists.txt
  clang-doc/CMakeLists.txt
  clang-doc/ClangDoc.cpp
  clang-doc/ClangDoc.h
  clang-doc/ClangDocBinary.cpp
  clang-doc/ClangDocBinary.h
  clang-doc/ClangDocMapper.cpp
  clang-doc/ClangDocMapper.h
  clang-doc/ClangDocRepresentation.h
  clang-doc/tool/CMakeLists.txt
  clang-doc/tool/ClangDocMain.cpp
  docs/clang-doc.rst
  test/CMakeLists.txt
  test/clang-doc/mapper-class.cpp
  test/clang-doc/mapper-enum.cpp
  test/clang-doc/mapper-function.cpp
  test/clang-doc/mapper-method.cpp
  test/clang-doc/mapper-namespace.cpp
  test/clang-doc/mapper-struct.cpp
  test/clang-doc/mapper-undefined.cpp
  test/clang-doc/mapper-union.cpp

Index: test/clang-doc/mapper-union.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-union.cpp
@@ -0,0 +1,26 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/A.bc --dump | FileCheck %s
+
+union A { int X; int Y; };
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'A'
+  // CHECK:  blob data = 'A'
+  // CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'A::X'
+// CHECK: 
+  // CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'A::Y'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
Index: test/clang-doc/mapper-undefined.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-undefined.cpp
@@ -0,0 +1,15 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/E.bc --dump | FileCheck %s
+
+class E;
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'E'
+  // CHECK:  blob data = 'E'
+  // CHECK: 
+// CHECK: 
+
Index: test/clang-doc/mapper-struct.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-struct.cpp
@@ -0,0 +1,19 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/C.bc --dump | FileCheck %s
+
+struct C { int i; };
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'C'
+  // CHECK:  blob data = 'C'
+  // CHECK: 
+// CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'C::i'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
Index: test/clang-doc/mapper-namespace.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-namespace.cpp
@@ -0,0 +1,13 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/A.bc --dump | FileCheck %s
+
+namespace A {}
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'A'
+  // CHECK:  blob data = 'A'
+// CHECK: 
Index: test/clang-doc/mapper-method.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-method.cpp
@@ -0,0 +1,30 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/_ZN1E6MethodEi.bc --dump | FileCheck %s
+
+class E {
+public: 
+	int Method(int param) { return param; }
+};
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'E::Method'
+  // CHECK:  blob data = 'Method'
+  // CHECK:  blob data = 'E'
+  // CHECK:  blob data = '_ZN1E6MethodEi'
+  // CHECK:  blob data = 'E'
+  // CHECK: 
+// CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK: 
+  // CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'param'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
Index: test/clang-doc/mapper-function.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-function.cpp
@@ -0,0 +1,25 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t

[PATCH] D41102: Setup clang-doc frontend framework

2018-02-19 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added inline comments.



Comment at: clang-doc/ClangDoc.cpp:32
+  ECtx.reportResult(
+  Name, Mapper.emitInfo(D, getComment(D), Name, getLine(D), getFile(D)));
+}

lebedev.ri wrote:
> I wonder if `Name` should be `std::move()`'d ? Or not, `reportResult()` seems 
> to take `StringRef`...
> 
> (in general, it might be a good idea to run clang-tidy on the code)
So the `ExecutionContext` can do implement different ways to do this -- in this 
case, the default container created is the `InMemoryToolResults`, which 
technically takes in `StringRef`s, but copies their data to its in-memory 
representation: 

```void InMemoryToolResults::addResult(StringRef Key, StringRef Value) {
KVResults.push_back({Key.str(), Value.str()});
}```

A different implementation of it (i.e. a results container not in memory) would 
likely have to be backed by a file, so the data would be written out there 
anyways.



Comment at: clang-doc/ClangDocBinary.cpp:72
+  assert(Abbrevs.find(recordID) == Abbrevs.end() &&
+ "Abbreviation already set.");
+  Abbrevs[recordID] = abbrevID;

lebedev.ri wrote:
> lebedev.ri wrote:
> > So it does not *set* the abbreviation, since it is not supposed to be 
> > called if the abbreviation is already set, but it *adds* a unique 
> > abbreviation.
> > I think it should be called `void AbbreviationMap::add(unsigned recordID, 
> > unsigned abbrevID)` then
> This is marked as done, but the name is still the same, and no 
> counter-comment was added, as far as i can see
It was changed to AbbreviationMap::add from AbbreviationMap::set, as you 
suggested -- unless I missed something in your comment?



Comment at: clang-doc/ClangDocBinary.h:82
+
+static std::map BlockIdNameMap = {
+  {NAMESPACE_BLOCK_ID, "NamespaceBlock"},

lebedev.ri wrote:
> lebedev.ri wrote:
> > Nice!
> > Some thoughts:
> > 1. I agree it makes sense to keep it close to the enum definition, in 
> > header...
> > 2. This will result in global constructor. Generally they are frowned upon 
> > in LLVM. But since this is a standalone binary, it may be ok?
> > 3. Have you tried using `StringRef` here, instead of `std::string`?
> > 4. `std::map` is in general a bad idea.
> >   Since the `enum`'s enumerators are all small and consecutive, maybe 
> > try `llvm::IndexedMap`?
> Also, this should be `static const`, since the underlying enum won't change 
> on the fly.
> 
> `#llvm` suggests to use TableGen here, i'm not sure how that would work.
> 
> As i have now noticed, there isn't a init-list constructor, so I think 
> **something** like this might work:
> ```
> static const llvm::IndexedMap BlockIdNameMap = []() {
>   llvm::IndexedMap map;
>   map.reserve(BI_LAST);
> 
>   // There is no init-list constructor for the IndexedMap, so have to 
> improvise
>   static const std::initializer_list> 
> inits = {
> {NAMESPACE_BLOCK_ID, "NamespaceBlock"},
> ...
>   };
>   for(const auto& init : inits)
> map[init.first] = init.second;
> }();
> ```
> 
> Also, even though `llvm::IndexedMap<>` is using `llvm::SmallVector<>` 
> internally, it does not expose the initial size as template parameter, 
> unfortunately, but hardcodes it to `0`. I think it would be great to add one 
> more template parameter to `llvm::IndexedMap<>`, which would default to `0`, 
> but would allow us here to avoid all memory allocation altogether.
> 
> What do you think? If you do agree that using `IndexedMap` seems like the 
> right choice, but **don't** want to write the patch for template parameter, i 
> might look into it..
Had to play with it a bit, but it's working now.

For the template parameter, I'm happy to take a look! Avoiding allocation here 
would be great.



Comment at: clang-doc/ClangDocMapper.cpp:202
+  for (comments::Comment *Child :
+   make_range(C->child_begin(), C->child_end())) {
+CurrentCI.Children.emplace_back(std::make_shared());

lebedev.ri wrote:
> It would be nice if you could (as a new Differential) add a `children()` 
> function to that class that will do that automatically.
Will do :)  (and same for the below)



Comment at: clang-doc/ClangDocMapper.h:36
+
+class ClangDocCommentVisitor
+: public ConstCommentVisitor {

sammccall wrote:
> why is this exposed?
> (and what does it do?)
Moved it into the mapper class, but it traverses a comment and extracts its 
information into the `CommentInfo` struct



Comment at: clang-doc/ClangDocMapper.h:66
+  template 
+  StringRef emitInfo(const C *D, const FullComment *FC, StringRef Key,
+ int LineNumber, StringRef File);

sammccall wrote:
> when returning a stringref, it might pay to be explicit about who owns the 
> data, so the caller knows the safe lifetime.
> (This isn't always spelled out in llvm, but should probably be done more 
> often!)
Definite

[PATCH] D41102: Setup clang-doc frontend framework

2018-02-19 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 135009.
juliehockett marked 27 inline comments as done.
juliehockett added a comment.

1. Decoupled the mapper implementation from the main program, exposing only the 
function to generate the action factory
2. Implemented the matchers into a RecursiveASTVisitor and moved the serializer 
code into the mapper class
3. Cleaned up string references, templates and overloaded functions
4. Made the record/block id to name mapping an IndexedMap

Still need to address using USRs as the key in the mapper, bitcode versioning, 
and documentation in each file -- will do that in the morning!


https://reviews.llvm.org/D41102

Files:
  CMakeLists.txt
  clang-doc/CMakeLists.txt
  clang-doc/ClangDoc.h
  clang-doc/ClangDocBinary.cpp
  clang-doc/ClangDocBinary.h
  clang-doc/ClangDocMapper.cpp
  clang-doc/ClangDocMapper.h
  clang-doc/ClangDocRepresentation.h
  clang-doc/tool/CMakeLists.txt
  clang-doc/tool/ClangDocMain.cpp
  docs/clang-doc.rst
  test/CMakeLists.txt
  test/clang-doc/mapper-class.cpp
  test/clang-doc/mapper-enum.cpp
  test/clang-doc/mapper-function.cpp
  test/clang-doc/mapper-method.cpp
  test/clang-doc/mapper-namespace.cpp
  test/clang-doc/mapper-struct.cpp
  test/clang-doc/mapper-undefined.cpp
  test/clang-doc/mapper-union.cpp

Index: test/clang-doc/mapper-union.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-union.cpp
@@ -0,0 +1,26 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/A.bc --dump | FileCheck %s
+
+union A { int X; int Y; };
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'A'
+  // CHECK:  blob data = 'A'
+  // CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'A::X'
+// CHECK: 
+  // CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'A::Y'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
Index: test/clang-doc/mapper-undefined.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-undefined.cpp
@@ -0,0 +1,15 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/E.bc --dump | FileCheck %s
+
+class E;
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'E'
+  // CHECK:  blob data = 'E'
+  // CHECK: 
+// CHECK: 
+
Index: test/clang-doc/mapper-struct.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-struct.cpp
@@ -0,0 +1,19 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/C.bc --dump | FileCheck %s
+
+struct C { int i; };
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'C'
+  // CHECK:  blob data = 'C'
+  // CHECK: 
+// CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'C::i'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
Index: test/clang-doc/mapper-namespace.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-namespace.cpp
@@ -0,0 +1,13 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/A.bc --dump | FileCheck %s
+
+namespace A {}
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'A'
+  // CHECK:  blob data = 'A'
+// CHECK: 
Index: test/clang-doc/mapper-method.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-method.cpp
@@ -0,0 +1,30 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/_ZN1E6MethodEi.bc --dump | FileCheck %s
+
+class E {
+public: 
+	int Method(int param) { return param; }
+};
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'E::Method'
+  // CHECK:  blob data = 'Method'
+  // CHECK:  blob data = 'E'
+  // CHECK:  blob data = '_ZN1E6MethodEi'
+  // CHECK:  blob data = 'E'
+  // CHECK: 
+// CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK: 
+  // CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'param'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
Index: test/clang-doc/mapper-function.cpp
===
--- /dev/null
+++ test/clang-doc/mapp

[PATCH] D41102: Setup clang-doc frontend framework

2018-02-20 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added a comment.

> 2. I've mentioned it before as a comment, but to what extent will you be 
> parsing information in this frontend? Currently the links between types are 
> primarily stored as strings. Are you planning to have the backend that 
> generates the MarkDown parse those strings and link them to types? E.g. the 
> parenttype is a std::vector and assuming you want the markdown 
> to have a link to this parent type, will the MarkDown have to parse this type 
> and lookup the link to the original type? Or will you embed references to 
> other types within the intermediate format?

This is a good question -- expecting the backend to parse the strings is a bit 
of an unrealistic assumption, as you point out. I'm currently switching the key 
type from the names to the USRs, and I think that might help resolve this too. 
With that, each type can reference the USR of the linked def, which can be used 
to directly lookup the linked def. Does that make sense? I have to see where 
the majority of the USR resolution should be done (i.e. here in the mapper or 
later in the reducer), so will update once I take a look at that.


https://reviews.llvm.org/D41102



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


[PATCH] D41102: Setup clang-doc frontend framework

2018-02-20 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 135168.
juliehockett marked 13 inline comments as done.
juliehockett added a comment.

1. Updating mapper keys to use USRs instead of names
2. Also updating internal representation to use USRs instead of names
3. Renaming files (getting rid of the ClangDoc prefix in most cases)
4. Added bitcode version number to output
5. Put brief documentation in header files
6. Updating internal representation to generate full infos for all decls 
(regardless of if they're defined -- the reducer step will consolidate these) 
and to store the namespace as a vector instead of a string.


https://reviews.llvm.org/D41102

Files:
  CMakeLists.txt
  clang-doc/BitcodeWriter.cpp
  clang-doc/BitcodeWriter.h
  clang-doc/CMakeLists.txt
  clang-doc/ClangDoc.h
  clang-doc/Mapper.cpp
  clang-doc/Mapper.h
  clang-doc/Representation.h
  clang-doc/tool/CMakeLists.txt
  clang-doc/tool/ClangDocMain.cpp
  docs/clang-doc.rst
  test/CMakeLists.txt
  test/clang-doc/mapper-class.cpp
  test/clang-doc/mapper-enum.cpp
  test/clang-doc/mapper-function.cpp
  test/clang-doc/mapper-method.cpp
  test/clang-doc/mapper-namespace.cpp
  test/clang-doc/mapper-struct.cpp
  test/clang-doc/mapper-union.cpp

Index: test/clang-doc/mapper-union.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-union.cpp
@@ -0,0 +1,29 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@u...@d.bc --dump | FileCheck %s
+
+union D { int X; int Y; };
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'D'
+  // CHECK: 
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'D::X'
+// CHECK: 
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'D::Y'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+
+
Index: test/clang-doc/mapper-struct.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-struct.cpp
@@ -0,0 +1,23 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@s...@c.bc --dump | FileCheck %s
+
+struct C { int i; };
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'C'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'C::i'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+
+
Index: test/clang-doc/mapper-namespace.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-namespace.cpp
@@ -0,0 +1,17 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@n...@a.bc --dump | FileCheck %s
+
+namespace A {}
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'A'
+// CHECK: 
+
+
Index: test/clang-doc/mapper-method.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-method.cpp
@@ -0,0 +1,31 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@S@G@F@Method#I#.bc --dump | FileCheck %s
+
+class G {
+public: 
+	int Method(int param) { return param; }
+};
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'Method'
+  // CHECK: 
+  // CHECK:  blob data = 'c:@S@G'
+  // CHECK: 
+// CHECK:  blob data = 'int'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'param'
+  // CHECK: 
+// CHECK: 
+
+
+
+
Index: test/clang-doc/mapper-function.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-function.cpp
@@ -0,0 +1,24 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@F@F#I#.bc --dump | FileCheck %s
+
+int F(int param) { return param; }
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'F'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'param'
+  // CHECK: 
+// CHECK: 
+
Index: test/clang-doc/mapper-enum.cpp

[PATCH] D41102: Setup clang-doc frontend framework

2018-02-20 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added a comment.

In https://reviews.llvm.org/D41102#1011299, @lebedev.ri wrote:

> I don't know the protocol, but i think it might be a good idea
>  to add a new entry to `CODE_OWNERS.TXT` for `clang-doc`?
>
> `clang-doc` going to be quite distinctive, and bigger/complicated
>  than what already is in `clang-tools-extra`.


Does anyone know what the protocol on this would be?




Comment at: clang-doc/ClangDocBinary.cpp:88
+  Stream.Emit((unsigned)'C', 8);
+  Stream.Emit((unsigned)'S', 8);
+}

lebedev.ri wrote:
> juliehockett wrote:
> > lebedev.ri wrote:
> > > General comment: shouldn't the bitcode be versioned?
> > Possibly? My understanding of the versioning (which could be incorrect) was 
> > that it was for the LLVM IR and how it is written in the given file -- I'm 
> > not writing to LLVM IR here, just using it as a data storage format, and so 
> > didn't think it was necessary. Happy to add it in though, but which version 
> > number should I use?
> The question i'm asking is: what will happen if two different (documenting 
> different attributes, with non-identical `enum {something}Id`, etc) 
> clang-doc's were used to generate two different parts of the docs (two 
> different TU's)?
> When merging two parts, if the older clang-doc is used, will it only accept 
> the part if bc it understands? Or fail altogether?
> And, does it make sense to allow to generate such mixed-up documentation?
> 
After some thought, I think it will depend on how the bitcode changes in the 
future. The reader can be implemented to simply ignore anything it doesn't 
recognize (with a default switch case), so that route is possible, but if the 
representation shifts in a major way it should probably just bail if the 
version is too early. 

I think this a good question to consider in implementing the reader and reducer 
portions of the tool -- for now, I've added the version number to the writer, 
so it can be checked in that part.


https://reviews.llvm.org/D41102



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


[PATCH] D43538: [clang-tidy] Update run-clang-tidy.py with config arg

2018-02-20 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett created this revision.
juliehockett added reviewers: aaron.ballman, hokein, alexfh.
juliehockett added a project: clang-tools-extra.
Herald added a subscriber: xazax.hun.

Updating the run-clang-tidy.py script to allow specification of the config 
argument to the clang-tidy invocation.


https://reviews.llvm.org/D43538

Files:
  clang-tidy/tool/run-clang-tidy.py


Index: clang-tidy/tool/run-clang-tidy.py
===
--- clang-tidy/tool/run-clang-tidy.py
+++ clang-tidy/tool/run-clang-tidy.py
@@ -75,7 +75,8 @@
 
 
 def get_tidy_invocation(f, clang_tidy_binary, checks, tmpdir, build_path,
-header_filter, extra_arg, extra_arg_before, quiet):
+header_filter, extra_arg, extra_arg_before, quiet,
+config):
   """Gets a command line for clang-tidy."""
   start = [clang_tidy_binary]
   if header_filter is not None:
@@ -99,6 +100,8 @@
   start.append('-p=' + build_path)
   if quiet:
   start.append('-quiet')
+  if config:
+  start.append('-config=' + config)
   start.append(f)
   return start
 
@@ -157,7 +160,7 @@
 invocation = get_tidy_invocation(name, args.clang_tidy_binary, args.checks,
  tmpdir, build_path, args.header_filter,
  args.extra_arg, args.extra_arg_before,
- args.quiet)
+ args.quiet, args.config)
 sys.stdout.write(' '.join(invocation) + '\n')
 subprocess.call(invocation)
 queue.task_done()
@@ -177,6 +180,14 @@
   parser.add_argument('-checks', default=None,
   help='checks filter, when not specified, use clang-tidy '
   'default')
+  parser.add_argument('-config', default=None,
+  help='Specifies a configuration in YAML/JSON format: '
+  '  -config="{Checks: \'*\','
+  '   CheckOptions: [{key: x,'
+  '   value: y}]}"'
+  'When the value is empty, clang-tidy will'
+  'attempt to find a file named .clang-tidy for'
+  'each source file in its parent directories.')
   parser.add_argument('-header-filter', default=None,
   help='regular expression matching the names of the '
   'headers to output diagnostics from. Diagnostics from '


Index: clang-tidy/tool/run-clang-tidy.py
===
--- clang-tidy/tool/run-clang-tidy.py
+++ clang-tidy/tool/run-clang-tidy.py
@@ -75,7 +75,8 @@
 
 
 def get_tidy_invocation(f, clang_tidy_binary, checks, tmpdir, build_path,
-header_filter, extra_arg, extra_arg_before, quiet):
+header_filter, extra_arg, extra_arg_before, quiet,
+config):
   """Gets a command line for clang-tidy."""
   start = [clang_tidy_binary]
   if header_filter is not None:
@@ -99,6 +100,8 @@
   start.append('-p=' + build_path)
   if quiet:
   start.append('-quiet')
+  if config:
+  start.append('-config=' + config)
   start.append(f)
   return start
 
@@ -157,7 +160,7 @@
 invocation = get_tidy_invocation(name, args.clang_tidy_binary, args.checks,
  tmpdir, build_path, args.header_filter,
  args.extra_arg, args.extra_arg_before,
- args.quiet)
+ args.quiet, args.config)
 sys.stdout.write(' '.join(invocation) + '\n')
 subprocess.call(invocation)
 queue.task_done()
@@ -177,6 +180,14 @@
   parser.add_argument('-checks', default=None,
   help='checks filter, when not specified, use clang-tidy '
   'default')
+  parser.add_argument('-config', default=None,
+  help='Specifies a configuration in YAML/JSON format: '
+  '  -config="{Checks: \'*\','
+  '   CheckOptions: [{key: x,'
+  '   value: y}]}"'
+  'When the value is empty, clang-tidy will'
+  'attempt to find a file named .clang-tidy for'
+  'each source file in its parent directories.')
   parser.add_argument('-header-filter', default=None,
   help='regular expression matching the names of the '
   'headers to output diagnostics from. Diagnostics from '
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43392: [clang-tidy] Add Fuchsia checker for visibility attributes

2018-02-20 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 135181.
juliehockett marked 10 inline comments as done.
juliehockett added a comment.

Updating check to allow for #pragma and command line visibility specs, and 
updating tests


https://reviews.llvm.org/D43392

Files:
  clang-tidy/fuchsia/AddVisibilityCheck.cpp
  clang-tidy/fuchsia/AddVisibilityCheck.h
  clang-tidy/fuchsia/CMakeLists.txt
  clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/fuchsia-add-visibility.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/fuchsia-add-visibility.cpp

Index: test/clang-tidy/fuchsia-add-visibility.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-add-visibility.cpp
@@ -0,0 +1,25 @@
+// RUN: %check_clang_tidy %s fuchsia-add-visibility %t -- \
+// RUN:   -config="{CheckOptions: [{key: fuchsia-add-visibility.Names, value: 'foo;bar;baz;foobar'}, \
+// RUN:{key: fuchsia-add-visibility.Visibility, value: 'default'}]}" \
+// RUN:   -- -std=c++11
+
+#pragma GCC visibility push(hidden)
+
+void foo();
+
+void foo() {}
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: no explicit visibility attribute set for specified function
+// CHECK-FIXES: __attribute__((visibility("default")))
+
+__attribute__((visibility("default")))
+void bar() {}
+
+__attribute__((visibility("default")))
+void baz();
+
+void baz() {}
+
+__attribute__((visibility("protected")))
+void foobar() {}
+// CHECK-MESSAGES: [[@LINE-2]]:1: warning: default visibility attribute not set for specified function
+// CHECK-FIXES: __attribute__((visibility("default")))
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -71,6 +71,7 @@
cppcoreguidelines-pro-type-vararg
cppcoreguidelines-slicing
cppcoreguidelines-special-member-functions
+   fuchsia-add-visibility
fuchsia-default-arguments
fuchsia-multiple-inheritance
fuchsia-overloaded-operator
Index: docs/clang-tidy/checks/fuchsia-add-visibility.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/fuchsia-add-visibility.rst
@@ -0,0 +1,34 @@
+.. title:: clang-tidy - fuchsia-add-visibility
+
+fuchsia-add-visibility
+==
+
+Finds functions given a list of names and suggests a fix to add
+an `__attribute__((visibility("VISIBILITY")))` to their definitions,
+if they do not already have a visibility attribute.
+
+For example, given the name 'func':
+
+.. code-block:: c++
+
+  void func() {}
+
+would be changed to 
+
+.. code-block:: c++
+
+  __attribute__((visibility("hidden")))
+  void func() {}
+  
+Options
+---
+
+.. option:: Names
+
+   A string containing a comma-separated list of function names to check for
+   a visibility attribute. Default is an empty string.
+
+.. option:: Visibility
+
+   A string specifying what visibility attribute to set, `hidden`, `default`, 
+   or `protected`. Default is `hidden`.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -70,6 +70,13 @@
   with looping constructs. Every backward jump is rejected. Forward jumps are
   only allowed in nested loops.
 
+- New `fuchsia-add-visibility
+  `_ check
+
+  Finds functions given a list of names and suggests a fix to add
+  an `__attribute__((visibility("VISIBILITY")))` to their definitions,
+  if they do not already have a visibility attribute.
+
 - New `fuchsia-multiple-inheritance
   `_ check
 
Index: clang-tidy/fuchsia/FuchsiaTidyModule.cpp
===
--- clang-tidy/fuchsia/FuchsiaTidyModule.cpp
+++ clang-tidy/fuchsia/FuchsiaTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "AddVisibilityCheck.h"
 #include "DefaultArgumentsCheck.h"
 #include "MultipleInheritanceCheck.h"
 #include "OverloadedOperatorCheck.h"
@@ -27,6 +28,8 @@
 class FuchsiaModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck(
+"fuchsia-add-visibility");
 CheckFactories.registerCheck(
 "fuchsia-default-arguments");
 CheckFactories.registerCheck(
Index: clang-tidy/fuchsia/CMakeLists.txt
===
--- clang-tidy/fuchsia/CMakeLists.txt
+++ clang-tidy/fuchsia/CMakeLists.txt
@@ -1,6 +1,7 @@
 set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyFuchsiaModule
+  AddVisibilityCheck.cpp
   DefaultArgumentsCheck.cpp
   FuchsiaTidyModule.cpp
   MultipleInheritanceC

[PATCH] D43392: [clang-tidy] Add Fuchsia checker for visibility attributes

2018-02-20 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added inline comments.



Comment at: clang-tidy/fuchsia/AddVisibilityCheck.cpp:68
+  diag(MatchedDecl->getLocStart(),
+   "visibility attribute not set for specified function")
+  << MatchedDecl

aaron.ballman wrote:
> jakehehrlich wrote:
> > aaron.ballman wrote:
> > > How about: "function expected to be annotated with '%0' visibility"
> > > 
> > > I'm mostly worried about the case where the function has a visibility 
> > > attribute, but it has the *wrong* visibility specified. The current 
> > > wording would be confusing in that circumstance. Or is that not a 
> > > scenario you care about, just that *any* visibility is specified on the 
> > > function?
> > The use case for this check is forcing code bases to carefully control what 
> > symbols are exported rather than just exporting everything. So if someone 
> > took the time to explicitly set the visibility of one of these symbols we 
> > care about then we should assume they knew what they were doing.
> > 
> > The specific use case I care about for this check is using 
> > -fvisibility=hidden and then checking to make sure a certain curated list 
> > of symbols has explicit default visibility.
> Ah, so a mismatch is unimportant, that's good to know. How about: "function 
> expected to be annotated with the 'visibility' attribute"?
So in implementing a way to handle #pragma and command line directives, it 
became clear that the more comprehensive check (that replaces existing attrs) 
was a trivial implementation on top of that, so I put it in. If we just want to 
ignore those cases, I can take out the conditional path.


https://reviews.llvm.org/D43392



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


[PATCH] D41102: Setup clang-doc frontend framework

2018-02-21 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added inline comments.



Comment at: clang-doc/BitcodeWriter.cpp:407
+
+void ClangDocBinaryWriter::writeBitstream(const EnumInfo &I,
+  BitstreamWriter &Stream,

lebedev.ri wrote:
> Hmm, common pattern again
> ```
> void ClangDocBinaryWriter::writeBitstream(const  &I,
>   BitstreamWriter &Stream,
>   bool writeBlockInfo) {
>   if (writeBlockInfo) emitBlockInfoBlock(Stream);
>   StreamSubBlock Block(Stream, BI__BLOCK_ID);
>   ...
> }
> ```
> Could be solved if a mapping from `TYPENAME` -> `BI__BLOCK_ID` 
> can be added.
> If LLVM would be using C++14, that'd be easy, but with C++11, it would 
> require whole new class (although with just a single static variable).
Do you want me to try to write that class, or leave it as it is?



Comment at: clang-doc/Mapper.cpp:113
+  populateInfo(I, D, C);
+  I.Loc.emplace_back(Location{LineNumber, File});
+}

lebedev.ri wrote:
> ```
> I.Loc.emplace_back({LineNumber, File});
> ```
That...doesn't work? Throws a no-matching-function error (suggesting to try 
emplacing a Location instead of a 


https://reviews.llvm.org/D41102



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


[PATCH] D41102: Setup clang-doc frontend framework

2018-02-21 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 135305.
juliehockett marked 20 inline comments as done.
juliehockett added a comment.

Cleaning up bitcode writer and fixing pointers for CommentInfos


https://reviews.llvm.org/D41102

Files:
  CMakeLists.txt
  clang-doc/BitcodeWriter.cpp
  clang-doc/BitcodeWriter.h
  clang-doc/CMakeLists.txt
  clang-doc/ClangDoc.h
  clang-doc/Mapper.cpp
  clang-doc/Mapper.h
  clang-doc/Representation.h
  clang-doc/tool/CMakeLists.txt
  clang-doc/tool/ClangDocMain.cpp
  docs/clang-doc.rst
  test/CMakeLists.txt
  test/clang-doc/mapper-class.cpp
  test/clang-doc/mapper-enum.cpp
  test/clang-doc/mapper-function.cpp
  test/clang-doc/mapper-method.cpp
  test/clang-doc/mapper-namespace.cpp
  test/clang-doc/mapper-struct.cpp
  test/clang-doc/mapper-union.cpp

Index: test/clang-doc/mapper-union.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-union.cpp
@@ -0,0 +1,29 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@u...@d.bc --dump | FileCheck %s
+
+union D { int X; int Y; };
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'D'
+  // CHECK: 
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'D::X'
+// CHECK: 
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'D::Y'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+
+
Index: test/clang-doc/mapper-struct.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-struct.cpp
@@ -0,0 +1,23 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@s...@c.bc --dump | FileCheck %s
+
+struct C { int i; };
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'C'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'C::i'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+
+
Index: test/clang-doc/mapper-namespace.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-namespace.cpp
@@ -0,0 +1,17 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@n...@a.bc --dump | FileCheck %s
+
+namespace A {}
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'A'
+// CHECK: 
+
+
Index: test/clang-doc/mapper-method.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-method.cpp
@@ -0,0 +1,31 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@S@G@F@Method#I#.bc --dump | FileCheck %s
+
+class G {
+public: 
+	int Method(int param) { return param; }
+};
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'Method'
+  // CHECK: 
+  // CHECK:  blob data = 'c:@S@G'
+  // CHECK: 
+// CHECK:  blob data = 'int'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'param'
+  // CHECK: 
+// CHECK: 
+
+
+
+
Index: test/clang-doc/mapper-function.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-function.cpp
@@ -0,0 +1,24 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@F@F#I#.bc --dump | FileCheck %s
+
+int F(int param) { return param; }
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'F'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'param'
+  // CHECK: 
+// CHECK: 
+
Index: test/clang-doc/mapper-enum.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-enum.cpp
@@ -0,0 +1,25 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@e...@b.bc --dump | FileCheck %s
+
+enum B { X, Y };
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHEC

[PATCH] D41102: Setup clang-doc frontend framework

2018-02-21 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added inline comments.



Comment at: clang-doc/BitcodeWriter.cpp:407
+
+void ClangDocBinaryWriter::writeBitstream(const EnumInfo &I,
+  BitstreamWriter &Stream,

jakehehrlich wrote:
> lebedev.ri wrote:
> > juliehockett wrote:
> > > lebedev.ri wrote:
> > > > Hmm, common pattern again
> > > > ```
> > > > void ClangDocBinaryWriter::writeBitstream(const  &I,
> > > >   BitstreamWriter &Stream,
> > > >   bool writeBlockInfo) {
> > > >   if (writeBlockInfo) emitBlockInfoBlock(Stream);
> > > >   StreamSubBlock Block(Stream, BI__BLOCK_ID);
> > > >   ...
> > > > }
> > > > ```
> > > > Could be solved if a mapping from `TYPENAME` -> 
> > > > `BI__BLOCK_ID` can be added.
> > > > If LLVM would be using C++14, that'd be easy, but with C++11, it would 
> > > > require whole new class (although with just a single static variable).
> > > Do you want me to try to write that class, or leave it as it is?
> > It would be something like: (total guesswork, literally just wrote it here, 
> > like rest of the snippets)
> > ```
> > template 
> > struct MapFromTypeToEnumerator {
> >   static const BlockId id;
> > };
> > 
> > template <>
> > struct MapFromTypeToEnumerator {
> >   static const BlockId id = BI_NAMESPACE_BLOCK_ID;
> > };
> > void ClangDocBitcodeWriter::writeBitstream(const NamespaceInfo &I) {
> >   EMITINFO(NAMESPACE)
> > }
> > ...
> > 
> > template 
> > void ClangDocBitcodeWriter::writeBitstream(const TypeInfo &I, bool 
> > writeBlockInfo) {
> >   if (writeBlockInfo) emitBlockInfoBlock();
> >   StreamSubBlockGuard Block(Stream, MapFromTypeToEnumerator::id);
> >   writeBitstream(I);
> > }
> > ```
> > Uhm, now that i have wrote it, it does not look as ugly as i though it 
> > would look...
> > So maybe try integrating that, i *think* it is a bit cleaner?
> If we know the set of types then it should just be a static member of every 
> *Info type. Then the mapping is just TYPENAME::id
@jakehehrlich The issue with that is that it would mix writer implementation 
details into the representation, which at this point has no knowledge of the 
writer. We can break that, but is that the best option?



Comment at: clang-doc/Representation.h:79
+  std::string Filename;
+};
+

lebedev.ri wrote:
> Hmm, have you tried adding a constructor here?
> ```
> struct Location {
>   int LineNumber;
>   std::string Filename;
> 
>   Location() = default;
> 
>   Location(int LineNumber_, std::string Filename_) : LineNumber(LineNumber_), 
> Filename(std::move(Filename_)) {}
> };
> ```
> ?
Okay after some research the way to do this is to add the constructor and then 
`emplace_back(Line, File)` -- no braces. That was a fun adventure into the 
implementations of emplace and push :)


https://reviews.llvm.org/D41102



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


[PATCH] D41102: Setup clang-doc frontend framework

2018-02-21 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 135342.
juliehockett marked 6 inline comments as done.
juliehockett added a comment.

Updating location creation and adding mapping from type to BlockId


https://reviews.llvm.org/D41102

Files:
  CMakeLists.txt
  clang-doc/BitcodeWriter.cpp
  clang-doc/BitcodeWriter.h
  clang-doc/CMakeLists.txt
  clang-doc/ClangDoc.h
  clang-doc/Mapper.cpp
  clang-doc/Mapper.h
  clang-doc/Representation.h
  clang-doc/tool/CMakeLists.txt
  clang-doc/tool/ClangDocMain.cpp
  docs/clang-doc.rst
  test/CMakeLists.txt
  test/clang-doc/mapper-class.cpp
  test/clang-doc/mapper-enum.cpp
  test/clang-doc/mapper-function.cpp
  test/clang-doc/mapper-method.cpp
  test/clang-doc/mapper-namespace.cpp
  test/clang-doc/mapper-struct.cpp
  test/clang-doc/mapper-union.cpp

Index: test/clang-doc/mapper-union.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-union.cpp
@@ -0,0 +1,29 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@u...@d.bc --dump | FileCheck %s
+
+union D { int X; int Y; };
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'D'
+  // CHECK: 
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'D::X'
+// CHECK: 
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'D::Y'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+
+
Index: test/clang-doc/mapper-struct.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-struct.cpp
@@ -0,0 +1,23 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@s...@c.bc --dump | FileCheck %s
+
+struct C { int i; };
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'C'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'C::i'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+
+
Index: test/clang-doc/mapper-namespace.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-namespace.cpp
@@ -0,0 +1,17 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@n...@a.bc --dump | FileCheck %s
+
+namespace A {}
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'A'
+// CHECK: 
+
+
Index: test/clang-doc/mapper-method.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-method.cpp
@@ -0,0 +1,31 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@S@G@F@Method#I#.bc --dump | FileCheck %s
+
+class G {
+public: 
+	int Method(int param) { return param; }
+};
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'Method'
+  // CHECK: 
+  // CHECK:  blob data = 'c:@S@G'
+  // CHECK: 
+// CHECK:  blob data = 'int'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'param'
+  // CHECK: 
+// CHECK: 
+
+
+
+
Index: test/clang-doc/mapper-function.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-function.cpp
@@ -0,0 +1,24 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@F@F#I#.bc --dump | FileCheck %s
+
+int F(int param) { return param; }
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'F'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'param'
+  // CHECK: 
+// CHECK: 
+
Index: test/clang-doc/mapper-enum.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-enum.cpp
@@ -0,0 +1,25 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@e...@b.bc --dump | FileCheck %s
+
+enum B { X, Y };
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CH

[PATCH] D41102: Setup clang-doc frontend framework

2018-02-22 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 135453.
juliehockett marked 13 inline comments as done.
juliehockett added a comment.

Cleaning up bitcode writer


https://reviews.llvm.org/D41102

Files:
  CMakeLists.txt
  clang-doc/BitcodeWriter.cpp
  clang-doc/BitcodeWriter.h
  clang-doc/CMakeLists.txt
  clang-doc/ClangDoc.h
  clang-doc/Mapper.cpp
  clang-doc/Mapper.h
  clang-doc/Representation.h
  clang-doc/tool/CMakeLists.txt
  clang-doc/tool/ClangDocMain.cpp
  docs/clang-doc.rst
  test/CMakeLists.txt
  test/clang-doc/mapper-class.cpp
  test/clang-doc/mapper-enum.cpp
  test/clang-doc/mapper-function.cpp
  test/clang-doc/mapper-method.cpp
  test/clang-doc/mapper-namespace.cpp
  test/clang-doc/mapper-struct.cpp
  test/clang-doc/mapper-union.cpp

Index: test/clang-doc/mapper-union.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-union.cpp
@@ -0,0 +1,29 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@u...@d.bc --dump | FileCheck %s
+
+union D { int X; int Y; };
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'D'
+  // CHECK: 
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'D::X'
+// CHECK: 
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'D::Y'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+
+
Index: test/clang-doc/mapper-struct.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-struct.cpp
@@ -0,0 +1,23 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@s...@c.bc --dump | FileCheck %s
+
+struct C { int i; };
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'C'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'C::i'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+
+
Index: test/clang-doc/mapper-namespace.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-namespace.cpp
@@ -0,0 +1,17 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@n...@a.bc --dump | FileCheck %s
+
+namespace A {}
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'A'
+// CHECK: 
+
+
Index: test/clang-doc/mapper-method.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-method.cpp
@@ -0,0 +1,31 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@S@G@F@Method#I#.bc --dump | FileCheck %s
+
+class G {
+public: 
+	int Method(int param) { return param; }
+};
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'Method'
+  // CHECK: 
+  // CHECK:  blob data = 'c:@S@G'
+  // CHECK: 
+// CHECK:  blob data = 'int'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'param'
+  // CHECK: 
+// CHECK: 
+
+
+
+
Index: test/clang-doc/mapper-function.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-function.cpp
@@ -0,0 +1,24 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@F@F#I#.bc --dump | FileCheck %s
+
+int F(int param) { return param; }
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'F'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'param'
+  // CHECK: 
+// CHECK: 
+
Index: test/clang-doc/mapper-enum.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-enum.cpp
@@ -0,0 +1,25 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@e...@b.bc --dump | FileCheck %s
+
+enum B { X, Y };
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'B'
+  

[PATCH] D41102: Setup clang-doc frontend framework

2018-02-22 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added inline comments.



Comment at: clang-doc/BitcodeWriter.cpp:219
+
+void ClangDocBitcodeWriter::emitIntRecord(int Value, RecordId ID) {
+  if (!Value) return;

lebedev.ri wrote:
> Now, all these three `emit*Record` functions now have the 'same signature':
> ```
> template 
> void ClangDocBitcodeWriter::emitRecord(const T& Record, RecordId ID);
> 
> template <>
> void ClangDocBitcodeWriter::emitRecord(StringRef Str, RecordId ID) {
> ...
> ```
> 
> **Assuming there are no implicit conversions going on**, i'd make that change.
> It, again, may open the road for further generalizations.
I overloaded the functions -- cleaner, and deals with any implicit conversions 
nicely.



Comment at: clang-doc/BitcodeWriter.h:178
+  void emitTypeBlock(const std::unique_ptr &N);
+  void emitMemberTypeBlock(const std::unique_ptr &N);
+  void emitFieldTypeBlock(const std::unique_ptr &N);

lebedev.ri wrote:
> Let's continue cracking down on duplication.
> I think these four functions need the same template treatment as 
> `writeBitstreamForInfo()`
> 
> (please feel free to use better names)
> ```
> template
> void emitBlock(const std::unique_ptr &B);
> 
> template
> void emitTypedBlock(const std::unique_ptr &B) {
>   StreamSubBlockGuard Block(Stream, MapFromInfoToBlockId::ID);
>   emitBlock(B);
> }
> 
> template<>
> void ClangDocBitcodeWriter::emitBlock(const std::unique_ptr &T) {
>   emitStringRecord(T->TypeUSR, FIELD_TYPE_TYPE);
>   for (const auto &CI : T->Description) emitCommentBlock(CI);
> }
> ```
> 
> I agree that it seems strange, and seem to actually increase the code size so 
> far,
> but i believe by exposing similar functionality under one function,
> later, it will open the road for more opportunities of further consolidation.
Since it actually ended up duplicating the `writeBitstreamForInfo()` code, I 
rolled all of this into one `emitBlock()` entry point.


https://reviews.llvm.org/D41102



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


[PATCH] D43341: [clang-doc] Implement reducer portion of the frontend framework

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

Updating for parent diff changes


https://reviews.llvm.org/D43341

Files:
  clang-doc/BitcodeReader.cpp
  clang-doc/BitcodeReader.h
  clang-doc/BitcodeWriter.cpp
  clang-doc/BitcodeWriter.h
  clang-doc/CMakeLists.txt
  clang-doc/Reducer.cpp
  clang-doc/Reducer.h
  clang-doc/Representation.cpp
  clang-doc/Representation.h
  clang-doc/tool/ClangDocMain.cpp
  test/clang-doc/mapper-class.cpp
  test/clang-doc/mapper-enum.cpp
  test/clang-doc/mapper-function.cpp
  test/clang-doc/mapper-method.cpp
  test/clang-doc/mapper-namespace.cpp
  test/clang-doc/mapper-struct.cpp
  test/clang-doc/mapper-union.cpp
  test/clang-doc/namespace.cpp
  test/clang-doc/record.cpp

Index: test/clang-doc/record.cpp
===
--- /dev/null
+++ test/clang-doc/record.cpp
@@ -0,0 +1,107 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/bc/docs.bc --dump | FileCheck %s
+
+union A { int X; int Y; };
+
+enum B { X, Y };
+
+struct C { int i; };
+
+class D {};
+
+class E {
+public:
+  E() {}
+  ~E() {}
+
+protected:
+  void ProtectedMethod();
+};
+
+void E::ProtectedMethod() {}
+
+class F : virtual private D, public E {};
+
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'E'
+  // CHECK: 
+  // CHECK:  blob data = 'c:@S@E'
+  // CHECK: 
+// CHECK:  blob data = 'void'
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = '~E'
+  // CHECK: 
+  // CHECK:  blob data = 'c:@S@E'
+  // CHECK: 
+// CHECK:  blob data = 'void'
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'ProtectedMethod'
+  // CHECK: 
+  // CHECK:  blob data = 'c:@S@E'
+  // CHECK: 
+// CHECK:  blob data = 'void'
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'A'
+  // CHECK: 
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'A::X'
+// CHECK: 
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'A::Y'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'C'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'C::i'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'D'
+  // CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'E'
+  // CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'F'
+  // CHECK: 
+  // CHECK: 
+  // CHECK:  blob data = 'c:@S@E'
+  // CHECK:  blob data = 'c:@S@D'
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'B'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'X'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'Y'
+  // CHECK: 
+// CHECK: 
Index: test/clang-doc/namespace.cpp
===
--- /dev/null
+++ test/clang-doc/namespace.cpp
@@ -0,0 +1,67 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/bc/docs.bc --dump | FileCheck %s
+
+namespace A {
+
+void f();
+void f() {};
+
+} // A
+
+namespace A {
+namespace B {
+
+enum E { X };
+
+E func(int i) { 
+  return X;
+}
+
+}
+}
+
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'A'
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'B'
+  // CHECK:  blob data = 'c:@N@A'
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'f'
+  // CHECK:  blob data = 'c:@N@A'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'void'
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'func'
+  // CHECK:  blob data = 'c:@N@A@N@B'
+  // CHECK:  blob data = 'c:@N@A'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'enum A::B::E'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'i'
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'E'
+  // CHECK:  blob data = 'c:@N@A@N@B'
+  // CHECK:  blob data = 'c:@N@A'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'A::B::X'
+  // CHECK: 
+// CHECK: 
Index: test/clang-doc/mapper-union.cpp
===
--- test/clang-doc/mapper-union.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-// RUN: rm -rf %t
-// RUN: mkdir %t
-// RUN: echo "" > %t/compile_flags.txt
-// RUN: cp "%s" "%t/test.cpp"
-// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
-// RUN: llvm-bcanalyzer %t/docs/c:@u...@d.bc --dump | FileCheck %s
-
-union D { int X; int Y; };
-// CHECK: 
-// CHECK: 
-  // CHECK: 
-// CHECK: 
-// CHECK: 
-  // CHECK:  blob data = 'D'
-  // 

[PATCH] D41102: Setup clang-doc frontend framework

2018-02-22 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 135559.
juliehockett marked 10 inline comments as done.
juliehockett added a comment.

Refactoring bitcode writer


https://reviews.llvm.org/D41102

Files:
  CMakeLists.txt
  clang-doc/BitcodeWriter.cpp
  clang-doc/BitcodeWriter.h
  clang-doc/CMakeLists.txt
  clang-doc/ClangDoc.h
  clang-doc/Mapper.cpp
  clang-doc/Mapper.h
  clang-doc/Representation.h
  clang-doc/tool/CMakeLists.txt
  clang-doc/tool/ClangDocMain.cpp
  docs/clang-doc.rst
  test/CMakeLists.txt
  test/clang-doc/mapper-class.cpp
  test/clang-doc/mapper-enum.cpp
  test/clang-doc/mapper-function.cpp
  test/clang-doc/mapper-method.cpp
  test/clang-doc/mapper-namespace.cpp
  test/clang-doc/mapper-struct.cpp
  test/clang-doc/mapper-union.cpp

Index: test/clang-doc/mapper-union.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-union.cpp
@@ -0,0 +1,29 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@u...@d.bc --dump | FileCheck %s
+
+union D { int X; int Y; };
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'D'
+  // CHECK: 
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'D::X'
+// CHECK: 
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'D::Y'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+
+
+
Index: test/clang-doc/mapper-struct.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-struct.cpp
@@ -0,0 +1,24 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@s...@c.bc --dump | FileCheck %s
+
+struct C { int i; };
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'C'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'C::i'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+
+
+
Index: test/clang-doc/mapper-namespace.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-namespace.cpp
@@ -0,0 +1,17 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@n...@a.bc --dump | FileCheck %s
+
+namespace A {}
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'A'
+// CHECK: 
+
+
Index: test/clang-doc/mapper-method.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-method.cpp
@@ -0,0 +1,31 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@S@G@F@Method#I#.bc --dump | FileCheck %s
+
+class G {
+public: 
+	int Method(int param) { return param; }
+};
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'Method'
+  // CHECK: 
+  // CHECK:  blob data = 'c:@S@G'
+  // CHECK: 
+// CHECK:  blob data = 'int'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'param'
+  // CHECK: 
+// CHECK: 
+
+
+
+
Index: test/clang-doc/mapper-function.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-function.cpp
@@ -0,0 +1,25 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@F@F#I#.bc --dump | FileCheck %s
+
+int F(int param) { return param; }
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'F'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'param'
+  // CHECK: 
+// CHECK: 
+
+
Index: test/clang-doc/mapper-enum.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-enum.cpp
@@ -0,0 +1,26 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@e...@b.bc --dump | FileCheck %s
+
+enum B { X, Y };
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'B'
+  // CHE

[PATCH] D43667: [clang-doc] Implement a YAML generator

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

Implmenting a YAML generator from the emitted bitcode summary of declarations. 
Emits one YAML file with all declaration information.

For a more detailed overview of the tool, see the design document on the 
mailing list: RFC: clang-doc proposal 



https://reviews.llvm.org/D43667

Files:
  clang-doc/CMakeLists.txt
  clang-doc/generators/CMakeLists.txt
  clang-doc/generators/GeneratorBase.cpp
  clang-doc/generators/Generators.h
  clang-doc/generators/YAMLGenerator.cpp
  clang-doc/tool/CMakeLists.txt
  clang-doc/tool/ClangDocMain.cpp
  test/clang-doc/namespace-yaml.cpp
  test/clang-doc/record-yaml.cpp

Index: test/clang-doc/record-yaml.cpp
===
--- /dev/null
+++ test/clang-doc/record-yaml.cpp
@@ -0,0 +1,119 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: cat %t/docs/yaml/docs.yaml | FileCheck %s
+
+union A { int X; int Y; };
+
+enum B { X, Y };
+
+struct C { int i; };
+
+class D {};
+
+class E {
+public:
+  E() {}
+  ~E() {}
+
+protected:
+  void ProtectedMethod();
+};
+
+void E::ProtectedMethod() {}
+
+class F : virtual private D, public E {};
+
+// CHECK: ---
+// CHECK: Namespaces:  
+// CHECK: Records: 
+// CHECK:   - Name:A
+// CHECK: TagType: Union
+// CHECK: IsDefinition:true
+// CHECK: Location:
+// CHECK: Members: 
+// CHECK:   - Type:int
+// CHECK: Name:'A::X'
+// CHECK: Access:  None
+// CHECK: Description: 
+// CHECK:   - Type:int
+// CHECK: Name:'A::Y'
+// CHECK: Access:  None
+// CHECK: Description: 
+// CHECK: ParentUSRs:  
+// CHECK: VirtualParentUSRs: 
+// CHECK:   - Name:C
+// CHECK: TagType: Struct
+// CHECK: IsDefinition:true
+// CHECK: Location:
+// CHECK: Members: 
+// CHECK:   - Type:int
+// CHECK: Name:'C::i'
+// CHECK: Access:  None
+// CHECK: Description: 
+// CHECK: ParentUSRs:  
+// CHECK: VirtualParentUSRs: 
+// CHECK:   - Name:D
+// CHECK: TagType: Class
+// CHECK: IsDefinition:true
+// CHECK: Location:
+// CHECK: Members: 
+// CHECK: ParentUSRs:  
+// CHECK: VirtualParentUSRs: 
+// CHECK:   - Name:E
+// CHECK: TagType: Class
+// CHECK: IsDefinition:true
+// CHECK: Location:
+// CHECK: Members: 
+// CHECK: ParentUSRs:  
+// CHECK: VirtualParentUSRs: 
+// CHECK:   - Name:F
+// CHECK: TagType: Class
+// CHECK: IsDefinition:true
+// CHECK: Location:
+// CHECK: Members: 
+// CHECK: ParentUSRs:  
+// CHECK:   - 'c:@S@E'
+// CHECK: VirtualParentUSRs: 
+// CHECK:   - 'c:@S@D'
+// CHECK: Functions:   
+// CHECK:   - Name:E
+// CHECK: IsDefinition:true
+// CHECK: Location:
+// CHECK: ParentUSR:   E
+// CHECK: Params:  
+// CHECK: ReturnType:  
+// CHECK:   Type:void
+// CHECK:   Description: 
+// CHECK: Access:  Public
+// CHECK:   - Name:'~E'
+// CHECK: IsDefinition:true
+// CHECK: Location:
+// CHECK: ParentUSR:   '~E'
+// CHECK: Params:  
+// CHECK: ReturnType:  
+// CHECK:   Type:void
+// CHECK:   Description: 
+// CHECK: Access:  Public
+// CHECK:   - Name:ProtectedMethod
+// CHECK: IsDefinition:true
+// CHECK: Location:
+// CHECK: ParentUSR:   ProtectedMethod
+// CHECK: Params:  
+// CHECK: ReturnType:  
+// CHECK:   Type:void
+// CHECK:   Description: 
+// CHECK: Access:  Public
+// CHECK: Enums:   
+// CHECK:   - Name:B
+// CHECK: IsDefinition:true
+// CHECK: Location:
+// CHECK: Scoped:  false
+// CHECK: Members: 
+// CHECK:   - Type:X
+// CHECK: Description: 
+// CHECK:   - Type:Y
+// CHECK: Description: 
+// CHECK: ...
Index: test/clang-doc/namespace-yaml.cpp
===
--- /dev/null
+++ test/cl

[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 &I : IS->getNamespaceInfos()) Success = writeNamespacePage(I);
+  return Success;
+}
+
+bool MDGenerator::writeClasses() {
+  bool Success = true;
+  for (const auto &I : IS->getRecordInfos()) {
+if (I->TagType == TagTypeKind::TTK_Class) Success = writeClassPage(I);
+  }
+  return Success;
+}
+
+bool MDGenerator::writeNamespacePage(const std::unique_ptr &I) {
+  SmallString<128> Path;
+  sys::path::native(NamespacesPath, Path);
+  // for (const auto &Namespace : 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 &C : I->Description) writeDescription(C, OS);
+
+  // TODO: Write subnamespaces
+
+  // Write functions.
+  bool wroteFunctionHeader = false;
+  for (const auto &F : 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 &R : 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 &S : Structs) {
+if (!wroteHeader) {
+  wroteHeader = true;
+  writeLine(genH2("Structs"), OS);
+}
+writeRecordSummary(*S, OS);
+writeBlankLine(OS);
+  }
+
+  // Write classes.
+  wroteHeader = false;
+  sortRecordInfos(Classes);
+  for (const auto &C : Classes) {
+if (!wroteHeader) {
+  wroteHeader = true;
+  writeLine(genH2("Classes"), OS);
+}
+writeRecordSummary(*C, OS);
+writeBlankLine(OS);
+  }
+
+  // Write unions.
+  wroteHeader = false;
+  sortRecordI

[PATCH] D41102: Setup clang-doc frontend framework

2018-02-23 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 135678.
juliehockett marked 29 inline comments as done.
juliehockett added a comment.

1. Continued refactoring the bitcode writer
2. Added a USR attribute to infos
3. Created a Reference struct to replace the string references to other infos


https://reviews.llvm.org/D41102

Files:
  CMakeLists.txt
  clang-doc/BitcodeWriter.cpp
  clang-doc/BitcodeWriter.h
  clang-doc/CMakeLists.txt
  clang-doc/ClangDoc.h
  clang-doc/Mapper.cpp
  clang-doc/Mapper.h
  clang-doc/Representation.h
  clang-doc/tool/CMakeLists.txt
  clang-doc/tool/ClangDocMain.cpp
  docs/clang-doc.rst
  test/CMakeLists.txt
  test/clang-doc/mapper-class.cpp
  test/clang-doc/mapper-enum.cpp
  test/clang-doc/mapper-function.cpp
  test/clang-doc/mapper-method.cpp
  test/clang-doc/mapper-namespace.cpp
  test/clang-doc/mapper-struct.cpp
  test/clang-doc/mapper-union.cpp

Index: test/clang-doc/mapper-union.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-union.cpp
@@ -0,0 +1,32 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@u...@d.bc --dump | FileCheck %s
+
+union D { int X; int Y; };
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'c:@U@D'
+  // CHECK:  blob data = 'D'
+  // CHECK: 
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'D::X'
+// CHECK: 
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'D::Y'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+
+
+
+
Index: test/clang-doc/mapper-struct.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-struct.cpp
@@ -0,0 +1,26 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@s...@c.bc --dump | FileCheck %s
+
+struct C { int i; };
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'c:@S@C'
+  // CHECK:  blob data = 'C'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'C::i'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+
+
+
+
Index: test/clang-doc/mapper-namespace.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-namespace.cpp
@@ -0,0 +1,19 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@n...@a.bc --dump | FileCheck %s
+
+namespace A {}
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'c:@N@A'
+  // CHECK:  blob data = 'A'
+// CHECK: 
+
+
+
Index: test/clang-doc/mapper-method.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-method.cpp
@@ -0,0 +1,33 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@S@G@F@Method#I#.bc --dump | FileCheck %s
+
+class G {
+public: 
+	int Method(int param) { return param; }
+};
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'c:@S@G@F@Method#I#'
+  // CHECK:  blob data = 'Method'
+  // CHECK: 
+  // CHECK:  blob data = 'c:@S@G'
+  // CHECK: 
+// CHECK:  blob data = 'int'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'param'
+  // CHECK: 
+// CHECK: 
+
+
+
+
+
Index: test/clang-doc/mapper-function.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-function.cpp
@@ -0,0 +1,29 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@F@F#I#.bc --dump | FileCheck %s
+
+int F(int param) { return param; }
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'c:@F@F#I#'
+  // CHECK:  blob data = 'F'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'param'
+  // CHECK: 
+// CHECK: 
+
+
+
+
+
Index: test/clang-doc/mapper-enum.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-enum.cpp
@@ -0,0 +1,27 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+

[PATCH] D41102: Setup clang-doc frontend framework

2018-02-23 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added a comment.

In https://reviews.llvm.org/D41102#1017499, @Athosvk wrote:

> Disadvantage is of course that you add complexity to certain parts of the 
> deserialization (/serialization) for nested types and inheritance, by either 
> having to do so in the correct order or having to defer the process of 
> initializing these pointers. But see this as just as some thought sharing. I 
> do think this would improve the interaction in the backend (assuming you use 
> the same representation as currently in the frontend).


I agree that the pointer approach would be much more efficient on the backend, 
but the issue here is that the mapper has no idea where the representation of 
anything other than the decl it's currently looking at will be, since it sees 
each decl and serializes it immediately. The reducer, on the other hand, will 
be able to see everything, and so such pointers could be added as a pass over 
the final reduced data structure.
So, as an idea (as this diff implements), I updated the string references to be 
a struct, which holds the USR of the referenced type (for serialization, both 
here in the mapper and for the dump option in the reducer, as well as a pointer 
to an `Info` struct. This pointer is not used at this point, but would be 
populated by the reducer. Thoughts?

> Have you actually started work already on some backend? Developing backend 
> and frontend in tandem can provide some additional insights as to how things 
> should be structured, especially representation-wise!

I added you as a subscriber on the follow-up patches (the reducer, YAML/MD 
formats) -- would love to hear your thoughts! As of now, the MD output is very 
rough, but I'm hoping to keep moving forward on that in the next few days.




Comment at: clang-doc/BitcodeWriter.h:53
+  BI_LAST = BI_COMMENT_BLOCK_ID
+};
+

lebedev.ri wrote:
> So what *exactly* does `BitCodeConstants::SubblockIDSize` mean?
> ```
> static_assert(BI_LAST < (1U << BitCodeConstants::SubblockIDSize), "Too many 
> block id's!");
> ```
> ?
It's the current abbrev id width for the block (described [[ 
https://llvm.org/docs/BitCodeFormat.html#enter-subblock-encoding | here ]]), so 
it's the max id width for the block's abbrevs.



Comment at: clang-doc/BitcodeWriter.h:94
+  FUNCTION_LOCATION,
+  FUNCTION_MANGLED_NAME,
+  FUNCTION_PARENT,

lebedev.ri wrote:
> So i have a question: if something (`FUNCTION_MANGLED_NAME` in this case) is 
> phased out, does it have to stay in this enum?
> That will introduce holes in `RecordIdNameMap`.
> Are the actual numerical id's of enumerators stored in the bitcode, or the 
> string (abbrev, `RecordIdNameMap[].Name`)?
> 
> Looking at tests, i guess these enums are internal detail, and they can be 
> changed freely, including removing enumerators.
> Am i wrong?
> 
> I think that should be explained in a comment before this `enum`.
Yes, the enum is an implementation detail (`FUNCTION_MANGLED_NAME` should have 
been removed earlier). I'll put the comment describing how it works!


https://reviews.llvm.org/D41102



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


[PATCH] D41102: Setup clang-doc frontend framework

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

Fixing CMakeLists formatting


https://reviews.llvm.org/D41102

Files:
  CMakeLists.txt
  clang-doc/BitcodeWriter.cpp
  clang-doc/BitcodeWriter.h
  clang-doc/CMakeLists.txt
  clang-doc/ClangDoc.h
  clang-doc/Mapper.cpp
  clang-doc/Mapper.h
  clang-doc/Representation.h
  clang-doc/tool/CMakeLists.txt
  clang-doc/tool/ClangDocMain.cpp
  docs/clang-doc.rst
  test/CMakeLists.txt
  test/clang-doc/mapper-class.cpp
  test/clang-doc/mapper-enum.cpp
  test/clang-doc/mapper-function.cpp
  test/clang-doc/mapper-method.cpp
  test/clang-doc/mapper-namespace.cpp
  test/clang-doc/mapper-struct.cpp
  test/clang-doc/mapper-union.cpp

Index: test/clang-doc/mapper-union.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-union.cpp
@@ -0,0 +1,32 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@u...@d.bc --dump | FileCheck %s
+
+union D { int X; int Y; };
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'c:@U@D'
+  // CHECK:  blob data = 'D'
+  // CHECK: 
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'D::X'
+// CHECK: 
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'D::Y'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+
+
+
+
Index: test/clang-doc/mapper-struct.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-struct.cpp
@@ -0,0 +1,26 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@s...@c.bc --dump | FileCheck %s
+
+struct C { int i; };
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'c:@S@C'
+  // CHECK:  blob data = 'C'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'C::i'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+
+
+
+
Index: test/clang-doc/mapper-namespace.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-namespace.cpp
@@ -0,0 +1,19 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@n...@a.bc --dump | FileCheck %s
+
+namespace A {}
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'c:@N@A'
+  // CHECK:  blob data = 'A'
+// CHECK: 
+
+
+
Index: test/clang-doc/mapper-method.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-method.cpp
@@ -0,0 +1,33 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@S@G@F@Method#I#.bc --dump | FileCheck %s
+
+class G {
+public: 
+	int Method(int param) { return param; }
+};
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'c:@S@G@F@Method#I#'
+  // CHECK:  blob data = 'Method'
+  // CHECK: 
+  // CHECK:  blob data = 'c:@S@G'
+  // CHECK: 
+// CHECK:  blob data = 'int'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'param'
+  // CHECK: 
+// CHECK: 
+
+
+
+
+
Index: test/clang-doc/mapper-function.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-function.cpp
@@ -0,0 +1,29 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@F@F#I#.bc --dump | FileCheck %s
+
+int F(int param) { return param; }
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'c:@F@F#I#'
+  // CHECK:  blob data = 'F'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'param'
+  // CHECK: 
+// CHECK: 
+
+
+
+
+
Index: test/clang-doc/mapper-enum.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-enum.cpp
@@ -0,0 +1,27 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcana

[PATCH] D43392: [clang-tidy] Add Fuchsia checker for visibility attributes

2018-02-26 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 135944.
juliehockett marked 6 inline comments as done.
juliehockett added a comment.

After discussion, the goal of this checker slightly changed to target 
definitions in header files, rather than declarations. As a result, the check 
now adds the attribute to any definition (declaration or not) that appears in a 
header file.

Also updating tests.


https://reviews.llvm.org/D43392

Files:
  clang-tidy/fuchsia/AddVisibilityCheck.cpp
  clang-tidy/fuchsia/AddVisibilityCheck.h
  clang-tidy/fuchsia/CMakeLists.txt
  clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/fuchsia-add-visibility.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/fuchsia-add-visibility-pragma.hpp
  test/clang-tidy/fuchsia-add-visibility.cpp
  test/clang-tidy/fuchsia-add-visibility.hpp

Index: test/clang-tidy/fuchsia-add-visibility.hpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-add-visibility.hpp
@@ -0,0 +1,48 @@
+// RUN: %check_clang_tidy %s fuchsia-add-visibility %t -- \
+// RUN:   -config="{CheckOptions: [{key: fuchsia-add-visibility.Names, value: 'foo;bar;baz;foobar;f;g;h;i'}, \
+// RUN:{key: fuchsia-add-visibility.Visibility, value: 'protected'}]}" \
+// RUN:   -header-filter=.* \
+// RUN: -- -std=c++11
+
+void foo();
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: no explicit visibility attribute set for specified function
+// CHECK-FIXES: __attribute__((visibility("protected")))
+
+void foo();
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: no explicit visibility attribute set for specified function
+// CHECK-FIXES: __attribute__((visibility("protected")))
+
+__attribute__((visibility("default")))
+void i();
+// CHECK-MESSAGES: [[@LINE-2]]:1: warning: protected visibility attribute not set for specified function
+// CHECK-FIXES: __attribute__((visibility("protected")))
+
+__attribute__((visibility("default")))
+void i();
+// CHECK-MESSAGES: [[@LINE-2]]:1: warning: protected visibility attribute not set for specified function
+// CHECK-FIXES: __attribute__((visibility("protected")))
+
+__attribute__((visibility("protected")))
+void bar() {}
+
+__attribute__((visibility("protected")))
+void baz();
+void baz() {}
+
+__attribute__((visibility("default")))
+void foobar() {}
+// CHECK-MESSAGES: [[@LINE-2]]:1: warning: protected visibility attribute not set for specified function
+// CHECK-FIXES: __attribute__((visibility("protected")))
+
+__attribute__((visibility("protected"))) 
+void foo(int);
+void foo(double);
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: no explicit visibility attribute set for specified function
+// CHECK-FIXES: __attribute__((visibility("protected")))
+
+template 
+__attribute__((visibility("protected"))) 
+void h(Ty);
+
+template <>
+void h(int);
Index: test/clang-tidy/fuchsia-add-visibility.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-add-visibility.cpp
@@ -0,0 +1,10 @@
+// RUN: clang-tidy %s -checks=-*,fuchsia-add-visibility \
+// RUN:   -config="{CheckOptions: [{key: fuchsia-add-visibility.Names, value: 'foo;bar;baz;foobar;f;g'}, \
+// RUN:{key: fuchsia-add-visibility.Visibility, value: 'protected'}]}" \
+// RUN: -- -std=c++11 | count 0
+
+// Note: this test expects no diagnostics, but FileCheck cannot handle that,
+// hence the use of | count 0.
+
+void foo();
+void foo() {}
Index: test/clang-tidy/fuchsia-add-visibility-pragma.hpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-add-visibility-pragma.hpp
@@ -0,0 +1,36 @@
+// RUN: %check_clang_tidy %s fuchsia-add-visibility %t -- \
+// RUN:   -config="{CheckOptions: [{key: fuchsia-add-visibility.Names, value: 'foo;bar;baz;foobar;f;g'}, \
+// RUN:{key: fuchsia-add-visibility.Visibility, value: 'protected'}]}" \
+// RUN:   -header-filter=.* \
+// RUN: -- -std=c++11
+
+#pragma GCC visibility push(hidden)
+
+void foo();
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: protected visibility attribute not set for specified function
+// CHECK-FIXES: __attribute__((visibility("protected")))
+
+__attribute__((visibility("protected")))
+void bar() {}
+
+__attribute__((visibility("protected")))
+void baz();
+void baz() {}
+
+__attribute__((visibility("default")))
+void foobar() {}
+// CHECK-MESSAGES: [[@LINE-2]]:1: warning: protected visibility attribute not set for specified function
+// CHECK-FIXES: __attribute__((visibility("protected")))
+
+__attribute__((visibility("protected"))) 
+void foo(int);
+void foo(double);
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: protected visibility attribute not set for specified function
+// CHECK-FIXES: __attribute__((visibility("protected")))
+
+template 
+__attribute__((visibility("protected"))) 
+void foo(Ty);
+
+template <>
+void foo(int);
Index: docs/clang-tidy/checks/list.rst
===

[PATCH] D43392: [clang-tidy] Add Fuchsia checker for visibility attributes

2018-02-26 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added inline comments.



Comment at: clang-tidy/fuchsia/AddVisibilityCheck.cpp:52-53
+  Finder->addMatcher(
+  functionDecl(allOf(hasAnyName(SmallVector(Names.begin(),
+  Names.end())),
+ isDefinition(), unless(hasVisibilityAttr(V

aaron.ballman wrote:
> Can you use `makeArrayRef()` rather than using a `SmallVector` that allocates?
Type-wise it gets funky -- `makeArrayRef()` creates an `ArrayRef`, 
and the matcher wants a container of `StringRefs`. Is there a good way to do 
that without allocating?


https://reviews.llvm.org/D43392



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


[PATCH] D43778: [clang-tidy] Adding RestrictIncludes check to Fuchsia module

2018-02-26 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett created this revision.
juliehockett added reviewers: aaron.ballman, hokein, ilya-biryukov.
juliehockett added a project: clang-tools-extra.
Herald added subscribers: xazax.hun, mgorny.

Adding a check to restrict specific includes. Given a list of includes that 
should not be used, the check issues a fixit to remove any include on that list 
from the source file.


https://reviews.llvm.org/D43778

Files:
  clang-tidy/fuchsia/CMakeLists.txt
  clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tidy/fuchsia/RestrictIncludesCheck.cpp
  clang-tidy/fuchsia/RestrictIncludesCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/fuchsia-restrict-includes.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/fuchsia-restrict-includes.cpp

Index: test/clang-tidy/fuchsia-restrict-includes.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-restrict-includes.cpp
@@ -0,0 +1,13 @@
+// RUN: %check_clang_tidy %s fuchsia-restrict-includes %t \
+// RUN:		-config="{CheckOptions: [{key: fuchsia-restrict-includes.Includes, value: 'b.h;s.h;'}]}" \
+// RUN:   -- -std=c++11 -I %S/Inputs/Headers -isystem %S/Inputs/Headers
+
+#include "a.h"
+#include "b.h"
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: Restricted include found.
+// CHECK-FIXES-NOT: #include "b.h"
+
+#include 
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: Restricted include found.
+// CHECK-FIXES-NOT: #include 
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -74,6 +74,7 @@
fuchsia-default-arguments
fuchsia-multiple-inheritance
fuchsia-overloaded-operator
+   fuchsia-restrict-includes
fuchsia-statically-constructed-objects
fuchsia-trailing-return
fuchsia-virtual-inheritance
Index: docs/clang-tidy/checks/fuchsia-restrict-includes.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/fuchsia-restrict-includes.rst
@@ -0,0 +1,27 @@
+.. title:: clang-tidy - fuchsia-restrict-includes
+
+fuchsia-restrict-includes
+=
+
+Checks for restricted headers and suggests their removal.
+
+For example, given the restricted include name 'a.h', if either:
+
+.. code-block:: c++
+
+  #include "a.h"
+
+or
+
+.. code-block:: c++
+
+  #include 
+
+appears, the fix would suggest its removal. 
+  
+Options
+---
+
+.. option:: Includes
+
+   A string containing a comma-separated list of header filenames to restrict. Default is an empty string.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -75,6 +75,11 @@
 
   Warns if a class inherits from multiple classes that are not pure virtual.
 
+- New `fuchsia-restrict-includes
+  `_ check
+
+  Checks for restricted headers and suggests their removal.
+
 - New `fuchsia-statically-constructed-objects
   `_ check
 
Index: clang-tidy/fuchsia/RestrictIncludesCheck.h
===
--- /dev/null
+++ clang-tidy/fuchsia/RestrictIncludesCheck.h
@@ -0,0 +1,44 @@
+//===--- RestrictIncludesCheck.h - clang-tidy-*- C++-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_RESTRICTHEADERSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_RESTRICTHEADERSCHECK_H
+
+#include "../ClangTidy.h"
+#include "../utils/OptionsUtils.h"
+
+namespace clang {
+namespace tidy {
+namespace fuchsia {
+
+/// Checks for restricted headers and suggests their removal.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia-restrict-includes.html
+class RestrictIncludesCheck : public ClangTidyCheck {
+ public:
+  RestrictIncludesCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context),
+RestrictedIncludes(utils::options::parseStringList(
+Options.get("Includes", "::std::vector"))) {}
+  void registerPPCallbacks(CompilerInstance &Compiler) override;
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
+  std::vector &getRestrictedIncludes() {
+return RestrictedIncludes;
+  }
+
+ private:
+  std::vector RestrictedIncludes;
+};
+
+}  // namespace fuchsia
+}  // namespace tidy
+}  // namespace clang
+
+#endif  // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_RESTRICTHEADERSCHECK_H
Index: clang-tidy/fuchsia/RestrictIncludesCheck.cpp
===

[PATCH] D41102: Setup clang-doc frontend framework

2018-02-26 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added a comment.

In https://reviews.llvm.org/D41102#1017918, @lebedev.ri wrote:

> Is there some (internal to `BitstreamWriter`) logic that would 'assert()' if 
> trying to output some recordid
>  which is, according to the `BLOCKINFO_BLOCK`, should not be there?
>  E.g. outputting `VERSION` in `BI_COMMENT_BLOCK_ID`?


Yes -- it will fail an assertion:
`Assertion 'V == Op.getLiteralValue() && "Invalid abbrev for record!"' failed.`




Comment at: clang-doc/BitcodeWriter.cpp:191
+  Record.clear();
+  for (const char C : BlockIdNameMap[ID]) Record.push_back(C);
+  Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record);

lebedev.ri wrote:
> Why do we have this indirection?
> Is there a need to first to (unefficiently?) copy to `Record`, and then emit 
> from there?
> Wouldn't this work just as well?
> ```
> Record.clear();
> Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, BlockIdNameMap[ID]);
> ```
No, since `BlockIdNameMap[ID]` returns a `StringRef`, which can be manipulated 
into an `std::string` or a `const char*`, but the `Stream` wants an `unsigned 
char`. So, the copying is to satisfy that. Unless there's a better way to 
convert a `StringRef` into an array of `unsigned char`?



Comment at: clang-doc/BitcodeWriter.cpp:196
+/// \brief Emits a record name to the BLOCKINFO block.
+void ClangDocBitcodeWriter::emitRecordID(RecordId ID) {
+  assert(RecordIdNameMap[ID] && "Unknown Abbreviation");

lebedev.ri wrote:
> Hmm, so i've been staring at this and 
> http://llvm.org/doxygen/classllvm_1_1BitstreamWriter.html and i must say i'm 
> not fond of this indirection.
> 
> What i don't understand is, in previous function, we don't store `BlockId`, 
> why do we want to store `RecordId`?
> Aren't they both unstable, and are implementation detail?
> Do we want to store it (`RecordId`)? If yes, please explain it as a new 
> comment in code.
> 
> If no, i guess this would work too?
> ```
> assert(RecordIdNameMap[ID] && "Unknown Abbreviation");
> Record.clear();
> Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, 
> RecordIdNameMap[ID].Name);
> ```
> And after that you can lower the default size of `SmallVector<> Record` down 
> to, hm, `4`?
I'm not entirely certain what you mean -- in `emitBlockId()`, we are storing 
both the block id and the block name in separate records 
(`BLOCKINFO_CODE_SETBID`, `BLOCKINFO_CODE_BLOCKNAME`, respectively). In 
`emitRecordId()`, we're doing something slightly different, in that we emit one 
record with both the record id and the record name (in record 
`BLOCKINFO_CODE_SETRECORDNAME`). 

Replacing the copy loop here has the same issue as above, namely that there 
isn't an easy way to convert between a `StringRef` and an array of `unsigned 
char`.



Comment at: clang-doc/BitcodeWriter.cpp:240
+  if (!prepRecordData(ID, Val)) return;
+  assert(Val < (1U << BitCodeConstants::IntSize));
+  Record.push_back(Val);

lebedev.ri wrote:
> Ok, now that i think about it, it can't be that easy.
> Maybe
> ```
> FIXME: assumes 8 bits per byte
> assert(llvm::APInt(8U*sizeof(Val), Val, /*isSigned=*/true).getBitWidth() <= 
> BitCodeConstants::IntSize));
> ```
> Not sure whether `getBitWidth()` is really the right function to ask though.
> (Not sure how this all works for negative numbers)
That assertion fails :/ I could do something like `static_cast(Val) == 
Val` but that would require a) IntSize being a power of 2 b) updating the 
assert anytime IntSize is updated, and 3) still throws a warning about 
comparing a signed to an unsigned int...



Comment at: clang-doc/BitcodeWriter.h:53
+  BI_LAST = BI_COMMENT_BLOCK_ID
+};
+

lebedev.ri wrote:
> juliehockett wrote:
> > lebedev.ri wrote:
> > > So what *exactly* does `BitCodeConstants::SubblockIDSize` mean?
> > > ```
> > > static_assert(BI_LAST < (1U << BitCodeConstants::SubblockIDSize), "Too 
> > > many block id's!");
> > > ```
> > > ?
> > It's the current abbrev id width for the block (described [[ 
> > https://llvm.org/docs/BitCodeFormat.html#enter-subblock-encoding | here 
> > ]]), so it's the max id width for the block's abbrevs.
> So in other words that `static_assert()` is doing the right thing?
> Add it after the `enum BlockId{}` then please, will both document things, and 
> ensure that things remain in a sane state.
No...it's the (max) number of the abbrevs relevant to the block itself, which 
is to say some subset of the RecordIds for any given block (e.g. for a 
`BI_COMMENT_BLOCK`,  the number of abbrevs would be 12 and so on the abbrev 
width would be 4). 

To assert for it we could put block start/end markers on the RecordIds and then 
use that to calculate the bitwidth, if you think the assertion should be there.


https://reviews.llvm.org/D41102



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cg

[PATCH] D41102: Setup clang-doc frontend framework

2018-02-26 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 136010.
juliehockett marked 10 inline comments as done.
juliehockett added a comment.

1. Moved the serialization logic out of the Mapper class and into its own 
namespace
2. Updated tests
3. Addressing comments


https://reviews.llvm.org/D41102

Files:
  CMakeLists.txt
  clang-doc/BitcodeWriter.cpp
  clang-doc/BitcodeWriter.h
  clang-doc/CMakeLists.txt
  clang-doc/ClangDoc.h
  clang-doc/Mapper.cpp
  clang-doc/Mapper.h
  clang-doc/Representation.h
  clang-doc/Serialize.cpp
  clang-doc/Serialize.h
  clang-doc/tool/CMakeLists.txt
  clang-doc/tool/ClangDocMain.cpp
  docs/clang-doc.rst
  test/CMakeLists.txt
  test/clang-doc/mapper-class-in-class.cpp
  test/clang-doc/mapper-class-in-function.cpp
  test/clang-doc/mapper-class.cpp
  test/clang-doc/mapper-enum.cpp
  test/clang-doc/mapper-function.cpp
  test/clang-doc/mapper-method.cpp
  test/clang-doc/mapper-namespace.cpp
  test/clang-doc/mapper-struct.cpp
  test/clang-doc/mapper-union.cpp

Index: test/clang-doc/mapper-union.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-union.cpp
@@ -0,0 +1,28 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@u...@d.bc --dump | FileCheck %s
+
+union D { int X; int Y; };
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'c:@U@D'
+  // CHECK:  blob data = 'D'
+  // CHECK: 
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'D::X'
+// CHECK: 
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'D::Y'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
Index: test/clang-doc/mapper-struct.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-struct.cpp
@@ -0,0 +1,22 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@s...@c.bc --dump | FileCheck %s
+
+struct C { int i; };
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'c:@S@C'
+  // CHECK:  blob data = 'C'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'C::i'
+// CHECK: 
+  // CHECK: 
+// CHECK: 
Index: test/clang-doc/mapper-namespace.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-namespace.cpp
@@ -0,0 +1,17 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@n...@a.bc --dump | FileCheck %s
+
+namespace A {}
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'c:@N@A'
+  // CHECK:  blob data = 'A'
+// CHECK: 
+
Index: test/clang-doc/mapper-method.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-method.cpp
@@ -0,0 +1,31 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@S@G@F@Method#I#.bc --dump | FileCheck %s
+
+class G {
+public: 
+	int Method(int param) { return param; }
+};
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'c:@S@G@F@Method#I#'
+  // CHECK:  blob data = 'Method'
+  // CHECK:  blob data = 'c:@S@G'
+  // CHECK: 
+  // CHECK: 
+  // CHECK:  blob data = 'c:@S@G'
+  // CHECK: 
+// CHECK:  blob data = 'int'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'param'
+  // CHECK: 
+// CHECK: 
+
Index: test/clang-doc/mapper-function.cpp
===
--- /dev/null
+++ test/clang-doc/mapper-function.cpp
@@ -0,0 +1,25 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump --omit-filenames -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/c:@F@F#I#.bc --dump | FileCheck %s
+
+int F(int param) { return param; }
+// CHECK: 
+// CHECK: 
+  // CHECK: 
+// CHECK: 
+// CHECK: 
+  // CHECK:  blob data = 'c:@F@F#I#'
+  // CHECK:  blob data = 'F'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+  // CHECK: 
+  // CHECK: 
+// CHECK:  blob data = 'int'
+// CHECK:  blob data = 'param'
+  // CHECK: 
+// CHECK: 
+
Index: test/clang-doc/mapper-enum.cpp
===

[PATCH] D40813: [clang-tidy] Adding Fuchsia checker for virtual inheritance

2017-12-14 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 127033.
juliehockett added a comment.

Updating checker to only warn on declarations.


https://reviews.llvm.org/D40813

Files:
  clang-tidy/fuchsia/CMakeLists.txt
  clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tidy/fuchsia/VirtualInheritanceCheck.cpp
  clang-tidy/fuchsia/VirtualInheritanceCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/fuchsia-virtual-inheritance.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/fuchsia-virtual-inheritance.cpp

Index: test/clang-tidy/fuchsia-virtual-inheritance.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-virtual-inheritance.cpp
@@ -0,0 +1,42 @@
+// RUN: %check_clang_tidy %s fuchsia-virtual-inheritance %t
+
+class A {
+public:
+  A(int value) : val(value) {}
+
+  int do_A() { return val; }
+
+private:
+  int val;
+};
+
+class B : public virtual A {
+  // CHECK-MESSAGES: [[@LINE-1]]:1: warning: direct virtual inheritance is disallowed [fuchsia-virtual-inheritance]
+  // CHECK-NEXT: class B : public virtual A {
+public:
+  B() : A(0) {}
+  int do_B() { return 1 + do_A(); }
+};
+
+class C : public virtual A {
+  // CHECK-MESSAGES: [[@LINE-1]]:1: warning: direct virtual inheritance is disallowed [fuchsia-virtual-inheritance]
+  // CHECK-NEXT: class C : public virtual A {
+public:
+  C() : A(0) {}
+  int do_C() { return 2 + do_A(); }
+};
+
+class D : public B, public C {
+public:
+  D(int value) : A(value), B(), C() {}
+
+  int do_D() { return do_A() + do_B() + do_C(); }
+};
+
+int main() {
+  A *a = new A(0);
+  B *b = new B();
+  C *c = new C();
+  D *d = new D(0);
+  return 0;
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -69,6 +69,7 @@
cppcoreguidelines-slicing
cppcoreguidelines-special-member-functions
fuchsia-default-arguments
+   fuchsia-virtual-inheritance
google-build-explicit-make-pair
google-build-namespaces
google-build-using-namespace
Index: docs/clang-tidy/checks/fuchsia-virtual-inheritance.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/fuchsia-virtual-inheritance.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - fuchsia-virtual-inheritance
+
+fuchsia-virtual-inheritance
+===
+
+Warns if classes are defined or created with virtual inheritance.
+
+For example, classes should not be defined with virtual inheritance:
+
+.. code-block:: c++
+
+  class B : public virtual A {};   // warning
+
+Classes with virtual inheritance should not be created:
+
+.. code-block:: c++
+
+  B *b = new B();   // warning
+
+See the features disallowed in Fuchsia at https://fuchsia.googlesource.com/zircon/+/master/docs/cxx.md
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -134,7 +134,12 @@
   `_ check
 
   Warns if a function or method is declared or called with default arguments.
+  
+- New `fuchsia-virtual-inheritance
+  `_ check
 
+  Warns if classes are defined or created with virtual inheritance.
+
 - New `google-objc-avoid-throwing-exception
   `_ check
 
Index: clang-tidy/fuchsia/VirtualInheritanceCheck.h
===
--- /dev/null
+++ clang-tidy/fuchsia/VirtualInheritanceCheck.h
@@ -0,0 +1,35 @@
+//===--- VirtualInheritanceCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_VIRTUAL_INHERITANCE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_VIRTUAL_INHERITANCE_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace fuchsia {
+
+/// Defining classes with virtual inheritance is disallowed.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia-virtual-inheritance.html
+class VirtualInheritanceCheck : public ClangTidyCheck {
+ public:
+  VirtualInheritanceCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+}  // namespace fuchsia
+}  // namespace tidy
+}  // namespace clang
+
+#endif  // LLVM_CLANG_TOOLS_EXTRA_CLANG_TI

[PATCH] D40813: [clang-tidy] Adding Fuchsia checker for virtual inheritance

2017-12-14 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett marked 3 inline comments as done.
juliehockett added inline comments.



Comment at: test/clang-tidy/fuchsia-virtual-inheritance.cpp:34-36
+  // CHECK-MESSAGES: [[@LINE-1]]:28: warning: constructing a class that 
inherits a virtual base class is disallowed [fuchsia-virtual-inheritance]
+  // CHECK-NEXT:  D(int value) : A(value), B(), C() {}
+  // CHECK-MESSAGES: [[@LINE-3]]:33: warning: constructing a class that 
inherits a virtual base class is disallowed [fuchsia-virtual-inheritance]

aaron.ballman wrote:
> juliehockett wrote:
> > aaron.ballman wrote:
> > > I'm also not certain this should be diagnosed either. It's technically 
> > > correct because it's calling the base class constructors here, but at the 
> > > same time, it seems very low-value and likely to cause the user to do 
> > > something really bad, like silence the warning by not calling the base 
> > > class constructors.
> > I see what you mean, but where then would you draw the line between warning 
> > and not? We could warn for construction everywhere except in initialization 
> > lists, but that seems like it might open the door to trivially get around 
> > the check in ways that should be disallowed.
> Would it be sufficient to only flag at the point of inheritance, or do you 
> have existing header files with class declarations using virtual inheritance 
> and are worried about consumers inheriting from those?
> 
> e.g., flag declarations but not construction.
Makes sense -- we think the declaration is the important one to limit here. The 
check for constructed virtual objects can be moved to a different checker if it 
becomes necessary.


https://reviews.llvm.org/D40813



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


[PATCH] D41102: Setup clang-doc frontend framework

2017-12-14 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 127053.
juliehockett marked 8 inline comments as done.

https://reviews.llvm.org/D41102

Files:
  tools/CMakeLists.txt
  tools/clang-doc/CMakeLists.txt
  tools/clang-doc/ClangDoc.cpp
  tools/clang-doc/ClangDoc.h
  tools/clang-doc/ClangDocReporter.cpp
  tools/clang-doc/ClangDocReporter.h
  tools/clang-doc/tool/CMakeLists.txt
  tools/clang-doc/tool/ClangDocMain.cpp

Index: tools/clang-doc/tool/ClangDocMain.cpp
===
--- /dev/null
+++ tools/clang-doc/tool/ClangDocMain.cpp
@@ -0,0 +1,68 @@
+//===-- ClangDocMain.cpp - Clangdoc -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ClangDoc.h"
+#include "clang/Driver/Options.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/Support/Process.h"
+#include "llvm/Support/Signals.h"
+#include 
+
+using namespace clang;
+using namespace llvm;
+
+namespace {
+
+cl::OptionCategory ClangDocCategory("clang-doc options");
+
+cl::opt
+EmitLLVM("emit-llvm",
+ cl::desc("Output in LLVM bitstream format (default is YAML)."),
+ cl::init(false), cl::cat(ClangDocCategory));
+
+cl::opt
+DoxygenOnly("doxygen",
+cl::desc("Use only doxygen-style comments to generate docs."),
+cl::init(false), cl::cat(ClangDocCategory));
+
+} // namespace
+
+int main(int argc, const char **argv) {
+  sys::PrintStackTraceOnErrorSignal(argv[0]);
+  tooling::CommonOptionsParser OptionsParser(argc, argv, ClangDocCategory);
+
+  clang::doc::OutFormat EmitFormat = EmitLLVM ? clang::doc::OutFormat::LLVM
+  : clang::doc::OutFormat::YAML;
+
+  // TODO: Update the source path list to only consider changed files for
+  // incremental doc updates.
+  doc::ClangDocReporter Reporter(OptionsParser.getSourcePathList());
+  doc::ClangDocContext Context{EmitFormat};
+
+  tooling::ClangTool Tool(OptionsParser.getCompilations(),
+  OptionsParser.getSourcePathList());
+
+  if (!DoxygenOnly)
+Tool.appendArgumentsAdjuster(tooling::getInsertArgumentAdjuster(
+"-fparse-all-comments", tooling::ArgumentInsertPosition::BEGIN));
+
+  doc::ClangDocActionFactory Factory(Context, Reporter);
+
+  outs() << "Parsing codebase...\n";
+  int Status = Tool.run(&Factory);
+  if (Status)
+return Status;
+
+  outs() << "Writing docs...\n";
+  Reporter.serialize(EmitFormat, outs());
+
+  return 0;
+}
Index: tools/clang-doc/tool/CMakeLists.txt
===
--- /dev/null
+++ tools/clang-doc/tool/CMakeLists.txt
@@ -0,0 +1,18 @@
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
+
+add_clang_executable(clang-doc
+  ClangDocMain.cpp
+  )
+
+target_link_libraries(clang-doc
+  PRIVATE
+  clangAST
+  clangASTMatchers
+  clangBasic
+  clangFormat
+  clangFrontend
+  clangDoc
+  clangRewrite
+  clangTooling
+  clangToolingCore
+  )
Index: tools/clang-doc/ClangDocReporter.h
===
--- /dev/null
+++ tools/clang-doc/ClangDocReporter.h
@@ -0,0 +1,117 @@
+//===-- Doc.cpp - ClangDoc --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_CLANG_DOC_REPORTER_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_CLANG_DOC_REPORTER_H
+
+#include "clang/AST/AST.h"
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/CommentVisitor.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Frontend/ASTConsumers.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+#include 
+#include 
+#include 
+
+using namespace clang::comments;
+
+namespace clang {
+namespace doc {
+
+enum class OutFormat { YAML, LLVM };
+
+struct StringPair {
+  std::string Key;
+  std::string Value;
+};
+
+struct CommentInfo {
+  std::string Kind;
+  std::string Text;
+  std::string Name;
+  std::string Direction;
+  std::string ParamName;
+  std::string CloseName;
+  bool SelfClosing = false;
+  bool Explicit = false;
+  llvm::StringMap Attrs;
+  llvm::SmallVector Args;
+  llvm::SmallVector Position;
+  std::vector Children;
+};
+
+// TODO: collect declarations of the same object, comment is preferentially:
+// 1) docstring on definition, 2) 

[PATCH] D41102: Setup clang-doc frontend framework

2017-12-14 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added inline comments.



Comment at: tools/clang-doc/ClangDocReporter.h:35
+
+struct StringPair {
+  std::string Key;

JDevlieghere wrote:
> Do you still need this?
Yes, it's used to serialize the map to yaml.


https://reviews.llvm.org/D41102



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


[PATCH] D40813: [clang-tidy] Adding Fuchsia checker for virtual inheritance

2017-12-15 Thread Julie Hockett via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
juliehockett marked 4 inline comments as done.
Closed by commit rL320841: [clang-tidy] Adding Fuchsia checker for virtual 
inheritance (authored by juliehockett, committed by ).
Herald added a subscriber: klimek.

Changed prior to commit:
  https://reviews.llvm.org/D40813?vs=127033&id=127160#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40813

Files:
  clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/fuchsia/VirtualInheritanceCheck.cpp
  clang-tools-extra/trunk/clang-tidy/fuchsia/VirtualInheritanceCheck.h
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-virtual-inheritance.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  clang-tools-extra/trunk/test/clang-tidy/fuchsia-virtual-inheritance.cpp

Index: clang-tools-extra/trunk/clang-tidy/fuchsia/VirtualInheritanceCheck.h
===
--- clang-tools-extra/trunk/clang-tidy/fuchsia/VirtualInheritanceCheck.h
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/VirtualInheritanceCheck.h
@@ -0,0 +1,35 @@
+//===--- VirtualInheritanceCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_VIRTUAL_INHERITANCE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_VIRTUAL_INHERITANCE_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace fuchsia {
+
+/// Defining classes with virtual inheritance is disallowed.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia-virtual-inheritance.html
+class VirtualInheritanceCheck : public ClangTidyCheck {
+ public:
+  VirtualInheritanceCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+}  // namespace fuchsia
+}  // namespace tidy
+}  // namespace clang
+
+#endif  // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_VIRTUAL_INHERITANCE_H
Index: clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
===
--- clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
@@ -11,6 +11,7 @@
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
 #include "DefaultArgumentsCheck.h"
+#include "VirtualInheritanceCheck.h"
 
 using namespace clang::ast_matchers;
 
@@ -24,6 +25,8 @@
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
 CheckFactories.registerCheck(
 "fuchsia-default-arguments");
+CheckFactories.registerCheck(
+"fuchsia-virtual-inheritance");
   }
 };
 // Register the FuchsiaTidyModule using this statically initialized variable.
Index: clang-tools-extra/trunk/clang-tidy/fuchsia/VirtualInheritanceCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/fuchsia/VirtualInheritanceCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/VirtualInheritanceCheck.cpp
@@ -0,0 +1,41 @@
+//===--- VirtualInheritanceCheck.cpp - clang-tidy--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "VirtualInheritanceCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace fuchsia {
+
+AST_MATCHER(CXXRecordDecl, hasDirectVirtualBaseClass) {
+  if (!Node.hasDefinition()) return false;
+  if (!Node.getNumVBases()) return false;
+  for (const CXXBaseSpecifier &Base : Node.bases())
+if (Base.isVirtual()) return true;
+  return false;
+}
+
+void VirtualInheritanceCheck::registerMatchers(MatchFinder *Finder) {
+  // Defining classes using direct virtual inheritance is disallowed.
+  Finder->addMatcher(cxxRecordDecl(hasDirectVirtualBaseClass()).bind("decl"),
+ this);
+}
+
+void VirtualInheritanceCheck::check(const MatchFinder::MatchResult &Result) {
+  if (const auto *D = Result.Nodes.getNodeAs("decl"))
+diag(D->getLocStart(), "direct virtual inheritance is disallowed");
+}
+
+}  // namespace fuchsia
+} 

[PATCH] D41363: [clang-tidy] Adding Fuchsia checker for overloaded operators

2017-12-18 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett created this revision.
juliehockett added reviewers: aaron.ballman, alexfh, hokein.
juliehockett added a project: clang-tools-extra.
Herald added subscribers: xazax.hun, mgorny.

Adds a check to the Fuchsia module to warn if an operator is overloaded, except 
move and copy operators.

See https://fuchsia.googlesource.com/zircon/+/master/docs/cxx.md for reference.


https://reviews.llvm.org/D41363

Files:
  clang-tidy/fuchsia/CMakeLists.txt
  clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
  clang-tidy/fuchsia/OverloadedOperatorCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/fuchsia-overloaded-operator.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/fuchsia-overloaded-operator.cpp

Index: test/clang-tidy/fuchsia-overloaded-operator.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-overloaded-operator.cpp
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s fuchsia-overloaded-operator %t
+
+class A {
+public:
+  int operator+(int);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: operator overloading is disallowed [fuchsia-overloaded-operator]
+};
+
+class B {
+public:
+  B &operator=(B other);
+  // CHECK-MESSAGES-NOT: [[@LINE-1]]:3: warning: operator overloading is disallowed [fuchsia-overloaded-operator]
+  B &operator=(B &&other);
+  // CHECK-MESSAGES-NOT: [[@LINE-1]]:3: warning: operator overloading is disallowed [fuchsia-overloaded-operator]
+};
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -69,6 +69,7 @@
cppcoreguidelines-slicing
cppcoreguidelines-special-member-functions
fuchsia-default-arguments
+   fuchsia-overloaded-operator
fuchsia-virtual-inheritance
google-build-explicit-make-pair
google-build-namespaces
Index: docs/clang-tidy/checks/fuchsia-overloaded-operator.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/fuchsia-overloaded-operator.rst
@@ -0,0 +1,17 @@
+.. title:: clang-tidy - fuchsia-overloaded-operator
+
+fuchsia-overloaded-operator
+===
+
+Warns if an operator is overloaded, except for the copy and move operators.
+
+For example:
+
+.. code-block:: c++
+
+  int operator+(int); // Warning
+
+  B &operator=(B other);  // No warning
+  B &operator=(B &&other) // No warning
+
+See the features disallowed in Fuchsia at https://fuchsia.googlesource.com/zircon/+/master/docs/cxx.md
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -134,7 +134,12 @@
   `_ check
 
   Warns if a function or method is declared or called with default arguments.
-  
+
+- New `fuchsia-overloaded-operator
+  `_ check
+
+  Warns if an operator is overloaded, except for the copy and move operators.
+
 - New `fuchsia-virtual-inheritance
   `_ check
 
Index: clang-tidy/fuchsia/OverloadedOperatorCheck.h
===
--- /dev/null
+++ clang-tidy/fuchsia/OverloadedOperatorCheck.h
@@ -0,0 +1,35 @@
+//===--- OverloadedOperatorCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_OVERLOADED_OPERATOR_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_OVERLOADED_OPERATOR_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace fuchsia {
+
+/// Operator overloading is disallowed.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia-overloaded-operator.html
+class OverloadedOperatorCheck : public ClangTidyCheck {
+public:
+  OverloadedOperatorCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace fuchsia
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_OVERLOADED_OPERATOR_H
Index: clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
===
--- /dev/null
+++ clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
@@ -0,0 +1,35 @@
+//===--- OverloadedOperatorCheck.cpp - clang-tidy---

[PATCH] D41363: [clang-tidy] Adding Fuchsia checker for overloaded operators

2017-12-20 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 127799.
juliehockett marked 7 inline comments as done.
juliehockett added a comment.

Fixing comments


https://reviews.llvm.org/D41363

Files:
  clang-tidy/fuchsia/CMakeLists.txt
  clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
  clang-tidy/fuchsia/OverloadedOperatorCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/fuchsia-overloaded-operator.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/fuchsia-overloaded-operator.cpp

Index: test/clang-tidy/fuchsia-overloaded-operator.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-overloaded-operator.cpp
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s fuchsia-overloaded-operator %t
+
+class A {
+public:
+  int operator+(int);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: cannot overload 'operator+' [fuchsia-overloaded-operator]
+};
+
+class B {
+public:
+  B &operator=(const B& other);
+  // CHECK-MESSAGES-NOT: [[@LINE-1]]:3: warning: cannot overload 'operator=' [fuchsia-overloaded-operator]
+  B &operator=(B &&other);
+  // CHECK-MESSAGES-NOT: [[@LINE-1]]:3: warning: cannot overload 'operator=' [fuchsia-overloaded-operator]
+};
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -69,6 +69,7 @@
cppcoreguidelines-slicing
cppcoreguidelines-special-member-functions
fuchsia-default-arguments
+   fuchsia-overloaded-operator
fuchsia-virtual-inheritance
google-build-explicit-make-pair
google-build-namespaces
Index: docs/clang-tidy/checks/fuchsia-overloaded-operator.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/fuchsia-overloaded-operator.rst
@@ -0,0 +1,18 @@
+.. title:: clang-tidy - fuchsia-overloaded-operator
+
+fuchsia-overloaded-operator
+===
+
+Warns if an operator is overloaded, except for the assignment (copy and move) 
+operators.
+
+For example:
+
+.. code-block:: c++
+
+  int operator+(int); // Warning
+
+  B &operator=(const B& other);  // No warning
+  B &operator=(B &&other) // No warning
+
+See the features disallowed in Fuchsia at https://fuchsia.googlesource.com/zircon/+/master/docs/cxx.md
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -134,7 +134,12 @@
   `_ check
 
   Warns if a function or method is declared or called with default arguments.
-  
+
+- New `fuchsia-overloaded-operator
+  `_ check
+
+  Warns if an operator is overloaded, except for the assignment (copy and move) operators.
+
 - New `fuchsia-virtual-inheritance
   `_ check
 
Index: clang-tidy/fuchsia/OverloadedOperatorCheck.h
===
--- /dev/null
+++ clang-tidy/fuchsia/OverloadedOperatorCheck.h
@@ -0,0 +1,35 @@
+//===--- OverloadedOperatorCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_OVERLOADED_OPERATOR_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_OVERLOADED_OPERATOR_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace fuchsia {
+
+/// Overloading operators is disallowed by the Fuchsia coding standard.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia-overloaded-operator.html
+class OverloadedOperatorCheck : public ClangTidyCheck {
+public:
+  OverloadedOperatorCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace fuchsia
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_OVERLOADED_OPERATOR_H
Index: clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
===
--- /dev/null
+++ clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
@@ -0,0 +1,35 @@
+//===--- OverloadedOperatorCheck.cpp - clang-tidy--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See 

  1   2   3   4   5   >