r331552 - Allow modifying the PrintingPolicy for fully qualified names.
Sterling Augustine via cfe-commits
cfe-commits at lists.llvm.org
Fri May 4 13:12:39 PDT 2018
Author: saugustine
Date: Fri May 4 13:12:39 2018
New Revision: 331552
URL: http://llvm.org/viewvc/llvm-project?rev=331552&view=rev
Log:
Allow modifying the PrintingPolicy for fully qualified names.
Author: mikhail.ramalho at gmail.com
Modified:
cfe/trunk/include/clang/AST/QualTypeNames.h
cfe/trunk/lib/AST/QualTypeNames.cpp
cfe/trunk/unittests/Tooling/QualTypeNamesTest.cpp
Modified: cfe/trunk/include/clang/AST/QualTypeNames.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/QualTypeNames.h?rev=331552&r1=331551&r2=331552&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/QualTypeNames.h (original)
+++ cfe/trunk/include/clang/AST/QualTypeNames.h Fri May 4 13:12:39 2018
@@ -72,6 +72,7 @@ namespace TypeName {
/// \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 &Ctx,
+ const PrintingPolicy &Policy,
bool WithGlobalNsPrefix = false);
/// \brief Generates a QualType that can be used to name the same type
Modified: cfe/trunk/lib/AST/QualTypeNames.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/QualTypeNames.cpp?rev=331552&r1=331551&r2=331552&view=diff
==============================================================================
--- cfe/trunk/lib/AST/QualTypeNames.cpp (original)
+++ cfe/trunk/lib/AST/QualTypeNames.cpp Fri May 4 13:12:39 2018
@@ -452,12 +452,8 @@ QualType getFullyQualifiedType(QualType
std::string getFullyQualifiedName(QualType QT,
const ASTContext &Ctx,
+ const PrintingPolicy &Policy,
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);
}
Modified: cfe/trunk/unittests/Tooling/QualTypeNamesTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/QualTypeNamesTest.cpp?rev=331552&r1=331551&r2=331552&view=diff
==============================================================================
--- cfe/trunk/unittests/Tooling/QualTypeNamesTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/QualTypeNamesTest.cpp Fri May 4 13:12:39 2018
@@ -26,9 +26,13 @@ struct TypeNameVisitor : TestVisitor<Typ
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 @@ TEST(QualTypeNameTest, getFullyQualified
" }\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
More information about the cfe-commits
mailing list