CXCursor.cpp revision a60ed47da13393796d8552b9fdca12abbb3eea42
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" 17ed122735639d83c10f18c28c7fd117bfcd0f62cbTed Kremenek#include "CXString.h" 187eaa8ae8692c5cd3eed8cb334fe5346470522091Douglas Gregor#include "clang/Frontend/ASTUnit.h" 1916c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek#include "clang/AST/Decl.h" 206931900f43cea558c6974075256c07728dbfecc6Douglas Gregor#include "clang/AST/DeclCXX.h" 21283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor#include "clang/AST/DeclObjC.h" 22283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor#include "clang/AST/Expr.h" 231f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor#include "clang/AST/ExprCXX.h" 24007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek#include "clang-c/Index.h" 25edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek#include "llvm/Support/ErrorHandling.h" 2616c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek 2716c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenekusing namespace clang; 281f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregorusing namespace cxcursor; 2916c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek 305bfb8c128c2ac8eb4032afc180cdc400a0f953caDouglas GregorCXCursor cxcursor::MakeCXCursorInvalid(CXCursorKind K) { 315bfb8c128c2ac8eb4032afc180cdc400a0f953caDouglas Gregor assert(K >= CXCursor_FirstInvalid && K <= CXCursor_LastInvalid); 325bfb8c128c2ac8eb4032afc180cdc400a0f953caDouglas Gregor CXCursor C = { K, { 0, 0, 0 } }; 335bfb8c128c2ac8eb4032afc180cdc400a0f953caDouglas Gregor return C; 3416c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek} 3516c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek 36e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenekstatic CXCursorKind GetCursorKind(const Attr *A) { 37e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek assert(A && "Invalid arguments!"); 38e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek switch (A->getKind()) { 39e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek default: break; 40387475d0c18aaeb022108de9d33b6c9fb7998843Sean Hunt case attr::IBAction: return CXCursor_IBActionAttr; 41387475d0c18aaeb022108de9d33b6c9fb7998843Sean Hunt case attr::IBOutlet: return CXCursor_IBOutletAttr; 42387475d0c18aaeb022108de9d33b6c9fb7998843Sean Hunt case attr::IBOutletCollection: return CXCursor_IBOutletCollectionAttr; 43e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek } 44e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek 45e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek return CXCursor_UnexposedAttr; 46e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek} 47e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek 48a60ed47da13393796d8552b9fdca12abbb3eea42Ted KremenekCXCursor cxcursor::MakeCXCursor(const Attr *A, Decl *Parent, 49a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 50e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek assert(A && Parent && TU && "Invalid arguments!"); 51e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek CXCursor C = { GetCursorKind(A), { Parent, (void*)A, TU } }; 52e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek return C; 53e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek} 54e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek 55a60ed47da13393796d8552b9fdca12abbb3eea42Ted KremenekCXCursor cxcursor::MakeCXCursor(Decl *D, CXTranslationUnit TU, 56007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek bool FirstInDeclGroup) { 5754d67caeee4fdce81f07163832f1163d5f2af5d2Daniel Dunbar assert(D && TU && "Invalid arguments!"); 58007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek CXCursor C = { getCursorKindForDecl(D), 59007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek { D, (void*) (FirstInDeclGroup ? 1 : 0), TU } 60007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek }; 615bfb8c128c2ac8eb4032afc180cdc400a0f953caDouglas Gregor return C; 62edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek} 63edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek 64a60ed47da13393796d8552b9fdca12abbb3eea42Ted KremenekCXCursor cxcursor::MakeCXCursor(Stmt *S, Decl *Parent, 65a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 6654d67caeee4fdce81f07163832f1163d5f2af5d2Daniel Dunbar assert(S && TU && "Invalid arguments!"); 6797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor CXCursorKind K = CXCursor_NotImplemented; 6897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor 6997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor switch (S->getStmtClass()) { 7097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::NoStmtClass: 7197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor break; 7297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor 7397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::NullStmtClass: 7497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CompoundStmtClass: 7597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CaseStmtClass: 7697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::DefaultStmtClass: 7797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::IfStmtClass: 7897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::SwitchStmtClass: 7997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::WhileStmtClass: 8097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::DoStmtClass: 8197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ForStmtClass: 8297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::GotoStmtClass: 8397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::IndirectGotoStmtClass: 8497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ContinueStmtClass: 8597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::BreakStmtClass: 8697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ReturnStmtClass: 8797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::DeclStmtClass: 8897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::SwitchCaseClass: 8997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::AsmStmtClass: 9097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCAtTryStmtClass: 9197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCAtCatchStmtClass: 9297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCAtFinallyStmtClass: 9397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCAtThrowStmtClass: 9497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCAtSynchronizedStmtClass: 9597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCForCollectionStmtClass: 9697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXCatchStmtClass: 9797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXTryStmtClass: 9897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor K = CXCursor_UnexposedStmt; 9997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor break; 10097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor 10136897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor case Stmt::LabelStmtClass: 10236897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor K = CXCursor_LabelStmt; 10336897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor break; 10436897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor 10597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::PredefinedExprClass: 10697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::IntegerLiteralClass: 10797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::FloatingLiteralClass: 10897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ImaginaryLiteralClass: 10997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::StringLiteralClass: 11097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CharacterLiteralClass: 11197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ParenExprClass: 1128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor case Stmt::UnaryOperatorClass: 1138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor case Stmt::OffsetOfExprClass: 11497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::SizeOfAlignOfExprClass: 11597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ArraySubscriptExprClass: 11697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::BinaryOperatorClass: 11797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CompoundAssignOperatorClass: 11897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ConditionalOperatorClass: 11997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ImplicitCastExprClass: 12097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CStyleCastExprClass: 12197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CompoundLiteralExprClass: 12297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ExtVectorElementExprClass: 12397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::InitListExprClass: 12497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::DesignatedInitExprClass: 12597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ImplicitValueInitExprClass: 12697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ParenListExprClass: 12797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::VAArgExprClass: 12897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::AddrLabelExprClass: 12997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::StmtExprClass: 13097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::TypesCompatibleExprClass: 13197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ChooseExprClass: 13297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::GNUNullExprClass: 13397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXStaticCastExprClass: 13497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXDynamicCastExprClass: 13597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXReinterpretCastExprClass: 13697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXConstCastExprClass: 13797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXFunctionalCastExprClass: 13897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXTypeidExprClass: 1399be88403e965cc49af76c9d33d818781d44b333eFrancois Pichet case Stmt::CXXUuidofExprClass: 14097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXBoolLiteralExprClass: 14197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXNullPtrLiteralExprClass: 14297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXThisExprClass: 14397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXThrowExprClass: 14497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXDefaultArgExprClass: 145ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor case Stmt::CXXScalarValueInitExprClass: 14697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXNewExprClass: 14797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXDeleteExprClass: 14897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXPseudoDestructorExprClass: 14997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::UnresolvedLookupExprClass: 15097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::UnaryTypeTraitExprClass: 15197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::DependentScopeDeclRefExprClass: 15297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXBindTemporaryExprClass: 15397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXExprWithTemporariesClass: 15497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXUnresolvedConstructExprClass: 15597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXDependentScopeMemberExprClass: 15697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::UnresolvedMemberExprClass: 1572e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl case Stmt::CXXNoexceptExprClass: 15897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCStringLiteralClass: 15997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCEncodeExprClass: 16097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCSelectorExprClass: 16197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCProtocolExprClass: 16297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCImplicitSetterGetterRefExprClass: 16397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCIsaExprClass: 16497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ShuffleVectorExprClass: 16597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::BlockExprClass: 1667cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall case Stmt::OpaqueValueExprClass: 16797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor K = CXCursor_UnexposedExpr; 16897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor break; 16936897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor 17097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::DeclRefExprClass: 17197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::BlockDeclRefExprClass: 17297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor // FIXME: UnresolvedLookupExpr? 17397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor // FIXME: DependentScopeDeclRefExpr? 17497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor K = CXCursor_DeclRefExpr; 17597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor break; 17697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor 17797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::MemberExprClass: 17897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCIvarRefExprClass: 17997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCPropertyRefExprClass: 18097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor // FIXME: UnresolvedMemberExpr? 18197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor // FIXME: CXXDependentScopeMemberExpr? 18297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor K = CXCursor_MemberRefExpr; 18397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor break; 18497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor 18597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CallExprClass: 18697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXOperatorCallExprClass: 18797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXMemberCallExprClass: 18897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXConstructExprClass: 18997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXTemporaryObjectExprClass: 19097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor // FIXME: CXXUnresolvedConstructExpr 19197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor // FIXME: ObjCImplicitSetterGetterRefExpr? 19297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor K = CXCursor_CallExpr; 19397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor break; 19497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor 19597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCMessageExprClass: 19697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor K = CXCursor_ObjCMessageExpr; 19797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor break; 19897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor } 19997b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor 200b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor CXCursor C = { K, { Parent, S, TU } }; 20197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor return C; 20297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor} 20397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor 2042e331b938b38057e333fab0ba841130ea8467794Douglas GregorCXCursor cxcursor::MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super, 205b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor SourceLocation Loc, 206a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 20754d67caeee4fdce81f07163832f1163d5f2af5d2Daniel Dunbar assert(Super && TU && "Invalid arguments!"); 2082e331b938b38057e333fab0ba841130ea8467794Douglas Gregor void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 209b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor CXCursor C = { CXCursor_ObjCSuperClassRef, { Super, RawLoc, TU } }; 2102e331b938b38057e333fab0ba841130ea8467794Douglas Gregor return C; 2112e331b938b38057e333fab0ba841130ea8467794Douglas Gregor} 2122e331b938b38057e333fab0ba841130ea8467794Douglas Gregor 2132e331b938b38057e333fab0ba841130ea8467794Douglas Gregorstd::pair<ObjCInterfaceDecl *, SourceLocation> 2142e331b938b38057e333fab0ba841130ea8467794Douglas Gregorcxcursor::getCursorObjCSuperClassRef(CXCursor C) { 2152e331b938b38057e333fab0ba841130ea8467794Douglas Gregor assert(C.kind == CXCursor_ObjCSuperClassRef); 2162e331b938b38057e333fab0ba841130ea8467794Douglas Gregor return std::make_pair(static_cast<ObjCInterfaceDecl *>(C.data[0]), 2172e331b938b38057e333fab0ba841130ea8467794Douglas Gregor SourceLocation::getFromRawEncoding( 2182e331b938b38057e333fab0ba841130ea8467794Douglas Gregor reinterpret_cast<uintptr_t>(C.data[1]))); 2192e331b938b38057e333fab0ba841130ea8467794Douglas Gregor} 2202e331b938b38057e333fab0ba841130ea8467794Douglas Gregor 22178db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas GregorCXCursor cxcursor::MakeCursorObjCProtocolRef(ObjCProtocolDecl *Super, 222b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor SourceLocation Loc, 223a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 22454d67caeee4fdce81f07163832f1163d5f2af5d2Daniel Dunbar assert(Super && TU && "Invalid arguments!"); 22578db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 226b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor CXCursor C = { CXCursor_ObjCProtocolRef, { Super, RawLoc, TU } }; 22778db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor return C; 22878db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor} 22978db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor 23078db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregorstd::pair<ObjCProtocolDecl *, SourceLocation> 23178db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregorcxcursor::getCursorObjCProtocolRef(CXCursor C) { 23278db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor assert(C.kind == CXCursor_ObjCProtocolRef); 23378db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor return std::make_pair(static_cast<ObjCProtocolDecl *>(C.data[0]), 23478db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor SourceLocation::getFromRawEncoding( 23578db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor reinterpret_cast<uintptr_t>(C.data[1]))); 23678db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor} 23778db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor 2381adb082a709f7b588f03672999294e061234b2cfDouglas GregorCXCursor cxcursor::MakeCursorObjCClassRef(ObjCInterfaceDecl *Class, 239b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor SourceLocation Loc, 240a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 241ebfa339321f8a4df9d5011e591a615d5765107d5Ted Kremenek // 'Class' can be null for invalid code. 242ebfa339321f8a4df9d5011e591a615d5765107d5Ted Kremenek if (!Class) 243ebfa339321f8a4df9d5011e591a615d5765107d5Ted Kremenek return MakeCXCursorInvalid(CXCursor_InvalidCode); 244ebfa339321f8a4df9d5011e591a615d5765107d5Ted Kremenek assert(TU && "Invalid arguments!"); 2451adb082a709f7b588f03672999294e061234b2cfDouglas Gregor void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 246b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor CXCursor C = { CXCursor_ObjCClassRef, { Class, RawLoc, TU } }; 2471adb082a709f7b588f03672999294e061234b2cfDouglas Gregor return C; 2481adb082a709f7b588f03672999294e061234b2cfDouglas Gregor} 2491adb082a709f7b588f03672999294e061234b2cfDouglas Gregor 2501adb082a709f7b588f03672999294e061234b2cfDouglas Gregorstd::pair<ObjCInterfaceDecl *, SourceLocation> 2511adb082a709f7b588f03672999294e061234b2cfDouglas Gregorcxcursor::getCursorObjCClassRef(CXCursor C) { 2521adb082a709f7b588f03672999294e061234b2cfDouglas Gregor assert(C.kind == CXCursor_ObjCClassRef); 2531adb082a709f7b588f03672999294e061234b2cfDouglas Gregor return std::make_pair(static_cast<ObjCInterfaceDecl *>(C.data[0]), 2541adb082a709f7b588f03672999294e061234b2cfDouglas Gregor SourceLocation::getFromRawEncoding( 2551adb082a709f7b588f03672999294e061234b2cfDouglas Gregor reinterpret_cast<uintptr_t>(C.data[1]))); 2561adb082a709f7b588f03672999294e061234b2cfDouglas Gregor} 2571adb082a709f7b588f03672999294e061234b2cfDouglas Gregor 2587d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas GregorCXCursor cxcursor::MakeCursorTypeRef(TypeDecl *Type, SourceLocation Loc, 259a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 26054d67caeee4fdce81f07163832f1163d5f2af5d2Daniel Dunbar assert(Type && TU && "Invalid arguments!"); 2617d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 2627d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor CXCursor C = { CXCursor_TypeRef, { Type, RawLoc, TU } }; 2637d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor return C; 2647d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor} 2657d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor 2667d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregorstd::pair<TypeDecl *, SourceLocation> 2677d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregorcxcursor::getCursorTypeRef(CXCursor C) { 2687d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor assert(C.kind == CXCursor_TypeRef); 2697d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor return std::make_pair(static_cast<TypeDecl *>(C.data[0]), 2707d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor SourceLocation::getFromRawEncoding( 2717d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor reinterpret_cast<uintptr_t>(C.data[1]))); 2727d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor} 2737d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor 2740b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas GregorCXCursor cxcursor::MakeCursorTemplateRef(TemplateDecl *Template, 275a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek SourceLocation Loc, 276a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 2770b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor assert(Template && TU && "Invalid arguments!"); 2780b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 2790b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor CXCursor C = { CXCursor_TemplateRef, { Template, RawLoc, TU } }; 2800b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor return C; 2810b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor} 2820b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor 2830b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregorstd::pair<TemplateDecl *, SourceLocation> 2840b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregorcxcursor::getCursorTemplateRef(CXCursor C) { 2850b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor assert(C.kind == CXCursor_TemplateRef); 2860b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor return std::make_pair(static_cast<TemplateDecl *>(C.data[0]), 2870b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor SourceLocation::getFromRawEncoding( 2880b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor reinterpret_cast<uintptr_t>(C.data[1]))); 2890b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor} 2900b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor 2916931900f43cea558c6974075256c07728dbfecc6Douglas GregorCXCursor cxcursor::MakeCursorNamespaceRef(NamedDecl *NS, SourceLocation Loc, 292a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 2936931900f43cea558c6974075256c07728dbfecc6Douglas Gregor 2946931900f43cea558c6974075256c07728dbfecc6Douglas Gregor assert(NS && (isa<NamespaceDecl>(NS) || isa<NamespaceAliasDecl>(NS)) && TU && 2956931900f43cea558c6974075256c07728dbfecc6Douglas Gregor "Invalid arguments!"); 2966931900f43cea558c6974075256c07728dbfecc6Douglas Gregor void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 2976931900f43cea558c6974075256c07728dbfecc6Douglas Gregor CXCursor C = { CXCursor_NamespaceRef, { NS, RawLoc, TU } }; 2986931900f43cea558c6974075256c07728dbfecc6Douglas Gregor return C; 2996931900f43cea558c6974075256c07728dbfecc6Douglas Gregor} 3006931900f43cea558c6974075256c07728dbfecc6Douglas Gregor 3016931900f43cea558c6974075256c07728dbfecc6Douglas Gregorstd::pair<NamedDecl *, SourceLocation> 3026931900f43cea558c6974075256c07728dbfecc6Douglas Gregorcxcursor::getCursorNamespaceRef(CXCursor C) { 3036931900f43cea558c6974075256c07728dbfecc6Douglas Gregor assert(C.kind == CXCursor_NamespaceRef); 3046931900f43cea558c6974075256c07728dbfecc6Douglas Gregor return std::make_pair(static_cast<NamedDecl *>(C.data[0]), 3056931900f43cea558c6974075256c07728dbfecc6Douglas Gregor SourceLocation::getFromRawEncoding( 3066931900f43cea558c6974075256c07728dbfecc6Douglas Gregor reinterpret_cast<uintptr_t>(C.data[1]))); 3076931900f43cea558c6974075256c07728dbfecc6Douglas Gregor} 3086931900f43cea558c6974075256c07728dbfecc6Douglas Gregor 309a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas GregorCXCursor cxcursor::MakeCursorMemberRef(FieldDecl *Field, SourceLocation Loc, 310a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 311a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor 312a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor assert(Field && TU && "Invalid arguments!"); 313a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 314a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor CXCursor C = { CXCursor_MemberRef, { Field, RawLoc, TU } }; 315a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor return C; 316a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor} 317a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor 318a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregorstd::pair<FieldDecl *, SourceLocation> 319a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregorcxcursor::getCursorMemberRef(CXCursor C) { 320a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor assert(C.kind == CXCursor_MemberRef); 321a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor return std::make_pair(static_cast<FieldDecl *>(C.data[0]), 322a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor SourceLocation::getFromRawEncoding( 323a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor reinterpret_cast<uintptr_t>(C.data[1]))); 324a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor} 325a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor 326a60ed47da13393796d8552b9fdca12abbb3eea42Ted KremenekCXCursor cxcursor::MakeCursorCXXBaseSpecifier(CXXBaseSpecifier *B, 327a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU){ 3283064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek CXCursor C = { CXCursor_CXXBaseSpecifier, { B, 0, TU } }; 3293064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek return C; 3303064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek} 3313064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek 3323064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed KremenekCXXBaseSpecifier *cxcursor::getCursorCXXBaseSpecifier(CXCursor C) { 3333064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek assert(C.kind == CXCursor_CXXBaseSpecifier); 3343064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek return static_cast<CXXBaseSpecifier*>(C.data[0]); 3353064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek} 3363064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek 3379f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas GregorCXCursor cxcursor::MakePreprocessingDirectiveCursor(SourceRange Range, 338a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 3399f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor CXCursor C = { CXCursor_PreprocessingDirective, 3409f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor { reinterpret_cast<void *>(Range.getBegin().getRawEncoding()), 3419f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor reinterpret_cast<void *>(Range.getEnd().getRawEncoding()), 3429f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor TU } 3439f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor }; 3449f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor return C; 3459f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor} 3469f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor 3479f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas GregorSourceRange cxcursor::getCursorPreprocessingDirective(CXCursor C) { 3489f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor assert(C.kind == CXCursor_PreprocessingDirective); 3499f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor return SourceRange(SourceLocation::getFromRawEncoding( 3509f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor reinterpret_cast<uintptr_t> (C.data[0])), 3514807231938d8aff28de09f78f301f9ba5845e5e4Douglas Gregor SourceLocation::getFromRawEncoding( 3524807231938d8aff28de09f78f301f9ba5845e5e4Douglas Gregor reinterpret_cast<uintptr_t> (C.data[1]))); 3534807231938d8aff28de09f78f301f9ba5845e5e4Douglas Gregor} 3544807231938d8aff28de09f78f301f9ba5845e5e4Douglas Gregor 355a60ed47da13393796d8552b9fdca12abbb3eea42Ted KremenekCXCursor cxcursor::MakeMacroDefinitionCursor(MacroDefinition *MI, 356a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 357572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor CXCursor C = { CXCursor_MacroDefinition, { MI, 0, TU } }; 358572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor return C; 359572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor} 360572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor 361572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas GregorMacroDefinition *cxcursor::getCursorMacroDefinition(CXCursor C) { 362572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor assert(C.kind == CXCursor_MacroDefinition); 363572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor return static_cast<MacroDefinition *>(C.data[0]); 364572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor} 365572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor 3664ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas GregorCXCursor cxcursor::MakeMacroInstantiationCursor(MacroInstantiation *MI, 367a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 3684ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor CXCursor C = { CXCursor_MacroInstantiation, { MI, 0, TU } }; 3694807231938d8aff28de09f78f301f9ba5845e5e4Douglas Gregor return C; 3704807231938d8aff28de09f78f301f9ba5845e5e4Douglas Gregor} 3714807231938d8aff28de09f78f301f9ba5845e5e4Douglas Gregor 3724ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas GregorMacroInstantiation *cxcursor::getCursorMacroInstantiation(CXCursor C) { 3734807231938d8aff28de09f78f301f9ba5845e5e4Douglas Gregor assert(C.kind == CXCursor_MacroInstantiation); 3744ae8f298b1ea51b4c2234f9148e2e4349c9bdd23Douglas Gregor return static_cast<MacroInstantiation *>(C.data[0]); 3759f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor} 3769f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor 377ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas GregorCXCursor cxcursor::MakeInclusionDirectiveCursor(InclusionDirective *ID, 378a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 379ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor CXCursor C = { CXCursor_InclusionDirective, { ID, 0, TU } }; 380ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor return C; 381ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor} 382ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor 383ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas GregorInclusionDirective *cxcursor::getCursorInclusionDirective(CXCursor C) { 384ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor assert(C.kind == CXCursor_InclusionDirective); 385ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor return static_cast<InclusionDirective *>(C.data[0]); 386ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor} 387ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor 38836897b05ca2886e287f01802614bc10cbadcec22Douglas GregorCXCursor cxcursor::MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc, 389a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 39036897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor 39136897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor assert(Label && TU && "Invalid arguments!"); 39236897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 39336897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor CXCursor C = { CXCursor_LabelRef, { Label, RawLoc, TU } }; 39436897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor return C; 39536897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor} 39636897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor 39736897b05ca2886e287f01802614bc10cbadcec22Douglas Gregorstd::pair<LabelStmt*, SourceLocation> 39836897b05ca2886e287f01802614bc10cbadcec22Douglas Gregorcxcursor::getCursorLabelRef(CXCursor C) { 39936897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor assert(C.kind == CXCursor_LabelRef); 40036897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor return std::make_pair(static_cast<LabelStmt *>(C.data[0]), 40136897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor SourceLocation::getFromRawEncoding( 40236897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor reinterpret_cast<uintptr_t>(C.data[1]))); 40336897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor} 40436897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor 4051f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas GregorCXCursor cxcursor::MakeCursorOverloadedDeclRef(OverloadExpr *E, 406a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 4071f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor assert(E && TU && "Invalid arguments!"); 4081f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor OverloadedDeclRefStorage Storage(E); 4091f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor void *RawLoc = reinterpret_cast<void *>(E->getNameLoc().getRawEncoding()); 4101f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor CXCursor C = { 4111f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor CXCursor_OverloadedDeclRef, 4121f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor { Storage.getOpaqueValue(), RawLoc, TU } 4131f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor }; 4141f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor return C; 4151f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor} 4161f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor 4171f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas GregorCXCursor cxcursor::MakeCursorOverloadedDeclRef(Decl *D, 4181f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor SourceLocation Loc, 419a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 4201f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor assert(D && TU && "Invalid arguments!"); 4211f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 4221f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor OverloadedDeclRefStorage Storage(D); 4231f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor CXCursor C = { 4241f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor CXCursor_OverloadedDeclRef, 4251f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor { Storage.getOpaqueValue(), RawLoc, TU } 4261f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor }; 4271f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor return C; 4281f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor} 4291f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor 4301f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas GregorCXCursor cxcursor::MakeCursorOverloadedDeclRef(TemplateName Name, 4311f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor SourceLocation Loc, 432a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 4331f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor assert(Name.getAsOverloadedTemplate() && TU && "Invalid arguments!"); 4341f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 4351f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor OverloadedDeclRefStorage Storage(Name.getAsOverloadedTemplate()); 4361f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor CXCursor C = { 4371f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor CXCursor_OverloadedDeclRef, 4381f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor { Storage.getOpaqueValue(), RawLoc, TU } 4391f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor }; 4401f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor return C; 4411f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor} 4421f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor 4431f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregorstd::pair<cxcursor::OverloadedDeclRefStorage, SourceLocation> 4441f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregorcxcursor::getCursorOverloadedDeclRef(CXCursor C) { 4451f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor assert(C.kind == CXCursor_OverloadedDeclRef); 4461f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor return std::make_pair(OverloadedDeclRefStorage::getFromOpaqueValue(C.data[0]), 4471f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor SourceLocation::getFromRawEncoding( 4481f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor reinterpret_cast<uintptr_t>(C.data[1]))); 4491f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor} 4501f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor 451283cae37b03047c14ef918503bc46b08405c3b69Douglas GregorDecl *cxcursor::getCursorDecl(CXCursor Cursor) { 452283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor return (Decl *)Cursor.data[0]; 453283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor} 454283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor 455283cae37b03047c14ef918503bc46b08405c3b69Douglas GregorExpr *cxcursor::getCursorExpr(CXCursor Cursor) { 456283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor return dyn_cast_or_null<Expr>(getCursorStmt(Cursor)); 457283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor} 458283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor 459283cae37b03047c14ef918503bc46b08405c3b69Douglas GregorStmt *cxcursor::getCursorStmt(CXCursor Cursor) { 46078db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor if (Cursor.kind == CXCursor_ObjCSuperClassRef || 4611adb082a709f7b588f03672999294e061234b2cfDouglas Gregor Cursor.kind == CXCursor_ObjCProtocolRef || 4621adb082a709f7b588f03672999294e061234b2cfDouglas Gregor Cursor.kind == CXCursor_ObjCClassRef) 4632e331b938b38057e333fab0ba841130ea8467794Douglas Gregor return 0; 4642e331b938b38057e333fab0ba841130ea8467794Douglas Gregor 465283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor return (Stmt *)Cursor.data[1]; 466283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor} 467283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor 46895f33555a6d51b6537a9ed3968c3d1c2e4991b51Ted KremenekAttr *cxcursor::getCursorAttr(CXCursor Cursor) { 46995f33555a6d51b6537a9ed3968c3d1c2e4991b51Ted Kremenek return (Attr *)Cursor.data[1]; 47095f33555a6d51b6537a9ed3968c3d1c2e4991b51Ted Kremenek} 47195f33555a6d51b6537a9ed3968c3d1c2e4991b51Ted Kremenek 472f46034af49435a4d1a0085a4738343122aeb6521Douglas GregorASTContext &cxcursor::getCursorContext(CXCursor Cursor) { 473b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor return getCursorASTUnit(Cursor)->getASTContext(); 474b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor} 47597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor 476b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas GregorASTUnit *cxcursor::getCursorASTUnit(CXCursor Cursor) { 477a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek return static_cast<ASTUnit *>(static_cast<CXTranslationUnit>(Cursor.data[2]) 478a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek ->TUData); 479a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek} 480a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek 481a60ed47da13393796d8552b9fdca12abbb3eea42Ted KremenekCXTranslationUnit cxcursor::getCursorTU(CXCursor Cursor) { 482a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek return static_cast<CXTranslationUnit>(Cursor.data[2]); 483283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor} 484283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor 485283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregorbool cxcursor::operator==(CXCursor X, CXCursor Y) { 486283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor return X.kind == Y.kind && X.data[0] == Y.data[0] && X.data[1] == Y.data[1] && 487283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor X.data[2] == Y.data[2]; 4882e331b938b38057e333fab0ba841130ea8467794Douglas Gregor} 489007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek 490007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek// FIXME: Remove once we can model DeclGroups and their appropriate ranges 491007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek// properly in the ASTs. 492007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenekbool cxcursor::isFirstInDeclGroup(CXCursor C) { 493007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek assert(clang_isDeclaration(C.kind)); 494007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek return ((uintptr_t) (C.data[1])) != 0; 495007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek} 496007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek 497