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