CXCursor.cpp revision 7d0d40e58807f73e06ff5eb637a48e9f978b0e2a
1740d490593e0de8732a697c9f77b90ddd463863bJordan Rose//===- CXCursor.cpp - Routines for manipulating CXCursors -----------------===// 2740d490593e0de8732a697c9f77b90ddd463863bJordan Rose// 3740d490593e0de8732a697c9f77b90ddd463863bJordan Rose// The LLVM Compiler Infrastructure 4740d490593e0de8732a697c9f77b90ddd463863bJordan Rose// 5740d490593e0de8732a697c9f77b90ddd463863bJordan Rose// This file is distributed under the University of Illinois Open Source 6740d490593e0de8732a697c9f77b90ddd463863bJordan Rose// License. See LICENSE.TXT for details. 7740d490593e0de8732a697c9f77b90ddd463863bJordan Rose// 8740d490593e0de8732a697c9f77b90ddd463863bJordan Rose//===----------------------------------------------------------------------===// 9740d490593e0de8732a697c9f77b90ddd463863bJordan Rose// 10740d490593e0de8732a697c9f77b90ddd463863bJordan Rose// This file defines routines for manipulating CXCursors. It should be the 11740d490593e0de8732a697c9f77b90ddd463863bJordan Rose// only file that has internal knowledge of the encoding of the data in 12740d490593e0de8732a697c9f77b90ddd463863bJordan Rose// CXCursor. 13740d490593e0de8732a697c9f77b90ddd463863bJordan Rose// 14740d490593e0de8732a697c9f77b90ddd463863bJordan Rose//===----------------------------------------------------------------------===// 15740d490593e0de8732a697c9f77b90ddd463863bJordan Rose 16f540c54701e3eeb34cb619a3a4eb18f1ac70ef2dJordan Rose#include "CXCursor.h" 1728038f33aa2db4833881fea757a1f0daf85ac02bJordan Rose#include "clang/Frontend/ASTUnit.h" 18b7a23e05d1d8f07f2a6edce5c88c728fe894c2c7Jordan Rose#include "clang/AST/Decl.h" 19740d490593e0de8732a697c9f77b90ddd463863bJordan Rose#include "clang/AST/DeclObjC.h" 20de507eaf3cb54d3cb234dc14499c10ab3373d15fJordan Rose#include "clang/AST/Expr.h" 21740d490593e0de8732a697c9f77b90ddd463863bJordan Rose#include "llvm/Support/ErrorHandling.h" 22740d490593e0de8732a697c9f77b90ddd463863bJordan Rose 23740d490593e0de8732a697c9f77b90ddd463863bJordan Roseusing namespace clang; 24740d490593e0de8732a697c9f77b90ddd463863bJordan Rose 25740d490593e0de8732a697c9f77b90ddd463863bJordan RoseCXCursor cxcursor::MakeCXCursorInvalid(CXCursorKind K) { 265699f62df144545702b91e91836a63db4e5f2627Jordan Rose assert(K >= CXCursor_FirstInvalid && K <= CXCursor_LastInvalid); 275699f62df144545702b91e91836a63db4e5f2627Jordan Rose CXCursor C = { K, { 0, 0, 0 } }; 285699f62df144545702b91e91836a63db4e5f2627Jordan Rose return C; 29740d490593e0de8732a697c9f77b90ddd463863bJordan Rose} 305699f62df144545702b91e91836a63db4e5f2627Jordan Rose 315699f62df144545702b91e91836a63db4e5f2627Jordan Rosestatic CXCursorKind GetCursorKind(Decl *D) { 325699f62df144545702b91e91836a63db4e5f2627Jordan Rose switch (D->getKind()) { 335699f62df144545702b91e91836a63db4e5f2627Jordan Rose case Decl::Enum: return CXCursor_EnumDecl; 345699f62df144545702b91e91836a63db4e5f2627Jordan Rose case Decl::EnumConstant: return CXCursor_EnumConstantDecl; 355699f62df144545702b91e91836a63db4e5f2627Jordan Rose case Decl::Field: return CXCursor_FieldDecl; 365699f62df144545702b91e91836a63db4e5f2627Jordan Rose case Decl::Function: 375699f62df144545702b91e91836a63db4e5f2627Jordan Rose return CXCursor_FunctionDecl; 385699f62df144545702b91e91836a63db4e5f2627Jordan Rose case Decl::ObjCCategory: return CXCursor_ObjCCategoryDecl; 395699f62df144545702b91e91836a63db4e5f2627Jordan Rose case Decl::ObjCCategoryImpl: return CXCursor_ObjCCategoryImplDecl; 405699f62df144545702b91e91836a63db4e5f2627Jordan Rose case Decl::ObjCClass: 415699f62df144545702b91e91836a63db4e5f2627Jordan Rose // FIXME 425699f62df144545702b91e91836a63db4e5f2627Jordan Rose return CXCursor_UnexposedDecl; 435699f62df144545702b91e91836a63db4e5f2627Jordan Rose case Decl::ObjCForwardProtocol: 445699f62df144545702b91e91836a63db4e5f2627Jordan Rose // FIXME 455699f62df144545702b91e91836a63db4e5f2627Jordan Rose return CXCursor_UnexposedDecl; 46740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Decl::ObjCImplementation: return CXCursor_ObjCImplementationDecl; 47740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Decl::ObjCInterface: return CXCursor_ObjCInterfaceDecl; 48740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Decl::ObjCIvar: return CXCursor_ObjCIvarDecl; 49740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Decl::ObjCMethod: 50740d490593e0de8732a697c9f77b90ddd463863bJordan Rose return cast<ObjCMethodDecl>(D)->isInstanceMethod() 51740d490593e0de8732a697c9f77b90ddd463863bJordan Rose ? CXCursor_ObjCInstanceMethodDecl : CXCursor_ObjCClassMethodDecl; 52740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Decl::ObjCProperty: return CXCursor_ObjCPropertyDecl; 53740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Decl::ObjCProtocol: return CXCursor_ObjCProtocolDecl; 54740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Decl::ParmVar: return CXCursor_ParmDecl; 55740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Decl::Typedef: return CXCursor_TypedefDecl; 56740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Decl::Var: return CXCursor_VarDecl; 57740d490593e0de8732a697c9f77b90ddd463863bJordan Rose default: 58740d490593e0de8732a697c9f77b90ddd463863bJordan Rose if (TagDecl *TD = dyn_cast<TagDecl>(D)) { 59740d490593e0de8732a697c9f77b90ddd463863bJordan Rose switch (TD->getTagKind()) { 60740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case TagDecl::TK_struct: return CXCursor_StructDecl; 61740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case TagDecl::TK_class: return CXCursor_ClassDecl; 62740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case TagDecl::TK_union: return CXCursor_UnionDecl; 63740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case TagDecl::TK_enum: return CXCursor_EnumDecl; 644e45dba1c0234eec7b7c348dbbf568c5ac9fc471Jordan Rose } 65740d490593e0de8732a697c9f77b90ddd463863bJordan Rose } 66740d490593e0de8732a697c9f77b90ddd463863bJordan Rose 67740d490593e0de8732a697c9f77b90ddd463863bJordan Rose return CXCursor_UnexposedDecl; 68740d490593e0de8732a697c9f77b90ddd463863bJordan Rose } 69740d490593e0de8732a697c9f77b90ddd463863bJordan Rose 70740d490593e0de8732a697c9f77b90ddd463863bJordan Rose llvm_unreachable("Invalid Decl"); 71740d490593e0de8732a697c9f77b90ddd463863bJordan Rose return CXCursor_NotImplemented; 72740d490593e0de8732a697c9f77b90ddd463863bJordan Rose} 73740d490593e0de8732a697c9f77b90ddd463863bJordan Rose 74740d490593e0de8732a697c9f77b90ddd463863bJordan RoseCXCursor cxcursor::MakeCXCursor(Decl *D, ASTUnit *TU) { 75740d490593e0de8732a697c9f77b90ddd463863bJordan Rose CXCursor C = { GetCursorKind(D), { D, 0, TU } }; 76740d490593e0de8732a697c9f77b90ddd463863bJordan Rose return C; 77740d490593e0de8732a697c9f77b90ddd463863bJordan Rose} 78740d490593e0de8732a697c9f77b90ddd463863bJordan Rose 79740d490593e0de8732a697c9f77b90ddd463863bJordan RoseCXCursor cxcursor::MakeCXCursor(Stmt *S, Decl *Parent, ASTUnit *TU) { 80740d490593e0de8732a697c9f77b90ddd463863bJordan Rose CXCursorKind K = CXCursor_NotImplemented; 81740d490593e0de8732a697c9f77b90ddd463863bJordan Rose 82740d490593e0de8732a697c9f77b90ddd463863bJordan Rose switch (S->getStmtClass()) { 83740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::NoStmtClass: 84740d490593e0de8732a697c9f77b90ddd463863bJordan Rose break; 85740d490593e0de8732a697c9f77b90ddd463863bJordan Rose 86740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::NullStmtClass: 87740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CompoundStmtClass: 88740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CaseStmtClass: 89740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::DefaultStmtClass: 90740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::LabelStmtClass: 91740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::IfStmtClass: 92740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::SwitchStmtClass: 93740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::WhileStmtClass: 94740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::DoStmtClass: 95740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::ForStmtClass: 96740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::GotoStmtClass: 97740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::IndirectGotoStmtClass: 98740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::ContinueStmtClass: 99740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::BreakStmtClass: 100740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::ReturnStmtClass: 101740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::DeclStmtClass: 102740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::SwitchCaseClass: 103740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::AsmStmtClass: 104740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::ObjCAtTryStmtClass: 105740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::ObjCAtCatchStmtClass: 106740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::ObjCAtFinallyStmtClass: 107740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::ObjCAtThrowStmtClass: 108740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::ObjCAtSynchronizedStmtClass: 109740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::ObjCForCollectionStmtClass: 110740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CXXCatchStmtClass: 111740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CXXTryStmtClass: 112740d490593e0de8732a697c9f77b90ddd463863bJordan Rose K = CXCursor_UnexposedStmt; 113740d490593e0de8732a697c9f77b90ddd463863bJordan Rose break; 114740d490593e0de8732a697c9f77b90ddd463863bJordan Rose 115740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::ExprClass: 116740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::PredefinedExprClass: 11785d7e01cf639b257d70f8a129709a2d7594d7b22Jordan Rose case Stmt::IntegerLiteralClass: 118740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::FloatingLiteralClass: 119740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::ImaginaryLiteralClass: 120740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::StringLiteralClass: 121740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CharacterLiteralClass: 12285d7e01cf639b257d70f8a129709a2d7594d7b22Jordan Rose case Stmt::ParenExprClass: 123740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::UnaryOperatorClass: 124740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::SizeOfAlignOfExprClass: 125740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::ArraySubscriptExprClass: 126740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CastExprClass: 127740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::BinaryOperatorClass: 128740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CompoundAssignOperatorClass: 129740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::ConditionalOperatorClass: 130740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::ImplicitCastExprClass: 131b7a23e05d1d8f07f2a6edce5c88c728fe894c2c7Jordan Rose case Stmt::ExplicitCastExprClass: 132740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CStyleCastExprClass: 133740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CompoundLiteralExprClass: 1344b3918e9534e46f9ac067c6e0018f94613292efaJordan Rose case Stmt::ExtVectorElementExprClass: 135740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::InitListExprClass: 136740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::DesignatedInitExprClass: 137740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::ImplicitValueInitExprClass: 13885d7e01cf639b257d70f8a129709a2d7594d7b22Jordan Rose case Stmt::ParenListExprClass: 13985d7e01cf639b257d70f8a129709a2d7594d7b22Jordan Rose case Stmt::VAArgExprClass: 140740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::AddrLabelExprClass: 141740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::StmtExprClass: 142740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::TypesCompatibleExprClass: 143740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::ChooseExprClass: 144740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::GNUNullExprClass: 145740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CXXNamedCastExprClass: 146740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CXXStaticCastExprClass: 147740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CXXDynamicCastExprClass: 148740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CXXReinterpretCastExprClass: 149740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CXXConstCastExprClass: 150740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CXXFunctionalCastExprClass: 151740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CXXTypeidExprClass: 152740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CXXBoolLiteralExprClass: 153740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CXXNullPtrLiteralExprClass: 154740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CXXThisExprClass: 155740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CXXThrowExprClass: 156740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CXXDefaultArgExprClass: 157740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CXXZeroInitValueExprClass: 158740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CXXNewExprClass: 159740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CXXDeleteExprClass: 160740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CXXPseudoDestructorExprClass: 161740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::UnresolvedLookupExprClass: 162740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::UnaryTypeTraitExprClass: 163740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::DependentScopeDeclRefExprClass: 164740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CXXBindTemporaryExprClass: 165740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CXXExprWithTemporariesClass: 166740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CXXUnresolvedConstructExprClass: 167740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::CXXDependentScopeMemberExprClass: 168740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::UnresolvedMemberExprClass: 169740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::ObjCStringLiteralClass: 170740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::ObjCEncodeExprClass: 171740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::ObjCSelectorExprClass: 172740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::ObjCProtocolExprClass: 173740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::ObjCImplicitSetterGetterRefExprClass: 174740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::ObjCSuperExprClass: 175740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::ObjCIsaExprClass: 176740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::ShuffleVectorExprClass: 177740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::BlockExprClass: 178740d490593e0de8732a697c9f77b90ddd463863bJordan Rose K = CXCursor_UnexposedExpr; 179740d490593e0de8732a697c9f77b90ddd463863bJordan Rose break; 180740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::DeclRefExprClass: 181740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::BlockDeclRefExprClass: 182740d490593e0de8732a697c9f77b90ddd463863bJordan Rose // FIXME: UnresolvedLookupExpr? 183740d490593e0de8732a697c9f77b90ddd463863bJordan Rose // FIXME: DependentScopeDeclRefExpr? 184740d490593e0de8732a697c9f77b90ddd463863bJordan Rose K = CXCursor_DeclRefExpr; 185740d490593e0de8732a697c9f77b90ddd463863bJordan Rose break; 186740d490593e0de8732a697c9f77b90ddd463863bJordan Rose 187740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::MemberExprClass: 188740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::ObjCIvarRefExprClass: 189740d490593e0de8732a697c9f77b90ddd463863bJordan Rose case Stmt::ObjCPropertyRefExprClass: 190740d490593e0de8732a697c9f77b90ddd463863bJordan Rose // FIXME: UnresolvedMemberExpr? 191b7a23e05d1d8f07f2a6edce5c88c728fe894c2c7Jordan Rose // FIXME: CXXDependentScopeMemberExpr? 192b7a23e05d1d8f07f2a6edce5c88c728fe894c2c7Jordan Rose K = CXCursor_MemberRefExpr; 193740d490593e0de8732a697c9f77b90ddd463863bJordan Rose break; 194740d490593e0de8732a697c9f77b90ddd463863bJordan Rose 19528038f33aa2db4833881fea757a1f0daf85ac02bJordan Rose case Stmt::CallExprClass: 19628038f33aa2db4833881fea757a1f0daf85ac02bJordan Rose case Stmt::CXXOperatorCallExprClass: 19728038f33aa2db4833881fea757a1f0daf85ac02bJordan Rose case Stmt::CXXMemberCallExprClass: 19828038f33aa2db4833881fea757a1f0daf85ac02bJordan Rose case Stmt::CXXConstructExprClass: 199b7a23e05d1d8f07f2a6edce5c88c728fe894c2c7Jordan Rose case Stmt::CXXTemporaryObjectExprClass: 200b7a23e05d1d8f07f2a6edce5c88c728fe894c2c7Jordan Rose // FIXME: CXXUnresolvedConstructExpr 20128038f33aa2db4833881fea757a1f0daf85ac02bJordan Rose // FIXME: ObjCImplicitSetterGetterRefExpr? 20228038f33aa2db4833881fea757a1f0daf85ac02bJordan Rose K = CXCursor_CallExpr; 20328038f33aa2db4833881fea757a1f0daf85ac02bJordan Rose break; 20428038f33aa2db4833881fea757a1f0daf85ac02bJordan Rose 20528038f33aa2db4833881fea757a1f0daf85ac02bJordan Rose case Stmt::ObjCMessageExprClass: 20628038f33aa2db4833881fea757a1f0daf85ac02bJordan Rose K = CXCursor_ObjCMessageExpr; 20728038f33aa2db4833881fea757a1f0daf85ac02bJordan Rose break; 208b7a23e05d1d8f07f2a6edce5c88c728fe894c2c7Jordan Rose } 209b7a23e05d1d8f07f2a6edce5c88c728fe894c2c7Jordan Rose 21028038f33aa2db4833881fea757a1f0daf85ac02bJordan Rose CXCursor C = { K, { Parent, S, TU } }; 21128038f33aa2db4833881fea757a1f0daf85ac02bJordan Rose return C; 2127c99aa385178c630e29f671299cdd9c104f1c885Jordan Rose} 2137c99aa385178c630e29f671299cdd9c104f1c885Jordan Rose 2147c99aa385178c630e29f671299cdd9c104f1c885Jordan RoseCXCursor cxcursor::MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super, 2157c99aa385178c630e29f671299cdd9c104f1c885Jordan Rose SourceLocation Loc, 2167c99aa385178c630e29f671299cdd9c104f1c885Jordan Rose ASTUnit *TU) { 2177c99aa385178c630e29f671299cdd9c104f1c885Jordan Rose void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 2187c99aa385178c630e29f671299cdd9c104f1c885Jordan Rose CXCursor C = { CXCursor_ObjCSuperClassRef, { Super, RawLoc, TU } }; 2197c99aa385178c630e29f671299cdd9c104f1c885Jordan Rose return C; 2207c99aa385178c630e29f671299cdd9c104f1c885Jordan Rose} 2217c99aa385178c630e29f671299cdd9c104f1c885Jordan Rose 2227c99aa385178c630e29f671299cdd9c104f1c885Jordan Rosestd::pair<ObjCInterfaceDecl *, SourceLocation> 2237c99aa385178c630e29f671299cdd9c104f1c885Jordan Rosecxcursor::getCursorObjCSuperClassRef(CXCursor C) { 2247c99aa385178c630e29f671299cdd9c104f1c885Jordan Rose assert(C.kind == CXCursor_ObjCSuperClassRef); 2257c99aa385178c630e29f671299cdd9c104f1c885Jordan Rose return std::make_pair(static_cast<ObjCInterfaceDecl *>(C.data[0]), 22642c72c258e08ca79c9267346b4badcddd8fcd001Benjamin Kramer SourceLocation::getFromRawEncoding( 22742c72c258e08ca79c9267346b4badcddd8fcd001Benjamin Kramer reinterpret_cast<uintptr_t>(C.data[1]))); 22842c72c258e08ca79c9267346b4badcddd8fcd001Benjamin Kramer} 22942c72c258e08ca79c9267346b4badcddd8fcd001Benjamin Kramer 2307c99aa385178c630e29f671299cdd9c104f1c885Jordan RoseCXCursor cxcursor::MakeCursorObjCProtocolRef(ObjCProtocolDecl *Super, 2317c99aa385178c630e29f671299cdd9c104f1c885Jordan Rose SourceLocation Loc, 2327c99aa385178c630e29f671299cdd9c104f1c885Jordan Rose ASTUnit *TU) { 233d1420c6fa788669e49f21e184927c7833881e399Richard Smith void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 2347c99aa385178c630e29f671299cdd9c104f1c885Jordan Rose CXCursor C = { CXCursor_ObjCProtocolRef, { Super, RawLoc, TU } }; 2357c99aa385178c630e29f671299cdd9c104f1c885Jordan Rose return C; 2367c99aa385178c630e29f671299cdd9c104f1c885Jordan Rose} 2377c99aa385178c630e29f671299cdd9c104f1c885Jordan Rose 2387c99aa385178c630e29f671299cdd9c104f1c885Jordan Rosestd::pair<ObjCProtocolDecl *, SourceLocation> 2397c99aa385178c630e29f671299cdd9c104f1c885Jordan Rosecxcursor::getCursorObjCProtocolRef(CXCursor C) { 2407c99aa385178c630e29f671299cdd9c104f1c885Jordan Rose assert(C.kind == CXCursor_ObjCProtocolRef); 2417c99aa385178c630e29f671299cdd9c104f1c885Jordan Rose return std::make_pair(static_cast<ObjCProtocolDecl *>(C.data[0]), 2427c99aa385178c630e29f671299cdd9c104f1c885Jordan Rose SourceLocation::getFromRawEncoding( 2437c99aa385178c630e29f671299cdd9c104f1c885Jordan Rose reinterpret_cast<uintptr_t>(C.data[1]))); 2447c99aa385178c630e29f671299cdd9c104f1c885Jordan Rose} 2457c99aa385178c630e29f671299cdd9c104f1c885Jordan Rose 2467c99aa385178c630e29f671299cdd9c104f1c885Jordan RoseCXCursor cxcursor::MakeCursorObjCClassRef(ObjCInterfaceDecl *Class, 2477c99aa385178c630e29f671299cdd9c104f1c885Jordan Rose SourceLocation Loc, 24828038f33aa2db4833881fea757a1f0daf85ac02bJordan Rose ASTUnit *TU) { 2496062334cc388bce69fb3978c4ecb26c6485a5c2bJordan Rose void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 2507c99aa385178c630e29f671299cdd9c104f1c885Jordan Rose CXCursor C = { CXCursor_ObjCClassRef, { Class, RawLoc, TU } }; 2516062334cc388bce69fb3978c4ecb26c6485a5c2bJordan Rose return C; 2526062334cc388bce69fb3978c4ecb26c6485a5c2bJordan Rose} 25385d7e01cf639b257d70f8a129709a2d7594d7b22Jordan Rose 25485d7e01cf639b257d70f8a129709a2d7594d7b22Jordan Rosestd::pair<ObjCInterfaceDecl *, SourceLocation> 255ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rosecxcursor::getCursorObjCClassRef(CXCursor C) { 256ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose assert(C.kind == CXCursor_ObjCClassRef); 257ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose return std::make_pair(static_cast<ObjCInterfaceDecl *>(C.data[0]), 258ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose SourceLocation::getFromRawEncoding( 259ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose reinterpret_cast<uintptr_t>(C.data[1]))); 260ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose} 261ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose 26285d7e01cf639b257d70f8a129709a2d7594d7b22Jordan RoseCXCursor cxcursor::MakeCursorTypeRef(TypeDecl *Type, SourceLocation Loc, 263ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose ASTUnit *TU) { 264ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 265ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose CXCursor C = { CXCursor_TypeRef, { Type, RawLoc, TU } }; 266ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose return C; 267ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose} 268ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose 269ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rosestd::pair<TypeDecl *, SourceLocation> 270ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rosecxcursor::getCursorTypeRef(CXCursor C) { 271ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose assert(C.kind == CXCursor_TypeRef); 272ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose return std::make_pair(static_cast<TypeDecl *>(C.data[0]), 273ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose SourceLocation::getFromRawEncoding( 274ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose reinterpret_cast<uintptr_t>(C.data[1]))); 275ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose} 276ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose 277ef15831780b705475e7b237ac16418e9b53cb7a6Jordan RoseDecl *cxcursor::getCursorDecl(CXCursor Cursor) { 278ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose return (Decl *)Cursor.data[0]; 279ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose} 280ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose 281740d490593e0de8732a697c9f77b90ddd463863bJordan RoseExpr *cxcursor::getCursorExpr(CXCursor Cursor) { 282740d490593e0de8732a697c9f77b90ddd463863bJordan Rose return dyn_cast_or_null<Expr>(getCursorStmt(Cursor)); 283740d490593e0de8732a697c9f77b90ddd463863bJordan Rose} 284ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose 285740d490593e0de8732a697c9f77b90ddd463863bJordan RoseStmt *cxcursor::getCursorStmt(CXCursor Cursor) { 286740d490593e0de8732a697c9f77b90ddd463863bJordan Rose if (Cursor.kind == CXCursor_ObjCSuperClassRef || 287ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose Cursor.kind == CXCursor_ObjCProtocolRef || 288ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose Cursor.kind == CXCursor_ObjCClassRef) 289740d490593e0de8732a697c9f77b90ddd463863bJordan Rose return 0; 290740d490593e0de8732a697c9f77b90ddd463863bJordan Rose 291740d490593e0de8732a697c9f77b90ddd463863bJordan Rose return (Stmt *)Cursor.data[1]; 292ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose} 293ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose 294ef15831780b705475e7b237ac16418e9b53cb7a6Jordan RoseASTContext &cxcursor::getCursorContext(CXCursor Cursor) { 295ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose return getCursorASTUnit(Cursor)->getASTContext(); 296ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose} 297ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose 298ef15831780b705475e7b237ac16418e9b53cb7a6Jordan RoseASTUnit *cxcursor::getCursorASTUnit(CXCursor Cursor) { 299ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose return static_cast<ASTUnit *>(Cursor.data[2]); 300ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose} 301ef15831780b705475e7b237ac16418e9b53cb7a6Jordan Rose 302740d490593e0de8732a697c9f77b90ddd463863bJordan Rosebool cxcursor::operator==(CXCursor X, CXCursor Y) { 303740d490593e0de8732a697c9f77b90ddd463863bJordan Rose return X.kind == Y.kind && X.data[0] == Y.data[0] && X.data[1] == Y.data[1] && 30485d7e01cf639b257d70f8a129709a2d7594d7b22Jordan Rose X.data[2] == Y.data[2]; 305b7a23e05d1d8f07f2a6edce5c88c728fe894c2c7Jordan Rose} 30685d7e01cf639b257d70f8a129709a2d7594d7b22Jordan Rose