Kaydet (Commit) adb08e89 authored tarafından Luboš Luňák's avatar Luboš Luňák

make (some) clang plugins share the same RecursiveASTVisitor

Each plugin currently uses its own recursive AST run, which adds up.
This patch adds another shared plugin which internally contains all
(suitable) plugins and dispatches to them from the same one recursive
run. This patch converts ~25 plugins and for starmath's accessibility.cxx
reduces clang build time from 5.43s to 5.14s (and it's 4.39s without any
plugins). As there are almost 50 more plugins to go, this can theoretically
result in 4.56s final time, although probably not all plugins can be
that easily converted, if at all.

This mostly requires very little change in many plugins (see e.g.
BadStatics), some even work without any functionality change (e.g.
CharRightShift). Traverse* calls require some changes but are often
not that difficult. WalkUp* probably can't be supported, although some
plugins can(?) possibly be adjusted to not rely on them. And of course
some plugins can be left as they are, using their own recursive run.
See description at the top of generator.cxx for description of how to
convert a plugin.

The sharedvisitor.cxx source is generated based on scanning relevant
plugin sources using a clang-based scanner/generator. The generated
source is intentionally included instead of getting always generated,
as the generating currently takes some time, so it should get updated
in git whenever a change in a plugin triggers a source change in it.

