office-gobmx/compilerplugins/clang/pluginhandler.hxx
Stephan Bergmann 6a10149c5f New loplugin:unusedmember
* See comment at head of compilerplugins/clang/unusedmember.cxx for description.

* Moved isAllRelevantCodeDefined from loplugin:fakebool to PluginHandler for
  reuse.  (Made it a member function so that it can reuse its two
  RecordCompleteMap instances across different loplugins.  Probably safer
  lifecycle-wise to have them as PluginHandler members than to have them as
  static local variables in function isAllRelevantCodeDefined.)

* Need Plugin::ignoreLocation overload for TypeLoc now, thanks to
  UnusedMember::VisitElaboratedTypeLoc.

* UETT_PreferredAlignOf was split off UETT_AlignOf with <https://github.com/
  llvm/llvm-project/commit/6822bd79ac43f267613f1615bf60407103e24dba> "PR26547:
  alignof should return ABI alignment, not preferred alignment".

* RecursiveASTVisitor::TraverseAlignedAttr traverses into the attribute's
  argument only since <https://github.com/llvm/llvm-project/commit/
  f26d551387f032e05e5e6551605b150f38c3f5b2> "Do not look through pack
  expansions when looking for unexpanded parameter packs".

Change-Id: Ic2702b03d4567fa2533333766de7920f3c524a69
Reviewed-on: https://gerrit.libreoffice.org/84416
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-12-05 13:30:36 +01:00

110 lines
3.3 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;
// Used internally by PluginHandler::isAllRelevantCodeDefined and its (free) helper functions:
typedef llvm::DenseMap<const CXXRecordDecl*, bool> RecordCompleteMap;
/**
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 isSharedPlugin, bool byDefault );
DiagnosticBuilder report( DiagnosticsEngine::Level level, const char * plugin, StringRef message,
CompilerInstance& compiler, SourceLocation loc = SourceLocation());
bool ignoreLocation(SourceLocation loc);
bool isDebugMode() const { return debugMode; }
static bool isUnitTestMode();
// If we overlap with a previous area we modified, we cannot perform this change
// without corrupting the source
bool checkOverlap(SourceRange range);
void addSourceModification(SourceRange range);
StringRef const& getMainFileName() const { return mainFileName; }
// Is all code that could see `decl` defined in this TU?
bool isAllRelevantCodeDefined(NamedDecl const * decl);
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::string scope;
std::string warningsOnly;
bool warningsAsErrors;
bool debugMode = false;
std::vector<std::pair<char const*, char const*>> mvModifiedRanges;
// Used internally by isAllRelevantCodeDefined:
RecordCompleteMap RecordsComplete_;
RecordCompleteMap MNCComplete_;
};
/**
The Clang plugin class, just forwards to PluginHandler.
*/
class LibreOfficeAction
: public PluginASTAction
{
public:
virtual std::unique_ptr<ASTConsumer> CreateASTConsumer( CompilerInstance& Compiler, StringRef InFile );
virtual bool ParseArgs( const CompilerInstance& CI, const std::vector< std::string >& args );
private:
std::vector< std::string > _args;
};
}
#endif // COMPILEPLUGIN_H
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */