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

Douglas Gregor dgregor at apple.com
Sat Jan 16 07:44:21 PST 2010


Author: dgregor
Date: Sat Jan 16 09:44:18 2010
New Revision: 93637

URL: http://llvm.org/viewvc/llvm-project?rev=93637&view=rev
Log:
Use a sane encoding for CXCursor_ObjCProtocolRef, using the actual
source locations where the protocols were referenced rather than the
location of some random enclosing declaration.

Modified:
    cfe/trunk/test/Index/c-index-api-fn-scan.m
    cfe/trunk/test/Index/c-index-api-loadTU-test.m
    cfe/trunk/test/Index/c-index-getCursor-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-fn-scan.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/c-index-api-fn-scan.m?rev=93637&r1=93636&r2=93637&view=diff

==============================================================================
--- cfe/trunk/test/Index/c-index-api-fn-scan.m (original)
+++ cfe/trunk/test/Index/c-index-api-fn-scan.m Sat Jan 16 09:44:18 2010
@@ -116,10 +116,10 @@
 // CHECK: <invalid loc>:86:2: TypedefDecl=id:0:0 [Context:id]
 // CHECK: <invalid loc>:86:3: TypedefDecl=id:0:0 [Context:id]
 // CHECK: c-index-api-fn-scan.m:86:5: VarDecl=c:86:12 [Context:c]
-// CHECK: c-index-api-fn-scan.m:86:6: ObjCProtocolRef=SubP:86:12 [Context:SubP]
-// CHECK: c-index-api-fn-scan.m:86:7: ObjCProtocolRef=SubP:86:12 [Context:SubP]
-// CHECK: c-index-api-fn-scan.m:86:8: ObjCProtocolRef=SubP:86:12 [Context:SubP]
-// CHECK: c-index-api-fn-scan.m:86:9: ObjCProtocolRef=SubP:86:12 [Context:SubP]
+// CHECK: c-index-api-fn-scan.m:86:6: ObjCProtocolRef=SubP:44:1 [Context:SubP]
+// CHECK: c-index-api-fn-scan.m:86:7: ObjCProtocolRef=SubP:44:1 [Context:SubP]
+// CHECK: c-index-api-fn-scan.m:86:8: ObjCProtocolRef=SubP:44:1 [Context:SubP]
+// CHECK: c-index-api-fn-scan.m:86:9: ObjCProtocolRef=SubP:44:1 [Context:SubP]
 // CHECK: c-index-api-fn-scan.m:86:10: VarDecl=c:86:12 [Context:c]
 // CHECK: c-index-api-fn-scan.m:86:12: VarDecl=c:86:12 [Context:c]
 // CHECK: c-index-api-fn-scan.m:86:13: VarDecl=c:86:12 [Context:c]
@@ -138,11 +138,11 @@
 // CHECK: <invalid loc>:87:2: TypedefDecl=id:0:0 [Context:id]
 // CHECK: <invalid loc>:87:3: TypedefDecl=id:0:0 [Context:id]
 // CHECK: c-index-api-fn-scan.m:87:5: VarDecl=d:87:13 [Context:d]
-// CHECK: c-index-api-fn-scan.m:87:6: ObjCProtocolRef=Proto:87:13 [Context:Proto]
-// CHECK: c-index-api-fn-scan.m:87:7: ObjCProtocolRef=Proto:87:13 [Context:Proto]
-// CHECK: c-index-api-fn-scan.m:87:8: ObjCProtocolRef=Proto:87:13 [Context:Proto]
-// CHECK: c-index-api-fn-scan.m:87:9: ObjCProtocolRef=Proto:87:13 [Context:Proto]
-// CHECK: c-index-api-fn-scan.m:87:10: ObjCProtocolRef=Proto:87:13 [Context:Proto]
+// CHECK: c-index-api-fn-scan.m:87:6: ObjCProtocolRef=Proto:40:1 [Context:Proto]
+// CHECK: c-index-api-fn-scan.m:87:7: ObjCProtocolRef=Proto:40:1 [Context:Proto]
+// CHECK: c-index-api-fn-scan.m:87:8: ObjCProtocolRef=Proto:40:1 [Context:Proto]
+// CHECK: c-index-api-fn-scan.m:87:9: ObjCProtocolRef=Proto:40:1 [Context:Proto]
+// CHECK: c-index-api-fn-scan.m:87:10: ObjCProtocolRef=Proto:40:1 [Context:Proto]
 // CHECK: c-index-api-fn-scan.m:87:11: VarDecl=d:87:13 [Context:d]
 // CHECK: c-index-api-fn-scan.m:87:13: VarDecl=d:87:13 [Context:d]
 // CHECK: c-index-api-fn-scan.m:88:2: VarRef=d:87:13 [Context:main]

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=93637&r1=93636&r2=93637&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 09:44:18 2010
@@ -65,11 +65,11 @@
 // CHECK: c-index-api-loadTU-test.m:24:1: ObjCProtocolDecl=Proto:24:1 [Context=c-index-api-loadTU-test.m] [Extent=24:1:26:4]
 // CHECK: c-index-api-loadTU-test.m:25:1: ObjCInstanceMethodDecl=pMethod:25:1 [Context=Proto] [Extent=25:1:25:10]
 // CHECK: c-index-api-loadTU-test.m:28:1: ObjCProtocolDecl=SubP:28:1 [Context=c-index-api-loadTU-test.m] [Extent=28:1:30:4]
