blob: 7e518edef9699d201e738ee00f91ab1226c52159 [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);
Ted Kremenek007a7c92010-11-01 23:26:51 +000048CXCursor MakeCXCursor(clang::Decl *D, ASTUnit *TU,
49 bool FirstInDeclGroup = true);
Ted Kremeneke77f4432010-02-18 03:09:07 +000050CXCursor MakeCXCursor(clang::Stmt *S, clang::Decl *Parent, ASTUnit *TU);
51CXCursor MakeCXCursorInvalid(CXCursorKind K);
Ted Kremenek16c440a2010-01-15 20:35:54 +000052
Douglas Gregor2e331b92010-01-16 14:00:32 +000053/// \brief Create an Objective-C superclass reference at the given location.
54CXCursor MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super,
Douglas Gregorb2cd4872010-01-20 23:57:43 +000055 SourceLocation Loc,
56 ASTUnit *TU);
Douglas Gregor2e331b92010-01-16 14:00:32 +000057
58/// \brief Unpack an ObjCSuperClassRef cursor into the interface it references
59/// and optionally the location where the reference occurred.
60std::pair<ObjCInterfaceDecl *, SourceLocation>
Douglas Gregor78db0cd2010-01-16 15:44:18 +000061 getCursorObjCSuperClassRef(CXCursor C);
62
63/// \brief Create an Objective-C protocol reference at the given location.
Douglas Gregorb2cd4872010-01-20 23:57:43 +000064CXCursor MakeCursorObjCProtocolRef(ObjCProtocolDecl *Proto, SourceLocation Loc,
65 ASTUnit *TU);
Douglas Gregor78db0cd2010-01-16 15:44:18 +000066
67/// \brief Unpack an ObjCProtocolRef cursor into the protocol it references
68/// and optionally the location where the reference occurred.
69std::pair<ObjCProtocolDecl *, SourceLocation>
70 getCursorObjCProtocolRef(CXCursor C);
Douglas Gregor2e331b92010-01-16 14:00:32 +000071
Douglas Gregor1adb0822010-01-16 17:14:40 +000072/// \brief Create an Objective-C class reference at the given location.
Douglas Gregorb2cd4872010-01-20 23:57:43 +000073CXCursor MakeCursorObjCClassRef(ObjCInterfaceDecl *Class, SourceLocation Loc,
74 ASTUnit *TU);
Douglas Gregor1adb0822010-01-16 17:14:40 +000075
76/// \brief Unpack an ObjCClassRef cursor into the class it references
77/// and optionally the location where the reference occurred.
78std::pair<ObjCInterfaceDecl *, SourceLocation>
79 getCursorObjCClassRef(CXCursor C);
80
Douglas Gregor7d0d40e2010-01-21 16:28:34 +000081/// \brief Create a type reference at the given location.
82CXCursor MakeCursorTypeRef(TypeDecl *Type, SourceLocation Loc, ASTUnit *TU);
Douglas Gregor0b36e612010-08-31 20:37:03 +000083
Douglas Gregor7d0d40e2010-01-21 16:28:34 +000084/// \brief Unpack a TypeRef cursor into the class it references
85/// and optionally the location where the reference occurred.
86std::pair<TypeDecl *, SourceLocation> getCursorTypeRef(CXCursor C);
87
Douglas Gregor0b36e612010-08-31 20:37:03 +000088/// \brief Create a reference to a template at the given location.
89CXCursor MakeCursorTemplateRef(TemplateDecl *Template, SourceLocation Loc,
90 ASTUnit *TU);
91
92/// \brief Unpack a TemplateRef cursor into the template it references and
93/// the location where the reference occurred.
94std::pair<TemplateDecl *, SourceLocation> getCursorTemplateRef(CXCursor C);
Douglas Gregor69319002010-08-31 23:48:11 +000095
96/// \brief Create a reference to a namespace or namespace alias at the given
97/// location.
98CXCursor MakeCursorNamespaceRef(NamedDecl *NS, SourceLocation Loc, ASTUnit *TU);
99
100/// \brief Unpack a NamespaceRef cursor into the namespace or namespace alias
101/// it references and the location where the reference occurred.
102std::pair<NamedDecl *, SourceLocation> getCursorNamespaceRef(CXCursor C);
103
Douglas Gregora67e03f2010-09-09 21:42:20 +0000104/// \brief Create a reference to a field at the given location.
105CXCursor MakeCursorMemberRef(FieldDecl *Field, SourceLocation Loc,
106 ASTUnit *TU);
107
108/// \brief Unpack a MemberRef cursor into the field it references and the
109/// location where the reference occurred.
110std::pair<FieldDecl *, SourceLocation> getCursorMemberRef(CXCursor C);
111
Ted Kremenek3064ef92010-08-27 21:34:58 +0000112/// \brief Create a CXX base specifier cursor.
113CXCursor MakeCursorCXXBaseSpecifier(CXXBaseSpecifier *B, ASTUnit *TU);
114
115/// \brief Unpack a CXXBaseSpecifier cursor into a CXXBaseSpecifier.
116CXXBaseSpecifier *getCursorCXXBaseSpecifier(CXCursor C);
117
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +0000118/// \brief Create a preprocessing directive cursor.
119CXCursor MakePreprocessingDirectiveCursor(SourceRange Range, ASTUnit *TU);
120
121/// \brief Unpack a given preprocessing directive to retrieve its source range.
122SourceRange getCursorPreprocessingDirective(CXCursor C);
Douglas Gregor48072312010-03-18 15:23:44 +0000123
Douglas Gregor572feb22010-03-18 18:04:21 +0000124/// \brief Create a macro definition cursor.
125CXCursor MakeMacroDefinitionCursor(MacroDefinition *, ASTUnit *TU);
126
127/// \brief Unpack a given macro definition cursor to retrieve its
128/// source range.
129MacroDefinition *getCursorMacroDefinition(CXCursor C);
130
Douglas Gregor48072312010-03-18 15:23:44 +0000131/// \brief Create a macro instantiation cursor.
Douglas Gregor4ae8f292010-03-18 17:52:52 +0000132CXCursor MakeMacroInstantiationCursor(MacroInstantiation *, ASTUnit *TU);
Douglas Gregor48072312010-03-18 15:23:44 +0000133
134/// \brief Unpack a given macro instantiation cursor to retrieve its
135/// source range.
Douglas Gregor4ae8f292010-03-18 17:52:52 +0000136MacroInstantiation *getCursorMacroInstantiation(CXCursor C);
Douglas Gregor48072312010-03-18 15:23:44 +0000137
Douglas Gregorecdcb882010-10-20 22:00:55 +0000138/// \brief Create an inclusion directive cursor.
139CXCursor MakeInclusionDirectiveCursor(InclusionDirective *, ASTUnit *TU);
140
141/// \brief Unpack a given inclusion directive cursor to retrieve its
142/// source range.
143InclusionDirective *getCursorInclusionDirective(CXCursor C);
144
Douglas Gregor36897b02010-09-10 00:22:18 +0000145/// \brief Create a label reference at the given location.
146CXCursor MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc, ASTUnit *TU);
147
148/// \brief Unpack a label reference into the label statement it refers to and
149/// the location of the reference.
150std::pair<LabelStmt *, SourceLocation> getCursorLabelRef(CXCursor C);
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000151
152/// \brief Create a overloaded declaration reference cursor for an expression.
153CXCursor MakeCursorOverloadedDeclRef(OverloadExpr *E, ASTUnit *TU);
154
155/// \brief Create a overloaded declaration reference cursor for a declaration.
156CXCursor MakeCursorOverloadedDeclRef(Decl *D, SourceLocation Location,
157 ASTUnit *TU);
158
159/// \brief Create a overloaded declaration reference cursor for a template name.
160CXCursor MakeCursorOverloadedDeclRef(TemplateName Template,
161 SourceLocation Location, ASTUnit *TU);
162
163/// \brief Internal storage for an overloaded declaration reference cursor;
164typedef llvm::PointerUnion3<OverloadExpr *, Decl *,
165 OverloadedTemplateStorage *>
166 OverloadedDeclRefStorage;
167
168/// \brief Unpack an overloaded declaration reference into an expression,
169/// declaration, or template name along with the source location.
170std::pair<OverloadedDeclRefStorage, SourceLocation>
171 getCursorOverloadedDeclRef(CXCursor C);
Douglas Gregor36897b02010-09-10 00:22:18 +0000172
Douglas Gregor283cae32010-01-15 21:56:13 +0000173Decl *getCursorDecl(CXCursor Cursor);
174Expr *getCursorExpr(CXCursor Cursor);
175Stmt *getCursorStmt(CXCursor Cursor);
Ted Kremenek95f33552010-08-26 01:42:22 +0000176Attr *getCursorAttr(CXCursor Cursor);
177
Douglas Gregorf46034a2010-01-18 23:41:10 +0000178ASTContext &getCursorContext(CXCursor Cursor);
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000179ASTUnit *getCursorASTUnit(CXCursor Cursor);
Douglas Gregor283cae32010-01-15 21:56:13 +0000180
181bool operator==(CXCursor X, CXCursor Y);
182
183inline bool operator!=(CXCursor X, CXCursor Y) {
184 return !(X == Y);
185}
186
Ted Kremenek007a7c92010-11-01 23:26:51 +0000187/// \brief Return true if the cursor represents a declaration that is the
188/// first in a declaration group.
189bool isFirstInDeclGroup(CXCursor C);
190
Ted Kremenek16c440a2010-01-15 20:35:54 +0000191}} // end namespace: clang::cxcursor
192
193#endif