Kaydet (Commit) c15b4cf3 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Adapt to current Clang trunk towards 3.7

Change-Id: Ibb2c641d49a1773be789c9259f53a040db6f605f
üst f17f89aa
...@@ -65,6 +65,18 @@ inline bool isInExternCContext(clang::FunctionDecl const & decl) { ...@@ -65,6 +65,18 @@ inline bool isInExternCContext(clang::FunctionDecl const & decl) {
#endif #endif
} }
inline bool forallBases(
clang::CXXRecordDecl const & decl,
clang::CXXRecordDecl::ForallBasesCallback BaseMatches,
bool AllowShortCircuit)
{
#if (__clang_major__ == 3 && __clang_minor__ >= 7) || __clang_major__ > 3
return decl.forallBases(BaseMatches, AllowShortCircuit);
#else
return decl.forallBases(BaseMatches, nullptr, AllowShortCircuit);
#endif
}
#if (__clang_major__ == 3 && __clang_minor__ >= 3) || __clang_major__ > 3 #if (__clang_major__ == 3 && __clang_minor__ >= 3) || __clang_major__ > 3
typedef clang::LinkageInfo LinkageInfo; typedef clang::LinkageInfo LinkageInfo;
#else #else
...@@ -129,6 +141,26 @@ inline clang::QualType getParamType( ...@@ -129,6 +141,26 @@ inline clang::QualType getParamType(
#endif #endif
} }
inline clang::Stmt::const_child_iterator begin(
clang::Stmt::const_child_range const & range)
{
#if (__clang_major__ == 3 && __clang_minor__ >= 7) || __clang_major__ > 3
return range.begin();
#else
return range.first;
#endif
}
inline clang::Stmt::const_child_iterator end(
clang::Stmt::const_child_range const & range)
{
#if (__clang_major__ == 3 && __clang_minor__ >= 7) || __clang_major__ > 3
return range.end();
#else
return range.second;
#endif
}
inline unsigned getBuiltinCallee(clang::CallExpr const & expr) { inline unsigned getBuiltinCallee(clang::CallExpr const & expr) {
#if (__clang_major__ == 3 && __clang_minor__ >= 5) || __clang_major__ > 3 #if (__clang_major__ == 3 && __clang_minor__ >= 5) || __clang_major__ > 3
return expr.getBuiltinCallee(); return expr.getBuiltinCallee();
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
#include "compat.hxx" #include "compat.hxx"
#include "plugin.hxx" #include "plugin.hxx"
#if __clang_major__ == 3 && __clang_minor__ < 7
template<> struct std::iterator_traits<ExprIterator> { template<> struct std::iterator_traits<ExprIterator> {
typedef std::ptrdiff_t difference_type; typedef std::ptrdiff_t difference_type;
typedef Expr * value_type; typedef Expr * value_type;
...@@ -34,6 +36,8 @@ template<> struct std::iterator_traits<ConstExprIterator> { ...@@ -34,6 +36,8 @@ template<> struct std::iterator_traits<ConstExprIterator> {
typedef std::random_access_iterator_tag iterator_category; typedef std::random_access_iterator_tag iterator_category;
}; };
#endif
namespace { namespace {
Expr const * ignoreParenAndTemporaryMaterialization(Expr const * expr) { Expr const * ignoreParenAndTemporaryMaterialization(Expr const * expr) {
......
...@@ -31,10 +31,10 @@ private: ...@@ -31,10 +31,10 @@ private:
}; };
static bool oneAndOnlyOne(clang::Stmt::const_child_range range) { static bool oneAndOnlyOne(clang::Stmt::const_child_range range) {
if (range.empty()) { if (compat::begin(range) == compat::end(range)) {
return false; return false;
} }
if ((++range.first) != range.second) { if (++compat::begin(range) != compat::end(range)) {
return false; return false;
} }
return true; return true;
...@@ -134,7 +134,7 @@ bool InlineSimpleMemberFunctions::VisitCXXMethodDecl(const CXXMethodDecl * funct ...@@ -134,7 +134,7 @@ bool InlineSimpleMemberFunctions::VisitCXXMethodDecl(const CXXMethodDecl * funct
{ {
childStmt2 = *childStmt2->child_begin(); childStmt2 = *childStmt2->child_begin();
if (dyn_cast<CXXThisExpr>( childStmt2 ) != nullptr if (dyn_cast<CXXThisExpr>( childStmt2 ) != nullptr
&& childStmt2->children().empty()) && compat::begin(childStmt2->children()) == compat::end(childStmt2->children()))
{ {
return true; return true;
} }
...@@ -145,7 +145,7 @@ bool InlineSimpleMemberFunctions::VisitCXXMethodDecl(const CXXMethodDecl * funct ...@@ -145,7 +145,7 @@ bool InlineSimpleMemberFunctions::VisitCXXMethodDecl(const CXXMethodDecl * funct
{ {
const Stmt* childStmt2 = *childStmt->child_begin(); const Stmt* childStmt2 = *childStmt->child_begin();
if (dyn_cast<CXXThisExpr>( childStmt2 ) != nullptr if (dyn_cast<CXXThisExpr>( childStmt2 ) != nullptr
&& childStmt2->children().empty()) && compat::begin(childStmt2->children()) == compat::end(childStmt2->children()))
{ {
return true; return true;
} }
...@@ -208,7 +208,7 @@ bool InlineSimpleMemberFunctions::VisitCXXMethodDecl(const CXXMethodDecl * funct ...@@ -208,7 +208,7 @@ bool InlineSimpleMemberFunctions::VisitCXXMethodDecl(const CXXMethodDecl * funct
} }
return true; return true;
} }
if ( childStmt->children().empty() ) if ( compat::begin(childStmt->children()) == compat::end(childStmt->children()) )
return true; return true;
childStmt = *childStmt->child_begin(); childStmt = *childStmt->child_begin();
} }
......
...@@ -73,7 +73,17 @@ bool isDerivedFrom(const CXXRecordDecl *decl, const char *pString) { ...@@ -73,7 +73,17 @@ bool isDerivedFrom(const CXXRecordDecl *decl, const char *pString) {
if (// not sure what hasAnyDependentBases() does, if (// not sure what hasAnyDependentBases() does,
// but it avoids classes we don't want, e.g. WeakAggComponentImplHelper1 // but it avoids classes we don't want, e.g. WeakAggComponentImplHelper1
!decl->hasAnyDependentBases() && !decl->hasAnyDependentBases() &&
!decl->forallBases(BaseCheckNotSubclass, static_cast<void*>(const_cast<char*>(pString)), true)) { !compat::forallBases(
*decl,
#if __clang_major__ == 3 && __clang_minor__ < 7
BaseCheckNotSubclass,
#else
[pString](const CXXRecordDecl *BaseDefinition) -> bool
{ return BaseCheckNotSubclass(
BaseDefinition, const_cast<char *>(pString)); },
#endif
true))
{
return true; return true;
} }
return false; return false;
......
...@@ -36,7 +36,13 @@ private: ...@@ -36,7 +36,13 @@ private:
std::string getFilename(SourceLocation loc); std::string getFilename(SourceLocation loc);
}; };
bool BaseCheckNotTestFixtureSubclass(const CXXRecordDecl *BaseDefinition, void *) { bool BaseCheckNotTestFixtureSubclass(
const CXXRecordDecl *BaseDefinition
#if __clang_major__ == 3 && __clang_minor__ < 7
, void *
#endif
)
{
if (BaseDefinition->getQualifiedNameAsString().compare("CppUnit::TestFixture") == 0) { if (BaseDefinition->getQualifiedNameAsString().compare("CppUnit::TestFixture") == 0) {
return false; return false;
} }
...@@ -49,7 +55,7 @@ bool isDerivedFromTestFixture(const CXXRecordDecl *decl) { ...@@ -49,7 +55,7 @@ bool isDerivedFromTestFixture(const CXXRecordDecl *decl) {
if (// not sure what hasAnyDependentBases() does, if (// not sure what hasAnyDependentBases() does,
// but it avoids classes we don't want, e.g. WeakAggComponentImplHelper1 // but it avoids classes we don't want, e.g. WeakAggComponentImplHelper1
!decl->hasAnyDependentBases() && !decl->hasAnyDependentBases() &&
!decl->forallBases(BaseCheckNotTestFixtureSubclass, nullptr, true)) { !compat::forallBases(*decl, BaseCheckNotTestFixtureSubclass, true)) {
return true; return true;
} }
return false; return false;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
// (LO classes won't get duplicated warnings, as the attribute is different). // (LO classes won't get duplicated warnings, as the attribute is different).
#if !HAVE_GCC_ATTRIBUTE_WARN_UNUSED_STL #if !HAVE_GCC_ATTRIBUTE_WARN_UNUSED_STL
#include "compat.hxx"
#include "unusedvariablecheck.hxx" #include "unusedvariablecheck.hxx"
#include <clang/AST/Attr.h> #include <clang/AST/Attr.h>
...@@ -48,7 +49,13 @@ void UnusedVariableCheck::run() ...@@ -48,7 +49,13 @@ void UnusedVariableCheck::run()
TraverseDecl( compiler.getASTContext().getTranslationUnitDecl()); TraverseDecl( compiler.getASTContext().getTranslationUnitDecl());
} }
bool BaseCheckNotDialogSubclass(const CXXRecordDecl *BaseDefinition, void *) { bool BaseCheckNotDialogSubclass(
const CXXRecordDecl *BaseDefinition
#if __clang_major__ == 3 && __clang_minor__ < 7
, void *
#endif
)
{
if (BaseDefinition && BaseDefinition->getQualifiedNameAsString().compare("Dialog") == 0) { if (BaseDefinition && BaseDefinition->getQualifiedNameAsString().compare("Dialog") == 0) {
return false; return false;
} }
...@@ -66,7 +73,7 @@ bool isDerivedFromDialog(const CXXRecordDecl *decl) { ...@@ -66,7 +73,7 @@ bool isDerivedFromDialog(const CXXRecordDecl *decl) {
if (// not sure what hasAnyDependentBases() does, if (// not sure what hasAnyDependentBases() does,
// but it avoids classes we don't want, e.g. WeakAggComponentImplHelper1 // but it avoids classes we don't want, e.g. WeakAggComponentImplHelper1
!decl->hasAnyDependentBases() && !decl->hasAnyDependentBases() &&
!decl->forallBases(BaseCheckNotDialogSubclass, nullptr, true)) { !compat::forallBases(*decl, BaseCheckNotDialogSubclass, true)) {
return true; return true;
} }
return false; return false;
......
...@@ -57,7 +57,13 @@ static bool startsWith(const std::string& s, const char* other) ...@@ -57,7 +57,13 @@ static bool startsWith(const std::string& s, const char* other)
return s.compare(0, strlen(other), other) == 0; return s.compare(0, strlen(other), other) == 0;
} }
bool BaseCheckNotWindowSubclass(const CXXRecordDecl *BaseDefinition, void *) { bool BaseCheckNotWindowSubclass(
const CXXRecordDecl *BaseDefinition
#if __clang_major__ == 3 && __clang_minor__ < 7
, void *
#endif
)
{
if (BaseDefinition && BaseDefinition->getQualifiedNameAsString() == "OutputDevice") { if (BaseDefinition && BaseDefinition->getQualifiedNameAsString() == "OutputDevice") {
return false; return false;
} }
...@@ -75,7 +81,7 @@ bool isDerivedFromWindow(const CXXRecordDecl *decl) { ...@@ -75,7 +81,7 @@ bool isDerivedFromWindow(const CXXRecordDecl *decl) {
if (// not sure what hasAnyDependentBases() does, if (// not sure what hasAnyDependentBases() does,
// but it avoids classes we don't want, e.g. WeakAggComponentImplHelper1 // but it avoids classes we don't want, e.g. WeakAggComponentImplHelper1
!decl->hasAnyDependentBases() && !decl->hasAnyDependentBases() &&
!decl->forallBases(BaseCheckNotWindowSubclass, nullptr, true)) { !compat::forallBases(*decl, BaseCheckNotWindowSubclass, true)) {
return true; return true;
} }
return false; return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment