]> granicus.if.org Git - clang/commitdiff
Fix for PR5871. Make __PRETTY_FUNCTION__ work for member functions defined in a class...
authorSam Weinig <sam.weinig@gmail.com>
Mon, 28 Dec 2009 03:19:38 +0000 (03:19 +0000)
committerSam Weinig <sam.weinig@gmail.com>
Mon, 28 Dec 2009 03:19:38 +0000 (03:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92200 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Decl.cpp
test/CodeGenCXX/predefined-expr.cpp

index 220b0fb1c7bdb5672345bb75fbbe2b515bdbde33..02a26d49f04f4097c0a195ec8c13f84f75fa9bac 100644 (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
index e726adb16337e08cb5d719205cb752c5376c6670..f5e5ca95282d493752da6e8a0ca7cfe0a0d55fcb 100644 (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;