[cfe-commits] r95008 - /cfe/trunk/lib/CodeGen/CGDebugInfo.cpp

Devang Patel dpatel at apple.com
Mon Feb 1 13:34:11 PST 2010


Author: dpatel
Date: Mon Feb  1 15:34:11 2010
New Revision: 95008

URL: http://llvm.org/viewvc/llvm-project?rev=95008&view=rev
Log:
Use DeclContext as getContextDescriptor() argument.


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

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=95008&r1=95007&r2=95008&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Feb  1 15:34:11 2010
@@ -50,16 +50,20 @@
 }
 
 /// getContextDescriptor - Get context info for the decl.
-llvm::DIDescriptor CGDebugInfo::getContextDescriptor(const Decl *D,
+llvm::DIDescriptor CGDebugInfo::getContextDescriptor(const Decl *Context,
                                               llvm::DIDescriptor &CompileUnit) {
-  if (const Decl *Parent = dyn_cast<Decl>(D->getDeclContext())) {
-   llvm::DenseMap<const Decl *, llvm::WeakVH>::iterator
-     I = RegionMap.find(Parent);
-   if (I != RegionMap.end())
-     return llvm::DIDescriptor(dyn_cast_or_null<llvm::MDNode>(I->second));
-   if (const NamespaceDecl *NSDecl = dyn_cast<NamespaceDecl>(Parent))
-     return llvm::DIDescriptor(getOrCreateNameSpace(NSDecl, CompileUnit));
-  }
+  if (!Context)
+    return CompileUnit;
+
+  llvm::DenseMap<const Decl *, llvm::WeakVH>::iterator
+    I = RegionMap.find(Context);
+  if (I != RegionMap.end())
+    return llvm::DIDescriptor(dyn_cast_or_null<llvm::MDNode>(I->second));
+  
+  // Check namespace.
+  if (const NamespaceDecl *NSDecl = dyn_cast<NamespaceDecl>(Context))
+    return llvm::DIDescriptor(getOrCreateNameSpace(NSDecl, CompileUnit));
+  
   return CompileUnit;
 }
 
@@ -420,9 +424,12 @@
   PresumedLoc PLoc = SM.getPresumedLoc(Ty->getDecl()->getLocation());
   unsigned Line = PLoc.isInvalid() ? 0 : PLoc.getLine();
 
+  llvm::DIDescriptor TyContext 
+    = getContextDescriptor(dyn_cast<Decl>(Ty->getDecl()->getDeclContext()),
+                           Unit);
   llvm::DIType DbgTy = 
     DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_typedef, 
-                                   getContextDescriptor(Ty->getDecl(), Unit), 
+                                   TyContext,
                                    Ty->getDecl()->getName(), Unit,
                                    Line, 0, 0, 0, 0, Src);
   return DbgTy;
@@ -1747,15 +1754,15 @@
 
 /// EmitGlobalVariable - Emit information about a global variable.
 void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
-                                     const VarDecl *Decl) {
-
+                                     const VarDecl *D) {
+  
   // Create global variable debug descriptor.
-  llvm::DICompileUnit Unit = getOrCreateCompileUnit(Decl->getLocation());
+  llvm::DICompileUnit Unit = getOrCreateCompileUnit(D->getLocation());
   SourceManager &SM = CGM.getContext().getSourceManager();
-  PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation());
+  PresumedLoc PLoc = SM.getPresumedLoc(D->getLocation());
   unsigned LineNo = PLoc.isInvalid() ? 0 : PLoc.getLine();
 
-  QualType T = Decl->getType();
+  QualType T = D->getType();
   if (T->isIncompleteArrayType()) {
 
     // CodeGen turns int[] into int[1] so we'll do the same here.
@@ -1767,8 +1774,10 @@
     T = CGM.getContext().getConstantArrayType(ET, ConstVal,
                                            ArrayType::Normal, 0);
   }
-  llvm::StringRef DeclName = Decl->getName();
-  DebugFactory.CreateGlobalVariable(getContextDescriptor(Decl, Unit), DeclName,
+  llvm::StringRef DeclName = D->getName();
+  llvm::DIDescriptor DContext = 
+    getContextDescriptor(dyn_cast<Decl>(D->getDeclContext()), Unit);
+  DebugFactory.CreateGlobalVariable(DContext, DeclName,
                                     DeclName, llvm::StringRef(), Unit, LineNo,
                                     getOrCreateType(T, Unit),
                                     Var->hasInternalLinkage(),
@@ -1820,7 +1829,7 @@
   unsigned LineNo = PLoc.isInvalid() ? 0 : PLoc.getLine();
 
   llvm::DIDescriptor Context = 
-    getContextDescriptor(NSDecl, Unit);
+    getContextDescriptor(dyn_cast<Decl>(NSDecl->getDeclContext()), Unit);
   llvm::DINameSpace NS =
     DebugFactory.CreateNameSpace(Context, NSDecl->getName(), 
 	llvm::DICompileUnit(Unit.getNode()), LineNo);





More information about the cfe-commits mailing list