Re: [PATCH] D36610: [Tooling] Add option to getFullyQualifiedName using a custom PritingPolicy

2018-05-04 Thread Sterling Augustine via cfe-commits
Committed as r331552.

On Fri, May 4, 2018 at 12:43 PM, Mikhail Ramalho via Phabricator <
revi...@reviews.llvm.org> wrote:

> mikhail.ramalho updated this revision to Diff 145255.
> mikhail.ramalho added a comment.
>
> Fixed the test case.
>
>
> https://reviews.llvm.org/D36610
>
> Files:
>   include/clang/AST/QualTypeNames.h
>   lib/AST/QualTypeNames.cpp
>   unittests/Tooling/QualTypeNamesTest.cpp
>
>
> Index: unittests/Tooling/QualTypeNamesTest.cpp
> ===
> --- unittests/Tooling/QualTypeNamesTest.cpp
> +++ unittests/Tooling/QualTypeNamesTest.cpp
> @@ -26,9 +26,13 @@
>  std::string ExpectedName =
>  ExpectedQualTypeNames.lookup(VD->getNameAsString());
>  if (ExpectedName != "") {
> -  std::string ActualName =
> -  TypeName::getFullyQualifiedName(VD->getType(), *Context,
> -  WithGlobalNsPrefix);
> +  PrintingPolicy Policy(Context->getPrintingPolicy());
> +  Policy.SuppressScope = false;
> +  Policy.AnonymousTagLocations = true;
> +  Policy.PolishForDeclaration = true;
> +  Policy.SuppressUnwrittenScope = true;
> +  std::string ActualName = TypeName::getFullyQualifiedName(
> +  VD->getType(), *Context, Policy, WithGlobalNsPrefix);
>if (ExpectedName != ActualName) {
>  // A custom message makes it much easier to see what declaration
>  // failed compared to EXPECT_EQ.
> @@ -217,6 +221,26 @@
>"  }\n"
>"}\n"
>);
> +
> +  TypeNameVisitor AnonStrucs;
> +  AnonStrucs.ExpectedQualTypeNames["a"] = "short";
> +  AnonStrucs.ExpectedQualTypeNames["un_in_st_1"] =
> +  "union (anonymous struct at input.cc:1:1)::(anonymous union at "
> +  "input.cc:2:27)";
> +  AnonStrucs.ExpectedQualTypeNames["b"] = "short";
> +  AnonStrucs.ExpectedQualTypeNames["un_in_st_2"] =
> +  "union (anonymous struct at input.cc:1:1)::(anonymous union at "
> +  "input.cc:5:27)";
> +  AnonStrucs.ExpectedQualTypeNames["anon_st"] =
> +  "struct (anonymous struct at input.cc:1:1)";
> +  AnonStrucs.runOver(R"(struct {
> +  union {
> +short a;
> +  } un_in_st_1;
> +  union {
> +short b;
> +  } un_in_st_2;
> +} anon_st;)");
>  }
>
>  }  // end anonymous namespace
> Index: lib/AST/QualTypeNames.cpp
> ===
> --- lib/AST/QualTypeNames.cpp
> +++ lib/AST/QualTypeNames.cpp
> @@ -452,12 +452,8 @@
>
>  std::string getFullyQualifiedName(QualType QT,
>const ASTContext ,
> +  const PrintingPolicy ,
>bool WithGlobalNsPrefix) {
> -  PrintingPolicy Policy(Ctx.getPrintingPolicy());
> -  Policy.SuppressScope = false;
> -  Policy.AnonymousTagLocations = false;
> -  Policy.PolishForDeclaration = true;
> -  Policy.SuppressUnwrittenScope = true;
>QualType FQQT = getFullyQualifiedType(QT, Ctx, WithGlobalNsPrefix);
>return FQQT.getAsString(Policy);
>  }
> Index: include/clang/AST/QualTypeNames.h
> ===
> --- include/clang/AST/QualTypeNames.h
> +++ include/clang/AST/QualTypeNames.h
> @@ -72,6 +72,7 @@
>  /// \param[in] WithGlobalNsPrefix - If true, then the global namespace
>  /// specifier "::" will be prepended to the fully qualified name.
>  std::string getFullyQualifiedName(QualType QT, const ASTContext ,
> +  const PrintingPolicy ,
>bool WithGlobalNsPrefix = false);
>
>  /// \brief Generates a QualType that can be used to name the same type
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36610: [Tooling] Add option to getFullyQualifiedName using a custom PritingPolicy

2018-05-04 Thread Mikhail Ramalho via Phabricator via cfe-commits
mikhail.ramalho updated this revision to Diff 145255.
mikhail.ramalho added a comment.

Fixed the test case.


https://reviews.llvm.org/D36610

Files:
  include/clang/AST/QualTypeNames.h
  lib/AST/QualTypeNames.cpp
  unittests/Tooling/QualTypeNamesTest.cpp


