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