diff options
| author | Douglas Gregor <dgregor@apple.com> | 2008-11-17 22:58:34 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2008-11-17 22:58:34 +0000 |
| commit | 92751d41a0a09020db5868e8aafb6aef2de3ad8e (patch) | |
| tree | 57fbc8fe4d663182ace304fb6c6a6d79a52d4393 /clang/lib/AST | |
| parent | c775712192b4069ea41031276662e1c2e6370e27 (diff) | |
| download | bcm5719-llvm-92751d41a0a09020db5868e8aafb6aef2de3ad8e.tar.gz bcm5719-llvm-92751d41a0a09020db5868e8aafb6aef2de3ad8e.zip | |
Eliminate all of the placeholder identifiers used for constructors,
destructors, and conversion functions. The placeholders were used to
work around the fact that the parser and some of Sema really wanted
declarators to have simple identifiers; now, the code that deals with
declarators will use DeclarationNames.
llvm-svn: 59469
Diffstat (limited to 'clang/lib/AST')
| -rw-r--r-- | clang/lib/AST/Decl.cpp | 52 | ||||
| -rw-r--r-- | clang/lib/AST/DeclCXX.cpp | 5 | ||||
| -rw-r--r-- | clang/lib/AST/DeclarationName.cpp | 46 |
3 files changed, 51 insertions, 52 deletions
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index dc4d6027ee8..eee934bebba 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -67,12 +67,12 @@ ParmVarDecl *ParmVarDecl::Create(ASTContext &C, DeclContext *DC, FunctionDecl *FunctionDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, - IdentifierInfo *Id, QualType T, + DeclarationName N, QualType T, StorageClass S, bool isInline, ScopedDecl *PrevDecl, SourceLocation TypeSpecStartLoc) { void *Mem = C.getAllocator().Allocate<FunctionDecl>(); - return new (Mem) FunctionDecl(Function, DC, L, Id, T, S, isInline, PrevDecl, + return new (Mem) FunctionDecl(Function, DC, L, N, T, S, isInline, PrevDecl, TypeSpecStartLoc); } @@ -130,54 +130,6 @@ FileScopeAsmDecl *FileScopeAsmDecl::Create(ASTContext &C, } //===----------------------------------------------------------------------===// -// NamedDecl Implementation -//===----------------------------------------------------------------------===// - -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 ""; -} - -//===----------------------------------------------------------------------===// // ScopedDecl Implementation //===----------------------------------------------------------------------===// diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp index 8855e99a26f..4037404124d 100644 --- a/clang/lib/AST/DeclCXX.cpp +++ b/clang/lib/AST/DeclCXX.cpp @@ -123,11 +123,12 @@ void CXXRecordDecl::addConversionFunction(ASTContext &Context, CXXMethodDecl * CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD, - SourceLocation L, IdentifierInfo *Id, + SourceLocation L, DeclarationName N, QualType T, bool isStatic, bool isInline, ScopedDecl *PrevDecl) { void *Mem = C.getAllocator().Allocate<CXXMethodDecl>(); - return new (Mem) CXXMethodDecl(CXXMethod, RD, L, Id, T, isStatic, isInline, PrevDecl); + return new (Mem) CXXMethodDecl(CXXMethod, RD, L, N, T, isStatic, isInline, + PrevDecl); } QualType CXXMethodDecl::getThisType(ASTContext &C) const { diff --git a/clang/lib/AST/DeclarationName.cpp b/clang/lib/AST/DeclarationName.cpp index 4266ef5eaf8..d58016a44cc 100644 --- a/clang/lib/AST/DeclarationName.cpp +++ b/clang/lib/AST/DeclarationName.cpp @@ -12,6 +12,8 @@ // //===----------------------------------------------------------------------===// #include "clang/AST/DeclarationName.h" +#include "clang/AST/Type.h" +#include "clang/AST/Decl.h" #include "clang/Basic/IdentifierTable.h" #include "llvm/ADT/FoldingSet.h" #include "llvm/Bitcode/Serialize.h" @@ -94,6 +96,50 @@ DeclarationName::NameKind DeclarationName::getNameKind() const { return Identifier; } +std::string DeclarationName::getAsString() const { + switch (getNameKind()) { + case Identifier: + if (const IdentifierInfo *II = getAsIdentifierInfo()) + return II->getName(); + return ""; + + case ObjCZeroArgSelector: + case ObjCOneArgSelector: + case ObjCMultiArgSelector: + return getObjCSelector().getName(); + + case CXXConstructorName: { + QualType ClassType = getCXXNameType(); + if (const RecordType *ClassRec = ClassType->getAsRecordType()) + return ClassRec->getDecl()->getName(); + return ClassType.getAsString(); + } + + case CXXDestructorName: { + std::string Result = "~"; + QualType Type = getCXXNameType(); + if (const RecordType *Rec = Type->getAsRecordType()) + Result += Rec->getDecl()->getName(); + else + Result += Type.getAsString(); + return Result; + } + + case CXXConversionFunctionName: { + std::string Result = "operator "; + QualType Type = getCXXNameType(); + if (const RecordType *Rec = Type->getAsRecordType()) + Result += Rec->getDecl()->getName(); + else + Result += Type.getAsString(); + return Result; + } + } + + assert(false && "Unexpected declaration name kind"); + return ""; +} + QualType DeclarationName::getCXXNameType() const { if (CXXSpecialName *CXXName = getAsCXXSpecialName()) return CXXName->Type; |

