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"
20 class TextDiagnosticBuffer;
22 /// VerifyDiagnosticsClient - Create a diagnostic client which will use markers
23 /// in the input source to check that all the emitted diagnostics match those
26 /// USING THE DIAGNOSTIC CHECKER:
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.
34 /// Here's an example:
36 /// int A = B; // expected-error {{use of undeclared identifier 'B'}}
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.
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:
47 /// void f(); // expected-note 2 {{previous declaration is here}}
49 class VerifyDiagnosticsClient : public DiagnosticClient {
52 llvm::OwningPtr<DiagnosticClient> PrimaryClient;
53 llvm::OwningPtr<TextDiagnosticBuffer> Buffer;
54 Preprocessor *CurrentPreprocessor;
58 void CheckDiagnostics();
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();
68 virtual void BeginSourceFile(const LangOptions &LangOpts,
69 const Preprocessor *PP);
71 virtual void EndSourceFile();
73 virtual void HandleDiagnostic(Diagnostic::Level DiagLevel,
74 const DiagnosticInfo &Info);
76 /// HadErrors - Check if there were any mismatches in expected diagnostics.
80 } // end namspace clang