Introduction the DeclarationName class, as a single, general method of
representing the names of declarations in the C family of
languages. DeclarationName is used in NamedDecl to store the name of
the declaration (naturally), and ObjCMethodDecl is now a NamedDecl.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59441 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index fa5e9ce..dc4d602 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -133,9 +133,47 @@
 // NamedDecl Implementation
 //===----------------------------------------------------------------------===//
 
-const char *NamedDecl::getName() const {
-  if (const IdentifierInfo *II = getIdentifier())
-    return II->getName();
+std::string NamedDecl::getName() const {
+  switch (Name.getNameKind()) {
+  case DeclarationName::Identifier:
+    if (const IdentifierInfo *II = Name.getAsIdentifierInfo())
+      return II->getName();
+    return "";
+
+  case DeclarationName::ObjCZeroArgSelector:
+  case DeclarationName::ObjCOneArgSelector:
+  case DeclarationName::ObjCMultiArgSelector:
+    return Name.getObjCSelector().getName();
+
+  case DeclarationName::CXXConstructorName: {
+    QualType ClassType = Name.getCXXNameType();
+    if (const RecordType *ClassRec = ClassType->getAsRecordType())
+      return ClassRec->getDecl()->getName();
+    return ClassType.getAsString();
+  }
+
+  case DeclarationName::CXXDestructorName: {
+    std::string Result = "~";
+    QualType Type = Name.getCXXNameType();
+    if (const RecordType *Rec = Type->getAsRecordType())
+      Result += Rec->getDecl()->getName();
+    else
+      Result += Type.getAsString();
+    return Result;
+  }
+
+  case DeclarationName::CXXConversionFunctionName: {
+    std::string Result = "operator ";
+    QualType Type = Name.getCXXNameType();
+    if (const RecordType *Rec = Type->getAsRecordType())
+      Result += Rec->getDecl()->getName();
+    else
+      Result += Type.getAsString();
+    return Result;
+  }
+  }
+
+  assert(false && "Unexpected declaration name kind");
   return "";
 }