libreoffice/compilerplugins/clang/pluginhandler.hxx
Stephan Bergmann 07b8711526 Memoize ignoreLocation results
...which, according to callgrind, reduces instruction fetch count spent on
compiling sw/source/core/layout/paintfrm.cxx (randomly selected because it is
rather large) by 5% from 41,992,064,226 to 39,861,989,855 (function main() in
clang-6.0).

This is best done by forwarding ignoreLocation calls from Plugin to the
PluginHandler signleton, but due to the tight mutual coupling between plugin.hxx
and pluginhandler.hxx that unfortunately required some reorganization (and two
outstanding TODO clean-ups of temporarily introduced using declarations in
plugin.hxx).

Change-Id: Ia4270517d194def7db7ed80cb6894e9c473e9499
2017-11-07 11:19:30 +01:00

97 lines
2.7 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* Based on LLVM/Clang.
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*
*/
#ifndef PLUGINHANDLER_H
#define PLUGINHANDLER_H
#include <cstddef>
#include <functional>
#include <memory>
#include <set>
#include <unordered_map>
#include <clang/AST/ASTConsumer.h>
#include <clang/Frontend/CompilerInstance.h>
#include <clang/Frontend/FrontendAction.h>
#include <clang/Rewrite/Core/Rewriter.h>
using namespace clang;
namespace std {
template<> struct hash<::clang::SourceLocation> {
size_t operator ()(::clang::SourceLocation loc) const
{ return loc.getRawEncoding(); }
};
}
namespace loplugin
{
class Plugin;
struct InstantiationData;
/**
Class that manages all LO modules.
*/
class PluginHandler
: public ASTConsumer
{
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 );
DiagnosticBuilder report( DiagnosticsEngine::Level level, const char * plugin, StringRef message,
CompilerInstance& compiler, SourceLocation loc = SourceLocation());
bool ignoreLocation(SourceLocation loc);
bool addRemoval( SourceLocation loc );
static bool isUnitTestMode();
private:
void handleOption( const std::string& option );
void createPlugins( std::set< std::string > rewriters );
DiagnosticBuilder report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc = SourceLocation());
bool checkIgnoreLocation(SourceLocation loc);
CompilerInstance& compiler;
StringRef const mainFileName;
std::unordered_map<SourceLocation, bool> ignored_;
Rewriter rewriter;
std::set< SourceLocation > removals;
std::string scope;
std::string warningsOnly;
bool warningsAsErrors;
};
/**
The Clang plugin class, just forwards to PluginHandler.
*/
class LibreOfficeAction
: public PluginASTAction
{
public:
#if CLANG_VERSION >= 30600
virtual std::unique_ptr<ASTConsumer> CreateASTConsumer( CompilerInstance& Compiler, StringRef InFile );
#else
virtual ASTConsumer* CreateASTConsumer( CompilerInstance& Compiler, StringRef InFile );
#endif
virtual bool ParseArgs( const CompilerInstance& CI, const std::vector< std::string >& args );
private:
std::vector< std::string > _args;
};
} // namespace
#endif // COMPILEPLUGIN_H
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */