1 //===- CXCursor.h - Routines for manipulating CXCursors -------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines routines for manipulating CXCursors.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_CXCURSOR_H
15 #define LLVM_CLANG_CXCURSOR_H
17 #include "clang-c/Index.h"
18 #include "clang/Basic/SourceLocation.h"
19 #include "llvm/ADT/PointerUnion.h"
27 class CXXBaseSpecifier
;
31 class InclusionDirective
;
33 class MacroDefinition
;
34 class MacroInstantiation
;
36 class ObjCInterfaceDecl
;
37 class ObjCProtocolDecl
;
38 class OverloadedTemplateStorage
;
47 CXCursor
MakeCXCursor(const clang::Attr
*A
, clang::Decl
*Parent
, ASTUnit
*TU
);
48 CXCursor
MakeCXCursor(clang::Decl
*D
, ASTUnit
*TU
,
49 bool FirstInDeclGroup
= true);
50 CXCursor
MakeCXCursor(clang::Stmt
*S
, clang::Decl
*Parent
, ASTUnit
*TU
);
51 CXCursor
MakeCXCursorInvalid(CXCursorKind K
);
53 /// \brief Create an Objective-C superclass reference at the given location.
54 CXCursor
MakeCursorObjCSuperClassRef(ObjCInterfaceDecl
*Super
,
58 /// \brief Unpack an ObjCSuperClassRef cursor into the interface it references
59 /// and optionally the location where the reference occurred.
60 std::pair
<ObjCInterfaceDecl
*, SourceLocation
>
61 getCursorObjCSuperClassRef(CXCursor C
);
63 /// \brief Create an Objective-C protocol reference at the given location.
64 CXCursor
MakeCursorObjCProtocolRef(ObjCProtocolDecl
*Proto
, SourceLocation Loc
,
67 /// \brief Unpack an ObjCProtocolRef cursor into the protocol it references
68 /// and optionally the location where the reference occurred.
69 std::pair
<ObjCProtocolDecl
*, SourceLocation
>
70 getCursorObjCProtocolRef(CXCursor C
);
72 /// \brief Create an Objective-C class reference at the given location.
73 CXCursor
MakeCursorObjCClassRef(ObjCInterfaceDecl
*Class
, SourceLocation Loc
,
76 /// \brief Unpack an ObjCClassRef cursor into the class it references
77 /// and optionally the location where the reference occurred.
78 std::pair
<ObjCInterfaceDecl
*, SourceLocation
>
79 getCursorObjCClassRef(CXCursor C
);
81 /// \brief Create a type reference at the given location.
82 CXCursor
MakeCursorTypeRef(TypeDecl
*Type
, SourceLocation Loc
, ASTUnit
*TU
);
84 /// \brief Unpack a TypeRef cursor into the class it references
85 /// and optionally the location where the reference occurred.
86 std::pair
<TypeDecl
*, SourceLocation
> getCursorTypeRef(CXCursor C
);
88 /// \brief Create a reference to a template at the given location.
89 CXCursor
MakeCursorTemplateRef(TemplateDecl
*Template
, SourceLocation Loc
,
92 /// \brief Unpack a TemplateRef cursor into the template it references and
93 /// the location where the reference occurred.
94 std::pair
<TemplateDecl
*, SourceLocation
> getCursorTemplateRef(CXCursor C
);
96 /// \brief Create a reference to a namespace or namespace alias at the given
98 CXCursor
MakeCursorNamespaceRef(NamedDecl
*NS
, SourceLocation Loc
, ASTUnit
*TU
);
100 /// \brief Unpack a NamespaceRef cursor into the namespace or namespace alias
101 /// it references and the location where the reference occurred.
102 std::pair
<NamedDecl
*, SourceLocation
> getCursorNamespaceRef(CXCursor C
);
104 /// \brief Create a reference to a field at the given location.
105 CXCursor
MakeCursorMemberRef(FieldDecl
*Field
, SourceLocation Loc
,
108 /// \brief Unpack a MemberRef cursor into the field it references and the
109 /// location where the reference occurred.
110 std::pair
<FieldDecl
*, SourceLocation
> getCursorMemberRef(CXCursor C
);
112 /// \brief Create a CXX base specifier cursor.
113 CXCursor
MakeCursorCXXBaseSpecifier(CXXBaseSpecifier
*B
, ASTUnit
*TU
);
115 /// \brief Unpack a CXXBaseSpecifier cursor into a CXXBaseSpecifier.
116 CXXBaseSpecifier
*getCursorCXXBaseSpecifier(CXCursor C
);
118 /// \brief Create a preprocessing directive cursor.
119 CXCursor
MakePreprocessingDirectiveCursor(SourceRange Range
, ASTUnit
*TU
);
121 /// \brief Unpack a given preprocessing directive to retrieve its source range.
122 SourceRange
getCursorPreprocessingDirective(CXCursor C
);
124 /// \brief Create a macro definition cursor.
125 CXCursor
MakeMacroDefinitionCursor(MacroDefinition
*, ASTUnit
*TU
);
127 /// \brief Unpack a given macro definition cursor to retrieve its
129 MacroDefinition
*getCursorMacroDefinition(CXCursor C
);
131 /// \brief Create a macro instantiation cursor.
132 CXCursor
MakeMacroInstantiationCursor(MacroInstantiation
*, ASTUnit
*TU
);
134 /// \brief Unpack a given macro instantiation cursor to retrieve its
136 MacroInstantiation
*getCursorMacroInstantiation(CXCursor C
);
138 /// \brief Create an inclusion directive cursor.
139 CXCursor
MakeInclusionDirectiveCursor(InclusionDirective
*, ASTUnit
*TU
);
141 /// \brief Unpack a given inclusion directive cursor to retrieve its
143 InclusionDirective
*getCursorInclusionDirective(CXCursor C
);
145 /// \brief Create a label reference at the given location.
146 CXCursor
MakeCursorLabelRef(LabelStmt
*Label
, SourceLocation Loc
, ASTUnit
*TU
);
148 /// \brief Unpack a label reference into the label statement it refers to and
149 /// the location of the reference.
150 std::pair
<LabelStmt
*, SourceLocation
> getCursorLabelRef(CXCursor C
);
152 /// \brief Create a overloaded declaration reference cursor for an expression.
153 CXCursor
MakeCursorOverloadedDeclRef(OverloadExpr
*E
, ASTUnit
*TU
);
155 /// \brief Create a overloaded declaration reference cursor for a declaration.
156 CXCursor
MakeCursorOverloadedDeclRef(Decl
*D
, SourceLocation Location
,
159 /// \brief Create a overloaded declaration reference cursor for a template name.
160 CXCursor
MakeCursorOverloadedDeclRef(TemplateName Template
,
161 SourceLocation Location
, ASTUnit
*TU
);
163 /// \brief Internal storage for an overloaded declaration reference cursor;
164 typedef llvm::PointerUnion3
<OverloadExpr
*, Decl
*,
165 OverloadedTemplateStorage
*>
166 OverloadedDeclRefStorage
;
168 /// \brief Unpack an overloaded declaration reference into an expression,
169 /// declaration, or template name along with the source location.
170 std::pair
<OverloadedDeclRefStorage
, SourceLocation
>
171 getCursorOverloadedDeclRef(CXCursor C
);
173 Decl
*getCursorDecl(CXCursor Cursor
);
174 Expr
*getCursorExpr(CXCursor Cursor
);
175 Stmt
*getCursorStmt(CXCursor Cursor
);
176 Attr
*getCursorAttr(CXCursor Cursor
);
178 ASTContext
&getCursorContext(CXCursor Cursor
);
179 ASTUnit
*getCursorASTUnit(CXCursor Cursor
);
181 bool operator==(CXCursor X
, CXCursor Y
);
183 inline bool operator!=(CXCursor X
, CXCursor Y
) {
187 /// \brief Return true if the cursor represents a declaration that is the
188 /// first in a declaration group.
189 bool isFirstInDeclGroup(CXCursor C
);
191 }} // end namespace: clang::cxcursor