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