CXCursor.cpp revision 97b9872d5775446cb8aca1380e437649fe848d91
116c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek//===- CXCursor.cpp - Routines for manipulating CXCursors -----------------===// 216c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek// 316c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek// The LLVM Compiler Infrastructure 416c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek// 516c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek// This file is distributed under the University of Illinois Open Source 616c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek// License. See LICENSE.TXT for details. 716c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek// 816c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek//===----------------------------------------------------------------------===// 916c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek// 102e331b938b38057e333fab0ba841130ea8467794Douglas Gregor// This file defines routines for manipulating CXCursors. It should be the 112e331b938b38057e333fab0ba841130ea8467794Douglas Gregor// only file that has internal knowledge of the encoding of the data in 122e331b938b38057e333fab0ba841130ea8467794Douglas Gregor// CXCursor. 1316c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek// 1416c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek//===----------------------------------------------------------------------===// 1516c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek 1616c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek#include "CXCursor.h" 1716c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek#include "clang/AST/Decl.h" 18283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor#include "clang/AST/DeclObjC.h" 19283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor#include "clang/AST/Expr.h" 20edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek#include "llvm/Support/ErrorHandling.h" 2116c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek 2216c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenekusing namespace clang; 2316c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek 2416c440a377b7ec8b722a2e2c7c864f75c95bd305Ted KremenekCXCursor cxcursor::MakeCXCursor(CXCursorKind K, Decl *D) { 25283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor CXCursor C = { K, { D, 0, 0 } }; 2616c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek return C; 2716c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek} 2816c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek 29f46034af49435a4d1a0085a4738343122aeb6521Douglas GregorCXCursor cxcursor::MakeCXCursor(CXCursorKind K, Decl *D, Stmt *S, 30f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor ASTContext &Context) { 3116c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek assert(clang_isReference(K)); 32f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor CXCursor C = { K, { D, S, &Context } }; 3316c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek return C; 3416c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek} 3516c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek 36edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenekstatic CXCursorKind GetCursorKind(Decl *D) { 37edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek switch (D->getKind()) { 3870ee54258035c860ebc71f7e5f803b74f3186889Ted Kremenek case Decl::Enum: return CXCursor_EnumDecl; 3970ee54258035c860ebc71f7e5f803b74f3186889Ted Kremenek case Decl::EnumConstant: return CXCursor_EnumConstantDecl; 4070ee54258035c860ebc71f7e5f803b74f3186889Ted Kremenek case Decl::Field: return CXCursor_FieldDecl; 41edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek case Decl::Function: 42b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor return CXCursor_FunctionDecl; 43edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek case Decl::ObjCCategory: return CXCursor_ObjCCategoryDecl; 44b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor case Decl::ObjCCategoryImpl: return CXCursor_ObjCCategoryImplDecl; 4570ee54258035c860ebc71f7e5f803b74f3186889Ted Kremenek case Decl::ObjCClass: 4670ee54258035c860ebc71f7e5f803b74f3186889Ted Kremenek // FIXME 47301221313be4f97327e931ead9794dd3a8bce160Douglas Gregor return CXCursor_UnexposedDecl; 486483a773db4d0ea3ab15de5801abe504c1dbc204Ted Kremenek case Decl::ObjCForwardProtocol: 496483a773db4d0ea3ab15de5801abe504c1dbc204Ted Kremenek // FIXME 50301221313be4f97327e931ead9794dd3a8bce160Douglas Gregor return CXCursor_UnexposedDecl; 51b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor case Decl::ObjCImplementation: return CXCursor_ObjCImplementationDecl; 52edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek case Decl::ObjCInterface: return CXCursor_ObjCInterfaceDecl; 5370ee54258035c860ebc71f7e5f803b74f3186889Ted Kremenek case Decl::ObjCIvar: return CXCursor_ObjCIvarDecl; 5470ee54258035c860ebc71f7e5f803b74f3186889Ted Kremenek case Decl::ObjCMethod: 5570ee54258035c860ebc71f7e5f803b74f3186889Ted Kremenek return cast<ObjCMethodDecl>(D)->isInstanceMethod() 5670ee54258035c860ebc71f7e5f803b74f3186889Ted Kremenek ? CXCursor_ObjCInstanceMethodDecl : CXCursor_ObjCClassMethodDecl; 5710fa3ccf087e167123fdb0a5e1313c7106c3c1fcTed Kremenek case Decl::ObjCProperty: return CXCursor_ObjCPropertyDecl; 58edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek case Decl::ObjCProtocol: return CXCursor_ObjCProtocolDecl; 5970ee54258035c860ebc71f7e5f803b74f3186889Ted Kremenek case Decl::ParmVar: return CXCursor_ParmDecl; 60edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek case Decl::Typedef: return CXCursor_TypedefDecl; 61edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek case Decl::Var: return CXCursor_VarDecl; 62edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek default: 63edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek if (TagDecl *TD = dyn_cast<TagDecl>(D)) { 64edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek switch (TD->getTagKind()) { 65edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek case TagDecl::TK_struct: return CXCursor_StructDecl; 66edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek case TagDecl::TK_class: return CXCursor_ClassDecl; 67edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek case TagDecl::TK_union: return CXCursor_UnionDecl; 68edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek case TagDecl::TK_enum: return CXCursor_EnumDecl; 69edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek } 70edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek } 71301221313be4f97327e931ead9794dd3a8bce160Douglas Gregor 72301221313be4f97327e931ead9794dd3a8bce160Douglas Gregor return CXCursor_UnexposedDecl; 73edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek } 74edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek 75edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek llvm_unreachable("Invalid Decl"); 76edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek return CXCursor_NotImplemented; 77edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek} 78edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek 79edc8aa68ef91aeea686c5aadf64ef902c38318ddTed KremenekCXCursor cxcursor::MakeCXCursor(Decl *D) { 80edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek return MakeCXCursor(GetCursorKind(D), D); 81edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek} 82edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek 8397b9872d5775446cb8aca1380e437649fe848d91Douglas GregorCXCursor cxcursor::MakeCXCursor(Stmt *S, Decl *Parent) { 8497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor CXCursorKind K = CXCursor_NotImplemented; 8597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor 8697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor switch (S->getStmtClass()) { 8797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::NoStmtClass: 8897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor break; 8997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor 9097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::NullStmtClass: 9197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CompoundStmtClass: 9297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CaseStmtClass: 9397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::DefaultStmtClass: 9497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::LabelStmtClass: 9597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::IfStmtClass: 9697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::SwitchStmtClass: 9797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::WhileStmtClass: 9897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::DoStmtClass: 9997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ForStmtClass: 10097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::GotoStmtClass: 10197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::IndirectGotoStmtClass: 10297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ContinueStmtClass: 10397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::BreakStmtClass: 10497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ReturnStmtClass: 10597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::DeclStmtClass: 10697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::SwitchCaseClass: 10797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::AsmStmtClass: 10897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCAtTryStmtClass: 10997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCAtCatchStmtClass: 11097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCAtFinallyStmtClass: 11197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCAtThrowStmtClass: 11297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCAtSynchronizedStmtClass: 11397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCForCollectionStmtClass: 11497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXCatchStmtClass: 11597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXTryStmtClass: 11697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor K = CXCursor_UnexposedStmt; 11797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor break; 11897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor 11997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ExprClass: 12097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::PredefinedExprClass: 12197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::IntegerLiteralClass: 12297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::FloatingLiteralClass: 12397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ImaginaryLiteralClass: 12497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::StringLiteralClass: 12597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CharacterLiteralClass: 12697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ParenExprClass: 12797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::UnaryOperatorClass: 12897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::SizeOfAlignOfExprClass: 12997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ArraySubscriptExprClass: 13097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CastExprClass: 13197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::BinaryOperatorClass: 13297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CompoundAssignOperatorClass: 13397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ConditionalOperatorClass: 13497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ImplicitCastExprClass: 13597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ExplicitCastExprClass: 13697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CStyleCastExprClass: 13797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CompoundLiteralExprClass: 13897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ExtVectorElementExprClass: 13997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::InitListExprClass: 14097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::DesignatedInitExprClass: 14197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ImplicitValueInitExprClass: 14297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ParenListExprClass: 14397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::VAArgExprClass: 14497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::AddrLabelExprClass: 14597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::StmtExprClass: 14697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::TypesCompatibleExprClass: 14797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ChooseExprClass: 14897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::GNUNullExprClass: 14997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXNamedCastExprClass: 15097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXStaticCastExprClass: 15197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXDynamicCastExprClass: 15297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXReinterpretCastExprClass: 15397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXConstCastExprClass: 15497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXFunctionalCastExprClass: 15597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXTypeidExprClass: 15697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXBoolLiteralExprClass: 15797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXNullPtrLiteralExprClass: 15897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXThisExprClass: 15997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXThrowExprClass: 16097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXDefaultArgExprClass: 16197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXZeroInitValueExprClass: 16297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXNewExprClass: 16397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXDeleteExprClass: 16497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXPseudoDestructorExprClass: 16597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::UnresolvedLookupExprClass: 16697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::UnaryTypeTraitExprClass: 16797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::DependentScopeDeclRefExprClass: 16897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXBindTemporaryExprClass: 16997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXExprWithTemporariesClass: 17097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXUnresolvedConstructExprClass: 17197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXDependentScopeMemberExprClass: 17297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::UnresolvedMemberExprClass: 17397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCStringLiteralClass: 17497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCEncodeExprClass: 17597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCSelectorExprClass: 17697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCProtocolExprClass: 17797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCImplicitSetterGetterRefExprClass: 17897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCSuperExprClass: 17997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCIsaExprClass: 18097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ShuffleVectorExprClass: 18197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::BlockExprClass: 18297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor K = CXCursor_UnexposedExpr; 18397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor break; 18497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::DeclRefExprClass: 18597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::BlockDeclRefExprClass: 18697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor // FIXME: UnresolvedLookupExpr? 18797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor // FIXME: DependentScopeDeclRefExpr? 18897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor K = CXCursor_DeclRefExpr; 18997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor break; 19097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor 19197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::MemberExprClass: 19297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCIvarRefExprClass: 19397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCPropertyRefExprClass: 19497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor // FIXME: UnresolvedMemberExpr? 19597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor // FIXME: CXXDependentScopeMemberExpr? 19697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor K = CXCursor_MemberRefExpr; 19797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor break; 19897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor 19997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CallExprClass: 20097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXOperatorCallExprClass: 20197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXMemberCallExprClass: 20297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXConstructExprClass: 20397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXTemporaryObjectExprClass: 20497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor // FIXME: CXXUnresolvedConstructExpr 20597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor // FIXME: ObjCImplicitSetterGetterRefExpr? 20697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor K = CXCursor_CallExpr; 20797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor break; 20897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor 20997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCMessageExprClass: 21097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor K = CXCursor_ObjCMessageExpr; 21197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor break; 21297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor } 21397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor 21497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor CXCursor C = { K, { Parent, S, 0 } }; 21597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor return C; 21697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor} 21797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor 2182e331b938b38057e333fab0ba841130ea8467794Douglas GregorCXCursor cxcursor::MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super, 2192e331b938b38057e333fab0ba841130ea8467794Douglas Gregor SourceLocation Loc) { 2202e331b938b38057e333fab0ba841130ea8467794Douglas Gregor void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 2212e331b938b38057e333fab0ba841130ea8467794Douglas Gregor CXCursor C = { CXCursor_ObjCSuperClassRef, { Super, RawLoc, 0 } }; 2222e331b938b38057e333fab0ba841130ea8467794Douglas Gregor return C; 2232e331b938b38057e333fab0ba841130ea8467794Douglas Gregor} 2242e331b938b38057e333fab0ba841130ea8467794Douglas Gregor 2252e331b938b38057e333fab0ba841130ea8467794Douglas Gregorstd::pair<ObjCInterfaceDecl *, SourceLocation> 2262e331b938b38057e333fab0ba841130ea8467794Douglas Gregorcxcursor::getCursorObjCSuperClassRef(CXCursor C) { 2272e331b938b38057e333fab0ba841130ea8467794Douglas Gregor assert(C.kind == CXCursor_ObjCSuperClassRef); 2282e331b938b38057e333fab0ba841130ea8467794Douglas Gregor return std::make_pair(static_cast<ObjCInterfaceDecl *>(C.data[0]), 2292e331b938b38057e333fab0ba841130ea8467794Douglas Gregor SourceLocation::getFromRawEncoding( 2302e331b938b38057e333fab0ba841130ea8467794Douglas Gregor reinterpret_cast<uintptr_t>(C.data[1]))); 2312e331b938b38057e333fab0ba841130ea8467794Douglas Gregor} 2322e331b938b38057e333fab0ba841130ea8467794Douglas Gregor 23378db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas GregorCXCursor cxcursor::MakeCursorObjCProtocolRef(ObjCProtocolDecl *Super, 23478db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor SourceLocation Loc) { 23578db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 23678db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor CXCursor C = { CXCursor_ObjCProtocolRef, { Super, RawLoc, 0 } }; 23778db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor return C; 23878db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor} 23978db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor 24078db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregorstd::pair<ObjCProtocolDecl *, SourceLocation> 24178db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregorcxcursor::getCursorObjCProtocolRef(CXCursor C) { 24278db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor assert(C.kind == CXCursor_ObjCProtocolRef); 24378db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor return std::make_pair(static_cast<ObjCProtocolDecl *>(C.data[0]), 24478db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor SourceLocation::getFromRawEncoding( 24578db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor reinterpret_cast<uintptr_t>(C.data[1]))); 24678db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor} 24778db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor 2481adb082a709f7b588f03672999294e061234b2cfDouglas GregorCXCursor cxcursor::MakeCursorObjCClassRef(ObjCInterfaceDecl *Class, 2491adb082a709f7b588f03672999294e061234b2cfDouglas Gregor SourceLocation Loc) { 2501adb082a709f7b588f03672999294e061234b2cfDouglas Gregor void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 2511adb082a709f7b588f03672999294e061234b2cfDouglas Gregor CXCursor C = { CXCursor_ObjCClassRef, { Class, RawLoc, 0 } }; 2521adb082a709f7b588f03672999294e061234b2cfDouglas Gregor return C; 2531adb082a709f7b588f03672999294e061234b2cfDouglas Gregor} 2541adb082a709f7b588f03672999294e061234b2cfDouglas Gregor 2551adb082a709f7b588f03672999294e061234b2cfDouglas Gregorstd::pair<ObjCInterfaceDecl *, SourceLocation> 2561adb082a709f7b588f03672999294e061234b2cfDouglas Gregorcxcursor::getCursorObjCClassRef(CXCursor C) { 2571adb082a709f7b588f03672999294e061234b2cfDouglas Gregor assert(C.kind == CXCursor_ObjCClassRef); 2581adb082a709f7b588f03672999294e061234b2cfDouglas Gregor return std::make_pair(static_cast<ObjCInterfaceDecl *>(C.data[0]), 2591adb082a709f7b588f03672999294e061234b2cfDouglas Gregor SourceLocation::getFromRawEncoding( 2601adb082a709f7b588f03672999294e061234b2cfDouglas Gregor reinterpret_cast<uintptr_t>(C.data[1]))); 2611adb082a709f7b588f03672999294e061234b2cfDouglas Gregor} 2621adb082a709f7b588f03672999294e061234b2cfDouglas Gregor 263283cae37b03047c14ef918503bc46b08405c3b69Douglas GregorDecl *cxcursor::getCursorDecl(CXCursor Cursor) { 264283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor return (Decl *)Cursor.data[0]; 265283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor} 266283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor 267283cae37b03047c14ef918503bc46b08405c3b69Douglas GregorExpr *cxcursor::getCursorExpr(CXCursor Cursor) { 268283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor return dyn_cast_or_null<Expr>(getCursorStmt(Cursor)); 269283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor} 270283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor 271283cae37b03047c14ef918503bc46b08405c3b69Douglas GregorStmt *cxcursor::getCursorStmt(CXCursor Cursor) { 27278db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor if (Cursor.kind == CXCursor_ObjCSuperClassRef || 2731adb082a709f7b588f03672999294e061234b2cfDouglas Gregor Cursor.kind == CXCursor_ObjCProtocolRef || 2741adb082a709f7b588f03672999294e061234b2cfDouglas Gregor Cursor.kind == CXCursor_ObjCClassRef) 2752e331b938b38057e333fab0ba841130ea8467794Douglas Gregor return 0; 2762e331b938b38057e333fab0ba841130ea8467794Douglas Gregor 277283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor return (Stmt *)Cursor.data[1]; 278283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor} 279283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor 280f46034af49435a4d1a0085a4738343122aeb6521Douglas GregorASTContext &cxcursor::getCursorContext(CXCursor Cursor) { 281f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor switch (Cursor.kind) { 282f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor case CXCursor_TypedefDecl: 283f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor case CXCursor_StructDecl: 284f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor case CXCursor_UnionDecl: 285f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor case CXCursor_ClassDecl: 286f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor case CXCursor_EnumDecl: 287f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor case CXCursor_FieldDecl: 288f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor case CXCursor_EnumConstantDecl: 289f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor case CXCursor_FunctionDecl: 290f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor case CXCursor_VarDecl: 291f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor case CXCursor_ParmDecl: 292f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor case CXCursor_ObjCInterfaceDecl: 293f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor case CXCursor_ObjCCategoryDecl: 294f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor case CXCursor_ObjCProtocolDecl: 295f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor case CXCursor_ObjCPropertyDecl: 296f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor case CXCursor_ObjCIvarDecl: 297f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor case CXCursor_ObjCInstanceMethodDecl: 298f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor case CXCursor_ObjCClassMethodDecl: 299b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor case CXCursor_ObjCImplementationDecl: 300b699866820102a69d83d6ac6941985c5ef4e8c40Douglas Gregor case CXCursor_ObjCCategoryImplDecl: 301301221313be4f97327e931ead9794dd3a8bce160Douglas Gregor case CXCursor_UnexposedDecl: 302f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor return static_cast<Decl *>(Cursor.data[0])->getASTContext(); 303f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor 304f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor case CXCursor_ObjCSuperClassRef: 305f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor case CXCursor_ObjCProtocolRef: 306f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor case CXCursor_ObjCClassRef: 307f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor return static_cast<Decl *>(Cursor.data[0])->getASTContext(); 308f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor 309f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor case CXCursor_ObjCSelectorRef: 310f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor case CXCursor_VarRef: 311f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor case CXCursor_FunctionRef: 312f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor case CXCursor_EnumConstantRef: 313f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor return *static_cast<ASTContext *>(Cursor.data[2]); 314f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor 315f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor case CXCursor_InvalidFile: 316f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor case CXCursor_NoDeclFound: 317f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor case CXCursor_NotImplemented: 318f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor llvm_unreachable("No context in an invalid cursor"); 31997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor break; 32097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor 32197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case CXCursor_UnexposedExpr: 32297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case CXCursor_DeclRefExpr: 32397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case CXCursor_MemberRefExpr: 32497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case CXCursor_CallExpr: 32597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case CXCursor_ObjCMessageExpr: 32697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case CXCursor_UnexposedStmt: 32797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor return static_cast<Decl *>(Cursor.data[0])->getASTContext(); 32897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor 329f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor } 330f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor 331f46034af49435a4d1a0085a4738343122aeb6521Douglas Gregor llvm_unreachable("No context available"); 332283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor} 333283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor 334283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregorbool cxcursor::operator==(CXCursor X, CXCursor Y) { 335283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor return X.kind == Y.kind && X.data[0] == Y.data[0] && X.data[1] == Y.data[1] && 336283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor X.data[2] == Y.data[2]; 3372e331b938b38057e333fab0ba841130ea8467794Douglas Gregor} 338