Ted Kremenek | 87553c4 | 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 | 6dc73bc | 2010-01-25 21:09:34 +0000 | [diff] [blame] | 15 | #define LLVM_CLANG_CXCURSOR_H |
Ted Kremenek | 87553c4 | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 16 | |
| 17 | #include "clang-c/Index.h" |
Douglas Gregor | 6c8959b | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 18 | #include "clang/Basic/SourceLocation.h" |
Douglas Gregor | 16a2bdd | 2010-09-13 22:52:57 +0000 | [diff] [blame^] | 19 | #include "llvm/ADT/PointerUnion.h" |
Douglas Gregor | 6c8959b | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 20 | #include <utility> |
Ted Kremenek | 87553c4 | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 21 | |
| 22 | namespace clang { |
| 23 | |
Douglas Gregor | 7ecd020 | 2010-01-18 23:41:10 +0000 | [diff] [blame] | 24 | class ASTContext; |
Douglas Gregor | fed36b1 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 25 | class ASTUnit; |
Ted Kremenek | bff3143 | 2010-02-18 03:09:07 +0000 | [diff] [blame] | 26 | class Attr; |
Ted Kremenek | ae9e221 | 2010-08-27 21:34:58 +0000 | [diff] [blame] | 27 | class CXXBaseSpecifier; |
Ted Kremenek | 87553c4 | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 28 | class Decl; |
Douglas Gregor | c58d05b | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 29 | class Expr; |
Douglas Gregor | f3af311 | 2010-09-09 21:42:20 +0000 | [diff] [blame] | 30 | class FieldDecl; |
Douglas Gregor | a93ab66 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 31 | class LabelStmt; |
Douglas Gregor | 06d6d32 | 2010-03-18 18:04:21 +0000 | [diff] [blame] | 32 | class MacroDefinition; |
Douglas Gregor | 065f8d1 | 2010-03-18 17:52:52 +0000 | [diff] [blame] | 33 | class MacroInstantiation; |
Douglas Gregor | c58d05b | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 34 | class NamedDecl; |
Douglas Gregor | 6c8959b | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 35 | class ObjCInterfaceDecl; |
Douglas Gregor | ef6eb84 | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 36 | class ObjCProtocolDecl; |
Douglas Gregor | 16a2bdd | 2010-09-13 22:52:57 +0000 | [diff] [blame^] | 37 | class OverloadedTemplateStorage; |
| 38 | class OverloadExpr; |
Ted Kremenek | 87553c4 | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 39 | class Stmt; |
Douglas Gregor | a23e8f7 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 40 | class TemplateDecl; |
Douglas Gregor | 16a2bdd | 2010-09-13 22:52:57 +0000 | [diff] [blame^] | 41 | class TemplateName; |
Douglas Gregor | 93f8995 | 2010-01-21 16:28:34 +0000 | [diff] [blame] | 42 | class TypeDecl; |
Douglas Gregor | 16a2bdd | 2010-09-13 22:52:57 +0000 | [diff] [blame^] | 43 | |
Ted Kremenek | 87553c4 | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 44 | namespace cxcursor { |
| 45 | |
Ted Kremenek | bff3143 | 2010-02-18 03:09:07 +0000 | [diff] [blame] | 46 | CXCursor MakeCXCursor(const clang::Attr *A, clang::Decl *Parent, ASTUnit *TU); |
Douglas Gregor | fed36b1 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 47 | CXCursor MakeCXCursor(clang::Decl *D, ASTUnit *TU); |
Ted Kremenek | bff3143 | 2010-02-18 03:09:07 +0000 | [diff] [blame] | 48 | CXCursor MakeCXCursor(clang::Stmt *S, clang::Decl *Parent, ASTUnit *TU); |
| 49 | CXCursor MakeCXCursorInvalid(CXCursorKind K); |
Ted Kremenek | 87553c4 | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 50 | |
Douglas Gregor | 6c8959b | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 51 | /// \brief Create an Objective-C superclass reference at the given location. |
| 52 | CXCursor MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super, |
Douglas Gregor | fed36b1 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 53 | SourceLocation Loc, |
| 54 | ASTUnit *TU); |
Douglas Gregor | 6c8959b | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 55 | |
| 56 | /// \brief Unpack an ObjCSuperClassRef cursor into the interface it references |
| 57 | /// and optionally the location where the reference occurred. |
| 58 | std::pair<ObjCInterfaceDecl *, SourceLocation> |
Douglas Gregor | ef6eb84 | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 59 | getCursorObjCSuperClassRef(CXCursor C); |
| 60 | |
| 61 | /// \brief Create an Objective-C protocol reference at the given location. |
Douglas Gregor | fed36b1 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 62 | CXCursor MakeCursorObjCProtocolRef(ObjCProtocolDecl *Proto, SourceLocation Loc, |
| 63 | ASTUnit *TU); |
Douglas Gregor | ef6eb84 | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 64 | |
| 65 | /// \brief Unpack an ObjCProtocolRef cursor into the protocol it references |
| 66 | /// and optionally the location where the reference occurred. |
| 67 | std::pair<ObjCProtocolDecl *, SourceLocation> |
| 68 | getCursorObjCProtocolRef(CXCursor C); |
Douglas Gregor | 6c8959b | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 69 | |
Douglas Gregor | 46d6614 | 2010-01-16 17:14:40 +0000 | [diff] [blame] | 70 | /// \brief Create an Objective-C class reference at the given location. |
Douglas Gregor | fed36b1 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 71 | CXCursor MakeCursorObjCClassRef(ObjCInterfaceDecl *Class, SourceLocation Loc, |
| 72 | ASTUnit *TU); |
Douglas Gregor | 46d6614 | 2010-01-16 17:14:40 +0000 | [diff] [blame] | 73 | |
| 74 | /// \brief Unpack an ObjCClassRef cursor into the class it references |
| 75 | /// and optionally the location where the reference occurred. |
| 76 | std::pair<ObjCInterfaceDecl *, SourceLocation> |
| 77 | getCursorObjCClassRef(CXCursor C); |
| 78 | |
Douglas Gregor | 93f8995 | 2010-01-21 16:28:34 +0000 | [diff] [blame] | 79 | /// \brief Create a type reference at the given location. |
| 80 | CXCursor MakeCursorTypeRef(TypeDecl *Type, SourceLocation Loc, ASTUnit *TU); |
Douglas Gregor | a23e8f7 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 81 | |
Douglas Gregor | 93f8995 | 2010-01-21 16:28:34 +0000 | [diff] [blame] | 82 | /// \brief Unpack a TypeRef cursor into the class it references |
| 83 | /// and optionally the location where the reference occurred. |
| 84 | std::pair<TypeDecl *, SourceLocation> getCursorTypeRef(CXCursor C); |
| 85 | |
Douglas Gregor | a23e8f7 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 86 | /// \brief Create a reference to a template at the given location. |
| 87 | CXCursor 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. |
| 92 | std::pair<TemplateDecl *, SourceLocation> getCursorTemplateRef(CXCursor C); |
Douglas Gregor | a89314e | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 93 | |
| 94 | /// \brief Create a reference to a namespace or namespace alias at the given |
| 95 | /// location. |
| 96 | CXCursor 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. |
| 100 | std::pair<NamedDecl *, SourceLocation> getCursorNamespaceRef(CXCursor C); |
| 101 | |
Douglas Gregor | f3af311 | 2010-09-09 21:42:20 +0000 | [diff] [blame] | 102 | /// \brief Create a reference to a field at the given location. |
| 103 | CXCursor 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. |
| 108 | std::pair<FieldDecl *, SourceLocation> getCursorMemberRef(CXCursor C); |
| 109 | |
Ted Kremenek | ae9e221 | 2010-08-27 21:34:58 +0000 | [diff] [blame] | 110 | /// \brief Create a CXX base specifier cursor. |
| 111 | CXCursor MakeCursorCXXBaseSpecifier(CXXBaseSpecifier *B, ASTUnit *TU); |
| 112 | |
| 113 | /// \brief Unpack a CXXBaseSpecifier cursor into a CXXBaseSpecifier. |
| 114 | CXXBaseSpecifier *getCursorCXXBaseSpecifier(CXCursor C); |
| 115 | |
Douglas Gregor | 92a524f | 2010-03-18 00:42:48 +0000 | [diff] [blame] | 116 | /// \brief Create a preprocessing directive cursor. |
| 117 | CXCursor MakePreprocessingDirectiveCursor(SourceRange Range, ASTUnit *TU); |
| 118 | |
| 119 | /// \brief Unpack a given preprocessing directive to retrieve its source range. |
| 120 | SourceRange getCursorPreprocessingDirective(CXCursor C); |
Douglas Gregor | 02ded2a | 2010-03-18 15:23:44 +0000 | [diff] [blame] | 121 | |
Douglas Gregor | 06d6d32 | 2010-03-18 18:04:21 +0000 | [diff] [blame] | 122 | /// \brief Create a macro definition cursor. |
| 123 | CXCursor MakeMacroDefinitionCursor(MacroDefinition *, ASTUnit *TU); |
| 124 | |
| 125 | /// \brief Unpack a given macro definition cursor to retrieve its |
| 126 | /// source range. |
| 127 | MacroDefinition *getCursorMacroDefinition(CXCursor C); |
| 128 | |
Douglas Gregor | 02ded2a | 2010-03-18 15:23:44 +0000 | [diff] [blame] | 129 | /// \brief Create a macro instantiation cursor. |
Douglas Gregor | 065f8d1 | 2010-03-18 17:52:52 +0000 | [diff] [blame] | 130 | CXCursor MakeMacroInstantiationCursor(MacroInstantiation *, ASTUnit *TU); |
Douglas Gregor | 02ded2a | 2010-03-18 15:23:44 +0000 | [diff] [blame] | 131 | |
| 132 | /// \brief Unpack a given macro instantiation cursor to retrieve its |
| 133 | /// source range. |
Douglas Gregor | 065f8d1 | 2010-03-18 17:52:52 +0000 | [diff] [blame] | 134 | MacroInstantiation *getCursorMacroInstantiation(CXCursor C); |
Douglas Gregor | 02ded2a | 2010-03-18 15:23:44 +0000 | [diff] [blame] | 135 | |
Douglas Gregor | a93ab66 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 136 | /// \brief Create a label reference at the given location. |
| 137 | CXCursor 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. |
| 141 | std::pair<LabelStmt *, SourceLocation> getCursorLabelRef(CXCursor C); |
Douglas Gregor | 16a2bdd | 2010-09-13 22:52:57 +0000 | [diff] [blame^] | 142 | |
| 143 | /// \brief Create a overloaded declaration reference cursor for an expression. |
| 144 | CXCursor MakeCursorOverloadedDeclRef(OverloadExpr *E, ASTUnit *TU); |
| 145 | |
| 146 | /// \brief Create a overloaded declaration reference cursor for a declaration. |
| 147 | CXCursor MakeCursorOverloadedDeclRef(Decl *D, SourceLocation Location, |
| 148 | ASTUnit *TU); |
| 149 | |
| 150 | /// \brief Create a overloaded declaration reference cursor for a template name. |
| 151 | CXCursor MakeCursorOverloadedDeclRef(TemplateName Template, |
| 152 | SourceLocation Location, ASTUnit *TU); |
| 153 | |
| 154 | /// \brief Internal storage for an overloaded declaration reference cursor; |
| 155 | typedef 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. |
| 161 | std::pair<OverloadedDeclRefStorage, SourceLocation> |
| 162 | getCursorOverloadedDeclRef(CXCursor C); |
Douglas Gregor | a93ab66 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 163 | |
Douglas Gregor | c58d05b | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 164 | Decl *getCursorDecl(CXCursor Cursor); |
| 165 | Expr *getCursorExpr(CXCursor Cursor); |
| 166 | Stmt *getCursorStmt(CXCursor Cursor); |
Ted Kremenek | a594082 | 2010-08-26 01:42:22 +0000 | [diff] [blame] | 167 | Attr *getCursorAttr(CXCursor Cursor); |
| 168 | |
Douglas Gregor | 7ecd020 | 2010-01-18 23:41:10 +0000 | [diff] [blame] | 169 | ASTContext &getCursorContext(CXCursor Cursor); |
Douglas Gregor | fed36b1 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 170 | ASTUnit *getCursorASTUnit(CXCursor Cursor); |
Douglas Gregor | c58d05b | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 171 | |
| 172 | bool operator==(CXCursor X, CXCursor Y); |
| 173 | |
| 174 | inline bool operator!=(CXCursor X, CXCursor Y) { |
| 175 | return !(X == Y); |
| 176 | } |
| 177 | |
Ted Kremenek | 87553c4 | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 178 | }} // end namespace: clang::cxcursor |
| 179 | |
| 180 | #endif |