blob: c7051ea2f987baadf323a9cfea9eecaa01bdacf0 [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;
Chandler Carruth9e5bb852011-07-14 08:20:46 +000034class MacroExpansion;
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 {
Argyrios Kyrtzidis671436e2011-09-27 00:30:33 +000046
47CXCursor getCursor(CXTranslationUnit, SourceLocation);
Ted Kremenek16c440a2010-01-15 20:35:54 +000048
Ted Kremeneka60ed472010-11-16 08:15:36 +000049CXCursor MakeCXCursor(const clang::Attr *A, clang::Decl *Parent,
50 CXTranslationUnit TU);
51CXCursor MakeCXCursor(clang::Decl *D, CXTranslationUnit TU,
Ted Kremenek007a7c92010-11-01 23:26:51 +000052 bool FirstInDeclGroup = true);
Ted Kremeneka60ed472010-11-16 08:15:36 +000053CXCursor MakeCXCursor(clang::Stmt *S, clang::Decl *Parent,
54 CXTranslationUnit TU);
Ted Kremeneke77f4432010-02-18 03:09:07 +000055CXCursor MakeCXCursorInvalid(CXCursorKind K);
Ted Kremenek16c440a2010-01-15 20:35:54 +000056
Douglas Gregor2e331b92010-01-16 14:00:32 +000057/// \brief Create an Objective-C superclass reference at the given location.
58CXCursor MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super,
Douglas Gregorb2cd4872010-01-20 23:57:43 +000059 SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +000060 CXTranslationUnit TU);
Douglas Gregor2e331b92010-01-16 14:00:32 +000061
62/// \brief Unpack an ObjCSuperClassRef cursor into the interface it references
63/// and optionally the location where the reference occurred.
64std::pair<ObjCInterfaceDecl *, SourceLocation>
Douglas Gregor78db0cd2010-01-16 15:44:18 +000065 getCursorObjCSuperClassRef(CXCursor C);
66
67/// \brief Create an Objective-C protocol reference at the given location.
Douglas Gregorb2cd4872010-01-20 23:57:43 +000068CXCursor MakeCursorObjCProtocolRef(ObjCProtocolDecl *Proto, SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +000069 CXTranslationUnit TU);
Douglas Gregor78db0cd2010-01-16 15:44:18 +000070
71/// \brief Unpack an ObjCProtocolRef cursor into the protocol it references
72/// and optionally the location where the reference occurred.
73std::pair<ObjCProtocolDecl *, SourceLocation>
74 getCursorObjCProtocolRef(CXCursor C);
Douglas Gregor2e331b92010-01-16 14:00:32 +000075
Douglas Gregor1adb0822010-01-16 17:14:40 +000076/// \brief Create an Objective-C class reference at the given location.
Douglas Gregorb2cd4872010-01-20 23:57:43 +000077CXCursor MakeCursorObjCClassRef(ObjCInterfaceDecl *Class, SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +000078 CXTranslationUnit TU);
Douglas Gregor1adb0822010-01-16 17:14:40 +000079
80/// \brief Unpack an ObjCClassRef cursor into the class it references
81/// and optionally the location where the reference occurred.
82std::pair<ObjCInterfaceDecl *, SourceLocation>
83 getCursorObjCClassRef(CXCursor C);
84
Douglas Gregor7d0d40e2010-01-21 16:28:34 +000085/// \brief Create a type reference at the given location.
Ted Kremeneka60ed472010-11-16 08:15:36 +000086CXCursor MakeCursorTypeRef(TypeDecl *Type, SourceLocation Loc,
87 CXTranslationUnit TU);
Douglas Gregor0b36e612010-08-31 20:37:03 +000088
Douglas Gregor7d0d40e2010-01-21 16:28:34 +000089/// \brief Unpack a TypeRef cursor into the class it references
90/// and optionally the location where the reference occurred.
91std::pair<TypeDecl *, SourceLocation> getCursorTypeRef(CXCursor C);
92
Douglas Gregor0b36e612010-08-31 20:37:03 +000093/// \brief Create a reference to a template at the given location.
94CXCursor MakeCursorTemplateRef(TemplateDecl *Template, SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +000095 CXTranslationUnit TU);
Douglas Gregor0b36e612010-08-31 20:37:03 +000096
97/// \brief Unpack a TemplateRef cursor into the template it references and
98/// the location where the reference occurred.
99std::pair<TemplateDecl *, SourceLocation> getCursorTemplateRef(CXCursor C);
Douglas Gregor69319002010-08-31 23:48:11 +0000100
101/// \brief Create a reference to a namespace or namespace alias at the given
102/// location.
Ted Kremeneka60ed472010-11-16 08:15:36 +0000103CXCursor MakeCursorNamespaceRef(NamedDecl *NS, SourceLocation Loc,
104 CXTranslationUnit TU);
Douglas Gregor69319002010-08-31 23:48:11 +0000105
106/// \brief Unpack a NamespaceRef cursor into the namespace or namespace alias
107/// it references and the location where the reference occurred.
108std::pair<NamedDecl *, SourceLocation> getCursorNamespaceRef(CXCursor C);
109
Douglas Gregora67e03f2010-09-09 21:42:20 +0000110/// \brief Create a reference to a field at the given location.
111CXCursor MakeCursorMemberRef(FieldDecl *Field, SourceLocation Loc,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000112 CXTranslationUnit TU);
Douglas Gregora67e03f2010-09-09 21:42:20 +0000113
114/// \brief Unpack a MemberRef cursor into the field it references and the
115/// location where the reference occurred.
116std::pair<FieldDecl *, SourceLocation> getCursorMemberRef(CXCursor C);
117
Ted Kremenek3064ef92010-08-27 21:34:58 +0000118/// \brief Create a CXX base specifier cursor.
Ted Kremeneka60ed472010-11-16 08:15:36 +0000119CXCursor MakeCursorCXXBaseSpecifier(CXXBaseSpecifier *B,
120 CXTranslationUnit TU);
Ted Kremenek3064ef92010-08-27 21:34:58 +0000121
122/// \brief Unpack a CXXBaseSpecifier cursor into a CXXBaseSpecifier.
123CXXBaseSpecifier *getCursorCXXBaseSpecifier(CXCursor C);
124
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +0000125/// \brief Create a preprocessing directive cursor.
Ted Kremeneka60ed472010-11-16 08:15:36 +0000126CXCursor MakePreprocessingDirectiveCursor(SourceRange Range,
127 CXTranslationUnit TU);
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +0000128
129/// \brief Unpack a given preprocessing directive to retrieve its source range.
130SourceRange getCursorPreprocessingDirective(CXCursor C);
Douglas Gregor48072312010-03-18 15:23:44 +0000131
Douglas Gregor572feb22010-03-18 18:04:21 +0000132/// \brief Create a macro definition cursor.
Ted Kremeneka60ed472010-11-16 08:15:36 +0000133CXCursor MakeMacroDefinitionCursor(MacroDefinition *, CXTranslationUnit TU);
Douglas Gregor572feb22010-03-18 18:04:21 +0000134
135/// \brief Unpack a given macro definition cursor to retrieve its
136/// source range.
137MacroDefinition *getCursorMacroDefinition(CXCursor C);
138
Chandler Carruth9e5bb852011-07-14 08:20:46 +0000139/// \brief Create a macro expansion cursor.
140CXCursor MakeMacroExpansionCursor(MacroExpansion *,
141 CXTranslationUnit TU);
Douglas Gregor48072312010-03-18 15:23:44 +0000142
Chandler Carruth9e5bb852011-07-14 08:20:46 +0000143/// \brief Unpack a given macro expansion cursor to retrieve its
Douglas Gregor48072312010-03-18 15:23:44 +0000144/// source range.
Chandler Carruth9e5bb852011-07-14 08:20:46 +0000145MacroExpansion *getCursorMacroExpansion(CXCursor C);
Douglas Gregor48072312010-03-18 15:23:44 +0000146
Douglas Gregorecdcb882010-10-20 22:00:55 +0000147/// \brief Create an inclusion directive cursor.
Ted Kremeneka60ed472010-11-16 08:15:36 +0000148CXCursor MakeInclusionDirectiveCursor(InclusionDirective *,
149 CXTranslationUnit TU);
Douglas Gregorecdcb882010-10-20 22:00:55 +0000150
151/// \brief Unpack a given inclusion directive cursor to retrieve its
152/// source range.
153InclusionDirective *getCursorInclusionDirective(CXCursor C);
154
Douglas Gregor36897b02010-09-10 00:22:18 +0000155/// \brief Create a label reference at the given location.
Ted Kremeneka60ed472010-11-16 08:15:36 +0000156CXCursor MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc,
157 CXTranslationUnit TU);
Douglas Gregor36897b02010-09-10 00:22:18 +0000158
159/// \brief Unpack a label reference into the label statement it refers to and
160/// the location of the reference.
161std::pair<LabelStmt *, SourceLocation> getCursorLabelRef(CXCursor C);
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000162
163/// \brief Create a overloaded declaration reference cursor for an expression.
Ted Kremeneka60ed472010-11-16 08:15:36 +0000164CXCursor MakeCursorOverloadedDeclRef(OverloadExpr *E, CXTranslationUnit TU);
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000165
166/// \brief Create a overloaded declaration reference cursor for a declaration.
167CXCursor MakeCursorOverloadedDeclRef(Decl *D, SourceLocation Location,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000168 CXTranslationUnit TU);
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000169
170/// \brief Create a overloaded declaration reference cursor for a template name.
171CXCursor MakeCursorOverloadedDeclRef(TemplateName Template,
Ted Kremeneka60ed472010-11-16 08:15:36 +0000172 SourceLocation Location,
173 CXTranslationUnit TU);
Douglas Gregor1f60d9e2010-09-13 22:52:57 +0000174
175/// \brief Internal storage for an overloaded declaration reference cursor;
176typedef llvm::PointerUnion3<OverloadExpr *, Decl *,
177 OverloadedTemplateStorage *>
178 OverloadedDeclRefStorage;
179
180/// \brief Unpack an overloaded declaration reference into an expression,
181/// declaration, or template name along with the source location.
182std::pair<OverloadedDeclRefStorage, SourceLocation>
183 getCursorOverloadedDeclRef(CXCursor C);
Douglas Gregor36897b02010-09-10 00:22:18 +0000184
Douglas Gregor283cae32010-01-15 21:56:13 +0000185Decl *getCursorDecl(CXCursor Cursor);
186Expr *getCursorExpr(CXCursor Cursor);
187Stmt *getCursorStmt(CXCursor Cursor);
Ted Kremenek95f33552010-08-26 01:42:22 +0000188Attr *getCursorAttr(CXCursor Cursor);
Argyrios Kyrtzidis8ccac3d2011-06-29 22:20:07 +0000189Decl *getCursorParentDecl(CXCursor Cursor);
Ted Kremenek95f33552010-08-26 01:42:22 +0000190
Douglas Gregorf46034a2010-01-18 23:41:10 +0000191ASTContext &getCursorContext(CXCursor Cursor);
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000192ASTUnit *getCursorASTUnit(CXCursor Cursor);
Ted Kremeneka60ed472010-11-16 08:15:36 +0000193CXTranslationUnit getCursorTU(CXCursor Cursor);
Douglas Gregor283cae32010-01-15 21:56:13 +0000194
195bool operator==(CXCursor X, CXCursor Y);
196
197inline bool operator!=(CXCursor X, CXCursor Y) {
198 return !(X == Y);
199}
200
Ted Kremenek007a7c92010-11-01 23:26:51 +0000201/// \brief Return true if the cursor represents a declaration that is the
202/// first in a declaration group.
203bool isFirstInDeclGroup(CXCursor C);
204
Ted Kremenek16c440a2010-01-15 20:35:54 +0000205}} // end namespace: clang::cxcursor
206
207#endif