diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-01-16 15:44:18 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-01-16 15:44:18 +0000 |
commit | ef6eb84da15e7894edcc0bae08161c5016d76f44 (patch) | |
tree | 1c3d81ed35b5df31ba2befe004cca13ad041e54c /clang/tools | |
parent | 002b67105500e620d5f87693f981a8abd0afb32b (diff) | |
download | bcm5719-llvm-ef6eb84da15e7894edcc0bae08161c5016d76f44.tar.gz bcm5719-llvm-ef6eb84da15e7894edcc0bae08161c5016d76f44.zip |
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.
llvm-svn: 93637
Diffstat (limited to 'clang/tools')
-rw-r--r-- | clang/tools/CIndex/CIndex.cpp | 36 | ||||
-rw-r--r-- | clang/tools/CIndex/CXCursor.cpp | 18 | ||||
-rw-r--r-- | clang/tools/CIndex/CXCursor.h | 11 |
3 files changed, 44 insertions, 21 deletions
diff --git a/clang/tools/CIndex/CIndex.cpp b/clang/tools/CIndex/CIndex.cpp index e58a08a0d6c..c08243e79c5 100644 --- a/clang/tools/CIndex/CIndex.cpp +++ b/clang/tools/CIndex/CIndex.cpp @@ -262,7 +262,10 @@ void CDeclVisitor::VisitFunctionDecl(FunctionDecl *ND) { 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 @@ void CDeclVisitor::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { 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::VisitObjCPropertyDecl(ObjCPropertyDecl *ND) { } 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 @@ static SourceLocation getLocationFromCursor(CXCursor C, } 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 @@ CXString clang_getCursorSpelling(CXCursor C) { ->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 clang_getCursor(CXTranslationUnit CTUnit, const char *source_name, 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 @@ CXDecl clang_getCursorDecl(CXCursor C) { 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)); diff --git a/clang/tools/CIndex/CXCursor.cpp b/clang/tools/CIndex/CXCursor.cpp index d6c38673e01..01d809a8db8 100644 --- a/clang/tools/CIndex/CXCursor.cpp +++ b/clang/tools/CIndex/CXCursor.cpp @@ -90,6 +90,21 @@ cxcursor::getCursorObjCSuperClassRef(CXCursor C) { 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 @@ Expr *cxcursor::getCursorExpr(CXCursor Cursor) { } 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]; diff --git a/clang/tools/CIndex/CXCursor.h b/clang/tools/CIndex/CXCursor.h index c2f8de33564..26bbc7d59c8 100644 --- a/clang/tools/CIndex/CXCursor.h +++ b/clang/tools/CIndex/CXCursor.h @@ -24,6 +24,7 @@ class Decl; class Expr; class NamedDecl; class ObjCInterfaceDecl; +class ObjCProtocolDecl; class Stmt; namespace cxcursor { @@ -39,7 +40,15 @@ CXCursor MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super, /// \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); |