CXCursor.h revision ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0ed
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 "llvm/ADT/PointerUnion.h" 20#include <utility> 21 22namespace clang { 23 24class ASTContext; 25class ASTUnit; 26class Attr; 27class CXXBaseSpecifier; 28class Decl; 29class Expr; 30class FieldDecl; 31class InclusionDirective; 32class LabelStmt; 33class MacroDefinition; 34class MacroInstantiation; 35class NamedDecl; 36class ObjCInterfaceDecl; 37class ObjCProtocolDecl; 38class OverloadedTemplateStorage; 39class OverloadExpr; 40class Stmt; 41class TemplateDecl; 42class TemplateName; 43class TypeDecl; 44 45namespace cxcursor { 46 47CXCursor MakeCXCursor(const clang::Attr *A, clang::Decl *Parent, ASTUnit *TU); 48CXCursor MakeCXCursor(clang::Decl *D, ASTUnit *TU); 49CXCursor MakeCXCursor(clang::Stmt *S, clang::Decl *Parent, ASTUnit *TU); 50CXCursor MakeCXCursorInvalid(CXCursorKind K); 51 52/// \brief Create an Objective-C superclass reference at the given location. 53CXCursor MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super, 54 SourceLocation Loc, 55 ASTUnit *TU); 56 57/// \brief Unpack an ObjCSuperClassRef cursor into the interface it references 58/// and optionally the location where the reference occurred. 59std::pair<ObjCInterfaceDecl *, SourceLocation> 60 getCursorObjCSuperClassRef(CXCursor C); 61 62/// \brief Create an Objective-C protocol reference at the given location. 63CXCursor MakeCursorObjCProtocolRef(ObjCProtocolDecl *Proto, SourceLocation Loc, 64 ASTUnit *TU); 65 66/// \brief Unpack an ObjCProtocolRef cursor into the protocol it references 67/// and optionally the location where the reference occurred. 68std::pair<ObjCProtocolDecl *, SourceLocation> 69 getCursorObjCProtocolRef(CXCursor C); 70 71/// \brief Create an Objective-C class reference at the given location. 72CXCursor MakeCursorObjCClassRef(ObjCInterfaceDecl *Class, SourceLocation Loc, 73 ASTUnit *TU); 74 75/// \brief Unpack an ObjCClassRef cursor into the class it references 76/// and optionally the location where the reference occurred. 77std::pair<ObjCInterfaceDecl *, SourceLocation> 78 getCursorObjCClassRef(CXCursor C); 79 80/// \brief Create a type reference at the given location. 81CXCursor MakeCursorTypeRef(TypeDecl *Type, SourceLocation Loc, ASTUnit *TU); 82 83/// \brief Unpack a TypeRef cursor into the class it references 84/// and optionally the location where the reference occurred. 85std::pair<TypeDecl *, SourceLocation> getCursorTypeRef(CXCursor C); 86 87/// \brief Create a reference to a template at the given location. 88CXCursor MakeCursorTemplateRef(TemplateDecl *Template, SourceLocation Loc, 89 ASTUnit *TU); 90 91/// \brief Unpack a TemplateRef cursor into the template it references and 92/// the location where the reference occurred. 93std::pair<TemplateDecl *, SourceLocation> getCursorTemplateRef(CXCursor C); 94 95/// \brief Create a reference to a namespace or namespace alias at the given 96/// location. 97CXCursor MakeCursorNamespaceRef(NamedDecl *NS, SourceLocation Loc, ASTUnit *TU); 98 99/// \brief Unpack a NamespaceRef cursor into the namespace or namespace alias 100/// it references and the location where the reference occurred. 101std::pair<NamedDecl *, SourceLocation> getCursorNamespaceRef(CXCursor C); 102 103/// \brief Create a reference to a field at the given location. 104CXCursor MakeCursorMemberRef(FieldDecl *Field, SourceLocation Loc, 105 ASTUnit *TU); 106 107/// \brief Unpack a MemberRef cursor into the field it references and the 108/// location where the reference occurred. 109std::pair<FieldDecl *, SourceLocation> getCursorMemberRef(CXCursor C); 110 111/// \brief Create a CXX base specifier cursor. 112CXCursor MakeCursorCXXBaseSpecifier(CXXBaseSpecifier *B, ASTUnit *TU); 113 114/// \brief Unpack a CXXBaseSpecifier cursor into a CXXBaseSpecifier. 115CXXBaseSpecifier *getCursorCXXBaseSpecifier(CXCursor C); 116 117/// \brief Create a preprocessing directive cursor. 118CXCursor MakePreprocessingDirectiveCursor(SourceRange Range, ASTUnit *TU); 119 120/// \brief Unpack a given preprocessing directive to retrieve its source range. 121SourceRange getCursorPreprocessingDirective(CXCursor C); 122 123/// \brief Create a macro definition cursor. 124CXCursor MakeMacroDefinitionCursor(MacroDefinition *, ASTUnit *TU); 125 126/// \brief Unpack a given macro definition cursor to retrieve its 127/// source range. 128MacroDefinition *getCursorMacroDefinition(CXCursor C); 129 130/// \brief Create a macro instantiation cursor. 131CXCursor MakeMacroInstantiationCursor(MacroInstantiation *, ASTUnit *TU); 132 133/// \brief Unpack a given macro instantiation cursor to retrieve its 134/// source range. 135MacroInstantiation *getCursorMacroInstantiation(CXCursor C); 136 137/// \brief Create an inclusion directive cursor. 138CXCursor MakeInclusionDirectiveCursor(InclusionDirective *, ASTUnit *TU); 139 140/// \brief Unpack a given inclusion directive cursor to retrieve its 141/// source range. 142InclusionDirective *getCursorInclusionDirective(CXCursor C); 143 144/// \brief Create a label reference at the given location. 145CXCursor MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc, ASTUnit *TU); 146 147/// \brief Unpack a label reference into the label statement it refers to and 148/// the location of the reference. 149std::pair<LabelStmt *, SourceLocation> getCursorLabelRef(CXCursor C); 150 151/// \brief Create a overloaded declaration reference cursor for an expression. 152CXCursor MakeCursorOverloadedDeclRef(OverloadExpr *E, ASTUnit *TU); 153 154/// \brief Create a overloaded declaration reference cursor for a declaration. 155CXCursor MakeCursorOverloadedDeclRef(Decl *D, SourceLocation Location, 156 ASTUnit *TU); 157 158/// \brief Create a overloaded declaration reference cursor for a template name. 159CXCursor MakeCursorOverloadedDeclRef(TemplateName Template, 160 SourceLocation Location, ASTUnit *TU); 161 162/// \brief Internal storage for an overloaded declaration reference cursor; 163typedef llvm::PointerUnion3<OverloadExpr *, Decl *, 164 OverloadedTemplateStorage *> 165 OverloadedDeclRefStorage; 166 167/// \brief Unpack an overloaded declaration reference into an expression, 168/// declaration, or template name along with the source location. 169std::pair<OverloadedDeclRefStorage, SourceLocation> 170 getCursorOverloadedDeclRef(CXCursor C); 171 172Decl *getCursorDecl(CXCursor Cursor); 173Expr *getCursorExpr(CXCursor Cursor); 174Stmt *getCursorStmt(CXCursor Cursor); 175Attr *getCursorAttr(CXCursor Cursor); 176 177ASTContext &getCursorContext(CXCursor Cursor); 178ASTUnit *getCursorASTUnit(CXCursor Cursor); 179 180bool operator==(CXCursor X, CXCursor Y); 181 182inline bool operator!=(CXCursor X, CXCursor Y) { 183 return !(X == Y); 184} 185 186}} // end namespace: clang::cxcursor 187 188#endif 189