blob: 958e331674abce0c2d67fa3dc0127cc98de21204 [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 Kremenekae9e2212010-08-27 21:34:58 +000026class CXXBaseSpecifier;
Ted Kremenek87553c42010-01-15 20:35:54 +000027class Decl;
Douglas Gregorc58d05b2010-01-15 21:56:13 +000028class Expr;
Douglas Gregor06d6d322010-03-18 18:04:21 +000029class MacroDefinition;
Douglas Gregor065f8d12010-03-18 17:52:52 +000030class MacroInstantiation;
Douglas Gregorc58d05b2010-01-15 21:56:13 +000031class NamedDecl;
Douglas Gregor6c8959b2010-01-16 14:00:32 +000032class ObjCInterfaceDecl;
Douglas Gregoref6eb842010-01-16 15:44:18 +000033class ObjCProtocolDecl;
Ted Kremenek87553c42010-01-15 20:35:54 +000034class Stmt;
Douglas Gregor93f89952010-01-21 16:28:34 +000035class TypeDecl;
Ted Kremenek87553c42010-01-15 20:35:54 +000036
37namespace cxcursor {
38
Ted Kremenekbff31432010-02-18 03:09:07 +000039CXCursor MakeCXCursor(const clang::Attr *A, clang::Decl *Parent, ASTUnit *TU);
Douglas Gregorfed36b12010-01-20 23:57:43 +000040CXCursor MakeCXCursor(clang::Decl *D, ASTUnit *TU);
Ted Kremenekbff31432010-02-18 03:09:07 +000041CXCursor MakeCXCursor(clang::Stmt *S, clang::Decl *Parent, ASTUnit *TU);
42CXCursor MakeCXCursorInvalid(CXCursorKind K);
Ted Kremenek87553c42010-01-15 20:35:54 +000043
Douglas Gregor6c8959b2010-01-16 14:00:32 +000044/// \brief Create an Objective-C superclass reference at the given location.
45CXCursor MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super,
Douglas Gregorfed36b12010-01-20 23:57:43 +000046 SourceLocation Loc,
47 ASTUnit *TU);
Douglas Gregor6c8959b2010-01-16 14:00:32 +000048
49/// \brief Unpack an ObjCSuperClassRef cursor into the interface it references
50/// and optionally the location where the reference occurred.
51std::pair<ObjCInterfaceDecl *, SourceLocation>
Douglas Gregoref6eb842010-01-16 15:44:18 +000052 getCursorObjCSuperClassRef(CXCursor C);
53
54/// \brief Create an Objective-C protocol reference at the given location.
Douglas Gregorfed36b12010-01-20 23:57:43 +000055CXCursor MakeCursorObjCProtocolRef(ObjCProtocolDecl *Proto, SourceLocation Loc,
56 ASTUnit *TU);
Douglas Gregoref6eb842010-01-16 15:44:18 +000057
58/// \brief Unpack an ObjCProtocolRef cursor into the protocol it references
59/// and optionally the location where the reference occurred.
60std::pair<ObjCProtocolDecl *, SourceLocation>
61 getCursorObjCProtocolRef(CXCursor C);
Douglas Gregor6c8959b2010-01-16 14:00:32 +000062
Douglas Gregor46d66142010-01-16 17:14:40 +000063/// \brief Create an Objective-C class reference at the given location.
Douglas Gregorfed36b12010-01-20 23:57:43 +000064CXCursor MakeCursorObjCClassRef(ObjCInterfaceDecl *Class, SourceLocation Loc,
65 ASTUnit *TU);
Douglas Gregor46d66142010-01-16 17:14:40 +000066
67/// \brief Unpack an ObjCClassRef cursor into the class it references
68/// and optionally the location where the reference occurred.
69std::pair<ObjCInterfaceDecl *, SourceLocation>
70 getCursorObjCClassRef(CXCursor C);
71
Douglas Gregor93f89952010-01-21 16:28:34 +000072/// \brief Create a type reference at the given location.
73CXCursor MakeCursorTypeRef(TypeDecl *Type, SourceLocation Loc, ASTUnit *TU);
74
75/// \brief Unpack a TypeRef cursor into the class it references
76/// and optionally the location where the reference occurred.
77std::pair<TypeDecl *, SourceLocation> getCursorTypeRef(CXCursor C);
78
Ted Kremenekae9e2212010-08-27 21:34:58 +000079/// \brief Create a CXX base specifier cursor.
80CXCursor MakeCursorCXXBaseSpecifier(CXXBaseSpecifier *B, ASTUnit *TU);
81
82/// \brief Unpack a CXXBaseSpecifier cursor into a CXXBaseSpecifier.
83CXXBaseSpecifier *getCursorCXXBaseSpecifier(CXCursor C);
84
Douglas Gregor92a524f2010-03-18 00:42:48 +000085/// \brief Create a preprocessing directive cursor.
86CXCursor MakePreprocessingDirectiveCursor(SourceRange Range, ASTUnit *TU);
87
88/// \brief Unpack a given preprocessing directive to retrieve its source range.
89SourceRange getCursorPreprocessingDirective(CXCursor C);
Douglas Gregor02ded2a2010-03-18 15:23:44 +000090
Douglas Gregor06d6d322010-03-18 18:04:21 +000091/// \brief Create a macro definition cursor.
92CXCursor MakeMacroDefinitionCursor(MacroDefinition *, ASTUnit *TU);
93
94/// \brief Unpack a given macro definition cursor to retrieve its
95/// source range.
96MacroDefinition *getCursorMacroDefinition(CXCursor C);
97
Douglas Gregor02ded2a2010-03-18 15:23:44 +000098/// \brief Create a macro instantiation cursor.
Douglas Gregor065f8d12010-03-18 17:52:52 +000099CXCursor MakeMacroInstantiationCursor(MacroInstantiation *, ASTUnit *TU);
Douglas Gregor02ded2a2010-03-18 15:23:44 +0000100
101/// \brief Unpack a given macro instantiation cursor to retrieve its
102/// source range.
Douglas Gregor065f8d12010-03-18 17:52:52 +0000103MacroInstantiation *getCursorMacroInstantiation(CXCursor C);
Douglas Gregor02ded2a2010-03-18 15:23:44 +0000104
Douglas Gregorc58d05b2010-01-15 21:56:13 +0000105Decl *getCursorDecl(CXCursor Cursor);
106Expr *getCursorExpr(CXCursor Cursor);
107Stmt *getCursorStmt(CXCursor Cursor);
Ted Kremeneka5940822010-08-26 01:42:22 +0000108Attr *getCursorAttr(CXCursor Cursor);
109
Douglas Gregor7ecd0202010-01-18 23:41:10 +0000110ASTContext &getCursorContext(CXCursor Cursor);
Douglas Gregorfed36b12010-01-20 23:57:43 +0000111ASTUnit *getCursorASTUnit(CXCursor Cursor);
Douglas Gregorc58d05b2010-01-15 21:56:13 +0000112
113bool operator==(CXCursor X, CXCursor Y);
114
115inline bool operator!=(CXCursor X, CXCursor Y) {
116 return !(X == Y);
117}
118
Ted Kremenek87553c42010-01-15 20:35:54 +0000119}} // end namespace: clang::cxcursor
120
121#endif