Ted Kremenek | 16c440a | 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 | 2e331b9 | 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 | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
Ted Kremenek | 0a90d32 | 2010-11-17 23:24:11 +0000 | [diff] [blame] | 16 | #include "CXTranslationUnit.h" |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 17 | #include "CXCursor.h" |
Ted Kremenek | ed12273 | 2010-11-16 01:56:27 +0000 | [diff] [blame] | 18 | #include "CXString.h" |
Chandler Carruth | f59edb9 | 2012-12-04 09:25:21 +0000 | [diff] [blame] | 19 | #include "CXType.h" |
| 20 | #include "clang-c/Index.h" |
David Blaikie | 0b5ca51 | 2013-09-13 18:32:52 +0000 | [diff] [blame] | 21 | #include "clang/AST/Attr.h" |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 22 | #include "clang/AST/Decl.h" |
Douglas Gregor | 6931900 | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclCXX.h" |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 24 | #include "clang/AST/DeclObjC.h" |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 25 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 26 | #include "clang/AST/Expr.h" |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 27 | #include "clang/AST/ExprCXX.h" |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 28 | #include "clang/AST/ExprObjC.h" |
Chandler Carruth | f59edb9 | 2012-12-04 09:25:21 +0000 | [diff] [blame] | 29 | #include "clang/Frontend/ASTUnit.h" |
Ted Kremenek | edc8aa6 | 2010-01-16 00:36:30 +0000 | [diff] [blame] | 30 | #include "llvm/Support/ErrorHandling.h" |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 31 | |
| 32 | using namespace clang; |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 33 | using namespace cxcursor; |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 34 | |
Ted Kremenek | bbf66ca | 2012-04-30 19:06:49 +0000 | [diff] [blame] | 35 | CXCursor cxcursor::MakeCXCursorInvalid(CXCursorKind K, CXTranslationUnit TU) { |
Douglas Gregor | 5bfb8c1 | 2010-01-20 23:34:41 +0000 | [diff] [blame] | 36 | assert(K >= CXCursor_FirstInvalid && K <= CXCursor_LastInvalid); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 37 | CXCursor C = { K, 0, { nullptr, nullptr, TU } }; |
Douglas Gregor | 5bfb8c1 | 2010-01-20 23:34:41 +0000 | [diff] [blame] | 38 | return C; |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 39 | } |
| 40 | |
Ted Kremenek | e77f443 | 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; |
Sean Hunt | 387475d | 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 | 6639e92 | 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 | 5f1c822 | 2011-10-13 09:41:32 +0000 | [diff] [blame] | 50 | case attr::Annotate: return CXCursor_AnnotateAttr; |
Argyrios Kyrtzidis | 84b7964 | 2011-12-06 22:05:01 +0000 | [diff] [blame] | 51 | case attr::AsmLabel: return CXCursor_AsmLabelAttr; |
Argyrios Kyrtzidis | 5133711 | 2013-09-25 00:14:38 +0000 | [diff] [blame] | 52 | case attr::Packed: return CXCursor_PackedAttr; |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 53 | case attr::Pure: return CXCursor_PureAttr; |
| 54 | case attr::Const: return CXCursor_ConstAttr; |
| 55 | case attr::NoDuplicate: return CXCursor_NoDuplicateAttr; |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [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; |
Ted Kremenek | e77f443 | 2010-02-18 03:09:07 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | return CXCursor_UnexposedAttr; |
| 63 | } |
| 64 | |
Dmitri Gribenko | 05756dc | 2013-01-14 00:46:27 +0000 | [diff] [blame] | 65 | CXCursor cxcursor::MakeCXCursor(const Attr *A, const Decl *Parent, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 66 | CXTranslationUnit TU) { |
Ted Kremenek | e77f443 | 2010-02-18 03:09:07 +0000 | [diff] [blame] | 67 | assert(A && Parent && TU && "Invalid arguments!"); |
Dmitri Gribenko | 3315618 | 2013-01-11 21:06:06 +0000 | [diff] [blame] | 68 | CXCursor C = { GetCursorKind(A), 0, { Parent, A, TU } }; |
Ted Kremenek | e77f443 | 2010-02-18 03:09:07 +0000 | [diff] [blame] | 69 | return C; |
| 70 | } |
| 71 | |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 72 | CXCursor cxcursor::MakeCXCursor(const Decl *D, CXTranslationUnit TU, |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 73 | SourceRange RegionOfInterest, |
Ted Kremenek | 007a7c9 | 2010-11-01 23:26:51 +0000 | [diff] [blame] | 74 | bool FirstInDeclGroup) { |
Daniel Dunbar | 54d67ca | 2010-01-25 00:40:30 +0000 | [diff] [blame] | 75 | assert(D && TU && "Invalid arguments!"); |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 76 | |
| 77 | CXCursorKind K = getCursorKindForDecl(D); |
| 78 | |
| 79 | if (K == CXCursor_ObjCClassMethodDecl || |
| 80 | K == CXCursor_ObjCInstanceMethodDecl) { |
| 81 | int SelectorIdIndex = -1; |
| 82 | // Check if cursor points to a selector id. |
| 83 | if (RegionOfInterest.isValid() && |
| 84 | RegionOfInterest.getBegin() == RegionOfInterest.getEnd()) { |
| 85 | SmallVector<SourceLocation, 16> SelLocs; |
| 86 | cast<ObjCMethodDecl>(D)->getSelectorLocs(SelLocs); |
Craig Topper | 09d19ef | 2013-07-04 03:08:24 +0000 | [diff] [blame] | 87 | SmallVectorImpl<SourceLocation>::iterator |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 88 | I=std::find(SelLocs.begin(), SelLocs.end(),RegionOfInterest.getBegin()); |
| 89 | if (I != SelLocs.end()) |
| 90 | SelectorIdIndex = I - SelLocs.begin(); |
| 91 | } |
| 92 | CXCursor C = { K, SelectorIdIndex, |
| 93 | { D, (void*)(intptr_t) (FirstInDeclGroup ? 1 : 0), TU }}; |
| 94 | return C; |
| 95 | } |
| 96 | |
| 97 | CXCursor C = { K, 0, { D, (void*)(intptr_t) (FirstInDeclGroup ? 1 : 0), TU }}; |
Douglas Gregor | 5bfb8c1 | 2010-01-20 23:34:41 +0000 | [diff] [blame] | 98 | return C; |
Ted Kremenek | edc8aa6 | 2010-01-16 00:36:30 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Dmitri Gribenko | 05756dc | 2013-01-14 00:46:27 +0000 | [diff] [blame] | 101 | CXCursor cxcursor::MakeCXCursor(const Stmt *S, const Decl *Parent, |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 102 | CXTranslationUnit TU, |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 103 | SourceRange RegionOfInterest) { |
Daniel Dunbar | 54d67ca | 2010-01-25 00:40:30 +0000 | [diff] [blame] | 104 | assert(S && TU && "Invalid arguments!"); |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 105 | CXCursorKind K = CXCursor_NotImplemented; |
| 106 | |
| 107 | switch (S->getStmtClass()) { |
| 108 | case Stmt::NoStmtClass: |
| 109 | break; |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 110 | |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 111 | case Stmt::CaseStmtClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 112 | K = CXCursor_CaseStmt; |
| 113 | break; |
| 114 | |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 115 | case Stmt::DefaultStmtClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 116 | K = CXCursor_DefaultStmt; |
| 117 | break; |
| 118 | |
| 119 | case Stmt::IfStmtClass: |
| 120 | K = CXCursor_IfStmt; |
| 121 | break; |
| 122 | |
| 123 | case Stmt::SwitchStmtClass: |
| 124 | K = CXCursor_SwitchStmt; |
| 125 | break; |
| 126 | |
| 127 | case Stmt::WhileStmtClass: |
| 128 | K = CXCursor_WhileStmt; |
| 129 | break; |
| 130 | |
| 131 | case Stmt::DoStmtClass: |
| 132 | K = CXCursor_DoStmt; |
| 133 | break; |
| 134 | |
| 135 | case Stmt::ForStmtClass: |
| 136 | K = CXCursor_ForStmt; |
| 137 | break; |
| 138 | |
| 139 | case Stmt::GotoStmtClass: |
| 140 | K = CXCursor_GotoStmt; |
| 141 | break; |
| 142 | |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 143 | case Stmt::IndirectGotoStmtClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 144 | K = CXCursor_IndirectGotoStmt; |
| 145 | break; |
| 146 | |
| 147 | case Stmt::ContinueStmtClass: |
| 148 | K = CXCursor_ContinueStmt; |
| 149 | break; |
| 150 | |
| 151 | case Stmt::BreakStmtClass: |
| 152 | K = CXCursor_BreakStmt; |
| 153 | break; |
| 154 | |
| 155 | case Stmt::ReturnStmtClass: |
| 156 | K = CXCursor_ReturnStmt; |
| 157 | break; |
| 158 | |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 159 | case Stmt::GCCAsmStmtClass: |
| 160 | K = CXCursor_GCCAsmStmt; |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 161 | break; |
Chad Rosier | 8cd64b4 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 162 | |
| 163 | case Stmt::MSAsmStmtClass: |
| 164 | K = CXCursor_MSAsmStmt; |
| 165 | break; |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 166 | |
| 167 | case Stmt::ObjCAtTryStmtClass: |
| 168 | K = CXCursor_ObjCAtTryStmt; |
| 169 | break; |
| 170 | |
| 171 | case Stmt::ObjCAtCatchStmtClass: |
| 172 | K = CXCursor_ObjCAtCatchStmt; |
| 173 | break; |
| 174 | |
| 175 | case Stmt::ObjCAtFinallyStmtClass: |
| 176 | K = CXCursor_ObjCAtFinallyStmt; |
| 177 | break; |
| 178 | |
| 179 | case Stmt::ObjCAtThrowStmtClass: |
| 180 | K = CXCursor_ObjCAtThrowStmt; |
| 181 | break; |
| 182 | |
| 183 | case Stmt::ObjCAtSynchronizedStmtClass: |
| 184 | K = CXCursor_ObjCAtSynchronizedStmt; |
| 185 | break; |
| 186 | |
| 187 | case Stmt::ObjCAutoreleasePoolStmtClass: |
| 188 | K = CXCursor_ObjCAutoreleasePoolStmt; |
| 189 | break; |
| 190 | |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 191 | case Stmt::ObjCForCollectionStmtClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 192 | K = CXCursor_ObjCForCollectionStmt; |
| 193 | break; |
| 194 | |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 195 | case Stmt::CXXCatchStmtClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 196 | K = CXCursor_CXXCatchStmt; |
| 197 | break; |
| 198 | |
| 199 | case Stmt::CXXTryStmtClass: |
| 200 | K = CXCursor_CXXTryStmt; |
| 201 | break; |
| 202 | |
| 203 | case Stmt::CXXForRangeStmtClass: |
| 204 | K = CXCursor_CXXForRangeStmt; |
| 205 | break; |
| 206 | |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 207 | case Stmt::SEHTryStmtClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 208 | K = CXCursor_SEHTryStmt; |
| 209 | break; |
| 210 | |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 211 | case Stmt::SEHExceptStmtClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 212 | K = CXCursor_SEHExceptStmt; |
| 213 | break; |
| 214 | |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 215 | case Stmt::SEHFinallyStmtClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 216 | K = CXCursor_SEHFinallyStmt; |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 217 | break; |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 218 | |
| 219 | case Stmt::SEHLeaveStmtClass: |
| 220 | K = CXCursor_SEHLeaveStmt; |
| 221 | break; |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 222 | |
John Wiegley | 21ff2e5 | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 223 | case Stmt::ArrayTypeTraitExprClass: |
Tanya Lattner | 61eee0c | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 224 | case Stmt::AsTypeExprClass: |
Eli Friedman | 276b061 | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 225 | case Stmt::AtomicExprClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 226 | case Stmt::BinaryConditionalOperatorClass: |
Douglas Gregor | 4ca8ac2 | 2012-02-24 07:38:34 +0000 | [diff] [blame] | 227 | case Stmt::TypeTraitExprClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 228 | case Stmt::CXXBindTemporaryExprClass: |
| 229 | case Stmt::CXXDefaultArgExprClass: |
Richard Smith | c3bf52c | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 230 | case Stmt::CXXDefaultInitExprClass: |
Richard Smith | 7c3e615 | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 231 | case Stmt::CXXStdInitializerListExprClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 232 | case Stmt::CXXScalarValueInitExprClass: |
| 233 | case Stmt::CXXUuidofExprClass: |
| 234 | case Stmt::ChooseExprClass: |
| 235 | case Stmt::DesignatedInitExprClass: |
| 236 | case Stmt::ExprWithCleanupsClass: |
| 237 | case Stmt::ExpressionTraitExprClass: |
| 238 | case Stmt::ExtVectorElementExprClass: |
| 239 | case Stmt::ImplicitCastExprClass: |
| 240 | case Stmt::ImplicitValueInitExprClass: |
| 241 | case Stmt::MaterializeTemporaryExprClass: |
| 242 | case Stmt::ObjCIndirectCopyRestoreExprClass: |
| 243 | case Stmt::OffsetOfExprClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 244 | case Stmt::ParenListExprClass: |
| 245 | case Stmt::PredefinedExprClass: |
| 246 | case Stmt::ShuffleVectorExprClass: |
Hal Finkel | 414a1bd | 2013-09-18 03:29:45 +0000 | [diff] [blame] | 247 | case Stmt::ConvertVectorExprClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 248 | case Stmt::UnaryExprOrTypeTraitExprClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 249 | case Stmt::VAArgExprClass: |
Ted Kremenek | b3f7542 | 2012-03-06 20:06:06 +0000 | [diff] [blame] | 250 | case Stmt::ObjCArrayLiteralClass: |
| 251 | case Stmt::ObjCDictionaryLiteralClass: |
Patrick Beard | eb382ec | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 252 | case Stmt::ObjCBoxedExprClass: |
Ted Kremenek | b3f7542 | 2012-03-06 20:06:06 +0000 | [diff] [blame] | 253 | case Stmt::ObjCSubscriptRefExprClass: |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 254 | K = CXCursor_UnexposedExpr; |
| 255 | break; |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 256 | |
John McCall | 4b9c2d2 | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 257 | case Stmt::OpaqueValueExprClass: |
| 258 | if (Expr *Src = cast<OpaqueValueExpr>(S)->getSourceExpr()) |
| 259 | return MakeCXCursor(Src, Parent, TU, RegionOfInterest); |
| 260 | K = CXCursor_UnexposedExpr; |
| 261 | break; |
| 262 | |
| 263 | case Stmt::PseudoObjectExprClass: |
| 264 | return MakeCXCursor(cast<PseudoObjectExpr>(S)->getSyntacticForm(), |
| 265 | Parent, TU, RegionOfInterest); |
| 266 | |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 267 | case Stmt::CompoundStmtClass: |
| 268 | K = CXCursor_CompoundStmt; |
| 269 | break; |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 270 | |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 271 | case Stmt::NullStmtClass: |
| 272 | K = CXCursor_NullStmt; |
| 273 | break; |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 274 | |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 275 | case Stmt::LabelStmtClass: |
| 276 | K = CXCursor_LabelStmt; |
| 277 | break; |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 278 | |
| 279 | case Stmt::AttributedStmtClass: |
| 280 | K = CXCursor_UnexposedStmt; |
| 281 | break; |
| 282 | |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 283 | case Stmt::DeclStmtClass: |
| 284 | K = CXCursor_DeclStmt; |
| 285 | break; |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 286 | |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 287 | case Stmt::CapturedStmtClass: |
| 288 | K = CXCursor_UnexposedStmt; |
| 289 | break; |
| 290 | |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 291 | case Stmt::IntegerLiteralClass: |
| 292 | K = CXCursor_IntegerLiteral; |
| 293 | break; |
| 294 | |
| 295 | case Stmt::FloatingLiteralClass: |
| 296 | K = CXCursor_FloatingLiteral; |
| 297 | break; |
| 298 | |
| 299 | case Stmt::ImaginaryLiteralClass: |
| 300 | K = CXCursor_ImaginaryLiteral; |
| 301 | break; |
| 302 | |
| 303 | case Stmt::StringLiteralClass: |
| 304 | K = CXCursor_StringLiteral; |
| 305 | break; |
| 306 | |
| 307 | case Stmt::CharacterLiteralClass: |
| 308 | K = CXCursor_CharacterLiteral; |
| 309 | break; |
| 310 | |
| 311 | case Stmt::ParenExprClass: |
| 312 | K = CXCursor_ParenExpr; |
| 313 | break; |
| 314 | |
| 315 | case Stmt::UnaryOperatorClass: |
| 316 | K = CXCursor_UnaryOperator; |
| 317 | break; |
Richard Smith | 534986f | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 318 | |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 319 | case Stmt::CXXNoexceptExprClass: |
| 320 | K = CXCursor_UnaryExpr; |
| 321 | break; |
| 322 | |
| 323 | case Stmt::ArraySubscriptExprClass: |
| 324 | K = CXCursor_ArraySubscriptExpr; |
| 325 | break; |
| 326 | |
| 327 | case Stmt::BinaryOperatorClass: |
| 328 | K = CXCursor_BinaryOperator; |
| 329 | break; |
| 330 | |
| 331 | case Stmt::CompoundAssignOperatorClass: |
| 332 | K = CXCursor_CompoundAssignOperator; |
| 333 | break; |
| 334 | |
| 335 | case Stmt::ConditionalOperatorClass: |
| 336 | K = CXCursor_ConditionalOperator; |
| 337 | break; |
| 338 | |
| 339 | case Stmt::CStyleCastExprClass: |
| 340 | K = CXCursor_CStyleCastExpr; |
| 341 | break; |
| 342 | |
| 343 | case Stmt::CompoundLiteralExprClass: |
| 344 | K = CXCursor_CompoundLiteralExpr; |
| 345 | break; |
| 346 | |
| 347 | case Stmt::InitListExprClass: |
| 348 | K = CXCursor_InitListExpr; |
| 349 | break; |
| 350 | |
| 351 | case Stmt::AddrLabelExprClass: |
| 352 | K = CXCursor_AddrLabelExpr; |
| 353 | break; |
| 354 | |
| 355 | case Stmt::StmtExprClass: |
| 356 | K = CXCursor_StmtExpr; |
| 357 | break; |
| 358 | |
| 359 | case Stmt::GenericSelectionExprClass: |
| 360 | K = CXCursor_GenericSelectionExpr; |
| 361 | break; |
| 362 | |
| 363 | case Stmt::GNUNullExprClass: |
| 364 | K = CXCursor_GNUNullExpr; |
| 365 | break; |
| 366 | |
| 367 | case Stmt::CXXStaticCastExprClass: |
| 368 | K = CXCursor_CXXStaticCastExpr; |
| 369 | break; |
| 370 | |
| 371 | case Stmt::CXXDynamicCastExprClass: |
| 372 | K = CXCursor_CXXDynamicCastExpr; |
| 373 | break; |
| 374 | |
| 375 | case Stmt::CXXReinterpretCastExprClass: |
| 376 | K = CXCursor_CXXReinterpretCastExpr; |
| 377 | break; |
| 378 | |
| 379 | case Stmt::CXXConstCastExprClass: |
| 380 | K = CXCursor_CXXConstCastExpr; |
| 381 | break; |
| 382 | |
| 383 | case Stmt::CXXFunctionalCastExprClass: |
| 384 | K = CXCursor_CXXFunctionalCastExpr; |
| 385 | break; |
| 386 | |
| 387 | case Stmt::CXXTypeidExprClass: |
| 388 | K = CXCursor_CXXTypeidExpr; |
| 389 | break; |
| 390 | |
| 391 | case Stmt::CXXBoolLiteralExprClass: |
| 392 | K = CXCursor_CXXBoolLiteralExpr; |
| 393 | break; |
| 394 | |
| 395 | case Stmt::CXXNullPtrLiteralExprClass: |
| 396 | K = CXCursor_CXXNullPtrLiteralExpr; |
| 397 | break; |
| 398 | |
| 399 | case Stmt::CXXThisExprClass: |
| 400 | K = CXCursor_CXXThisExpr; |
| 401 | break; |
| 402 | |
| 403 | case Stmt::CXXThrowExprClass: |
| 404 | K = CXCursor_CXXThrowExpr; |
| 405 | break; |
| 406 | |
| 407 | case Stmt::CXXNewExprClass: |
| 408 | K = CXCursor_CXXNewExpr; |
| 409 | break; |
| 410 | |
| 411 | case Stmt::CXXDeleteExprClass: |
| 412 | K = CXCursor_CXXDeleteExpr; |
| 413 | break; |
| 414 | |
| 415 | case Stmt::ObjCStringLiteralClass: |
| 416 | K = CXCursor_ObjCStringLiteral; |
| 417 | break; |
| 418 | |
| 419 | case Stmt::ObjCEncodeExprClass: |
| 420 | K = CXCursor_ObjCEncodeExpr; |
| 421 | break; |
| 422 | |
| 423 | case Stmt::ObjCSelectorExprClass: |
| 424 | K = CXCursor_ObjCSelectorExpr; |
| 425 | break; |
| 426 | |
| 427 | case Stmt::ObjCProtocolExprClass: |
| 428 | K = CXCursor_ObjCProtocolExpr; |
| 429 | break; |
Ted Kremenek | b3f7542 | 2012-03-06 20:06:06 +0000 | [diff] [blame] | 430 | |
| 431 | case Stmt::ObjCBoolLiteralExprClass: |
| 432 | K = CXCursor_ObjCBoolLiteralExpr; |
| 433 | break; |
| 434 | |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 435 | case Stmt::ObjCBridgedCastExprClass: |
| 436 | K = CXCursor_ObjCBridgedCastExpr; |
| 437 | break; |
| 438 | |
| 439 | case Stmt::BlockExprClass: |
| 440 | K = CXCursor_BlockExpr; |
| 441 | break; |
| 442 | |
| 443 | case Stmt::PackExpansionExprClass: |
| 444 | K = CXCursor_PackExpansionExpr; |
| 445 | break; |
| 446 | |
| 447 | case Stmt::SizeOfPackExprClass: |
| 448 | K = CXCursor_SizeOfPackExpr; |
| 449 | break; |
| 450 | |
Argyrios Kyrtzidis | edab047 | 2013-04-23 17:57:17 +0000 | [diff] [blame] | 451 | case Stmt::DeclRefExprClass: |
| 452 | if (const ImplicitParamDecl *IPD = |
| 453 | dyn_cast_or_null<ImplicitParamDecl>(cast<DeclRefExpr>(S)->getDecl())) { |
| 454 | if (const ObjCMethodDecl *MD = |
| 455 | dyn_cast<ObjCMethodDecl>(IPD->getDeclContext())) { |
| 456 | if (MD->getSelfDecl() == IPD) { |
| 457 | K = CXCursor_ObjCSelfExpr; |
| 458 | break; |
| 459 | } |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | K = CXCursor_DeclRefExpr; |
| 464 | break; |
| 465 | |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 466 | case Stmt::DependentScopeDeclRefExprClass: |
John McCall | 91a5755 | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 467 | case Stmt::SubstNonTypeTemplateParmExprClass: |
Douglas Gregor | c7793c7 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 468 | case Stmt::SubstNonTypeTemplateParmPackExprClass: |
Richard Smith | 9a4db03 | 2012-09-12 00:56:43 +0000 | [diff] [blame] | 469 | case Stmt::FunctionParmPackExprClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 470 | case Stmt::UnresolvedLookupExprClass: |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 471 | K = CXCursor_DeclRefExpr; |
| 472 | break; |
| 473 | |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 474 | case Stmt::CXXDependentScopeMemberExprClass: |
| 475 | case Stmt::CXXPseudoDestructorExprClass: |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 476 | case Stmt::MemberExprClass: |
John McCall | 76da55d | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 477 | case Stmt::MSPropertyRefExprClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 478 | case Stmt::ObjCIsaExprClass: |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 479 | case Stmt::ObjCIvarRefExprClass: |
| 480 | case Stmt::ObjCPropertyRefExprClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 481 | case Stmt::UnresolvedMemberExprClass: |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 482 | K = CXCursor_MemberRefExpr; |
| 483 | break; |
| 484 | |
| 485 | case Stmt::CallExprClass: |
| 486 | case Stmt::CXXOperatorCallExprClass: |
| 487 | case Stmt::CXXMemberCallExprClass: |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 488 | case Stmt::CUDAKernelCallExprClass: |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 489 | case Stmt::CXXConstructExprClass: |
| 490 | case Stmt::CXXTemporaryObjectExprClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 491 | case Stmt::CXXUnresolvedConstructExprClass: |
Richard Smith | 9fcce65 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 492 | case Stmt::UserDefinedLiteralClass: |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 493 | K = CXCursor_CallExpr; |
| 494 | break; |
| 495 | |
Douglas Gregor | 011d8b9 | 2012-02-15 00:54:55 +0000 | [diff] [blame] | 496 | case Stmt::LambdaExprClass: |
| 497 | K = CXCursor_LambdaExpr; |
| 498 | break; |
| 499 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 500 | case Stmt::ObjCMessageExprClass: { |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 501 | K = CXCursor_ObjCMessageExpr; |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 502 | int SelectorIdIndex = -1; |
| 503 | // Check if cursor points to a selector id. |
| 504 | if (RegionOfInterest.isValid() && |
| 505 | RegionOfInterest.getBegin() == RegionOfInterest.getEnd()) { |
| 506 | SmallVector<SourceLocation, 16> SelLocs; |
| 507 | cast<ObjCMessageExpr>(S)->getSelectorLocs(SelLocs); |
Craig Topper | 09d19ef | 2013-07-04 03:08:24 +0000 | [diff] [blame] | 508 | SmallVectorImpl<SourceLocation>::iterator |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 509 | I=std::find(SelLocs.begin(), SelLocs.end(),RegionOfInterest.getBegin()); |
| 510 | if (I != SelLocs.end()) |
| 511 | SelectorIdIndex = I - SelLocs.begin(); |
| 512 | } |
| 513 | CXCursor C = { K, 0, { Parent, S, TU } }; |
| 514 | return getSelectorIdentifierCursor(SelectorIdIndex, C); |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 515 | } |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 516 | |
| 517 | case Stmt::MSDependentExistsStmtClass: |
| 518 | K = CXCursor_UnexposedStmt; |
| 519 | break; |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 520 | case Stmt::OMPParallelDirectiveClass: |
| 521 | K = CXCursor_OMPParallelDirective; |
| 522 | break; |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 523 | case Stmt::OMPSimdDirectiveClass: |
| 524 | K = CXCursor_OMPSimdDirective; |
| 525 | break; |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 526 | case Stmt::OMPForDirectiveClass: |
| 527 | K = CXCursor_OMPForDirective; |
| 528 | break; |
| 529 | case Stmt::OMPSectionsDirectiveClass: |
| 530 | K = CXCursor_OMPSectionsDirective; |
| 531 | break; |
| 532 | case Stmt::OMPSectionDirectiveClass: |
| 533 | K = CXCursor_OMPSectionDirective; |
| 534 | break; |
| 535 | case Stmt::OMPSingleDirectiveClass: |
| 536 | K = CXCursor_OMPSingleDirective; |
| 537 | break; |
| 538 | case Stmt::OMPParallelForDirectiveClass: |
| 539 | K = CXCursor_OMPParallelForDirective; |
| 540 | break; |
| 541 | case Stmt::OMPParallelSectionsDirectiveClass: |
| 542 | K = CXCursor_OMPParallelSectionsDirective; |
| 543 | break; |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 544 | } |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 545 | |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 546 | CXCursor C = { K, 0, { Parent, S, TU } }; |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 547 | return C; |
| 548 | } |
| 549 | |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 550 | CXCursor cxcursor::MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super, |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 551 | SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 552 | CXTranslationUnit TU) { |
Daniel Dunbar | 54d67ca | 2010-01-25 00:40:30 +0000 | [diff] [blame] | 553 | assert(Super && TU && "Invalid arguments!"); |
Dmitri Gribenko | cb6bcf1 | 2013-02-16 01:07:48 +0000 | [diff] [blame] | 554 | void *RawLoc = Loc.getPtrEncoding(); |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 555 | CXCursor C = { CXCursor_ObjCSuperClassRef, 0, { Super, RawLoc, TU } }; |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 556 | return C; |
| 557 | } |
| 558 | |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 559 | std::pair<const ObjCInterfaceDecl *, SourceLocation> |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 560 | cxcursor::getCursorObjCSuperClassRef(CXCursor C) { |
| 561 | assert(C.kind == CXCursor_ObjCSuperClassRef); |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 562 | return std::make_pair(static_cast<const ObjCInterfaceDecl *>(C.data[0]), |
Dmitri Gribenko | 62d0f56 | 2013-02-14 20:07:36 +0000 | [diff] [blame] | 563 | SourceLocation::getFromPtrEncoding(C.data[1])); |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 564 | } |
| 565 | |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 566 | CXCursor cxcursor::MakeCursorObjCProtocolRef(const ObjCProtocolDecl *Proto, |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 567 | SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 568 | CXTranslationUnit TU) { |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 569 | assert(Proto && TU && "Invalid arguments!"); |
Dmitri Gribenko | cb6bcf1 | 2013-02-16 01:07:48 +0000 | [diff] [blame] | 570 | void *RawLoc = Loc.getPtrEncoding(); |
Dmitri Gribenko | 3315618 | 2013-01-11 21:06:06 +0000 | [diff] [blame] | 571 | CXCursor C = { CXCursor_ObjCProtocolRef, 0, { Proto, RawLoc, TU } }; |
Douglas Gregor | 78db0cd | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 572 | return C; |
| 573 | } |
| 574 | |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 575 | std::pair<const ObjCProtocolDecl *, SourceLocation> |
Douglas Gregor | 78db0cd | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 576 | cxcursor::getCursorObjCProtocolRef(CXCursor C) { |
| 577 | assert(C.kind == CXCursor_ObjCProtocolRef); |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 578 | return std::make_pair(static_cast<const ObjCProtocolDecl *>(C.data[0]), |
Dmitri Gribenko | 62d0f56 | 2013-02-14 20:07:36 +0000 | [diff] [blame] | 579 | SourceLocation::getFromPtrEncoding(C.data[1])); |
Douglas Gregor | 78db0cd | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 580 | } |
| 581 | |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 582 | CXCursor cxcursor::MakeCursorObjCClassRef(const ObjCInterfaceDecl *Class, |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 583 | SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 584 | CXTranslationUnit TU) { |
Ted Kremenek | ebfa339 | 2010-03-19 20:39:03 +0000 | [diff] [blame] | 585 | // 'Class' can be null for invalid code. |
| 586 | if (!Class) |
| 587 | return MakeCXCursorInvalid(CXCursor_InvalidCode); |
| 588 | assert(TU && "Invalid arguments!"); |
Dmitri Gribenko | cb6bcf1 | 2013-02-16 01:07:48 +0000 | [diff] [blame] | 589 | void *RawLoc = Loc.getPtrEncoding(); |
Dmitri Gribenko | 3315618 | 2013-01-11 21:06:06 +0000 | [diff] [blame] | 590 | CXCursor C = { CXCursor_ObjCClassRef, 0, { Class, RawLoc, TU } }; |
Douglas Gregor | 1adb082 | 2010-01-16 17:14:40 +0000 | [diff] [blame] | 591 | return C; |
| 592 | } |
| 593 | |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 594 | std::pair<const ObjCInterfaceDecl *, SourceLocation> |
Douglas Gregor | 1adb082 | 2010-01-16 17:14:40 +0000 | [diff] [blame] | 595 | cxcursor::getCursorObjCClassRef(CXCursor C) { |
| 596 | assert(C.kind == CXCursor_ObjCClassRef); |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 597 | return std::make_pair(static_cast<const ObjCInterfaceDecl *>(C.data[0]), |
Dmitri Gribenko | 62d0f56 | 2013-02-14 20:07:36 +0000 | [diff] [blame] | 598 | SourceLocation::getFromPtrEncoding(C.data[1])); |
Douglas Gregor | 1adb082 | 2010-01-16 17:14:40 +0000 | [diff] [blame] | 599 | } |
| 600 | |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 601 | CXCursor cxcursor::MakeCursorTypeRef(const TypeDecl *Type, SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 602 | CXTranslationUnit TU) { |
Daniel Dunbar | 54d67ca | 2010-01-25 00:40:30 +0000 | [diff] [blame] | 603 | assert(Type && TU && "Invalid arguments!"); |
Dmitri Gribenko | cb6bcf1 | 2013-02-16 01:07:48 +0000 | [diff] [blame] | 604 | void *RawLoc = Loc.getPtrEncoding(); |
Dmitri Gribenko | 3315618 | 2013-01-11 21:06:06 +0000 | [diff] [blame] | 605 | CXCursor C = { CXCursor_TypeRef, 0, { Type, RawLoc, TU } }; |
Douglas Gregor | 7d0d40e | 2010-01-21 16:28:34 +0000 | [diff] [blame] | 606 | return C; |
| 607 | } |
| 608 | |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 609 | std::pair<const TypeDecl *, SourceLocation> |
Douglas Gregor | 7d0d40e | 2010-01-21 16:28:34 +0000 | [diff] [blame] | 610 | cxcursor::getCursorTypeRef(CXCursor C) { |
| 611 | assert(C.kind == CXCursor_TypeRef); |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 612 | return std::make_pair(static_cast<const TypeDecl *>(C.data[0]), |
Dmitri Gribenko | 62d0f56 | 2013-02-14 20:07:36 +0000 | [diff] [blame] | 613 | SourceLocation::getFromPtrEncoding(C.data[1])); |
Douglas Gregor | 7d0d40e | 2010-01-21 16:28:34 +0000 | [diff] [blame] | 614 | } |
| 615 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 616 | CXCursor cxcursor::MakeCursorTemplateRef(const TemplateDecl *Template, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 617 | SourceLocation Loc, |
| 618 | CXTranslationUnit TU) { |
Douglas Gregor | 0b36e61 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 619 | assert(Template && TU && "Invalid arguments!"); |
Dmitri Gribenko | cb6bcf1 | 2013-02-16 01:07:48 +0000 | [diff] [blame] | 620 | void *RawLoc = Loc.getPtrEncoding(); |
Dmitri Gribenko | 3315618 | 2013-01-11 21:06:06 +0000 | [diff] [blame] | 621 | CXCursor C = { CXCursor_TemplateRef, 0, { Template, RawLoc, TU } }; |
Douglas Gregor | 0b36e61 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 622 | return C; |
| 623 | } |
| 624 | |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 625 | std::pair<const TemplateDecl *, SourceLocation> |
Douglas Gregor | 0b36e61 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 626 | cxcursor::getCursorTemplateRef(CXCursor C) { |
| 627 | assert(C.kind == CXCursor_TemplateRef); |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 628 | return std::make_pair(static_cast<const TemplateDecl *>(C.data[0]), |
Dmitri Gribenko | 62d0f56 | 2013-02-14 20:07:36 +0000 | [diff] [blame] | 629 | SourceLocation::getFromPtrEncoding(C.data[1])); |
Douglas Gregor | 0b36e61 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 630 | } |
| 631 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 632 | CXCursor cxcursor::MakeCursorNamespaceRef(const NamedDecl *NS, |
| 633 | SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 634 | CXTranslationUnit TU) { |
Douglas Gregor | 6931900 | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 635 | |
| 636 | assert(NS && (isa<NamespaceDecl>(NS) || isa<NamespaceAliasDecl>(NS)) && TU && |
| 637 | "Invalid arguments!"); |
Dmitri Gribenko | cb6bcf1 | 2013-02-16 01:07:48 +0000 | [diff] [blame] | 638 | void *RawLoc = Loc.getPtrEncoding(); |
Dmitri Gribenko | 3315618 | 2013-01-11 21:06:06 +0000 | [diff] [blame] | 639 | CXCursor C = { CXCursor_NamespaceRef, 0, { NS, RawLoc, TU } }; |
Douglas Gregor | 6931900 | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 640 | return C; |
| 641 | } |
| 642 | |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 643 | std::pair<const NamedDecl *, SourceLocation> |
Douglas Gregor | 6931900 | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 644 | cxcursor::getCursorNamespaceRef(CXCursor C) { |
| 645 | assert(C.kind == CXCursor_NamespaceRef); |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 646 | return std::make_pair(static_cast<const NamedDecl *>(C.data[0]), |
Dmitri Gribenko | 62d0f56 | 2013-02-14 20:07:36 +0000 | [diff] [blame] | 647 | SourceLocation::getFromPtrEncoding(C.data[1])); |
Douglas Gregor | 6931900 | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 648 | } |
| 649 | |
Douglas Gregor | 011d8b9 | 2012-02-15 00:54:55 +0000 | [diff] [blame] | 650 | CXCursor cxcursor::MakeCursorVariableRef(const VarDecl *Var, SourceLocation Loc, |
| 651 | CXTranslationUnit TU) { |
| 652 | |
| 653 | assert(Var && TU && "Invalid arguments!"); |
Dmitri Gribenko | cb6bcf1 | 2013-02-16 01:07:48 +0000 | [diff] [blame] | 654 | void *RawLoc = Loc.getPtrEncoding(); |
Dmitri Gribenko | 3315618 | 2013-01-11 21:06:06 +0000 | [diff] [blame] | 655 | CXCursor C = { CXCursor_VariableRef, 0, { Var, RawLoc, TU } }; |
Douglas Gregor | 011d8b9 | 2012-02-15 00:54:55 +0000 | [diff] [blame] | 656 | return C; |
| 657 | } |
| 658 | |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 659 | std::pair<const VarDecl *, SourceLocation> |
Douglas Gregor | 011d8b9 | 2012-02-15 00:54:55 +0000 | [diff] [blame] | 660 | cxcursor::getCursorVariableRef(CXCursor C) { |
| 661 | assert(C.kind == CXCursor_VariableRef); |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 662 | return std::make_pair(static_cast<const VarDecl *>(C.data[0]), |
Dmitri Gribenko | 62d0f56 | 2013-02-14 20:07:36 +0000 | [diff] [blame] | 663 | SourceLocation::getFromPtrEncoding(C.data[1])); |
Douglas Gregor | 011d8b9 | 2012-02-15 00:54:55 +0000 | [diff] [blame] | 664 | } |
| 665 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 666 | CXCursor cxcursor::MakeCursorMemberRef(const FieldDecl *Field, SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 667 | CXTranslationUnit TU) { |
Douglas Gregor | a67e03f | 2010-09-09 21:42:20 +0000 | [diff] [blame] | 668 | |
| 669 | assert(Field && TU && "Invalid arguments!"); |
Dmitri Gribenko | cb6bcf1 | 2013-02-16 01:07:48 +0000 | [diff] [blame] | 670 | void *RawLoc = Loc.getPtrEncoding(); |
Dmitri Gribenko | 3315618 | 2013-01-11 21:06:06 +0000 | [diff] [blame] | 671 | CXCursor C = { CXCursor_MemberRef, 0, { Field, RawLoc, TU } }; |
Douglas Gregor | a67e03f | 2010-09-09 21:42:20 +0000 | [diff] [blame] | 672 | return C; |
| 673 | } |
| 674 | |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 675 | std::pair<const FieldDecl *, SourceLocation> |
Douglas Gregor | a67e03f | 2010-09-09 21:42:20 +0000 | [diff] [blame] | 676 | cxcursor::getCursorMemberRef(CXCursor C) { |
| 677 | assert(C.kind == CXCursor_MemberRef); |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 678 | return std::make_pair(static_cast<const FieldDecl *>(C.data[0]), |
Dmitri Gribenko | 62d0f56 | 2013-02-14 20:07:36 +0000 | [diff] [blame] | 679 | SourceLocation::getFromPtrEncoding(C.data[1])); |
Douglas Gregor | a67e03f | 2010-09-09 21:42:20 +0000 | [diff] [blame] | 680 | } |
| 681 | |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 682 | CXCursor cxcursor::MakeCursorCXXBaseSpecifier(const CXXBaseSpecifier *B, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 683 | CXTranslationUnit TU){ |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 684 | CXCursor C = { CXCursor_CXXBaseSpecifier, 0, { B, nullptr, TU } }; |
Ted Kremenek | 3064ef9 | 2010-08-27 21:34:58 +0000 | [diff] [blame] | 685 | return C; |
| 686 | } |
| 687 | |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 688 | const CXXBaseSpecifier *cxcursor::getCursorCXXBaseSpecifier(CXCursor C) { |
Ted Kremenek | 3064ef9 | 2010-08-27 21:34:58 +0000 | [diff] [blame] | 689 | assert(C.kind == CXCursor_CXXBaseSpecifier); |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 690 | return static_cast<const CXXBaseSpecifier*>(C.data[0]); |
Ted Kremenek | 3064ef9 | 2010-08-27 21:34:58 +0000 | [diff] [blame] | 691 | } |
| 692 | |
Douglas Gregor | 9f1e3ff | 2010-03-18 00:42:48 +0000 | [diff] [blame] | 693 | CXCursor cxcursor::MakePreprocessingDirectiveCursor(SourceRange Range, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 694 | CXTranslationUnit TU) { |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 695 | CXCursor C = { CXCursor_PreprocessingDirective, 0, |
Dmitri Gribenko | cb6bcf1 | 2013-02-16 01:07:48 +0000 | [diff] [blame] | 696 | { Range.getBegin().getPtrEncoding(), |
| 697 | Range.getEnd().getPtrEncoding(), |
Douglas Gregor | 9f1e3ff | 2010-03-18 00:42:48 +0000 | [diff] [blame] | 698 | TU } |
| 699 | }; |
| 700 | return C; |
| 701 | } |
| 702 | |
| 703 | SourceRange cxcursor::getCursorPreprocessingDirective(CXCursor C) { |
| 704 | assert(C.kind == CXCursor_PreprocessingDirective); |
Dmitri Gribenko | 62d0f56 | 2013-02-14 20:07:36 +0000 | [diff] [blame] | 705 | SourceRange Range(SourceLocation::getFromPtrEncoding(C.data[0]), |
| 706 | SourceLocation::getFromPtrEncoding(C.data[1])); |
Argyrios Kyrtzidis | ee0f84f | 2011-09-26 08:01:41 +0000 | [diff] [blame] | 707 | ASTUnit *TU = getCursorASTUnit(C); |
| 708 | return TU->mapRangeFromPreamble(Range); |
Douglas Gregor | 9f1e3ff | 2010-03-18 00:42:48 +0000 | [diff] [blame] | 709 | } |
| 710 | |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 711 | CXCursor cxcursor::MakeMacroDefinitionCursor(const MacroDefinition *MI, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 712 | CXTranslationUnit TU) { |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 713 | CXCursor C = { CXCursor_MacroDefinition, 0, { MI, nullptr, TU } }; |
Douglas Gregor | 572feb2 | 2010-03-18 18:04:21 +0000 | [diff] [blame] | 714 | return C; |
| 715 | } |
| 716 | |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 717 | const MacroDefinition *cxcursor::getCursorMacroDefinition(CXCursor C) { |
Douglas Gregor | 572feb2 | 2010-03-18 18:04:21 +0000 | [diff] [blame] | 718 | assert(C.kind == CXCursor_MacroDefinition); |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 719 | return static_cast<const MacroDefinition *>(C.data[0]); |
Douglas Gregor | 572feb2 | 2010-03-18 18:04:21 +0000 | [diff] [blame] | 720 | } |
| 721 | |
Chandler Carruth | 9e5bb85 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 722 | CXCursor cxcursor::MakeMacroExpansionCursor(MacroExpansion *MI, |
| 723 | CXTranslationUnit TU) { |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 724 | CXCursor C = { CXCursor_MacroExpansion, 0, { MI, nullptr, TU } }; |
Douglas Gregor | 4807231 | 2010-03-18 15:23:44 +0000 | [diff] [blame] | 725 | return C; |
| 726 | } |
| 727 | |
Argyrios Kyrtzidis | 664b06f | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 728 | CXCursor cxcursor::MakeMacroExpansionCursor(MacroDefinition *MI, |
| 729 | SourceLocation Loc, |
| 730 | CXTranslationUnit TU) { |
| 731 | assert(Loc.isValid()); |
| 732 | CXCursor C = { CXCursor_MacroExpansion, 0, { MI, Loc.getPtrEncoding(), TU } }; |
| 733 | return C; |
| 734 | } |
| 735 | |
| 736 | const IdentifierInfo *cxcursor::MacroExpansionCursor::getName() const { |
| 737 | if (isPseudo()) |
| 738 | return getAsMacroDefinition()->getName(); |
| 739 | return getAsMacroExpansion()->getName(); |
| 740 | } |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 741 | const MacroDefinition *cxcursor::MacroExpansionCursor::getDefinition() const { |
Argyrios Kyrtzidis | 664b06f | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 742 | if (isPseudo()) |
| 743 | return getAsMacroDefinition(); |
| 744 | return getAsMacroExpansion()->getDefinition(); |
| 745 | } |
| 746 | SourceRange cxcursor::MacroExpansionCursor::getSourceRange() const { |
| 747 | if (isPseudo()) |
| 748 | return getPseudoLoc(); |
| 749 | return getAsMacroExpansion()->getSourceRange(); |
Douglas Gregor | 4807231 | 2010-03-18 15:23:44 +0000 | [diff] [blame] | 750 | } |
| 751 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 752 | CXCursor cxcursor::MakeInclusionDirectiveCursor(InclusionDirective *ID, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 753 | CXTranslationUnit TU) { |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 754 | CXCursor C = { CXCursor_InclusionDirective, 0, { ID, nullptr, TU } }; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 755 | return C; |
| 756 | } |
| 757 | |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 758 | const InclusionDirective *cxcursor::getCursorInclusionDirective(CXCursor C) { |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 759 | assert(C.kind == CXCursor_InclusionDirective); |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 760 | return static_cast<const InclusionDirective *>(C.data[0]); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 761 | } |
| 762 | |
Douglas Gregor | 36897b0 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 763 | CXCursor cxcursor::MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 764 | CXTranslationUnit TU) { |
Douglas Gregor | 36897b0 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 765 | |
| 766 | assert(Label && TU && "Invalid arguments!"); |
Dmitri Gribenko | cb6bcf1 | 2013-02-16 01:07:48 +0000 | [diff] [blame] | 767 | void *RawLoc = Loc.getPtrEncoding(); |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 768 | CXCursor C = { CXCursor_LabelRef, 0, { Label, RawLoc, TU } }; |
Douglas Gregor | 36897b0 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 769 | return C; |
| 770 | } |
| 771 | |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 772 | std::pair<const LabelStmt *, SourceLocation> |
Douglas Gregor | 36897b0 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 773 | cxcursor::getCursorLabelRef(CXCursor C) { |
| 774 | assert(C.kind == CXCursor_LabelRef); |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 775 | return std::make_pair(static_cast<const LabelStmt *>(C.data[0]), |
Dmitri Gribenko | 62d0f56 | 2013-02-14 20:07:36 +0000 | [diff] [blame] | 776 | SourceLocation::getFromPtrEncoding(C.data[1])); |
Douglas Gregor | 36897b0 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 777 | } |
| 778 | |
Dmitri Gribenko | e22339c | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 779 | CXCursor cxcursor::MakeCursorOverloadedDeclRef(const OverloadExpr *E, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 780 | CXTranslationUnit TU) { |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 781 | assert(E && TU && "Invalid arguments!"); |
| 782 | OverloadedDeclRefStorage Storage(E); |
Dmitri Gribenko | cb6bcf1 | 2013-02-16 01:07:48 +0000 | [diff] [blame] | 783 | void *RawLoc = E->getNameLoc().getPtrEncoding(); |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 784 | CXCursor C = { |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 785 | CXCursor_OverloadedDeclRef, 0, |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 786 | { Storage.getOpaqueValue(), RawLoc, TU } |
| 787 | }; |
| 788 | return C; |
| 789 | } |
| 790 | |
Dmitri Gribenko | e22339c | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 791 | CXCursor cxcursor::MakeCursorOverloadedDeclRef(const Decl *D, |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 792 | SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 793 | CXTranslationUnit TU) { |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 794 | assert(D && TU && "Invalid arguments!"); |
Dmitri Gribenko | cb6bcf1 | 2013-02-16 01:07:48 +0000 | [diff] [blame] | 795 | void *RawLoc = Loc.getPtrEncoding(); |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 796 | OverloadedDeclRefStorage Storage(D); |
| 797 | CXCursor C = { |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 798 | CXCursor_OverloadedDeclRef, 0, |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 799 | { Storage.getOpaqueValue(), RawLoc, TU } |
| 800 | }; |
| 801 | return C; |
| 802 | } |
| 803 | |
| 804 | CXCursor cxcursor::MakeCursorOverloadedDeclRef(TemplateName Name, |
| 805 | SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 806 | CXTranslationUnit TU) { |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 807 | assert(Name.getAsOverloadedTemplate() && TU && "Invalid arguments!"); |
Dmitri Gribenko | cb6bcf1 | 2013-02-16 01:07:48 +0000 | [diff] [blame] | 808 | void *RawLoc = Loc.getPtrEncoding(); |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 809 | OverloadedDeclRefStorage Storage(Name.getAsOverloadedTemplate()); |
| 810 | CXCursor C = { |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 811 | CXCursor_OverloadedDeclRef, 0, |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 812 | { Storage.getOpaqueValue(), RawLoc, TU } |
| 813 | }; |
| 814 | return C; |
| 815 | } |
| 816 | |
| 817 | std::pair<cxcursor::OverloadedDeclRefStorage, SourceLocation> |
| 818 | cxcursor::getCursorOverloadedDeclRef(CXCursor C) { |
| 819 | assert(C.kind == CXCursor_OverloadedDeclRef); |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 820 | return std::make_pair(OverloadedDeclRefStorage::getFromOpaqueValue( |
| 821 | const_cast<void *>(C.data[0])), |
Dmitri Gribenko | 62d0f56 | 2013-02-14 20:07:36 +0000 | [diff] [blame] | 822 | SourceLocation::getFromPtrEncoding(C.data[1])); |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 823 | } |
| 824 | |
Dmitri Gribenko | e22339c | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 825 | const Decl *cxcursor::getCursorDecl(CXCursor Cursor) { |
| 826 | return static_cast<const Decl *>(Cursor.data[0]); |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 827 | } |
| 828 | |
Dmitri Gribenko | ff74f96 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 829 | const Expr *cxcursor::getCursorExpr(CXCursor Cursor) { |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 830 | return dyn_cast_or_null<Expr>(getCursorStmt(Cursor)); |
| 831 | } |
| 832 | |
Dmitri Gribenko | ff74f96 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 833 | const Stmt *cxcursor::getCursorStmt(CXCursor Cursor) { |
Douglas Gregor | 78db0cd | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 834 | if (Cursor.kind == CXCursor_ObjCSuperClassRef || |
Douglas Gregor | 1adb082 | 2010-01-16 17:14:40 +0000 | [diff] [blame] | 835 | Cursor.kind == CXCursor_ObjCProtocolRef || |
| 836 | Cursor.kind == CXCursor_ObjCClassRef) |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 837 | return nullptr; |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 838 | |
Dmitri Gribenko | ff74f96 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 839 | return static_cast<const Stmt *>(Cursor.data[1]); |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 840 | } |
| 841 | |
Dmitri Gribenko | 7d91438 | 2013-01-26 18:08:08 +0000 | [diff] [blame] | 842 | const Attr *cxcursor::getCursorAttr(CXCursor Cursor) { |
| 843 | return static_cast<const Attr *>(Cursor.data[1]); |
Ted Kremenek | 95f3355 | 2010-08-26 01:42:22 +0000 | [diff] [blame] | 844 | } |
| 845 | |
Dmitri Gribenko | 404628c | 2013-01-26 18:12:08 +0000 | [diff] [blame] | 846 | const Decl *cxcursor::getCursorParentDecl(CXCursor Cursor) { |
| 847 | return static_cast<const Decl *>(Cursor.data[0]); |
Argyrios Kyrtzidis | 8ccac3d | 2011-06-29 22:20:07 +0000 | [diff] [blame] | 848 | } |
| 849 | |
Douglas Gregor | f46034a | 2010-01-18 23:41:10 +0000 | [diff] [blame] | 850 | ASTContext &cxcursor::getCursorContext(CXCursor Cursor) { |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 851 | return getCursorASTUnit(Cursor)->getASTContext(); |
| 852 | } |
Douglas Gregor | f46034a | 2010-01-18 23:41:10 +0000 | [diff] [blame] | 853 | |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 854 | ASTUnit *cxcursor::getCursorASTUnit(CXCursor Cursor) { |
Dmitri Gribenko | 46f9252 | 2013-01-11 19:28:44 +0000 | [diff] [blame] | 855 | CXTranslationUnit TU = getCursorTU(Cursor); |
Argyrios Kyrtzidis | 4451746 | 2011-12-09 00:17:49 +0000 | [diff] [blame] | 856 | if (!TU) |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 857 | return nullptr; |
Dmitri Gribenko | 5694feb | 2013-01-26 18:53:38 +0000 | [diff] [blame] | 858 | return cxtu::getASTUnit(TU); |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | CXTranslationUnit cxcursor::getCursorTU(CXCursor Cursor) { |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 862 | return static_cast<CXTranslationUnit>(const_cast<void*>(Cursor.data[2])); |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 863 | } |
| 864 | |
Argyrios Kyrtzidis | e15db6f | 2012-05-09 16:12:57 +0000 | [diff] [blame] | 865 | void cxcursor::getOverriddenCursors(CXCursor cursor, |
| 866 | SmallVectorImpl<CXCursor> &overridden) { |
| 867 | assert(clang_isDeclaration(cursor.kind)); |
Argyrios Kyrtzidis | 21c3607 | 2012-10-09 01:23:50 +0000 | [diff] [blame] | 868 | const NamedDecl *D = dyn_cast_or_null<NamedDecl>(getCursorDecl(cursor)); |
Argyrios Kyrtzidis | e15db6f | 2012-05-09 16:12:57 +0000 | [diff] [blame] | 869 | if (!D) |
| 870 | return; |
| 871 | |
Argyrios Kyrtzidis | e15db6f | 2012-05-09 16:12:57 +0000 | [diff] [blame] | 872 | CXTranslationUnit TU = getCursorTU(cursor); |
Argyrios Kyrtzidis | 21c3607 | 2012-10-09 01:23:50 +0000 | [diff] [blame] | 873 | SmallVector<const NamedDecl *, 8> OverDecls; |
| 874 | D->getASTContext().getOverriddenMethods(D, OverDecls); |
Argyrios Kyrtzidis | e15db6f | 2012-05-09 16:12:57 +0000 | [diff] [blame] | 875 | |
Craig Topper | 09d19ef | 2013-07-04 03:08:24 +0000 | [diff] [blame] | 876 | for (SmallVectorImpl<const NamedDecl *>::iterator |
Argyrios Kyrtzidis | 21c3607 | 2012-10-09 01:23:50 +0000 | [diff] [blame] | 877 | I = OverDecls.begin(), E = OverDecls.end(); I != E; ++I) { |
Dmitri Gribenko | 05756dc | 2013-01-14 00:46:27 +0000 | [diff] [blame] | 878 | overridden.push_back(MakeCXCursor(*I, TU)); |
Argyrios Kyrtzidis | e15db6f | 2012-05-09 16:12:57 +0000 | [diff] [blame] | 879 | } |
| 880 | } |
| 881 | |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 882 | std::pair<int, SourceLocation> |
| 883 | cxcursor::getSelectorIdentifierIndexAndLoc(CXCursor cursor) { |
| 884 | if (cursor.kind == CXCursor_ObjCMessageExpr) { |
| 885 | if (cursor.xdata != -1) |
| 886 | return std::make_pair(cursor.xdata, |
| 887 | cast<ObjCMessageExpr>(getCursorExpr(cursor)) |
| 888 | ->getSelectorLoc(cursor.xdata)); |
| 889 | } else if (cursor.kind == CXCursor_ObjCClassMethodDecl || |
| 890 | cursor.kind == CXCursor_ObjCInstanceMethodDecl) { |
| 891 | if (cursor.xdata != -1) |
| 892 | return std::make_pair(cursor.xdata, |
| 893 | cast<ObjCMethodDecl>(getCursorDecl(cursor)) |
| 894 | ->getSelectorLoc(cursor.xdata)); |
| 895 | } |
| 896 | |
| 897 | return std::make_pair(-1, SourceLocation()); |
| 898 | } |
| 899 | |
| 900 | CXCursor cxcursor::getSelectorIdentifierCursor(int SelIdx, CXCursor cursor) { |
| 901 | CXCursor newCursor = cursor; |
| 902 | |
| 903 | if (cursor.kind == CXCursor_ObjCMessageExpr) { |
| 904 | if (SelIdx == -1 || |
| 905 | unsigned(SelIdx) >= cast<ObjCMessageExpr>(getCursorExpr(cursor)) |
| 906 | ->getNumSelectorLocs()) |
| 907 | newCursor.xdata = -1; |
| 908 | else |
| 909 | newCursor.xdata = SelIdx; |
| 910 | } else if (cursor.kind == CXCursor_ObjCClassMethodDecl || |
| 911 | cursor.kind == CXCursor_ObjCInstanceMethodDecl) { |
| 912 | if (SelIdx == -1 || |
| 913 | unsigned(SelIdx) >= cast<ObjCMethodDecl>(getCursorDecl(cursor)) |
| 914 | ->getNumSelectorLocs()) |
| 915 | newCursor.xdata = -1; |
| 916 | else |
| 917 | newCursor.xdata = SelIdx; |
| 918 | } |
| 919 | |
| 920 | return newCursor; |
| 921 | } |
| 922 | |
| 923 | CXCursor cxcursor::getTypeRefCursor(CXCursor cursor) { |
| 924 | if (cursor.kind != CXCursor_CallExpr) |
| 925 | return cursor; |
| 926 | |
| 927 | if (cursor.xdata == 0) |
| 928 | return cursor; |
| 929 | |
Dmitri Gribenko | ff74f96 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 930 | const Expr *E = getCursorExpr(cursor); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 931 | TypeSourceInfo *Type = nullptr; |
Dmitri Gribenko | ff74f96 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 932 | if (const CXXUnresolvedConstructExpr * |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 933 | UnCtor = dyn_cast<CXXUnresolvedConstructExpr>(E)) { |
| 934 | Type = UnCtor->getTypeSourceInfo(); |
Dmitri Gribenko | ff74f96 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 935 | } else if (const CXXTemporaryObjectExpr *Tmp = |
| 936 | dyn_cast<CXXTemporaryObjectExpr>(E)){ |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 937 | Type = Tmp->getTypeSourceInfo(); |
| 938 | } |
| 939 | |
| 940 | if (!Type) |
| 941 | return cursor; |
| 942 | |
| 943 | CXTranslationUnit TU = getCursorTU(cursor); |
| 944 | QualType Ty = Type->getType(); |
| 945 | TypeLoc TL = Type->getTypeLoc(); |
| 946 | SourceLocation Loc = TL.getBeginLoc(); |
| 947 | |
| 948 | if (const ElaboratedType *ElabT = Ty->getAs<ElaboratedType>()) { |
| 949 | Ty = ElabT->getNamedType(); |
David Blaikie | 39e6ab4 | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 950 | ElaboratedTypeLoc ElabTL = TL.castAs<ElaboratedTypeLoc>(); |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 951 | Loc = ElabTL.getNamedTypeLoc().getBeginLoc(); |
| 952 | } |
| 953 | |
| 954 | if (const TypedefType *Typedef = Ty->getAs<TypedefType>()) |
| 955 | return MakeCursorTypeRef(Typedef->getDecl(), Loc, TU); |
| 956 | if (const TagType *Tag = Ty->getAs<TagType>()) |
| 957 | return MakeCursorTypeRef(Tag->getDecl(), Loc, TU); |
| 958 | if (const TemplateTypeParmType *TemplP = Ty->getAs<TemplateTypeParmType>()) |
| 959 | return MakeCursorTypeRef(TemplP->getDecl(), Loc, TU); |
| 960 | |
| 961 | return cursor; |
| 962 | } |
| 963 | |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 964 | bool cxcursor::operator==(CXCursor X, CXCursor Y) { |
| 965 | return X.kind == Y.kind && X.data[0] == Y.data[0] && X.data[1] == Y.data[1] && |
| 966 | X.data[2] == Y.data[2]; |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 967 | } |
Ted Kremenek | 007a7c9 | 2010-11-01 23:26:51 +0000 | [diff] [blame] | 968 | |
| 969 | // FIXME: Remove once we can model DeclGroups and their appropriate ranges |
| 970 | // properly in the ASTs. |
| 971 | bool cxcursor::isFirstInDeclGroup(CXCursor C) { |
| 972 | assert(clang_isDeclaration(C.kind)); |
| 973 | return ((uintptr_t) (C.data[1])) != 0; |
| 974 | } |
| 975 | |
Ted Kremenek | eca099b | 2010-12-08 23:43:14 +0000 | [diff] [blame] | 976 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | b0d6eaa | 2011-09-27 00:30:30 +0000 | [diff] [blame] | 977 | // libclang CXCursor APIs |
| 978 | //===----------------------------------------------------------------------===// |
| 979 | |
Argyrios Kyrtzidis | fa865df | 2011-09-27 04:14:36 +0000 | [diff] [blame] | 980 | extern "C" { |
| 981 | |
| 982 | int clang_Cursor_isNull(CXCursor cursor) { |
| 983 | return clang_equalCursors(cursor, clang_getNullCursor()); |
| 984 | } |
| 985 | |
Argyrios Kyrtzidis | b0d6eaa | 2011-09-27 00:30:30 +0000 | [diff] [blame] | 986 | CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor cursor) { |
| 987 | return getCursorTU(cursor); |
| 988 | } |
| 989 | |
Argyrios Kyrtzidis | d98ef9a | 2012-04-11 19:32:19 +0000 | [diff] [blame] | 990 | int clang_Cursor_getNumArguments(CXCursor C) { |
| 991 | if (clang_isDeclaration(C.kind)) { |
Dmitri Gribenko | e22339c | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 992 | const Decl *D = cxcursor::getCursorDecl(C); |
Argyrios Kyrtzidis | d98ef9a | 2012-04-11 19:32:19 +0000 | [diff] [blame] | 993 | if (const ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(D)) |
| 994 | return MD->param_size(); |
| 995 | if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) |
| 996 | return FD->param_size(); |
| 997 | } |
| 998 | |
Argyrios Kyrtzidis | e9ebd85 | 2013-04-01 17:38:59 +0000 | [diff] [blame] | 999 | if (clang_isExpression(C.kind)) { |
| 1000 | const Expr *E = cxcursor::getCursorExpr(C); |
| 1001 | if (const CallExpr *CE = dyn_cast<CallExpr>(E)) { |
| 1002 | return CE->getNumArgs(); |
| 1003 | } |
| 1004 | } |
| 1005 | |
Argyrios Kyrtzidis | d98ef9a | 2012-04-11 19:32:19 +0000 | [diff] [blame] | 1006 | return -1; |
| 1007 | } |
| 1008 | |
| 1009 | CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i) { |
| 1010 | if (clang_isDeclaration(C.kind)) { |
Dmitri Gribenko | e22339c | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 1011 | const Decl *D = cxcursor::getCursorDecl(C); |
| 1012 | if (const ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(D)) { |
Argyrios Kyrtzidis | d98ef9a | 2012-04-11 19:32:19 +0000 | [diff] [blame] | 1013 | if (i < MD->param_size()) |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1014 | return cxcursor::MakeCXCursor(MD->parameters()[i], |
Argyrios Kyrtzidis | d98ef9a | 2012-04-11 19:32:19 +0000 | [diff] [blame] | 1015 | cxcursor::getCursorTU(C)); |
Dmitri Gribenko | e22339c | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 1016 | } else if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) { |
Argyrios Kyrtzidis | d98ef9a | 2012-04-11 19:32:19 +0000 | [diff] [blame] | 1017 | if (i < FD->param_size()) |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1018 | return cxcursor::MakeCXCursor(FD->parameters()[i], |
Argyrios Kyrtzidis | d98ef9a | 2012-04-11 19:32:19 +0000 | [diff] [blame] | 1019 | cxcursor::getCursorTU(C)); |
| 1020 | } |
| 1021 | } |
| 1022 | |
Argyrios Kyrtzidis | e9ebd85 | 2013-04-01 17:38:59 +0000 | [diff] [blame] | 1023 | if (clang_isExpression(C.kind)) { |
| 1024 | const Expr *E = cxcursor::getCursorExpr(C); |
| 1025 | if (const CallExpr *CE = dyn_cast<CallExpr>(E)) { |
| 1026 | if (i < CE->getNumArgs()) { |
| 1027 | return cxcursor::MakeCXCursor(CE->getArg(i), |
| 1028 | getCursorDecl(C), |
| 1029 | cxcursor::getCursorTU(C)); |
| 1030 | } |
| 1031 | } |
| 1032 | } |
| 1033 | |
Argyrios Kyrtzidis | d98ef9a | 2012-04-11 19:32:19 +0000 | [diff] [blame] | 1034 | return clang_getNullCursor(); |
| 1035 | } |
| 1036 | |
Ted Kremenek | 017dd74 | 2013-04-24 07:17:12 +0000 | [diff] [blame] | 1037 | } // end: extern "C" |
| 1038 | |
| 1039 | //===----------------------------------------------------------------------===// |
| 1040 | // CXCursorSet. |
| 1041 | //===----------------------------------------------------------------------===// |
| 1042 | |
| 1043 | typedef llvm::DenseMap<CXCursor, unsigned> CXCursorSet_Impl; |
| 1044 | |
| 1045 | static inline CXCursorSet packCXCursorSet(CXCursorSet_Impl *setImpl) { |
| 1046 | return (CXCursorSet) setImpl; |
| 1047 | } |
| 1048 | static inline CXCursorSet_Impl *unpackCXCursorSet(CXCursorSet set) { |
| 1049 | return (CXCursorSet_Impl*) set; |
| 1050 | } |
| 1051 | namespace llvm { |
| 1052 | template<> struct DenseMapInfo<CXCursor> { |
| 1053 | public: |
| 1054 | static inline CXCursor getEmptyKey() { |
| 1055 | return MakeCXCursorInvalid(CXCursor_InvalidFile); |
| 1056 | } |
| 1057 | static inline CXCursor getTombstoneKey() { |
| 1058 | return MakeCXCursorInvalid(CXCursor_NoDeclFound); |
| 1059 | } |
| 1060 | static inline unsigned getHashValue(const CXCursor &cursor) { |
| 1061 | return llvm::DenseMapInfo<std::pair<const void *, const void *> > |
| 1062 | ::getHashValue(std::make_pair(cursor.data[0], cursor.data[1])); |
| 1063 | } |
| 1064 | static inline bool isEqual(const CXCursor &x, const CXCursor &y) { |
| 1065 | return x.kind == y.kind && |
| 1066 | x.data[0] == y.data[0] && |
| 1067 | x.data[1] == y.data[1]; |
| 1068 | } |
| 1069 | }; |
| 1070 | } |
| 1071 | |
| 1072 | extern "C" { |
| 1073 | CXCursorSet clang_createCXCursorSet() { |
| 1074 | return packCXCursorSet(new CXCursorSet_Impl()); |
| 1075 | } |
| 1076 | |
| 1077 | void clang_disposeCXCursorSet(CXCursorSet set) { |
| 1078 | delete unpackCXCursorSet(set); |
| 1079 | } |
| 1080 | |
| 1081 | unsigned clang_CXCursorSet_contains(CXCursorSet set, CXCursor cursor) { |
| 1082 | CXCursorSet_Impl *setImpl = unpackCXCursorSet(set); |
| 1083 | if (!setImpl) |
| 1084 | return 0; |
Ted Kremenek | 96bbe19 | 2013-04-24 07:25:40 +0000 | [diff] [blame] | 1085 | return setImpl->find(cursor) != setImpl->end(); |
Ted Kremenek | 017dd74 | 2013-04-24 07:17:12 +0000 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | unsigned clang_CXCursorSet_insert(CXCursorSet set, CXCursor cursor) { |
| 1089 | // Do not insert invalid cursors into the set. |
| 1090 | if (cursor.kind >= CXCursor_FirstInvalid && |
| 1091 | cursor.kind <= CXCursor_LastInvalid) |
| 1092 | return 1; |
| 1093 | |
| 1094 | CXCursorSet_Impl *setImpl = unpackCXCursorSet(set); |
| 1095 | if (!setImpl) |
| 1096 | return 1; |
| 1097 | unsigned &entry = (*setImpl)[cursor]; |
| 1098 | unsigned flag = entry == 0 ? 1 : 0; |
| 1099 | entry = 1; |
| 1100 | return flag; |
| 1101 | } |
| 1102 | |
Douglas Gregor | 8fa0a80 | 2011-08-04 20:04:59 +0000 | [diff] [blame] | 1103 | CXCompletionString clang_getCursorCompletionString(CXCursor cursor) { |
| 1104 | enum CXCursorKind kind = clang_getCursorKind(cursor); |
| 1105 | if (clang_isDeclaration(kind)) { |
Dmitri Gribenko | e22339c | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 1106 | const Decl *decl = getCursorDecl(cursor); |
| 1107 | if (const NamedDecl *namedDecl = dyn_cast_or_null<NamedDecl>(decl)) { |
Douglas Gregor | 8fa0a80 | 2011-08-04 20:04:59 +0000 | [diff] [blame] | 1108 | ASTUnit *unit = getCursorASTUnit(cursor); |
Douglas Gregor | d1f09b4 | 2013-01-31 04:52:16 +0000 | [diff] [blame] | 1109 | CodeCompletionResult Result(namedDecl, CCP_Declaration); |
Argyrios Kyrtzidis | 5e192a7 | 2012-01-17 02:15:54 +0000 | [diff] [blame] | 1110 | CodeCompletionString *String |
| 1111 | = Result.CreateCodeCompletionString(unit->getASTContext(), |
| 1112 | unit->getPreprocessor(), |
Argyrios Kyrtzidis | 28a83f5 | 2012-04-10 17:23:48 +0000 | [diff] [blame] | 1113 | unit->getCodeCompletionTUInfo().getAllocator(), |
Dmitri Gribenko | d99ef53 | 2012-07-02 17:35:10 +0000 | [diff] [blame] | 1114 | unit->getCodeCompletionTUInfo(), |
| 1115 | true); |
Argyrios Kyrtzidis | 5e192a7 | 2012-01-17 02:15:54 +0000 | [diff] [blame] | 1116 | return String; |
Douglas Gregor | 8fa0a80 | 2011-08-04 20:04:59 +0000 | [diff] [blame] | 1117 | } |
| 1118 | } |
| 1119 | else if (kind == CXCursor_MacroDefinition) { |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 1120 | const MacroDefinition *definition = getCursorMacroDefinition(cursor); |
Douglas Gregor | 8fa0a80 | 2011-08-04 20:04:59 +0000 | [diff] [blame] | 1121 | const IdentifierInfo *MacroInfo = definition->getName(); |
| 1122 | ASTUnit *unit = getCursorASTUnit(cursor); |
Dmitri Gribenko | b395847 | 2013-01-14 00:36:42 +0000 | [diff] [blame] | 1123 | CodeCompletionResult Result(MacroInfo); |
Argyrios Kyrtzidis | 5e192a7 | 2012-01-17 02:15:54 +0000 | [diff] [blame] | 1124 | CodeCompletionString *String |
| 1125 | = Result.CreateCodeCompletionString(unit->getASTContext(), |
| 1126 | unit->getPreprocessor(), |
Argyrios Kyrtzidis | 28a83f5 | 2012-04-10 17:23:48 +0000 | [diff] [blame] | 1127 | unit->getCodeCompletionTUInfo().getAllocator(), |
Dmitri Gribenko | d99ef53 | 2012-07-02 17:35:10 +0000 | [diff] [blame] | 1128 | unit->getCodeCompletionTUInfo(), |
| 1129 | false); |
Argyrios Kyrtzidis | 5e192a7 | 2012-01-17 02:15:54 +0000 | [diff] [blame] | 1130 | return String; |
Douglas Gregor | 8fa0a80 | 2011-08-04 20:04:59 +0000 | [diff] [blame] | 1131 | } |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1132 | return nullptr; |
Douglas Gregor | 8fa0a80 | 2011-08-04 20:04:59 +0000 | [diff] [blame] | 1133 | } |
Ted Kremenek | 8eece46 | 2012-04-30 19:33:45 +0000 | [diff] [blame] | 1134 | } // end: extern C. |
Ted Kremenek | bbf66ca | 2012-04-30 19:06:49 +0000 | [diff] [blame] | 1135 | |
| 1136 | namespace { |
| 1137 | struct OverridenCursorsPool { |
Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1138 | typedef SmallVector<CXCursor, 2> CursorVec; |
Ted Kremenek | bbf66ca | 2012-04-30 19:06:49 +0000 | [diff] [blame] | 1139 | std::vector<CursorVec*> AllCursors; |
| 1140 | std::vector<CursorVec*> AvailableCursors; |
| 1141 | |
| 1142 | ~OverridenCursorsPool() { |
| 1143 | for (std::vector<CursorVec*>::iterator I = AllCursors.begin(), |
| 1144 | E = AllCursors.end(); I != E; ++I) { |
| 1145 | delete *I; |
| 1146 | } |
| 1147 | } |
| 1148 | }; |
| 1149 | } |
| 1150 | |
| 1151 | void *cxcursor::createOverridenCXCursorsPool() { |
| 1152 | return new OverridenCursorsPool(); |
| 1153 | } |
| 1154 | |
| 1155 | void cxcursor::disposeOverridenCXCursorsPool(void *pool) { |
| 1156 | delete static_cast<OverridenCursorsPool*>(pool); |
| 1157 | } |
Ted Kremenek | 8eece46 | 2012-04-30 19:33:45 +0000 | [diff] [blame] | 1158 | |
| 1159 | extern "C" { |
Ted Kremenek | bbf66ca | 2012-04-30 19:06:49 +0000 | [diff] [blame] | 1160 | void clang_getOverriddenCursors(CXCursor cursor, |
| 1161 | CXCursor **overridden, |
| 1162 | unsigned *num_overridden) { |
| 1163 | if (overridden) |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1164 | *overridden = nullptr; |
Ted Kremenek | bbf66ca | 2012-04-30 19:06:49 +0000 | [diff] [blame] | 1165 | if (num_overridden) |
| 1166 | *num_overridden = 0; |
| 1167 | |
| 1168 | CXTranslationUnit TU = cxcursor::getCursorTU(cursor); |
| 1169 | |
| 1170 | if (!overridden || !num_overridden || !TU) |
| 1171 | return; |
| 1172 | |
| 1173 | if (!clang_isDeclaration(cursor.kind)) |
| 1174 | return; |
| 1175 | |
| 1176 | OverridenCursorsPool &pool = |
| 1177 | *static_cast<OverridenCursorsPool*>(TU->OverridenCursorsPool); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1178 | |
| 1179 | OverridenCursorsPool::CursorVec *Vec = nullptr; |
| 1180 | |
Ted Kremenek | bbf66ca | 2012-04-30 19:06:49 +0000 | [diff] [blame] | 1181 | if (!pool.AvailableCursors.empty()) { |
| 1182 | Vec = pool.AvailableCursors.back(); |
| 1183 | pool.AvailableCursors.pop_back(); |
| 1184 | } |
| 1185 | else { |
| 1186 | Vec = new OverridenCursorsPool::CursorVec(); |
| 1187 | pool.AllCursors.push_back(Vec); |
| 1188 | } |
| 1189 | |
| 1190 | // Clear out the vector, but don't free the memory contents. This |
| 1191 | // reduces malloc() traffic. |
| 1192 | Vec->clear(); |
| 1193 | |
| 1194 | // Use the first entry to contain a back reference to the vector. |
| 1195 | // This is a complete hack. |
| 1196 | CXCursor backRefCursor = MakeCXCursorInvalid(CXCursor_InvalidFile, TU); |
| 1197 | backRefCursor.data[0] = Vec; |
| 1198 | assert(cxcursor::getCursorTU(backRefCursor) == TU); |
| 1199 | Vec->push_back(backRefCursor); |
| 1200 | |
| 1201 | // Get the overriden cursors. |
| 1202 | cxcursor::getOverriddenCursors(cursor, *Vec); |
| 1203 | |
| 1204 | // Did we get any overriden cursors? If not, return Vec to the pool |
| 1205 | // of available cursor vectors. |
| 1206 | if (Vec->size() == 1) { |
| 1207 | pool.AvailableCursors.push_back(Vec); |
| 1208 | return; |
| 1209 | } |
| 1210 | |
| 1211 | // Now tell the caller about the overriden cursors. |
| 1212 | assert(Vec->size() > 1); |
| 1213 | *overridden = &((*Vec)[1]); |
| 1214 | *num_overridden = Vec->size() - 1; |
| 1215 | } |
| 1216 | |
| 1217 | void clang_disposeOverriddenCursors(CXCursor *overridden) { |
| 1218 | if (!overridden) |
| 1219 | return; |
| 1220 | |
| 1221 | // Use pointer arithmetic to get back the first faux entry |
| 1222 | // which has a back-reference to the TU and the vector. |
| 1223 | --overridden; |
| 1224 | OverridenCursorsPool::CursorVec *Vec = |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 1225 | static_cast<OverridenCursorsPool::CursorVec *>( |
| 1226 | const_cast<void *>(overridden->data[0])); |
Ted Kremenek | bbf66ca | 2012-04-30 19:06:49 +0000 | [diff] [blame] | 1227 | CXTranslationUnit TU = getCursorTU(*overridden); |
| 1228 | |
| 1229 | assert(Vec && TU); |
| 1230 | |
| 1231 | OverridenCursorsPool &pool = |
| 1232 | *static_cast<OverridenCursorsPool*>(TU->OverridenCursorsPool); |
| 1233 | |
| 1234 | pool.AvailableCursors.push_back(Vec); |
| 1235 | } |
Argyrios Kyrtzidis | f39a7ae | 2012-07-02 23:54:36 +0000 | [diff] [blame] | 1236 | |
| 1237 | int clang_Cursor_isDynamicCall(CXCursor C) { |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1238 | const Expr *E = nullptr; |
Argyrios Kyrtzidis | f39a7ae | 2012-07-02 23:54:36 +0000 | [diff] [blame] | 1239 | if (clang_isExpression(C.kind)) |
| 1240 | E = getCursorExpr(C); |
| 1241 | if (!E) |
| 1242 | return 0; |
| 1243 | |
| 1244 | if (const ObjCMessageExpr *MsgE = dyn_cast<ObjCMessageExpr>(E)) |
| 1245 | return MsgE->getReceiverKind() == ObjCMessageExpr::Instance; |
| 1246 | |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1247 | const MemberExpr *ME = nullptr; |
Argyrios Kyrtzidis | f39a7ae | 2012-07-02 23:54:36 +0000 | [diff] [blame] | 1248 | if (isa<MemberExpr>(E)) |
| 1249 | ME = cast<MemberExpr>(E); |
| 1250 | else if (const CallExpr *CE = dyn_cast<CallExpr>(E)) |
| 1251 | ME = dyn_cast_or_null<MemberExpr>(CE->getCallee()); |
| 1252 | |
| 1253 | if (ME) { |
| 1254 | if (const CXXMethodDecl * |
| 1255 | MD = dyn_cast_or_null<CXXMethodDecl>(ME->getMemberDecl())) |
| 1256 | return MD->isVirtual() && !ME->hasQualifier(); |
| 1257 | } |
| 1258 | |
| 1259 | return 0; |
| 1260 | } |
| 1261 | |
Argyrios Kyrtzidis | e4a990f | 2012-11-01 02:01:34 +0000 | [diff] [blame] | 1262 | CXType clang_Cursor_getReceiverType(CXCursor C) { |
| 1263 | CXTranslationUnit TU = cxcursor::getCursorTU(C); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1264 | const Expr *E = nullptr; |
Argyrios Kyrtzidis | e4a990f | 2012-11-01 02:01:34 +0000 | [diff] [blame] | 1265 | if (clang_isExpression(C.kind)) |
| 1266 | E = getCursorExpr(C); |
| 1267 | |
| 1268 | if (const ObjCMessageExpr *MsgE = dyn_cast_or_null<ObjCMessageExpr>(E)) |
| 1269 | return cxtype::MakeCXType(MsgE->getReceiverType(), TU); |
| 1270 | |
| 1271 | return cxtype::MakeCXType(QualType(), TU); |
| 1272 | } |
| 1273 | |
Ted Kremenek | eca099b | 2010-12-08 23:43:14 +0000 | [diff] [blame] | 1274 | } // end: extern "C" |