1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | #ifndef LLVM_CLANG_FRONTEND_DIAGNOSTICRENDERER_H |
16 | #define LLVM_CLANG_FRONTEND_DIAGNOSTICRENDERER_H |
17 | |
18 | #include "clang/Basic/Diagnostic.h" |
19 | #include "clang/Basic/DiagnosticOptions.h" |
20 | #include "clang/Basic/LLVM.h" |
21 | #include "clang/Basic/SourceLocation.h" |
22 | #include "llvm/ADT/ArrayRef.h" |
23 | #include "llvm/ADT/IntrusiveRefCntPtr.h" |
24 | #include "llvm/ADT/PointerUnion.h" |
25 | #include "llvm/ADT/StringRef.h" |
26 | |
27 | namespace clang { |
28 | |
29 | class LangOptions; |
30 | class SourceManager; |
31 | |
32 | using DiagOrStoredDiag = |
33 | llvm::PointerUnion<const Diagnostic *, const StoredDiagnostic *>; |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | class DiagnosticRenderer { |
48 | protected: |
49 | const LangOptions &LangOpts; |
50 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts; |
51 | |
52 | |
53 | |
54 | |
55 | |
56 | |
57 | SourceLocation LastLoc; |
58 | |
59 | |
60 | |
61 | |
62 | |
63 | SourceLocation LastIncludeLoc; |
64 | |
65 | |
66 | |
67 | |
68 | |
69 | DiagnosticsEngine::Level LastLevel = DiagnosticsEngine::Ignored; |
70 | |
71 | DiagnosticRenderer(const LangOptions &LangOpts, |
72 | DiagnosticOptions *DiagOpts); |
73 | |
74 | virtual ~DiagnosticRenderer(); |
75 | |
76 | virtual void emitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc, |
77 | DiagnosticsEngine::Level Level, |
78 | StringRef Message, |
79 | ArrayRef<CharSourceRange> Ranges, |
80 | DiagOrStoredDiag Info) = 0; |
81 | |
82 | virtual void emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc, |
83 | DiagnosticsEngine::Level Level, |
84 | ArrayRef<CharSourceRange> Ranges) = 0; |
85 | |
86 | virtual void emitCodeContext(FullSourceLoc Loc, |
87 | DiagnosticsEngine::Level Level, |
88 | SmallVectorImpl<CharSourceRange> &Ranges, |
89 | ArrayRef<FixItHint> Hints) = 0; |
90 | |
91 | virtual void emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) = 0; |
92 | virtual void emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc, |
93 | StringRef ModuleName) = 0; |
94 | virtual void emitBuildingModuleLocation(FullSourceLoc Loc, PresumedLoc PLoc, |
95 | StringRef ModuleName) = 0; |
96 | |
97 | virtual void beginDiagnostic(DiagOrStoredDiag D, |
98 | DiagnosticsEngine::Level Level) {} |
99 | virtual void endDiagnostic(DiagOrStoredDiag D, |
100 | DiagnosticsEngine::Level Level) {} |
101 | |
102 | private: |
103 | void emitBasicNote(StringRef Message); |
104 | void emitIncludeStack(FullSourceLoc Loc, PresumedLoc PLoc, |
105 | DiagnosticsEngine::Level Level); |
106 | void emitIncludeStackRecursively(FullSourceLoc Loc); |
107 | void emitImportStack(FullSourceLoc Loc); |
108 | void emitImportStackRecursively(FullSourceLoc Loc, StringRef ModuleName); |
109 | void emitModuleBuildStack(const SourceManager &SM); |
110 | void emitCaret(FullSourceLoc Loc, DiagnosticsEngine::Level Level, |
111 | ArrayRef<CharSourceRange> Ranges, ArrayRef<FixItHint> Hints); |
112 | void emitSingleMacroExpansion(FullSourceLoc Loc, |
113 | DiagnosticsEngine::Level Level, |
114 | ArrayRef<CharSourceRange> Ranges); |
115 | void emitMacroExpansions(FullSourceLoc Loc, DiagnosticsEngine::Level Level, |
116 | ArrayRef<CharSourceRange> Ranges, |
117 | ArrayRef<FixItHint> Hints); |
118 | |
119 | public: |
120 | |
121 | |
122 | |
123 | |
124 | |
125 | |
126 | |
127 | |
128 | |
129 | |
130 | |
131 | |
132 | void emitDiagnostic(FullSourceLoc Loc, DiagnosticsEngine::Level Level, |
133 | StringRef Message, ArrayRef<CharSourceRange> Ranges, |
134 | ArrayRef<FixItHint> FixItHints, |
135 | DiagOrStoredDiag D = (Diagnostic *)nullptr); |
136 | |
137 | void emitStoredDiagnostic(StoredDiagnostic &Diag); |
138 | }; |
139 | |
140 | |
141 | |
142 | class DiagnosticNoteRenderer : public DiagnosticRenderer { |
143 | public: |
144 | DiagnosticNoteRenderer(const LangOptions &LangOpts, |
145 | DiagnosticOptions *DiagOpts) |
146 | : DiagnosticRenderer(LangOpts, DiagOpts) {} |
147 | |
148 | ~DiagnosticNoteRenderer() override; |
149 | |
150 | void emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) override; |
151 | |
152 | void emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc, |
153 | StringRef ModuleName) override; |
154 | |
155 | void emitBuildingModuleLocation(FullSourceLoc Loc, PresumedLoc PLoc, |
156 | StringRef ModuleName) override; |
157 | |
158 | virtual void emitNote(FullSourceLoc Loc, StringRef Message) = 0; |
159 | }; |
160 | |
161 | } |
162 | |
163 | #endif |
164 | |