]> granicus.if.org Git - clang/commitdiff
Emit debug info for namespaces.
authorDevang Patel <dpatel@apple.com>
Mon, 1 Feb 2010 19:16:32 +0000 (19:16 +0000)
committerDevang Patel <dpatel@apple.com>
Mon, 1 Feb 2010 19:16:32 +0000 (19:16 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94991 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDebugInfo.cpp
lib/CodeGen/CGDebugInfo.h

index b0f2c0fa4298eabc5bd7ddbefd08359f1a980fc9..36b3a8390f41b11e966e4b89129726344375153f 100644 (file)
@@ -57,6 +57,8 @@ llvm::DIDescriptor CGDebugInfo::getContextDescriptor(const Decl *D,
      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));
   }
   return CompileUnit;
 }
@@ -1802,3 +1804,26 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
                                     Var->hasInternalLinkage(),
                                     true/*definition*/, Var);
 }
+
+/// getOrCreateNamesSpace - Return namespace descriptor for the given
+/// namespace decl.
+llvm::DINameSpace 
+CGDebugInfo::getOrCreateNameSpace(const NamespaceDecl *NSDecl, 
+                                  llvm::DIDescriptor Unit) {
+  llvm::DenseMap<const NamespaceDecl *, llvm::WeakVH>::iterator I = 
+    NameSpaceCache.find(NSDecl);
+  if (I != NameSpaceCache.end())
+    return llvm::DINameSpace(cast<llvm::MDNode>(I->second));
+  
+  SourceManager &SM = CGM.getContext().getSourceManager();
+  PresumedLoc PLoc = SM.getPresumedLoc(NSDecl->getLocation());
+  unsigned LineNo = PLoc.isInvalid() ? 0 : PLoc.getLine();
+
+  llvm::DIDescriptor Context = 
+    getContextDescriptor(NSDecl, Unit);
+  llvm::DINameSpace NS =
+    DebugFactory.CreateNameSpace(Context, NSDecl->getName(), 
+       llvm::DICompileUnit(Unit.getNode()), LineNo);
+  NameSpaceCache[NSDecl] = llvm::WeakVH(NS.getNode());
+  return NS;
+}
index 9a56a9ab5cd1cdfe4455956f9d4c3cbac6bfc5e9..c2bcc4bd122771006a6201d120d6b1fce376830c 100644 (file)
@@ -68,6 +68,7 @@ class CGDebugInfo {
   llvm::BumpPtrAllocator DebugInfoNames;
 
   llvm::DenseMap<const FunctionDecl *, llvm::WeakVH> SPCache;
+  llvm::DenseMap<const NamespaceDecl *, llvm::WeakVH> NameSpaceCache;
 
   /// Helper functions for getOrCreateType.
   llvm::DIType CreateType(const BuiltinType *Ty, llvm::DICompileUnit U);
@@ -89,7 +90,9 @@ class CGDebugInfo {
   llvm::DIType getOrCreateMethodType(const CXXMethodDecl *Method,
                                      llvm::DICompileUnit Unit);
   llvm::DIType getOrCreateVTablePtrType(llvm::DICompileUnit Unit);
-  
+  llvm::DINameSpace getOrCreateNameSpace(const NamespaceDecl *N, 
+                                         llvm::DIDescriptor Unit);
+
   llvm::DIType CreatePointerLikeType(unsigned Tag,
                                      const Type *Ty, QualType PointeeTy,
                                      llvm::DICompileUnit U);