Index: unittests/Tooling/QualTypeNamesTest.cpp
===
--- unittests/Tooling/QualTypeNamesTest.cpp
+++ unittests/Tooling/QualTypeNamesTest.cpp
@@ -26,9 +26,13 @@
 std::string ExpectedName =
 ExpectedQualTypeNames.lookup(VD->getNameAsString());
 if (ExpectedName != "") {
-  std::string ActualName =
-  TypeName::getFullyQualifiedName(VD->getType(), *Context,
-  WithGlobalNsPrefix);
+  PrintingPolicy Policy(Context->getPrintingPolicy());
+  Policy.SuppressScope = false;
+  Policy.AnonymousTagLocations = true;
+  Policy.PolishForDeclaration = true;
+  Policy.SuppressUnwrittenScope = true;
+  std::string ActualName = TypeName::getFullyQualifiedName(
+  VD->getType(), *Context, Policy, WithGlobalNsPrefix);
   if (ExpectedName != ActualName) {
 // A custom message makes it much easier to see what declaration
 // failed compared to EXPECT_EQ.
@@ -217,6 +221,26 @@
   "  }\n"
   "}\n"
   );
+
+  TypeNameVisitor AnonStrucs;
+  AnonStrucs.ExpectedQualTypeNames["a"] = "short";
+  AnonStrucs.ExpectedQualTypeNames["un_in_st_1"] =
+  "union (anonymous struct at input.cc:1:1)::(anonymous union at "
+  "input.cc:2:27)";
+  AnonStrucs.ExpectedQualTypeNames["b"] = "short";
+  AnonStrucs.ExpectedQualTypeNames["un_in_st_2"] =
+  "union (anonymous struct at input.cc:1:1)::(anonymous union at "
+  "input.cc:5:27)";
+  AnonStrucs.ExpectedQualTypeNames["anon_st"] =
+  "struct (anonymous struct at input.cc:1:1)";
+  AnonStrucs.runOver(R"(struct {
+  union {
+short a;
+  } un_in_st_1;
+  union {
+short b;
+  } un_in_st_2;
+} anon_st;)");
 }
 
 }  // end anonymous namespace
Index: lib/AST/QualTypeNames.cpp
===
--- lib/AST/QualTypeNames.cpp
+++ lib/AST/QualTypeNames.cpp
@@ -452,12 +452,8 @@
 
 std::string getFullyQualifiedName(QualType QT,
   const ASTContext ,
+  const PrintingPolicy ,
   bool WithGlobalNsPrefix) {
-  PrintingPolicy Policy(Ctx.getPrintingPolicy());
-  Policy.SuppressScope = false;
-  Policy.AnonymousTagLocations = false;
-  Policy.PolishForDeclaration = true;
-  Policy.SuppressUnwrittenScope = true;
   QualType FQQT = getFullyQualifiedType(QT, Ctx, WithGlobalNsPrefix);
   return FQQT.getAsString(Policy);
 }
Index: include/clang/AST/QualTypeNames.h
===
--- include/clang/AST/QualTypeNames.h
+++ include/clang/AST/QualTypeNames.h
@@ -72,6 +72,7 @@
 /// \param[in] WithGlobalNsPrefix - If true, then the global namespace
 /// specifier "::" will be prepended to the fully qualified name.
 std::string getFullyQualifiedName(QualType QT, const ASTContext ,
+  const PrintingPolicy ,
   bool WithGlobalNsPrefix = false);
 
 /// \brief Generates a QualType that can be used to name the same type


