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" |
| 19 | #include <utility> |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 20 | |
| 21 | namespace clang { |
| 22 | |
Douglas Gregor | f46034a | 2010-01-18 23:41:10 +0000 | [diff] [blame] | 23 | class ASTContext; |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 24 | class ASTUnit; |
Ted Kremenek | e77f443 | 2010-02-18 03:09:07 +0000 | [diff] [blame] | 25 | class Attr; |
Ted Kremenek | 3064ef9 | 2010-08-27 21:34:58 +0000 | [diff] [blame] | 26 | class CXXBaseSpecifier; |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 27 | class Decl; |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 28 | class Expr; |
Douglas Gregor | 572feb2 | 2010-03-18 18:04:21 +0000 | [diff] [blame] | 29 | class MacroDefinition; |
Douglas Gregor | 4ae8f29 | 2010-03-18 17:52:52 +0000 | [diff] [blame] | 30 | class MacroInstantiation; |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 31 | class NamedDecl; |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 32 | class ObjCInterfaceDecl; |
Douglas Gregor | 78db0cd | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 33 | class ObjCProtocolDecl; |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 34 | class Stmt; |
Douglas Gregor | 0b36e61 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 35 | class TemplateDecl; |
Douglas Gregor | 7d0d40e | 2010-01-21 16:28:34 +0000 | [diff] [blame] | 36 | class TypeDecl; |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 37 | |
| 38 | namespace cxcursor { |
| 39 | |
Ted Kremenek | e77f443 | 2010-02-18 03:09:07 +0000 | [diff] [blame] | 40 | CXCursor MakeCXCursor(const clang::Attr *A, clang::Decl *Parent, ASTUnit *TU); |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 41 | CXCursor MakeCXCursor(clang::Decl *D, ASTUnit *TU); |
Ted Kremenek | e77f443 | 2010-02-18 03:09:07 +0000 | [diff] [blame] | 42 | CXCursor MakeCXCursor(clang::Stmt *S, clang::Decl *Parent, ASTUnit *TU); |
| 43 | CXCursor MakeCXCursorInvalid(CXCursorKind K); |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 44 | |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 45 | /// \brief Create an Objective-C superclass reference at the given location. |
| 46 | CXCursor MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super, |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 47 | SourceLocation Loc, |
| 48 | ASTUnit *TU); |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 49 | |
| 50 | /// \brief Unpack an ObjCSuperClassRef cursor into the interface it references |
| 51 | /// and optionally the location where the reference occurred. |
| 52 | std::pair<ObjCInterfaceDecl *, SourceLocation> |
Douglas Gregor | 78db0cd | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 53 | getCursorObjCSuperClassRef(CXCursor C); |
| 54 | |
| 55 | /// \brief Create an Objective-C protocol reference at the given location. |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 56 | CXCursor MakeCursorObjCProtocolRef(ObjCProtocolDecl *Proto, SourceLocation Loc, |
| 57 | ASTUnit *TU); |
Douglas Gregor | 78db0cd | 2010-01-16 15:44:18 +0000 | [diff] [blame] | 58 | |
| 59 | /// \brief Unpack an ObjCProtocolRef cursor into the protocol it references |
| 60 | /// and optionally the location where the reference occurred. |
| 61 | std::pair<ObjCProtocolDecl *, SourceLocation> |
| 62 | getCursorObjCProtocolRef(CXCursor C); |
Douglas Gregor | 2e331b9 | 2010-01-16 14:00:32 +0000 | [diff] [blame] | 63 | |
Douglas Gregor | 1adb082 | 2010-01-16 17:14:40 +0000 | [diff] [blame] | 64 | /// \brief Create an Objective-C class reference at the given location. |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 65 | CXCursor MakeCursorObjCClassRef(ObjCInterfaceDecl *Class, SourceLocation Loc, |
| 66 | ASTUnit *TU); |
Douglas Gregor | 1adb082 | 2010-01-16 17:14:40 +0000 | [diff] [blame] | 67 | |
| 68 | /// \brief Unpack an ObjCClassRef cursor into the class it references |
| 69 | /// and optionally the location where the reference occurred. |
| 70 | std::pair<ObjCInterfaceDecl *, SourceLocation> |
| 71 | getCursorObjCClassRef(CXCursor C); |
| 72 | |
Douglas Gregor | 7d0d40e | 2010-01-21 16:28:34 +0000 | [diff] [blame] | 73 | /// \brief Create a type reference at the given location. |
| 74 | CXCursor MakeCursorTypeRef(TypeDecl *Type, SourceLocation Loc, ASTUnit *TU); |
Douglas Gregor | 0b36e61 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 75 | |
Douglas Gregor | 7d0d40e | 2010-01-21 16:28:34 +0000 | [diff] [blame] | 76 | /// \brief Unpack a TypeRef cursor into the class it references |
| 77 | /// and optionally the location where the reference occurred. |
| 78 | std::pair<TypeDecl *, SourceLocation> getCursorTypeRef(CXCursor C); |
| 79 | |
Douglas Gregor | 0b36e61 | 2010-08-31 20:37:03 +0000 | [diff] [blame] | 80 | /// \brief Create a reference to a template at the given location. |
| 81 | CXCursor MakeCursorTemplateRef(TemplateDecl *Template, SourceLocation Loc, |
| 82 | ASTUnit *TU); |
| 83 | |
| 84 | /// \brief Unpack a TemplateRef cursor into the template it references and |
| 85 | /// the location where the reference occurred. |
| 86 | std::pair<TemplateDecl *, SourceLocation> getCursorTemplateRef(CXCursor C); |
Douglas Gregor | 6931900 | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 87 | |
| 88 | /// \brief Create a reference to a namespace or namespace alias at the given |
| 89 | /// location. |
| 90 | CXCursor MakeCursorNamespaceRef(NamedDecl *NS, SourceLocation Loc, ASTUnit *TU); |
| 91 | |
| 92 | /// \brief Unpack a NamespaceRef cursor into the namespace or namespace alias |
| 93 | /// it references and the location where the reference occurred. |
| 94 | std::pair<NamedDecl *, SourceLocation> getCursorNamespaceRef(CXCursor C); |
| 95 | |
Ted Kremenek | 3064ef9 | 2010-08-27 21:34:58 +0000 | [diff] [blame] | 96 | /// \brief Create a CXX base specifier cursor. |
| 97 | CXCursor MakeCursorCXXBaseSpecifier(CXXBaseSpecifier *B, ASTUnit *TU); |
| 98 | |
| 99 | /// \brief Unpack a CXXBaseSpecifier cursor into a CXXBaseSpecifier. |
| 100 | CXXBaseSpecifier *getCursorCXXBaseSpecifier(CXCursor C); |
| 101 | |
Douglas Gregor | 9f1e3ff | 2010-03-18 00:42:48 +0000 | [diff] [blame] | 102 | /// \brief Create a preprocessing directive cursor. |
| 103 | CXCursor MakePreprocessingDirectiveCursor(SourceRange Range, ASTUnit *TU); |
| 104 | |
| 105 | /// \brief Unpack a given preprocessing directive to retrieve its source range. |
| 106 | SourceRange getCursorPreprocessingDirective(CXCursor C); |
Douglas Gregor | 4807231 | 2010-03-18 15:23:44 +0000 | [diff] [blame] | 107 | |
Douglas Gregor | 572feb2 | 2010-03-18 18:04:21 +0000 | [diff] [blame] | 108 | /// \brief Create a macro definition cursor. |
| 109 | CXCursor MakeMacroDefinitionCursor(MacroDefinition *, ASTUnit *TU); |
| 110 | |
| 111 | /// \brief Unpack a given macro definition cursor to retrieve its |
| 112 | /// source range. |
| 113 | MacroDefinition *getCursorMacroDefinition(CXCursor C); |
| 114 | |
Douglas Gregor | 4807231 | 2010-03-18 15:23:44 +0000 | [diff] [blame] | 115 | /// \brief Create a macro instantiation cursor. |
Douglas Gregor | 4ae8f29 | 2010-03-18 17:52:52 +0000 | [diff] [blame] | 116 | CXCursor MakeMacroInstantiationCursor(MacroInstantiation *, ASTUnit *TU); |
Douglas Gregor | 4807231 | 2010-03-18 15:23:44 +0000 | [diff] [blame] | 117 | |
| 118 | /// \brief Unpack a given macro instantiation cursor to retrieve its |
| 119 | /// source range. |
Douglas Gregor | 4ae8f29 | 2010-03-18 17:52:52 +0000 | [diff] [blame] | 120 | MacroInstantiation *getCursorMacroInstantiation(CXCursor C); |
Douglas Gregor | 4807231 | 2010-03-18 15:23:44 +0000 | [diff] [blame] | 121 | |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 122 | Decl *getCursorDecl(CXCursor Cursor); |
| 123 | Expr *getCursorExpr(CXCursor Cursor); |
| 124 | Stmt *getCursorStmt(CXCursor Cursor); |
Ted Kremenek | 95f3355 | 2010-08-26 01:42:22 +0000 | [diff] [blame] | 125 | Attr *getCursorAttr(CXCursor Cursor); |
| 126 | |
Douglas Gregor | f46034a | 2010-01-18 23:41:10 +0000 | [diff] [blame] | 127 | ASTContext &getCursorContext(CXCursor Cursor); |
Douglas Gregor | b2cd487 | 2010-01-20 23:57:43 +0000 | [diff] [blame] | 128 | ASTUnit *getCursorASTUnit(CXCursor Cursor); |
Douglas Gregor | 283cae3 | 2010-01-15 21:56:13 +0000 | [diff] [blame] | 129 | |
| 130 | bool operator==(CXCursor X, CXCursor Y); |
| 131 | |
| 132 | inline bool operator!=(CXCursor X, CXCursor Y) { |
| 133 | return !(X == Y); |
| 134 | } |
| 135 | |
Ted Kremenek | 16c440a | 2010-01-15 20:35:54 +0000 | [diff] [blame] | 136 | }} // end namespace: clang::cxcursor |
| 137 | |
| 138 | #endif |