1 //===-- VerifyDiagnosticsClient.h - Verifying Diagnostic Client -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CLANG_FRONTEND_VERIFYDIAGNOSTICSCLIENT_H
11 #define LLVM_CLANG_FRONTEND_VERIFYDIAGNOSTICSCLIENT_H
13 #include "clang/Basic/Diagnostic.h"
14 #include "llvm/ADT/OwningPtr.h"
19 class TextDiagnosticBuffer
;
21 /// VerifyDiagnosticsClient - Create a diagnostic client which will use markers
22 /// in the input source to check that all the emitted diagnostics match those
25 /// USING THE DIAGNOSTIC CHECKER:
27 /// Indicating that a line expects an error or a warning is simple. Put a
28 /// comment on the line that has the diagnostic, use:
30 /// expected-{error,warning,note}
32 /// to tag if it's an expected error or warning, and place the expected text
33 /// between {{ and }} markers. The full text doesn't have to be included, only
34 /// enough to ensure that the correct diagnostic was emitted.
36 /// Here's an example:
38 /// int A = B; // expected-error {{use of undeclared identifier 'B'}}
40 /// You can place as many diagnostics on one line as you wish. To make the code
41 /// more readable, you can use slash-newline to separate out the diagnostics.
43 /// The simple syntax above allows each specification to match exactly one
44 /// error. You can use the extended syntax to customize this. The extended
45 /// syntax is "expected-<type> <n> {{diag text}}", where <type> is one of
46 /// "error", "warning" or "note", and <n> is a positive integer. This allows the
47 /// diagnostic to appear as many times as specified. Example:
49 /// void f(); // expected-note 2 {{previous declaration is here}}
51 /// Regex matching mode may be selected by appending '-re' to type. Example:
55 /// Examples matching error: "variable has incomplete type 'struct s'"
57 /// // expected-error {{variable has incomplete type 'struct s'}}
58 /// // expected-error {{variable has incomplete type}}
60 /// // expected-error-re {{variable has has type 'struct .'}}
61 /// // expected-error-re {{variable has has type 'struct .*'}}
62 /// // expected-error-re {{variable has has type 'struct (.*)'}}
63 /// // expected-error-re {{variable has has type 'struct[[:space:]](.*)'}}
65 class VerifyDiagnosticsClient
: public DiagnosticClient
{
68 llvm::OwningPtr
<DiagnosticClient
> PrimaryClient
;
69 llvm::OwningPtr
<TextDiagnosticBuffer
> Buffer
;
70 Preprocessor
*CurrentPreprocessor
;
73 void CheckDiagnostics();
76 /// Create a new verifying diagnostic client, which will issue errors to \arg
77 /// PrimaryClient when a diagnostic does not match what is expected (as
78 /// indicated in the source file). The verifying diagnostic client takes
79 /// ownership of \arg PrimaryClient.
80 VerifyDiagnosticsClient(Diagnostic
&Diags
, DiagnosticClient
*PrimaryClient
);
81 ~VerifyDiagnosticsClient();
83 virtual void BeginSourceFile(const LangOptions
&LangOpts
,
84 const Preprocessor
*PP
);
86 virtual void EndSourceFile();
88 virtual void HandleDiagnostic(Diagnostic::Level DiagLevel
,
89 const DiagnosticInfo
&Info
);
92 } // end namspace clang