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 | // |
| 10 | // This file defines routines for manipulating CXCursors. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "CXCursor.h" |
| 15 | #include "clang/AST/Decl.h" |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame^] | 16 | #include "clang/AST/DeclObjC.h" |
| 17 | #include "clang/AST/Expr.h" |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 18 | |
| 19 | using namespace clang; |
| 20 | |
| 21 | CXCursor cxcursor::MakeCXCursor(CXCursorKind K, Decl *D) { |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame^] | 22 | CXCursor C = { K, { D, 0, 0 } }; |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 23 | return C; |
| 24 | } |
| 25 | |
| 26 | CXCursor cxcursor::MakeCXCursor(CXCursorKind K, Decl *D, Stmt *S) { |
| 27 | assert(clang_isReference(K)); |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame^] | 28 | CXCursor C = { K, { D, S, 0 } }; |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 29 | return C; |
| 30 | } |
| 31 | |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame^] | 32 | Decl *cxcursor::getCursorDecl(CXCursor Cursor) { |
| 33 | return (Decl *)Cursor.data[0]; |
| 34 | } |
| 35 | |
| 36 | Expr *cxcursor::getCursorExpr(CXCursor Cursor) { |
| 37 | return dyn_cast_or_null<Expr>(getCursorStmt(Cursor)); |
| 38 | } |
| 39 | |
| 40 | Stmt *cxcursor::getCursorStmt(CXCursor Cursor) { |
| 41 | return (Stmt *)Cursor.data[1]; |
| 42 | } |
| 43 | |
| 44 | Decl *cxcursor::getCursorReferringDecl(CXCursor Cursor) { |
| 45 | return (Decl *)Cursor.data[2]; |
| 46 | } |
| 47 | |
| 48 | NamedDecl *cxcursor::getCursorInterfaceParent(CXCursor Cursor) { |
| 49 | assert(Cursor.kind == CXCursor_ObjCClassRef); |
| 50 | assert(isa<ObjCInterfaceDecl>(getCursorDecl(Cursor))); |
| 51 | // FIXME: This is a hack (storing the parent decl in the stmt slot). |
| 52 | return static_cast<NamedDecl *>(Cursor.data[1]); |
| 53 | } |
| 54 | |
| 55 | bool cxcursor::operator==(CXCursor X, CXCursor Y) { |
| 56 | return X.kind == Y.kind && X.data[0] == Y.data[0] && X.data[1] == Y.data[1] && |
| 57 | X.data[2] == Y.data[2]; |
| 58 | } |