blob: df3950478799d7064961118aa47cbf162456717b [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"
Ted Kremenek16c440a2010-01-15 20:35:54 +000021#include "clang/AST/Decl.h"
Douglas Gregor69319002010-08-31 23:48:11 +000022#include "clang/AST/DeclCXX.h"
Douglas Gregor283cae32010-01-15 21:56:13 +000023#include "clang/AST/DeclObjC.h"
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +000024#include "clang/AST/DeclTemplate.h"
Douglas Gregor283cae32010-01-15 21:56:13 +000025#include "clang/AST/Expr.h"
Douglas Gregor1f60d9e2010-09-13 22:52:57 +000026#include "clang/AST/ExprCXX.h"
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +000027#include "clang/AST/ExprObjC.h"
Chandler Carruthf59edb92012-12-04 09:25:21 +000028#include "clang/Frontend/ASTUnit.h"
Ted Kremenekedc8aa62010-01-16 00:36:30 +000029#include "llvm/Support/ErrorHandling.h"
Ted Kremenek16c440a2010-01-15 20:35:54 +000030
31using namespace clang;
Douglas Gregor1f60d9e2010-09-13 22:52:57 +000032using namespace cxcursor;
Ted Kremenek16c440a2010-01-15 20:35:54 +000033
Ted Kremenekbbf66ca2012-04-30 19:06:49 +000034CXCursor cxcursor::MakeCXCursorInvalid(CXCursorKind K, CXTranslationUnit TU) {
Douglas Gregor5bfb8c12010-01-20 23:34:41 +000035 assert(K >= CXCursor_FirstInvalid && K <= CXCursor_LastInvalid);
Ted Kremenekbbf66ca2012-04-30 19:06:49 +000036 CXCursor C = { K, 0, { 0, 0, TU } };
Douglas Gregor5bfb8c12010-01-20 23:34:41 +000037 return C;
Ted Kremenek16c440a2010-01-15 20:35:54 +000038}
39
Ted Kremeneke77f4432010-02-18 03:09:07 +000040static CXCursorKind GetCursorKind(const Attr *A) {
41 assert(A && "Invalid arguments!");
42 switch (A->getKind()) {
43 default: break;
Sean Hunt387475d2010-06-16 23:43:53 +000044 case attr::IBAction: return CXCursor_IBActionAttr;
45 case attr::IBOutlet: return CXCursor_IBOutletAttr;
46 case attr::IBOutletCollection: return CXCursor_IBOutletCollectionAttr;
Argyrios Kyrtzidis6639e922011-09-13 17:39:31 +000047 case attr::Final: return CXCursor_CXXFinalAttr;
48 case attr::Override: return CXCursor_CXXOverrideAttr;
Erik Verbruggen5f1c8222011-10-13 09:41:32 +000049 case attr::Annotate: return CXCursor_AnnotateAttr;
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +000050 case attr::AsmLabel: return CXCursor_AsmLabelAttr;
Ted Kremeneke77f4432010-02-18 03:09:07 +000051 }
52
53 return CXCursor_UnexposedAttr;
54}
55
Dmitri Gribenko05756dc2013-01-14 00:46:27 +000056CXCursor cxcursor::MakeCXCursor(const Attr *A, const Decl *Parent,
Ted Kremeneka60ed472010-11-16 08:15:36 +000057 CXTranslationUnit TU) {
Ted Kremeneke77f4432010-02-18 03:09:07 +000058 assert(A && Parent && TU && "Invalid arguments!");
Dmitri Gribenko33156182013-01-11 21:06:06 +000059 CXCursor C = { GetCursorKind(A), 0, { Parent, A, TU } };
Ted Kremeneke77f4432010-02-18 03:09:07 +000060 return C;
61}
62
Dmitri Gribenko67812b22013-01-11 21:01:49 +000063CXCursor cxcursor::MakeCXCursor(const Decl *D, CXTranslationUnit TU,
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +000064 SourceRange RegionOfInterest,
Ted Kremenek007a7c92010-11-01 23:26:51 +000065 bool FirstInDeclGroup) {
Daniel Dunbar54d67ca2010-01-25 00:40:30 +000066 assert(D && TU && "Invalid arguments!");
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +000067
68 CXCursorKind K = getCursorKindForDecl(D);
69
70 if (K == CXCursor_ObjCClassMethodDecl ||
71 K == CXCursor_ObjCInstanceMethodDecl) {
72 int SelectorIdIndex = -1;
73 // Check if cursor points to a selector id.
74 if (RegionOfInterest.isValid() &&
75 RegionOfInterest.getBegin() == RegionOfInterest.getEnd()) {
76 SmallVector<SourceLocation, 16> SelLocs;
77 cast<ObjCMethodDecl>(D)->getSelectorLocs(SelLocs);
Craig Topper09d19ef2013-07-04 03:08:24 +000078 SmallVectorImpl<SourceLocation>::iterator
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +000079 I=std::find(SelLocs.begin(), SelLocs.end(),RegionOfInterest.getBegin());
80 if (I != SelLocs.end())
81 SelectorIdIndex = I - SelLocs.begin();
82 }
83 CXCursor C = { K, SelectorIdIndex,
84 { D, (void*)(intptr_t) (FirstInDeclGroup ? 1 : 0), TU }};
85 return C;
86 }
87
88 CXCursor C = { K, 0, { D, (void*)(intptr_t) (FirstInDeclGroup ? 1 : 0), TU }};
Douglas Gregor5bfb8c12010-01-20 23:34:41 +000089 return C;
Ted Kremenekedc8aa62010-01-16 00:36:30 +000090}
91
Dmitri Gribenko05756dc2013-01-14 00:46:27 +000092CXCursor cxcursor::MakeCXCursor(const Stmt *S, const Decl *Parent,
Dmitri Gribenko67812b22013-01-11 21:01:49 +000093 CXTranslationUnit TU,
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +000094 SourceRange RegionOfInterest) {
Daniel Dunbar54d67ca2010-01-25 00:40:30 +000095 assert(S && TU && "Invalid arguments!");
Douglas Gregor97b98722010-01-19 23:20:36 +000096 CXCursorKind K = CXCursor_NotImplemented;
97
98 switch (S->getStmtClass()) {
99 case Stmt::NoStmtClass:
100 break;
Douglas Gregor42b29842011-10-05 19:00:14 +0000101
Douglas Gregor97b98722010-01-19 23:20:36 +0000102 case Stmt::CaseStmtClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000103 K = CXCursor_CaseStmt;
104 break;
105
Douglas Gregor97b98722010-01-19 23:20:36 +0000106 case Stmt::DefaultStmtClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000107 K = CXCursor_DefaultStmt;
108 break;
109
110 case Stmt::IfStmtClass:
111 K = CXCursor_IfStmt;
112 break;
113
114 case Stmt::SwitchStmtClass:
115 K = CXCursor_SwitchStmt;
116 break;
117
118 case Stmt::WhileStmtClass:
119 K = CXCursor_WhileStmt;
120 break;
121
122 case Stmt::DoStmtClass:
123 K = CXCursor_DoStmt;
124 break;
125
126 case Stmt::ForStmtClass:
127 K = CXCursor_ForStmt;
128 break;
129
130 case Stmt::GotoStmtClass:
131 K = CXCursor_GotoStmt;
132 break;
133
Douglas Gregor97b98722010-01-19 23:20:36 +0000134 case Stmt::IndirectGotoStmtClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000135 K = CXCursor_IndirectGotoStmt;
136 break;
137
138 case Stmt::ContinueStmtClass:
139 K = CXCursor_ContinueStmt;
140 break;
141
142 case Stmt::BreakStmtClass:
143 K = CXCursor_BreakStmt;
144 break;
145
146 case Stmt::ReturnStmtClass:
147 K = CXCursor_ReturnStmt;
148 break;
149
Chad Rosierdf5faf52012-08-25 00:11:56 +0000150 case Stmt::GCCAsmStmtClass:
151 K = CXCursor_GCCAsmStmt;
Douglas Gregor42b29842011-10-05 19:00:14 +0000152 break;
Chad Rosier8cd64b42012-06-11 20:47:18 +0000153
154 case Stmt::MSAsmStmtClass:
155 K = CXCursor_MSAsmStmt;
156 break;
Douglas Gregor42b29842011-10-05 19:00:14 +0000157
158 case Stmt::ObjCAtTryStmtClass:
159 K = CXCursor_ObjCAtTryStmt;
160 break;
161
162 case Stmt::ObjCAtCatchStmtClass:
163 K = CXCursor_ObjCAtCatchStmt;
164 break;
165
166 case Stmt::ObjCAtFinallyStmtClass:
167 K = CXCursor_ObjCAtFinallyStmt;
168 break;
169
170 case Stmt::ObjCAtThrowStmtClass:
171 K = CXCursor_ObjCAtThrowStmt;
172 break;
173
174 case Stmt::ObjCAtSynchronizedStmtClass:
175 K = CXCursor_ObjCAtSynchronizedStmt;
176 break;
177
178 case Stmt::ObjCAutoreleasePoolStmtClass:
179 K = CXCursor_ObjCAutoreleasePoolStmt;
180 break;
181
Douglas Gregor97b98722010-01-19 23:20:36 +0000182 case Stmt::ObjCForCollectionStmtClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000183 K = CXCursor_ObjCForCollectionStmt;
184 break;
185
Douglas Gregor97b98722010-01-19 23:20:36 +0000186 case Stmt::CXXCatchStmtClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000187 K = CXCursor_CXXCatchStmt;
188 break;
189
190 case Stmt::CXXTryStmtClass:
191 K = CXCursor_CXXTryStmt;
192 break;
193
194 case Stmt::CXXForRangeStmtClass:
195 K = CXCursor_CXXForRangeStmt;
196 break;
197
John Wiegley28bbe4b2011-04-28 01:08:34 +0000198 case Stmt::SEHTryStmtClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000199 K = CXCursor_SEHTryStmt;
200 break;
201
John Wiegley28bbe4b2011-04-28 01:08:34 +0000202 case Stmt::SEHExceptStmtClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000203 K = CXCursor_SEHExceptStmt;
204 break;
205
John Wiegley28bbe4b2011-04-28 01:08:34 +0000206 case Stmt::SEHFinallyStmtClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000207 K = CXCursor_SEHFinallyStmt;
Douglas Gregor97b98722010-01-19 23:20:36 +0000208 break;
Douglas Gregor42b29842011-10-05 19:00:14 +0000209
John Wiegley21ff2e52011-04-28 00:16:57 +0000210 case Stmt::ArrayTypeTraitExprClass:
Tanya Lattner61eee0c2011-06-04 00:47:47 +0000211 case Stmt::AsTypeExprClass:
Eli Friedman276b0612011-10-11 02:20:01 +0000212 case Stmt::AtomicExprClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000213 case Stmt::BinaryConditionalOperatorClass:
214 case Stmt::BinaryTypeTraitExprClass:
Douglas Gregor4ca8ac22012-02-24 07:38:34 +0000215 case Stmt::TypeTraitExprClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000216 case Stmt::CXXBindTemporaryExprClass:
217 case Stmt::CXXDefaultArgExprClass:
Richard Smithc3bf52c2013-04-20 22:23:05 +0000218 case Stmt::CXXDefaultInitExprClass:
Richard Smith7c3e6152013-06-12 22:31:48 +0000219 case Stmt::CXXStdInitializerListExprClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000220 case Stmt::CXXScalarValueInitExprClass:
221 case Stmt::CXXUuidofExprClass:
222 case Stmt::ChooseExprClass:
223 case Stmt::DesignatedInitExprClass:
224 case Stmt::ExprWithCleanupsClass:
225 case Stmt::ExpressionTraitExprClass:
226 case Stmt::ExtVectorElementExprClass:
227 case Stmt::ImplicitCastExprClass:
228 case Stmt::ImplicitValueInitExprClass:
229 case Stmt::MaterializeTemporaryExprClass:
230 case Stmt::ObjCIndirectCopyRestoreExprClass:
231 case Stmt::OffsetOfExprClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000232 case Stmt::ParenListExprClass:
233 case Stmt::PredefinedExprClass:
234 case Stmt::ShuffleVectorExprClass:
235 case Stmt::UnaryExprOrTypeTraitExprClass:
236 case Stmt::UnaryTypeTraitExprClass:
237 case Stmt::VAArgExprClass:
Ted Kremenekb3f75422012-03-06 20:06:06 +0000238 case Stmt::ObjCArrayLiteralClass:
239 case Stmt::ObjCDictionaryLiteralClass:
Patrick Beardeb382ec2012-04-19 00:25:12 +0000240 case Stmt::ObjCBoxedExprClass:
Ted Kremenekb3f75422012-03-06 20:06:06 +0000241 case Stmt::ObjCSubscriptRefExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000242 K = CXCursor_UnexposedExpr;
243 break;
Douglas Gregor42b29842011-10-05 19:00:14 +0000244
John McCall4b9c2d22011-11-06 09:01:30 +0000245 case Stmt::OpaqueValueExprClass:
246 if (Expr *Src = cast<OpaqueValueExpr>(S)->getSourceExpr())
247 return MakeCXCursor(Src, Parent, TU, RegionOfInterest);
248 K = CXCursor_UnexposedExpr;
249 break;
250
251 case Stmt::PseudoObjectExprClass:
252 return MakeCXCursor(cast<PseudoObjectExpr>(S)->getSyntacticForm(),
253 Parent, TU, RegionOfInterest);
254
Douglas Gregor42b29842011-10-05 19:00:14 +0000255 case Stmt::CompoundStmtClass:
256 K = CXCursor_CompoundStmt;
257 break;
Richard Smith534986f2012-04-14 00:33:13 +0000258
Douglas Gregor42b29842011-10-05 19:00:14 +0000259 case Stmt::NullStmtClass:
260 K = CXCursor_NullStmt;
261 break;
Richard Smith534986f2012-04-14 00:33:13 +0000262
Douglas Gregor42b29842011-10-05 19:00:14 +0000263 case Stmt::LabelStmtClass:
264 K = CXCursor_LabelStmt;
265 break;
Richard Smith534986f2012-04-14 00:33:13 +0000266
267 case Stmt::AttributedStmtClass:
268 K = CXCursor_UnexposedStmt;
269 break;
270
Douglas Gregor42b29842011-10-05 19:00:14 +0000271 case Stmt::DeclStmtClass:
272 K = CXCursor_DeclStmt;
273 break;
Richard Smith534986f2012-04-14 00:33:13 +0000274
Tareq A. Siraj051303c2013-04-16 18:53:08 +0000275 case Stmt::CapturedStmtClass:
276 K = CXCursor_UnexposedStmt;
277 break;
278
Douglas Gregor42b29842011-10-05 19:00:14 +0000279 case Stmt::IntegerLiteralClass:
280 K = CXCursor_IntegerLiteral;
281 break;
282
283 case Stmt::FloatingLiteralClass:
284 K = CXCursor_FloatingLiteral;
285 break;
286
287 case Stmt::ImaginaryLiteralClass:
288 K = CXCursor_ImaginaryLiteral;
289 break;
290
291 case Stmt::StringLiteralClass:
292 K = CXCursor_StringLiteral;
293 break;
294
295 case Stmt::CharacterLiteralClass:
296 K = CXCursor_CharacterLiteral;
297 break;
298
299 case Stmt::ParenExprClass:
300 K = CXCursor_ParenExpr;
301 break;
302
303 case Stmt::UnaryOperatorClass:
304 K = CXCursor_UnaryOperator;
305 break;
Richard Smith534986f2012-04-14 00:33:13 +0000306
Douglas Gregor42b29842011-10-05 19:00:14 +0000307 case Stmt::CXXNoexceptExprClass:
308 K = CXCursor_UnaryExpr;
309 break;
310
311 case Stmt::ArraySubscriptExprClass:
312 K = CXCursor_ArraySubscriptExpr;
313 break;
314
315 case Stmt::BinaryOperatorClass:
316 K = CXCursor_BinaryOperator;
317 break;
318
319 case Stmt::CompoundAssignOperatorClass:
320 K = CXCursor_CompoundAssignOperator;
321 break;
322
323 case Stmt::ConditionalOperatorClass:
324 K = CXCursor_ConditionalOperator;
325 break;
326
327 case Stmt::CStyleCastExprClass:
328 K = CXCursor_CStyleCastExpr;
329 break;
330
331 case Stmt::CompoundLiteralExprClass:
332 K = CXCursor_CompoundLiteralExpr;
333 break;
334
335 case Stmt::InitListExprClass:
336 K = CXCursor_InitListExpr;
337 break;
338
339 case Stmt::AddrLabelExprClass:
340 K = CXCursor_AddrLabelExpr;
341 break;
342
343 case Stmt::StmtExprClass:
344 K = CXCursor_StmtExpr;
345 break;
346
347 case Stmt::GenericSelectionExprClass:
348 K = CXCursor_GenericSelectionExpr;
349 break;
350
351 case Stmt::GNUNullExprClass:
352 K = CXCursor_GNUNullExpr;
353 break;
354
355 case Stmt::CXXStaticCastExprClass:
356 K = CXCursor_CXXStaticCastExpr;
357 break;
358
359 case Stmt::CXXDynamicCastExprClass:
360 K = CXCursor_CXXDynamicCastExpr;
361 break;
362
363 case Stmt::CXXReinterpretCastExprClass:
364 K = CXCursor_CXXReinterpretCastExpr;
365 break;
366
367 case Stmt::CXXConstCastExprClass:
368 K = CXCursor_CXXConstCastExpr;
369 break;
370
371 case Stmt::CXXFunctionalCastExprClass:
372 K = CXCursor_CXXFunctionalCastExpr;
373 break;
374
375 case Stmt::CXXTypeidExprClass:
376 K = CXCursor_CXXTypeidExpr;
377 break;
378
379 case Stmt::CXXBoolLiteralExprClass:
380 K = CXCursor_CXXBoolLiteralExpr;
381 break;
382
383 case Stmt::CXXNullPtrLiteralExprClass:
384 K = CXCursor_CXXNullPtrLiteralExpr;
385 break;
386
387 case Stmt::CXXThisExprClass:
388 K = CXCursor_CXXThisExpr;
389 break;
390
391 case Stmt::CXXThrowExprClass:
392 K = CXCursor_CXXThrowExpr;
393 break;
394
395 case Stmt::CXXNewExprClass:
396 K = CXCursor_CXXNewExpr;
397 break;
398
399 case Stmt::CXXDeleteExprClass:
400 K = CXCursor_CXXDeleteExpr;
401 break;
402
403 case Stmt::ObjCStringLiteralClass:
404 K = CXCursor_ObjCStringLiteral;
405 break;
406
407 case Stmt::ObjCEncodeExprClass:
408 K = CXCursor_ObjCEncodeExpr;
409 break;
410
411 case Stmt::ObjCSelectorExprClass:
412 K = CXCursor_ObjCSelectorExpr;
413 break;
414
415 case Stmt::ObjCProtocolExprClass:
416 K = CXCursor_ObjCProtocolExpr;
417 break;
Ted Kremenekb3f75422012-03-06 20:06:06 +0000418
419 case Stmt::ObjCBoolLiteralExprClass:
420 K = CXCursor_ObjCBoolLiteralExpr;
421 break;
422
Douglas Gregor42b29842011-10-05 19:00:14 +0000423 case Stmt::ObjCBridgedCastExprClass:
424 K = CXCursor_ObjCBridgedCastExpr;
425 break;
426
427 case Stmt::BlockExprClass:
428 K = CXCursor_BlockExpr;
429 break;
430
431 case Stmt::PackExpansionExprClass:
432 K = CXCursor_PackExpansionExpr;
433 break;
434
435 case Stmt::SizeOfPackExprClass:
436 K = CXCursor_SizeOfPackExpr;
437 break;
438
Argyrios Kyrtzidisedab0472013-04-23 17:57:17 +0000439 case Stmt::DeclRefExprClass:
440 if (const ImplicitParamDecl *IPD =
441 dyn_cast_or_null<ImplicitParamDecl>(cast<DeclRefExpr>(S)->getDecl())) {
442 if (const ObjCMethodDecl *MD =
443 dyn_cast<ObjCMethodDecl>(IPD->getDeclContext())) {
444 if (MD->getSelfDecl() == IPD) {
445 K = CXCursor_ObjCSelfExpr;
446 break;
447 }
448 }
449 }
450
451 K = CXCursor_DeclRefExpr;
452 break;
453
Douglas Gregor42b29842011-10-05 19:00:14 +0000454 case Stmt::DependentScopeDeclRefExprClass:
John McCall91a57552011-07-15 05:09:51 +0000455 case Stmt::SubstNonTypeTemplateParmExprClass:
Douglas Gregorc7793c72011-01-15 01:15:58 +0000456 case Stmt::SubstNonTypeTemplateParmPackExprClass:
Richard Smith9a4db032012-09-12 00:56:43 +0000457 case Stmt::FunctionParmPackExprClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000458 case Stmt::UnresolvedLookupExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000459 K = CXCursor_DeclRefExpr;
460 break;
461
Douglas Gregor42b29842011-10-05 19:00:14 +0000462 case Stmt::CXXDependentScopeMemberExprClass:
463 case Stmt::CXXPseudoDestructorExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000464 case Stmt::MemberExprClass:
John McCall76da55d2013-04-16 07:28:30 +0000465 case Stmt::MSPropertyRefExprClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000466 case Stmt::ObjCIsaExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000467 case Stmt::ObjCIvarRefExprClass:
468 case Stmt::ObjCPropertyRefExprClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000469 case Stmt::UnresolvedMemberExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000470 K = CXCursor_MemberRefExpr;
471 break;
472
473 case Stmt::CallExprClass:
474 case Stmt::CXXOperatorCallExprClass:
475 case Stmt::CXXMemberCallExprClass:
Peter Collingbournee08ce652011-02-09 21:07:24 +0000476 case Stmt::CUDAKernelCallExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000477 case Stmt::CXXConstructExprClass:
478 case Stmt::CXXTemporaryObjectExprClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000479 case Stmt::CXXUnresolvedConstructExprClass:
Richard Smith9fcce652012-03-07 08:35:16 +0000480 case Stmt::UserDefinedLiteralClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000481 K = CXCursor_CallExpr;
482 break;
483
Douglas Gregor011d8b92012-02-15 00:54:55 +0000484 case Stmt::LambdaExprClass:
485 K = CXCursor_LambdaExpr;
486 break;
487
Douglas Gregorba0513d2011-10-25 01:33:02 +0000488 case Stmt::ObjCMessageExprClass: {
Douglas Gregor97b98722010-01-19 23:20:36 +0000489 K = CXCursor_ObjCMessageExpr;
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000490 int SelectorIdIndex = -1;
491 // Check if cursor points to a selector id.
492 if (RegionOfInterest.isValid() &&
493 RegionOfInterest.getBegin() == RegionOfInterest.getEnd()) {
494 SmallVector<SourceLocation, 16> SelLocs;
495 cast<ObjCMessageExpr>(S)->getSelectorLocs(SelLocs);
Craig Topper09d19ef2013-07-04 03:08:24 +0000496 SmallVectorImpl<SourceLocation>::iterator
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000497 I=std::find(SelLocs.begin(), SelLocs.end(),RegionOfInterest.getBegin());
498 if (I != SelLocs.end())
499 SelectorIdIndex = I - SelLocs.begin();
500 }
501 CXCursor C = { K, 0, { Parent, S, TU } };
502 return getSelectorIdentifierCursor(SelectorIdIndex, C);
Douglas Gregor97b98722010-01-19 23:20:36 +0000503 }
Douglas Gregorba0513d2011-10-25 01:33:02 +0000504
505 case Stmt::MSDependentExistsStmtClass:
506 K = CXCursor_UnexposedStmt;
507 break;
Alexey Bataev4fa7eab2013-07-19 03:13:43 +0000508 case Stmt::OMPParallelDirectiveClass:
509 K = CXCursor_OMPParallelDirective;
510 break;
511
Douglas Gregorba0513d2011-10-25 01:33:02 +0000512 }
Douglas Gregor97b98722010-01-19 23:20:36 +0000513
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000514 CXCursor C = { K, 0, { Parent, S, TU } };
Douglas Gregor97b98722010-01-19 23:20:36 +0000515 return C;
516}
517
Douglas Gregor2e331b92010-01-16 14:00:32 +0000518CXCursor cxcursor::MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super,
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000519 SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000520 CXTranslationUnit TU) {
Daniel Dunbar54d67ca2010-01-25 00:40:30 +0000521 assert(Super && TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000522 void *RawLoc = Loc.getPtrEncoding();
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000523 CXCursor C = { CXCursor_ObjCSuperClassRef, 0, { Super, RawLoc, TU } };
Douglas Gregor2e331b92010-01-16 14:00:32 +0000524 return C;
525}
526
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000527std::pair<const ObjCInterfaceDecl *, SourceLocation>
Douglas Gregor2e331b92010-01-16 14:00:32 +0000528cxcursor::getCursorObjCSuperClassRef(CXCursor C) {
529 assert(C.kind == CXCursor_ObjCSuperClassRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000530 return std::make_pair(static_cast<const ObjCInterfaceDecl *>(C.data[0]),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000531 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregor2e331b92010-01-16 14:00:32 +0000532}
533
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +0000534CXCursor cxcursor::MakeCursorObjCProtocolRef(const ObjCProtocolDecl *Proto,
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000535 SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000536 CXTranslationUnit TU) {
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +0000537 assert(Proto && TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000538 void *RawLoc = Loc.getPtrEncoding();
Dmitri Gribenko33156182013-01-11 21:06:06 +0000539 CXCursor C = { CXCursor_ObjCProtocolRef, 0, { Proto, RawLoc, TU } };
Douglas Gregor78db0cd2010-01-16 15:44:18 +0000540 return C;
541}
542
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000543std::pair<const ObjCProtocolDecl *, SourceLocation>
Douglas Gregor78db0cd2010-01-16 15:44:18 +0000544cxcursor::getCursorObjCProtocolRef(CXCursor C) {
545 assert(C.kind == CXCursor_ObjCProtocolRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000546 return std::make_pair(static_cast<const ObjCProtocolDecl *>(C.data[0]),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000547 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregor78db0cd2010-01-16 15:44:18 +0000548}
549
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +0000550CXCursor cxcursor::MakeCursorObjCClassRef(const ObjCInterfaceDecl *Class,
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000551 SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000552 CXTranslationUnit TU) {
Ted Kremenekebfa3392010-03-19 20:39:03 +0000553 // 'Class' can be null for invalid code.
554 if (!Class)
555 return MakeCXCursorInvalid(CXCursor_InvalidCode);
556 assert(TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000557 void *RawLoc = Loc.getPtrEncoding();
Dmitri Gribenko33156182013-01-11 21:06:06 +0000558 CXCursor C = { CXCursor_ObjCClassRef, 0, { Class, RawLoc, TU } };
Douglas Gregor1adb0822010-01-16 17:14:40 +0000559 return C;
560}
561
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000562std::pair<const ObjCInterfaceDecl *, SourceLocation>
Douglas Gregor1adb0822010-01-16 17:14:40 +0000563cxcursor::getCursorObjCClassRef(CXCursor C) {
564 assert(C.kind == CXCursor_ObjCClassRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000565 return std::make_pair(static_cast<const ObjCInterfaceDecl *>(C.data[0]),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000566 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregor1adb0822010-01-16 17:14:40 +0000567}
568
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +0000569CXCursor cxcursor::MakeCursorTypeRef(const TypeDecl *Type, SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000570 CXTranslationUnit TU) {
Daniel Dunbar54d67ca2010-01-25 00:40:30 +0000571 assert(Type && TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000572 void *RawLoc = Loc.getPtrEncoding();
Dmitri Gribenko33156182013-01-11 21:06:06 +0000573 CXCursor C = { CXCursor_TypeRef, 0, { Type, RawLoc, TU } };
Douglas Gregor7d0d40e2010-01-21 16:28:34 +0000574 return C;
575}
576
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000577std::pair<const TypeDecl *, SourceLocation>
Douglas Gregor7d0d40e2010-01-21 16:28:34 +0000578cxcursor::getCursorTypeRef(CXCursor C) {
579 assert(C.kind == CXCursor_TypeRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000580 return std::make_pair(static_cast<const TypeDecl *>(C.data[0]),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000581 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregor7d0d40e2010-01-21 16:28:34 +0000582}
583
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +0000584CXCursor cxcursor::MakeCursorTemplateRef(const TemplateDecl *Template,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000585 SourceLocation Loc,
586 CXTranslationUnit TU) {
Douglas Gregor0b36e612010-08-31 20:37:03 +0000587 assert(Template && TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000588 void *RawLoc = Loc.getPtrEncoding();
Dmitri Gribenko33156182013-01-11 21:06:06 +0000589 CXCursor C = { CXCursor_TemplateRef, 0, { Template, RawLoc, TU } };
Douglas Gregor0b36e612010-08-31 20:37:03 +0000590 return C;
591}
592
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000593std::pair<const TemplateDecl *, SourceLocation>
Douglas Gregor0b36e612010-08-31 20:37:03 +0000594cxcursor::getCursorTemplateRef(CXCursor C) {
595 assert(C.kind == CXCursor_TemplateRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000596 return std::make_pair(static_cast<const TemplateDecl *>(C.data[0]),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000597 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregor0b36e612010-08-31 20:37:03 +0000598}
599
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +0000600CXCursor cxcursor::MakeCursorNamespaceRef(const NamedDecl *NS,
601 SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000602 CXTranslationUnit TU) {
Douglas Gregor69319002010-08-31 23:48:11 +0000603
604 assert(NS && (isa<NamespaceDecl>(NS) || isa<NamespaceAliasDecl>(NS)) && TU &&
605 "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000606 void *RawLoc = Loc.getPtrEncoding();
Dmitri Gribenko33156182013-01-11 21:06:06 +0000607 CXCursor C = { CXCursor_NamespaceRef, 0, { NS, RawLoc, TU } };
Douglas Gregor69319002010-08-31 23:48:11 +0000608 return C;
609}
610
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000611std::pair<const NamedDecl *, SourceLocation>
Douglas Gregor69319002010-08-31 23:48:11 +0000612cxcursor::getCursorNamespaceRef(CXCursor C) {
613 assert(C.kind == CXCursor_NamespaceRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000614 return std::make_pair(static_cast<const NamedDecl *>(C.data[0]),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000615 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregor69319002010-08-31 23:48:11 +0000616}
617
Douglas Gregor011d8b92012-02-15 00:54:55 +0000618CXCursor cxcursor::MakeCursorVariableRef(const VarDecl *Var, SourceLocation Loc,
619 CXTranslationUnit TU) {
620
621 assert(Var && TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000622 void *RawLoc = Loc.getPtrEncoding();
Dmitri Gribenko33156182013-01-11 21:06:06 +0000623 CXCursor C = { CXCursor_VariableRef, 0, { Var, RawLoc, TU } };
Douglas Gregor011d8b92012-02-15 00:54:55 +0000624 return C;
625}
626
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000627std::pair<const VarDecl *, SourceLocation>
Douglas Gregor011d8b92012-02-15 00:54:55 +0000628cxcursor::getCursorVariableRef(CXCursor C) {
629 assert(C.kind == CXCursor_VariableRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000630 return std::make_pair(static_cast<const VarDecl *>(C.data[0]),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000631 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregor011d8b92012-02-15 00:54:55 +0000632}
633
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +0000634CXCursor cxcursor::MakeCursorMemberRef(const FieldDecl *Field, SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000635 CXTranslationUnit TU) {
Douglas Gregora67e03f2010-09-09 21:42:20 +0000636
637 assert(Field && TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000638 void *RawLoc = Loc.getPtrEncoding();
Dmitri Gribenko33156182013-01-11 21:06:06 +0000639 CXCursor C = { CXCursor_MemberRef, 0, { Field, RawLoc, TU } };
Douglas Gregora67e03f2010-09-09 21:42:20 +0000640 return C;
641}
642
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000643std::pair<const FieldDecl *, SourceLocation>
Douglas Gregora67e03f2010-09-09 21:42:20 +0000644cxcursor::getCursorMemberRef(CXCursor C) {
645 assert(C.kind == CXCursor_MemberRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000646 return std::make_pair(static_cast<const FieldDecl *>(C.data[0]),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000647 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregora67e03f2010-09-09 21:42:20 +0000648}
649
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +0000650CXCursor cxcursor::MakeCursorCXXBaseSpecifier(const CXXBaseSpecifier *B,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000651 CXTranslationUnit TU){
Dmitri Gribenko33156182013-01-11 21:06:06 +0000652 CXCursor C = { CXCursor_CXXBaseSpecifier, 0, { B, 0, TU } };
Ted Kremenek3064ef92010-08-27 21:34:58 +0000653 return C;
654}
655
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000656const CXXBaseSpecifier *cxcursor::getCursorCXXBaseSpecifier(CXCursor C) {
Ted Kremenek3064ef92010-08-27 21:34:58 +0000657 assert(C.kind == CXCursor_CXXBaseSpecifier);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000658 return static_cast<const CXXBaseSpecifier*>(C.data[0]);
Ted Kremenek3064ef92010-08-27 21:34:58 +0000659}
660
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +0000661CXCursor cxcursor::MakePreprocessingDirectiveCursor(SourceRange Range,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000662 CXTranslationUnit TU) {
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000663 CXCursor C = { CXCursor_PreprocessingDirective, 0,
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000664 { Range.getBegin().getPtrEncoding(),
665 Range.getEnd().getPtrEncoding(),
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +0000666 TU }
667 };
668 return C;
669}
670
671SourceRange cxcursor::getCursorPreprocessingDirective(CXCursor C) {
672 assert(C.kind == CXCursor_PreprocessingDirective);
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000673 SourceRange Range(SourceLocation::getFromPtrEncoding(C.data[0]),
674 SourceLocation::getFromPtrEncoding(C.data[1]));
Argyrios Kyrtzidisee0f84f2011-09-26 08:01:41 +0000675 ASTUnit *TU = getCursorASTUnit(C);
676 return TU->mapRangeFromPreamble(Range);
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +0000677}
678
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000679CXCursor cxcursor::MakeMacroDefinitionCursor(const MacroDefinition *MI,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000680 CXTranslationUnit TU) {
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000681 CXCursor C = { CXCursor_MacroDefinition, 0, { MI, 0, TU } };
Douglas Gregor572feb22010-03-18 18:04:21 +0000682 return C;
683}
684
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000685const MacroDefinition *cxcursor::getCursorMacroDefinition(CXCursor C) {
Douglas Gregor572feb22010-03-18 18:04:21 +0000686 assert(C.kind == CXCursor_MacroDefinition);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000687 return static_cast<const MacroDefinition *>(C.data[0]);
Douglas Gregor572feb22010-03-18 18:04:21 +0000688}
689
Chandler Carruth9e5bb852011-07-14 08:20:46 +0000690CXCursor cxcursor::MakeMacroExpansionCursor(MacroExpansion *MI,
691 CXTranslationUnit TU) {
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000692 CXCursor C = { CXCursor_MacroExpansion, 0, { MI, 0, TU } };
Douglas Gregor48072312010-03-18 15:23:44 +0000693 return C;
694}
695
Argyrios Kyrtzidis664b06f2013-01-07 19:16:25 +0000696CXCursor cxcursor::MakeMacroExpansionCursor(MacroDefinition *MI,
697 SourceLocation Loc,
698 CXTranslationUnit TU) {
699 assert(Loc.isValid());
700 CXCursor C = { CXCursor_MacroExpansion, 0, { MI, Loc.getPtrEncoding(), TU } };
701 return C;
702}
703
704const IdentifierInfo *cxcursor::MacroExpansionCursor::getName() const {
705 if (isPseudo())
706 return getAsMacroDefinition()->getName();
707 return getAsMacroExpansion()->getName();
708}
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000709const MacroDefinition *cxcursor::MacroExpansionCursor::getDefinition() const {
Argyrios Kyrtzidis664b06f2013-01-07 19:16:25 +0000710 if (isPseudo())
711 return getAsMacroDefinition();
712 return getAsMacroExpansion()->getDefinition();
713}
714SourceRange cxcursor::MacroExpansionCursor::getSourceRange() const {
715 if (isPseudo())
716 return getPseudoLoc();
717 return getAsMacroExpansion()->getSourceRange();
Douglas Gregor48072312010-03-18 15:23:44 +0000718}
719
Douglas Gregorecdcb882010-10-20 22:00:55 +0000720CXCursor cxcursor::MakeInclusionDirectiveCursor(InclusionDirective *ID,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000721 CXTranslationUnit TU) {
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000722 CXCursor C = { CXCursor_InclusionDirective, 0, { ID, 0, TU } };
Douglas Gregorecdcb882010-10-20 22:00:55 +0000723 return C;
724}
725
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000726const InclusionDirective *cxcursor::getCursorInclusionDirective(CXCursor C) {
Douglas Gregorecdcb882010-10-20 22:00:55 +0000727 assert(C.kind == CXCursor_InclusionDirective);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000728 return static_cast<const InclusionDirective *>(C.data[0]);
Douglas Gregorecdcb882010-10-20 22:00:55 +0000729}
730
Douglas Gregor36897b02010-09-10 00:22:18 +0000731CXCursor cxcursor::MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000732 CXTranslationUnit TU) {
Douglas Gregor36897b02010-09-10 00:22:18 +0000733
734 assert(Label && TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000735 void *RawLoc = Loc.getPtrEncoding();
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000736 CXCursor C = { CXCursor_LabelRef, 0, { Label, RawLoc, TU } };
Douglas Gregor36897b02010-09-10 00:22:18 +0000737 return C;
738}
739
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000740std::pair<const LabelStmt *, SourceLocation>
Douglas Gregor36897b02010-09-10 00:22:18 +0000741cxcursor::getCursorLabelRef(CXCursor C) {
742 assert(C.kind == CXCursor_LabelRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000743 return std::make_pair(static_cast<const LabelStmt *>(C.data[0]),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000744 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregor36897b02010-09-10 00:22:18 +0000745}
746
Dmitri Gribenkoe22339c2013-01-23 17:25:27 +0000747CXCursor cxcursor::MakeCursorOverloadedDeclRef(const OverloadExpr *E,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000748 CXTranslationUnit TU) {
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000749 assert(E && TU && "Invalid arguments!");
750 OverloadedDeclRefStorage Storage(E);
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000751 void *RawLoc = E->getNameLoc().getPtrEncoding();
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000752 CXCursor C = {
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000753 CXCursor_OverloadedDeclRef, 0,
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000754 { Storage.getOpaqueValue(), RawLoc, TU }
755 };
756 return C;
757}
758
Dmitri Gribenkoe22339c2013-01-23 17:25:27 +0000759CXCursor cxcursor::MakeCursorOverloadedDeclRef(const Decl *D,
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000760 SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000761 CXTranslationUnit TU) {
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000762 assert(D && TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000763 void *RawLoc = Loc.getPtrEncoding();
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000764 OverloadedDeclRefStorage Storage(D);
765 CXCursor C = {
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000766 CXCursor_OverloadedDeclRef, 0,
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000767 { Storage.getOpaqueValue(), RawLoc, TU }
768 };
769 return C;
770}
771
772CXCursor cxcursor::MakeCursorOverloadedDeclRef(TemplateName Name,
773 SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000774 CXTranslationUnit TU) {
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000775 assert(Name.getAsOverloadedTemplate() && TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000776 void *RawLoc = Loc.getPtrEncoding();
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000777 OverloadedDeclRefStorage Storage(Name.getAsOverloadedTemplate());
778 CXCursor C = {
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000779 CXCursor_OverloadedDeclRef, 0,
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000780 { Storage.getOpaqueValue(), RawLoc, TU }
781 };
782 return C;
783}
784
785std::pair<cxcursor::OverloadedDeclRefStorage, SourceLocation>
786cxcursor::getCursorOverloadedDeclRef(CXCursor C) {
787 assert(C.kind == CXCursor_OverloadedDeclRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000788 return std::make_pair(OverloadedDeclRefStorage::getFromOpaqueValue(
789 const_cast<void *>(C.data[0])),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000790 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000791}
792
Dmitri Gribenkoe22339c2013-01-23 17:25:27 +0000793const Decl *cxcursor::getCursorDecl(CXCursor Cursor) {
794 return static_cast<const Decl *>(Cursor.data[0]);
Douglas Gregor283cae32010-01-15 21:56:13 +0000795}
796
Dmitri Gribenkoff74f962013-01-26 15:29:08 +0000797const Expr *cxcursor::getCursorExpr(CXCursor Cursor) {
Douglas Gregor283cae32010-01-15 21:56:13 +0000798 return dyn_cast_or_null<Expr>(getCursorStmt(Cursor));
799}
800
Dmitri Gribenkoff74f962013-01-26 15:29:08 +0000801const Stmt *cxcursor::getCursorStmt(CXCursor Cursor) {
Douglas Gregor78db0cd2010-01-16 15:44:18 +0000802 if (Cursor.kind == CXCursor_ObjCSuperClassRef ||
Douglas Gregor1adb0822010-01-16 17:14:40 +0000803 Cursor.kind == CXCursor_ObjCProtocolRef ||
804 Cursor.kind == CXCursor_ObjCClassRef)
Douglas Gregor2e331b92010-01-16 14:00:32 +0000805 return 0;
806
Dmitri Gribenkoff74f962013-01-26 15:29:08 +0000807 return static_cast<const Stmt *>(Cursor.data[1]);
Douglas Gregor283cae32010-01-15 21:56:13 +0000808}
809
Dmitri Gribenko7d914382013-01-26 18:08:08 +0000810const Attr *cxcursor::getCursorAttr(CXCursor Cursor) {
811 return static_cast<const Attr *>(Cursor.data[1]);
Ted Kremenek95f33552010-08-26 01:42:22 +0000812}
813
Dmitri Gribenko404628c2013-01-26 18:12:08 +0000814const Decl *cxcursor::getCursorParentDecl(CXCursor Cursor) {
815 return static_cast<const Decl *>(Cursor.data[0]);
Argyrios Kyrtzidis8ccac3d2011-06-29 22:20:07 +0000816}
817
Douglas Gregorf46034a2010-01-18 23:41:10 +0000818ASTContext &cxcursor::getCursorContext(CXCursor Cursor) {
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000819 return getCursorASTUnit(Cursor)->getASTContext();
820}
Douglas Gregorf46034a2010-01-18 23:41:10 +0000821
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000822ASTUnit *cxcursor::getCursorASTUnit(CXCursor Cursor) {
Dmitri Gribenko46f92522013-01-11 19:28:44 +0000823 CXTranslationUnit TU = getCursorTU(Cursor);
Argyrios Kyrtzidis44517462011-12-09 00:17:49 +0000824 if (!TU)
825 return 0;
Dmitri Gribenko5694feb2013-01-26 18:53:38 +0000826 return cxtu::getASTUnit(TU);
Ted Kremeneka60ed472010-11-16 08:15:36 +0000827}
828
829CXTranslationUnit cxcursor::getCursorTU(CXCursor Cursor) {
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000830 return static_cast<CXTranslationUnit>(const_cast<void*>(Cursor.data[2]));
Douglas Gregor283cae32010-01-15 21:56:13 +0000831}
832
Argyrios Kyrtzidise15db6f2012-05-09 16:12:57 +0000833void cxcursor::getOverriddenCursors(CXCursor cursor,
834 SmallVectorImpl<CXCursor> &overridden) {
835 assert(clang_isDeclaration(cursor.kind));
Argyrios Kyrtzidis21c36072012-10-09 01:23:50 +0000836 const NamedDecl *D = dyn_cast_or_null<NamedDecl>(getCursorDecl(cursor));
Argyrios Kyrtzidise15db6f2012-05-09 16:12:57 +0000837 if (!D)
838 return;
839
Argyrios Kyrtzidise15db6f2012-05-09 16:12:57 +0000840 CXTranslationUnit TU = getCursorTU(cursor);
Argyrios Kyrtzidis21c36072012-10-09 01:23:50 +0000841 SmallVector<const NamedDecl *, 8> OverDecls;
842 D->getASTContext().getOverriddenMethods(D, OverDecls);
Argyrios Kyrtzidise15db6f2012-05-09 16:12:57 +0000843
Craig Topper09d19ef2013-07-04 03:08:24 +0000844 for (SmallVectorImpl<const NamedDecl *>::iterator
Argyrios Kyrtzidis21c36072012-10-09 01:23:50 +0000845 I = OverDecls.begin(), E = OverDecls.end(); I != E; ++I) {
Dmitri Gribenko05756dc2013-01-14 00:46:27 +0000846 overridden.push_back(MakeCXCursor(*I, TU));
Argyrios Kyrtzidise15db6f2012-05-09 16:12:57 +0000847 }
848}
849
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000850std::pair<int, SourceLocation>
851cxcursor::getSelectorIdentifierIndexAndLoc(CXCursor cursor) {
852 if (cursor.kind == CXCursor_ObjCMessageExpr) {
853 if (cursor.xdata != -1)
854 return std::make_pair(cursor.xdata,
855 cast<ObjCMessageExpr>(getCursorExpr(cursor))
856 ->getSelectorLoc(cursor.xdata));
857 } else if (cursor.kind == CXCursor_ObjCClassMethodDecl ||
858 cursor.kind == CXCursor_ObjCInstanceMethodDecl) {
859 if (cursor.xdata != -1)
860 return std::make_pair(cursor.xdata,
861 cast<ObjCMethodDecl>(getCursorDecl(cursor))
862 ->getSelectorLoc(cursor.xdata));
863 }
864
865 return std::make_pair(-1, SourceLocation());
866}
867
868CXCursor cxcursor::getSelectorIdentifierCursor(int SelIdx, CXCursor cursor) {
869 CXCursor newCursor = cursor;
870
871 if (cursor.kind == CXCursor_ObjCMessageExpr) {
872 if (SelIdx == -1 ||
873 unsigned(SelIdx) >= cast<ObjCMessageExpr>(getCursorExpr(cursor))
874 ->getNumSelectorLocs())
875 newCursor.xdata = -1;
876 else
877 newCursor.xdata = SelIdx;
878 } else if (cursor.kind == CXCursor_ObjCClassMethodDecl ||
879 cursor.kind == CXCursor_ObjCInstanceMethodDecl) {
880 if (SelIdx == -1 ||
881 unsigned(SelIdx) >= cast<ObjCMethodDecl>(getCursorDecl(cursor))
882 ->getNumSelectorLocs())
883 newCursor.xdata = -1;
884 else
885 newCursor.xdata = SelIdx;
886 }
887
888 return newCursor;
889}
890
891CXCursor cxcursor::getTypeRefCursor(CXCursor cursor) {
892 if (cursor.kind != CXCursor_CallExpr)
893 return cursor;
894
895 if (cursor.xdata == 0)
896 return cursor;
897
Dmitri Gribenkoff74f962013-01-26 15:29:08 +0000898 const Expr *E = getCursorExpr(cursor);
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000899 TypeSourceInfo *Type = 0;
Dmitri Gribenkoff74f962013-01-26 15:29:08 +0000900 if (const CXXUnresolvedConstructExpr *
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000901 UnCtor = dyn_cast<CXXUnresolvedConstructExpr>(E)) {
902 Type = UnCtor->getTypeSourceInfo();
Dmitri Gribenkoff74f962013-01-26 15:29:08 +0000903 } else if (const CXXTemporaryObjectExpr *Tmp =
904 dyn_cast<CXXTemporaryObjectExpr>(E)){
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000905 Type = Tmp->getTypeSourceInfo();
906 }
907
908 if (!Type)
909 return cursor;
910
911 CXTranslationUnit TU = getCursorTU(cursor);
912 QualType Ty = Type->getType();
913 TypeLoc TL = Type->getTypeLoc();
914 SourceLocation Loc = TL.getBeginLoc();
915
916 if (const ElaboratedType *ElabT = Ty->getAs<ElaboratedType>()) {
917 Ty = ElabT->getNamedType();
David Blaikie39e6ab42013-02-18 22:06:02 +0000918 ElaboratedTypeLoc ElabTL = TL.castAs<ElaboratedTypeLoc>();
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000919 Loc = ElabTL.getNamedTypeLoc().getBeginLoc();
920 }
921
922 if (const TypedefType *Typedef = Ty->getAs<TypedefType>())
923 return MakeCursorTypeRef(Typedef->getDecl(), Loc, TU);
924 if (const TagType *Tag = Ty->getAs<TagType>())
925 return MakeCursorTypeRef(Tag->getDecl(), Loc, TU);
926 if (const TemplateTypeParmType *TemplP = Ty->getAs<TemplateTypeParmType>())
927 return MakeCursorTypeRef(TemplP->getDecl(), Loc, TU);
928
929 return cursor;
930}
931
Douglas Gregor283cae32010-01-15 21:56:13 +0000932bool cxcursor::operator==(CXCursor X, CXCursor Y) {
933 return X.kind == Y.kind && X.data[0] == Y.data[0] && X.data[1] == Y.data[1] &&
934 X.data[2] == Y.data[2];
Douglas Gregor2e331b92010-01-16 14:00:32 +0000935}
Ted Kremenek007a7c92010-11-01 23:26:51 +0000936
937// FIXME: Remove once we can model DeclGroups and their appropriate ranges
938// properly in the ASTs.
939bool cxcursor::isFirstInDeclGroup(CXCursor C) {
940 assert(clang_isDeclaration(C.kind));
941 return ((uintptr_t) (C.data[1])) != 0;
942}
943
Ted Kremenekeca099b2010-12-08 23:43:14 +0000944//===----------------------------------------------------------------------===//
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +0000945// libclang CXCursor APIs
946//===----------------------------------------------------------------------===//
947
Argyrios Kyrtzidisfa865df2011-09-27 04:14:36 +0000948extern "C" {
949
950int clang_Cursor_isNull(CXCursor cursor) {
951 return clang_equalCursors(cursor, clang_getNullCursor());
952}
953
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +0000954CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor cursor) {
955 return getCursorTU(cursor);
956}
957
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +0000958int clang_Cursor_getNumArguments(CXCursor C) {
959 if (clang_isDeclaration(C.kind)) {
Dmitri Gribenkoe22339c2013-01-23 17:25:27 +0000960 const Decl *D = cxcursor::getCursorDecl(C);
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +0000961 if (const ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(D))
962 return MD->param_size();
963 if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
964 return FD->param_size();
965 }
966
Argyrios Kyrtzidise9ebd852013-04-01 17:38:59 +0000967 if (clang_isExpression(C.kind)) {
968 const Expr *E = cxcursor::getCursorExpr(C);
969 if (const CallExpr *CE = dyn_cast<CallExpr>(E)) {
970 return CE->getNumArgs();
971 }
972 }
973
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +0000974 return -1;
975}
976
977CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i) {
978 if (clang_isDeclaration(C.kind)) {
Dmitri Gribenkoe22339c2013-01-23 17:25:27 +0000979 const Decl *D = cxcursor::getCursorDecl(C);
980 if (const ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(D)) {
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +0000981 if (i < MD->param_size())
982 return cxcursor::MakeCXCursor(MD->param_begin()[i],
983 cxcursor::getCursorTU(C));
Dmitri Gribenkoe22339c2013-01-23 17:25:27 +0000984 } else if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) {
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +0000985 if (i < FD->param_size())
986 return cxcursor::MakeCXCursor(FD->param_begin()[i],
987 cxcursor::getCursorTU(C));
988 }
989 }
990
Argyrios Kyrtzidise9ebd852013-04-01 17:38:59 +0000991 if (clang_isExpression(C.kind)) {
992 const Expr *E = cxcursor::getCursorExpr(C);
993 if (const CallExpr *CE = dyn_cast<CallExpr>(E)) {
994 if (i < CE->getNumArgs()) {
995 return cxcursor::MakeCXCursor(CE->getArg(i),
996 getCursorDecl(C),
997 cxcursor::getCursorTU(C));
998 }
999 }
1000 }
1001
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +00001002 return clang_getNullCursor();
1003}
1004
Ted Kremenek017dd742013-04-24 07:17:12 +00001005} // end: extern "C"
1006
1007//===----------------------------------------------------------------------===//
1008// CXCursorSet.
1009//===----------------------------------------------------------------------===//
1010
1011typedef llvm::DenseMap<CXCursor, unsigned> CXCursorSet_Impl;
1012
1013static inline CXCursorSet packCXCursorSet(CXCursorSet_Impl *setImpl) {
1014 return (CXCursorSet) setImpl;
1015}
1016static inline CXCursorSet_Impl *unpackCXCursorSet(CXCursorSet set) {
1017 return (CXCursorSet_Impl*) set;
1018}
1019namespace llvm {
1020template<> struct DenseMapInfo<CXCursor> {
1021public:
1022 static inline CXCursor getEmptyKey() {
1023 return MakeCXCursorInvalid(CXCursor_InvalidFile);
1024 }
1025 static inline CXCursor getTombstoneKey() {
1026 return MakeCXCursorInvalid(CXCursor_NoDeclFound);
1027 }
1028 static inline unsigned getHashValue(const CXCursor &cursor) {
1029 return llvm::DenseMapInfo<std::pair<const void *, const void *> >
1030 ::getHashValue(std::make_pair(cursor.data[0], cursor.data[1]));
1031 }
1032 static inline bool isEqual(const CXCursor &x, const CXCursor &y) {
1033 return x.kind == y.kind &&
1034 x.data[0] == y.data[0] &&
1035 x.data[1] == y.data[1];
1036 }
1037};
1038}
1039
1040extern "C" {
1041CXCursorSet clang_createCXCursorSet() {
1042 return packCXCursorSet(new CXCursorSet_Impl());
1043}
1044
1045void clang_disposeCXCursorSet(CXCursorSet set) {
1046 delete unpackCXCursorSet(set);
1047}
1048
1049unsigned clang_CXCursorSet_contains(CXCursorSet set, CXCursor cursor) {
1050 CXCursorSet_Impl *setImpl = unpackCXCursorSet(set);
1051 if (!setImpl)
1052 return 0;
Ted Kremenek96bbe192013-04-24 07:25:40 +00001053 return setImpl->find(cursor) != setImpl->end();
Ted Kremenek017dd742013-04-24 07:17:12 +00001054}
1055
1056unsigned clang_CXCursorSet_insert(CXCursorSet set, CXCursor cursor) {
1057 // Do not insert invalid cursors into the set.
1058 if (cursor.kind >= CXCursor_FirstInvalid &&
1059 cursor.kind <= CXCursor_LastInvalid)
1060 return 1;
1061
1062 CXCursorSet_Impl *setImpl = unpackCXCursorSet(set);
1063 if (!setImpl)
1064 return 1;
1065 unsigned &entry = (*setImpl)[cursor];
1066 unsigned flag = entry == 0 ? 1 : 0;
1067 entry = 1;
1068 return flag;
1069}
1070
Douglas Gregor8fa0a802011-08-04 20:04:59 +00001071CXCompletionString clang_getCursorCompletionString(CXCursor cursor) {
1072 enum CXCursorKind kind = clang_getCursorKind(cursor);
1073 if (clang_isDeclaration(kind)) {
Dmitri Gribenkoe22339c2013-01-23 17:25:27 +00001074 const Decl *decl = getCursorDecl(cursor);
1075 if (const NamedDecl *namedDecl = dyn_cast_or_null<NamedDecl>(decl)) {
Douglas Gregor8fa0a802011-08-04 20:04:59 +00001076 ASTUnit *unit = getCursorASTUnit(cursor);
Douglas Gregord1f09b42013-01-31 04:52:16 +00001077 CodeCompletionResult Result(namedDecl, CCP_Declaration);
Argyrios Kyrtzidis5e192a72012-01-17 02:15:54 +00001078 CodeCompletionString *String
1079 = Result.CreateCodeCompletionString(unit->getASTContext(),
1080 unit->getPreprocessor(),
Argyrios Kyrtzidis28a83f52012-04-10 17:23:48 +00001081 unit->getCodeCompletionTUInfo().getAllocator(),
Dmitri Gribenkod99ef532012-07-02 17:35:10 +00001082 unit->getCodeCompletionTUInfo(),
1083 true);
Argyrios Kyrtzidis5e192a72012-01-17 02:15:54 +00001084 return String;
Douglas Gregor8fa0a802011-08-04 20:04:59 +00001085 }
1086 }
1087 else if (kind == CXCursor_MacroDefinition) {
Dmitri Gribenko67812b22013-01-11 21:01:49 +00001088 const MacroDefinition *definition = getCursorMacroDefinition(cursor);
Douglas Gregor8fa0a802011-08-04 20:04:59 +00001089 const IdentifierInfo *MacroInfo = definition->getName();
1090 ASTUnit *unit = getCursorASTUnit(cursor);
Dmitri Gribenkob3958472013-01-14 00:36:42 +00001091 CodeCompletionResult Result(MacroInfo);
Argyrios Kyrtzidis5e192a72012-01-17 02:15:54 +00001092 CodeCompletionString *String
1093 = Result.CreateCodeCompletionString(unit->getASTContext(),
1094 unit->getPreprocessor(),
Argyrios Kyrtzidis28a83f52012-04-10 17:23:48 +00001095 unit->getCodeCompletionTUInfo().getAllocator(),
Dmitri Gribenkod99ef532012-07-02 17:35:10 +00001096 unit->getCodeCompletionTUInfo(),
1097 false);
Argyrios Kyrtzidis5e192a72012-01-17 02:15:54 +00001098 return String;
Douglas Gregor8fa0a802011-08-04 20:04:59 +00001099 }
1100 return NULL;
1101}
Ted Kremenek8eece462012-04-30 19:33:45 +00001102} // end: extern C.
Ted Kremenekbbf66ca2012-04-30 19:06:49 +00001103
1104namespace {
1105 struct OverridenCursorsPool {
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00001106 typedef SmallVector<CXCursor, 2> CursorVec;
Ted Kremenekbbf66ca2012-04-30 19:06:49 +00001107 std::vector<CursorVec*> AllCursors;
1108 std::vector<CursorVec*> AvailableCursors;
1109
1110 ~OverridenCursorsPool() {
1111 for (std::vector<CursorVec*>::iterator I = AllCursors.begin(),
1112 E = AllCursors.end(); I != E; ++I) {
1113 delete *I;
1114 }
1115 }
1116 };
1117}
1118
1119void *cxcursor::createOverridenCXCursorsPool() {
1120 return new OverridenCursorsPool();
1121}
1122
1123void cxcursor::disposeOverridenCXCursorsPool(void *pool) {
1124 delete static_cast<OverridenCursorsPool*>(pool);
1125}
Ted Kremenek8eece462012-04-30 19:33:45 +00001126
1127extern "C" {
Ted Kremenekbbf66ca2012-04-30 19:06:49 +00001128void clang_getOverriddenCursors(CXCursor cursor,
1129 CXCursor **overridden,
1130 unsigned *num_overridden) {
1131 if (overridden)
1132 *overridden = 0;
1133 if (num_overridden)
1134 *num_overridden = 0;
1135
1136 CXTranslationUnit TU = cxcursor::getCursorTU(cursor);
1137
1138 if (!overridden || !num_overridden || !TU)
1139 return;
1140
1141 if (!clang_isDeclaration(cursor.kind))
1142 return;
1143
1144 OverridenCursorsPool &pool =
1145 *static_cast<OverridenCursorsPool*>(TU->OverridenCursorsPool);
1146
1147 OverridenCursorsPool::CursorVec *Vec = 0;
1148
1149 if (!pool.AvailableCursors.empty()) {
1150 Vec = pool.AvailableCursors.back();
1151 pool.AvailableCursors.pop_back();
1152 }
1153 else {
1154 Vec = new OverridenCursorsPool::CursorVec();
1155 pool.AllCursors.push_back(Vec);
1156 }
1157
1158 // Clear out the vector, but don't free the memory contents. This
1159 // reduces malloc() traffic.
1160 Vec->clear();
1161
1162 // Use the first entry to contain a back reference to the vector.
1163 // This is a complete hack.
1164 CXCursor backRefCursor = MakeCXCursorInvalid(CXCursor_InvalidFile, TU);
1165 backRefCursor.data[0] = Vec;
1166 assert(cxcursor::getCursorTU(backRefCursor) == TU);
1167 Vec->push_back(backRefCursor);
1168
1169 // Get the overriden cursors.
1170 cxcursor::getOverriddenCursors(cursor, *Vec);
1171
1172 // Did we get any overriden cursors? If not, return Vec to the pool
1173 // of available cursor vectors.
1174 if (Vec->size() == 1) {
1175 pool.AvailableCursors.push_back(Vec);
1176 return;
1177 }
1178
1179 // Now tell the caller about the overriden cursors.
1180 assert(Vec->size() > 1);
1181 *overridden = &((*Vec)[1]);
1182 *num_overridden = Vec->size() - 1;
1183}
1184
1185void clang_disposeOverriddenCursors(CXCursor *overridden) {
1186 if (!overridden)
1187 return;
1188
1189 // Use pointer arithmetic to get back the first faux entry
1190 // which has a back-reference to the TU and the vector.
1191 --overridden;
1192 OverridenCursorsPool::CursorVec *Vec =
Dmitri Gribenko67812b22013-01-11 21:01:49 +00001193 static_cast<OverridenCursorsPool::CursorVec *>(
1194 const_cast<void *>(overridden->data[0]));
Ted Kremenekbbf66ca2012-04-30 19:06:49 +00001195 CXTranslationUnit TU = getCursorTU(*overridden);
1196
1197 assert(Vec && TU);
1198
1199 OverridenCursorsPool &pool =
1200 *static_cast<OverridenCursorsPool*>(TU->OverridenCursorsPool);
1201
1202 pool.AvailableCursors.push_back(Vec);
1203}
Argyrios Kyrtzidisf39a7ae2012-07-02 23:54:36 +00001204
1205int clang_Cursor_isDynamicCall(CXCursor C) {
1206 const Expr *E = 0;
1207 if (clang_isExpression(C.kind))
1208 E = getCursorExpr(C);
1209 if (!E)
1210 return 0;
1211
1212 if (const ObjCMessageExpr *MsgE = dyn_cast<ObjCMessageExpr>(E))
1213 return MsgE->getReceiverKind() == ObjCMessageExpr::Instance;
1214
1215 const MemberExpr *ME = 0;
1216 if (isa<MemberExpr>(E))
1217 ME = cast<MemberExpr>(E);
1218 else if (const CallExpr *CE = dyn_cast<CallExpr>(E))
1219 ME = dyn_cast_or_null<MemberExpr>(CE->getCallee());
1220
1221 if (ME) {
1222 if (const CXXMethodDecl *
1223 MD = dyn_cast_or_null<CXXMethodDecl>(ME->getMemberDecl()))
1224 return MD->isVirtual() && !ME->hasQualifier();
1225 }
1226
1227 return 0;
1228}
1229
Argyrios Kyrtzidise4a990f2012-11-01 02:01:34 +00001230CXType clang_Cursor_getReceiverType(CXCursor C) {
1231 CXTranslationUnit TU = cxcursor::getCursorTU(C);
1232 const Expr *E = 0;
1233 if (clang_isExpression(C.kind))
1234 E = getCursorExpr(C);
1235
1236 if (const ObjCMessageExpr *MsgE = dyn_cast_or_null<ObjCMessageExpr>(E))
1237 return cxtype::MakeCXType(MsgE->getReceiverType(), TU);
1238
1239 return cxtype::MakeCXType(QualType(), TU);
1240}
1241
Ted Kremenekeca099b2010-12-08 23:43:14 +00001242} // end: extern "C"