1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | #ifndef LLVM_CLANG_TOOLS_LIBCLANG_CXCURSOR_H |
14 | #define LLVM_CLANG_TOOLS_LIBCLANG_CXCURSOR_H |
15 | |
16 | #include "clang-c/Index.h" |
17 | #include "clang/Basic/SourceLocation.h" |
18 | #include "llvm/ADT/PointerUnion.h" |
19 | #include <utility> |
20 | |
21 | namespace clang { |
22 | |
23 | class ASTContext; |
24 | class ASTUnit; |
25 | class Attr; |
26 | class CXXBaseSpecifier; |
27 | class Decl; |
28 | class Expr; |
29 | class FieldDecl; |
30 | class InclusionDirective; |
31 | class LabelStmt; |
32 | class MacroDefinitionRecord; |
33 | class MacroExpansion; |
34 | class NamedDecl; |
35 | class ObjCInterfaceDecl; |
36 | class ObjCProtocolDecl; |
37 | class OverloadedTemplateStorage; |
38 | class OverloadExpr; |
39 | class Stmt; |
40 | class TemplateDecl; |
41 | class TemplateName; |
42 | class TypeDecl; |
43 | class VarDecl; |
44 | class IdentifierInfo; |
45 | |
46 | namespace cxcursor { |
47 | |
48 | CXCursor getCursor(CXTranslationUnit, SourceLocation); |
49 | |
50 | CXCursor MakeCXCursor(const clang::Attr *A, const clang::Decl *Parent, |
51 | CXTranslationUnit TU); |
52 | CXCursor MakeCXCursor(const clang::Decl *D, CXTranslationUnit TU, |
53 | SourceRange RegionOfInterest = SourceRange(), |
54 | bool FirstInDeclGroup = true); |
55 | CXCursor MakeCXCursor(const clang::Stmt *S, const clang::Decl *Parent, |
56 | CXTranslationUnit TU, |
57 | SourceRange RegionOfInterest = SourceRange()); |
58 | CXCursor MakeCXCursorInvalid(CXCursorKind K, CXTranslationUnit TU = nullptr); |
59 | |
60 | |
61 | CXCursor MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super, |
62 | SourceLocation Loc, |
63 | CXTranslationUnit TU); |
64 | |
65 | |
66 | |
67 | std::pair<const ObjCInterfaceDecl *, SourceLocation> |
68 | getCursorObjCSuperClassRef(CXCursor C); |
69 | |
70 | |
71 | CXCursor MakeCursorObjCProtocolRef(const ObjCProtocolDecl *Proto, |
72 | SourceLocation Loc, |
73 | CXTranslationUnit TU); |
74 | |
75 | |
76 | |
77 | std::pair<const ObjCProtocolDecl *, SourceLocation> |
78 | getCursorObjCProtocolRef(CXCursor C); |
79 | |
80 | |
81 | CXCursor MakeCursorObjCClassRef(const ObjCInterfaceDecl *Class, |
82 | SourceLocation Loc, |
83 | CXTranslationUnit TU); |
84 | |
85 | |
86 | |
87 | std::pair<const ObjCInterfaceDecl *, SourceLocation> |
88 | getCursorObjCClassRef(CXCursor C); |
89 | |
90 | |
91 | CXCursor MakeCursorTypeRef(const TypeDecl *Type, SourceLocation Loc, |
92 | CXTranslationUnit TU); |
93 | |
94 | |
95 | |
96 | std::pair<const TypeDecl *, SourceLocation> getCursorTypeRef(CXCursor C); |
97 | |
98 | |
99 | CXCursor MakeCursorTemplateRef(const TemplateDecl *Template, SourceLocation Loc, |
100 | CXTranslationUnit TU); |
101 | |
102 | |
103 | |
104 | std::pair<const TemplateDecl *, SourceLocation> |
105 | getCursorTemplateRef(CXCursor C); |
106 | |
107 | |
108 | |
109 | CXCursor MakeCursorNamespaceRef(const NamedDecl *NS, SourceLocation Loc, |
110 | CXTranslationUnit TU); |
111 | |
112 | |
113 | |
114 | std::pair<const NamedDecl *, SourceLocation> getCursorNamespaceRef(CXCursor C); |
115 | |
116 | |
117 | CXCursor MakeCursorVariableRef(const VarDecl *Var, SourceLocation Loc, |
118 | CXTranslationUnit TU); |
119 | |
120 | |
121 | |
122 | std::pair<const VarDecl *, SourceLocation> getCursorVariableRef(CXCursor C); |
123 | |
124 | |
125 | CXCursor MakeCursorMemberRef(const FieldDecl *Field, SourceLocation Loc, |
126 | CXTranslationUnit TU); |
127 | |
128 | |
129 | |
130 | std::pair<const FieldDecl *, SourceLocation> getCursorMemberRef(CXCursor C); |
131 | |
132 | |
133 | CXCursor MakeCursorCXXBaseSpecifier(const CXXBaseSpecifier *B, |
134 | CXTranslationUnit TU); |
135 | |
136 | |
137 | const CXXBaseSpecifier *getCursorCXXBaseSpecifier(CXCursor C); |
138 | |
139 | |
140 | CXCursor MakePreprocessingDirectiveCursor(SourceRange Range, |
141 | CXTranslationUnit TU); |
142 | |
143 | |
144 | SourceRange getCursorPreprocessingDirective(CXCursor C); |
145 | |
146 | |
147 | CXCursor MakeMacroDefinitionCursor(const MacroDefinitionRecord *, |
148 | CXTranslationUnit TU); |
149 | |
150 | |
151 | |
152 | const MacroDefinitionRecord *getCursorMacroDefinition(CXCursor C); |
153 | |
154 | |
155 | CXCursor MakeMacroExpansionCursor(MacroExpansion *, CXTranslationUnit TU); |
156 | |
157 | |
158 | |
159 | CXCursor MakeMacroExpansionCursor(MacroDefinitionRecord *, SourceLocation Loc, |
160 | CXTranslationUnit TU); |
161 | |
162 | |
163 | |
164 | |
165 | |
166 | |
167 | |
168 | |
169 | class MacroExpansionCursor { |
170 | CXCursor C; |
171 | |
172 | bool isPseudo() const { return C.data[1] != nullptr; } |
173 | const MacroDefinitionRecord *getAsMacroDefinition() const { |
174 | assert(isPseudo()); |
175 | return static_cast<const MacroDefinitionRecord *>(C.data[0]); |
176 | } |
177 | const MacroExpansion *getAsMacroExpansion() const { |
178 | assert(!isPseudo()); |
179 | return static_cast<const MacroExpansion *>(C.data[0]); |
180 | } |
181 | SourceLocation getPseudoLoc() const { |
182 | assert(isPseudo()); |
183 | return SourceLocation::getFromPtrEncoding(C.data[1]); |
184 | } |
185 | |
186 | public: |
187 | MacroExpansionCursor(CXCursor C) : C(C) { |
188 | assert(C.kind == CXCursor_MacroExpansion); |
189 | } |
190 | |
191 | const IdentifierInfo *getName() const; |
192 | const MacroDefinitionRecord *getDefinition() const; |
193 | SourceRange getSourceRange() const; |
194 | }; |
195 | |
196 | |
197 | static inline MacroExpansionCursor getCursorMacroExpansion(CXCursor C) { |
198 | return C; |
199 | } |
200 | |
201 | |
202 | CXCursor MakeInclusionDirectiveCursor(InclusionDirective *, |
203 | CXTranslationUnit TU); |
204 | |
205 | |
206 | |
207 | const InclusionDirective *getCursorInclusionDirective(CXCursor C); |
208 | |
209 | |
210 | CXCursor MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc, |
211 | CXTranslationUnit TU); |
212 | |
213 | |
214 | |
215 | std::pair<const LabelStmt *, SourceLocation> getCursorLabelRef(CXCursor C); |
216 | |
217 | |
218 | CXCursor MakeCursorOverloadedDeclRef(const OverloadExpr *E, |
219 | CXTranslationUnit TU); |
220 | |
221 | |
222 | CXCursor MakeCursorOverloadedDeclRef(const Decl *D, SourceLocation Location, |
223 | CXTranslationUnit TU); |
224 | |
225 | |
226 | CXCursor MakeCursorOverloadedDeclRef(TemplateName Template, |
227 | SourceLocation Location, |
228 | CXTranslationUnit TU); |
229 | |
230 | |
231 | typedef llvm::PointerUnion3<const OverloadExpr *, const Decl *, |
232 | OverloadedTemplateStorage *> |
233 | OverloadedDeclRefStorage; |
234 | |
235 | |
236 | |
237 | std::pair<OverloadedDeclRefStorage, SourceLocation> |
238 | getCursorOverloadedDeclRef(CXCursor C); |
239 | |
240 | const Decl *getCursorDecl(CXCursor Cursor); |
241 | const Expr *getCursorExpr(CXCursor Cursor); |
242 | const Stmt *getCursorStmt(CXCursor Cursor); |
243 | const Attr *getCursorAttr(CXCursor Cursor); |
244 | |
245 | ASTContext &getCursorContext(CXCursor Cursor); |
246 | ASTUnit *getCursorASTUnit(CXCursor Cursor); |
247 | CXTranslationUnit getCursorTU(CXCursor Cursor); |
248 | |
249 | void getOverriddenCursors(CXCursor cursor, |
250 | SmallVectorImpl<CXCursor> &overridden); |
251 | |
252 | |
253 | |
254 | void *createOverridenCXCursorsPool(); |
255 | |
256 | |
257 | void disposeOverridenCXCursorsPool(void *pool); |
258 | |
259 | |
260 | |
261 | std::pair<int, SourceLocation> getSelectorIdentifierIndexAndLoc(CXCursor); |
262 | static inline int getSelectorIdentifierIndex(CXCursor cursor) { |
263 | return getSelectorIdentifierIndexAndLoc(cursor).first; |
264 | } |
265 | static inline SourceLocation getSelectorIdentifierLoc(CXCursor cursor) { |
266 | return getSelectorIdentifierIndexAndLoc(cursor).second; |
267 | } |
268 | |
269 | CXCursor getSelectorIdentifierCursor(int SelIdx, CXCursor cursor); |
270 | |
271 | static inline CXCursor getTypeRefedCallExprCursor(CXCursor cursor) { |
272 | CXCursor newCursor = cursor; |
273 | if (cursor.kind == CXCursor_CallExpr) |
274 | newCursor.xdata = 1; |
275 | return newCursor; |
276 | } |
277 | |
278 | CXCursor getTypeRefCursor(CXCursor cursor); |
279 | |
280 | |
281 | |
282 | |
283 | bool getDeclCursorUSR(const Decl *D, SmallVectorImpl<char> &Buf); |
284 | |
285 | bool operator==(CXCursor X, CXCursor Y); |
286 | |
287 | inline bool operator!=(CXCursor X, CXCursor Y) { |
288 | return !(X == Y); |
289 | } |
290 | |
291 | |
292 | |
293 | bool isFirstInDeclGroup(CXCursor C); |
294 | |
295 | }} |
296 | |
297 | #endif |
298 | |