Index: unittests/Tooling/QualTypeNamesTest.cpp
===
--- unittests/Tooling/QualTypeNamesTest.cpp
+++ unittests/Tooling/QualTypeNamesTest.cpp
@@ -26,9 +26,13 @@
 std::string ExpectedName =
 ExpectedQualTypeNames.lookup(VD->getNameAsString());
 if (ExpectedName != "") {
-  std::string ActualName =
-  TypeName::getFullyQualifiedName(VD->getType(), *Context,
-  WithGlobalNsPrefix);
+  PrintingPolicy Policy(Context->getPrintingPolicy());
+  Policy.SuppressScope = false;
+  Policy.AnonymousTagLocations = true;
+  Policy.PolishForDeclaration = true;
+  Policy.SuppressUnwrittenScope = true;
+  std::string ActualName = TypeName::getFullyQualifiedName(
+  VD->getType(), *Context, Policy, WithGlobalNsPrefix);
   if (ExpectedName != ActualName) {
 // A custom message makes it much easier to see what declaration
 // failed compared to EXPECT_EQ.
@@ -217,6 +221,26 @@
   "  }\n"
   "}\n"
   );
+
+  TypeNameVisitor AnonStrucs;
+  AnonStrucs.ExpectedQualTypeNames["a"] = "short";
+  AnonStrucs.ExpectedQualTypeNames["un_in_st_1"] =
+  "union (anonymous struct at input.cc:1:1)::(anonymous union at "
+  "input.cc:2:27)";
+  AnonStrucs.ExpectedQualTypeNames["b"] = "short";
+  AnonStrucs.ExpectedQualTypeNames["un_in_st_2"] =
+  "union (anonymous 

Re: [PATCH] D36610: [Tooling] Add option to getFullyQualifiedName using a custom PritingPolicy

2018-05-04 Thread Sterling Augustine via cfe-commits
I applied this to a clean local copy, which has no other changes, and have
the following test error, which may be pilot error on my part, but
nevertheless, this test needs to be robust to changes in the line number.

llvm-svn/llvm/tools/clang/unittests/Tooling/QualTypeNamesTest.cpp:39:
Failure
Value of: false
  Actual: false
Expected: true
Typename::getFullyQualifiedName failed for (anonymous struct)::un_in_st_1
   Actual: union (anonymous struct at input.cc:1:1)::(anonymous union at
input.cc:2:27)
 Exepcted: union (anonymous struct at input.cc:1:1)::(anonymous union at
input.cc:2:31)



On Fri, May 4, 2018 at 9:22 AM, Mikhail Ramalho via Phabricator <
revi...@reviews.llvm.org> wrote:

> mikhail.ramalho added a comment.
>
> Thanks.
>
> I just need someone to push it, as I don't have write access to the repo.
>
>
> https://reviews.llvm.org/D36610
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36610: [Tooling] Add option to getFullyQualifiedName using a custom PritingPolicy

2018-05-04 Thread Mikhail Ramalho via Phabricator via cfe-commits
mikhail.ramalho added a comment.

Thanks.

I just need someone to push it, as I don't have write access to the repo.


https://reviews.llvm.org/D36610



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


[PATCH] D36610: [Tooling] Add option to getFullyQualifiedName using a custom PritingPolicy

2018-05-03 Thread Sterling Augustine via Phabricator via cfe-commits
saugustine added a comment.

In https://reviews.llvm.org/D36610#1083952, @mikhail.ramalho wrote:

> Ping.


Given that richard smith is the only non-approver, and that he hasn't 
responded, and that I contributed this code, I'm going to make an executive 
decision and say that this is OK to submit.

We will roll back if there are problems.


https://reviews.llvm.org/D36610



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


Re: [PATCH] D36610: [Tooling] Add option to getFullyQualifiedName using a custom PritingPolicy

2018-05-02 Thread Mikhail Ramalho via cfe-commits
Last review asked to change the test case, I just want to make sure
everything is fine this time.

2018-05-02 8:54 GMT+01:00 Manuel Klimek via Phabricator <
revi...@reviews.llvm.org>:

> klimek added a comment.
>
> I believe this was accepted by rnk - are you waiting for specific further
> feedback?
>
>
> https://reviews.llvm.org/D36610
>
>
>
>


-- 

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


[PATCH] D36610: [Tooling] Add option to getFullyQualifiedName using a custom PritingPolicy

2018-05-02 Thread Mikhail Ramalho via Phabricator via cfe-commits
mikhail.ramalho added subscribers: rsmith, rnk.
mikhail.ramalho added a comment.

Last review asked to change the test case, I just want to make sure
everything is fine this time.


https://reviews.llvm.org/D36610



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


[PATCH] D36610: [Tooling] Add option to getFullyQualifiedName using a custom PritingPolicy

2018-05-02 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

I believe this was accepted by rnk - are you waiting for specific further 
feedback?


https://reviews.llvm.org/D36610



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


[PATCH] D36610: [Tooling] Add option to getFullyQualifiedName using a custom PritingPolicy

2018-05-01 Thread Mikhail Ramalho via Phabricator via cfe-commits
mikhail.ramalho marked an inline comment as done.
mikhail.ramalho added a comment.

Ping.


https://reviews.llvm.org/D36610



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


[PATCH] D36610: [Tooling] Add option to getFullyQualifiedName using a custom PritingPolicy

2018-04-24 Thread Mikhail Ramalho via Phabricator via cfe-commits
mikhail.ramalho marked an inline comment as done.
mikhail.ramalho added a comment.

ping.




Comment at: unittests/Tooling/QualTypeNamesTest.cpp:225
+
+  TypeNameVisitor PrintingPolicy;
+  PrintingPolicy.ExpectedQualTypeNames["a"] = "short";

rnk wrote:
> Please choose a different variable name that doesn't clash with the 
> PrintingPolicy type.
Done.


https://reviews.llvm.org/D36610



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


[PATCH] D36610: [Tooling] Add option to getFullyQualifiedName using a custom PritingPolicy

2018-04-16 Thread Mikhail Ramalho via Phabricator via cfe-commits
mikhail.ramalho updated this revision to Diff 142709.
mikhail.ramalho added a comment.

Renamed variables in the test so it doesn't match the type name


https://reviews.llvm.org/D36610

Files:
  include/clang/AST/QualTypeNames.h
  lib/AST/QualTypeNames.cpp
  unittests/Tooling/QualTypeNamesTest.cpp


Index: unittests/Tooling/QualTypeNamesTest.cpp
===
--- unittests/Tooling/QualTypeNamesTest.cpp
+++ unittests/Tooling/QualTypeNamesTest.cpp
@@ -26,9 +26,13 @@
 std::string ExpectedName =
 ExpectedQualTypeNames.lookup(VD->getNameAsString());
 if (ExpectedName != "") {
-  std::string ActualName =
-  TypeName::getFullyQualifiedName(VD->getType(), *Context,
-  WithGlobalNsPrefix);
+  PrintingPolicy Policy(Context->getPrintingPolicy());
+  Policy.SuppressScope = false;
+  Policy.AnonymousTagLocations = true;
+  Policy.PolishForDeclaration = true;
+  Policy.SuppressUnwrittenScope = true;
+  std::string ActualName = TypeName::getFullyQualifiedName(
+  VD->getType(), *Context, Policy, WithGlobalNsPrefix);
   if (ExpectedName != ActualName) {
 // A custom message makes it much easier to see what declaration
 // failed compared to EXPECT_EQ.
@@ -217,6 +221,26 @@
   "  }\n"
   "}\n"
   );
+
+  TypeNameVisitor AnonStrucs;
+  AnonStrucs.ExpectedQualTypeNames["a"] = "short";
+  AnonStrucs.ExpectedQualTypeNames["un_in_st_1"] =
+  "union (anonymous struct at input.cc:1:1)::(anonymous union at "
+  "input.cc:2:31)";
+  AnonStrucs.ExpectedQualTypeNames["b"] = "short";
+  AnonStrucs.ExpectedQualTypeNames["un_in_st_2"] =
+  "union (anonymous struct at input.cc:1:1)::(anonymous union at "
+  "input.cc:5:31)";
+  AnonStrucs.ExpectedQualTypeNames["anon_st"] =
+  "struct (anonymous struct at input.cc:1:1)";
+  AnonStrucs.runOver(R"(struct {
+  union {
+short a;
+  } un_in_st_1;
+  union {
+short b;
+  } un_in_st_2;
+} anon_st;)");
 }
 
