These version checks are about the Clang the plugins are built /against/

...not the (Clang) compiler they are being built /with/.  (Also simplifies the
checking #if code.)

Change-Id: I416321be4ef4478785be40571f81500fd3b6feb8
This commit is contained in:
Stephan Bergmann
2016-02-26 12:50:16 +01:00
parent cd2725de90
commit 01f3b95884
20 changed files with 66 additions and 60 deletions

View File

@@ -14,7 +14,7 @@ CLANG_COMMA :=,
CLANGCXX=$(filter-out -m32 -m64 -fsanitize=%,$(CXX))
# Compile flags ('make CLANGCXXFLAGS=-g' if you need to debug the plugin)
CLANGCXXFLAGS=-O2 -Wall -Wextra -g
CLANGCXXFLAGS=-O2 -Wall -Wextra -Wundef -g
# The uninteresting rest.

View File

@@ -34,7 +34,7 @@ class CheckConfigMacros
public:
explicit CheckConfigMacros( const InstantiationData& data );
virtual void run() override;
#if __clang_major__ < 3 || __clang_major__ == 3 && __clang_minor__ < 3
#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;
@@ -42,7 +42,7 @@ class CheckConfigMacros
virtual void Defined( const Token& macroToken ) override;
#else
virtual void MacroDefined( const Token& macroToken, const MacroDirective* info ) override;
#if __clang_major__ == 3 && __clang_minor__ < 7
#if CLANG_VERSION < 30700
virtual void MacroUndefined( const Token& macroToken, const MacroDirective* info ) override;
virtual void Ifdef( SourceLocation location, const Token& macroToken, const MacroDirective* info ) override;
virtual void Ifndef( SourceLocation location, const Token& macroToken, const MacroDirective* info ) override;
@@ -51,9 +51,9 @@ class CheckConfigMacros
virtual void Ifdef( SourceLocation location, const Token& macroToken, const MacroDefinition& info ) override;
virtual void Ifndef( SourceLocation location, const Token& macroToken, const MacroDefinition& info ) override;
#endif
#if __clang_major__ == 3 && __clang_minor__ < 4
#if CLANG_VERSION < 30400
virtual void Defined( const Token& macroToken, const MacroDirective* info ) override;
#elif __clang_major__ == 3 && __clang_minor__ < 7
#elif CLANG_VERSION < 30700
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;
@@ -76,7 +76,7 @@ void CheckConfigMacros::run()
// nothing, only check preprocessor usage
}
#if __clang_major__ < 3 || __clang_major__ == 3 && __clang_minor__ < 3
#if CLANG_VERSION < 30300
void CheckConfigMacros::MacroDefined( const Token& macroToken, const MacroInfo* info )
{
SourceLocation location = info->getDefinitionLoc();
@@ -95,9 +95,9 @@ void CheckConfigMacros::MacroDefined( const Token& macroToken, const MacroDirect
}
}
#if __clang_major__ < 3 || __clang_major__ == 3 && __clang_minor__ < 3
#if CLANG_VERSION < 30300
void CheckConfigMacros::MacroUndefined( const Token& macroToken, const MacroInfo* )
#elif __clang_major__ == 3 && __clang_minor__ < 7
#elif CLANG_VERSION < 30700
void CheckConfigMacros::MacroUndefined( const Token& macroToken, const MacroDirective* )
#else
void CheckConfigMacros::MacroUndefined( const Token& macroToken, const MacroDefinition& )
@@ -106,9 +106,9 @@ void CheckConfigMacros::MacroUndefined( const Token& macroToken, const MacroDefi
configMacros.erase( macroToken.getIdentifierInfo()->getName());
}
#if __clang_major__ < 3 || __clang_major__ == 3 && __clang_minor__ < 3
#if CLANG_VERSION < 30300
void CheckConfigMacros::Ifdef( SourceLocation location, const Token& macroToken )
#elif __clang_major__ == 3 && __clang_minor__ < 7
#elif 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 +117,9 @@ void CheckConfigMacros::Ifdef( SourceLocation location, const Token& macroToken,
checkMacro( macroToken, location );
}
#if __clang_major__ < 3 || __clang_major__ == 3 && __clang_minor__ < 3
#if CLANG_VERSION < 30300
void CheckConfigMacros::Ifndef( SourceLocation location, const Token& macroToken )
#elif __clang_major__ == 3 && __clang_minor__ < 7
#elif 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,11 +128,11 @@ void CheckConfigMacros::Ifndef( SourceLocation location, const Token& macroToken
checkMacro( macroToken, location );
}
#if __clang_major__ < 3 || __clang_major__ == 3 && __clang_minor__ < 3
#if CLANG_VERSION < 30300
void CheckConfigMacros::Defined( const Token& macroToken )
#elif __clang_major__ == 3 && __clang_minor__ < 4
#elif CLANG_VERSION < 30400
void CheckConfigMacros::Defined( const Token& macroToken, const MacroDirective* )
#elif __clang_major__ == 3 && __clang_minor__ < 7
#elif CLANG_VERSION < 30700
void CheckConfigMacros::Defined( const Token& macroToken, const MacroDirective* , SourceRange )
#else
void CheckConfigMacros::Defined( const Token& macroToken, const MacroDefinition& , SourceRange )

