summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/Decl.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2008-11-17 14:58:09 +0000
committerDouglas Gregor <dgregor@apple.com>2008-11-17 14:58:09 +0000
commit77324f385482d592ef54b286ffbb00f47b9259ac (patch)
tree7c60f2f71c6e87fbc3242d87e24cf4b23cd9d435 /clang/lib/AST/Decl.cpp
parentd1f5e5d30458080f3591251d29bd6758f667a448 (diff)
downloadbcm5719-llvm-77324f385482d592ef54b286ffbb00f47b9259ac.tar.gz
bcm5719-llvm-77324f385482d592ef54b286ffbb00f47b9259ac.zip
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. llvm-svn: 59441
Diffstat (limited to 'clang/lib/AST/Decl.cpp')
-rw-r--r--clang/lib/AST/Decl.cpp44
1 files changed, 41 insertions, 3 deletions
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index fa5e9ce36eb..dc4d6027ee8 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -133,9 +133,47 @@ FileScopeAsmDecl *FileScopeAsmDecl::Create(ASTContext &C,
// 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 "";
}
OpenPOWER on IntegriCloud