Change-Id: Ia0d2e3a5a464659503dbb4ed6c20b6cc89b4de01
Reviewed-on: https://gerrit.libreoffice.org/68026
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
Reviewed-by: 's avatarLuboš Luňák <l.lunak@collabora.com>
üst 3a15c034
......@@ -22,6 +22,10 @@ else
CLANGCXXFLAGS=-O2 -Wall -Wextra -Wundef -g
endif
# Whether to make plugins use one shared ASTRecursiveVisitor (plugins run faster).
# By default enabled, disable if you work on an affected plugin (re-generating takes time).
LO_CLANG_SHARED_PLUGINS=1
# The uninteresting rest.
include $(SRCDIR)/solenv/gbuild/gbuild.mk
......@@ -50,6 +54,8 @@ else
CLANGINCLUDES=$(if $(filter /usr,$(CLANGDIR)),,-isystem $(CLANGDIR)/include)
endif
LLVMCONFIG=$(CLANGDIR)/bin/llvm-config
# Clang/LLVM libraries are intentionally not linked in, they are usually built as static libraries, which means the resulting
# plugin would be big (even though the clang binary already includes it all) and it'd be necessary to explicitly specify
# also all the dependency libraries.
......@@ -59,6 +65,10 @@ CLANGINDIR=$(SRCDIR)/compilerplugins/clang
# plugin will cause cache misses with ccache.
CLANGOUTDIR=$(BUILDDIR)/compilerplugins/obj
ifdef LO_CLANG_SHARED_PLUGINS
CLANGCXXFLAGS+=-DLO_CLANG_SHARED_PLUGINS
endif
QUIET=$(if $(verbose),,@)
ifneq ($(ENABLE_WERROR),)
......@@ -72,8 +82,13 @@ endif
compilerplugins: compilerplugins-build
ifdef LO_CLANG_SHARED_PLUGINS
# The shared source, intentionally put first in the list because it takes the longest to build.
CLANGSRC=sharedvisitor/sharedvisitor.cxx
endif
# The list of source files, generated automatically (all files in clang/, but not subdirs).
CLANGSRC=$(foreach src,$(wildcard $(CLANGINDIR)/*.cxx), $(notdir $(src)))
CLANGSRC+=$(foreach src,$(wildcard $(CLANGINDIR)/*.cxx), $(notdir $(src)))
# Remember the sources and if they have changed, force plugin relinking.
CLANGSRCCHANGED= \
$(shell mkdir -p $(CLANGOUTDIR) ; \
......@@ -152,4 +167,35 @@ endif
$(CLANGOUTDIR)/clang-timestamp: $(CLANGDIR)/bin/clang$(CLANG_EXE_EXT)
$(QUIET)touch $@
ifdef LO_CLANG_SHARED_PLUGINS
# Update the shared visitor source if needed. It is intentionally included in the sources and generated only when
# needed, because the generating takes a while.
# If you want to remake the source with LO_CLANG_SHARED_PLUGINS disabled, run 'make LO_CLANG_SHARED_PLUGINS=1'.
$(CLANGINDIR)/sharedvisitor/sharedvisitor.cxx: $(shell grep -l "LO_CLANG_SHARED_PLUGINS" $(CLANGINDIR)/*.cxx)
$(CLANGINDIR)/sharedvisitor/sharedvisitor.cxx: $(CLANGOUTDIR)/sharedvisitor/generator$(CLANG_EXE_EXT)
$(call gb_Output_announce,$(subst $(SRCDIR)/,,$@),$(true),GEN,1)
$(CLANGOUTDIR)/sharedvisitor/generator$(CLANG_EXE_EXT) $(shell grep -l "LO_CLANG_SHARED_PLUGINS" $(CLANGINDIR)/*.cxx) \
> $(CLANGINDIR)/sharedvisitor/sharedvisitor.cxx
CLANGTOOLLIBS = -lclangTooling -lclangDriver -lclangFrontend -lclangParse -lclangSema -lclangEdit -lclangAnalysis \
-lclangAST -lclangLex -lclangSerialization -lclangBasic $(shell $(LLVMCONFIG) --ldflags --libs --system-libs)
# Path to the clang system headers (no idea if there's a better way to get it).
CLANGTOOLDEFS = -DCLANGSYSINCLUDE=$(shell $(LLVMCONFIG) --libdir)/clang/$(shell $(LLVMCONFIG) --version | sed 's/svn//')/include
$(CLANGOUTDIR)/sharedvisitor/generator$(CLANG_EXE_EXT): $(CLANGINDIR)/sharedvisitor/generator.cxx
$(call gb_Output_announce,$(subst $(BUILDDIR)/,,$@),$(true),GEN,1)
$(QUIET)$(COMPILER_PLUGINS_CXX) $(CLANGCXXFLAGS) $(CLANGWERROR) $(CLANGDEFS) $(CLANGTOOLDEFS) $(CLANGINCLUDES) \
-DCLANGDIR=$(CLANGDIR) -DBUILDDIR=$(BUILDDIR) -I$(BUILDDIR)/config_host \
$< -o $@ -MMD -MT $@ -MP -MF $(CLANGOUTDIR)/sharedvisitor/generator.d $(CLANGTOOLLIBS)
compilerplugins-build: $(CLANGOUTDIR)/sharedvisitor
$(CLANGOUTDIR)/sharedvisitor:
mkdir -p $(CLANGOUTDIR)/sharedvisitor
-include $(CLANGOUTDIR)/sharedvisitor/generator.d
# TODO WNT version
endif
# vim: set noet sw=4 ts=4:
......@@ -7,6 +7,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef LO_CLANG_SHARED_PLUGINS
#include <cassert>
#include "check.hxx"
......@@ -22,8 +24,12 @@ public:
explicit BadStatics(loplugin::InstantiationData const& rData):
FilteringPlugin(rData) {}
bool preRun() override {
return compiler.getLangOpts().CPlusPlus; // no non-trivial dtors in C
}
void run() override {
if (compiler.getLangOpts().CPlusPlus) { // no non-trivial dtors in C
if (preRun()) {
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
}
}
......@@ -244,8 +250,10 @@ public:
};
loplugin::Plugin::Registration<BadStatics> X("badstatics");
loplugin::Plugin::Registration<BadStatics> badstatics("badstatics");
} // namespace
#endif // LO_CLANG_SHARED_PLUGINS
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -7,6 +7,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef LO_CLANG_SHARED_PLUGINS
#include <cassert>
#include <string>
#include <iostream>
......@@ -26,13 +28,18 @@ public:
explicit BlockBlock(loplugin::InstantiationData const & data):
FilteringPlugin(data) {}
virtual void run() override
virtual bool preRun() override
{
StringRef fn(handler.getMainFileName());
if (loplugin::isSamePathname(fn, SRCDIR "/sal/osl/unx/file_misc.cxx"))
return;
return false;
return true;
}
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
void run() override {
if (preRun()) {
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
}
}
bool VisitCompoundStmt(CompoundStmt const * );
......@@ -67,8 +74,10 @@ bool BlockBlock::VisitCompoundStmt(CompoundStmt const * compound)
return true;
}
loplugin::Plugin::Registration< BlockBlock > X("blockblock", true);
loplugin::Plugin::Registration< BlockBlock > blockblock("blockblock", true);
}
#endif // LO_CLANG_SHARED_PLUGINS
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -7,6 +7,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef LO_CLANG_SHARED_PLUGINS
#include "check.hxx"
#include "plugin.hxx"
......@@ -51,8 +53,10 @@ public:
}
};
loplugin::Plugin::Registration<CharRightShift> X("charrightshift");
loplugin::Plugin::Registration<CharRightShift> charrightshift("charrightshift");
}
#endif // LO_CLANG_SHARED_PLUGINS
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
......@@ -115,6 +115,8 @@ public:
inline ContextCheck Struct(llvm::StringRef id) const;
explicit ContextCheck(const clang::NamespaceDecl * decl ) : context_( decl ) {}
private:
friend DeclCheck;
friend TypeCheck;
......
......@@ -7,6 +7,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef LO_CLANG_SHARED_PLUGINS
#include <string>
#include <iostream>
#include <map>
......@@ -114,8 +116,10 @@ bool DataMemberShadow::VisitFieldDecl(FieldDecl const * fieldDecl)
return true;
}
loplugin::Plugin::Registration< DataMemberShadow > X("datamembershadow", true);
loplugin::Plugin::Registration< DataMemberShadow > datamembershadow("datamembershadow", true);
}
#endif // LO_CLANG_SHARED_PLUGINS
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -9,6 +9,8 @@
*
*/
#ifndef LO_CLANG_SHARED_PLUGINS
#include "check.hxx"
#include "plugin.hxx"
#include <clang/Lex/Lexer.h>
......@@ -31,9 +33,11 @@ public:
virtual void run() override;
bool VisitCallExpr(CallExpr const* call);
bool TraverseCXXCatchStmt(CXXCatchStmt*);
bool PreTraverseCXXCatchStmt(CXXCatchStmt*);
bool PostTraverseCXXCatchStmt(CXXCatchStmt*, bool traverseOk);
private:
CXXCatchStmt const* currCatchStmt = nullptr;
std::stack<CXXCatchStmt const*> currCatchStmt;
};
DbgUnhandledException::DbgUnhandledException(const InstantiationData& data)
......@@ -46,13 +50,27 @@ void DbgUnhandledException::run()
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
}
bool DbgUnhandledException::PreTraverseCXXCatchStmt(CXXCatchStmt* catchStmt)
{
currCatchStmt.push(catchStmt);
return true;
}
bool DbgUnhandledException::PostTraverseCXXCatchStmt(CXXCatchStmt* catchStmt, bool)
{
assert(currCatchStmt.top() == catchStmt);
currCatchStmt.pop();
return true;
}
bool DbgUnhandledException::TraverseCXXCatchStmt(CXXCatchStmt* catchStmt)
{
auto prevCatchStmt = currCatchStmt;
currCatchStmt = catchStmt;
auto rv = RecursiveASTVisitor::TraverseCXXCatchStmt(catchStmt);
currCatchStmt = prevCatchStmt;
return rv;
if (!PreTraverseCXXCatchStmt(catchStmt))
return false;
bool ret = RecursiveASTVisitor::TraverseCXXCatchStmt(catchStmt);
if (!PostTraverseCXXCatchStmt(catchStmt, ret))
return false;
return ret;
}
bool DbgUnhandledException::VisitCallExpr(const CallExpr* call)
......@@ -66,13 +84,13 @@ bool DbgUnhandledException::VisitCallExpr(const CallExpr* call)
if (!func->getIdentifier() || func->getName() != "DbgUnhandledException")
return true;
if (!currCatchStmt)
if (currCatchStmt.empty())
{
report(DiagnosticsEngine::Warning, "DBG_UNHANDLED_EXCEPTION outside catch block",
compat::getBeginLoc(call));
return true;
}
auto catchBlock = dyn_cast<CompoundStmt>(currCatchStmt->getHandlerBlock());
auto catchBlock = dyn_cast<CompoundStmt>(currCatchStmt.top()->getHandlerBlock());
if (!catchBlock)
{
report(DiagnosticsEngine::Warning,
......@@ -100,8 +118,10 @@ bool DbgUnhandledException::VisitCallExpr(const CallExpr* call)
return true;
}
static Plugin::Registration<DbgUnhandledException> X("dbgunhandledexception");
static Plugin::Registration<DbgUnhandledException> dbgunhandledexception("dbgunhandledexception");
} // namespace
#endif // LO_CLANG_SHARED_PLUGINS
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -7,6 +7,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef LO_CLANG_SHARED_PLUGINS
#include "plugin.hxx"
namespace {
......@@ -38,8 +40,10 @@ bool DerefNullPtr::VisitUnaryDeref(UnaryOperator const * op) {
return true;
}
loplugin::Plugin::Registration<DerefNullPtr> X("derefnullptr");
loplugin::Plugin::Registration<DerefNullPtr> derefnullptr("derefnullptr");
}
#endif // LO_CLANG_SHARED_PLUGINS
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -7,6 +7,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef LO_CLANG_SHARED_PLUGINS
#include "check.hxx"
#include "compat.hxx"
#include "plugin.hxx"
......@@ -78,7 +80,9 @@ bool DoubleConvert::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr const
return true;
}
static loplugin::Plugin::Registration<DoubleConvert> reg("doubleconvert");
static loplugin::Plugin::Registration<DoubleConvert> doubleconvert("doubleconvert");
}
#endif // LO_CLANG_SHARED_PLUGINS
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
......@@ -7,6 +7,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef LO_CLANG_SHARED_PLUGINS
#include <algorithm>
#include <cassert>
#include <cstddef>
......@@ -184,17 +186,22 @@ public:
return true;
}
virtual bool preRun() override {
return compiler.getLangOpts().CPlusPlus;
}
private:
void run() override {
if (compiler.getLangOpts().CPlusPlus) {
if (preRun()) {
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
}
}
};
static loplugin::Plugin::Registration<DynCastVisibility> reg(
static loplugin::Plugin::Registration<DynCastVisibility> dyncastvisibility(
"dyncastvisibility");
}
#endif // LO_CLANG_SHARED_PLUGINS
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
......@@ -7,6 +7,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef LO_CLANG_SHARED_PLUGINS
#include <cassert>
#include "check.hxx"
......@@ -180,7 +182,9 @@ private:
}
};
loplugin::Plugin::Registration<Empty> X("empty");
loplugin::Plugin::Registration<Empty> emptyRegistration("empty");
}
#endif // LO_CLANG_SHARED_PLUGINS
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
......@@ -7,6 +7,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef LO_CLANG_SHARED_PLUGINS
#include <cassert>
#include <string>
#include <iostream>
......@@ -84,7 +86,9 @@ bool EmptyIf::VisitIfStmt(IfStmt const* ifStmt)
return true;
}
loplugin::Plugin::Registration<EmptyIf> X("emptyif", true);
loplugin::Plugin::Registration<EmptyIf> emptyif("emptyif", true);
}
#endif // LO_CLANG_SHARED_PLUGINS
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -7,6 +7,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef LO_CLANG_SHARED_PLUGINS
#include <string>
#include "plugin.hxx"
......@@ -71,8 +73,10 @@ bool ExternAndNotDefined::VisitFunctionDecl(const FunctionDecl * functionDecl) {
}
loplugin::Plugin::Registration< ExternAndNotDefined > X("externandnotdefined");
loplugin::Plugin::Registration< ExternAndNotDefined > externandnotdefined("externandnotdefined");
}
#endif // LO_CLANG_SHARED_PLUGINS
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -7,6 +7,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef LO_CLANG_SHARED_PLUGINS
#include "check.hxx"
#include "plugin.hxx"
......@@ -109,8 +111,10 @@ public:
}
};
loplugin::Plugin::Registration<ExternVar> X("externvar");
loplugin::Plugin::Registration<ExternVar> externvar("externvar");
}
#endif // LO_CLANG_SHARED_PLUGINS
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
......@@ -7,6 +7,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef LO_CLANG_SHARED_PLUGINS
#include <cassert>
#include <string>
......@@ -46,8 +48,10 @@ bool InlineVisible::VisitFunctionDecl(FunctionDecl const * decl) {
return true;
}
loplugin::Plugin::Registration<InlineVisible> X("inlinevisible");
loplugin::Plugin::Registration<InlineVisible> inlinevisible("inlinevisible");
}
#endif // LO_CLANG_SHARED_PLUGINS
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -9,6 +9,8 @@
*
*/
#ifndef LO_CLANG_SHARED_PLUGINS
#include <algorithm>
#include <cassert>
#include <list>
......@@ -234,8 +236,10 @@ void LoopVarTooSmall::checkExpr(Expr const * expr) {
}
}
loplugin::Plugin::Registration< LoopVarTooSmall > X("loopvartoosmall");
loplugin::Plugin::Registration< LoopVarTooSmall > loopvartoosmall("loopvartoosmall");
}
#endif // LO_CLANG_SHARED_PLUGINS
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -154,9 +154,10 @@ void normalizeDotDotInFilePath( std::string & s )
}
}
void Plugin::registerPlugin( Plugin* (*create)( const InstantiationData& ), const char* optionName, bool isPPCallback, bool byDefault )
void Plugin::registerPlugin( Plugin* (*create)( const InstantiationData& ), const char* optionName,
bool isPPCallback, bool isSharedPlugin, bool byDefault )
{
PluginHandler::registerPlugin( create, optionName, isPPCallback, byDefault );
PluginHandler::registerPlugin( create, optionName, isPPCallback, isSharedPlugin, byDefault );
}
bool Plugin::evaluate(const Expr* expr, APSInt& x)
......
......@@ -51,11 +51,20 @@ class Plugin
public:
explicit Plugin( const InstantiationData& data );
virtual ~Plugin() {}
// The main function of the plugin.
// Note that for shared plugins, its functionality must be split into preRun() and postRun(),
// see sharedvisitor/generator.cxx .
virtual void run() = 0;
// Should be called from run() before TraverseDecl().
// If returns false, run() should not do anything.
virtual bool preRun() { return true; }
virtual void postRun() {}
template< typename T > class Registration;
enum { isPPCallback = false };
// Returns location right after the end of the token that starts at the given location.
SourceLocation locationAfterToken( SourceLocation location );
virtual bool setSharedPlugin( Plugin* /*plugin*/, const char* /*name*/ ) { return false; }
enum { isPPCallback = false };
enum { isSharedPlugin = false };
protected:
DiagnosticBuilder report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc = SourceLocation()) const;
bool ignoreLocation( SourceLocation loc ) const
......@@ -92,7 +101,8 @@ protected:
Expr const * argument1, Expr const * argument2);
private:
static void registerPlugin( Plugin* (*create)( const InstantiationData& ), const char* optionName, bool isPPCallback, bool byDefault );
static void registerPlugin( Plugin* (*create)( const InstantiationData& ), const char* optionName,
bool isPPCallback, bool isSharedPlugin, bool byDefault );
template< typename T > static Plugin* createHelper( const InstantiationData& data );
bool evaluate(const Expr* expr, APSInt& x);
......@@ -220,7 +230,7 @@ template< typename T >
inline
Plugin::Registration< T >::Registration( const char* optionName, bool byDefault )
{
registerPlugin( &T::template createHelper< T >, optionName, T::isPPCallback, byDefault );
registerPlugin( &T::template createHelper< T >, optionName, T::isPPCallback, T::isSharedPlugin, byDefault );
}
inline
......
......@@ -46,7 +46,9 @@ struct PluginData
Plugin* object;
const char* optionName;
bool isPPCallback;
bool isSharedPlugin;
bool byDefault;
bool disabledRun;
};
const int MAX_PLUGINS = 200;
......@@ -150,9 +152,26 @@ void PluginHandler::createPlugins( std::set< std::string > rewriters )
}
for( auto r: rewriters )
report( DiagnosticsEngine::Fatal, "unknown plugin tool %0" ) << r;
// If there is a shared plugin, make it handle all plugins that it can handle.
for( int i = 0; i < pluginCount; ++i )
{
if( plugins[ i ].isSharedPlugin && plugins[ i ].object != nullptr )
{
Plugin* plugin = plugins[ i ].object;
for( int j = 0; j < pluginCount; ++j )
{
if( plugins[ j ].object != nullptr
&& plugin->setSharedPlugin( plugins[ j ].object, plugins[ j ].optionName ))
{
plugins[ j ].disabledRun = true;
}
}
}
}
}
void PluginHandler::registerPlugin( Plugin* (*create)( const InstantiationData& ), const char* optionName, bool isPPCallback, bool byDefault )
void PluginHandler::registerPlugin( Plugin* (*create)( const InstantiationData& ), const char* optionName,
bool isPPCallback, bool isSharedPlugin, bool byDefault )
{
assert( !bPluginObjectsCreated );
assert( pluginCount < MAX_PLUGINS );
......@@ -160,7 +179,9 @@ void PluginHandler::registerPlugin( Plugin* (*create)( const InstantiationData&
plugins[ pluginCount ].object = NULL;
plugins[ pluginCount ].optionName = optionName;
plugins[ pluginCount ].isPPCallback = isPPCallback;
plugins[ pluginCount ].isSharedPlugin = isSharedPlugin;
plugins[ pluginCount ].byDefault = byDefault;
plugins[ pluginCount ].disabledRun = false;
++pluginCount;
}
......@@ -281,7 +302,7 @@ void PluginHandler::HandleTranslationUnit( ASTContext& context )
for( int i = 0; i < pluginCount; ++i )
{
if( plugins[ i ].object != NULL )
if( plugins[ i ].object != NULL && !plugins[ i ].disabledRun )
{
plugins[ i ].object->run();
}
......
......@@ -50,7 +50,8 @@ public:
PluginHandler( CompilerInstance& compiler, const std::vector< std::string >& args );
virtual ~PluginHandler();
virtual void HandleTranslationUnit( ASTContext& context ) override;
static void registerPlugin( Plugin* (*create)( const InstantiationData& ), const char* optionName, bool isPPCallback, bool byDefault );
static void registerPlugin( Plugin* (*create)( const InstantiationData& ), const char* optionName,
bool isPPCallback, bool isSharedPlugin, bool byDefault );
DiagnosticBuilder report( DiagnosticsEngine::Level level, const char * plugin, StringRef message,
CompilerInstance& compiler, SourceLocation loc = SourceLocation());
bool ignoreLocation(SourceLocation loc);
......
......@@ -7,6 +7,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef LO_CLANG_SHARED_PLUGINS
#include "plugin.hxx"
namespace {
......@@ -48,8 +50,10 @@ bool PrivateBase::VisitCXXRecordDecl(CXXRecordDecl const * decl) {
return true;
}
loplugin::Plugin::Registration<PrivateBase> X("privatebase");
loplugin::Plugin::Registration<PrivateBase> privatebase("privatebase");
}
#endif // LO_CLANG_SHARED_PLUGINS
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -7,6 +7,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef LO_CLANG_SHARED_PLUGINS
#include <algorithm>
#include <cassert>
#include <limits>
......@@ -40,6 +42,7 @@ public:
{}
void run() override;
void postRun() override;
bool VisitNamedDecl(NamedDecl const * decl);
......@@ -56,8 +59,12 @@ private:
void ReservedId::run() {
//TODO: Rules for C?
if (TraverseDecl(compiler.getASTContext().getTranslationUnitDecl())
&& compiler.hasPreprocessor())
if (TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()))
postRun();
}
void ReservedId::postRun() {
if( compiler.hasPreprocessor())
{
auto & prep = compiler.getPreprocessor();
for (auto const & m: prep.macros(false)) {
......@@ -302,8 +309,10 @@ bool ReservedId::isApi(NamedDecl const * decl) {
return false;
}
loplugin::Plugin::Registration<ReservedId> X("reservedid");
loplugin::Plugin::Registration<ReservedId> reservedid("reservedid");
}
#endif // LO_CLANG_SHARED_PLUGINS
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This diff is collapsed.
......@@ -7,6 +7,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef LO_CLANG_SHARED_PLUGINS
#include <memory>
#include <cassert>
#include <string>
......@@ -34,6 +36,10 @@ public:
bool TraverseReturnStmt(ReturnStmt*) { return true; }
bool TraverseInitListExpr(InitListExpr*) { return true; }
bool TraverseCXXBindTemporaryExpr(CXXBindTemporaryExpr*) { return true; }
// ignore them for the shared visitor too
bool PreTraverseReturnStmt(ReturnStmt*) { return false; }
bool PreTraverseInitListExpr(InitListExpr*) { return false; }
bool PreTraverseCXXBindTemporaryExpr(CXXBindTemporaryExpr*) { return false; }
};
bool SimplifyConstruct::VisitCXXConstructExpr(CXXConstructExpr const* constructExpr)
......@@ -63,7 +69,9 @@ bool SimplifyConstruct::VisitCXXConstructExpr(CXXConstructExpr const* constructE
return true;
}
loplugin::Plugin::Registration<SimplifyConstruct> X("simplifyconstruct", true);
loplugin::Plugin::Registration<SimplifyConstruct> simplifyconstruct("simplifyconstruct", true);
}
#endif // LO_CLANG_SHARED_PLUGINS
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -61,7 +61,7 @@ bool Tutorial1::VisitReturnStmt( const ReturnStmt* returnstmt )
}
// Register the plugin action with the LO plugin handling.
static Plugin::Registration< Tutorial1 > X( "tutorial1" );
static Plugin::Registration< Tutorial1 > tutorial1( "tutorial1" );
} // namespace