[cfe-commits] r148904 - in /cfe/trunk/lib/CodeGen: CGDebugInfo.cpp CGDebugInfo.h

Eric Christopher echristo at apple.com
Tue Jan 24 18:06:59 PST 2012


Author: echristo
Date: Tue Jan 24 20:06:59 2012
New Revision: 148904

URL: http://llvm.org/viewvc/llvm-project?rev=148904&view=rev
Log:
Refactor the record decl forward declaration code a bit.

Modified:
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
    cfe/trunk/lib/CodeGen/CGDebugInfo.h

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=148904&r1=148903&r2=148904&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue Jan 24 20:06:59 2012
@@ -479,6 +479,31 @@
                                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<CXXRecordDecl>(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 @@
 
   if (const RecordDecl *RD = dyn_cast<RecordDecl>(Context)) {
     if (!RD->isDependentType()) {
-      llvm::DIFile DefUnit = getOrCreateFile(RD->getLocation());
-      unsigned Line = getLineNumber(RD->getLocation());
       llvm::DIDescriptor FDContext =
         createContextChain(cast<Decl>(RD->getDeclContext()));
-      
-      const CXXRecordDecl *CXXDecl = dyn_cast<CXXRecordDecl>(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 @@
 
   if (const RecordType *RTy = dyn_cast<RecordType>(PointeeTy)) {
     RecordDecl *RD = RTy->getDecl();
-    llvm::DIFile DefUnit = getOrCreateFile(RD->getLocation());
-    unsigned Line = getLineNumber(RD->getLocation());
     llvm::DIDescriptor FDContext =
       getContextDescriptor(cast<Decl>(RD->getDeclContext()));
-
-    CXXRecordDecl *CXXDecl = dyn_cast<CXXRecordDecl>(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);
 

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=148904&r1=148903&r2=148904&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Tue Jan 24 20:06:59 2012
@@ -232,6 +232,10 @@
   /// 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);
 





More information about the cfe-commits mailing list