[cfe-commits] r93634 - in /cfe/trunk: test/Index/c-index-api-loadTU-test.m tools/CIndex/CIndex.cpp tools/CIndex/CXCursor.cpp tools/CIndex/CXCursor.h

Douglas Gregor dgregor at apple.com
Sat Jan 16 06:00:32 PST 2010


Author: dgregor
Date: Sat Jan 16 08:00:32 2010
New Revision: 93634

URL: http://llvm.org/viewvc/llvm-project?rev=93634&view=rev
Log:
Give CXCursor_ObjCSuperClassRef a sane encoding, which is only known
to CXCursor.cpp.

Modified:
    cfe/trunk/test/Index/c-index-api-loadTU-test.m
    cfe/trunk/tools/CIndex/CIndex.cpp
    cfe/trunk/tools/CIndex/CXCursor.cpp
    cfe/trunk/tools/CIndex/CXCursor.h

Modified: cfe/trunk/test/Index/c-index-api-loadTU-test.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/c-index-api-loadTU-test.m?rev=93634&r1=93633&r2=93634&view=diff

==============================================================================
--- cfe/trunk/test/Index/c-index-api-loadTU-test.m (original)
+++ cfe/trunk/test/Index/c-index-api-loadTU-test.m Sat Jan 16 08:00:32 2010
@@ -57,7 +57,7 @@
 // CHECK: c-index-api-loadTU-test.m:8:1: ObjCInstanceMethodDecl=foo:8:1 [Context=Foo] [Extent=8:1:8:6]
 // CHECK: c-index-api-loadTU-test.m:9:1: ObjCClassMethodDecl=fooC:9:1 [Context=Foo] [Extent=9:1:9:7]
 // CHECK: c-index-api-loadTU-test.m:13:12: ObjCInterfaceDecl=Bar:13:1 [Context=c-index-api-loadTU-test.m] [Extent=13:1:17:4]
-// CHECK: c-index-api-loadTU-test.m:13:18: ObjCSuperClassRef=Foo:13:1 [Context=Bar] [Extent=13:1:17:4]
+// CHECK: c-index-api-loadTU-test.m:13:18: ObjCSuperClassRef=Foo:4:1 [Context=Bar] [Extent=4:1:11:4]
 // CHECK: c-index-api-loadTU-test.m:19:1: ObjCCategoryDecl=FooCat:19:1 [Context=c-index-api-loadTU-test.m] [Extent=19:1:22:4]
 // CHECK: c-index-api-loadTU-test.m:4:1: ObjCClassRef=Foo:19:1 [Context=FooCat] [Extent=19:1:22:4]
 // CHECK: c-index-api-loadTU-test.m:20:1: ObjCInstanceMethodDecl=catMethodWithFloat::20:1 [Context=FooCat] [Extent=20:1:20:40]
@@ -68,7 +68,7 @@
 // CHECK: c-index-api-loadTU-test.m:24:1: ObjCProtocolRef=Proto:24:1 [Context=SubP] [Extent=24:1:26:4]
 // CHECK: c-index-api-loadTU-test.m:29:1: ObjCInstanceMethodDecl=spMethod:29:1 [Context=SubP] [Extent=29:1:29:11]
 // CHECK: c-index-api-loadTU-test.m:32:12: ObjCInterfaceDecl=Baz:32:1 [Context=c-index-api-loadTU-test.m] [Extent=32:1:39:4]
-// CHECK: c-index-api-loadTU-test.m:32:18: ObjCSuperClassRef=Bar:32:1 [Context=Baz] [Extent=32:1:39:4]
+// CHECK: c-index-api-loadTU-test.m:32:18: ObjCSuperClassRef=Bar:13:1 [Context=Baz] [Extent=13:1:17:4]
 // CHECK: c-index-api-loadTU-test.m:28:1: ObjCProtocolRef=SubP:28:1 [Context=Baz] [Extent=28:1:30:4]
 // CHECK: c-index-api-loadTU-test.m:34:9: ObjCIvarDecl=_anIVar:34:9 [Context=Baz] [Extent=34:9:34:15]
 // CHECK: c-index-api-loadTU-test.m:37:1: ObjCInstanceMethodDecl=bazMethod:37:1 [Context=Baz] [Extent=37:1:37:20]

Modified: cfe/trunk/tools/CIndex/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.cpp?rev=93634&r1=93633&r2=93634&view=diff

==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndex.cpp Sat Jan 16 08:00:32 2010
@@ -209,6 +209,7 @@
     CXCursor C = { CK, { ND, 0, 0 } };
     Callback(CDecl, C, CData);
   }
+
 public:
   CDeclVisitor(CXDecl C, CXDeclIterator cback, CXClientData D,
                unsigned MaxPCHLevel) :
@@ -276,7 +277,10 @@
 void CDeclVisitor::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
   // Issue callbacks for super class.
   if (D->getSuperClass())
-    Call(CXCursor_ObjCSuperClassRef, D);
+    Callback(CDecl, 
+             MakeCursorObjCSuperClassRef(D->getSuperClass(),
+                                         D->getSuperClassLoc()), 
+             CData);
   
   for (ObjCProtocolDecl::protocol_iterator I = D->protocol_begin(),
        E = D->protocol_end(); I != E; ++I)
