Author: arphaman Date: Tue Apr 11 11:46:03 2017 New Revision: 299962 URL: http://llvm.org/viewvc/llvm-project?rev=299962&view=rev Log: [ASTPrinter] Print nested name specifiers for out-of-line functions
rdar://31501863 Added: cfe/trunk/test/Misc/ast-print-out-of-line-func.cpp Modified: cfe/trunk/lib/AST/DeclPrinter.cpp cfe/trunk/lib/AST/DeclarationName.cpp cfe/trunk/test/Index/comment-cplus-decls.cpp cfe/trunk/test/Index/overriding-method-comments.mm Modified: cfe/trunk/lib/AST/DeclPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=299962&r1=299961&r2=299962&view=diff ============================================================================== --- cfe/trunk/lib/AST/DeclPrinter.cpp (original) +++ cfe/trunk/lib/AST/DeclPrinter.cpp Tue Apr 11 11:46:03 2017 @@ -504,7 +504,14 @@ void DeclPrinter::VisitFunctionDecl(Func PrintingPolicy SubPolicy(Policy); SubPolicy.SuppressSpecifiers = false; - std::string Proto = D->getNameInfo().getAsString(); + std::string Proto; + if (!Policy.SuppressScope) { + if (const NestedNameSpecifier *NS = D->getQualifier()) { + llvm::raw_string_ostream OS(Proto); + NS->print(OS, Policy); + } + } + Proto += D->getNameInfo().getAsString(); if (GuideDecl) Proto = GuideDecl->getDeducedTemplate()->getDeclName().getAsString(); if (const TemplateArgumentList *TArgs = D->getTemplateSpecializationArgs()) { Modified: cfe/trunk/lib/AST/DeclarationName.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclarationName.cpp?rev=299962&r1=299961&r2=299962&view=diff ============================================================================== --- cfe/trunk/lib/AST/DeclarationName.cpp (original) +++ cfe/trunk/lib/AST/DeclarationName.cpp Tue Apr 11 11:46:03 2017 @@ -660,7 +660,9 @@ void DeclarationNameInfo::printName(raw_ LangOptions LO; LO.CPlusPlus = true; LO.Bool = true; - OS << TInfo->getType().getAsString(PrintingPolicy(LO)); + PrintingPolicy PP(LO); + PP.SuppressScope = true; + OS << TInfo->getType().getAsString(PP); } else OS << Name; return; Modified: cfe/trunk/test/Index/comment-cplus-decls.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/comment-cplus-decls.cpp?rev=299962&r1=299961&r2=299962&view=diff ============================================================================== --- cfe/trunk/test/Index/comment-cplus-decls.cpp (original) +++ cfe/trunk/test/Index/comment-cplus-decls.cpp Tue Apr 11 11:46:03 2017 @@ -102,7 +102,7 @@ namespace test0 { friend void ns::f(int a); }; } -// CHECK: <Declaration>friend void f(int a)</Declaration> +// CHECK: <Declaration>friend void ns::f(int a)</Declaration> namespace test1 { template <class T> struct Outer { @@ -115,7 +115,7 @@ namespace test1 { }; }; } -// CHECK: <Declaration>friend void foo(T)</Declaration> +// CHECK: <Declaration>friend void Outer<T>::foo(T)</Declaration> namespace test2 { namespace foo { @@ -129,7 +129,7 @@ namespace test2 { friend void ::test2::foo::Func(int x); }; } -// CHECK: <Declaration>friend void Func(int x)</Declaration> +// CHECK: <Declaration>friend void ::test2::foo::Func(int x)</Declaration> namespace test3 { template<class T> class vector { @@ -149,7 +149,7 @@ namespace test3 { }; } // CHECK: <Declaration>void f(const T &t = T())</Declaration> -// CHECK: <Declaration>friend void f(const test3::A &)</Declaration> +// CHECK: <Declaration>friend void vector<A>::f(const test3::A &)</Declaration> class MyClass { Modified: cfe/trunk/test/Index/overriding-method-comments.mm URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/overriding-method-comments.mm?rev=299962&r1=299961&r2=299962&view=diff ============================================================================== --- cfe/trunk/test/Index/overriding-method-comments.mm (original) +++ cfe/trunk/test/Index/overriding-method-comments.mm Tue Apr 11 11:46:03 2017 @@ -78,7 +78,7 @@ struct Base { void Base::foo_outofline(int RRR) {} -// CHECK: FullCommentAsXML=[<Function isInstanceMethod="1" file="{{[^"]+}}overriding-method-comments.mm" line="[[@LINE-2]]" column="12"><Name>foo_outofline</Name><USR>c:@S@Base@F@foo_outofline#I#</USR><Declaration>void foo_outofline(int RRR)</Declaration><Abstract><Para> Does something. </Para></Abstract><Parameters><Parameter><Name>RRR</Name><Index>0</Index><Direction isExplicit="0">in</Direction><Discussion><Para> argument to undefined virtual.</Para></Discussion></Parameter></Parameters></Function>] +// CHECK: FullCommentAsXML=[<Function isInstanceMethod="1" file="{{[^"]+}}overriding-method-comments.mm" line="[[@LINE-2]]" column="12"><Name>foo_outofline</Name><USR>c:@S@Base@F@foo_outofline#I#</USR><Declaration>void Base::foo_outofline(int RRR)</Declaration><Abstract><Para> Does something. </Para></Abstract><Parameters><Parameter><Name>RRR</Name><Index>0</Index><Direction isExplicit="0">in</Direction><Discussion><Para> argument to undefined virtual.</Para></Discussion></Parameter></Parameters></Function>] struct Derived : public Base { virtual void foo_pure(int PPP); Added: cfe/trunk/test/Misc/ast-print-out-of-line-func.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/ast-print-out-of-line-func.cpp?rev=299962&view=auto ============================================================================== --- cfe/trunk/test/Misc/ast-print-out-of-line-func.cpp (added) +++ cfe/trunk/test/Misc/ast-print-out-of-line-func.cpp Tue Apr 11 11:46:03 2017 @@ -0,0 +1,54 @@ +// RUN: %clang_cc1 -ast-print -std=c++14 %s | FileCheck %s + +namespace ns { + +struct Wrapper { +class Inner { + Inner(); + Inner(int); + ~Inner(); + + void operator += (int); + + template<typename T> + void member(); + + static void staticMember(); + + operator int(); + + operator ns::Wrapper(); + // CHECK: operator ns::Wrapper() +}; +}; + +Wrapper::Inner::Inner() { } +// CHECK: Wrapper::Inner::Inner() + +void Wrapper::Inner::operator +=(int) { } +// CHECK: void Wrapper::Inner::operator+=(int) + +} + +ns::Wrapper::Inner::Inner(int) { } +// CHECK: ns::Wrapper::Inner::Inner(int) + +ns::Wrapper::Inner::~Inner() { } +// CHECK: ns::Wrapper::Inner::~Inner() + +template<typename T> +void ::ns::Wrapper::Inner::member() { } +// CHECK: template <typename T> void ::ns::Wrapper::Inner::member() + +ns::Wrapper::Inner::operator int() { return 0; } +// CHECK: ns::Wrapper::Inner::operator int() + +ns::Wrapper::Inner::operator ::ns::Wrapper() { return ns::Wrapper(); } +// CHECK: ns::Wrapper::Inner::operator ::ns::Wrapper() + +namespace ns { + +void Wrapper::Inner::staticMember() { } +// CHECK: void Wrapper::Inner::staticMember() + +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits