blob: a5f111edc1d8a89008ffd75ecf89df0542b2945e [file] [log] [blame]
Ted Kremenek16c440a2010-01-15 20:35:54 +00001//===- 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
Ted Kremenek2cd10b02010-01-25 21:09:34 +000015#define LLVM_CLANG_CXCURSOR_H
Ted Kremenek16c440a2010-01-15 20:35:54 +000016
17#include "clang-c/Index.h"
Douglas Gregor2e331b92010-01-16 14:00:32 +000018#include "clang/Basic/SourceLocation.h"
19#include <utility>
Ted Kremenek16c440a2010-01-15 20:35:54 +000020
21namespace clang {
22
Douglas Gregorf46034a2010-01-18 23:41:10 +000023class ASTContext;
Douglas Gregorb2cd4872010-01-20 23:57:43 +000024class ASTUnit;
Ted Kremeneke77f4432010-02-18 03:09:07 +000025class Attr;
Ted Kremenek3064ef92010-08-27 21:34:58 +000026class CXXBaseSpecifier;
Ted Kremenek16c440a2010-01-15 20:35:54 +000027class Decl;
Douglas Gregor283cae32010-01-15 21:56:13 +000028class Expr;
Douglas Gregor572feb22010-03-18 18:04:21 +000029class MacroDefinition;
Douglas Gregor4ae8f292010-03-18 17:52:52 +000030class MacroInstantiation;
Douglas Gregor283cae32010-01-15 21:56:13 +000031class NamedDecl;
Douglas Gregor2e331b92010-01-16 14:00:32 +000032class ObjCInterfaceDecl;
Douglas Gregor78db0cd2010-01-16 15:44:18 +000033class ObjCProtocolDecl;
Ted Kremenek16c440a2010-01-15 20:35:54 +000034class Stmt;
Douglas Gregor0b36e612010-08-31 20:37:03 +000035class TemplateDecl;
Douglas Gregor7d0d40e2010-01-21 16:28:34 +000036class TypeDecl;
Ted Kremenek16c440a2010-01-15 20:35:54 +000037
38namespace cxcursor {
39
Ted Kremeneke77f4432010-02-18 03:09:07 +000040CXCursor MakeCXCursor(const clang::Attr *A, clang::Decl *Parent, ASTUnit *TU);
Douglas Gregorb2cd4872010-01-20 23:57:43 +000041CXCursor MakeCXCursor(clang::Decl *D, ASTUnit *TU);
Ted Kremeneke77f4432010-02-18 03:09:07 +000042CXCursor MakeCXCursor(clang::Stmt *S, clang::Decl *Parent, ASTUnit *TU);
43CXCursor MakeCXCursorInvalid(CXCursorKind K);
Ted Kremenek16c440a2010-01-15 20:35:54 +000044
Douglas Gregor2e331b92010-01-16 14:00:32 +000045/// \brief Create an Objective-C superclass reference at the given location.
46CXCursor MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super,
Douglas Gregorb2cd4872010-01-20 23:57:43 +000047 SourceLocation Loc,
48 ASTUnit *TU);
Douglas Gregor2e331b92010-01-16 14:00:32 +000049
50/// \brief Unpack an ObjCSuperClassRef cursor into the interface it references
51/// and optionally the location where the reference occurred.
52std::pair<ObjCInterfaceDecl *, SourceLocation>
Douglas Gregor78db0cd2010-01-16 15:44:18 +000053 getCursorObjCSuperClassRef(CXCursor C);
54
55/// \brief Create an Objective-C protocol reference at the given location.
Douglas Gregorb2cd4872010-01-20 23:57:43 +000056CXCursor MakeCursorObjCProtocolRef(ObjCProtocolDecl *Proto, SourceLocation Loc,
57 ASTUnit *TU);
Douglas Gregor78db0cd2010-01-16 15:44:18 +000058
59/// \brief Unpack an ObjCProtocolRef cursor into the protocol it references
60/// and optionally the location where the reference occurred.
61std::pair<ObjCProtocolDecl *, SourceLocation>
62 getCursorObjCProtocolRef(CXCursor C);
Douglas Gregor2e331b92010-01-16 14:00:32 +000063
Douglas Gregor1adb0822010-01-16 17:14:40 +000064/// \brief Create an Objective-C class reference at the given location.
Douglas Gregorb2cd4872010-01-20 23:57:43 +000065CXCursor MakeCursorObjCClassRef(ObjCInterfaceDecl *Class, SourceLocation Loc,
66 ASTUnit *TU);
Douglas Gregor1adb0822010-01-16 17:14:40 +000067
68/// \brief Unpack an ObjCClassRef cursor into the class it references
69/// and optionally the location where the reference occurred.
70std::pair<ObjCInterfaceDecl *, SourceLocation>
71 getCursorObjCClassRef(CXCursor C);
72
Douglas Gregor7d0d40e2010-01-21 16:28:34 +000073/// \brief Create a type reference at the given location.
74CXCursor MakeCursorTypeRef(TypeDecl *Type, SourceLocation Loc, ASTUnit *TU);
Douglas Gregor0b36e612010-08-31 20:37:03 +000075
Douglas Gregor7d0d40e2010-01-21 16:28:34 +000076/// \brief Unpack a TypeRef cursor into the class it references
77/// and optionally the location where the reference occurred.
78std::pair<TypeDecl *, SourceLocation> getCursorTypeRef(CXCursor C);
79
Douglas Gregor0b36e612010-08-31 20:37:03 +000080/// \brief Create a reference to a template at the given location.
81CXCursor MakeCursorTemplateRef(TemplateDecl *Template, SourceLocation Loc,
82 ASTUnit *TU);
83
84/// \brief Unpack a TemplateRef cursor into the template it references and
85/// the location where the reference occurred.
86std::pair<TemplateDecl *, SourceLocation> getCursorTemplateRef(CXCursor C);
Douglas Gregor69319002010-08-31 23:48:11 +000087
88/// \brief Create a reference to a namespace or namespace alias at the given
89/// location.
90CXCursor MakeCursorNamespaceRef(NamedDecl *NS, SourceLocation Loc, ASTUnit *TU);
91
92/// \brief Unpack a NamespaceRef cursor into the namespace or namespace alias
93/// it references and the location where the reference occurred.
94std::pair<NamedDecl *, SourceLocation> getCursorNamespaceRef(CXCursor C);
95
Ted Kremenek3064ef92010-08-27 21:34:58 +000096/// \brief Create a CXX base specifier cursor.
97CXCursor MakeCursorCXXBaseSpecifier(CXXBaseSpecifier *B, ASTUnit *TU);
98
99/// \brief Unpack a CXXBaseSpecifier cursor into a CXXBaseSpecifier.
100CXXBaseSpecifier *getCursorCXXBaseSpecifier(CXCursor C);
101
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +0000102/// \brief Create a preprocessing directive cursor.
103CXCursor MakePreprocessingDirectiveCursor(SourceRange Range, ASTUnit *TU);
104
105/// \brief Unpack a given preprocessing directive to retrieve its source range.
106SourceRange getCursorPreprocessingDirective(CXCursor C);
Douglas Gregor48072312010-03-18 15:23:44 +0000107
Douglas Gregor572feb22010-03-18 18:04:21 +0000108/// \brief Create a macro definition cursor.
109CXCursor MakeMacroDefinitionCursor(MacroDefinition *, ASTUnit *TU);
110
111/// \brief Unpack a given macro definition cursor to retrieve its
112/// source range.
113MacroDefinition *getCursorMacroDefinition(CXCursor C);
114
Douglas Gregor48072312010-03-18 15:23:44 +0000115/// \brief Create a macro instantiation cursor.
Douglas Gregor4ae8f292010-03-18 17:52:52 +0000116CXCursor MakeMacroInstantiationCursor(MacroInstantiation *, ASTUnit *TU);
Douglas Gregor48072312010-03-18 15:23:44 +0000117
118/// \brief Unpack a given macro instantiation cursor to retrieve its
119/// source range.
Douglas Gregor4ae8f292010-03-18 17:52:52 +0000120MacroInstantiation *getCursorMacroInstantiation(CXCursor C);
Douglas Gregor48072312010-03-18 15:23:44 +0000121
Douglas Gregor283cae32010-01-15 21:56:13 +0000122Decl *getCursorDecl(CXCursor Cursor);
123Expr *getCursorExpr(CXCursor Cursor);
124Stmt *getCursorStmt(CXCursor Cursor);
Ted Kremenek95f33552010-08-26 01:42:22 +0000125Attr *getCursorAttr(CXCursor Cursor);
126
Douglas Gregorf46034a2010-01-18 23:41:10 +0000127ASTContext &getCursorContext(CXCursor Cursor);
Douglas Gregorb2cd4872010-01-20 23:57:43 +0000128ASTUnit *getCursorASTUnit(CXCursor Cursor);
Douglas Gregor283cae32010-01-15 21:56:13 +0000129
130bool operator==(CXCursor X, CXCursor Y);
131
132inline bool operator!=(CXCursor X, CXCursor Y) {
133 return !(X == Y);
134}
135
Ted Kremenek16c440a2010-01-15 20:35:54 +0000136}} // end namespace: clang::cxcursor
137
138#endif