-}  // end anonymous namespace
+} // end anonymous namespace
Index: lib/AST/QualTypeNames.cpp
===
--- lib/AST/QualTypeNames.cpp
+++ lib/AST/QualTypeNames.cpp
@@ -450,14 +450,9 @@
   return QT;
 }
 
-std::string getFullyQualifiedName(QualType QT,
-  const ASTContext ,
+std::string getFullyQualifiedName(QualType QT, const ASTContext ,
+  const PrintingPolicy ,
   bool WithGlobalNsPrefix) {
-  PrintingPolicy Policy(Ctx.getPrintingPolicy());
-  Policy.SuppressScope = false;
-  Policy.AnonymousTagLocations = false;
-  Policy.PolishForDeclaration = true;
-  Policy.SuppressUnwrittenScope = true;
   QualType FQQT = getFullyQualifiedType(QT, Ctx, WithGlobalNsPrefix);
   return FQQT.getAsString(Policy);
 }
Index: include/clang/AST/QualTypeNames.h
===
--- include/clang/AST/QualTypeNames.h
+++ include/clang/AST/QualTypeNames.h
@@ -72,6 +72,7 @@
 /// \param[in] WithGlobalNsPrefix - If true, then the global namespace
 /// specifier "::" will be prepended to the fully qualified name.
 std::string getFullyQualifiedName(QualType QT, const ASTContext ,
+  const PrintingPolicy ,
   bool WithGlobalNsPrefix = false);
 
 /// \brief Generates a QualType that can be used to name the same type


Index: unittests/Tooling/QualTypeNamesTest.cpp
===
--- unittests/Tooling/QualTypeNamesTest.cpp
+++ unittests/Tooling/QualTypeNamesTest.cpp
@@ -26,9 +26,13 @@
 std::string ExpectedName =
 ExpectedQualTypeNames.lookup(VD->getNameAsString());
 if (ExpectedName != "") {
-  std::string ActualName =
-  TypeName::getFullyQualifiedName(VD->getType(), *Context,
-  WithGlobalNsPrefix);
+  PrintingPolicy Policy(Context->getPrintingPolicy());
+  Policy.SuppressScope = false;
+  Policy.AnonymousTagLocations = true;
+  Policy.PolishForDeclaration = true;
+  Policy.SuppressUnwrittenScope = true;
+  std::string ActualName = TypeName::getFullyQualifiedName(
+  VD->getType(), *Context, Policy, WithGlobalNsPrefix);
   if (ExpectedName != ActualName) {
 // A custom message makes it much easier to see what declaration
 // failed compared to EXPECT_EQ.
@@ -217,6 +221,26 @@
   "  }\n"
   "}\n"
   );
+
+  TypeNameVisitor AnonStrucs;
+  AnonStrucs.ExpectedQualTypeNames["a"] = "short";
+  AnonStrucs.ExpectedQualTypeNames["un_in_st_1"] =
+  "union (anonymous struct at input.cc:1:1)::(anonymous union at "
+  

[PATCH] D36610: [Tooling] Add option to getFullyQualifiedName using a custom PritingPolicy

2018-04-16 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.

Mostly looks good.




Comment at: unittests/Tooling/QualTypeNamesTest.cpp:225
+
+  TypeNameVisitor PrintingPolicy;
+  PrintingPolicy.ExpectedQualTypeNames["a"] = "short";

Please choose a different variable name that doesn't clash with the 
PrintingPolicy type.


https://reviews.llvm.org/D36610



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


[PATCH] D36610: [Tooling] Add option to getFullyQualifiedName using a custom PritingPolicy

2018-04-15 Thread Mikhail Ramalho via Phabricator via cfe-commits
mikhail.ramalho updated this revision to Diff 142578.
mikhail.ramalho added a comment.

Rebased to current master.

Removed the getFullyQualifiedName overloaded function.


https://reviews.llvm.org/D36610

Files:
  include/clang/AST/QualTypeNames.h
  lib/AST/QualTypeNames.cpp
  unittests/Tooling/QualTypeNamesTest.cpp


Index: unittests/Tooling/QualTypeNamesTest.cpp
===
--- unittests/Tooling/QualTypeNamesTest.cpp
+++ unittests/Tooling/QualTypeNamesTest.cpp
@@ -26,9 +26,13 @@
 std::string ExpectedName =
 ExpectedQualTypeNames.lookup(VD->getNameAsString());
 if (ExpectedName != "") {
-  std::string ActualName =
-  TypeName::getFullyQualifiedName(VD->getType(), *Context,
-  WithGlobalNsPrefix);
+  PrintingPolicy Policy(Context->getPrintingPolicy());
+  Policy.SuppressScope = false;
+  Policy.AnonymousTagLocations = true;
+  Policy.PolishForDeclaration = true;
+  Policy.SuppressUnwrittenScope = true;
+  std::string ActualName = TypeName::getFullyQualifiedName(
+  VD->getType(), *Context, Policy, WithGlobalNsPrefix);
   if (ExpectedName != ActualName) {
 // A custom message makes it much easier to see what declaration
 // failed compared to EXPECT_EQ.
@@ -217,6 +221,26 @@
   "  }\n"
   "}\n"
   );
+
+  TypeNameVisitor PrintingPolicy;
+  PrintingPolicy.ExpectedQualTypeNames["a"] = "short";
+  PrintingPolicy.ExpectedQualTypeNames["un_in_st_1"] =
+  "union (anonymous struct at input.cc:1:1)::(anonymous union at "
+  "input.cc:2:31)";
+  PrintingPolicy.ExpectedQualTypeNames["b"] = "short";
+  PrintingPolicy.ExpectedQualTypeNames["un_in_st_2"] =
+  "union (anonymous struct at input.cc:1:1)::(anonymous union at "
+  "input.cc:5:31)";
+  PrintingPolicy.ExpectedQualTypeNames["anon_st"] =
+  "struct (anonymous struct at input.cc:1:1)";
+  PrintingPolicy.runOver(R"(struct {
+  union {
+short a;
+  } un_in_st_1;
+  union {
+short b;
+  } un_in_st_2;
+} anon_st;)");
 }
 
 }  // end anonymous namespace
