-
Notifications
You must be signed in to change notification settings - Fork 10
/
Diagnostics.h
105 lines (68 loc) · 2.4 KB
/
Diagnostics.h
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef CCONS_DIAGNOSTICS_H
#define CCONS_DIAGNOSTICS_H
//
// Utilities related to diagnostics reporting for ccons.
//
// Part of ccons, the interactive console for the C programming language.
//
// Copyright (c) 2009 Alexei Svitkine. This file is distributed under the
// terms of MIT Open Source License. See file LICENSE for details.
//
#include <set>
#include <map>
#include <llvm/Support/raw_os_ostream.h>
#include <clang/Basic/LangOptions.h>
#include <clang/Basic/Diagnostic.h>
#include <clang/Frontend/TextDiagnosticPrinter.h>
namespace ccons {
//
// DiagnosticsProvider provides a re-usable clang::Diagnostic object
// that can be used for multiple parse operations.
//
class DiagnosticsProvider {
public:
explicit DiagnosticsProvider(llvm::raw_os_ostream& out);
void HandleDiagnostic(clang::DiagnosticsEngine::Level DiagLevel,
const clang::Diagnostic& Info);
void BeginSourceFile(const clang::LangOptions& opts, const clang::Preprocessor *pp);
void setOffset(unsigned offset);
clang::DiagnosticsEngine * getDiagnosticsEngine();
private:
unsigned _offs;
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> _dop;
clang::TextDiagnosticPrinter _tdp;
llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> _diagIDs;
clang::DiagnosticsEngine _engine;
std::set<std::pair<clang::diag::kind, unsigned> > _memory;
};
//
// ProxyDiagnosticConsumer can act as a proxy to another diagnostic client.
//
class ProxyDiagnosticConsumer : public clang::DiagnosticConsumer {
public:
explicit ProxyDiagnosticConsumer(clang::DiagnosticConsumer *DC);
void HandleDiagnostic(clang::DiagnosticsEngine::Level DiagLevel,
const clang::Diagnostic& Info);
bool hadError(clang::diag::kind Kind) const;
bool hadErrors() const;
clang::DiagnosticConsumer * clone(clang::DiagnosticsEngine& Diags) const;
private:
clang::DiagnosticConsumer *_DC;
std::multimap<clang::diag::kind, const clang::Diagnostic> _errors;
};
//
// NullDiagnosticProvider
//
class NullDiagnosticProvider {
public:
NullDiagnosticProvider();
clang::DiagnosticsEngine * getDiagnosticsEngine();
ProxyDiagnosticConsumer * getProxyDiagnosticConsumer();
private:
llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> _dop;
ProxyDiagnosticConsumer *_pdc; // owned by _engine
llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> _diagnosticIDs;
clang::DiagnosticsEngine _engine;
};
} // namespace ccons
#endif // CCONS_DIAGNOSTICS_H