blob: 4a29dd0f1c158786315995e3ad6459287b7ac71f [file] [log] [blame]
Ted Kremenek87553c42010-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 Kremenek6dc73bc2010-01-25 21:09:34 +000015#define LLVM_CLANG_CXCURSOR_H
Ted Kremenek87553c42010-01-15 20:35:54 +000016
17#include "clang-c/Index.h"
Douglas Gregor6c8959b2010-01-16 14:00:32 +000018#include "clang/Basic/SourceLocation.h"
Douglas Gregor16a2bdd2010-09-13 22:52:57 +000019#include "llvm/ADT/PointerUnion.h"
Douglas Gregor6c8959b2010-01-16 14:00:32 +000020#include <utility>
Ted Kremenek87553c42010-01-15 20:35:54 +000021
22namespace clang {
23
Douglas Gregor7ecd0202010-01-18 23:41:10 +000024class ASTContext;
Douglas Gregorfed36b12010-01-20 23:57:43 +000025class ASTUnit;
Ted Kremenekbff31432010-02-18 03:09:07 +000026class Attr;
Ted Kremenekae9e2212010-08-27 21:34:58 +000027class CXXBaseSpecifier;
Ted Kremenek87553c42010-01-15 20:35:54 +000028class Decl;
Douglas Gregorc58d05b2010-01-15 21:56:13 +000029class Expr;
Douglas Gregorf3af3112010-09-09 21:42:20 +000030class FieldDecl;
Douglas Gregora93ab662010-09-10 00:22:18 +000031class LabelStmt;
Douglas Gregor06d6d322010-03-18 18:04:21 +000032class MacroDefinition;
Douglas Gregor065f8d12010-03-18 17:52:52 +000033class MacroInstantiation;
Douglas Gregorc58d05b2010-01-15 21:56:13 +000034class NamedDecl;
Douglas Gregor6c8959b2010-01-16 14:00:32 +000035class ObjCInterfaceDecl;
Douglas Gregoref6eb842010-01-16 15:44:18 +000036class ObjCProtocolDecl;
Douglas Gregor16a2bdd2010-09-13 22:52:57 +000037class OverloadedTemplateStorage;
38class OverloadExpr;
Ted Kremenek87553c42010-01-15 20:35:54 +000039class Stmt;
Douglas Gregora23e8f72010-08-31 20:37:03 +000040class TemplateDecl;
Douglas Gregor16a2bdd2010-09-13 22:52:57 +000041class TemplateName;
Douglas Gregor93f89952010-01-21 16:28:34 +000042class TypeDecl;
Douglas Gregor16a2bdd2010-09-13 22:52:57 +000043
Ted Kremenek87553c42010-01-15 20:35:54 +000044namespace cxcursor {
45
Ted Kremenekbff31432010-02-18 03:09:07 +000046CXCursor MakeCXCursor(const clang::Attr *A, clang::Decl *Parent, ASTUnit *TU);
Douglas Gregorfed36b12010-01-20 23:57:43 +000047CXCursor MakeCXCursor(clang::Decl *D, ASTUnit *TU);
Ted Kremenekbff31432010-02-18 03:09:07 +000048CXCursor MakeCXCursor(clang::Stmt *S, clang::Decl *Parent, ASTUnit *TU);
49CXCursor MakeCXCursorInvalid(CXCursorKind K);
Ted Kremenek87553c42010-01-15 20:35:54 +000050
Douglas Gregor6c8959b2010-01-16 14:00:32 +000051/// \brief Create an Objective-C superclass reference at the given location.
52CXCursor MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super,
Douglas Gregorfed36b12010-01-20 23:57:43 +000053 SourceLocation Loc,
54 ASTUnit *TU);
Douglas Gregor6c8959b2010-01-16 14:00:32 +000055
56/// \brief Unpack an ObjCSuperClassRef cursor into the interface it references
57/// and optionally the location where the reference occurred.
58std::pair<ObjCInterfaceDecl *, SourceLocation>
Douglas Gregoref6eb842010-01-16 15:44:18 +000059 getCursorObjCSuperClassRef(CXCursor C);
60
61/// \brief Create an Objective-C protocol reference at the given location.
Douglas Gregorfed36b12010-01-20 23:57:43 +000062CXCursor MakeCursorObjCProtocolRef(ObjCProtocolDecl *Proto, SourceLocation Loc,
63 ASTUnit *TU);
Douglas Gregoref6eb842010-01-16 15:44:18 +000064
65/// \brief Unpack an ObjCProtocolRef cursor into the protocol it references
66/// and optionally the location where the reference occurred.
67std::pair<ObjCProtocolDecl *, SourceLocation>
68 getCursorObjCProtocolRef(CXCursor C);
Douglas Gregor6c8959b2010-01-16 14:00:32 +000069
Douglas Gregor46d66142010-01-16 17:14:40 +000070/// \brief Create an Objective-C class reference at the given location.
Douglas Gregorfed36b12010-01-20 23:57:43 +000071CXCursor MakeCursorObjCClassRef(ObjCInterfaceDecl *Class, SourceLocation Loc,
72 ASTUnit *TU);
Douglas Gregor46d66142010-01-16 17:14:40 +000073
74/// \brief Unpack an ObjCClassRef cursor into the class it references
75/// and optionally the location where the reference occurred.
76std::pair<ObjCInterfaceDecl *, SourceLocation>
77 getCursorObjCClassRef(CXCursor C);
78
Douglas Gregor93f89952010-01-21 16:28:34 +000079/// \brief Create a type reference at the given location.
80CXCursor MakeCursorTypeRef(TypeDecl *Type, SourceLocation Loc, ASTUnit *TU);
Douglas Gregora23e8f72010-08-31 20:37:03 +000081
Douglas Gregor93f89952010-01-21 16:28:34 +000082/// \brief Unpack a TypeRef cursor into the class it references
83/// and optionally the location where the reference occurred.
84std::pair<TypeDecl *, SourceLocation> getCursorTypeRef(CXCursor C);
85
Douglas Gregora23e8f72010-08-31 20:37:03 +000086/// \brief Create a reference to a template at the given location.
87CXCursor MakeCursorTemplateRef(TemplateDecl *Template, SourceLocation Loc,
88 ASTUnit *TU);
89
90/// \brief Unpack a TemplateRef cursor into the template it references and
91/// the location where the reference occurred.
92std::pair<TemplateDecl *, SourceLocation> getCursorTemplateRef(CXCursor C);
Douglas Gregora89314e2010-08-31 23:48:11 +000093
94/// \brief Create a reference to a namespace or namespace alias at the given
95/// location.
96CXCursor MakeCursorNamespaceRef(NamedDecl *NS, SourceLocation Loc, ASTUnit *TU);
97
98/// \brief Unpack a NamespaceRef cursor into the namespace or namespace alias
99/// it references and the location where the reference occurred.
100std::pair<NamedDecl *, SourceLocation> getCursorNamespaceRef(CXCursor C);
101
Douglas Gregorf3af3112010-09-09 21:42:20 +0000102/// \brief Create a reference to a field at the given location.
103CXCursor MakeCursorMemberRef(FieldDecl *Field, SourceLocation Loc,
104 ASTUnit *TU);
105
106/// \brief Unpack a MemberRef cursor into the field it references and the
107/// location where the reference occurred.
108std::pair<FieldDecl *, SourceLocation> getCursorMemberRef(CXCursor C);
109
Ted Kremenekae9e2212010-08-27 21:34:58 +0000110/// \brief Create a CXX base specifier cursor.
111CXCursor MakeCursorCXXBaseSpecifier(CXXBaseSpecifier *B, ASTUnit *TU);
112
113/// \brief Unpack a CXXBaseSpecifier cursor into a CXXBaseSpecifier.
114CXXBaseSpecifier *getCursorCXXBaseSpecifier(CXCursor C);
115
Douglas Gregor92a524f2010-03-18 00:42:48 +0000116/// \brief Create a preprocessing directive cursor.
117CXCursor MakePreprocessingDirectiveCursor(SourceRange Range, ASTUnit *TU);
118
119/// \brief Unpack a given preprocessing directive to retrieve its source range.
120SourceRange getCursorPreprocessingDirective(CXCursor C);
Douglas Gregor02ded2a2010-03-18 15:23:44 +0000121
Douglas Gregor06d6d322010-03-18 18:04:21 +0000122/// \brief Create a macro definition cursor.
123CXCursor MakeMacroDefinitionCursor(MacroDefinition *, ASTUnit *TU);
124
125/// \brief Unpack a given macro definition cursor to retrieve its
126/// source range.
127MacroDefinition *getCursorMacroDefinition(CXCursor C);
128
Douglas Gregor02ded2a2010-03-18 15:23:44 +0000129/// \brief Create a macro instantiation cursor.
Douglas Gregor065f8d12010-03-18 17:52:52 +0000130CXCursor MakeMacroInstantiationCursor(MacroInstantiation *, ASTUnit *TU);
Douglas Gregor02ded2a2010-03-18 15:23:44 +0000131
132/// \brief Unpack a given macro instantiation cursor to retrieve its
133/// source range.
Douglas Gregor065f8d12010-03-18 17:52:52 +0000134MacroInstantiation *getCursorMacroInstantiation(CXCursor C);
Douglas Gregor02ded2a2010-03-18 15:23:44 +0000135
Douglas Gregora93ab662010-09-10 00:22:18 +0000136/// \brief Create a label reference at the given location.
137CXCursor MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc, ASTUnit *TU);
138
139/// \brief Unpack a label reference into the label statement it refers to and
140/// the location of the reference.
141std::pair<LabelStmt *, SourceLocation> getCursorLabelRef(CXCursor C);
Douglas Gregor16a2bdd2010-09-13 22:52:57 +0000142
143/// \brief Create a overloaded declaration reference cursor for an expression.
144CXCursor MakeCursorOverloadedDeclRef(OverloadExpr *E, ASTUnit *TU);
145
146/// \brief Create a overloaded declaration reference cursor for a declaration.
147CXCursor MakeCursorOverloadedDeclRef(Decl *D, SourceLocation Location,
148 ASTUnit *TU);
149
150/// \brief Create a overloaded declaration reference cursor for a template name.
151CXCursor MakeCursorOverloadedDeclRef(TemplateName Template,
152 SourceLocation Location, ASTUnit *TU);
153
154/// \brief Internal storage for an overloaded declaration reference cursor;
155typedef llvm::PointerUnion3<OverloadExpr *, Decl *,
156 OverloadedTemplateStorage *>
157 OverloadedDeclRefStorage;
158
159/// \brief Unpack an overloaded declaration reference into an expression,
160/// declaration, or template name along with the source location.
161std::pair<OverloadedDeclRefStorage, SourceLocation>
162 getCursorOverloadedDeclRef(CXCursor C);
Douglas Gregora93ab662010-09-10 00:22:18 +0000163
Douglas Gregorc58d05b2010-01-15 21:56:13 +0000164Decl *getCursorDecl(CXCursor Cursor);
165Expr *getCursorExpr(CXCursor Cursor);
166Stmt *getCursorStmt(CXCursor Cursor);
Ted Kremeneka5940822010-08-26 01:42:22 +0000167Attr *getCursorAttr(CXCursor Cursor);
168
Douglas Gregor7ecd0202010-01-18 23:41:10 +0000169ASTContext &getCursorContext(CXCursor Cursor);
Douglas Gregorfed36b12010-01-20 23:57:43 +0000170ASTUnit *getCursorASTUnit(CXCursor Cursor);
Douglas Gregorc58d05b2010-01-15 21:56:13 +0000171
172bool operator==(CXCursor X, CXCursor Y);
173
174inline bool operator!=(CXCursor X, CXCursor Y) {
175 return !(X == Y);
176}
177
Ted Kremenek87553c42010-01-15 20:35:54 +0000178}} // end namespace: clang::cxcursor
179
180#endif