File: FixItExporter.h

package info (click to toggle)
clazy 1.17-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,248 kB
  • sloc: cpp: 23,552; python: 1,450; xml: 450; sh: 237; makefile: 45
file content (54 lines) | stat: -rw-r--r-- 1,644 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
    SPDX-FileCopyrightText: 2019 Christian Gagneraud <chgans@gmail.com>

    SPDX-License-Identifier: LGPL-2.0-or-later
*/

#ifndef CLAZY_FIX_IT_EXPORTER_H
#define CLAZY_FIX_IT_EXPORTER_H

#include <clang/Basic/Diagnostic.h>
#include <clang/Tooling/Core/Diagnostic.h>

namespace clang
{
class FixItOptions;
}

class FixItExporter : public clang::DiagnosticConsumer
{
public:
    explicit FixItExporter(clang::DiagnosticsEngine &DiagEngine,
                           clang::SourceManager &SourceMgr,
                           const clang::LangOptions &LangOpts,
                           const std::string &exportFixes,
                           bool isClazyStandalone);

    ~FixItExporter() override;

    bool IncludeInDiagnosticCounts() const override;

    void BeginSourceFile(const clang::LangOptions &LangOpts, const clang::Preprocessor *PP = nullptr) override;

    void EndSourceFile() override;

    void HandleDiagnostic(clang::DiagnosticsEngine::Level DiagLevel, const clang::Diagnostic &Info) override;

    void Export();

    /// Emit a diagnostic via the adapted diagnostic client.
    void Diag(clang::SourceLocation Loc, unsigned DiagID);

private:
    clang::DiagnosticsEngine &DiagEngine;
    clang::SourceManager &SourceMgr;
    const clang::LangOptions &LangOpts;
    const std::string exportFixes;
    DiagnosticConsumer *Client = nullptr;
    std::unique_ptr<DiagnosticConsumer> Owner;
    bool m_recordNotes = false;
    clang::tooling::Diagnostic ConvertDiagnostic(const clang::Diagnostic &Info);
    clang::tooling::Replacement ConvertFixIt(const clang::FixItHint &Hint);
};

#endif // CLAZY_FIX_IT_EXPORTER_H