blob: aa5d4f3a39832855ecd7363fb8b231c0c96ac2a9 [file] [log] [blame]
Ted Kremenek87553c42010-01-15 20:35:54 +00001//===- CXCursor.h - 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#ifndef LLVM_CLANG_CXCURSOR_H
Ted Kremenek6dc73bc2010-01-25 21:09:34 +000015#define LLVM_CLANG_CXCURSOR_H
Ted Kremenek87553c42010-01-15 20:35:54 +000016
17#include "clang-c/Index.h"
Douglas Gregor6c8959b2010-01-16 14:00:32 +000018#include "clang/Basic/SourceLocation.h"
19#include <utility>
Ted Kremenek87553c42010-01-15 20:35:54 +000020
21namespace clang {
22
Douglas Gregor7ecd0202010-01-18 23:41:10 +000023class ASTContext;
Douglas Gregorfed36b12010-01-20 23:57:43 +000024class ASTUnit;
Ted Kremenekbff31432010-02-18 03:09:07 +000025class Attr;
Ted Kremenek87553c42010-01-15 20:35:54 +000026class Decl;
Douglas Gregorc58d05b2010-01-15 21:56:13 +000027class Expr;
28class NamedDecl;
Douglas Gregor6c8959b2010-01-16 14:00:32 +000029class ObjCInterfaceDecl;
Douglas Gregoref6eb842010-01-16 15:44:18 +000030class ObjCProtocolDecl;
Ted Kremenek87553c42010-01-15 20:35:54 +000031class Stmt;
Douglas Gregor93f89952010-01-21 16:28:34 +000032class TypeDecl;
Ted Kremenek87553c42010-01-15 20:35:54 +000033
34namespace cxcursor {
35
Ted Kremenekbff31432010-02-18 03:09:07 +000036CXCursor MakeCXCursor(const clang::Attr *A, clang::Decl *Parent, ASTUnit *TU);
Douglas Gregorfed36b12010-01-20 23:57:43 +000037CXCursor MakeCXCursor(clang::Decl *D, ASTUnit *TU);
Ted Kremenekbff31432010-02-18 03:09:07 +000038CXCursor MakeCXCursor(clang::Stmt *S, clang::Decl *Parent, ASTUnit *TU);
39CXCursor MakeCXCursorInvalid(CXCursorKind K);
Ted Kremenek87553c42010-01-15 20:35:54 +000040
Douglas Gregor6c8959b2010-01-16 14:00:32 +000041/// \brief Create an Objective-C superclass reference at the given location.
42CXCursor MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super,
Douglas Gregorfed36b12010-01-20 23:57:43 +000043 SourceLocation Loc,
44 ASTUnit *TU);
Douglas Gregor6c8959b2010-01-16 14:00:32 +000045
46/// \brief Unpack an ObjCSuperClassRef cursor into the interface it references
47/// and optionally the location where the reference occurred.
48std::pair<ObjCInterfaceDecl *, SourceLocation>
Douglas Gregoref6eb842010-01-16 15:44:18 +000049 getCursorObjCSuperClassRef(CXCursor C);
50
51/// \brief Create an Objective-C protocol reference at the given location.
Douglas Gregorfed36b12010-01-20 23:57:43 +000052CXCursor MakeCursorObjCProtocolRef(ObjCProtocolDecl *Proto, SourceLocation Loc,
53 ASTUnit *TU);
Douglas Gregoref6eb842010-01-16 15:44:18 +000054
55/// \brief Unpack an ObjCProtocolRef cursor into the protocol it references
56/// and optionally the location where the reference occurred.
57std::pair<ObjCProtocolDecl *, SourceLocation>
58 getCursorObjCProtocolRef(CXCursor C);
Douglas Gregor6c8959b2010-01-16 14:00:32 +000059
Douglas Gregor46d66142010-01-16 17:14:40 +000060/// \brief Create an Objective-C class reference at the given location.
Douglas Gregorfed36b12010-01-20 23:57:43 +000061CXCursor MakeCursorObjCClassRef(ObjCInterfaceDecl *Class, SourceLocation Loc,
62 ASTUnit *TU);
Douglas Gregor46d66142010-01-16 17:14:40 +000063
64/// \brief Unpack an ObjCClassRef cursor into the class it references
65/// and optionally the location where the reference occurred.
66std::pair<ObjCInterfaceDecl *, SourceLocation>
67 getCursorObjCClassRef(CXCursor C);
68
Douglas Gregor93f89952010-01-21 16:28:34 +000069/// \brief Create a type reference at the given location.
70CXCursor MakeCursorTypeRef(TypeDecl *Type, SourceLocation Loc, ASTUnit *TU);
71
72/// \brief Unpack a TypeRef cursor into the class it references
73/// and optionally the location where the reference occurred.
74std::pair<TypeDecl *, SourceLocation> getCursorTypeRef(CXCursor C);
75
Douglas Gregor92a524f2010-03-18 00:42:48 +000076/// \brief Create a preprocessing directive cursor.
77CXCursor MakePreprocessingDirectiveCursor(SourceRange Range, ASTUnit *TU);
78
79/// \brief Unpack a given preprocessing directive to retrieve its source range.
80SourceRange getCursorPreprocessingDirective(CXCursor C);
81
Douglas Gregorc58d05b2010-01-15 21:56:13 +000082Decl *getCursorDecl(CXCursor Cursor);
83Expr *getCursorExpr(CXCursor Cursor);
84Stmt *getCursorStmt(CXCursor Cursor);
Douglas Gregor7ecd0202010-01-18 23:41:10 +000085ASTContext &getCursorContext(CXCursor Cursor);
Douglas Gregorfed36b12010-01-20 23:57:43 +000086ASTUnit *getCursorASTUnit(CXCursor Cursor);
Douglas Gregorc58d05b2010-01-15 21:56:13 +000087
88bool operator==(CXCursor X, CXCursor Y);
89
90inline bool operator!=(CXCursor X, CXCursor Y) {
91 return !(X == Y);
92}
93
Ted Kremenek87553c42010-01-15 20:35:54 +000094}} // end namespace: clang::cxcursor
95
96#endif