2010-01-16 04:35:54 +08:00
|
|
|
//===- CXCursor.h - Routines for manipulating CXCursors -------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines routines for manipulating CXCursors.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:25:19 +08:00
|
|
|
#ifndef LLVM_CLANG_TOOLS_LIBCLANG_CXCURSOR_H
|
|
|
|
#define LLVM_CLANG_TOOLS_LIBCLANG_CXCURSOR_H
|
2010-01-16 04:35:54 +08:00
|
|
|
|
|
|
|
#include "clang-c/Index.h"
|
2010-01-16 22:00:32 +08:00
|
|
|
#include "clang/Basic/SourceLocation.h"
|
2010-09-14 06:52:57 +08:00
|
|
|
#include "llvm/ADT/PointerUnion.h"
|
2010-01-16 22:00:32 +08:00
|
|
|
#include <utility>
|
2010-01-16 04:35:54 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
|
2010-01-19 07:41:10 +08:00
|
|
|
class ASTContext;
|
2010-01-21 07:57:43 +08:00
|
|
|
class ASTUnit;
|
2010-02-18 11:09:07 +08:00
|
|
|
class Attr;
|
2010-08-28 05:34:58 +08:00
|
|
|
class CXXBaseSpecifier;
|
2010-01-16 04:35:54 +08:00
|
|
|
class Decl;
|
2010-01-16 05:56:13 +08:00
|
|
|
class Expr;
|
2010-09-10 05:42:20 +08:00
|
|
|
class FieldDecl;
|
2010-10-21 06:00:55 +08:00
|
|
|
class InclusionDirective;
|
2010-09-10 08:22:18 +08:00
|
|
|
class LabelStmt;
|
2015-05-04 10:25:31 +08:00
|
|
|
class MacroDefinitionRecord;
|
2011-07-14 16:20:46 +08:00
|
|
|
class MacroExpansion;
|
2010-01-16 05:56:13 +08:00
|
|
|
class NamedDecl;
|
2010-01-16 22:00:32 +08:00
|
|
|
class ObjCInterfaceDecl;
|
2010-01-16 23:44:18 +08:00
|
|
|
class ObjCProtocolDecl;
|
2010-09-14 06:52:57 +08:00
|
|
|
class OverloadedTemplateStorage;
|
|
|
|
class OverloadExpr;
|
2010-01-16 04:35:54 +08:00
|
|
|
class Stmt;
|
2010-09-01 04:37:03 +08:00
|
|
|
class TemplateDecl;
|
2010-09-14 06:52:57 +08:00
|
|
|
class TemplateName;
|
2010-01-22 00:28:34 +08:00
|
|
|
class TypeDecl;
|
2012-02-15 08:54:55 +08:00
|
|
|
class VarDecl;
|
2013-01-08 03:16:25 +08:00
|
|
|
class IdentifierInfo;
|
2010-09-14 06:52:57 +08:00
|
|
|
|
2010-01-16 04:35:54 +08:00
|
|
|
namespace cxcursor {
|
2011-09-27 08:30:33 +08:00
|
|
|
|
|
|
|
CXCursor getCursor(CXTranslationUnit, SourceLocation);
|
2010-01-16 04:35:54 +08:00
|
|
|
|
2013-01-14 08:46:27 +08:00
|
|
|
CXCursor MakeCXCursor(const clang::Attr *A, const clang::Decl *Parent,
|
2010-11-16 16:15:36 +08:00
|
|
|
CXTranslationUnit TU);
|
2013-01-12 05:01:49 +08:00
|
|
|
CXCursor MakeCXCursor(const clang::Decl *D, CXTranslationUnit TU,
|
2011-10-06 15:00:54 +08:00
|
|
|
SourceRange RegionOfInterest = SourceRange(),
|
2010-11-02 07:26:51 +08:00
|
|
|
bool FirstInDeclGroup = true);
|
2013-01-14 08:46:27 +08:00
|
|
|
CXCursor MakeCXCursor(const clang::Stmt *S, const clang::Decl *Parent,
|
2011-10-06 15:00:54 +08:00
|
|
|
CXTranslationUnit TU,
|
|
|
|
SourceRange RegionOfInterest = SourceRange());
|
2014-06-08 16:38:04 +08:00
|
|
|
CXCursor MakeCXCursorInvalid(CXCursorKind K, CXTranslationUnit TU = nullptr);
|
2010-01-16 04:35:54 +08:00
|
|
|
|
2010-01-16 22:00:32 +08:00
|
|
|
/// \brief Create an Objective-C superclass reference at the given location.
|
|
|
|
CXCursor MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super,
|
2010-01-21 07:57:43 +08:00
|
|
|
SourceLocation Loc,
|
2010-11-16 16:15:36 +08:00
|
|
|
CXTranslationUnit TU);
|
2010-01-16 22:00:32 +08:00
|
|
|
|
|
|
|
/// \brief Unpack an ObjCSuperClassRef cursor into the interface it references
|
|
|
|
/// and optionally the location where the reference occurred.
|
2013-01-12 05:01:49 +08:00
|
|
|
std::pair<const ObjCInterfaceDecl *, SourceLocation>
|
2010-01-16 23:44:18 +08:00
|
|
|
getCursorObjCSuperClassRef(CXCursor C);
|
|
|
|
|
|
|
|
/// \brief Create an Objective-C protocol reference at the given location.
|
2011-10-18 03:48:19 +08:00
|
|
|
CXCursor MakeCursorObjCProtocolRef(const ObjCProtocolDecl *Proto,
|
|
|
|
SourceLocation Loc,
|
2010-11-16 16:15:36 +08:00
|
|
|
CXTranslationUnit TU);
|
2010-01-16 23:44:18 +08:00
|
|
|
|
|
|
|
/// \brief Unpack an ObjCProtocolRef cursor into the protocol it references
|
|
|
|
/// and optionally the location where the reference occurred.
|
2013-01-12 05:01:49 +08:00
|
|
|
std::pair<const ObjCProtocolDecl *, SourceLocation>
|
2010-01-16 23:44:18 +08:00
|
|
|
getCursorObjCProtocolRef(CXCursor C);
|
2010-01-16 22:00:32 +08:00
|
|
|
|
2010-01-17 01:14:40 +08:00
|
|
|
/// \brief Create an Objective-C class reference at the given location.
|
2011-10-18 03:48:19 +08:00
|
|
|
CXCursor MakeCursorObjCClassRef(const ObjCInterfaceDecl *Class,
|
|
|
|
SourceLocation Loc,
|
2010-11-16 16:15:36 +08:00
|
|
|
CXTranslationUnit TU);
|
2010-01-17 01:14:40 +08:00
|
|
|
|
|
|
|
/// \brief Unpack an ObjCClassRef cursor into the class it references
|
|
|
|
/// and optionally the location where the reference occurred.
|
2013-01-12 05:01:49 +08:00
|
|
|
std::pair<const ObjCInterfaceDecl *, SourceLocation>
|
2010-01-17 01:14:40 +08:00
|
|
|
getCursorObjCClassRef(CXCursor C);
|
|
|
|
|
2010-01-22 00:28:34 +08:00
|
|
|
/// \brief Create a type reference at the given location.
|
2011-10-18 03:48:19 +08:00
|
|
|
CXCursor MakeCursorTypeRef(const TypeDecl *Type, SourceLocation Loc,
|
2010-11-16 16:15:36 +08:00
|
|
|
CXTranslationUnit TU);
|
2010-09-01 04:37:03 +08:00
|
|
|
|
2010-01-22 00:28:34 +08:00
|
|
|
/// \brief Unpack a TypeRef cursor into the class it references
|
|
|
|
/// and optionally the location where the reference occurred.
|
2013-01-12 05:01:49 +08:00
|
|
|
std::pair<const TypeDecl *, SourceLocation> getCursorTypeRef(CXCursor C);
|
2010-01-22 00:28:34 +08:00
|
|
|
|
2010-09-01 04:37:03 +08:00
|
|
|
/// \brief Create a reference to a template at the given location.
|
2011-11-18 08:26:51 +08:00
|
|
|
CXCursor MakeCursorTemplateRef(const TemplateDecl *Template, SourceLocation Loc,
|
2010-11-16 16:15:36 +08:00
|
|
|
CXTranslationUnit TU);
|
2010-09-01 04:37:03 +08:00
|
|
|
|
|
|
|
/// \brief Unpack a TemplateRef cursor into the template it references and
|
|
|
|
/// the location where the reference occurred.
|
2013-01-12 05:01:49 +08:00
|
|
|
std::pair<const TemplateDecl *, SourceLocation>
|
|
|
|
getCursorTemplateRef(CXCursor C);
|
2010-09-01 07:48:11 +08:00
|
|
|
|
|
|
|
/// \brief Create a reference to a namespace or namespace alias at the given
|
|
|
|
/// location.
|
2011-11-18 08:26:51 +08:00
|
|
|
CXCursor MakeCursorNamespaceRef(const NamedDecl *NS, SourceLocation Loc,
|
2010-11-16 16:15:36 +08:00
|
|
|
CXTranslationUnit TU);
|
2010-09-01 07:48:11 +08:00
|
|
|
|
|
|
|
/// \brief Unpack a NamespaceRef cursor into the namespace or namespace alias
|
|
|
|
/// it references and the location where the reference occurred.
|
2013-01-12 05:01:49 +08:00
|
|
|
std::pair<const NamedDecl *, SourceLocation> getCursorNamespaceRef(CXCursor C);
|
2010-09-01 07:48:11 +08:00
|
|
|
|
2012-02-15 08:54:55 +08:00
|
|
|
/// \brief Create a reference to a variable at the given location.
|
|
|
|
CXCursor MakeCursorVariableRef(const VarDecl *Var, SourceLocation Loc,
|
|
|
|
CXTranslationUnit TU);
|
|
|
|
|
|
|
|
/// \brief Unpack a VariableRef cursor into the variable it references and the
|
|
|
|
/// location where the where the reference occurred.
|
2013-01-12 05:01:49 +08:00
|
|
|
std::pair<const VarDecl *, SourceLocation> getCursorVariableRef(CXCursor C);
|
2012-02-15 08:54:55 +08:00
|
|
|
|
2010-09-10 05:42:20 +08:00
|
|
|
/// \brief Create a reference to a field at the given location.
|
2011-11-18 08:26:51 +08:00
|
|
|
CXCursor MakeCursorMemberRef(const FieldDecl *Field, SourceLocation Loc,
|
2010-11-16 16:15:36 +08:00
|
|
|
CXTranslationUnit TU);
|
2010-09-10 05:42:20 +08:00
|
|
|
|
|
|
|
/// \brief Unpack a MemberRef cursor into the field it references and the
|
|
|
|
/// location where the reference occurred.
|
2013-01-12 05:01:49 +08:00
|
|
|
std::pair<const FieldDecl *, SourceLocation> getCursorMemberRef(CXCursor C);
|
2010-09-10 05:42:20 +08:00
|
|
|
|
2010-08-28 05:34:58 +08:00
|
|
|
/// \brief Create a CXX base specifier cursor.
|
2011-11-22 15:24:51 +08:00
|
|
|
CXCursor MakeCursorCXXBaseSpecifier(const CXXBaseSpecifier *B,
|
2010-11-16 16:15:36 +08:00
|
|
|
CXTranslationUnit TU);
|
2010-08-28 05:34:58 +08:00
|
|
|
|
|
|
|
/// \brief Unpack a CXXBaseSpecifier cursor into a CXXBaseSpecifier.
|
2013-01-12 05:01:49 +08:00
|
|
|
const CXXBaseSpecifier *getCursorCXXBaseSpecifier(CXCursor C);
|
2010-08-28 05:34:58 +08:00
|
|
|
|
2010-03-18 08:42:48 +08:00
|
|
|
/// \brief Create a preprocessing directive cursor.
|
2010-11-16 16:15:36 +08:00
|
|
|
CXCursor MakePreprocessingDirectiveCursor(SourceRange Range,
|
|
|
|
CXTranslationUnit TU);
|
2010-03-18 08:42:48 +08:00
|
|
|
|
|
|
|
/// \brief Unpack a given preprocessing directive to retrieve its source range.
|
|
|
|
SourceRange getCursorPreprocessingDirective(CXCursor C);
|
2010-03-18 23:23:44 +08:00
|
|
|
|
2010-03-19 02:04:21 +08:00
|
|
|
/// \brief Create a macro definition cursor.
|
2015-05-04 10:25:31 +08:00
|
|
|
CXCursor MakeMacroDefinitionCursor(const MacroDefinitionRecord *,
|
2013-01-12 05:01:49 +08:00
|
|
|
CXTranslationUnit TU);
|
2010-03-19 02:04:21 +08:00
|
|
|
|
|
|
|
/// \brief Unpack a given macro definition cursor to retrieve its
|
|
|
|
/// source range.
|
2015-05-04 10:25:31 +08:00
|
|
|
const MacroDefinitionRecord *getCursorMacroDefinition(CXCursor C);
|
2010-03-19 02:04:21 +08:00
|
|
|
|
2011-07-14 16:20:46 +08:00
|
|
|
/// \brief Create a macro expansion cursor.
|
2015-05-04 10:25:31 +08:00
|
|
|
CXCursor MakeMacroExpansionCursor(MacroExpansion *, CXTranslationUnit TU);
|
2010-03-18 23:23:44 +08:00
|
|
|
|
2013-01-08 03:16:25 +08:00
|
|
|
/// \brief Create a "pseudo" macro expansion cursor, using a macro definition
|
|
|
|
/// and a source location.
|
2015-05-04 10:25:31 +08:00
|
|
|
CXCursor MakeMacroExpansionCursor(MacroDefinitionRecord *, SourceLocation Loc,
|
2013-01-08 03:16:25 +08:00
|
|
|
CXTranslationUnit TU);
|
|
|
|
|
|
|
|
/// \brief Wraps a macro expansion cursor and provides a common interface
|
|
|
|
/// for a normal macro expansion cursor or a "pseudo" one.
|
|
|
|
///
|
|
|
|
/// "Pseudo" macro expansion cursors (essentially a macro definition along with
|
|
|
|
/// a source location) are created in special cases, for example they can be
|
|
|
|
/// created for identifiers inside macro definitions, if these identifiers are
|
|
|
|
/// macro names.
|
|
|
|
class MacroExpansionCursor {
|
|
|
|
CXCursor C;
|
|
|
|
|
2015-05-04 10:25:31 +08:00
|
|
|
bool isPseudo() const { return C.data[1] != nullptr; }
|
|
|
|
const MacroDefinitionRecord *getAsMacroDefinition() const {
|
2013-01-08 03:16:25 +08:00
|
|
|
assert(isPseudo());
|
2015-05-04 10:25:31 +08:00
|
|
|
return static_cast<const MacroDefinitionRecord *>(C.data[0]);
|
2013-01-08 03:16:25 +08:00
|
|
|
}
|
2013-01-12 05:01:49 +08:00
|
|
|
const MacroExpansion *getAsMacroExpansion() const {
|
2013-01-08 03:16:25 +08:00
|
|
|
assert(!isPseudo());
|
2013-01-12 05:01:49 +08:00
|
|
|
return static_cast<const MacroExpansion *>(C.data[0]);
|
2013-01-08 03:16:25 +08:00
|
|
|
}
|
|
|
|
SourceLocation getPseudoLoc() const {
|
|
|
|
assert(isPseudo());
|
|
|
|
return SourceLocation::getFromPtrEncoding(C.data[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
MacroExpansionCursor(CXCursor C) : C(C) {
|
|
|
|
assert(C.kind == CXCursor_MacroExpansion);
|
|
|
|
}
|
|
|
|
|
|
|
|
const IdentifierInfo *getName() const;
|
2015-05-04 10:25:31 +08:00
|
|
|
const MacroDefinitionRecord *getDefinition() const;
|
2013-01-08 03:16:25 +08:00
|
|
|
SourceRange getSourceRange() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief Unpack a given macro expansion cursor to retrieve its info.
|
|
|
|
static inline MacroExpansionCursor getCursorMacroExpansion(CXCursor C) {
|
|
|
|
return C;
|
|
|
|
}
|
2010-03-18 23:23:44 +08:00
|
|
|
|
2010-10-21 06:00:55 +08:00
|
|
|
/// \brief Create an inclusion directive cursor.
|
2010-11-16 16:15:36 +08:00
|
|
|
CXCursor MakeInclusionDirectiveCursor(InclusionDirective *,
|
|
|
|
CXTranslationUnit TU);
|
2010-10-21 06:00:55 +08:00
|
|
|
|
|
|
|
/// \brief Unpack a given inclusion directive cursor to retrieve its
|
|
|
|
/// source range.
|
2013-01-12 05:01:49 +08:00
|
|
|
const InclusionDirective *getCursorInclusionDirective(CXCursor C);
|
2010-10-21 06:00:55 +08:00
|
|
|
|
2010-09-10 08:22:18 +08:00
|
|
|
/// \brief Create a label reference at the given location.
|
2010-11-16 16:15:36 +08:00
|
|
|
CXCursor MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc,
|
|
|
|
CXTranslationUnit TU);
|
2010-09-10 08:22:18 +08:00
|
|
|
|
|
|
|
/// \brief Unpack a label reference into the label statement it refers to and
|
|
|
|
/// the location of the reference.
|
2013-01-12 05:01:49 +08:00
|
|
|
std::pair<const LabelStmt *, SourceLocation> getCursorLabelRef(CXCursor C);
|
2010-09-14 06:52:57 +08:00
|
|
|
|
|
|
|
/// \brief Create a overloaded declaration reference cursor for an expression.
|
2013-01-24 01:25:27 +08:00
|
|
|
CXCursor MakeCursorOverloadedDeclRef(const OverloadExpr *E,
|
|
|
|
CXTranslationUnit TU);
|
2010-09-14 06:52:57 +08:00
|
|
|
|
|
|
|
/// \brief Create a overloaded declaration reference cursor for a declaration.
|
2013-01-24 01:25:27 +08:00
|
|
|
CXCursor MakeCursorOverloadedDeclRef(const Decl *D, SourceLocation Location,
|
2010-11-16 16:15:36 +08:00
|
|
|
CXTranslationUnit TU);
|
2010-09-14 06:52:57 +08:00
|
|
|
|
|
|
|
/// \brief Create a overloaded declaration reference cursor for a template name.
|
|
|
|
CXCursor MakeCursorOverloadedDeclRef(TemplateName Template,
|
2010-11-16 16:15:36 +08:00
|
|
|
SourceLocation Location,
|
|
|
|
CXTranslationUnit TU);
|
2010-09-14 06:52:57 +08:00
|
|
|
|
|
|
|
/// \brief Internal storage for an overloaded declaration reference cursor;
|
2013-01-24 01:25:27 +08:00
|
|
|
typedef llvm::PointerUnion3<const OverloadExpr *, const Decl *,
|
2010-09-14 06:52:57 +08:00
|
|
|
OverloadedTemplateStorage *>
|
|
|
|
OverloadedDeclRefStorage;
|
|
|
|
|
|
|
|
/// \brief Unpack an overloaded declaration reference into an expression,
|
|
|
|
/// declaration, or template name along with the source location.
|
|
|
|
std::pair<OverloadedDeclRefStorage, SourceLocation>
|
|
|
|
getCursorOverloadedDeclRef(CXCursor C);
|
2010-09-10 08:22:18 +08:00
|
|
|
|
2013-01-24 01:25:27 +08:00
|
|
|
const Decl *getCursorDecl(CXCursor Cursor);
|
2013-01-26 23:29:08 +08:00
|
|
|
const Expr *getCursorExpr(CXCursor Cursor);
|
|
|
|
const Stmt *getCursorStmt(CXCursor Cursor);
|
2013-01-27 02:08:08 +08:00
|
|
|
const Attr *getCursorAttr(CXCursor Cursor);
|
2013-01-27 02:12:08 +08:00
|
|
|
const Decl *getCursorParentDecl(CXCursor Cursor);
|
2010-08-26 09:42:22 +08:00
|
|
|
|
2010-01-19 07:41:10 +08:00
|
|
|
ASTContext &getCursorContext(CXCursor Cursor);
|
2010-01-21 07:57:43 +08:00
|
|
|
ASTUnit *getCursorASTUnit(CXCursor Cursor);
|
2010-11-16 16:15:36 +08:00
|
|
|
CXTranslationUnit getCursorTU(CXCursor Cursor);
|
2011-10-06 15:00:46 +08:00
|
|
|
|
|
|
|
void getOverriddenCursors(CXCursor cursor,
|
2012-05-01 03:06:49 +08:00
|
|
|
SmallVectorImpl<CXCursor> &overridden);
|
|
|
|
|
|
|
|
/// \brief Create an opaque pool used for fast generation of overriden
|
|
|
|
/// CXCursor arrays.
|
|
|
|
void *createOverridenCXCursorsPool();
|
2011-10-06 15:00:46 +08:00
|
|
|
|
2012-05-01 03:06:49 +08:00
|
|
|
/// \brief Dispose of the overriden CXCursors pool.
|
|
|
|
void disposeOverridenCXCursorsPool(void *pool);
|
|
|
|
|
2011-10-06 15:00:54 +08:00
|
|
|
/// \brief Returns a index/location pair for a selector identifier if the cursor
|
|
|
|
/// points to one.
|
|
|
|
std::pair<int, SourceLocation> getSelectorIdentifierIndexAndLoc(CXCursor);
|
|
|
|
static inline int getSelectorIdentifierIndex(CXCursor cursor) {
|
|
|
|
return getSelectorIdentifierIndexAndLoc(cursor).first;
|
|
|
|
}
|
|
|
|
static inline SourceLocation getSelectorIdentifierLoc(CXCursor cursor) {
|
|
|
|
return getSelectorIdentifierIndexAndLoc(cursor).second;
|
|
|
|
}
|
|
|
|
|
|
|
|
CXCursor getSelectorIdentifierCursor(int SelIdx, CXCursor cursor);
|
|
|
|
|
|
|
|
static inline CXCursor getTypeRefedCallExprCursor(CXCursor cursor) {
|
|
|
|
CXCursor newCursor = cursor;
|
|
|
|
if (cursor.kind == CXCursor_CallExpr)
|
|
|
|
newCursor.xdata = 1;
|
|
|
|
return newCursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
CXCursor getTypeRefCursor(CXCursor cursor);
|
|
|
|
|
2011-10-12 15:07:36 +08:00
|
|
|
/// \brief Generate a USR for \arg D and put it in \arg Buf.
|
|
|
|
/// \returns true if no USR was computed or the result should be ignored,
|
|
|
|
/// false otherwise.
|
2011-10-18 03:48:19 +08:00
|
|
|
bool getDeclCursorUSR(const Decl *D, SmallVectorImpl<char> &Buf);
|
2011-10-12 15:07:36 +08:00
|
|
|
|
2010-01-16 05:56:13 +08:00
|
|
|
bool operator==(CXCursor X, CXCursor Y);
|
|
|
|
|
|
|
|
inline bool operator!=(CXCursor X, CXCursor Y) {
|
|
|
|
return !(X == Y);
|
|
|
|
}
|
|
|
|
|
2010-11-02 07:26:51 +08:00
|
|
|
/// \brief Return true if the cursor represents a declaration that is the
|
|
|
|
/// first in a declaration group.
|
|
|
|
bool isFirstInDeclGroup(CXCursor C);
|
|
|
|
|
2015-06-23 07:07:51 +08:00
|
|
|
}} // end namespace: clang::cxcursor
|
2010-01-16 04:35:54 +08:00
|
|
|
|
|
|
|
#endif
|