blob: d506400407f070d0db38d08f679edffdbddd0e24 [file] [log] [blame]
Ted Kremenek16c440a2010-01-15 20:35:54 +00001//===- CXCursor.cpp - Routines for manipulating CXCursors -----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Douglas Gregor2e331b92010-01-16 14:00:32 +000010// This file defines routines for manipulating CXCursors. It should be the
11// only file that has internal knowledge of the encoding of the data in
12// CXCursor.
Ted Kremenek16c440a2010-01-15 20:35:54 +000013//
14//===----------------------------------------------------------------------===//
15
16#include "CXCursor.h"
Douglas Gregor7eaa8ae2010-01-20 00:23:15 +000017#include "clang/Frontend/ASTUnit.h"
Ted Kremenek16c440a2010-01-15 20:35:54 +000018#include "clang/AST/Decl.h"
Douglas Gregor69319002010-08-31 23:48:11 +000019#include "clang/AST/DeclCXX.h"
Douglas Gregor283cae32010-01-15 21:56:13 +000020#include "clang/AST/DeclObjC.h"
21#include "clang/AST/Expr.h"
Douglas Gregor1f60d9e2010-09-13 22:52:57 +000022#include "clang/AST/ExprCXX.h"
Ted Kremenekedc8aa62010-01-16 00:36:30 +000023#include "llvm/Support/ErrorHandling.h"
Ted Kremenek16c440a2010-01-15 20:35:54 +000024
25using namespace clang;
Douglas Gregor1f60d9e2010-09-13 22:52:57 +000026using namespace cxcursor;
Ted Kremenek16c440a2010-01-15 20:35:54 +000027
Douglas Gregor5bfb8c12010-01-20 23:34:41 +000028CXCursor cxcursor::MakeCXCursorInvalid(CXCursorKind K) {
29 assert(K >= CXCursor_FirstInvalid && K <= CXCursor_LastInvalid);
30 CXCursor C = { K, { 0, 0, 0 } };
31 return C;
Ted Kremenek16c440a2010-01-15 20:35:54 +000032}
33
Ted Kremeneke77f4432010-02-18 03:09:07 +000034static CXCursorKind GetCursorKind(const Attr *A) {
35 assert(A && "Invalid arguments!");
36 switch (A->getKind()) {
37 default: break;
Sean Hunt387475d2010-06-16 23:43:53 +000038 case attr::IBAction: return CXCursor_IBActionAttr;
39 case attr::IBOutlet: return CXCursor_IBOutletAttr;
40 case attr::IBOutletCollection: return CXCursor_IBOutletCollectionAttr;
Ted Kremeneke77f4432010-02-18 03:09:07 +000041 }
42
43 return CXCursor_UnexposedAttr;
44}
45
46CXCursor 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 Gregorb2cd4872010-01-20 23:57:43 +000052CXCursor cxcursor::MakeCXCursor(Decl *D, ASTUnit *TU) {
Daniel Dunbar54d67ca2010-01-25 00:40:30 +000053 assert(D && TU && "Invalid arguments!");
Douglas Gregore8d7beb2010-09-03 23:30:36 +000054 CXCursor C = { getCursorKindForDecl(D), { D, 0, TU } };
Douglas Gregor5bfb8c12010-01-20 23:34:41 +000055 return C;
Ted Kremenekedc8aa62010-01-16 00:36:30 +000056}
57
Douglas Gregorb2cd4872010-01-20 23:57:43 +000058CXCursor cxcursor::MakeCXCursor(Stmt *S, Decl *Parent, ASTUnit *TU) {
Daniel Dunbar54d67ca2010-01-25 00:40:30 +000059 assert(S && TU && "Invalid arguments!");
Douglas Gregor97b98722010-01-19 23:20:36 +000060 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 Gregor97b98722010-01-19 23:20:36 +000070 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 Gregor36897b02010-09-10 00:22:18 +000094 case Stmt::LabelStmtClass:
95 K = CXCursor_LabelStmt;
96 break;
97
Douglas Gregor97b98722010-01-19 23:20:36 +000098 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 Gregor8ecdb652010-04-28 22:16:22 +0000105 case Stmt::UnaryOperatorClass:
106 case Stmt::OffsetOfExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000107 case Stmt::SizeOfAlignOfExprClass:
108 case Stmt::ArraySubscriptExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000109 case Stmt::BinaryOperatorClass:
110 case Stmt::CompoundAssignOperatorClass:
111 case Stmt::ConditionalOperatorClass:
112 case Stmt::ImplicitCastExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000113 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 Gregor97b98722010-01-19 23:20:36 +0000126 case Stmt::CXXStaticCastExprClass:
127 case Stmt::CXXDynamicCastExprClass:
128 case Stmt::CXXReinterpretCastExprClass:
129 case Stmt::CXXConstCastExprClass:
130 case Stmt::CXXFunctionalCastExprClass:
131 case Stmt::CXXTypeidExprClass:
Francois Pichet9be88402010-09-08 23:47:05 +0000132 case Stmt::CXXUuidofExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000133 case Stmt::CXXBoolLiteralExprClass:
134 case Stmt::CXXNullPtrLiteralExprClass:
135 case Stmt::CXXThisExprClass:
136 case Stmt::CXXThrowExprClass:
137 case Stmt::CXXDefaultArgExprClass:
Douglas Gregored8abf12010-07-08 06:14:04 +0000138 case Stmt::CXXScalarValueInitExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000139 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 Redl2e156222010-09-10 20:55:43 +0000150 case Stmt::CXXNoexceptExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000151 case Stmt::ObjCStringLiteralClass:
152 case Stmt::ObjCEncodeExprClass:
153 case Stmt::ObjCSelectorExprClass:
154 case Stmt::ObjCProtocolExprClass:
155 case Stmt::ObjCImplicitSetterGetterRefExprClass:
Douglas Gregor97b98722010-01-19 23:20:36 +0000156 case Stmt::ObjCIsaExprClass:
157 case Stmt::ShuffleVectorExprClass:
158 case Stmt::BlockExprClass:
159 K = CXCursor_UnexposedExpr;
160 break;
Douglas Gregor36897b02010-09-10 00:22:18 +0000161
Douglas Gregor97b98722010-01-19 23:20:36 +0000162 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 Gregorb2cd4872010-01-20 23:57:43 +0000192 CXCursor C = { K, { Parent, S, TU } };
Douglas Gregor97b98722010-01-19 23:20:36 +0000193 return C;
194}
195
Douglas Gregor2e331b92010-01-16 14:00:32 +0000196CXCursor cxcursor::MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super,
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000197 SourceLocation Loc,
198 ASTUnit *TU) {
Daniel Dunbar54d67ca2010-01-25 00:40:30 +0000199 assert(Super && TU && "Invalid arguments!");
Douglas Gregor2e331b92010-01-16 14:00:32 +0000200 void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000201 CXCursor C = { CXCursor_ObjCSuperClassRef, { Super, RawLoc, TU } };
Douglas Gregor2e331b92010-01-16 14:00:32 +0000202 return C;
203}
204
205std::pair<ObjCInterfaceDecl *, SourceLocation>
206cxcursor::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 Gregor78db0cd2010-01-16 15:44:18 +0000213CXCursor cxcursor::MakeCursorObjCProtocolRef(ObjCProtocolDecl *Super,
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000214 SourceLocation Loc,
215 ASTUnit *TU) {
Daniel Dunbar54d67ca2010-01-25 00:40:30 +0000216 assert(Super && TU && "Invalid arguments!");
Douglas Gregor78db0cd2010-01-16 15:44:18 +0000217 void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000218 CXCursor C = { CXCursor_ObjCProtocolRef, { Super, RawLoc, TU } };
Douglas Gregor78db0cd2010-01-16 15:44:18 +0000219 return C;
220}
221
222std::pair<ObjCProtocolDecl *, SourceLocation>
223cxcursor::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 Gregor1adb0822010-01-16 17:14:40 +0000230CXCursor cxcursor::MakeCursorObjCClassRef(ObjCInterfaceDecl *Class,
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000231 SourceLocation Loc,
232 ASTUnit *TU) {
Ted Kremenekebfa3392010-03-19 20:39:03 +0000233 // 'Class' can be null for invalid code.
234 if (!Class)
235 return MakeCXCursorInvalid(CXCursor_InvalidCode);
236 assert(TU && "Invalid arguments!");
Douglas Gregor1adb0822010-01-16 17:14:40 +0000237 void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000238 CXCursor C = { CXCursor_ObjCClassRef, { Class, RawLoc, TU } };
Douglas Gregor1adb0822010-01-16 17:14:40 +0000239 return C;
240}
241
242std::pair<ObjCInterfaceDecl *, SourceLocation>
243cxcursor::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 Gregor7d0d40e2010-01-21 16:28:34 +0000250CXCursor cxcursor::MakeCursorTypeRef(TypeDecl *Type, SourceLocation Loc,
251 ASTUnit *TU) {
Daniel Dunbar54d67ca2010-01-25 00:40:30 +0000252 assert(Type && TU && "Invalid arguments!");
Douglas Gregor7d0d40e2010-01-21 16:28:34 +0000253 void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
254 CXCursor C = { CXCursor_TypeRef, { Type, RawLoc, TU } };
255 return C;
256}
257
258std::pair<TypeDecl *, SourceLocation>
259cxcursor::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 Gregor0b36e612010-08-31 20:37:03 +0000266CXCursor 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
274std::pair<TemplateDecl *, SourceLocation>
275cxcursor::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 Gregor69319002010-08-31 23:48:11 +0000282CXCursor 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
292std::pair<NamedDecl *, SourceLocation>
293cxcursor::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 Gregora67e03f2010-09-09 21:42:20 +0000300CXCursor 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
309std::pair<FieldDecl *, SourceLocation>
310cxcursor::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 Kremenek3064ef92010-08-27 21:34:58 +0000317CXCursor cxcursor::MakeCursorCXXBaseSpecifier(CXXBaseSpecifier *B, ASTUnit *TU){
318 CXCursor C = { CXCursor_CXXBaseSpecifier, { B, 0, TU } };
319 return C;
320}
321
322CXXBaseSpecifier *cxcursor::getCursorCXXBaseSpecifier(CXCursor C) {
323 assert(C.kind == CXCursor_CXXBaseSpecifier);
324 return static_cast<CXXBaseSpecifier*>(C.data[0]);
325}
326
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +0000327CXCursor 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
337SourceRange 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 Gregor572feb22010-03-18 18:04:21 +0000345CXCursor cxcursor::MakeMacroDefinitionCursor(MacroDefinition *MI, ASTUnit *TU) {
346 CXCursor C = { CXCursor_MacroDefinition, { MI, 0, TU } };
347 return C;
348}
349
350MacroDefinition *cxcursor::getCursorMacroDefinition(CXCursor C) {
351 assert(C.kind == CXCursor_MacroDefinition);
352 return static_cast<MacroDefinition *>(C.data[0]);
353}
354
Douglas Gregor4ae8f292010-03-18 17:52:52 +0000355CXCursor cxcursor::MakeMacroInstantiationCursor(MacroInstantiation *MI,
Douglas Gregor48072312010-03-18 15:23:44 +0000356 ASTUnit *TU) {
Douglas Gregor4ae8f292010-03-18 17:52:52 +0000357 CXCursor C = { CXCursor_MacroInstantiation, { MI, 0, TU } };
Douglas Gregor48072312010-03-18 15:23:44 +0000358 return C;
359}
360
Douglas Gregor4ae8f292010-03-18 17:52:52 +0000361MacroInstantiation *cxcursor::getCursorMacroInstantiation(CXCursor C) {
Douglas Gregor48072312010-03-18 15:23:44 +0000362 assert(C.kind == CXCursor_MacroInstantiation);
Douglas Gregor4ae8f292010-03-18 17:52:52 +0000363 return static_cast<MacroInstantiation *>(C.data[0]);
Douglas Gregor48072312010-03-18 15:23:44 +0000364}
365
Douglas Gregorecdcb882010-10-20 22:00:55 +0000366CXCursor cxcursor::MakeInclusionDirectiveCursor(InclusionDirective *ID,
367 ASTUnit *TU) {
368 CXCursor C = { CXCursor_InclusionDirective, { ID, 0, TU } };
369 return C;
370}
371
372InclusionDirective *cxcursor::getCursorInclusionDirective(CXCursor C) {
373 assert(C.kind == CXCursor_InclusionDirective);
374 return static_cast<InclusionDirective *>(C.data[0]);
375}
376
Douglas Gregor36897b02010-09-10 00:22:18 +0000377CXCursor 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
386std::pair<LabelStmt*, SourceLocation>
387cxcursor::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 Gregor1f60d9e2010-09-13 22:52:57 +0000394CXCursor 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
406CXCursor 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
419CXCursor 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
432std::pair<cxcursor::OverloadedDeclRefStorage, SourceLocation>
433cxcursor::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 Gregor283cae32010-01-15 21:56:13 +0000440Decl *cxcursor::getCursorDecl(CXCursor Cursor) {
441 return (Decl *)Cursor.data[0];
442}
443
444Expr *cxcursor::getCursorExpr(CXCursor Cursor) {
445 return dyn_cast_or_null<Expr>(getCursorStmt(Cursor));
446}
447
448Stmt *cxcursor::getCursorStmt(CXCursor Cursor) {
Douglas Gregor78db0cd2010-01-16 15:44:18 +0000449 if (Cursor.kind == CXCursor_ObjCSuperClassRef ||
Douglas Gregor1adb0822010-01-16 17:14:40 +0000450 Cursor.kind == CXCursor_ObjCProtocolRef ||
451 Cursor.kind == CXCursor_ObjCClassRef)
Douglas Gregor2e331b92010-01-16 14:00:32 +0000452 return 0;
453
Douglas Gregor283cae32010-01-15 21:56:13 +0000454 return (Stmt *)Cursor.data[1];
455}
456
Ted Kremenek95f33552010-08-26 01:42:22 +0000457Attr *cxcursor::getCursorAttr(CXCursor Cursor) {
458 return (Attr *)Cursor.data[1];
459}
460
Douglas Gregorf46034a2010-01-18 23:41:10 +0000461ASTContext &cxcursor::getCursorContext(CXCursor Cursor) {
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000462 return getCursorASTUnit(Cursor)->getASTContext();
463}
Douglas Gregorf46034a2010-01-18 23:41:10 +0000464
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000465ASTUnit *cxcursor::getCursorASTUnit(CXCursor Cursor) {
466 return static_cast<ASTUnit *>(Cursor.data[2]);
Douglas Gregor283cae32010-01-15 21:56:13 +0000467}
468
Douglas Gregor283cae32010-01-15 21:56:13 +0000469bool 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 Gregor2e331b92010-01-16 14:00:32 +0000472}