From c1485310503a055719a589594b4aabcc063ab60e Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Tue, 25 Feb 2014 18:49:49 +0000 Subject: [PATCH] Pretty Printer: Print constexpr and ref qualifiers. Don't print return types on destructors. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202181 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/DeclPrinter.cpp | 16 ++++++++++++- test/Index/comment-cplus-decls.cpp | 2 +- test/Index/comment-cplus-template-decls.cpp | 2 +- test/Index/comment-to-html-xml-conversion.cpp | 2 +- unittests/AST/DeclPrinterTest.cpp | 24 ++++++++----------- 5 files changed, 28 insertions(+), 18 deletions(-) diff --git a/lib/AST/DeclPrinter.cpp b/lib/AST/DeclPrinter.cpp index 05701a5b06..aa292dbfe1 100644 --- a/lib/AST/DeclPrinter.cpp +++ b/lib/AST/DeclPrinter.cpp @@ -399,6 +399,7 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { if (D->isInlineSpecified()) Out << "inline "; if (D->isVirtualAsWritten()) Out << "virtual "; if (D->isModulePrivate()) Out << "__module_private__ "; + if (D->isConstexpr() && !D->isExplicitlyDefaulted()) Out << "constexpr "; if ((CDecl && CDecl->isExplicitSpecified()) || (ConversionDecl && ConversionDecl->isExplicit())) Out << "explicit "; @@ -449,6 +450,17 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { Proto += " volatile"; if (FT->isRestrict()) Proto += " restrict"; + + switch (FT->getRefQualifier()) { + case RQ_None: + break; + case RQ_LValue: + Proto += " &"; + break; + case RQ_RValue: + Proto += " &&"; + break; + } } if (FT && FT->hasDynamicExceptionSpec()) { @@ -537,8 +549,10 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { } } Out << ")"; + if (BMInitializer->isPackExpansion()) + Out << "..."; } - } else if (!ConversionDecl) { + } else if (!ConversionDecl && !isa(D)) { if (FT && FT->hasTrailingReturn()) { Out << "auto " << Proto << " -> "; Proto.clear(); diff --git a/test/Index/comment-cplus-decls.cpp b/test/Index/comment-cplus-decls.cpp index de1c2c5226..002482ed0f 100644 --- a/test/Index/comment-cplus-decls.cpp +++ b/test/Index/comment-cplus-decls.cpp @@ -42,7 +42,7 @@ protected: // CHECK: class Test {} // CHECK: Test() : reserved(new Test::data()) // CHECK: unsigned int getID() const -// CHECK: void ~Test() +// CHECK: ~Test() // CHECK: Test::data *reserved diff --git a/test/Index/comment-cplus-template-decls.cpp b/test/Index/comment-cplus-template-decls.cpp index 039f092a62..9510c7ce15 100644 --- a/test/Index/comment-cplus-template-decls.cpp +++ b/test/Index/comment-cplus-template-decls.cpp @@ -27,7 +27,7 @@ template struct A { }; // CHECK: template <typename T> struct A {} // CHECK: A<T>() -// CHECK: void ~A<T>() +// CHECK: ~A<T>() /** * \Brief Eee diff --git a/test/Index/comment-to-html-xml-conversion.cpp b/test/Index/comment-to-html-xml-conversion.cpp index 697f91c9cb..a824ec48b4 100644 --- a/test/Index/comment-to-html-xml-conversion.cpp +++ b/test/Index/comment-to-html-xml-conversion.cpp @@ -734,7 +734,7 @@ class comment_to_xml_conversion_01 { /// Aaa. ~comment_to_xml_conversion_01(); -// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:3: CXXDestructor=~comment_to_xml_conversion_01:{{.*}} FullCommentAsXML=[~comment_to_xml_conversion_01c:@C@comment_to_xml_conversion_01@F@~comment_to_xml_conversion_01#void ~comment_to_xml_conversion_01() Aaa.] +// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:3: CXXDestructor=~comment_to_xml_conversion_01:{{.*}} FullCommentAsXML=[~comment_to_xml_conversion_01c:@C@comment_to_xml_conversion_01@F@~comment_to_xml_conversion_01#~comment_to_xml_conversion_01() Aaa.] /// \param aaa Blah blah. int comment_to_xml_conversion_02(int aaa); diff --git a/unittests/AST/DeclPrinterTest.cpp b/unittests/AST/DeclPrinterTest.cpp index 34739f7e8a..381536d9cd 100644 --- a/unittests/AST/DeclPrinterTest.cpp +++ b/unittests/AST/DeclPrinterTest.cpp @@ -354,8 +354,8 @@ TEST(DeclPrinter, TestFunctionDecl7) { ASSERT_TRUE(PrintedDeclCXX11Matches( "constexpr int A(int a);", "A", - "int A(int a)")); - // WRONG; Should be: "constexpr int A(int a);" + "constexpr int A(int a)")); + // Should be: with semicolon } TEST(DeclPrinter, TestFunctionDecl8) { @@ -480,8 +480,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl7) { " constexpr A();" "};", constructorDecl(ofClass(hasName("A"))).bind("id"), - "A()")); - // WRONG; Should be: "constexpr A();" + "constexpr A()")); } TEST(DeclPrinter, TestCXXConstructorDecl8) { @@ -519,8 +518,7 @@ TEST(DeclPrinter, TestCXXConstructorDecl11) { " A(T&&... ts) : T(ts)... {}" "};", constructorDecl(ofClass(hasName("A"))).bind("id"), - "A(T &&ts...) : T(ts)")); - // WRONG; Should be: "A(T&&... ts) : T(ts)..." + "A(T &&ts...) : T(ts)...")); } TEST(DeclPrinter, TestCXXDestructorDecl1) { @@ -529,8 +527,7 @@ TEST(DeclPrinter, TestCXXDestructorDecl1) { " ~A();" "};", destructorDecl(ofClass(hasName("A"))).bind("id"), - "void ~A()")); - // WRONG; Should be: "~A();" + "~A()")); } TEST(DeclPrinter, TestCXXDestructorDecl2) { @@ -539,8 +536,7 @@ TEST(DeclPrinter, TestCXXDestructorDecl2) { " virtual ~A();" "};", destructorDecl(ofClass(hasName("A"))).bind("id"), - "virtual void ~A()")); - // WRONG; Should be: "virtual ~A();" + "virtual ~A()")); } TEST(DeclPrinter, TestCXXConversionDecl1) { @@ -765,8 +761,8 @@ TEST(DeclPrinter, TestCXXMethodDecl_RefQualifier1) { " void A(int a) &;" "};", "A", - "void A(int a)")); - // WRONG; Should be: "void A(int a) &;" + "void A(int a) &")); + // Should be: with semicolon } TEST(DeclPrinter, TestCXXMethodDecl_RefQualifier2) { @@ -775,8 +771,8 @@ TEST(DeclPrinter, TestCXXMethodDecl_RefQualifier2) { " void A(int a) &&;" "};", "A", - "void A(int a)")); - // WRONG; Should be: "void A(int a) &&;" + "void A(int a) &&")); + // Should be: with semicolon } TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification1) { -- 2.40.0