CXCursor.cpp revision 011d8b93b7cfa8492b8a9c909a850d6577e08dca
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 160a90d32523bfe5fa63e11b648686c9699f786d15Ted Kremenek#include "CXTranslationUnit.h" 1716c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek#include "CXCursor.h" 18ed122735639d83c10f18c28c7fd117bfcd0f62cbTed Kremenek#include "CXString.h" 197eaa8ae8692c5cd3eed8cb334fe5346470522091Douglas Gregor#include "clang/Frontend/ASTUnit.h" 2016c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek#include "clang/AST/Decl.h" 216931900f43cea558c6974075256c07728dbfecc6Douglas Gregor#include "clang/AST/DeclCXX.h" 22283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor#include "clang/AST/DeclObjC.h" 23aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis#include "clang/AST/DeclTemplate.h" 24283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor#include "clang/AST/Expr.h" 251f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor#include "clang/AST/ExprCXX.h" 26aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis#include "clang/AST/ExprObjC.h" 27007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek#include "clang-c/Index.h" 28edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek#include "llvm/Support/ErrorHandling.h" 2916c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek 3016c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenekusing namespace clang; 311f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregorusing namespace cxcursor; 3216c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek 335bfb8c128c2ac8eb4032afc180cdc400a0f953caDouglas GregorCXCursor cxcursor::MakeCXCursorInvalid(CXCursorKind K) { 345bfb8c128c2ac8eb4032afc180cdc400a0f953caDouglas Gregor assert(K >= CXCursor_FirstInvalid && K <= CXCursor_LastInvalid); 35aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis CXCursor C = { K, 0, { 0, 0, 0 } }; 365bfb8c128c2ac8eb4032afc180cdc400a0f953caDouglas Gregor return C; 3716c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek} 3816c440a377b7ec8b722a2e2c7c864f75c95bd305Ted Kremenek 39e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenekstatic CXCursorKind GetCursorKind(const Attr *A) { 40e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek assert(A && "Invalid arguments!"); 41e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek switch (A->getKind()) { 42e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek default: break; 43387475d0c18aaeb022108de9d33b6c9fb7998843Sean Hunt case attr::IBAction: return CXCursor_IBActionAttr; 44387475d0c18aaeb022108de9d33b6c9fb7998843Sean Hunt case attr::IBOutlet: return CXCursor_IBOutletAttr; 45387475d0c18aaeb022108de9d33b6c9fb7998843Sean Hunt case attr::IBOutletCollection: return CXCursor_IBOutletCollectionAttr; 466639e9255489ad8e10278d5658fdd4b3c0e1e4cdArgyrios Kyrtzidis case attr::Final: return CXCursor_CXXFinalAttr; 476639e9255489ad8e10278d5658fdd4b3c0e1e4cdArgyrios Kyrtzidis case attr::Override: return CXCursor_CXXOverrideAttr; 485f1c822def3efffe1d8f7299fbbbc3b1cdd4833dErik Verbruggen case attr::Annotate: return CXCursor_AnnotateAttr; 4984b796492de8a708150dd3f86ae191041d42eef9Argyrios Kyrtzidis case attr::AsmLabel: return CXCursor_AsmLabelAttr; 50e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek } 51e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek 52e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek return CXCursor_UnexposedAttr; 53e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek} 54e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek 55a60ed47da13393796d8552b9fdca12abbb3eea42Ted KremenekCXCursor cxcursor::MakeCXCursor(const Attr *A, Decl *Parent, 56a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 57e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek assert(A && Parent && TU && "Invalid arguments!"); 58aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis CXCursor C = { GetCursorKind(A), 0, { Parent, (void*)A, TU } }; 59e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek return C; 60e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek} 61e77f443dbca8cdc23e5aa94a2653367e4a7cbe47Ted Kremenek 62a60ed47da13393796d8552b9fdca12abbb3eea42Ted KremenekCXCursor cxcursor::MakeCXCursor(Decl *D, CXTranslationUnit TU, 63aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis SourceRange RegionOfInterest, 64007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek bool FirstInDeclGroup) { 6554d67caeee4fdce81f07163832f1163d5f2af5d2Daniel Dunbar assert(D && TU && "Invalid arguments!"); 66aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis 67aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis CXCursorKind K = getCursorKindForDecl(D); 68aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis 69aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis if (K == CXCursor_ObjCClassMethodDecl || 70aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis K == CXCursor_ObjCInstanceMethodDecl) { 71aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis int SelectorIdIndex = -1; 72aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis // Check if cursor points to a selector id. 73aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis if (RegionOfInterest.isValid() && 74aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis RegionOfInterest.getBegin() == RegionOfInterest.getEnd()) { 75aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis SmallVector<SourceLocation, 16> SelLocs; 76aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis cast<ObjCMethodDecl>(D)->getSelectorLocs(SelLocs); 77aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis SmallVector<SourceLocation, 16>::iterator 78aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis I=std::find(SelLocs.begin(), SelLocs.end(),RegionOfInterest.getBegin()); 79aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis if (I != SelLocs.end()) 80aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis SelectorIdIndex = I - SelLocs.begin(); 81aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis } 82aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis CXCursor C = { K, SelectorIdIndex, 83aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis { D, (void*)(intptr_t) (FirstInDeclGroup ? 1 : 0), TU }}; 84aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis return C; 85aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis } 86aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis 87aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis CXCursor C = { K, 0, { D, (void*)(intptr_t) (FirstInDeclGroup ? 1 : 0), TU }}; 885bfb8c128c2ac8eb4032afc180cdc400a0f953caDouglas Gregor return C; 89edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek} 90edc8aa68ef91aeea686c5aadf64ef902c38318ddTed Kremenek 91aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios KyrtzidisCXCursor cxcursor::MakeCXCursor(Stmt *S, Decl *Parent, CXTranslationUnit TU, 92aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis SourceRange RegionOfInterest) { 9354d67caeee4fdce81f07163832f1163d5f2af5d2Daniel Dunbar assert(S && TU && "Invalid arguments!"); 9497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor CXCursorKind K = CXCursor_NotImplemented; 9597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor 9697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor switch (S->getStmtClass()) { 9797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::NoStmtClass: 9897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor break; 9942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 10097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CaseStmtClass: 10142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_CaseStmt; 10242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 10342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 10497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::DefaultStmtClass: 10542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_DefaultStmt; 10642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 10742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 10842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::IfStmtClass: 10942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_IfStmt; 11042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 11142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 11242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::SwitchStmtClass: 11342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_SwitchStmt; 11442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 11542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 11642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::WhileStmtClass: 11742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_WhileStmt; 11842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 11942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 12042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::DoStmtClass: 12142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_DoStmt; 12242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 12342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 12442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::ForStmtClass: 12542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_ForStmt; 12642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 12742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 12842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::GotoStmtClass: 12942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_GotoStmt; 13042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 13142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 13297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::IndirectGotoStmtClass: 13342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_IndirectGotoStmt; 13442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 13542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 13642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::ContinueStmtClass: 13742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_ContinueStmt; 13842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 13942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 14042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::BreakStmtClass: 14142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_BreakStmt; 14242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 14342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 14442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::ReturnStmtClass: 14542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_ReturnStmt; 14642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 14742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 14842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::AsmStmtClass: 14942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_AsmStmt; 15042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 15142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 15242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::ObjCAtTryStmtClass: 15342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_ObjCAtTryStmt; 15442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 15542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 15642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::ObjCAtCatchStmtClass: 15742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_ObjCAtCatchStmt; 15842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 15942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 16042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::ObjCAtFinallyStmtClass: 16142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_ObjCAtFinallyStmt; 16242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 16342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 16442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::ObjCAtThrowStmtClass: 16542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_ObjCAtThrowStmt; 16642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 16742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 16842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::ObjCAtSynchronizedStmtClass: 16942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_ObjCAtSynchronizedStmt; 17042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 17142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 17242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::ObjCAutoreleasePoolStmtClass: 17342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_ObjCAutoreleasePoolStmt; 17442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 17542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 17697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCForCollectionStmtClass: 17742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_ObjCForCollectionStmt; 17842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 17942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 18097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXCatchStmtClass: 18142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_CXXCatchStmt; 18242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 18342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 18442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::CXXTryStmtClass: 18542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_CXXTryStmt; 18642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 18742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 18842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::CXXForRangeStmtClass: 18942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_CXXForRangeStmt; 19042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 19142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 19228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley case Stmt::SEHTryStmtClass: 19342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_SEHTryStmt; 19442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 19542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 19628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley case Stmt::SEHExceptStmtClass: 19742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_SEHExceptStmt; 19842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 19942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 20028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley case Stmt::SEHFinallyStmtClass: 20142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_SEHFinallyStmt; 20242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 20342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 20442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::ArrayTypeTraitExprClass: 20542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::AsTypeExprClass: 206276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman case Stmt::AtomicExprClass: 20742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::BinaryConditionalOperatorClass: 20842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::BinaryTypeTraitExprClass: 20942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::CXXBindTemporaryExprClass: 21042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::CXXDefaultArgExprClass: 21142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::CXXScalarValueInitExprClass: 21242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::CXXUuidofExprClass: 21342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::ChooseExprClass: 21442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::DesignatedInitExprClass: 21542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::ExprWithCleanupsClass: 21642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::ExpressionTraitExprClass: 21742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::ExtVectorElementExprClass: 21842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::ImplicitCastExprClass: 21942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::ImplicitValueInitExprClass: 22003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor case Stmt::MaterializeTemporaryExprClass: 22142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::ObjCIndirectCopyRestoreExprClass: 22242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::OffsetOfExprClass: 22342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::ParenListExprClass: 22442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::PredefinedExprClass: 22542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::ShuffleVectorExprClass: 22642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::UnaryExprOrTypeTraitExprClass: 22742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::UnaryTypeTraitExprClass: 22842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::VAArgExprClass: 22942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_UnexposedExpr; 23042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 23142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 2324b9c2d235fb9449e249d74f48ecfec601650de93John McCall case Stmt::OpaqueValueExprClass: 2334b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (Expr *Src = cast<OpaqueValueExpr>(S)->getSourceExpr()) 2344b9c2d235fb9449e249d74f48ecfec601650de93John McCall return MakeCXCursor(Src, Parent, TU, RegionOfInterest); 2354b9c2d235fb9449e249d74f48ecfec601650de93John McCall K = CXCursor_UnexposedExpr; 2364b9c2d235fb9449e249d74f48ecfec601650de93John McCall break; 2374b9c2d235fb9449e249d74f48ecfec601650de93John McCall 2384b9c2d235fb9449e249d74f48ecfec601650de93John McCall case Stmt::PseudoObjectExprClass: 2394b9c2d235fb9449e249d74f48ecfec601650de93John McCall return MakeCXCursor(cast<PseudoObjectExpr>(S)->getSyntacticForm(), 2404b9c2d235fb9449e249d74f48ecfec601650de93John McCall Parent, TU, RegionOfInterest); 2414b9c2d235fb9449e249d74f48ecfec601650de93John McCall 24242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::CompoundStmtClass: 24342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_CompoundStmt; 24497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor break; 24597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor 24642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::NullStmtClass: 24742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_NullStmt; 24836897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor break; 24936897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor 25042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::LabelStmtClass: 25142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_LabelStmt; 25242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 25342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 25442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::DeclStmtClass: 25542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_DeclStmt; 25642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 25742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 25842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::IntegerLiteralClass: 25942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_IntegerLiteral; 26042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 26142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 26242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::FloatingLiteralClass: 26342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_FloatingLiteral; 26442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 26542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 26642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::ImaginaryLiteralClass: 26742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_ImaginaryLiteral; 26842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 26942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 27042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::StringLiteralClass: 27142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_StringLiteral; 27242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 27342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 27442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::CharacterLiteralClass: 27542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_CharacterLiteral; 27642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 27742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 27842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::ParenExprClass: 27942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_ParenExpr; 28042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 28142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 2828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor case Stmt::UnaryOperatorClass: 28342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_UnaryOperator; 28442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 28542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 28642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::CXXNoexceptExprClass: 28742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_UnaryExpr; 28842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 28942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 29042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::ArraySubscriptExprClass: 29142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_ArraySubscriptExpr; 29242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 29342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 29442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::BinaryOperatorClass: 29542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_BinaryOperator; 29642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 29742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 29897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CompoundAssignOperatorClass: 29942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_CompoundAssignOperator; 30042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 30142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 30242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::ConditionalOperatorClass: 30342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_ConditionalOperator; 30442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 30542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 30697b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CStyleCastExprClass: 30742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_CStyleCastExpr; 30842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 30942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 31042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::CompoundLiteralExprClass: 31142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_CompoundLiteralExpr; 31242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 31342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 31442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::InitListExprClass: 31542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_InitListExpr; 31642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 31742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 31842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::AddrLabelExprClass: 31942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_AddrLabelExpr; 32042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 32142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 32242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::StmtExprClass: 32342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_StmtExpr; 32442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 32542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 326f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne case Stmt::GenericSelectionExprClass: 32742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_GenericSelectionExpr; 32842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 32942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 33042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::GNUNullExprClass: 33142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_GNUNullExpr; 33242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 33342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 33442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::CXXStaticCastExprClass: 33542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_CXXStaticCastExpr; 33642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 33742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 33842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::CXXDynamicCastExprClass: 33942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_CXXDynamicCastExpr; 34042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 34142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 34242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::CXXReinterpretCastExprClass: 34342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_CXXReinterpretCastExpr; 34442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 34542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 34642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::CXXConstCastExprClass: 34742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_CXXConstCastExpr; 34842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 34942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 35097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXFunctionalCastExprClass: 35142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_CXXFunctionalCastExpr; 35242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 35342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 35442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::CXXTypeidExprClass: 35542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_CXXTypeidExpr; 35642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 35742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 35842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::CXXBoolLiteralExprClass: 35942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_CXXBoolLiteralExpr; 36042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 36142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 36242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::CXXNullPtrLiteralExprClass: 36342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_CXXNullPtrLiteralExpr; 36442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 36542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 36642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::CXXThisExprClass: 36742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_CXXThisExpr; 36842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 36942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 37042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::CXXThrowExprClass: 37142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_CXXThrowExpr; 37242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 37342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 37442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::CXXNewExprClass: 37542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_CXXNewExpr; 37642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 37742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 37842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::CXXDeleteExprClass: 37942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_CXXDeleteExpr; 38042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 38142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 38242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::ObjCStringLiteralClass: 38342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_ObjCStringLiteral; 38442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 38542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 38642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::ObjCEncodeExprClass: 38742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_ObjCEncodeExpr; 38842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 38942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 39042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::ObjCSelectorExprClass: 39142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_ObjCSelectorExpr; 39242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 39342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 39442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::ObjCProtocolExprClass: 39542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_ObjCProtocolExpr; 39642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 39742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 398f85e193739c953358c865005855253af4f68a497John McCall case Stmt::ObjCBridgedCastExprClass: 39942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_ObjCBridgedCastExpr; 40042b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 40142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 40242b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::BlockExprClass: 40342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_BlockExpr; 40442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 40542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 406be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor case Stmt::PackExpansionExprClass: 40742b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_PackExpansionExpr; 40842b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor break; 40942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 410ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor case Stmt::SizeOfPackExprClass: 41142b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor K = CXCursor_SizeOfPackExpr; 41297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor break; 41342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor 41497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::BlockDeclRefExprClass: 41542b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::DeclRefExprClass: 41642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::DependentScopeDeclRefExprClass: 41791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall case Stmt::SubstNonTypeTemplateParmExprClass: 418c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor case Stmt::SubstNonTypeTemplateParmPackExprClass: 41942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::UnresolvedLookupExprClass: 42097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor K = CXCursor_DeclRefExpr; 42197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor break; 42297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor 42342b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::CXXDependentScopeMemberExprClass: 42442b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::CXXPseudoDestructorExprClass: 42597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::MemberExprClass: 42642b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::ObjCIsaExprClass: 42797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCIvarRefExprClass: 42897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::ObjCPropertyRefExprClass: 42942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::UnresolvedMemberExprClass: 43097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor K = CXCursor_MemberRefExpr; 43197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor break; 43297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor 43397b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CallExprClass: 43497b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXOperatorCallExprClass: 43597b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXMemberCallExprClass: 436e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne case Stmt::CUDAKernelCallExprClass: 43797b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXConstructExprClass: 43897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor case Stmt::CXXTemporaryObjectExprClass: 43942b2984771a7fd1b17c78bbb2c59fed3db2f1960Douglas Gregor case Stmt::CXXUnresolvedConstructExprClass: 44097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor K = CXCursor_CallExpr; 44197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor break; 44297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor 443011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor case Stmt::LambdaExprClass: 444011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor K = CXCursor_LambdaExpr; 445011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor break; 446011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor 447ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor case Stmt::ObjCMessageExprClass: { 44897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor K = CXCursor_ObjCMessageExpr; 449aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis int SelectorIdIndex = -1; 450aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis // Check if cursor points to a selector id. 451aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis if (RegionOfInterest.isValid() && 452aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis RegionOfInterest.getBegin() == RegionOfInterest.getEnd()) { 453aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis SmallVector<SourceLocation, 16> SelLocs; 454aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis cast<ObjCMessageExpr>(S)->getSelectorLocs(SelLocs); 455aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis SmallVector<SourceLocation, 16>::iterator 456aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis I=std::find(SelLocs.begin(), SelLocs.end(),RegionOfInterest.getBegin()); 457aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis if (I != SelLocs.end()) 458aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis SelectorIdIndex = I - SelLocs.begin(); 459aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis } 460aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis CXCursor C = { K, 0, { Parent, S, TU } }; 461aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis return getSelectorIdentifierCursor(SelectorIdIndex, C); 46297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor } 463ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 464ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor case Stmt::MSDependentExistsStmtClass: 465ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor K = CXCursor_UnexposedStmt; 466ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor break; 467ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor } 46897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor 469aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis CXCursor C = { K, 0, { Parent, S, TU } }; 47097b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor return C; 47197b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor} 47297b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor 4732e331b938b38057e333fab0ba841130ea8467794Douglas GregorCXCursor cxcursor::MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super, 474b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor SourceLocation Loc, 475a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 47654d67caeee4fdce81f07163832f1163d5f2af5d2Daniel Dunbar assert(Super && TU && "Invalid arguments!"); 4772e331b938b38057e333fab0ba841130ea8467794Douglas Gregor void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 478aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis CXCursor C = { CXCursor_ObjCSuperClassRef, 0, { Super, RawLoc, TU } }; 4792e331b938b38057e333fab0ba841130ea8467794Douglas Gregor return C; 4802e331b938b38057e333fab0ba841130ea8467794Douglas Gregor} 4812e331b938b38057e333fab0ba841130ea8467794Douglas Gregor 4822e331b938b38057e333fab0ba841130ea8467794Douglas Gregorstd::pair<ObjCInterfaceDecl *, SourceLocation> 4832e331b938b38057e333fab0ba841130ea8467794Douglas Gregorcxcursor::getCursorObjCSuperClassRef(CXCursor C) { 4842e331b938b38057e333fab0ba841130ea8467794Douglas Gregor assert(C.kind == CXCursor_ObjCSuperClassRef); 4852e331b938b38057e333fab0ba841130ea8467794Douglas Gregor return std::make_pair(static_cast<ObjCInterfaceDecl *>(C.data[0]), 4862e331b938b38057e333fab0ba841130ea8467794Douglas Gregor SourceLocation::getFromRawEncoding( 4872e331b938b38057e333fab0ba841130ea8467794Douglas Gregor reinterpret_cast<uintptr_t>(C.data[1]))); 4882e331b938b38057e333fab0ba841130ea8467794Douglas Gregor} 4892e331b938b38057e333fab0ba841130ea8467794Douglas Gregor 4904e7064fa7e344e8f87a5b8457e96dfdd252c4a9eArgyrios KyrtzidisCXCursor cxcursor::MakeCursorObjCProtocolRef(const ObjCProtocolDecl *Proto, 491b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor SourceLocation Loc, 492a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 4934e7064fa7e344e8f87a5b8457e96dfdd252c4a9eArgyrios Kyrtzidis assert(Proto && TU && "Invalid arguments!"); 49478db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 4954e7064fa7e344e8f87a5b8457e96dfdd252c4a9eArgyrios Kyrtzidis CXCursor C = { CXCursor_ObjCProtocolRef, 0, { (void*)Proto, RawLoc, TU } }; 49678db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor return C; 49778db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor} 49878db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor 49978db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregorstd::pair<ObjCProtocolDecl *, SourceLocation> 50078db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregorcxcursor::getCursorObjCProtocolRef(CXCursor C) { 50178db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor assert(C.kind == CXCursor_ObjCProtocolRef); 50278db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor return std::make_pair(static_cast<ObjCProtocolDecl *>(C.data[0]), 50378db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor SourceLocation::getFromRawEncoding( 50478db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor reinterpret_cast<uintptr_t>(C.data[1]))); 50578db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor} 50678db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor 5074e7064fa7e344e8f87a5b8457e96dfdd252c4a9eArgyrios KyrtzidisCXCursor cxcursor::MakeCursorObjCClassRef(const ObjCInterfaceDecl *Class, 508b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor SourceLocation Loc, 509a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 510ebfa339321f8a4df9d5011e591a615d5765107d5Ted Kremenek // 'Class' can be null for invalid code. 511ebfa339321f8a4df9d5011e591a615d5765107d5Ted Kremenek if (!Class) 512ebfa339321f8a4df9d5011e591a615d5765107d5Ted Kremenek return MakeCXCursorInvalid(CXCursor_InvalidCode); 513ebfa339321f8a4df9d5011e591a615d5765107d5Ted Kremenek assert(TU && "Invalid arguments!"); 5141adb082a709f7b588f03672999294e061234b2cfDouglas Gregor void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 5154e7064fa7e344e8f87a5b8457e96dfdd252c4a9eArgyrios Kyrtzidis CXCursor C = { CXCursor_ObjCClassRef, 0, { (void*)Class, RawLoc, TU } }; 5161adb082a709f7b588f03672999294e061234b2cfDouglas Gregor return C; 5171adb082a709f7b588f03672999294e061234b2cfDouglas Gregor} 5181adb082a709f7b588f03672999294e061234b2cfDouglas Gregor 5191adb082a709f7b588f03672999294e061234b2cfDouglas Gregorstd::pair<ObjCInterfaceDecl *, SourceLocation> 5201adb082a709f7b588f03672999294e061234b2cfDouglas Gregorcxcursor::getCursorObjCClassRef(CXCursor C) { 5211adb082a709f7b588f03672999294e061234b2cfDouglas Gregor assert(C.kind == CXCursor_ObjCClassRef); 5221adb082a709f7b588f03672999294e061234b2cfDouglas Gregor return std::make_pair(static_cast<ObjCInterfaceDecl *>(C.data[0]), 5231adb082a709f7b588f03672999294e061234b2cfDouglas Gregor SourceLocation::getFromRawEncoding( 5241adb082a709f7b588f03672999294e061234b2cfDouglas Gregor reinterpret_cast<uintptr_t>(C.data[1]))); 5251adb082a709f7b588f03672999294e061234b2cfDouglas Gregor} 5261adb082a709f7b588f03672999294e061234b2cfDouglas Gregor 5274e7064fa7e344e8f87a5b8457e96dfdd252c4a9eArgyrios KyrtzidisCXCursor cxcursor::MakeCursorTypeRef(const TypeDecl *Type, SourceLocation Loc, 528a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 52954d67caeee4fdce81f07163832f1163d5f2af5d2Daniel Dunbar assert(Type && TU && "Invalid arguments!"); 5307d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 5314e7064fa7e344e8f87a5b8457e96dfdd252c4a9eArgyrios Kyrtzidis CXCursor C = { CXCursor_TypeRef, 0, { (void*)Type, RawLoc, TU } }; 5327d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor return C; 5337d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor} 5347d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor 5357d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregorstd::pair<TypeDecl *, SourceLocation> 5367d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregorcxcursor::getCursorTypeRef(CXCursor C) { 5377d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor assert(C.kind == CXCursor_TypeRef); 5387d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor return std::make_pair(static_cast<TypeDecl *>(C.data[0]), 5397d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor SourceLocation::getFromRawEncoding( 5407d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor reinterpret_cast<uintptr_t>(C.data[1]))); 5417d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor} 5427d0d40e58807f73e06ff5eb637a48e9f978b0e2aDouglas Gregor 543b395c63b473bf1b3783bff371a993332e8c4c5e3Argyrios KyrtzidisCXCursor cxcursor::MakeCursorTemplateRef(const TemplateDecl *Template, 544a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek SourceLocation Loc, 545a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 5460b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor assert(Template && TU && "Invalid arguments!"); 5470b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 548b395c63b473bf1b3783bff371a993332e8c4c5e3Argyrios Kyrtzidis CXCursor C = { CXCursor_TemplateRef, 0, { (void*)Template, RawLoc, TU } }; 5490b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor return C; 5500b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor} 5510b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor 5520b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregorstd::pair<TemplateDecl *, SourceLocation> 5530b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregorcxcursor::getCursorTemplateRef(CXCursor C) { 5540b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor assert(C.kind == CXCursor_TemplateRef); 5550b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor return std::make_pair(static_cast<TemplateDecl *>(C.data[0]), 5560b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor SourceLocation::getFromRawEncoding( 5570b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor reinterpret_cast<uintptr_t>(C.data[1]))); 5580b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor} 5590b36e614aa19df72885d5e0de996f7fbb9874ec3Douglas Gregor 560b395c63b473bf1b3783bff371a993332e8c4c5e3Argyrios KyrtzidisCXCursor cxcursor::MakeCursorNamespaceRef(const NamedDecl *NS, 561b395c63b473bf1b3783bff371a993332e8c4c5e3Argyrios Kyrtzidis SourceLocation Loc, 562a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 5636931900f43cea558c6974075256c07728dbfecc6Douglas Gregor 5646931900f43cea558c6974075256c07728dbfecc6Douglas Gregor assert(NS && (isa<NamespaceDecl>(NS) || isa<NamespaceAliasDecl>(NS)) && TU && 5656931900f43cea558c6974075256c07728dbfecc6Douglas Gregor "Invalid arguments!"); 5666931900f43cea558c6974075256c07728dbfecc6Douglas Gregor void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 567b395c63b473bf1b3783bff371a993332e8c4c5e3Argyrios Kyrtzidis CXCursor C = { CXCursor_NamespaceRef, 0, { (void*)NS, RawLoc, TU } }; 5686931900f43cea558c6974075256c07728dbfecc6Douglas Gregor return C; 5696931900f43cea558c6974075256c07728dbfecc6Douglas Gregor} 5706931900f43cea558c6974075256c07728dbfecc6Douglas Gregor 5716931900f43cea558c6974075256c07728dbfecc6Douglas Gregorstd::pair<NamedDecl *, SourceLocation> 5726931900f43cea558c6974075256c07728dbfecc6Douglas Gregorcxcursor::getCursorNamespaceRef(CXCursor C) { 5736931900f43cea558c6974075256c07728dbfecc6Douglas Gregor assert(C.kind == CXCursor_NamespaceRef); 5746931900f43cea558c6974075256c07728dbfecc6Douglas Gregor return std::make_pair(static_cast<NamedDecl *>(C.data[0]), 5756931900f43cea558c6974075256c07728dbfecc6Douglas Gregor SourceLocation::getFromRawEncoding( 5766931900f43cea558c6974075256c07728dbfecc6Douglas Gregor reinterpret_cast<uintptr_t>(C.data[1]))); 5776931900f43cea558c6974075256c07728dbfecc6Douglas Gregor} 5786931900f43cea558c6974075256c07728dbfecc6Douglas Gregor 579011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas GregorCXCursor cxcursor::MakeCursorVariableRef(const VarDecl *Var, SourceLocation Loc, 580011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor CXTranslationUnit TU) { 581011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor 582011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor assert(Var && TU && "Invalid arguments!"); 583011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 584011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor CXCursor C = { CXCursor_VariableRef, 0, { (void*)Var, RawLoc, TU } }; 585011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor return C; 586011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor} 587011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor 588011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregorstd::pair<VarDecl *, SourceLocation> 589011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregorcxcursor::getCursorVariableRef(CXCursor C) { 590011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor assert(C.kind == CXCursor_VariableRef); 591011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor return std::make_pair(static_cast<VarDecl *>(C.data[0]), 592011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor SourceLocation::getFromRawEncoding( 593011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor reinterpret_cast<uintptr_t>(C.data[1]))); 594011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor} 595011d8b93b7cfa8492b8a9c909a850d6577e08dcaDouglas Gregor 596b395c63b473bf1b3783bff371a993332e8c4c5e3Argyrios KyrtzidisCXCursor cxcursor::MakeCursorMemberRef(const FieldDecl *Field, SourceLocation Loc, 597a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 598a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor 599a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor assert(Field && TU && "Invalid arguments!"); 600a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 601b395c63b473bf1b3783bff371a993332e8c4c5e3Argyrios Kyrtzidis CXCursor C = { CXCursor_MemberRef, 0, { (void*)Field, RawLoc, TU } }; 602a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor return C; 603a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor} 604a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor 605a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregorstd::pair<FieldDecl *, SourceLocation> 606a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregorcxcursor::getCursorMemberRef(CXCursor C) { 607a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor assert(C.kind == CXCursor_MemberRef); 608a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor return std::make_pair(static_cast<FieldDecl *>(C.data[0]), 609a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor SourceLocation::getFromRawEncoding( 610a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor reinterpret_cast<uintptr_t>(C.data[1]))); 611a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor} 612a67e03fdf1ae8a1f92463a307d0b6281f1161f40Douglas Gregor 6132957e6f8c4c2e58a4b9cb639949fea801970fe36Argyrios KyrtzidisCXCursor cxcursor::MakeCursorCXXBaseSpecifier(const CXXBaseSpecifier *B, 614a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU){ 6152957e6f8c4c2e58a4b9cb639949fea801970fe36Argyrios Kyrtzidis CXCursor C = { CXCursor_CXXBaseSpecifier, 0, { (void*)B, 0, TU } }; 6163064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek return C; 6173064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek} 6183064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek 6193064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed KremenekCXXBaseSpecifier *cxcursor::getCursorCXXBaseSpecifier(CXCursor C) { 6203064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek assert(C.kind == CXCursor_CXXBaseSpecifier); 6213064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek return static_cast<CXXBaseSpecifier*>(C.data[0]); 6223064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek} 6233064ef9e604d19a0cfd0d8e3ed3055bfd83f88fdTed Kremenek 6249f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas GregorCXCursor cxcursor::MakePreprocessingDirectiveCursor(SourceRange Range, 625a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 626aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis CXCursor C = { CXCursor_PreprocessingDirective, 0, 6279f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor { reinterpret_cast<void *>(Range.getBegin().getRawEncoding()), 6289f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor reinterpret_cast<void *>(Range.getEnd().getRawEncoding()), 6299f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor TU } 6309f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor }; 6319f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor return C; 6329f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor} 6339f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor 6349f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas GregorSourceRange cxcursor::getCursorPreprocessingDirective(CXCursor C) { 6359f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor assert(C.kind == CXCursor_PreprocessingDirective); 636ee0f84fc84ed7de7975e102668d8e53a778f7a8cArgyrios Kyrtzidis SourceRange Range = SourceRange(SourceLocation::getFromRawEncoding( 6379f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor reinterpret_cast<uintptr_t> (C.data[0])), 6384807231938d8aff28de09f78f301f9ba5845e5e4Douglas Gregor SourceLocation::getFromRawEncoding( 6394807231938d8aff28de09f78f301f9ba5845e5e4Douglas Gregor reinterpret_cast<uintptr_t> (C.data[1]))); 640ee0f84fc84ed7de7975e102668d8e53a778f7a8cArgyrios Kyrtzidis ASTUnit *TU = getCursorASTUnit(C); 641ee0f84fc84ed7de7975e102668d8e53a778f7a8cArgyrios Kyrtzidis return TU->mapRangeFromPreamble(Range); 6424807231938d8aff28de09f78f301f9ba5845e5e4Douglas Gregor} 6434807231938d8aff28de09f78f301f9ba5845e5e4Douglas Gregor 644a60ed47da13393796d8552b9fdca12abbb3eea42Ted KremenekCXCursor cxcursor::MakeMacroDefinitionCursor(MacroDefinition *MI, 645a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 646aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis CXCursor C = { CXCursor_MacroDefinition, 0, { MI, 0, TU } }; 647572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor return C; 648572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor} 649572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor 650572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas GregorMacroDefinition *cxcursor::getCursorMacroDefinition(CXCursor C) { 651572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor assert(C.kind == CXCursor_MacroDefinition); 652572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor return static_cast<MacroDefinition *>(C.data[0]); 653572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor} 654572feb2a190b5e8b04fb06c4ac50ee0f61e93ff0Douglas Gregor 6559e5bb85ac899eeab7c21b5ff9030c3da6ff4837bChandler CarruthCXCursor cxcursor::MakeMacroExpansionCursor(MacroExpansion *MI, 6569e5bb85ac899eeab7c21b5ff9030c3da6ff4837bChandler Carruth CXTranslationUnit TU) { 657aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis CXCursor C = { CXCursor_MacroExpansion, 0, { MI, 0, TU } }; 6584807231938d8aff28de09f78f301f9ba5845e5e4Douglas Gregor return C; 6594807231938d8aff28de09f78f301f9ba5845e5e4Douglas Gregor} 6604807231938d8aff28de09f78f301f9ba5845e5e4Douglas Gregor 6619e5bb85ac899eeab7c21b5ff9030c3da6ff4837bChandler CarruthMacroExpansion *cxcursor::getCursorMacroExpansion(CXCursor C) { 6629b2a0ac970a077bdc0bf08c6c682f80ad733c892Chandler Carruth assert(C.kind == CXCursor_MacroExpansion); 6639e5bb85ac899eeab7c21b5ff9030c3da6ff4837bChandler Carruth return static_cast<MacroExpansion *>(C.data[0]); 6649f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor} 6659f1e3ff3b3095967e2b92b57a53524e2d6bb141cDouglas Gregor 666ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas GregorCXCursor cxcursor::MakeInclusionDirectiveCursor(InclusionDirective *ID, 667a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 668aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis CXCursor C = { CXCursor_InclusionDirective, 0, { ID, 0, TU } }; 669ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor return C; 670ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor} 671ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor 672ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas GregorInclusionDirective *cxcursor::getCursorInclusionDirective(CXCursor C) { 673ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor assert(C.kind == CXCursor_InclusionDirective); 674ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor return static_cast<InclusionDirective *>(C.data[0]); 675ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor} 676ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0edDouglas Gregor 67736897b05ca2886e287f01802614bc10cbadcec22Douglas GregorCXCursor cxcursor::MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc, 678a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 67936897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor 68036897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor assert(Label && TU && "Invalid arguments!"); 68136897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 682aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis CXCursor C = { CXCursor_LabelRef, 0, { Label, RawLoc, TU } }; 68336897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor return C; 68436897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor} 68536897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor 68636897b05ca2886e287f01802614bc10cbadcec22Douglas Gregorstd::pair<LabelStmt*, SourceLocation> 68736897b05ca2886e287f01802614bc10cbadcec22Douglas Gregorcxcursor::getCursorLabelRef(CXCursor C) { 68836897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor assert(C.kind == CXCursor_LabelRef); 68936897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor return std::make_pair(static_cast<LabelStmt *>(C.data[0]), 69036897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor SourceLocation::getFromRawEncoding( 69136897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor reinterpret_cast<uintptr_t>(C.data[1]))); 69236897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor} 69336897b05ca2886e287f01802614bc10cbadcec22Douglas Gregor 6941f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas GregorCXCursor cxcursor::MakeCursorOverloadedDeclRef(OverloadExpr *E, 695a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 6961f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor assert(E && TU && "Invalid arguments!"); 6971f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor OverloadedDeclRefStorage Storage(E); 6981f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor void *RawLoc = reinterpret_cast<void *>(E->getNameLoc().getRawEncoding()); 6991f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor CXCursor C = { 700aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis CXCursor_OverloadedDeclRef, 0, 7011f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor { Storage.getOpaqueValue(), RawLoc, TU } 7021f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor }; 7031f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor return C; 7041f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor} 7051f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor 7061f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas GregorCXCursor cxcursor::MakeCursorOverloadedDeclRef(Decl *D, 7071f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor SourceLocation Loc, 708a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 7091f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor assert(D && TU && "Invalid arguments!"); 7101f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 7111f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor OverloadedDeclRefStorage Storage(D); 7121f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor CXCursor C = { 713aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis CXCursor_OverloadedDeclRef, 0, 7141f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor { Storage.getOpaqueValue(), RawLoc, TU } 7151f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor }; 7161f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor return C; 7171f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor} 7181f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor 7191f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas GregorCXCursor cxcursor::MakeCursorOverloadedDeclRef(TemplateName Name, 7201f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor SourceLocation Loc, 721a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek CXTranslationUnit TU) { 7221f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor assert(Name.getAsOverloadedTemplate() && TU && "Invalid arguments!"); 7231f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 7241f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor OverloadedDeclRefStorage Storage(Name.getAsOverloadedTemplate()); 7251f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor CXCursor C = { 726aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis CXCursor_OverloadedDeclRef, 0, 7271f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor { Storage.getOpaqueValue(), RawLoc, TU } 7281f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor }; 7291f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor return C; 7301f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor} 7311f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor 7321f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregorstd::pair<cxcursor::OverloadedDeclRefStorage, SourceLocation> 7331f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregorcxcursor::getCursorOverloadedDeclRef(CXCursor C) { 7341f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor assert(C.kind == CXCursor_OverloadedDeclRef); 7351f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor return std::make_pair(OverloadedDeclRefStorage::getFromOpaqueValue(C.data[0]), 7361f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor SourceLocation::getFromRawEncoding( 7371f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor reinterpret_cast<uintptr_t>(C.data[1]))); 7381f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor} 7391f60d9ea523fc321d811fe880ba9a1ec74fa8f9bDouglas Gregor 740283cae37b03047c14ef918503bc46b08405c3b69Douglas GregorDecl *cxcursor::getCursorDecl(CXCursor Cursor) { 741283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor return (Decl *)Cursor.data[0]; 742283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor} 743283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor 744283cae37b03047c14ef918503bc46b08405c3b69Douglas GregorExpr *cxcursor::getCursorExpr(CXCursor Cursor) { 745283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor return dyn_cast_or_null<Expr>(getCursorStmt(Cursor)); 746283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor} 747283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor 748283cae37b03047c14ef918503bc46b08405c3b69Douglas GregorStmt *cxcursor::getCursorStmt(CXCursor Cursor) { 74978db0cdd49ec24034a5b2a4210fcda03a0919a81Douglas Gregor if (Cursor.kind == CXCursor_ObjCSuperClassRef || 7501adb082a709f7b588f03672999294e061234b2cfDouglas Gregor Cursor.kind == CXCursor_ObjCProtocolRef || 7511adb082a709f7b588f03672999294e061234b2cfDouglas Gregor Cursor.kind == CXCursor_ObjCClassRef) 7522e331b938b38057e333fab0ba841130ea8467794Douglas Gregor return 0; 7532e331b938b38057e333fab0ba841130ea8467794Douglas Gregor 754283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor return (Stmt *)Cursor.data[1]; 755283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor} 756283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor 75795f33555a6d51b6537a9ed3968c3d1c2e4991b51Ted KremenekAttr *cxcursor::getCursorAttr(CXCursor Cursor) { 75895f33555a6d51b6537a9ed3968c3d1c2e4991b51Ted Kremenek return (Attr *)Cursor.data[1]; 75995f33555a6d51b6537a9ed3968c3d1c2e4991b51Ted Kremenek} 76095f33555a6d51b6537a9ed3968c3d1c2e4991b51Ted Kremenek 7618ccac3de1335f1cfd7cea56ba1cefcf0b724ce3fArgyrios KyrtzidisDecl *cxcursor::getCursorParentDecl(CXCursor Cursor) { 7628ccac3de1335f1cfd7cea56ba1cefcf0b724ce3fArgyrios Kyrtzidis return (Decl *)Cursor.data[0]; 7638ccac3de1335f1cfd7cea56ba1cefcf0b724ce3fArgyrios Kyrtzidis} 7648ccac3de1335f1cfd7cea56ba1cefcf0b724ce3fArgyrios Kyrtzidis 765f46034af49435a4d1a0085a4738343122aeb6521Douglas GregorASTContext &cxcursor::getCursorContext(CXCursor Cursor) { 766b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor return getCursorASTUnit(Cursor)->getASTContext(); 767b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas Gregor} 76897b9872d5775446cb8aca1380e437649fe848d91Douglas Gregor 769b2cd48756119f4d8d2a865b4b3e0e8efd02e26a0Douglas GregorASTUnit *cxcursor::getCursorASTUnit(CXCursor Cursor) { 7704451746d8f658b51eaf15dd24664a488457063a9Argyrios Kyrtzidis CXTranslationUnit TU = static_cast<CXTranslationUnit>(Cursor.data[2]); 7714451746d8f658b51eaf15dd24664a488457063a9Argyrios Kyrtzidis if (!TU) 7724451746d8f658b51eaf15dd24664a488457063a9Argyrios Kyrtzidis return 0; 7734451746d8f658b51eaf15dd24664a488457063a9Argyrios Kyrtzidis return static_cast<ASTUnit *>(TU->TUData); 774a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek} 775a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek 776a60ed47da13393796d8552b9fdca12abbb3eea42Ted KremenekCXTranslationUnit cxcursor::getCursorTU(CXCursor Cursor) { 777a60ed47da13393796d8552b9fdca12abbb3eea42Ted Kremenek return static_cast<CXTranslationUnit>(Cursor.data[2]); 778283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor} 779283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor 780b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidisstatic void CollectOverriddenMethods(CXTranslationUnit TU, 781b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis DeclContext *Ctx, 782b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis ObjCMethodDecl *Method, 783b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis SmallVectorImpl<CXCursor> &Methods) { 784b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis if (!Ctx) 785b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis return; 786b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis 787b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis // If we have a class or category implementation, jump straight to the 788b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis // interface. 789b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis if (ObjCImplDecl *Impl = dyn_cast<ObjCImplDecl>(Ctx)) 790b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis return CollectOverriddenMethods(TU, Impl->getClassInterface(), 791b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis Method, Methods); 792b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis 793b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis ObjCContainerDecl *Container = dyn_cast<ObjCContainerDecl>(Ctx); 794b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis if (!Container) 795b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis return; 796b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis 797b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis // Check whether we have a matching method at this level. 798b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis if (ObjCMethodDecl *Overridden = Container->getMethod(Method->getSelector(), 799b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis Method->isInstanceMethod())) 800b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis if (Method != Overridden) { 801b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis // We found an override at this level; there is no need to look 802b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis // into other protocols or categories. 803b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis Methods.push_back(MakeCXCursor(Overridden, TU)); 804b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis return; 805b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis } 806b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis 807b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis if (ObjCProtocolDecl *Protocol = dyn_cast<ObjCProtocolDecl>(Container)) { 808b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis for (ObjCProtocolDecl::protocol_iterator P = Protocol->protocol_begin(), 809b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis PEnd = Protocol->protocol_end(); 810b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis P != PEnd; ++P) 811b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis CollectOverriddenMethods(TU, *P, Method, Methods); 812b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis } 813b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis 814b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis if (ObjCCategoryDecl *Category = dyn_cast<ObjCCategoryDecl>(Container)) { 815b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis for (ObjCCategoryDecl::protocol_iterator P = Category->protocol_begin(), 816b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis PEnd = Category->protocol_end(); 817b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis P != PEnd; ++P) 818b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis CollectOverriddenMethods(TU, *P, Method, Methods); 819b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis } 820b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis 821b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis if (ObjCInterfaceDecl *Interface = dyn_cast<ObjCInterfaceDecl>(Container)) { 822b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis for (ObjCInterfaceDecl::protocol_iterator P = Interface->protocol_begin(), 823b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis PEnd = Interface->protocol_end(); 824b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis P != PEnd; ++P) 825b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis CollectOverriddenMethods(TU, *P, Method, Methods); 826b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis 827b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis for (ObjCCategoryDecl *Category = Interface->getCategoryList(); 828b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis Category; Category = Category->getNextClassCategory()) 829b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis CollectOverriddenMethods(TU, Category, Method, Methods); 830b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis 831b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis // We only look into the superclass if we haven't found anything yet. 832b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis if (Methods.empty()) 833b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis if (ObjCInterfaceDecl *Super = Interface->getSuperClass()) 834b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis return CollectOverriddenMethods(TU, Super, Method, Methods); 835b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis } 836b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis} 837b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis 838b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidisvoid cxcursor::getOverriddenCursors(CXCursor cursor, 839b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis SmallVectorImpl<CXCursor> &overridden) { 840b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis if (!clang_isDeclaration(cursor.kind)) 841b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis return; 842b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis 843b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis Decl *D = getCursorDecl(cursor); 844b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis if (!D) 845b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis return; 846b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis 847b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis // Handle C++ member functions. 848b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis CXTranslationUnit TU = getCursorTU(cursor); 849b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis if (CXXMethodDecl *CXXMethod = dyn_cast<CXXMethodDecl>(D)) { 850b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis for (CXXMethodDecl::method_iterator 851b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis M = CXXMethod->begin_overridden_methods(), 852b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis MEnd = CXXMethod->end_overridden_methods(); 853b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis M != MEnd; ++M) 854b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis overridden.push_back(MakeCXCursor(const_cast<CXXMethodDecl*>(*M), TU)); 855b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis return; 856b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis } 857b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis 858b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(D); 859b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis if (!Method) 860b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis return; 861b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis 862b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis // Handle Objective-C methods. 863b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis CollectOverriddenMethods(TU, Method->getDeclContext(), Method, overridden); 864b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis} 865b11be041e4f05519a2eabf6a99429ba6110f1ca9Argyrios Kyrtzidis 866aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidisstd::pair<int, SourceLocation> 867aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidiscxcursor::getSelectorIdentifierIndexAndLoc(CXCursor cursor) { 868aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis if (cursor.kind == CXCursor_ObjCMessageExpr) { 869aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis if (cursor.xdata != -1) 870aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis return std::make_pair(cursor.xdata, 871aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis cast<ObjCMessageExpr>(getCursorExpr(cursor)) 872aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis ->getSelectorLoc(cursor.xdata)); 873aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis } else if (cursor.kind == CXCursor_ObjCClassMethodDecl || 874aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis cursor.kind == CXCursor_ObjCInstanceMethodDecl) { 875aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis if (cursor.xdata != -1) 876aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis return std::make_pair(cursor.xdata, 877aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis cast<ObjCMethodDecl>(getCursorDecl(cursor)) 878aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis ->getSelectorLoc(cursor.xdata)); 879aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis } 880aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis 881aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis return std::make_pair(-1, SourceLocation()); 882aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis} 883aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis 884aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios KyrtzidisCXCursor cxcursor::getSelectorIdentifierCursor(int SelIdx, CXCursor cursor) { 885aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis CXCursor newCursor = cursor; 886aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis 887aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis if (cursor.kind == CXCursor_ObjCMessageExpr) { 888aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis if (SelIdx == -1 || 889aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis unsigned(SelIdx) >= cast<ObjCMessageExpr>(getCursorExpr(cursor)) 890aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis ->getNumSelectorLocs()) 891aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis newCursor.xdata = -1; 892aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis else 893aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis newCursor.xdata = SelIdx; 894aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis } else if (cursor.kind == CXCursor_ObjCClassMethodDecl || 895aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis cursor.kind == CXCursor_ObjCInstanceMethodDecl) { 896aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis if (SelIdx == -1 || 897aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis unsigned(SelIdx) >= cast<ObjCMethodDecl>(getCursorDecl(cursor)) 898aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis ->getNumSelectorLocs()) 899aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis newCursor.xdata = -1; 900aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis else 901aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis newCursor.xdata = SelIdx; 902aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis } 903aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis 904aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis return newCursor; 905aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis} 906aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis 907aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios KyrtzidisCXCursor cxcursor::getTypeRefCursor(CXCursor cursor) { 908aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis if (cursor.kind != CXCursor_CallExpr) 909aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis return cursor; 910aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis 911aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis if (cursor.xdata == 0) 912aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis return cursor; 913aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis 914aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis Expr *E = getCursorExpr(cursor); 915aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis TypeSourceInfo *Type = 0; 916aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis if (CXXUnresolvedConstructExpr * 917aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis UnCtor = dyn_cast<CXXUnresolvedConstructExpr>(E)) { 918aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis Type = UnCtor->getTypeSourceInfo(); 919aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis } else if (CXXTemporaryObjectExpr *Tmp = dyn_cast<CXXTemporaryObjectExpr>(E)){ 920aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis Type = Tmp->getTypeSourceInfo(); 921aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis } 922aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis 923aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis if (!Type) 924aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis return cursor; 925aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis 926aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis CXTranslationUnit TU = getCursorTU(cursor); 927aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis QualType Ty = Type->getType(); 928aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis TypeLoc TL = Type->getTypeLoc(); 929aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis SourceLocation Loc = TL.getBeginLoc(); 930aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis 931aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis if (const ElaboratedType *ElabT = Ty->getAs<ElaboratedType>()) { 932aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis Ty = ElabT->getNamedType(); 933aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis ElaboratedTypeLoc ElabTL = cast<ElaboratedTypeLoc>(TL); 934aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis Loc = ElabTL.getNamedTypeLoc().getBeginLoc(); 935aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis } 936aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis 937aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis if (const TypedefType *Typedef = Ty->getAs<TypedefType>()) 938aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis return MakeCursorTypeRef(Typedef->getDecl(), Loc, TU); 939aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis if (const TagType *Tag = Ty->getAs<TagType>()) 940aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis return MakeCursorTypeRef(Tag->getDecl(), Loc, TU); 941aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis if (const TemplateTypeParmType *TemplP = Ty->getAs<TemplateTypeParmType>()) 942aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis return MakeCursorTypeRef(TemplP->getDecl(), Loc, TU); 943aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis 944aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis return cursor; 945aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis} 946aed123ec3cc37e457fe20a6158fdadf8849ad916Argyrios Kyrtzidis 947283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregorbool cxcursor::operator==(CXCursor X, CXCursor Y) { 948283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor return X.kind == Y.kind && X.data[0] == Y.data[0] && X.data[1] == Y.data[1] && 949283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor X.data[2] == Y.data[2]; 9502e331b938b38057e333fab0ba841130ea8467794Douglas Gregor} 951007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek 952007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek// FIXME: Remove once we can model DeclGroups and their appropriate ranges 953007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek// properly in the ASTs. 954007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenekbool cxcursor::isFirstInDeclGroup(CXCursor C) { 955007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek assert(clang_isDeclaration(C.kind)); 956007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek return ((uintptr_t) (C.data[1])) != 0; 957007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek} 958007a7c9d8dcdb2e9cd94b6075108bfc4c90e6ccdTed Kremenek 959eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek//===----------------------------------------------------------------------===// 960b0d6eaa6b646c18c49923aefc76973801f561701Argyrios Kyrtzidis// libclang CXCursor APIs 961b0d6eaa6b646c18c49923aefc76973801f561701Argyrios Kyrtzidis//===----------------------------------------------------------------------===// 962b0d6eaa6b646c18c49923aefc76973801f561701Argyrios Kyrtzidis 963fa865df489fe68668c554dece36c68b4ce03920fArgyrios Kyrtzidisextern "C" { 964fa865df489fe68668c554dece36c68b4ce03920fArgyrios Kyrtzidis 965fa865df489fe68668c554dece36c68b4ce03920fArgyrios Kyrtzidisint clang_Cursor_isNull(CXCursor cursor) { 966fa865df489fe68668c554dece36c68b4ce03920fArgyrios Kyrtzidis return clang_equalCursors(cursor, clang_getNullCursor()); 967fa865df489fe68668c554dece36c68b4ce03920fArgyrios Kyrtzidis} 968fa865df489fe68668c554dece36c68b4ce03920fArgyrios Kyrtzidis 969b0d6eaa6b646c18c49923aefc76973801f561701Argyrios KyrtzidisCXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor cursor) { 970b0d6eaa6b646c18c49923aefc76973801f561701Argyrios Kyrtzidis return getCursorTU(cursor); 971b0d6eaa6b646c18c49923aefc76973801f561701Argyrios Kyrtzidis} 972b0d6eaa6b646c18c49923aefc76973801f561701Argyrios Kyrtzidis 973fa865df489fe68668c554dece36c68b4ce03920fArgyrios Kyrtzidis} // end: extern "C" 974fa865df489fe68668c554dece36c68b4ce03920fArgyrios Kyrtzidis 975b0d6eaa6b646c18c49923aefc76973801f561701Argyrios Kyrtzidis//===----------------------------------------------------------------------===// 976eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek// CXCursorSet. 977eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek//===----------------------------------------------------------------------===// 978eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek 979eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenektypedef llvm::DenseMap<CXCursor, unsigned> CXCursorSet_Impl; 980eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek 981eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenekstatic inline CXCursorSet packCXCursorSet(CXCursorSet_Impl *setImpl) { 982eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek return (CXCursorSet) setImpl; 983eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek} 984eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenekstatic inline CXCursorSet_Impl *unpackCXCursorSet(CXCursorSet set) { 985eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek return (CXCursorSet_Impl*) set; 986eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek} 987eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremeneknamespace llvm { 988da6fb69873079a0193ed8c9fa1d1b859d4f87b95Ted Kremenektemplate<> struct DenseMapInfo<CXCursor> { 989eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenekpublic: 990eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek static inline CXCursor getEmptyKey() { 991eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek return MakeCXCursorInvalid(CXCursor_InvalidFile); 992eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek } 993eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek static inline CXCursor getTombstoneKey() { 994eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek return MakeCXCursorInvalid(CXCursor_NoDeclFound); 995eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek } 996eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek static inline unsigned getHashValue(const CXCursor &cursor) { 997eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek return llvm::DenseMapInfo<std::pair<void*,void*> > 998eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek ::getHashValue(std::make_pair(cursor.data[0], cursor.data[1])); 999eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek } 1000eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek static inline bool isEqual(const CXCursor &x, const CXCursor &y) { 1001eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek return x.kind == y.kind && 1002eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek x.data[0] == y.data[0] && 1003eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek x.data[1] == y.data[1]; 1004eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek } 1005eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek}; 1006eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek} 1007eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek 1008eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenekextern "C" { 1009eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted KremenekCXCursorSet clang_createCXCursorSet() { 1010eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek return packCXCursorSet(new CXCursorSet_Impl()); 1011eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek} 1012eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek 1013eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenekvoid clang_disposeCXCursorSet(CXCursorSet set) { 1014eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek delete unpackCXCursorSet(set); 1015eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek} 1016eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek 1017eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenekunsigned clang_CXCursorSet_contains(CXCursorSet set, CXCursor cursor) { 1018eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek CXCursorSet_Impl *setImpl = unpackCXCursorSet(set); 1019eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek if (!setImpl) 1020eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek return 0; 1021eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek return setImpl->find(cursor) == setImpl->end(); 1022eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek} 1023eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek 1024e8b3de090b9de3c27c5d381e767217ddb849d5d8Anders Carlssonunsigned clang_CXCursorSet_insert(CXCursorSet set, CXCursor cursor) { 1025eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek // Do not insert invalid cursors into the set. 1026eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek if (cursor.kind >= CXCursor_FirstInvalid && 1027eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek cursor.kind <= CXCursor_LastInvalid) 1028eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek return 1; 1029eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek 1030eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek CXCursorSet_Impl *setImpl = unpackCXCursorSet(set); 1031eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek if (!setImpl) 1032eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek return 1; 1033eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek unsigned &entry = (*setImpl)[cursor]; 1034eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek unsigned flag = entry == 0 ? 1 : 0; 1035eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek entry = 1; 1036eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek return flag; 1037eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek} 10388fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor 10398fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas GregorCXCompletionString clang_getCursorCompletionString(CXCursor cursor) { 10408fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor enum CXCursorKind kind = clang_getCursorKind(cursor); 10418fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor if (clang_isDeclaration(kind)) { 10428fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor Decl *decl = getCursorDecl(cursor); 104316ed0e6fda74800595cb98d11969fc4afcc00bacArgyrios Kyrtzidis if (NamedDecl *namedDecl = dyn_cast_or_null<NamedDecl>(decl)) { 10448fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor ASTUnit *unit = getCursorASTUnit(cursor); 10455e192a7d60e776fa65e633cd9c2a0d59df132f23Argyrios Kyrtzidis CodeCompletionAllocator *Allocator 10465e192a7d60e776fa65e633cd9c2a0d59df132f23Argyrios Kyrtzidis = unit->getCursorCompletionAllocator().getPtr(); 10475e192a7d60e776fa65e633cd9c2a0d59df132f23Argyrios Kyrtzidis CodeCompletionResult Result(namedDecl); 10485e192a7d60e776fa65e633cd9c2a0d59df132f23Argyrios Kyrtzidis CodeCompletionString *String 10495e192a7d60e776fa65e633cd9c2a0d59df132f23Argyrios Kyrtzidis = Result.CreateCodeCompletionString(unit->getASTContext(), 10505e192a7d60e776fa65e633cd9c2a0d59df132f23Argyrios Kyrtzidis unit->getPreprocessor(), 10515e192a7d60e776fa65e633cd9c2a0d59df132f23Argyrios Kyrtzidis *Allocator); 10525e192a7d60e776fa65e633cd9c2a0d59df132f23Argyrios Kyrtzidis return String; 10538fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor } 10548fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor } 10558fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor else if (kind == CXCursor_MacroDefinition) { 10568fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor MacroDefinition *definition = getCursorMacroDefinition(cursor); 10578fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor const IdentifierInfo *MacroInfo = definition->getName(); 10588fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor ASTUnit *unit = getCursorASTUnit(cursor); 10595e192a7d60e776fa65e633cd9c2a0d59df132f23Argyrios Kyrtzidis CodeCompletionAllocator *Allocator 10605e192a7d60e776fa65e633cd9c2a0d59df132f23Argyrios Kyrtzidis = unit->getCursorCompletionAllocator().getPtr(); 10615e192a7d60e776fa65e633cd9c2a0d59df132f23Argyrios Kyrtzidis CodeCompletionResult Result(const_cast<IdentifierInfo *>(MacroInfo)); 10625e192a7d60e776fa65e633cd9c2a0d59df132f23Argyrios Kyrtzidis CodeCompletionString *String 10635e192a7d60e776fa65e633cd9c2a0d59df132f23Argyrios Kyrtzidis = Result.CreateCodeCompletionString(unit->getASTContext(), 10645e192a7d60e776fa65e633cd9c2a0d59df132f23Argyrios Kyrtzidis unit->getPreprocessor(), 10655e192a7d60e776fa65e633cd9c2a0d59df132f23Argyrios Kyrtzidis *Allocator); 10665e192a7d60e776fa65e633cd9c2a0d59df132f23Argyrios Kyrtzidis return String; 10678fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor } 10688fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor return NULL; 10698fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor} 10708fa0a80b4482ad94e82c4a19e23de17fd69140b5Douglas Gregor 1071eca099bdb0178d408d4f717c2e9627e0d0e673c6Ted Kremenek} // end: extern "C" 1072