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