-// 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:28:17: 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: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:32:23: 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]
 // CHECK: c-index-api-loadTU-test.m:41:1: EnumDecl=:41:1 [Context=c-index-api-loadTU-test.m] [Extent=41:1:43:1]

Modified: cfe/trunk/test/Index/c-index-getCursor-test.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/c-index-getCursor-test.m?rev=93637&r1=93636&r2=93637&view=diff

==============================================================================
--- cfe/trunk/test/Index/c-index-getCursor-test.m (original)
+++ cfe/trunk/test/Index/c-index-getCursor-test.m Sat Jan 16 09:44:18 2010
@@ -120,7 +120,7 @@
 // CHECK: {start_line=47 start_col=2 end_line=47 end_col=3} TypedefDecl=id:0:0
 // CHECK: {start_line=47 start_col=4 end_line=47 end_col=4} FunctionDefn=main:44:5
 // CHECK: {start_line=47 start_col=5 end_line=47 end_col=5} VarDecl=c:47:12
-// CHECK: {start_line=47 start_col=6 end_line=47 end_col=9} ObjCProtocolRef=SubP:47:12
+// CHECK: {start_line=47 start_col=6 end_line=47 end_col=9} ObjCProtocolRef=SubP:27:1
 // CHECK: {start_line=47 start_col=10 end_line=47 end_col=10} VarDecl=c:47:12
 // CHECK: {start_line=47 start_col=11 end_line=47 end_col=11} FunctionDefn=main:44:5
 // CHECK: {start_line=47 start_col=12 end_line=47 end_col=15} VarDecl=c:47:12
@@ -129,7 +129,7 @@
 // CHECK: {start_line=48 start_col=2 end_line=48 end_col=3} TypedefDecl=id:0:0
 // CHECK: {start_line=48 start_col=4 end_line=48 end_col=4} FunctionDefn=main:44:5
 // CHECK: {start_line=48 start_col=5 end_line=48 end_col=5} VarDecl=d:48:13
-// CHECK: {start_line=48 start_col=6 end_line=48 end_col=10} ObjCProtocolRef=Proto:48:13
+// CHECK: {start_line=48 start_col=6 end_line=48 end_col=10} ObjCProtocolRef=Proto:23:1
 // CHECK: {start_line=48 start_col=11 end_line=48 end_col=11} VarDecl=d:48:13
 // CHECK: {start_line=48 start_col=12 end_line=48 end_col=12} FunctionDefn=main:44:5
 // CHECK: {start_line=48 start_col=13 end_line=48 end_col=13} VarDecl=d:48:13

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

==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndex.cpp Sat Jan 16 09:44:18 2010
@@ -262,7 +262,10 @@
 void CDeclVisitor::VisitObjCCategoryDecl(ObjCCategoryDecl *ND) {
   // Issue callbacks for the containing class.
   Call(CXCursor_ObjCClassRef, ND);
-  // FIXME: Issue callbacks for protocol refs.
+  ObjCCategoryDecl::protocol_loc_iterator PL = ND->protocol_loc_begin();
+  for (ObjCCategoryDecl::protocol_iterator I = ND->protocol_begin(),
+         E = ND->protocol_end(); I != E; ++I, ++PL)
+    Callback(CDecl, MakeCursorObjCProtocolRef(*I, *PL), CData);
   VisitDeclContext(dyn_cast<DeclContext>(ND));
 }
 
@@ -282,9 +285,10 @@
                                          D->getSuperClassLoc()), 
              CData);
   
-  for (ObjCProtocolDecl::protocol_iterator I = D->protocol_begin(),
-       E = D->protocol_end(); I != E; ++I)
-    Call(CXCursor_ObjCProtocolRef, *I);
+  ObjCInterfaceDecl::protocol_loc_iterator PL = D->protocol_loc_begin();
+  for (ObjCInterfaceDecl::protocol_iterator I = D->protocol_begin(),
+         E = D->protocol_end(); I != E; ++I, ++PL)
+    Callback(CDecl, MakeCursorObjCProtocolRef(*I, *PL), CData);
   VisitDeclContext(dyn_cast<DeclContext>(D));
 }
 
@@ -307,9 +311,10 @@
 }
 
 void CDeclVisitor::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) {
+  ObjCProtocolDecl::protocol_loc_iterator PL = PID->protocol_loc_begin();
   for (ObjCProtocolDecl::protocol_iterator I = PID->protocol_begin(),
-       E = PID->protocol_end(); I != E; ++I)
-    Call(CXCursor_ObjCProtocolRef, *I);
+         E = PID->protocol_end(); I != E; ++I, ++PL)
+    Callback(CDecl, MakeCursorObjCProtocolRef(*I, *PL), CData);
   
   VisitDeclContext(dyn_cast<DeclContext>(PID));
 }
