[en_US] Added 13 autocorrect words
[LibreOffice.git] / compilerplugins / clang / pluginhandler.hxx
blob54ab613b3a7e33db3159a11589a07a0c9a03c569
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 // Used internally by PluginHandler::isAllRelevantCodeDefined and its (free) helper functions:
44 typedef llvm::DenseMap<const CXXRecordDecl*, bool> RecordCompleteMap;
46 /**
47 Class that manages all LO modules.
49 class PluginHandler
50 : public ASTConsumer
52 public:
53 PluginHandler( CompilerInstance& compiler, const std::vector< std::string >& args );
54 virtual ~PluginHandler();
55 virtual void HandleTranslationUnit( ASTContext& context ) override;
56 static void registerPlugin( Plugin* (*create)( const InstantiationData& ), const char* optionName,
57 bool isPPCallback, bool isSharedPlugin, bool byDefault );
58 DiagnosticBuilder report( DiagnosticsEngine::Level level, const char * plugin, StringRef message,
59 CompilerInstance& compiler, SourceLocation loc = SourceLocation());
60 bool ignoreLocation(SourceLocation loc);
61 bool isDebugMode() const { return debugMode; }
62 static bool isUnitTestMode();
63 // If we overlap with a previous area we modified, we cannot perform this change
64 // without corrupting the source
65 bool checkOverlap(SourceRange range);
66 void addSourceModification(SourceRange range);
67 StringRef const& getMainFileName() const { return mainFileName; }
69 // Is all code that could see `decl` defined in this TU?
70 bool isAllRelevantCodeDefined(NamedDecl const * decl);
72 private:
73 void handleOption( const std::string& option );
74 void createPlugins( std::set< std::string > rewriters );
75 DiagnosticBuilder report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc = SourceLocation());
76 bool checkIgnoreLocation(SourceLocation loc);
77 CompilerInstance& compiler;
78 StringRef const mainFileName;
79 std::unordered_map<SourceLocation, bool> ignored_;
80 Rewriter rewriter;
81 std::string scope;
82 std::string warningsOnly;
83 bool warningsAsErrors;
84 bool debugMode = false;
85 std::vector<std::pair<char const*, char const*>> mvModifiedRanges;
87 // Used internally by isAllRelevantCodeDefined:
88 RecordCompleteMap RecordsComplete_;
89 RecordCompleteMap MNCComplete_;
92 /**
93 The Clang plugin class, just forwards to PluginHandler.
95 class LibreOfficeAction
96 : public PluginASTAction
98 public:
99 virtual std::unique_ptr<ASTConsumer> CreateASTConsumer( CompilerInstance& Compiler, StringRef InFile );
101 virtual bool ParseArgs( const CompilerInstance& CI, const std::vector< std::string >& args );
102 private:
103 std::vector< std::string > _args;
108 #endif // COMPILEPLUGIN_H
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */