CXCursor.h revision 3064ef9e604d19a0cfd0d8e3ed3055bfd83f88fd
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 15#define LLVM_CLANG_CXCURSOR_H 16 17#include "clang-c/Index.h" 18#include "clang/Basic/SourceLocation.h" 19#include <utility> 20 21namespace clang { 22 23class ASTContext; 24class ASTUnit; 25class Attr; 26class CXXBaseSpecifier; 27class Decl; 28class Expr; 29class MacroDefinition; 30class MacroInstantiation; 31class NamedDecl; 32class ObjCInterfaceDecl; 33class ObjCProtocolDecl; 34class Stmt; 35class TypeDecl; 36 37namespace cxcursor { 38 39CXCursor MakeCXCursor(const clang::Attr *A, clang::Decl *Parent, ASTUnit *TU); 40CXCursor MakeCXCursor(clang::Decl *D, ASTUnit *TU); 41CXCursor MakeCXCursor(clang::Stmt *S, clang::Decl *Parent, ASTUnit *TU); 42CXCursor MakeCXCursorInvalid(CXCursorKind K); 43 44/// \brief Create an Objective-C superclass reference at the given location. 45CXCursor MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super, 46 SourceLocation Loc, 47 ASTUnit *TU); 48 49/// \brief Unpack an ObjCSuperClassRef cursor into the interface it references 50/// and optionally the location where the reference occurred. 51std::pair<ObjCInterfaceDecl *, SourceLocation> 52 getCursorObjCSuperClassRef(CXCursor C); 53 54/// \brief Create an Objective-C protocol reference at the given location. 55CXCursor MakeCursorObjCProtocolRef(ObjCProtocolDecl *Proto, SourceLocation Loc, 56 ASTUnit *TU); 57 58/// \brief Unpack an ObjCProtocolRef cursor into the protocol it references 59/// and optionally the location where the reference occurred. 60std::pair<ObjCProtocolDecl *, SourceLocation> 61 getCursorObjCProtocolRef(CXCursor C); 62 63/// \brief Create an Objective-C class reference at the given location. 64CXCursor MakeCursorObjCClassRef(ObjCInterfaceDecl *Class, SourceLocation Loc, 65 ASTUnit *TU); 66 67/// \brief Unpack an ObjCClassRef cursor into the class it references 68/// and optionally the location where the reference occurred. 69std::pair<ObjCInterfaceDecl *, SourceLocation> 70 getCursorObjCClassRef(CXCursor C); 71 72/// \brief Create a type reference at the given location. 73CXCursor MakeCursorTypeRef(TypeDecl *Type, SourceLocation Loc, ASTUnit *TU); 74 75/// \brief Unpack a TypeRef cursor into the class it references 76/// and optionally the location where the reference occurred. 77std::pair<TypeDecl *, SourceLocation> getCursorTypeRef(CXCursor C); 78 79/// \brief Create a CXX base specifier cursor. 80CXCursor MakeCursorCXXBaseSpecifier(CXXBaseSpecifier *B, ASTUnit *TU); 81 82/// \brief Unpack a CXXBaseSpecifier cursor into a CXXBaseSpecifier. 83CXXBaseSpecifier *getCursorCXXBaseSpecifier(CXCursor C); 84 85/// \brief Create a preprocessing directive cursor. 86CXCursor MakePreprocessingDirectiveCursor(SourceRange Range, ASTUnit *TU); 87 88/// \brief Unpack a given preprocessing directive to retrieve its source range. 89SourceRange getCursorPreprocessingDirective(CXCursor C); 90 91/// \brief Create a macro definition cursor. 92CXCursor MakeMacroDefinitionCursor(MacroDefinition *, ASTUnit *TU); 93 94/// \brief Unpack a given macro definition cursor to retrieve its 95/// source range. 96MacroDefinition *getCursorMacroDefinition(CXCursor C); 97 98/// \brief Create a macro instantiation cursor. 99CXCursor MakeMacroInstantiationCursor(MacroInstantiation *, ASTUnit *TU); 100 101/// \brief Unpack a given macro instantiation cursor to retrieve its 102/// source range. 103MacroInstantiation *getCursorMacroInstantiation(CXCursor C); 104 105Decl *getCursorDecl(CXCursor Cursor); 106Expr *getCursorExpr(CXCursor Cursor); 107Stmt *getCursorStmt(CXCursor Cursor); 108Attr *getCursorAttr(CXCursor Cursor); 109 110ASTContext &getCursorContext(CXCursor Cursor); 111ASTUnit *getCursorASTUnit(CXCursor Cursor); 112 113bool operator==(CXCursor X, CXCursor Y); 114 115inline bool operator!=(CXCursor X, CXCursor Y) { 116 return !(X == Y); 117} 118 119}} // end namespace: clang::cxcursor 120 121#endif 122