View File

@@ -30,7 +30,9 @@
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/raw_ostream.h"
#if (__clang_major__ == 3 && __clang_minor__ >= 4) || __clang_major__ > 3
#include "config_clang.h"
#if CLANG_VERSION >= 30400
#define LO_COMPILERPLUGINS_CLANG_COMPAT_HAVE_isAtEndOfImmediateMacroExpansion \
true
#else
@@ -42,7 +44,7 @@
namespace compat {
inline bool isLookupContext(clang::DeclContext const & ctxt) {
#if (__clang_major__ == 3 && __clang_minor__ >= 7) || __clang_major__ > 3
#if CLANG_VERSION >= 30700
return ctxt.isLookupContext();
#else
return !ctxt.isFunctionOrMethod()
@@ -51,7 +53,7 @@ inline bool isLookupContext(clang::DeclContext const & ctxt) {
}
inline bool isExternCContext(clang::DeclContext const & ctxt) {
#if (__clang_major__ == 3 && __clang_minor__ >= 4) || __clang_major__ > 3
#if CLANG_VERSION >= 30400
return ctxt.isExternCContext();
#else
for (clang::DeclContext const * c = &ctxt;
@@ -67,7 +69,7 @@ inline bool isExternCContext(clang::DeclContext const & ctxt) {
}
inline bool isInExternCContext(clang::FunctionDecl const & decl) {
#if (__clang_major__ == 3 && __clang_minor__ >= 4) || __clang_major__ > 3
#if CLANG_VERSION >= 30400
return decl.isInExternCContext();
#else
return isExternCContext(*decl.getCanonicalDecl()->getDeclContext());
@@ -80,7 +82,7 @@ inline bool forallBases(
void* callbackParam,
bool AllowShortCircuit)
{
#if (__clang_major__ == 3 && __clang_minor__ > 7) || __clang_major__ > 3
#if CLANG_VERSION >= 30700
(void) callbackParam;
return decl.forallBases(BaseMatches, AllowShortCircuit);
#else
@@ -88,14 +90,14 @@ inline bool forallBases(
#endif
}
#if (__clang_major__ == 3 && __clang_minor__ >= 3) || __clang_major__ > 3
#if CLANG_VERSION >= 30300
typedef clang::LinkageInfo LinkageInfo;
#else
typedef clang::NamedDecl::LinkageInfo LinkageInfo;
#endif
inline clang::Linkage getLinkage(LinkageInfo const & info) {
#if (__clang_major__ == 3 && __clang_minor__ >= 3) || __clang_major__ > 3
#if CLANG_VERSION >= 30300
return info.getLinkage();
#else
return info.linkage();
@@ -103,7 +105,7 @@ inline clang::Linkage getLinkage(LinkageInfo const & info) {
}
inline clang::Visibility getVisibility(LinkageInfo const & info) {
#if (__clang_major__ == 3 && __clang_minor__ >= 3) || __clang_major__ > 3
#if CLANG_VERSION >= 30300
return info.getVisibility();
#else
return info.visibility();
@@ -111,7 +113,7 @@ inline clang::Visibility getVisibility(LinkageInfo const & info) {
}
inline bool isFirstDecl(clang::FunctionDecl const & decl) {
#if (__clang_major__ == 3 && __clang_minor__ >= 4) || __clang_major__ > 3
#if CLANG_VERSION >= 30400
return decl.isFirstDecl();
#else
return decl.isFirstDeclaration();
@@ -119,7 +121,7 @@ inline bool isFirstDecl(clang::FunctionDecl const & decl) {
}
inline clang::QualType getReturnType(clang::FunctionDecl const & decl) {
#if (__clang_major__ == 3 && __clang_minor__ >= 5) || __clang_major__ > 3
#if CLANG_VERSION >= 30500
return decl.getReturnType();
#else
return decl.getResultType();
@@ -127,7 +129,7 @@ inline clang::QualType getReturnType(clang::FunctionDecl const & decl) {
}
inline clang::QualType getReturnType(clang::FunctionProtoType const & type) {
#if (__clang_major__ == 3 && __clang_minor__ >= 5) || __clang_major__ > 3
#if CLANG_VERSION >= 30500
return type.getReturnType();
#else
return type.getResultType();
@@ -135,7 +137,7 @@ inline clang::QualType getReturnType(clang::FunctionProtoType const & type) {
}
inline unsigned getNumParams(clang::FunctionProtoType const & type) {
#if (__clang_major__ == 3 && __clang_minor__ >= 5) || __clang_major__ > 3
#if CLANG_VERSION >= 30500
return type.getNumParams();
#else
return type.getNumArgs();
@@ -145,7 +147,7 @@ inline unsigned getNumParams(clang::FunctionProtoType const & type) {
inline clang::QualType getParamType(
clang::FunctionProtoType const & type, unsigned i)
{
#if (__clang_major__ == 3 && __clang_minor__ >= 5) || __clang_major__ > 3
#if CLANG_VERSION >= 30500
return type.getParamType(i);
#else
return type.getArgType(i);
@@ -155,7 +157,7 @@ inline clang::QualType getParamType(
inline clang::Stmt::const_child_iterator begin(
clang::Stmt::const_child_range const & range)
{
#if (__clang_major__ == 3 && __clang_minor__ > 7) || __clang_major__ > 3
#if CLANG_VERSION >= 30700
return range.begin();
#else
return range.first;
@@ -165,7 +167,7 @@ inline clang::Stmt::const_child_iterator begin(
inline clang::Stmt::const_child_iterator end(
clang::Stmt::const_child_range const & range)
{
#if (__clang_major__ == 3 && __clang_minor__ > 7) || __clang_major__ > 3
#if CLANG_VERSION >= 30700
return range.end();
#else
return range.second;
@@ -173,7 +175,7 @@ inline clang::Stmt::const_child_iterator end(
}
inline unsigned getBuiltinCallee(clang::CallExpr const & expr) {
#if (__clang_major__ == 3 && __clang_minor__ >= 5) || __clang_major__ > 3
#if CLANG_VERSION >= 30500
return expr.getBuiltinCallee();
#else
return expr.isBuiltinCall();
@@ -183,7 +185,7 @@ inline unsigned getBuiltinCallee(clang::CallExpr const & expr) {
inline bool isInMainFile(
clang::SourceManager const & manager, clang::SourceLocation Loc)
{
#if (__clang_major__ == 3 && __clang_minor__ >= 4) || __clang_major__ > 3
#if CLANG_VERSION >= 30400
return manager.isInMainFile(Loc);
#else
return manager.isFromMainFile(Loc);
@@ -194,7 +196,7 @@ inline unsigned getCustomDiagID(
clang::DiagnosticsEngine & engine, clang::DiagnosticsEngine::Level L,
llvm::StringRef FormatString)
{
#if (__clang_major__ == 3 && __clang_minor__ >= 5) || __clang_major__ > 3
#if CLANG_VERSION >= 30500
return engine.getDiagnosticIDs()->getCustomDiagID(
static_cast<clang::DiagnosticIDs::Level>(L), FormatString);
#else
@@ -205,13 +207,13 @@ inline unsigned getCustomDiagID(
inline std::unique_ptr<llvm::raw_fd_ostream> create_raw_fd_ostream(
char const * Filename, std::string & ErrorInfo)
{
#if (__clang_major__ == 3 && __clang_minor__ >= 6) || __clang_major__ > 3
#if CLANG_VERSION >= 30600
std::error_code ec;
std::unique_ptr<llvm::raw_fd_ostream> s(
new llvm::raw_fd_ostream(Filename, ec, llvm::sys::fs::F_None));
ErrorInfo = ec ? "error: " + ec.message() : std::string();
return s;
#elif __clang_major__ == 3 && __clang_minor__ == 5
#elif CLANG_VERSION >= 30500
return std::unique_ptr<llvm::raw_fd_ostream>(
new llvm::raw_fd_ostream(Filename, ErrorInfo, llvm::sys::fs::F_None));
#else
@@ -220,7 +222,7 @@ inline std::unique_ptr<llvm::raw_fd_ostream> create_raw_fd_ostream(
#endif
}
#if (__clang_major__ == 3 && __clang_minor__ >= 7) || __clang_major__ > 3
#if CLANG_VERSION >= 30700
typedef clang::DeclContext::lookup_result DeclContextLookupResult;
typedef clang::DeclContext::lookup_iterator DeclContextLookupIterator;
#else
@@ -229,7 +231,7 @@ typedef clang::DeclContext::lookup_const_iterator DeclContextLookupIterator;
#endif
inline DeclContextLookupIterator begin(DeclContextLookupResult const & result) {
#if (__clang_major__ == 3 && __clang_minor__ >= 3) || __clang_major__ > 3
#if CLANG_VERSION >= 30300
return result.begin();
#else
return result.first;
@@ -237,7 +239,7 @@ inline DeclContextLookupIterator begin(DeclContextLookupResult const & result) {
}
inline DeclContextLookupIterator end(DeclContextLookupResult const & result) {
#if (__clang_major__ == 3 && __clang_minor__ >= 3) || __clang_major__ > 3
#if CLANG_VERSION >= 30300
return result.end();
#else
return result.second;
@@ -247,7 +249,7 @@ inline DeclContextLookupIterator end(DeclContextLookupResult const & result) {
inline void addPPCallbacks(
clang::Preprocessor & preprocessor, clang::PPCallbacks * C)
{
#if (__clang_major__ == 3 && __clang_minor__ >= 6) || __clang_major__ > 3
#if CLANG_VERSION >= 30600
preprocessor.addPPCallbacks(std::unique_ptr<clang::PPCallbacks>(C));
#else
preprocessor.addPPCallbacks(C);
@@ -256,7 +258,7 @@ inline void addPPCallbacks(
inline bool isMacroBodyExpansion(clang::CompilerInstance& compiler, clang::SourceLocation location)
{
#if (__clang_major__ == 3 && __clang_minor__ >= 3) || __clang_major__ > 3
#if CLANG_VERSION >= 30300
return compiler.getSourceManager().isMacroBodyExpansion(location);
#else
return location.isMacroID()
@@ -266,7 +268,7 @@ inline bool isMacroBodyExpansion(clang::CompilerInstance& compiler, clang::Sourc
inline auto getAsTagDecl(clang::Type const& t) -> clang::TagDecl *
{
#if (__clang_major__ == 3 && __clang_minor__ > 5) || __clang_major__ > 3
#if CLANG_VERSION >= 30500
// TODO not sure if it works with clang 3.6, trunk is known to work
return t.getAsTagDecl();
#else

View File

@@ -12,7 +12,8 @@
#if defined(__unix__)
// only compile this on clang 3.7 or higher, which is known to work
// there were problems on clang 3.5 at least
#if (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 7))
#include "config_clang.h"
#if CLANG_VERSION >= 30700
#include <cassert>
#include <stdlib.h>
#include <string>

View File

@@ -18,7 +18,7 @@
#include "compat.hxx"
#include "plugin.hxx"
#if __clang_major__ == 3 && __clang_minor__ < 7
#if CLANG_VERSION < 30700
template<> struct std::iterator_traits<ExprIterator> {
typedef std::ptrdiff_t difference_type;
@@ -230,7 +230,7 @@ bool hasCLanguageLinkageType(FunctionDecl const * decl) {
if (decl->isExternC()) {
return true;
}
#if (__clang_major__ == 3 && __clang_minor__ >= 3) || __clang_major__ > 3
#if CLANG_VERSION >= 30300
if (decl->isInExternCContext()) {
return true;
}

View File

@@ -193,7 +193,7 @@ bool Nullptr::isFromCIncludeFile(SourceLocation spellingLocation) const {
}
bool Nullptr::isMacroBodyExpansion(SourceLocation location) const {
#if (__clang_major__ == 3 && __clang_minor__ >= 3) || __clang_major__ > 3
#if CLANG_VERSION >= 30300
return compiler.getSourceManager().isMacroBodyExpansion(location);
#else
return location.isMacroID()

View File

@@ -250,7 +250,7 @@ void PluginHandler::HandleTranslationUnit( ASTContext& context )
}
}
#if (__clang_major__ == 3 && __clang_minor__ >= 6) || __clang_major__ > 3
#if CLANG_VERSION >= 30600
std::unique_ptr<ASTConsumer> LibreOfficeAction::CreateASTConsumer( CompilerInstance& Compiler, StringRef )
{
return llvm::make_unique<PluginHandler>( Compiler, _args );

View File

@@ -54,7 +54,7 @@ class LibreOfficeAction
: public PluginASTAction
{
public:
#if (__clang_major__ == 3 && __clang_minor__ >= 6) || __clang_major__ > 3
#if CLANG_VERSION >= 30600
virtual std::unique_ptr<ASTConsumer> CreateASTConsumer( CompilerInstance& Compiler, StringRef InFile );
#else
virtual ASTConsumer* CreateASTConsumer( CompilerInstance& Compiler, StringRef InFile );

View File

@@ -83,7 +83,7 @@ bool isDerivedFrom(const CXXRecordDecl *decl, const char *pString) {
!decl->hasAnyDependentBases() &&
!compat::forallBases(
*decl,
#if __clang_major__ == 3 && __clang_minor__ <= 7
#if CLANG_VERSION < 30800
BaseCheckNotSubclass,
#else
[pString](const CXXRecordDecl *BaseDefinition) -> bool

View File

@@ -30,7 +30,7 @@ bool isSalBool(QualType type) {
// 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_major__ == 3 && __clang_minor__ >= 3) || __clang_major__ > 3
#if CLANG_VERSION >= 30300
return decl.isInlined();
#else
(void)decl;
@@ -53,7 +53,7 @@ bool hasCLanguageLinkageType(FunctionDecl const * decl) {
if (decl->isExternC()) {
return true;
}
#if (__clang_major__ == 3 && __clang_minor__ >= 3) || __clang_major__ > 3
#if CLANG_VERSION >= 30300
if (decl->isInExternCContext()) {
return true;
}

View File

@@ -34,7 +34,7 @@ public:
bool BaseCheckNotSfxPoolItemSubclass(
const CXXRecordDecl *BaseDefinition
#if __clang_major__ == 3 && __clang_minor__ <= 7
#if CLANG_VERSION < 30800
, void *
#endif
)
@@ -65,7 +65,7 @@ bool isDerivedFromSfxPoolItem(const CXXRecordDecl *decl) {
bool BaseCheckNotSwMsgPoolItemSubclass(
const CXXRecordDecl *BaseDefinition
#if __clang_major__ == 3 && __clang_minor__ <= 7
#if CLANG_VERSION < 30800
, void *
#endif
)

View File

@@ -38,7 +38,7 @@ private:
bool BaseCheckNotTestFixtureSubclass(
const CXXRecordDecl *BaseDefinition
#if __clang_major__ == 3 && __clang_minor__ <= 7
#if CLANG_VERSION < 30800
, void *
#endif
)

View File

@@ -185,7 +185,7 @@ found:
}
bool StdException::isInMainFile(SourceLocation spellingLocation) const {
#if (__clang_major__ == 3 && __clang_minor__ >= 4) || __clang_major__ > 3
#if CLANG_VERSION >= 30400
return compiler.getSourceManager().isInMainFile(spellingLocation);
#else
return compiler.getSourceManager().isFromMainFile(spellingLocation);

View File

@@ -33,7 +33,7 @@ bool hasCLanguageLinkageType(FunctionDecl const * decl) {
if (decl->isExternC()) {
return true;
}
#if (__clang_major__ == 3 && __clang_minor__ >= 3) || __clang_major__ > 3
#if CLANG_VERSION >= 30300
if (decl->isInExternCContext()) {
return true;
}
@@ -147,7 +147,7 @@ bool UnrefFun::VisitFunctionDecl(FunctionDecl const * decl) {
report(
DiagnosticsEngine::Warning,
(canon->isDefined()
#if (__clang_major__ == 3 && __clang_minor__ >= 4) || __clang_major__ > 3
#if CLANG_VERSION >= 30400
? (canon->isExternallyVisible()
? "Unreferenced externally visible function%0 definition"
: "Unreferenced externally invisible function%0 definition")

View File

@@ -81,7 +81,7 @@ MyFuncInfo UnusedDefaultParams::niceName(const FunctionDecl* functionDecl)
else if (functionDecl->getClassScopeSpecializationPattern())
functionDecl = functionDecl->getClassScopeSpecializationPattern();
// workaround clang-3.5 issue
#if __clang_major__ > 3 || ( __clang_major__ == 3 && __clang_minor__ >= 6 )
#if CLANG_VERSION >= 30600
else if (functionDecl->getTemplateInstantiationPattern())
functionDecl = functionDecl->getTemplateInstantiationPattern();
#endif

View File

@@ -119,7 +119,7 @@ MyFuncInfo UnusedMethods::niceName(const FunctionDecl* functionDecl)
else if (functionDecl->getClassScopeSpecializationPattern())
functionDecl = functionDecl->getClassScopeSpecializationPattern();
// workaround clang-3.5 issue
#if __clang_major__ > 3 || ( __clang_major__ == 3 && __clang_minor__ >= 6 )
#if CLANG_VERSION >= 30600
else if (functionDecl->getTemplateInstantiationPattern())
functionDecl = functionDecl->getTemplateInstantiationPattern();
#endif

View File

@@ -51,7 +51,7 @@ void UnusedVariableCheck::run()
bool BaseCheckNotDialogSubclass(
const CXXRecordDecl *BaseDefinition
#if __clang_major__ == 3 && __clang_minor__ <= 7
#if CLANG_VERSION < 30800
, void *
#endif
)

View File

@@ -59,7 +59,7 @@ static bool startsWith(const std::string& s, const char* other)
bool BaseCheckNotWindowSubclass(
const CXXRecordDecl *BaseDefinition
#if __clang_major__ == 3 && __clang_minor__ <= 7
#if CLANG_VERSION < 30800
, void *
#endif
)