[cfe-commits] r92200 - in /cfe/trunk: lib/AST/Decl.cpp test/CodeGenCXX/predefined-expr.cpp
Sam Weinig
sam.weinig at gmail.com
Sun Dec 27 19:19:38 PST 2009
Author: weinig
Date: Sun Dec 27 21:19:38 2009
New Revision: 92200
URL: http://llvm.org/viewvc/llvm-project?rev=92200&view=rev
Log:
Fix for PR5871. Make __PRETTY_FUNCTION__ work for member functions defined in a class local to a function.
Modified:
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/test/CodeGenCXX/predefined-expr.cpp
Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=92200&r1=92199&r2=92200&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Sun Dec 27 21:19:38 2009
@@ -455,11 +455,6 @@
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 @@
} 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
Modified: cfe/trunk/test/CodeGenCXX/predefined-expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/predefined-expr.cpp?rev=92200&r1=92199&r2=92200&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/predefined-expr.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/predefined-expr.cpp Sun Dec 27 21:19:38 2009
@@ -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 @@
} 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 @@
anonymous.anonymousStruct.anonymousStructFunction();
anonymous.anonymousUnion.anonymousUnionFunction();
+ NS::localClass(0);
+
NS::externFunction();
return 0;
More information about the cfe-commits
mailing list