]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - contrib/llvm/tools/clang/include/clang/Frontend/VerifyDiagnosticConsumer.h
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.git] / contrib / llvm / tools / clang / include / clang / Frontend / VerifyDiagnosticConsumer.h
1 //===- VerifyDiagnosticConsumer.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 DiagnosticsEngine;
19 class TextDiagnosticBuffer;
20
21 /// VerifyDiagnosticConsumer - Create a diagnostic client which will use
22 /// markers in the input source to check that all the emitted diagnostics match
23 /// those expected.
24 ///
25 /// USING THE DIAGNOSTIC CHECKER:
26 ///
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:
29 ///
30 ///     expected-{error,warning,note}
31 ///
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.
35 ///
36 /// Here's an example:
37 ///
38 ///   int A = B; // expected-error {{use of undeclared identifier 'B'}}
39 ///
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.
42 ///
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:
48 ///
49 ///   void f(); // expected-note 2 {{previous declaration is here}}
50 ///
51 /// Regex matching mode may be selected by appending '-re' to type. Example:
52 ///
53 ///   expected-error-re
54 ///
55 /// Examples matching error: "variable has incomplete type 'struct s'"
56 ///
57 ///   // expected-error {{variable has incomplete type 'struct s'}}
58 ///   // expected-error {{variable has incomplete type}}
59 ///
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:]](.*)'}}
64 ///
65 class VerifyDiagnosticConsumer: public DiagnosticConsumer {
66 public:
67   DiagnosticsEngine &Diags;
68   DiagnosticConsumer *PrimaryClient;
69   bool OwnsPrimaryClient;
70   llvm::OwningPtr<TextDiagnosticBuffer> Buffer;
71   Preprocessor *CurrentPreprocessor;
72
73 private:
74   FileID FirstErrorFID; // FileID of first diagnostic
75   void CheckDiagnostics();
76
77 public:
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();
83
84   virtual void BeginSourceFile(const LangOptions &LangOpts,
85                                const Preprocessor *PP);
86
87   virtual void EndSourceFile();
88
89   virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
90                                 const Diagnostic &Info);
91   
92   virtual DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const;
93 };
94
95 } // end namspace clang
96
97 #endif