From: Eric Christopher Date: Wed, 25 Jan 2012 02:06:59 +0000 (+0000) Subject: Refactor the record decl forward declaration code a bit. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5d613b57972a761973861f7c38b3e6442243a6ab;p=clang Refactor the record decl forward declaration code a bit. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148904 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 332fa8e1b8..65b88f5e5b 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -479,6 +479,31 @@ llvm::DIType CGDebugInfo::CreateType(const PointerType *Ty, Ty->getPointeeType(), Unit); } +// Creates a forward declaration for a RecordDecl in the given context. +llvm::DIType CGDebugInfo::createRecordFwdDecl(const RecordDecl *RD, + llvm::DIDescriptor Ctx) { + + llvm::DIFile DefUnit = getOrCreateFile(RD->getLocation()); + unsigned Line = getLineNumber(RD->getLocation()); + const CXXRecordDecl *CXXDecl = dyn_cast(RD); + + if (CXXDecl) + return DBuilder.createClassType(Ctx, RD->getName(), DefUnit, + Line, 0, 0, 0, + llvm::DIType::FlagFwdDecl, + llvm::DIType(), llvm::DIArray()); + else if (RD->isStruct()) + return DBuilder.createStructType(Ctx, RD->getName(), DefUnit, + Line, 0, 0, llvm::DIType::FlagFwdDecl, + llvm::DIArray()); + else if (RD->isUnion()) + return DBuilder.createUnionType(Ctx, RD->getName(), DefUnit, + Line, 0, 0, llvm::DIType::FlagFwdDecl, + llvm::DIArray()); + else + llvm_unreachable("Unknown RecordDecl type!"); +} + // Walk up the context chain and create forward decls for record decls, // and normal descriptors for namespaces. llvm::DIDescriptor CGDebugInfo::createContextChain(const Decl *Context) { @@ -497,27 +522,9 @@ llvm::DIDescriptor CGDebugInfo::createContextChain(const Decl *Context) { if (const RecordDecl *RD = dyn_cast(Context)) { if (!RD->isDependentType()) { - llvm::DIFile DefUnit = getOrCreateFile(RD->getLocation()); - unsigned Line = getLineNumber(RD->getLocation()); llvm::DIDescriptor FDContext = createContextChain(cast(RD->getDeclContext())); - - const CXXRecordDecl *CXXDecl = dyn_cast(RD); - llvm::DIType Ty = llvm::DIType(); - - if (CXXDecl) - Ty = DBuilder.createClassType(FDContext, RD->getName(), DefUnit, - Line, 0, 0, 0, - llvm::DIType::FlagFwdDecl, - llvm::DIType(), llvm::DIArray()); - else if (RD->isStruct()) - Ty = DBuilder.createStructType(FDContext, RD->getName(), DefUnit, - Line, 0, 0, llvm::DIType::FlagFwdDecl, - llvm::DIArray()); - else if (RD->isUnion()) - Ty = DBuilder.createUnionType(FDContext, RD->getName(), DefUnit, - Line, 0, 0, llvm::DIType::FlagFwdDecl, - llvm::DIArray()); + llvm::DIType Ty = createRecordFwdDecl(RD, FDContext); RegionMap[Context] = llvm::WeakVH(Ty); return llvm::DIDescriptor(Ty); @@ -546,26 +553,9 @@ llvm::DIType CGDebugInfo::CreatePointeeType(QualType PointeeTy, if (const RecordType *RTy = dyn_cast(PointeeTy)) { RecordDecl *RD = RTy->getDecl(); - llvm::DIFile DefUnit = getOrCreateFile(RD->getLocation()); - unsigned Line = getLineNumber(RD->getLocation()); llvm::DIDescriptor FDContext = getContextDescriptor(cast(RD->getDeclContext())); - - CXXRecordDecl *CXXDecl = dyn_cast(RD); - if (CXXDecl) - return DBuilder.createClassType(FDContext, RD->getName(), DefUnit, - Line, 0, 0, 0, llvm::DIType::FlagFwdDecl, - llvm::DIType(), llvm::DIArray()); - else if (RD->isStruct()) - return DBuilder.createStructType(FDContext, RD->getName(), DefUnit, - Line, 0, 0, llvm::DIType::FlagFwdDecl, - llvm::DIArray()); - else if (RD->isUnion()) - return DBuilder.createUnionType(FDContext, RD->getName(), DefUnit, - Line, 0, 0, llvm::DIType::FlagFwdDecl, - llvm::DIArray()); - else - llvm_unreachable("Unknown RecordDecl type!"); + return createRecordFwdDecl(RD, FDContext); } return getOrCreateType(PointeeTy, Unit); diff --git a/lib/CodeGen/CGDebugInfo.h b/lib/CodeGen/CGDebugInfo.h index 8e1dd2b6f8..6c56efc35f 100644 --- a/lib/CodeGen/CGDebugInfo.h +++ b/lib/CodeGen/CGDebugInfo.h @@ -232,6 +232,10 @@ private: /// getContextDescriptor - Get context info for the decl. llvm::DIDescriptor getContextDescriptor(const Decl *Decl); + /// createRecordFwdDecl - Create a forward decl for a RecordType in a given + /// context. + llvm::DIType createRecordFwdDecl(const RecordDecl *, llvm::DIDescriptor); + /// createContextChain - Create a set of decls for the context chain. llvm::DIDescriptor createContextChain(const Decl *Decl);