CXCursor.h revision a67e03fdf1ae8a1f92463a307d0b6281f1161f40
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 CXXBaseSpecifier;
27class Decl;
28class Expr;
29class FieldDecl;
30class MacroDefinition;
31class MacroInstantiation;
32class NamedDecl;
33class ObjCInterfaceDecl;
34class ObjCProtocolDecl;
35class Stmt;
36class TemplateDecl;
37class TypeDecl;
38
39namespace cxcursor {
40
41CXCursor MakeCXCursor(const clang::Attr *A, clang::Decl *Parent, ASTUnit *TU);
42CXCursor MakeCXCursor(clang::Decl *D, ASTUnit *TU);
43CXCursor MakeCXCursor(clang::Stmt *S, clang::Decl *Parent, ASTUnit *TU);
44CXCursor MakeCXCursorInvalid(CXCursorKind K);
45
46/// \brief Create an Objective-C superclass reference at the given location.
47CXCursor MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super,
48                                     SourceLocation Loc,
49                                     ASTUnit *TU);
50
51/// \brief Unpack an ObjCSuperClassRef cursor into the interface it references
52/// and optionally the location where the reference occurred.
53std::pair<ObjCInterfaceDecl *, SourceLocation>
54  getCursorObjCSuperClassRef(CXCursor C);
55
56/// \brief Create an Objective-C protocol reference at the given location.
57CXCursor MakeCursorObjCProtocolRef(ObjCProtocolDecl *Proto, SourceLocation Loc,
58                                   ASTUnit *TU);
59
60/// \brief Unpack an ObjCProtocolRef cursor into the protocol it references
61/// and optionally the location where the reference occurred.
62std::pair<ObjCProtocolDecl *, SourceLocation>
63  getCursorObjCProtocolRef(CXCursor C);
64
65/// \brief Create an Objective-C class reference at the given location.
66CXCursor MakeCursorObjCClassRef(ObjCInterfaceDecl *Class, SourceLocation Loc,
67                                ASTUnit *TU);
68
69/// \brief Unpack an ObjCClassRef cursor into the class it references
70/// and optionally the location where the reference occurred.
71std::pair<ObjCInterfaceDecl *, SourceLocation>
72  getCursorObjCClassRef(CXCursor C);
73
74/// \brief Create a type reference at the given location.
75CXCursor MakeCursorTypeRef(TypeDecl *Type, SourceLocation Loc, ASTUnit *TU);
76
77/// \brief Unpack a TypeRef cursor into the class it references
78/// and optionally the location where the reference occurred.
79std::pair<TypeDecl *, SourceLocation> getCursorTypeRef(CXCursor C);
80
81/// \brief Create a reference to a template at the given location.
82CXCursor MakeCursorTemplateRef(TemplateDecl *Template, SourceLocation Loc,
83                               ASTUnit *TU);
84
85/// \brief Unpack a TemplateRef cursor into the template it references and
86/// the location where the reference occurred.
87std::pair<TemplateDecl *, SourceLocation> getCursorTemplateRef(CXCursor C);
88
89/// \brief Create a reference to a namespace or namespace alias at the given
90/// location.
91CXCursor MakeCursorNamespaceRef(NamedDecl *NS, SourceLocation Loc, ASTUnit *TU);
92
93/// \brief Unpack a NamespaceRef cursor into the namespace or namespace alias
94/// it references and the location where the reference occurred.
95std::pair<NamedDecl *, SourceLocation> getCursorNamespaceRef(CXCursor C);
96
97/// \brief Create a reference to a field at the given location.
98CXCursor MakeCursorMemberRef(FieldDecl *Field, SourceLocation Loc,
99                             ASTUnit *TU);
100
101/// \brief Unpack a MemberRef cursor into the field it references and the
102/// location where the reference occurred.
103std::pair<FieldDecl *, SourceLocation> getCursorMemberRef(CXCursor C);
104
105/// \brief Create a CXX base specifier cursor.
106CXCursor MakeCursorCXXBaseSpecifier(CXXBaseSpecifier *B, ASTUnit *TU);
107
108/// \brief Unpack a CXXBaseSpecifier cursor into a CXXBaseSpecifier.
109CXXBaseSpecifier *getCursorCXXBaseSpecifier(CXCursor C);
110
111/// \brief Create a preprocessing directive cursor.
112CXCursor MakePreprocessingDirectiveCursor(SourceRange Range, ASTUnit *TU);
113
114/// \brief Unpack a given preprocessing directive to retrieve its source range.
115SourceRange getCursorPreprocessingDirective(CXCursor C);
116
117/// \brief Create a macro definition cursor.
118CXCursor MakeMacroDefinitionCursor(MacroDefinition *, ASTUnit *TU);
119
120/// \brief Unpack a given macro definition cursor to retrieve its
121/// source range.
122MacroDefinition *getCursorMacroDefinition(CXCursor C);
123
124/// \brief Create a macro instantiation cursor.
125CXCursor MakeMacroInstantiationCursor(MacroInstantiation *, ASTUnit *TU);
126
127/// \brief Unpack a given macro instantiation cursor to retrieve its
128/// source range.
129MacroInstantiation *getCursorMacroInstantiation(CXCursor C);
130
131Decl *getCursorDecl(CXCursor Cursor);
132Expr *getCursorExpr(CXCursor Cursor);
133Stmt *getCursorStmt(CXCursor Cursor);
134Attr *getCursorAttr(CXCursor Cursor);
135
136ASTContext &getCursorContext(CXCursor Cursor);
137ASTUnit *getCursorASTUnit(CXCursor Cursor);
138
139bool operator==(CXCursor X, CXCursor Y);
140
141inline bool operator!=(CXCursor X, CXCursor Y) {
142  return !(X == Y);
143}
144
145}} // end namespace: clang::cxcursor
146
147#endif
148