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