blob: 0c72e9690067768d9b799bfe2e945e388886ef14 [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//
10// This file defines routines for manipulating CXCursors.
11//
12//===----------------------------------------------------------------------===//
13
14#include "CXCursor.h"
15#include "clang/AST/Decl.h"
Douglas Gregor283cae32010-01-15 21:56:13 +000016#include "clang/AST/DeclObjC.h"
17#include "clang/AST/Expr.h"
Ted Kremenek16c440a2010-01-15 20:35:54 +000018
19using namespace clang;
20
21CXCursor cxcursor::MakeCXCursor(CXCursorKind K, Decl *D) {
Douglas Gregor283cae32010-01-15 21:56:13 +000022 CXCursor C = { K, { D, 0, 0 } };
Ted Kremenek16c440a2010-01-15 20:35:54 +000023 return C;
24}
25
26CXCursor cxcursor::MakeCXCursor(CXCursorKind K, Decl *D, Stmt *S) {
27 assert(clang_isReference(K));
Douglas Gregor283cae32010-01-15 21:56:13 +000028 CXCursor C = { K, { D, S, 0 } };
Ted Kremenek16c440a2010-01-15 20:35:54 +000029 return C;
30}
31
Douglas Gregor283cae32010-01-15 21:56:13 +000032Decl *cxcursor::getCursorDecl(CXCursor Cursor) {
33 return (Decl *)Cursor.data[0];
34}
35
36Expr *cxcursor::getCursorExpr(CXCursor Cursor) {
37 return dyn_cast_or_null<Expr>(getCursorStmt(Cursor));
38}
39
40Stmt *cxcursor::getCursorStmt(CXCursor Cursor) {
41 return (Stmt *)Cursor.data[1];
42}
43
44Decl *cxcursor::getCursorReferringDecl(CXCursor Cursor) {
45 return (Decl *)Cursor.data[2];
46}
47
48NamedDecl *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
55bool 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}