• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "llvm/ADT/PointerUnion.h"
20 #include <utility>
21 
22 namespace clang {
23 
24 class ASTContext;
25 class ASTUnit;
26 class Attr;
27 class CXXBaseSpecifier;
28 class Decl;
29 class Expr;
30 class FieldDecl;
31 class InclusionDirective;
32 class LabelStmt;
33 class MacroDefinition;
34 class MacroExpansion;
35 class NamedDecl;
36 class ObjCInterfaceDecl;
37 class ObjCProtocolDecl;
38 class OverloadedTemplateStorage;
39 class OverloadExpr;
40 class Stmt;
41 class TemplateDecl;
42 class TemplateName;
43 class TypeDecl;
44 
45 namespace cxcursor {
46 
47 CXCursor MakeCXCursor(const clang::Attr *A, clang::Decl *Parent,
48                       CXTranslationUnit TU);
49 CXCursor MakeCXCursor(clang::Decl *D, CXTranslationUnit TU,
50                       bool FirstInDeclGroup = true);
51 CXCursor MakeCXCursor(clang::Stmt *S, clang::Decl *Parent,
52                       CXTranslationUnit TU);
53 CXCursor MakeCXCursorInvalid(CXCursorKind K);
54 
55 /// \brief Create an Objective-C superclass reference at the given location.
56 CXCursor MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super,
57                                      SourceLocation Loc,
58                                      CXTranslationUnit TU);
59 
60 /// \brief Unpack an ObjCSuperClassRef cursor into the interface it references
61 /// and optionally the location where the reference occurred.
62 std::pair<ObjCInterfaceDecl *, SourceLocation>
63   getCursorObjCSuperClassRef(CXCursor C);
64 
65 /// \brief Create an Objective-C protocol reference at the given location.
66 CXCursor MakeCursorObjCProtocolRef(ObjCProtocolDecl *Proto, SourceLocation Loc,
67                                    CXTranslationUnit TU);
68 
69 /// \brief Unpack an ObjCProtocolRef cursor into the protocol it references
70 /// and optionally the location where the reference occurred.
71 std::pair<ObjCProtocolDecl *, SourceLocation>
72   getCursorObjCProtocolRef(CXCursor C);
73 
74 /// \brief Create an Objective-C class reference at the given location.
75 CXCursor MakeCursorObjCClassRef(ObjCInterfaceDecl *Class, SourceLocation Loc,
76                                 CXTranslationUnit TU);
77 
78 /// \brief Unpack an ObjCClassRef cursor into the class it references
79 /// and optionally the location where the reference occurred.
80 std::pair<ObjCInterfaceDecl *, SourceLocation>
81   getCursorObjCClassRef(CXCursor C);
82 
83 /// \brief Create a type reference at the given location.
84 CXCursor MakeCursorTypeRef(TypeDecl *Type, SourceLocation Loc,
85                            CXTranslationUnit TU);
86 
87 /// \brief Unpack a TypeRef cursor into the class it references
88 /// and optionally the location where the reference occurred.
89 std::pair<TypeDecl *, SourceLocation> getCursorTypeRef(CXCursor C);
90 
91 /// \brief Create a reference to a template at the given location.
92 CXCursor MakeCursorTemplateRef(TemplateDecl *Template, SourceLocation Loc,
93                                CXTranslationUnit TU);
94 
95 /// \brief Unpack a TemplateRef cursor into the template it references and
96 /// the location where the reference occurred.
97 std::pair<TemplateDecl *, SourceLocation> getCursorTemplateRef(CXCursor C);
98 
99 /// \brief Create a reference to a namespace or namespace alias at the given
100 /// location.
101 CXCursor MakeCursorNamespaceRef(NamedDecl *NS, SourceLocation Loc,
102                                 CXTranslationUnit TU);
103 
104 /// \brief Unpack a NamespaceRef cursor into the namespace or namespace alias
105 /// it references and the location where the reference occurred.
106 std::pair<NamedDecl *, SourceLocation> getCursorNamespaceRef(CXCursor C);
107 
108 /// \brief Create a reference to a field at the given location.
109 CXCursor MakeCursorMemberRef(FieldDecl *Field, SourceLocation Loc,
110                              CXTranslationUnit TU);
111 
112 /// \brief Unpack a MemberRef cursor into the field it references and the
113 /// location where the reference occurred.
114 std::pair<FieldDecl *, SourceLocation> getCursorMemberRef(CXCursor C);
115 
116 /// \brief Create a CXX base specifier cursor.
117 CXCursor MakeCursorCXXBaseSpecifier(CXXBaseSpecifier *B,
118                                     CXTranslationUnit TU);
119 
120 /// \brief Unpack a CXXBaseSpecifier cursor into a CXXBaseSpecifier.
121 CXXBaseSpecifier *getCursorCXXBaseSpecifier(CXCursor C);
122 
123 /// \brief Create a preprocessing directive cursor.
124 CXCursor MakePreprocessingDirectiveCursor(SourceRange Range,
125                                           CXTranslationUnit TU);
126 
127 /// \brief Unpack a given preprocessing directive to retrieve its source range.
128 SourceRange getCursorPreprocessingDirective(CXCursor C);
129 
130 /// \brief Create a macro definition cursor.
131 CXCursor MakeMacroDefinitionCursor(MacroDefinition *, CXTranslationUnit TU);
132 
133 /// \brief Unpack a given macro definition cursor to retrieve its
134 /// source range.
135 MacroDefinition *getCursorMacroDefinition(CXCursor C);
136 
137 /// \brief Create a macro expansion cursor.
138 CXCursor MakeMacroExpansionCursor(MacroExpansion *,
139                                   CXTranslationUnit TU);
140 
141 /// \brief Unpack a given macro expansion cursor to retrieve its
142 /// source range.
143 MacroExpansion *getCursorMacroExpansion(CXCursor C);
144 
145 /// \brief Create an inclusion directive cursor.
146 CXCursor MakeInclusionDirectiveCursor(InclusionDirective *,
147                                       CXTranslationUnit TU);
148 
149 /// \brief Unpack a given inclusion directive cursor to retrieve its
150 /// source range.
151 InclusionDirective *getCursorInclusionDirective(CXCursor C);
152 
153 /// \brief Create a label reference at the given location.
154 CXCursor MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc,
155                             CXTranslationUnit TU);
156 
157 /// \brief Unpack a label reference into the label statement it refers to and
158 /// the location of the reference.
159 std::pair<LabelStmt *, SourceLocation> getCursorLabelRef(CXCursor C);
160 
161 /// \brief Create a overloaded declaration reference cursor for an expression.
162 CXCursor MakeCursorOverloadedDeclRef(OverloadExpr *E, CXTranslationUnit TU);
163 
164 /// \brief Create a overloaded declaration reference cursor for a declaration.
165 CXCursor MakeCursorOverloadedDeclRef(Decl *D, SourceLocation Location,
166                                      CXTranslationUnit TU);
167 
168 /// \brief Create a overloaded declaration reference cursor for a template name.
169 CXCursor MakeCursorOverloadedDeclRef(TemplateName Template,
170                                      SourceLocation Location,
171                                      CXTranslationUnit TU);
172 
173 /// \brief Internal storage for an overloaded declaration reference cursor;
174 typedef llvm::PointerUnion3<OverloadExpr *, Decl *,
175                             OverloadedTemplateStorage *>
176   OverloadedDeclRefStorage;
177 
178 /// \brief Unpack an overloaded declaration reference into an expression,
179 /// declaration, or template name along with the source location.
180 std::pair<OverloadedDeclRefStorage, SourceLocation>
181   getCursorOverloadedDeclRef(CXCursor C);
182 
183 Decl *getCursorDecl(CXCursor Cursor);
184 Expr *getCursorExpr(CXCursor Cursor);
185 Stmt *getCursorStmt(CXCursor Cursor);
186 Attr *getCursorAttr(CXCursor Cursor);
187 Decl *getCursorParentDecl(CXCursor Cursor);
188 
189 ASTContext &getCursorContext(CXCursor Cursor);
190 ASTUnit *getCursorASTUnit(CXCursor Cursor);
191 CXTranslationUnit getCursorTU(CXCursor Cursor);
192 
193 bool operator==(CXCursor X, CXCursor Y);
194 
195 inline bool operator!=(CXCursor X, CXCursor Y) {
196   return !(X == Y);
197 }
198 
199 /// \brief Return true if the cursor represents a declaration that is the
200 /// first in a declaration group.
201 bool isFirstInDeclGroup(CXCursor C);
202 
203 }} // end namespace: clang::cxcursor
204 
205 #endif
206