bump product version to 6.3.0.0.beta1
[LibreOffice.git] / compilerplugins / clang / pluginhandler.hxx
blob10b4ae21df2bf6f5bd436595a2859136d06ae542
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * Based on LLVM/Clang.
7 * This file is distributed under the University of Illinois Open Source
8 * License. See LICENSE.TXT for details.
12 #ifndef PLUGINHANDLER_H
13 #define PLUGINHANDLER_H
15 #include <cstddef>
16 #include <functional>
17 #include <memory>
18 #include <set>
19 #include <unordered_map>
21 #include <clang/AST/ASTConsumer.h>
22 #include <clang/Frontend/CompilerInstance.h>
23 #include <clang/Frontend/FrontendAction.h>
24 #include <clang/Rewrite/Core/Rewriter.h>
26 using namespace clang;
28 namespace std {
30 template<> struct hash<::clang::SourceLocation> {
31 size_t operator ()(::clang::SourceLocation loc) const
32 { return loc.getRawEncoding(); }
37 namespace loplugin
40 class Plugin;
41 struct InstantiationData;
43 /**
44 Class that manages all LO modules.
46 class PluginHandler
47 : public ASTConsumer
49 public:
50 PluginHandler( CompilerInstance& compiler, const std::vector< std::string >& args );
51 virtual ~PluginHandler();
52 virtual void HandleTranslationUnit( ASTContext& context ) override;
53 static void registerPlugin( Plugin* (*create)( const InstantiationData& ), const char* optionName,
54 bool isPPCallback, bool isSharedPlugin, bool byDefault );
55 DiagnosticBuilder report( DiagnosticsEngine::Level level, const char * plugin, StringRef message,
56 CompilerInstance& compiler, SourceLocation loc = SourceLocation());
57 bool ignoreLocation(SourceLocation loc);
58 bool isDebugMode() const { return debugMode; }
59 static bool isUnitTestMode();
60 // If we overlap with a previous area we modified, we cannot perform this change
61 // without corrupting the source
62 bool checkOverlap(SourceRange range);
63 void addSourceModification(SourceRange range);
64 StringRef const& getMainFileName() const { return mainFileName; }
65 private:
66 void handleOption( const std::string& option );
67 void createPlugins( std::set< std::string > rewriters );
68 DiagnosticBuilder report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc = SourceLocation());
69 bool checkIgnoreLocation(SourceLocation loc);
70 CompilerInstance& compiler;
71 StringRef const mainFileName;
72 std::unordered_map<SourceLocation, bool> ignored_;
73 Rewriter rewriter;
74 std::string scope;
75 std::string warningsOnly;
76 bool warningsAsErrors;
77 bool debugMode = false;
78 std::vector<std::pair<char const*, char const*>> mvModifiedRanges;
81 /**
82 The Clang plugin class, just forwards to PluginHandler.
84 class LibreOfficeAction
85 : public PluginASTAction
87 public:
88 virtual std::unique_ptr<ASTConsumer> CreateASTConsumer( CompilerInstance& Compiler, StringRef InFile );
90 virtual bool ParseArgs( const CompilerInstance& CI, const std::vector< std::string >& args );
91 private:
92 std::vector< std::string > _args;
97 #endif // COMPILEPLUGIN_H
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */