1 //===- VerifyDiagnosticConsumer.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"
18 class DiagnosticsEngine;
19 class TextDiagnosticBuffer;
21 /// VerifyDiagnosticConsumer - Create a diagnostic client which will use
22 /// markers in the input source to check that all the emitted diagnostics match
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 VerifyDiagnosticConsumer: public DiagnosticConsumer {
67 DiagnosticsEngine &Diags;
68 DiagnosticConsumer *PrimaryClient;
69 bool OwnsPrimaryClient;
70 OwningPtr<TextDiagnosticBuffer> Buffer;
71 Preprocessor *CurrentPreprocessor;
74 FileID FirstErrorFID; // FileID of first diagnostic
75 void CheckDiagnostics();
78 /// Create a new verifying diagnostic client, which will issue errors to \arg
79 /// the currently-attached diagnostic client when a diagnostic does not match
80 /// what is expected (as indicated in the source file).
81 VerifyDiagnosticConsumer(DiagnosticsEngine &Diags);
82 ~VerifyDiagnosticConsumer();
84 virtual void BeginSourceFile(const LangOptions &LangOpts,
85 const Preprocessor *PP);
87 virtual void EndSourceFile();
89 virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
90 const Diagnostic &Info);
92 virtual DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const;
95 } // end namspace clang