Ted Kremenek | 87553c4 | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 1 | //===- CXCursor.cpp - Routines for manipulating CXCursors -----------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Douglas Gregor | 6c8959b | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 10 | // This file defines routines for manipulating CXCursors. It should be the |
| 11 | // only file that has internal knowledge of the encoding of the data in |
| 12 | // CXCursor. |
Ted Kremenek | 87553c4 | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
Ted Kremenek | 7df92ae | 2010-11-17 23:24:11 +0000 | [diff] [blame] | 16 | #include "CXTranslationUnit.h" |
Ted Kremenek | 87553c4 | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 17 | #include "CXCursor.h" |
Ted Kremenek | 4b4f369 | 2010-11-16 01:56:27 +0000 | [diff] [blame] | 18 | #include "CXString.h" |
Chandler Carruth | cc0694c | 2012-12-04 09:25:21 +0000 | [diff] [blame] | 19 | #include "CXType.h" |
| 20 | #include "clang-c/Index.h" |
David Blaikie | 0a4e61f | 2013-09-13 18:32:52 +0000 | [diff] [blame] | 21 | #include "clang/AST/Attr.h" |
Ted Kremenek | 87553c4 | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 22 | #include "clang/AST/Decl.h" |
Douglas Gregor | a89314e | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclCXX.h" |
Douglas Gregor | c58d05b | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 24 | #include "clang/AST/DeclObjC.h" |
Argyrios Kyrtzidis | cddafd3 | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 25 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | c58d05b | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 26 | #include "clang/AST/Expr.h" |
Douglas Gregor | 16a2bdd | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 27 | #include "clang/AST/ExprCXX.h" |
Argyrios Kyrtzidis | cddafd3 | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 28 | #include "clang/AST/ExprObjC.h" |
Chandler Carruth | cc0694c | 2012-12-04 09:25:21 +0000 | [diff] [blame] | 29 | #include "clang/Frontend/ASTUnit.h" |
Ted Kremenek | c2aa0f1 | 2010-01-16 00:36:30 +0000 | [diff] [blame] | 30 | #include "llvm/Support/ErrorHandling.h" |
Ted Kremenek | 87553c4 | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 31 | |
| 32 | using namespace clang; |
Douglas Gregor | 16a2bdd | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 33 | using namespace cxcursor; |
Ted Kremenek | 87553c4 | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 34 | |
Ted Kremenek | d77f621 | 2012-04-30 19:06:49 +0000 | [diff] [blame] | 35 | CXCursor cxcursor::MakeCXCursorInvalid(CXCursorKind K, CXTranslationUnit TU) { |
Douglas Gregor | 58552bc | 2010-01-20 23:34:41 +0000 | [diff] [blame] | 36 | assert(K >= CXCursor_FirstInvalid && K <= CXCursor_LastInvalid); |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 37 | CXCursor C = { K, 0, { nullptr, nullptr, TU } }; |
Douglas Gregor | 58552bc | 2010-01-20 23:34:41 +0000 | [diff] [blame] | 38 | return C; |
Ted Kremenek | 87553c4 | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 39 | } |
| 40 | |
Ted Kremenek | bff3143 | 2010-02-18 03:09:07 +0000 | [diff] [blame] | 41 | static CXCursorKind GetCursorKind(const Attr *A) { |
| 42 | assert(A && "Invalid arguments!"); |
| 43 | switch (A->getKind()) { |
| 44 | default: break; |
Alexis Hunt | 344393e | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 45 | case attr::IBAction: return CXCursor_IBActionAttr; |
| 46 | case attr::IBOutlet: return CXCursor_IBOutletAttr; |
| 47 | case attr::IBOutletCollection: return CXCursor_IBOutletCollectionAttr; |
Argyrios Kyrtzidis | 2cb4e3c | 2011-09-13 17:39:31 +0000 | [diff] [blame] | 48 | case attr::Final: return CXCursor_CXXFinalAttr; |
| 49 | case attr::Override: return CXCursor_CXXOverrideAttr; |
Erik Verbruggen | ca98f2a | 2011-10-13 09:41:32 +0000 | [diff] [blame] | 50 | case attr::Annotate: return CXCursor_AnnotateAttr; |
Argyrios Kyrtzidis | 66f433a | 2011-12-06 22:05:01 +0000 | [diff] [blame] | 51 | case attr::AsmLabel: return CXCursor_AsmLabelAttr; |
Argyrios Kyrtzidis | 16834f1 | 2013-09-25 00:14:38 +0000 | [diff] [blame] | 52 | case attr::Packed: return CXCursor_PackedAttr; |
Joey Gouly | 8122838 | 2014-05-01 15:41:58 +0000 | [diff] [blame] | 53 | case attr::Pure: return CXCursor_PureAttr; |
| 54 | case attr::Const: return CXCursor_ConstAttr; |
| 55 | case attr::NoDuplicate: return CXCursor_NoDuplicateAttr; |
Eli Bendersky | 2581e66 | 2014-05-28 19:29:58 +0000 | [diff] [blame] | 56 | case attr::CUDAConstant: return CXCursor_CUDAConstantAttr; |
| 57 | case attr::CUDADevice: return CXCursor_CUDADeviceAttr; |
| 58 | case attr::CUDAGlobal: return CXCursor_CUDAGlobalAttr; |
| 59 | case attr::CUDAHost: return CXCursor_CUDAHostAttr; |
Eli Bendersky | 9b07147 | 2014-08-08 14:59:00 +0000 | [diff] [blame] | 60 | case attr::CUDAShared: return CXCursor_CUDASharedAttr; |
Saleem Abdulrasool | 79c6971 | 2015-09-05 18:53:43 +0000 | [diff] [blame] | 61 | case attr::Visibility: return CXCursor_VisibilityAttr; |
Saleem Abdulrasool | 8aa0b80 | 2015-12-10 18:45:18 +0000 | [diff] [blame] | 62 | case attr::DLLExport: return CXCursor_DLLExport; |
| 63 | case attr::DLLImport: return CXCursor_DLLImport; |
Ted Kremenek | bff3143 | 2010-02-18 03:09:07 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | return CXCursor_UnexposedAttr; |
| 67 | } |
| 68 | |
Dmitri Gribenko | 9c256e3 | 2013-01-14 00:46:27 +0000 | [diff] [blame] | 69 | CXCursor cxcursor::MakeCXCursor(const Attr *A, const Decl *Parent, |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 70 | CXTranslationUnit TU) { |
Ted Kremenek | bff3143 | 2010-02-18 03:09:07 +0000 | [diff] [blame] | 71 | assert(A && Parent && TU && "Invalid arguments!"); |
Dmitri Gribenko | 7a7284d | 2013-01-11 21:06:06 +0000 | [diff] [blame] | 72 | CXCursor C = { GetCursorKind(A), 0, { Parent, A, TU } }; |
Ted Kremenek | bff3143 | 2010-02-18 03:09:07 +0000 | [diff] [blame] | 73 | return C; |
| 74 | } |
| 75 | |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 76 | CXCursor cxcursor::MakeCXCursor(const Decl *D, CXTranslationUnit TU, |
Argyrios Kyrtzidis | cddafd3 | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 77 | SourceRange RegionOfInterest, |
Ted Kremenek | 818e5c1 | 2010-11-01 23:26:51 +0000 | [diff] [blame] | 78 | bool FirstInDeclGroup) { |
Daniel Dunbar | 2def7eb | 2010-01-25 00:40:30 +0000 | [diff] [blame] | 79 | assert(D && TU && "Invalid arguments!"); |
Argyrios Kyrtzidis | cddafd3 | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 80 | |
| 81 | CXCursorKind K = getCursorKindForDecl(D); |
| 82 | |
| 83 | if (K == CXCursor_ObjCClassMethodDecl || |
| 84 | K == CXCursor_ObjCInstanceMethodDecl) { |
| 85 | int SelectorIdIndex = -1; |
| 86 | // Check if cursor points to a selector id. |
| 87 | if (RegionOfInterest.isValid() && |
| 88 | RegionOfInterest.getBegin() == RegionOfInterest.getEnd()) { |
| 89 | SmallVector<SourceLocation, 16> SelLocs; |
| 90 | cast<ObjCMethodDecl>(D)->getSelectorLocs(SelLocs); |
Craig Topper | 2341c0d | 2013-07-04 03:08:24 +0000 | [diff] [blame] | 91 | SmallVectorImpl<SourceLocation>::iterator |
Argyrios Kyrtzidis | cddafd3 | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 92 | I=std::find(SelLocs.begin(), SelLocs.end(),RegionOfInterest.getBegin()); |
| 93 | if (I != SelLocs.end()) |
| 94 | SelectorIdIndex = I - SelLocs.begin(); |
| 95 | } |
| 96 | CXCursor C = { K, SelectorIdIndex, |
| 97 | { D, (void*)(intptr_t) (FirstInDeclGroup ? 1 : 0), TU }}; |
| 98 | return C; |
| 99 | } |
| 100 | |
| 101 | CXCursor C = { K, 0, { D, (void*)(intptr_t) (FirstInDeclGroup ? 1 : 0), TU }}; |
Douglas Gregor | 58552bc | 2010-01-20 23:34:41 +0000 | [diff] [blame] | 102 | return C; |
Ted Kremenek | c2aa0f1 | 2010-01-16 00:36:30 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Dmitri Gribenko | 9c256e3 | 2013-01-14 00:46:27 +0000 | [diff] [blame] | 105 | CXCursor cxcursor::MakeCXCursor(const Stmt *S, const Decl *Parent, |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 106 | CXTranslationUnit TU, |
Argyrios Kyrtzidis | cddafd3 | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 107 | SourceRange RegionOfInterest) { |
Daniel Dunbar | 2def7eb | 2010-01-25 00:40:30 +0000 | [diff] [blame] | 108 | assert(S && TU && "Invalid arguments!"); |
Douglas Gregor | 8f40bbee | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 109 | CXCursorKind K = CXCursor_NotImplemented; |
| 110 | |
| 111 | switch (S->getStmtClass()) { |
| 112 | case Stmt::NoStmtClass: |
| 113 | break; |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 114 | |
Douglas Gregor | 8f40bbee | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 115 | case Stmt::CaseStmtClass: |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 116 | K = CXCursor_CaseStmt; |
| 117 | break; |
| 118 | |
Douglas Gregor | 8f40bbee | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 119 | case Stmt::DefaultStmtClass: |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 120 | K = CXCursor_DefaultStmt; |
| 121 | break; |
| 122 | |
| 123 | case Stmt::IfStmtClass: |
| 124 | K = CXCursor_IfStmt; |
| 125 | break; |
| 126 | |
| 127 | case Stmt::SwitchStmtClass: |
| 128 | K = CXCursor_SwitchStmt; |
| 129 | break; |
| 130 | |
| 131 | case Stmt::WhileStmtClass: |
| 132 | K = CXCursor_WhileStmt; |
| 133 | break; |
| 134 | |
| 135 | case Stmt::DoStmtClass: |
| 136 | K = CXCursor_DoStmt; |
| 137 | break; |
| 138 | |
| 139 | case Stmt::ForStmtClass: |
| 140 | K = CXCursor_ForStmt; |
| 141 | break; |
| 142 | |
| 143 | case Stmt::GotoStmtClass: |
| 144 | K = CXCursor_GotoStmt; |
| 145 | break; |
| 146 | |
Douglas Gregor | 8f40bbee | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 147 | case Stmt::IndirectGotoStmtClass: |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 148 | K = CXCursor_IndirectGotoStmt; |
| 149 | break; |
| 150 | |
| 151 | case Stmt::ContinueStmtClass: |
| 152 | K = CXCursor_ContinueStmt; |
| 153 | break; |
| 154 | |
| 155 | case Stmt::BreakStmtClass: |
| 156 | K = CXCursor_BreakStmt; |
| 157 | break; |
| 158 | |
| 159 | case Stmt::ReturnStmtClass: |
| 160 | K = CXCursor_ReturnStmt; |
| 161 | break; |
| 162 | |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 163 | case Stmt::GCCAsmStmtClass: |
| 164 | K = CXCursor_GCCAsmStmt; |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 165 | break; |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 166 | |
| 167 | case Stmt::MSAsmStmtClass: |
| 168 | K = CXCursor_MSAsmStmt; |
| 169 | break; |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 170 | |
| 171 | case Stmt::ObjCAtTryStmtClass: |
| 172 | K = CXCursor_ObjCAtTryStmt; |
| 173 | break; |
| 174 | |
| 175 | case Stmt::ObjCAtCatchStmtClass: |
| 176 | K = CXCursor_ObjCAtCatchStmt; |
| 177 | break; |
| 178 | |
| 179 | case Stmt::ObjCAtFinallyStmtClass: |
| 180 | K = CXCursor_ObjCAtFinallyStmt; |
| 181 | break; |
| 182 | |
| 183 | case Stmt::ObjCAtThrowStmtClass: |
| 184 | K = CXCursor_ObjCAtThrowStmt; |
| 185 | break; |
| 186 | |
| 187 | case Stmt::ObjCAtSynchronizedStmtClass: |
| 188 | K = CXCursor_ObjCAtSynchronizedStmt; |
| 189 | break; |
| 190 | |
| 191 | case Stmt::ObjCAutoreleasePoolStmtClass: |
| 192 | K = CXCursor_ObjCAutoreleasePoolStmt; |
| 193 | break; |
| 194 | |
Douglas Gregor | 8f40bbee | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 195 | case Stmt::ObjCForCollectionStmtClass: |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 196 | K = CXCursor_ObjCForCollectionStmt; |
| 197 | break; |
| 198 | |
Douglas Gregor | 8f40bbee | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 199 | case Stmt::CXXCatchStmtClass: |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 200 | K = CXCursor_CXXCatchStmt; |
| 201 | break; |
| 202 | |
| 203 | case Stmt::CXXTryStmtClass: |
| 204 | K = CXCursor_CXXTryStmt; |
| 205 | break; |
| 206 | |
| 207 | case Stmt::CXXForRangeStmtClass: |
| 208 | K = CXCursor_CXXForRangeStmt; |
| 209 | break; |
| 210 | |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 211 | case Stmt::SEHTryStmtClass: |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 212 | K = CXCursor_SEHTryStmt; |
| 213 | break; |
| 214 | |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 215 | case Stmt::SEHExceptStmtClass: |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 216 | K = CXCursor_SEHExceptStmt; |
| 217 | break; |
| 218 | |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 219 | case Stmt::SEHFinallyStmtClass: |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 220 | K = CXCursor_SEHFinallyStmt; |
Douglas Gregor | 8f40bbee | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 221 | break; |
Nico Weber | 9b98207 | 2014-07-07 00:12:30 +0000 | [diff] [blame] | 222 | |
| 223 | case Stmt::SEHLeaveStmtClass: |
| 224 | K = CXCursor_SEHLeaveStmt; |
| 225 | break; |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 226 | |
John Wiegley | 6242b6a | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 227 | case Stmt::ArrayTypeTraitExprClass: |
Tanya Lattner | 55808c1 | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 228 | case Stmt::AsTypeExprClass: |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 229 | case Stmt::AtomicExprClass: |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 230 | case Stmt::BinaryConditionalOperatorClass: |
Douglas Gregor | 29c42f2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 231 | case Stmt::TypeTraitExprClass: |
Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 232 | case Stmt::CoroutineBodyStmtClass: |
| 233 | case Stmt::CoawaitExprClass: |
| 234 | case Stmt::CoreturnStmtClass: |
| 235 | case Stmt::CoyieldExprClass: |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 236 | case Stmt::CXXBindTemporaryExprClass: |
| 237 | case Stmt::CXXDefaultArgExprClass: |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 238 | case Stmt::CXXDefaultInitExprClass: |
Richard Smith | 0f0af19 | 2014-11-08 05:07:16 +0000 | [diff] [blame] | 239 | case Stmt::CXXFoldExprClass: |
Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 240 | case Stmt::CXXStdInitializerListExprClass: |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 241 | case Stmt::CXXScalarValueInitExprClass: |
| 242 | case Stmt::CXXUuidofExprClass: |
| 243 | case Stmt::ChooseExprClass: |
| 244 | case Stmt::DesignatedInitExprClass: |
Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 245 | case Stmt::DesignatedInitUpdateExprClass: |
Richard Smith | 410306b | 2016-12-12 02:53:20 +0000 | [diff] [blame] | 246 | case Stmt::ArrayInitLoopExprClass: |
| 247 | case Stmt::ArrayInitIndexExprClass: |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 248 | case Stmt::ExprWithCleanupsClass: |
| 249 | case Stmt::ExpressionTraitExprClass: |
| 250 | case Stmt::ExtVectorElementExprClass: |
| 251 | case Stmt::ImplicitCastExprClass: |
| 252 | case Stmt::ImplicitValueInitExprClass: |
Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 253 | case Stmt::NoInitExprClass: |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 254 | case Stmt::MaterializeTemporaryExprClass: |
| 255 | case Stmt::ObjCIndirectCopyRestoreExprClass: |
| 256 | case Stmt::OffsetOfExprClass: |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 257 | case Stmt::ParenListExprClass: |
| 258 | case Stmt::PredefinedExprClass: |
| 259 | case Stmt::ShuffleVectorExprClass: |
Hal Finkel | c4d7c82 | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 260 | case Stmt::ConvertVectorExprClass: |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 261 | case Stmt::VAArgExprClass: |
Ted Kremenek | 77006f6 | 2012-03-06 20:06:06 +0000 | [diff] [blame] | 262 | case Stmt::ObjCArrayLiteralClass: |
| 263 | case Stmt::ObjCDictionaryLiteralClass: |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 264 | case Stmt::ObjCBoxedExprClass: |
Ted Kremenek | 77006f6 | 2012-03-06 20:06:06 +0000 | [diff] [blame] | 265 | case Stmt::ObjCSubscriptRefExprClass: |
Douglas Gregor | 8f40bbee | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 266 | K = CXCursor_UnexposedExpr; |
| 267 | break; |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 268 | |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 269 | case Stmt::OpaqueValueExprClass: |
| 270 | if (Expr *Src = cast<OpaqueValueExpr>(S)->getSourceExpr()) |
| 271 | return MakeCXCursor(Src, Parent, TU, RegionOfInterest); |
| 272 | K = CXCursor_UnexposedExpr; |
| 273 | break; |
| 274 | |
| 275 | case Stmt::PseudoObjectExprClass: |
| 276 | return MakeCXCursor(cast<PseudoObjectExpr>(S)->getSyntacticForm(), |
| 277 | Parent, TU, RegionOfInterest); |
| 278 | |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 279 | case Stmt::CompoundStmtClass: |
| 280 | K = CXCursor_CompoundStmt; |
| 281 | break; |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 282 | |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 283 | case Stmt::NullStmtClass: |
| 284 | K = CXCursor_NullStmt; |
| 285 | break; |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 286 | |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 287 | case Stmt::LabelStmtClass: |
| 288 | K = CXCursor_LabelStmt; |
| 289 | break; |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 290 | |
| 291 | case Stmt::AttributedStmtClass: |
| 292 | K = CXCursor_UnexposedStmt; |
| 293 | break; |
| 294 | |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 295 | case Stmt::DeclStmtClass: |
| 296 | K = CXCursor_DeclStmt; |
| 297 | break; |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 298 | |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 299 | case Stmt::CapturedStmtClass: |
| 300 | K = CXCursor_UnexposedStmt; |
| 301 | break; |
| 302 | |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 303 | case Stmt::IntegerLiteralClass: |
| 304 | K = CXCursor_IntegerLiteral; |
| 305 | break; |
| 306 | |
| 307 | case Stmt::FloatingLiteralClass: |
| 308 | K = CXCursor_FloatingLiteral; |
| 309 | break; |
| 310 | |
| 311 | case Stmt::ImaginaryLiteralClass: |
| 312 | K = CXCursor_ImaginaryLiteral; |
| 313 | break; |
| 314 | |
| 315 | case Stmt::StringLiteralClass: |
| 316 | K = CXCursor_StringLiteral; |
| 317 | break; |
| 318 | |
| 319 | case Stmt::CharacterLiteralClass: |
| 320 | K = CXCursor_CharacterLiteral; |
| 321 | break; |
| 322 | |
| 323 | case Stmt::ParenExprClass: |
| 324 | K = CXCursor_ParenExpr; |
| 325 | break; |
| 326 | |
| 327 | case Stmt::UnaryOperatorClass: |
| 328 | K = CXCursor_UnaryOperator; |
| 329 | break; |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 330 | |
Olivier Goffart | 692d533 | 2016-06-09 16:16:06 +0000 | [diff] [blame] | 331 | case Stmt::UnaryExprOrTypeTraitExprClass: |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 332 | case Stmt::CXXNoexceptExprClass: |
| 333 | K = CXCursor_UnaryExpr; |
| 334 | break; |
| 335 | |
Alexey Bataev | f763027 | 2015-11-25 12:01:00 +0000 | [diff] [blame] | 336 | case Stmt::MSPropertySubscriptExprClass: |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 337 | case Stmt::ArraySubscriptExprClass: |
| 338 | K = CXCursor_ArraySubscriptExpr; |
| 339 | break; |
| 340 | |
Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 341 | case Stmt::OMPArraySectionExprClass: |
| 342 | K = CXCursor_OMPArraySectionExpr; |
| 343 | break; |
| 344 | |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 345 | case Stmt::BinaryOperatorClass: |
| 346 | K = CXCursor_BinaryOperator; |
| 347 | break; |
| 348 | |
| 349 | case Stmt::CompoundAssignOperatorClass: |
| 350 | K = CXCursor_CompoundAssignOperator; |
| 351 | break; |
| 352 | |
| 353 | case Stmt::ConditionalOperatorClass: |
| 354 | K = CXCursor_ConditionalOperator; |
| 355 | break; |
| 356 | |
| 357 | case Stmt::CStyleCastExprClass: |
| 358 | K = CXCursor_CStyleCastExpr; |
| 359 | break; |
| 360 | |
| 361 | case Stmt::CompoundLiteralExprClass: |
| 362 | K = CXCursor_CompoundLiteralExpr; |
| 363 | break; |
| 364 | |
| 365 | case Stmt::InitListExprClass: |
| 366 | K = CXCursor_InitListExpr; |
| 367 | break; |
| 368 | |
| 369 | case Stmt::AddrLabelExprClass: |
| 370 | K = CXCursor_AddrLabelExpr; |
| 371 | break; |
| 372 | |
| 373 | case Stmt::StmtExprClass: |
| 374 | K = CXCursor_StmtExpr; |
| 375 | break; |
| 376 | |
| 377 | case Stmt::GenericSelectionExprClass: |
| 378 | K = CXCursor_GenericSelectionExpr; |
| 379 | break; |
| 380 | |
| 381 | case Stmt::GNUNullExprClass: |
| 382 | K = CXCursor_GNUNullExpr; |
| 383 | break; |
| 384 | |
| 385 | case Stmt::CXXStaticCastExprClass: |
| 386 | K = CXCursor_CXXStaticCastExpr; |
| 387 | break; |
| 388 | |
| 389 | case Stmt::CXXDynamicCastExprClass: |
| 390 | K = CXCursor_CXXDynamicCastExpr; |
| 391 | break; |
| 392 | |
| 393 | case Stmt::CXXReinterpretCastExprClass: |
| 394 | K = CXCursor_CXXReinterpretCastExpr; |
| 395 | break; |
| 396 | |
| 397 | case Stmt::CXXConstCastExprClass: |
| 398 | K = CXCursor_CXXConstCastExpr; |
| 399 | break; |
| 400 | |
| 401 | case Stmt::CXXFunctionalCastExprClass: |
| 402 | K = CXCursor_CXXFunctionalCastExpr; |
| 403 | break; |
| 404 | |
| 405 | case Stmt::CXXTypeidExprClass: |
| 406 | K = CXCursor_CXXTypeidExpr; |
| 407 | break; |
| 408 | |
| 409 | case Stmt::CXXBoolLiteralExprClass: |
| 410 | K = CXCursor_CXXBoolLiteralExpr; |
| 411 | break; |
| 412 | |
| 413 | case Stmt::CXXNullPtrLiteralExprClass: |
| 414 | K = CXCursor_CXXNullPtrLiteralExpr; |
| 415 | break; |
| 416 | |
| 417 | case Stmt::CXXThisExprClass: |
| 418 | K = CXCursor_CXXThisExpr; |
| 419 | break; |
| 420 | |
| 421 | case Stmt::CXXThrowExprClass: |
| 422 | K = CXCursor_CXXThrowExpr; |
| 423 | break; |
| 424 | |
| 425 | case Stmt::CXXNewExprClass: |
| 426 | K = CXCursor_CXXNewExpr; |
| 427 | break; |
| 428 | |
| 429 | case Stmt::CXXDeleteExprClass: |
| 430 | K = CXCursor_CXXDeleteExpr; |
| 431 | break; |
| 432 | |
| 433 | case Stmt::ObjCStringLiteralClass: |
| 434 | K = CXCursor_ObjCStringLiteral; |
| 435 | break; |
| 436 | |
| 437 | case Stmt::ObjCEncodeExprClass: |
| 438 | K = CXCursor_ObjCEncodeExpr; |
| 439 | break; |
| 440 | |
| 441 | case Stmt::ObjCSelectorExprClass: |
| 442 | K = CXCursor_ObjCSelectorExpr; |
| 443 | break; |
| 444 | |
| 445 | case Stmt::ObjCProtocolExprClass: |
| 446 | K = CXCursor_ObjCProtocolExpr; |
| 447 | break; |
Ted Kremenek | 77006f6 | 2012-03-06 20:06:06 +0000 | [diff] [blame] | 448 | |
| 449 | case Stmt::ObjCBoolLiteralExprClass: |
| 450 | K = CXCursor_ObjCBoolLiteralExpr; |
| 451 | break; |
Erik Pilkington | 29099de | 2016-07-16 00:35:23 +0000 | [diff] [blame] | 452 | |
| 453 | case Stmt::ObjCAvailabilityCheckExprClass: |
| 454 | K = CXCursor_ObjCAvailabilityCheckExpr; |
| 455 | break; |
| 456 | |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 457 | case Stmt::ObjCBridgedCastExprClass: |
| 458 | K = CXCursor_ObjCBridgedCastExpr; |
| 459 | break; |
| 460 | |
| 461 | case Stmt::BlockExprClass: |
| 462 | K = CXCursor_BlockExpr; |
| 463 | break; |
| 464 | |
| 465 | case Stmt::PackExpansionExprClass: |
| 466 | K = CXCursor_PackExpansionExpr; |
| 467 | break; |
| 468 | |
| 469 | case Stmt::SizeOfPackExprClass: |
| 470 | K = CXCursor_SizeOfPackExpr; |
| 471 | break; |
| 472 | |
Argyrios Kyrtzidis | c2233be | 2013-04-23 17:57:17 +0000 | [diff] [blame] | 473 | case Stmt::DeclRefExprClass: |
| 474 | if (const ImplicitParamDecl *IPD = |
| 475 | dyn_cast_or_null<ImplicitParamDecl>(cast<DeclRefExpr>(S)->getDecl())) { |
| 476 | if (const ObjCMethodDecl *MD = |
| 477 | dyn_cast<ObjCMethodDecl>(IPD->getDeclContext())) { |
| 478 | if (MD->getSelfDecl() == IPD) { |
| 479 | K = CXCursor_ObjCSelfExpr; |
| 480 | break; |
| 481 | } |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | K = CXCursor_DeclRefExpr; |
| 486 | break; |
| 487 | |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 488 | case Stmt::DependentScopeDeclRefExprClass: |
John McCall | 7c454bb | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 489 | case Stmt::SubstNonTypeTemplateParmExprClass: |
Douglas Gregor | cdbc539 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 490 | case Stmt::SubstNonTypeTemplateParmPackExprClass: |
Richard Smith | b15fe3a | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 491 | case Stmt::FunctionParmPackExprClass: |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 492 | case Stmt::UnresolvedLookupExprClass: |
Kaelyn Takata | e1f49d5 | 2014-10-27 18:07:20 +0000 | [diff] [blame] | 493 | case Stmt::TypoExprClass: // A typo could actually be a DeclRef or a MemberRef |
Douglas Gregor | 8f40bbee | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 494 | K = CXCursor_DeclRefExpr; |
| 495 | break; |
| 496 | |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 497 | case Stmt::CXXDependentScopeMemberExprClass: |
| 498 | case Stmt::CXXPseudoDestructorExprClass: |
Douglas Gregor | 8f40bbee | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 499 | case Stmt::MemberExprClass: |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 500 | case Stmt::MSPropertyRefExprClass: |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 501 | case Stmt::ObjCIsaExprClass: |
Douglas Gregor | 8f40bbee | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 502 | case Stmt::ObjCIvarRefExprClass: |
| 503 | case Stmt::ObjCPropertyRefExprClass: |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 504 | case Stmt::UnresolvedMemberExprClass: |
Douglas Gregor | 8f40bbee | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 505 | K = CXCursor_MemberRefExpr; |
| 506 | break; |
| 507 | |
| 508 | case Stmt::CallExprClass: |
| 509 | case Stmt::CXXOperatorCallExprClass: |
| 510 | case Stmt::CXXMemberCallExprClass: |
Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 511 | case Stmt::CUDAKernelCallExprClass: |
Douglas Gregor | 8f40bbee | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 512 | case Stmt::CXXConstructExprClass: |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 513 | case Stmt::CXXInheritedCtorInitExprClass: |
Douglas Gregor | 8f40bbee | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 514 | case Stmt::CXXTemporaryObjectExprClass: |
Douglas Gregor | 4c362d5 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 515 | case Stmt::CXXUnresolvedConstructExprClass: |
Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 516 | case Stmt::UserDefinedLiteralClass: |
Douglas Gregor | 8f40bbee | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 517 | K = CXCursor_CallExpr; |
| 518 | break; |
| 519 | |
Douglas Gregor | 3009383 | 2012-02-15 00:54:55 +0000 | [diff] [blame] | 520 | case Stmt::LambdaExprClass: |
| 521 | K = CXCursor_LambdaExpr; |
| 522 | break; |
| 523 | |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 524 | case Stmt::ObjCMessageExprClass: { |
Douglas Gregor | 8f40bbee | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 525 | K = CXCursor_ObjCMessageExpr; |
Argyrios Kyrtzidis | cddafd3 | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 526 | int SelectorIdIndex = -1; |
| 527 | // Check if cursor points to a selector id. |
| 528 | if (RegionOfInterest.isValid() && |
| 529 | RegionOfInterest.getBegin() == RegionOfInterest.getEnd()) { |
| 530 | SmallVector<SourceLocation, 16> SelLocs; |
| 531 | cast<ObjCMessageExpr>(S)->getSelectorLocs(SelLocs); |
Craig Topper | 2341c0d | 2013-07-04 03:08:24 +0000 | [diff] [blame] | 532 | SmallVectorImpl<SourceLocation>::iterator |
Argyrios Kyrtzidis | cddafd3 | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 533 | I=std::find(SelLocs.begin(), SelLocs.end(),RegionOfInterest.getBegin()); |
| 534 | if (I != SelLocs.end()) |
| 535 | SelectorIdIndex = I - SelLocs.begin(); |
| 536 | } |
| 537 | CXCursor C = { K, 0, { Parent, S, TU } }; |
| 538 | return getSelectorIdentifierCursor(SelectorIdIndex, C); |
Douglas Gregor | 8f40bbee | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 539 | } |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 540 | |
| 541 | case Stmt::MSDependentExistsStmtClass: |
| 542 | K = CXCursor_UnexposedStmt; |
| 543 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 544 | case Stmt::OMPParallelDirectiveClass: |
| 545 | K = CXCursor_OMPParallelDirective; |
| 546 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 547 | case Stmt::OMPSimdDirectiveClass: |
| 548 | K = CXCursor_OMPSimdDirective; |
| 549 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 550 | case Stmt::OMPForDirectiveClass: |
| 551 | K = CXCursor_OMPForDirective; |
| 552 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 553 | case Stmt::OMPForSimdDirectiveClass: |
| 554 | K = CXCursor_OMPForSimdDirective; |
| 555 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 556 | case Stmt::OMPSectionsDirectiveClass: |
| 557 | K = CXCursor_OMPSectionsDirective; |
| 558 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 559 | case Stmt::OMPSectionDirectiveClass: |
| 560 | K = CXCursor_OMPSectionDirective; |
| 561 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 562 | case Stmt::OMPSingleDirectiveClass: |
| 563 | K = CXCursor_OMPSingleDirective; |
| 564 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 565 | case Stmt::OMPMasterDirectiveClass: |
| 566 | K = CXCursor_OMPMasterDirective; |
| 567 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 568 | case Stmt::OMPCriticalDirectiveClass: |
| 569 | K = CXCursor_OMPCriticalDirective; |
| 570 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 571 | case Stmt::OMPParallelForDirectiveClass: |
| 572 | K = CXCursor_OMPParallelForDirective; |
| 573 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 574 | case Stmt::OMPParallelForSimdDirectiveClass: |
| 575 | K = CXCursor_OMPParallelForSimdDirective; |
| 576 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 577 | case Stmt::OMPParallelSectionsDirectiveClass: |
| 578 | K = CXCursor_OMPParallelSectionsDirective; |
| 579 | break; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 580 | case Stmt::OMPTaskDirectiveClass: |
| 581 | K = CXCursor_OMPTaskDirective; |
| 582 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 583 | case Stmt::OMPTaskyieldDirectiveClass: |
| 584 | K = CXCursor_OMPTaskyieldDirective; |
| 585 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 586 | case Stmt::OMPBarrierDirectiveClass: |
| 587 | K = CXCursor_OMPBarrierDirective; |
| 588 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 589 | case Stmt::OMPTaskwaitDirectiveClass: |
| 590 | K = CXCursor_OMPTaskwaitDirective; |
| 591 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 592 | case Stmt::OMPTaskgroupDirectiveClass: |
| 593 | K = CXCursor_OMPTaskgroupDirective; |
| 594 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 595 | case Stmt::OMPFlushDirectiveClass: |
| 596 | K = CXCursor_OMPFlushDirective; |
| 597 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 598 | case Stmt::OMPOrderedDirectiveClass: |
| 599 | K = CXCursor_OMPOrderedDirective; |
| 600 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 601 | case Stmt::OMPAtomicDirectiveClass: |
| 602 | K = CXCursor_OMPAtomicDirective; |
| 603 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 604 | case Stmt::OMPTargetDirectiveClass: |
| 605 | K = CXCursor_OMPTargetDirective; |
| 606 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 607 | case Stmt::OMPTargetDataDirectiveClass: |
| 608 | K = CXCursor_OMPTargetDataDirective; |
| 609 | break; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 610 | case Stmt::OMPTargetEnterDataDirectiveClass: |
| 611 | K = CXCursor_OMPTargetEnterDataDirective; |
| 612 | break; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 613 | case Stmt::OMPTargetExitDataDirectiveClass: |
| 614 | K = CXCursor_OMPTargetExitDataDirective; |
| 615 | break; |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 616 | case Stmt::OMPTargetParallelDirectiveClass: |
| 617 | K = CXCursor_OMPTargetParallelDirective; |
| 618 | break; |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 619 | case Stmt::OMPTargetParallelForDirectiveClass: |
| 620 | K = CXCursor_OMPTargetParallelForDirective; |
| 621 | break; |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 622 | case Stmt::OMPTargetUpdateDirectiveClass: |
| 623 | K = CXCursor_OMPTargetUpdateDirective; |
| 624 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 625 | case Stmt::OMPTeamsDirectiveClass: |
| 626 | K = CXCursor_OMPTeamsDirective; |
| 627 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 628 | case Stmt::OMPCancellationPointDirectiveClass: |
| 629 | K = CXCursor_OMPCancellationPointDirective; |
| 630 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 631 | case Stmt::OMPCancelDirectiveClass: |
| 632 | K = CXCursor_OMPCancelDirective; |
| 633 | break; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 634 | case Stmt::OMPTaskLoopDirectiveClass: |
| 635 | K = CXCursor_OMPTaskLoopDirective; |
| 636 | break; |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 637 | case Stmt::OMPTaskLoopSimdDirectiveClass: |
| 638 | K = CXCursor_OMPTaskLoopSimdDirective; |
| 639 | break; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 640 | case Stmt::OMPDistributeDirectiveClass: |
| 641 | K = CXCursor_OMPDistributeDirective; |
| 642 | break; |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 643 | case Stmt::OMPDistributeParallelForDirectiveClass: |
| 644 | K = CXCursor_OMPDistributeParallelForDirective; |
| 645 | break; |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 646 | case Stmt::OMPDistributeParallelForSimdDirectiveClass: |
| 647 | K = CXCursor_OMPDistributeParallelForSimdDirective; |
| 648 | break; |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 649 | case Stmt::OMPDistributeSimdDirectiveClass: |
| 650 | K = CXCursor_OMPDistributeSimdDirective; |
| 651 | break; |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 652 | case Stmt::OMPTargetParallelForSimdDirectiveClass: |
| 653 | K = CXCursor_OMPTargetParallelForSimdDirective; |
| 654 | break; |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 655 | case Stmt::OMPTargetSimdDirectiveClass: |
| 656 | K = CXCursor_OMPTargetSimdDirective; |
| 657 | break; |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 658 | case Stmt::OMPTeamsDistributeDirectiveClass: |
| 659 | K = CXCursor_OMPTeamsDistributeDirective; |
| 660 | break; |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 661 | case Stmt::OMPTeamsDistributeSimdDirectiveClass: |
| 662 | K = CXCursor_OMPTeamsDistributeSimdDirective; |
| 663 | break; |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 664 | case Stmt::OMPTeamsDistributeParallelForSimdDirectiveClass: |
| 665 | K = CXCursor_OMPTeamsDistributeParallelForSimdDirective; |
| 666 | break; |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 667 | case Stmt::OMPTeamsDistributeParallelForDirectiveClass: |
| 668 | K = CXCursor_OMPTeamsDistributeParallelForDirective; |
| 669 | break; |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 670 | case Stmt::OMPTargetTeamsDirectiveClass: |
| 671 | K = CXCursor_OMPTargetTeamsDirective; |
| 672 | break; |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 673 | case Stmt::OMPTargetTeamsDistributeDirectiveClass: |
| 674 | K = CXCursor_OMPTargetTeamsDistributeDirective; |
| 675 | break; |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 676 | case Stmt::OMPTargetTeamsDistributeParallelForDirectiveClass: |
| 677 | K = CXCursor_OMPTargetTeamsDistributeParallelForDirective; |
| 678 | break; |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 679 | case Stmt::OMPTargetTeamsDistributeParallelForSimdDirectiveClass: |
| 680 | K = CXCursor_OMPTargetTeamsDistributeParallelForSimdDirective; |
| 681 | break; |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame^] | 682 | case Stmt::OMPTargetTeamsDistributeSimdDirectiveClass: |
| 683 | K = CXCursor_OMPTargetTeamsDistributeSimdDirective; |
| 684 | break; |
Douglas Gregor | deb4a2be | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 685 | } |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 686 | |
Argyrios Kyrtzidis | cddafd3 | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 687 | CXCursor C = { K, 0, { Parent, S, TU } }; |
Douglas Gregor | 8f40bbee | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 688 | return C; |
| 689 | } |
| 690 | |
Douglas Gregor | 6c8959b | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 691 | CXCursor cxcursor::MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super, |
Douglas Gregor | fed36b1 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 692 | SourceLocation Loc, |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 693 | CXTranslationUnit TU) { |
Daniel Dunbar | 2def7eb | 2010-01-25 00:40:30 +0000 | [diff] [blame] | 694 | assert(Super && TU && "Invalid arguments!"); |
Dmitri Gribenko | 19b79c8 | 2013-02-16 01:07:48 +0000 | [diff] [blame] | 695 | void *RawLoc = Loc.getPtrEncoding(); |
Argyrios Kyrtzidis | cddafd3 | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 696 | CXCursor C = { CXCursor_ObjCSuperClassRef, 0, { Super, RawLoc, TU } }; |
Douglas Gregor | 6c8959b | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 697 | return C; |
| 698 | } |
| 699 | |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 700 | std::pair<const ObjCInterfaceDecl *, SourceLocation> |
Douglas Gregor | 6c8959b | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 701 | cxcursor::getCursorObjCSuperClassRef(CXCursor C) { |
| 702 | assert(C.kind == CXCursor_ObjCSuperClassRef); |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 703 | return std::make_pair(static_cast<const ObjCInterfaceDecl *>(C.data[0]), |
Dmitri Gribenko | 6b8fca1 | 2013-02-14 20:07:36 +0000 | [diff] [blame] | 704 | SourceLocation::getFromPtrEncoding(C.data[1])); |
Douglas Gregor | 6c8959b | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 705 | } |
| 706 | |
Argyrios Kyrtzidis | dc199a3 | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 707 | CXCursor cxcursor::MakeCursorObjCProtocolRef(const ObjCProtocolDecl *Proto, |
Douglas Gregor | fed36b1 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 708 | SourceLocation Loc, |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 709 | CXTranslationUnit TU) { |
Argyrios Kyrtzidis | dc199a3 | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 710 | assert(Proto && TU && "Invalid arguments!"); |
Dmitri Gribenko | 19b79c8 | 2013-02-16 01:07:48 +0000 | [diff] [blame] | 711 | void *RawLoc = Loc.getPtrEncoding(); |
Dmitri Gribenko | 7a7284d | 2013-01-11 21:06:06 +0000 | [diff] [blame] | 712 | CXCursor C = { CXCursor_ObjCProtocolRef, 0, { Proto, RawLoc, TU } }; |
Douglas Gregor | ef6eb84 | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 713 | return C; |
| 714 | } |
| 715 | |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 716 | std::pair<const ObjCProtocolDecl *, SourceLocation> |
Douglas Gregor | ef6eb84 | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 717 | cxcursor::getCursorObjCProtocolRef(CXCursor C) { |
| 718 | assert(C.kind == CXCursor_ObjCProtocolRef); |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 719 | return std::make_pair(static_cast<const ObjCProtocolDecl *>(C.data[0]), |
Dmitri Gribenko | 6b8fca1 | 2013-02-14 20:07:36 +0000 | [diff] [blame] | 720 | SourceLocation::getFromPtrEncoding(C.data[1])); |
Douglas Gregor | ef6eb84 | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 721 | } |
| 722 | |
Argyrios Kyrtzidis | dc199a3 | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 723 | CXCursor cxcursor::MakeCursorObjCClassRef(const ObjCInterfaceDecl *Class, |
Douglas Gregor | fed36b1 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 724 | SourceLocation Loc, |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 725 | CXTranslationUnit TU) { |
Ted Kremenek | e184ac5 | 2010-03-19 20:39:03 +0000 | [diff] [blame] | 726 | // 'Class' can be null for invalid code. |
| 727 | if (!Class) |
| 728 | return MakeCXCursorInvalid(CXCursor_InvalidCode); |
| 729 | assert(TU && "Invalid arguments!"); |
Dmitri Gribenko | 19b79c8 | 2013-02-16 01:07:48 +0000 | [diff] [blame] | 730 | void *RawLoc = Loc.getPtrEncoding(); |
Dmitri Gribenko | 7a7284d | 2013-01-11 21:06:06 +0000 | [diff] [blame] | 731 | CXCursor C = { CXCursor_ObjCClassRef, 0, { Class, RawLoc, TU } }; |
Douglas Gregor | 46d6614 | 2010-01-16 17:14:40 +0000 | [diff] [blame] | 732 | return C; |
| 733 | } |
| 734 | |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 735 | std::pair<const ObjCInterfaceDecl *, SourceLocation> |
Douglas Gregor | 46d6614 | 2010-01-16 17:14:40 +0000 | [diff] [blame] | 736 | cxcursor::getCursorObjCClassRef(CXCursor C) { |
| 737 | assert(C.kind == CXCursor_ObjCClassRef); |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 738 | return std::make_pair(static_cast<const ObjCInterfaceDecl *>(C.data[0]), |
Dmitri Gribenko | 6b8fca1 | 2013-02-14 20:07:36 +0000 | [diff] [blame] | 739 | SourceLocation::getFromPtrEncoding(C.data[1])); |
Douglas Gregor | 46d6614 | 2010-01-16 17:14:40 +0000 | [diff] [blame] | 740 | } |
| 741 | |
Argyrios Kyrtzidis | dc199a3 | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 742 | CXCursor cxcursor::MakeCursorTypeRef(const TypeDecl *Type, SourceLocation Loc, |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 743 | CXTranslationUnit TU) { |
Daniel Dunbar | 2def7eb | 2010-01-25 00:40:30 +0000 | [diff] [blame] | 744 | assert(Type && TU && "Invalid arguments!"); |
Dmitri Gribenko | 19b79c8 | 2013-02-16 01:07:48 +0000 | [diff] [blame] | 745 | void *RawLoc = Loc.getPtrEncoding(); |
Dmitri Gribenko | 7a7284d | 2013-01-11 21:06:06 +0000 | [diff] [blame] | 746 | CXCursor C = { CXCursor_TypeRef, 0, { Type, RawLoc, TU } }; |
Douglas Gregor | 93f8995 | 2010-01-21 16:28:34 +0000 | [diff] [blame] | 747 | return C; |
| 748 | } |
| 749 | |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 750 | std::pair<const TypeDecl *, SourceLocation> |
Douglas Gregor | 93f8995 | 2010-01-21 16:28:34 +0000 | [diff] [blame] | 751 | cxcursor::getCursorTypeRef(CXCursor C) { |
| 752 | assert(C.kind == CXCursor_TypeRef); |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 753 | return std::make_pair(static_cast<const TypeDecl *>(C.data[0]), |
Dmitri Gribenko | 6b8fca1 | 2013-02-14 20:07:36 +0000 | [diff] [blame] | 754 | SourceLocation::getFromPtrEncoding(C.data[1])); |
Douglas Gregor | 93f8995 | 2010-01-21 16:28:34 +0000 | [diff] [blame] | 755 | } |
| 756 | |
Argyrios Kyrtzidis | effdbf5 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 757 | CXCursor cxcursor::MakeCursorTemplateRef(const TemplateDecl *Template, |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 758 | SourceLocation Loc, |
| 759 | CXTranslationUnit TU) { |
Douglas Gregor | a23e8f7 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 760 | assert(Template && TU && "Invalid arguments!"); |
Dmitri Gribenko | 19b79c8 | 2013-02-16 01:07:48 +0000 | [diff] [blame] | 761 | void *RawLoc = Loc.getPtrEncoding(); |
Dmitri Gribenko | 7a7284d | 2013-01-11 21:06:06 +0000 | [diff] [blame] | 762 | CXCursor C = { CXCursor_TemplateRef, 0, { Template, RawLoc, TU } }; |
Douglas Gregor | a23e8f7 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 763 | return C; |
| 764 | } |
| 765 | |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 766 | std::pair<const TemplateDecl *, SourceLocation> |
Douglas Gregor | a23e8f7 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 767 | cxcursor::getCursorTemplateRef(CXCursor C) { |
| 768 | assert(C.kind == CXCursor_TemplateRef); |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 769 | return std::make_pair(static_cast<const TemplateDecl *>(C.data[0]), |
Dmitri Gribenko | 6b8fca1 | 2013-02-14 20:07:36 +0000 | [diff] [blame] | 770 | SourceLocation::getFromPtrEncoding(C.data[1])); |
Douglas Gregor | a23e8f7 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 771 | } |
| 772 | |
Argyrios Kyrtzidis | effdbf5 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 773 | CXCursor cxcursor::MakeCursorNamespaceRef(const NamedDecl *NS, |
| 774 | SourceLocation Loc, |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 775 | CXTranslationUnit TU) { |
Douglas Gregor | a89314e | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 776 | |
| 777 | assert(NS && (isa<NamespaceDecl>(NS) || isa<NamespaceAliasDecl>(NS)) && TU && |
| 778 | "Invalid arguments!"); |
Dmitri Gribenko | 19b79c8 | 2013-02-16 01:07:48 +0000 | [diff] [blame] | 779 | void *RawLoc = Loc.getPtrEncoding(); |
Dmitri Gribenko | 7a7284d | 2013-01-11 21:06:06 +0000 | [diff] [blame] | 780 | CXCursor C = { CXCursor_NamespaceRef, 0, { NS, RawLoc, TU } }; |
Douglas Gregor | a89314e | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 781 | return C; |
| 782 | } |
| 783 | |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 784 | std::pair<const NamedDecl *, SourceLocation> |
Douglas Gregor | a89314e | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 785 | cxcursor::getCursorNamespaceRef(CXCursor C) { |
| 786 | assert(C.kind == CXCursor_NamespaceRef); |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 787 | return std::make_pair(static_cast<const NamedDecl *>(C.data[0]), |
Dmitri Gribenko | 6b8fca1 | 2013-02-14 20:07:36 +0000 | [diff] [blame] | 788 | SourceLocation::getFromPtrEncoding(C.data[1])); |
Douglas Gregor | a89314e | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 789 | } |
| 790 | |
Douglas Gregor | 3009383 | 2012-02-15 00:54:55 +0000 | [diff] [blame] | 791 | CXCursor cxcursor::MakeCursorVariableRef(const VarDecl *Var, SourceLocation Loc, |
| 792 | CXTranslationUnit TU) { |
| 793 | |
| 794 | assert(Var && TU && "Invalid arguments!"); |
Dmitri Gribenko | 19b79c8 | 2013-02-16 01:07:48 +0000 | [diff] [blame] | 795 | void *RawLoc = Loc.getPtrEncoding(); |
Dmitri Gribenko | 7a7284d | 2013-01-11 21:06:06 +0000 | [diff] [blame] | 796 | CXCursor C = { CXCursor_VariableRef, 0, { Var, RawLoc, TU } }; |
Douglas Gregor | 3009383 | 2012-02-15 00:54:55 +0000 | [diff] [blame] | 797 | return C; |
| 798 | } |
| 799 | |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 800 | std::pair<const VarDecl *, SourceLocation> |
Douglas Gregor | 3009383 | 2012-02-15 00:54:55 +0000 | [diff] [blame] | 801 | cxcursor::getCursorVariableRef(CXCursor C) { |
| 802 | assert(C.kind == CXCursor_VariableRef); |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 803 | return std::make_pair(static_cast<const VarDecl *>(C.data[0]), |
Dmitri Gribenko | 6b8fca1 | 2013-02-14 20:07:36 +0000 | [diff] [blame] | 804 | SourceLocation::getFromPtrEncoding(C.data[1])); |
Douglas Gregor | 3009383 | 2012-02-15 00:54:55 +0000 | [diff] [blame] | 805 | } |
| 806 | |
Argyrios Kyrtzidis | effdbf5 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 807 | CXCursor cxcursor::MakeCursorMemberRef(const FieldDecl *Field, SourceLocation Loc, |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 808 | CXTranslationUnit TU) { |
Douglas Gregor | f3af311 | 2010-09-09 21:42:20 +0000 | [diff] [blame] | 809 | |
| 810 | assert(Field && TU && "Invalid arguments!"); |
Dmitri Gribenko | 19b79c8 | 2013-02-16 01:07:48 +0000 | [diff] [blame] | 811 | void *RawLoc = Loc.getPtrEncoding(); |
Dmitri Gribenko | 7a7284d | 2013-01-11 21:06:06 +0000 | [diff] [blame] | 812 | CXCursor C = { CXCursor_MemberRef, 0, { Field, RawLoc, TU } }; |
Douglas Gregor | f3af311 | 2010-09-09 21:42:20 +0000 | [diff] [blame] | 813 | return C; |
| 814 | } |
| 815 | |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 816 | std::pair<const FieldDecl *, SourceLocation> |
Douglas Gregor | f3af311 | 2010-09-09 21:42:20 +0000 | [diff] [blame] | 817 | cxcursor::getCursorMemberRef(CXCursor C) { |
| 818 | assert(C.kind == CXCursor_MemberRef); |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 819 | return std::make_pair(static_cast<const FieldDecl *>(C.data[0]), |
Dmitri Gribenko | 6b8fca1 | 2013-02-14 20:07:36 +0000 | [diff] [blame] | 820 | SourceLocation::getFromPtrEncoding(C.data[1])); |
Douglas Gregor | f3af311 | 2010-09-09 21:42:20 +0000 | [diff] [blame] | 821 | } |
| 822 | |
Argyrios Kyrtzidis | 4c910b1 | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 823 | CXCursor cxcursor::MakeCursorCXXBaseSpecifier(const CXXBaseSpecifier *B, |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 824 | CXTranslationUnit TU){ |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 825 | CXCursor C = { CXCursor_CXXBaseSpecifier, 0, { B, nullptr, TU } }; |
Ted Kremenek | ae9e221 | 2010-08-27 21:34:58 +0000 | [diff] [blame] | 826 | return C; |
| 827 | } |
| 828 | |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 829 | const CXXBaseSpecifier *cxcursor::getCursorCXXBaseSpecifier(CXCursor C) { |
Ted Kremenek | ae9e221 | 2010-08-27 21:34:58 +0000 | [diff] [blame] | 830 | assert(C.kind == CXCursor_CXXBaseSpecifier); |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 831 | return static_cast<const CXXBaseSpecifier*>(C.data[0]); |
Ted Kremenek | ae9e221 | 2010-08-27 21:34:58 +0000 | [diff] [blame] | 832 | } |
| 833 | |
Douglas Gregor | 92a524f | 2010-03-18 00:42:48 +0000 | [diff] [blame] | 834 | CXCursor cxcursor::MakePreprocessingDirectiveCursor(SourceRange Range, |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 835 | CXTranslationUnit TU) { |
Argyrios Kyrtzidis | cddafd3 | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 836 | CXCursor C = { CXCursor_PreprocessingDirective, 0, |
Dmitri Gribenko | 19b79c8 | 2013-02-16 01:07:48 +0000 | [diff] [blame] | 837 | { Range.getBegin().getPtrEncoding(), |
| 838 | Range.getEnd().getPtrEncoding(), |
Douglas Gregor | 92a524f | 2010-03-18 00:42:48 +0000 | [diff] [blame] | 839 | TU } |
| 840 | }; |
| 841 | return C; |
| 842 | } |
| 843 | |
| 844 | SourceRange cxcursor::getCursorPreprocessingDirective(CXCursor C) { |
| 845 | assert(C.kind == CXCursor_PreprocessingDirective); |
Dmitri Gribenko | 6b8fca1 | 2013-02-14 20:07:36 +0000 | [diff] [blame] | 846 | SourceRange Range(SourceLocation::getFromPtrEncoding(C.data[0]), |
| 847 | SourceLocation::getFromPtrEncoding(C.data[1])); |
Argyrios Kyrtzidis | 4cdfcae | 2011-09-26 08:01:41 +0000 | [diff] [blame] | 848 | ASTUnit *TU = getCursorASTUnit(C); |
| 849 | return TU->mapRangeFromPreamble(Range); |
Douglas Gregor | 92a524f | 2010-03-18 00:42:48 +0000 | [diff] [blame] | 850 | } |
| 851 | |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 852 | CXCursor cxcursor::MakeMacroDefinitionCursor(const MacroDefinitionRecord *MI, |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 853 | CXTranslationUnit TU) { |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 854 | CXCursor C = {CXCursor_MacroDefinition, 0, {MI, nullptr, TU}}; |
Douglas Gregor | 06d6d32 | 2010-03-18 18:04:21 +0000 | [diff] [blame] | 855 | return C; |
| 856 | } |
| 857 | |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 858 | const MacroDefinitionRecord *cxcursor::getCursorMacroDefinition(CXCursor C) { |
Douglas Gregor | 06d6d32 | 2010-03-18 18:04:21 +0000 | [diff] [blame] | 859 | assert(C.kind == CXCursor_MacroDefinition); |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 860 | return static_cast<const MacroDefinitionRecord *>(C.data[0]); |
Douglas Gregor | 06d6d32 | 2010-03-18 18:04:21 +0000 | [diff] [blame] | 861 | } |
| 862 | |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 863 | CXCursor cxcursor::MakeMacroExpansionCursor(MacroExpansion *MI, |
Chandler Carruth | a88a2218 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 864 | CXTranslationUnit TU) { |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 865 | CXCursor C = { CXCursor_MacroExpansion, 0, { MI, nullptr, TU } }; |
Douglas Gregor | 02ded2a | 2010-03-18 15:23:44 +0000 | [diff] [blame] | 866 | return C; |
| 867 | } |
| 868 | |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 869 | CXCursor cxcursor::MakeMacroExpansionCursor(MacroDefinitionRecord *MI, |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 870 | SourceLocation Loc, |
| 871 | CXTranslationUnit TU) { |
| 872 | assert(Loc.isValid()); |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 873 | CXCursor C = {CXCursor_MacroExpansion, 0, {MI, Loc.getPtrEncoding(), TU}}; |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 874 | return C; |
| 875 | } |
| 876 | |
| 877 | const IdentifierInfo *cxcursor::MacroExpansionCursor::getName() const { |
| 878 | if (isPseudo()) |
| 879 | return getAsMacroDefinition()->getName(); |
| 880 | return getAsMacroExpansion()->getName(); |
| 881 | } |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 882 | const MacroDefinitionRecord * |
| 883 | cxcursor::MacroExpansionCursor::getDefinition() const { |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 884 | if (isPseudo()) |
| 885 | return getAsMacroDefinition(); |
| 886 | return getAsMacroExpansion()->getDefinition(); |
| 887 | } |
| 888 | SourceRange cxcursor::MacroExpansionCursor::getSourceRange() const { |
| 889 | if (isPseudo()) |
| 890 | return getPseudoLoc(); |
| 891 | return getAsMacroExpansion()->getSourceRange(); |
Douglas Gregor | 02ded2a | 2010-03-18 15:23:44 +0000 | [diff] [blame] | 892 | } |
| 893 | |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 894 | CXCursor cxcursor::MakeInclusionDirectiveCursor(InclusionDirective *ID, |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 895 | CXTranslationUnit TU) { |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 896 | CXCursor C = { CXCursor_InclusionDirective, 0, { ID, nullptr, TU } }; |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 897 | return C; |
| 898 | } |
| 899 | |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 900 | const InclusionDirective *cxcursor::getCursorInclusionDirective(CXCursor C) { |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 901 | assert(C.kind == CXCursor_InclusionDirective); |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 902 | return static_cast<const InclusionDirective *>(C.data[0]); |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 903 | } |
| 904 | |
Douglas Gregor | a93ab66 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 905 | CXCursor cxcursor::MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc, |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 906 | CXTranslationUnit TU) { |
Douglas Gregor | a93ab66 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 907 | |
| 908 | assert(Label && TU && "Invalid arguments!"); |
Dmitri Gribenko | 19b79c8 | 2013-02-16 01:07:48 +0000 | [diff] [blame] | 909 | void *RawLoc = Loc.getPtrEncoding(); |
Argyrios Kyrtzidis | cddafd3 | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 910 | CXCursor C = { CXCursor_LabelRef, 0, { Label, RawLoc, TU } }; |
Douglas Gregor | a93ab66 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 911 | return C; |
| 912 | } |
| 913 | |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 914 | std::pair<const LabelStmt *, SourceLocation> |
Douglas Gregor | a93ab66 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 915 | cxcursor::getCursorLabelRef(CXCursor C) { |
| 916 | assert(C.kind == CXCursor_LabelRef); |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 917 | return std::make_pair(static_cast<const LabelStmt *>(C.data[0]), |
Dmitri Gribenko | 6b8fca1 | 2013-02-14 20:07:36 +0000 | [diff] [blame] | 918 | SourceLocation::getFromPtrEncoding(C.data[1])); |
Douglas Gregor | a93ab66 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 919 | } |
| 920 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 921 | CXCursor cxcursor::MakeCursorOverloadedDeclRef(const OverloadExpr *E, |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 922 | CXTranslationUnit TU) { |
Douglas Gregor | 16a2bdd | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 923 | assert(E && TU && "Invalid arguments!"); |
| 924 | OverloadedDeclRefStorage Storage(E); |
Dmitri Gribenko | 19b79c8 | 2013-02-16 01:07:48 +0000 | [diff] [blame] | 925 | void *RawLoc = E->getNameLoc().getPtrEncoding(); |
Douglas Gregor | 16a2bdd | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 926 | CXCursor C = { |
Argyrios Kyrtzidis | cddafd3 | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 927 | CXCursor_OverloadedDeclRef, 0, |
Douglas Gregor | 16a2bdd | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 928 | { Storage.getOpaqueValue(), RawLoc, TU } |
| 929 | }; |
| 930 | return C; |
| 931 | } |
| 932 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 933 | CXCursor cxcursor::MakeCursorOverloadedDeclRef(const Decl *D, |
Douglas Gregor | 16a2bdd | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 934 | SourceLocation Loc, |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 935 | CXTranslationUnit TU) { |
Douglas Gregor | 16a2bdd | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 936 | assert(D && TU && "Invalid arguments!"); |
Dmitri Gribenko | 19b79c8 | 2013-02-16 01:07:48 +0000 | [diff] [blame] | 937 | void *RawLoc = Loc.getPtrEncoding(); |
Douglas Gregor | 16a2bdd | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 938 | OverloadedDeclRefStorage Storage(D); |
| 939 | CXCursor C = { |
Argyrios Kyrtzidis | cddafd3 | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 940 | CXCursor_OverloadedDeclRef, 0, |
Douglas Gregor | 16a2bdd | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 941 | { Storage.getOpaqueValue(), RawLoc, TU } |
| 942 | }; |
| 943 | return C; |
| 944 | } |
| 945 | |
| 946 | CXCursor cxcursor::MakeCursorOverloadedDeclRef(TemplateName Name, |
| 947 | SourceLocation Loc, |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 948 | CXTranslationUnit TU) { |
Douglas Gregor | 16a2bdd | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 949 | assert(Name.getAsOverloadedTemplate() && TU && "Invalid arguments!"); |
Dmitri Gribenko | 19b79c8 | 2013-02-16 01:07:48 +0000 | [diff] [blame] | 950 | void *RawLoc = Loc.getPtrEncoding(); |
Douglas Gregor | 16a2bdd | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 951 | OverloadedDeclRefStorage Storage(Name.getAsOverloadedTemplate()); |
| 952 | CXCursor C = { |
Argyrios Kyrtzidis | cddafd3 | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 953 | CXCursor_OverloadedDeclRef, 0, |
Douglas Gregor | 16a2bdd | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 954 | { Storage.getOpaqueValue(), RawLoc, TU } |
| 955 | }; |
| 956 | return C; |
| 957 | } |
| 958 | |
| 959 | std::pair<cxcursor::OverloadedDeclRefStorage, SourceLocation> |
| 960 | cxcursor::getCursorOverloadedDeclRef(CXCursor C) { |
| 961 | assert(C.kind == CXCursor_OverloadedDeclRef); |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 962 | return std::make_pair(OverloadedDeclRefStorage::getFromOpaqueValue( |
| 963 | const_cast<void *>(C.data[0])), |
Dmitri Gribenko | 6b8fca1 | 2013-02-14 20:07:36 +0000 | [diff] [blame] | 964 | SourceLocation::getFromPtrEncoding(C.data[1])); |
Douglas Gregor | 16a2bdd | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 965 | } |
| 966 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 967 | const Decl *cxcursor::getCursorDecl(CXCursor Cursor) { |
| 968 | return static_cast<const Decl *>(Cursor.data[0]); |
Douglas Gregor | c58d05b | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 969 | } |
| 970 | |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 971 | const Expr *cxcursor::getCursorExpr(CXCursor Cursor) { |
Douglas Gregor | c58d05b | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 972 | return dyn_cast_or_null<Expr>(getCursorStmt(Cursor)); |
| 973 | } |
| 974 | |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 975 | const Stmt *cxcursor::getCursorStmt(CXCursor Cursor) { |
Douglas Gregor | ef6eb84 | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 976 | if (Cursor.kind == CXCursor_ObjCSuperClassRef || |
Douglas Gregor | 46d6614 | 2010-01-16 17:14:40 +0000 | [diff] [blame] | 977 | Cursor.kind == CXCursor_ObjCProtocolRef || |
| 978 | Cursor.kind == CXCursor_ObjCClassRef) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 979 | return nullptr; |
Douglas Gregor | 6c8959b | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 980 | |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 981 | return static_cast<const Stmt *>(Cursor.data[1]); |
Douglas Gregor | c58d05b | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 982 | } |
| 983 | |
Dmitri Gribenko | e4baea6 | 2013-01-26 18:08:08 +0000 | [diff] [blame] | 984 | const Attr *cxcursor::getCursorAttr(CXCursor Cursor) { |
| 985 | return static_cast<const Attr *>(Cursor.data[1]); |
Ted Kremenek | a594082 | 2010-08-26 01:42:22 +0000 | [diff] [blame] | 986 | } |
| 987 | |
Dmitri Gribenko | a169118 | 2013-01-26 18:12:08 +0000 | [diff] [blame] | 988 | const Decl *cxcursor::getCursorParentDecl(CXCursor Cursor) { |
| 989 | return static_cast<const Decl *>(Cursor.data[0]); |
Argyrios Kyrtzidis | 8bb2ecf | 2011-06-29 22:20:07 +0000 | [diff] [blame] | 990 | } |
| 991 | |
Douglas Gregor | 7ecd020 | 2010-01-18 23:41:10 +0000 | [diff] [blame] | 992 | ASTContext &cxcursor::getCursorContext(CXCursor Cursor) { |
Douglas Gregor | fed36b1 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 993 | return getCursorASTUnit(Cursor)->getASTContext(); |
| 994 | } |
Douglas Gregor | 7ecd020 | 2010-01-18 23:41:10 +0000 | [diff] [blame] | 995 | |
Douglas Gregor | fed36b1 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 996 | ASTUnit *cxcursor::getCursorASTUnit(CXCursor Cursor) { |
Dmitri Gribenko | 2c173b4 | 2013-01-11 19:28:44 +0000 | [diff] [blame] | 997 | CXTranslationUnit TU = getCursorTU(Cursor); |
Argyrios Kyrtzidis | fa469d0 | 2011-12-09 00:17:49 +0000 | [diff] [blame] | 998 | if (!TU) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 999 | return nullptr; |
Dmitri Gribenko | c22ea1c | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 1000 | return cxtu::getASTUnit(TU); |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | CXTranslationUnit cxcursor::getCursorTU(CXCursor Cursor) { |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 1004 | return static_cast<CXTranslationUnit>(const_cast<void*>(Cursor.data[2])); |
Douglas Gregor | c58d05b | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 1005 | } |
| 1006 | |
Argyrios Kyrtzidis | 08f96a9 | 2012-05-09 16:12:57 +0000 | [diff] [blame] | 1007 | void cxcursor::getOverriddenCursors(CXCursor cursor, |
| 1008 | SmallVectorImpl<CXCursor> &overridden) { |
| 1009 | assert(clang_isDeclaration(cursor.kind)); |
Argyrios Kyrtzidis | b9556e6 | 2012-10-09 01:23:50 +0000 | [diff] [blame] | 1010 | const NamedDecl *D = dyn_cast_or_null<NamedDecl>(getCursorDecl(cursor)); |
Argyrios Kyrtzidis | 08f96a9 | 2012-05-09 16:12:57 +0000 | [diff] [blame] | 1011 | if (!D) |
| 1012 | return; |
| 1013 | |
Argyrios Kyrtzidis | 08f96a9 | 2012-05-09 16:12:57 +0000 | [diff] [blame] | 1014 | CXTranslationUnit TU = getCursorTU(cursor); |
Argyrios Kyrtzidis | b9556e6 | 2012-10-09 01:23:50 +0000 | [diff] [blame] | 1015 | SmallVector<const NamedDecl *, 8> OverDecls; |
| 1016 | D->getASTContext().getOverriddenMethods(D, OverDecls); |
Argyrios Kyrtzidis | 08f96a9 | 2012-05-09 16:12:57 +0000 | [diff] [blame] | 1017 | |
Craig Topper | 2341c0d | 2013-07-04 03:08:24 +0000 | [diff] [blame] | 1018 | for (SmallVectorImpl<const NamedDecl *>::iterator |
Argyrios Kyrtzidis | b9556e6 | 2012-10-09 01:23:50 +0000 | [diff] [blame] | 1019 | I = OverDecls.begin(), E = OverDecls.end(); I != E; ++I) { |
Dmitri Gribenko | 9c256e3 | 2013-01-14 00:46:27 +0000 | [diff] [blame] | 1020 | overridden.push_back(MakeCXCursor(*I, TU)); |
Argyrios Kyrtzidis | 08f96a9 | 2012-05-09 16:12:57 +0000 | [diff] [blame] | 1021 | } |
| 1022 | } |
| 1023 | |
Argyrios Kyrtzidis | cddafd3 | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 1024 | std::pair<int, SourceLocation> |
| 1025 | cxcursor::getSelectorIdentifierIndexAndLoc(CXCursor cursor) { |
| 1026 | if (cursor.kind == CXCursor_ObjCMessageExpr) { |
| 1027 | if (cursor.xdata != -1) |
| 1028 | return std::make_pair(cursor.xdata, |
| 1029 | cast<ObjCMessageExpr>(getCursorExpr(cursor)) |
| 1030 | ->getSelectorLoc(cursor.xdata)); |
| 1031 | } else if (cursor.kind == CXCursor_ObjCClassMethodDecl || |
| 1032 | cursor.kind == CXCursor_ObjCInstanceMethodDecl) { |
| 1033 | if (cursor.xdata != -1) |
| 1034 | return std::make_pair(cursor.xdata, |
| 1035 | cast<ObjCMethodDecl>(getCursorDecl(cursor)) |
| 1036 | ->getSelectorLoc(cursor.xdata)); |
| 1037 | } |
| 1038 | |
| 1039 | return std::make_pair(-1, SourceLocation()); |
| 1040 | } |
| 1041 | |
| 1042 | CXCursor cxcursor::getSelectorIdentifierCursor(int SelIdx, CXCursor cursor) { |
| 1043 | CXCursor newCursor = cursor; |
| 1044 | |
| 1045 | if (cursor.kind == CXCursor_ObjCMessageExpr) { |
| 1046 | if (SelIdx == -1 || |
| 1047 | unsigned(SelIdx) >= cast<ObjCMessageExpr>(getCursorExpr(cursor)) |
| 1048 | ->getNumSelectorLocs()) |
| 1049 | newCursor.xdata = -1; |
| 1050 | else |
| 1051 | newCursor.xdata = SelIdx; |
| 1052 | } else if (cursor.kind == CXCursor_ObjCClassMethodDecl || |
| 1053 | cursor.kind == CXCursor_ObjCInstanceMethodDecl) { |
| 1054 | if (SelIdx == -1 || |
| 1055 | unsigned(SelIdx) >= cast<ObjCMethodDecl>(getCursorDecl(cursor)) |
| 1056 | ->getNumSelectorLocs()) |
| 1057 | newCursor.xdata = -1; |
| 1058 | else |
| 1059 | newCursor.xdata = SelIdx; |
| 1060 | } |
| 1061 | |
| 1062 | return newCursor; |
| 1063 | } |
| 1064 | |
| 1065 | CXCursor cxcursor::getTypeRefCursor(CXCursor cursor) { |
| 1066 | if (cursor.kind != CXCursor_CallExpr) |
| 1067 | return cursor; |
| 1068 | |
| 1069 | if (cursor.xdata == 0) |
| 1070 | return cursor; |
| 1071 | |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 1072 | const Expr *E = getCursorExpr(cursor); |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 1073 | TypeSourceInfo *Type = nullptr; |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 1074 | if (const CXXUnresolvedConstructExpr * |
Argyrios Kyrtzidis | cddafd3 | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 1075 | UnCtor = dyn_cast<CXXUnresolvedConstructExpr>(E)) { |
| 1076 | Type = UnCtor->getTypeSourceInfo(); |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 1077 | } else if (const CXXTemporaryObjectExpr *Tmp = |
| 1078 | dyn_cast<CXXTemporaryObjectExpr>(E)){ |
Argyrios Kyrtzidis | cddafd3 | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 1079 | Type = Tmp->getTypeSourceInfo(); |
| 1080 | } |
| 1081 | |
| 1082 | if (!Type) |
| 1083 | return cursor; |
| 1084 | |
| 1085 | CXTranslationUnit TU = getCursorTU(cursor); |
| 1086 | QualType Ty = Type->getType(); |
| 1087 | TypeLoc TL = Type->getTypeLoc(); |
| 1088 | SourceLocation Loc = TL.getBeginLoc(); |
| 1089 | |
| 1090 | if (const ElaboratedType *ElabT = Ty->getAs<ElaboratedType>()) { |
| 1091 | Ty = ElabT->getNamedType(); |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 1092 | ElaboratedTypeLoc ElabTL = TL.castAs<ElaboratedTypeLoc>(); |
Argyrios Kyrtzidis | cddafd3 | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 1093 | Loc = ElabTL.getNamedTypeLoc().getBeginLoc(); |
| 1094 | } |
| 1095 | |
| 1096 | if (const TypedefType *Typedef = Ty->getAs<TypedefType>()) |
| 1097 | return MakeCursorTypeRef(Typedef->getDecl(), Loc, TU); |
| 1098 | if (const TagType *Tag = Ty->getAs<TagType>()) |
| 1099 | return MakeCursorTypeRef(Tag->getDecl(), Loc, TU); |
| 1100 | if (const TemplateTypeParmType *TemplP = Ty->getAs<TemplateTypeParmType>()) |
| 1101 | return MakeCursorTypeRef(TemplP->getDecl(), Loc, TU); |
| 1102 | |
| 1103 | return cursor; |
| 1104 | } |
| 1105 | |
Douglas Gregor | c58d05b | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 1106 | bool cxcursor::operator==(CXCursor X, CXCursor Y) { |
| 1107 | return X.kind == Y.kind && X.data[0] == Y.data[0] && X.data[1] == Y.data[1] && |
| 1108 | X.data[2] == Y.data[2]; |
Douglas Gregor | 6c8959b | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 1109 | } |
Ted Kremenek | 818e5c1 | 2010-11-01 23:26:51 +0000 | [diff] [blame] | 1110 | |
| 1111 | // FIXME: Remove once we can model DeclGroups and their appropriate ranges |
| 1112 | // properly in the ASTs. |
| 1113 | bool cxcursor::isFirstInDeclGroup(CXCursor C) { |
| 1114 | assert(clang_isDeclaration(C.kind)); |
| 1115 | return ((uintptr_t) (C.data[1])) != 0; |
| 1116 | } |
| 1117 | |
Ted Kremenek | bbedd06 | 2010-12-08 23:43:14 +0000 | [diff] [blame] | 1118 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | d6e9fa5 | 2011-09-27 00:30:30 +0000 | [diff] [blame] | 1119 | // libclang CXCursor APIs |
| 1120 | //===----------------------------------------------------------------------===// |
| 1121 | |
Argyrios Kyrtzidis | a1bcb6a | 2011-09-27 04:14:36 +0000 | [diff] [blame] | 1122 | int clang_Cursor_isNull(CXCursor cursor) { |
| 1123 | return clang_equalCursors(cursor, clang_getNullCursor()); |
| 1124 | } |
| 1125 | |
Argyrios Kyrtzidis | d6e9fa5 | 2011-09-27 00:30:30 +0000 | [diff] [blame] | 1126 | CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor cursor) { |
| 1127 | return getCursorTU(cursor); |
| 1128 | } |
| 1129 | |
Argyrios Kyrtzidis | 0c27e4b | 2012-04-11 19:32:19 +0000 | [diff] [blame] | 1130 | int clang_Cursor_getNumArguments(CXCursor C) { |
| 1131 | if (clang_isDeclaration(C.kind)) { |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 1132 | const Decl *D = cxcursor::getCursorDecl(C); |
Argyrios Kyrtzidis | 0c27e4b | 2012-04-11 19:32:19 +0000 | [diff] [blame] | 1133 | if (const ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(D)) |
| 1134 | return MD->param_size(); |
| 1135 | if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) |
| 1136 | return FD->param_size(); |
| 1137 | } |
| 1138 | |
Argyrios Kyrtzidis | b279297 | 2013-04-01 17:38:59 +0000 | [diff] [blame] | 1139 | if (clang_isExpression(C.kind)) { |
| 1140 | const Expr *E = cxcursor::getCursorExpr(C); |
| 1141 | if (const CallExpr *CE = dyn_cast<CallExpr>(E)) { |
| 1142 | return CE->getNumArgs(); |
| 1143 | } |
| 1144 | } |
| 1145 | |
Argyrios Kyrtzidis | 0c27e4b | 2012-04-11 19:32:19 +0000 | [diff] [blame] | 1146 | return -1; |
| 1147 | } |
| 1148 | |
| 1149 | CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i) { |
| 1150 | if (clang_isDeclaration(C.kind)) { |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 1151 | const Decl *D = cxcursor::getCursorDecl(C); |
| 1152 | if (const ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(D)) { |
Argyrios Kyrtzidis | 0c27e4b | 2012-04-11 19:32:19 +0000 | [diff] [blame] | 1153 | if (i < MD->param_size()) |
Alp Toker | 03376dc | 2014-07-07 09:02:20 +0000 | [diff] [blame] | 1154 | return cxcursor::MakeCXCursor(MD->parameters()[i], |
Argyrios Kyrtzidis | 0c27e4b | 2012-04-11 19:32:19 +0000 | [diff] [blame] | 1155 | cxcursor::getCursorTU(C)); |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 1156 | } else if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) { |
Argyrios Kyrtzidis | 0c27e4b | 2012-04-11 19:32:19 +0000 | [diff] [blame] | 1157 | if (i < FD->param_size()) |
Alp Toker | 03376dc | 2014-07-07 09:02:20 +0000 | [diff] [blame] | 1158 | return cxcursor::MakeCXCursor(FD->parameters()[i], |
Argyrios Kyrtzidis | 0c27e4b | 2012-04-11 19:32:19 +0000 | [diff] [blame] | 1159 | cxcursor::getCursorTU(C)); |
| 1160 | } |
| 1161 | } |
| 1162 | |
Argyrios Kyrtzidis | b279297 | 2013-04-01 17:38:59 +0000 | [diff] [blame] | 1163 | if (clang_isExpression(C.kind)) { |
| 1164 | const Expr *E = cxcursor::getCursorExpr(C); |
| 1165 | if (const CallExpr *CE = dyn_cast<CallExpr>(E)) { |
| 1166 | if (i < CE->getNumArgs()) { |
| 1167 | return cxcursor::MakeCXCursor(CE->getArg(i), |
| 1168 | getCursorDecl(C), |
| 1169 | cxcursor::getCursorTU(C)); |
| 1170 | } |
| 1171 | } |
| 1172 | } |
| 1173 | |
Argyrios Kyrtzidis | 0c27e4b | 2012-04-11 19:32:19 +0000 | [diff] [blame] | 1174 | return clang_getNullCursor(); |
| 1175 | } |
| 1176 | |
Eli Bendersky | c27a0c4 | 2014-10-10 20:01:05 +0000 | [diff] [blame] | 1177 | int clang_Cursor_getNumTemplateArguments(CXCursor C) { |
| 1178 | if (clang_getCursorKind(C) != CXCursor_FunctionDecl) { |
| 1179 | return -1; |
| 1180 | } |
| 1181 | |
| 1182 | const FunctionDecl *FD = llvm::dyn_cast_or_null<clang::FunctionDecl>( |
| 1183 | getCursorDecl(C)); |
| 1184 | if (!FD) { |
| 1185 | return -1; |
| 1186 | } |
| 1187 | |
| 1188 | const FunctionTemplateSpecializationInfo* SpecInfo = |
| 1189 | FD->getTemplateSpecializationInfo(); |
| 1190 | if (!SpecInfo) { |
| 1191 | return -1; |
| 1192 | } |
| 1193 | |
| 1194 | return SpecInfo->TemplateArguments->size(); |
| 1195 | } |
| 1196 | |
| 1197 | enum CXGetTemplateArgumentStatus { |
| 1198 | /** \brief The operation completed successfully */ |
| 1199 | CXGetTemplateArgumentStatus_Success = 0, |
| 1200 | |
| 1201 | /** \brief The specified cursor did not represent a FunctionDecl. */ |
| 1202 | CXGetTemplateArgumentStatus_CursorNotFunctionDecl = -1, |
| 1203 | |
| 1204 | /** \brief The specified cursor was not castable to a FunctionDecl. */ |
| 1205 | CXGetTemplateArgumentStatus_BadFunctionDeclCast = -2, |
| 1206 | |
| 1207 | /** \brief A NULL FunctionTemplateSpecializationInfo was retrieved. */ |
| 1208 | CXGetTemplateArgumentStatus_NullTemplSpecInfo = -3, |
| 1209 | |
| 1210 | /** \brief An invalid (OOB) argument index was specified */ |
| 1211 | CXGetTemplateArgumentStatus_InvalidIndex = -4 |
| 1212 | }; |
| 1213 | |
| 1214 | static int clang_Cursor_getTemplateArgument( |
| 1215 | CXCursor C, unsigned I, TemplateArgument *TA) { |
| 1216 | if (clang_getCursorKind(C) != CXCursor_FunctionDecl) { |
| 1217 | return CXGetTemplateArgumentStatus_CursorNotFunctionDecl; |
| 1218 | } |
| 1219 | |
| 1220 | const FunctionDecl *FD = llvm::dyn_cast_or_null<clang::FunctionDecl>( |
| 1221 | getCursorDecl(C)); |
| 1222 | if (!FD) { |
| 1223 | return CXGetTemplateArgumentStatus_BadFunctionDeclCast; |
| 1224 | } |
| 1225 | |
| 1226 | const FunctionTemplateSpecializationInfo* SpecInfo = |
| 1227 | FD->getTemplateSpecializationInfo(); |
| 1228 | if (!SpecInfo) { |
| 1229 | return CXGetTemplateArgumentStatus_NullTemplSpecInfo; |
| 1230 | } |
| 1231 | |
| 1232 | if (I >= SpecInfo->TemplateArguments->size()) { |
| 1233 | return CXGetTemplateArgumentStatus_InvalidIndex; |
| 1234 | } |
| 1235 | |
| 1236 | *TA = SpecInfo->TemplateArguments->get(I); |
| 1237 | return 0; |
| 1238 | } |
| 1239 | |
| 1240 | enum CXTemplateArgumentKind clang_Cursor_getTemplateArgumentKind(CXCursor C, |
| 1241 | unsigned I) { |
| 1242 | TemplateArgument TA; |
| 1243 | if (clang_Cursor_getTemplateArgument(C, I, &TA)) { |
| 1244 | return CXTemplateArgumentKind_Invalid; |
| 1245 | } |
| 1246 | |
| 1247 | switch (TA.getKind()) { |
| 1248 | case TemplateArgument::Null: return CXTemplateArgumentKind_Null; |
| 1249 | case TemplateArgument::Type: return CXTemplateArgumentKind_Type; |
| 1250 | case TemplateArgument::Declaration: |
| 1251 | return CXTemplateArgumentKind_Declaration; |
| 1252 | case TemplateArgument::NullPtr: return CXTemplateArgumentKind_NullPtr; |
| 1253 | case TemplateArgument::Integral: return CXTemplateArgumentKind_Integral; |
| 1254 | case TemplateArgument::Template: return CXTemplateArgumentKind_Template; |
| 1255 | case TemplateArgument::TemplateExpansion: |
| 1256 | return CXTemplateArgumentKind_TemplateExpansion; |
| 1257 | case TemplateArgument::Expression: return CXTemplateArgumentKind_Expression; |
| 1258 | case TemplateArgument::Pack: return CXTemplateArgumentKind_Pack; |
| 1259 | } |
| 1260 | |
| 1261 | return CXTemplateArgumentKind_Invalid; |
| 1262 | } |
| 1263 | |
| 1264 | CXType clang_Cursor_getTemplateArgumentType(CXCursor C, unsigned I) { |
| 1265 | TemplateArgument TA; |
| 1266 | if (clang_Cursor_getTemplateArgument(C, I, &TA) != |
| 1267 | CXGetTemplateArgumentStatus_Success) { |
| 1268 | return cxtype::MakeCXType(QualType(), getCursorTU(C)); |
| 1269 | } |
| 1270 | |
| 1271 | if (TA.getKind() != TemplateArgument::Type) { |
| 1272 | return cxtype::MakeCXType(QualType(), getCursorTU(C)); |
| 1273 | } |
| 1274 | |
| 1275 | return cxtype::MakeCXType(TA.getAsType(), getCursorTU(C)); |
| 1276 | } |
| 1277 | |
| 1278 | long long clang_Cursor_getTemplateArgumentValue(CXCursor C, unsigned I) { |
| 1279 | TemplateArgument TA; |
| 1280 | if (clang_Cursor_getTemplateArgument(C, I, &TA) != |
| 1281 | CXGetTemplateArgumentStatus_Success) { |
| 1282 | assert(0 && "Unable to retrieve TemplateArgument"); |
| 1283 | return 0; |
| 1284 | } |
| 1285 | |
| 1286 | if (TA.getKind() != TemplateArgument::Integral) { |
| 1287 | assert(0 && "Passed template argument is not Integral"); |
| 1288 | return 0; |
| 1289 | } |
| 1290 | |
| 1291 | return TA.getAsIntegral().getSExtValue(); |
| 1292 | } |
| 1293 | |
| 1294 | unsigned long long clang_Cursor_getTemplateArgumentUnsignedValue(CXCursor C, |
| 1295 | unsigned I) { |
| 1296 | TemplateArgument TA; |
| 1297 | if (clang_Cursor_getTemplateArgument(C, I, &TA) != |
| 1298 | CXGetTemplateArgumentStatus_Success) { |
| 1299 | assert(0 && "Unable to retrieve TemplateArgument"); |
| 1300 | return 0; |
| 1301 | } |
| 1302 | |
| 1303 | if (TA.getKind() != TemplateArgument::Integral) { |
| 1304 | assert(0 && "Passed template argument is not Integral"); |
| 1305 | return 0; |
| 1306 | } |
| 1307 | |
| 1308 | return TA.getAsIntegral().getZExtValue(); |
| 1309 | } |
| 1310 | |
Ted Kremenek | c0b9866 | 2013-04-24 07:17:12 +0000 | [diff] [blame] | 1311 | //===----------------------------------------------------------------------===// |
| 1312 | // CXCursorSet. |
| 1313 | //===----------------------------------------------------------------------===// |
| 1314 | |
| 1315 | typedef llvm::DenseMap<CXCursor, unsigned> CXCursorSet_Impl; |
| 1316 | |
| 1317 | static inline CXCursorSet packCXCursorSet(CXCursorSet_Impl *setImpl) { |
| 1318 | return (CXCursorSet) setImpl; |
| 1319 | } |
| 1320 | static inline CXCursorSet_Impl *unpackCXCursorSet(CXCursorSet set) { |
| 1321 | return (CXCursorSet_Impl*) set; |
| 1322 | } |
| 1323 | namespace llvm { |
| 1324 | template<> struct DenseMapInfo<CXCursor> { |
| 1325 | public: |
| 1326 | static inline CXCursor getEmptyKey() { |
| 1327 | return MakeCXCursorInvalid(CXCursor_InvalidFile); |
| 1328 | } |
| 1329 | static inline CXCursor getTombstoneKey() { |
| 1330 | return MakeCXCursorInvalid(CXCursor_NoDeclFound); |
| 1331 | } |
| 1332 | static inline unsigned getHashValue(const CXCursor &cursor) { |
| 1333 | return llvm::DenseMapInfo<std::pair<const void *, const void *> > |
| 1334 | ::getHashValue(std::make_pair(cursor.data[0], cursor.data[1])); |
| 1335 | } |
| 1336 | static inline bool isEqual(const CXCursor &x, const CXCursor &y) { |
| 1337 | return x.kind == y.kind && |
| 1338 | x.data[0] == y.data[0] && |
| 1339 | x.data[1] == y.data[1]; |
| 1340 | } |
| 1341 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 1342 | } |
Ted Kremenek | c0b9866 | 2013-04-24 07:17:12 +0000 | [diff] [blame] | 1343 | |
Ted Kremenek | c0b9866 | 2013-04-24 07:17:12 +0000 | [diff] [blame] | 1344 | CXCursorSet clang_createCXCursorSet() { |
| 1345 | return packCXCursorSet(new CXCursorSet_Impl()); |
| 1346 | } |
| 1347 | |
| 1348 | void clang_disposeCXCursorSet(CXCursorSet set) { |
| 1349 | delete unpackCXCursorSet(set); |
| 1350 | } |
| 1351 | |
| 1352 | unsigned clang_CXCursorSet_contains(CXCursorSet set, CXCursor cursor) { |
| 1353 | CXCursorSet_Impl *setImpl = unpackCXCursorSet(set); |
| 1354 | if (!setImpl) |
| 1355 | return 0; |
Ted Kremenek | 29b28e8 | 2013-04-24 07:25:40 +0000 | [diff] [blame] | 1356 | return setImpl->find(cursor) != setImpl->end(); |
Ted Kremenek | c0b9866 | 2013-04-24 07:17:12 +0000 | [diff] [blame] | 1357 | } |
| 1358 | |
| 1359 | unsigned clang_CXCursorSet_insert(CXCursorSet set, CXCursor cursor) { |
| 1360 | // Do not insert invalid cursors into the set. |
| 1361 | if (cursor.kind >= CXCursor_FirstInvalid && |
| 1362 | cursor.kind <= CXCursor_LastInvalid) |
| 1363 | return 1; |
| 1364 | |
| 1365 | CXCursorSet_Impl *setImpl = unpackCXCursorSet(set); |
| 1366 | if (!setImpl) |
| 1367 | return 1; |
| 1368 | unsigned &entry = (*setImpl)[cursor]; |
| 1369 | unsigned flag = entry == 0 ? 1 : 0; |
| 1370 | entry = 1; |
| 1371 | return flag; |
| 1372 | } |
| 1373 | |
Douglas Gregor | 3f35bb2 | 2011-08-04 20:04:59 +0000 | [diff] [blame] | 1374 | CXCompletionString clang_getCursorCompletionString(CXCursor cursor) { |
| 1375 | enum CXCursorKind kind = clang_getCursorKind(cursor); |
| 1376 | if (clang_isDeclaration(kind)) { |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 1377 | const Decl *decl = getCursorDecl(cursor); |
| 1378 | if (const NamedDecl *namedDecl = dyn_cast_or_null<NamedDecl>(decl)) { |
Douglas Gregor | 3f35bb2 | 2011-08-04 20:04:59 +0000 | [diff] [blame] | 1379 | ASTUnit *unit = getCursorASTUnit(cursor); |
Douglas Gregor | 0a0e2b3 | 2013-01-31 04:52:16 +0000 | [diff] [blame] | 1380 | CodeCompletionResult Result(namedDecl, CCP_Declaration); |
Argyrios Kyrtzidis | 7890821 | 2012-01-17 02:15:54 +0000 | [diff] [blame] | 1381 | CodeCompletionString *String |
| 1382 | = Result.CreateCodeCompletionString(unit->getASTContext(), |
| 1383 | unit->getPreprocessor(), |
Douglas Gregor | c3425b1 | 2015-07-07 06:20:19 +0000 | [diff] [blame] | 1384 | CodeCompletionContext::CCC_Other, |
Argyrios Kyrtzidis | 9d7c0fe | 2012-04-10 17:23:48 +0000 | [diff] [blame] | 1385 | unit->getCodeCompletionTUInfo().getAllocator(), |
Dmitri Gribenko | 3292d06 | 2012-07-02 17:35:10 +0000 | [diff] [blame] | 1386 | unit->getCodeCompletionTUInfo(), |
| 1387 | true); |
Argyrios Kyrtzidis | 7890821 | 2012-01-17 02:15:54 +0000 | [diff] [blame] | 1388 | return String; |
Douglas Gregor | 3f35bb2 | 2011-08-04 20:04:59 +0000 | [diff] [blame] | 1389 | } |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 1390 | } else if (kind == CXCursor_MacroDefinition) { |
| 1391 | const MacroDefinitionRecord *definition = getCursorMacroDefinition(cursor); |
Douglas Gregor | 3f35bb2 | 2011-08-04 20:04:59 +0000 | [diff] [blame] | 1392 | const IdentifierInfo *MacroInfo = definition->getName(); |
| 1393 | ASTUnit *unit = getCursorASTUnit(cursor); |
Dmitri Gribenko | 049a4ff | 2013-01-14 00:36:42 +0000 | [diff] [blame] | 1394 | CodeCompletionResult Result(MacroInfo); |
Douglas Gregor | c3425b1 | 2015-07-07 06:20:19 +0000 | [diff] [blame] | 1395 | CodeCompletionString *String |
| 1396 | = Result.CreateCodeCompletionString(unit->getASTContext(), |
| 1397 | unit->getPreprocessor(), |
| 1398 | CodeCompletionContext::CCC_Other, |
| 1399 | unit->getCodeCompletionTUInfo().getAllocator(), |
| 1400 | unit->getCodeCompletionTUInfo(), |
| 1401 | false); |
Argyrios Kyrtzidis | 7890821 | 2012-01-17 02:15:54 +0000 | [diff] [blame] | 1402 | return String; |
Douglas Gregor | 3f35bb2 | 2011-08-04 20:04:59 +0000 | [diff] [blame] | 1403 | } |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 1404 | return nullptr; |
Douglas Gregor | 3f35bb2 | 2011-08-04 20:04:59 +0000 | [diff] [blame] | 1405 | } |
Ted Kremenek | d77f621 | 2012-04-30 19:06:49 +0000 | [diff] [blame] | 1406 | |
| 1407 | namespace { |
| 1408 | struct OverridenCursorsPool { |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1409 | typedef SmallVector<CXCursor, 2> CursorVec; |
Ted Kremenek | d77f621 | 2012-04-30 19:06:49 +0000 | [diff] [blame] | 1410 | std::vector<CursorVec*> AllCursors; |
| 1411 | std::vector<CursorVec*> AvailableCursors; |
| 1412 | |
| 1413 | ~OverridenCursorsPool() { |
| 1414 | for (std::vector<CursorVec*>::iterator I = AllCursors.begin(), |
| 1415 | E = AllCursors.end(); I != E; ++I) { |
| 1416 | delete *I; |
| 1417 | } |
| 1418 | } |
| 1419 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 1420 | } |
Ted Kremenek | d77f621 | 2012-04-30 19:06:49 +0000 | [diff] [blame] | 1421 | |
| 1422 | void *cxcursor::createOverridenCXCursorsPool() { |
| 1423 | return new OverridenCursorsPool(); |
| 1424 | } |
| 1425 | |
| 1426 | void cxcursor::disposeOverridenCXCursorsPool(void *pool) { |
| 1427 | delete static_cast<OverridenCursorsPool*>(pool); |
| 1428 | } |
Ted Kremenek | b47610a | 2012-04-30 19:33:45 +0000 | [diff] [blame] | 1429 | |
Ted Kremenek | d77f621 | 2012-04-30 19:06:49 +0000 | [diff] [blame] | 1430 | void clang_getOverriddenCursors(CXCursor cursor, |
| 1431 | CXCursor **overridden, |
| 1432 | unsigned *num_overridden) { |
| 1433 | if (overridden) |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 1434 | *overridden = nullptr; |
Ted Kremenek | d77f621 | 2012-04-30 19:06:49 +0000 | [diff] [blame] | 1435 | if (num_overridden) |
| 1436 | *num_overridden = 0; |
| 1437 | |
| 1438 | CXTranslationUnit TU = cxcursor::getCursorTU(cursor); |
| 1439 | |
| 1440 | if (!overridden || !num_overridden || !TU) |
| 1441 | return; |
| 1442 | |
| 1443 | if (!clang_isDeclaration(cursor.kind)) |
| 1444 | return; |
| 1445 | |
| 1446 | OverridenCursorsPool &pool = |
| 1447 | *static_cast<OverridenCursorsPool*>(TU->OverridenCursorsPool); |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 1448 | |
| 1449 | OverridenCursorsPool::CursorVec *Vec = nullptr; |
| 1450 | |
Ted Kremenek | d77f621 | 2012-04-30 19:06:49 +0000 | [diff] [blame] | 1451 | if (!pool.AvailableCursors.empty()) { |
| 1452 | Vec = pool.AvailableCursors.back(); |
| 1453 | pool.AvailableCursors.pop_back(); |
| 1454 | } |
| 1455 | else { |
| 1456 | Vec = new OverridenCursorsPool::CursorVec(); |
| 1457 | pool.AllCursors.push_back(Vec); |
| 1458 | } |
| 1459 | |
| 1460 | // Clear out the vector, but don't free the memory contents. This |
| 1461 | // reduces malloc() traffic. |
| 1462 | Vec->clear(); |
| 1463 | |
| 1464 | // Use the first entry to contain a back reference to the vector. |
| 1465 | // This is a complete hack. |
| 1466 | CXCursor backRefCursor = MakeCXCursorInvalid(CXCursor_InvalidFile, TU); |
| 1467 | backRefCursor.data[0] = Vec; |
| 1468 | assert(cxcursor::getCursorTU(backRefCursor) == TU); |
| 1469 | Vec->push_back(backRefCursor); |
| 1470 | |
| 1471 | // Get the overriden cursors. |
| 1472 | cxcursor::getOverriddenCursors(cursor, *Vec); |
| 1473 | |
| 1474 | // Did we get any overriden cursors? If not, return Vec to the pool |
| 1475 | // of available cursor vectors. |
| 1476 | if (Vec->size() == 1) { |
| 1477 | pool.AvailableCursors.push_back(Vec); |
| 1478 | return; |
| 1479 | } |
| 1480 | |
| 1481 | // Now tell the caller about the overriden cursors. |
| 1482 | assert(Vec->size() > 1); |
| 1483 | *overridden = &((*Vec)[1]); |
| 1484 | *num_overridden = Vec->size() - 1; |
| 1485 | } |
| 1486 | |
| 1487 | void clang_disposeOverriddenCursors(CXCursor *overridden) { |
| 1488 | if (!overridden) |
| 1489 | return; |
| 1490 | |
| 1491 | // Use pointer arithmetic to get back the first faux entry |
| 1492 | // which has a back-reference to the TU and the vector. |
| 1493 | --overridden; |
| 1494 | OverridenCursorsPool::CursorVec *Vec = |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 1495 | static_cast<OverridenCursorsPool::CursorVec *>( |
| 1496 | const_cast<void *>(overridden->data[0])); |
Ted Kremenek | d77f621 | 2012-04-30 19:06:49 +0000 | [diff] [blame] | 1497 | CXTranslationUnit TU = getCursorTU(*overridden); |
| 1498 | |
| 1499 | assert(Vec && TU); |
| 1500 | |
| 1501 | OverridenCursorsPool &pool = |
| 1502 | *static_cast<OverridenCursorsPool*>(TU->OverridenCursorsPool); |
| 1503 | |
| 1504 | pool.AvailableCursors.push_back(Vec); |
| 1505 | } |
Argyrios Kyrtzidis | b6df6821 | 2012-07-02 23:54:36 +0000 | [diff] [blame] | 1506 | |
| 1507 | int clang_Cursor_isDynamicCall(CXCursor C) { |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 1508 | const Expr *E = nullptr; |
Argyrios Kyrtzidis | b6df6821 | 2012-07-02 23:54:36 +0000 | [diff] [blame] | 1509 | if (clang_isExpression(C.kind)) |
| 1510 | E = getCursorExpr(C); |
| 1511 | if (!E) |
| 1512 | return 0; |
| 1513 | |
Argyrios Kyrtzidis | 6cc5f73 | 2014-11-10 23:21:35 +0000 | [diff] [blame] | 1514 | if (const ObjCMessageExpr *MsgE = dyn_cast<ObjCMessageExpr>(E)) { |
| 1515 | if (MsgE->getReceiverKind() != ObjCMessageExpr::Instance) |
| 1516 | return false; |
| 1517 | if (auto *RecE = dyn_cast<ObjCMessageExpr>( |
| 1518 | MsgE->getInstanceReceiver()->IgnoreParenCasts())) { |
| 1519 | if (RecE->getMethodFamily() == OMF_alloc) |
| 1520 | return false; |
| 1521 | } |
| 1522 | return true; |
| 1523 | } |
Argyrios Kyrtzidis | b6df6821 | 2012-07-02 23:54:36 +0000 | [diff] [blame] | 1524 | |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 1525 | const MemberExpr *ME = nullptr; |
Argyrios Kyrtzidis | b6df6821 | 2012-07-02 23:54:36 +0000 | [diff] [blame] | 1526 | if (isa<MemberExpr>(E)) |
| 1527 | ME = cast<MemberExpr>(E); |
| 1528 | else if (const CallExpr *CE = dyn_cast<CallExpr>(E)) |
| 1529 | ME = dyn_cast_or_null<MemberExpr>(CE->getCallee()); |
| 1530 | |
| 1531 | if (ME) { |
| 1532 | if (const CXXMethodDecl * |
| 1533 | MD = dyn_cast_or_null<CXXMethodDecl>(ME->getMemberDecl())) |
| 1534 | return MD->isVirtual() && !ME->hasQualifier(); |
| 1535 | } |
| 1536 | |
| 1537 | return 0; |
| 1538 | } |
| 1539 | |
Argyrios Kyrtzidis | b26a24c | 2012-11-01 02:01:34 +0000 | [diff] [blame] | 1540 | CXType clang_Cursor_getReceiverType(CXCursor C) { |
| 1541 | CXTranslationUnit TU = cxcursor::getCursorTU(C); |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 1542 | const Expr *E = nullptr; |
Argyrios Kyrtzidis | b26a24c | 2012-11-01 02:01:34 +0000 | [diff] [blame] | 1543 | if (clang_isExpression(C.kind)) |
| 1544 | E = getCursorExpr(C); |
| 1545 | |
| 1546 | if (const ObjCMessageExpr *MsgE = dyn_cast_or_null<ObjCMessageExpr>(E)) |
| 1547 | return cxtype::MakeCXType(MsgE->getReceiverType(), TU); |
| 1548 | |
| 1549 | return cxtype::MakeCXType(QualType(), TU); |
| 1550 | } |