Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 1 | //===- 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 Kremenek | 2cd10b0 | 2010-01-25 21:09:34 +0000 | [diff] [blame] | 15 | #define LLVM_CLANG_CXCURSOR_H |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 16 | |
| 17 | #include "clang-c/Index.h" |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 18 | #include "clang/Basic/SourceLocation.h" |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/PointerUnion.h" |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 20 | #include <utility> |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 21 | |
| 22 | namespace clang { |
| 23 | |
Douglas Gregor | f46034a | 2010-01-18 23:41:10 +0000 | [diff] [blame] | 24 | class ASTContext; |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 25 | class ASTUnit; |
Ted Kremenek | e77f443 | 2010-02-18 03:09:07 +0000 | [diff] [blame] | 26 | class Attr; |
Ted Kremenek | 3064ef9 | 2010-08-27 21:34:58 +0000 | [diff] [blame] | 27 | class CXXBaseSpecifier; |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 28 | class Decl; |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 29 | class Expr; |
Douglas Gregor | a67e03f | 2010-09-09 21:42:20 +0000 | [diff] [blame] | 30 | class FieldDecl; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 31 | class InclusionDirective; |
Douglas Gregor | 36897b0 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 32 | class LabelStmt; |
Douglas Gregor | 572feb2 | 2010-03-18 18:04:21 +0000 | [diff] [blame] | 33 | class MacroDefinition; |
Chandler Carruth | 9e5bb85 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 34 | class MacroExpansion; |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 35 | class NamedDecl; |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 36 | class ObjCInterfaceDecl; |
Douglas Gregor | 78db0cd | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 37 | class ObjCProtocolDecl; |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 38 | class OverloadedTemplateStorage; |
| 39 | class OverloadExpr; |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 40 | class Stmt; |
Douglas Gregor | 0b36e61 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 41 | class TemplateDecl; |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 42 | class TemplateName; |
Douglas Gregor | 7d0d40e | 2010-01-21 16:28:34 +0000 | [diff] [blame] | 43 | class TypeDecl; |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 44 | |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 45 | namespace cxcursor { |
Argyrios Kyrtzidis | 671436e | 2011-09-27 00:30:33 +0000 | [diff] [blame] | 46 | |
| 47 | CXCursor getCursor(CXTranslationUnit, SourceLocation); |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 48 | |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 49 | CXCursor MakeCXCursor(const clang::Attr *A, clang::Decl *Parent, |
| 50 | CXTranslationUnit TU); |
| 51 | CXCursor MakeCXCursor(clang::Decl *D, CXTranslationUnit TU, |
Ted Kremenek | 007a7c9 | 2010-11-01 23:26:51 +0000 | [diff] [blame] | 52 | bool FirstInDeclGroup = true); |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 53 | CXCursor MakeCXCursor(clang::Stmt *S, clang::Decl *Parent, |
| 54 | CXTranslationUnit TU); |
Ted Kremenek | e77f443 | 2010-02-18 03:09:07 +0000 | [diff] [blame] | 55 | CXCursor MakeCXCursorInvalid(CXCursorKind K); |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 56 | |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 57 | /// \brief Create an Objective-C superclass reference at the given location. |
| 58 | CXCursor MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super, |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 59 | SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 60 | CXTranslationUnit TU); |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 61 | |
| 62 | /// \brief Unpack an ObjCSuperClassRef cursor into the interface it references |
| 63 | /// and optionally the location where the reference occurred. |
| 64 | std::pair<ObjCInterfaceDecl *, SourceLocation> |
Douglas Gregor | 78db0cd | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 65 | getCursorObjCSuperClassRef(CXCursor C); |
| 66 | |
| 67 | /// \brief Create an Objective-C protocol reference at the given location. |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 68 | CXCursor MakeCursorObjCProtocolRef(ObjCProtocolDecl *Proto, SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 69 | CXTranslationUnit TU); |
Douglas Gregor | 78db0cd | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 70 | |
| 71 | /// \brief Unpack an ObjCProtocolRef cursor into the protocol it references |
| 72 | /// and optionally the location where the reference occurred. |
| 73 | std::pair<ObjCProtocolDecl *, SourceLocation> |
| 74 | getCursorObjCProtocolRef(CXCursor C); |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 75 | |
Douglas Gregor | 1adb082 | 2010-01-16 17:14:40 +0000 | [diff] [blame] | 76 | /// \brief Create an Objective-C class reference at the given location. |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 77 | CXCursor MakeCursorObjCClassRef(ObjCInterfaceDecl *Class, SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 78 | CXTranslationUnit TU); |
Douglas Gregor | 1adb082 | 2010-01-16 17:14:40 +0000 | [diff] [blame] | 79 | |
| 80 | /// \brief Unpack an ObjCClassRef cursor into the class it references |
| 81 | /// and optionally the location where the reference occurred. |
| 82 | std::pair<ObjCInterfaceDecl *, SourceLocation> |
| 83 | getCursorObjCClassRef(CXCursor C); |
| 84 | |
Douglas Gregor | 7d0d40e | 2010-01-21 16:28:34 +0000 | [diff] [blame] | 85 | /// \brief Create a type reference at the given location. |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 86 | CXCursor MakeCursorTypeRef(TypeDecl *Type, SourceLocation Loc, |
| 87 | CXTranslationUnit TU); |
Douglas Gregor | 0b36e61 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 88 | |
Douglas Gregor | 7d0d40e | 2010-01-21 16:28:34 +0000 | [diff] [blame] | 89 | /// \brief Unpack a TypeRef cursor into the class it references |
| 90 | /// and optionally the location where the reference occurred. |
| 91 | std::pair<TypeDecl *, SourceLocation> getCursorTypeRef(CXCursor C); |
| 92 | |
Douglas Gregor | 0b36e61 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 93 | /// \brief Create a reference to a template at the given location. |
| 94 | CXCursor MakeCursorTemplateRef(TemplateDecl *Template, SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 95 | CXTranslationUnit TU); |
Douglas Gregor | 0b36e61 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 96 | |
| 97 | /// \brief Unpack a TemplateRef cursor into the template it references and |
| 98 | /// the location where the reference occurred. |
| 99 | std::pair<TemplateDecl *, SourceLocation> getCursorTemplateRef(CXCursor C); |
Douglas Gregor | 6931900 | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 100 | |
| 101 | /// \brief Create a reference to a namespace or namespace alias at the given |
| 102 | /// location. |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 103 | CXCursor MakeCursorNamespaceRef(NamedDecl *NS, SourceLocation Loc, |
| 104 | CXTranslationUnit TU); |
Douglas Gregor | 6931900 | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 105 | |
| 106 | /// \brief Unpack a NamespaceRef cursor into the namespace or namespace alias |
| 107 | /// it references and the location where the reference occurred. |
| 108 | std::pair<NamedDecl *, SourceLocation> getCursorNamespaceRef(CXCursor C); |
| 109 | |
Douglas Gregor | a67e03f | 2010-09-09 21:42:20 +0000 | [diff] [blame] | 110 | /// \brief Create a reference to a field at the given location. |
| 111 | CXCursor MakeCursorMemberRef(FieldDecl *Field, SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 112 | CXTranslationUnit TU); |
Douglas Gregor | a67e03f | 2010-09-09 21:42:20 +0000 | [diff] [blame] | 113 | |
| 114 | /// \brief Unpack a MemberRef cursor into the field it references and the |
| 115 | /// location where the reference occurred. |
| 116 | std::pair<FieldDecl *, SourceLocation> getCursorMemberRef(CXCursor C); |
| 117 | |
Ted Kremenek | 3064ef9 | 2010-08-27 21:34:58 +0000 | [diff] [blame] | 118 | /// \brief Create a CXX base specifier cursor. |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 119 | CXCursor MakeCursorCXXBaseSpecifier(CXXBaseSpecifier *B, |
| 120 | CXTranslationUnit TU); |
Ted Kremenek | 3064ef9 | 2010-08-27 21:34:58 +0000 | [diff] [blame] | 121 | |
| 122 | /// \brief Unpack a CXXBaseSpecifier cursor into a CXXBaseSpecifier. |
| 123 | CXXBaseSpecifier *getCursorCXXBaseSpecifier(CXCursor C); |
| 124 | |
Douglas Gregor | 9f1e3ff | 2010-03-18 00:42:48 +0000 | [diff] [blame] | 125 | /// \brief Create a preprocessing directive cursor. |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 126 | CXCursor MakePreprocessingDirectiveCursor(SourceRange Range, |
| 127 | CXTranslationUnit TU); |
Douglas Gregor | 9f1e3ff | 2010-03-18 00:42:48 +0000 | [diff] [blame] | 128 | |
| 129 | /// \brief Unpack a given preprocessing directive to retrieve its source range. |
| 130 | SourceRange getCursorPreprocessingDirective(CXCursor C); |
Douglas Gregor | 4807231 | 2010-03-18 15:23:44 +0000 | [diff] [blame] | 131 | |
Douglas Gregor | 572feb2 | 2010-03-18 18:04:21 +0000 | [diff] [blame] | 132 | /// \brief Create a macro definition cursor. |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 133 | CXCursor MakeMacroDefinitionCursor(MacroDefinition *, CXTranslationUnit TU); |
Douglas Gregor | 572feb2 | 2010-03-18 18:04:21 +0000 | [diff] [blame] | 134 | |
| 135 | /// \brief Unpack a given macro definition cursor to retrieve its |
| 136 | /// source range. |
| 137 | MacroDefinition *getCursorMacroDefinition(CXCursor C); |
| 138 | |
Chandler Carruth | 9e5bb85 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 139 | /// \brief Create a macro expansion cursor. |
| 140 | CXCursor MakeMacroExpansionCursor(MacroExpansion *, |
| 141 | CXTranslationUnit TU); |
Douglas Gregor | 4807231 | 2010-03-18 15:23:44 +0000 | [diff] [blame] | 142 | |
Chandler Carruth | 9e5bb85 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 143 | /// \brief Unpack a given macro expansion cursor to retrieve its |
Douglas Gregor | 4807231 | 2010-03-18 15:23:44 +0000 | [diff] [blame] | 144 | /// source range. |
Chandler Carruth | 9e5bb85 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 145 | MacroExpansion *getCursorMacroExpansion(CXCursor C); |
Douglas Gregor | 4807231 | 2010-03-18 15:23:44 +0000 | [diff] [blame] | 146 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 147 | /// \brief Create an inclusion directive cursor. |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 148 | CXCursor MakeInclusionDirectiveCursor(InclusionDirective *, |
| 149 | CXTranslationUnit TU); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 150 | |
| 151 | /// \brief Unpack a given inclusion directive cursor to retrieve its |
| 152 | /// source range. |
| 153 | InclusionDirective *getCursorInclusionDirective(CXCursor C); |
| 154 | |
Douglas Gregor | 36897b0 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 155 | /// \brief Create a label reference at the given location. |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 156 | CXCursor MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc, |
| 157 | CXTranslationUnit TU); |
Douglas Gregor | 36897b0 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 158 | |
| 159 | /// \brief Unpack a label reference into the label statement it refers to and |
| 160 | /// the location of the reference. |
| 161 | std::pair<LabelStmt *, SourceLocation> getCursorLabelRef(CXCursor C); |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 162 | |
| 163 | /// \brief Create a overloaded declaration reference cursor for an expression. |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 164 | CXCursor MakeCursorOverloadedDeclRef(OverloadExpr *E, CXTranslationUnit TU); |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 165 | |
| 166 | /// \brief Create a overloaded declaration reference cursor for a declaration. |
| 167 | CXCursor MakeCursorOverloadedDeclRef(Decl *D, SourceLocation Location, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 168 | CXTranslationUnit TU); |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 169 | |
| 170 | /// \brief Create a overloaded declaration reference cursor for a template name. |
| 171 | CXCursor MakeCursorOverloadedDeclRef(TemplateName Template, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 172 | SourceLocation Location, |
| 173 | CXTranslationUnit TU); |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 174 | |
| 175 | /// \brief Internal storage for an overloaded declaration reference cursor; |
| 176 | typedef 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. |
| 182 | std::pair<OverloadedDeclRefStorage, SourceLocation> |
| 183 | getCursorOverloadedDeclRef(CXCursor C); |
Douglas Gregor | 36897b0 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 184 | |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 185 | Decl *getCursorDecl(CXCursor Cursor); |
| 186 | Expr *getCursorExpr(CXCursor Cursor); |
| 187 | Stmt *getCursorStmt(CXCursor Cursor); |
Ted Kremenek | 95f3355 | 2010-08-26 01:42:22 +0000 | [diff] [blame] | 188 | Attr *getCursorAttr(CXCursor Cursor); |
Argyrios Kyrtzidis | 8ccac3d | 2011-06-29 22:20:07 +0000 | [diff] [blame] | 189 | Decl *getCursorParentDecl(CXCursor Cursor); |
Ted Kremenek | 95f3355 | 2010-08-26 01:42:22 +0000 | [diff] [blame] | 190 | |
Douglas Gregor | f46034a | 2010-01-18 23:41:10 +0000 | [diff] [blame] | 191 | ASTContext &getCursorContext(CXCursor Cursor); |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 192 | ASTUnit *getCursorASTUnit(CXCursor Cursor); |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 193 | CXTranslationUnit getCursorTU(CXCursor Cursor); |
Argyrios Kyrtzidis | b11be04 | 2011-10-06 07:00:46 +0000 | [diff] [blame^] | 194 | |
| 195 | void getOverriddenCursors(CXCursor cursor, |
| 196 | SmallVectorImpl<CXCursor> &overridden); |
| 197 | |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 198 | bool operator==(CXCursor X, CXCursor Y); |
| 199 | |
| 200 | inline bool operator!=(CXCursor X, CXCursor Y) { |
| 201 | return !(X == Y); |
| 202 | } |
| 203 | |
Ted Kremenek | 007a7c9 | 2010-11-01 23:26:51 +0000 | [diff] [blame] | 204 | /// \brief Return true if the cursor represents a declaration that is the |
| 205 | /// first in a declaration group. |
| 206 | bool isFirstInDeclGroup(CXCursor C); |
| 207 | |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 208 | }} // end namespace: clang::cxcursor |
| 209 | |
| 210 | #endif |