1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | #ifndef LLVM_CLANG_FRONTEND_VERIFYDIAGNOSTICCONSUMER_H |
10 | #define LLVM_CLANG_FRONTEND_VERIFYDIAGNOSTICCONSUMER_H |
11 | |
12 | #include "clang/Basic/Diagnostic.h" |
13 | #include "clang/Basic/LLVM.h" |
14 | #include "clang/Basic/SourceLocation.h" |
15 | #include "clang/Lex/Preprocessor.h" |
16 | #include "llvm/ADT/DenseMap.h" |
17 | #include "llvm/ADT/PointerIntPair.h" |
18 | #include "llvm/ADT/StringRef.h" |
19 | #include <cassert> |
20 | #include <limits> |
21 | #include <memory> |
22 | #include <string> |
23 | #include <vector> |
24 | |
25 | namespace clang { |
26 | |
27 | class FileEntry; |
28 | class LangOptions; |
29 | class SourceManager; |
30 | class TextDiagnosticBuffer; |
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 | |
106 | |
107 | |
108 | |
109 | |
110 | |
111 | |
112 | |
113 | |
114 | |
115 | |
116 | |
117 | |
118 | |
119 | |
120 | |
121 | |
122 | |
123 | |
124 | |
125 | |
126 | |
127 | |
128 | |
129 | |
130 | |
131 | |
132 | |
133 | |
134 | |
135 | |
136 | |
137 | |
138 | |
139 | |
140 | |
141 | |
142 | |
143 | |
144 | |
145 | |
146 | class VerifyDiagnosticConsumer: public DiagnosticConsumer, |
147 | public CommentHandler { |
148 | public: |
149 | |
150 | |
151 | class Directive { |
152 | public: |
153 | static std::unique_ptr<Directive> create(bool RegexKind, |
154 | SourceLocation DirectiveLoc, |
155 | SourceLocation DiagnosticLoc, |
156 | bool MatchAnyLine, StringRef Text, |
157 | unsigned Min, unsigned Max); |
158 | |
159 | public: |
160 | |
161 | static const unsigned MaxCount = std::numeric_limits<unsigned>::max(); |
162 | |
163 | SourceLocation DirectiveLoc; |
164 | SourceLocation DiagnosticLoc; |
165 | const std::string Text; |
166 | unsigned Min, Max; |
167 | bool MatchAnyLine; |
168 | |
169 | Directive(const Directive &) = delete; |
170 | Directive &operator=(const Directive &) = delete; |
171 | virtual ~Directive() = default; |
172 | |
173 | |
174 | |
175 | virtual bool isValid(std::string &Error) = 0; |
176 | |
177 | |
178 | virtual bool match(StringRef S) = 0; |
179 | |
180 | protected: |
181 | Directive(SourceLocation DirectiveLoc, SourceLocation DiagnosticLoc, |
182 | bool MatchAnyLine, StringRef Text, unsigned Min, unsigned Max) |
183 | : DirectiveLoc(DirectiveLoc), DiagnosticLoc(DiagnosticLoc), |
184 | Text(Text), Min(Min), Max(Max), MatchAnyLine(MatchAnyLine) { |
185 | (0) . __assert_fail ("!DirectiveLoc.isInvalid() && \"DirectiveLoc is invalid!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Frontend/VerifyDiagnosticConsumer.h", 185, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(!DirectiveLoc.isInvalid() && "DirectiveLoc is invalid!"); |
186 | (0) . __assert_fail ("(!DiagnosticLoc.isInvalid() || MatchAnyLine) && \"DiagnosticLoc is invalid!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Frontend/VerifyDiagnosticConsumer.h", 187, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert((!DiagnosticLoc.isInvalid() || MatchAnyLine) && |
187 | (0) . __assert_fail ("(!DiagnosticLoc.isInvalid() || MatchAnyLine) && \"DiagnosticLoc is invalid!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Frontend/VerifyDiagnosticConsumer.h", 187, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "DiagnosticLoc is invalid!"); |
188 | } |
189 | }; |
190 | |
191 | using DirectiveList = std::vector<std::unique_ptr<Directive>>; |
192 | |
193 | |
194 | struct ExpectedData { |
195 | DirectiveList Errors; |
196 | DirectiveList Warnings; |
197 | DirectiveList ; |
198 | DirectiveList Notes; |
199 | |
200 | void Reset() { |
201 | Errors.clear(); |
202 | Warnings.clear(); |
203 | Remarks.clear(); |
204 | Notes.clear(); |
205 | } |
206 | }; |
207 | |
208 | enum DirectiveStatus { |
209 | HasNoDirectives, |
210 | HasNoDirectivesReported, |
211 | HasExpectedNoDiagnostics, |
212 | HasOtherExpectedDirectives |
213 | }; |
214 | |
215 | private: |
216 | DiagnosticsEngine &Diags; |
217 | DiagnosticConsumer *PrimaryClient; |
218 | std::unique_ptr<DiagnosticConsumer> PrimaryClientOwner; |
219 | std::unique_ptr<TextDiagnosticBuffer> Buffer; |
220 | const Preprocessor *CurrentPreprocessor = nullptr; |
221 | const LangOptions *LangOpts = nullptr; |
222 | SourceManager *SrcManager = nullptr; |
223 | unsigned ActiveSourceFiles = 0; |
224 | DirectiveStatus Status; |
225 | ExpectedData ED; |
226 | |
227 | void CheckDiagnostics(); |
228 | |
229 | void setSourceManager(SourceManager &SM) { |
230 | (0) . __assert_fail ("(!SrcManager || SrcManager == &SM) && \"SourceManager changed!\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Frontend/VerifyDiagnosticConsumer.h", 230, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert((!SrcManager || SrcManager == &SM) && "SourceManager changed!"); |
231 | SrcManager = &SM; |
232 | } |
233 | |
234 | |
235 | class UnparsedFileStatus { |
236 | llvm::PointerIntPair<const FileEntry *, 1, bool> Data; |
237 | |
238 | public: |
239 | UnparsedFileStatus(const FileEntry *File, bool FoundDirectives) |
240 | : Data(File, FoundDirectives) {} |
241 | |
242 | const FileEntry *getFile() const { return Data.getPointer(); } |
243 | bool foundDirectives() const { return Data.getInt(); } |
244 | }; |
245 | |
246 | using ParsedFilesMap = llvm::DenseMap<FileID, const FileEntry *>; |
247 | using UnparsedFilesMap = llvm::DenseMap<FileID, UnparsedFileStatus>; |
248 | |
249 | ParsedFilesMap ParsedFiles; |
250 | UnparsedFilesMap UnparsedFiles; |
251 | |
252 | public: |
253 | |
254 | |
255 | |
256 | VerifyDiagnosticConsumer(DiagnosticsEngine &Diags); |
257 | ~VerifyDiagnosticConsumer() override; |
258 | |
259 | void BeginSourceFile(const LangOptions &LangOpts, |
260 | const Preprocessor *PP) override; |
261 | |
262 | void EndSourceFile() override; |
263 | |
264 | enum ParsedStatus { |
265 | |
266 | IsParsed, |
267 | |
268 | |
269 | IsUnparsed, |
270 | |
271 | |
272 | IsUnparsedNoDirectives |
273 | }; |
274 | |
275 | |
276 | void UpdateParsedFileStatus(SourceManager &SM, FileID FID, ParsedStatus PS); |
277 | |
278 | bool HandleComment(Preprocessor &PP, SourceRange ) override; |
279 | |
280 | void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, |
281 | const Diagnostic &Info) override; |
282 | }; |
283 | |
284 | } |
285 | |
286 | #endif |
287 | |