CXCursor.cpp revision 6ad6f2848d7652ab2991286eb48be440d3493b28
1d22bd1421cdfa1900df5b76e6f862596bdd11074Michel Dänzer//===- CXCursor.cpp - Routines for manipulating CXCursors -----------------===// 2d22bd1421cdfa1900df5b76e6f862596bdd11074Michel Dänzer// 3d22bd1421cdfa1900df5b76e6f862596bdd11074Michel Dänzer// The LLVM Compiler Infrastructure 4d22bd1421cdfa1900df5b76e6f862596bdd11074Michel Dänzer// 5d22bd1421cdfa1900df5b76e6f862596bdd11074Michel Dänzer// This file is distributed under the University of Illinois Open Source 6601498ae73e654c2de997ea75075613a694d604dJosé Fonseca// License. See LICENSE.TXT for details. 7601498ae73e654c2de997ea75075613a694d604dJosé Fonseca// 8601498ae73e654c2de997ea75075613a694d604dJosé Fonseca//===----------------------------------------------------------------------===// 9601498ae73e654c2de997ea75075613a694d604dJosé Fonseca// 10601498ae73e654c2de997ea75075613a694d604dJosé Fonseca// This file defines routines for manipulating CXCursors. It should be the 11601498ae73e654c2de997ea75075613a694d604dJosé Fonseca// only file that has internal knowledge of the encoding of the data in 12235225ec935002b4669d14a48c9c20864a5496f8José Fonseca// CXCursor. 13601498ae73e654c2de997ea75075613a694d604dJosé Fonseca// 14235225ec935002b4669d14a48c9c20864a5496f8José Fonseca//===----------------------------------------------------------------------===// 15d49dfe66cfb0e13094e5918b9857c4eb474a53f6José Fonseca 16235225ec935002b4669d14a48c9c20864a5496f8José Fonseca#include "CXTranslationUnit.h" 17d49dfe66cfb0e13094e5918b9857c4eb474a53f6José Fonseca#include "CXCursor.h" 18601498ae73e654c2de997ea75075613a694d604dJosé Fonseca#include "CXString.h" 19601498ae73e654c2de997ea75075613a694d604dJosé Fonseca#include "clang/Frontend/ASTUnit.h" 20601498ae73e654c2de997ea75075613a694d604dJosé Fonseca#include "clang/AST/Decl.h" 21601498ae73e654c2de997ea75075613a694d604dJosé Fonseca#include "clang/AST/DeclCXX.h" 22601498ae73e654c2de997ea75075613a694d604dJosé Fonseca#include "clang/AST/DeclObjC.h" 23601498ae73e654c2de997ea75075613a694d604dJosé Fonseca#include "clang/AST/Expr.h" 24601498ae73e654c2de997ea75075613a694d604dJosé Fonseca#include "clang/AST/ExprCXX.h" 25f1600d3a9725803f0526fb3fd673787307539d27Jakob Bornecrantz#include "clang-c/Index.h" 26f1600d3a9725803f0526fb3fd673787307539d27Jakob Bornecrantz#include "llvm/Support/ErrorHandling.h" 27601498ae73e654c2de997ea75075613a694d604dJosé Fonseca 28601498ae73e654c2de997ea75075613a694d604dJosé Fonsecausing namespace clang; 29601498ae73e654c2de997ea75075613a694d604dJosé Fonsecausing namespace cxcursor; 30601498ae73e654c2de997ea75075613a694d604dJosé Fonseca 31601498ae73e654c2de997ea75075613a694d604dJosé FonsecaCXCursor cxcursor::MakeCXCursorInvalid(CXCursorKind K) { 32601498ae73e654c2de997ea75075613a694d604dJosé Fonseca assert(K >= CXCursor_FirstInvalid && K <= CXCursor_LastInvalid); 33601498ae73e654c2de997ea75075613a694d604dJosé Fonseca CXCursor C = { K, { 0, 0, 0 } }; 34601498ae73e654c2de997ea75075613a694d604dJosé Fonseca return C; 358f26b59f53d6d80bf7d3c39a4dd3c438a2c305a4Maarten Lankhorst} 36f1600d3a9725803f0526fb3fd673787307539d27Jakob Bornecrantz 37f1600d3a9725803f0526fb3fd673787307539d27Jakob Bornecrantzstatic CXCursorKind GetCursorKind(const Attr *A) { 38f1600d3a9725803f0526fb3fd673787307539d27Jakob Bornecrantz assert(A && "Invalid arguments!"); 39f1600d3a9725803f0526fb3fd673787307539d27Jakob Bornecrantz switch (A->getKind()) { 40f1600d3a9725803f0526fb3fd673787307539d27Jakob Bornecrantz default: break; 41601498ae73e654c2de997ea75075613a694d604dJosé Fonseca case attr::IBAction: return CXCursor_IBActionAttr; 42601498ae73e654c2de997ea75075613a694d604dJosé Fonseca case attr::IBOutlet: return CXCursor_IBOutletAttr; 43 case attr::IBOutletCollection: return CXCursor_IBOutletCollectionAttr; 44 } 45 46 return CXCursor_UnexposedAttr; 47} 48 49CXCursor cxcursor::MakeCXCursor(const Attr *A, Decl *Parent, 50 CXTranslationUnit TU) { 51 assert(A && Parent && TU && "Invalid arguments!"); 52 CXCursor C = { GetCursorKind(A), { Parent, (void*)A, TU } }; 53 return C; 54} 55 56CXCursor cxcursor::MakeCXCursor(Decl *D, CXTranslationUnit TU, 57 bool FirstInDeclGroup) { 58 assert(D && TU && "Invalid arguments!"); 59 CXCursor C = { getCursorKindForDecl(D), 60 { D, (void*) (FirstInDeclGroup ? 1 : 0), TU } 61 }; 62 return C; 63} 64 65CXCursor cxcursor::MakeCXCursor(Stmt *S, Decl *Parent, 66 CXTranslationUnit TU) { 67 assert(S && TU && "Invalid arguments!"); 68 CXCursorKind K = CXCursor_NotImplemented; 69 70 switch (S->getStmtClass()) { 71 case Stmt::NoStmtClass: 72 break; 73 74 case Stmt::NullStmtClass: 75 case Stmt::CompoundStmtClass: 76 case Stmt::CaseStmtClass: 77 case Stmt::DefaultStmtClass: 78 case Stmt::IfStmtClass: 79 case Stmt::SwitchStmtClass: 80 case Stmt::WhileStmtClass: 81 case Stmt::DoStmtClass: 82 case Stmt::ForStmtClass: 83 case Stmt::GotoStmtClass: 84 case Stmt::IndirectGotoStmtClass: 85 case Stmt::ContinueStmtClass: 86 case Stmt::BreakStmtClass: 87 case Stmt::ReturnStmtClass: 88 case Stmt::DeclStmtClass: 89 case Stmt::SwitchCaseClass: 90 case Stmt::AsmStmtClass: 91 case Stmt::ObjCAtTryStmtClass: 92 case Stmt::ObjCAtCatchStmtClass: 93 case Stmt::ObjCAtFinallyStmtClass: 94 case Stmt::ObjCAtThrowStmtClass: 95 case Stmt::ObjCAtSynchronizedStmtClass: 96 case Stmt::ObjCForCollectionStmtClass: 97 case Stmt::CXXCatchStmtClass: 98 case Stmt::CXXTryStmtClass: 99 K = CXCursor_UnexposedStmt; 100 break; 101 102 case Stmt::LabelStmtClass: 103 K = CXCursor_LabelStmt; 104 break; 105 106 case Stmt::PredefinedExprClass: 107 case Stmt::IntegerLiteralClass: 108 case Stmt::FloatingLiteralClass: 109 case Stmt::ImaginaryLiteralClass: 110 case Stmt::StringLiteralClass: 111 case Stmt::CharacterLiteralClass: 112 case Stmt::ParenExprClass: 113 case Stmt::UnaryOperatorClass: 114 case Stmt::OffsetOfExprClass: 115 case Stmt::SizeOfAlignOfExprClass: 116 case Stmt::ArraySubscriptExprClass: 117 case Stmt::BinaryOperatorClass: 118 case Stmt::CompoundAssignOperatorClass: 119 case Stmt::ConditionalOperatorClass: 120 case Stmt::ImplicitCastExprClass: 121 case Stmt::CStyleCastExprClass: 122 case Stmt::CompoundLiteralExprClass: 123 case Stmt::ExtVectorElementExprClass: 124 case Stmt::InitListExprClass: 125 case Stmt::DesignatedInitExprClass: 126 case Stmt::ImplicitValueInitExprClass: 127 case Stmt::ParenListExprClass: 128 case Stmt::VAArgExprClass: 129 case Stmt::AddrLabelExprClass: 130 case Stmt::StmtExprClass: 131 case Stmt::TypesCompatibleExprClass: 132 case Stmt::ChooseExprClass: 133 case Stmt::GNUNullExprClass: 134 case Stmt::CXXStaticCastExprClass: 135 case Stmt::CXXDynamicCastExprClass: 136 case Stmt::CXXReinterpretCastExprClass: 137 case Stmt::CXXConstCastExprClass: 138 case Stmt::CXXFunctionalCastExprClass: 139 case Stmt::CXXTypeidExprClass: 140 case Stmt::CXXUuidofExprClass: 141 case Stmt::CXXBoolLiteralExprClass: 142 case Stmt::CXXNullPtrLiteralExprClass: 143 case Stmt::CXXThisExprClass: 144 case Stmt::CXXThrowExprClass: 145 case Stmt::CXXDefaultArgExprClass: 146 case Stmt::CXXScalarValueInitExprClass: 147 case Stmt::CXXNewExprClass: 148 case Stmt::CXXDeleteExprClass: 149 case Stmt::CXXPseudoDestructorExprClass: 150 case Stmt::UnresolvedLookupExprClass: 151 case Stmt::UnaryTypeTraitExprClass: 152 case Stmt::BinaryTypeTraitExprClass: 153 case Stmt::DependentScopeDeclRefExprClass: 154 case Stmt::CXXBindTemporaryExprClass: 155 case Stmt::ExprWithCleanupsClass: 156 case Stmt::CXXUnresolvedConstructExprClass: 157 case Stmt::CXXDependentScopeMemberExprClass: 158 case Stmt::UnresolvedMemberExprClass: 159 case Stmt::CXXNoexceptExprClass: 160 case Stmt::ObjCStringLiteralClass: 161 case Stmt::ObjCEncodeExprClass: 162 case Stmt::ObjCSelectorExprClass: 163 case Stmt::ObjCProtocolExprClass: 164 case Stmt::ObjCIsaExprClass: 165 case Stmt::ShuffleVectorExprClass: 166 case Stmt::BlockExprClass: 167 case Stmt::OpaqueValueExprClass: 168 K = CXCursor_UnexposedExpr; 169 break; 170 171 case Stmt::DeclRefExprClass: 172 case Stmt::BlockDeclRefExprClass: 173 // FIXME: UnresolvedLookupExpr? 174 // FIXME: DependentScopeDeclRefExpr? 175 K = CXCursor_DeclRefExpr; 176 break; 177 178 case Stmt::MemberExprClass: 179 case Stmt::ObjCIvarRefExprClass: 180 case Stmt::ObjCPropertyRefExprClass: 181 // FIXME: UnresolvedMemberExpr? 182 // FIXME: CXXDependentScopeMemberExpr? 183 K = CXCursor_MemberRefExpr; 184 break; 185 186 case Stmt::CallExprClass: 187 case Stmt::CXXOperatorCallExprClass: 188 case Stmt::CXXMemberCallExprClass: 189 case Stmt::CXXConstructExprClass: 190 case Stmt::CXXTemporaryObjectExprClass: 191 // FIXME: CXXUnresolvedConstructExpr 192 K = CXCursor_CallExpr; 193 break; 194 195 case Stmt::ObjCMessageExprClass: 196 K = CXCursor_ObjCMessageExpr; 197 break; 198 } 199 200 CXCursor C = { K, { Parent, S, TU } }; 201 return C; 202} 203 204CXCursor cxcursor::MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super, 205 SourceLocation Loc, 206 CXTranslationUnit TU) { 207 assert(Super && TU && "Invalid arguments!"); 208 void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 209 CXCursor C = { CXCursor_ObjCSuperClassRef, { Super, RawLoc, TU } }; 210 return C; 211} 212 213std::pair<ObjCInterfaceDecl *, SourceLocation> 214cxcursor::getCursorObjCSuperClassRef(CXCursor C) { 215 assert(C.kind == CXCursor_ObjCSuperClassRef); 216 return std::make_pair(static_cast<ObjCInterfaceDecl *>(C.data[0]), 217 SourceLocation::getFromRawEncoding( 218 reinterpret_cast<uintptr_t>(C.data[1]))); 219} 220 221CXCursor cxcursor::MakeCursorObjCProtocolRef(ObjCProtocolDecl *Super, 222 SourceLocation Loc, 223 CXTranslationUnit TU) { 224 assert(Super && TU && "Invalid arguments!"); 225 void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 226 CXCursor C = { CXCursor_ObjCProtocolRef, { Super, RawLoc, TU } }; 227 return C; 228} 229 230std::pair<ObjCProtocolDecl *, SourceLocation> 231cxcursor::getCursorObjCProtocolRef(CXCursor C) { 232 assert(C.kind == CXCursor_ObjCProtocolRef); 233 return std::make_pair(static_cast<ObjCProtocolDecl *>(C.data[0]), 234 SourceLocation::getFromRawEncoding( 235 reinterpret_cast<uintptr_t>(C.data[1]))); 236} 237 238CXCursor cxcursor::MakeCursorObjCClassRef(ObjCInterfaceDecl *Class, 239 SourceLocation Loc, 240 CXTranslationUnit TU) { 241 // 'Class' can be null for invalid code. 242 if (!Class) 243 return MakeCXCursorInvalid(CXCursor_InvalidCode); 244 assert(TU && "Invalid arguments!"); 245 void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 246 CXCursor C = { CXCursor_ObjCClassRef, { Class, RawLoc, TU } }; 247 return C; 248} 249 250std::pair<ObjCInterfaceDecl *, SourceLocation> 251cxcursor::getCursorObjCClassRef(CXCursor C) { 252 assert(C.kind == CXCursor_ObjCClassRef); 253 return std::make_pair(static_cast<ObjCInterfaceDecl *>(C.data[0]), 254 SourceLocation::getFromRawEncoding( 255 reinterpret_cast<uintptr_t>(C.data[1]))); 256} 257 258CXCursor cxcursor::MakeCursorTypeRef(TypeDecl *Type, SourceLocation Loc, 259 CXTranslationUnit TU) { 260 assert(Type && TU && "Invalid arguments!"); 261 void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 262 CXCursor C = { CXCursor_TypeRef, { Type, RawLoc, TU } }; 263 return C; 264} 265 266std::pair<TypeDecl *, SourceLocation> 267cxcursor::getCursorTypeRef(CXCursor C) { 268 assert(C.kind == CXCursor_TypeRef); 269 return std::make_pair(static_cast<TypeDecl *>(C.data[0]), 270 SourceLocation::getFromRawEncoding( 271 reinterpret_cast<uintptr_t>(C.data[1]))); 272} 273 274CXCursor cxcursor::MakeCursorTemplateRef(TemplateDecl *Template, 275 SourceLocation Loc, 276 CXTranslationUnit TU) { 277 assert(Template && TU && "Invalid arguments!"); 278 void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 279 CXCursor C = { CXCursor_TemplateRef, { Template, RawLoc, TU } }; 280 return C; 281} 282 283std::pair<TemplateDecl *, SourceLocation> 284cxcursor::getCursorTemplateRef(CXCursor C) { 285 assert(C.kind == CXCursor_TemplateRef); 286 return std::make_pair(static_cast<TemplateDecl *>(C.data[0]), 287 SourceLocation::getFromRawEncoding( 288 reinterpret_cast<uintptr_t>(C.data[1]))); 289} 290 291CXCursor cxcursor::MakeCursorNamespaceRef(NamedDecl *NS, SourceLocation Loc, 292 CXTranslationUnit TU) { 293 294 assert(NS && (isa<NamespaceDecl>(NS) || isa<NamespaceAliasDecl>(NS)) && TU && 295 "Invalid arguments!"); 296 void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 297 CXCursor C = { CXCursor_NamespaceRef, { NS, RawLoc, TU } }; 298 return C; 299} 300 301std::pair<NamedDecl *, SourceLocation> 302cxcursor::getCursorNamespaceRef(CXCursor C) { 303 assert(C.kind == CXCursor_NamespaceRef); 304 return std::make_pair(static_cast<NamedDecl *>(C.data[0]), 305 SourceLocation::getFromRawEncoding( 306 reinterpret_cast<uintptr_t>(C.data[1]))); 307} 308 309CXCursor cxcursor::MakeCursorMemberRef(FieldDecl *Field, SourceLocation Loc, 310 CXTranslationUnit TU) { 311 312 assert(Field && TU && "Invalid arguments!"); 313 void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 314 CXCursor C = { CXCursor_MemberRef, { Field, RawLoc, TU } }; 315 return C; 316} 317 318std::pair<FieldDecl *, SourceLocation> 319cxcursor::getCursorMemberRef(CXCursor C) { 320 assert(C.kind == CXCursor_MemberRef); 321 return std::make_pair(static_cast<FieldDecl *>(C.data[0]), 322 SourceLocation::getFromRawEncoding( 323 reinterpret_cast<uintptr_t>(C.data[1]))); 324} 325 326CXCursor cxcursor::MakeCursorCXXBaseSpecifier(CXXBaseSpecifier *B, 327 CXTranslationUnit TU){ 328 CXCursor C = { CXCursor_CXXBaseSpecifier, { B, 0, TU } }; 329 return C; 330} 331 332CXXBaseSpecifier *cxcursor::getCursorCXXBaseSpecifier(CXCursor C) { 333 assert(C.kind == CXCursor_CXXBaseSpecifier); 334 return static_cast<CXXBaseSpecifier*>(C.data[0]); 335} 336 337CXCursor cxcursor::MakePreprocessingDirectiveCursor(SourceRange Range, 338 CXTranslationUnit TU) { 339 CXCursor C = { CXCursor_PreprocessingDirective, 340 { reinterpret_cast<void *>(Range.getBegin().getRawEncoding()), 341 reinterpret_cast<void *>(Range.getEnd().getRawEncoding()), 342 TU } 343 }; 344 return C; 345} 346 347SourceRange cxcursor::getCursorPreprocessingDirective(CXCursor C) { 348 assert(C.kind == CXCursor_PreprocessingDirective); 349 return SourceRange(SourceLocation::getFromRawEncoding( 350 reinterpret_cast<uintptr_t> (C.data[0])), 351 SourceLocation::getFromRawEncoding( 352 reinterpret_cast<uintptr_t> (C.data[1]))); 353} 354 355CXCursor cxcursor::MakeMacroDefinitionCursor(MacroDefinition *MI, 356 CXTranslationUnit TU) { 357 CXCursor C = { CXCursor_MacroDefinition, { MI, 0, TU } }; 358 return C; 359} 360 361MacroDefinition *cxcursor::getCursorMacroDefinition(CXCursor C) { 362 assert(C.kind == CXCursor_MacroDefinition); 363 return static_cast<MacroDefinition *>(C.data[0]); 364} 365 366CXCursor cxcursor::MakeMacroInstantiationCursor(MacroInstantiation *MI, 367 CXTranslationUnit TU) { 368 CXCursor C = { CXCursor_MacroInstantiation, { MI, 0, TU } }; 369 return C; 370} 371 372MacroInstantiation *cxcursor::getCursorMacroInstantiation(CXCursor C) { 373 assert(C.kind == CXCursor_MacroInstantiation); 374 return static_cast<MacroInstantiation *>(C.data[0]); 375} 376 377CXCursor cxcursor::MakeInclusionDirectiveCursor(InclusionDirective *ID, 378 CXTranslationUnit TU) { 379 CXCursor C = { CXCursor_InclusionDirective, { ID, 0, TU } }; 380 return C; 381} 382 383InclusionDirective *cxcursor::getCursorInclusionDirective(CXCursor C) { 384 assert(C.kind == CXCursor_InclusionDirective); 385 return static_cast<InclusionDirective *>(C.data[0]); 386} 387 388CXCursor cxcursor::MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc, 389 CXTranslationUnit TU) { 390 391 assert(Label && TU && "Invalid arguments!"); 392 void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 393 CXCursor C = { CXCursor_LabelRef, { Label, RawLoc, TU } }; 394 return C; 395} 396 397std::pair<LabelStmt*, SourceLocation> 398cxcursor::getCursorLabelRef(CXCursor C) { 399 assert(C.kind == CXCursor_LabelRef); 400 return std::make_pair(static_cast<LabelStmt *>(C.data[0]), 401 SourceLocation::getFromRawEncoding( 402 reinterpret_cast<uintptr_t>(C.data[1]))); 403} 404 405CXCursor cxcursor::MakeCursorOverloadedDeclRef(OverloadExpr *E, 406 CXTranslationUnit TU) { 407 assert(E && TU && "Invalid arguments!"); 408 OverloadedDeclRefStorage Storage(E); 409 void *RawLoc = reinterpret_cast<void *>(E->getNameLoc().getRawEncoding()); 410 CXCursor C = { 411 CXCursor_OverloadedDeclRef, 412 { Storage.getOpaqueValue(), RawLoc, TU } 413 }; 414 return C; 415} 416 417CXCursor cxcursor::MakeCursorOverloadedDeclRef(Decl *D, 418 SourceLocation Loc, 419 CXTranslationUnit TU) { 420 assert(D && TU && "Invalid arguments!"); 421 void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 422 OverloadedDeclRefStorage Storage(D); 423 CXCursor C = { 424 CXCursor_OverloadedDeclRef, 425 { Storage.getOpaqueValue(), RawLoc, TU } 426 }; 427 return C; 428} 429 430CXCursor cxcursor::MakeCursorOverloadedDeclRef(TemplateName Name, 431 SourceLocation Loc, 432 CXTranslationUnit TU) { 433 assert(Name.getAsOverloadedTemplate() && TU && "Invalid arguments!"); 434 void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); 435 OverloadedDeclRefStorage Storage(Name.getAsOverloadedTemplate()); 436 CXCursor C = { 437 CXCursor_OverloadedDeclRef, 438 { Storage.getOpaqueValue(), RawLoc, TU } 439 }; 440 return C; 441} 442 443std::pair<cxcursor::OverloadedDeclRefStorage, SourceLocation> 444cxcursor::getCursorOverloadedDeclRef(CXCursor C) { 445 assert(C.kind == CXCursor_OverloadedDeclRef); 446 return std::make_pair(OverloadedDeclRefStorage::getFromOpaqueValue(C.data[0]), 447 SourceLocation::getFromRawEncoding( 448 reinterpret_cast<uintptr_t>(C.data[1]))); 449} 450 451Decl *cxcursor::getCursorDecl(CXCursor Cursor) { 452 return (Decl *)Cursor.data[0]; 453} 454 455Expr *cxcursor::getCursorExpr(CXCursor Cursor) { 456 return dyn_cast_or_null<Expr>(getCursorStmt(Cursor)); 457} 458 459Stmt *cxcursor::getCursorStmt(CXCursor Cursor) { 460 if (Cursor.kind == CXCursor_ObjCSuperClassRef || 461 Cursor.kind == CXCursor_ObjCProtocolRef || 462 Cursor.kind == CXCursor_ObjCClassRef) 463 return 0; 464 465 return (Stmt *)Cursor.data[1]; 466} 467 468Attr *cxcursor::getCursorAttr(CXCursor Cursor) { 469 return (Attr *)Cursor.data[1]; 470} 471 472ASTContext &cxcursor::getCursorContext(CXCursor Cursor) { 473 return getCursorASTUnit(Cursor)->getASTContext(); 474} 475 476ASTUnit *cxcursor::getCursorASTUnit(CXCursor Cursor) { 477 return static_cast<ASTUnit *>(static_cast<CXTranslationUnit>(Cursor.data[2]) 478 ->TUData); 479} 480 481CXTranslationUnit cxcursor::getCursorTU(CXCursor Cursor) { 482 return static_cast<CXTranslationUnit>(Cursor.data[2]); 483} 484 485bool cxcursor::operator==(CXCursor X, CXCursor Y) { 486 return X.kind == Y.kind && X.data[0] == Y.data[0] && X.data[1] == Y.data[1] && 487 X.data[2] == Y.data[2]; 488} 489 490// FIXME: Remove once we can model DeclGroups and their appropriate ranges 491// properly in the ASTs. 492bool cxcursor::isFirstInDeclGroup(CXCursor C) { 493 assert(clang_isDeclaration(C.kind)); 494 return ((uintptr_t) (C.data[1])) != 0; 495} 496 497