blob: a413903f9a40c46f888971a6b04a5de092d14710 [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);
78 SmallVector<SourceLocation, 16>::iterator
79 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:
218 case Stmt::CXXScalarValueInitExprClass:
219 case Stmt::CXXUuidofExprClass:
220 case Stmt::ChooseExprClass:
221 case Stmt::DesignatedInitExprClass:
222 case Stmt::ExprWithCleanupsClass:
223 case Stmt::ExpressionTraitExprClass:
224 case Stmt::ExtVectorElementExprClass:
225 case Stmt::ImplicitCastExprClass:
226 case Stmt::ImplicitValueInitExprClass:
227 case Stmt::MaterializeTemporaryExprClass:
228 case Stmt::ObjCIndirectCopyRestoreExprClass:
229 case Stmt::OffsetOfExprClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000230 case Stmt::ParenListExprClass:
231 case Stmt::PredefinedExprClass:
232 case Stmt::ShuffleVectorExprClass:
233 case Stmt::UnaryExprOrTypeTraitExprClass:
234 case Stmt::UnaryTypeTraitExprClass:
235 case Stmt::VAArgExprClass:
Ted Kremenekb3f75422012-03-06 20:06:06 +0000236 case Stmt::ObjCArrayLiteralClass:
237 case Stmt::ObjCDictionaryLiteralClass:
Patrick Beardeb382ec2012-04-19 00:25:12 +0000238 case Stmt::ObjCBoxedExprClass:
Ted Kremenekb3f75422012-03-06 20:06:06 +0000239 case Stmt::ObjCSubscriptRefExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000240 K = CXCursor_UnexposedExpr;
241 break;
Douglas Gregor42b29842011-10-05 19:00:14 +0000242
John McCall4b9c2d22011-11-06 09:01:30 +0000243 case Stmt::OpaqueValueExprClass:
244 if (Expr *Src = cast<OpaqueValueExpr>(S)->getSourceExpr())
245 return MakeCXCursor(Src, Parent, TU, RegionOfInterest);
246 K = CXCursor_UnexposedExpr;
247 break;
248
249 case Stmt::PseudoObjectExprClass:
250 return MakeCXCursor(cast<PseudoObjectExpr>(S)->getSyntacticForm(),
251 Parent, TU, RegionOfInterest);
252
Douglas Gregor42b29842011-10-05 19:00:14 +0000253 case Stmt::CompoundStmtClass:
254 K = CXCursor_CompoundStmt;
255 break;
Richard Smith534986f2012-04-14 00:33:13 +0000256
Douglas Gregor42b29842011-10-05 19:00:14 +0000257 case Stmt::NullStmtClass:
258 K = CXCursor_NullStmt;
259 break;
Richard Smith534986f2012-04-14 00:33:13 +0000260
Douglas Gregor42b29842011-10-05 19:00:14 +0000261 case Stmt::LabelStmtClass:
262 K = CXCursor_LabelStmt;
263 break;
Richard Smith534986f2012-04-14 00:33:13 +0000264
265 case Stmt::AttributedStmtClass:
266 K = CXCursor_UnexposedStmt;
267 break;
268
Douglas Gregor42b29842011-10-05 19:00:14 +0000269 case Stmt::DeclStmtClass:
270 K = CXCursor_DeclStmt;
271 break;
Richard Smith534986f2012-04-14 00:33:13 +0000272
Douglas Gregor42b29842011-10-05 19:00:14 +0000273 case Stmt::IntegerLiteralClass:
274 K = CXCursor_IntegerLiteral;
275 break;
276
277 case Stmt::FloatingLiteralClass:
278 K = CXCursor_FloatingLiteral;
279 break;
280
281 case Stmt::ImaginaryLiteralClass:
282 K = CXCursor_ImaginaryLiteral;
283 break;
284
285 case Stmt::StringLiteralClass:
286 K = CXCursor_StringLiteral;
287 break;
288
289 case Stmt::CharacterLiteralClass:
290 K = CXCursor_CharacterLiteral;
291 break;
292
293 case Stmt::ParenExprClass:
294 K = CXCursor_ParenExpr;
295 break;
296
297 case Stmt::UnaryOperatorClass:
298 K = CXCursor_UnaryOperator;
299 break;
Richard Smith534986f2012-04-14 00:33:13 +0000300
Douglas Gregor42b29842011-10-05 19:00:14 +0000301 case Stmt::CXXNoexceptExprClass:
302 K = CXCursor_UnaryExpr;
303 break;
304
305 case Stmt::ArraySubscriptExprClass:
306 K = CXCursor_ArraySubscriptExpr;
307 break;
308
309 case Stmt::BinaryOperatorClass:
310 K = CXCursor_BinaryOperator;
311 break;
312
313 case Stmt::CompoundAssignOperatorClass:
314 K = CXCursor_CompoundAssignOperator;
315 break;
316
317 case Stmt::ConditionalOperatorClass:
318 K = CXCursor_ConditionalOperator;
319 break;
320
321 case Stmt::CStyleCastExprClass:
322 K = CXCursor_CStyleCastExpr;
323 break;
324
325 case Stmt::CompoundLiteralExprClass:
326 K = CXCursor_CompoundLiteralExpr;
327 break;
328
329 case Stmt::InitListExprClass:
330 K = CXCursor_InitListExpr;
331 break;
332
333 case Stmt::AddrLabelExprClass:
334 K = CXCursor_AddrLabelExpr;
335 break;
336
337 case Stmt::StmtExprClass:
338 K = CXCursor_StmtExpr;
339 break;
340
341 case Stmt::GenericSelectionExprClass:
342 K = CXCursor_GenericSelectionExpr;
343 break;
344
345 case Stmt::GNUNullExprClass:
346 K = CXCursor_GNUNullExpr;
347 break;
348
349 case Stmt::CXXStaticCastExprClass:
350 K = CXCursor_CXXStaticCastExpr;
351 break;
352
353 case Stmt::CXXDynamicCastExprClass:
354 K = CXCursor_CXXDynamicCastExpr;
355 break;
356
357 case Stmt::CXXReinterpretCastExprClass:
358 K = CXCursor_CXXReinterpretCastExpr;
359 break;
360
361 case Stmt::CXXConstCastExprClass:
362 K = CXCursor_CXXConstCastExpr;
363 break;
364
365 case Stmt::CXXFunctionalCastExprClass:
366 K = CXCursor_CXXFunctionalCastExpr;
367 break;
368
369 case Stmt::CXXTypeidExprClass:
370 K = CXCursor_CXXTypeidExpr;
371 break;
372
373 case Stmt::CXXBoolLiteralExprClass:
374 K = CXCursor_CXXBoolLiteralExpr;
375 break;
376
377 case Stmt::CXXNullPtrLiteralExprClass:
378 K = CXCursor_CXXNullPtrLiteralExpr;
379 break;
380
381 case Stmt::CXXThisExprClass:
382 K = CXCursor_CXXThisExpr;
383 break;
384
385 case Stmt::CXXThrowExprClass:
386 K = CXCursor_CXXThrowExpr;
387 break;
388
389 case Stmt::CXXNewExprClass:
390 K = CXCursor_CXXNewExpr;
391 break;
392
393 case Stmt::CXXDeleteExprClass:
394 K = CXCursor_CXXDeleteExpr;
395 break;
396
397 case Stmt::ObjCStringLiteralClass:
398 K = CXCursor_ObjCStringLiteral;
399 break;
400
401 case Stmt::ObjCEncodeExprClass:
402 K = CXCursor_ObjCEncodeExpr;
403 break;
404
405 case Stmt::ObjCSelectorExprClass:
406 K = CXCursor_ObjCSelectorExpr;
407 break;
408
409 case Stmt::ObjCProtocolExprClass:
410 K = CXCursor_ObjCProtocolExpr;
411 break;
Ted Kremenekb3f75422012-03-06 20:06:06 +0000412
413 case Stmt::ObjCBoolLiteralExprClass:
414 K = CXCursor_ObjCBoolLiteralExpr;
415 break;
416
Douglas Gregor42b29842011-10-05 19:00:14 +0000417 case Stmt::ObjCBridgedCastExprClass:
418 K = CXCursor_ObjCBridgedCastExpr;
419 break;
420
421 case Stmt::BlockExprClass:
422 K = CXCursor_BlockExpr;
423 break;
424
425 case Stmt::PackExpansionExprClass:
426 K = CXCursor_PackExpansionExpr;
427 break;
428
429 case Stmt::SizeOfPackExprClass:
430 K = CXCursor_SizeOfPackExpr;
431 break;
432
Douglas Gregor42b29842011-10-05 19:00:14 +0000433 case Stmt::DeclRefExprClass:
434 case Stmt::DependentScopeDeclRefExprClass:
John McCall91a57552011-07-15 05:09:51 +0000435 case Stmt::SubstNonTypeTemplateParmExprClass:
Douglas Gregorc7793c72011-01-15 01:15:58 +0000436 case Stmt::SubstNonTypeTemplateParmPackExprClass:
Richard Smith9a4db032012-09-12 00:56:43 +0000437 case Stmt::FunctionParmPackExprClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000438 case Stmt::UnresolvedLookupExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000439 K = CXCursor_DeclRefExpr;
440 break;
441
Douglas Gregor42b29842011-10-05 19:00:14 +0000442 case Stmt::CXXDependentScopeMemberExprClass:
443 case Stmt::CXXPseudoDestructorExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000444 case Stmt::MemberExprClass:
John McCall76da55d2013-04-16 07:28:30 +0000445 case Stmt::MSPropertyRefExprClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000446 case Stmt::ObjCIsaExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000447 case Stmt::ObjCIvarRefExprClass:
448 case Stmt::ObjCPropertyRefExprClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000449 case Stmt::UnresolvedMemberExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000450 K = CXCursor_MemberRefExpr;
451 break;
452
453 case Stmt::CallExprClass:
454 case Stmt::CXXOperatorCallExprClass:
455 case Stmt::CXXMemberCallExprClass:
Peter Collingbournee08ce652011-02-09 21:07:24 +0000456 case Stmt::CUDAKernelCallExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000457 case Stmt::CXXConstructExprClass:
458 case Stmt::CXXTemporaryObjectExprClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000459 case Stmt::CXXUnresolvedConstructExprClass:
Richard Smith9fcce652012-03-07 08:35:16 +0000460 case Stmt::UserDefinedLiteralClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000461 K = CXCursor_CallExpr;
462 break;
463
Douglas Gregor011d8b92012-02-15 00:54:55 +0000464 case Stmt::LambdaExprClass:
465 K = CXCursor_LambdaExpr;
466 break;
467
Douglas Gregorba0513d2011-10-25 01:33:02 +0000468 case Stmt::ObjCMessageExprClass: {
Douglas Gregor97b98722010-01-19 23:20:36 +0000469 K = CXCursor_ObjCMessageExpr;
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000470 int SelectorIdIndex = -1;
471 // Check if cursor points to a selector id.
472 if (RegionOfInterest.isValid() &&
473 RegionOfInterest.getBegin() == RegionOfInterest.getEnd()) {
474 SmallVector<SourceLocation, 16> SelLocs;
475 cast<ObjCMessageExpr>(S)->getSelectorLocs(SelLocs);
476 SmallVector<SourceLocation, 16>::iterator
477 I=std::find(SelLocs.begin(), SelLocs.end(),RegionOfInterest.getBegin());
478 if (I != SelLocs.end())
479 SelectorIdIndex = I - SelLocs.begin();
480 }
481 CXCursor C = { K, 0, { Parent, S, TU } };
482 return getSelectorIdentifierCursor(SelectorIdIndex, C);
Douglas Gregor97b98722010-01-19 23:20:36 +0000483 }
Douglas Gregorba0513d2011-10-25 01:33:02 +0000484
485 case Stmt::MSDependentExistsStmtClass:
486 K = CXCursor_UnexposedStmt;
487 break;
488 }
Douglas Gregor97b98722010-01-19 23:20:36 +0000489
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000490 CXCursor C = { K, 0, { Parent, S, TU } };
Douglas Gregor97b98722010-01-19 23:20:36 +0000491 return C;
492}
493
Douglas Gregor2e331b92010-01-16 14:00:32 +0000494CXCursor cxcursor::MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super,
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000495 SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000496 CXTranslationUnit TU) {
Daniel Dunbar54d67ca2010-01-25 00:40:30 +0000497 assert(Super && TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000498 void *RawLoc = Loc.getPtrEncoding();
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000499 CXCursor C = { CXCursor_ObjCSuperClassRef, 0, { Super, RawLoc, TU } };
Douglas Gregor2e331b92010-01-16 14:00:32 +0000500 return C;
501}
502
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000503std::pair<const ObjCInterfaceDecl *, SourceLocation>
Douglas Gregor2e331b92010-01-16 14:00:32 +0000504cxcursor::getCursorObjCSuperClassRef(CXCursor C) {
505 assert(C.kind == CXCursor_ObjCSuperClassRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000506 return std::make_pair(static_cast<const ObjCInterfaceDecl *>(C.data[0]),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000507 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregor2e331b92010-01-16 14:00:32 +0000508}
509
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +0000510CXCursor cxcursor::MakeCursorObjCProtocolRef(const ObjCProtocolDecl *Proto,
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000511 SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000512 CXTranslationUnit TU) {
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +0000513 assert(Proto && TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000514 void *RawLoc = Loc.getPtrEncoding();
Dmitri Gribenko33156182013-01-11 21:06:06 +0000515 CXCursor C = { CXCursor_ObjCProtocolRef, 0, { Proto, RawLoc, TU } };
Douglas Gregor78db0cd2010-01-16 15:44:18 +0000516 return C;
517}
518
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000519std::pair<const ObjCProtocolDecl *, SourceLocation>
Douglas Gregor78db0cd2010-01-16 15:44:18 +0000520cxcursor::getCursorObjCProtocolRef(CXCursor C) {
521 assert(C.kind == CXCursor_ObjCProtocolRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000522 return std::make_pair(static_cast<const ObjCProtocolDecl *>(C.data[0]),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000523 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregor78db0cd2010-01-16 15:44:18 +0000524}
525
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +0000526CXCursor cxcursor::MakeCursorObjCClassRef(const ObjCInterfaceDecl *Class,
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000527 SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000528 CXTranslationUnit TU) {
Ted Kremenekebfa3392010-03-19 20:39:03 +0000529 // 'Class' can be null for invalid code.
530 if (!Class)
531 return MakeCXCursorInvalid(CXCursor_InvalidCode);
532 assert(TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000533 void *RawLoc = Loc.getPtrEncoding();
Dmitri Gribenko33156182013-01-11 21:06:06 +0000534 CXCursor C = { CXCursor_ObjCClassRef, 0, { Class, RawLoc, TU } };
Douglas Gregor1adb0822010-01-16 17:14:40 +0000535 return C;
536}
537
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000538std::pair<const ObjCInterfaceDecl *, SourceLocation>
Douglas Gregor1adb0822010-01-16 17:14:40 +0000539cxcursor::getCursorObjCClassRef(CXCursor C) {
540 assert(C.kind == CXCursor_ObjCClassRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000541 return std::make_pair(static_cast<const ObjCInterfaceDecl *>(C.data[0]),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000542 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregor1adb0822010-01-16 17:14:40 +0000543}
544
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +0000545CXCursor cxcursor::MakeCursorTypeRef(const TypeDecl *Type, SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000546 CXTranslationUnit TU) {
Daniel Dunbar54d67ca2010-01-25 00:40:30 +0000547 assert(Type && TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000548 void *RawLoc = Loc.getPtrEncoding();
Dmitri Gribenko33156182013-01-11 21:06:06 +0000549 CXCursor C = { CXCursor_TypeRef, 0, { Type, RawLoc, TU } };
Douglas Gregor7d0d40e2010-01-21 16:28:34 +0000550 return C;
551}
552
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000553std::pair<const TypeDecl *, SourceLocation>
Douglas Gregor7d0d40e2010-01-21 16:28:34 +0000554cxcursor::getCursorTypeRef(CXCursor C) {
555 assert(C.kind == CXCursor_TypeRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000556 return std::make_pair(static_cast<const TypeDecl *>(C.data[0]),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000557 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregor7d0d40e2010-01-21 16:28:34 +0000558}
559
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +0000560CXCursor cxcursor::MakeCursorTemplateRef(const TemplateDecl *Template,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000561 SourceLocation Loc,
562 CXTranslationUnit TU) {
Douglas Gregor0b36e612010-08-31 20:37:03 +0000563 assert(Template && TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000564 void *RawLoc = Loc.getPtrEncoding();
Dmitri Gribenko33156182013-01-11 21:06:06 +0000565 CXCursor C = { CXCursor_TemplateRef, 0, { Template, RawLoc, TU } };
Douglas Gregor0b36e612010-08-31 20:37:03 +0000566 return C;
567}
568
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000569std::pair<const TemplateDecl *, SourceLocation>
Douglas Gregor0b36e612010-08-31 20:37:03 +0000570cxcursor::getCursorTemplateRef(CXCursor C) {
571 assert(C.kind == CXCursor_TemplateRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000572 return std::make_pair(static_cast<const TemplateDecl *>(C.data[0]),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000573 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregor0b36e612010-08-31 20:37:03 +0000574}
575
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +0000576CXCursor cxcursor::MakeCursorNamespaceRef(const NamedDecl *NS,
577 SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000578 CXTranslationUnit TU) {
Douglas Gregor69319002010-08-31 23:48:11 +0000579
580 assert(NS && (isa<NamespaceDecl>(NS) || isa<NamespaceAliasDecl>(NS)) && TU &&
581 "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000582 void *RawLoc = Loc.getPtrEncoding();
Dmitri Gribenko33156182013-01-11 21:06:06 +0000583 CXCursor C = { CXCursor_NamespaceRef, 0, { NS, RawLoc, TU } };
Douglas Gregor69319002010-08-31 23:48:11 +0000584 return C;
585}
586
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000587std::pair<const NamedDecl *, SourceLocation>
Douglas Gregor69319002010-08-31 23:48:11 +0000588cxcursor::getCursorNamespaceRef(CXCursor C) {
589 assert(C.kind == CXCursor_NamespaceRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000590 return std::make_pair(static_cast<const NamedDecl *>(C.data[0]),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000591 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregor69319002010-08-31 23:48:11 +0000592}
593
Douglas Gregor011d8b92012-02-15 00:54:55 +0000594CXCursor cxcursor::MakeCursorVariableRef(const VarDecl *Var, SourceLocation Loc,
595 CXTranslationUnit TU) {
596
597 assert(Var && TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000598 void *RawLoc = Loc.getPtrEncoding();
Dmitri Gribenko33156182013-01-11 21:06:06 +0000599 CXCursor C = { CXCursor_VariableRef, 0, { Var, RawLoc, TU } };
Douglas Gregor011d8b92012-02-15 00:54:55 +0000600 return C;
601}
602
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000603std::pair<const VarDecl *, SourceLocation>
Douglas Gregor011d8b92012-02-15 00:54:55 +0000604cxcursor::getCursorVariableRef(CXCursor C) {
605 assert(C.kind == CXCursor_VariableRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000606 return std::make_pair(static_cast<const VarDecl *>(C.data[0]),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000607 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregor011d8b92012-02-15 00:54:55 +0000608}
609
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +0000610CXCursor cxcursor::MakeCursorMemberRef(const FieldDecl *Field, SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000611 CXTranslationUnit TU) {
Douglas Gregora67e03f2010-09-09 21:42:20 +0000612
613 assert(Field && TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000614 void *RawLoc = Loc.getPtrEncoding();
Dmitri Gribenko33156182013-01-11 21:06:06 +0000615 CXCursor C = { CXCursor_MemberRef, 0, { Field, RawLoc, TU } };
Douglas Gregora67e03f2010-09-09 21:42:20 +0000616 return C;
617}
618
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000619std::pair<const FieldDecl *, SourceLocation>
Douglas Gregora67e03f2010-09-09 21:42:20 +0000620cxcursor::getCursorMemberRef(CXCursor C) {
621 assert(C.kind == CXCursor_MemberRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000622 return std::make_pair(static_cast<const FieldDecl *>(C.data[0]),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000623 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregora67e03f2010-09-09 21:42:20 +0000624}
625
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +0000626CXCursor cxcursor::MakeCursorCXXBaseSpecifier(const CXXBaseSpecifier *B,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000627 CXTranslationUnit TU){
Dmitri Gribenko33156182013-01-11 21:06:06 +0000628 CXCursor C = { CXCursor_CXXBaseSpecifier, 0, { B, 0, TU } };
Ted Kremenek3064ef92010-08-27 21:34:58 +0000629 return C;
630}
631
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000632const CXXBaseSpecifier *cxcursor::getCursorCXXBaseSpecifier(CXCursor C) {
Ted Kremenek3064ef92010-08-27 21:34:58 +0000633 assert(C.kind == CXCursor_CXXBaseSpecifier);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000634 return static_cast<const CXXBaseSpecifier*>(C.data[0]);
Ted Kremenek3064ef92010-08-27 21:34:58 +0000635}
636
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +0000637CXCursor cxcursor::MakePreprocessingDirectiveCursor(SourceRange Range,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000638 CXTranslationUnit TU) {
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000639 CXCursor C = { CXCursor_PreprocessingDirective, 0,
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000640 { Range.getBegin().getPtrEncoding(),
641 Range.getEnd().getPtrEncoding(),
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +0000642 TU }
643 };
644 return C;
645}
646
647SourceRange cxcursor::getCursorPreprocessingDirective(CXCursor C) {
648 assert(C.kind == CXCursor_PreprocessingDirective);
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000649 SourceRange Range(SourceLocation::getFromPtrEncoding(C.data[0]),
650 SourceLocation::getFromPtrEncoding(C.data[1]));
Argyrios Kyrtzidisee0f84f2011-09-26 08:01:41 +0000651 ASTUnit *TU = getCursorASTUnit(C);
652 return TU->mapRangeFromPreamble(Range);
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +0000653}
654
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000655CXCursor cxcursor::MakeMacroDefinitionCursor(const MacroDefinition *MI,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000656 CXTranslationUnit TU) {
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000657 CXCursor C = { CXCursor_MacroDefinition, 0, { MI, 0, TU } };
Douglas Gregor572feb22010-03-18 18:04:21 +0000658 return C;
659}
660
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000661const MacroDefinition *cxcursor::getCursorMacroDefinition(CXCursor C) {
Douglas Gregor572feb22010-03-18 18:04:21 +0000662 assert(C.kind == CXCursor_MacroDefinition);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000663 return static_cast<const MacroDefinition *>(C.data[0]);
Douglas Gregor572feb22010-03-18 18:04:21 +0000664}
665
Chandler Carruth9e5bb852011-07-14 08:20:46 +0000666CXCursor cxcursor::MakeMacroExpansionCursor(MacroExpansion *MI,
667 CXTranslationUnit TU) {
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000668 CXCursor C = { CXCursor_MacroExpansion, 0, { MI, 0, TU } };
Douglas Gregor48072312010-03-18 15:23:44 +0000669 return C;
670}
671
Argyrios Kyrtzidis664b06f2013-01-07 19:16:25 +0000672CXCursor cxcursor::MakeMacroExpansionCursor(MacroDefinition *MI,
673 SourceLocation Loc,
674 CXTranslationUnit TU) {
675 assert(Loc.isValid());
676 CXCursor C = { CXCursor_MacroExpansion, 0, { MI, Loc.getPtrEncoding(), TU } };
677 return C;
678}
679
680const IdentifierInfo *cxcursor::MacroExpansionCursor::getName() const {
681 if (isPseudo())
682 return getAsMacroDefinition()->getName();
683 return getAsMacroExpansion()->getName();
684}
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000685const MacroDefinition *cxcursor::MacroExpansionCursor::getDefinition() const {
Argyrios Kyrtzidis664b06f2013-01-07 19:16:25 +0000686 if (isPseudo())
687 return getAsMacroDefinition();
688 return getAsMacroExpansion()->getDefinition();
689}
690SourceRange cxcursor::MacroExpansionCursor::getSourceRange() const {
691 if (isPseudo())
692 return getPseudoLoc();
693 return getAsMacroExpansion()->getSourceRange();
Douglas Gregor48072312010-03-18 15:23:44 +0000694}
695
Douglas Gregorecdcb882010-10-20 22:00:55 +0000696CXCursor cxcursor::MakeInclusionDirectiveCursor(InclusionDirective *ID,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000697 CXTranslationUnit TU) {
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000698 CXCursor C = { CXCursor_InclusionDirective, 0, { ID, 0, TU } };
Douglas Gregorecdcb882010-10-20 22:00:55 +0000699 return C;
700}
701
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000702const InclusionDirective *cxcursor::getCursorInclusionDirective(CXCursor C) {
Douglas Gregorecdcb882010-10-20 22:00:55 +0000703 assert(C.kind == CXCursor_InclusionDirective);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000704 return static_cast<const InclusionDirective *>(C.data[0]);
Douglas Gregorecdcb882010-10-20 22:00:55 +0000705}
706
Douglas Gregor36897b02010-09-10 00:22:18 +0000707CXCursor cxcursor::MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000708 CXTranslationUnit TU) {
Douglas Gregor36897b02010-09-10 00:22:18 +0000709
710 assert(Label && TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000711 void *RawLoc = Loc.getPtrEncoding();
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000712 CXCursor C = { CXCursor_LabelRef, 0, { Label, RawLoc, TU } };
Douglas Gregor36897b02010-09-10 00:22:18 +0000713 return C;
714}
715
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000716std::pair<const LabelStmt *, SourceLocation>
Douglas Gregor36897b02010-09-10 00:22:18 +0000717cxcursor::getCursorLabelRef(CXCursor C) {
718 assert(C.kind == CXCursor_LabelRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000719 return std::make_pair(static_cast<const LabelStmt *>(C.data[0]),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000720 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregor36897b02010-09-10 00:22:18 +0000721}
722
Dmitri Gribenkoe22339c2013-01-23 17:25:27 +0000723CXCursor cxcursor::MakeCursorOverloadedDeclRef(const OverloadExpr *E,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000724 CXTranslationUnit TU) {
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000725 assert(E && TU && "Invalid arguments!");
726 OverloadedDeclRefStorage Storage(E);
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000727 void *RawLoc = E->getNameLoc().getPtrEncoding();
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000728 CXCursor C = {
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000729 CXCursor_OverloadedDeclRef, 0,
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000730 { Storage.getOpaqueValue(), RawLoc, TU }
731 };
732 return C;
733}
734
Dmitri Gribenkoe22339c2013-01-23 17:25:27 +0000735CXCursor cxcursor::MakeCursorOverloadedDeclRef(const Decl *D,
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000736 SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000737 CXTranslationUnit TU) {
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000738 assert(D && TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000739 void *RawLoc = Loc.getPtrEncoding();
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000740 OverloadedDeclRefStorage Storage(D);
741 CXCursor C = {
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000742 CXCursor_OverloadedDeclRef, 0,
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000743 { Storage.getOpaqueValue(), RawLoc, TU }
744 };
745 return C;
746}
747
748CXCursor cxcursor::MakeCursorOverloadedDeclRef(TemplateName Name,
749 SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000750 CXTranslationUnit TU) {
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000751 assert(Name.getAsOverloadedTemplate() && TU && "Invalid arguments!");
Dmitri Gribenkocb6bcf12013-02-16 01:07:48 +0000752 void *RawLoc = Loc.getPtrEncoding();
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000753 OverloadedDeclRefStorage Storage(Name.getAsOverloadedTemplate());
754 CXCursor C = {
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000755 CXCursor_OverloadedDeclRef, 0,
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000756 { Storage.getOpaqueValue(), RawLoc, TU }
757 };
758 return C;
759}
760
761std::pair<cxcursor::OverloadedDeclRefStorage, SourceLocation>
762cxcursor::getCursorOverloadedDeclRef(CXCursor C) {
763 assert(C.kind == CXCursor_OverloadedDeclRef);
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000764 return std::make_pair(OverloadedDeclRefStorage::getFromOpaqueValue(
765 const_cast<void *>(C.data[0])),
Dmitri Gribenko62d0f562013-02-14 20:07:36 +0000766 SourceLocation::getFromPtrEncoding(C.data[1]));
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000767}
768
Dmitri Gribenkoe22339c2013-01-23 17:25:27 +0000769const Decl *cxcursor::getCursorDecl(CXCursor Cursor) {
770 return static_cast<const Decl *>(Cursor.data[0]);
Douglas Gregor283cae32010-01-15 21:56:13 +0000771}
772
Dmitri Gribenkoff74f962013-01-26 15:29:08 +0000773const Expr *cxcursor::getCursorExpr(CXCursor Cursor) {
Douglas Gregor283cae32010-01-15 21:56:13 +0000774 return dyn_cast_or_null<Expr>(getCursorStmt(Cursor));
775}
776
Dmitri Gribenkoff74f962013-01-26 15:29:08 +0000777const Stmt *cxcursor::getCursorStmt(CXCursor Cursor) {
Douglas Gregor78db0cd2010-01-16 15:44:18 +0000778 if (Cursor.kind == CXCursor_ObjCSuperClassRef ||
Douglas Gregor1adb0822010-01-16 17:14:40 +0000779 Cursor.kind == CXCursor_ObjCProtocolRef ||
780 Cursor.kind == CXCursor_ObjCClassRef)
Douglas Gregor2e331b92010-01-16 14:00:32 +0000781 return 0;
782
Dmitri Gribenkoff74f962013-01-26 15:29:08 +0000783 return static_cast<const Stmt *>(Cursor.data[1]);
Douglas Gregor283cae32010-01-15 21:56:13 +0000784}
785
Dmitri Gribenko7d914382013-01-26 18:08:08 +0000786const Attr *cxcursor::getCursorAttr(CXCursor Cursor) {
787 return static_cast<const Attr *>(Cursor.data[1]);
Ted Kremenek95f33552010-08-26 01:42:22 +0000788}
789
Dmitri Gribenko404628c2013-01-26 18:12:08 +0000790const Decl *cxcursor::getCursorParentDecl(CXCursor Cursor) {
791 return static_cast<const Decl *>(Cursor.data[0]);
Argyrios Kyrtzidis8ccac3d2011-06-29 22:20:07 +0000792}
793
Douglas Gregorf46034a2010-01-18 23:41:10 +0000794ASTContext &cxcursor::getCursorContext(CXCursor Cursor) {
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000795 return getCursorASTUnit(Cursor)->getASTContext();
796}
Douglas Gregorf46034a2010-01-18 23:41:10 +0000797
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000798ASTUnit *cxcursor::getCursorASTUnit(CXCursor Cursor) {
Dmitri Gribenko46f92522013-01-11 19:28:44 +0000799 CXTranslationUnit TU = getCursorTU(Cursor);
Argyrios Kyrtzidis44517462011-12-09 00:17:49 +0000800 if (!TU)
801 return 0;
Dmitri Gribenko5694feb2013-01-26 18:53:38 +0000802 return cxtu::getASTUnit(TU);
Ted Kremeneka60ed472010-11-16 08:15:36 +0000803}
804
805CXTranslationUnit cxcursor::getCursorTU(CXCursor Cursor) {
Dmitri Gribenko67812b22013-01-11 21:01:49 +0000806 return static_cast<CXTranslationUnit>(const_cast<void*>(Cursor.data[2]));
Douglas Gregor283cae32010-01-15 21:56:13 +0000807}
808
Argyrios Kyrtzidise15db6f2012-05-09 16:12:57 +0000809void cxcursor::getOverriddenCursors(CXCursor cursor,
810 SmallVectorImpl<CXCursor> &overridden) {
811 assert(clang_isDeclaration(cursor.kind));
Argyrios Kyrtzidis21c36072012-10-09 01:23:50 +0000812 const NamedDecl *D = dyn_cast_or_null<NamedDecl>(getCursorDecl(cursor));
Argyrios Kyrtzidise15db6f2012-05-09 16:12:57 +0000813 if (!D)
814 return;
815
Argyrios Kyrtzidise15db6f2012-05-09 16:12:57 +0000816 CXTranslationUnit TU = getCursorTU(cursor);
Argyrios Kyrtzidis21c36072012-10-09 01:23:50 +0000817 SmallVector<const NamedDecl *, 8> OverDecls;
818 D->getASTContext().getOverriddenMethods(D, OverDecls);
Argyrios Kyrtzidise15db6f2012-05-09 16:12:57 +0000819
Argyrios Kyrtzidis21c36072012-10-09 01:23:50 +0000820 for (SmallVector<const NamedDecl *, 8>::iterator
821 I = OverDecls.begin(), E = OverDecls.end(); I != E; ++I) {
Dmitri Gribenko05756dc2013-01-14 00:46:27 +0000822 overridden.push_back(MakeCXCursor(*I, TU));
Argyrios Kyrtzidise15db6f2012-05-09 16:12:57 +0000823 }
824}
825
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000826std::pair<int, SourceLocation>
827cxcursor::getSelectorIdentifierIndexAndLoc(CXCursor cursor) {
828 if (cursor.kind == CXCursor_ObjCMessageExpr) {
829 if (cursor.xdata != -1)
830 return std::make_pair(cursor.xdata,
831 cast<ObjCMessageExpr>(getCursorExpr(cursor))
832 ->getSelectorLoc(cursor.xdata));
833 } else if (cursor.kind == CXCursor_ObjCClassMethodDecl ||
834 cursor.kind == CXCursor_ObjCInstanceMethodDecl) {
835 if (cursor.xdata != -1)
836 return std::make_pair(cursor.xdata,
837 cast<ObjCMethodDecl>(getCursorDecl(cursor))
838 ->getSelectorLoc(cursor.xdata));
839 }
840
841 return std::make_pair(-1, SourceLocation());
842}
843
844CXCursor cxcursor::getSelectorIdentifierCursor(int SelIdx, CXCursor cursor) {
845 CXCursor newCursor = cursor;
846
847 if (cursor.kind == CXCursor_ObjCMessageExpr) {
848 if (SelIdx == -1 ||
849 unsigned(SelIdx) >= cast<ObjCMessageExpr>(getCursorExpr(cursor))
850 ->getNumSelectorLocs())
851 newCursor.xdata = -1;
852 else
853 newCursor.xdata = SelIdx;
854 } else if (cursor.kind == CXCursor_ObjCClassMethodDecl ||
855 cursor.kind == CXCursor_ObjCInstanceMethodDecl) {
856 if (SelIdx == -1 ||
857 unsigned(SelIdx) >= cast<ObjCMethodDecl>(getCursorDecl(cursor))
858 ->getNumSelectorLocs())
859 newCursor.xdata = -1;
860 else
861 newCursor.xdata = SelIdx;
862 }
863
864 return newCursor;
865}
866
867CXCursor cxcursor::getTypeRefCursor(CXCursor cursor) {
868 if (cursor.kind != CXCursor_CallExpr)
869 return cursor;
870
871 if (cursor.xdata == 0)
872 return cursor;
873
Dmitri Gribenkoff74f962013-01-26 15:29:08 +0000874 const Expr *E = getCursorExpr(cursor);
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000875 TypeSourceInfo *Type = 0;
Dmitri Gribenkoff74f962013-01-26 15:29:08 +0000876 if (const CXXUnresolvedConstructExpr *
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000877 UnCtor = dyn_cast<CXXUnresolvedConstructExpr>(E)) {
878 Type = UnCtor->getTypeSourceInfo();
Dmitri Gribenkoff74f962013-01-26 15:29:08 +0000879 } else if (const CXXTemporaryObjectExpr *Tmp =
880 dyn_cast<CXXTemporaryObjectExpr>(E)){
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000881 Type = Tmp->getTypeSourceInfo();
882 }
883
884 if (!Type)
885 return cursor;
886
887 CXTranslationUnit TU = getCursorTU(cursor);
888 QualType Ty = Type->getType();
889 TypeLoc TL = Type->getTypeLoc();
890 SourceLocation Loc = TL.getBeginLoc();
891
892 if (const ElaboratedType *ElabT = Ty->getAs<ElaboratedType>()) {
893 Ty = ElabT->getNamedType();
David Blaikie39e6ab42013-02-18 22:06:02 +0000894 ElaboratedTypeLoc ElabTL = TL.castAs<ElaboratedTypeLoc>();
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000895 Loc = ElabTL.getNamedTypeLoc().getBeginLoc();
896 }
897
898 if (const TypedefType *Typedef = Ty->getAs<TypedefType>())
899 return MakeCursorTypeRef(Typedef->getDecl(), Loc, TU);
900 if (const TagType *Tag = Ty->getAs<TagType>())
901 return MakeCursorTypeRef(Tag->getDecl(), Loc, TU);
902 if (const TemplateTypeParmType *TemplP = Ty->getAs<TemplateTypeParmType>())
903 return MakeCursorTypeRef(TemplP->getDecl(), Loc, TU);
904
905 return cursor;
906}
907
Douglas Gregor283cae32010-01-15 21:56:13 +0000908bool cxcursor::operator==(CXCursor X, CXCursor Y) {
909 return X.kind == Y.kind && X.data[0] == Y.data[0] && X.data[1] == Y.data[1] &&
910 X.data[2] == Y.data[2];
Douglas Gregor2e331b92010-01-16 14:00:32 +0000911}
Ted Kremenek007a7c92010-11-01 23:26:51 +0000912
913// FIXME: Remove once we can model DeclGroups and their appropriate ranges
914// properly in the ASTs.
915bool cxcursor::isFirstInDeclGroup(CXCursor C) {
916 assert(clang_isDeclaration(C.kind));
917 return ((uintptr_t) (C.data[1])) != 0;
918}
919
Ted Kremenekeca099b2010-12-08 23:43:14 +0000920//===----------------------------------------------------------------------===//
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +0000921// libclang CXCursor APIs
922//===----------------------------------------------------------------------===//
923
Argyrios Kyrtzidisfa865df2011-09-27 04:14:36 +0000924extern "C" {
925
926int clang_Cursor_isNull(CXCursor cursor) {
927 return clang_equalCursors(cursor, clang_getNullCursor());
928}
929
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +0000930CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor cursor) {
931 return getCursorTU(cursor);
932}
933
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +0000934int clang_Cursor_getNumArguments(CXCursor C) {
935 if (clang_isDeclaration(C.kind)) {
Dmitri Gribenkoe22339c2013-01-23 17:25:27 +0000936 const Decl *D = cxcursor::getCursorDecl(C);
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +0000937 if (const ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(D))
938 return MD->param_size();
939 if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
940 return FD->param_size();
941 }
942
Argyrios Kyrtzidise9ebd852013-04-01 17:38:59 +0000943 if (clang_isExpression(C.kind)) {
944 const Expr *E = cxcursor::getCursorExpr(C);
945 if (const CallExpr *CE = dyn_cast<CallExpr>(E)) {
946 return CE->getNumArgs();
947 }
948 }
949
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +0000950 return -1;
951}
952
953CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i) {
954 if (clang_isDeclaration(C.kind)) {
Dmitri Gribenkoe22339c2013-01-23 17:25:27 +0000955 const Decl *D = cxcursor::getCursorDecl(C);
956 if (const ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(D)) {
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +0000957 if (i < MD->param_size())
958 return cxcursor::MakeCXCursor(MD->param_begin()[i],
959 cxcursor::getCursorTU(C));
Dmitri Gribenkoe22339c2013-01-23 17:25:27 +0000960 } else if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) {
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +0000961 if (i < FD->param_size())
962 return cxcursor::MakeCXCursor(FD->param_begin()[i],
963 cxcursor::getCursorTU(C));
964 }
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 if (i < CE->getNumArgs()) {
971 return cxcursor::MakeCXCursor(CE->getArg(i),
972 getCursorDecl(C),
973 cxcursor::getCursorTU(C));
974 }
975 }
976 }
977
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +0000978 return clang_getNullCursor();
979}
980
Argyrios Kyrtzidisfa865df2011-09-27 04:14:36 +0000981} // end: extern "C"
982
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +0000983//===----------------------------------------------------------------------===//
Ted Kremenekeca099b2010-12-08 23:43:14 +0000984// CXCursorSet.
985//===----------------------------------------------------------------------===//
986
987typedef llvm::DenseMap<CXCursor, unsigned> CXCursorSet_Impl;
988
989static inline CXCursorSet packCXCursorSet(CXCursorSet_Impl *setImpl) {
990 return (CXCursorSet) setImpl;
991}
992static inline CXCursorSet_Impl *unpackCXCursorSet(CXCursorSet set) {
993 return (CXCursorSet_Impl*) set;
994}
995namespace llvm {
Ted Kremenekda6fb692010-12-09 00:33:41 +0000996template<> struct DenseMapInfo<CXCursor> {
Ted Kremenekeca099b2010-12-08 23:43:14 +0000997public:
998 static inline CXCursor getEmptyKey() {
999 return MakeCXCursorInvalid(CXCursor_InvalidFile);
1000 }
1001 static inline CXCursor getTombstoneKey() {
1002 return MakeCXCursorInvalid(CXCursor_NoDeclFound);
1003 }
1004 static inline unsigned getHashValue(const CXCursor &cursor) {
Dmitri Gribenko67812b22013-01-11 21:01:49 +00001005 return llvm::DenseMapInfo<std::pair<const void *, const void *> >
Ted Kremenekeca099b2010-12-08 23:43:14 +00001006 ::getHashValue(std::make_pair(cursor.data[0], cursor.data[1]));
1007 }
1008 static inline bool isEqual(const CXCursor &x, const CXCursor &y) {
1009 return x.kind == y.kind &&
1010 x.data[0] == y.data[0] &&
1011 x.data[1] == y.data[1];
1012 }
1013};
1014}
1015
1016extern "C" {
1017CXCursorSet clang_createCXCursorSet() {
1018 return packCXCursorSet(new CXCursorSet_Impl());
1019}
1020
1021void clang_disposeCXCursorSet(CXCursorSet set) {
1022 delete unpackCXCursorSet(set);
1023}
1024
1025unsigned clang_CXCursorSet_contains(CXCursorSet set, CXCursor cursor) {
1026 CXCursorSet_Impl *setImpl = unpackCXCursorSet(set);
1027 if (!setImpl)
1028 return 0;
1029 return setImpl->find(cursor) == setImpl->end();
1030}
1031
Anders Carlssone8b3de02010-12-09 01:00:12 +00001032unsigned clang_CXCursorSet_insert(CXCursorSet set, CXCursor cursor) {
Ted Kremenekeca099b2010-12-08 23:43:14 +00001033 // Do not insert invalid cursors into the set.
1034 if (cursor.kind >= CXCursor_FirstInvalid &&
1035 cursor.kind <= CXCursor_LastInvalid)
1036 return 1;
1037
1038 CXCursorSet_Impl *setImpl = unpackCXCursorSet(set);
1039 if (!setImpl)
1040 return 1;
1041 unsigned &entry = (*setImpl)[cursor];
1042 unsigned flag = entry == 0 ? 1 : 0;
1043 entry = 1;
1044 return flag;
1045}
Douglas Gregor8fa0a802011-08-04 20:04:59 +00001046
1047CXCompletionString clang_getCursorCompletionString(CXCursor cursor) {
1048 enum CXCursorKind kind = clang_getCursorKind(cursor);
1049 if (clang_isDeclaration(kind)) {
Dmitri Gribenkoe22339c2013-01-23 17:25:27 +00001050 const Decl *decl = getCursorDecl(cursor);
1051 if (const NamedDecl *namedDecl = dyn_cast_or_null<NamedDecl>(decl)) {
Douglas Gregor8fa0a802011-08-04 20:04:59 +00001052 ASTUnit *unit = getCursorASTUnit(cursor);
Douglas Gregord1f09b42013-01-31 04:52:16 +00001053 CodeCompletionResult Result(namedDecl, CCP_Declaration);
Argyrios Kyrtzidis5e192a72012-01-17 02:15:54 +00001054 CodeCompletionString *String
1055 = Result.CreateCodeCompletionString(unit->getASTContext(),
1056 unit->getPreprocessor(),
Argyrios Kyrtzidis28a83f52012-04-10 17:23:48 +00001057 unit->getCodeCompletionTUInfo().getAllocator(),
Dmitri Gribenkod99ef532012-07-02 17:35:10 +00001058 unit->getCodeCompletionTUInfo(),
1059 true);
Argyrios Kyrtzidis5e192a72012-01-17 02:15:54 +00001060 return String;
Douglas Gregor8fa0a802011-08-04 20:04:59 +00001061 }
1062 }
1063 else if (kind == CXCursor_MacroDefinition) {
Dmitri Gribenko67812b22013-01-11 21:01:49 +00001064 const MacroDefinition *definition = getCursorMacroDefinition(cursor);
Douglas Gregor8fa0a802011-08-04 20:04:59 +00001065 const IdentifierInfo *MacroInfo = definition->getName();
1066 ASTUnit *unit = getCursorASTUnit(cursor);
Dmitri Gribenkob3958472013-01-14 00:36:42 +00001067 CodeCompletionResult Result(MacroInfo);
Argyrios Kyrtzidis5e192a72012-01-17 02:15:54 +00001068 CodeCompletionString *String
1069 = Result.CreateCodeCompletionString(unit->getASTContext(),
1070 unit->getPreprocessor(),
Argyrios Kyrtzidis28a83f52012-04-10 17:23:48 +00001071 unit->getCodeCompletionTUInfo().getAllocator(),
Dmitri Gribenkod99ef532012-07-02 17:35:10 +00001072 unit->getCodeCompletionTUInfo(),
1073 false);
Argyrios Kyrtzidis5e192a72012-01-17 02:15:54 +00001074 return String;
Douglas Gregor8fa0a802011-08-04 20:04:59 +00001075 }
1076 return NULL;
1077}
Ted Kremenek8eece462012-04-30 19:33:45 +00001078} // end: extern C.
Ted Kremenekbbf66ca2012-04-30 19:06:49 +00001079
1080namespace {
1081 struct OverridenCursorsPool {
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00001082 typedef SmallVector<CXCursor, 2> CursorVec;
Ted Kremenekbbf66ca2012-04-30 19:06:49 +00001083 std::vector<CursorVec*> AllCursors;
1084 std::vector<CursorVec*> AvailableCursors;
1085
1086 ~OverridenCursorsPool() {
1087 for (std::vector<CursorVec*>::iterator I = AllCursors.begin(),
1088 E = AllCursors.end(); I != E; ++I) {
1089 delete *I;
1090 }
1091 }
1092 };
1093}
1094
1095void *cxcursor::createOverridenCXCursorsPool() {
1096 return new OverridenCursorsPool();
1097}
1098
1099void cxcursor::disposeOverridenCXCursorsPool(void *pool) {
1100 delete static_cast<OverridenCursorsPool*>(pool);
1101}
Ted Kremenek8eece462012-04-30 19:33:45 +00001102
1103extern "C" {
Ted Kremenekbbf66ca2012-04-30 19:06:49 +00001104void clang_getOverriddenCursors(CXCursor cursor,
1105 CXCursor **overridden,
1106 unsigned *num_overridden) {
1107 if (overridden)
1108 *overridden = 0;
1109 if (num_overridden)
1110 *num_overridden = 0;
1111
1112 CXTranslationUnit TU = cxcursor::getCursorTU(cursor);
1113
1114 if (!overridden || !num_overridden || !TU)
1115 return;
1116
1117 if (!clang_isDeclaration(cursor.kind))
1118 return;
1119
1120 OverridenCursorsPool &pool =
1121 *static_cast<OverridenCursorsPool*>(TU->OverridenCursorsPool);
1122
1123 OverridenCursorsPool::CursorVec *Vec = 0;
1124
1125 if (!pool.AvailableCursors.empty()) {
1126 Vec = pool.AvailableCursors.back();
1127 pool.AvailableCursors.pop_back();
1128 }
1129 else {
1130 Vec = new OverridenCursorsPool::CursorVec();
1131 pool.AllCursors.push_back(Vec);
1132 }
1133
1134 // Clear out the vector, but don't free the memory contents. This
1135 // reduces malloc() traffic.
1136 Vec->clear();
1137
1138 // Use the first entry to contain a back reference to the vector.
1139 // This is a complete hack.
1140 CXCursor backRefCursor = MakeCXCursorInvalid(CXCursor_InvalidFile, TU);
1141 backRefCursor.data[0] = Vec;
1142 assert(cxcursor::getCursorTU(backRefCursor) == TU);
1143 Vec->push_back(backRefCursor);
1144
1145 // Get the overriden cursors.
1146 cxcursor::getOverriddenCursors(cursor, *Vec);
1147
1148 // Did we get any overriden cursors? If not, return Vec to the pool
1149 // of available cursor vectors.
1150 if (Vec->size() == 1) {
1151 pool.AvailableCursors.push_back(Vec);
1152 return;
1153 }
1154
1155 // Now tell the caller about the overriden cursors.
1156 assert(Vec->size() > 1);
1157 *overridden = &((*Vec)[1]);
1158 *num_overridden = Vec->size() - 1;
1159}
1160
1161void clang_disposeOverriddenCursors(CXCursor *overridden) {
1162 if (!overridden)
1163 return;
1164
1165 // Use pointer arithmetic to get back the first faux entry
1166 // which has a back-reference to the TU and the vector.
1167 --overridden;
1168 OverridenCursorsPool::CursorVec *Vec =
Dmitri Gribenko67812b22013-01-11 21:01:49 +00001169 static_cast<OverridenCursorsPool::CursorVec *>(
1170 const_cast<void *>(overridden->data[0]));
Ted Kremenekbbf66ca2012-04-30 19:06:49 +00001171 CXTranslationUnit TU = getCursorTU(*overridden);
1172
1173 assert(Vec && TU);
1174
1175 OverridenCursorsPool &pool =
1176 *static_cast<OverridenCursorsPool*>(TU->OverridenCursorsPool);
1177
1178 pool.AvailableCursors.push_back(Vec);
1179}
Argyrios Kyrtzidisf39a7ae2012-07-02 23:54:36 +00001180
1181int clang_Cursor_isDynamicCall(CXCursor C) {
1182 const Expr *E = 0;
1183 if (clang_isExpression(C.kind))
1184 E = getCursorExpr(C);
1185 if (!E)
1186 return 0;
1187
1188 if (const ObjCMessageExpr *MsgE = dyn_cast<ObjCMessageExpr>(E))
1189 return MsgE->getReceiverKind() == ObjCMessageExpr::Instance;
1190
1191 const MemberExpr *ME = 0;
1192 if (isa<MemberExpr>(E))
1193 ME = cast<MemberExpr>(E);
1194 else if (const CallExpr *CE = dyn_cast<CallExpr>(E))
1195 ME = dyn_cast_or_null<MemberExpr>(CE->getCallee());
1196
1197 if (ME) {
1198 if (const CXXMethodDecl *
1199 MD = dyn_cast_or_null<CXXMethodDecl>(ME->getMemberDecl()))
1200 return MD->isVirtual() && !ME->hasQualifier();
1201 }
1202
1203 return 0;
1204}
1205
Argyrios Kyrtzidise4a990f2012-11-01 02:01:34 +00001206CXType clang_Cursor_getReceiverType(CXCursor C) {
1207 CXTranslationUnit TU = cxcursor::getCursorTU(C);
1208 const Expr *E = 0;
1209 if (clang_isExpression(C.kind))
1210 E = getCursorExpr(C);
1211
1212 if (const ObjCMessageExpr *MsgE = dyn_cast_or_null<ObjCMessageExpr>(E))
1213 return cxtype::MakeCXType(MsgE->getReceiverType(), TU);
1214
1215 return cxtype::MakeCXType(QualType(), TU);
1216}
1217
Ted Kremenekeca099b2010-12-08 23:43:14 +00001218} // end: extern "C"