From 83a586ec19dd0db7fe4bc3b8e881173ae07f74f4 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Sun, 13 Apr 2008 21:07:44 +0000 Subject: Introduce support for finding class and enum names via ordinary name lookup in C++ llvm-svn: 49621 --- clang/lib/AST/ASTContext.cpp | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'clang/lib/AST/ASTContext.cpp') diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 5af59aadd37..e4b48e21e44 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -788,6 +788,28 @@ QualType ASTContext::getFunctionType(QualType ResultTy, QualType *ArgArray, return QualType(FTP, 0); } +/// getTypeDeclType - Return the unique reference to the type for the +/// specified type declaration. +QualType ASTContext::getTypeDeclType(TypeDecl *Decl) { + if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); + + if (TypedefDecl *Typedef = dyn_cast_or_null(Decl)) + return getTypedefType(Typedef); + else if (ObjCInterfaceDecl *ObjCInterface + = dyn_cast_or_null(Decl)) + return getObjCInterfaceType(ObjCInterface); + else if (RecordDecl *Record = dyn_cast_or_null(Decl)) { + Decl->TypeForDecl = new RecordType(Record); + Types.push_back(Decl->TypeForDecl); + return QualType(Decl->TypeForDecl, 0); + } else if (EnumDecl *Enum = dyn_cast_or_null(Decl)) { + Decl->TypeForDecl = new EnumType(Enum); + Types.push_back(Decl->TypeForDecl); + return QualType(Decl->TypeForDecl, 0); + } else + assert(false && "TypeDecl without a type?"); +} + /// getTypedefType - Return the unique reference to the type for the /// specified typename decl. QualType ASTContext::getTypedefType(TypedefDecl *Decl) { @@ -913,15 +935,7 @@ QualType ASTContext::getTypeOfType(QualType tofType) { /// specified TagDecl (struct/union/class/enum) decl. QualType ASTContext::getTagDeclType(TagDecl *Decl) { assert (Decl); - - // The decl stores the type cache. - if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); - - TagType* T = new TagType(Decl, QualType()); - Types.push_back(T); - Decl->TypeForDecl = T; - - return QualType(T, 0); + return getTypeDeclType(Decl); } /// getSizeType - Return the unique type for "size_t" (C99 7.17), the result -- cgit v1.2.3