clang API Documentation
00001 //===- VerifyDiagnosticConsumer.h - Verifying Diagnostic Client -*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 00010 #ifndef LLVM_CLANG_FRONTEND_VERIFYDIAGNOSTICSCLIENT_H 00011 #define LLVM_CLANG_FRONTEND_VERIFYDIAGNOSTICSCLIENT_H 00012 00013 #include "clang/Basic/Diagnostic.h" 00014 #include "llvm/ADT/OwningPtr.h" 00015 00016 namespace clang { 00017 00018 class DiagnosticsEngine; 00019 class TextDiagnosticBuffer; 00020 00021 /// VerifyDiagnosticConsumer - Create a diagnostic client which will use 00022 /// markers in the input source to check that all the emitted diagnostics match 00023 /// those expected. 00024 /// 00025 /// USING THE DIAGNOSTIC CHECKER: 00026 /// 00027 /// Indicating that a line expects an error or a warning is simple. Put a 00028 /// comment on the line that has the diagnostic, use: 00029 /// 00030 /// expected-{error,warning,note} 00031 /// 00032 /// to tag if it's an expected error or warning, and place the expected text 00033 /// between {{ and }} markers. The full text doesn't have to be included, only 00034 /// enough to ensure that the correct diagnostic was emitted. 00035 /// 00036 /// Here's an example: 00037 /// 00038 /// int A = B; // expected-error {{use of undeclared identifier 'B'}} 00039 /// 00040 /// You can place as many diagnostics on one line as you wish. To make the code 00041 /// more readable, you can use slash-newline to separate out the diagnostics. 00042 /// 00043 /// The simple syntax above allows each specification to match exactly one 00044 /// error. You can use the extended syntax to customize this. The extended 00045 /// syntax is "expected-<type> <n> {{diag text}}", where <type> is one of 00046 /// "error", "warning" or "note", and <n> is a positive integer. This allows the 00047 /// diagnostic to appear as many times as specified. Example: 00048 /// 00049 /// void f(); // expected-note 2 {{previous declaration is here}} 00050 /// 00051 /// Regex matching mode may be selected by appending '-re' to type. Example: 00052 /// 00053 /// expected-error-re 00054 /// 00055 /// Examples matching error: "variable has incomplete type 'struct s'" 00056 /// 00057 /// // expected-error {{variable has incomplete type 'struct s'}} 00058 /// // expected-error {{variable has incomplete type}} 00059 /// 00060 /// // expected-error-re {{variable has has type 'struct .'}} 00061 /// // expected-error-re {{variable has has type 'struct .*'}} 00062 /// // expected-error-re {{variable has has type 'struct (.*)'}} 00063 /// // expected-error-re {{variable has has type 'struct[[:space:]](.*)'}} 00064 /// 00065 class VerifyDiagnosticConsumer: public DiagnosticConsumer { 00066 public: 00067 DiagnosticsEngine &Diags; 00068 DiagnosticConsumer *PrimaryClient; 00069 bool OwnsPrimaryClient; 00070 OwningPtr<TextDiagnosticBuffer> Buffer; 00071 Preprocessor *CurrentPreprocessor; 00072 00073 private: 00074 FileID FirstErrorFID; // FileID of first diagnostic 00075 void CheckDiagnostics(); 00076 00077 public: 00078 /// Create a new verifying diagnostic client, which will issue errors to \arg 00079 /// the currently-attached diagnostic client when a diagnostic does not match 00080 /// what is expected (as indicated in the source file). 00081 VerifyDiagnosticConsumer(DiagnosticsEngine &Diags); 00082 ~VerifyDiagnosticConsumer(); 00083 00084 virtual void BeginSourceFile(const LangOptions &LangOpts, 00085 const Preprocessor *PP); 00086 00087 virtual void EndSourceFile(); 00088 00089 virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, 00090 const Diagnostic &Info); 00091 00092 virtual DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const; 00093 }; 00094 00095 } // end namspace clang 00096 00097 #endif