1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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
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
;
30 template<> struct hash
<::clang::SourceLocation
> {
31 size_t operator ()(::clang::SourceLocation loc
) const
32 { return loc
.getRawEncoding(); }
41 struct InstantiationData
;
44 Class that manages all LO modules.
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
; }
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_
;
75 std::string warningsOnly
;
76 bool warningsAsErrors
;
77 bool debugMode
= false;
78 std::vector
<std::pair
<char const*, char const*>> mvModifiedRanges
;
82 The Clang plugin class, just forwards to PluginHandler.
84 class LibreOfficeAction
85 : public PluginASTAction
88 virtual std::unique_ptr
<ASTConsumer
> CreateASTConsumer( CompilerInstance
& Compiler
, StringRef InFile
);
90 virtual bool ParseArgs( const CompilerInstance
& CI
, const std::vector
< std::string
>& args
);
92 std::vector
< std::string
> _args
;
97 #endif // COMPILEPLUGIN_H
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */