Fix for PR5871. Make __PRETTY_FUNCTION__ work for member functions defined in a class local to a function.

llvm-svn: 92200
This commit is contained in:
Sam Weinig 2009-12-28 03:19:38 +00:00
parent 0b00a1b54e
commit b999f68ed9
2 changed files with 46 additions and 5 deletions

View File

@ -455,11 +455,6 @@ std::string NamedDecl::getQualifiedNameAsString(const PrintingPolicy &P) const {
return getNameAsString();
while (Ctx) {
if (Ctx->isFunctionOrMethod())
// FIXME: That probably will happen, when D was member of local
// scope class/struct/union. How do we handle this case?
break;
if (const ClassTemplateSpecializationDecl *Spec
= dyn_cast<ClassTemplateSpecializationDecl>(Ctx)) {
const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
@ -483,6 +478,34 @@ std::string NamedDecl::getQualifiedNameAsString(const PrintingPolicy &P) const {
} else {
Names.push_back(RD->getNameAsString());
}
} else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(Ctx)) {
std::string Proto = FD->getNameAsString();
const FunctionProtoType *FT = 0;
if (FD->hasWrittenPrototype())
FT = dyn_cast<FunctionProtoType>(FD->getType()->getAs<FunctionType>());
Proto += "(";
if (FT) {
llvm::raw_string_ostream POut(Proto);
unsigned NumParams = FD->getNumParams();
for (unsigned i = 0; i < NumParams; ++i) {
if (i)
POut << ", ";
std::string Param;
FD->getParamDecl(i)->getType().getAsStringInternal(Param, P);
POut << Param;
}
if (FT->isVariadic()) {
if (NumParams > 0)
POut << ", ";
POut << "...";
}
}
Proto += ")";
Names.push_back(Proto);
} else if (const NamedDecl *ND = dyn_cast<NamedDecl>(Ctx))
Names.push_back(ND->getNameAsString());
else

View File

@ -75,6 +75,9 @@
// CHECK: private constant [27 x i8] c"anonymousNamespaceFunction\00"
// CHECK: private constant [84 x i8] c"void <anonymous namespace>::ClassInAnonymousNamespace::anonymousNamespaceFunction()\00"
// CHECK: private constant [19 x i8] c"localClassFunction\00"
// CHECK: private constant [59 x i8] c"void NS::localClass(int)::LocalClass::localClassFunction()\00"
int printf(const char * _Format, ...);
class ClassInTopLevelNamespace {
@ -270,6 +273,19 @@ public:
} anonymousUnion;
};
void localClass(int) {
class LocalClass {
public:
void localClassFunction() {
printf("__func__ %s\n", __func__);
printf("__FUNCTION__ %s\n", __FUNCTION__);
printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__);
}
};
LocalClass lc;
lc.localClassFunction();
}
extern void externFunction() {
printf("__func__ %s\n", __func__);
printf("__FUNCTION__ %s\n", __FUNCTION__);
@ -325,6 +341,8 @@ int main() {
anonymous.anonymousStruct.anonymousStructFunction();
anonymous.anonymousUnion.anonymousUnionFunction();
NS::localClass(0);
NS::externFunction();
return 0;