[PATCH] D85033: [clang] Provide a better pretty-printed name for unnamed parameters, lambda classes and lambda captures.

2020-08-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM aside from a minor nit.




Comment at: clang/lib/AST/Decl.cpp:2130
+  // the pretty-printed name of the capture instead.
+  if (isa(DD) &&
+  maybePrintFieldForLambdaCapture(OS, Policy, cast(DD)))

Rather than `isa<>` followed by a `cast<>`, how about:
```
if (const auto *FD = dyn_cast(DD)) {
  if (maybePrintFieldForLambdaCapture(...)
return;
}
```
Alternatively, you could sink the `dyn_cast<>` down into 
`maybePrintFieldForLambdaCapture()` since that already has to handle case where 
it's not printing a field capture.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85033

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


[PATCH] D85033: [clang] Provide a better pretty-printed name for unnamed parameters, lambda classes and lambda captures.

2020-08-01 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno updated this revision to Diff 282391.
riccibruno edited the summary of this revision.
riccibruno added a comment.

Don't forget to increment the field iterator in the loop of 
`maybePrintFieldForLambdaCapture`, and modify the tests to test this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85033

Files:
  clang/lib/AST/Decl.cpp
  clang/test/AST/ast-dump-record-definition-data-json.cpp
  clang/test/Analysis/explain-svals.cpp
  clang/test/Index/annotate-tokens.cpp
  clang/test/Index/linkage.c
  clang/test/Index/load-decls.c
  clang/test/Index/load-namespaces.cpp
  clang/test/Index/preamble.c
  clang/test/Index/print-type.c
  clang/test/Index/print-type.cpp
  clang/test/Index/recursive-cxx-member-calls.cpp
  clang/test/Index/usrs.m
  clang/test/Modules/module-private.cpp
  clang/test/SemaCXX/lambda-expressions.cpp
  clang/test/SemaCXX/warn-large-by-value-copy.cpp
  clang/test/Tooling/clang-diff-ast.cpp
  clang/unittests/AST/ASTTraverserTest.cpp
  clang/unittests/AST/NamedDeclPrinterTest.cpp

Index: clang/unittests/AST/NamedDeclPrinterTest.cpp
===
--- clang/unittests/AST/NamedDeclPrinterTest.cpp
+++ clang/unittests/AST/NamedDeclPrinterTest.cpp
@@ -6,7 +6,8 @@
 //
 //===--===//
 //
-// This file contains tests for NamedDecl::printQualifiedName().
+// This file contains tests for NamedDecl::printName()
+// and NamedDecl::printQualifiedName().
 //
 // These tests have a coding convention:
 // * declaration to be printed is named 'A' unless it should have some special
@@ -93,11 +94,10 @@
   return ::testing::AssertionSuccess();
 }
 
