[llvm] r187212 - Add a way to get the context of any particular scope.

Eric Christopher echristo at gmail.com
Fri Jul 26 10:02:36 PDT 2013


Author: echristo
Date: Fri Jul 26 12:02:36 2013
New Revision: 187212

URL: http://llvm.org/viewvc/llvm-project?rev=187212&view=rev
Log:
Add a way to get the context of any particular scope.

Modified:
    llvm/trunk/include/llvm/DebugInfo.h
    llvm/trunk/lib/IR/DebugInfo.cpp

Modified: llvm/trunk/include/llvm/DebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo.h?rev=187212&r1=187211&r2=187212&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo.h (original)
+++ llvm/trunk/include/llvm/DebugInfo.h Fri Jul 26 12:02:36 2013
@@ -187,6 +187,9 @@ namespace llvm {
   public:
     explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
 
+    /// Gets the parent scope for this scope node or returns a
+    /// default constructed scope.
+    DIScope getContext() const;
     StringRef getFilename() const;
     StringRef getDirectory() const;
   };

Modified: llvm/trunk/lib/IR/DebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfo.cpp?rev=187212&r1=187211&r2=187212&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DebugInfo.cpp (original)
+++ llvm/trunk/lib/IR/DebugInfo.cpp Fri Jul 26 12:02:36 2013
@@ -692,6 +692,31 @@ Value *DITemplateValueParameter::getValu
   return getField(DbgNode, 4);
 }
 
+// If the current node has a parent scope then return that,
+// else return an empty scope.
+DIScope DIScope::getContext() const {
+
+  if (isType())
+    return DIType(DbgNode).getContext();
+
+  if (isSubprogram())
+    return DISubprogram(DbgNode).getContext();
+
+  if (isLexicalBlock())
+    return DILexicalBlock(DbgNode).getContext();
+
+  if (isLexicalBlockFile())
+    return DILexicalBlockFile(DbgNode).getContext();
+
+  if (isNameSpace())
+    return DINameSpace(DbgNode).getContext();
+
+  if (isFile() || isCompileUnit())
+    return DIScope();
+
+  return DIScope();
+}
+
 StringRef DIScope::getFilename() const {
   if (!DbgNode)
     return StringRef();





More information about the llvm-commits mailing list