@@ -340,11 +344,9 @@
       assert(OID && "clang_getCursorLine(): Missing category decl");
       return OID->getClassInterface()->getLocation();
     }
-    case CXCursor_ObjCSuperClassRef: {
-      ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(ND);
-      assert(OID && "clang_getCursorLine(): Missing interface decl");
-      return OID->getSuperClassLoc();
-    }
+    case CXCursor_ObjCSuperClassRef:
+      return getCursorObjCSuperClassRef(C).second;
+
     case CXCursor_ObjCProtocolRef: {
       ObjCProtocolDecl *OID = dyn_cast<ObjCProtocolDecl>(ND);
       assert(OID && "clang_getCursorLine(): Missing protocol decl");
@@ -761,10 +763,8 @@
   if (clang_isReference(C.kind)) {
     switch (C.kind) {
     case CXCursor_ObjCSuperClassRef: {
-      ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(ND);
-      assert(OID && "clang_getCursorLine(): Missing interface decl");
-      return CIndexer::createCXString(OID->getSuperClass()->getIdentifier()
-                                      ->getNameStart());
+      ObjCInterfaceDecl *Super = getCursorObjCSuperClassRef(C).first;
+      return CIndexer::createCXString(Super->getIdentifier()->getNameStart());
     }
     case CXCursor_ObjCClassRef: {
       if (ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(ND))

Modified: cfe/trunk/tools/CIndex/CXCursor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CXCursor.cpp?rev=93634&r1=93633&r2=93634&view=diff

==============================================================================
--- cfe/trunk/tools/CIndex/CXCursor.cpp (original)
+++ cfe/trunk/tools/CIndex/CXCursor.cpp Sat Jan 16 08:00:32 2010
@@ -7,7 +7,9 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// This file defines routines for manipulating CXCursors.
+// This file defines routines for manipulating CXCursors. It should be the
+// only file that has internal knowledge of the encoding of the data in
+// CXCursor.
 //
 //===----------------------------------------------------------------------===//
 
@@ -73,6 +75,21 @@
   return MakeCXCursor(GetCursorKind(D), D);
 }
 
+CXCursor cxcursor::MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super, 
+                                         SourceLocation Loc) {
+  void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
+  CXCursor C = { CXCursor_ObjCSuperClassRef, { Super, RawLoc, 0 } };
+  return C;    
+}
+
+std::pair<ObjCInterfaceDecl *, SourceLocation> 
+cxcursor::getCursorObjCSuperClassRef(CXCursor C) {
+  assert(C.kind == CXCursor_ObjCSuperClassRef);
+  return std::make_pair(static_cast<ObjCInterfaceDecl *>(C.data[0]),
+           SourceLocation::getFromRawEncoding(
+                                      reinterpret_cast<uintptr_t>(C.data[1])));
+}
+
 Decl *cxcursor::getCursorDecl(CXCursor Cursor) {
   return (Decl *)Cursor.data[0];
 }
@@ -82,6 +99,9 @@
 }
 
 Stmt *cxcursor::getCursorStmt(CXCursor Cursor) {
+  if (Cursor.kind == CXCursor_ObjCSuperClassRef)
+    return 0;
+
   return (Stmt *)Cursor.data[1];
 }
 
@@ -99,4 +119,4 @@
 bool cxcursor::operator==(CXCursor X, CXCursor Y) {
   return X.kind == Y.kind && X.data[0] == Y.data[0] && X.data[1] == Y.data[1] &&
          X.data[2] == Y.data[2];
-}
\ No newline at end of file
+}

Modified: cfe/trunk/tools/CIndex/CXCursor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CXCursor.h?rev=93634&r1=93633&r2=93634&view=diff

==============================================================================
--- cfe/trunk/tools/CIndex/CXCursor.h (original)
+++ cfe/trunk/tools/CIndex/CXCursor.h Sat Jan 16 08:00:32 2010
@@ -15,12 +15,15 @@
 #define LLVM_CLANG_CXCursor_H
 
 #include "clang-c/Index.h"
+#include "clang/Basic/SourceLocation.h"
+#include <utility>
 
 namespace clang {
 
 class Decl;
 class Expr;
 class NamedDecl;
+class ObjCInterfaceDecl;
 class Stmt;
 
 namespace cxcursor {
@@ -29,6 +32,15 @@
 CXCursor MakeCXCursor(CXCursorKind K, clang::Decl *D, clang::Stmt *S);
 CXCursor MakeCXCursor(clang::Decl *D);
 
+/// \brief Create an Objective-C superclass reference at the given location.
+CXCursor MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super, 
+                                     SourceLocation Loc);
+
+/// \brief Unpack an ObjCSuperClassRef cursor into the interface it references
+/// and optionally the location where the reference occurred.
+std::pair<ObjCInterfaceDecl *, SourceLocation> 
+getCursorObjCSuperClassRef(CXCursor C);
+
 Decl *getCursorDecl(CXCursor Cursor);
 Expr *getCursorExpr(CXCursor Cursor);
 Stmt *getCursorStmt(CXCursor Cursor);





More information about the cfe-commits mailing list