From: Dmitri Gribenko Date: Fri, 11 Jan 2013 21:01:49 +0000 (+0000) Subject: libclang: change CXCursor to store 'const void *' pointers for X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=67812b2f94f4b5e7d2596db1705ffa1149ddc45a;p=clang 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 --- diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h index fc7120c00d..0214a7da6d 100644 --- a/include/clang-c/Index.h +++ b/include/clang-c/Index.h @@ -2101,7 +2101,7 @@ enum CXCursorKind { typedef struct { enum CXCursorKind kind; int xdata; - void *data[3]; + const void *data[3]; } CXCursor; /** diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 249abcc2c5..02d5486d90 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -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 >::getHashValue( + return llvm::DenseMapInfo >::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 P + std::pair P = getCursorObjCSuperClassRef(C); return cxloc::translateSourceLocation(P.first->getASTContext(), P.second); } case CXCursor_ObjCProtocolRef: { - std::pair P + std::pair P = getCursorObjCProtocolRef(C); return cxloc::translateSourceLocation(P.first->getASTContext(), P.second); } case CXCursor_ObjCClassRef: { - std::pair P + std::pair P = getCursorObjCClassRef(C); return cxloc::translateSourceLocation(P.first->getASTContext(), P.second); } case CXCursor_TypeRef: { - std::pair P = getCursorTypeRef(C); + std::pair P = getCursorTypeRef(C); return cxloc::translateSourceLocation(P.first->getASTContext(), P.second); } case CXCursor_TemplateRef: { - std::pair P = getCursorTemplateRef(C); + std::pair P = + getCursorTemplateRef(C); return cxloc::translateSourceLocation(P.first->getASTContext(), P.second); } case CXCursor_NamespaceRef: { - std::pair P = getCursorNamespaceRef(C); + std::pair P = getCursorNamespaceRef(C); return cxloc::translateSourceLocation(P.first->getASTContext(), P.second); } case CXCursor_MemberRef: { - std::pair P = getCursorMemberRef(C); + std::pair P = getCursorMemberRef(C); return cxloc::translateSourceLocation(P.first->getASTContext(), P.second); } case CXCursor_VariableRef: { - std::pair P = getCursorVariableRef(C); + std::pair 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 P = getCursorLabelRef(C); + std::pair 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(); diff --git a/tools/libclang/CIndexCXX.cpp b/tools/libclang/CIndexCXX.cpp index 6a1b7de29c..d069d41de2 100644 --- a/tools/libclang/CIndexCXX.cpp +++ b/tools/libclang/CIndexCXX.cpp @@ -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(); } diff --git a/tools/libclang/CIndexer.h b/tools/libclang/CIndexer.h index d34547dffd..08162c563e 100644 --- a/tools/libclang/CIndexer.h +++ b/tools/libclang/CIndexer.h @@ -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 diff --git a/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp index 8a9cf233c0..9be4fa202c 100644 --- a/tools/libclang/CXCursor.cpp +++ b/tools/libclang/CXCursor.cpp @@ -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 +std::pair cxcursor::getCursorObjCSuperClassRef(CXCursor C) { assert(C.kind == CXCursor_ObjCSuperClassRef); - return std::make_pair(static_cast(C.data[0]), + return std::make_pair(static_cast(C.data[0]), SourceLocation::getFromRawEncoding( reinterpret_cast(C.data[1]))); } @@ -515,10 +516,10 @@ CXCursor cxcursor::MakeCursorObjCProtocolRef(const ObjCProtocolDecl *Proto, return C; } -std::pair +std::pair cxcursor::getCursorObjCProtocolRef(CXCursor C) { assert(C.kind == CXCursor_ObjCProtocolRef); - return std::make_pair(static_cast(C.data[0]), + return std::make_pair(static_cast(C.data[0]), SourceLocation::getFromRawEncoding( reinterpret_cast(C.data[1]))); } @@ -535,10 +536,10 @@ CXCursor cxcursor::MakeCursorObjCClassRef(const ObjCInterfaceDecl *Class, return C; } -std::pair +std::pair cxcursor::getCursorObjCClassRef(CXCursor C) { assert(C.kind == CXCursor_ObjCClassRef); - return std::make_pair(static_cast(C.data[0]), + return std::make_pair(static_cast(C.data[0]), SourceLocation::getFromRawEncoding( reinterpret_cast(C.data[1]))); } @@ -551,10 +552,10 @@ CXCursor cxcursor::MakeCursorTypeRef(const TypeDecl *Type, SourceLocation Loc, return C; } -std::pair +std::pair cxcursor::getCursorTypeRef(CXCursor C) { assert(C.kind == CXCursor_TypeRef); - return std::make_pair(static_cast(C.data[0]), + return std::make_pair(static_cast(C.data[0]), SourceLocation::getFromRawEncoding( reinterpret_cast(C.data[1]))); } @@ -568,10 +569,10 @@ CXCursor cxcursor::MakeCursorTemplateRef(const TemplateDecl *Template, return C; } -std::pair +std::pair cxcursor::getCursorTemplateRef(CXCursor C) { assert(C.kind == CXCursor_TemplateRef); - return std::make_pair(static_cast(C.data[0]), + return std::make_pair(static_cast(C.data[0]), SourceLocation::getFromRawEncoding( reinterpret_cast(C.data[1]))); } @@ -587,10 +588,10 @@ CXCursor cxcursor::MakeCursorNamespaceRef(const NamedDecl *NS, return C; } -std::pair +std::pair cxcursor::getCursorNamespaceRef(CXCursor C) { assert(C.kind == CXCursor_NamespaceRef); - return std::make_pair(static_cast(C.data[0]), + return std::make_pair(static_cast(C.data[0]), SourceLocation::getFromRawEncoding( reinterpret_cast(C.data[1]))); } @@ -604,10 +605,10 @@ CXCursor cxcursor::MakeCursorVariableRef(const VarDecl *Var, SourceLocation Loc, return C; } -std::pair +std::pair cxcursor::getCursorVariableRef(CXCursor C) { assert(C.kind == CXCursor_VariableRef); - return std::make_pair(static_cast(C.data[0]), + return std::make_pair(static_cast(C.data[0]), SourceLocation::getFromRawEncoding( reinterpret_cast(C.data[1]))); } @@ -621,10 +622,10 @@ CXCursor cxcursor::MakeCursorMemberRef(const FieldDecl *Field, SourceLocation Lo return C; } -std::pair +std::pair cxcursor::getCursorMemberRef(CXCursor C) { assert(C.kind == CXCursor_MemberRef); - return std::make_pair(static_cast(C.data[0]), + return std::make_pair(static_cast(C.data[0]), SourceLocation::getFromRawEncoding( reinterpret_cast(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(C.data[0]); + return static_cast(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(C.data[0]); + return static_cast(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(C.data[0]); + return static_cast(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 +std::pair cxcursor::getCursorLabelRef(CXCursor C) { assert(C.kind == CXCursor_LabelRef); - return std::make_pair(static_cast(C.data[0]), + return std::make_pair(static_cast(C.data[0]), SourceLocation::getFromRawEncoding( reinterpret_cast(C.data[1]))); } @@ -770,7 +771,8 @@ CXCursor cxcursor::MakeCursorOverloadedDeclRef(TemplateName Name, std::pair 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(C.data[0])), SourceLocation::getFromRawEncoding( reinterpret_cast(C.data[1]))); } @@ -812,7 +814,7 @@ ASTUnit *cxcursor::getCursorASTUnit(CXCursor Cursor) { } CXTranslationUnit cxcursor::getCursorTU(CXCursor Cursor) { - return static_cast(Cursor.data[2]); + return static_cast(const_cast(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 > + return llvm::DenseMapInfo > ::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(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(overridden->data[0]); + static_cast( + const_cast(overridden->data[0])); CXTranslationUnit TU = getCursorTU(*overridden); assert(Vec && TU); diff --git a/tools/libclang/CXCursor.h b/tools/libclang/CXCursor.h index 86fb975243..79892f4d29 100644 --- a/tools/libclang/CXCursor.h +++ b/tools/libclang/CXCursor.h @@ -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 +std::pair 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 +std::pair 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 +std::pair 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 getCursorTypeRef(CXCursor C); +std::pair 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 getCursorTemplateRef(CXCursor C); +std::pair + 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 getCursorNamespaceRef(CXCursor C); +std::pair 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 getCursorVariableRef(CXCursor C); +std::pair 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 getCursorMemberRef(CXCursor C); +std::pair 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(C.data[0]); + return static_cast(C.data[0]); } - MacroExpansion *getAsMacroExpansion() const { + const MacroExpansion *getAsMacroExpansion() const { assert(!isPseudo()); - return static_cast(C.data[0]); + return static_cast(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 getCursorLabelRef(CXCursor C); +std::pair getCursorLabelRef(CXCursor C); /// \brief Create a overloaded declaration reference cursor for an expression. CXCursor MakeCursorOverloadedDeclRef(OverloadExpr *E, CXTranslationUnit TU); diff --git a/tools/libclang/CXType.cpp b/tools/libclang/CXType.cpp index c18b48a82d..88c0e51181 100644 --- a/tools/libclang/CXType.cpp +++ b/tools/libclang/CXType.cpp @@ -635,23 +635,23 @@ CXString clang_getDeclObjCTypeEncoding(CXCursor C) { if (!clang_isDeclaration(C.kind)) return cxstring::createCXString(""); - Decl *D = static_cast(C.data[0]); + const Decl *D = static_cast(C.data[0]); ASTUnit *AU = cxcursor::getCursorASTUnit(C); ASTContext &Ctx = AU->getASTContext(); std::string encoding; - if (ObjCMethodDecl *OMD = dyn_cast(D)) { + if (const ObjCMethodDecl *OMD = dyn_cast(D)) { if (Ctx.getObjCEncodingForMethodDecl(OMD, encoding)) return cxstring::createCXString("?"); - } else if (ObjCPropertyDecl *OPD = dyn_cast(D)) + } else if (const ObjCPropertyDecl *OPD = dyn_cast(D)) Ctx.getObjCEncodingForPropertyDecl(OPD, NULL, encoding); - else if (FunctionDecl *FD = dyn_cast(D)) + else if (const FunctionDecl *FD = dyn_cast(D)) Ctx.getObjCEncodingForFunctionDecl(FD, encoding); else { QualType Ty; - if (TypeDecl *TD = dyn_cast(D)) + if (const TypeDecl *TD = dyn_cast(D)) Ty = Ctx.getTypeDeclType(TD); - if (ValueDecl *VD = dyn_cast(D)) + if (const ValueDecl *VD = dyn_cast(D)) Ty = VD->getType(); else return cxstring::createCXString("?"); Ctx.getObjCEncodingForType(Ty, encoding);