blob: a8cb1f96d4d617762ff2b9417c73ef3e29ebc385 [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"
Douglas Gregor7eaa8ae2010-01-20 00:23:15 +000019#include "clang/Frontend/ASTUnit.h"
Ted Kremenek16c440a2010-01-15 20:35:54 +000020#include "clang/AST/Decl.h"
Douglas Gregor69319002010-08-31 23:48:11 +000021#include "clang/AST/DeclCXX.h"
Douglas Gregor283cae32010-01-15 21:56:13 +000022#include "clang/AST/DeclObjC.h"
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +000023#include "clang/AST/DeclTemplate.h"
Douglas Gregor283cae32010-01-15 21:56:13 +000024#include "clang/AST/Expr.h"
Douglas Gregor1f60d9e2010-09-13 22:52:57 +000025#include "clang/AST/ExprCXX.h"
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +000026#include "clang/AST/ExprObjC.h"
Ted Kremenek007a7c92010-11-01 23:26:51 +000027#include "clang-c/Index.h"
Ted Kremenekedc8aa62010-01-16 00:36:30 +000028#include "llvm/Support/ErrorHandling.h"
Ted Kremenek16c440a2010-01-15 20:35:54 +000029
30using namespace clang;
Douglas Gregor1f60d9e2010-09-13 22:52:57 +000031using namespace cxcursor;
Ted Kremenek16c440a2010-01-15 20:35:54 +000032
Ted Kremenekbbf66ca2012-04-30 19:06:49 +000033CXCursor cxcursor::MakeCXCursorInvalid(CXCursorKind K, CXTranslationUnit TU) {
Douglas Gregor5bfb8c12010-01-20 23:34:41 +000034 assert(K >= CXCursor_FirstInvalid && K <= CXCursor_LastInvalid);
Ted Kremenekbbf66ca2012-04-30 19:06:49 +000035 CXCursor C = { K, 0, { 0, 0, TU } };
Douglas Gregor5bfb8c12010-01-20 23:34:41 +000036 return C;
Ted Kremenek16c440a2010-01-15 20:35:54 +000037}
38
Ted Kremeneke77f4432010-02-18 03:09:07 +000039static CXCursorKind GetCursorKind(const Attr *A) {
40 assert(A && "Invalid arguments!");
41 switch (A->getKind()) {
42 default: break;
Sean Hunt387475d2010-06-16 23:43:53 +000043 case attr::IBAction: return CXCursor_IBActionAttr;
44 case attr::IBOutlet: return CXCursor_IBOutletAttr;
45 case attr::IBOutletCollection: return CXCursor_IBOutletCollectionAttr;
Argyrios Kyrtzidis6639e922011-09-13 17:39:31 +000046 case attr::Final: return CXCursor_CXXFinalAttr;
47 case attr::Override: return CXCursor_CXXOverrideAttr;
Erik Verbruggen5f1c8222011-10-13 09:41:32 +000048 case attr::Annotate: return CXCursor_AnnotateAttr;
Argyrios Kyrtzidis84b79642011-12-06 22:05:01 +000049 case attr::AsmLabel: return CXCursor_AsmLabelAttr;
Ted Kremeneke77f4432010-02-18 03:09:07 +000050 }
51
52 return CXCursor_UnexposedAttr;
53}
54
Ted Kremeneka60ed472010-11-16 08:15:36 +000055CXCursor cxcursor::MakeCXCursor(const Attr *A, Decl *Parent,
56 CXTranslationUnit TU) {
Ted Kremeneke77f4432010-02-18 03:09:07 +000057 assert(A && Parent && TU && "Invalid arguments!");
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +000058 CXCursor C = { GetCursorKind(A), 0, { Parent, (void*)A, TU } };
Ted Kremeneke77f4432010-02-18 03:09:07 +000059 return C;
60}
61
Ted Kremeneka60ed472010-11-16 08:15:36 +000062CXCursor cxcursor::MakeCXCursor(Decl *D, CXTranslationUnit TU,
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +000063 SourceRange RegionOfInterest,
Ted Kremenek007a7c92010-11-01 23:26:51 +000064 bool FirstInDeclGroup) {
Daniel Dunbar54d67ca2010-01-25 00:40:30 +000065 assert(D && TU && "Invalid arguments!");
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +000066
67 CXCursorKind K = getCursorKindForDecl(D);
68
69 if (K == CXCursor_ObjCClassMethodDecl ||
70 K == CXCursor_ObjCInstanceMethodDecl) {
71 int SelectorIdIndex = -1;
72 // Check if cursor points to a selector id.
73 if (RegionOfInterest.isValid() &&
74 RegionOfInterest.getBegin() == RegionOfInterest.getEnd()) {
75 SmallVector<SourceLocation, 16> SelLocs;
76 cast<ObjCMethodDecl>(D)->getSelectorLocs(SelLocs);
77 SmallVector<SourceLocation, 16>::iterator
78 I=std::find(SelLocs.begin(), SelLocs.end(),RegionOfInterest.getBegin());
79 if (I != SelLocs.end())
80 SelectorIdIndex = I - SelLocs.begin();
81 }
82 CXCursor C = { K, SelectorIdIndex,
83 { D, (void*)(intptr_t) (FirstInDeclGroup ? 1 : 0), TU }};
84 return C;
85 }
86
87 CXCursor C = { K, 0, { D, (void*)(intptr_t) (FirstInDeclGroup ? 1 : 0), TU }};
Douglas Gregor5bfb8c12010-01-20 23:34:41 +000088 return C;
Ted Kremenekedc8aa62010-01-16 00:36:30 +000089}
90
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +000091CXCursor cxcursor::MakeCXCursor(Stmt *S, Decl *Parent, CXTranslationUnit TU,
92 SourceRange RegionOfInterest) {
Daniel Dunbar54d67ca2010-01-25 00:40:30 +000093 assert(S && TU && "Invalid arguments!");
Douglas Gregor97b98722010-01-19 23:20:36 +000094 CXCursorKind K = CXCursor_NotImplemented;
95
96 switch (S->getStmtClass()) {
97 case Stmt::NoStmtClass:
98 break;
Douglas Gregor42b29842011-10-05 19:00:14 +000099
Douglas Gregor97b98722010-01-19 23:20:36 +0000100 case Stmt::CaseStmtClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000101 K = CXCursor_CaseStmt;
102 break;
103
Douglas Gregor97b98722010-01-19 23:20:36 +0000104 case Stmt::DefaultStmtClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000105 K = CXCursor_DefaultStmt;
106 break;
107
108 case Stmt::IfStmtClass:
109 K = CXCursor_IfStmt;
110 break;
111
112 case Stmt::SwitchStmtClass:
113 K = CXCursor_SwitchStmt;
114 break;
115
116 case Stmt::WhileStmtClass:
117 K = CXCursor_WhileStmt;
118 break;
119
120 case Stmt::DoStmtClass:
121 K = CXCursor_DoStmt;
122 break;
123
124 case Stmt::ForStmtClass:
125 K = CXCursor_ForStmt;
126 break;
127
128 case Stmt::GotoStmtClass:
129 K = CXCursor_GotoStmt;
130 break;
131
Douglas Gregor97b98722010-01-19 23:20:36 +0000132 case Stmt::IndirectGotoStmtClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000133 K = CXCursor_IndirectGotoStmt;
134 break;
135
136 case Stmt::ContinueStmtClass:
137 K = CXCursor_ContinueStmt;
138 break;
139
140 case Stmt::BreakStmtClass:
141 K = CXCursor_BreakStmt;
142 break;
143
144 case Stmt::ReturnStmtClass:
145 K = CXCursor_ReturnStmt;
146 break;
147
Chad Rosierdf5faf52012-08-25 00:11:56 +0000148 case Stmt::GCCAsmStmtClass:
149 K = CXCursor_GCCAsmStmt;
Douglas Gregor42b29842011-10-05 19:00:14 +0000150 break;
Chad Rosier8cd64b42012-06-11 20:47:18 +0000151
152 case Stmt::MSAsmStmtClass:
153 K = CXCursor_MSAsmStmt;
154 break;
Douglas Gregor42b29842011-10-05 19:00:14 +0000155
156 case Stmt::ObjCAtTryStmtClass:
157 K = CXCursor_ObjCAtTryStmt;
158 break;
159
160 case Stmt::ObjCAtCatchStmtClass:
161 K = CXCursor_ObjCAtCatchStmt;
162 break;
163
164 case Stmt::ObjCAtFinallyStmtClass:
165 K = CXCursor_ObjCAtFinallyStmt;
166 break;
167
168 case Stmt::ObjCAtThrowStmtClass:
169 K = CXCursor_ObjCAtThrowStmt;
170 break;
171
172 case Stmt::ObjCAtSynchronizedStmtClass:
173 K = CXCursor_ObjCAtSynchronizedStmt;
174 break;
175
176 case Stmt::ObjCAutoreleasePoolStmtClass:
177 K = CXCursor_ObjCAutoreleasePoolStmt;
178 break;
179
Douglas Gregor97b98722010-01-19 23:20:36 +0000180 case Stmt::ObjCForCollectionStmtClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000181 K = CXCursor_ObjCForCollectionStmt;
182 break;
183
Douglas Gregor97b98722010-01-19 23:20:36 +0000184 case Stmt::CXXCatchStmtClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000185 K = CXCursor_CXXCatchStmt;
186 break;
187
188 case Stmt::CXXTryStmtClass:
189 K = CXCursor_CXXTryStmt;
190 break;
191
192 case Stmt::CXXForRangeStmtClass:
193 K = CXCursor_CXXForRangeStmt;
194 break;
195
John Wiegley28bbe4b2011-04-28 01:08:34 +0000196 case Stmt::SEHTryStmtClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000197 K = CXCursor_SEHTryStmt;
198 break;
199
John Wiegley28bbe4b2011-04-28 01:08:34 +0000200 case Stmt::SEHExceptStmtClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000201 K = CXCursor_SEHExceptStmt;
202 break;
203
John Wiegley28bbe4b2011-04-28 01:08:34 +0000204 case Stmt::SEHFinallyStmtClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000205 K = CXCursor_SEHFinallyStmt;
Douglas Gregor97b98722010-01-19 23:20:36 +0000206 break;
Douglas Gregor42b29842011-10-05 19:00:14 +0000207
John Wiegley21ff2e52011-04-28 00:16:57 +0000208 case Stmt::ArrayTypeTraitExprClass:
Tanya Lattner61eee0c2011-06-04 00:47:47 +0000209 case Stmt::AsTypeExprClass:
Eli Friedman276b0612011-10-11 02:20:01 +0000210 case Stmt::AtomicExprClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000211 case Stmt::BinaryConditionalOperatorClass:
212 case Stmt::BinaryTypeTraitExprClass:
Douglas Gregor4ca8ac22012-02-24 07:38:34 +0000213 case Stmt::TypeTraitExprClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000214 case Stmt::CXXBindTemporaryExprClass:
215 case Stmt::CXXDefaultArgExprClass:
216 case Stmt::CXXScalarValueInitExprClass:
217 case Stmt::CXXUuidofExprClass:
218 case Stmt::ChooseExprClass:
219 case Stmt::DesignatedInitExprClass:
220 case Stmt::ExprWithCleanupsClass:
221 case Stmt::ExpressionTraitExprClass:
222 case Stmt::ExtVectorElementExprClass:
223 case Stmt::ImplicitCastExprClass:
224 case Stmt::ImplicitValueInitExprClass:
225 case Stmt::MaterializeTemporaryExprClass:
226 case Stmt::ObjCIndirectCopyRestoreExprClass:
227 case Stmt::OffsetOfExprClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000228 case Stmt::ParenListExprClass:
229 case Stmt::PredefinedExprClass:
230 case Stmt::ShuffleVectorExprClass:
231 case Stmt::UnaryExprOrTypeTraitExprClass:
232 case Stmt::UnaryTypeTraitExprClass:
233 case Stmt::VAArgExprClass:
Ted Kremenekb3f75422012-03-06 20:06:06 +0000234 case Stmt::ObjCArrayLiteralClass:
235 case Stmt::ObjCDictionaryLiteralClass:
Patrick Beardeb382ec2012-04-19 00:25:12 +0000236 case Stmt::ObjCBoxedExprClass:
Ted Kremenekb3f75422012-03-06 20:06:06 +0000237 case Stmt::ObjCSubscriptRefExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000238 K = CXCursor_UnexposedExpr;
239 break;
Douglas Gregor42b29842011-10-05 19:00:14 +0000240
John McCall4b9c2d22011-11-06 09:01:30 +0000241 case Stmt::OpaqueValueExprClass:
242 if (Expr *Src = cast<OpaqueValueExpr>(S)->getSourceExpr())
243 return MakeCXCursor(Src, Parent, TU, RegionOfInterest);
244 K = CXCursor_UnexposedExpr;
245 break;
246
247 case Stmt::PseudoObjectExprClass:
248 return MakeCXCursor(cast<PseudoObjectExpr>(S)->getSyntacticForm(),
249 Parent, TU, RegionOfInterest);
250
Douglas Gregor42b29842011-10-05 19:00:14 +0000251 case Stmt::CompoundStmtClass:
252 K = CXCursor_CompoundStmt;
253 break;
Richard Smith534986f2012-04-14 00:33:13 +0000254
Douglas Gregor42b29842011-10-05 19:00:14 +0000255 case Stmt::NullStmtClass:
256 K = CXCursor_NullStmt;
257 break;
Richard Smith534986f2012-04-14 00:33:13 +0000258
Douglas Gregor42b29842011-10-05 19:00:14 +0000259 case Stmt::LabelStmtClass:
260 K = CXCursor_LabelStmt;
261 break;
Richard Smith534986f2012-04-14 00:33:13 +0000262
263 case Stmt::AttributedStmtClass:
264 K = CXCursor_UnexposedStmt;
265 break;
266
Douglas Gregor42b29842011-10-05 19:00:14 +0000267 case Stmt::DeclStmtClass:
268 K = CXCursor_DeclStmt;
269 break;
Richard Smith534986f2012-04-14 00:33:13 +0000270
Douglas Gregor42b29842011-10-05 19:00:14 +0000271 case Stmt::IntegerLiteralClass:
272 K = CXCursor_IntegerLiteral;
273 break;
274
275 case Stmt::FloatingLiteralClass:
276 K = CXCursor_FloatingLiteral;
277 break;
278
279 case Stmt::ImaginaryLiteralClass:
280 K = CXCursor_ImaginaryLiteral;
281 break;
282
283 case Stmt::StringLiteralClass:
284 K = CXCursor_StringLiteral;
285 break;
286
287 case Stmt::CharacterLiteralClass:
288 K = CXCursor_CharacterLiteral;
289 break;
290
291 case Stmt::ParenExprClass:
292 K = CXCursor_ParenExpr;
293 break;
294
295 case Stmt::UnaryOperatorClass:
296 K = CXCursor_UnaryOperator;
297 break;
Richard Smith534986f2012-04-14 00:33:13 +0000298
Douglas Gregor42b29842011-10-05 19:00:14 +0000299 case Stmt::CXXNoexceptExprClass:
300 K = CXCursor_UnaryExpr;
301 break;
302
303 case Stmt::ArraySubscriptExprClass:
304 K = CXCursor_ArraySubscriptExpr;
305 break;
306
307 case Stmt::BinaryOperatorClass:
308 K = CXCursor_BinaryOperator;
309 break;
310
311 case Stmt::CompoundAssignOperatorClass:
312 K = CXCursor_CompoundAssignOperator;
313 break;
314
315 case Stmt::ConditionalOperatorClass:
316 K = CXCursor_ConditionalOperator;
317 break;
318
319 case Stmt::CStyleCastExprClass:
320 K = CXCursor_CStyleCastExpr;
321 break;
322
323 case Stmt::CompoundLiteralExprClass:
324 K = CXCursor_CompoundLiteralExpr;
325 break;
326
327 case Stmt::InitListExprClass:
328 K = CXCursor_InitListExpr;
329 break;
330
331 case Stmt::AddrLabelExprClass:
332 K = CXCursor_AddrLabelExpr;
333 break;
334
335 case Stmt::StmtExprClass:
336 K = CXCursor_StmtExpr;
337 break;
338
339 case Stmt::GenericSelectionExprClass:
340 K = CXCursor_GenericSelectionExpr;
341 break;
342
343 case Stmt::GNUNullExprClass:
344 K = CXCursor_GNUNullExpr;
345 break;
346
347 case Stmt::CXXStaticCastExprClass:
348 K = CXCursor_CXXStaticCastExpr;
349 break;
350
351 case Stmt::CXXDynamicCastExprClass:
352 K = CXCursor_CXXDynamicCastExpr;
353 break;
354
355 case Stmt::CXXReinterpretCastExprClass:
356 K = CXCursor_CXXReinterpretCastExpr;
357 break;
358
359 case Stmt::CXXConstCastExprClass:
360 K = CXCursor_CXXConstCastExpr;
361 break;
362
363 case Stmt::CXXFunctionalCastExprClass:
364 K = CXCursor_CXXFunctionalCastExpr;
365 break;
366
367 case Stmt::CXXTypeidExprClass:
368 K = CXCursor_CXXTypeidExpr;
369 break;
370
371 case Stmt::CXXBoolLiteralExprClass:
372 K = CXCursor_CXXBoolLiteralExpr;
373 break;
374
375 case Stmt::CXXNullPtrLiteralExprClass:
376 K = CXCursor_CXXNullPtrLiteralExpr;
377 break;
378
379 case Stmt::CXXThisExprClass:
380 K = CXCursor_CXXThisExpr;
381 break;
382
383 case Stmt::CXXThrowExprClass:
384 K = CXCursor_CXXThrowExpr;
385 break;
386
387 case Stmt::CXXNewExprClass:
388 K = CXCursor_CXXNewExpr;
389 break;
390
391 case Stmt::CXXDeleteExprClass:
392 K = CXCursor_CXXDeleteExpr;
393 break;
394
395 case Stmt::ObjCStringLiteralClass:
396 K = CXCursor_ObjCStringLiteral;
397 break;
398
399 case Stmt::ObjCEncodeExprClass:
400 K = CXCursor_ObjCEncodeExpr;
401 break;
402
403 case Stmt::ObjCSelectorExprClass:
404 K = CXCursor_ObjCSelectorExpr;
405 break;
406
407 case Stmt::ObjCProtocolExprClass:
408 K = CXCursor_ObjCProtocolExpr;
409 break;
Ted Kremenekb3f75422012-03-06 20:06:06 +0000410
411 case Stmt::ObjCBoolLiteralExprClass:
412 K = CXCursor_ObjCBoolLiteralExpr;
413 break;
414
Douglas Gregor42b29842011-10-05 19:00:14 +0000415 case Stmt::ObjCBridgedCastExprClass:
416 K = CXCursor_ObjCBridgedCastExpr;
417 break;
418
419 case Stmt::BlockExprClass:
420 K = CXCursor_BlockExpr;
421 break;
422
423 case Stmt::PackExpansionExprClass:
424 K = CXCursor_PackExpansionExpr;
425 break;
426
427 case Stmt::SizeOfPackExprClass:
428 K = CXCursor_SizeOfPackExpr;
429 break;
430
Douglas Gregor42b29842011-10-05 19:00:14 +0000431 case Stmt::DeclRefExprClass:
432 case Stmt::DependentScopeDeclRefExprClass:
John McCall91a57552011-07-15 05:09:51 +0000433 case Stmt::SubstNonTypeTemplateParmExprClass:
Douglas Gregorc7793c72011-01-15 01:15:58 +0000434 case Stmt::SubstNonTypeTemplateParmPackExprClass:
Richard Smith9a4db032012-09-12 00:56:43 +0000435 case Stmt::FunctionParmPackExprClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000436 case Stmt::UnresolvedLookupExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000437 K = CXCursor_DeclRefExpr;
438 break;
439
Douglas Gregor42b29842011-10-05 19:00:14 +0000440 case Stmt::CXXDependentScopeMemberExprClass:
441 case Stmt::CXXPseudoDestructorExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000442 case Stmt::MemberExprClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000443 case Stmt::ObjCIsaExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000444 case Stmt::ObjCIvarRefExprClass:
445 case Stmt::ObjCPropertyRefExprClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000446 case Stmt::UnresolvedMemberExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000447 K = CXCursor_MemberRefExpr;
448 break;
449
450 case Stmt::CallExprClass:
451 case Stmt::CXXOperatorCallExprClass:
452 case Stmt::CXXMemberCallExprClass:
Peter Collingbournee08ce652011-02-09 21:07:24 +0000453 case Stmt::CUDAKernelCallExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000454 case Stmt::CXXConstructExprClass:
455 case Stmt::CXXTemporaryObjectExprClass:
Douglas Gregor42b29842011-10-05 19:00:14 +0000456 case Stmt::CXXUnresolvedConstructExprClass:
Richard Smith9fcce652012-03-07 08:35:16 +0000457 case Stmt::UserDefinedLiteralClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000458 K = CXCursor_CallExpr;
459 break;
460
Douglas Gregor011d8b92012-02-15 00:54:55 +0000461 case Stmt::LambdaExprClass:
462 K = CXCursor_LambdaExpr;
463 break;
464
Douglas Gregorba0513d2011-10-25 01:33:02 +0000465 case Stmt::ObjCMessageExprClass: {
Douglas Gregor97b98722010-01-19 23:20:36 +0000466 K = CXCursor_ObjCMessageExpr;
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000467 int SelectorIdIndex = -1;
468 // Check if cursor points to a selector id.
469 if (RegionOfInterest.isValid() &&
470 RegionOfInterest.getBegin() == RegionOfInterest.getEnd()) {
471 SmallVector<SourceLocation, 16> SelLocs;
472 cast<ObjCMessageExpr>(S)->getSelectorLocs(SelLocs);
473 SmallVector<SourceLocation, 16>::iterator
474 I=std::find(SelLocs.begin(), SelLocs.end(),RegionOfInterest.getBegin());
475 if (I != SelLocs.end())
476 SelectorIdIndex = I - SelLocs.begin();
477 }
478 CXCursor C = { K, 0, { Parent, S, TU } };
479 return getSelectorIdentifierCursor(SelectorIdIndex, C);
Douglas Gregor97b98722010-01-19 23:20:36 +0000480 }
Douglas Gregorba0513d2011-10-25 01:33:02 +0000481
482 case Stmt::MSDependentExistsStmtClass:
483 K = CXCursor_UnexposedStmt;
484 break;
485 }
Douglas Gregor97b98722010-01-19 23:20:36 +0000486
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000487 CXCursor C = { K, 0, { Parent, S, TU } };
Douglas Gregor97b98722010-01-19 23:20:36 +0000488 return C;
489}
490
Douglas Gregor2e331b92010-01-16 14:00:32 +0000491CXCursor cxcursor::MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super,
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000492 SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000493 CXTranslationUnit TU) {
Daniel Dunbar54d67ca2010-01-25 00:40:30 +0000494 assert(Super && TU && "Invalid arguments!");
Douglas Gregor2e331b92010-01-16 14:00:32 +0000495 void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000496 CXCursor C = { CXCursor_ObjCSuperClassRef, 0, { Super, RawLoc, TU } };
Douglas Gregor2e331b92010-01-16 14:00:32 +0000497 return C;
498}
499
500std::pair<ObjCInterfaceDecl *, SourceLocation>
501cxcursor::getCursorObjCSuperClassRef(CXCursor C) {
502 assert(C.kind == CXCursor_ObjCSuperClassRef);
503 return std::make_pair(static_cast<ObjCInterfaceDecl *>(C.data[0]),
504 SourceLocation::getFromRawEncoding(
505 reinterpret_cast<uintptr_t>(C.data[1])));
506}
507
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +0000508CXCursor cxcursor::MakeCursorObjCProtocolRef(const ObjCProtocolDecl *Proto,
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000509 SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000510 CXTranslationUnit TU) {
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +0000511 assert(Proto && TU && "Invalid arguments!");
Douglas Gregor78db0cd2010-01-16 15:44:18 +0000512 void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +0000513 CXCursor C = { CXCursor_ObjCProtocolRef, 0, { (void*)Proto, RawLoc, TU } };
Douglas Gregor78db0cd2010-01-16 15:44:18 +0000514 return C;
515}
516
517std::pair<ObjCProtocolDecl *, SourceLocation>
518cxcursor::getCursorObjCProtocolRef(CXCursor C) {
519 assert(C.kind == CXCursor_ObjCProtocolRef);
520 return std::make_pair(static_cast<ObjCProtocolDecl *>(C.data[0]),
521 SourceLocation::getFromRawEncoding(
522 reinterpret_cast<uintptr_t>(C.data[1])));
523}
524
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +0000525CXCursor cxcursor::MakeCursorObjCClassRef(const ObjCInterfaceDecl *Class,
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000526 SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000527 CXTranslationUnit TU) {
Ted Kremenekebfa3392010-03-19 20:39:03 +0000528 // 'Class' can be null for invalid code.
529 if (!Class)
530 return MakeCXCursorInvalid(CXCursor_InvalidCode);
531 assert(TU && "Invalid arguments!");
Douglas Gregor1adb0822010-01-16 17:14:40 +0000532 void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +0000533 CXCursor C = { CXCursor_ObjCClassRef, 0, { (void*)Class, RawLoc, TU } };
Douglas Gregor1adb0822010-01-16 17:14:40 +0000534 return C;
535}
536
537std::pair<ObjCInterfaceDecl *, SourceLocation>
538cxcursor::getCursorObjCClassRef(CXCursor C) {
539 assert(C.kind == CXCursor_ObjCClassRef);
540 return std::make_pair(static_cast<ObjCInterfaceDecl *>(C.data[0]),
541 SourceLocation::getFromRawEncoding(
542 reinterpret_cast<uintptr_t>(C.data[1])));
543}
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!");
Douglas Gregor7d0d40e2010-01-21 16:28:34 +0000548 void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
Argyrios Kyrtzidis4e7064f2011-10-17 19:48:19 +0000549 CXCursor C = { CXCursor_TypeRef, 0, { (void*)Type, RawLoc, TU } };
Douglas Gregor7d0d40e2010-01-21 16:28:34 +0000550 return C;
551}
552
553std::pair<TypeDecl *, SourceLocation>
554cxcursor::getCursorTypeRef(CXCursor C) {
555 assert(C.kind == CXCursor_TypeRef);
556 return std::make_pair(static_cast<TypeDecl *>(C.data[0]),
557 SourceLocation::getFromRawEncoding(
558 reinterpret_cast<uintptr_t>(C.data[1])));
559}
560
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +0000561CXCursor cxcursor::MakeCursorTemplateRef(const TemplateDecl *Template,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000562 SourceLocation Loc,
563 CXTranslationUnit TU) {
Douglas Gregor0b36e612010-08-31 20:37:03 +0000564 assert(Template && TU && "Invalid arguments!");
565 void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +0000566 CXCursor C = { CXCursor_TemplateRef, 0, { (void*)Template, RawLoc, TU } };
Douglas Gregor0b36e612010-08-31 20:37:03 +0000567 return C;
568}
569
570std::pair<TemplateDecl *, SourceLocation>
571cxcursor::getCursorTemplateRef(CXCursor C) {
572 assert(C.kind == CXCursor_TemplateRef);
573 return std::make_pair(static_cast<TemplateDecl *>(C.data[0]),
574 SourceLocation::getFromRawEncoding(
575 reinterpret_cast<uintptr_t>(C.data[1])));
576}
577
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +0000578CXCursor cxcursor::MakeCursorNamespaceRef(const NamedDecl *NS,
579 SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000580 CXTranslationUnit TU) {
Douglas Gregor69319002010-08-31 23:48:11 +0000581
582 assert(NS && (isa<NamespaceDecl>(NS) || isa<NamespaceAliasDecl>(NS)) && TU &&
583 "Invalid arguments!");
584 void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +0000585 CXCursor C = { CXCursor_NamespaceRef, 0, { (void*)NS, RawLoc, TU } };
Douglas Gregor69319002010-08-31 23:48:11 +0000586 return C;
587}
588
589std::pair<NamedDecl *, SourceLocation>
590cxcursor::getCursorNamespaceRef(CXCursor C) {
591 assert(C.kind == CXCursor_NamespaceRef);
592 return std::make_pair(static_cast<NamedDecl *>(C.data[0]),
593 SourceLocation::getFromRawEncoding(
594 reinterpret_cast<uintptr_t>(C.data[1])));
595}
596
Douglas Gregor011d8b92012-02-15 00:54:55 +0000597CXCursor cxcursor::MakeCursorVariableRef(const VarDecl *Var, SourceLocation Loc,
598 CXTranslationUnit TU) {
599
600 assert(Var && TU && "Invalid arguments!");
601 void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
602 CXCursor C = { CXCursor_VariableRef, 0, { (void*)Var, RawLoc, TU } };
603 return C;
604}
605
606std::pair<VarDecl *, SourceLocation>
607cxcursor::getCursorVariableRef(CXCursor C) {
608 assert(C.kind == CXCursor_VariableRef);
609 return std::make_pair(static_cast<VarDecl *>(C.data[0]),
610 SourceLocation::getFromRawEncoding(
611 reinterpret_cast<uintptr_t>(C.data[1])));
612}
613
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +0000614CXCursor cxcursor::MakeCursorMemberRef(const FieldDecl *Field, SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000615 CXTranslationUnit TU) {
Douglas Gregora67e03f2010-09-09 21:42:20 +0000616
617 assert(Field && TU && "Invalid arguments!");
618 void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
Argyrios Kyrtzidisb395c632011-11-18 00:26:51 +0000619 CXCursor C = { CXCursor_MemberRef, 0, { (void*)Field, RawLoc, TU } };
Douglas Gregora67e03f2010-09-09 21:42:20 +0000620 return C;
621}
622
623std::pair<FieldDecl *, SourceLocation>
624cxcursor::getCursorMemberRef(CXCursor C) {
625 assert(C.kind == CXCursor_MemberRef);
626 return std::make_pair(static_cast<FieldDecl *>(C.data[0]),
627 SourceLocation::getFromRawEncoding(
628 reinterpret_cast<uintptr_t>(C.data[1])));
629}
630
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +0000631CXCursor cxcursor::MakeCursorCXXBaseSpecifier(const CXXBaseSpecifier *B,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000632 CXTranslationUnit TU){
Argyrios Kyrtzidis2957e6f2011-11-22 07:24:51 +0000633 CXCursor C = { CXCursor_CXXBaseSpecifier, 0, { (void*)B, 0, TU } };
Ted Kremenek3064ef92010-08-27 21:34:58 +0000634 return C;
635}
636
637CXXBaseSpecifier *cxcursor::getCursorCXXBaseSpecifier(CXCursor C) {
638 assert(C.kind == CXCursor_CXXBaseSpecifier);
639 return static_cast<CXXBaseSpecifier*>(C.data[0]);
640}
641
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +0000642CXCursor cxcursor::MakePreprocessingDirectiveCursor(SourceRange Range,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000643 CXTranslationUnit TU) {
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000644 CXCursor C = { CXCursor_PreprocessingDirective, 0,
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +0000645 { reinterpret_cast<void *>(Range.getBegin().getRawEncoding()),
646 reinterpret_cast<void *>(Range.getEnd().getRawEncoding()),
647 TU }
648 };
649 return C;
650}
651
652SourceRange cxcursor::getCursorPreprocessingDirective(CXCursor C) {
653 assert(C.kind == CXCursor_PreprocessingDirective);
Argyrios Kyrtzidisee0f84f2011-09-26 08:01:41 +0000654 SourceRange Range = SourceRange(SourceLocation::getFromRawEncoding(
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +0000655 reinterpret_cast<uintptr_t> (C.data[0])),
656 SourceLocation::getFromRawEncoding(
657 reinterpret_cast<uintptr_t> (C.data[1])));
Argyrios Kyrtzidisee0f84f2011-09-26 08:01:41 +0000658 ASTUnit *TU = getCursorASTUnit(C);
659 return TU->mapRangeFromPreamble(Range);
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +0000660}
661
Ted Kremeneka60ed472010-11-16 08:15:36 +0000662CXCursor cxcursor::MakeMacroDefinitionCursor(MacroDefinition *MI,
663 CXTranslationUnit TU) {
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000664 CXCursor C = { CXCursor_MacroDefinition, 0, { MI, 0, TU } };
Douglas Gregor572feb22010-03-18 18:04:21 +0000665 return C;
666}
667
668MacroDefinition *cxcursor::getCursorMacroDefinition(CXCursor C) {
669 assert(C.kind == CXCursor_MacroDefinition);
670 return static_cast<MacroDefinition *>(C.data[0]);
671}
672
Chandler Carruth9e5bb852011-07-14 08:20:46 +0000673CXCursor cxcursor::MakeMacroExpansionCursor(MacroExpansion *MI,
674 CXTranslationUnit TU) {
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000675 CXCursor C = { CXCursor_MacroExpansion, 0, { MI, 0, TU } };
Douglas Gregor48072312010-03-18 15:23:44 +0000676 return C;
677}
678
Chandler Carruth9e5bb852011-07-14 08:20:46 +0000679MacroExpansion *cxcursor::getCursorMacroExpansion(CXCursor C) {
Chandler Carruth9b2a0ac2011-07-14 08:41:15 +0000680 assert(C.kind == CXCursor_MacroExpansion);
Chandler Carruth9e5bb852011-07-14 08:20:46 +0000681 return static_cast<MacroExpansion *>(C.data[0]);
Douglas Gregor48072312010-03-18 15:23:44 +0000682}
683
Douglas Gregorecdcb882010-10-20 22:00:55 +0000684CXCursor cxcursor::MakeInclusionDirectiveCursor(InclusionDirective *ID,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000685 CXTranslationUnit TU) {
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000686 CXCursor C = { CXCursor_InclusionDirective, 0, { ID, 0, TU } };
Douglas Gregorecdcb882010-10-20 22:00:55 +0000687 return C;
688}
689
690InclusionDirective *cxcursor::getCursorInclusionDirective(CXCursor C) {
691 assert(C.kind == CXCursor_InclusionDirective);
692 return static_cast<InclusionDirective *>(C.data[0]);
693}
694
Douglas Gregor36897b02010-09-10 00:22:18 +0000695CXCursor cxcursor::MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000696 CXTranslationUnit TU) {
Douglas Gregor36897b02010-09-10 00:22:18 +0000697
698 assert(Label && TU && "Invalid arguments!");
699 void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000700 CXCursor C = { CXCursor_LabelRef, 0, { Label, RawLoc, TU } };
Douglas Gregor36897b02010-09-10 00:22:18 +0000701 return C;
702}
703
704std::pair<LabelStmt*, SourceLocation>
705cxcursor::getCursorLabelRef(CXCursor C) {
706 assert(C.kind == CXCursor_LabelRef);
707 return std::make_pair(static_cast<LabelStmt *>(C.data[0]),
708 SourceLocation::getFromRawEncoding(
709 reinterpret_cast<uintptr_t>(C.data[1])));
710}
711
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000712CXCursor cxcursor::MakeCursorOverloadedDeclRef(OverloadExpr *E,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000713 CXTranslationUnit TU) {
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000714 assert(E && TU && "Invalid arguments!");
715 OverloadedDeclRefStorage Storage(E);
716 void *RawLoc = reinterpret_cast<void *>(E->getNameLoc().getRawEncoding());
717 CXCursor C = {
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000718 CXCursor_OverloadedDeclRef, 0,
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000719 { Storage.getOpaqueValue(), RawLoc, TU }
720 };
721 return C;
722}
723
724CXCursor cxcursor::MakeCursorOverloadedDeclRef(Decl *D,
725 SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000726 CXTranslationUnit TU) {
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000727 assert(D && TU && "Invalid arguments!");
728 void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
729 OverloadedDeclRefStorage Storage(D);
730 CXCursor C = {
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000731 CXCursor_OverloadedDeclRef, 0,
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000732 { Storage.getOpaqueValue(), RawLoc, TU }
733 };
734 return C;
735}
736
737CXCursor cxcursor::MakeCursorOverloadedDeclRef(TemplateName Name,
738 SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000739 CXTranslationUnit TU) {
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000740 assert(Name.getAsOverloadedTemplate() && TU && "Invalid arguments!");
741 void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
742 OverloadedDeclRefStorage Storage(Name.getAsOverloadedTemplate());
743 CXCursor C = {
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000744 CXCursor_OverloadedDeclRef, 0,
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000745 { Storage.getOpaqueValue(), RawLoc, TU }
746 };
747 return C;
748}
749
750std::pair<cxcursor::OverloadedDeclRefStorage, SourceLocation>
751cxcursor::getCursorOverloadedDeclRef(CXCursor C) {
752 assert(C.kind == CXCursor_OverloadedDeclRef);
753 return std::make_pair(OverloadedDeclRefStorage::getFromOpaqueValue(C.data[0]),
754 SourceLocation::getFromRawEncoding(
755 reinterpret_cast<uintptr_t>(C.data[1])));
756}
757
Douglas Gregor283cae32010-01-15 21:56:13 +0000758Decl *cxcursor::getCursorDecl(CXCursor Cursor) {
759 return (Decl *)Cursor.data[0];
760}
761
762Expr *cxcursor::getCursorExpr(CXCursor Cursor) {
763 return dyn_cast_or_null<Expr>(getCursorStmt(Cursor));
764}
765
766Stmt *cxcursor::getCursorStmt(CXCursor Cursor) {
Douglas Gregor78db0cd2010-01-16 15:44:18 +0000767 if (Cursor.kind == CXCursor_ObjCSuperClassRef ||
Douglas Gregor1adb0822010-01-16 17:14:40 +0000768 Cursor.kind == CXCursor_ObjCProtocolRef ||
769 Cursor.kind == CXCursor_ObjCClassRef)
Douglas Gregor2e331b92010-01-16 14:00:32 +0000770 return 0;
771
Douglas Gregor283cae32010-01-15 21:56:13 +0000772 return (Stmt *)Cursor.data[1];
773}
774
Ted Kremenek95f33552010-08-26 01:42:22 +0000775Attr *cxcursor::getCursorAttr(CXCursor Cursor) {
776 return (Attr *)Cursor.data[1];
777}
778
Argyrios Kyrtzidis8ccac3d2011-06-29 22:20:07 +0000779Decl *cxcursor::getCursorParentDecl(CXCursor Cursor) {
780 return (Decl *)Cursor.data[0];
781}
782
Douglas Gregorf46034a2010-01-18 23:41:10 +0000783ASTContext &cxcursor::getCursorContext(CXCursor Cursor) {
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000784 return getCursorASTUnit(Cursor)->getASTContext();
785}
Douglas Gregorf46034a2010-01-18 23:41:10 +0000786
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000787ASTUnit *cxcursor::getCursorASTUnit(CXCursor Cursor) {
Argyrios Kyrtzidis44517462011-12-09 00:17:49 +0000788 CXTranslationUnit TU = static_cast<CXTranslationUnit>(Cursor.data[2]);
789 if (!TU)
790 return 0;
791 return static_cast<ASTUnit *>(TU->TUData);
Ted Kremeneka60ed472010-11-16 08:15:36 +0000792}
793
794CXTranslationUnit cxcursor::getCursorTU(CXCursor Cursor) {
795 return static_cast<CXTranslationUnit>(Cursor.data[2]);
Douglas Gregor283cae32010-01-15 21:56:13 +0000796}
797
Argyrios Kyrtzidis15f4c982012-04-10 21:01:03 +0000798static void CollectOverriddenMethodsRecurse(CXTranslationUnit TU,
799 ObjCContainerDecl *Container,
Argyrios Kyrtzidisb11be042011-10-06 07:00:46 +0000800 ObjCMethodDecl *Method,
Argyrios Kyrtzidis15f4c982012-04-10 21:01:03 +0000801 SmallVectorImpl<CXCursor> &Methods,
802 bool MovedToSuper) {
Argyrios Kyrtzidisb11be042011-10-06 07:00:46 +0000803 if (!Container)
804 return;
805
Argyrios Kyrtzidis044e6452012-03-08 00:20:03 +0000806 // In categories look for overriden methods from protocols. A method from
807 // category is not "overriden" since it is considered as the "same" method
808 // (same USR) as the one from the interface.
809 if (ObjCCategoryDecl *Category = dyn_cast<ObjCCategoryDecl>(Container)) {
Argyrios Kyrtzidis15f4c982012-04-10 21:01:03 +0000810 // Check whether we have a matching method at this category but only if we
811 // are at the super class level.
812 if (MovedToSuper)
813 if (ObjCMethodDecl *
814 Overridden = Container->getMethod(Method->getSelector(),
815 Method->isInstanceMethod()))
816 if (Method != Overridden) {
817 // We found an override at this category; there is no need to look
818 // into its protocols.
819 Methods.push_back(MakeCXCursor(Overridden, TU));
820 return;
821 }
822
Argyrios Kyrtzidis044e6452012-03-08 00:20:03 +0000823 for (ObjCCategoryDecl::protocol_iterator P = Category->protocol_begin(),
824 PEnd = Category->protocol_end();
825 P != PEnd; ++P)
Argyrios Kyrtzidis15f4c982012-04-10 21:01:03 +0000826 CollectOverriddenMethodsRecurse(TU, *P, Method, Methods, MovedToSuper);
Argyrios Kyrtzidis044e6452012-03-08 00:20:03 +0000827 return;
828 }
829
Argyrios Kyrtzidisb11be042011-10-06 07:00:46 +0000830 // Check whether we have a matching method at this level.
831 if (ObjCMethodDecl *Overridden = Container->getMethod(Method->getSelector(),
832 Method->isInstanceMethod()))
833 if (Method != Overridden) {
834 // We found an override at this level; there is no need to look
835 // into other protocols or categories.
836 Methods.push_back(MakeCXCursor(Overridden, TU));
837 return;
838 }
839
840 if (ObjCProtocolDecl *Protocol = dyn_cast<ObjCProtocolDecl>(Container)) {
841 for (ObjCProtocolDecl::protocol_iterator P = Protocol->protocol_begin(),
842 PEnd = Protocol->protocol_end();
843 P != PEnd; ++P)
Argyrios Kyrtzidis15f4c982012-04-10 21:01:03 +0000844 CollectOverriddenMethodsRecurse(TU, *P, Method, Methods, MovedToSuper);
Argyrios Kyrtzidisb11be042011-10-06 07:00:46 +0000845 }
846
Argyrios Kyrtzidisb11be042011-10-06 07:00:46 +0000847 if (ObjCInterfaceDecl *Interface = dyn_cast<ObjCInterfaceDecl>(Container)) {
848 for (ObjCInterfaceDecl::protocol_iterator P = Interface->protocol_begin(),
849 PEnd = Interface->protocol_end();
850 P != PEnd; ++P)
Argyrios Kyrtzidis15f4c982012-04-10 21:01:03 +0000851 CollectOverriddenMethodsRecurse(TU, *P, Method, Methods, MovedToSuper);
Argyrios Kyrtzidisb11be042011-10-06 07:00:46 +0000852
853 for (ObjCCategoryDecl *Category = Interface->getCategoryList();
854 Category; Category = Category->getNextClassCategory())
Argyrios Kyrtzidis15f4c982012-04-10 21:01:03 +0000855 CollectOverriddenMethodsRecurse(TU, Category, Method, Methods,
856 MovedToSuper);
Argyrios Kyrtzidisb11be042011-10-06 07:00:46 +0000857
Argyrios Kyrtzidis044e6452012-03-08 00:20:03 +0000858 if (ObjCInterfaceDecl *Super = Interface->getSuperClass())
Argyrios Kyrtzidis15f4c982012-04-10 21:01:03 +0000859 return CollectOverriddenMethodsRecurse(TU, Super, Method, Methods,
860 /*MovedToSuper=*/true);
Argyrios Kyrtzidisb11be042011-10-06 07:00:46 +0000861 }
862}
863
Argyrios Kyrtzidis15f4c982012-04-10 21:01:03 +0000864static inline void CollectOverriddenMethods(CXTranslationUnit TU,
865 ObjCContainerDecl *Container,
866 ObjCMethodDecl *Method,
867 SmallVectorImpl<CXCursor> &Methods) {
868 CollectOverriddenMethodsRecurse(TU, Container, Method, Methods,
869 /*MovedToSuper=*/false);
870}
871
Argyrios Kyrtzidise15db6f2012-05-09 16:12:57 +0000872static void collectOverriddenMethodsSlow(CXTranslationUnit TU,
873 ObjCMethodDecl *Method,
874 SmallVectorImpl<CXCursor> &overridden) {
875 assert(Method->isOverriding());
Argyrios Kyrtzidisb11be042011-10-06 07:00:46 +0000876
Argyrios Kyrtzidis044e6452012-03-08 00:20:03 +0000877 if (ObjCProtocolDecl *
878 ProtD = dyn_cast<ObjCProtocolDecl>(Method->getDeclContext())) {
879 CollectOverriddenMethods(TU, ProtD, Method, overridden);
880
881 } else if (ObjCImplDecl *
882 IMD = dyn_cast<ObjCImplDecl>(Method->getDeclContext())) {
883 ObjCInterfaceDecl *ID = IMD->getClassInterface();
884 if (!ID)
885 return;
886 // Start searching for overridden methods using the method from the
887 // interface as starting point.
888 if (ObjCMethodDecl *IFaceMeth = ID->getMethod(Method->getSelector(),
889 Method->isInstanceMethod()))
890 Method = IFaceMeth;
891 CollectOverriddenMethods(TU, ID, Method, overridden);
892
893 } else if (ObjCCategoryDecl *
894 CatD = dyn_cast<ObjCCategoryDecl>(Method->getDeclContext())) {
895 ObjCInterfaceDecl *ID = CatD->getClassInterface();
896 if (!ID)
897 return;
898 // Start searching for overridden methods using the method from the
899 // interface as starting point.
900 if (ObjCMethodDecl *IFaceMeth = ID->getMethod(Method->getSelector(),
901 Method->isInstanceMethod()))
902 Method = IFaceMeth;
903 CollectOverriddenMethods(TU, ID, Method, overridden);
904
905 } else {
Argyrios Kyrtzidis15f4c982012-04-10 21:01:03 +0000906 CollectOverriddenMethods(TU,
907 dyn_cast_or_null<ObjCContainerDecl>(Method->getDeclContext()),
908 Method, overridden);
Argyrios Kyrtzidis044e6452012-03-08 00:20:03 +0000909 }
Argyrios Kyrtzidisb11be042011-10-06 07:00:46 +0000910}
911
Argyrios Kyrtzidise15db6f2012-05-09 16:12:57 +0000912static void collectOnCategoriesAfterLocation(SourceLocation Loc,
913 ObjCInterfaceDecl *Class,
914 CXTranslationUnit TU,
915 ObjCMethodDecl *Method,
916 SmallVectorImpl<CXCursor> &Methods) {
917 if (!Class)
918 return;
919
920 SourceManager &SM = static_cast<ASTUnit *>(TU->TUData)->getSourceManager();
921 for (ObjCCategoryDecl *Category = Class->getCategoryList();
922 Category; Category = Category->getNextClassCategory())
923 if (SM.isBeforeInTranslationUnit(Loc, Category->getLocation()))
924 CollectOverriddenMethodsRecurse(TU, Category, Method, Methods, true);
925
926 collectOnCategoriesAfterLocation(Loc, Class->getSuperClass(), TU,
927 Method, Methods);
928}
929
930/// \brief Faster collection that is enabled when ObjCMethodDecl::isOverriding()
931/// returns false.
932/// You'd think that in that case there are no overrides but categories can
933/// "introduce" new overridden methods that are missed by Sema because the
934/// overrides lookup that it does for methods, inside implementations, will
935/// stop at the interface level (if there is a method there) and not look
936/// further in super classes.
937static void collectOverriddenMethodsFast(CXTranslationUnit TU,
938 ObjCMethodDecl *Method,
939 SmallVectorImpl<CXCursor> &Methods) {
940 assert(!Method->isOverriding());
941
942 ObjCContainerDecl *ContD = cast<ObjCContainerDecl>(Method->getDeclContext());
943 if (isa<ObjCInterfaceDecl>(ContD) || isa<ObjCProtocolDecl>(ContD))
944 return;
945 ObjCInterfaceDecl *Class = Method->getClassInterface();
946 if (!Class)
947 return;
948
949 collectOnCategoriesAfterLocation(Class->getLocation(), Class->getSuperClass(),
950 TU, Method, Methods);
951}
952
953void cxcursor::getOverriddenCursors(CXCursor cursor,
954 SmallVectorImpl<CXCursor> &overridden) {
955 assert(clang_isDeclaration(cursor.kind));
956 Decl *D = getCursorDecl(cursor);
957 if (!D)
958 return;
959
960 // Handle C++ member functions.
961 CXTranslationUnit TU = getCursorTU(cursor);
962 if (CXXMethodDecl *CXXMethod = dyn_cast<CXXMethodDecl>(D)) {
963 for (CXXMethodDecl::method_iterator
964 M = CXXMethod->begin_overridden_methods(),
965 MEnd = CXXMethod->end_overridden_methods();
966 M != MEnd; ++M)
967 overridden.push_back(MakeCXCursor(const_cast<CXXMethodDecl*>(*M), TU));
968 return;
969 }
970
971 ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(D);
972 if (!Method)
973 return;
974
975 if (Method->isRedeclaration()) {
976 Method = cast<ObjCContainerDecl>(Method->getDeclContext())->
977 getMethod(Method->getSelector(), Method->isInstanceMethod());
978 }
979
980 if (!Method->isOverriding()) {
981 collectOverriddenMethodsFast(TU, Method, overridden);
982 } else {
983 collectOverriddenMethodsSlow(TU, Method, overridden);
984 assert(!overridden.empty() &&
985 "ObjCMethodDecl's overriding bit is not as expected");
986 }
987}
988
Argyrios Kyrtzidisaed123e2011-10-06 07:00:54 +0000989std::pair<int, SourceLocation>
990cxcursor::getSelectorIdentifierIndexAndLoc(CXCursor cursor) {
991 if (cursor.kind == CXCursor_ObjCMessageExpr) {
992 if (cursor.xdata != -1)
993 return std::make_pair(cursor.xdata,
994 cast<ObjCMessageExpr>(getCursorExpr(cursor))
995 ->getSelectorLoc(cursor.xdata));
996 } else if (cursor.kind == CXCursor_ObjCClassMethodDecl ||
997 cursor.kind == CXCursor_ObjCInstanceMethodDecl) {
998 if (cursor.xdata != -1)
999 return std::make_pair(cursor.xdata,
1000 cast<ObjCMethodDecl>(getCursorDecl(cursor))
1001 ->getSelectorLoc(cursor.xdata));
1002 }
1003
1004 return std::make_pair(-1, SourceLocation());
1005}
1006
1007CXCursor cxcursor::getSelectorIdentifierCursor(int SelIdx, CXCursor cursor) {
1008 CXCursor newCursor = cursor;
1009
1010 if (cursor.kind == CXCursor_ObjCMessageExpr) {
1011 if (SelIdx == -1 ||
1012 unsigned(SelIdx) >= cast<ObjCMessageExpr>(getCursorExpr(cursor))
1013 ->getNumSelectorLocs())
1014 newCursor.xdata = -1;
1015 else
1016 newCursor.xdata = SelIdx;
1017 } else if (cursor.kind == CXCursor_ObjCClassMethodDecl ||
1018 cursor.kind == CXCursor_ObjCInstanceMethodDecl) {
1019 if (SelIdx == -1 ||
1020 unsigned(SelIdx) >= cast<ObjCMethodDecl>(getCursorDecl(cursor))
1021 ->getNumSelectorLocs())
1022 newCursor.xdata = -1;
1023 else
1024 newCursor.xdata = SelIdx;
1025 }
1026
1027 return newCursor;
1028}
1029
1030CXCursor cxcursor::getTypeRefCursor(CXCursor cursor) {
1031 if (cursor.kind != CXCursor_CallExpr)
1032 return cursor;
1033
1034 if (cursor.xdata == 0)
1035 return cursor;
1036
1037 Expr *E = getCursorExpr(cursor);
1038 TypeSourceInfo *Type = 0;
1039 if (CXXUnresolvedConstructExpr *
1040 UnCtor = dyn_cast<CXXUnresolvedConstructExpr>(E)) {
1041 Type = UnCtor->getTypeSourceInfo();
1042 } else if (CXXTemporaryObjectExpr *Tmp = dyn_cast<CXXTemporaryObjectExpr>(E)){
1043 Type = Tmp->getTypeSourceInfo();
1044 }
1045
1046 if (!Type)
1047 return cursor;
1048
1049 CXTranslationUnit TU = getCursorTU(cursor);
1050 QualType Ty = Type->getType();
1051 TypeLoc TL = Type->getTypeLoc();
1052 SourceLocation Loc = TL.getBeginLoc();
1053
1054 if (const ElaboratedType *ElabT = Ty->getAs<ElaboratedType>()) {
1055 Ty = ElabT->getNamedType();
1056 ElaboratedTypeLoc ElabTL = cast<ElaboratedTypeLoc>(TL);
1057 Loc = ElabTL.getNamedTypeLoc().getBeginLoc();
1058 }
1059
1060 if (const TypedefType *Typedef = Ty->getAs<TypedefType>())
1061 return MakeCursorTypeRef(Typedef->getDecl(), Loc, TU);
1062 if (const TagType *Tag = Ty->getAs<TagType>())
1063 return MakeCursorTypeRef(Tag->getDecl(), Loc, TU);
1064 if (const TemplateTypeParmType *TemplP = Ty->getAs<TemplateTypeParmType>())
1065 return MakeCursorTypeRef(TemplP->getDecl(), Loc, TU);
1066
1067 return cursor;
1068}
1069
Douglas Gregor283cae32010-01-15 21:56:13 +00001070bool cxcursor::operator==(CXCursor X, CXCursor Y) {
1071 return X.kind == Y.kind && X.data[0] == Y.data[0] && X.data[1] == Y.data[1] &&
1072 X.data[2] == Y.data[2];
Douglas Gregor2e331b92010-01-16 14:00:32 +00001073}
Ted Kremenek007a7c92010-11-01 23:26:51 +00001074
1075// FIXME: Remove once we can model DeclGroups and their appropriate ranges
1076// properly in the ASTs.
1077bool cxcursor::isFirstInDeclGroup(CXCursor C) {
1078 assert(clang_isDeclaration(C.kind));
1079 return ((uintptr_t) (C.data[1])) != 0;
1080}
1081
Ted Kremenekeca099b2010-12-08 23:43:14 +00001082//===----------------------------------------------------------------------===//
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +00001083// libclang CXCursor APIs
1084//===----------------------------------------------------------------------===//
1085
Argyrios Kyrtzidisfa865df2011-09-27 04:14:36 +00001086extern "C" {
1087
1088int clang_Cursor_isNull(CXCursor cursor) {
1089 return clang_equalCursors(cursor, clang_getNullCursor());
1090}
1091
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +00001092CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor cursor) {
1093 return getCursorTU(cursor);
1094}
1095
Argyrios Kyrtzidisd98ef9a2012-04-11 19:32:19 +00001096int clang_Cursor_getNumArguments(CXCursor C) {
1097 if (clang_isDeclaration(C.kind)) {
1098 Decl *D = cxcursor::getCursorDecl(C);
1099 if (const ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(D))
1100 return MD->param_size();
1101 if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
1102 return FD->param_size();
1103 }
1104
1105 return -1;
1106}
1107
1108CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i) {
1109 if (clang_isDeclaration(C.kind)) {
1110 Decl *D = cxcursor::getCursorDecl(C);
1111 if (ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(D)) {
1112 if (i < MD->param_size())
1113 return cxcursor::MakeCXCursor(MD->param_begin()[i],
1114 cxcursor::getCursorTU(C));
1115 } else if (FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) {
1116 if (i < FD->param_size())
1117 return cxcursor::MakeCXCursor(FD->param_begin()[i],
1118 cxcursor::getCursorTU(C));
1119 }
1120 }
1121
1122 return clang_getNullCursor();
1123}
1124
Argyrios Kyrtzidisfa865df2011-09-27 04:14:36 +00001125} // end: extern "C"
1126
Argyrios Kyrtzidisb0d6eaa2011-09-27 00:30:30 +00001127//===----------------------------------------------------------------------===//
Ted Kremenekeca099b2010-12-08 23:43:14 +00001128// CXCursorSet.
1129//===----------------------------------------------------------------------===//
1130
1131typedef llvm::DenseMap<CXCursor, unsigned> CXCursorSet_Impl;
1132
1133static inline CXCursorSet packCXCursorSet(CXCursorSet_Impl *setImpl) {
1134 return (CXCursorSet) setImpl;
1135}
1136static inline CXCursorSet_Impl *unpackCXCursorSet(CXCursorSet set) {
1137 return (CXCursorSet_Impl*) set;
1138}
1139namespace llvm {
Ted Kremenekda6fb692010-12-09 00:33:41 +00001140template<> struct DenseMapInfo<CXCursor> {
Ted Kremenekeca099b2010-12-08 23:43:14 +00001141public:
1142 static inline CXCursor getEmptyKey() {
1143 return MakeCXCursorInvalid(CXCursor_InvalidFile);
1144 }
1145 static inline CXCursor getTombstoneKey() {
1146 return MakeCXCursorInvalid(CXCursor_NoDeclFound);
1147 }
1148 static inline unsigned getHashValue(const CXCursor &cursor) {
1149 return llvm::DenseMapInfo<std::pair<void*,void*> >
1150 ::getHashValue(std::make_pair(cursor.data[0], cursor.data[1]));
1151 }
1152 static inline bool isEqual(const CXCursor &x, const CXCursor &y) {
1153 return x.kind == y.kind &&
1154 x.data[0] == y.data[0] &&
1155 x.data[1] == y.data[1];
1156 }
1157};
1158}
1159
1160extern "C" {
1161CXCursorSet clang_createCXCursorSet() {
1162 return packCXCursorSet(new CXCursorSet_Impl());
1163}
1164
1165void clang_disposeCXCursorSet(CXCursorSet set) {
1166 delete unpackCXCursorSet(set);
1167}
1168
1169unsigned clang_CXCursorSet_contains(CXCursorSet set, CXCursor cursor) {
1170 CXCursorSet_Impl *setImpl = unpackCXCursorSet(set);
1171 if (!setImpl)
1172 return 0;
1173 return setImpl->find(cursor) == setImpl->end();
1174}
1175
Anders Carlssone8b3de02010-12-09 01:00:12 +00001176unsigned clang_CXCursorSet_insert(CXCursorSet set, CXCursor cursor) {
Ted Kremenekeca099b2010-12-08 23:43:14 +00001177 // Do not insert invalid cursors into the set.
1178 if (cursor.kind >= CXCursor_FirstInvalid &&
1179 cursor.kind <= CXCursor_LastInvalid)
1180 return 1;
1181
1182 CXCursorSet_Impl *setImpl = unpackCXCursorSet(set);
1183 if (!setImpl)
1184 return 1;
1185 unsigned &entry = (*setImpl)[cursor];
1186 unsigned flag = entry == 0 ? 1 : 0;
1187 entry = 1;
1188 return flag;
1189}
Douglas Gregor8fa0a802011-08-04 20:04:59 +00001190
1191CXCompletionString clang_getCursorCompletionString(CXCursor cursor) {
1192 enum CXCursorKind kind = clang_getCursorKind(cursor);
1193 if (clang_isDeclaration(kind)) {
1194 Decl *decl = getCursorDecl(cursor);
Argyrios Kyrtzidis16ed0e62011-12-10 02:36:25 +00001195 if (NamedDecl *namedDecl = dyn_cast_or_null<NamedDecl>(decl)) {
Douglas Gregor8fa0a802011-08-04 20:04:59 +00001196 ASTUnit *unit = getCursorASTUnit(cursor);
Argyrios Kyrtzidis5e192a72012-01-17 02:15:54 +00001197 CodeCompletionResult Result(namedDecl);
1198 CodeCompletionString *String
1199 = Result.CreateCodeCompletionString(unit->getASTContext(),
1200 unit->getPreprocessor(),
Argyrios Kyrtzidis28a83f52012-04-10 17:23:48 +00001201 unit->getCodeCompletionTUInfo().getAllocator(),
Dmitri Gribenkod99ef532012-07-02 17:35:10 +00001202 unit->getCodeCompletionTUInfo(),
1203 true);
Argyrios Kyrtzidis5e192a72012-01-17 02:15:54 +00001204 return String;
Douglas Gregor8fa0a802011-08-04 20:04:59 +00001205 }
1206 }
1207 else if (kind == CXCursor_MacroDefinition) {
1208 MacroDefinition *definition = getCursorMacroDefinition(cursor);
1209 const IdentifierInfo *MacroInfo = definition->getName();
1210 ASTUnit *unit = getCursorASTUnit(cursor);
Argyrios Kyrtzidis5e192a72012-01-17 02:15:54 +00001211 CodeCompletionResult Result(const_cast<IdentifierInfo *>(MacroInfo));
1212 CodeCompletionString *String
1213 = Result.CreateCodeCompletionString(unit->getASTContext(),
1214 unit->getPreprocessor(),
Argyrios Kyrtzidis28a83f52012-04-10 17:23:48 +00001215 unit->getCodeCompletionTUInfo().getAllocator(),
Dmitri Gribenkod99ef532012-07-02 17:35:10 +00001216 unit->getCodeCompletionTUInfo(),
1217 false);
Argyrios Kyrtzidis5e192a72012-01-17 02:15:54 +00001218 return String;
Douglas Gregor8fa0a802011-08-04 20:04:59 +00001219 }
1220 return NULL;
1221}
Ted Kremenek8eece462012-04-30 19:33:45 +00001222} // end: extern C.
Ted Kremenekbbf66ca2012-04-30 19:06:49 +00001223
1224namespace {
1225 struct OverridenCursorsPool {
1226 typedef llvm::SmallVector<CXCursor, 2> CursorVec;
1227 std::vector<CursorVec*> AllCursors;
1228 std::vector<CursorVec*> AvailableCursors;
1229
1230 ~OverridenCursorsPool() {
1231 for (std::vector<CursorVec*>::iterator I = AllCursors.begin(),
1232 E = AllCursors.end(); I != E; ++I) {
1233 delete *I;
1234 }
1235 }
1236 };
1237}
1238
1239void *cxcursor::createOverridenCXCursorsPool() {
1240 return new OverridenCursorsPool();
1241}
1242
1243void cxcursor::disposeOverridenCXCursorsPool(void *pool) {
1244 delete static_cast<OverridenCursorsPool*>(pool);
1245}
Ted Kremenek8eece462012-04-30 19:33:45 +00001246
1247extern "C" {
Ted Kremenekbbf66ca2012-04-30 19:06:49 +00001248void clang_getOverriddenCursors(CXCursor cursor,
1249 CXCursor **overridden,
1250 unsigned *num_overridden) {
1251 if (overridden)
1252 *overridden = 0;
1253 if (num_overridden)
1254 *num_overridden = 0;
1255
1256 CXTranslationUnit TU = cxcursor::getCursorTU(cursor);
1257
1258 if (!overridden || !num_overridden || !TU)
1259 return;
1260
1261 if (!clang_isDeclaration(cursor.kind))
1262 return;
1263
1264 OverridenCursorsPool &pool =
1265 *static_cast<OverridenCursorsPool*>(TU->OverridenCursorsPool);
1266
1267 OverridenCursorsPool::CursorVec *Vec = 0;
1268
1269 if (!pool.AvailableCursors.empty()) {
1270 Vec = pool.AvailableCursors.back();
1271 pool.AvailableCursors.pop_back();
1272 }
1273 else {
1274 Vec = new OverridenCursorsPool::CursorVec();
1275 pool.AllCursors.push_back(Vec);
1276 }
1277
1278 // Clear out the vector, but don't free the memory contents. This
1279 // reduces malloc() traffic.
1280 Vec->clear();
1281
1282 // Use the first entry to contain a back reference to the vector.
1283 // This is a complete hack.
1284 CXCursor backRefCursor = MakeCXCursorInvalid(CXCursor_InvalidFile, TU);
1285 backRefCursor.data[0] = Vec;
1286 assert(cxcursor::getCursorTU(backRefCursor) == TU);
1287 Vec->push_back(backRefCursor);
1288
1289 // Get the overriden cursors.
1290 cxcursor::getOverriddenCursors(cursor, *Vec);
1291
1292 // Did we get any overriden cursors? If not, return Vec to the pool
1293 // of available cursor vectors.
1294 if (Vec->size() == 1) {
1295 pool.AvailableCursors.push_back(Vec);
1296 return;
1297 }
1298
1299 // Now tell the caller about the overriden cursors.
1300 assert(Vec->size() > 1);
1301 *overridden = &((*Vec)[1]);
1302 *num_overridden = Vec->size() - 1;
1303}
1304
1305void clang_disposeOverriddenCursors(CXCursor *overridden) {
1306 if (!overridden)
1307 return;
1308
1309 // Use pointer arithmetic to get back the first faux entry
1310 // which has a back-reference to the TU and the vector.
1311 --overridden;
1312 OverridenCursorsPool::CursorVec *Vec =
1313 static_cast<OverridenCursorsPool::CursorVec*>(overridden->data[0]);
1314 CXTranslationUnit TU = getCursorTU(*overridden);
1315
1316 assert(Vec && TU);
1317
1318 OverridenCursorsPool &pool =
1319 *static_cast<OverridenCursorsPool*>(TU->OverridenCursorsPool);
1320
1321 pool.AvailableCursors.push_back(Vec);
1322}
Argyrios Kyrtzidisf39a7ae2012-07-02 23:54:36 +00001323
1324int clang_Cursor_isDynamicCall(CXCursor C) {
1325 const Expr *E = 0;
1326 if (clang_isExpression(C.kind))
1327 E = getCursorExpr(C);
1328 if (!E)
1329 return 0;
1330
1331 if (const ObjCMessageExpr *MsgE = dyn_cast<ObjCMessageExpr>(E))
1332 return MsgE->getReceiverKind() == ObjCMessageExpr::Instance;
1333
1334 const MemberExpr *ME = 0;
1335 if (isa<MemberExpr>(E))
1336 ME = cast<MemberExpr>(E);
1337 else if (const CallExpr *CE = dyn_cast<CallExpr>(E))
1338 ME = dyn_cast_or_null<MemberExpr>(CE->getCallee());
1339
1340 if (ME) {
1341 if (const CXXMethodDecl *
1342 MD = dyn_cast_or_null<CXXMethodDecl>(ME->getMemberDecl()))
1343 return MD->isVirtual() && !ME->hasQualifier();
1344 }
1345
1346 return 0;
1347}
1348
Ted Kremenekeca099b2010-12-08 23:43:14 +00001349} // end: extern "C"