Index: lib/AST/QualTypeNames.cpp
===
--- lib/AST/QualTypeNames.cpp
+++ lib/AST/QualTypeNames.cpp
@@ -450,14 +450,9 @@
   return QT;
 }
 
-std::string getFullyQualifiedName(QualType QT,
-  const ASTContext ,
+std::string getFullyQualifiedName(QualType QT, const ASTContext ,
+  const PrintingPolicy ,
   bool WithGlobalNsPrefix) {
-  PrintingPolicy Policy(Ctx.getPrintingPolicy());
-  Policy.SuppressScope = false;
-  Policy.AnonymousTagLocations = false;
-  Policy.PolishForDeclaration = true;
-  Policy.SuppressUnwrittenScope = true;
   QualType FQQT = getFullyQualifiedType(QT, Ctx, WithGlobalNsPrefix);
   return FQQT.getAsString(Policy);
 }
Index: include/clang/AST/QualTypeNames.h
===
--- include/clang/AST/QualTypeNames.h
+++ include/clang/AST/QualTypeNames.h
@@ -72,6 +72,7 @@
 /// \param[in] WithGlobalNsPrefix - If true, then the global namespace
 /// specifier "::" will be prepended to the fully qualified name.
 std::string getFullyQualifiedName(QualType QT, const ASTContext ,
+  const PrintingPolicy ,
   bool WithGlobalNsPrefix = false);
 
 /// \brief Generates a QualType that can be used to name the same type


Index: unittests/Tooling/QualTypeNamesTest.cpp
===
--- unittests/Tooling/QualTypeNamesTest.cpp
+++ unittests/Tooling/QualTypeNamesTest.cpp
@@ -26,9 +26,13 @@
 std::string ExpectedName =
 ExpectedQualTypeNames.lookup(VD->getNameAsString());
 if (ExpectedName != "") {
-  std::string ActualName =
-  TypeName::getFullyQualifiedName(VD->getType(), *Context,
-  WithGlobalNsPrefix);
+  PrintingPolicy Policy(Context->getPrintingPolicy());
+  Policy.SuppressScope = false;
+  Policy.AnonymousTagLocations = true;
+  Policy.PolishForDeclaration = true;
+  Policy.SuppressUnwrittenScope = true;
+  std::string ActualName = TypeName::getFullyQualifiedName(
+  VD->getType(), *Context, Policy, WithGlobalNsPrefix);
   if (ExpectedName != ActualName) {
 // A custom message makes it much easier to see what declaration
 // failed compared to EXPECT_EQ.
@@ -217,6 +221,26 @@
   "  }\n"
   "}\n"
   );
+
+  TypeNameVisitor PrintingPolicy;
+  PrintingPolicy.ExpectedQualTypeNames["a"] = "short";
+  PrintingPolicy.ExpectedQualTypeNames["un_in_st_1"] =
+  "union 

[PATCH] D36610: [Tooling] Add option to getFullyQualifiedName using a custom PritingPolicy

2017-11-07 Thread Mikhail Ramalho via Phabricator via cfe-commits
mikhail.ramalho added a comment.

Should we keep just the version with the custom printing policy then?


https://reviews.llvm.org/D36610



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


[PATCH] D36610: [Tooling] Add option to getFullyQualifiedName using a custom PritingPolicy

2017-11-07 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

Sorry for jumping in late, but I'm somewhat questioning whether an extra 
function in the API is worth the cost here:
If you already have a printing policy, getting the type name will be 1 line 
instead of 2; having an extra function in a large API seems not worth it at a 
first glance.


https://reviews.llvm.org/D36610



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


[PATCH] D36610: [Tooling] Add option to getFullyQualifiedName using a custom PritingPolicy

2017-09-13 Thread Mikhail Ramalho via Phabricator via cfe-commits
mikhail.ramalho marked an inline comment as done.
mikhail.ramalho added a comment.

ping


https://reviews.llvm.org/D36610



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


[PATCH] D36610: [Tooling] Add option to getFullyQualifiedName using a custom PritingPolicy

2017-08-15 Thread Mikhail Ramalho via Phabricator via cfe-commits
mikhail.ramalho updated this revision to Diff 63.
mikhail.ramalho added a comment.

Updated QualTypeNamesTest.cpp to use multiline string in all tests.

Also ran clang-format -style=LLVM for code style.


https://reviews.llvm.org/D36610

Files:
  include/clang/Tooling/Core/QualTypeNames.h
  lib/Tooling/Core/QualTypeNames.cpp
  unittests/Tooling/QualTypeNamesTest.cpp

Index: unittests/Tooling/QualTypeNamesTest.cpp
===
--- unittests/Tooling/QualTypeNamesTest.cpp
+++ unittests/Tooling/QualTypeNamesTest.cpp
@@ -7,28 +7,40 @@
 //
 //===--===//
 
-#include "clang/Tooling/Core/QualTypeNames.h"
 #include "TestVisitor.h"
+#include "clang/Tooling/Core/QualTypeNames.h"
 using namespace clang;
 
 namespace {
 struct TypeNameVisitor : TestVisitor {
   llvm::StringMap ExpectedQualTypeNames;
   bool WithGlobalNsPrefix = false;
+  bool CustomPrintingPolicy = false;
 
   // ValueDecls are the least-derived decl with both a qualtype and a
   // name.
   bool traverseDecl(Decl *D) {
-return true;  // Always continue
+return true; // Always continue
   }
 
   bool VisitValueDecl(const ValueDecl *VD) {
 std::string ExpectedName =
 ExpectedQualTypeNames.lookup(VD->getNameAsString());
 if (ExpectedName != "") {
-  std::string ActualName =
-  TypeName::getFullyQualifiedName(VD->getType(), *Context,
-  WithGlobalNsPrefix);
+  std::string ActualName;
+  if (!CustomPrintingPolicy)
+ActualName = TypeName::getFullyQualifiedName(VD->getType(), *Context,
+ WithGlobalNsPrefix);
+  else {
+PrintingPolicy Policy(Context->getPrintingPolicy());
+Policy.SuppressScope = false;
+Policy.AnonymousTagLocations = true;
+Policy.PolishForDeclaration = true;
+Policy.SuppressUnwrittenScope = true;
+ActualName = TypeName::getFullyQualifiedName(
+VD->getType(), *Context, Policy, WithGlobalNsPrefix);
+  }
+
   if (ExpectedName != ActualName) {
 // A custom message makes it much easier to see what declaration
 // failed compared to EXPECT_EQ.
@@ -93,94 +105,92 @@
   Visitor.ExpectedQualTypeNames["CheckM"] = "const A::B::Class0 *";
   Visitor.ExpectedQualTypeNames["CheckN"] = "const X *";
   Visitor.runOver(
-  "int CheckInt;\n"
-  "template \n"
-  "class OuterTemplateClass { };\n"
-  "namespace A {\n"
-  " namespace B {\n"
-  "   class Class0 { };\n"
-  "   namespace C {\n"
-  " typedef int MyInt;"
-  " template \n"
-  " using InnerAlias = OuterTemplateClass;\n"
-  " InnerAlias AliasTypeVal;\n"
-  "   }\n"
-  "   template class Template0;"
-  "   template class Template1;"
-  "   typedef B::Class0 AnotherClass;\n"
-  "   void Function1(Template0 CheckC);\n"
-  "   void Function2(Template0,\n"
-  "Template0 > CheckD);\n"
-  "   void Function3(const B::Class0* CheckM);\n"
-  "  }\n"
-  "template class Variadic {};\n"
-  "Variadic, "
-  " B::Template1, "
-  " B::C::MyInt > CheckE;\n"
-  " namespace BC = B::C;\n"
-  " BC::MyInt CheckL;\n"
-  "}\n"
-  "using A::B::Class0;\n"
-  "void Function(Class0 CheckF);\n"
-  "using namespace A::B::C;\n"
-  "void Function(MyInt CheckG);\n"
-  "void f() {\n"
-  "  struct X {} CheckH;\n"
-  "}\n"
-  "struct X;\n"
-  "void f(const ::X* CheckN) {}\n"
-  "namespace {\n"
-  "  class aClass {};\n"
-  "   aClass CheckI;\n"
-  "}\n"
-  "namespace A {\n"
-  "  struct aStruct {} CheckJ;\n"
-  "}\n"
-  "namespace {\n"
-  "  namespace D {\n"
-  "namespace {\n"
-  "  class aStruct {};\n"
-  "  aStruct CheckK;\n"
-  "}\n"
-  "  }\n"
-  "}\n"
-  "template struct Foo {\n"
-  "  typedef typename T::A dependent_type;\n"
-  "  typedef int non_dependent_type;\n"
-  "  dependent_type dependent_type_var;\n"
-  "  non_dependent_type non_dependent_type_var;\n"
-  "};\n"
-  "struct X { typedef int A; };"
-  "Foo var;"
-  "void F() {\n"
-  "  var.dependent_type_var = 0;\n"
-  "var.non_dependent_type_var = 0;\n"
-  "}\n"
-  "class EnumScopeClass {\n"
-  "public:\n"
-  "  enum AnEnum { ZERO, ONE };\n"
-  "};\n"
-  "EnumScopeClass::AnEnum AnEnumVar;\n",
-  TypeNameVisitor::Lang_CXX11
-);
+  R"(int CheckInt;
+ template 
+ class OuterTemplateClass { };
+ namespace A {
+  namespace B {
+class Class0 { };
+namespace C {
+  typedef int MyInt;
+ 

[PATCH] D36610: [Tooling] Add option to getFullyQualifiedName using a custom PritingPolicy

2017-08-11 Thread Mikhail Ramalho via Phabricator via cfe-commits
mikhail.ramalho added a comment.

Should I update the other tests in QualTypeNamesTest.cpp to use multiline 
strings as well?


https://reviews.llvm.org/D36610



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


[PATCH] D36610: [Tooling] Add option to getFullyQualifiedName using a custom PritingPolicy

2017-08-11 Thread Sterling Augustine via Phabricator via cfe-commits
saugustine accepted this revision.
saugustine added a comment.
This revision is now accepted and ready to land.

This is a good change as far as functionality, but I defer to others on the 
style and other details.


https://reviews.llvm.org/D36610



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


[PATCH] D36610: [Tooling] Add option to getFullyQualifiedName using a custom PritingPolicy

2017-08-11 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: unittests/Tooling/QualTypeNamesTest.cpp:247
+  "struct (anonymous struct at input.cc:1:1)";
+  PrintingPolicy.runOver(
+  "struct\n"

You should probably use multiline string here, i.e. R(" ... ")


https://reviews.llvm.org/D36610



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


[PATCH] D36610: [Tooling] Add option to getFullyQualifiedName using a custom PritingPolicy

2017-08-11 Thread Mikhail Ramalho via Phabricator via cfe-commits
mikhail.ramalho created this revision.
Herald added a subscriber: klimek.

In our user case, we need to generate unique names for every tag, including 
anonymous structs/unions.

This adds a custom PrintingPolicy option to getFullyQualifiedName and the test 
case shows that different names are generated for different anonymous 
unions/structs.


https://reviews.llvm.org/D36610

Files:
  include/clang/Tooling/Core/QualTypeNames.h
  lib/Tooling/Core/QualTypeNames.cpp
  unittests/Tooling/QualTypeNamesTest.cpp

Index: unittests/Tooling/QualTypeNamesTest.cpp
===
--- unittests/Tooling/QualTypeNamesTest.cpp
+++ unittests/Tooling/QualTypeNamesTest.cpp
@@ -15,6 +15,7 @@
 struct TypeNameVisitor : TestVisitor {
   llvm::StringMap ExpectedQualTypeNames;
   bool WithGlobalNsPrefix = false;
+  bool CustomPrintingPolicy = false;
 
   // ValueDecls are the least-derived decl with both a qualtype and a
   // name.
@@ -26,9 +27,22 @@
 std::string ExpectedName =
 ExpectedQualTypeNames.lookup(VD->getNameAsString());
 if (ExpectedName != "") {
-  std::string ActualName =
-  TypeName::getFullyQualifiedName(VD->getType(), *Context,
-  WithGlobalNsPrefix);
+  std::string ActualName;
+  if (!CustomPrintingPolicy)
+ActualName =
+TypeName::getFullyQualifiedName(VD->getType(), *Context,
+WithGlobalNsPrefix);
+  else {
+PrintingPolicy Policy(Context->getPrintingPolicy());
+Policy.SuppressScope = false;
+Policy.AnonymousTagLocations = true;
+Policy.PolishForDeclaration = true;
+Policy.SuppressUnwrittenScope = true;
+ActualName =
+TypeName::getFullyQualifiedName(VD->getType(), *Context,
+Policy, WithGlobalNsPrefix);
+  }
+
   if (ExpectedName != ActualName) {
 // A custom message makes it much easier to see what declaration
 // failed compared to EXPECT_EQ.
@@ -217,6 +231,32 @@
   "  }\n"
   "}\n"
   );
+
+  TypeNameVisitor PrintingPolicy;
+  PrintingPolicy.CustomPrintingPolicy = true;
+  PrintingPolicy.ExpectedQualTypeNames["a"] = "short";
+  PrintingPolicy.ExpectedQualTypeNames["un_in_st_1"] =
+  "union (anonymous struct at input.cc:1:1)::(anonymous union at "
+  "input.cc:3:3)";
+  PrintingPolicy.ExpectedQualTypeNames["b"] = "short";
+  PrintingPolicy.ExpectedQualTypeNames["un_in_st_2"] =
+  "union (anonymous struct at input.cc:1:1)::(anonymous union at "
+  "input.cc:7:3)";
+  PrintingPolicy.ExpectedQualTypeNames["anon_st"] =
+  "struct (anonymous struct at input.cc:1:1)";
+  PrintingPolicy.runOver(
+  "struct\n"
+  "{\n"
+  "  union\n"
+  "  {\n"
+  "short a;\n"
+  "  } un_in_st_1;\n"
+  "  union\n"
+  "  {\n"
+  "short b;\n"
+  "  } un_in_st_2;\n"
+  "} anon_st;\n"
+  );
 }
 
 }  // end anonymous namespace
Index: lib/Tooling/Core/QualTypeNames.cpp
===
--- lib/Tooling/Core/QualTypeNames.cpp
+++ lib/Tooling/Core/QualTypeNames.cpp
@@ -463,14 +463,21 @@
 
 std::string getFullyQualifiedName(QualType QT,
   const ASTContext ,
+  const PrintingPolicy ,
+  bool WithGlobalNsPrefix) {
+  QualType FQQT = getFullyQualifiedType(QT, Ctx, WithGlobalNsPrefix);
+  return FQQT.getAsString(Policy);
+}
+
+std::string getFullyQualifiedName(QualType QT,
+  const ASTContext ,
   bool WithGlobalNsPrefix) {
   PrintingPolicy Policy(Ctx.getPrintingPolicy());
   Policy.SuppressScope = false;
   Policy.AnonymousTagLocations = false;
   Policy.PolishForDeclaration = true;
   Policy.SuppressUnwrittenScope = true;
-  QualType FQQT = getFullyQualifiedType(QT, Ctx, WithGlobalNsPrefix);
-  return FQQT.getAsString(Policy);
+  return getFullyQualifiedName(QT, Ctx, Policy, WithGlobalNsPrefix);
 }
 
 }  // end namespace TypeName
Index: include/clang/Tooling/Core/QualTypeNames.h
===
--- include/clang/Tooling/Core/QualTypeNames.h
+++ include/clang/Tooling/Core/QualTypeNames.h
@@ -74,6 +74,11 @@
 std::string getFullyQualifiedName(QualType QT,
   const ASTContext ,
   bool WithGlobalNsPrefix = false);
+
+std::string getFullyQualifiedName(QualType QT,
+  const ASTContext ,
+  const PrintingPolicy ,
+  bool WithGlobalNsPrefix = false);
 }  // end namespace TypeName
 }  // end namespace clang
 #endif  // LLVM_CLANG_TOOLING_CORE_QUALTYPENAMES_H
___
cfe-commits mailing list