+/**
+ * This class provides Simple diagnostic Client. It uses implementation in library for printing diagnostci information.
+ * Also it counts number of warnings, errors, ... When an error occurs the program is stopped.
+ */
+class MyDiagnosticClient : public TextDiagnosticPrinter
+{
+ int nwarnings; /** Save number of Warnings occured during diagnostic */
+ int nnotes;
+ int nignored;
+ int nerrors;
+ public:
+ /**
+ * Initialize number of warnings, errors, ...
+ */
+ MyDiagnosticClient(llvm::raw_ostream &os, const DiagnosticOptions &diags, bool OwnsOutputStream = false):TextDiagnosticPrinter(os, diags, OwnsOutputStream = false)
+ {
+ nwarnings=0;
+ nnotes=0;
+ nignored=0;
+ nerrors = 0;
+ }
+ /**
+ * This method prints diagnostic and counts diagnostic types.
+ */
+ virtual void HandleDiagnostic(Diagnostic::Level DiagLevel, const DiagnosticInfo &Info)
+ {
+ TextDiagnosticPrinter::HandleDiagnostic(DiagLevel, Info); // print diagnostic information using library implementation
+ switch (DiagLevel) // count number of all diagnostic information
+ {
+ case 0 : nignored+=1; break;
+ case 1 : nnotes+=1; break;
+ case 2 : nwarnings+=1; break;
+ default : nerrors+=1;
+ print_stats();
+ exit(1);
+ }
+ }
+ /**
+ * Print statistics about diagnostic.
+ */
+ void print_stats()
+ {
+ cout<<"\n--Diagnostic Info--\n";
+ cout<<"Number of ignored: "<<nignored<<"\n";
+ cout<<"Number of notes: "<<nnotes<<"\n";
+ cout<<"Number of warnings: "<<nwarnings<<"\n";
+ cout<<"Number of errors and fatal errors: "<<nerrors<<"\n";
+ }
+
+ int getNbrOfWarnings() /** Return number of warnings */
+ {
+ return nwarnings;
+ }
+
+ int getNbrOfNotes() /** Return number of notes */
+ {
+ return nnotes;
+ }
+
+ int getNbrOfIgnored() /** Return number of ignored */
+ {
+ return nignored;
+ }
+};