Kaydet (Commit) 9f4d23c1 authored tarafından Noel Grandin's avatar Noel Grandin

filter out some of the AST in the plugins

by checking if the current namespace decl is in our code, so we have to
scan less stuff, which results in a 10% perf improvement for me

Change-Id: Idf0e30d57b6d0dcd13daa9ed679c28b9d233d387
Reviewed-on: https://gerrit.libreoffice.org/58942
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 4917430c
......@@ -23,10 +23,10 @@
namespace {
class AutoMem:
public RecursiveASTVisitor<AutoMem>, public loplugin::Plugin
public loplugin::FilteringPlugin<AutoMem>
{
public:
explicit AutoMem(loplugin::InstantiationData const & data): Plugin(data), mbInsideDestructor(false) {}
explicit AutoMem(loplugin::InstantiationData const & data): FilteringPlugin(data), mbInsideDestructor(false) {}
virtual void run() override
{
......
......@@ -15,13 +15,12 @@
namespace {
class BadStatics
: public clang::RecursiveASTVisitor<BadStatics>
, public loplugin::Plugin
: public loplugin::FilteringPlugin<BadStatics>
{
public:
explicit BadStatics(loplugin::InstantiationData const& rData):
Plugin(rData) {}
FilteringPlugin(rData) {}
void run() override {
if (compiler.getLangOpts().CPlusPlus) { // no non-trivial dtors in C
......
......@@ -28,11 +28,11 @@ Stmt const * lookThroughExprWithCleanups(Stmt const * stmt) {
}
class CommaOperator:
public RecursiveASTVisitor<CommaOperator>, public loplugin::Plugin
public loplugin::FilteringPlugin<CommaOperator>
{
public:
explicit CommaOperator(loplugin::InstantiationData const & data):
Plugin(data) {}
FilteringPlugin(data) {}
virtual void run() override
{
......
......@@ -21,11 +21,11 @@
namespace {
class CppunitAssertEquals:
public RecursiveASTVisitor<CppunitAssertEquals>, public loplugin::Plugin
public loplugin::FilteringPlugin<CppunitAssertEquals>
{
public:
explicit CppunitAssertEquals(loplugin::InstantiationData const & data):
Plugin(data) {}
FilteringPlugin(data) {}
virtual void run() override
{
......
......@@ -165,10 +165,10 @@ bool canBeUsedForFunctionalCast(TypeSourceInfo const * info) {
}
class CStyleCast:
public RecursiveASTVisitor<CStyleCast>, public loplugin::RewritePlugin
public loplugin::FilteringRewritePlugin<CStyleCast>
{
public:
explicit CStyleCast(loplugin::InstantiationData const & data): RewritePlugin(data)
explicit CStyleCast(loplugin::InstantiationData const & data): FilteringRewritePlugin(data)
{}
virtual void run() override {
......
......@@ -12,11 +12,11 @@
namespace {
class DerefNullPtr:
public RecursiveASTVisitor<DerefNullPtr>, public loplugin::Plugin
public loplugin::FilteringPlugin<DerefNullPtr>
{
public:
explicit DerefNullPtr(loplugin::InstantiationData const & data):
Plugin(data) {}
FilteringPlugin(data) {}
void run() override
{ TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
......
......@@ -17,10 +17,10 @@
namespace {
class ExternAndNotDefined:
public RecursiveASTVisitor<ExternAndNotDefined>, public loplugin::Plugin
public loplugin::FilteringPlugin<ExternAndNotDefined>
{
public:
explicit ExternAndNotDefined(loplugin::InstantiationData const & data): Plugin(data) {}
explicit ExternAndNotDefined(loplugin::InstantiationData const & data): FilteringPlugin(data) {}
virtual void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
......
......@@ -90,11 +90,11 @@ bool isAlwaysNull(CXXDynamicCastExpr const * expr) {
}
class FailedDynCast:
public RecursiveASTVisitor<FailedDynCast>, public loplugin::Plugin
public loplugin::FilteringPlugin<FailedDynCast>
{
public:
explicit FailedDynCast(loplugin::InstantiationData const & data):
Plugin(data) {}
FilteringPlugin(data) {}
bool shouldVisitTemplateInstantiations() const { return true; }
......
......@@ -74,12 +74,11 @@ std::string replace_all(std::string subject, const std::string& search, const st
}
class GetImplementationName:
public clang::RecursiveASTVisitor<GetImplementationName>,
public loplugin::Plugin
public loplugin::FilteringPlugin<GetImplementationName>
{
public:
explicit GetImplementationName(loplugin::InstantiationData const & data)
: Plugin(data)
: FilteringPlugin(data)
, m_Outdir(initOutdir())
, m_OutdirCreated(false)
, m_Srcdir(initSrcdir())
......
......@@ -221,11 +221,11 @@ bool hasCLanguageLinkageType(FunctionDecl const * decl) {
}
class ImplicitBoolConversion:
public RecursiveASTVisitor<ImplicitBoolConversion>, public loplugin::Plugin
public loplugin::FilteringPlugin<ImplicitBoolConversion>
{
public:
explicit ImplicitBoolConversion(loplugin::InstantiationData const & data):
Plugin(data) {}
FilteringPlugin(data) {}
virtual void run() override
{ TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
......
......@@ -18,10 +18,10 @@
namespace {
class InlineSimpleMemberFunctions:
public RecursiveASTVisitor<InlineSimpleMemberFunctions>, public loplugin::RewritePlugin
public loplugin::FilteringRewritePlugin<InlineSimpleMemberFunctions>
{
public:
explicit InlineSimpleMemberFunctions(loplugin::InstantiationData const & data): RewritePlugin(data) {}
explicit InlineSimpleMemberFunctions(loplugin::InstantiationData const & data): FilteringRewritePlugin(data) {}
virtual void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
......
......@@ -18,11 +18,11 @@
namespace {
class InlineVisible:
public RecursiveASTVisitor<InlineVisible>, public loplugin::Plugin
public loplugin::FilteringPlugin<InlineVisible>
{
public:
explicit InlineVisible(loplugin::InstantiationData const & data):
Plugin(data) {}
FilteringPlugin(data) {}
void run() override
{ TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
......
......@@ -18,12 +18,11 @@
namespace {
class LiteralToBoolConversion:
public RecursiveASTVisitor<LiteralToBoolConversion>,
public loplugin::RewritePlugin
public loplugin::FilteringRewritePlugin<LiteralToBoolConversion>
{
public:
explicit LiteralToBoolConversion(loplugin::InstantiationData const & data):
RewritePlugin(data) {}
FilteringRewritePlugin(data) {}
virtual void run() override
{ TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
......
......@@ -23,11 +23,11 @@ namespace
{
class LoopVarTooSmall:
public RecursiveASTVisitor<LoopVarTooSmall>, public loplugin::Plugin
public loplugin::FilteringPlugin<LoopVarTooSmall>
{
public:
explicit LoopVarTooSmall(loplugin::InstantiationData const & data):
Plugin(data) {}
FilteringPlugin(data) {}
virtual void run() override {
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
......
......@@ -22,10 +22,10 @@ namespace
{
class MemoryVar:
public RecursiveASTVisitor<MemoryVar>, public loplugin::Plugin
public loplugin::FilteringPlugin<MemoryVar>
{
public:
explicit MemoryVar(loplugin::InstantiationData const & data): Plugin(data), mbChecking(false) {}
explicit MemoryVar(loplugin::InstantiationData const & data): FilteringPlugin(data), mbChecking(false) {}
virtual void run() override {
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
......
......@@ -47,11 +47,11 @@ static std::set<std::pair<std::string,std::string> > childToParentClassSet; // c
static std::map<std::string,std::string> definitionMap; // className -> filename
class MergeClasses:
public RecursiveASTVisitor<MergeClasses>, public loplugin::Plugin
public loplugin::FilteringPlugin<MergeClasses>
{
public:
explicit MergeClasses(loplugin::InstantiationData const & data):
Plugin(data) {}
FilteringPlugin(data) {}
virtual void run() override
{
......
......@@ -52,11 +52,11 @@ bool isNullPointerCast(CastExpr const * expr) {
}
class Nullptr:
public RecursiveASTVisitor<Nullptr>, public loplugin::RewritePlugin
public loplugin::FilteringRewritePlugin<Nullptr>
{
public:
explicit Nullptr(loplugin::InstantiationData const & data):
RewritePlugin(data) {}
FilteringRewritePlugin(data) {}
void run() override
{ TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
......
......@@ -76,10 +76,10 @@ public:
};
class OnceVar:
public RecursiveASTVisitor<OnceVar>, public loplugin::Plugin
public loplugin::FilteringPlugin<OnceVar>
{
public:
explicit OnceVar(loplugin::InstantiationData const & data): Plugin(data) {}
explicit OnceVar(loplugin::InstantiationData const & data): FilteringPlugin(data) {}
virtual void run() override {
// ignore some files with problematic macros
......
......@@ -20,11 +20,11 @@
namespace {
class Override:
public RecursiveASTVisitor<Override>, public loplugin::RewritePlugin
public loplugin::FilteringRewritePlugin<Override>
{
public:
explicit Override(loplugin::InstantiationData const & data):
RewritePlugin(data) {}
FilteringRewritePlugin(data) {}
virtual void run() override;
......
......@@ -28,10 +28,10 @@
namespace {
class PassStuffByRef:
public RecursiveASTVisitor<PassStuffByRef>, public loplugin::Plugin
public loplugin::FilteringPlugin<PassStuffByRef>
{
public:
explicit PassStuffByRef(loplugin::InstantiationData const & data): Plugin(data), mbInsideFunctionDecl(false), mbFoundReturnValueDisqualifier(false) {}
explicit PassStuffByRef(loplugin::InstantiationData const & data): FilteringPlugin(data), mbInsideFunctionDecl(false), mbFoundReturnValueDisqualifier(false) {}
virtual void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
......
......@@ -102,6 +102,19 @@ private:
const char* name;
};
template<typename Derived>
class FilteringPlugin : public RecursiveASTVisitor<Derived>, public Plugin
{
public:
explicit FilteringPlugin( const InstantiationData& data ) : Plugin(data) {}
bool TraverseNamespaceDecl(NamespaceDecl * decl) {
if (ignoreLocation(decl->getLocStart()))
return true;
return RecursiveASTVisitor<Derived>::TraverseNamespaceDecl(decl);
}
};
/**
Base class for rewriter plugins.
......@@ -227,6 +240,19 @@ RewritePlugin::RewriteOption operator|( RewritePlugin::RewriteOption option1, Re
return static_cast< RewritePlugin::RewriteOption >( int( option1 ) | int( option2 ));
}
template<typename Derived>
class FilteringRewritePlugin : public RecursiveASTVisitor<Derived>, public RewritePlugin
{
public:
explicit FilteringRewritePlugin( const InstantiationData& data ) : RewritePlugin(data) {}
bool TraverseNamespaceDecl(NamespaceDecl * decl) {
if (ignoreLocation(decl->getLocStart()))
return true;
return RecursiveASTVisitor<Derived>::TraverseNamespaceDecl(decl);
}
};
void normalizeDotDotInFilePath(std::string&);
// Same as pathname.startswith(prefix), except on Windows, where pathname and
......
......@@ -12,10 +12,10 @@
namespace {
class PrivateBase:
public RecursiveASTVisitor<PrivateBase>, public loplugin::Plugin
public loplugin::FilteringPlugin<PrivateBase>
{
public:
explicit PrivateBase(loplugin::InstantiationData const & data): Plugin(data)
explicit PrivateBase(loplugin::InstantiationData const & data): FilteringPlugin(data)
{}
void run() override;
......
......@@ -23,10 +23,10 @@
namespace {
class PtrVector:
public RecursiveASTVisitor<PtrVector>, public loplugin::Plugin
public loplugin::FilteringPlugin<PtrVector>
{
public:
explicit PtrVector(loplugin::InstantiationData const & data): Plugin(data)
explicit PtrVector(loplugin::InstantiationData const & data): FilteringPlugin(data)
{}
virtual void run() override
......
......@@ -22,11 +22,11 @@ namespace
{
class RangedForCopy:
public RecursiveASTVisitor<RangedForCopy>, public loplugin::Plugin
public loplugin::FilteringPlugin<RangedForCopy>
{
public:
explicit RangedForCopy(loplugin::InstantiationData const & data):
Plugin(data) {}
FilteringPlugin(data) {}
virtual void run() override {
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
......
......@@ -78,11 +78,11 @@ AlgebraicType algebraicType(clang::Type const & type) {
}
class RedundantCast:
public RecursiveASTVisitor<RedundantCast>, public loplugin::RewritePlugin
public loplugin::FilteringRewritePlugin<RedundantCast>
{
public:
explicit RedundantCast(loplugin::InstantiationData const & data):
RewritePlugin(data)
FilteringRewritePlugin(data)
{}
virtual void run() override {
......
......@@ -38,10 +38,10 @@ not delete on last 'release'.
namespace {
class RefCounting:
public RecursiveASTVisitor<RefCounting>, public loplugin::Plugin
public loplugin::FilteringPlugin<RefCounting>
{
public:
explicit RefCounting(loplugin::InstantiationData const & data): Plugin(data)
explicit RefCounting(loplugin::InstantiationData const & data): FilteringPlugin(data)
{}
virtual void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
......
......@@ -20,11 +20,11 @@ namespace
{
class RenderContext:
public RecursiveASTVisitor<RenderContext>, public loplugin::Plugin
public loplugin::FilteringPlugin<RenderContext>
{
public:
explicit RenderContext(loplugin::InstantiationData const & data):
Plugin(data) {}
FilteringPlugin(data) {}
virtual void run() override {
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
......
......@@ -143,11 +143,11 @@ bool hasBoolOverload(FunctionDecl const * decl, bool mustBeDeleted) {
}
class SalBool:
public RecursiveASTVisitor<SalBool>, public loplugin::RewritePlugin
public loplugin::FilteringRewritePlugin<SalBool>
{
public:
explicit SalBool(loplugin::InstantiationData const & data):
RewritePlugin(data) {}
FilteringRewritePlugin(data) {}
virtual void run() override;
......
......@@ -29,7 +29,7 @@ if appropriate.
*/
SalLogAreas::SalLogAreas( const InstantiationData& data )
: Plugin(data), inFunction(nullptr)
: FilteringPlugin(data), inFunction(nullptr)
{
}
......
......@@ -20,8 +20,7 @@ namespace loplugin
{
class SalLogAreas
: public RecursiveASTVisitor< SalLogAreas >
, public Plugin
: public FilteringPlugin< SalLogAreas >
{
public:
explicit SalLogAreas( const InstantiationData& data );
......
......@@ -22,10 +22,10 @@ forgotten and hard to notice.
namespace {
class SfxPoolItem:
public RecursiveASTVisitor<SfxPoolItem>, public loplugin::Plugin
public loplugin::FilteringPlugin<SfxPoolItem>
{
public:
explicit SfxPoolItem(loplugin::InstantiationData const & data): Plugin(data)
explicit SfxPoolItem(loplugin::InstantiationData const & data): FilteringPlugin(data)
{}
virtual void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
......
......@@ -76,11 +76,11 @@ Value getValue(Expr const * expr) {
}
class SimplifyBool:
public RecursiveASTVisitor<SimplifyBool>, public loplugin::Plugin
public loplugin::FilteringPlugin<SimplifyBool>
{
public:
explicit SimplifyBool(loplugin::InstantiationData const & data):
Plugin(data) {}
FilteringPlugin(data) {}
void run() override;
......
......@@ -18,12 +18,12 @@
namespace {
class StaticMethods:
public RecursiveASTVisitor<StaticMethods>, public loplugin::Plugin
public loplugin::FilteringPlugin<StaticMethods>
{
private:
bool bVisitedThis;
public:
explicit StaticMethods(loplugin::InstantiationData const & data): Plugin(data), bVisitedThis(false) {}
explicit StaticMethods(loplugin::InstantiationData const & data): FilteringPlugin(data), bVisitedThis(false) {}
void run() override
{ TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
......
......@@ -40,7 +40,7 @@ struct WalkCounter
// Ctor, nothing special, pass the argument(s).
CascadingAssignOp::CascadingAssignOp( const InstantiationData& data )
: Plugin( data )
: FilteringPlugin( data )
{
}
......
......@@ -22,9 +22,7 @@ struct WalkCounter;
// The class implementing the plugin action.
class CascadingAssignOp
// Inherits from the Clang class that will allow examing the Clang AST tree (i.e. syntax tree).
: public RecursiveASTVisitor< CascadingAssignOp >
// And the base class for LO Clang plugins.
, public Plugin
: public FilteringPlugin< CascadingAssignOp >
{
public:
CascadingAssignOp( const InstantiationData& data );
......
......@@ -39,7 +39,7 @@ struct WalkCounter
// Ctor, nothing special, pass the argument(s).
CascadingCondOp::CascadingCondOp( const InstantiationData& data )
: Plugin( data )
: FilteringPlugin( data )
{
}
......
......@@ -22,9 +22,7 @@ struct WalkCounter;
// The class implementing the plugin action.
class CascadingCondOp
// Inherits from the Clang class that will allow examing the Clang AST tree (i.e. syntax tree).
: public RecursiveASTVisitor< CascadingCondOp >
// And the base class for LO Clang plugins.
, public Plugin
: public FilteringPlugin< CascadingCondOp >
{
public:
CascadingCondOp( const InstantiationData& data );
......
......@@ -33,8 +33,7 @@ namespace loplugin
{
class ChangeFunctionCalls
: public RecursiveASTVisitor< ChangeFunctionCalls >
, public RewritePlugin
: public loplugin::FilteringRewritePlugin< ChangeFunctionCalls >
{
public:
explicit ChangeFunctionCalls( CompilerInstance& compiler, Rewriter& rewriter );
......@@ -43,7 +42,7 @@ class ChangeFunctionCalls
};
ChangeFunctionCalls::ChangeFunctionCalls( CompilerInstance& compiler, Rewriter& rewriter )
: RewritePlugin( compiler, rewriter )
: FilteringRewritePlugin( compiler, rewriter )
{
}
......
......@@ -19,11 +19,11 @@
namespace {
class ConstantFunction:
public RecursiveASTVisitor<ConstantFunction>, public loplugin::Plugin
public loplugin::FilteringPlugin<ConstantFunction>
{
StringRef getFilename(const FunctionDecl* functionDecl);
public:
explicit ConstantFunction(InstantiationData const & data): Plugin(data) {}
explicit ConstantFunction(InstantiationData const & data): FilteringRewritePlugin(data) {}
void run() override
{
......
......@@ -32,10 +32,10 @@ CXXRecordDecl const * getClass(CXXMethodDecl const * decl) {
}
class DeletedSpecial:
public RecursiveASTVisitor<DeletedSpecial>, public loplugin::Plugin
public loplugin::FilteringPlugin<DeletedSpecial>
{
public:
explicit DeletedSpecial(InstantiationData const & data): Plugin(data) {}
explicit DeletedSpecial(InstantiationData const & data): FilteringPlugin(data) {}
virtual void run() override;
......
......@@ -12,12 +12,11 @@
namespace {
class DerivedClass:
public RecursiveASTVisitor<DerivedClass>,
public loplugin::Plugin
public loplugin::FilteringPlugin<DerivedClass>
{
public:
explicit DerivedClass(InstantiationData const & data):
Plugin(data) {}
FilteringPlugin(data) {}
virtual void run() override
{ TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
......
......@@ -22,10 +22,10 @@
namespace {
class FindOnContainer:
public RecursiveASTVisitor<FindOnContainer>, public loplugin::Plugin
public loplugin::FilteringPlugin<FindOnContainer>
{
public:
explicit FindOnContainer(InstantiationData const & data): Plugin(data) {}
explicit FindOnContainer(InstantiationData const & data): FilteringPlugin(data) {}
virtual void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
......
......@@ -21,7 +21,7 @@ namespace loplugin
{
LclStaticFix::LclStaticFix( CompilerInstance& compiler, Rewriter& rewriter )
: RewritePlugin( compiler, rewriter )
: FilteringRewritePlugin( compiler, rewriter )
{
}
......
......@@ -18,8 +18,7 @@ namespace loplugin
{
class LclStaticFix
: public RecursiveASTVisitor< LclStaticFix >
, public RewritePlugin
: public loplugin::FilteringRewritePlugin< LclStaticFix >
{
public:
explicit LclStaticFix( CompilerInstance& compiler, Rewriter& rewriter );
......
......@@ -43,11 +43,11 @@ bool isDerivedFromWindow(const CXXRecordDecl* decl) {
return false;
}
class PaintMethodConversion: public RecursiveASTVisitor<PaintMethodConversion>, public loplugin::RewritePlugin
class PaintMethodConversion: public loplugin::FilteringRewritePlugin<PaintMethodConversion>
{
public:
explicit PaintMethodConversion(InstantiationData const& data):
RewritePlugin(data)
FilteringRewritePlugin(data)
{}
virtual void run() override
......
......@@ -21,7 +21,7 @@ namespace loplugin
{
PostfixIncrementFix::PostfixIncrementFix( const InstantiationData& data )
: RewritePlugin( data )
: FilteringRewritePlugin( data )
{
}
......
......@@ -18,8 +18,7 @@ namespace loplugin
{
class PostfixIncrementFix