From 506a43a28e16fd08b23f2ee57c3ef0debba27042 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Tue, 11 Apr 2017 16:46:03 +0000 Subject: [PATCH] [ASTPrinter] Print nested name specifiers for out-of-line functions rdar://31501863 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@299962 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/DeclPrinter.cpp | 9 +++- lib/AST/DeclarationName.cpp | 4 +- test/Index/comment-cplus-decls.cpp | 8 ++-- test/Index/overriding-method-comments.mm | 2 +- test/Misc/ast-print-out-of-line-func.cpp | 54 ++++++++++++++++++++++++ 5 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 test/Misc/ast-print-out-of-line-func.cpp diff --git a/lib/AST/DeclPrinter.cpp b/lib/AST/DeclPrinter.cpp index aedc35b0f8..5d841a197f 100644 --- a/lib/AST/DeclPrinter.cpp +++ b/lib/AST/DeclPrinter.cpp @@ -504,7 +504,14 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { 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()) { diff --git a/lib/AST/DeclarationName.cpp b/lib/AST/DeclarationName.cpp index 6053bd7e39..1f8e26deda 100644 --- a/lib/AST/DeclarationName.cpp +++ b/lib/AST/DeclarationName.cpp @@ -660,7 +660,9 @@ void DeclarationNameInfo::printName(raw_ostream &OS) const { 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; diff --git a/test/Index/comment-cplus-decls.cpp b/test/Index/comment-cplus-decls.cpp index 463aa9e792..6e32c60a22 100644 --- a/test/Index/comment-cplus-decls.cpp +++ b/test/Index/comment-cplus-decls.cpp @@ -102,7 +102,7 @@ namespace test0 { friend void ns::f(int a); }; } -// CHECK: friend void f(int a) +// CHECK: friend void ns::f(int a) namespace test1 { template struct Outer { @@ -115,7 +115,7 @@ namespace test1 { }; }; } -// CHECK: friend void foo(T) +// CHECK: friend void Outer<T>::foo(T) namespace test2 { namespace foo { @@ -129,7 +129,7 @@ namespace test2 { friend void ::test2::foo::Func(int x); }; } -// CHECK: friend void Func(int x) +// CHECK: friend void ::test2::foo::Func(int x) namespace test3 { template class vector { @@ -149,7 +149,7 @@ namespace test3 { }; } // CHECK: void f(const T &t = T()) -// CHECK: friend void f(const test3::A &) +// CHECK: friend void vector<A>::f(const test3::A &) class MyClass { diff --git a/test/Index/overriding-method-comments.mm b/test/Index/overriding-method-comments.mm index d995e0eca7..824d055b16 100644 --- a/test/Index/overriding-method-comments.mm +++ b/test/Index/overriding-method-comments.mm @@ -78,7 +78,7 @@ struct Base { void Base::foo_outofline(int RRR) {} -// CHECK: FullCommentAsXML=[foo_outoflinec:@S@Base@F@foo_outofline#I#void foo_outofline(int RRR) Does something. RRR0in argument to undefined virtual.] +// CHECK: FullCommentAsXML=[foo_outoflinec:@S@Base@F@foo_outofline#I#void Base::foo_outofline(int RRR) Does something. RRR0in argument to undefined virtual.] struct Derived : public Base { virtual void foo_pure(int PPP); diff --git a/test/Misc/ast-print-out-of-line-func.cpp b/test/Misc/ast-print-out-of-line-func.cpp new file mode 100644 index 0000000000..7c4f7ae7f8 --- /dev/null +++ b/test/Misc/ast-print-out-of-line-func.cpp @@ -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 + 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 +void ::ns::Wrapper::Inner::member() { } +// CHECK: template 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() + +} -- 2.40.0