blob: b80ea4ee4ff1f800a9226c121586af5b675a0db1 [file] [log] [blame]
Ted Kremenek16c440a2010-01-15 20:35:54 +00001//===- 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 Gregor2e331b92010-01-16 14:00:32 +000010// 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 Kremenek16c440a2010-01-15 20:35:54 +000013//
14//===----------------------------------------------------------------------===//
15
Ted Kremenek0a90d322010-11-17 23:24:11 +000016#include "CXTranslationUnit.h"
Ted Kremenek16c440a2010-01-15 20:35:54 +000017#include "CXCursor.h"
Ted Kremeneked122732010-11-16 01:56:27 +000018#include "CXString.h"
Chandler Carruthf59edb92012-12-04 09:25:21 +000019#include "CXType.h"
20#include "clang-c/Index.h"
David Blaikie0b5ca512013-09-13 18:32:52 +000021#include "clang/AST/Attr.h"
Ted Kremenek16c440a2010-01-15 20:35:54 +000022#include "clang/AST/Decl.h"
Douglas Gregor69319002010-08-31 23:48:11 +000023#include "clang/AST/DeclCXX.h"
Douglas Gregor283cae32010-01-15 21:56:13 +000024#include "clang/AST/DeclObjC.h"
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +000025#include "clang/AST/DeclTemplate.h"
Douglas Gregor283cae32010-01-15 21:56:13 +000026#include "clang/AST/Expr.h"
Douglas Gregor1f60d9e2010-09-13 22:52:57 +000027#include "clang/AST/ExprCXX.h"
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +000028#include "clang/AST/ExprObjC.h"
Chandler Carruthf59edb92012-12-04 09:25:21 +000029#include "clang/Frontend/ASTUnit.h"
Ted Kremenekedc8aa62010-01-16 00:36:30 +000030#include "llvm/Support/ErrorHandling.h"
Ted Kremenek16c440a2010-01-15 20:35:54 +000031
32using namespace clang;
Douglas Gregor1f60d9e2010-09-13 22:52:57 +000033using namespace cxcursor;
Ted Kremenek16c440a2010-01-15 20:35:54 +000034
Ted Kremenekbbf66ca2012-04-30 19:06:49 +000035CXCursor cxcursor::MakeCXCursorInvalid(CXCursorKind K, CXTranslationUnit TU) {
Douglas Gregor5bfb8c12010-01-20 23:34:41 +000036 assert(K >= CXCursor_FirstInvalid && K <= CXCursor_LastInvalid);
Ted Kremenekbbf66ca2012-04-30 19:06:49 +000037 CXCursor C = { K, 0, { 0, 0, TU } };
Douglas Gregor5bfb8c12010-01-20 23:34:41 +000038 return C;
Ted Kremenek16c440a2010-01-15 20:35:54 +000039}
40
Ted Kremeneke77f4432010-02-18 03:09:07 +000041static CXCursorKind GetCursorKind(const Attr *A) {
42 assert(A && "Invalid arguments!");
43 switch (A->getKind()) {
44 default: break;
Sean Hunt387475d2010-06-16 23:43:53 +000045 case attr::IBAction: return CXCursor_IBActionAttr;
46 case attr::IBOutlet: return CXCursor_IBOutletAttr;
47 case attr::IBOutletCollection: return CXCursor_IBOutletCollectionAttr;
Argyrios Kyrtzidis6639e922011-09-13 17:39:31 +000048 case attr::Final: return CXCursor_CXXFinalAttr;
49 case attr::Override: return CXCursor_CXXOverrideAttr;
Erik Verbruggen5f1c8222011-10-13 09:41:32 +000050 case attr::Annotate: return CXCursor_AnnotateAttr;
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +000051 case attr::AsmLabel: return CXCursor_AsmLabelAttr;
Ted Kremeneke77f4432010-02-18 03:09:07 +000052 }
53
54 return CXCursor_UnexposedAttr;
55}
56
Dmitri Gribenko05756dc2013-01-14 00:46:27 +000057CXCursor cxcursor::MakeCXCursor(const Attr *A, const Decl *Parent,
Ted Kremeneka60ed472010-11-16 08:15:36 +000058 CXTranslationUnit TU) {
Ted Kremeneke77f4432010-02-18 03:09:07 +000059 assert(A && Parent && TU && "Invalid arguments!");
Dmitri Gribenko33156182013-01-11 21:06:06 +000060 CXCursor C = { GetCursorKind(A), 0, { Parent, A, TU } };
Ted Kremeneke77f4432010-02-18 03:09:07 +000061 return C;
62}
63
Dmitri Gribenko67812b22013-01-11 21:01:49 +000064CXCursor cxcursor::MakeCXCursor(const Decl *D, CXTranslationUnit TU,
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +000065 SourceRange RegionOfInterest,
Ted Kremenek007a7c92010-11-01 23:26:51 +000066 bool FirstInDeclGroup) {
Daniel Dunbar54d67ca2010-01-25 00:40:30 +000067 assert(D && TU && "Invalid arguments!");
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +000068
69 CXCursorKind K = getCursorKindForDecl(D);
70
71 if (K == CXCursor_ObjCClassMethodDecl ||
72 K == CXCursor_ObjCInstanceMethodDecl) {
73 int SelectorIdIndex = -1;
74 // Check if cursor points to a selector id.
75 if (RegionOfInterest.isValid() &&
76 RegionOfInterest.getBegin() == RegionOfInterest.getEnd()) {
77 SmallVector<SourceLocation, 16> SelLocs;
78 cast<ObjCMethodDecl>(D)->getSelectorLocs(SelLocs);
Craig Topper09d19ef2013-07-04 03:08:24 +000079 SmallVectorImpl<SourceLocation>::iterator
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +000080 I=std::find(SelLocs.begin(), SelLocs.end(),RegionOfInterest.getBegin());
81 if (I != SelLocs.end())
82 SelectorIdIndex = I - SelLocs.begin();
83 }
84 CXCursor C = { K, SelectorIdIndex,
85 { D, (void*)(intptr_t) (FirstInDeclGroup ? 1 : 0), TU }};
86 return C;
87 }
88
89 CXCursor C = { K, 0, { D, (void*)(intptr_t) (FirstInDeclGroup ? 1 : 0), TU }};
Douglas Gregor5bfb8c12010-01-20 23:34:41 +000090 return C;
Ted Kremenekedc8aa62010-01-16 00:36:30 +000091}
92
Dmitri Gribenko05756dc2013-01-14 00:46:27 +000093CXCursor cxcursor::MakeCXCursor(const Stmt *S, const Decl *Parent,
Dmitri Gribenko67812b22013-01-11 21:01:49 +000094 CXTranslationUnit TU,
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +000095 SourceRange RegionOfInterest) {
Daniel Dunbar54d67ca2010-01-25 00:40:30 +000096 assert(S && TU && "Invalid arguments!");
Douglas Gregor97b98722010-01-19 23:20:36 +000097 CXCursorKind K = CXCursor_NotImplemented;
98
99 switch (S->getStmtClass()) {
100 case Stmt::NoStmtClass:
101 break;
Douglas Gregor42b29842011-10-05 19:00:14 +0000102
Douglas Gregor97b98722010-01-19 23:20:36 +0000103 case Stmt::CaseStmtClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000104 K = CXCursor_CaseStmt;
105 break;
106
Douglas Gregor97b98722010-01-19 23:20:36 +0000107 case Stmt::DefaultStmtClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000108 K = CXCursor_DefaultStmt;
109 break;
110
111 case Stmt::IfStmtClass:
112 K = CXCursor_IfStmt;
113 break;
114
115 case Stmt::SwitchStmtClass:
116 K = CXCursor_SwitchStmt;
117 break;
118
119 case Stmt::WhileStmtClass:
120 K = CXCursor_WhileStmt;
121 break;
122
123 case Stmt::DoStmtClass:
124 K = CXCursor_DoStmt;
125 break;
126
127 case Stmt::ForStmtClass:
128 K = CXCursor_ForStmt;
129 break;
130
131 case Stmt::GotoStmtClass:
132 K = CXCursor_GotoStmt;
133 break;
134
Douglas Gregor97b98722010-01-19 23:20:36 +0000135 case Stmt::IndirectGotoStmtClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000136 K = CXCursor_IndirectGotoStmt;
137 break;
138
139 case Stmt::ContinueStmtClass:
140 K = CXCursor_ContinueStmt;
141 break;
142
143 case Stmt::BreakStmtClass:
144 K = CXCursor_BreakStmt;
145 break;
146
147 case Stmt::ReturnStmtClass:
148 K = CXCursor_ReturnStmt;
149 break;
150
Chad Rosierdf5faf52012-08-25 00:11:56 +0000151 case Stmt::GCCAsmStmtClass:
152 K = CXCursor_GCCAsmStmt;
Douglas Gregor42b29842011-10-05 19:00:14 +0000153 break;
Chad Rosier8cd64b42012-06-11 20:47:18 +0000154
155 case Stmt::MSAsmStmtClass:
156 K = CXCursor_MSAsmStmt;
157 break;
Douglas Gregor42b29842011-10-05 19:00:14 +0000158
159 case Stmt::ObjCAtTryStmtClass:
160 K = CXCursor_ObjCAtTryStmt;
161 break;
162
163 case Stmt::ObjCAtCatchStmtClass:
164 K = CXCursor_ObjCAtCatchStmt;
165 break;
166
167 case Stmt::ObjCAtFinallyStmtClass:
168 K = CXCursor_ObjCAtFinallyStmt;
169 break;
170
171 case Stmt::ObjCAtThrowStmtClass:
172 K = CXCursor_ObjCAtThrowStmt;
173 break;
174
175 case Stmt::ObjCAtSynchronizedStmtClass:
176 K = CXCursor_ObjCAtSynchronizedStmt;
177 break;
178
179 case Stmt::ObjCAutoreleasePoolStmtClass:
180 K = CXCursor_ObjCAutoreleasePoolStmt;
181 break;
182
Douglas Gregor97b98722010-01-19 23:20:36 +0000183 case Stmt::ObjCForCollectionStmtClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000184 K = CXCursor_ObjCForCollectionStmt;
185 break;
186
Douglas Gregor97b98722010-01-19 23:20:36 +0000187 case Stmt::CXXCatchStmtClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000188 K = CXCursor_CXXCatchStmt;
189 break;
190
191 case Stmt::CXXTryStmtClass:
192 K = CXCursor_CXXTryStmt;
193 break;
194
195 case Stmt::CXXForRangeStmtClass:
196 K = CXCursor_CXXForRangeStmt;
197 break;
198
John Wiegley28bbe4b2011-04-28 01:08:34 +0000199 case Stmt::SEHTryStmtClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000200 K = CXCursor_SEHTryStmt;
201 break;
202
John Wiegley28bbe4b2011-04-28 01:08:34 +0000203 case Stmt::SEHExceptStmtClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000204 K = CXCursor_SEHExceptStmt;
205 break;
206
John Wiegley28bbe4b2011-04-28 01:08:34 +0000207 case Stmt::SEHFinallyStmtClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000208 K = CXCursor_SEHFinallyStmt;
Douglas Gregor97b98722010-01-19 23:20:36 +0000209 break;
Douglas Gregor42b29842011-10-05 19:00:14 +0000210
John Wiegley21ff2e52011-04-28 00:16:57 +0000211 case Stmt::ArrayTypeTraitExprClass:
Tanya Lattner61eee0c2011-06-04 00:47:47 +0000212 case Stmt::AsTypeExprClass:
Eli Friedman276b0612011-10-11 02:20:01 +0000213 case Stmt::AtomicExprClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000214 case Stmt::BinaryConditionalOperatorClass:
215 case Stmt::BinaryTypeTraitExprClass:
Douglas Gregor4ca8ac22012-02-24 07:38:34 +0000216 case Stmt::TypeTraitExprClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000217 case Stmt::CXXBindTemporaryExprClass:
218 case Stmt::CXXDefaultArgExprClass:
Richard Smithc3bf52c2013-04-20 22:23:05 +0000219 case Stmt::CXXDefaultInitExprClass:
Richard Smith7c3e6152013-06-12 22:31:48 +0000220 case Stmt::CXXStdInitializerListExprClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000221 case Stmt::CXXScalarValueInitExprClass:
222 case Stmt::CXXUuidofExprClass:
223 case Stmt::ChooseExprClass:
224 case Stmt::DesignatedInitExprClass:
225 case Stmt::ExprWithCleanupsClass:
226 case Stmt::ExpressionTraitExprClass:
227 case Stmt::ExtVectorElementExprClass:
228 case Stmt::ImplicitCastExprClass:
229 case Stmt::ImplicitValueInitExprClass:
230 case Stmt::MaterializeTemporaryExprClass:
231 case Stmt::ObjCIndirectCopyRestoreExprClass:
232 case Stmt::OffsetOfExprClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000233 case Stmt::ParenListExprClass:
234 case Stmt::PredefinedExprClass:
235 case Stmt::ShuffleVectorExprClass:
236 case Stmt::UnaryExprOrTypeTraitExprClass:
237 case Stmt::UnaryTypeTraitExprClass:
238 case Stmt::VAArgExprClass:
Ted Kremenekb3f75422012-03-06 20:06:06 +0000239 case Stmt::ObjCArrayLiteralClass:
240 case Stmt::ObjCDictionaryLiteralClass:
Patrick Beardeb382ec2012-04-19 00:25:12 +0000241 case Stmt::ObjCBoxedExprClass:
Ted Kremenekb3f75422012-03-06 20:06:06 +0000242 case Stmt::ObjCSubscriptRefExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000243 K = CXCursor_UnexposedExpr;
244 break;
Douglas Gregor42b29842011-10-05 19:00:14 +0000245
John McCall4b9c2d22011-11-06 09:01:30 +0000246 case Stmt::OpaqueValueExprClass:
247 if (Expr *Src = cast<OpaqueValueExpr>(S)->getSourceExpr())
248 return MakeCXCursor(Src, Parent, TU, RegionOfInterest);
249 K = CXCursor_UnexposedExpr;
250 break;
251
252 case Stmt::PseudoObjectExprClass:
253 return MakeCXCursor(cast<PseudoObjectExpr>(S)->getSyntacticForm(),
254 Parent, TU, RegionOfInterest);
255
Douglas Gregor42b29842011-10-05 19:00:14 +0000256 case Stmt::CompoundStmtClass:
257 K = CXCursor_CompoundStmt;
258 break;
Richard Smith534986f2012-04-14 00:33:13 +0000259
Douglas Gregor42b29842011-10-05 19:00:14 +0000260 case Stmt::NullStmtClass:
261 K = CXCursor_NullStmt;
262 break;
Richard Smith534986f2012-04-14 00:33:13 +0000263
Douglas Gregor42b29842011-10-05 19:00:14 +0000264 case Stmt::LabelStmtClass:
265 K = CXCursor_LabelStmt;
266 break;
Richard Smith534986f2012-04-14 00:33:13 +0000267
268 case Stmt::AttributedStmtClass:
269 K = CXCursor_UnexposedStmt;
270 break;
271
Douglas Gregor42b29842011-10-05 19:00:14 +0000272 case Stmt::DeclStmtClass:
273 K = CXCursor_DeclStmt;
274 break;
Richard Smith534986f2012-04-14 00:33:13 +0000275
Tareq A. Siraj051303c2013-04-16 18:53:08 +0000276 case Stmt::CapturedStmtClass:
277 K = CXCursor_UnexposedStmt;
278 break;
279
Douglas Gregor42b29842011-10-05 19:00:14 +0000280 case Stmt::IntegerLiteralClass:
281 K = CXCursor_IntegerLiteral;
282 break;
283
284 case Stmt::FloatingLiteralClass:
285 K = CXCursor_FloatingLiteral;
286 break;
287
288 case Stmt::ImaginaryLiteralClass:
289 K = CXCursor_ImaginaryLiteral;
290 break;
291
292 case Stmt::StringLiteralClass:
293 K = CXCursor_StringLiteral;
294 break;
295
296 case Stmt::CharacterLiteralClass:
297 K = CXCursor_CharacterLiteral;
298 break;
299
300 case Stmt::ParenExprClass:
301 K = CXCursor_ParenExpr;
302 break;
303
304 case Stmt::UnaryOperatorClass:
305 K = CXCursor_UnaryOperator;
306 break;
Richard Smith534986f2012-04-14 00:33:13 +0000307
Douglas Gregor42b29842011-10-05 19:00:14 +0000308 case Stmt::CXXNoexceptExprClass:
309 K = CXCursor_UnaryExpr;
310 break;
311
312 case Stmt::ArraySubscriptExprClass:
313 K = CXCursor_ArraySubscriptExpr;
314 break;
315
316 case Stmt::BinaryOperatorClass:
317 K = CXCursor_BinaryOperator;
318 break;
319
320 case Stmt::CompoundAssignOperatorClass:
321 K = CXCursor_CompoundAssignOperator;
322 break;
323
324 case Stmt::ConditionalOperatorClass:
325 K = CXCursor_ConditionalOperator;
326 break;
327
328 case Stmt::CStyleCastExprClass:
329 K = CXCursor_CStyleCastExpr;
330 break;
331
332 case Stmt::CompoundLiteralExprClass:
333 K = CXCursor_CompoundLiteralExpr;
334 break;
335
336 case Stmt::InitListExprClass:
337 K = CXCursor_InitListExpr;
338 break;
339
340 case Stmt::AddrLabelExprClass:
341 K = CXCursor_AddrLabelExpr;
342 break;
343
344 case Stmt::StmtExprClass:
345 K = CXCursor_StmtExpr;
346 break;
347
348 case Stmt::GenericSelectionExprClass:
349 K = CXCursor_GenericSelectionExpr;
350 break;
351
352 case Stmt::GNUNullExprClass:
353 K = CXCursor_GNUNullExpr;
354 break;
355
356 case Stmt::CXXStaticCastExprClass:
357 K = CXCursor_CXXStaticCastExpr;
358 break;
359
360 case Stmt::CXXDynamicCastExprClass:
361 K = CXCursor_CXXDynamicCastExpr;
362 break;
363
364 case Stmt::CXXReinterpretCastExprClass:
365 K = CXCursor_CXXReinterpretCastExpr;
366 break;
367
368 case Stmt::CXXConstCastExprClass:
369 K = CXCursor_CXXConstCastExpr;
370 break;
371
372 case Stmt::CXXFunctionalCastExprClass:
373 K = CXCursor_CXXFunctionalCastExpr;
374 break;
375
376 case Stmt::CXXTypeidExprClass:
377 K = CXCursor_CXXTypeidExpr;
378 break;
379
380 case Stmt::CXXBoolLiteralExprClass:
381 K = CXCursor_CXXBoolLiteralExpr;
382 break;
383
384 case Stmt::CXXNullPtrLiteralExprClass:
385 K = CXCursor_CXXNullPtrLiteralExpr;
386 break;
387
388 case Stmt::CXXThisExprClass:
389 K = CXCursor_CXXThisExpr;
390 break;
391
392 case Stmt::CXXThrowExprClass:
393 K = CXCursor_CXXThrowExpr;
394 break;
395
396 case Stmt::CXXNewExprClass:
397 K = CXCursor_CXXNewExpr;
398 break;
399
400 case Stmt::CXXDeleteExprClass:
401 K = CXCursor_CXXDeleteExpr;
402 break;
403
404 case Stmt::ObjCStringLiteralClass:
405 K = CXCursor_ObjCStringLiteral;
406 break;
407
408 case Stmt::ObjCEncodeExprClass:
409 K = CXCursor_ObjCEncodeExpr;
410 break;
411
412 case Stmt::ObjCSelectorExprClass:
413 K = CXCursor_ObjCSelectorExpr;
414 break;
415
416 case Stmt::ObjCProtocolExprClass:
417 K = CXCursor_ObjCProtocolExpr;
418 break;
Ted Kremenekb3f75422012-03-06 20:06:06 +0000419
420 case Stmt::ObjCBoolLiteralExprClass:
421 K = CXCursor_ObjCBoolLiteralExpr;
422 break;
423
Douglas Gregor42b29842011-10-05 19:00:14 +0000424 case Stmt::ObjCBridgedCastExprClass:
425 K = CXCursor_ObjCBridgedCastExpr;
426 break;
427
428 case Stmt::BlockExprClass:
429 K = CXCursor_BlockExpr;
430 break;
431
432 case Stmt::PackExpansionExprClass:
433 K = CXCursor_PackExpansionExpr;
434 break;
435
436 case Stmt::SizeOfPackExprClass:
437 K = CXCursor_SizeOfPackExpr;
438 break;
439
Argyrios Kyrtzidisedab0472013-04-23 17:57:17 +0000440 case Stmt::DeclRefExprClass:
441 if (const ImplicitParamDecl *IPD =
442 dyn_cast_or_null<ImplicitParamDecl>(cast<DeclRefExpr>(S)->getDecl())) {
443 if (const ObjCMethodDecl *MD =
444 dyn_cast<ObjCMethodDecl>(IPD->getDeclContext())) {
445 if (MD->getSelfDecl() == IPD) {
446 K = CXCursor_ObjCSelfExpr;
447 break;
448 }
449 }
450 }
451
452 K = CXCursor_DeclRefExpr;
453 break;
454
Douglas Gregor42b29842011-10-05 19:00:14 +0000455 case Stmt::DependentScopeDeclRefExprClass:
John McCall91a57552011-07-15 05:09:51 +0000456 case Stmt::SubstNonTypeTemplateParmExprClass:
Douglas Gregorc7793c72011-01-15 01:15:58 +0000457 case Stmt::SubstNonTypeTemplateParmPackExprClass:
Richard Smith9a4db032012-09-12 00:56:43 +0000458 case Stmt::FunctionParmPackExprClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000459 case Stmt::UnresolvedLookupExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000460 K = CXCursor_DeclRefExpr;
461 break;
462
Douglas Gregor42b29842011-10-05 19:00:14 +0000463 case Stmt::CXXDependentScopeMemberExprClass:
464 case Stmt::CXXPseudoDestructorExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000465 case Stmt::MemberExprClass:
John McCall76da55d2013-04-16 07:28:30 +0000466 case Stmt::MSPropertyRefExprClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000467 case Stmt::ObjCIsaExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000468 case Stmt::ObjCIvarRefExprClass:
469 case Stmt::ObjCPropertyRefExprClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000470 case Stmt::UnresolvedMemberExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000471 K = CXCursor_MemberRefExpr;
472 break;
473
474 case Stmt::CallExprClass:
475 case Stmt::CXXOperatorCallExprClass:
476 case Stmt::CXXMemberCallExprClass:
Peter Collingbournee08ce652011-02-09 21:07:24 +0000477 case Stmt::CUDAKernelCallExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000478 case Stmt::CXXConstructExprClass:
479 case Stmt::CXXTemporaryObjectExprClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000480 case Stmt::CXXUnresolvedConstructExprClass:
Richard Smith9fcce652012-03-07 08:35:16 +0000481 case Stmt::UserDefinedLiteralClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000482 K = CXCursor_CallExpr;
483 break;
484
Douglas Gregor011d8b92012-02-15 00:54:55 +0000485 case Stmt::LambdaExprClass:
486 K = CXCursor_LambdaExpr;
487 break;
488
Douglas Gregorba0513d2011-10-25 01:33:02 +0000489 case Stmt::ObjCMessageExprClass: {
Douglas Gregor97b98722010-01-19 23:20:36 +0000490 K = CXCursor_ObjCMessageExpr;
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000491 int SelectorIdIndex = -1;
492 // Check if cursor points to a selector id.
493 if (RegionOfInterest.isValid() &&
494 RegionOfInterest.getBegin() == RegionOfInterest.getEnd()) {
495 SmallVector<SourceLocation, 16> SelLocs;
496 cast<ObjCMessageExpr>(S)->getSelectorLocs(SelLocs);
Craig Topper09d19ef2013-07-04 03:08:24 +0000497 SmallVectorImpl<SourceLocation>::iterator
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000498 I=std::find(SelLocs.begin(), SelLocs.end(),RegionOfInterest.getBegin());
499 if (I != SelLocs.end())
500 SelectorIdIndex = I - SelLocs.begin();
501 }
502 CXCursor C = { K, 0, { Parent, S, TU } };
503 return getSelectorIdentifierCursor(SelectorIdIndex, C);
Douglas Gregor97b98722010-01-19 23:20:36 +0000504 }
Douglas Gregorba0513d2011-10-25 01:33:02 +0000505
506 case Stmt::MSDependentExistsStmtClass:
507 K = CXCursor_UnexposedStmt;
508 break;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000509 case Stmt::OMPParallelDirectiveClass:
510 K = CXCursor_OMPParallelDirective;
511 break;
512
Douglas Gregorba0513d2011-10-25 01:33:02 +0000513 }
Douglas Gregor97b98722010-01-19 23:20:36 +0000514
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000515 CXCursor C = { K, 0, { Parent, S, TU } };
Douglas Gregor97b98722010-01-19 23:20:36 +0000516 return C;
517}
518
Douglas Gregor2e331b92010-01-16 14:00:32 +0000519CXCursor cxcursor::MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super,
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000520 SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000521 CXTranslationUnit TU) {
Daniel Dunbar54d67ca2010-01-25 00:40:30 +0000522 assert(Super && TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000523 void *RawLoc = Loc.getPtrEncoding();
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000524 CXCursor C = { CXCursor_ObjCSuperClassRef, 0, { Super, RawLoc, TU } };
Douglas Gregor2e331b92010-01-16 14:00:32 +0000525 return C;
526}
527
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000528std::pair<const ObjCInterfaceDecl *, SourceLocation>
Douglas Gregor2e331b92010-01-16 14:00:32 +0000529cxcursor::getCursorObjCSuperClassRef(CXCursor C) {
530 assert(C.kind == CXCursor_ObjCSuperClassRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000531 return std::make_pair(static_cast<const ObjCInterfaceDecl *>(C.data[0]),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000532 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregor2e331b92010-01-16 14:00:32 +0000533}
534
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +0000535CXCursor cxcursor::MakeCursorObjCProtocolRef(const ObjCProtocolDecl *Proto,
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000536 SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000537 CXTranslationUnit TU) {
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +0000538 assert(Proto && TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000539 void *RawLoc = Loc.getPtrEncoding();
Dmitri Gribenko33156182013-01-11 21:06:06 +0000540 CXCursor C = { CXCursor_ObjCProtocolRef, 0, { Proto, RawLoc, TU } };
Douglas Gregor78db0cd2010-01-16 15:44:18 +0000541 return C;
542}
543
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000544std::pair<const ObjCProtocolDecl *, SourceLocation>
Douglas Gregor78db0cd2010-01-16 15:44:18 +0000545cxcursor::getCursorObjCProtocolRef(CXCursor C) {
546 assert(C.kind == CXCursor_ObjCProtocolRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000547 return std::make_pair(static_cast<const ObjCProtocolDecl *>(C.data[0]),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000548 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregor78db0cd2010-01-16 15:44:18 +0000549}
550
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +0000551CXCursor cxcursor::MakeCursorObjCClassRef(const ObjCInterfaceDecl *Class,
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000552 SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000553 CXTranslationUnit TU) {
Ted Kremenekebfa3392010-03-19 20:39:03 +0000554 // 'Class' can be null for invalid code.
555 if (!Class)
556 return MakeCXCursorInvalid(CXCursor_InvalidCode);
557 assert(TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000558 void *RawLoc = Loc.getPtrEncoding();
Dmitri Gribenko33156182013-01-11 21:06:06 +0000559 CXCursor C = { CXCursor_ObjCClassRef, 0, { Class, RawLoc, TU } };
Douglas Gregor1adb0822010-01-16 17:14:40 +0000560 return C;
561}
562
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000563std::pair<const ObjCInterfaceDecl *, SourceLocation>
Douglas Gregor1adb0822010-01-16 17:14:40 +0000564cxcursor::getCursorObjCClassRef(CXCursor C) {
565 assert(C.kind == CXCursor_ObjCClassRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000566 return std::make_pair(static_cast<const ObjCInterfaceDecl *>(C.data[0]),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000567 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregor1adb0822010-01-16 17:14:40 +0000568}
569
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +0000570CXCursor cxcursor::MakeCursorTypeRef(const TypeDecl *Type, SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000571 CXTranslationUnit TU) {
Daniel Dunbar54d67ca2010-01-25 00:40:30 +0000572 assert(Type && TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000573 void *RawLoc = Loc.getPtrEncoding();
Dmitri Gribenko33156182013-01-11 21:06:06 +0000574 CXCursor C = { CXCursor_TypeRef, 0, { Type, RawLoc, TU } };
Douglas Gregor7d0d40e2010-01-21 16:28:34 +0000575 return C;
576}
577
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000578std::pair<const TypeDecl *, SourceLocation>
Douglas Gregor7d0d40e2010-01-21 16:28:34 +0000579cxcursor::getCursorTypeRef(CXCursor C) {
580 assert(C.kind == CXCursor_TypeRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000581 return std::make_pair(static_cast<const TypeDecl *>(C.data[0]),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000582 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregor7d0d40e2010-01-21 16:28:34 +0000583}
584
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +0000585CXCursor cxcursor::MakeCursorTemplateRef(const TemplateDecl *Template,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000586 SourceLocation Loc,
587 CXTranslationUnit TU) {
Douglas Gregor0b36e612010-08-31 20:37:03 +0000588 assert(Template && TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000589 void *RawLoc = Loc.getPtrEncoding();
Dmitri Gribenko33156182013-01-11 21:06:06 +0000590 CXCursor C = { CXCursor_TemplateRef, 0, { Template, RawLoc, TU } };
Douglas Gregor0b36e612010-08-31 20:37:03 +0000591 return C;
592}
593
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000594std::pair<const TemplateDecl *, SourceLocation>
Douglas Gregor0b36e612010-08-31 20:37:03 +0000595cxcursor::getCursorTemplateRef(CXCursor C) {
596 assert(C.kind == CXCursor_TemplateRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000597 return std::make_pair(static_cast<const TemplateDecl *>(C.data[0]),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000598 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregor0b36e612010-08-31 20:37:03 +0000599}
600
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +0000601CXCursor cxcursor::MakeCursorNamespaceRef(const NamedDecl *NS,
602 SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000603 CXTranslationUnit TU) {
Douglas Gregor69319002010-08-31 23:48:11 +0000604
605 assert(NS && (isa<NamespaceDecl>(NS) || isa<NamespaceAliasDecl>(NS)) && TU &&
606 "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000607 void *RawLoc = Loc.getPtrEncoding();
Dmitri Gribenko33156182013-01-11 21:06:06 +0000608 CXCursor C = { CXCursor_NamespaceRef, 0, { NS, RawLoc, TU } };
Douglas Gregor69319002010-08-31 23:48:11 +0000609 return C;
610}
611
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000612std::pair<const NamedDecl *, SourceLocation>
Douglas Gregor69319002010-08-31 23:48:11 +0000613cxcursor::getCursorNamespaceRef(CXCursor C) {
614 assert(C.kind == CXCursor_NamespaceRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000615 return std::make_pair(static_cast<const NamedDecl *>(C.data[0]),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000616 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregor69319002010-08-31 23:48:11 +0000617}
618
Douglas Gregor011d8b92012-02-15 00:54:55 +0000619CXCursor cxcursor::MakeCursorVariableRef(const VarDecl *Var, SourceLocation Loc,
620 CXTranslationUnit TU) {
621
622 assert(Var && TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000623 void *RawLoc = Loc.getPtrEncoding();
Dmitri Gribenko33156182013-01-11 21:06:06 +0000624 CXCursor C = { CXCursor_VariableRef, 0, { Var, RawLoc, TU } };
Douglas Gregor011d8b92012-02-15 00:54:55 +0000625 return C;
626}
627
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000628std::pair<const VarDecl *, SourceLocation>
Douglas Gregor011d8b92012-02-15 00:54:55 +0000629cxcursor::getCursorVariableRef(CXCursor C) {
630 assert(C.kind == CXCursor_VariableRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000631 return std::make_pair(static_cast<const VarDecl *>(C.data[0]),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000632 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregor011d8b92012-02-15 00:54:55 +0000633}
634
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +0000635CXCursor cxcursor::MakeCursorMemberRef(const FieldDecl *Field, SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000636 CXTranslationUnit TU) {
Douglas Gregora67e03f2010-09-09 21:42:20 +0000637
638 assert(Field && TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000639 void *RawLoc = Loc.getPtrEncoding();
Dmitri Gribenko33156182013-01-11 21:06:06 +0000640 CXCursor C = { CXCursor_MemberRef, 0, { Field, RawLoc, TU } };
Douglas Gregora67e03f2010-09-09 21:42:20 +0000641 return C;
642}
643
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000644std::pair<const FieldDecl *, SourceLocation>
Douglas Gregora67e03f2010-09-09 21:42:20 +0000645cxcursor::getCursorMemberRef(CXCursor C) {
646 assert(C.kind == CXCursor_MemberRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000647 return std::make_pair(static_cast<const FieldDecl *>(C.data[0]),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000648 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregora67e03f2010-09-09 21:42:20 +0000649}
650
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +0000651CXCursor cxcursor::MakeCursorCXXBaseSpecifier(const CXXBaseSpecifier *B,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000652 CXTranslationUnit TU){
Dmitri Gribenko33156182013-01-11 21:06:06 +0000653 CXCursor C = { CXCursor_CXXBaseSpecifier, 0, { B, 0, TU } };
Ted Kremenek3064ef92010-08-27 21:34:58 +0000654 return C;
655}
656
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000657const CXXBaseSpecifier *cxcursor::getCursorCXXBaseSpecifier(CXCursor C) {
Ted Kremenek3064ef92010-08-27 21:34:58 +0000658 assert(C.kind == CXCursor_CXXBaseSpecifier);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000659 return static_cast<const CXXBaseSpecifier*>(C.data[0]);
Ted Kremenek3064ef92010-08-27 21:34:58 +0000660}
661
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +0000662CXCursor cxcursor::MakePreprocessingDirectiveCursor(SourceRange Range,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000663 CXTranslationUnit TU) {
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000664 CXCursor C = { CXCursor_PreprocessingDirective, 0,
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000665 { Range.getBegin().getPtrEncoding(),
666 Range.getEnd().getPtrEncoding(),
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +0000667 TU }
668 };
669 return C;
670}
671
672SourceRange cxcursor::getCursorPreprocessingDirective(CXCursor C) {
673 assert(C.kind == CXCursor_PreprocessingDirective);
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000674 SourceRange Range(SourceLocation::getFromPtrEncoding(C.data[0]),
675 SourceLocation::getFromPtrEncoding(C.data[1]));
Argyrios Kyrtzidisee0f84f2011-09-26 08:01:41 +0000676 ASTUnit *TU = getCursorASTUnit(C);
677 return TU->mapRangeFromPreamble(Range);
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +0000678}
679
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000680CXCursor cxcursor::MakeMacroDefinitionCursor(const MacroDefinition *MI,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000681 CXTranslationUnit TU) {
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000682 CXCursor C = { CXCursor_MacroDefinition, 0, { MI, 0, TU } };
Douglas Gregor572feb22010-03-18 18:04:21 +0000683 return C;
684}
685
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000686const MacroDefinition *cxcursor::getCursorMacroDefinition(CXCursor C) {
Douglas Gregor572feb22010-03-18 18:04:21 +0000687 assert(C.kind == CXCursor_MacroDefinition);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000688 return static_cast<const MacroDefinition *>(C.data[0]);
Douglas Gregor572feb22010-03-18 18:04:21 +0000689}
690
Chandler Carruth9e5bb852011-07-14 08:20:46 +0000691CXCursor cxcursor::MakeMacroExpansionCursor(MacroExpansion *MI,
692 CXTranslationUnit TU) {
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000693 CXCursor C = { CXCursor_MacroExpansion, 0, { MI, 0, TU } };
Douglas Gregor48072312010-03-18 15:23:44 +0000694 return C;
695}
696
Argyrios Kyrtzidis664b06f2013-01-07 19:16:25 +0000697CXCursor cxcursor::MakeMacroExpansionCursor(MacroDefinition *MI,
698 SourceLocation Loc,
699 CXTranslationUnit TU) {
700 assert(Loc.isValid());
701 CXCursor C = { CXCursor_MacroExpansion, 0, { MI, Loc.getPtrEncoding(), TU } };
702 return C;
703}
704
705const IdentifierInfo *cxcursor::MacroExpansionCursor::getName() const {
706 if (isPseudo())
707 return getAsMacroDefinition()->getName();
708 return getAsMacroExpansion()->getName();
709}
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000710const MacroDefinition *cxcursor::MacroExpansionCursor::getDefinition() const {
Argyrios Kyrtzidis664b06f2013-01-07 19:16:25 +0000711 if (isPseudo())
712 return getAsMacroDefinition();
713 return getAsMacroExpansion()->getDefinition();
714}
715SourceRange cxcursor::MacroExpansionCursor::getSourceRange() const {
716 if (isPseudo())
717 return getPseudoLoc();
718 return getAsMacroExpansion()->getSourceRange();
Douglas Gregor48072312010-03-18 15:23:44 +0000719}
720
Douglas Gregorecdcb882010-10-20 22:00:55 +0000721CXCursor cxcursor::MakeInclusionDirectiveCursor(InclusionDirective *ID,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000722 CXTranslationUnit TU) {
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000723 CXCursor C = { CXCursor_InclusionDirective, 0, { ID, 0, TU } };
Douglas Gregorecdcb882010-10-20 22:00:55 +0000724 return C;
725}
726
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000727const InclusionDirective *cxcursor::getCursorInclusionDirective(CXCursor C) {
Douglas Gregorecdcb882010-10-20 22:00:55 +0000728 assert(C.kind == CXCursor_InclusionDirective);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000729 return static_cast<const InclusionDirective *>(C.data[0]);
Douglas Gregorecdcb882010-10-20 22:00:55 +0000730}
731
Douglas Gregor36897b02010-09-10 00:22:18 +0000732CXCursor cxcursor::MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000733 CXTranslationUnit TU) {
Douglas Gregor36897b02010-09-10 00:22:18 +0000734
735 assert(Label && TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000736 void *RawLoc = Loc.getPtrEncoding();
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000737 CXCursor C = { CXCursor_LabelRef, 0, { Label, RawLoc, TU } };
Douglas Gregor36897b02010-09-10 00:22:18 +0000738 return C;
739}
740
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000741std::pair<const LabelStmt *, SourceLocation>
Douglas Gregor36897b02010-09-10 00:22:18 +0000742cxcursor::getCursorLabelRef(CXCursor C) {
743 assert(C.kind == CXCursor_LabelRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000744 return std::make_pair(static_cast<const LabelStmt *>(C.data[0]),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000745 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregor36897b02010-09-10 00:22:18 +0000746}
747
Dmitri Gribenkoe22339c2013-01-23 17:25:27 +0000748CXCursor cxcursor::MakeCursorOverloadedDeclRef(const OverloadExpr *E,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000749 CXTranslationUnit TU) {
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000750 assert(E && TU && "Invalid arguments!");
751 OverloadedDeclRefStorage Storage(E);
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000752 void *RawLoc = E->getNameLoc().getPtrEncoding();
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000753 CXCursor C = {
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000754 CXCursor_OverloadedDeclRef, 0,
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000755 { Storage.getOpaqueValue(), RawLoc, TU }
756 };
757 return C;
758}
759
Dmitri Gribenkoe22339c2013-01-23 17:25:27 +0000760CXCursor cxcursor::MakeCursorOverloadedDeclRef(const Decl *D,
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000761 SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000762 CXTranslationUnit TU) {
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000763 assert(D && TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000764 void *RawLoc = Loc.getPtrEncoding();
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000765 OverloadedDeclRefStorage Storage(D);
766 CXCursor C = {
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000767 CXCursor_OverloadedDeclRef, 0,
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000768 { Storage.getOpaqueValue(), RawLoc, TU }
769 };
770 return C;
771}
772
773CXCursor cxcursor::MakeCursorOverloadedDeclRef(TemplateName Name,
774 SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000775 CXTranslationUnit TU) {
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000776 assert(Name.getAsOverloadedTemplate() && TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000777 void *RawLoc = Loc.getPtrEncoding();
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000778 OverloadedDeclRefStorage Storage(Name.getAsOverloadedTemplate());
779 CXCursor C = {
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000780 CXCursor_OverloadedDeclRef, 0,
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000781 { Storage.getOpaqueValue(), RawLoc, TU }
782 };
783 return C;
784}
785
786std::pair<cxcursor::OverloadedDeclRefStorage, SourceLocation>
787cxcursor::getCursorOverloadedDeclRef(CXCursor C) {
788 assert(C.kind == CXCursor_OverloadedDeclRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000789 return std::make_pair(OverloadedDeclRefStorage::getFromOpaqueValue(
790 const_cast<void *>(C.data[0])),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000791 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000792}
793
Dmitri Gribenkoe22339c2013-01-23 17:25:27 +0000794const Decl *cxcursor::getCursorDecl(CXCursor Cursor) {
795 return static_cast<const Decl *>(Cursor.data[0]);
Douglas Gregor283cae32010-01-15 21:56:13 +0000796}
797
Dmitri Gribenkoff74f962013-01-26 15:29:08 +0000798const Expr *cxcursor::getCursorExpr(CXCursor Cursor) {
Douglas Gregor283cae32010-01-15 21:56:13 +0000799 return dyn_cast_or_null<Expr>(getCursorStmt(Cursor));
800}
801
Dmitri Gribenkoff74f962013-01-26 15:29:08 +0000802const Stmt *cxcursor::getCursorStmt(CXCursor Cursor) {
Douglas Gregor78db0cd2010-01-16 15:44:18 +0000803 if (Cursor.kind == CXCursor_ObjCSuperClassRef ||
Douglas Gregor1adb0822010-01-16 17:14:40 +0000804 Cursor.kind == CXCursor_ObjCProtocolRef ||
805 Cursor.kind == CXCursor_ObjCClassRef)
Douglas Gregor2e331b92010-01-16 14:00:32 +0000806 return 0;
807
Dmitri Gribenkoff74f962013-01-26 15:29:08 +0000808 return static_cast<const Stmt *>(Cursor.data[1]);
Douglas Gregor283cae32010-01-15 21:56:13 +0000809}
810
Dmitri Gribenko7d914382013-01-26 18:08:08 +0000811const Attr *cxcursor::getCursorAttr(CXCursor Cursor) {
812 return static_cast<const Attr *>(Cursor.data[1]);
Ted Kremenek95f33552010-08-26 01:42:22 +0000813}
814
Dmitri Gribenko404628c2013-01-26 18:12:08 +0000815const Decl *cxcursor::getCursorParentDecl(CXCursor Cursor) {
816 return static_cast<const Decl *>(Cursor.data[0]);
Argyrios Kyrtzidis8ccac3d2011-06-29 22:20:07 +0000817}
818
Douglas Gregorf46034a2010-01-18 23:41:10 +0000819ASTContext &cxcursor::getCursorContext(CXCursor Cursor) {
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000820 return getCursorASTUnit(Cursor)->getASTContext();
821}
Douglas Gregorf46034a2010-01-18 23:41:10 +0000822
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000823ASTUnit *cxcursor::getCursorASTUnit(CXCursor Cursor) {
Dmitri Gribenko46f92522013-01-11 19:28:44 +0000824 CXTranslationUnit TU = getCursorTU(Cursor);
Argyrios Kyrtzidis44517462011-12-09 00:17:49 +0000825 if (!TU)
826 return 0;
Dmitri Gribenko5694feb2013-01-26 18:53:38 +0000827 return cxtu::getASTUnit(TU);
Ted Kremeneka60ed472010-11-16 08:15:36 +0000828}
829
830CXTranslationUnit cxcursor::getCursorTU(CXCursor Cursor) {
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000831 return static_cast<CXTranslationUnit>(const_cast<void*>(Cursor.data[2]));
Douglas Gregor283cae32010-01-15 21:56:13 +0000832}
833
Argyrios Kyrtzidise15db6f2012-05-09 16:12:57 +0000834void cxcursor::getOverriddenCursors(CXCursor cursor,
835 SmallVectorImpl<CXCursor> &overridden) {
836 assert(clang_isDeclaration(cursor.kind));
Argyrios Kyrtzidis21c36072012-10-09 01:23:50 +0000837 const NamedDecl *D = dyn_cast_or_null<NamedDecl>(getCursorDecl(cursor));
Argyrios Kyrtzidise15db6f2012-05-09 16:12:57 +0000838 if (!D)
839 return;
840
Argyrios Kyrtzidise15db6f2012-05-09 16:12:57 +0000841 CXTranslationUnit TU = getCursorTU(cursor);
Argyrios Kyrtzidis21c36072012-10-09 01:23:50 +0000842 SmallVector<const NamedDecl *, 8> OverDecls;
843 D->getASTContext().getOverriddenMethods(D, OverDecls);
Argyrios Kyrtzidise15db6f2012-05-09 16:12:57 +0000844
Craig Topper09d19ef2013-07-04 03:08:24 +0000845 for (SmallVectorImpl<const NamedDecl *>::iterator
Argyrios Kyrtzidis21c36072012-10-09 01:23:50 +0000846 I = OverDecls.begin(), E = OverDecls.end(); I != E; ++I) {
Dmitri Gribenko05756dc2013-01-14 00:46:27 +0000847 overridden.push_back(MakeCXCursor(*I, TU));
Argyrios Kyrtzidise15db6f2012-05-09 16:12:57 +0000848 }
849}
850
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000851std::pair<int, SourceLocation>
852cxcursor::getSelectorIdentifierIndexAndLoc(CXCursor cursor) {
853 if (cursor.kind == CXCursor_ObjCMessageExpr) {
854 if (cursor.xdata != -1)
855 return std::make_pair(cursor.xdata,
856 cast<ObjCMessageExpr>(getCursorExpr(cursor))
857 ->getSelectorLoc(cursor.xdata));
858 } else if (cursor.kind == CXCursor_ObjCClassMethodDecl ||
859 cursor.kind == CXCursor_ObjCInstanceMethodDecl) {
860 if (cursor.xdata != -1)
861 return std::make_pair(cursor.xdata,
862 cast<ObjCMethodDecl>(getCursorDecl(cursor))
863 ->getSelectorLoc(cursor.xdata));
864 }
865
866 return std::make_pair(-1, SourceLocation());
867}
868
869CXCursor cxcursor::getSelectorIdentifierCursor(int SelIdx, CXCursor cursor) {
870 CXCursor newCursor = cursor;
871
872 if (cursor.kind == CXCursor_ObjCMessageExpr) {
873 if (SelIdx == -1 ||
874 unsigned(SelIdx) >= cast<ObjCMessageExpr>(getCursorExpr(cursor))
875 ->getNumSelectorLocs())
876 newCursor.xdata = -1;
877 else
878 newCursor.xdata = SelIdx;
879 } else if (cursor.kind == CXCursor_ObjCClassMethodDecl ||
880 cursor.kind == CXCursor_ObjCInstanceMethodDecl) {
881 if (SelIdx == -1 ||
882 unsigned(SelIdx) >= cast<ObjCMethodDecl>(getCursorDecl(cursor))
883 ->getNumSelectorLocs())
884 newCursor.xdata = -1;
885 else
886 newCursor.xdata = SelIdx;
887 }
888
889 return newCursor;
890}
891
892CXCursor cxcursor::getTypeRefCursor(CXCursor cursor) {
893 if (cursor.kind != CXCursor_CallExpr)
894 return cursor;
895
896 if (cursor.xdata == 0)
897 return cursor;
898
Dmitri Gribenkoff74f962013-01-26 15:29:08 +0000899 const Expr *E = getCursorExpr(cursor);
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000900 TypeSourceInfo *Type = 0;
Dmitri Gribenkoff74f962013-01-26 15:29:08 +0000901 if (const CXXUnresolvedConstructExpr *
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000902 UnCtor = dyn_cast<CXXUnresolvedConstructExpr>(E)) {
903 Type = UnCtor->getTypeSourceInfo();
Dmitri Gribenkoff74f962013-01-26 15:29:08 +0000904 } else if (const CXXTemporaryObjectExpr *Tmp =
905 dyn_cast<CXXTemporaryObjectExpr>(E)){
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000906 Type = Tmp->getTypeSourceInfo();
907 }
908
909 if (!Type)
910 return cursor;
911
912 CXTranslationUnit TU = getCursorTU(cursor);
913 QualType Ty = Type->getType();
914 TypeLoc TL = Type->getTypeLoc();
915 SourceLocation Loc = TL.getBeginLoc();
916
917 if (const ElaboratedType *ElabT = Ty->getAs<ElaboratedType>()) {
918 Ty = ElabT->getNamedType();
David Blaikie39e6ab42013-02-18 22:06:02 +0000919 ElaboratedTypeLoc ElabTL = TL.castAs<ElaboratedTypeLoc>();
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000920 Loc = ElabTL.getNamedTypeLoc().getBeginLoc();
921 }
922
923 if (const TypedefType *Typedef = Ty->getAs<TypedefType>())
924 return MakeCursorTypeRef(Typedef->getDecl(), Loc, TU);
925 if (const TagType *Tag = Ty->getAs<TagType>())
926 return MakeCursorTypeRef(Tag->getDecl(), Loc, TU);
927 if (const TemplateTypeParmType *TemplP = Ty->getAs<TemplateTypeParmType>())
928 return MakeCursorTypeRef(TemplP->getDecl(), Loc, TU);
929
930 return cursor;
931}
932
Douglas Gregor283cae32010-01-15 21:56:13 +0000933bool cxcursor::operator==(CXCursor X, CXCursor Y) {
934 return X.kind == Y.kind && X.data[0] == Y.data[0] && X.data[1] == Y.data[1] &&
935 X.data[2] == Y.data[2];
Douglas Gregor2e331b92010-01-16 14:00:32 +0000936}
Ted Kremenek007a7c92010-11-01 23:26:51 +0000937
938// FIXME: Remove once we can model DeclGroups and their appropriate ranges
939// properly in the ASTs.
940bool cxcursor::isFirstInDeclGroup(CXCursor C) {
941 assert(clang_isDeclaration(C.kind));
942 return ((uintptr_t) (C.data[1])) != 0;
943}
944
Ted Kremenekeca099b2010-12-08 23:43:14 +0000945//===----------------------------------------------------------------------===//
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +0000946// libclang CXCursor APIs
947//===----------------------------------------------------------------------===//
948
Argyrios Kyrtzidisfa865df2011-09-27 04:14:36 +0000949extern "C" {
950
951int clang_Cursor_isNull(CXCursor cursor) {
952 return clang_equalCursors(cursor, clang_getNullCursor());
953}
954
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +0000955CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor cursor) {
956 return getCursorTU(cursor);
957}
958
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +0000959int clang_Cursor_getNumArguments(CXCursor C) {
960 if (clang_isDeclaration(C.kind)) {
Dmitri Gribenkoe22339c2013-01-23 17:25:27 +0000961 const Decl *D = cxcursor::getCursorDecl(C);
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +0000962 if (const ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(D))
963 return MD->param_size();
964 if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
965 return FD->param_size();
966 }
967
Argyrios Kyrtzidise9ebd852013-04-01 17:38:59 +0000968 if (clang_isExpression(C.kind)) {
969 const Expr *E = cxcursor::getCursorExpr(C);
970 if (const CallExpr *CE = dyn_cast<CallExpr>(E)) {
971 return CE->getNumArgs();
972 }
973 }
974
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +0000975 return -1;
976}
977
978CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i) {
979 if (clang_isDeclaration(C.kind)) {
Dmitri Gribenkoe22339c2013-01-23 17:25:27 +0000980 const Decl *D = cxcursor::getCursorDecl(C);
981 if (const ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(D)) {
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +0000982 if (i < MD->param_size())
983 return cxcursor::MakeCXCursor(MD->param_begin()[i],
984 cxcursor::getCursorTU(C));
Dmitri Gribenkoe22339c2013-01-23 17:25:27 +0000985 } else if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) {
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +0000986 if (i < FD->param_size())
987 return cxcursor::MakeCXCursor(FD->param_begin()[i],
988 cxcursor::getCursorTU(C));
989 }
990 }
991
Argyrios Kyrtzidise9ebd852013-04-01 17:38:59 +0000992 if (clang_isExpression(C.kind)) {
993 const Expr *E = cxcursor::getCursorExpr(C);
994 if (const CallExpr *CE = dyn_cast<CallExpr>(E)) {
995 if (i < CE->getNumArgs()) {
996 return cxcursor::MakeCXCursor(CE->getArg(i),
997 getCursorDecl(C),
998 cxcursor::getCursorTU(C));
999 }
1000 }
1001 }
1002
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +00001003 return clang_getNullCursor();
1004}
1005
Ted Kremenek017dd742013-04-24 07:17:12 +00001006} // end: extern "C"
1007
1008//===----------------------------------------------------------------------===//
1009// CXCursorSet.
1010//===----------------------------------------------------------------------===//
1011
1012typedef llvm::DenseMap<CXCursor, unsigned> CXCursorSet_Impl;
1013
1014static inline CXCursorSet packCXCursorSet(CXCursorSet_Impl *setImpl) {
1015 return (CXCursorSet) setImpl;
1016}
1017static inline CXCursorSet_Impl *unpackCXCursorSet(CXCursorSet set) {
1018 return (CXCursorSet_Impl*) set;
1019}
1020namespace llvm {
1021template<> struct DenseMapInfo<CXCursor> {
1022public:
1023 static inline CXCursor getEmptyKey() {
1024 return MakeCXCursorInvalid(CXCursor_InvalidFile);
1025 }
1026 static inline CXCursor getTombstoneKey() {
1027 return MakeCXCursorInvalid(CXCursor_NoDeclFound);
1028 }
1029 static inline unsigned getHashValue(const CXCursor &cursor) {
1030 return llvm::DenseMapInfo<std::pair<const void *, const void *> >
1031 ::getHashValue(std::make_pair(cursor.data[0], cursor.data[1]));
1032 }
1033 static inline bool isEqual(const CXCursor &x, const CXCursor &y) {
1034 return x.kind == y.kind &&
1035 x.data[0] == y.data[0] &&
1036 x.data[1] == y.data[1];
1037 }
1038};
1039}
1040
1041extern "C" {
1042CXCursorSet clang_createCXCursorSet() {
1043 return packCXCursorSet(new CXCursorSet_Impl());
1044}
1045
1046void clang_disposeCXCursorSet(CXCursorSet set) {
1047 delete unpackCXCursorSet(set);
1048}
1049
1050unsigned clang_CXCursorSet_contains(CXCursorSet set, CXCursor cursor) {
1051 CXCursorSet_Impl *setImpl = unpackCXCursorSet(set);
1052 if (!setImpl)
1053 return 0;
Ted Kremenek96bbe192013-04-24 07:25:40 +00001054 return setImpl->find(cursor) != setImpl->end();
Ted Kremenek017dd742013-04-24 07:17:12 +00001055}
1056
1057unsigned clang_CXCursorSet_insert(CXCursorSet set, CXCursor cursor) {
1058 // Do not insert invalid cursors into the set.
1059 if (cursor.kind >= CXCursor_FirstInvalid &&
1060 cursor.kind <= CXCursor_LastInvalid)
1061 return 1;
1062
1063 CXCursorSet_Impl *setImpl = unpackCXCursorSet(set);
1064 if (!setImpl)
1065 return 1;
1066 unsigned &entry = (*setImpl)[cursor];
1067 unsigned flag = entry == 0 ? 1 : 0;
1068 entry = 1;
1069 return flag;
1070}
1071
Douglas Gregor8fa0a802011-08-04 20:04:59 +00001072CXCompletionString clang_getCursorCompletionString(CXCursor cursor) {
1073 enum CXCursorKind kind = clang_getCursorKind(cursor);
1074 if (clang_isDeclaration(kind)) {
Dmitri Gribenkoe22339c2013-01-23 17:25:27 +00001075 const Decl *decl = getCursorDecl(cursor);
1076 if (const NamedDecl *namedDecl = dyn_cast_or_null<NamedDecl>(decl)) {
Douglas Gregor8fa0a802011-08-04 20:04:59 +00001077 ASTUnit *unit = getCursorASTUnit(cursor);
Douglas Gregord1f09b42013-01-31 04:52:16 +00001078 CodeCompletionResult Result(namedDecl, CCP_Declaration);
Argyrios Kyrtzidis5e192a72012-01-17 02:15:54 +00001079 CodeCompletionString *String
1080 = Result.CreateCodeCompletionString(unit->getASTContext(),
1081 unit->getPreprocessor(),
Argyrios Kyrtzidis28a83f52012-04-10 17:23:48 +00001082 unit->getCodeCompletionTUInfo().getAllocator(),
Dmitri Gribenkod99ef532012-07-02 17:35:10 +00001083 unit->getCodeCompletionTUInfo(),
1084 true);
Argyrios Kyrtzidis5e192a72012-01-17 02:15:54 +00001085 return String;
Douglas Gregor8fa0a802011-08-04 20:04:59 +00001086 }
1087 }
1088 else if (kind == CXCursor_MacroDefinition) {
Dmitri Gribenko67812b22013-01-11 21:01:49 +00001089 const MacroDefinition *definition = getCursorMacroDefinition(cursor);
Douglas Gregor8fa0a802011-08-04 20:04:59 +00001090 const IdentifierInfo *MacroInfo = definition->getName();
1091 ASTUnit *unit = getCursorASTUnit(cursor);
Dmitri Gribenkob3958472013-01-14 00:36:42 +00001092 CodeCompletionResult Result(MacroInfo);
Argyrios Kyrtzidis5e192a72012-01-17 02:15:54 +00001093 CodeCompletionString *String
1094 = Result.CreateCodeCompletionString(unit->getASTContext(),
1095 unit->getPreprocessor(),
Argyrios Kyrtzidis28a83f52012-04-10 17:23:48 +00001096 unit->getCodeCompletionTUInfo().getAllocator(),
Dmitri Gribenkod99ef532012-07-02 17:35:10 +00001097 unit->getCodeCompletionTUInfo(),
1098 false);
Argyrios Kyrtzidis5e192a72012-01-17 02:15:54 +00001099 return String;
Douglas Gregor8fa0a802011-08-04 20:04:59 +00001100 }
1101 return NULL;
1102}
Ted Kremenek8eece462012-04-30 19:33:45 +00001103} // end: extern C.
Ted Kremenekbbf66ca2012-04-30 19:06:49 +00001104
1105namespace {
1106 struct OverridenCursorsPool {
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00001107 typedef SmallVector<CXCursor, 2> CursorVec;
Ted Kremenekbbf66ca2012-04-30 19:06:49 +00001108 std::vector<CursorVec*> AllCursors;
1109 std::vector<CursorVec*> AvailableCursors;
1110
1111 ~OverridenCursorsPool() {
1112 for (std::vector<CursorVec*>::iterator I = AllCursors.begin(),
1113 E = AllCursors.end(); I != E; ++I) {
1114 delete *I;
1115 }
1116 }
1117 };
1118}
1119
1120void *cxcursor::createOverridenCXCursorsPool() {
1121 return new OverridenCursorsPool();
1122}
1123
1124void cxcursor::disposeOverridenCXCursorsPool(void *pool) {
1125 delete static_cast<OverridenCursorsPool*>(pool);
1126}
Ted Kremenek8eece462012-04-30 19:33:45 +00001127
1128extern "C" {
Ted Kremenekbbf66ca2012-04-30 19:06:49 +00001129void clang_getOverriddenCursors(CXCursor cursor,
1130 CXCursor **overridden,
1131 unsigned *num_overridden) {
1132 if (overridden)
1133 *overridden = 0;
1134 if (num_overridden)
1135 *num_overridden = 0;
1136
1137 CXTranslationUnit TU = cxcursor::getCursorTU(cursor);
1138
1139 if (!overridden || !num_overridden || !TU)
1140 return;
1141
1142 if (!clang_isDeclaration(cursor.kind))
1143 return;
1144
1145 OverridenCursorsPool &pool =
1146 *static_cast<OverridenCursorsPool*>(TU->OverridenCursorsPool);
1147
1148 OverridenCursorsPool::CursorVec *Vec = 0;
1149
1150 if (!pool.AvailableCursors.empty()) {
1151 Vec = pool.AvailableCursors.back();
1152 pool.AvailableCursors.pop_back();
1153 }
1154 else {
1155 Vec = new OverridenCursorsPool::CursorVec();
1156 pool.AllCursors.push_back(Vec);
1157 }
1158
1159 // Clear out the vector, but don't free the memory contents. This
1160 // reduces malloc() traffic.
1161 Vec->clear();
1162
1163 // Use the first entry to contain a back reference to the vector.
1164 // This is a complete hack.
1165 CXCursor backRefCursor = MakeCXCursorInvalid(CXCursor_InvalidFile, TU);
1166 backRefCursor.data[0] = Vec;
1167 assert(cxcursor::getCursorTU(backRefCursor) == TU);
1168 Vec->push_back(backRefCursor);
1169
1170 // Get the overriden cursors.
1171 cxcursor::getOverriddenCursors(cursor, *Vec);
1172
1173 // Did we get any overriden cursors? If not, return Vec to the pool
1174 // of available cursor vectors.
1175 if (Vec->size() == 1) {
1176 pool.AvailableCursors.push_back(Vec);
1177 return;
1178 }
1179
1180 // Now tell the caller about the overriden cursors.
1181 assert(Vec->size() > 1);
1182 *overridden = &((*Vec)[1]);
1183 *num_overridden = Vec->size() - 1;
1184}
1185
1186void clang_disposeOverriddenCursors(CXCursor *overridden) {
1187 if (!overridden)
1188 return;
1189
1190 // Use pointer arithmetic to get back the first faux entry
1191 // which has a back-reference to the TU and the vector.
1192 --overridden;
1193 OverridenCursorsPool::CursorVec *Vec =
Dmitri Gribenko67812b22013-01-11 21:01:49 +00001194 static_cast<OverridenCursorsPool::CursorVec *>(
1195 const_cast<void *>(overridden->data[0]));
Ted Kremenekbbf66ca2012-04-30 19:06:49 +00001196 CXTranslationUnit TU = getCursorTU(*overridden);
1197
1198 assert(Vec && TU);
1199
1200 OverridenCursorsPool &pool =
1201 *static_cast<OverridenCursorsPool*>(TU->OverridenCursorsPool);
1202
1203 pool.AvailableCursors.push_back(Vec);
1204}
Argyrios Kyrtzidisf39a7ae2012-07-02 23:54:36 +00001205
1206int clang_Cursor_isDynamicCall(CXCursor C) {
1207 const Expr *E = 0;
1208 if (clang_isExpression(C.kind))
1209 E = getCursorExpr(C);
1210 if (!E)
1211 return 0;
1212
1213 if (const ObjCMessageExpr *MsgE = dyn_cast<ObjCMessageExpr>(E))
1214 return MsgE->getReceiverKind() == ObjCMessageExpr::Instance;
1215
1216 const MemberExpr *ME = 0;
1217 if (isa<MemberExpr>(E))
1218 ME = cast<MemberExpr>(E);
1219 else if (const CallExpr *CE = dyn_cast<CallExpr>(E))
1220 ME = dyn_cast_or_null<MemberExpr>(CE->getCallee());
1221
1222 if (ME) {
1223 if (const CXXMethodDecl *
1224 MD = dyn_cast_or_null<CXXMethodDecl>(ME->getMemberDecl()))
1225 return MD->isVirtual() && !ME->hasQualifier();
1226 }
1227
1228 return 0;
1229}
1230
Argyrios Kyrtzidise4a990f2012-11-01 02:01:34 +00001231CXType clang_Cursor_getReceiverType(CXCursor C) {
1232 CXTranslationUnit TU = cxcursor::getCursorTU(C);
1233 const Expr *E = 0;
1234 if (clang_isExpression(C.kind))
1235 E = getCursorExpr(C);
1236
1237 if (const ObjCMessageExpr *MsgE = dyn_cast_or_null<ObjCMessageExpr>(E))
1238 return cxtype::MakeCXType(MsgE->getReceiverType(), TU);
1239
1240 return cxtype::MakeCXType(QualType(), TU);
1241}
1242
Ted Kremenekeca099b2010-12-08 23:43:14 +00001243} // end: extern "C"