1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | #include "CXTranslationUnit.h" |
16 | #include "CXCursor.h" |
17 | #include "CXString.h" |
18 | #include "CXType.h" |
19 | #include "clang-c/Index.h" |
20 | #include "clang/AST/Attr.h" |
21 | #include "clang/AST/Decl.h" |
22 | #include "clang/AST/DeclCXX.h" |
23 | #include "clang/AST/DeclObjC.h" |
24 | #include "clang/AST/DeclTemplate.h" |
25 | #include "clang/AST/Expr.h" |
26 | #include "clang/AST/ExprCXX.h" |
27 | #include "clang/AST/ExprObjC.h" |
28 | #include "clang/Frontend/ASTUnit.h" |
29 | #include "llvm/Support/ErrorHandling.h" |
30 | |
31 | using namespace clang; |
32 | using namespace cxcursor; |
33 | |
34 | CXCursor cxcursor::MakeCXCursorInvalid(CXCursorKind K, CXTranslationUnit TU) { |
35 | = CXCursor_FirstInvalid && K <= CXCursor_LastInvalid", "/home/seafit/code_projects/clang_source/clang/tools/libclang/CXCursor.cpp", 35, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(K >= CXCursor_FirstInvalid && K <= CXCursor_LastInvalid); |
36 | CXCursor C = { K, 0, { nullptr, nullptr, TU } }; |
37 | return C; |
38 | } |
39 | |
40 | static CXCursorKind GetCursorKind(const Attr *A) { |
41 | (0) . __assert_fail ("A && \"Invalid arguments!\"", "/home/seafit/code_projects/clang_source/clang/tools/libclang/CXCursor.cpp", 41, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(A && "Invalid arguments!"); |
42 | switch (A->getKind()) { |
43 | default: break; |
44 | case attr::IBAction: return CXCursor_IBActionAttr; |
45 | case attr::IBOutlet: return CXCursor_IBOutletAttr; |
46 | case attr::IBOutletCollection: return CXCursor_IBOutletCollectionAttr; |
47 | case attr::Final: return CXCursor_CXXFinalAttr; |
48 | case attr::Override: return CXCursor_CXXOverrideAttr; |
49 | case attr::Annotate: return CXCursor_AnnotateAttr; |
50 | case attr::AsmLabel: return CXCursor_AsmLabelAttr; |
51 | case attr::Packed: return CXCursor_PackedAttr; |
52 | case attr::Pure: return CXCursor_PureAttr; |
53 | case attr::Const: return CXCursor_ConstAttr; |
54 | case attr::NoDuplicate: return CXCursor_NoDuplicateAttr; |
55 | case attr::CUDAConstant: return CXCursor_CUDAConstantAttr; |
56 | case attr::CUDADevice: return CXCursor_CUDADeviceAttr; |
57 | case attr::CUDAGlobal: return CXCursor_CUDAGlobalAttr; |
58 | case attr::CUDAHost: return CXCursor_CUDAHostAttr; |
59 | case attr::CUDAShared: return CXCursor_CUDASharedAttr; |
60 | case attr::Visibility: return CXCursor_VisibilityAttr; |
61 | case attr::DLLExport: return CXCursor_DLLExport; |
62 | case attr::DLLImport: return CXCursor_DLLImport; |
63 | case attr::NSReturnsRetained: return CXCursor_NSReturnsRetained; |
64 | case attr::NSReturnsNotRetained: return CXCursor_NSReturnsNotRetained; |
65 | case attr::NSReturnsAutoreleased: return CXCursor_NSReturnsAutoreleased; |
66 | case attr::NSConsumesSelf: return CXCursor_NSConsumesSelf; |
67 | case attr::NSConsumed: return CXCursor_NSConsumed; |
68 | case attr::ObjCException: return CXCursor_ObjCException; |
69 | case attr::ObjCNSObject: return CXCursor_ObjCNSObject; |
70 | case attr::ObjCIndependentClass: return CXCursor_ObjCIndependentClass; |
71 | case attr::ObjCPreciseLifetime: return CXCursor_ObjCPreciseLifetime; |
72 | case attr::ObjCReturnsInnerPointer: return CXCursor_ObjCReturnsInnerPointer; |
73 | case attr::ObjCRequiresSuper: return CXCursor_ObjCRequiresSuper; |
74 | case attr::ObjCRootClass: return CXCursor_ObjCRootClass; |
75 | case attr::ObjCSubclassingRestricted: return CXCursor_ObjCSubclassingRestricted; |
76 | case attr::ObjCExplicitProtocolImpl: return CXCursor_ObjCExplicitProtocolImpl; |
77 | case attr::ObjCDesignatedInitializer: return CXCursor_ObjCDesignatedInitializer; |
78 | case attr::ObjCRuntimeVisible: return CXCursor_ObjCRuntimeVisible; |
79 | case attr::ObjCBoxable: return CXCursor_ObjCBoxable; |
80 | case attr::FlagEnum: return CXCursor_FlagEnum; |
81 | case attr::Convergent: return CXCursor_ConvergentAttr; |
82 | case attr::WarnUnused: return CXCursor_WarnUnusedAttr; |
83 | case attr::WarnUnusedResult: return CXCursor_WarnUnusedResultAttr; |
84 | case attr::Aligned: return CXCursor_AlignedAttr; |
85 | } |
86 | |
87 | return CXCursor_UnexposedAttr; |
88 | } |
89 | |
90 | CXCursor cxcursor::MakeCXCursor(const Attr *A, const Decl *Parent, |
91 | CXTranslationUnit TU) { |
92 | (0) . __assert_fail ("A && Parent && TU && \"Invalid arguments!\"", "/home/seafit/code_projects/clang_source/clang/tools/libclang/CXCursor.cpp", 92, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(A && Parent && TU && "Invalid arguments!"); |
93 | CXCursor C = { GetCursorKind(A), 0, { Parent, A, TU } }; |
94 | return C; |
95 | } |
96 | |
97 | CXCursor cxcursor::MakeCXCursor(const Decl *D, CXTranslationUnit TU, |
98 | SourceRange RegionOfInterest, |
99 | bool FirstInDeclGroup) { |
100 | (0) . __assert_fail ("D && TU && \"Invalid arguments!\"", "/home/seafit/code_projects/clang_source/clang/tools/libclang/CXCursor.cpp", 100, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(D && TU && "Invalid arguments!"); |
101 | |
102 | CXCursorKind K = getCursorKindForDecl(D); |
103 | |
104 | if (K == CXCursor_ObjCClassMethodDecl || |
105 | K == CXCursor_ObjCInstanceMethodDecl) { |
106 | int SelectorIdIndex = -1; |
107 | |
108 | if (RegionOfInterest.isValid() && |
109 | RegionOfInterest.getBegin() == RegionOfInterest.getEnd()) { |
110 | SmallVector<SourceLocation, 16> SelLocs; |
111 | cast<ObjCMethodDecl>(D)->getSelectorLocs(SelLocs); |
112 | SmallVectorImpl<SourceLocation>::iterator |
113 | I=std::find(SelLocs.begin(), SelLocs.end(),RegionOfInterest.getBegin()); |
114 | if (I != SelLocs.end()) |
115 | SelectorIdIndex = I - SelLocs.begin(); |
116 | } |
117 | CXCursor C = { K, SelectorIdIndex, |
118 | { D, (void*)(intptr_t) (FirstInDeclGroup ? 1 : 0), TU }}; |
119 | return C; |
120 | } |
121 | |
122 | CXCursor C = { K, 0, { D, (void*)(intptr_t) (FirstInDeclGroup ? 1 : 0), TU }}; |
123 | return C; |
124 | } |
125 | |
126 | CXCursor cxcursor::MakeCXCursor(const Stmt *S, const Decl *Parent, |
127 | CXTranslationUnit TU, |
128 | SourceRange RegionOfInterest) { |
129 | (0) . __assert_fail ("S && TU && \"Invalid arguments!\"", "/home/seafit/code_projects/clang_source/clang/tools/libclang/CXCursor.cpp", 129, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(S && TU && "Invalid arguments!"); |
130 | CXCursorKind K = CXCursor_NotImplemented; |
131 | |
132 | switch (S->getStmtClass()) { |
133 | case Stmt::NoStmtClass: |
134 | break; |
135 | |
136 | case Stmt::CaseStmtClass: |
137 | K = CXCursor_CaseStmt; |
138 | break; |
139 | |
140 | case Stmt::DefaultStmtClass: |
141 | K = CXCursor_DefaultStmt; |
142 | break; |
143 | |
144 | case Stmt::IfStmtClass: |
145 | K = CXCursor_IfStmt; |
146 | break; |
147 | |
148 | case Stmt::SwitchStmtClass: |
149 | K = CXCursor_SwitchStmt; |
150 | break; |
151 | |
152 | case Stmt::WhileStmtClass: |
153 | K = CXCursor_WhileStmt; |
154 | break; |
155 | |
156 | case Stmt::DoStmtClass: |
157 | K = CXCursor_DoStmt; |
158 | break; |
159 | |
160 | case Stmt::ForStmtClass: |
161 | K = CXCursor_ForStmt; |
162 | break; |
163 | |
164 | case Stmt::GotoStmtClass: |
165 | K = CXCursor_GotoStmt; |
166 | break; |
167 | |
168 | case Stmt::IndirectGotoStmtClass: |
169 | K = CXCursor_IndirectGotoStmt; |
170 | break; |
171 | |
172 | case Stmt::ContinueStmtClass: |
173 | K = CXCursor_ContinueStmt; |
174 | break; |
175 | |
176 | case Stmt::BreakStmtClass: |
177 | K = CXCursor_BreakStmt; |
178 | break; |
179 | |
180 | case Stmt::ReturnStmtClass: |
181 | K = CXCursor_ReturnStmt; |
182 | break; |
183 | |
184 | case Stmt::GCCAsmStmtClass: |
185 | K = CXCursor_GCCAsmStmt; |
186 | break; |
187 | |
188 | case Stmt::MSAsmStmtClass: |
189 | K = CXCursor_MSAsmStmt; |
190 | break; |
191 | |
192 | case Stmt::ObjCAtTryStmtClass: |
193 | K = CXCursor_ObjCAtTryStmt; |
194 | break; |
195 | |
196 | case Stmt::ObjCAtCatchStmtClass: |
197 | K = CXCursor_ObjCAtCatchStmt; |
198 | break; |
199 | |
200 | case Stmt::ObjCAtFinallyStmtClass: |
201 | K = CXCursor_ObjCAtFinallyStmt; |
202 | break; |
203 | |
204 | case Stmt::ObjCAtThrowStmtClass: |
205 | K = CXCursor_ObjCAtThrowStmt; |
206 | break; |
207 | |
208 | case Stmt::ObjCAtSynchronizedStmtClass: |
209 | K = CXCursor_ObjCAtSynchronizedStmt; |
210 | break; |
211 | |
212 | case Stmt::ObjCAutoreleasePoolStmtClass: |
213 | K = CXCursor_ObjCAutoreleasePoolStmt; |
214 | break; |
215 | |
216 | case Stmt::ObjCForCollectionStmtClass: |
217 | K = CXCursor_ObjCForCollectionStmt; |
218 | break; |
219 | |
220 | case Stmt::CXXCatchStmtClass: |
221 | K = CXCursor_CXXCatchStmt; |
222 | break; |
223 | |
224 | case Stmt::CXXTryStmtClass: |
225 | K = CXCursor_CXXTryStmt; |
226 | break; |
227 | |
228 | case Stmt::CXXForRangeStmtClass: |
229 | K = CXCursor_CXXForRangeStmt; |
230 | break; |
231 | |
232 | case Stmt::SEHTryStmtClass: |
233 | K = CXCursor_SEHTryStmt; |
234 | break; |
235 | |
236 | case Stmt::SEHExceptStmtClass: |
237 | K = CXCursor_SEHExceptStmt; |
238 | break; |
239 | |
240 | case Stmt::SEHFinallyStmtClass: |
241 | K = CXCursor_SEHFinallyStmt; |
242 | break; |
243 | |
244 | case Stmt::SEHLeaveStmtClass: |
245 | K = CXCursor_SEHLeaveStmt; |
246 | break; |
247 | |
248 | case Stmt::CoroutineBodyStmtClass: |
249 | case Stmt::CoreturnStmtClass: |
250 | K = CXCursor_UnexposedStmt; |
251 | break; |
252 | |
253 | case Stmt::ArrayTypeTraitExprClass: |
254 | case Stmt::AsTypeExprClass: |
255 | case Stmt::AtomicExprClass: |
256 | case Stmt::BinaryConditionalOperatorClass: |
257 | case Stmt::TypeTraitExprClass: |
258 | case Stmt::CoawaitExprClass: |
259 | case Stmt::DependentCoawaitExprClass: |
260 | case Stmt::CoyieldExprClass: |
261 | case Stmt::CXXBindTemporaryExprClass: |
262 | case Stmt::CXXDefaultArgExprClass: |
263 | case Stmt::CXXDefaultInitExprClass: |
264 | case Stmt::CXXFoldExprClass: |
265 | case Stmt::CXXStdInitializerListExprClass: |
266 | case Stmt::CXXScalarValueInitExprClass: |
267 | case Stmt::CXXUuidofExprClass: |
268 | case Stmt::ChooseExprClass: |
269 | case Stmt::DesignatedInitExprClass: |
270 | case Stmt::DesignatedInitUpdateExprClass: |
271 | case Stmt::ArrayInitLoopExprClass: |
272 | case Stmt::ArrayInitIndexExprClass: |
273 | case Stmt::ExprWithCleanupsClass: |
274 | case Stmt::ExpressionTraitExprClass: |
275 | case Stmt::ExtVectorElementExprClass: |
276 | case Stmt::ImplicitCastExprClass: |
277 | case Stmt::ImplicitValueInitExprClass: |
278 | case Stmt::NoInitExprClass: |
279 | case Stmt::MaterializeTemporaryExprClass: |
280 | case Stmt::ObjCIndirectCopyRestoreExprClass: |
281 | case Stmt::OffsetOfExprClass: |
282 | case Stmt::ParenListExprClass: |
283 | case Stmt::PredefinedExprClass: |
284 | case Stmt::ShuffleVectorExprClass: |
285 | case Stmt::ConvertVectorExprClass: |
286 | case Stmt::VAArgExprClass: |
287 | case Stmt::ObjCArrayLiteralClass: |
288 | case Stmt::ObjCDictionaryLiteralClass: |
289 | case Stmt::ObjCBoxedExprClass: |
290 | case Stmt::ObjCSubscriptRefExprClass: |
291 | K = CXCursor_UnexposedExpr; |
292 | break; |
293 | |
294 | case Stmt::OpaqueValueExprClass: |
295 | if (Expr *Src = cast<OpaqueValueExpr>(S)->getSourceExpr()) |
296 | return MakeCXCursor(Src, Parent, TU, RegionOfInterest); |
297 | K = CXCursor_UnexposedExpr; |
298 | break; |
299 | |
300 | case Stmt::PseudoObjectExprClass: |
301 | return MakeCXCursor(cast<PseudoObjectExpr>(S)->getSyntacticForm(), |
302 | Parent, TU, RegionOfInterest); |
303 | |
304 | case Stmt::CompoundStmtClass: |
305 | K = CXCursor_CompoundStmt; |
306 | break; |
307 | |
308 | case Stmt::NullStmtClass: |
309 | K = CXCursor_NullStmt; |
310 | break; |
311 | |
312 | case Stmt::LabelStmtClass: |
313 | K = CXCursor_LabelStmt; |
314 | break; |
315 | |
316 | case Stmt::AttributedStmtClass: |
317 | K = CXCursor_UnexposedStmt; |
318 | break; |
319 | |
320 | case Stmt::DeclStmtClass: |
321 | K = CXCursor_DeclStmt; |
322 | break; |
323 | |
324 | case Stmt::CapturedStmtClass: |
325 | K = CXCursor_UnexposedStmt; |
326 | break; |
327 | |
328 | case Stmt::IntegerLiteralClass: |
329 | K = CXCursor_IntegerLiteral; |
330 | break; |
331 | |
332 | case Stmt::FixedPointLiteralClass: |
333 | K = CXCursor_FixedPointLiteral; |
334 | break; |
335 | |
336 | case Stmt::FloatingLiteralClass: |
337 | K = CXCursor_FloatingLiteral; |
338 | break; |
339 | |
340 | case Stmt::ImaginaryLiteralClass: |
341 | K = CXCursor_ImaginaryLiteral; |
342 | break; |
343 | |
344 | case Stmt::StringLiteralClass: |
345 | K = CXCursor_StringLiteral; |
346 | break; |
347 | |
348 | case Stmt::CharacterLiteralClass: |
349 | K = CXCursor_CharacterLiteral; |
350 | break; |
351 | |
352 | case Stmt::ConstantExprClass: |
353 | return MakeCXCursor(cast<ConstantExpr>(S)->getSubExpr(), |
354 | Parent, TU, RegionOfInterest); |
355 | |
356 | case Stmt::ParenExprClass: |
357 | K = CXCursor_ParenExpr; |
358 | break; |
359 | |
360 | case Stmt::UnaryOperatorClass: |
361 | K = CXCursor_UnaryOperator; |
362 | break; |
363 | |
364 | case Stmt::UnaryExprOrTypeTraitExprClass: |
365 | case Stmt::CXXNoexceptExprClass: |
366 | K = CXCursor_UnaryExpr; |
367 | break; |
368 | |
369 | case Stmt::MSPropertySubscriptExprClass: |
370 | case Stmt::ArraySubscriptExprClass: |
371 | K = CXCursor_ArraySubscriptExpr; |
372 | break; |
373 | |
374 | case Stmt::OMPArraySectionExprClass: |
375 | K = CXCursor_OMPArraySectionExpr; |
376 | break; |
377 | |
378 | case Stmt::BinaryOperatorClass: |
379 | K = CXCursor_BinaryOperator; |
380 | break; |
381 | |
382 | case Stmt::CompoundAssignOperatorClass: |
383 | K = CXCursor_CompoundAssignOperator; |
384 | break; |
385 | |
386 | case Stmt::ConditionalOperatorClass: |
387 | K = CXCursor_ConditionalOperator; |
388 | break; |
389 | |
390 | case Stmt::CStyleCastExprClass: |
391 | K = CXCursor_CStyleCastExpr; |
392 | break; |
393 | |
394 | case Stmt::CompoundLiteralExprClass: |
395 | K = CXCursor_CompoundLiteralExpr; |
396 | break; |
397 | |
398 | case Stmt::InitListExprClass: |
399 | K = CXCursor_InitListExpr; |
400 | break; |
401 | |
402 | case Stmt::AddrLabelExprClass: |
403 | K = CXCursor_AddrLabelExpr; |
404 | break; |
405 | |
406 | case Stmt::StmtExprClass: |
407 | K = CXCursor_StmtExpr; |
408 | break; |
409 | |
410 | case Stmt::GenericSelectionExprClass: |
411 | K = CXCursor_GenericSelectionExpr; |
412 | break; |
413 | |
414 | case Stmt::GNUNullExprClass: |
415 | K = CXCursor_GNUNullExpr; |
416 | break; |
417 | |
418 | case Stmt::CXXStaticCastExprClass: |
419 | K = CXCursor_CXXStaticCastExpr; |
420 | break; |
421 | |
422 | case Stmt::CXXDynamicCastExprClass: |
423 | K = CXCursor_CXXDynamicCastExpr; |
424 | break; |
425 | |
426 | case Stmt::CXXReinterpretCastExprClass: |
427 | K = CXCursor_CXXReinterpretCastExpr; |
428 | break; |
429 | |
430 | case Stmt::CXXConstCastExprClass: |
431 | K = CXCursor_CXXConstCastExpr; |
432 | break; |
433 | |
434 | case Stmt::CXXFunctionalCastExprClass: |
435 | K = CXCursor_CXXFunctionalCastExpr; |
436 | break; |
437 | |
438 | case Stmt::CXXTypeidExprClass: |
439 | K = CXCursor_CXXTypeidExpr; |
440 | break; |
441 | |
442 | case Stmt::CXXBoolLiteralExprClass: |
443 | K = CXCursor_CXXBoolLiteralExpr; |
444 | break; |
445 | |
446 | case Stmt::CXXNullPtrLiteralExprClass: |
447 | K = CXCursor_CXXNullPtrLiteralExpr; |
448 | break; |
449 | |
450 | case Stmt::CXXThisExprClass: |
451 | K = CXCursor_CXXThisExpr; |
452 | break; |
453 | |
454 | case Stmt::CXXThrowExprClass: |
455 | K = CXCursor_CXXThrowExpr; |
456 | break; |
457 | |
458 | case Stmt::CXXNewExprClass: |
459 | K = CXCursor_CXXNewExpr; |
460 | break; |
461 | |
462 | case Stmt::CXXDeleteExprClass: |
463 | K = CXCursor_CXXDeleteExpr; |
464 | break; |
465 | |
466 | case Stmt::ObjCStringLiteralClass: |
467 | K = CXCursor_ObjCStringLiteral; |
468 | break; |
469 | |
470 | case Stmt::ObjCEncodeExprClass: |
471 | K = CXCursor_ObjCEncodeExpr; |
472 | break; |
473 | |
474 | case Stmt::ObjCSelectorExprClass: |
475 | K = CXCursor_ObjCSelectorExpr; |
476 | break; |
477 | |
478 | case Stmt::ObjCProtocolExprClass: |
479 | K = CXCursor_ObjCProtocolExpr; |
480 | break; |
481 | |
482 | case Stmt::ObjCBoolLiteralExprClass: |
483 | K = CXCursor_ObjCBoolLiteralExpr; |
484 | break; |
485 | |
486 | case Stmt::ObjCAvailabilityCheckExprClass: |
487 | K = CXCursor_ObjCAvailabilityCheckExpr; |
488 | break; |
489 | |
490 | case Stmt::ObjCBridgedCastExprClass: |
491 | K = CXCursor_ObjCBridgedCastExpr; |
492 | break; |
493 | |
494 | case Stmt::BlockExprClass: |
495 | K = CXCursor_BlockExpr; |
496 | break; |
497 | |
498 | case Stmt::PackExpansionExprClass: |
499 | K = CXCursor_PackExpansionExpr; |
500 | break; |
501 | |
502 | case Stmt::SizeOfPackExprClass: |
503 | K = CXCursor_SizeOfPackExpr; |
504 | break; |
505 | |
506 | case Stmt::DeclRefExprClass: |
507 | if (const ImplicitParamDecl *IPD = |
508 | dyn_cast_or_null<ImplicitParamDecl>(cast<DeclRefExpr>(S)->getDecl())) { |
509 | if (const ObjCMethodDecl *MD = |
510 | dyn_cast<ObjCMethodDecl>(IPD->getDeclContext())) { |
511 | if (MD->getSelfDecl() == IPD) { |
512 | K = CXCursor_ObjCSelfExpr; |
513 | break; |
514 | } |
515 | } |
516 | } |
517 | |
518 | K = CXCursor_DeclRefExpr; |
519 | break; |
520 | |
521 | case Stmt::DependentScopeDeclRefExprClass: |
522 | case Stmt::SubstNonTypeTemplateParmExprClass: |
523 | case Stmt::SubstNonTypeTemplateParmPackExprClass: |
524 | case Stmt::FunctionParmPackExprClass: |
525 | case Stmt::UnresolvedLookupExprClass: |
526 | case Stmt::TypoExprClass: |
527 | K = CXCursor_DeclRefExpr; |
528 | break; |
529 | |
530 | case Stmt::CXXDependentScopeMemberExprClass: |
531 | case Stmt::CXXPseudoDestructorExprClass: |
532 | case Stmt::MemberExprClass: |
533 | case Stmt::MSPropertyRefExprClass: |
534 | case Stmt::ObjCIsaExprClass: |
535 | case Stmt::ObjCIvarRefExprClass: |
536 | case Stmt::ObjCPropertyRefExprClass: |
537 | case Stmt::UnresolvedMemberExprClass: |
538 | K = CXCursor_MemberRefExpr; |
539 | break; |
540 | |
541 | case Stmt::CallExprClass: |
542 | case Stmt::CXXOperatorCallExprClass: |
543 | case Stmt::CXXMemberCallExprClass: |
544 | case Stmt::CUDAKernelCallExprClass: |
545 | case Stmt::CXXConstructExprClass: |
546 | case Stmt::CXXInheritedCtorInitExprClass: |
547 | case Stmt::CXXTemporaryObjectExprClass: |
548 | case Stmt::CXXUnresolvedConstructExprClass: |
549 | case Stmt::UserDefinedLiteralClass: |
550 | K = CXCursor_CallExpr; |
551 | break; |
552 | |
553 | case Stmt::LambdaExprClass: |
554 | K = CXCursor_LambdaExpr; |
555 | break; |
556 | |
557 | case Stmt::ObjCMessageExprClass: { |
558 | K = CXCursor_ObjCMessageExpr; |
559 | int SelectorIdIndex = -1; |
560 | |
561 | if (RegionOfInterest.isValid() && |
562 | RegionOfInterest.getBegin() == RegionOfInterest.getEnd()) { |
563 | SmallVector<SourceLocation, 16> SelLocs; |
564 | cast<ObjCMessageExpr>(S)->getSelectorLocs(SelLocs); |
565 | SmallVectorImpl<SourceLocation>::iterator |
566 | I=std::find(SelLocs.begin(), SelLocs.end(),RegionOfInterest.getBegin()); |
567 | if (I != SelLocs.end()) |
568 | SelectorIdIndex = I - SelLocs.begin(); |
569 | } |
570 | CXCursor C = { K, 0, { Parent, S, TU } }; |
571 | return getSelectorIdentifierCursor(SelectorIdIndex, C); |
572 | } |
573 | |
574 | case Stmt::MSDependentExistsStmtClass: |
575 | K = CXCursor_UnexposedStmt; |
576 | break; |
577 | case Stmt::OMPParallelDirectiveClass: |
578 | K = CXCursor_OMPParallelDirective; |
579 | break; |
580 | case Stmt::OMPSimdDirectiveClass: |
581 | K = CXCursor_OMPSimdDirective; |
582 | break; |
583 | case Stmt::OMPForDirectiveClass: |
584 | K = CXCursor_OMPForDirective; |
585 | break; |
586 | case Stmt::OMPForSimdDirectiveClass: |
587 | K = CXCursor_OMPForSimdDirective; |
588 | break; |
589 | case Stmt::OMPSectionsDirectiveClass: |
590 | K = CXCursor_OMPSectionsDirective; |
591 | break; |
592 | case Stmt::OMPSectionDirectiveClass: |
593 | K = CXCursor_OMPSectionDirective; |
594 | break; |
595 | case Stmt::OMPSingleDirectiveClass: |
596 | K = CXCursor_OMPSingleDirective; |
597 | break; |
598 | case Stmt::OMPMasterDirectiveClass: |
599 | K = CXCursor_OMPMasterDirective; |
600 | break; |
601 | case Stmt::OMPCriticalDirectiveClass: |
602 | K = CXCursor_OMPCriticalDirective; |
603 | break; |
604 | case Stmt::OMPParallelForDirectiveClass: |
605 | K = CXCursor_OMPParallelForDirective; |
606 | break; |
607 | case Stmt::OMPParallelForSimdDirectiveClass: |
608 | K = CXCursor_OMPParallelForSimdDirective; |
609 | break; |
610 | case Stmt::OMPParallelSectionsDirectiveClass: |
611 | K = CXCursor_OMPParallelSectionsDirective; |
612 | break; |
613 | case Stmt::OMPTaskDirectiveClass: |
614 | K = CXCursor_OMPTaskDirective; |
615 | break; |
616 | case Stmt::OMPTaskyieldDirectiveClass: |
617 | K = CXCursor_OMPTaskyieldDirective; |
618 | break; |
619 | case Stmt::OMPBarrierDirectiveClass: |
620 | K = CXCursor_OMPBarrierDirective; |
621 | break; |
622 | case Stmt::OMPTaskwaitDirectiveClass: |
623 | K = CXCursor_OMPTaskwaitDirective; |
624 | break; |
625 | case Stmt::OMPTaskgroupDirectiveClass: |
626 | K = CXCursor_OMPTaskgroupDirective; |
627 | break; |
628 | case Stmt::OMPFlushDirectiveClass: |
629 | K = CXCursor_OMPFlushDirective; |
630 | break; |
631 | case Stmt::OMPOrderedDirectiveClass: |
632 | K = CXCursor_OMPOrderedDirective; |
633 | break; |
634 | case Stmt::OMPAtomicDirectiveClass: |
635 | K = CXCursor_OMPAtomicDirective; |
636 | break; |
637 | case Stmt::OMPTargetDirectiveClass: |
638 | K = CXCursor_OMPTargetDirective; |
639 | break; |
640 | case Stmt::OMPTargetDataDirectiveClass: |
641 | K = CXCursor_OMPTargetDataDirective; |
642 | break; |
643 | case Stmt::OMPTargetEnterDataDirectiveClass: |
644 | K = CXCursor_OMPTargetEnterDataDirective; |
645 | break; |
646 | case Stmt::OMPTargetExitDataDirectiveClass: |
647 | K = CXCursor_OMPTargetExitDataDirective; |
648 | break; |
649 | case Stmt::OMPTargetParallelDirectiveClass: |
650 | K = CXCursor_OMPTargetParallelDirective; |
651 | break; |
652 | case Stmt::OMPTargetParallelForDirectiveClass: |
653 | K = CXCursor_OMPTargetParallelForDirective; |
654 | break; |
655 | case Stmt::OMPTargetUpdateDirectiveClass: |
656 | K = CXCursor_OMPTargetUpdateDirective; |
657 | break; |
658 | case Stmt::OMPTeamsDirectiveClass: |
659 | K = CXCursor_OMPTeamsDirective; |
660 | break; |
661 | case Stmt::OMPCancellationPointDirectiveClass: |
662 | K = CXCursor_OMPCancellationPointDirective; |
663 | break; |
664 | case Stmt::OMPCancelDirectiveClass: |
665 | K = CXCursor_OMPCancelDirective; |
666 | break; |
667 | case Stmt::OMPTaskLoopDirectiveClass: |
668 | K = CXCursor_OMPTaskLoopDirective; |
669 | break; |
670 | case Stmt::OMPTaskLoopSimdDirectiveClass: |
671 | K = CXCursor_OMPTaskLoopSimdDirective; |
672 | break; |
673 | case Stmt::OMPDistributeDirectiveClass: |
674 | K = CXCursor_OMPDistributeDirective; |
675 | break; |
676 | case Stmt::OMPDistributeParallelForDirectiveClass: |
677 | K = CXCursor_OMPDistributeParallelForDirective; |
678 | break; |
679 | case Stmt::OMPDistributeParallelForSimdDirectiveClass: |
680 | K = CXCursor_OMPDistributeParallelForSimdDirective; |
681 | break; |
682 | case Stmt::OMPDistributeSimdDirectiveClass: |
683 | K = CXCursor_OMPDistributeSimdDirective; |
684 | break; |
685 | case Stmt::OMPTargetParallelForSimdDirectiveClass: |
686 | K = CXCursor_OMPTargetParallelForSimdDirective; |
687 | break; |
688 | case Stmt::OMPTargetSimdDirectiveClass: |
689 | K = CXCursor_OMPTargetSimdDirective; |
690 | break; |
691 | case Stmt::OMPTeamsDistributeDirectiveClass: |
692 | K = CXCursor_OMPTeamsDistributeDirective; |
693 | break; |
694 | case Stmt::OMPTeamsDistributeSimdDirectiveClass: |
695 | K = CXCursor_OMPTeamsDistributeSimdDirective; |
696 | break; |
697 | case Stmt::OMPTeamsDistributeParallelForSimdDirectiveClass: |
698 | K = CXCursor_OMPTeamsDistributeParallelForSimdDirective; |
699 | break; |
700 | case Stmt::OMPTeamsDistributeParallelForDirectiveClass: |
701 | K = CXCursor_OMPTeamsDistributeParallelForDirective; |
702 | break; |
703 | case Stmt::OMPTargetTeamsDirectiveClass: |
704 | K = CXCursor_OMPTargetTeamsDirective; |
705 | break; |
706 | case Stmt::OMPTargetTeamsDistributeDirectiveClass: |
707 | K = CXCursor_OMPTargetTeamsDistributeDirective; |
708 | break; |
709 | case Stmt::OMPTargetTeamsDistributeParallelForDirectiveClass: |
710 | K = CXCursor_OMPTargetTeamsDistributeParallelForDirective; |
711 | break; |
712 | case Stmt::OMPTargetTeamsDistributeParallelForSimdDirectiveClass: |
713 | K = CXCursor_OMPTargetTeamsDistributeParallelForSimdDirective; |
714 | break; |
715 | case Stmt::OMPTargetTeamsDistributeSimdDirectiveClass: |
716 | K = CXCursor_OMPTargetTeamsDistributeSimdDirective; |
717 | break; |
718 | } |
719 | |
720 | CXCursor C = { K, 0, { Parent, S, TU } }; |
721 | return C; |
722 | } |
723 | |
724 | CXCursor cxcursor::MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super, |
725 | SourceLocation Loc, |
726 | CXTranslationUnit TU) { |
727 | (0) . __assert_fail ("Super && TU && \"Invalid arguments!\"", "/home/seafit/code_projects/clang_source/clang/tools/libclang/CXCursor.cpp", 727, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Super && TU && "Invalid arguments!"); |
728 | void *RawLoc = Loc.getPtrEncoding(); |
729 | CXCursor C = { CXCursor_ObjCSuperClassRef, 0, { Super, RawLoc, TU } }; |
730 | return C; |
731 | } |
732 | |
733 | std::pair<const ObjCInterfaceDecl *, SourceLocation> |
734 | cxcursor::getCursorObjCSuperClassRef(CXCursor C) { |
735 | assert(C.kind == CXCursor_ObjCSuperClassRef); |
736 | return std::make_pair(static_cast<const ObjCInterfaceDecl *>(C.data[0]), |
737 | SourceLocation::getFromPtrEncoding(C.data[1])); |
738 | } |
739 | |
740 | CXCursor cxcursor::MakeCursorObjCProtocolRef(const ObjCProtocolDecl *Proto, |
741 | SourceLocation Loc, |
742 | CXTranslationUnit TU) { |
743 | (0) . __assert_fail ("Proto && TU && \"Invalid arguments!\"", "/home/seafit/code_projects/clang_source/clang/tools/libclang/CXCursor.cpp", 743, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Proto && TU && "Invalid arguments!"); |
744 | void *RawLoc = Loc.getPtrEncoding(); |
745 | CXCursor C = { CXCursor_ObjCProtocolRef, 0, { Proto, RawLoc, TU } }; |
746 | return C; |
747 | } |
748 | |
749 | std::pair<const ObjCProtocolDecl *, SourceLocation> |
750 | cxcursor::getCursorObjCProtocolRef(CXCursor C) { |
751 | assert(C.kind == CXCursor_ObjCProtocolRef); |
752 | return std::make_pair(static_cast<const ObjCProtocolDecl *>(C.data[0]), |
753 | SourceLocation::getFromPtrEncoding(C.data[1])); |
754 | } |
755 | |
756 | CXCursor cxcursor::MakeCursorObjCClassRef(const ObjCInterfaceDecl *Class, |
757 | SourceLocation Loc, |
758 | CXTranslationUnit TU) { |
759 | |
760 | if (!Class) |
761 | return MakeCXCursorInvalid(CXCursor_InvalidCode); |
762 | (0) . __assert_fail ("TU && \"Invalid arguments!\"", "/home/seafit/code_projects/clang_source/clang/tools/libclang/CXCursor.cpp", 762, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(TU && "Invalid arguments!"); |
763 | void *RawLoc = Loc.getPtrEncoding(); |
764 | CXCursor C = { CXCursor_ObjCClassRef, 0, { Class, RawLoc, TU } }; |
765 | return C; |
766 | } |
767 | |
768 | std::pair<const ObjCInterfaceDecl *, SourceLocation> |
769 | cxcursor::getCursorObjCClassRef(CXCursor C) { |
770 | assert(C.kind == CXCursor_ObjCClassRef); |
771 | return std::make_pair(static_cast<const ObjCInterfaceDecl *>(C.data[0]), |
772 | SourceLocation::getFromPtrEncoding(C.data[1])); |
773 | } |
774 | |
775 | CXCursor cxcursor::MakeCursorTypeRef(const TypeDecl *Type, SourceLocation Loc, |
776 | CXTranslationUnit TU) { |
777 | (0) . __assert_fail ("Type && TU && \"Invalid arguments!\"", "/home/seafit/code_projects/clang_source/clang/tools/libclang/CXCursor.cpp", 777, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Type && TU && "Invalid arguments!"); |
778 | void *RawLoc = Loc.getPtrEncoding(); |
779 | CXCursor C = { CXCursor_TypeRef, 0, { Type, RawLoc, TU } }; |
780 | return C; |
781 | } |
782 | |
783 | std::pair<const TypeDecl *, SourceLocation> |
784 | cxcursor::getCursorTypeRef(CXCursor C) { |
785 | assert(C.kind == CXCursor_TypeRef); |
786 | return std::make_pair(static_cast<const TypeDecl *>(C.data[0]), |
787 | SourceLocation::getFromPtrEncoding(C.data[1])); |
788 | } |
789 | |
790 | CXCursor cxcursor::MakeCursorTemplateRef(const TemplateDecl *Template, |
791 | SourceLocation Loc, |
792 | CXTranslationUnit TU) { |
793 | (0) . __assert_fail ("Template && TU && \"Invalid arguments!\"", "/home/seafit/code_projects/clang_source/clang/tools/libclang/CXCursor.cpp", 793, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Template && TU && "Invalid arguments!"); |
794 | void *RawLoc = Loc.getPtrEncoding(); |
795 | CXCursor C = { CXCursor_TemplateRef, 0, { Template, RawLoc, TU } }; |
796 | return C; |
797 | } |
798 | |
799 | std::pair<const TemplateDecl *, SourceLocation> |
800 | cxcursor::getCursorTemplateRef(CXCursor C) { |
801 | assert(C.kind == CXCursor_TemplateRef); |
802 | return std::make_pair(static_cast<const TemplateDecl *>(C.data[0]), |
803 | SourceLocation::getFromPtrEncoding(C.data[1])); |
804 | } |
805 | |
806 | CXCursor cxcursor::MakeCursorNamespaceRef(const NamedDecl *NS, |
807 | SourceLocation Loc, |
808 | CXTranslationUnit TU) { |
809 | |
810 | (0) . __assert_fail ("NS && (isa(NS) || isa(NS)) && TU && \"Invalid arguments!\"", "/home/seafit/code_projects/clang_source/clang/tools/libclang/CXCursor.cpp", 811, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(NS && (isa<NamespaceDecl>(NS) || isa<NamespaceAliasDecl>(NS)) && TU && |
811 | (0) . __assert_fail ("NS && (isa(NS) || isa(NS)) && TU && \"Invalid arguments!\"", "/home/seafit/code_projects/clang_source/clang/tools/libclang/CXCursor.cpp", 811, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Invalid arguments!"); |
812 | void *RawLoc = Loc.getPtrEncoding(); |
813 | CXCursor C = { CXCursor_NamespaceRef, 0, { NS, RawLoc, TU } }; |
814 | return C; |
815 | } |
816 | |
817 | std::pair<const NamedDecl *, SourceLocation> |
818 | cxcursor::getCursorNamespaceRef(CXCursor C) { |
819 | assert(C.kind == CXCursor_NamespaceRef); |
820 | return std::make_pair(static_cast<const NamedDecl *>(C.data[0]), |
821 | SourceLocation::getFromPtrEncoding(C.data[1])); |
822 | } |
823 | |
824 | CXCursor cxcursor::MakeCursorVariableRef(const VarDecl *Var, SourceLocation Loc, |
825 | CXTranslationUnit TU) { |
826 | |
827 | (0) . __assert_fail ("Var && TU && \"Invalid arguments!\"", "/home/seafit/code_projects/clang_source/clang/tools/libclang/CXCursor.cpp", 827, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Var && TU && "Invalid arguments!"); |
828 | void *RawLoc = Loc.getPtrEncoding(); |
829 | CXCursor C = { CXCursor_VariableRef, 0, { Var, RawLoc, TU } }; |
830 | return C; |
831 | } |
832 | |
833 | std::pair<const VarDecl *, SourceLocation> |
834 | cxcursor::getCursorVariableRef(CXCursor C) { |
835 | assert(C.kind == CXCursor_VariableRef); |
836 | return std::make_pair(static_cast<const VarDecl *>(C.data[0]), |
837 | SourceLocation::getFromPtrEncoding(C.data[1])); |
838 | } |
839 | |
840 | CXCursor cxcursor::MakeCursorMemberRef(const FieldDecl *Field, SourceLocation Loc, |
841 | CXTranslationUnit TU) { |
842 | |
843 | (0) . __assert_fail ("Field && TU && \"Invalid arguments!\"", "/home/seafit/code_projects/clang_source/clang/tools/libclang/CXCursor.cpp", 843, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Field && TU && "Invalid arguments!"); |
844 | void *RawLoc = Loc.getPtrEncoding(); |
845 | CXCursor C = { CXCursor_MemberRef, 0, { Field, RawLoc, TU } }; |
846 | return C; |
847 | } |
848 | |
849 | std::pair<const FieldDecl *, SourceLocation> |
850 | cxcursor::getCursorMemberRef(CXCursor C) { |
851 | assert(C.kind == CXCursor_MemberRef); |
852 | return std::make_pair(static_cast<const FieldDecl *>(C.data[0]), |
853 | SourceLocation::getFromPtrEncoding(C.data[1])); |
854 | } |
855 | |
856 | CXCursor cxcursor::MakeCursorCXXBaseSpecifier(const CXXBaseSpecifier *B, |
857 | CXTranslationUnit TU){ |
858 | CXCursor C = { CXCursor_CXXBaseSpecifier, 0, { B, nullptr, TU } }; |
859 | return C; |
860 | } |
861 | |
862 | const CXXBaseSpecifier *cxcursor::getCursorCXXBaseSpecifier(CXCursor C) { |
863 | assert(C.kind == CXCursor_CXXBaseSpecifier); |
864 | return static_cast<const CXXBaseSpecifier*>(C.data[0]); |
865 | } |
866 | |
867 | CXCursor cxcursor::MakePreprocessingDirectiveCursor(SourceRange Range, |
868 | CXTranslationUnit TU) { |
869 | CXCursor C = { CXCursor_PreprocessingDirective, 0, |
870 | { Range.getBegin().getPtrEncoding(), |
871 | Range.getEnd().getPtrEncoding(), |
872 | TU } |
873 | }; |
874 | return C; |
875 | } |
876 | |
877 | SourceRange cxcursor::getCursorPreprocessingDirective(CXCursor C) { |
878 | assert(C.kind == CXCursor_PreprocessingDirective); |
879 | SourceRange Range(SourceLocation::getFromPtrEncoding(C.data[0]), |
880 | SourceLocation::getFromPtrEncoding(C.data[1])); |
881 | ASTUnit *TU = getCursorASTUnit(C); |
882 | return TU->mapRangeFromPreamble(Range); |
883 | } |
884 | |
885 | CXCursor cxcursor::MakeMacroDefinitionCursor(const MacroDefinitionRecord *MI, |
886 | CXTranslationUnit TU) { |
887 | CXCursor C = {CXCursor_MacroDefinition, 0, {MI, nullptr, TU}}; |
888 | return C; |
889 | } |
890 | |
891 | const MacroDefinitionRecord *cxcursor::getCursorMacroDefinition(CXCursor C) { |
892 | assert(C.kind == CXCursor_MacroDefinition); |
893 | return static_cast<const MacroDefinitionRecord *>(C.data[0]); |
894 | } |
895 | |
896 | CXCursor cxcursor::MakeMacroExpansionCursor(MacroExpansion *MI, |
897 | CXTranslationUnit TU) { |
898 | CXCursor C = { CXCursor_MacroExpansion, 0, { MI, nullptr, TU } }; |
899 | return C; |
900 | } |
901 | |
902 | CXCursor cxcursor::MakeMacroExpansionCursor(MacroDefinitionRecord *MI, |
903 | SourceLocation Loc, |
904 | CXTranslationUnit TU) { |
905 | assert(Loc.isValid()); |
906 | CXCursor C = {CXCursor_MacroExpansion, 0, {MI, Loc.getPtrEncoding(), TU}}; |
907 | return C; |
908 | } |
909 | |
910 | const IdentifierInfo *cxcursor::MacroExpansionCursor::getName() const { |
911 | if (isPseudo()) |
912 | return getAsMacroDefinition()->getName(); |
913 | return getAsMacroExpansion()->getName(); |
914 | } |
915 | const MacroDefinitionRecord * |
916 | cxcursor::MacroExpansionCursor::getDefinition() const { |
917 | if (isPseudo()) |
918 | return getAsMacroDefinition(); |
919 | return getAsMacroExpansion()->getDefinition(); |
920 | } |
921 | SourceRange cxcursor::MacroExpansionCursor::getSourceRange() const { |
922 | if (isPseudo()) |
923 | return getPseudoLoc(); |
924 | return getAsMacroExpansion()->getSourceRange(); |
925 | } |
926 | |
927 | CXCursor cxcursor::MakeInclusionDirectiveCursor(InclusionDirective *ID, |
928 | CXTranslationUnit TU) { |
929 | CXCursor C = { CXCursor_InclusionDirective, 0, { ID, nullptr, TU } }; |
930 | return C; |
931 | } |
932 | |
933 | const InclusionDirective *cxcursor::getCursorInclusionDirective(CXCursor C) { |
934 | assert(C.kind == CXCursor_InclusionDirective); |
935 | return static_cast<const InclusionDirective *>(C.data[0]); |
936 | } |
937 | |
938 | CXCursor cxcursor::MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc, |
939 | CXTranslationUnit TU) { |
940 | |
941 | (0) . __assert_fail ("Label && TU && \"Invalid arguments!\"", "/home/seafit/code_projects/clang_source/clang/tools/libclang/CXCursor.cpp", 941, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Label && TU && "Invalid arguments!"); |
942 | void *RawLoc = Loc.getPtrEncoding(); |
943 | CXCursor C = { CXCursor_LabelRef, 0, { Label, RawLoc, TU } }; |
944 | return C; |
945 | } |
946 | |
947 | std::pair<const LabelStmt *, SourceLocation> |
948 | cxcursor::getCursorLabelRef(CXCursor C) { |
949 | assert(C.kind == CXCursor_LabelRef); |
950 | return std::make_pair(static_cast<const LabelStmt *>(C.data[0]), |
951 | SourceLocation::getFromPtrEncoding(C.data[1])); |
952 | } |
953 | |
954 | CXCursor cxcursor::MakeCursorOverloadedDeclRef(const OverloadExpr *E, |
955 | CXTranslationUnit TU) { |
956 | (0) . __assert_fail ("E && TU && \"Invalid arguments!\"", "/home/seafit/code_projects/clang_source/clang/tools/libclang/CXCursor.cpp", 956, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(E && TU && "Invalid arguments!"); |
957 | OverloadedDeclRefStorage Storage(E); |
958 | void *RawLoc = E->getNameLoc().getPtrEncoding(); |
959 | CXCursor C = { |
960 | CXCursor_OverloadedDeclRef, 0, |
961 | { Storage.getOpaqueValue(), RawLoc, TU } |
962 | }; |
963 | return C; |
964 | } |
965 | |
966 | CXCursor cxcursor::MakeCursorOverloadedDeclRef(const Decl *D, |
967 | SourceLocation Loc, |
968 | CXTranslationUnit TU) { |
969 | (0) . __assert_fail ("D && TU && \"Invalid arguments!\"", "/home/seafit/code_projects/clang_source/clang/tools/libclang/CXCursor.cpp", 969, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(D && TU && "Invalid arguments!"); |
970 | void *RawLoc = Loc.getPtrEncoding(); |
971 | OverloadedDeclRefStorage Storage(D); |
972 | CXCursor C = { |
973 | CXCursor_OverloadedDeclRef, 0, |
974 | { Storage.getOpaqueValue(), RawLoc, TU } |
975 | }; |
976 | return C; |
977 | } |
978 | |
979 | CXCursor cxcursor::MakeCursorOverloadedDeclRef(TemplateName Name, |
980 | SourceLocation Loc, |
981 | CXTranslationUnit TU) { |
982 | (0) . __assert_fail ("Name.getAsOverloadedTemplate() && TU && \"Invalid arguments!\"", "/home/seafit/code_projects/clang_source/clang/tools/libclang/CXCursor.cpp", 982, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Name.getAsOverloadedTemplate() && TU && "Invalid arguments!"); |
983 | void *RawLoc = Loc.getPtrEncoding(); |
984 | OverloadedDeclRefStorage Storage(Name.getAsOverloadedTemplate()); |
985 | CXCursor C = { |
986 | CXCursor_OverloadedDeclRef, 0, |
987 | { Storage.getOpaqueValue(), RawLoc, TU } |
988 | }; |
989 | return C; |
990 | } |
991 | |
992 | std::pair<cxcursor::OverloadedDeclRefStorage, SourceLocation> |
993 | cxcursor::getCursorOverloadedDeclRef(CXCursor C) { |
994 | assert(C.kind == CXCursor_OverloadedDeclRef); |
995 | return std::make_pair(OverloadedDeclRefStorage::getFromOpaqueValue( |
996 | const_cast<void *>(C.data[0])), |
997 | SourceLocation::getFromPtrEncoding(C.data[1])); |
998 | } |
999 | |
1000 | const Decl *cxcursor::getCursorDecl(CXCursor Cursor) { |
1001 | return static_cast<const Decl *>(Cursor.data[0]); |
1002 | } |
1003 | |
1004 | const Expr *cxcursor::getCursorExpr(CXCursor Cursor) { |
1005 | return dyn_cast_or_null<Expr>(getCursorStmt(Cursor)); |
1006 | } |
1007 | |
1008 | const Stmt *cxcursor::getCursorStmt(CXCursor Cursor) { |
1009 | if (Cursor.kind == CXCursor_ObjCSuperClassRef || |
1010 | Cursor.kind == CXCursor_ObjCProtocolRef || |
1011 | Cursor.kind == CXCursor_ObjCClassRef) |
1012 | return nullptr; |
1013 | |
1014 | return static_cast<const Stmt *>(Cursor.data[1]); |
1015 | } |
1016 | |
1017 | const Attr *cxcursor::getCursorAttr(CXCursor Cursor) { |
1018 | return static_cast<const Attr *>(Cursor.data[1]); |
1019 | } |
1020 | |
1021 | ASTContext &cxcursor::getCursorContext(CXCursor Cursor) { |
1022 | return getCursorASTUnit(Cursor)->getASTContext(); |
1023 | } |
1024 | |
1025 | ASTUnit *cxcursor::getCursorASTUnit(CXCursor Cursor) { |
1026 | CXTranslationUnit TU = getCursorTU(Cursor); |
1027 | if (!TU) |
1028 | return nullptr; |
1029 | return cxtu::getASTUnit(TU); |
1030 | } |
1031 | |
1032 | CXTranslationUnit cxcursor::getCursorTU(CXCursor Cursor) { |
1033 | return static_cast<CXTranslationUnit>(const_cast<void*>(Cursor.data[2])); |
1034 | } |
1035 | |
1036 | void cxcursor::getOverriddenCursors(CXCursor cursor, |
1037 | SmallVectorImpl<CXCursor> &overridden) { |
1038 | assert(clang_isDeclaration(cursor.kind)); |
1039 | const NamedDecl *D = dyn_cast_or_null<NamedDecl>(getCursorDecl(cursor)); |
1040 | if (!D) |
1041 | return; |
1042 | |
1043 | CXTranslationUnit TU = getCursorTU(cursor); |
1044 | SmallVector<const NamedDecl *, 8> OverDecls; |
1045 | D->getASTContext().getOverriddenMethods(D, OverDecls); |
1046 | |
1047 | for (SmallVectorImpl<const NamedDecl *>::iterator |
1048 | I = OverDecls.begin(), E = OverDecls.end(); I != E; ++I) { |
1049 | overridden.push_back(MakeCXCursor(*I, TU)); |
1050 | } |
1051 | } |
1052 | |
1053 | std::pair<int, SourceLocation> |
1054 | cxcursor::getSelectorIdentifierIndexAndLoc(CXCursor cursor) { |
1055 | if (cursor.kind == CXCursor_ObjCMessageExpr) { |
1056 | if (cursor.xdata != -1) |
1057 | return std::make_pair(cursor.xdata, |
1058 | cast<ObjCMessageExpr>(getCursorExpr(cursor)) |
1059 | ->getSelectorLoc(cursor.xdata)); |
1060 | } else if (cursor.kind == CXCursor_ObjCClassMethodDecl || |
1061 | cursor.kind == CXCursor_ObjCInstanceMethodDecl) { |
1062 | if (cursor.xdata != -1) |
1063 | return std::make_pair(cursor.xdata, |
1064 | cast<ObjCMethodDecl>(getCursorDecl(cursor)) |
1065 | ->getSelectorLoc(cursor.xdata)); |
1066 | } |
1067 | |
1068 | return std::make_pair(-1, SourceLocation()); |
1069 | } |
1070 | |
1071 | CXCursor cxcursor::getSelectorIdentifierCursor(int SelIdx, CXCursor cursor) { |
1072 | CXCursor newCursor = cursor; |
1073 | |
1074 | if (cursor.kind == CXCursor_ObjCMessageExpr) { |
1075 | if (SelIdx == -1 || |
1076 | unsigned(SelIdx) >= cast<ObjCMessageExpr>(getCursorExpr(cursor)) |
1077 | ->getNumSelectorLocs()) |
1078 | newCursor.xdata = -1; |
1079 | else |
1080 | newCursor.xdata = SelIdx; |
1081 | } else if (cursor.kind == CXCursor_ObjCClassMethodDecl || |
1082 | cursor.kind == CXCursor_ObjCInstanceMethodDecl) { |
1083 | if (SelIdx == -1 || |
1084 | unsigned(SelIdx) >= cast<ObjCMethodDecl>(getCursorDecl(cursor)) |
1085 | ->getNumSelectorLocs()) |
1086 | newCursor.xdata = -1; |
1087 | else |
1088 | newCursor.xdata = SelIdx; |
1089 | } |
1090 | |
1091 | return newCursor; |
1092 | } |
1093 | |
1094 | CXCursor cxcursor::getTypeRefCursor(CXCursor cursor) { |
1095 | if (cursor.kind != CXCursor_CallExpr) |
1096 | return cursor; |
1097 | |
1098 | if (cursor.xdata == 0) |
1099 | return cursor; |
1100 | |
1101 | const Expr *E = getCursorExpr(cursor); |
1102 | TypeSourceInfo *Type = nullptr; |
1103 | if (const CXXUnresolvedConstructExpr * |
1104 | UnCtor = dyn_cast<CXXUnresolvedConstructExpr>(E)) { |
1105 | Type = UnCtor->getTypeSourceInfo(); |
1106 | } else if (const CXXTemporaryObjectExpr *Tmp = |
1107 | dyn_cast<CXXTemporaryObjectExpr>(E)){ |
1108 | Type = Tmp->getTypeSourceInfo(); |
1109 | } |
1110 | |
1111 | if (!Type) |
1112 | return cursor; |
1113 | |
1114 | CXTranslationUnit TU = getCursorTU(cursor); |
1115 | QualType Ty = Type->getType(); |
1116 | TypeLoc TL = Type->getTypeLoc(); |
1117 | SourceLocation Loc = TL.getBeginLoc(); |
1118 | |
1119 | if (const ElaboratedType *ElabT = Ty->getAs<ElaboratedType>()) { |
1120 | Ty = ElabT->getNamedType(); |
1121 | ElaboratedTypeLoc ElabTL = TL.castAs<ElaboratedTypeLoc>(); |
1122 | Loc = ElabTL.getNamedTypeLoc().getBeginLoc(); |
1123 | } |
1124 | |
1125 | if (const TypedefType *Typedef = Ty->getAs<TypedefType>()) |
1126 | return MakeCursorTypeRef(Typedef->getDecl(), Loc, TU); |
1127 | if (const TagType *Tag = Ty->getAs<TagType>()) |
1128 | return MakeCursorTypeRef(Tag->getDecl(), Loc, TU); |
1129 | if (const TemplateTypeParmType *TemplP = Ty->getAs<TemplateTypeParmType>()) |
1130 | return MakeCursorTypeRef(TemplP->getDecl(), Loc, TU); |
1131 | |
1132 | return cursor; |
1133 | } |
1134 | |
1135 | bool cxcursor::operator==(CXCursor X, CXCursor Y) { |
1136 | return X.kind == Y.kind && X.data[0] == Y.data[0] && X.data[1] == Y.data[1] && |
1137 | X.data[2] == Y.data[2]; |
1138 | } |
1139 | |
1140 | |
1141 | |
1142 | bool cxcursor::isFirstInDeclGroup(CXCursor C) { |
1143 | assert(clang_isDeclaration(C.kind)); |
1144 | return ((uintptr_t) (C.data[1])) != 0; |
1145 | } |
1146 | |
1147 | |
1148 | |
1149 | |
1150 | |
1151 | int clang_Cursor_isNull(CXCursor cursor) { |
1152 | return clang_equalCursors(cursor, clang_getNullCursor()); |
1153 | } |
1154 | |
1155 | CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor cursor) { |
1156 | return getCursorTU(cursor); |
1157 | } |
1158 | |
1159 | int clang_Cursor_getNumArguments(CXCursor C) { |
1160 | if (clang_isDeclaration(C.kind)) { |
1161 | const Decl *D = cxcursor::getCursorDecl(C); |
1162 | if (const ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(D)) |
1163 | return MD->param_size(); |
1164 | if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) |
1165 | return FD->param_size(); |
1166 | } |
1167 | |
1168 | if (clang_isExpression(C.kind)) { |
1169 | const Expr *E = cxcursor::getCursorExpr(C); |
1170 | if (const CallExpr *CE = dyn_cast<CallExpr>(E)) { |
1171 | return CE->getNumArgs(); |
1172 | } |
1173 | if (const CXXConstructExpr *CE = dyn_cast<CXXConstructExpr>(E)) { |
1174 | return CE->getNumArgs(); |
1175 | } |
1176 | } |
1177 | |
1178 | return -1; |
1179 | } |
1180 | |
1181 | CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i) { |
1182 | if (clang_isDeclaration(C.kind)) { |
1183 | const Decl *D = cxcursor::getCursorDecl(C); |
1184 | if (const ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(D)) { |
1185 | if (i < MD->param_size()) |
1186 | return cxcursor::MakeCXCursor(MD->parameters()[i], |
1187 | cxcursor::getCursorTU(C)); |
1188 | } else if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) { |
1189 | if (i < FD->param_size()) |
1190 | return cxcursor::MakeCXCursor(FD->parameters()[i], |
1191 | cxcursor::getCursorTU(C)); |
1192 | } |
1193 | } |
1194 | |
1195 | if (clang_isExpression(C.kind)) { |
1196 | const Expr *E = cxcursor::getCursorExpr(C); |
1197 | if (const CallExpr *CE = dyn_cast<CallExpr>(E)) { |
1198 | if (i < CE->getNumArgs()) { |
1199 | return cxcursor::MakeCXCursor(CE->getArg(i), |
1200 | getCursorDecl(C), |
1201 | cxcursor::getCursorTU(C)); |
1202 | } |
1203 | } |
1204 | if (const CXXConstructExpr *CE = dyn_cast<CXXConstructExpr>(E)) { |
1205 | if (i < CE->getNumArgs()) { |
1206 | return cxcursor::MakeCXCursor(CE->getArg(i), |
1207 | getCursorDecl(C), |
1208 | cxcursor::getCursorTU(C)); |
1209 | } |
1210 | } |
1211 | } |
1212 | |
1213 | return clang_getNullCursor(); |
1214 | } |
1215 | |
1216 | int clang_Cursor_getNumTemplateArguments(CXCursor C) { |
1217 | if (clang_getCursorKind(C) != CXCursor_FunctionDecl) { |
1218 | return -1; |
1219 | } |
1220 | |
1221 | const FunctionDecl *FD = llvm::dyn_cast_or_null<clang::FunctionDecl>( |
1222 | getCursorDecl(C)); |
1223 | if (!FD) { |
1224 | return -1; |
1225 | } |
1226 | |
1227 | const FunctionTemplateSpecializationInfo* SpecInfo = |
1228 | FD->getTemplateSpecializationInfo(); |
1229 | if (!SpecInfo) { |
1230 | return -1; |
1231 | } |
1232 | |
1233 | return SpecInfo->TemplateArguments->size(); |
1234 | } |
1235 | |
1236 | enum CXGetTemplateArgumentStatus { |
1237 | |
1238 | CXGetTemplateArgumentStatus_Success = 0, |
1239 | |
1240 | |
1241 | CXGetTemplateArgumentStatus_CursorNotFunctionDecl = -1, |
1242 | |
1243 | |
1244 | CXGetTemplateArgumentStatus_BadFunctionDeclCast = -2, |
1245 | |
1246 | |
1247 | CXGetTemplateArgumentStatus_NullTemplSpecInfo = -3, |
1248 | |
1249 | |
1250 | CXGetTemplateArgumentStatus_InvalidIndex = -4 |
1251 | }; |
1252 | |
1253 | static int clang_Cursor_getTemplateArgument( |
1254 | CXCursor C, unsigned I, TemplateArgument *TA) { |
1255 | if (clang_getCursorKind(C) != CXCursor_FunctionDecl) { |
1256 | return CXGetTemplateArgumentStatus_CursorNotFunctionDecl; |
1257 | } |
1258 | |
1259 | const FunctionDecl *FD = llvm::dyn_cast_or_null<clang::FunctionDecl>( |
1260 | getCursorDecl(C)); |
1261 | if (!FD) { |
1262 | return CXGetTemplateArgumentStatus_BadFunctionDeclCast; |
1263 | } |
1264 | |
1265 | const FunctionTemplateSpecializationInfo* SpecInfo = |
1266 | FD->getTemplateSpecializationInfo(); |
1267 | if (!SpecInfo) { |
1268 | return CXGetTemplateArgumentStatus_NullTemplSpecInfo; |
1269 | } |
1270 | |
1271 | if (I >= SpecInfo->TemplateArguments->size()) { |
1272 | return CXGetTemplateArgumentStatus_InvalidIndex; |
1273 | } |
1274 | |
1275 | *TA = SpecInfo->TemplateArguments->get(I); |
1276 | return 0; |
1277 | } |
1278 | |
1279 | enum CXTemplateArgumentKind clang_Cursor_getTemplateArgumentKind(CXCursor C, |
1280 | unsigned I) { |
1281 | TemplateArgument TA; |
1282 | if (clang_Cursor_getTemplateArgument(C, I, &TA)) { |
1283 | return CXTemplateArgumentKind_Invalid; |
1284 | } |
1285 | |
1286 | switch (TA.getKind()) { |
1287 | case TemplateArgument::Null: return CXTemplateArgumentKind_Null; |
1288 | case TemplateArgument::Type: return CXTemplateArgumentKind_Type; |
1289 | case TemplateArgument::Declaration: |
1290 | return CXTemplateArgumentKind_Declaration; |
1291 | case TemplateArgument::NullPtr: return CXTemplateArgumentKind_NullPtr; |
1292 | case TemplateArgument::Integral: return CXTemplateArgumentKind_Integral; |
1293 | case TemplateArgument::Template: return CXTemplateArgumentKind_Template; |
1294 | case TemplateArgument::TemplateExpansion: |
1295 | return CXTemplateArgumentKind_TemplateExpansion; |
1296 | case TemplateArgument::Expression: return CXTemplateArgumentKind_Expression; |
1297 | case TemplateArgument::Pack: return CXTemplateArgumentKind_Pack; |
1298 | } |
1299 | |
1300 | return CXTemplateArgumentKind_Invalid; |
1301 | } |
1302 | |
1303 | CXType clang_Cursor_getTemplateArgumentType(CXCursor C, unsigned I) { |
1304 | TemplateArgument TA; |
1305 | if (clang_Cursor_getTemplateArgument(C, I, &TA) != |
1306 | CXGetTemplateArgumentStatus_Success) { |
1307 | return cxtype::MakeCXType(QualType(), getCursorTU(C)); |
1308 | } |
1309 | |
1310 | if (TA.getKind() != TemplateArgument::Type) { |
1311 | return cxtype::MakeCXType(QualType(), getCursorTU(C)); |
1312 | } |
1313 | |
1314 | return cxtype::MakeCXType(TA.getAsType(), getCursorTU(C)); |
1315 | } |
1316 | |
1317 | long long clang_Cursor_getTemplateArgumentValue(CXCursor C, unsigned I) { |
1318 | TemplateArgument TA; |
1319 | if (clang_Cursor_getTemplateArgument(C, I, &TA) != |
1320 | CXGetTemplateArgumentStatus_Success) { |
1321 | (0) . __assert_fail ("0 && \"Unable to retrieve TemplateArgument\"", "/home/seafit/code_projects/clang_source/clang/tools/libclang/CXCursor.cpp", 1321, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(0 && "Unable to retrieve TemplateArgument"); |
1322 | return 0; |
1323 | } |
1324 | |
1325 | if (TA.getKind() != TemplateArgument::Integral) { |
1326 | (0) . __assert_fail ("0 && \"Passed template argument is not Integral\"", "/home/seafit/code_projects/clang_source/clang/tools/libclang/CXCursor.cpp", 1326, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(0 && "Passed template argument is not Integral"); |
1327 | return 0; |
1328 | } |
1329 | |
1330 | return TA.getAsIntegral().getSExtValue(); |
1331 | } |
1332 | |
1333 | unsigned long long clang_Cursor_getTemplateArgumentUnsignedValue(CXCursor C, |
1334 | unsigned I) { |
1335 | TemplateArgument TA; |
1336 | if (clang_Cursor_getTemplateArgument(C, I, &TA) != |
1337 | CXGetTemplateArgumentStatus_Success) { |
1338 | (0) . __assert_fail ("0 && \"Unable to retrieve TemplateArgument\"", "/home/seafit/code_projects/clang_source/clang/tools/libclang/CXCursor.cpp", 1338, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(0 && "Unable to retrieve TemplateArgument"); |
1339 | return 0; |
1340 | } |
1341 | |
1342 | if (TA.getKind() != TemplateArgument::Integral) { |
1343 | (0) . __assert_fail ("0 && \"Passed template argument is not Integral\"", "/home/seafit/code_projects/clang_source/clang/tools/libclang/CXCursor.cpp", 1343, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(0 && "Passed template argument is not Integral"); |
1344 | return 0; |
1345 | } |
1346 | |
1347 | return TA.getAsIntegral().getZExtValue(); |
1348 | } |
1349 | |
1350 | |
1351 | |
1352 | |
1353 | |
1354 | typedef llvm::DenseMap<CXCursor, unsigned> CXCursorSet_Impl; |
1355 | |
1356 | static inline CXCursorSet packCXCursorSet(CXCursorSet_Impl *setImpl) { |
1357 | return (CXCursorSet) setImpl; |
1358 | } |
1359 | static inline CXCursorSet_Impl *unpackCXCursorSet(CXCursorSet set) { |
1360 | return (CXCursorSet_Impl*) set; |
1361 | } |
1362 | namespace llvm { |
1363 | template<> struct DenseMapInfo<CXCursor> { |
1364 | public: |
1365 | static inline CXCursor getEmptyKey() { |
1366 | return MakeCXCursorInvalid(CXCursor_InvalidFile); |
1367 | } |
1368 | static inline CXCursor getTombstoneKey() { |
1369 | return MakeCXCursorInvalid(CXCursor_NoDeclFound); |
1370 | } |
1371 | static inline unsigned getHashValue(const CXCursor &cursor) { |
1372 | return llvm::DenseMapInfo<std::pair<const void *, const void *> > |
1373 | ::getHashValue(std::make_pair(cursor.data[0], cursor.data[1])); |
1374 | } |
1375 | static inline bool isEqual(const CXCursor &x, const CXCursor &y) { |
1376 | return x.kind == y.kind && |
1377 | x.data[0] == y.data[0] && |
1378 | x.data[1] == y.data[1]; |
1379 | } |
1380 | }; |
1381 | } |
1382 | |
1383 | CXCursorSet clang_createCXCursorSet() { |
1384 | return packCXCursorSet(new CXCursorSet_Impl()); |
1385 | } |
1386 | |
1387 | void clang_disposeCXCursorSet(CXCursorSet set) { |
1388 | delete unpackCXCursorSet(set); |
1389 | } |
1390 | |
1391 | unsigned clang_CXCursorSet_contains(CXCursorSet set, CXCursor cursor) { |
1392 | CXCursorSet_Impl *setImpl = unpackCXCursorSet(set); |
1393 | if (!setImpl) |
1394 | return 0; |
1395 | return setImpl->find(cursor) != setImpl->end(); |
1396 | } |
1397 | |
1398 | unsigned clang_CXCursorSet_insert(CXCursorSet set, CXCursor cursor) { |
1399 | |
1400 | if (cursor.kind >= CXCursor_FirstInvalid && |
1401 | cursor.kind <= CXCursor_LastInvalid) |
1402 | return 1; |
1403 | |
1404 | CXCursorSet_Impl *setImpl = unpackCXCursorSet(set); |
1405 | if (!setImpl) |
1406 | return 1; |
1407 | unsigned &entry = (*setImpl)[cursor]; |
1408 | unsigned flag = entry == 0 ? 1 : 0; |
1409 | entry = 1; |
1410 | return flag; |
1411 | } |
1412 | |
1413 | CXCompletionString clang_getCursorCompletionString(CXCursor cursor) { |
1414 | enum CXCursorKind kind = clang_getCursorKind(cursor); |
1415 | if (clang_isDeclaration(kind)) { |
1416 | const Decl *decl = getCursorDecl(cursor); |
1417 | if (const NamedDecl *namedDecl = dyn_cast_or_null<NamedDecl>(decl)) { |
1418 | ASTUnit *unit = getCursorASTUnit(cursor); |
1419 | CodeCompletionResult Result(namedDecl, CCP_Declaration); |
1420 | CodeCompletionString *String |
1421 | = Result.CreateCodeCompletionString(unit->getASTContext(), |
1422 | unit->getPreprocessor(), |
1423 | CodeCompletionContext::CCC_Other, |
1424 | unit->getCodeCompletionTUInfo().getAllocator(), |
1425 | unit->getCodeCompletionTUInfo(), |
1426 | true); |
1427 | return String; |
1428 | } |
1429 | } else if (kind == CXCursor_MacroDefinition) { |
1430 | const MacroDefinitionRecord *definition = getCursorMacroDefinition(cursor); |
1431 | const IdentifierInfo *Macro = definition->getName(); |
1432 | ASTUnit *unit = getCursorASTUnit(cursor); |
1433 | CodeCompletionResult Result( |
1434 | Macro, |
1435 | unit->getPreprocessor().getMacroDefinition(Macro).getMacroInfo()); |
1436 | CodeCompletionString *String = Result.CreateCodeCompletionString( |
1437 | unit->getASTContext(), unit->getPreprocessor(), |
1438 | CodeCompletionContext::CCC_Other, |
1439 | unit->getCodeCompletionTUInfo().getAllocator(), |
1440 | unit->getCodeCompletionTUInfo(), false); |
1441 | return String; |
1442 | } |
1443 | return nullptr; |
1444 | } |
1445 | |
1446 | namespace { |
1447 | struct OverridenCursorsPool { |
1448 | typedef SmallVector<CXCursor, 2> CursorVec; |
1449 | std::vector<CursorVec*> AllCursors; |
1450 | std::vector<CursorVec*> AvailableCursors; |
1451 | |
1452 | ~OverridenCursorsPool() { |
1453 | for (std::vector<CursorVec*>::iterator I = AllCursors.begin(), |
1454 | E = AllCursors.end(); I != E; ++I) { |
1455 | delete *I; |
1456 | } |
1457 | } |
1458 | }; |
1459 | } |
1460 | |
1461 | void *cxcursor::createOverridenCXCursorsPool() { |
1462 | return new OverridenCursorsPool(); |
1463 | } |
1464 | |
1465 | void cxcursor::disposeOverridenCXCursorsPool(void *pool) { |
1466 | delete static_cast<OverridenCursorsPool*>(pool); |
1467 | } |
1468 | |
1469 | void clang_getOverriddenCursors(CXCursor cursor, |
1470 | CXCursor **overridden, |
1471 | unsigned *num_overridden) { |
1472 | if (overridden) |
1473 | *overridden = nullptr; |
1474 | if (num_overridden) |
1475 | *num_overridden = 0; |
1476 | |
1477 | CXTranslationUnit TU = cxcursor::getCursorTU(cursor); |
1478 | |
1479 | if (!overridden || !num_overridden || !TU) |
1480 | return; |
1481 | |
1482 | if (!clang_isDeclaration(cursor.kind)) |
1483 | return; |
1484 | |
1485 | OverridenCursorsPool &pool = |
1486 | *static_cast<OverridenCursorsPool*>(TU->OverridenCursorsPool); |
1487 | |
1488 | OverridenCursorsPool::CursorVec *Vec = nullptr; |
1489 | |
1490 | if (!pool.AvailableCursors.empty()) { |
1491 | Vec = pool.AvailableCursors.back(); |
1492 | pool.AvailableCursors.pop_back(); |
1493 | } |
1494 | else { |
1495 | Vec = new OverridenCursorsPool::CursorVec(); |
1496 | pool.AllCursors.push_back(Vec); |
1497 | } |
1498 | |
1499 | |
1500 | |
1501 | Vec->clear(); |
1502 | |
1503 | |
1504 | |
1505 | CXCursor backRefCursor = MakeCXCursorInvalid(CXCursor_InvalidFile, TU); |
1506 | backRefCursor.data[0] = Vec; |
1507 | assert(cxcursor::getCursorTU(backRefCursor) == TU); |
1508 | Vec->push_back(backRefCursor); |
1509 | |
1510 | |
1511 | cxcursor::getOverriddenCursors(cursor, *Vec); |
1512 | |
1513 | |
1514 | |
1515 | if (Vec->size() == 1) { |
1516 | pool.AvailableCursors.push_back(Vec); |
1517 | return; |
1518 | } |
1519 | |
1520 | |
1521 | size() > 1", "/home/seafit/code_projects/clang_source/clang/tools/libclang/CXCursor.cpp", 1521, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Vec->size() > 1); |
1522 | *overridden = &((*Vec)[1]); |
1523 | *num_overridden = Vec->size() - 1; |
1524 | } |
1525 | |
1526 | void clang_disposeOverriddenCursors(CXCursor *overridden) { |
1527 | if (!overridden) |
1528 | return; |
1529 | |
1530 | |
1531 | |
1532 | --overridden; |
1533 | OverridenCursorsPool::CursorVec *Vec = |
1534 | static_cast<OverridenCursorsPool::CursorVec *>( |
1535 | const_cast<void *>(overridden->data[0])); |
1536 | CXTranslationUnit TU = getCursorTU(*overridden); |
1537 | |
1538 | assert(Vec && TU); |
1539 | |
1540 | OverridenCursorsPool &pool = |
1541 | *static_cast<OverridenCursorsPool*>(TU->OverridenCursorsPool); |
1542 | |
1543 | pool.AvailableCursors.push_back(Vec); |
1544 | } |
1545 | |
1546 | int clang_Cursor_isDynamicCall(CXCursor C) { |
1547 | const Expr *E = nullptr; |
1548 | if (clang_isExpression(C.kind)) |
1549 | E = getCursorExpr(C); |
1550 | if (!E) |
1551 | return 0; |
1552 | |
1553 | if (const ObjCMessageExpr *MsgE = dyn_cast<ObjCMessageExpr>(E)) { |
1554 | if (MsgE->getReceiverKind() != ObjCMessageExpr::Instance) |
1555 | return false; |
1556 | if (auto *RecE = dyn_cast<ObjCMessageExpr>( |
1557 | MsgE->getInstanceReceiver()->IgnoreParenCasts())) { |
1558 | if (RecE->getMethodFamily() == OMF_alloc) |
1559 | return false; |
1560 | } |
1561 | return true; |
1562 | } |
1563 | |
1564 | if (auto *PropRefE = dyn_cast<ObjCPropertyRefExpr>(E)) { |
1565 | return !PropRefE->isSuperReceiver(); |
1566 | } |
1567 | |
1568 | const MemberExpr *ME = nullptr; |
1569 | if (isa<MemberExpr>(E)) |
1570 | ME = cast<MemberExpr>(E); |
1571 | else if (const CallExpr *CE = dyn_cast<CallExpr>(E)) |
1572 | ME = dyn_cast_or_null<MemberExpr>(CE->getCallee()); |
1573 | |
1574 | if (ME) { |
1575 | if (const CXXMethodDecl * |
1576 | MD = dyn_cast_or_null<CXXMethodDecl>(ME->getMemberDecl())) |
1577 | return MD->isVirtual() && |
1578 | ME->performsVirtualDispatch( |
1579 | cxcursor::getCursorContext(C).getLangOpts()); |
1580 | } |
1581 | |
1582 | return 0; |
1583 | } |
1584 | |
1585 | CXType clang_Cursor_getReceiverType(CXCursor C) { |
1586 | CXTranslationUnit TU = cxcursor::getCursorTU(C); |
1587 | const Expr *E = nullptr; |
1588 | if (clang_isExpression(C.kind)) |
1589 | E = getCursorExpr(C); |
1590 | |
1591 | if (const ObjCMessageExpr *MsgE = dyn_cast_or_null<ObjCMessageExpr>(E)) |
1592 | return cxtype::MakeCXType(MsgE->getReceiverType(), TU); |
1593 | |
1594 | if (auto *PropRefE = dyn_cast<ObjCPropertyRefExpr>(E)) { |
1595 | return cxtype::MakeCXType( |
1596 | PropRefE->getReceiverType(cxcursor::getCursorContext(C)), TU); |
1597 | } |
1598 | |
1599 | const MemberExpr *ME = nullptr; |
1600 | if (isa<MemberExpr>(E)) |
1601 | ME = cast<MemberExpr>(E); |
1602 | else if (const CallExpr *CE = dyn_cast<CallExpr>(E)) |
1603 | ME = dyn_cast_or_null<MemberExpr>(CE->getCallee()); |
1604 | |
1605 | if (ME) { |
1606 | if (dyn_cast_or_null<CXXMethodDecl>(ME->getMemberDecl())) { |
1607 | auto receiverTy = ME->getBase()->IgnoreImpCasts()->getType(); |
1608 | return cxtype::MakeCXType(receiverTy, TU); |
1609 | } |
1610 | } |
1611 | |
1612 | return cxtype::MakeCXType(QualType(), TU); |
1613 | } |
1614 | |