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