-::testing::AssertionResult
-PrintedNamedDeclMatches(StringRef Code, const std::vector ,
-bool SuppressUnwrittenScope,
-const DeclarationMatcher ,
-StringRef ExpectedPrinted, StringRef FileName) {
+::testing::AssertionResult PrintedQualifiedNamedDeclMatches(
+StringRef Code, const std::vector ,
+bool SuppressUnwrittenScope, const DeclarationMatcher ,
+StringRef ExpectedPrinted, StringRef FileName) {
   return PrintedDeclMatches(Code, Args, NodeMatch, ExpectedPrinted, FileName,
 [=](llvm::raw_ostream , const NamedDecl *ND) {
   auto Policy =
@@ -108,34 +108,43 @@
 });
 }
 
+::testing::AssertionResult PrintedUnqualifiedNamedDeclMatches(
+StringRef Code, const std::vector ,
+const DeclarationMatcher , StringRef ExpectedPrinted,
+StringRef FileName) {
+  return PrintedDeclMatches(
+  Code, Args, NodeMatch, ExpectedPrinted, FileName,
+  [=](llvm::raw_ostream , const NamedDecl *ND) { ND->printName(Out); });
+}
+
 ::testing::AssertionResult
-PrintedNamedDeclCXX98Matches(StringRef Code, StringRef DeclName,
- StringRef ExpectedPrinted) {
+PrintedQualifiedNamedDeclCXX98Matches(StringRef Code, StringRef DeclName,
+  StringRef ExpectedPrinted) {
   std::vector Args(1, "-std=c++98");
-  return PrintedNamedDeclMatches(Code, Args,
- /*SuppressUnwrittenScope*/ false,
- namedDecl(hasName(DeclName)).bind("id"),
- ExpectedPrinted, "input.cc");
+  return PrintedQualifiedNamedDeclMatches(
+  Code, Args,
+  /*SuppressUnwrittenScope*/ false, namedDecl(hasName(DeclName)).bind("id"),
+  ExpectedPrinted, "input.cc");
 }
 
 ::testing::AssertionResult
-PrintedWrittenNamedDeclCXX11Matches(StringRef Code, StringRef DeclName,
-StringRef ExpectedPrinted) {
+PrintedWrittenQualifiedNamedDeclCXX11Matches(StringRef Code, StringRef DeclName,
+ StringRef ExpectedPrinted) {
   std::vector Args(1, "-std=c++11");
-  return PrintedNamedDeclMatches(Code, Args,
- /*SuppressUnwrittenScope*/ true,
- namedDecl(hasName(DeclName)).bind("id"),
- ExpectedPrinted, "input.cc");
+  return PrintedQualifiedNamedDeclMatches(
+  Code, Args,
+  /*SuppressUnwrittenScope*/ true, namedDecl(hasName(DeclName)).bind("id"),
+  ExpectedPrinted, "input.cc");
 }
 
-::testing::AssertionResult
-PrintedWrittenPropertyDeclObjCMatches(StringRef Code, StringRef DeclName,
-   StringRef ExpectedPrinted) {
+::testing::AssertionResult PrintedWrittenQualifiedPropertyDeclObjCMatches(
+StringRef Code, StringRef DeclName, StringRef ExpectedPrinted) {
   std::vector Args{"-std=c++11", "-xobjective-c++"};
-  return PrintedNamedDeclMatches(Code, Args,
- /*SuppressUnwrittenScope*/ true,
- 

[PATCH] D85033: [clang] Provide a better pretty-printed name for unnamed parameters, lambda classes and lambda captures.

2020-07-31 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno updated this revision to Diff 282312.
riccibruno added a comment.

Add `-fno-delayed-template-parsing` to the new unit tests to also pass on 
Windows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85033

Files:
  clang/lib/AST/Decl.cpp
  clang/test/AST/ast-dump-record-definition-data-json.cpp
  clang/test/Analysis/explain-svals.cpp
  clang/test/Index/annotate-tokens.cpp
  clang/test/Index/linkage.c
  clang/test/Index/load-decls.c
  clang/test/Index/load-namespaces.cpp
  clang/test/Index/preamble.c
  clang/test/Index/print-type.c
  clang/test/Index/print-type.cpp
  clang/test/Index/recursive-cxx-member-calls.cpp
  clang/test/Index/usrs.m
  clang/test/Modules/module-private.cpp
  clang/test/SemaCXX/lambda-expressions.cpp
  clang/test/SemaCXX/warn-large-by-value-copy.cpp
  clang/test/Tooling/clang-diff-ast.cpp
  clang/unittests/AST/ASTTraverserTest.cpp
  clang/unittests/AST/NamedDeclPrinterTest.cpp

Index: clang/unittests/AST/NamedDeclPrinterTest.cpp
===
--- clang/unittests/AST/NamedDeclPrinterTest.cpp
+++ clang/unittests/AST/NamedDeclPrinterTest.cpp
@@ -6,7 +6,8 @@
 //
 //===--===//
 //
-// This file contains tests for NamedDecl::printQualifiedName().
+// This file contains tests for NamedDecl::printName()
+// and NamedDecl::printQualifiedName().
 //
 // These tests have a coding convention:
 // * declaration to be printed is named 'A' unless it should have some special
@@ -93,11 +94,10 @@
   return ::testing::AssertionSuccess();
 }
 
-::testing::AssertionResult
-PrintedNamedDeclMatches(StringRef Code, const std::vector ,
-bool SuppressUnwrittenScope,
-const DeclarationMatcher ,
-StringRef ExpectedPrinted, StringRef FileName) {
+::testing::AssertionResult PrintedQualifiedNamedDeclMatches(
+StringRef Code, const std::vector ,
+bool SuppressUnwrittenScope, const DeclarationMatcher ,
+StringRef ExpectedPrinted, StringRef FileName) {
   return PrintedDeclMatches(Code, Args, NodeMatch, ExpectedPrinted, FileName,
 [=](llvm::raw_ostream , const NamedDecl *ND) {
   auto Policy =
@@ -108,34 +108,43 @@
 });
 }
 
+::testing::AssertionResult PrintedUnqualifiedNamedDeclMatches(
+StringRef Code, const std::vector ,
+const DeclarationMatcher , StringRef ExpectedPrinted,
+StringRef FileName) {
+  return PrintedDeclMatches(
+  Code, Args, NodeMatch, ExpectedPrinted, FileName,
+  [=](llvm::raw_ostream , const NamedDecl *ND) { ND->printName(Out); });
+}
+
 ::testing::AssertionResult
-PrintedNamedDeclCXX98Matches(StringRef Code, StringRef DeclName,
- StringRef ExpectedPrinted) {
+PrintedQualifiedNamedDeclCXX98Matches(StringRef Code, StringRef DeclName,
+  StringRef ExpectedPrinted) {
   std::vector Args(1, "-std=c++98");
-  return PrintedNamedDeclMatches(Code, Args,
- /*SuppressUnwrittenScope*/ false,
- namedDecl(hasName(DeclName)).bind("id"),
- ExpectedPrinted, "input.cc");
+  return PrintedQualifiedNamedDeclMatches(
+  Code, Args,
+  /*SuppressUnwrittenScope*/ false, namedDecl(hasName(DeclName)).bind("id"),
+  ExpectedPrinted, "input.cc");
 }
 
 ::testing::AssertionResult
-PrintedWrittenNamedDeclCXX11Matches(StringRef Code, StringRef DeclName,
-StringRef ExpectedPrinted) {
+PrintedWrittenQualifiedNamedDeclCXX11Matches(StringRef Code, StringRef DeclName,
+ StringRef ExpectedPrinted) {
   std::vector Args(1, "-std=c++11");
-  return PrintedNamedDeclMatches(Code, Args,
- /*SuppressUnwrittenScope*/ true,
- namedDecl(hasName(DeclName)).bind("id"),
- ExpectedPrinted, "input.cc");
+  return PrintedQualifiedNamedDeclMatches(
+  Code, Args,
+  /*SuppressUnwrittenScope*/ true, namedDecl(hasName(DeclName)).bind("id"),
+  ExpectedPrinted, "input.cc");
 }
 
-::testing::AssertionResult
-PrintedWrittenPropertyDeclObjCMatches(StringRef Code, StringRef DeclName,
-   StringRef ExpectedPrinted) {
+::testing::AssertionResult PrintedWrittenQualifiedPropertyDeclObjCMatches(
+StringRef Code, StringRef DeclName, StringRef ExpectedPrinted) {
   std::vector Args{"-std=c++11", "-xobjective-c++"};
-  return PrintedNamedDeclMatches(Code, Args,
- /*SuppressUnwrittenScope*/ true,
- objcPropertyDecl(hasName(DeclName)).bind("id"),
- ExpectedPrinted, "input.m");
+  

[PATCH] D85033: [clang] Provide a better pretty-printed name for unnamed parameters, lambda classes and lambda captures.

2020-07-31 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno updated this revision to Diff 282296.
riccibruno added a comment.

Make the unit tests in `NamedDeclPrinterTest.cpp` more robust.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85033

Files:
  clang/lib/AST/Decl.cpp
  clang/test/AST/ast-dump-record-definition-data-json.cpp
  clang/test/Analysis/explain-svals.cpp
  clang/test/Index/annotate-tokens.cpp
  clang/test/Index/linkage.c
  clang/test/Index/load-decls.c
  clang/test/Index/load-namespaces.cpp
  clang/test/Index/preamble.c
  clang/test/Index/print-type.c
  clang/test/Index/print-type.cpp
  clang/test/Index/recursive-cxx-member-calls.cpp
  clang/test/Index/usrs.m
  clang/test/Modules/module-private.cpp
  clang/test/SemaCXX/lambda-expressions.cpp
  clang/test/SemaCXX/warn-large-by-value-copy.cpp
  clang/test/Tooling/clang-diff-ast.cpp
  clang/unittests/AST/ASTTraverserTest.cpp
  clang/unittests/AST/NamedDeclPrinterTest.cpp

Index: clang/unittests/AST/NamedDeclPrinterTest.cpp
===
--- clang/unittests/AST/NamedDeclPrinterTest.cpp
+++ clang/unittests/AST/NamedDeclPrinterTest.cpp
@@ -6,7 +6,8 @@
 //
 //===--===//
 //
-// This file contains tests for NamedDecl::printQualifiedName().
+// This file contains tests for NamedDecl::printName()
+// and NamedDecl::printQualifiedName().
 //
 // These tests have a coding convention:
 // * declaration to be printed is named 'A' unless it should have some special
@@ -93,11 +94,10 @@
   return ::testing::AssertionSuccess();
 }
 
-::testing::AssertionResult
-PrintedNamedDeclMatches(StringRef Code, const std::vector ,
-bool SuppressUnwrittenScope,
-const DeclarationMatcher ,
-StringRef ExpectedPrinted, StringRef FileName) {
+::testing::AssertionResult PrintedQualifiedNamedDeclMatches(
+StringRef Code, const std::vector ,
+bool SuppressUnwrittenScope, const DeclarationMatcher ,
+StringRef ExpectedPrinted, StringRef FileName) {
   return PrintedDeclMatches(Code, Args, NodeMatch, ExpectedPrinted, FileName,
 [=](llvm::raw_ostream , const NamedDecl *ND) {
   auto Policy =
@@ -108,34 +108,43 @@
 });
 }
 
+::testing::AssertionResult PrintedUnqualifiedNamedDeclMatches(
+StringRef Code, const std::vector ,
+const DeclarationMatcher , StringRef ExpectedPrinted,
+StringRef FileName) {
+  return PrintedDeclMatches(
+  Code, Args, NodeMatch, ExpectedPrinted, FileName,
+  [=](llvm::raw_ostream , const NamedDecl *ND) { ND->printName(Out); });
+}
+
 ::testing::AssertionResult
-PrintedNamedDeclCXX98Matches(StringRef Code, StringRef DeclName,
- StringRef ExpectedPrinted) {
+PrintedQualifiedNamedDeclCXX98Matches(StringRef Code, StringRef DeclName,
+  StringRef ExpectedPrinted) {
   std::vector Args(1, "-std=c++98");
-  return PrintedNamedDeclMatches(Code, Args,
- /*SuppressUnwrittenScope*/ false,
- namedDecl(hasName(DeclName)).bind("id"),
- ExpectedPrinted, "input.cc");
+  return PrintedQualifiedNamedDeclMatches(
+  Code, Args,
+  /*SuppressUnwrittenScope*/ false, namedDecl(hasName(DeclName)).bind("id"),
+  ExpectedPrinted, "input.cc");
 }
 
 ::testing::AssertionResult
-PrintedWrittenNamedDeclCXX11Matches(StringRef Code, StringRef DeclName,
-StringRef ExpectedPrinted) {
+PrintedWrittenQualifiedNamedDeclCXX11Matches(StringRef Code, StringRef DeclName,
+ StringRef ExpectedPrinted) {
   std::vector Args(1, "-std=c++11");
-  return PrintedNamedDeclMatches(Code, Args,
- /*SuppressUnwrittenScope*/ true,
- namedDecl(hasName(DeclName)).bind("id"),
- ExpectedPrinted, "input.cc");
+  return PrintedQualifiedNamedDeclMatches(
+  Code, Args,
+  /*SuppressUnwrittenScope*/ true, namedDecl(hasName(DeclName)).bind("id"),
+  ExpectedPrinted, "input.cc");
 }
 
-::testing::AssertionResult
-PrintedWrittenPropertyDeclObjCMatches(StringRef Code, StringRef DeclName,
-   StringRef ExpectedPrinted) {
+::testing::AssertionResult PrintedWrittenQualifiedPropertyDeclObjCMatches(
+StringRef Code, StringRef DeclName, StringRef ExpectedPrinted) {
   std::vector Args{"-std=c++11", "-xobjective-c++"};
-  return PrintedNamedDeclMatches(Code, Args,
- /*SuppressUnwrittenScope*/ true,
- objcPropertyDecl(hasName(DeclName)).bind("id"),
- ExpectedPrinted, "input.m");
+  return