@@ -346,12 +351,8 @@
     }
     case CXCursor_ObjCSuperClassRef:
       return getCursorObjCSuperClassRef(C).second;
-
-    case CXCursor_ObjCProtocolRef: {
-      ObjCProtocolDecl *OID = dyn_cast<ObjCProtocolDecl>(ND);
-      assert(OID && "clang_getCursorLine(): Missing protocol decl");
-      return OID->getLocation();
-    }
+    case CXCursor_ObjCProtocolRef:
+      return getCursorObjCProtocolRef(C).second;
     case CXCursor_ObjCSelectorRef: {
       ObjCMessageExpr *OME = dyn_cast<ObjCMessageExpr>(getCursorStmt(C));
       assert(OME && "clang_getCursorLine(): Missing message expr");
@@ -776,7 +777,7 @@
                             ->getNameStart());
     }
     case CXCursor_ObjCProtocolRef: {
-      ObjCProtocolDecl *OID = dyn_cast<ObjCProtocolDecl>(ND);
+      ObjCProtocolDecl *OID = getCursorObjCProtocolRef(C).first;
       assert(OID && "clang_getCursorLine(): Missing protocol decl");
       return CIndexer::createCXString(OID->getIdentifier()->getNameStart());
     }
@@ -884,10 +885,8 @@
         CXCursor C = { CXCursor_ObjCClassRef, { Dcl, ALoc.getParentDecl(), 0 }};
         return C;
       }
-      if (isa<ObjCProtocolDecl>(Dcl)) {
-        CXCursor C = {CXCursor_ObjCProtocolRef, {Dcl, ALoc.getParentDecl(), 0}};
-        return C;
-      }
+      if (ObjCProtocolDecl *Proto = dyn_cast<ObjCProtocolDecl>(Dcl))
+        return MakeCursorObjCProtocolRef(Proto, ALoc.AsNamedRef().Loc);
     }
     return MakeCXCursor(Dcl);
   }
@@ -933,8 +932,7 @@
 
   if (clang_isReference(C.kind)) {
     if (getCursorStmt(C)) {
-      if (C.kind == CXCursor_ObjCClassRef ||
-          C.kind == CXCursor_ObjCProtocolRef)
+      if (C.kind == CXCursor_ObjCClassRef)
         return getCursorStmt(C);
       else
         return getDeclFromExpr(getCursorStmt(C));

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

==============================================================================
--- cfe/trunk/tools/CIndex/CXCursor.cpp (original)
+++ cfe/trunk/tools/CIndex/CXCursor.cpp Sat Jan 16 09:44:18 2010
@@ -90,6 +90,21 @@
                                       reinterpret_cast<uintptr_t>(C.data[1])));
 }
 
+CXCursor cxcursor::MakeCursorObjCProtocolRef(ObjCProtocolDecl *Super, 
+                                             SourceLocation Loc) {
+  void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
+  CXCursor C = { CXCursor_ObjCProtocolRef, { Super, RawLoc, 0 } };
+  return C;    
+}
+
+std::pair<ObjCProtocolDecl *, SourceLocation> 
+cxcursor::getCursorObjCProtocolRef(CXCursor C) {
+  assert(C.kind == CXCursor_ObjCProtocolRef);
+  return std::make_pair(static_cast<ObjCProtocolDecl *>(C.data[0]),
+           SourceLocation::getFromRawEncoding(
+                                      reinterpret_cast<uintptr_t>(C.data[1])));
+}
+
 Decl *cxcursor::getCursorDecl(CXCursor Cursor) {
   return (Decl *)Cursor.data[0];
 }
@@ -99,7 +114,8 @@
 }
 
 Stmt *cxcursor::getCursorStmt(CXCursor Cursor) {
-  if (Cursor.kind == CXCursor_ObjCSuperClassRef)
+  if (Cursor.kind == CXCursor_ObjCSuperClassRef ||
+      Cursor.kind == CXCursor_ObjCProtocolRef)
     return 0;
 
   return (Stmt *)Cursor.data[1];

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

==============================================================================
--- cfe/trunk/tools/CIndex/CXCursor.h (original)
+++ cfe/trunk/tools/CIndex/CXCursor.h Sat Jan 16 09:44:18 2010
@@ -24,6 +24,7 @@
 class Expr;
 class NamedDecl;
 class ObjCInterfaceDecl;
+class ObjCProtocolDecl;
 class Stmt;
 
 namespace cxcursor {
@@ -39,7 +40,15 @@
 /// \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);
+  getCursorObjCSuperClassRef(CXCursor C);
+
+/// \brief Create an Objective-C protocol reference at the given location.
+CXCursor MakeCursorObjCProtocolRef(ObjCProtocolDecl *Proto, SourceLocation Loc);
+
+/// \brief Unpack an ObjCProtocolRef cursor into the protocol it references
+/// and optionally the location where the reference occurred.
+std::pair<ObjCProtocolDecl *, SourceLocation> 
+  getCursorObjCProtocolRef(CXCursor C);
 
 Decl *getCursorDecl(CXCursor Cursor);
 Expr *getCursorExpr(CXCursor Cursor);





More information about the cfe-commits mailing list