Remove support for Clang < 3.3

Change-Id: I185852a738bac10dc6d331afccfcbc7ae1225cb1
This commit is contained in:
Stephan Bergmann 2016-06-29 08:55:27 +02:00
parent 6439d93cbe
commit 1ce7176ba1
12 changed files with 29 additions and 155 deletions

View File

@ -34,13 +34,6 @@ class CheckConfigMacros
public:
explicit CheckConfigMacros( const InstantiationData& data );
virtual void run() override;
#if CLANG_VERSION < 30300
virtual void MacroDefined( const Token& macroToken, const MacroInfo* info ) override;
virtual void MacroUndefined( const Token& macroToken, const MacroInfo* info ) override;
virtual void Ifdef( SourceLocation location, const Token& macroToken ) override;
virtual void Ifndef( SourceLocation location, const Token& macroToken ) override;
virtual void Defined( const Token& macroToken ) override;
#else
virtual void MacroDefined( const Token& macroToken, const MacroDirective* info ) override;
#if CLANG_VERSION < 30700
virtual void MacroUndefined( const Token& macroToken, const MacroDirective* info ) override;
@ -57,7 +50,6 @@ class CheckConfigMacros
virtual void Defined( const Token& macroToken, const MacroDirective* info, SourceRange Range ) override;
#else
virtual void Defined( const Token& macroToken, const MacroDefinition& info, SourceRange Range ) override;
#endif
#endif
enum { isPPCallback = true };
private:
@ -76,15 +68,9 @@ void CheckConfigMacros::run()
// nothing, only check preprocessor usage
}
#if CLANG_VERSION < 30300
void CheckConfigMacros::MacroDefined( const Token& macroToken, const MacroInfo* info )
{
SourceLocation location = info->getDefinitionLoc();
#else
void CheckConfigMacros::MacroDefined( const Token& macroToken, const MacroDirective* info )
{
SourceLocation location = info->getLocation();
#endif
const char* filename = compiler.getSourceManager().getPresumedLoc( location ).getFilename();
if( filename != NULL
&& ( strncmp( filename, BUILDDIR "/config_host/", strlen( BUILDDIR "/config_host/" )) == 0
@ -95,9 +81,7 @@ void CheckConfigMacros::MacroDefined( const Token& macroToken, const MacroDirect
}
}
#if CLANG_VERSION < 30300
void CheckConfigMacros::MacroUndefined( const Token& macroToken, const MacroInfo* )
#elif CLANG_VERSION < 30700
#if CLANG_VERSION < 30700
void CheckConfigMacros::MacroUndefined( const Token& macroToken, const MacroDirective* )
#else
void CheckConfigMacros::MacroUndefined( const Token& macroToken, const MacroDefinition& )
@ -106,9 +90,7 @@ void CheckConfigMacros::MacroUndefined( const Token& macroToken, const MacroDefi
configMacros.erase( macroToken.getIdentifierInfo()->getName());
}
#if CLANG_VERSION < 30300
void CheckConfigMacros::Ifdef( SourceLocation location, const Token& macroToken )
#elif CLANG_VERSION < 30700
#if CLANG_VERSION < 30700
void CheckConfigMacros::Ifdef( SourceLocation location, const Token& macroToken, const MacroDirective* )
#else
void CheckConfigMacros::Ifdef( SourceLocation location, const Token& macroToken, const MacroDefinition& )
@ -117,9 +99,7 @@ void CheckConfigMacros::Ifdef( SourceLocation location, const Token& macroToken,
checkMacro( macroToken, location );
}
#if CLANG_VERSION < 30300
void CheckConfigMacros::Ifndef( SourceLocation location, const Token& macroToken )
#elif CLANG_VERSION < 30700
#if CLANG_VERSION < 30700
void CheckConfigMacros::Ifndef( SourceLocation location, const Token& macroToken, const MacroDirective* )
#else
void CheckConfigMacros::Ifndef( SourceLocation location, const Token& macroToken, const MacroDefinition& )
@ -128,9 +108,7 @@ void CheckConfigMacros::Ifndef( SourceLocation location, const Token& macroToken
checkMacro( macroToken, location );
}
#if CLANG_VERSION < 30300
void CheckConfigMacros::Defined( const Token& macroToken )
#elif CLANG_VERSION < 30400
#if CLANG_VERSION < 30400
void CheckConfigMacros::Defined( const Token& macroToken, const MacroDirective* )
#elif CLANG_VERSION < 30700
void CheckConfigMacros::Defined( const Token& macroToken, const MacroDirective* , SourceRange )

View File

@ -90,28 +90,6 @@ inline bool forallBases(
#endif
}
#if CLANG_VERSION >= 30300
typedef clang::LinkageInfo LinkageInfo;
#else
typedef clang::NamedDecl::LinkageInfo LinkageInfo;
#endif
inline clang::Linkage getLinkage(LinkageInfo const & info) {
#if CLANG_VERSION >= 30300
return info.getLinkage();
#else
return info.linkage();
#endif
}
inline clang::Visibility getVisibility(LinkageInfo const & info) {
#if CLANG_VERSION >= 30300
return info.getVisibility();
#else
return info.visibility();
#endif
}
inline bool isFirstDecl(clang::FunctionDecl const & decl) {
#if CLANG_VERSION >= 30400
return decl.isFirstDecl();
@ -251,30 +229,6 @@ inline std::unique_ptr<llvm::raw_fd_ostream> create_raw_fd_ostream(
#endif
}
#if CLANG_VERSION >= 30700
typedef clang::DeclContext::lookup_result DeclContextLookupResult;
typedef clang::DeclContext::lookup_iterator DeclContextLookupIterator;
#else
typedef clang::DeclContext::lookup_const_result DeclContextLookupResult;
typedef clang::DeclContext::lookup_const_iterator DeclContextLookupIterator;
#endif
inline DeclContextLookupIterator begin(DeclContextLookupResult const & result) {
#if CLANG_VERSION >= 30300
return result.begin();
#else
return result.first;
#endif
}
inline DeclContextLookupIterator end(DeclContextLookupResult const & result) {
#if CLANG_VERSION >= 30300
return result.end();
#else
return result.second;
#endif
}
inline void addPPCallbacks(
clang::Preprocessor & preprocessor, clang::PPCallbacks * C)
{
@ -303,16 +257,6 @@ inline bool isMacroArgExpansion(
#endif
}
inline bool isMacroBodyExpansion(clang::CompilerInstance& compiler, clang::SourceLocation location)
{
#if CLANG_VERSION >= 30300
return compiler.getSourceManager().isMacroBodyExpansion(location);
#else
return location.isMacroID()
&& !compiler.getSourceManager().isMacroArgExpansion(location);
#endif
}
inline auto getAsTagDecl(clang::Type const& t) -> clang::TagDecl *
{
#if CLANG_VERSION >= 30500

View File

@ -33,7 +33,7 @@ bool ExternAndNotDefined::VisitFunctionDecl(const FunctionDecl * functionDecl) {
return true;
}
if (functionDecl->isDefined() || functionDecl->isPure()
|| (compat::getLinkage(functionDecl->getLinkageAndVisibility())
|| (functionDecl->getLinkageAndVisibility().getLinkage()
!= ExternalLinkage)) {
return true;
}

View File

@ -224,15 +224,9 @@ bool hasCLanguageLinkageType(FunctionDecl const * decl) {
if (decl->isExternC()) {
return true;
}
#if CLANG_VERSION >= 30300
if (decl->isInExternCContext()) {
return true;
}
#else
if (decl->getCanonicalDecl()->getDeclContext()->isExternCContext()) {
return true;
}
#endif
return false;
}

View File

@ -93,7 +93,7 @@ void LiteralToBoolConversion::handleImplicitCastSubExpr(
while (compiler.getSourceManager().isMacroArgExpansion(loc)) {
loc = compiler.getSourceManager().getImmediateMacroCallerLoc(loc);
}
if (compat::isMacroBodyExpansion(compiler, loc)) {
if (compiler.getSourceManager().isMacroBodyExpansion(loc)) {
StringRef name { Lexer::getImmediateMacroName(
loc, compiler.getSourceManager(), compiler.getLangOpts()) };
if (name == "sal_False" || name == "sal_True") {

View File

@ -67,8 +67,6 @@ private:
bool isFromCIncludeFile(SourceLocation spellingLocation) const;
bool isMacroBodyExpansion(SourceLocation location) const;
void visitCXXCtorInitializer(CXXCtorInitializer const * init);
void handleZero(Expr const * expr);
@ -218,15 +216,6 @@ bool Nullptr::isFromCIncludeFile(SourceLocation spellingLocation) const {
.endswith(".h"));
}
bool Nullptr::isMacroBodyExpansion(SourceLocation location) const {
#if CLANG_VERSION >= 30300
return compiler.getSourceManager().isMacroBodyExpansion(location);
#else
return location.isMacroID()
&& !compiler.getSourceManager().isMacroArgExpansion(location);
#endif
}
void Nullptr::visitCXXCtorInitializer(CXXCtorInitializer const * init) {
if (!init->isWritten()) {
return;
@ -273,7 +262,7 @@ void Nullptr::handleNull(
while (compiler.getSourceManager().isMacroArgExpansion(loc)) {
loc = compiler.getSourceManager().getImmediateMacroCallerLoc(loc);
}
if (isMacroBodyExpansion(loc)) {
if (compiler.getSourceManager().isMacroBodyExpansion(loc)) {
if (Lexer::getImmediateMacroName(
loc, compiler.getSourceManager(), compiler.getLangOpts())
== "NULL")
@ -336,7 +325,8 @@ void Nullptr::rewriteOrWarn(
locStart = compiler.getSourceManager()
.getImmediateMacroCallerLoc(locStart);
}
if (compiler.getLangOpts().CPlusPlus && isMacroBodyExpansion(locStart)
if (compiler.getLangOpts().CPlusPlus
&& compiler.getSourceManager().isMacroBodyExpansion(locStart)
&& (Lexer::getImmediateMacroName(
locStart, compiler.getSourceManager(),
compiler.getLangOpts())
@ -350,7 +340,8 @@ void Nullptr::rewriteOrWarn(
locEnd = compiler.getSourceManager()
.getImmediateMacroCallerLoc(locEnd);
}
if (compiler.getLangOpts().CPlusPlus && isMacroBodyExpansion(locEnd)
if (compiler.getLangOpts().CPlusPlus
&& compiler.getSourceManager().isMacroBodyExpansion(locEnd)
&& (Lexer::getImmediateMacroName(
locEnd, compiler.getSourceManager(),
compiler.getLangOpts())

View File

@ -146,8 +146,8 @@ bool RedundantCast::VisitImplicitCastExpr(const ImplicitCastExpr * expr) {
&& isVoidPointer(
dyn_cast<CXXStaticCastExpr>(e)->getSubExpr()
->IgnoreParenImpCasts()->getType())
&& !compat::isMacroBodyExpansion(
compiler, e->getLocStart()))
&& !compiler.getSourceManager().isMacroBodyExpansion(
e->getLocStart()))
{
report(
DiagnosticsEngine::Warning,
@ -223,13 +223,13 @@ bool RedundantCast::VisitCXXReinterpretCastExpr(
loc = compiler.getSourceManager().getImmediateMacroCallerLoc(
loc);
}
if (compat::isMacroBodyExpansion(compiler, loc)) {
if (compiler.getSourceManager().isMacroBodyExpansion(loc)) {
auto loc2 = expr->getLocEnd();
while (compiler.getSourceManager().isMacroArgExpansion(loc2)) {
loc2 = compiler.getSourceManager()
.getImmediateMacroCallerLoc(loc2);
}
if (compat::isMacroBodyExpansion(compiler, loc2)) {
if (compiler.getSourceManager().isMacroBodyExpansion(loc2)) {
//TODO: check loc, loc2 are in same macro body expansion
loc = compiler.getSourceManager().getSpellingLoc(loc);
}

View File

@ -32,20 +32,6 @@ bool isSalBoolArray(QualType type) {
|| isSalBoolArray(t->getElementType()));
}
// Clang 3.2 FunctionDecl::isInlined doesn't work as advertised ("Determine
// whether this function should be inlined, because it is either marked 'inline'
// or 'constexpr' or is a member function of a class that was defined in the
// class body.") but mis-classifies salhelper::Timer's isTicking, isExpired, and
// expiresBefore members as defined in salhelper/source/timer.cxx as inlined:
bool isInlined(FunctionDecl const & decl) {
#if CLANG_VERSION >= 30300
return decl.isInlined();
#else
(void)decl;
return false;
#endif
}
// It appears that, given a function declaration, there is no way to determine
// the language linkage of the function's type, only of the function's name
// (via FunctionDecl::isExternC); however, in a case like
@ -61,15 +47,9 @@ bool hasCLanguageLinkageType(FunctionDecl const * decl) {
if (decl->isExternC()) {
return true;
}
#if CLANG_VERSION >= 30300
if (decl->isInExternCContext()) {
return true;
}
#else
if (decl->getCanonicalDecl()->getDeclContext()->isExternCContext()) {
return true;
}
#endif
return false;
}
@ -94,7 +74,7 @@ OverrideKind getOverrideKind(FunctionDecl const * decl) {
bool hasBoolOverload(FunctionDecl const * decl, bool mustBeDeleted) {
unsigned n = decl->getNumParams();
auto res = decl->getDeclContext()->lookup(decl->getDeclName());
for (auto d = compat::begin(res); d != compat::end(res); ++d) {
for (auto d = res.begin(); d != res.end(); ++d) {
FunctionDecl const * f = dyn_cast<FunctionDecl>(*d);
if (f != nullptr && (!mustBeDeleted || f->isDeleted())) {
if (f->getNumParams() == n) {
@ -298,7 +278,7 @@ bool SalBool::VisitCStyleCastExpr(CStyleCastExpr * expr) {
while (compiler.getSourceManager().isMacroArgExpansion(loc)) {
loc = compiler.getSourceManager().getImmediateMacroCallerLoc(loc);
}
if (compat::isMacroBodyExpansion(compiler, loc)) {
if (compiler.getSourceManager().isMacroBodyExpansion(loc)) {
StringRef name { Lexer::getImmediateMacroName(
loc, compiler.getSourceManager(), compiler.getLangOpts()) };
if (name == "sal_False" || name == "sal_True") {
@ -396,7 +376,7 @@ bool SalBool::VisitImplicitCastExpr(ImplicitCastExpr * expr) {
while (compiler.getSourceManager().isMacroArgExpansion(l)) {
l = compiler.getSourceManager().getImmediateMacroCallerLoc(l);
}
if (compat::isMacroBodyExpansion(compiler, l)) {
if (compiler.getSourceManager().isMacroBodyExpansion(l)) {
auto n = Lexer::getImmediateMacroName(
l, compiler.getSourceManager(), compiler.getLangOpts());
if (n == "sal_False" || n == "sal_True") {
@ -495,7 +475,7 @@ bool SalBool::VisitParmVarDecl(ParmVarDecl const * decl) {
|| (isInUnoIncludeFile(
compiler.getSourceManager().getSpellingLoc(
f->getNameInfo().getLoc()))
&& (!isInlined(*f) || f->hasAttr<DeprecatedAttr>()
&& (!f->isInlined() || f->hasAttr<DeprecatedAttr>()
|| decl->getType()->isReferenceType()
|| hasBoolOverload(f, false)))
|| f->isDeleted() || hasBoolOverload(f, true)))
@ -672,7 +652,7 @@ bool SalBool::VisitFunctionDecl(FunctionDecl const * decl) {
|| (isInUnoIncludeFile(
compiler.getSourceManager().getSpellingLoc(
f->getNameInfo().getLoc()))
&& (!isInlined(*f) || f->hasAttr<DeprecatedAttr>()))))
&& (!f->isInlined() || f->hasAttr<DeprecatedAttr>()))))
{
SourceLocation loc { decl->getLocStart() };
SourceLocation l { compiler.getSourceManager().getExpansionLoc(

View File

@ -440,7 +440,7 @@ bool ConstantFunction::VisitFunctionDecl(const FunctionDecl * pFunctionDecl) {
}
std::string aImmediateMacro = "";
if (compat::isMacroBodyExpansion(compiler, pFunctionDecl->getLocStart()) ) {
if (compiler.getSourceManager().isMacroBodyExpansion(pFunctionDecl->getLocStart()) ) {
StringRef name { Lexer::getImmediateMacroName(
pFunctionDecl->getLocStart(), compiler.getSourceManager(), compiler.getLangOpts()) };
aImmediateMacro = name;

View File

@ -34,12 +34,8 @@ class RtlConstAsciiMacro
bool VisitCXXConstructExpr( CXXConstructExpr* expr );
bool VisitCXXTemporaryObjectExpr( CXXTemporaryObjectExpr* expr );
bool VisitStringLiteral( const StringLiteral* literal );
#if CLANG_VERSION < 30300
virtual void MacroExpands( const Token& macro, const MacroInfo* info, SourceRange range ) override;
#else
virtual void MacroExpands( const Token& macro, const MacroDirective* directive,
SourceRange range, const MacroArgs* args ) override;
#endif
enum { isPPCallback = true };
private:
map< SourceLocation, SourceLocation > expansions; // start location -> end location
@ -59,12 +55,8 @@ void RtlConstAsciiMacro::run()
TraverseDecl( compiler.getASTContext().getTranslationUnitDecl());
}
#if CLANG_VERSION < 30300
void RtlConstAsciiMacro::MacroExpands( const Token& macro, const MacroInfo*, SourceRange range )
#else
void RtlConstAsciiMacro::MacroExpands( const Token& macro, const MacroDirective*,
SourceRange range, const MacroArgs* )
#endif
{
if( macro.getIdentifierInfo()->getName() != "RTL_CONSTASCII_USTRINGPARAM" )
return;

View File

@ -62,7 +62,7 @@ bool hasOverloads(FunctionDecl const * decl, unsigned arguments) {
ctx = ctx->getParent();
}
auto res = ctx->lookup(decl->getDeclName());
for (auto d = compat::begin(res); d != compat::end(res); ++d) {
for (auto d = res.begin(); d != res.end(); ++d) {
FunctionDecl const * f = dyn_cast<FunctionDecl>(*d);
if (f != nullptr && f->getMinRequiredArguments() <= arguments
&& f->getNumParams() >= arguments)
@ -782,7 +782,8 @@ bool StringConstant::VisitCXXConstructExpr(CXXConstructExpr const * expr) {
loc = compiler.getSourceManager()
.getImmediateMacroCallerLoc(loc);
}
if (compat::isMacroBodyExpansion(compiler, loc)
if ((compiler.getSourceManager()
.isMacroBodyExpansion(loc))
&& (Lexer::getImmediateMacroName(
loc, compiler.getSourceManager(),
compiler.getLangOpts())
@ -1119,7 +1120,7 @@ void StringConstant::reportChange(
while (compiler.getSourceManager().isMacroArgExpansion(loc)) {
loc = compiler.getSourceManager().getImmediateMacroCallerLoc(loc);
}
if (compat::isMacroBodyExpansion(compiler, loc)) {
if (compiler.getSourceManager().isMacroBodyExpansion(loc)) {
loc = compiler.getSourceManager().getSpellingLoc(loc);
}
unsigned n = Lexer::MeasureTokenLength(

View File

@ -33,15 +33,9 @@ bool hasCLanguageLinkageType(FunctionDecl const * decl) {
if (decl->isExternC()) {
return true;
}
#if CLANG_VERSION >= 30300
if (decl->isInExternCContext()) {
return true;
}
#else
if (decl->getCanonicalDecl()->getDeclContext()->isExternCContext()) {
return true;
}
#endif
return false;
}
@ -134,13 +128,13 @@ bool UnrefFun::VisitFunctionDecl(FunctionDecl const * decl) {
{
return true;
}
compat::LinkageInfo info(canon->getLinkageAndVisibility());
if (compat::getLinkage(info) == ExternalLinkage
LinkageInfo info(canon->getLinkageAndVisibility());
if (info.getLinkage() == ExternalLinkage
&& hasCLanguageLinkageType(canon) && canon->isDefined()
&& ((decl == canon && compat::getVisibility(info) == DefaultVisibility)
&& ((decl == canon && info.getVisibility() == DefaultVisibility)
|| ((canon->hasAttr<ConstructorAttr>()
|| canon->hasAttr<DestructorAttr>())
&& compat::getVisibility(info) == HiddenVisibility)))
&& info.getVisibility() == HiddenVisibility)))
{
return true;
}