Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 1 | //===- 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 Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 10 | // 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 Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #include "CXCursor.h" |
Douglas Gregor | 7eaa8ae | 2010-01-20 00:23:15 +0000 | [diff] [blame] | 17 | #include "clang/Frontend/ASTUnit.h" |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 18 | #include "clang/AST/Decl.h" |
Douglas Gregor | 6931900 | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclCXX.h" |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclObjC.h" |
| 21 | #include "clang/AST/Expr.h" |
Ted Kremenek | edc8aa6 | 2010-01-16 00:36:30 +0000 | [diff] [blame] | 22 | #include "llvm/Support/ErrorHandling.h" |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 23 | |
| 24 | using namespace clang; |
| 25 | |
Douglas Gregor | 5bfb8c1 | 2010-01-20 23:34:41 +0000 | [diff] [blame] | 26 | CXCursor cxcursor::MakeCXCursorInvalid(CXCursorKind K) { |
| 27 | assert(K >= CXCursor_FirstInvalid && K <= CXCursor_LastInvalid); |
| 28 | CXCursor C = { K, { 0, 0, 0 } }; |
| 29 | return C; |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 30 | } |
| 31 | |
Ted Kremenek | e77f443 | 2010-02-18 03:09:07 +0000 | [diff] [blame] | 32 | static CXCursorKind GetCursorKind(const Attr *A) { |
| 33 | assert(A && "Invalid arguments!"); |
| 34 | switch (A->getKind()) { |
| 35 | default: break; |
Sean Hunt | 387475d | 2010-06-16 23:43:53 +0000 | [diff] [blame] | 36 | case attr::IBAction: return CXCursor_IBActionAttr; |
| 37 | case attr::IBOutlet: return CXCursor_IBOutletAttr; |
| 38 | case attr::IBOutletCollection: return CXCursor_IBOutletCollectionAttr; |
Ted Kremenek | e77f443 | 2010-02-18 03:09:07 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | return CXCursor_UnexposedAttr; |
| 42 | } |
| 43 | |
| 44 | CXCursor cxcursor::MakeCXCursor(const Attr *A, Decl *Parent, ASTUnit *TU) { |
| 45 | assert(A && Parent && TU && "Invalid arguments!"); |
| 46 | CXCursor C = { GetCursorKind(A), { Parent, (void*)A, TU } }; |
| 47 | return C; |
| 48 | } |
| 49 | |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 50 | CXCursor cxcursor::MakeCXCursor(Decl *D, ASTUnit *TU) { |
Daniel Dunbar | 54d67ca | 2010-01-25 00:40:30 +0000 | [diff] [blame] | 51 | assert(D && TU && "Invalid arguments!"); |
Douglas Gregor | e8d7beb | 2010-09-03 23:30:36 +0000 | [diff] [blame] | 52 | CXCursor C = { getCursorKindForDecl(D), { D, 0, TU } }; |
Douglas Gregor | 5bfb8c1 | 2010-01-20 23:34:41 +0000 | [diff] [blame] | 53 | return C; |
Ted Kremenek | edc8aa6 | 2010-01-16 00:36:30 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 56 | CXCursor cxcursor::MakeCXCursor(Stmt *S, Decl *Parent, ASTUnit *TU) { |
Daniel Dunbar | 54d67ca | 2010-01-25 00:40:30 +0000 | [diff] [blame] | 57 | assert(S && TU && "Invalid arguments!"); |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 58 | CXCursorKind K = CXCursor_NotImplemented; |
| 59 | |
| 60 | switch (S->getStmtClass()) { |
| 61 | case Stmt::NoStmtClass: |
| 62 | break; |
| 63 | |
| 64 | case Stmt::NullStmtClass: |
| 65 | case Stmt::CompoundStmtClass: |
| 66 | case Stmt::CaseStmtClass: |
| 67 | case Stmt::DefaultStmtClass: |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 68 | case Stmt::IfStmtClass: |
| 69 | case Stmt::SwitchStmtClass: |
| 70 | case Stmt::WhileStmtClass: |
| 71 | case Stmt::DoStmtClass: |
| 72 | case Stmt::ForStmtClass: |
| 73 | case Stmt::GotoStmtClass: |
| 74 | case Stmt::IndirectGotoStmtClass: |
| 75 | case Stmt::ContinueStmtClass: |
| 76 | case Stmt::BreakStmtClass: |
| 77 | case Stmt::ReturnStmtClass: |
| 78 | case Stmt::DeclStmtClass: |
| 79 | case Stmt::SwitchCaseClass: |
| 80 | case Stmt::AsmStmtClass: |
| 81 | case Stmt::ObjCAtTryStmtClass: |
| 82 | case Stmt::ObjCAtCatchStmtClass: |
| 83 | case Stmt::ObjCAtFinallyStmtClass: |
| 84 | case Stmt::ObjCAtThrowStmtClass: |
| 85 | case Stmt::ObjCAtSynchronizedStmtClass: |
| 86 | case Stmt::ObjCForCollectionStmtClass: |
| 87 | case Stmt::CXXCatchStmtClass: |
| 88 | case Stmt::CXXTryStmtClass: |
| 89 | K = CXCursor_UnexposedStmt; |
| 90 | break; |
| 91 | |
Douglas Gregor | 36897b0 | 2010-09-10 00:22:18 +0000 | [diff] [blame^] | 92 | case Stmt::LabelStmtClass: |
| 93 | K = CXCursor_LabelStmt; |
| 94 | break; |
| 95 | |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 96 | case Stmt::PredefinedExprClass: |
| 97 | case Stmt::IntegerLiteralClass: |
| 98 | case Stmt::FloatingLiteralClass: |
| 99 | case Stmt::ImaginaryLiteralClass: |
| 100 | case Stmt::StringLiteralClass: |
| 101 | case Stmt::CharacterLiteralClass: |
| 102 | case Stmt::ParenExprClass: |
Douglas Gregor | 8ecdb65 | 2010-04-28 22:16:22 +0000 | [diff] [blame] | 103 | case Stmt::UnaryOperatorClass: |
| 104 | case Stmt::OffsetOfExprClass: |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 105 | case Stmt::SizeOfAlignOfExprClass: |
| 106 | case Stmt::ArraySubscriptExprClass: |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 107 | case Stmt::BinaryOperatorClass: |
| 108 | case Stmt::CompoundAssignOperatorClass: |
| 109 | case Stmt::ConditionalOperatorClass: |
| 110 | case Stmt::ImplicitCastExprClass: |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 111 | case Stmt::CStyleCastExprClass: |
| 112 | case Stmt::CompoundLiteralExprClass: |
| 113 | case Stmt::ExtVectorElementExprClass: |
| 114 | case Stmt::InitListExprClass: |
| 115 | case Stmt::DesignatedInitExprClass: |
| 116 | case Stmt::ImplicitValueInitExprClass: |
| 117 | case Stmt::ParenListExprClass: |
| 118 | case Stmt::VAArgExprClass: |
| 119 | case Stmt::AddrLabelExprClass: |
| 120 | case Stmt::StmtExprClass: |
| 121 | case Stmt::TypesCompatibleExprClass: |
| 122 | case Stmt::ChooseExprClass: |
| 123 | case Stmt::GNUNullExprClass: |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 124 | case Stmt::CXXStaticCastExprClass: |
| 125 | case Stmt::CXXDynamicCastExprClass: |
| 126 | case Stmt::CXXReinterpretCastExprClass: |
| 127 | case Stmt::CXXConstCastExprClass: |
| 128 | case Stmt::CXXFunctionalCastExprClass: |
| 129 | case Stmt::CXXTypeidExprClass: |
Francois Pichet | 9be8840 | 2010-09-08 23:47:05 +0000 | [diff] [blame] | 130 | case Stmt::CXXUuidofExprClass: |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 131 | case Stmt::CXXBoolLiteralExprClass: |
| 132 | case Stmt::CXXNullPtrLiteralExprClass: |
| 133 | case Stmt::CXXThisExprClass: |
| 134 | case Stmt::CXXThrowExprClass: |
| 135 | case Stmt::CXXDefaultArgExprClass: |
Douglas Gregor | ed8abf1 | 2010-07-08 06:14:04 +0000 | [diff] [blame] | 136 | case Stmt::CXXScalarValueInitExprClass: |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 137 | case Stmt::CXXNewExprClass: |
| 138 | case Stmt::CXXDeleteExprClass: |
| 139 | case Stmt::CXXPseudoDestructorExprClass: |
| 140 | case Stmt::UnresolvedLookupExprClass: |
| 141 | case Stmt::UnaryTypeTraitExprClass: |
| 142 | case Stmt::DependentScopeDeclRefExprClass: |
| 143 | case Stmt::CXXBindTemporaryExprClass: |
| 144 | case Stmt::CXXExprWithTemporariesClass: |
| 145 | case Stmt::CXXUnresolvedConstructExprClass: |
| 146 | case Stmt::CXXDependentScopeMemberExprClass: |
| 147 | case Stmt::UnresolvedMemberExprClass: |
| 148 | case Stmt::ObjCStringLiteralClass: |
| 149 | case Stmt::ObjCEncodeExprClass: |
| 150 | case Stmt::ObjCSelectorExprClass: |
| 151 | case Stmt::ObjCProtocolExprClass: |
| 152 | case Stmt::ObjCImplicitSetterGetterRefExprClass: |
| 153 | case Stmt::ObjCSuperExprClass: |
| 154 | case Stmt::ObjCIsaExprClass: |
| 155 | case Stmt::ShuffleVectorExprClass: |
| 156 | case Stmt::BlockExprClass: |
| 157 | K = CXCursor_UnexposedExpr; |
| 158 | break; |
Douglas Gregor | 36897b0 | 2010-09-10 00:22:18 +0000 | [diff] [blame^] | 159 | |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 160 | case Stmt::DeclRefExprClass: |
| 161 | case Stmt::BlockDeclRefExprClass: |
| 162 | // FIXME: UnresolvedLookupExpr? |
| 163 | // FIXME: DependentScopeDeclRefExpr? |
| 164 | K = CXCursor_DeclRefExpr; |
| 165 | break; |
| 166 | |
| 167 | case Stmt::MemberExprClass: |
| 168 | case Stmt::ObjCIvarRefExprClass: |
| 169 | case Stmt::ObjCPropertyRefExprClass: |
| 170 | // FIXME: UnresolvedMemberExpr? |
| 171 | // FIXME: CXXDependentScopeMemberExpr? |
| 172 | K = CXCursor_MemberRefExpr; |
| 173 | break; |
| 174 | |
| 175 | case Stmt::CallExprClass: |
| 176 | case Stmt::CXXOperatorCallExprClass: |
| 177 | case Stmt::CXXMemberCallExprClass: |
| 178 | case Stmt::CXXConstructExprClass: |
| 179 | case Stmt::CXXTemporaryObjectExprClass: |
| 180 | // FIXME: CXXUnresolvedConstructExpr |
| 181 | // FIXME: ObjCImplicitSetterGetterRefExpr? |
| 182 | K = CXCursor_CallExpr; |
| 183 | break; |
| 184 | |
| 185 | case Stmt::ObjCMessageExprClass: |
| 186 | K = CXCursor_ObjCMessageExpr; |
| 187 | break; |
| 188 | } |
| 189 | |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 190 | CXCursor C = { K, { Parent, S, TU } }; |
Douglas Gregor | 97b9872 | 2010-01-19 23:20:36 +0000 | [diff] [blame] | 191 | return C; |
| 192 | } |
| 193 | |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 194 | CXCursor cxcursor::MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super, |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 195 | SourceLocation Loc, |
| 196 | ASTUnit *TU) { |
Daniel Dunbar | 54d67ca | 2010-01-25 00:40:30 +0000 | [diff] [blame] | 197 | assert(Super && TU && "Invalid arguments!"); |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 198 | void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 199 | CXCursor C = { CXCursor_ObjCSuperClassRef, { Super, RawLoc, TU } }; |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 200 | return C; |
| 201 | } |
| 202 | |
| 203 | std::pair<ObjCInterfaceDecl *, SourceLocation> |
| 204 | cxcursor::getCursorObjCSuperClassRef(CXCursor C) { |
| 205 | assert(C.kind == CXCursor_ObjCSuperClassRef); |
| 206 | return std::make_pair(static_cast<ObjCInterfaceDecl *>(C.data[0]), |
| 207 | SourceLocation::getFromRawEncoding( |
| 208 | reinterpret_cast<uintptr_t>(C.data[1]))); |
| 209 | } |
| 210 | |
Douglas Gregor | 78db0cd | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 211 | CXCursor cxcursor::MakeCursorObjCProtocolRef(ObjCProtocolDecl *Super, |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 212 | SourceLocation Loc, |
| 213 | ASTUnit *TU) { |
Daniel Dunbar | 54d67ca | 2010-01-25 00:40:30 +0000 | [diff] [blame] | 214 | assert(Super && TU && "Invalid arguments!"); |
Douglas Gregor | 78db0cd | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 215 | void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 216 | CXCursor C = { CXCursor_ObjCProtocolRef, { Super, RawLoc, TU } }; |
Douglas Gregor | 78db0cd | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 217 | return C; |
| 218 | } |
| 219 | |
| 220 | std::pair<ObjCProtocolDecl *, SourceLocation> |
| 221 | cxcursor::getCursorObjCProtocolRef(CXCursor C) { |
| 222 | assert(C.kind == CXCursor_ObjCProtocolRef); |
| 223 | return std::make_pair(static_cast<ObjCProtocolDecl *>(C.data[0]), |
| 224 | SourceLocation::getFromRawEncoding( |
| 225 | reinterpret_cast<uintptr_t>(C.data[1]))); |
| 226 | } |
| 227 | |
Douglas Gregor | 1adb082 | 2010-01-16 17:14:40 +0000 | [diff] [blame] | 228 | CXCursor cxcursor::MakeCursorObjCClassRef(ObjCInterfaceDecl *Class, |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 229 | SourceLocation Loc, |
| 230 | ASTUnit *TU) { |
Ted Kremenek | ebfa339 | 2010-03-19 20:39:03 +0000 | [diff] [blame] | 231 | // 'Class' can be null for invalid code. |
| 232 | if (!Class) |
| 233 | return MakeCXCursorInvalid(CXCursor_InvalidCode); |
| 234 | assert(TU && "Invalid arguments!"); |
Douglas Gregor | 1adb082 | 2010-01-16 17:14:40 +0000 | [diff] [blame] | 235 | void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 236 | CXCursor C = { CXCursor_ObjCClassRef, { Class, RawLoc, TU } }; |
Douglas Gregor | 1adb082 | 2010-01-16 17:14:40 +0000 | [diff] [blame] | 237 | return C; |
| 238 | } |
| 239 | |
| 240 | std::pair<ObjCInterfaceDecl *, SourceLocation> |
| 241 | cxcursor::getCursorObjCClassRef(CXCursor C) { |
| 242 | assert(C.kind == CXCursor_ObjCClassRef); |
| 243 | return std::make_pair(static_cast<ObjCInterfaceDecl *>(C.data[0]), |
| 244 | SourceLocation::getFromRawEncoding( |
| 245 | reinterpret_cast<uintptr_t>(C.data[1]))); |
| 246 | } |
| 247 | |
Douglas Gregor | 7d0d40e | 2010-01-21 16:28:34 +0000 | [diff] [blame] | 248 | CXCursor cxcursor::MakeCursorTypeRef(TypeDecl *Type, SourceLocation Loc, |
| 249 | ASTUnit *TU) { |
Daniel Dunbar | 54d67ca | 2010-01-25 00:40:30 +0000 | [diff] [blame] | 250 | assert(Type && TU && "Invalid arguments!"); |
Douglas Gregor | 7d0d40e | 2010-01-21 16:28:34 +0000 | [diff] [blame] | 251 | void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); |
| 252 | CXCursor C = { CXCursor_TypeRef, { Type, RawLoc, TU } }; |
| 253 | return C; |
| 254 | } |
| 255 | |
| 256 | std::pair<TypeDecl *, SourceLocation> |
| 257 | cxcursor::getCursorTypeRef(CXCursor C) { |
| 258 | assert(C.kind == CXCursor_TypeRef); |
| 259 | return std::make_pair(static_cast<TypeDecl *>(C.data[0]), |
| 260 | SourceLocation::getFromRawEncoding( |
| 261 | reinterpret_cast<uintptr_t>(C.data[1]))); |
| 262 | } |
| 263 | |
Douglas Gregor | 0b36e61 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 264 | CXCursor cxcursor::MakeCursorTemplateRef(TemplateDecl *Template, |
| 265 | SourceLocation Loc, ASTUnit *TU) { |
| 266 | assert(Template && TU && "Invalid arguments!"); |
| 267 | void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); |
| 268 | CXCursor C = { CXCursor_TemplateRef, { Template, RawLoc, TU } }; |
| 269 | return C; |
| 270 | } |
| 271 | |
| 272 | std::pair<TemplateDecl *, SourceLocation> |
| 273 | cxcursor::getCursorTemplateRef(CXCursor C) { |
| 274 | assert(C.kind == CXCursor_TemplateRef); |
| 275 | return std::make_pair(static_cast<TemplateDecl *>(C.data[0]), |
| 276 | SourceLocation::getFromRawEncoding( |
| 277 | reinterpret_cast<uintptr_t>(C.data[1]))); |
| 278 | } |
| 279 | |
Douglas Gregor | 6931900 | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 280 | CXCursor cxcursor::MakeCursorNamespaceRef(NamedDecl *NS, SourceLocation Loc, |
| 281 | ASTUnit *TU) { |
| 282 | |
| 283 | assert(NS && (isa<NamespaceDecl>(NS) || isa<NamespaceAliasDecl>(NS)) && TU && |
| 284 | "Invalid arguments!"); |
| 285 | void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); |
| 286 | CXCursor C = { CXCursor_NamespaceRef, { NS, RawLoc, TU } }; |
| 287 | return C; |
| 288 | } |
| 289 | |
| 290 | std::pair<NamedDecl *, SourceLocation> |
| 291 | cxcursor::getCursorNamespaceRef(CXCursor C) { |
| 292 | assert(C.kind == CXCursor_NamespaceRef); |
| 293 | return std::make_pair(static_cast<NamedDecl *>(C.data[0]), |
| 294 | SourceLocation::getFromRawEncoding( |
| 295 | reinterpret_cast<uintptr_t>(C.data[1]))); |
| 296 | } |
| 297 | |
Douglas Gregor | a67e03f | 2010-09-09 21:42:20 +0000 | [diff] [blame] | 298 | CXCursor cxcursor::MakeCursorMemberRef(FieldDecl *Field, SourceLocation Loc, |
| 299 | ASTUnit *TU) { |
| 300 | |
| 301 | assert(Field && TU && "Invalid arguments!"); |
| 302 | void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); |
| 303 | CXCursor C = { CXCursor_MemberRef, { Field, RawLoc, TU } }; |
| 304 | return C; |
| 305 | } |
| 306 | |
| 307 | std::pair<FieldDecl *, SourceLocation> |
| 308 | cxcursor::getCursorMemberRef(CXCursor C) { |
| 309 | assert(C.kind == CXCursor_MemberRef); |
| 310 | return std::make_pair(static_cast<FieldDecl *>(C.data[0]), |
| 311 | SourceLocation::getFromRawEncoding( |
| 312 | reinterpret_cast<uintptr_t>(C.data[1]))); |
| 313 | } |
| 314 | |
Ted Kremenek | 3064ef9 | 2010-08-27 21:34:58 +0000 | [diff] [blame] | 315 | CXCursor cxcursor::MakeCursorCXXBaseSpecifier(CXXBaseSpecifier *B, ASTUnit *TU){ |
| 316 | CXCursor C = { CXCursor_CXXBaseSpecifier, { B, 0, TU } }; |
| 317 | return C; |
| 318 | } |
| 319 | |
| 320 | CXXBaseSpecifier *cxcursor::getCursorCXXBaseSpecifier(CXCursor C) { |
| 321 | assert(C.kind == CXCursor_CXXBaseSpecifier); |
| 322 | return static_cast<CXXBaseSpecifier*>(C.data[0]); |
| 323 | } |
| 324 | |
Douglas Gregor | 9f1e3ff | 2010-03-18 00:42:48 +0000 | [diff] [blame] | 325 | CXCursor cxcursor::MakePreprocessingDirectiveCursor(SourceRange Range, |
| 326 | ASTUnit *TU) { |
| 327 | CXCursor C = { CXCursor_PreprocessingDirective, |
| 328 | { reinterpret_cast<void *>(Range.getBegin().getRawEncoding()), |
| 329 | reinterpret_cast<void *>(Range.getEnd().getRawEncoding()), |
| 330 | TU } |
| 331 | }; |
| 332 | return C; |
| 333 | } |
| 334 | |
| 335 | SourceRange cxcursor::getCursorPreprocessingDirective(CXCursor C) { |
| 336 | assert(C.kind == CXCursor_PreprocessingDirective); |
| 337 | return SourceRange(SourceLocation::getFromRawEncoding( |
| 338 | reinterpret_cast<uintptr_t> (C.data[0])), |
| 339 | SourceLocation::getFromRawEncoding( |
| 340 | reinterpret_cast<uintptr_t> (C.data[1]))); |
| 341 | } |
| 342 | |
Douglas Gregor | 572feb2 | 2010-03-18 18:04:21 +0000 | [diff] [blame] | 343 | CXCursor cxcursor::MakeMacroDefinitionCursor(MacroDefinition *MI, ASTUnit *TU) { |
| 344 | CXCursor C = { CXCursor_MacroDefinition, { MI, 0, TU } }; |
| 345 | return C; |
| 346 | } |
| 347 | |
| 348 | MacroDefinition *cxcursor::getCursorMacroDefinition(CXCursor C) { |
| 349 | assert(C.kind == CXCursor_MacroDefinition); |
| 350 | return static_cast<MacroDefinition *>(C.data[0]); |
| 351 | } |
| 352 | |
Douglas Gregor | 4ae8f29 | 2010-03-18 17:52:52 +0000 | [diff] [blame] | 353 | CXCursor cxcursor::MakeMacroInstantiationCursor(MacroInstantiation *MI, |
Douglas Gregor | 4807231 | 2010-03-18 15:23:44 +0000 | [diff] [blame] | 354 | ASTUnit *TU) { |
Douglas Gregor | 4ae8f29 | 2010-03-18 17:52:52 +0000 | [diff] [blame] | 355 | CXCursor C = { CXCursor_MacroInstantiation, { MI, 0, TU } }; |
Douglas Gregor | 4807231 | 2010-03-18 15:23:44 +0000 | [diff] [blame] | 356 | return C; |
| 357 | } |
| 358 | |
Douglas Gregor | 4ae8f29 | 2010-03-18 17:52:52 +0000 | [diff] [blame] | 359 | MacroInstantiation *cxcursor::getCursorMacroInstantiation(CXCursor C) { |
Douglas Gregor | 4807231 | 2010-03-18 15:23:44 +0000 | [diff] [blame] | 360 | assert(C.kind == CXCursor_MacroInstantiation); |
Douglas Gregor | 4ae8f29 | 2010-03-18 17:52:52 +0000 | [diff] [blame] | 361 | return static_cast<MacroInstantiation *>(C.data[0]); |
Douglas Gregor | 4807231 | 2010-03-18 15:23:44 +0000 | [diff] [blame] | 362 | } |
| 363 | |
Douglas Gregor | 36897b0 | 2010-09-10 00:22:18 +0000 | [diff] [blame^] | 364 | CXCursor cxcursor::MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc, |
| 365 | ASTUnit *TU) { |
| 366 | |
| 367 | assert(Label && TU && "Invalid arguments!"); |
| 368 | void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding()); |
| 369 | CXCursor C = { CXCursor_LabelRef, { Label, RawLoc, TU } }; |
| 370 | return C; |
| 371 | } |
| 372 | |
| 373 | std::pair<LabelStmt*, SourceLocation> |
| 374 | cxcursor::getCursorLabelRef(CXCursor C) { |
| 375 | assert(C.kind == CXCursor_LabelRef); |
| 376 | return std::make_pair(static_cast<LabelStmt *>(C.data[0]), |
| 377 | SourceLocation::getFromRawEncoding( |
| 378 | reinterpret_cast<uintptr_t>(C.data[1]))); |
| 379 | } |
| 380 | |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 381 | Decl *cxcursor::getCursorDecl(CXCursor Cursor) { |
| 382 | return (Decl *)Cursor.data[0]; |
| 383 | } |
| 384 | |
| 385 | Expr *cxcursor::getCursorExpr(CXCursor Cursor) { |
| 386 | return dyn_cast_or_null<Expr>(getCursorStmt(Cursor)); |
| 387 | } |
| 388 | |
| 389 | Stmt *cxcursor::getCursorStmt(CXCursor Cursor) { |
Douglas Gregor | 78db0cd | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 390 | if (Cursor.kind == CXCursor_ObjCSuperClassRef || |
Douglas Gregor | 1adb082 | 2010-01-16 17:14:40 +0000 | [diff] [blame] | 391 | Cursor.kind == CXCursor_ObjCProtocolRef || |
| 392 | Cursor.kind == CXCursor_ObjCClassRef) |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 393 | return 0; |
| 394 | |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 395 | return (Stmt *)Cursor.data[1]; |
| 396 | } |
| 397 | |
Ted Kremenek | 95f3355 | 2010-08-26 01:42:22 +0000 | [diff] [blame] | 398 | Attr *cxcursor::getCursorAttr(CXCursor Cursor) { |
| 399 | return (Attr *)Cursor.data[1]; |
| 400 | } |
| 401 | |
Douglas Gregor | f46034a | 2010-01-18 23:41:10 +0000 | [diff] [blame] | 402 | ASTContext &cxcursor::getCursorContext(CXCursor Cursor) { |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 403 | return getCursorASTUnit(Cursor)->getASTContext(); |
| 404 | } |
Douglas Gregor | f46034a | 2010-01-18 23:41:10 +0000 | [diff] [blame] | 405 | |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 406 | ASTUnit *cxcursor::getCursorASTUnit(CXCursor Cursor) { |
| 407 | return static_cast<ASTUnit *>(Cursor.data[2]); |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 408 | } |
| 409 | |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 410 | bool cxcursor::operator==(CXCursor X, CXCursor Y) { |
| 411 | return X.kind == Y.kind && X.data[0] == Y.data[0] && X.data[1] == Y.data[1] && |
| 412 | X.data[2] == Y.data[2]; |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 413 | } |