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