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