]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/clang/Frontend/VerifyDiagnosticsClient.h
Update clang to r96341.
[FreeBSD/FreeBSD.git] / include / clang / Frontend / VerifyDiagnosticsClient.h
1 //===-- VerifyDiagnosticsClient.h - Verifying Diagnostic Client -*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_CLANG_FRONTEND_VERIFYDIAGNOSTICSCLIENT_H
11 #define LLVM_CLANG_FRONTEND_VERIFYDIAGNOSTICSCLIENT_H
12
13 #include "clang/Basic/Diagnostic.h"
14 #include "llvm/ADT/OwningPtr.h"
15
16 namespace clang {
17
18 class Diagnostic;
19 class SourceMgr;
20 class TextDiagnosticBuffer;
21
22 /// VerifyDiagnosticsClient - Create a diagnostic client which will use markers
23 /// in the input source to check that all the emitted diagnostics match those
24 /// expected.
25 ///
26 /// USING THE DIAGNOSTIC CHECKER:
27 ///
28 /// Indicating that a line expects an error or a warning is simple. Put a
29 /// comment on the line that has the diagnostic, use "expected-{error,warning}"
30 /// to tag if it's an expected error or warning, and place the expected text
31 /// between {{ and }} markers. The full text doesn't have to be included, only
32 /// enough to ensure that the correct diagnostic was emitted.
33 ///
34 /// Here's an example:
35 ///
36 ///   int A = B; // expected-error {{use of undeclared identifier 'B'}}
37 ///
38 /// You can place as many diagnostics on one line as you wish. To make the code
39 /// more readable, you can use slash-newline to separate out the diagnostics.
40 ///
41 /// The simple syntax above allows each specification to match exactly one
42 /// error.  You can use the extended syntax to customize this. The extended
43 /// syntax is "expected-<type> <n> {{diag text}}", where <type> is one of
44 /// "error", "warning" or "note", and <n> is a positive integer. This allows the
45 /// diagnostic to appear as many times as specified. Example:
46 ///
47 ///   void f(); // expected-note 2 {{previous declaration is here}}
48 ///
49 class VerifyDiagnosticsClient : public DiagnosticClient {
50 public:
51   Diagnostic &Diags;
52   llvm::OwningPtr<DiagnosticClient> PrimaryClient;
53   llvm::OwningPtr<TextDiagnosticBuffer> Buffer;
54   Preprocessor *CurrentPreprocessor;
55   unsigned NumErrors;
56
57 private:
58   void CheckDiagnostics();
59
60 public:
61   /// Create a new verifying diagnostic client, which will issue errors to \arg
62   /// PrimaryClient when a diagnostic does not match what is expected (as
63   /// indicated in the source file). The verifying diagnostic client takes
64   /// ownership of \arg PrimaryClient.
65   VerifyDiagnosticsClient(Diagnostic &Diags, DiagnosticClient *PrimaryClient);
66   ~VerifyDiagnosticsClient();
67
68   virtual void BeginSourceFile(const LangOptions &LangOpts,
69                                const Preprocessor *PP);
70
71   virtual void EndSourceFile();
72
73   virtual void HandleDiagnostic(Diagnostic::Level DiagLevel,
74                                 const DiagnosticInfo &Info);
75
76   /// HadErrors - Check if there were any mismatches in expected diagnostics.
77   bool HadErrors();
78 };
79
80 } // end namspace clang
81
82 #endif