blob: 1664f5a9ced2afecdfbe4cc7ea93b9c3fdf5fb8b [file] [log] [blame]
Ted Kremenek16c440a2010-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 Kremenek2cd10b02010-01-25 21:09:34 +000015#define LLVM_CLANG_CXCURSOR_H
Ted Kremenek16c440a2010-01-15 20:35:54 +000016
17#include "clang-c/Index.h"
Douglas Gregor2e331b92010-01-16 14:00:32 +000018#include "clang/Basic/SourceLocation.h"
19#include <utility>
Ted Kremenek16c440a2010-01-15 20:35:54 +000020
21namespace clang {
22
Douglas Gregorf46034a2010-01-18 23:41:10 +000023class ASTContext;
Douglas Gregorb2cd4872010-01-20 23:57:43 +000024class ASTUnit;
Ted Kremeneke77f4432010-02-18 03:09:07 +000025class Attr;
Ted Kremenek16c440a2010-01-15 20:35:54 +000026class Decl;
Douglas Gregor283cae32010-01-15 21:56:13 +000027class Expr;
Douglas Gregor572feb22010-03-18 18:04:21 +000028class MacroDefinition;
Douglas Gregor4ae8f292010-03-18 17:52:52 +000029class MacroInstantiation;
Douglas Gregor283cae32010-01-15 21:56:13 +000030class NamedDecl;
Douglas Gregor2e331b92010-01-16 14:00:32 +000031class ObjCInterfaceDecl;
Douglas Gregor78db0cd2010-01-16 15:44:18 +000032class ObjCProtocolDecl;
Ted Kremenek16c440a2010-01-15 20:35:54 +000033class Stmt;
Douglas Gregor7d0d40e2010-01-21 16:28:34 +000034class TypeDecl;
Ted Kremenek16c440a2010-01-15 20:35:54 +000035
36namespace cxcursor {
37
Ted Kremeneke77f4432010-02-18 03:09:07 +000038CXCursor MakeCXCursor(const clang::Attr *A, clang::Decl *Parent, ASTUnit *TU);
Douglas Gregorb2cd4872010-01-20 23:57:43 +000039CXCursor MakeCXCursor(clang::Decl *D, ASTUnit *TU);
Ted Kremeneke77f4432010-02-18 03:09:07 +000040CXCursor MakeCXCursor(clang::Stmt *S, clang::Decl *Parent, ASTUnit *TU);
41CXCursor MakeCXCursorInvalid(CXCursorKind K);
Ted Kremenek16c440a2010-01-15 20:35:54 +000042
Douglas Gregor2e331b92010-01-16 14:00:32 +000043/// \brief Create an Objective-C superclass reference at the given location.
44CXCursor MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super,
Douglas Gregorb2cd4872010-01-20 23:57:43 +000045 SourceLocation Loc,
46 ASTUnit *TU);
Douglas Gregor2e331b92010-01-16 14:00:32 +000047
48/// \brief Unpack an ObjCSuperClassRef cursor into the interface it references
49/// and optionally the location where the reference occurred.
50std::pair<ObjCInterfaceDecl *, SourceLocation>
Douglas Gregor78db0cd2010-01-16 15:44:18 +000051 getCursorObjCSuperClassRef(CXCursor C);
52
53/// \brief Create an Objective-C protocol reference at the given location.
Douglas Gregorb2cd4872010-01-20 23:57:43 +000054CXCursor MakeCursorObjCProtocolRef(ObjCProtocolDecl *Proto, SourceLocation Loc,
55 ASTUnit *TU);
Douglas Gregor78db0cd2010-01-16 15:44:18 +000056
57/// \brief Unpack an ObjCProtocolRef cursor into the protocol it references
58/// and optionally the location where the reference occurred.
59std::pair<ObjCProtocolDecl *, SourceLocation>
60 getCursorObjCProtocolRef(CXCursor C);
Douglas Gregor2e331b92010-01-16 14:00:32 +000061
Douglas Gregor1adb0822010-01-16 17:14:40 +000062/// \brief Create an Objective-C class reference at the given location.
Douglas Gregorb2cd4872010-01-20 23:57:43 +000063CXCursor MakeCursorObjCClassRef(ObjCInterfaceDecl *Class, SourceLocation Loc,
64 ASTUnit *TU);
Douglas Gregor1adb0822010-01-16 17:14:40 +000065
66/// \brief Unpack an ObjCClassRef cursor into the class it references
67/// and optionally the location where the reference occurred.
68std::pair<ObjCInterfaceDecl *, SourceLocation>
69 getCursorObjCClassRef(CXCursor C);
70
Douglas Gregor7d0d40e2010-01-21 16:28:34 +000071/// \brief Create a type reference at the given location.
72CXCursor MakeCursorTypeRef(TypeDecl *Type, SourceLocation Loc, ASTUnit *TU);
73
74/// \brief Unpack a TypeRef cursor into the class it references
75/// and optionally the location where the reference occurred.
76std::pair<TypeDecl *, SourceLocation> getCursorTypeRef(CXCursor C);
77
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +000078/// \brief Create a preprocessing directive cursor.
79CXCursor MakePreprocessingDirectiveCursor(SourceRange Range, ASTUnit *TU);
80
81/// \brief Unpack a given preprocessing directive to retrieve its source range.
82SourceRange getCursorPreprocessingDirective(CXCursor C);
Douglas Gregor48072312010-03-18 15:23:44 +000083
Douglas Gregor572feb22010-03-18 18:04:21 +000084/// \brief Create a macro definition cursor.
85CXCursor MakeMacroDefinitionCursor(MacroDefinition *, ASTUnit *TU);
86
87/// \brief Unpack a given macro definition cursor to retrieve its
88/// source range.
89MacroDefinition *getCursorMacroDefinition(CXCursor C);
90
Douglas Gregor48072312010-03-18 15:23:44 +000091/// \brief Create a macro instantiation cursor.
Douglas Gregor4ae8f292010-03-18 17:52:52 +000092CXCursor MakeMacroInstantiationCursor(MacroInstantiation *, ASTUnit *TU);
Douglas Gregor48072312010-03-18 15:23:44 +000093
94/// \brief Unpack a given macro instantiation cursor to retrieve its
95/// source range.
Douglas Gregor4ae8f292010-03-18 17:52:52 +000096MacroInstantiation *getCursorMacroInstantiation(CXCursor C);
Douglas Gregor48072312010-03-18 15:23:44 +000097
Douglas Gregor283cae32010-01-15 21:56:13 +000098Decl *getCursorDecl(CXCursor Cursor);
99Expr *getCursorExpr(CXCursor Cursor);
100Stmt *getCursorStmt(CXCursor Cursor);
Douglas Gregorf46034a2010-01-18 23:41:10 +0000101ASTContext &getCursorContext(CXCursor Cursor);
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000102ASTUnit *getCursorASTUnit(CXCursor Cursor);
Douglas Gregor283cae32010-01-15 21:56:13 +0000103
104bool operator==(CXCursor X, CXCursor Y);
105
106inline bool operator!=(CXCursor X, CXCursor Y) {
107 return !(X == Y);
108}
109
Ted Kremenek16c440a2010-01-15 20:35:54 +0000110}} // end namespace: clang::cxcursor
111
112#endif