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 | |
Benjamin Kramer | 2f5db8b | 2014-08-13 16:25:19 +0000 | [diff] [blame] | 14 | #ifndef LLVM_CLANG_TOOLS_LIBCLANG_CXCURSOR_H |
| 15 | #define LLVM_CLANG_TOOLS_LIBCLANG_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 | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 31 | class InclusionDirective; |
Douglas Gregor | a93ab66 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 32 | class LabelStmt; |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 33 | class MacroDefinitionRecord; |
Chandler Carruth | a88a2218 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 34 | class MacroExpansion; |
Douglas Gregor | c58d05b | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 35 | class NamedDecl; |
Douglas Gregor | 6c8959b | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 36 | class ObjCInterfaceDecl; |
Douglas Gregor | ef6eb84 | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 37 | class ObjCProtocolDecl; |
Douglas Gregor | 16a2bdd | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 38 | class OverloadedTemplateStorage; |
| 39 | class OverloadExpr; |
Ted Kremenek | 87553c4 | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 40 | class Stmt; |
Douglas Gregor | a23e8f7 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 41 | class TemplateDecl; |
Douglas Gregor | 16a2bdd | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 42 | class TemplateName; |
Douglas Gregor | 93f8995 | 2010-01-21 16:28:34 +0000 | [diff] [blame] | 43 | class TypeDecl; |
Douglas Gregor | 3009383 | 2012-02-15 00:54:55 +0000 | [diff] [blame] | 44 | class VarDecl; |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 45 | class IdentifierInfo; |
Douglas Gregor | 16a2bdd | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 46 | |
Ted Kremenek | 87553c4 | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 47 | namespace cxcursor { |
Argyrios Kyrtzidis | fd51520 | 2011-09-27 00:30:33 +0000 | [diff] [blame] | 48 | |
| 49 | CXCursor getCursor(CXTranslationUnit, SourceLocation); |
Ted Kremenek | 87553c4 | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 50 | |
Dmitri Gribenko | 9c256e3 | 2013-01-14 00:46:27 +0000 | [diff] [blame] | 51 | CXCursor MakeCXCursor(const clang::Attr *A, const clang::Decl *Parent, |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 52 | CXTranslationUnit TU); |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 53 | CXCursor MakeCXCursor(const clang::Decl *D, CXTranslationUnit TU, |
Argyrios Kyrtzidis | cddafd3 | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 54 | SourceRange RegionOfInterest = SourceRange(), |
Ted Kremenek | 818e5c1 | 2010-11-01 23:26:51 +0000 | [diff] [blame] | 55 | bool FirstInDeclGroup = true); |
Dmitri Gribenko | 9c256e3 | 2013-01-14 00:46:27 +0000 | [diff] [blame] | 56 | CXCursor MakeCXCursor(const clang::Stmt *S, const clang::Decl *Parent, |
Argyrios Kyrtzidis | cddafd3 | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 57 | CXTranslationUnit TU, |
| 58 | SourceRange RegionOfInterest = SourceRange()); |
Craig Topper | 69186e7 | 2014-06-08 08:38:04 +0000 | [diff] [blame] | 59 | CXCursor MakeCXCursorInvalid(CXCursorKind K, CXTranslationUnit TU = nullptr); |
Ted Kremenek | 87553c4 | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 60 | |
Douglas Gregor | 6c8959b | 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 | fed36b1 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 63 | SourceLocation Loc, |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 64 | CXTranslationUnit TU); |
Douglas Gregor | 6c8959b | 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 | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 68 | std::pair<const ObjCInterfaceDecl *, SourceLocation> |
Douglas Gregor | ef6eb84 | 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 | dc199a3 | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 72 | CXCursor MakeCursorObjCProtocolRef(const ObjCProtocolDecl *Proto, |
| 73 | SourceLocation Loc, |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 74 | CXTranslationUnit TU); |
Douglas Gregor | ef6eb84 | 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 | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 78 | std::pair<const ObjCProtocolDecl *, SourceLocation> |
Douglas Gregor | ef6eb84 | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 79 | getCursorObjCProtocolRef(CXCursor C); |
Douglas Gregor | 6c8959b | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 80 | |
Douglas Gregor | 46d6614 | 2010-01-16 17:14:40 +0000 | [diff] [blame] | 81 | /// \brief Create an Objective-C class reference at the given location. |
Argyrios Kyrtzidis | dc199a3 | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 82 | CXCursor MakeCursorObjCClassRef(const ObjCInterfaceDecl *Class, |
| 83 | SourceLocation Loc, |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 84 | CXTranslationUnit TU); |
Douglas Gregor | 46d6614 | 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 | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 88 | std::pair<const ObjCInterfaceDecl *, SourceLocation> |
Douglas Gregor | 46d6614 | 2010-01-16 17:14:40 +0000 | [diff] [blame] | 89 | getCursorObjCClassRef(CXCursor C); |
| 90 | |
Douglas Gregor | 93f8995 | 2010-01-21 16:28:34 +0000 | [diff] [blame] | 91 | /// \brief Create a type reference at the given location. |
Argyrios Kyrtzidis | dc199a3 | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 92 | CXCursor MakeCursorTypeRef(const TypeDecl *Type, SourceLocation Loc, |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 93 | CXTranslationUnit TU); |
Douglas Gregor | a23e8f7 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 94 | |
Douglas Gregor | 93f8995 | 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 | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 97 | std::pair<const TypeDecl *, SourceLocation> getCursorTypeRef(CXCursor C); |
Douglas Gregor | 93f8995 | 2010-01-21 16:28:34 +0000 | [diff] [blame] | 98 | |
Douglas Gregor | a23e8f7 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 99 | /// \brief Create a reference to a template at the given location. |
Argyrios Kyrtzidis | effdbf5 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 100 | CXCursor MakeCursorTemplateRef(const TemplateDecl *Template, SourceLocation Loc, |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 101 | CXTranslationUnit TU); |
Douglas Gregor | a23e8f7 | 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 | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 105 | std::pair<const TemplateDecl *, SourceLocation> |
| 106 | getCursorTemplateRef(CXCursor C); |
Douglas Gregor | a89314e | 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 | effdbf5 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 110 | CXCursor MakeCursorNamespaceRef(const NamedDecl *NS, SourceLocation Loc, |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 111 | CXTranslationUnit TU); |
Douglas Gregor | a89314e | 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 | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 115 | std::pair<const NamedDecl *, SourceLocation> getCursorNamespaceRef(CXCursor C); |
Douglas Gregor | a89314e | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 116 | |
Douglas Gregor | 3009383 | 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 | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 123 | std::pair<const VarDecl *, SourceLocation> getCursorVariableRef(CXCursor C); |
Douglas Gregor | 3009383 | 2012-02-15 00:54:55 +0000 | [diff] [blame] | 124 | |
Douglas Gregor | f3af311 | 2010-09-09 21:42:20 +0000 | [diff] [blame] | 125 | /// \brief Create a reference to a field at the given location. |
Argyrios Kyrtzidis | effdbf5 | 2011-11-18 00:26:51 +0000 | [diff] [blame] | 126 | CXCursor MakeCursorMemberRef(const FieldDecl *Field, SourceLocation Loc, |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 127 | CXTranslationUnit TU); |
Douglas Gregor | f3af311 | 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 | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 131 | std::pair<const FieldDecl *, SourceLocation> getCursorMemberRef(CXCursor C); |
Douglas Gregor | f3af311 | 2010-09-09 21:42:20 +0000 | [diff] [blame] | 132 | |
Ted Kremenek | ae9e221 | 2010-08-27 21:34:58 +0000 | [diff] [blame] | 133 | /// \brief Create a CXX base specifier cursor. |
Argyrios Kyrtzidis | 4c910b1 | 2011-11-22 07:24:51 +0000 | [diff] [blame] | 134 | CXCursor MakeCursorCXXBaseSpecifier(const CXXBaseSpecifier *B, |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 135 | CXTranslationUnit TU); |
Ted Kremenek | ae9e221 | 2010-08-27 21:34:58 +0000 | [diff] [blame] | 136 | |
| 137 | /// \brief Unpack a CXXBaseSpecifier cursor into a CXXBaseSpecifier. |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 138 | const CXXBaseSpecifier *getCursorCXXBaseSpecifier(CXCursor C); |
Ted Kremenek | ae9e221 | 2010-08-27 21:34:58 +0000 | [diff] [blame] | 139 | |
Douglas Gregor | 92a524f | 2010-03-18 00:42:48 +0000 | [diff] [blame] | 140 | /// \brief Create a preprocessing directive cursor. |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 141 | CXCursor MakePreprocessingDirectiveCursor(SourceRange Range, |
| 142 | CXTranslationUnit TU); |
Douglas Gregor | 92a524f | 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 | 02ded2a | 2010-03-18 15:23:44 +0000 | [diff] [blame] | 146 | |
Douglas Gregor | 06d6d32 | 2010-03-18 18:04:21 +0000 | [diff] [blame] | 147 | /// \brief Create a macro definition cursor. |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 148 | CXCursor MakeMacroDefinitionCursor(const MacroDefinitionRecord *, |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 149 | CXTranslationUnit TU); |
Douglas Gregor | 06d6d32 | 2010-03-18 18:04:21 +0000 | [diff] [blame] | 150 | |
| 151 | /// \brief Unpack a given macro definition cursor to retrieve its |
| 152 | /// source range. |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 153 | const MacroDefinitionRecord *getCursorMacroDefinition(CXCursor C); |
Douglas Gregor | 06d6d32 | 2010-03-18 18:04:21 +0000 | [diff] [blame] | 154 | |
Chandler Carruth | a88a2218 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 155 | /// \brief Create a macro expansion cursor. |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 156 | CXCursor MakeMacroExpansionCursor(MacroExpansion *, CXTranslationUnit TU); |
Douglas Gregor | 02ded2a | 2010-03-18 15:23:44 +0000 | [diff] [blame] | 157 | |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 158 | /// \brief Create a "pseudo" macro expansion cursor, using a macro definition |
| 159 | /// and a source location. |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 160 | CXCursor MakeMacroExpansionCursor(MacroDefinitionRecord *, SourceLocation Loc, |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 161 | CXTranslationUnit TU); |
| 162 | |
| 163 | /// \brief Wraps a macro expansion cursor and provides a common interface |
| 164 | /// for a normal macro expansion cursor or a "pseudo" one. |
| 165 | /// |
| 166 | /// "Pseudo" macro expansion cursors (essentially a macro definition along with |
| 167 | /// a source location) are created in special cases, for example they can be |
| 168 | /// created for identifiers inside macro definitions, if these identifiers are |
| 169 | /// macro names. |
| 170 | class MacroExpansionCursor { |
| 171 | CXCursor C; |
| 172 | |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 173 | bool isPseudo() const { return C.data[1] != nullptr; } |
| 174 | const MacroDefinitionRecord *getAsMacroDefinition() const { |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 175 | assert(isPseudo()); |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 176 | return static_cast<const MacroDefinitionRecord *>(C.data[0]); |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 177 | } |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 178 | const MacroExpansion *getAsMacroExpansion() const { |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 179 | assert(!isPseudo()); |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 180 | return static_cast<const MacroExpansion *>(C.data[0]); |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 181 | } |
| 182 | SourceLocation getPseudoLoc() const { |
| 183 | assert(isPseudo()); |
| 184 | return SourceLocation::getFromPtrEncoding(C.data[1]); |
| 185 | } |
| 186 | |
| 187 | public: |
| 188 | MacroExpansionCursor(CXCursor C) : C(C) { |
| 189 | assert(C.kind == CXCursor_MacroExpansion); |
| 190 | } |
| 191 | |
| 192 | const IdentifierInfo *getName() const; |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 193 | const MacroDefinitionRecord *getDefinition() const; |
Argyrios Kyrtzidis | 579825a | 2013-01-07 19:16:25 +0000 | [diff] [blame] | 194 | SourceRange getSourceRange() const; |
| 195 | }; |
| 196 | |
| 197 | /// \brief Unpack a given macro expansion cursor to retrieve its info. |
| 198 | static inline MacroExpansionCursor getCursorMacroExpansion(CXCursor C) { |
| 199 | return C; |
| 200 | } |
Douglas Gregor | 02ded2a | 2010-03-18 15:23:44 +0000 | [diff] [blame] | 201 | |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 202 | /// \brief Create an inclusion directive cursor. |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 203 | CXCursor MakeInclusionDirectiveCursor(InclusionDirective *, |
| 204 | CXTranslationUnit TU); |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 205 | |
| 206 | /// \brief Unpack a given inclusion directive cursor to retrieve its |
| 207 | /// source range. |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 208 | const InclusionDirective *getCursorInclusionDirective(CXCursor C); |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 209 | |
Douglas Gregor | a93ab66 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 210 | /// \brief Create a label reference at the given location. |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 211 | CXCursor MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc, |
| 212 | CXTranslationUnit TU); |
Douglas Gregor | a93ab66 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 213 | |
| 214 | /// \brief Unpack a label reference into the label statement it refers to and |
| 215 | /// the location of the reference. |
Dmitri Gribenko | ba2f746 | 2013-01-11 21:01:49 +0000 | [diff] [blame] | 216 | std::pair<const LabelStmt *, SourceLocation> getCursorLabelRef(CXCursor C); |
Douglas Gregor | 16a2bdd | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 217 | |
| 218 | /// \brief Create a overloaded declaration reference cursor for an expression. |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 219 | CXCursor MakeCursorOverloadedDeclRef(const OverloadExpr *E, |
| 220 | CXTranslationUnit TU); |
Douglas Gregor | 16a2bdd | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 221 | |
| 222 | /// \brief Create a overloaded declaration reference cursor for a declaration. |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 223 | CXCursor MakeCursorOverloadedDeclRef(const Decl *D, SourceLocation Location, |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 224 | CXTranslationUnit TU); |
Douglas Gregor | 16a2bdd | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 225 | |
| 226 | /// \brief Create a overloaded declaration reference cursor for a template name. |
| 227 | CXCursor MakeCursorOverloadedDeclRef(TemplateName Template, |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 228 | SourceLocation Location, |
| 229 | CXTranslationUnit TU); |
Douglas Gregor | 16a2bdd | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 230 | |
| 231 | /// \brief Internal storage for an overloaded declaration reference cursor; |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 232 | typedef llvm::PointerUnion3<const OverloadExpr *, const Decl *, |
Douglas Gregor | 16a2bdd | 2010-09-13 22:52:57 +0000 | [diff] [blame] | 233 | OverloadedTemplateStorage *> |
| 234 | OverloadedDeclRefStorage; |
| 235 | |
| 236 | /// \brief Unpack an overloaded declaration reference into an expression, |
| 237 | /// declaration, or template name along with the source location. |
| 238 | std::pair<OverloadedDeclRefStorage, SourceLocation> |
| 239 | getCursorOverloadedDeclRef(CXCursor C); |
Douglas Gregor | a93ab66 | 2010-09-10 00:22:18 +0000 | [diff] [blame] | 240 | |
Dmitri Gribenko | d15bb30 | 2013-01-23 17:25:27 +0000 | [diff] [blame] | 241 | const Decl *getCursorDecl(CXCursor Cursor); |
Dmitri Gribenko | e835406 | 2013-01-26 15:29:08 +0000 | [diff] [blame] | 242 | const Expr *getCursorExpr(CXCursor Cursor); |
| 243 | const Stmt *getCursorStmt(CXCursor Cursor); |
Dmitri Gribenko | e4baea6 | 2013-01-26 18:08:08 +0000 | [diff] [blame] | 244 | const Attr *getCursorAttr(CXCursor Cursor); |
Dmitri Gribenko | a169118 | 2013-01-26 18:12:08 +0000 | [diff] [blame] | 245 | const Decl *getCursorParentDecl(CXCursor Cursor); |
Ted Kremenek | a594082 | 2010-08-26 01:42:22 +0000 | [diff] [blame] | 246 | |
Douglas Gregor | 7ecd020 | 2010-01-18 23:41:10 +0000 | [diff] [blame] | 247 | ASTContext &getCursorContext(CXCursor Cursor); |
Douglas Gregor | fed36b1 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 248 | ASTUnit *getCursorASTUnit(CXCursor Cursor); |
Ted Kremenek | 9155428 | 2010-11-16 08:15:36 +0000 | [diff] [blame] | 249 | CXTranslationUnit getCursorTU(CXCursor Cursor); |
Argyrios Kyrtzidis | 3b947f7 | 2011-10-06 07:00:46 +0000 | [diff] [blame] | 250 | |
| 251 | void getOverriddenCursors(CXCursor cursor, |
Ted Kremenek | d77f621 | 2012-04-30 19:06:49 +0000 | [diff] [blame] | 252 | SmallVectorImpl<CXCursor> &overridden); |
| 253 | |
| 254 | /// \brief Create an opaque pool used for fast generation of overriden |
| 255 | /// CXCursor arrays. |
| 256 | void *createOverridenCXCursorsPool(); |
Argyrios Kyrtzidis | 3b947f7 | 2011-10-06 07:00:46 +0000 | [diff] [blame] | 257 | |
Ted Kremenek | d77f621 | 2012-04-30 19:06:49 +0000 | [diff] [blame] | 258 | /// \brief Dispose of the overriden CXCursors pool. |
| 259 | void disposeOverridenCXCursorsPool(void *pool); |
| 260 | |
Argyrios Kyrtzidis | cddafd3 | 2011-10-06 07:00:54 +0000 | [diff] [blame] | 261 | /// \brief Returns a index/location pair for a selector identifier if the cursor |
| 262 | /// points to one. |
| 263 | std::pair<int, SourceLocation> getSelectorIdentifierIndexAndLoc(CXCursor); |
| 264 | static inline int getSelectorIdentifierIndex(CXCursor cursor) { |
| 265 | return getSelectorIdentifierIndexAndLoc(cursor).first; |
| 266 | } |
| 267 | static inline SourceLocation getSelectorIdentifierLoc(CXCursor cursor) { |
| 268 | return getSelectorIdentifierIndexAndLoc(cursor).second; |
| 269 | } |
| 270 | |
| 271 | CXCursor getSelectorIdentifierCursor(int SelIdx, CXCursor cursor); |
| 272 | |
| 273 | static inline CXCursor getTypeRefedCallExprCursor(CXCursor cursor) { |
| 274 | CXCursor newCursor = cursor; |
| 275 | if (cursor.kind == CXCursor_CallExpr) |
| 276 | newCursor.xdata = 1; |
| 277 | return newCursor; |
| 278 | } |
| 279 | |
| 280 | CXCursor getTypeRefCursor(CXCursor cursor); |
| 281 | |
Argyrios Kyrtzidis | e454986 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 282 | /// \brief Generate a USR for \arg D and put it in \arg Buf. |
| 283 | /// \returns true if no USR was computed or the result should be ignored, |
| 284 | /// false otherwise. |
Argyrios Kyrtzidis | dc199a3 | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 285 | bool getDeclCursorUSR(const Decl *D, SmallVectorImpl<char> &Buf); |
Argyrios Kyrtzidis | e454986 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 286 | |
Douglas Gregor | c58d05b | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 287 | bool operator==(CXCursor X, CXCursor Y); |
| 288 | |
| 289 | inline bool operator!=(CXCursor X, CXCursor Y) { |
| 290 | return !(X == Y); |
| 291 | } |
| 292 | |
Ted Kremenek | 818e5c1 | 2010-11-01 23:26:51 +0000 | [diff] [blame] | 293 | /// \brief Return true if the cursor represents a declaration that is the |
| 294 | /// first in a declaration group. |
| 295 | bool isFirstInDeclGroup(CXCursor C); |
| 296 | |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 297 | }} // end namespace: clang::cxcursor |
Ted Kremenek | 87553c4 | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 298 | |
| 299 | #endif |