CXCursor.h revision f51f20fa34654da75d15a9e2a1a0cd2fc0d8603d
1//===- 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
15#define LLVM_CLANG_CXCURSOR_H
16
17#include "clang-c/Index.h"
18#include "clang/Basic/SourceLocation.h"
19#include <utility>
20
21namespace clang {
22
23class ASTContext;
24class ASTUnit;
25class Attr;
26class Decl;
27class Expr;
28class MacroDefinition;
29class MacroInstantiation;
30class NamedDecl;
31class ObjCInterfaceDecl;
32class ObjCProtocolDecl;
33class Stmt;
34class TypeDecl;
35
36namespace cxcursor {
37
38CXCursor MakeCXCursor(const clang::Attr *A, clang::Decl *Parent, ASTUnit *TU);
39CXCursor MakeCXCursor(clang::Decl *D, ASTUnit *TU);
40CXCursor MakeCXCursor(clang::Stmt *S, clang::Decl *Parent, ASTUnit *TU);
41CXCursor MakeCXCursorInvalid(CXCursorKind K);
42
43/// \brief Create an Objective-C superclass reference at the given location.
44CXCursor MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super,
45                                     SourceLocation Loc,
46                                     ASTUnit *TU);
47
48/// \brief Unpack an ObjCSuperClassRef cursor into the interface it references
49/// and optionally the location where the reference occurred.
50std::pair<ObjCInterfaceDecl *, SourceLocation>
51  getCursorObjCSuperClassRef(CXCursor C);
52
53/// \brief Create an Objective-C protocol reference at the given location.
54CXCursor MakeCursorObjCProtocolRef(ObjCProtocolDecl *Proto, SourceLocation Loc,
55                                   ASTUnit *TU);
56
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);
61
62/// \brief Create an Objective-C class reference at the given location.
63CXCursor MakeCursorObjCClassRef(ObjCInterfaceDecl *Class, SourceLocation Loc,
64                                ASTUnit *TU);
65
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
71/// \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
78/// \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);
83
84/// \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
91/// \brief Create a macro instantiation cursor.
92CXCursor MakeMacroInstantiationCursor(MacroInstantiation *, ASTUnit *TU);
93
94/// \brief Unpack a given macro instantiation cursor to retrieve its
95/// source range.
96MacroInstantiation *getCursorMacroInstantiation(CXCursor C);
97
98Decl *getCursorDecl(CXCursor Cursor);
99Expr *getCursorExpr(CXCursor Cursor);
100Stmt *getCursorStmt(CXCursor Cursor);
101ASTContext &getCursorContext(CXCursor Cursor);
102ASTUnit *getCursorASTUnit(CXCursor Cursor);
103
104bool operator==(CXCursor X, CXCursor Y);
105
106inline bool operator!=(CXCursor X, CXCursor Y) {
107  return !(X == Y);
108}
109
110}} // end namespace: clang::cxcursor
111
112#endif
113