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 | 011d8b9 | 2012-02-15 00:54:55 +0000 | [diff] [blame] | 44 | class VarDecl; |
Argyrios Kyrtzidis | 664b06f | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 45 | class IdentifierInfo; |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 46 | |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 47 | namespace cxcursor { |
Argyrios Kyrtzidis | 671436e | 2011-09-27 00:30:33 +0000 | [diff] [blame] | 48 | |
| 49 | CXCursor getCursor(CXTranslationUnit, SourceLocation); |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 50 | |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 51 | CXCursor MakeCXCursor(const clang::Attr *A, clang::Decl *Parent, |
| 52 | CXTranslationUnit TU); |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame^] | 53 | CXCursor MakeCXCursor(const clang::Decl *D, CXTranslationUnit TU, |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 54 | SourceRange RegionOfInterest = SourceRange(), |
Ted Kremenek | 007a7c9 | 2010-11-01 23:26:51 +0000 | [diff] [blame] | 55 | bool FirstInDeclGroup = true); |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame^] | 56 | CXCursor MakeCXCursor(const clang::Stmt *S, clang::Decl *Parent, |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 57 | CXTranslationUnit TU, |
| 58 | SourceRange RegionOfInterest = SourceRange()); |
Ted Kremenek | bbf66ca | 2012-04-30 19:06:49 +0000 | [diff] [blame] | 59 | CXCursor MakeCXCursorInvalid(CXCursorKind K, CXTranslationUnit TU = 0); |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 60 | |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 61 | /// \brief Create an Objective-C superclass reference at the given location. |
| 62 | CXCursor MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super, |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 63 | SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 64 | CXTranslationUnit TU); |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 65 | |
| 66 | /// \brief Unpack an ObjCSuperClassRef cursor into the interface it references |
| 67 | /// and optionally the location where the reference occurred. |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame^] | 68 | std::pair<const ObjCInterfaceDecl *, SourceLocation> |
Douglas Gregor | 78db0cd | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 69 | getCursorObjCSuperClassRef(CXCursor C); |
| 70 | |
| 71 | /// \brief Create an Objective-C protocol reference at the given location. |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 72 | CXCursor MakeCursorObjCProtocolRef(const ObjCProtocolDecl *Proto, |
| 73 | SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 74 | CXTranslationUnit TU); |
Douglas Gregor | 78db0cd | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 75 | |
| 76 | /// \brief Unpack an ObjCProtocolRef cursor into the protocol it references |
| 77 | /// and optionally the location where the reference occurred. |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame^] | 78 | std::pair<const ObjCProtocolDecl *, SourceLocation> |
Douglas Gregor | 78db0cd | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 79 | getCursorObjCProtocolRef(CXCursor C); |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 80 | |
Douglas Gregor | 1adb082 | 2010-01-16 17:14:40 +0000 | [diff] [blame] | 81 | /// \brief Create an Objective-C class reference at the given location. |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 82 | CXCursor MakeCursorObjCClassRef(const ObjCInterfaceDecl *Class, |
| 83 | SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 84 | CXTranslationUnit TU); |
Douglas Gregor | 1adb082 | 2010-01-16 17:14:40 +0000 | [diff] [blame] | 85 | |
| 86 | /// \brief Unpack an ObjCClassRef cursor into the class it references |
| 87 | /// and optionally the location where the reference occurred. |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame^] | 88 | std::pair<const ObjCInterfaceDecl *, SourceLocation> |
Douglas Gregor | 1adb082 | 2010-01-16 17:14:40 +0000 | [diff] [blame] | 89 | getCursorObjCClassRef(CXCursor C); |
| 90 | |
Douglas Gregor | 7d0d40e | 2010-01-21 16:28:34 +0000 | [diff] [blame] | 91 | /// \brief Create a type reference at the given location. |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 92 | CXCursor MakeCursorTypeRef(const TypeDecl *Type, SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 93 | CXTranslationUnit TU); |
Douglas Gregor | 0b36e61 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 94 | |
Douglas Gregor | 7d0d40e | 2010-01-21 16:28:34 +0000 | [diff] [blame] | 95 | /// \brief Unpack a TypeRef cursor into the class it references |
| 96 | /// and optionally the location where the reference occurred. |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame^] | 97 | std::pair<const TypeDecl *, SourceLocation> getCursorTypeRef(CXCursor C); |
Douglas Gregor | 7d0d40e | 2010-01-21 16:28:34 +0000 | [diff] [blame] | 98 | |
Douglas Gregor | 0b36e61 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 99 | /// \brief Create a reference to a template at the given location. |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 100 | CXCursor MakeCursorTemplateRef(const TemplateDecl *Template, SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 101 | CXTranslationUnit TU); |
Douglas Gregor | 0b36e61 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 102 | |
| 103 | /// \brief Unpack a TemplateRef cursor into the template it references and |
| 104 | /// the location where the reference occurred. |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame^] | 105 | std::pair<const TemplateDecl *, SourceLocation> |
| 106 | getCursorTemplateRef(CXCursor C); |
Douglas Gregor | 6931900 | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 107 | |
| 108 | /// \brief Create a reference to a namespace or namespace alias at the given |
| 109 | /// location. |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 110 | CXCursor MakeCursorNamespaceRef(const NamedDecl *NS, SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 111 | CXTranslationUnit TU); |
Douglas Gregor | 6931900 | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 112 | |
| 113 | /// \brief Unpack a NamespaceRef cursor into the namespace or namespace alias |
| 114 | /// it references and the location where the reference occurred. |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame^] | 115 | std::pair<const NamedDecl *, SourceLocation> getCursorNamespaceRef(CXCursor C); |
Douglas Gregor | 6931900 | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 116 | |
Douglas Gregor | 011d8b9 | 2012-02-15 00:54:55 +0000 | [diff] [blame] | 117 | /// \brief Create a reference to a variable at the given location. |
| 118 | CXCursor MakeCursorVariableRef(const VarDecl *Var, SourceLocation Loc, |
| 119 | CXTranslationUnit TU); |
| 120 | |
| 121 | /// \brief Unpack a VariableRef cursor into the variable it references and the |
| 122 | /// location where the where the reference occurred. |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame^] | 123 | std::pair<const VarDecl *, SourceLocation> getCursorVariableRef(CXCursor C); |
Douglas Gregor | 011d8b9 | 2012-02-15 00:54:55 +0000 | [diff] [blame] | 124 | |
Douglas Gregor | a67e03f | 2010-09-09 21:42:20 +0000 | [diff] [blame] | 125 | /// \brief Create a reference to a field at the given location. |
Argyrios Kyrtzidis | b395c63 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 126 | CXCursor MakeCursorMemberRef(const FieldDecl *Field, SourceLocation Loc, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 127 | CXTranslationUnit TU); |
Douglas Gregor | a67e03f | 2010-09-09 21:42:20 +0000 | [diff] [blame] | 128 | |
| 129 | /// \brief Unpack a MemberRef cursor into the field it references and the |
| 130 | /// location where the reference occurred. |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame^] | 131 | std::pair<const FieldDecl *, SourceLocation> getCursorMemberRef(CXCursor C); |
Douglas Gregor | a67e03f | 2010-09-09 21:42:20 +0000 | [diff] [blame] | 132 | |
Ted Kremenek | 3064ef9 | 2010-08-27 21:34:58 +0000 | [diff] [blame] | 133 | /// \brief Create a CXX base specifier cursor. |
Argyrios Kyrtzidis | 2957e6f | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 134 | CXCursor MakeCursorCXXBaseSpecifier(const CXXBaseSpecifier *B, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 135 | CXTranslationUnit TU); |
Ted Kremenek | 3064ef9 | 2010-08-27 21:34:58 +0000 | [diff] [blame] | 136 | |
| 137 | /// \brief Unpack a CXXBaseSpecifier cursor into a CXXBaseSpecifier. |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame^] | 138 | const CXXBaseSpecifier *getCursorCXXBaseSpecifier(CXCursor C); |
Ted Kremenek | 3064ef9 | 2010-08-27 21:34:58 +0000 | [diff] [blame] | 139 | |
Douglas Gregor | 9f1e3ff | 2010-03-18 00:42:48 +0000 | [diff] [blame] | 140 | /// \brief Create a preprocessing directive cursor. |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 141 | CXCursor MakePreprocessingDirectiveCursor(SourceRange Range, |
| 142 | CXTranslationUnit TU); |
Douglas Gregor | 9f1e3ff | 2010-03-18 00:42:48 +0000 | [diff] [blame] | 143 | |
| 144 | /// \brief Unpack a given preprocessing directive to retrieve its source range. |
| 145 | SourceRange getCursorPreprocessingDirective(CXCursor C); |
Douglas Gregor | 4807231 | 2010-03-18 15:23:44 +0000 | [diff] [blame] | 146 | |
Douglas Gregor | 572feb2 | 2010-03-18 18:04:21 +0000 | [diff] [blame] | 147 | /// \brief Create a macro definition cursor. |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame^] | 148 | CXCursor MakeMacroDefinitionCursor(const MacroDefinition *, |
| 149 | CXTranslationUnit TU); |
Douglas Gregor | 572feb2 | 2010-03-18 18:04:21 +0000 | [diff] [blame] | 150 | |
| 151 | /// \brief Unpack a given macro definition cursor to retrieve its |
| 152 | /// source range. |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame^] | 153 | const MacroDefinition *getCursorMacroDefinition(CXCursor C); |
Douglas Gregor | 572feb2 | 2010-03-18 18:04:21 +0000 | [diff] [blame] | 154 | |
Chandler Carruth | 9e5bb85 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 155 | /// \brief Create a macro expansion cursor. |
| 156 | CXCursor MakeMacroExpansionCursor(MacroExpansion *, |
| 157 | CXTranslationUnit TU); |
Douglas Gregor | 4807231 | 2010-03-18 15:23:44 +0000 | [diff] [blame] | 158 | |
Argyrios Kyrtzidis | 664b06f | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 159 | /// \brief Create a "pseudo" macro expansion cursor, using a macro definition |
| 160 | /// and a source location. |
| 161 | CXCursor MakeMacroExpansionCursor(MacroDefinition *, SourceLocation Loc, |
| 162 | CXTranslationUnit TU); |
| 163 | |
| 164 | /// \brief Wraps a macro expansion cursor and provides a common interface |
| 165 | /// for a normal macro expansion cursor or a "pseudo" one. |
| 166 | /// |
| 167 | /// "Pseudo" macro expansion cursors (essentially a macro definition along with |
| 168 | /// a source location) are created in special cases, for example they can be |
| 169 | /// created for identifiers inside macro definitions, if these identifiers are |
| 170 | /// macro names. |
| 171 | class MacroExpansionCursor { |
| 172 | CXCursor C; |
| 173 | |
| 174 | bool isPseudo() const { |
| 175 | return C.data[1] != 0; |
| 176 | } |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame^] | 177 | const MacroDefinition *getAsMacroDefinition() const { |
Argyrios Kyrtzidis | 664b06f | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 178 | assert(isPseudo()); |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame^] | 179 | return static_cast<const MacroDefinition *>(C.data[0]); |
Argyrios Kyrtzidis | 664b06f | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 180 | } |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame^] | 181 | const MacroExpansion *getAsMacroExpansion() const { |
Argyrios Kyrtzidis | 664b06f | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 182 | assert(!isPseudo()); |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame^] | 183 | return static_cast<const MacroExpansion *>(C.data[0]); |
Argyrios Kyrtzidis | 664b06f | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 184 | } |
| 185 | SourceLocation getPseudoLoc() const { |
| 186 | assert(isPseudo()); |
| 187 | return SourceLocation::getFromPtrEncoding(C.data[1]); |
| 188 | } |
| 189 | |
| 190 | public: |
| 191 | MacroExpansionCursor(CXCursor C) : C(C) { |
| 192 | assert(C.kind == CXCursor_MacroExpansion); |
| 193 | } |
| 194 | |
| 195 | const IdentifierInfo *getName() const; |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame^] | 196 | const MacroDefinition *getDefinition() const; |
Argyrios Kyrtzidis | 664b06f | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 197 | SourceRange getSourceRange() const; |
| 198 | }; |
| 199 | |
| 200 | /// \brief Unpack a given macro expansion cursor to retrieve its info. |
| 201 | static inline MacroExpansionCursor getCursorMacroExpansion(CXCursor C) { |
| 202 | return C; |
| 203 | } |
Douglas Gregor | 4807231 | 2010-03-18 15:23:44 +0000 | [diff] [blame] | 204 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 205 | /// \brief Create an inclusion directive cursor. |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 206 | CXCursor MakeInclusionDirectiveCursor(InclusionDirective *, |
| 207 | CXTranslationUnit TU); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 208 | |
| 209 | /// \brief Unpack a given inclusion directive cursor to retrieve its |
| 210 | /// source range. |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame^] | 211 | const InclusionDirective *getCursorInclusionDirective(CXCursor C); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 212 | |
Douglas Gregor | 36897b0 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 213 | /// \brief Create a label reference at the given location. |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 214 | CXCursor MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc, |
| 215 | CXTranslationUnit TU); |
Douglas Gregor | 36897b0 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 216 | |
| 217 | /// \brief Unpack a label reference into the label statement it refers to and |
| 218 | /// the location of the reference. |
Dmitri Gribenko | 67812b2 | 2013-01-11 21:01:49 +0000 | [diff] [blame^] | 219 | std::pair<const LabelStmt *, SourceLocation> getCursorLabelRef(CXCursor C); |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 220 | |
| 221 | /// \brief Create a overloaded declaration reference cursor for an expression. |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 222 | CXCursor MakeCursorOverloadedDeclRef(OverloadExpr *E, CXTranslationUnit TU); |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 223 | |
| 224 | /// \brief Create a overloaded declaration reference cursor for a declaration. |
| 225 | CXCursor MakeCursorOverloadedDeclRef(Decl *D, SourceLocation Location, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 226 | CXTranslationUnit TU); |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 227 | |
| 228 | /// \brief Create a overloaded declaration reference cursor for a template name. |
| 229 | CXCursor MakeCursorOverloadedDeclRef(TemplateName Template, |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 230 | SourceLocation Location, |
| 231 | CXTranslationUnit TU); |
Douglas Gregor | 1f60d9e | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 232 | |
| 233 | /// \brief Internal storage for an overloaded declaration reference cursor; |
| 234 | typedef llvm::PointerUnion3<OverloadExpr *, Decl *, |
| 235 | OverloadedTemplateStorage *> |
| 236 | OverloadedDeclRefStorage; |
| 237 | |
| 238 | /// \brief Unpack an overloaded declaration reference into an expression, |
| 239 | /// declaration, or template name along with the source location. |
| 240 | std::pair<OverloadedDeclRefStorage, SourceLocation> |
| 241 | getCursorOverloadedDeclRef(CXCursor C); |
Douglas Gregor | 36897b0 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 242 | |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 243 | Decl *getCursorDecl(CXCursor Cursor); |
| 244 | Expr *getCursorExpr(CXCursor Cursor); |
| 245 | Stmt *getCursorStmt(CXCursor Cursor); |
Ted Kremenek | 95f3355 | 2010-08-26 01:42:22 +0000 | [diff] [blame] | 246 | Attr *getCursorAttr(CXCursor Cursor); |
Argyrios Kyrtzidis | 8ccac3d | 2011-06-29 22:20:07 +0000 | [diff] [blame] | 247 | Decl *getCursorParentDecl(CXCursor Cursor); |
Ted Kremenek | 95f3355 | 2010-08-26 01:42:22 +0000 | [diff] [blame] | 248 | |
Douglas Gregor | f46034a | 2010-01-18 23:41:10 +0000 | [diff] [blame] | 249 | ASTContext &getCursorContext(CXCursor Cursor); |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 250 | ASTUnit *getCursorASTUnit(CXCursor Cursor); |
Ted Kremenek | a60ed47 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 251 | CXTranslationUnit getCursorTU(CXCursor Cursor); |
Argyrios Kyrtzidis | b11be04 | 2011-10-06 07:00:46 +0000 | [diff] [blame] | 252 | |
| 253 | void getOverriddenCursors(CXCursor cursor, |
Ted Kremenek | bbf66ca | 2012-04-30 19:06:49 +0000 | [diff] [blame] | 254 | SmallVectorImpl<CXCursor> &overridden); |
| 255 | |
| 256 | /// \brief Create an opaque pool used for fast generation of overriden |
| 257 | /// CXCursor arrays. |
| 258 | void *createOverridenCXCursorsPool(); |
Argyrios Kyrtzidis | b11be04 | 2011-10-06 07:00:46 +0000 | [diff] [blame] | 259 | |
Ted Kremenek | bbf66ca | 2012-04-30 19:06:49 +0000 | [diff] [blame] | 260 | /// \brief Dispose of the overriden CXCursors pool. |
| 261 | void disposeOverridenCXCursorsPool(void *pool); |
| 262 | |
Argyrios Kyrtzidis | aed123e | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 263 | /// \brief Returns a index/location pair for a selector identifier if the cursor |
| 264 | /// points to one. |
| 265 | std::pair<int, SourceLocation> getSelectorIdentifierIndexAndLoc(CXCursor); |
| 266 | static inline int getSelectorIdentifierIndex(CXCursor cursor) { |
| 267 | return getSelectorIdentifierIndexAndLoc(cursor).first; |
| 268 | } |
| 269 | static inline SourceLocation getSelectorIdentifierLoc(CXCursor cursor) { |
| 270 | return getSelectorIdentifierIndexAndLoc(cursor).second; |
| 271 | } |
| 272 | |
| 273 | CXCursor getSelectorIdentifierCursor(int SelIdx, CXCursor cursor); |
| 274 | |
| 275 | static inline CXCursor getTypeRefedCallExprCursor(CXCursor cursor) { |
| 276 | CXCursor newCursor = cursor; |
| 277 | if (cursor.kind == CXCursor_CallExpr) |
| 278 | newCursor.xdata = 1; |
| 279 | return newCursor; |
| 280 | } |
| 281 | |
| 282 | CXCursor getTypeRefCursor(CXCursor cursor); |
| 283 | |
Argyrios Kyrtzidis | b6a4ac4 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 284 | /// \brief Generate a USR for \arg D and put it in \arg Buf. |
| 285 | /// \returns true if no USR was computed or the result should be ignored, |
| 286 | /// false otherwise. |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 287 | bool getDeclCursorUSR(const Decl *D, SmallVectorImpl<char> &Buf); |
Argyrios Kyrtzidis | b6a4ac4 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 288 | |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 289 | bool operator==(CXCursor X, CXCursor Y); |
| 290 | |
| 291 | inline bool operator!=(CXCursor X, CXCursor Y) { |
| 292 | return !(X == Y); |
| 293 | } |
| 294 | |
Ted Kremenek | 007a7c9 | 2010-11-01 23:26:51 +0000 | [diff] [blame] | 295 | /// \brief Return true if the cursor represents a declaration that is the |
| 296 | /// first in a declaration group. |
| 297 | bool isFirstInDeclGroup(CXCursor C); |
| 298 | |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 299 | }} // end namespace: clang::cxcursor |
| 300 | |
| 301 | #endif |