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" |
Douglas Gregor | 7eaa8ae | 2010-01-20 00:23:15 +0000 | [diff] [blame] | 19 | #include "clang/Frontend/ASTUnit.h" |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 20 | #include "clang/AST/Decl.h" |
Douglas Gregor | 6931900 | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 21 | #include "clang/AST/DeclCXX.h" |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 22 | #include "clang/AST/DeclObjC.h" |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 24 | #include "clang/AST/Expr.h" |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 25 | #include "clang/AST/ExprCXX.h" |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 26 | #include "clang/AST/ExprObjC.h" |
Ted Kremenek | 007a7c9 | 2010-11-01 23:26:51 +0000 | [diff] [blame] | 27 | #include "clang-c/Index.h" |
Ted Kremenek | edc8aa6 | 2010-01-16 00:36:30 +0000 | [diff] [blame] | 28 | #include "llvm/Support/ErrorHandling.h" |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 29 | |
| 30 | using namespace clang; |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 31 | using namespace cxcursor; |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 32 | |
Douglas Gregor | 5bfb8c1 | 2010-01-20 23:34:41 +0000 | [diff] [blame] | 33 | CXCursor cxcursor::MakeCXCursorInvalid(CXCursorKind K) { |
| 34 | assert(K >= CXCursor_FirstInvalid && K <= CXCursor_LastInvalid); |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 35 | CXCursor C = { K, 0, { 0, 0, 0 } }; |
Douglas Gregor | 5bfb8c1 | 2010-01-20 23:34:41 +0000 | [diff] [blame] | 36 | return C; |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 37 | } |
| 38 | |
Ted Kremenek | e77f443 | 2010-02-18 03:09:07 +0000 | [diff] [blame] | 39 | static CXCursorKind GetCursorKind(const Attr *A) { |
| 40 | assert(A && "Invalid arguments!"); |
| 41 | switch (A->getKind()) { |
| 42 | default: break; |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 43 | case attr::IBAction: return CXCursor_IBActionAttr; |
| 44 | case attr::IBOutlet: return CXCursor_IBOutletAttr; |
| 45 | case attr::IBOutletCollection: return CXCursor_IBOutletCollectionAttr; |
Argyrios Kyrtzidis | 6639e92 | 2011-09-13 17:39:31 +0000 | [diff] [blame] | 46 | case attr::Final: return CXCursor_CXXFinalAttr; |
| 47 | case attr::Override: return CXCursor_CXXOverrideAttr; |
Erik Verbruggen | 5f1c822 | 2011-10-13 09:41:32 +0000 | [diff] [blame] | 48 | case attr::Annotate: return CXCursor_AnnotateAttr; |
Argyrios Kyrtzidis | 84b7964 | 2011-12-06 22:05:01 +0000 | [diff] [blame] | 49 | case attr::AsmLabel: return CXCursor_AsmLabelAttr; |
Ted Kremenek | e77f443 | 2010-02-18 03:09:07 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | return CXCursor_UnexposedAttr; |
| 53 | } |
| 54 | |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 55 | CXCursor cxcursor::MakeCXCursor(const Attr *A, Decl *Parent, |
| 56 | CXTranslationUnit TU) { |
Ted Kremenek | e77f443 | 2010-02-18 03:09:07 +0000 | [diff] [blame] | 57 | assert(A && Parent && TU && "Invalid arguments!"); |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 58 | CXCursor C = { GetCursorKind(A), 0, { Parent, (void*)A, TU } }; |
Ted Kremenek | e77f443 | 2010-02-18 03:09:07 +0000 | [diff] [blame] | 59 | return C; |
| 60 | } |
| 61 | |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 62 | CXCursor cxcursor::MakeCXCursor(Decl *D, CXTranslationUnit TU, |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 63 | SourceRange RegionOfInterest, |
Ted Kremenek | 007a7c9 | 2010-11-01 23:26:51 +0000 | [diff] [blame] | 64 | bool FirstInDeclGroup) { |
Daniel Dunbar | 54d67ca | 2010-01-25 00:40:30 +0000 | [diff] [blame] | 65 | assert(D && TU && "Invalid arguments!"); |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 66 | |
| 67 | CXCursorKind K = getCursorKindForDecl(D); |
| 68 | |
| 69 | if (K == CXCursor_ObjCClassMethodDecl || |
| 70 | K == CXCursor_ObjCInstanceMethodDecl) { |
| 71 | int SelectorIdIndex = -1; |
| 72 | // Check if cursor points to a selector id. |
| 73 | if (RegionOfInterest.isValid() && |
| 74 | RegionOfInterest.getBegin() == RegionOfInterest.getEnd()) { |
| 75 | SmallVector<SourceLocation, 16> SelLocs; |
| 76 | cast<ObjCMethodDecl>(D)->getSelectorLocs(SelLocs); |
| 77 | SmallVector<SourceLocation, 16>::iterator |
| 78 | I=std::find(SelLocs.begin(), SelLocs.end(),RegionOfInterest.getBegin()); |
| 79 | if (I != SelLocs.end()) |
| 80 | SelectorIdIndex = I - SelLocs.begin(); |
| 81 | } |
| 82 | CXCursor C = { K, SelectorIdIndex, |
| 83 | { D, (void*)(intptr_t) (FirstInDeclGroup ? 1 : 0), TU }}; |
| 84 | return C; |
| 85 | } |
| 86 | |
| 87 | CXCursor C = { K, 0, { D, (void*)(intptr_t) (FirstInDeclGroup ? 1 : 0), TU }}; |
Douglas Gregor | 5bfb8c1 | 2010-01-20 23:34:41 +0000 | [diff] [blame] | 88 | return C; |
Ted Kremenek | edc8aa6 | 2010-01-16 00:36:30 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 91 | CXCursor cxcursor::MakeCXCursor(Stmt *S, Decl *Parent, CXTranslationUnit TU, |
| 92 | SourceRange RegionOfInterest) { |
Daniel Dunbar | 54d67ca | 2010-01-25 00:40:30 +0000 | [diff] [blame] | 93 | assert(S && TU && "Invalid arguments!"); |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 94 | CXCursorKind K = CXCursor_NotImplemented; |
| 95 | |
| 96 | switch (S->getStmtClass()) { |
| 97 | case Stmt::NoStmtClass: |
| 98 | break; |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 99 | |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 100 | case Stmt::CaseStmtClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 101 | K = CXCursor_CaseStmt; |
| 102 | break; |
| 103 | |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 104 | case Stmt::DefaultStmtClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 105 | K = CXCursor_DefaultStmt; |
| 106 | break; |
| 107 | |
| 108 | case Stmt::IfStmtClass: |
| 109 | K = CXCursor_IfStmt; |
| 110 | break; |
| 111 | |
| 112 | case Stmt::SwitchStmtClass: |
| 113 | K = CXCursor_SwitchStmt; |
| 114 | break; |
| 115 | |
| 116 | case Stmt::WhileStmtClass: |
| 117 | K = CXCursor_WhileStmt; |
| 118 | break; |
| 119 | |
| 120 | case Stmt::DoStmtClass: |
| 121 | K = CXCursor_DoStmt; |
| 122 | break; |
| 123 | |
| 124 | case Stmt::ForStmtClass: |
| 125 | K = CXCursor_ForStmt; |
| 126 | break; |
| 127 | |
| 128 | case Stmt::GotoStmtClass: |
| 129 | K = CXCursor_GotoStmt; |
| 130 | break; |
| 131 | |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 132 | case Stmt::IndirectGotoStmtClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 133 | K = CXCursor_IndirectGotoStmt; |
| 134 | break; |
| 135 | |
| 136 | case Stmt::ContinueStmtClass: |
| 137 | K = CXCursor_ContinueStmt; |
| 138 | break; |
| 139 | |
| 140 | case Stmt::BreakStmtClass: |
| 141 | K = CXCursor_BreakStmt; |
| 142 | break; |
| 143 | |
| 144 | case Stmt::ReturnStmtClass: |
| 145 | K = CXCursor_ReturnStmt; |
| 146 | break; |
| 147 | |
| 148 | case Stmt::AsmStmtClass: |
| 149 | K = CXCursor_AsmStmt; |
| 150 | break; |
| 151 | |
| 152 | case Stmt::ObjCAtTryStmtClass: |
| 153 | K = CXCursor_ObjCAtTryStmt; |
| 154 | break; |
| 155 | |
| 156 | case Stmt::ObjCAtCatchStmtClass: |
| 157 | K = CXCursor_ObjCAtCatchStmt; |
| 158 | break; |
| 159 | |
| 160 | case Stmt::ObjCAtFinallyStmtClass: |
| 161 | K = CXCursor_ObjCAtFinallyStmt; |
| 162 | break; |
| 163 | |
| 164 | case Stmt::ObjCAtThrowStmtClass: |
| 165 | K = CXCursor_ObjCAtThrowStmt; |
| 166 | break; |
| 167 | |
| 168 | case Stmt::ObjCAtSynchronizedStmtClass: |
| 169 | K = CXCursor_ObjCAtSynchronizedStmt; |
| 170 | break; |
| 171 | |
| 172 | case Stmt::ObjCAutoreleasePoolStmtClass: |
| 173 | K = CXCursor_ObjCAutoreleasePoolStmt; |
| 174 | break; |
| 175 | |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 176 | case Stmt::ObjCForCollectionStmtClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 177 | K = CXCursor_ObjCForCollectionStmt; |
| 178 | break; |
| 179 | |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 180 | case Stmt::CXXCatchStmtClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 181 | K = CXCursor_CXXCatchStmt; |
| 182 | break; |
| 183 | |
| 184 | case Stmt::CXXTryStmtClass: |
| 185 | K = CXCursor_CXXTryStmt; |
| 186 | break; |
| 187 | |
| 188 | case Stmt::CXXForRangeStmtClass: |
| 189 | K = CXCursor_CXXForRangeStmt; |
| 190 | break; |
| 191 | |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 192 | case Stmt::SEHTryStmtClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 193 | K = CXCursor_SEHTryStmt; |
| 194 | break; |
| 195 | |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 196 | case Stmt::SEHExceptStmtClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 197 | K = CXCursor_SEHExceptStmt; |
| 198 | break; |
| 199 | |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 200 | case Stmt::SEHFinallyStmtClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 201 | K = CXCursor_SEHFinallyStmt; |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 202 | break; |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 203 | |
John Wiegley | 21ff2e5 | 2011-04-28 00:16:57 +0000 | [diff] [blame] | 204 | case Stmt::ArrayTypeTraitExprClass: |
Tanya Lattner | 61eee0c | 2011-06-04 00:47:47 +0000 | [diff] [blame] | 205 | case Stmt::AsTypeExprClass: |
Eli Friedman | 276b061 | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 206 | case Stmt::AtomicExprClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 207 | case Stmt::BinaryConditionalOperatorClass: |
| 208 | case Stmt::BinaryTypeTraitExprClass: |
| 209 | case Stmt::CXXBindTemporaryExprClass: |
| 210 | case Stmt::CXXDefaultArgExprClass: |
| 211 | case Stmt::CXXScalarValueInitExprClass: |
| 212 | case Stmt::CXXUuidofExprClass: |
| 213 | case Stmt::ChooseExprClass: |
| 214 | case Stmt::DesignatedInitExprClass: |
| 215 | case Stmt::ExprWithCleanupsClass: |
| 216 | case Stmt::ExpressionTraitExprClass: |
| 217 | case Stmt::ExtVectorElementExprClass: |
| 218 | case Stmt::ImplicitCastExprClass: |
| 219 | case Stmt::ImplicitValueInitExprClass: |
| 220 | case Stmt::MaterializeTemporaryExprClass: |
| 221 | case Stmt::ObjCIndirectCopyRestoreExprClass: |
| 222 | case Stmt::OffsetOfExprClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 223 | case Stmt::ParenListExprClass: |
| 224 | case Stmt::PredefinedExprClass: |
| 225 | case Stmt::ShuffleVectorExprClass: |
| 226 | case Stmt::UnaryExprOrTypeTraitExprClass: |
| 227 | case Stmt::UnaryTypeTraitExprClass: |
| 228 | case Stmt::VAArgExprClass: |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 229 | K = CXCursor_UnexposedExpr; |
| 230 | break; |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 231 | |
John McCall | 4b9c2d2 | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 232 | case Stmt::OpaqueValueExprClass: |
| 233 | if (Expr *Src = cast<OpaqueValueExpr>(S)->getSourceExpr()) |
| 234 | return MakeCXCursor(Src, Parent, TU, RegionOfInterest); |
| 235 | K = CXCursor_UnexposedExpr; |
| 236 | break; |
| 237 | |
| 238 | case Stmt::PseudoObjectExprClass: |
| 239 | return MakeCXCursor(cast<PseudoObjectExpr>(S)->getSyntacticForm(), |
| 240 | Parent, TU, RegionOfInterest); |
| 241 | |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 242 | case Stmt::CompoundStmtClass: |
| 243 | K = CXCursor_CompoundStmt; |
| 244 | break; |
Douglas Gregor | 36897b0 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 245 | |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 246 | case Stmt::NullStmtClass: |
| 247 | K = CXCursor_NullStmt; |
| 248 | break; |
| 249 | |
| 250 | case Stmt::LabelStmtClass: |
| 251 | K = CXCursor_LabelStmt; |
| 252 | break; |
| 253 | |
| 254 | case Stmt::DeclStmtClass: |
| 255 | K = CXCursor_DeclStmt; |
| 256 | break; |
| 257 | |
| 258 | case Stmt::IntegerLiteralClass: |
| 259 | K = CXCursor_IntegerLiteral; |
| 260 | break; |
| 261 | |
| 262 | case Stmt::FloatingLiteralClass: |
| 263 | K = CXCursor_FloatingLiteral; |
| 264 | break; |
| 265 | |
| 266 | case Stmt::ImaginaryLiteralClass: |
| 267 | K = CXCursor_ImaginaryLiteral; |
| 268 | break; |
| 269 | |
| 270 | case Stmt::StringLiteralClass: |
| 271 | K = CXCursor_StringLiteral; |
| 272 | break; |
| 273 | |
| 274 | case Stmt::CharacterLiteralClass: |
| 275 | K = CXCursor_CharacterLiteral; |
| 276 | break; |
| 277 | |
| 278 | case Stmt::ParenExprClass: |
| 279 | K = CXCursor_ParenExpr; |
| 280 | break; |
| 281 | |
| 282 | case Stmt::UnaryOperatorClass: |
| 283 | K = CXCursor_UnaryOperator; |
| 284 | break; |
| 285 | |
| 286 | case Stmt::CXXNoexceptExprClass: |
| 287 | K = CXCursor_UnaryExpr; |
| 288 | break; |
| 289 | |
| 290 | case Stmt::ArraySubscriptExprClass: |
| 291 | K = CXCursor_ArraySubscriptExpr; |
| 292 | break; |
| 293 | |
| 294 | case Stmt::BinaryOperatorClass: |
| 295 | K = CXCursor_BinaryOperator; |
| 296 | break; |
| 297 | |
| 298 | case Stmt::CompoundAssignOperatorClass: |
| 299 | K = CXCursor_CompoundAssignOperator; |
| 300 | break; |
| 301 | |
| 302 | case Stmt::ConditionalOperatorClass: |
| 303 | K = CXCursor_ConditionalOperator; |
| 304 | break; |
| 305 | |
| 306 | case Stmt::CStyleCastExprClass: |
| 307 | K = CXCursor_CStyleCastExpr; |
| 308 | break; |
| 309 | |
| 310 | case Stmt::CompoundLiteralExprClass: |
| 311 | K = CXCursor_CompoundLiteralExpr; |
| 312 | break; |
| 313 | |
| 314 | case Stmt::InitListExprClass: |
| 315 | K = CXCursor_InitListExpr; |
| 316 | break; |
| 317 | |
| 318 | case Stmt::AddrLabelExprClass: |
| 319 | K = CXCursor_AddrLabelExpr; |
| 320 | break; |
| 321 | |
| 322 | case Stmt::StmtExprClass: |
| 323 | K = CXCursor_StmtExpr; |
| 324 | break; |
| 325 | |
| 326 | case Stmt::GenericSelectionExprClass: |
| 327 | K = CXCursor_GenericSelectionExpr; |
| 328 | break; |
| 329 | |
| 330 | case Stmt::GNUNullExprClass: |
| 331 | K = CXCursor_GNUNullExpr; |
| 332 | break; |
| 333 | |
| 334 | case Stmt::CXXStaticCastExprClass: |
| 335 | K = CXCursor_CXXStaticCastExpr; |
| 336 | break; |
| 337 | |
| 338 | case Stmt::CXXDynamicCastExprClass: |
| 339 | K = CXCursor_CXXDynamicCastExpr; |
| 340 | break; |
| 341 | |
| 342 | case Stmt::CXXReinterpretCastExprClass: |
| 343 | K = CXCursor_CXXReinterpretCastExpr; |
| 344 | break; |
| 345 | |
| 346 | case Stmt::CXXConstCastExprClass: |
| 347 | K = CXCursor_CXXConstCastExpr; |
| 348 | break; |
| 349 | |
| 350 | case Stmt::CXXFunctionalCastExprClass: |
| 351 | K = CXCursor_CXXFunctionalCastExpr; |
| 352 | break; |
| 353 | |
| 354 | case Stmt::CXXTypeidExprClass: |
| 355 | K = CXCursor_CXXTypeidExpr; |
| 356 | break; |
| 357 | |
| 358 | case Stmt::CXXBoolLiteralExprClass: |
| 359 | K = CXCursor_CXXBoolLiteralExpr; |
| 360 | break; |
| 361 | |
| 362 | case Stmt::CXXNullPtrLiteralExprClass: |
| 363 | K = CXCursor_CXXNullPtrLiteralExpr; |
| 364 | break; |
| 365 | |
| 366 | case Stmt::CXXThisExprClass: |
| 367 | K = CXCursor_CXXThisExpr; |
| 368 | break; |
| 369 | |
| 370 | case Stmt::CXXThrowExprClass: |
| 371 | K = CXCursor_CXXThrowExpr; |
| 372 | break; |
| 373 | |
| 374 | case Stmt::CXXNewExprClass: |
| 375 | K = CXCursor_CXXNewExpr; |
| 376 | break; |
| 377 | |
| 378 | case Stmt::CXXDeleteExprClass: |
| 379 | K = CXCursor_CXXDeleteExpr; |
| 380 | break; |
| 381 | |
| 382 | case Stmt::ObjCStringLiteralClass: |
| 383 | K = CXCursor_ObjCStringLiteral; |
| 384 | break; |
| 385 | |
| 386 | case Stmt::ObjCEncodeExprClass: |
| 387 | K = CXCursor_ObjCEncodeExpr; |
| 388 | break; |
| 389 | |
| 390 | case Stmt::ObjCSelectorExprClass: |
| 391 | K = CXCursor_ObjCSelectorExpr; |
| 392 | break; |
| 393 | |
| 394 | case Stmt::ObjCProtocolExprClass: |
| 395 | K = CXCursor_ObjCProtocolExpr; |
| 396 | break; |
| 397 | |
| 398 | case Stmt::ObjCBridgedCastExprClass: |
| 399 | K = CXCursor_ObjCBridgedCastExpr; |
| 400 | break; |
| 401 | |
| 402 | case Stmt::BlockExprClass: |
| 403 | K = CXCursor_BlockExpr; |
| 404 | break; |
| 405 | |
| 406 | case Stmt::PackExpansionExprClass: |
| 407 | K = CXCursor_PackExpansionExpr; |
| 408 | break; |
| 409 | |
| 410 | case Stmt::SizeOfPackExprClass: |
| 411 | K = CXCursor_SizeOfPackExpr; |
| 412 | break; |
| 413 | |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 414 | case Stmt::BlockDeclRefExprClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 415 | case Stmt::DeclRefExprClass: |
| 416 | case Stmt::DependentScopeDeclRefExprClass: |
John McCall | 91a5755 | 2011-07-15 05:09:51 +0000 | [diff] [blame] | 417 | case Stmt::SubstNonTypeTemplateParmExprClass: |
Douglas Gregor | c7793c7 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 418 | case Stmt::SubstNonTypeTemplateParmPackExprClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 419 | case Stmt::UnresolvedLookupExprClass: |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 420 | K = CXCursor_DeclRefExpr; |
| 421 | break; |
| 422 | |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 423 | case Stmt::CXXDependentScopeMemberExprClass: |
| 424 | case Stmt::CXXPseudoDestructorExprClass: |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 425 | case Stmt::MemberExprClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 426 | case Stmt::ObjCIsaExprClass: |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 427 | case Stmt::ObjCIvarRefExprClass: |
| 428 | case Stmt::ObjCPropertyRefExprClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 429 | case Stmt::UnresolvedMemberExprClass: |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 430 | K = CXCursor_MemberRefExpr; |
| 431 | break; |
| 432 | |
| 433 | case Stmt::CallExprClass: |
| 434 | case Stmt::CXXOperatorCallExprClass: |
| 435 | case Stmt::CXXMemberCallExprClass: |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 436 | case Stmt::CUDAKernelCallExprClass: |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 437 | case Stmt::CXXConstructExprClass: |
| 438 | case Stmt::CXXTemporaryObjectExprClass: |
Douglas Gregor | 42b2984 | 2011-10-05 19:00:14 +0000 | [diff] [blame] | 439 | case Stmt::CXXUnresolvedConstructExprClass: |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 440 | K = CXCursor_CallExpr; |
| 441 | break; |
| 442 | |
Douglas Gregor | 011d8b9 | 2012-02-15 00:54:55 +0000 | [diff] [blame^] | 443 | case Stmt::LambdaExprClass: |
| 444 | K = CXCursor_LambdaExpr; |
| 445 | break; |
| 446 | |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 447 | case Stmt::ObjCMessageExprClass: { |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 448 | K = CXCursor_ObjCMessageExpr; |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 449 | int SelectorIdIndex = -1; |
| 450 | // Check if cursor points to a selector id. |
| 451 | if (RegionOfInterest.isValid() && |
| 452 | RegionOfInterest.getBegin() == RegionOfInterest.getEnd()) { |
| 453 | SmallVector<SourceLocation, 16> SelLocs; |
| 454 | cast<ObjCMessageExpr>(S)->getSelectorLocs(SelLocs); |
| 455 | SmallVector<SourceLocation, 16>::iterator |
| 456 | I=std::find(SelLocs.begin(), SelLocs.end(),RegionOfInterest.getBegin()); |
| 457 | if (I != SelLocs.end()) |
| 458 | SelectorIdIndex = I - SelLocs.begin(); |
| 459 | } |
| 460 | CXCursor C = { K, 0, { Parent, S, TU } }; |
| 461 | return getSelectorIdentifierCursor(SelectorIdIndex, C); |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 462 | } |
Douglas Gregor | ba0513d | 2011-10-25 01:33:02 +0000 | [diff] [blame] | 463 | |
| 464 | case Stmt::MSDependentExistsStmtClass: |
| 465 | K = CXCursor_UnexposedStmt; |
| 466 | break; |
| 467 | } |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 468 | |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 469 | CXCursor C = { K, 0, { Parent, S, TU } }; |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 470 | return C; |
| 471 | } |
| 472 | |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 473 | CXCursor cxcursor::MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super, |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 474 | SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 475 | CXTranslationUnit TU) { |
Daniel Dunbar | 54d67ca | 2010-01-25 00:40:30 +0000 | [diff] [blame] | 476 | assert(Super && TU && "Invalid arguments!"); |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 477 | void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 478 | CXCursor C = { CXCursor_ObjCSuperClassRef, 0, { Super, RawLoc, TU } }; |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 479 | return C; |
| 480 | } |
| 481 | |
| 482 | std::pair<ObjCInterfaceDecl *, SourceLocation> |
| 483 | cxcursor::getCursorObjCSuperClassRef(CXCursor C) { |
| 484 | assert(C.kind == CXCursor_ObjCSuperClassRef); |
| 485 | return std::make_pair(static_cast<ObjCInterfaceDecl *>(C.data[0]), |
| 486 | SourceLocation::getFromRawEncoding( |
| 487 | reinterpret_cast<uintptr_t>(C.data[1]))); |
| 488 | } |
| 489 | |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 490 | CXCursor cxcursor::MakeCursorObjCProtocolRef(const ObjCProtocolDecl *Proto, |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 491 | SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 492 | CXTranslationUnit TU) { |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 493 | assert(Proto && TU && "Invalid arguments!"); |
Douglas Gregor | 78db0cd | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 494 | void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 495 | CXCursor C = { CXCursor_ObjCProtocolRef, 0, { (void*)Proto, RawLoc, TU } }; |
Douglas Gregor | 78db0cd | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 496 | return C; |
| 497 | } |
| 498 | |
| 499 | std::pair<ObjCProtocolDecl *, SourceLocation> |
| 500 | cxcursor::getCursorObjCProtocolRef(CXCursor C) { |
| 501 | assert(C.kind == CXCursor_ObjCProtocolRef); |
| 502 | return std::make_pair(static_cast<ObjCProtocolDecl *>(C.data[0]), |
| 503 | SourceLocation::getFromRawEncoding( |
| 504 | reinterpret_cast<uintptr_t>(C.data[1]))); |
| 505 | } |
| 506 | |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 507 | CXCursor cxcursor::MakeCursorObjCClassRef(const ObjCInterfaceDecl *Class, |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 508 | SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 509 | CXTranslationUnit TU) { |
Ted Kremenek | ebfa339 | 2010-03-19 20:39:03 +0000 | [diff] [blame] | 510 | // 'Class' can be null for invalid code. |
| 511 | if (!Class) |
| 512 | return MakeCXCursorInvalid(CXCursor_InvalidCode); |
| 513 | assert(TU && "Invalid arguments!"); |
Douglas Gregor | 1adb082 | 2010-01-16 17:14:40 +0000 | [diff] [blame] | 514 | void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 515 | CXCursor C = { CXCursor_ObjCClassRef, 0, { (void*)Class, RawLoc, TU } }; |
Douglas Gregor | 1adb082 | 2010-01-16 17:14:40 +0000 | [diff] [blame] | 516 | return C; |
| 517 | } |
| 518 | |
| 519 | std::pair<ObjCInterfaceDecl *, SourceLocation> |
| 520 | cxcursor::getCursorObjCClassRef(CXCursor C) { |
| 521 | assert(C.kind == CXCursor_ObjCClassRef); |
| 522 | return std::make_pair(static_cast<ObjCInterfaceDecl *>(C.data[0]), |
| 523 | SourceLocation::getFromRawEncoding( |
| 524 | reinterpret_cast<uintptr_t>(C.data[1]))); |
| 525 | } |
| 526 | |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 527 | CXCursor cxcursor::MakeCursorTypeRef(const TypeDecl *Type, SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 528 | CXTranslationUnit TU) { |
Daniel Dunbar | 54d67ca | 2010-01-25 00:40:30 +0000 | [diff] [blame] | 529 | assert(Type && TU && "Invalid arguments!"); |
Douglas Gregor | 7d0d40e | 2010-01-21 16:28:34 +0000 | [diff] [blame] | 530 | void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 531 | CXCursor C = { CXCursor_TypeRef, 0, { (void*)Type, RawLoc, TU } }; |
Douglas Gregor | 7d0d40e | 2010-01-21 16:28:34 +0000 | [diff] [blame] | 532 | return C; |
| 533 | } |
| 534 | |
| 535 | std::pair<TypeDecl *, SourceLocation> |
| 536 | cxcursor::getCursorTypeRef(CXCursor C) { |
| 537 | assert(C.kind == CXCursor_TypeRef); |
| 538 | return std::make_pair(static_cast<TypeDecl *>(C.data[0]), |
| 539 | SourceLocation::getFromRawEncoding( |
| 540 | reinterpret_cast<uintptr_t>(C.data[1]))); |
| 541 | } |
| 542 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 543 | CXCursor cxcursor::MakeCursorTemplateRef(const TemplateDecl *Template, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 544 | SourceLocation Loc, |
| 545 | CXTranslationUnit TU) { |
Douglas Gregor | 0b36e61 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 546 | assert(Template && TU && "Invalid arguments!"); |
| 547 | void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 548 | CXCursor C = { CXCursor_TemplateRef, 0, { (void*)Template, RawLoc, TU } }; |
Douglas Gregor | 0b36e61 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 549 | return C; |
| 550 | } |
| 551 | |
| 552 | std::pair<TemplateDecl *, SourceLocation> |
| 553 | cxcursor::getCursorTemplateRef(CXCursor C) { |
| 554 | assert(C.kind == CXCursor_TemplateRef); |
| 555 | return std::make_pair(static_cast<TemplateDecl *>(C.data[0]), |
| 556 | SourceLocation::getFromRawEncoding( |
| 557 | reinterpret_cast<uintptr_t>(C.data[1]))); |
| 558 | } |
| 559 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 560 | CXCursor cxcursor::MakeCursorNamespaceRef(const NamedDecl *NS, |
| 561 | SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 562 | CXTranslationUnit TU) { |
Douglas Gregor | 6931900 | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 563 | |
| 564 | assert(NS && (isa<NamespaceDecl>(NS) || isa<NamespaceAliasDecl>(NS)) && TU && |
| 565 | "Invalid arguments!"); |
| 566 | void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 567 | CXCursor C = { CXCursor_NamespaceRef, 0, { (void*)NS, RawLoc, TU } }; |
Douglas Gregor | 6931900 | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 568 | return C; |
| 569 | } |
| 570 | |
| 571 | std::pair<NamedDecl *, SourceLocation> |
| 572 | cxcursor::getCursorNamespaceRef(CXCursor C) { |
| 573 | assert(C.kind == CXCursor_NamespaceRef); |
| 574 | return std::make_pair(static_cast<NamedDecl *>(C.data[0]), |
| 575 | SourceLocation::getFromRawEncoding( |
| 576 | reinterpret_cast<uintptr_t>(C.data[1]))); |
| 577 | } |
| 578 | |
Douglas Gregor | 011d8b9 | 2012-02-15 00:54:55 +0000 | [diff] [blame^] | 579 | CXCursor cxcursor::MakeCursorVariableRef(const VarDecl *Var, SourceLocation Loc, |
| 580 | CXTranslationUnit TU) { |
| 581 | |
| 582 | assert(Var && TU && "Invalid arguments!"); |
| 583 | void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); |
| 584 | CXCursor C = { CXCursor_VariableRef, 0, { (void*)Var, RawLoc, TU } }; |
| 585 | return C; |
| 586 | } |
| 587 | |
| 588 | std::pair<VarDecl *, SourceLocation> |
| 589 | cxcursor::getCursorVariableRef(CXCursor C) { |
| 590 | assert(C.kind == CXCursor_VariableRef); |
| 591 | return std::make_pair(static_cast<VarDecl *>(C.data[0]), |
| 592 | SourceLocation::getFromRawEncoding( |
| 593 | reinterpret_cast<uintptr_t>(C.data[1]))); |
| 594 | } |
| 595 | |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 596 | CXCursor cxcursor::MakeCursorMemberRef(const FieldDecl *Field, SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 597 | CXTranslationUnit TU) { |
Douglas Gregor | a67e03f | 2010-09-09 21:42:20 +0000 | [diff] [blame] | 598 | |
| 599 | assert(Field && TU && "Invalid arguments!"); |
| 600 | void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 601 | CXCursor C = { CXCursor_MemberRef, 0, { (void*)Field, RawLoc, TU } }; |
Douglas Gregor | a67e03f | 2010-09-09 21:42:20 +0000 | [diff] [blame] | 602 | return C; |
| 603 | } |
| 604 | |
| 605 | std::pair<FieldDecl *, SourceLocation> |
| 606 | cxcursor::getCursorMemberRef(CXCursor C) { |
| 607 | assert(C.kind == CXCursor_MemberRef); |
| 608 | return std::make_pair(static_cast<FieldDecl *>(C.data[0]), |
| 609 | SourceLocation::getFromRawEncoding( |
| 610 | reinterpret_cast<uintptr_t>(C.data[1]))); |
| 611 | } |
| 612 | |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 613 | CXCursor cxcursor::MakeCursorCXXBaseSpecifier(const CXXBaseSpecifier *B, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 614 | CXTranslationUnit TU){ |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 615 | CXCursor C = { CXCursor_CXXBaseSpecifier, 0, { (void*)B, 0, TU } }; |
Ted Kremenek | 3064ef9 | 2010-08-27 21:34:58 +0000 | [diff] [blame] | 616 | return C; |
| 617 | } |
| 618 | |
| 619 | CXXBaseSpecifier *cxcursor::getCursorCXXBaseSpecifier(CXCursor C) { |
| 620 | assert(C.kind == CXCursor_CXXBaseSpecifier); |
| 621 | return static_cast<CXXBaseSpecifier*>(C.data[0]); |
| 622 | } |
| 623 | |
Douglas Gregor | 9f1e3ff | 2010-03-18 00:42:48 +0000 | [diff] [blame] | 624 | CXCursor cxcursor::MakePreprocessingDirectiveCursor(SourceRange Range, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 625 | CXTranslationUnit TU) { |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 626 | CXCursor C = { CXCursor_PreprocessingDirective, 0, |
Douglas Gregor | 9f1e3ff | 2010-03-18 00:42:48 +0000 | [diff] [blame] | 627 | { reinterpret_cast<void *>(Range.getBegin().getRawEncoding()), |
| 628 | reinterpret_cast<void *>(Range.getEnd().getRawEncoding()), |
| 629 | TU } |
| 630 | }; |
| 631 | return C; |
| 632 | } |
| 633 | |
| 634 | SourceRange cxcursor::getCursorPreprocessingDirective(CXCursor C) { |
| 635 | assert(C.kind == CXCursor_PreprocessingDirective); |
Argyrios Kyrtzidis | ee0f84f | 2011-09-26 08:01:41 +0000 | [diff] [blame] | 636 | SourceRange Range = SourceRange(SourceLocation::getFromRawEncoding( |
Douglas Gregor | 9f1e3ff | 2010-03-18 00:42:48 +0000 | [diff] [blame] | 637 | reinterpret_cast<uintptr_t> (C.data[0])), |
| 638 | SourceLocation::getFromRawEncoding( |
| 639 | reinterpret_cast<uintptr_t> (C.data[1]))); |
Argyrios Kyrtzidis | ee0f84f | 2011-09-26 08:01:41 +0000 | [diff] [blame] | 640 | ASTUnit *TU = getCursorASTUnit(C); |
| 641 | return TU->mapRangeFromPreamble(Range); |
Douglas Gregor | 9f1e3ff | 2010-03-18 00:42:48 +0000 | [diff] [blame] | 642 | } |
| 643 | |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 644 | CXCursor cxcursor::MakeMacroDefinitionCursor(MacroDefinition *MI, |
| 645 | CXTranslationUnit TU) { |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 646 | CXCursor C = { CXCursor_MacroDefinition, 0, { MI, 0, TU } }; |
Douglas Gregor | 572feb2 | 2010-03-18 18:04:21 +0000 | [diff] [blame] | 647 | return C; |
| 648 | } |
| 649 | |
| 650 | MacroDefinition *cxcursor::getCursorMacroDefinition(CXCursor C) { |
| 651 | assert(C.kind == CXCursor_MacroDefinition); |
| 652 | return static_cast<MacroDefinition *>(C.data[0]); |
| 653 | } |
| 654 | |
Chandler Carruth | 9e5bb85 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 655 | CXCursor cxcursor::MakeMacroExpansionCursor(MacroExpansion *MI, |
| 656 | CXTranslationUnit TU) { |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 657 | CXCursor C = { CXCursor_MacroExpansion, 0, { MI, 0, TU } }; |
Douglas Gregor | 4807231 | 2010-03-18 15:23:44 +0000 | [diff] [blame] | 658 | return C; |
| 659 | } |
| 660 | |
Chandler Carruth | 9e5bb85 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 661 | MacroExpansion *cxcursor::getCursorMacroExpansion(CXCursor C) { |
Chandler Carruth | 9b2a0ac | 2011-07-14 08:41:15 +0000 | [diff] [blame] | 662 | assert(C.kind == CXCursor_MacroExpansion); |
Chandler Carruth | 9e5bb85 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 663 | return static_cast<MacroExpansion *>(C.data[0]); |
Douglas Gregor | 4807231 | 2010-03-18 15:23:44 +0000 | [diff] [blame] | 664 | } |
| 665 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 666 | CXCursor cxcursor::MakeInclusionDirectiveCursor(InclusionDirective *ID, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 667 | CXTranslationUnit TU) { |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 668 | CXCursor C = { CXCursor_InclusionDirective, 0, { ID, 0, TU } }; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 669 | return C; |
| 670 | } |
| 671 | |
| 672 | InclusionDirective *cxcursor::getCursorInclusionDirective(CXCursor C) { |
| 673 | assert(C.kind == CXCursor_InclusionDirective); |
| 674 | return static_cast<InclusionDirective *>(C.data[0]); |
| 675 | } |
| 676 | |
Douglas Gregor | 36897b0 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 677 | CXCursor cxcursor::MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 678 | CXTranslationUnit TU) { |
Douglas Gregor | 36897b0 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 679 | |
| 680 | assert(Label && TU && "Invalid arguments!"); |
| 681 | void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 682 | CXCursor C = { CXCursor_LabelRef, 0, { Label, RawLoc, TU } }; |
Douglas Gregor | 36897b0 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 683 | return C; |
| 684 | } |
| 685 | |
| 686 | std::pair<LabelStmt*, SourceLocation> |
| 687 | cxcursor::getCursorLabelRef(CXCursor C) { |
| 688 | assert(C.kind == CXCursor_LabelRef); |
| 689 | return std::make_pair(static_cast<LabelStmt *>(C.data[0]), |
| 690 | SourceLocation::getFromRawEncoding( |
| 691 | reinterpret_cast<uintptr_t>(C.data[1]))); |
| 692 | } |
| 693 | |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 694 | CXCursor cxcursor::MakeCursorOverloadedDeclRef(OverloadExpr *E, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 695 | CXTranslationUnit TU) { |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 696 | assert(E && TU && "Invalid arguments!"); |
| 697 | OverloadedDeclRefStorage Storage(E); |
| 698 | void *RawLoc = reinterpret_cast<void *>(E->getNameLoc().getRawEncoding()); |
| 699 | CXCursor C = { |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 700 | CXCursor_OverloadedDeclRef, 0, |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 701 | { Storage.getOpaqueValue(), RawLoc, TU } |
| 702 | }; |
| 703 | return C; |
| 704 | } |
| 705 | |
| 706 | CXCursor cxcursor::MakeCursorOverloadedDeclRef(Decl *D, |
| 707 | SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 708 | CXTranslationUnit TU) { |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 709 | assert(D && TU && "Invalid arguments!"); |
| 710 | void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); |
| 711 | OverloadedDeclRefStorage Storage(D); |
| 712 | CXCursor C = { |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 713 | CXCursor_OverloadedDeclRef, 0, |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 714 | { Storage.getOpaqueValue(), RawLoc, TU } |
| 715 | }; |
| 716 | return C; |
| 717 | } |
| 718 | |
| 719 | CXCursor cxcursor::MakeCursorOverloadedDeclRef(TemplateName Name, |
| 720 | SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 721 | CXTranslationUnit TU) { |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 722 | assert(Name.getAsOverloadedTemplate() && TU && "Invalid arguments!"); |
| 723 | void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); |
| 724 | OverloadedDeclRefStorage Storage(Name.getAsOverloadedTemplate()); |
| 725 | CXCursor C = { |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 726 | CXCursor_OverloadedDeclRef, 0, |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 727 | { Storage.getOpaqueValue(), RawLoc, TU } |
| 728 | }; |
| 729 | return C; |
| 730 | } |
| 731 | |
| 732 | std::pair<cxcursor::OverloadedDeclRefStorage, SourceLocation> |
| 733 | cxcursor::getCursorOverloadedDeclRef(CXCursor C) { |
| 734 | assert(C.kind == CXCursor_OverloadedDeclRef); |
| 735 | return std::make_pair(OverloadedDeclRefStorage::getFromOpaqueValue(C.data[0]), |
| 736 | SourceLocation::getFromRawEncoding( |
| 737 | reinterpret_cast<uintptr_t>(C.data[1]))); |
| 738 | } |
| 739 | |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 740 | Decl *cxcursor::getCursorDecl(CXCursor Cursor) { |
| 741 | return (Decl *)Cursor.data[0]; |
| 742 | } |
| 743 | |
| 744 | Expr *cxcursor::getCursorExpr(CXCursor Cursor) { |
| 745 | return dyn_cast_or_null<Expr>(getCursorStmt(Cursor)); |
| 746 | } |
| 747 | |
| 748 | Stmt *cxcursor::getCursorStmt(CXCursor Cursor) { |
Douglas Gregor | 78db0cd | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 749 | if (Cursor.kind == CXCursor_ObjCSuperClassRef || |
Douglas Gregor | 1adb082 | 2010-01-16 17:14:40 +0000 | [diff] [blame] | 750 | Cursor.kind == CXCursor_ObjCProtocolRef || |
| 751 | Cursor.kind == CXCursor_ObjCClassRef) |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 752 | return 0; |
| 753 | |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 754 | return (Stmt *)Cursor.data[1]; |
| 755 | } |
| 756 | |
Ted Kremenek | 95f3355 | 2010-08-26 01:42:22 +0000 | [diff] [blame] | 757 | Attr *cxcursor::getCursorAttr(CXCursor Cursor) { |
| 758 | return (Attr *)Cursor.data[1]; |
| 759 | } |
| 760 | |
Argyrios Kyrtzidis | 8ccac3d | 2011-06-29 22:20:07 +0000 | [diff] [blame] | 761 | Decl *cxcursor::getCursorParentDecl(CXCursor Cursor) { |
| 762 | return (Decl *)Cursor.data[0]; |
| 763 | } |
| 764 | |
Douglas Gregor | f46034a | 2010-01-18 23:41:10 +0000 | [diff] [blame] | 765 | ASTContext &cxcursor::getCursorContext(CXCursor Cursor) { |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 766 | return getCursorASTUnit(Cursor)->getASTContext(); |
| 767 | } |
Douglas Gregor | f46034a | 2010-01-18 23:41:10 +0000 | [diff] [blame] | 768 | |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 769 | ASTUnit *cxcursor::getCursorASTUnit(CXCursor Cursor) { |
Argyrios Kyrtzidis | 4451746 | 2011-12-09 00:17:49 +0000 | [diff] [blame] | 770 | CXTranslationUnit TU = static_cast<CXTranslationUnit>(Cursor.data[2]); |
| 771 | if (!TU) |
| 772 | return 0; |
| 773 | return static_cast<ASTUnit *>(TU->TUData); |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | CXTranslationUnit cxcursor::getCursorTU(CXCursor Cursor) { |
| 777 | return static_cast<CXTranslationUnit>(Cursor.data[2]); |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 778 | } |
| 779 | |
Argyrios Kyrtzidis | b11be04 | 2011-10-06 07:00:46 +0000 | [diff] [blame] | 780 | static void CollectOverriddenMethods(CXTranslationUnit TU, |
| 781 | DeclContext *Ctx, |
| 782 | ObjCMethodDecl *Method, |
| 783 | SmallVectorImpl<CXCursor> &Methods) { |
| 784 | if (!Ctx) |
| 785 | return; |
| 786 | |
| 787 | // If we have a class or category implementation, jump straight to the |
| 788 | // interface. |
| 789 | if (ObjCImplDecl *Impl = dyn_cast<ObjCImplDecl>(Ctx)) |
| 790 | return CollectOverriddenMethods(TU, Impl->getClassInterface(), |
| 791 | Method, Methods); |
| 792 | |
| 793 | ObjCContainerDecl *Container = dyn_cast<ObjCContainerDecl>(Ctx); |
| 794 | if (!Container) |
| 795 | return; |
| 796 | |
| 797 | // Check whether we have a matching method at this level. |
| 798 | if (ObjCMethodDecl *Overridden = Container->getMethod(Method->getSelector(), |
| 799 | Method->isInstanceMethod())) |
| 800 | if (Method != Overridden) { |
| 801 | // We found an override at this level; there is no need to look |
| 802 | // into other protocols or categories. |
| 803 | Methods.push_back(MakeCXCursor(Overridden, TU)); |
| 804 | return; |
| 805 | } |
| 806 | |
| 807 | if (ObjCProtocolDecl *Protocol = dyn_cast<ObjCProtocolDecl>(Container)) { |
| 808 | for (ObjCProtocolDecl::protocol_iterator P = Protocol->protocol_begin(), |
| 809 | PEnd = Protocol->protocol_end(); |
| 810 | P != PEnd; ++P) |
| 811 | CollectOverriddenMethods(TU, *P, Method, Methods); |
| 812 | } |
| 813 | |
| 814 | if (ObjCCategoryDecl *Category = dyn_cast<ObjCCategoryDecl>(Container)) { |
| 815 | for (ObjCCategoryDecl::protocol_iterator P = Category->protocol_begin(), |
| 816 | PEnd = Category->protocol_end(); |
| 817 | P != PEnd; ++P) |
| 818 | CollectOverriddenMethods(TU, *P, Method, Methods); |
| 819 | } |
| 820 | |
| 821 | if (ObjCInterfaceDecl *Interface = dyn_cast<ObjCInterfaceDecl>(Container)) { |
| 822 | for (ObjCInterfaceDecl::protocol_iterator P = Interface->protocol_begin(), |
| 823 | PEnd = Interface->protocol_end(); |
| 824 | P != PEnd; ++P) |
| 825 | CollectOverriddenMethods(TU, *P, Method, Methods); |
| 826 | |
| 827 | for (ObjCCategoryDecl *Category = Interface->getCategoryList(); |
| 828 | Category; Category = Category->getNextClassCategory()) |
| 829 | CollectOverriddenMethods(TU, Category, Method, Methods); |
| 830 | |
| 831 | // We only look into the superclass if we haven't found anything yet. |
| 832 | if (Methods.empty()) |
| 833 | if (ObjCInterfaceDecl *Super = Interface->getSuperClass()) |
| 834 | return CollectOverriddenMethods(TU, Super, Method, Methods); |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | void cxcursor::getOverriddenCursors(CXCursor cursor, |
| 839 | SmallVectorImpl<CXCursor> &overridden) { |
| 840 | if (!clang_isDeclaration(cursor.kind)) |
| 841 | return; |
| 842 | |
| 843 | Decl *D = getCursorDecl(cursor); |
| 844 | if (!D) |
| 845 | return; |
| 846 | |
| 847 | // Handle C++ member functions. |
| 848 | CXTranslationUnit TU = getCursorTU(cursor); |
| 849 | if (CXXMethodDecl *CXXMethod = dyn_cast<CXXMethodDecl>(D)) { |
| 850 | for (CXXMethodDecl::method_iterator |
| 851 | M = CXXMethod->begin_overridden_methods(), |
| 852 | MEnd = CXXMethod->end_overridden_methods(); |
| 853 | M != MEnd; ++M) |
| 854 | overridden.push_back(MakeCXCursor(const_cast<CXXMethodDecl*>(*M), TU)); |
| 855 | return; |
| 856 | } |
| 857 | |
| 858 | ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(D); |
| 859 | if (!Method) |
| 860 | return; |
| 861 | |
| 862 | // Handle Objective-C methods. |
| 863 | CollectOverriddenMethods(TU, Method->getDeclContext(), Method, overridden); |
| 864 | } |
| 865 | |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 866 | std::pair<int, SourceLocation> |
| 867 | cxcursor::getSelectorIdentifierIndexAndLoc(CXCursor cursor) { |
| 868 | if (cursor.kind == CXCursor_ObjCMessageExpr) { |
| 869 | if (cursor.xdata != -1) |
| 870 | return std::make_pair(cursor.xdata, |
| 871 | cast<ObjCMessageExpr>(getCursorExpr(cursor)) |
| 872 | ->getSelectorLoc(cursor.xdata)); |
| 873 | } else if (cursor.kind == CXCursor_ObjCClassMethodDecl || |
| 874 | cursor.kind == CXCursor_ObjCInstanceMethodDecl) { |
| 875 | if (cursor.xdata != -1) |
| 876 | return std::make_pair(cursor.xdata, |
| 877 | cast<ObjCMethodDecl>(getCursorDecl(cursor)) |
| 878 | ->getSelectorLoc(cursor.xdata)); |
| 879 | } |
| 880 | |
| 881 | return std::make_pair(-1, SourceLocation()); |
| 882 | } |
| 883 | |
| 884 | CXCursor cxcursor::getSelectorIdentifierCursor(int SelIdx, CXCursor cursor) { |
| 885 | CXCursor newCursor = cursor; |
| 886 | |
| 887 | if (cursor.kind == CXCursor_ObjCMessageExpr) { |
| 888 | if (SelIdx == -1 || |
| 889 | unsigned(SelIdx) >= cast<ObjCMessageExpr>(getCursorExpr(cursor)) |
| 890 | ->getNumSelectorLocs()) |
| 891 | newCursor.xdata = -1; |
| 892 | else |
| 893 | newCursor.xdata = SelIdx; |
| 894 | } else if (cursor.kind == CXCursor_ObjCClassMethodDecl || |
| 895 | cursor.kind == CXCursor_ObjCInstanceMethodDecl) { |
| 896 | if (SelIdx == -1 || |
| 897 | unsigned(SelIdx) >= cast<ObjCMethodDecl>(getCursorDecl(cursor)) |
| 898 | ->getNumSelectorLocs()) |
| 899 | newCursor.xdata = -1; |
| 900 | else |
| 901 | newCursor.xdata = SelIdx; |
| 902 | } |
| 903 | |
| 904 | return newCursor; |
| 905 | } |
| 906 | |
| 907 | CXCursor cxcursor::getTypeRefCursor(CXCursor cursor) { |
| 908 | if (cursor.kind != CXCursor_CallExpr) |
| 909 | return cursor; |
| 910 | |
| 911 | if (cursor.xdata == 0) |
| 912 | return cursor; |
| 913 | |
| 914 | Expr *E = getCursorExpr(cursor); |
| 915 | TypeSourceInfo *Type = 0; |
| 916 | if (CXXUnresolvedConstructExpr * |
| 917 | UnCtor = dyn_cast<CXXUnresolvedConstructExpr>(E)) { |
| 918 | Type = UnCtor->getTypeSourceInfo(); |
| 919 | } else if (CXXTemporaryObjectExpr *Tmp = dyn_cast<CXXTemporaryObjectExpr>(E)){ |
| 920 | Type = Tmp->getTypeSourceInfo(); |
| 921 | } |
| 922 | |
| 923 | if (!Type) |
| 924 | return cursor; |
| 925 | |
| 926 | CXTranslationUnit TU = getCursorTU(cursor); |
| 927 | QualType Ty = Type->getType(); |
| 928 | TypeLoc TL = Type->getTypeLoc(); |
| 929 | SourceLocation Loc = TL.getBeginLoc(); |
| 930 | |
| 931 | if (const ElaboratedType *ElabT = Ty->getAs<ElaboratedType>()) { |
| 932 | Ty = ElabT->getNamedType(); |
| 933 | ElaboratedTypeLoc ElabTL = cast<ElaboratedTypeLoc>(TL); |
| 934 | Loc = ElabTL.getNamedTypeLoc().getBeginLoc(); |
| 935 | } |
| 936 | |
| 937 | if (const TypedefType *Typedef = Ty->getAs<TypedefType>()) |
| 938 | return MakeCursorTypeRef(Typedef->getDecl(), Loc, TU); |
| 939 | if (const TagType *Tag = Ty->getAs<TagType>()) |
| 940 | return MakeCursorTypeRef(Tag->getDecl(), Loc, TU); |
| 941 | if (const TemplateTypeParmType *TemplP = Ty->getAs<TemplateTypeParmType>()) |
| 942 | return MakeCursorTypeRef(TemplP->getDecl(), Loc, TU); |
| 943 | |
| 944 | return cursor; |
| 945 | } |
| 946 | |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 947 | bool cxcursor::operator==(CXCursor X, CXCursor Y) { |
| 948 | return X.kind == Y.kind && X.data[0] == Y.data[0] && X.data[1] == Y.data[1] && |
| 949 | X.data[2] == Y.data[2]; |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 950 | } |
Ted Kremenek | 007a7c9 | 2010-11-01 23:26:51 +0000 | [diff] [blame] | 951 | |
| 952 | // FIXME: Remove once we can model DeclGroups and their appropriate ranges |
| 953 | // properly in the ASTs. |
| 954 | bool cxcursor::isFirstInDeclGroup(CXCursor C) { |
| 955 | assert(clang_isDeclaration(C.kind)); |
| 956 | return ((uintptr_t) (C.data[1])) != 0; |
| 957 | } |
| 958 | |
Ted Kremenek | eca099b | 2010-12-08 23:43:14 +0000 | [diff] [blame] | 959 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | b0d6eaa | 2011-09-27 00:30:30 +0000 | [diff] [blame] | 960 | // libclang CXCursor APIs |
| 961 | //===----------------------------------------------------------------------===// |
| 962 | |
Argyrios Kyrtzidis | fa865df | 2011-09-27 04:14:36 +0000 | [diff] [blame] | 963 | extern "C" { |
| 964 | |
| 965 | int clang_Cursor_isNull(CXCursor cursor) { |
| 966 | return clang_equalCursors(cursor, clang_getNullCursor()); |
| 967 | } |
| 968 | |
Argyrios Kyrtzidis | b0d6eaa | 2011-09-27 00:30:30 +0000 | [diff] [blame] | 969 | CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor cursor) { |
| 970 | return getCursorTU(cursor); |
| 971 | } |
| 972 | |
Argyrios Kyrtzidis | fa865df | 2011-09-27 04:14:36 +0000 | [diff] [blame] | 973 | } // end: extern "C" |
| 974 | |
Argyrios Kyrtzidis | b0d6eaa | 2011-09-27 00:30:30 +0000 | [diff] [blame] | 975 | //===----------------------------------------------------------------------===// |
Ted Kremenek | eca099b | 2010-12-08 23:43:14 +0000 | [diff] [blame] | 976 | // CXCursorSet. |
| 977 | //===----------------------------------------------------------------------===// |
| 978 | |
| 979 | typedef llvm::DenseMap<CXCursor, unsigned> CXCursorSet_Impl; |
| 980 | |
| 981 | static inline CXCursorSet packCXCursorSet(CXCursorSet_Impl *setImpl) { |
| 982 | return (CXCursorSet) setImpl; |
| 983 | } |
| 984 | static inline CXCursorSet_Impl *unpackCXCursorSet(CXCursorSet set) { |
| 985 | return (CXCursorSet_Impl*) set; |
| 986 | } |
| 987 | namespace llvm { |
Ted Kremenek | da6fb69 | 2010-12-09 00:33:41 +0000 | [diff] [blame] | 988 | template<> struct DenseMapInfo<CXCursor> { |
Ted Kremenek | eca099b | 2010-12-08 23:43:14 +0000 | [diff] [blame] | 989 | public: |
| 990 | static inline CXCursor getEmptyKey() { |
| 991 | return MakeCXCursorInvalid(CXCursor_InvalidFile); |
| 992 | } |
| 993 | static inline CXCursor getTombstoneKey() { |
| 994 | return MakeCXCursorInvalid(CXCursor_NoDeclFound); |
| 995 | } |
| 996 | static inline unsigned getHashValue(const CXCursor &cursor) { |
| 997 | return llvm::DenseMapInfo<std::pair<void*,void*> > |
| 998 | ::getHashValue(std::make_pair(cursor.data[0], cursor.data[1])); |
| 999 | } |
| 1000 | static inline bool isEqual(const CXCursor &x, const CXCursor &y) { |
| 1001 | return x.kind == y.kind && |
| 1002 | x.data[0] == y.data[0] && |
| 1003 | x.data[1] == y.data[1]; |
| 1004 | } |
| 1005 | }; |
| 1006 | } |
| 1007 | |
| 1008 | extern "C" { |
| 1009 | CXCursorSet clang_createCXCursorSet() { |
| 1010 | return packCXCursorSet(new CXCursorSet_Impl()); |
| 1011 | } |
| 1012 | |
| 1013 | void clang_disposeCXCursorSet(CXCursorSet set) { |
| 1014 | delete unpackCXCursorSet(set); |
| 1015 | } |
| 1016 | |
| 1017 | unsigned clang_CXCursorSet_contains(CXCursorSet set, CXCursor cursor) { |
| 1018 | CXCursorSet_Impl *setImpl = unpackCXCursorSet(set); |
| 1019 | if (!setImpl) |
| 1020 | return 0; |
| 1021 | return setImpl->find(cursor) == setImpl->end(); |
| 1022 | } |
| 1023 | |
Anders Carlsson | e8b3de0 | 2010-12-09 01:00:12 +0000 | [diff] [blame] | 1024 | unsigned clang_CXCursorSet_insert(CXCursorSet set, CXCursor cursor) { |
Ted Kremenek | eca099b | 2010-12-08 23:43:14 +0000 | [diff] [blame] | 1025 | // Do not insert invalid cursors into the set. |
| 1026 | if (cursor.kind >= CXCursor_FirstInvalid && |
| 1027 | cursor.kind <= CXCursor_LastInvalid) |
| 1028 | return 1; |
| 1029 | |
| 1030 | CXCursorSet_Impl *setImpl = unpackCXCursorSet(set); |
| 1031 | if (!setImpl) |
| 1032 | return 1; |
| 1033 | unsigned &entry = (*setImpl)[cursor]; |
| 1034 | unsigned flag = entry == 0 ? 1 : 0; |
| 1035 | entry = 1; |
| 1036 | return flag; |
| 1037 | } |
Douglas Gregor | 8fa0a80 | 2011-08-04 20:04:59 +0000 | [diff] [blame] | 1038 | |
| 1039 | CXCompletionString clang_getCursorCompletionString(CXCursor cursor) { |
| 1040 | enum CXCursorKind kind = clang_getCursorKind(cursor); |
| 1041 | if (clang_isDeclaration(kind)) { |
| 1042 | Decl *decl = getCursorDecl(cursor); |
Argyrios Kyrtzidis | 16ed0e6 | 2011-12-10 02:36:25 +0000 | [diff] [blame] | 1043 | if (NamedDecl *namedDecl = dyn_cast_or_null<NamedDecl>(decl)) { |
Douglas Gregor | 8fa0a80 | 2011-08-04 20:04:59 +0000 | [diff] [blame] | 1044 | ASTUnit *unit = getCursorASTUnit(cursor); |
Argyrios Kyrtzidis | 5e192a7 | 2012-01-17 02:15:54 +0000 | [diff] [blame] | 1045 | CodeCompletionAllocator *Allocator |
| 1046 | = unit->getCursorCompletionAllocator().getPtr(); |
| 1047 | CodeCompletionResult Result(namedDecl); |
| 1048 | CodeCompletionString *String |
| 1049 | = Result.CreateCodeCompletionString(unit->getASTContext(), |
| 1050 | unit->getPreprocessor(), |
| 1051 | *Allocator); |
| 1052 | return String; |
Douglas Gregor | 8fa0a80 | 2011-08-04 20:04:59 +0000 | [diff] [blame] | 1053 | } |
| 1054 | } |
| 1055 | else if (kind == CXCursor_MacroDefinition) { |
| 1056 | MacroDefinition *definition = getCursorMacroDefinition(cursor); |
| 1057 | const IdentifierInfo *MacroInfo = definition->getName(); |
| 1058 | ASTUnit *unit = getCursorASTUnit(cursor); |
Argyrios Kyrtzidis | 5e192a7 | 2012-01-17 02:15:54 +0000 | [diff] [blame] | 1059 | CodeCompletionAllocator *Allocator |
| 1060 | = unit->getCursorCompletionAllocator().getPtr(); |
| 1061 | CodeCompletionResult Result(const_cast<IdentifierInfo *>(MacroInfo)); |
| 1062 | CodeCompletionString *String |
| 1063 | = Result.CreateCodeCompletionString(unit->getASTContext(), |
| 1064 | unit->getPreprocessor(), |
| 1065 | *Allocator); |
| 1066 | return String; |
Douglas Gregor | 8fa0a80 | 2011-08-04 20:04:59 +0000 | [diff] [blame] | 1067 | } |
| 1068 | return NULL; |
| 1069 | } |
| 1070 | |
Ted Kremenek | eca099b | 2010-12-08 23:43:14 +0000 | [diff] [blame] | 1071 | } // end: extern "C" |