[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
This commit is contained in:
Alex Lorenz 2017-04-11 16:46:03 +00:00
parent 9f266a5e16
commit 506a43a28e
5 changed files with 70 additions and 7 deletions

View File

@ -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()) {

View File

@ -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;

View File

@ -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&lt;T&gt;::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 &amp;t = T())</Declaration>
// CHECK: <Declaration>friend void f(const test3::A &amp;)</Declaration>
// CHECK: <Declaration>friend void vector&lt;A&gt;::f(const test3::A &amp;)</Declaration>
class MyClass
{

View File

@ -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);

View File

@ -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()
}