blob: a31a32207673ae9fb532db9b1145597c590e64ff [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"
Douglas Gregor1f60d9e2010-09-13 22:52:57 +000019#include "llvm/ADT/PointerUnion.h"
Douglas Gregor2e331b92010-01-16 14:00:32 +000020#include <utility>
Ted Kremenek16c440a2010-01-15 20:35:54 +000021
22namespace clang {
23
Douglas Gregorf46034a2010-01-18 23:41:10 +000024class ASTContext;
Douglas Gregorb2cd4872010-01-20 23:57:43 +000025class ASTUnit;
Ted Kremeneke77f4432010-02-18 03:09:07 +000026class Attr;
Ted Kremenek3064ef92010-08-27 21:34:58 +000027class CXXBaseSpecifier;
Ted Kremenek16c440a2010-01-15 20:35:54 +000028class Decl;
Douglas Gregor283cae32010-01-15 21:56:13 +000029class Expr;
Douglas Gregora67e03f2010-09-09 21:42:20 +000030class FieldDecl;
Douglas Gregorecdcb882010-10-20 22:00:55 +000031class InclusionDirective;
Douglas Gregor36897b02010-09-10 00:22:18 +000032class LabelStmt;
Douglas Gregor572feb22010-03-18 18:04:21 +000033class MacroDefinition;
Douglas Gregor4ae8f292010-03-18 17:52:52 +000034class MacroInstantiation;
Douglas Gregor283cae32010-01-15 21:56:13 +000035class NamedDecl;
Douglas Gregor2e331b92010-01-16 14:00:32 +000036class ObjCInterfaceDecl;
Douglas Gregor78db0cd2010-01-16 15:44:18 +000037class ObjCProtocolDecl;
Douglas Gregor1f60d9e2010-09-13 22:52:57 +000038class OverloadedTemplateStorage;
39class OverloadExpr;
Ted Kremenek16c440a2010-01-15 20:35:54 +000040class Stmt;
Douglas Gregor0b36e612010-08-31 20:37:03 +000041class TemplateDecl;
Douglas Gregor1f60d9e2010-09-13 22:52:57 +000042class TemplateName;
Douglas Gregor7d0d40e2010-01-21 16:28:34 +000043class TypeDecl;
Douglas Gregor1f60d9e2010-09-13 22:52:57 +000044
Ted Kremenek16c440a2010-01-15 20:35:54 +000045namespace cxcursor {
46
Ted Kremeneke77f4432010-02-18 03:09:07 +000047CXCursor MakeCXCursor(const clang::Attr *A, clang::Decl *Parent, ASTUnit *TU);
Douglas Gregorb2cd4872010-01-20 23:57:43 +000048CXCursor MakeCXCursor(clang::Decl *D, ASTUnit *TU);
Ted Kremeneke77f4432010-02-18 03:09:07 +000049CXCursor MakeCXCursor(clang::Stmt *S, clang::Decl *Parent, ASTUnit *TU);
50CXCursor MakeCXCursorInvalid(CXCursorKind K);
Ted Kremenek16c440a2010-01-15 20:35:54 +000051
Douglas Gregor2e331b92010-01-16 14:00:32 +000052/// \brief Create an Objective-C superclass reference at the given location.
53CXCursor MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super,
Douglas Gregorb2cd4872010-01-20 23:57:43 +000054 SourceLocation Loc,
55 ASTUnit *TU);
Douglas Gregor2e331b92010-01-16 14:00:32 +000056
57/// \brief Unpack an ObjCSuperClassRef cursor into the interface it references
58/// and optionally the location where the reference occurred.
59std::pair<ObjCInterfaceDecl *, SourceLocation>
Douglas Gregor78db0cd2010-01-16 15:44:18 +000060 getCursorObjCSuperClassRef(CXCursor C);
61
62/// \brief Create an Objective-C protocol reference at the given location.
Douglas Gregorb2cd4872010-01-20 23:57:43 +000063CXCursor MakeCursorObjCProtocolRef(ObjCProtocolDecl *Proto, SourceLocation Loc,
64 ASTUnit *TU);
Douglas Gregor78db0cd2010-01-16 15:44:18 +000065
66/// \brief Unpack an ObjCProtocolRef cursor into the protocol it references
67/// and optionally the location where the reference occurred.
68std::pair<ObjCProtocolDecl *, SourceLocation>
69 getCursorObjCProtocolRef(CXCursor C);
Douglas Gregor2e331b92010-01-16 14:00:32 +000070
Douglas Gregor1adb0822010-01-16 17:14:40 +000071/// \brief Create an Objective-C class reference at the given location.
Douglas Gregorb2cd4872010-01-20 23:57:43 +000072CXCursor MakeCursorObjCClassRef(ObjCInterfaceDecl *Class, SourceLocation Loc,
73 ASTUnit *TU);
Douglas Gregor1adb0822010-01-16 17:14:40 +000074
75/// \brief Unpack an ObjCClassRef cursor into the class it references
76/// and optionally the location where the reference occurred.
77std::pair<ObjCInterfaceDecl *, SourceLocation>
78 getCursorObjCClassRef(CXCursor C);
79
Douglas Gregor7d0d40e2010-01-21 16:28:34 +000080/// \brief Create a type reference at the given location.
81CXCursor MakeCursorTypeRef(TypeDecl *Type, SourceLocation Loc, ASTUnit *TU);
Douglas Gregor0b36e612010-08-31 20:37:03 +000082
Douglas Gregor7d0d40e2010-01-21 16:28:34 +000083/// \brief Unpack a TypeRef cursor into the class it references
84/// and optionally the location where the reference occurred.
85std::pair<TypeDecl *, SourceLocation> getCursorTypeRef(CXCursor C);
86
Douglas Gregor0b36e612010-08-31 20:37:03 +000087/// \brief Create a reference to a template at the given location.
88CXCursor MakeCursorTemplateRef(TemplateDecl *Template, SourceLocation Loc,
89 ASTUnit *TU);
90
91/// \brief Unpack a TemplateRef cursor into the template it references and
92/// the location where the reference occurred.
93std::pair<TemplateDecl *, SourceLocation> getCursorTemplateRef(CXCursor C);
Douglas Gregor69319002010-08-31 23:48:11 +000094
95/// \brief Create a reference to a namespace or namespace alias at the given
96/// location.
97CXCursor MakeCursorNamespaceRef(NamedDecl *NS, SourceLocation Loc, ASTUnit *TU);
98
99/// \brief Unpack a NamespaceRef cursor into the namespace or namespace alias
100/// it references and the location where the reference occurred.
101std::pair<NamedDecl *, SourceLocation> getCursorNamespaceRef(CXCursor C);
102
Douglas Gregora67e03f2010-09-09 21:42:20 +0000103/// \brief Create a reference to a field at the given location.
104CXCursor MakeCursorMemberRef(FieldDecl *Field, SourceLocation Loc,
105 ASTUnit *TU);
106
107/// \brief Unpack a MemberRef cursor into the field it references and the
108/// location where the reference occurred.
109std::pair<FieldDecl *, SourceLocation> getCursorMemberRef(CXCursor C);
110
Ted Kremenek3064ef92010-08-27 21:34:58 +0000111/// \brief Create a CXX base specifier cursor.
112CXCursor MakeCursorCXXBaseSpecifier(CXXBaseSpecifier *B, ASTUnit *TU);
113
114/// \brief Unpack a CXXBaseSpecifier cursor into a CXXBaseSpecifier.
115CXXBaseSpecifier *getCursorCXXBaseSpecifier(CXCursor C);
116
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +0000117/// \brief Create a preprocessing directive cursor.
118CXCursor MakePreprocessingDirectiveCursor(SourceRange Range, ASTUnit *TU);
119
120/// \brief Unpack a given preprocessing directive to retrieve its source range.
121SourceRange getCursorPreprocessingDirective(CXCursor C);
Douglas Gregor48072312010-03-18 15:23:44 +0000122
Douglas Gregor572feb22010-03-18 18:04:21 +0000123/// \brief Create a macro definition cursor.
124CXCursor MakeMacroDefinitionCursor(MacroDefinition *, ASTUnit *TU);
125
126/// \brief Unpack a given macro definition cursor to retrieve its
127/// source range.
128MacroDefinition *getCursorMacroDefinition(CXCursor C);
129
Douglas Gregor48072312010-03-18 15:23:44 +0000130/// \brief Create a macro instantiation cursor.
Douglas Gregor4ae8f292010-03-18 17:52:52 +0000131CXCursor MakeMacroInstantiationCursor(MacroInstantiation *, ASTUnit *TU);
Douglas Gregor48072312010-03-18 15:23:44 +0000132
133/// \brief Unpack a given macro instantiation cursor to retrieve its
134/// source range.
Douglas Gregor4ae8f292010-03-18 17:52:52 +0000135MacroInstantiation *getCursorMacroInstantiation(CXCursor C);
Douglas Gregor48072312010-03-18 15:23:44 +0000136
Douglas Gregorecdcb882010-10-20 22:00:55 +0000137/// \brief Create an inclusion directive cursor.
138CXCursor MakeInclusionDirectiveCursor(InclusionDirective *, ASTUnit *TU);
139
140/// \brief Unpack a given inclusion directive cursor to retrieve its
141/// source range.
142InclusionDirective *getCursorInclusionDirective(CXCursor C);
143
Douglas Gregor36897b02010-09-10 00:22:18 +0000144/// \brief Create a label reference at the given location.
145CXCursor MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc, ASTUnit *TU);
146
147/// \brief Unpack a label reference into the label statement it refers to and
148/// the location of the reference.
149std::pair<LabelStmt *, SourceLocation> getCursorLabelRef(CXCursor C);
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000150
151/// \brief Create a overloaded declaration reference cursor for an expression.
152CXCursor MakeCursorOverloadedDeclRef(OverloadExpr *E, ASTUnit *TU);
153
154/// \brief Create a overloaded declaration reference cursor for a declaration.
155CXCursor MakeCursorOverloadedDeclRef(Decl *D, SourceLocation Location,
156 ASTUnit *TU);
157
158/// \brief Create a overloaded declaration reference cursor for a template name.
159CXCursor MakeCursorOverloadedDeclRef(TemplateName Template,
160 SourceLocation Location, ASTUnit *TU);
161
162/// \brief Internal storage for an overloaded declaration reference cursor;
163typedef llvm::PointerUnion3<OverloadExpr *, Decl *,
164 OverloadedTemplateStorage *>
165 OverloadedDeclRefStorage;
166
167/// \brief Unpack an overloaded declaration reference into an expression,
168/// declaration, or template name along with the source location.
169std::pair<OverloadedDeclRefStorage, SourceLocation>
170 getCursorOverloadedDeclRef(CXCursor C);
Douglas Gregor36897b02010-09-10 00:22:18 +0000171
Douglas Gregor283cae32010-01-15 21:56:13 +0000172Decl *getCursorDecl(CXCursor Cursor);
173Expr *getCursorExpr(CXCursor Cursor);
174Stmt *getCursorStmt(CXCursor Cursor);
Ted Kremenek95f33552010-08-26 01:42:22 +0000175Attr *getCursorAttr(CXCursor Cursor);
176
Douglas Gregorf46034a2010-01-18 23:41:10 +0000177ASTContext &getCursorContext(CXCursor Cursor);
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000178ASTUnit *getCursorASTUnit(CXCursor Cursor);
Douglas Gregor283cae32010-01-15 21:56:13 +0000179
180bool operator==(CXCursor X, CXCursor Y);
181
182inline bool operator!=(CXCursor X, CXCursor Y) {
183 return !(X == Y);
184}
185
Ted Kremenek16c440a2010-01-15 20:35:54 +0000186}} // end namespace: clang::cxcursor
187
188#endif