libclang: change CXCursor to store 'const void *' pointers for

const-correctness, and update all users


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172252 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dmitri Gribenko 2013-01-11 21:01:49 +00:00
Родитель 06d8c60e37
Коммит 67812b2f94
7 изменённых файлов: 102 добавлений и 94 удалений

Просмотреть файл

@ -2101,7 +2101,7 @@ enum CXCursorKind {
typedef struct {
enum CXCursorKind kind;
int xdata;
void *data[3];
const void *data[3];
} CXCursor;
/**

Просмотреть файл

@ -512,7 +512,7 @@ bool CursorVisitor::VisitChildren(CXCursor Cursor) {
}
if (Cursor.kind == CXCursor_CXXBaseSpecifier) {
if (CXXBaseSpecifier *Base = getCursorCXXBaseSpecifier(Cursor)) {
if (const CXXBaseSpecifier *Base = getCursorCXXBaseSpecifier(Cursor)) {
if (TypeSourceInfo *BaseTSInfo = Base->getTypeSourceInfo()) {
return Visit(BaseTSInfo->getTypeLoc());
}
@ -534,7 +534,8 @@ bool CursorVisitor::VisitChildren(CXCursor Cursor) {
if (Cursor.kind == CXCursor_MacroDefinition &&
BeginLoc == RegionOfInterest.getEnd()) {
SourceLocation Loc = AU->mapLocationToPreamble(BeginLoc);
MacroInfo *MI = getMacroInfo(cxcursor::getCursorMacroDefinition(Cursor),TU);
const MacroInfo *MI =
getMacroInfo(cxcursor::getCursorMacroDefinition(Cursor), TU);
if (MacroDefinition *MacroDef =
checkForMacroInMacroDefinition(MI, Loc, TU))
return Visit(cxcursor::MakeMacroExpansionCursor(MacroDef, BeginLoc, TU));
@ -3123,52 +3124,52 @@ CXString clang_getCursorSpelling(CXCursor C) {
if (clang_isReference(C.kind)) {
switch (C.kind) {
case CXCursor_ObjCSuperClassRef: {
ObjCInterfaceDecl *Super = getCursorObjCSuperClassRef(C).first;
const ObjCInterfaceDecl *Super = getCursorObjCSuperClassRef(C).first;
return createCXString(Super->getIdentifier()->getNameStart());
}
case CXCursor_ObjCClassRef: {
ObjCInterfaceDecl *Class = getCursorObjCClassRef(C).first;
const ObjCInterfaceDecl *Class = getCursorObjCClassRef(C).first;
return createCXString(Class->getIdentifier()->getNameStart());
}
case CXCursor_ObjCProtocolRef: {
ObjCProtocolDecl *OID = getCursorObjCProtocolRef(C).first;
const ObjCProtocolDecl *OID = getCursorObjCProtocolRef(C).first;
assert(OID && "getCursorSpelling(): Missing protocol decl");
return createCXString(OID->getIdentifier()->getNameStart());
}
case CXCursor_CXXBaseSpecifier: {
CXXBaseSpecifier *B = getCursorCXXBaseSpecifier(C);
const CXXBaseSpecifier *B = getCursorCXXBaseSpecifier(C);
return createCXString(B->getType().getAsString());
}
case CXCursor_TypeRef: {
TypeDecl *Type = getCursorTypeRef(C).first;
const TypeDecl *Type = getCursorTypeRef(C).first;
assert(Type && "Missing type decl");
return createCXString(getCursorContext(C).getTypeDeclType(Type).
getAsString());
}
case CXCursor_TemplateRef: {
TemplateDecl *Template = getCursorTemplateRef(C).first;
const TemplateDecl *Template = getCursorTemplateRef(C).first;
assert(Template && "Missing template decl");
return createCXString(Template->getNameAsString());
}
case CXCursor_NamespaceRef: {
NamedDecl *NS = getCursorNamespaceRef(C).first;
const NamedDecl *NS = getCursorNamespaceRef(C).first;
assert(NS && "Missing namespace decl");
return createCXString(NS->getNameAsString());
}
case CXCursor_MemberRef: {
FieldDecl *Field = getCursorMemberRef(C).first;
const FieldDecl *Field = getCursorMemberRef(C).first;
assert(Field && "Missing member decl");
return createCXString(Field->getNameAsString());
}
case CXCursor_LabelRef: {
LabelStmt *Label = getCursorLabelRef(C).first;
const LabelStmt *Label = getCursorLabelRef(C).first;
assert(Label && "Missing label");
return createCXString(Label->getName());
@ -3191,7 +3192,7 @@ CXString clang_getCursorSpelling(CXCursor C) {
}
case CXCursor_VariableRef: {
VarDecl *Var = getCursorVariableRef(C).first;
const VarDecl *Var = getCursorVariableRef(C).first;
assert(Var && "Missing variable decl");
return createCXString(Var->getNameAsString());
@ -3902,7 +3903,7 @@ unsigned clang_hashCursor(CXCursor C) {
if (clang_isExpression(C.kind) || clang_isStatement(C.kind))
Index = 1;
return llvm::DenseMapInfo<std::pair<unsigned, void*> >::getHashValue(
return llvm::DenseMapInfo<std::pair<unsigned, const void*> >::getHashValue(
std::make_pair(C.kind, C.data[Index]));
}
@ -3959,50 +3960,51 @@ CXSourceLocation clang_getCursorLocation(CXCursor C) {
if (clang_isReference(C.kind)) {
switch (C.kind) {
case CXCursor_ObjCSuperClassRef: {
std::pair<ObjCInterfaceDecl *, SourceLocation> P
std::pair<const ObjCInterfaceDecl *, SourceLocation> P
= getCursorObjCSuperClassRef(C);
return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
}
case CXCursor_ObjCProtocolRef: {
std::pair<ObjCProtocolDecl *, SourceLocation> P
std::pair<const ObjCProtocolDecl *, SourceLocation> P
= getCursorObjCProtocolRef(C);
return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
}
case CXCursor_ObjCClassRef: {
std::pair<ObjCInterfaceDecl *, SourceLocation> P
std::pair<const ObjCInterfaceDecl *, SourceLocation> P
= getCursorObjCClassRef(C);
return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
}
case CXCursor_TypeRef: {
std::pair<TypeDecl *, SourceLocation> P = getCursorTypeRef(C);
std::pair<const TypeDecl *, SourceLocation> P = getCursorTypeRef(C);
return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
}
case CXCursor_TemplateRef: {
std::pair<TemplateDecl *, SourceLocation> P = getCursorTemplateRef(C);
std::pair<const TemplateDecl *, SourceLocation> P =
getCursorTemplateRef(C);
return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
}
case CXCursor_NamespaceRef: {
std::pair<NamedDecl *, SourceLocation> P = getCursorNamespaceRef(C);
std::pair<const NamedDecl *, SourceLocation> P = getCursorNamespaceRef(C);
return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
}
case CXCursor_MemberRef: {
std::pair<FieldDecl *, SourceLocation> P = getCursorMemberRef(C);
std::pair<const FieldDecl *, SourceLocation> P = getCursorMemberRef(C);
return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
}
case CXCursor_VariableRef: {
std::pair<VarDecl *, SourceLocation> P = getCursorVariableRef(C);
std::pair<const VarDecl *, SourceLocation> P = getCursorVariableRef(C);
return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
}
case CXCursor_CXXBaseSpecifier: {
CXXBaseSpecifier *BaseSpec = getCursorCXXBaseSpecifier(C);
const CXXBaseSpecifier *BaseSpec = getCursorCXXBaseSpecifier(C);
if (!BaseSpec)
return clang_getNullLocation();
@ -4015,7 +4017,7 @@ CXSourceLocation clang_getCursorLocation(CXCursor C) {
}
case CXCursor_LabelRef: {
std::pair<LabelStmt *, SourceLocation> P = getCursorLabelRef(C);
std::pair<const LabelStmt *, SourceLocation> P = getCursorLabelRef(C);
return cxloc::translateSourceLocation(getCursorContext(C), P.second);
}
@ -4310,7 +4312,7 @@ CXCursor clang_getCursorReferenced(CXCursor C) {
}
if (C.kind == CXCursor_MacroExpansion) {
if (MacroDefinition *Def = getCursorMacroExpansion(C).getDefinition())
if (const MacroDefinition *Def = getCursorMacroExpansion(C).getDefinition())
return MakeMacroDefinitionCursor(Def, tu);
}
@ -4322,16 +4324,16 @@ CXCursor clang_getCursorReferenced(CXCursor C) {
return MakeCXCursor(getCursorObjCSuperClassRef(C).first, tu);
case CXCursor_ObjCProtocolRef: {
ObjCProtocolDecl *Prot = getCursorObjCProtocolRef(C).first;
if (ObjCProtocolDecl *Def = Prot->getDefinition())
const ObjCProtocolDecl *Prot = getCursorObjCProtocolRef(C).first;
if (const ObjCProtocolDecl *Def = Prot->getDefinition())
return MakeCXCursor(Def, tu);
return MakeCXCursor(Prot, tu);
}
case CXCursor_ObjCClassRef: {
ObjCInterfaceDecl *Class = getCursorObjCClassRef(C).first;
if (ObjCInterfaceDecl *Def = Class->getDefinition())
const ObjCInterfaceDecl *Class = getCursorObjCClassRef(C).first;
if (const ObjCInterfaceDecl *Def = Class->getDefinition())
return MakeCXCursor(Def, tu);
return MakeCXCursor(Class, tu);
@ -4350,7 +4352,7 @@ CXCursor clang_getCursorReferenced(CXCursor C) {
return MakeCXCursor(getCursorMemberRef(C).first, tu );
case CXCursor_CXXBaseSpecifier: {
CXXBaseSpecifier *B = cxcursor::getCursorCXXBaseSpecifier(C);
const CXXBaseSpecifier *B = cxcursor::getCursorCXXBaseSpecifier(C);
return clang_getTypeDeclaration(cxtype::MakeCXType(B->getType(),
tu ));
}
@ -5828,7 +5830,7 @@ CXFile clang_getIncludedFile(CXCursor cursor) {
if (cursor.kind != CXCursor_InclusionDirective)
return 0;
InclusionDirective *ID = getCursorInclusionDirective(cursor);
const InclusionDirective *ID = getCursorInclusionDirective(cursor);
return (void *)ID->getFile();
}
@ -6241,8 +6243,8 @@ MacroInfo *cxindex::getMacroInfo(const IdentifierInfo &II,
return 0;
}
MacroInfo *cxindex::getMacroInfo(MacroDefinition *MacroDef,
CXTranslationUnit TU) {
const MacroInfo *cxindex::getMacroInfo(const MacroDefinition *MacroDef,
CXTranslationUnit TU) {
if (!MacroDef || !TU)
return 0;
const IdentifierInfo *II = MacroDef->getName();

Просмотреть файл

@ -26,7 +26,7 @@ unsigned clang_isVirtualBase(CXCursor C) {
if (C.kind != CXCursor_CXXBaseSpecifier)
return 0;
CXXBaseSpecifier *B = getCursorCXXBaseSpecifier(C);
const CXXBaseSpecifier *B = getCursorCXXBaseSpecifier(C);
return B->isVirtual();
}

Просмотреть файл

@ -107,7 +107,8 @@ public:
CXTranslationUnit TU);
/// \brief Retrieves the corresponding MacroInfo of a MacroDefinition.
MacroInfo *getMacroInfo(MacroDefinition *MacroDef, CXTranslationUnit TU);
const MacroInfo *getMacroInfo(const MacroDefinition *MacroDef,
CXTranslationUnit TU);
/// \brief If \c Loc resides inside the definition of \c MI and it points at
/// an identifier that has ever been a macro name, this returns the latest

Просмотреть файл

@ -60,7 +60,7 @@ CXCursor cxcursor::MakeCXCursor(const Attr *A, Decl *Parent,
return C;
}
CXCursor cxcursor::MakeCXCursor(Decl *D, CXTranslationUnit TU,
CXCursor cxcursor::MakeCXCursor(const Decl *D, CXTranslationUnit TU,
SourceRange RegionOfInterest,
bool FirstInDeclGroup) {
assert(D && TU && "Invalid arguments!");
@ -89,7 +89,8 @@ CXCursor cxcursor::MakeCXCursor(Decl *D, CXTranslationUnit TU,
return C;
}
CXCursor cxcursor::MakeCXCursor(Stmt *S, Decl *Parent, CXTranslationUnit TU,
CXCursor cxcursor::MakeCXCursor(const Stmt *S, Decl *Parent,
CXTranslationUnit TU,
SourceRange RegionOfInterest) {
assert(S && TU && "Invalid arguments!");
CXCursorKind K = CXCursor_NotImplemented;
@ -498,10 +499,10 @@ CXCursor cxcursor::MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super,
return C;
}
std::pair<ObjCInterfaceDecl *, SourceLocation>
std::pair<const ObjCInterfaceDecl *, SourceLocation>
cxcursor::getCursorObjCSuperClassRef(CXCursor C) {
assert(C.kind == CXCursor_ObjCSuperClassRef);
return std::make_pair(static_cast<ObjCInterfaceDecl *>(C.data[0]),
return std::make_pair(static_cast<const ObjCInterfaceDecl *>(C.data[0]),
SourceLocation::getFromRawEncoding(
reinterpret_cast<uintptr_t>(C.data[1])));
}
@ -515,10 +516,10 @@ CXCursor cxcursor::MakeCursorObjCProtocolRef(const ObjCProtocolDecl *Proto,
return C;
}
std::pair<ObjCProtocolDecl *, SourceLocation>
std::pair<const ObjCProtocolDecl *, SourceLocation>
cxcursor::getCursorObjCProtocolRef(CXCursor C) {
assert(C.kind == CXCursor_ObjCProtocolRef);
return std::make_pair(static_cast<ObjCProtocolDecl *>(C.data[0]),
return std::make_pair(static_cast<const ObjCProtocolDecl *>(C.data[0]),
SourceLocation::getFromRawEncoding(
reinterpret_cast<uintptr_t>(C.data[1])));
}
@ -535,10 +536,10 @@ CXCursor cxcursor::MakeCursorObjCClassRef(const ObjCInterfaceDecl *Class,
return C;
}
std::pair<ObjCInterfaceDecl *, SourceLocation>
std::pair<const ObjCInterfaceDecl *, SourceLocation>
cxcursor::getCursorObjCClassRef(CXCursor C) {
assert(C.kind == CXCursor_ObjCClassRef);
return std::make_pair(static_cast<ObjCInterfaceDecl *>(C.data[0]),
return std::make_pair(static_cast<const ObjCInterfaceDecl *>(C.data[0]),
SourceLocation::getFromRawEncoding(
reinterpret_cast<uintptr_t>(C.data[1])));
}
@ -551,10 +552,10 @@ CXCursor cxcursor::MakeCursorTypeRef(const TypeDecl *Type, SourceLocation Loc,
return C;
}
std::pair<TypeDecl *, SourceLocation>
std::pair<const TypeDecl *, SourceLocation>
cxcursor::getCursorTypeRef(CXCursor C) {
assert(C.kind == CXCursor_TypeRef);
return std::make_pair(static_cast<TypeDecl *>(C.data[0]),
return std::make_pair(static_cast<const TypeDecl *>(C.data[0]),
SourceLocation::getFromRawEncoding(
reinterpret_cast<uintptr_t>(C.data[1])));
}
@ -568,10 +569,10 @@ CXCursor cxcursor::MakeCursorTemplateRef(const TemplateDecl *Template,
return C;
}
std::pair<TemplateDecl *, SourceLocation>
std::pair<const TemplateDecl *, SourceLocation>
cxcursor::getCursorTemplateRef(CXCursor C) {
assert(C.kind == CXCursor_TemplateRef);
return std::make_pair(static_cast<TemplateDecl *>(C.data[0]),
return std::make_pair(static_cast<const TemplateDecl *>(C.data[0]),
SourceLocation::getFromRawEncoding(
reinterpret_cast<uintptr_t>(C.data[1])));
}
@ -587,10 +588,10 @@ CXCursor cxcursor::MakeCursorNamespaceRef(const NamedDecl *NS,
return C;
}
std::pair<NamedDecl *, SourceLocation>
std::pair<const NamedDecl *, SourceLocation>
cxcursor::getCursorNamespaceRef(CXCursor C) {
assert(C.kind == CXCursor_NamespaceRef);
return std::make_pair(static_cast<NamedDecl *>(C.data[0]),
return std::make_pair(static_cast<const NamedDecl *>(C.data[0]),
SourceLocation::getFromRawEncoding(
reinterpret_cast<uintptr_t>(C.data[1])));
}
@ -604,10 +605,10 @@ CXCursor cxcursor::MakeCursorVariableRef(const VarDecl *Var, SourceLocation Loc,
return C;
}
std::pair<VarDecl *, SourceLocation>
std::pair<const VarDecl *, SourceLocation>
cxcursor::getCursorVariableRef(CXCursor C) {
assert(C.kind == CXCursor_VariableRef);
return std::make_pair(static_cast<VarDecl *>(C.data[0]),
return std::make_pair(static_cast<const VarDecl *>(C.data[0]),
SourceLocation::getFromRawEncoding(
reinterpret_cast<uintptr_t>(C.data[1])));
}
@ -621,10 +622,10 @@ CXCursor cxcursor::MakeCursorMemberRef(const FieldDecl *Field, SourceLocation Lo
return C;
}
std::pair<FieldDecl *, SourceLocation>
std::pair<const FieldDecl *, SourceLocation>
cxcursor::getCursorMemberRef(CXCursor C) {
assert(C.kind == CXCursor_MemberRef);
return std::make_pair(static_cast<FieldDecl *>(C.data[0]),
return std::make_pair(static_cast<const FieldDecl *>(C.data[0]),
SourceLocation::getFromRawEncoding(
reinterpret_cast<uintptr_t>(C.data[1])));
}
@ -635,9 +636,9 @@ CXCursor cxcursor::MakeCursorCXXBaseSpecifier(const CXXBaseSpecifier *B,
return C;
}
CXXBaseSpecifier *cxcursor::getCursorCXXBaseSpecifier(CXCursor C) {
const CXXBaseSpecifier *cxcursor::getCursorCXXBaseSpecifier(CXCursor C) {
assert(C.kind == CXCursor_CXXBaseSpecifier);
return static_cast<CXXBaseSpecifier*>(C.data[0]);
return static_cast<const CXXBaseSpecifier*>(C.data[0]);
}
CXCursor cxcursor::MakePreprocessingDirectiveCursor(SourceRange Range,
@ -660,15 +661,15 @@ SourceRange cxcursor::getCursorPreprocessingDirective(CXCursor C) {
return TU->mapRangeFromPreamble(Range);
}
CXCursor cxcursor::MakeMacroDefinitionCursor(MacroDefinition *MI,
CXCursor cxcursor::MakeMacroDefinitionCursor(const MacroDefinition *MI,
CXTranslationUnit TU) {
CXCursor C = { CXCursor_MacroDefinition, 0, { MI, 0, TU } };
return C;
}
MacroDefinition *cxcursor::getCursorMacroDefinition(CXCursor C) {
const MacroDefinition *cxcursor::getCursorMacroDefinition(CXCursor C) {
assert(C.kind == CXCursor_MacroDefinition);
return static_cast<MacroDefinition *>(C.data[0]);
return static_cast<const MacroDefinition *>(C.data[0]);
}
CXCursor cxcursor::MakeMacroExpansionCursor(MacroExpansion *MI,
@ -690,7 +691,7 @@ const IdentifierInfo *cxcursor::MacroExpansionCursor::getName() const {
return getAsMacroDefinition()->getName();
return getAsMacroExpansion()->getName();
}
MacroDefinition *cxcursor::MacroExpansionCursor::getDefinition() const {
const MacroDefinition *cxcursor::MacroExpansionCursor::getDefinition() const {
if (isPseudo())
return getAsMacroDefinition();
return getAsMacroExpansion()->getDefinition();
@ -707,9 +708,9 @@ CXCursor cxcursor::MakeInclusionDirectiveCursor(InclusionDirective *ID,
return C;
}
InclusionDirective *cxcursor::getCursorInclusionDirective(CXCursor C) {
const InclusionDirective *cxcursor::getCursorInclusionDirective(CXCursor C) {
assert(C.kind == CXCursor_InclusionDirective);
return static_cast<InclusionDirective *>(C.data[0]);
return static_cast<const InclusionDirective *>(C.data[0]);
}
CXCursor cxcursor::MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc,
@ -721,10 +722,10 @@ CXCursor cxcursor::MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc,
return C;
}
std::pair<LabelStmt*, SourceLocation>
std::pair<const LabelStmt *, SourceLocation>
cxcursor::getCursorLabelRef(CXCursor C) {
assert(C.kind == CXCursor_LabelRef);
return std::make_pair(static_cast<LabelStmt *>(C.data[0]),
return std::make_pair(static_cast<const LabelStmt *>(C.data[0]),
SourceLocation::getFromRawEncoding(
reinterpret_cast<uintptr_t>(C.data[1])));
}
@ -770,7 +771,8 @@ CXCursor cxcursor::MakeCursorOverloadedDeclRef(TemplateName Name,
std::pair<cxcursor::OverloadedDeclRefStorage, SourceLocation>
cxcursor::getCursorOverloadedDeclRef(CXCursor C) {
assert(C.kind == CXCursor_OverloadedDeclRef);
return std::make_pair(OverloadedDeclRefStorage::getFromOpaqueValue(C.data[0]),
return std::make_pair(OverloadedDeclRefStorage::getFromOpaqueValue(
const_cast<void *>(C.data[0])),
SourceLocation::getFromRawEncoding(
reinterpret_cast<uintptr_t>(C.data[1])));
}
@ -812,7 +814,7 @@ ASTUnit *cxcursor::getCursorASTUnit(CXCursor Cursor) {
}
CXTranslationUnit cxcursor::getCursorTU(CXCursor Cursor) {
return static_cast<CXTranslationUnit>(Cursor.data[2]);
return static_cast<CXTranslationUnit>(const_cast<void*>(Cursor.data[2]));
}
void cxcursor::getOverriddenCursors(CXCursor cursor,
@ -992,7 +994,7 @@ public:
return MakeCXCursorInvalid(CXCursor_NoDeclFound);
}
static inline unsigned getHashValue(const CXCursor &cursor) {
return llvm::DenseMapInfo<std::pair<void*,void*> >
return llvm::DenseMapInfo<std::pair<const void *, const void *> >
::getHashValue(std::make_pair(cursor.data[0], cursor.data[1]));
}
static inline bool isEqual(const CXCursor &x, const CXCursor &y) {
@ -1051,7 +1053,7 @@ CXCompletionString clang_getCursorCompletionString(CXCursor cursor) {
}
}
else if (kind == CXCursor_MacroDefinition) {
MacroDefinition *definition = getCursorMacroDefinition(cursor);
const MacroDefinition *definition = getCursorMacroDefinition(cursor);
const IdentifierInfo *MacroInfo = definition->getName();
ASTUnit *unit = getCursorASTUnit(cursor);
CodeCompletionResult Result(const_cast<IdentifierInfo *>(MacroInfo));
@ -1156,7 +1158,8 @@ void clang_disposeOverriddenCursors(CXCursor *overridden) {
// which has a back-reference to the TU and the vector.
--overridden;
OverridenCursorsPool::CursorVec *Vec =
static_cast<OverridenCursorsPool::CursorVec*>(overridden->data[0]);
static_cast<OverridenCursorsPool::CursorVec *>(
const_cast<void *>(overridden->data[0]));
CXTranslationUnit TU = getCursorTU(*overridden);
assert(Vec && TU);

Просмотреть файл

@ -50,10 +50,10 @@ CXCursor getCursor(CXTranslationUnit, SourceLocation);
CXCursor MakeCXCursor(const clang::Attr *A, clang::Decl *Parent,
CXTranslationUnit TU);
CXCursor MakeCXCursor(clang::Decl *D, CXTranslationUnit TU,
CXCursor MakeCXCursor(const clang::Decl *D, CXTranslationUnit TU,
SourceRange RegionOfInterest = SourceRange(),
bool FirstInDeclGroup = true);
CXCursor MakeCXCursor(clang::Stmt *S, clang::Decl *Parent,
CXCursor MakeCXCursor(const clang::Stmt *S, clang::Decl *Parent,
CXTranslationUnit TU,
SourceRange RegionOfInterest = SourceRange());
CXCursor MakeCXCursorInvalid(CXCursorKind K, CXTranslationUnit TU = 0);
@ -65,7 +65,7 @@ CXCursor MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super,
/// \brief Unpack an ObjCSuperClassRef cursor into the interface it references
/// and optionally the location where the reference occurred.
std::pair<ObjCInterfaceDecl *, SourceLocation>
std::pair<const ObjCInterfaceDecl *, SourceLocation>
getCursorObjCSuperClassRef(CXCursor C);
/// \brief Create an Objective-C protocol reference at the given location.
@ -75,7 +75,7 @@ CXCursor MakeCursorObjCProtocolRef(const ObjCProtocolDecl *Proto,
/// \brief Unpack an ObjCProtocolRef cursor into the protocol it references
/// and optionally the location where the reference occurred.
std::pair<ObjCProtocolDecl *, SourceLocation>
std::pair<const ObjCProtocolDecl *, SourceLocation>
getCursorObjCProtocolRef(CXCursor C);
/// \brief Create an Objective-C class reference at the given location.
@ -85,7 +85,7 @@ CXCursor MakeCursorObjCClassRef(const ObjCInterfaceDecl *Class,
/// \brief Unpack an ObjCClassRef cursor into the class it references
/// and optionally the location where the reference occurred.
std::pair<ObjCInterfaceDecl *, SourceLocation>
std::pair<const ObjCInterfaceDecl *, SourceLocation>
getCursorObjCClassRef(CXCursor C);
/// \brief Create a type reference at the given location.
@ -94,7 +94,7 @@ CXCursor MakeCursorTypeRef(const TypeDecl *Type, SourceLocation Loc,
/// \brief Unpack a TypeRef cursor into the class it references
/// and optionally the location where the reference occurred.
std::pair<TypeDecl *, SourceLocation> getCursorTypeRef(CXCursor C);
std::pair<const TypeDecl *, SourceLocation> getCursorTypeRef(CXCursor C);
/// \brief Create a reference to a template at the given location.
CXCursor MakeCursorTemplateRef(const TemplateDecl *Template, SourceLocation Loc,
@ -102,7 +102,8 @@ CXCursor MakeCursorTemplateRef(const TemplateDecl *Template, SourceLocation Loc,
/// \brief Unpack a TemplateRef cursor into the template it references and
/// the location where the reference occurred.
std::pair<TemplateDecl *, SourceLocation> getCursorTemplateRef(CXCursor C);
std::pair<const TemplateDecl *, SourceLocation>
getCursorTemplateRef(CXCursor C);
/// \brief Create a reference to a namespace or namespace alias at the given
/// location.
@ -111,7 +112,7 @@ CXCursor MakeCursorNamespaceRef(const NamedDecl *NS, SourceLocation Loc,
/// \brief Unpack a NamespaceRef cursor into the namespace or namespace alias
/// it references and the location where the reference occurred.
std::pair<NamedDecl *, SourceLocation> getCursorNamespaceRef(CXCursor C);
std::pair<const NamedDecl *, SourceLocation> getCursorNamespaceRef(CXCursor C);
/// \brief Create a reference to a variable at the given location.
CXCursor MakeCursorVariableRef(const VarDecl *Var, SourceLocation Loc,
@ -119,7 +120,7 @@ CXCursor MakeCursorVariableRef(const VarDecl *Var, SourceLocation Loc,
/// \brief Unpack a VariableRef cursor into the variable it references and the
/// location where the where the reference occurred.
std::pair<VarDecl *, SourceLocation> getCursorVariableRef(CXCursor C);
std::pair<const VarDecl *, SourceLocation> getCursorVariableRef(CXCursor C);
/// \brief Create a reference to a field at the given location.
CXCursor MakeCursorMemberRef(const FieldDecl *Field, SourceLocation Loc,
@ -127,14 +128,14 @@ CXCursor MakeCursorMemberRef(const FieldDecl *Field, SourceLocation Loc,
/// \brief Unpack a MemberRef cursor into the field it references and the
/// location where the reference occurred.
std::pair<FieldDecl *, SourceLocation> getCursorMemberRef(CXCursor C);
std::pair<const FieldDecl *, SourceLocation> getCursorMemberRef(CXCursor C);
/// \brief Create a CXX base specifier cursor.
CXCursor MakeCursorCXXBaseSpecifier(const CXXBaseSpecifier *B,
CXTranslationUnit TU);
/// \brief Unpack a CXXBaseSpecifier cursor into a CXXBaseSpecifier.
CXXBaseSpecifier *getCursorCXXBaseSpecifier(CXCursor C);
const CXXBaseSpecifier *getCursorCXXBaseSpecifier(CXCursor C);
/// \brief Create a preprocessing directive cursor.
CXCursor MakePreprocessingDirectiveCursor(SourceRange Range,
@ -144,11 +145,12 @@ CXCursor MakePreprocessingDirectiveCursor(SourceRange Range,
SourceRange getCursorPreprocessingDirective(CXCursor C);
/// \brief Create a macro definition cursor.
CXCursor MakeMacroDefinitionCursor(MacroDefinition *, CXTranslationUnit TU);
CXCursor MakeMacroDefinitionCursor(const MacroDefinition *,
CXTranslationUnit TU);
/// \brief Unpack a given macro definition cursor to retrieve its
/// source range.
MacroDefinition *getCursorMacroDefinition(CXCursor C);
const MacroDefinition *getCursorMacroDefinition(CXCursor C);
/// \brief Create a macro expansion cursor.
CXCursor MakeMacroExpansionCursor(MacroExpansion *,
@ -172,13 +174,13 @@ class MacroExpansionCursor {
bool isPseudo() const {
return C.data[1] != 0;
}
MacroDefinition *getAsMacroDefinition() const {
const MacroDefinition *getAsMacroDefinition() const {
assert(isPseudo());
return static_cast<MacroDefinition *>(C.data[0]);
return static_cast<const MacroDefinition *>(C.data[0]);
}
MacroExpansion *getAsMacroExpansion() const {
const MacroExpansion *getAsMacroExpansion() const {
assert(!isPseudo());
return static_cast<MacroExpansion *>(C.data[0]);
return static_cast<const MacroExpansion *>(C.data[0]);
}
SourceLocation getPseudoLoc() const {
assert(isPseudo());
@ -191,7 +193,7 @@ public:
}
const IdentifierInfo *getName() const;
MacroDefinition *getDefinition() const;
const MacroDefinition *getDefinition() const;
SourceRange getSourceRange() const;
};
@ -206,7 +208,7 @@ CXCursor MakeInclusionDirectiveCursor(InclusionDirective *,
/// \brief Unpack a given inclusion directive cursor to retrieve its
/// source range.
InclusionDirective *getCursorInclusionDirective(CXCursor C);
const InclusionDirective *getCursorInclusionDirective(CXCursor C);
/// \brief Create a label reference at the given location.
CXCursor MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc,
@ -214,7 +216,7 @@ CXCursor MakeCursorLabelRef(LabelStmt *Label, SourceLocation Loc,
/// \brief Unpack a label reference into the label statement it refers to and
/// the location of the reference.
std::pair<LabelStmt *, SourceLocation> getCursorLabelRef(CXCursor C);
std::pair<const LabelStmt *, SourceLocation> getCursorLabelRef(CXCursor C);
/// \brief Create a overloaded declaration reference cursor for an expression.
CXCursor MakeCursorOverloadedDeclRef(OverloadExpr *E, CXTranslationUnit TU);

Просмотреть файл

@ -635,23 +635,23 @@ CXString clang_getDeclObjCTypeEncoding(CXCursor C) {
if (!clang_isDeclaration(C.kind))
return cxstring::createCXString("");
Decl *D = static_cast<Decl*>(C.data[0]);
const Decl *D = static_cast<const Decl*>(C.data[0]);
ASTUnit *AU = cxcursor::getCursorASTUnit(C);
ASTContext &Ctx = AU->getASTContext();
std::string encoding;
if (ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(D)) {
if (const ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(D)) {
if (Ctx.getObjCEncodingForMethodDecl(OMD, encoding))
return cxstring::createCXString("?");
} else if (ObjCPropertyDecl *OPD = dyn_cast<ObjCPropertyDecl>(D))
} else if (const ObjCPropertyDecl *OPD = dyn_cast<ObjCPropertyDecl>(D))
Ctx.getObjCEncodingForPropertyDecl(OPD, NULL, encoding);
else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
Ctx.getObjCEncodingForFunctionDecl(FD, encoding);
else {
QualType Ty;
if (TypeDecl *TD = dyn_cast<TypeDecl>(D))
if (const TypeDecl *TD = dyn_cast<TypeDecl>(D))
Ty = Ctx.getTypeDeclType(TD);
if (ValueDecl *VD = dyn_cast<ValueDecl>(D))
if (const ValueDecl *VD = dyn_cast<ValueDecl>(D))
Ty = VD->getType();
else return cxstring::createCXString("?");
Ctx.getObjCEncodingForType(Ty, encoding);