From 64c46def5d7958279eb24e19dae557e17054a919 Mon Sep 17 00:00:00 2001 From: Tarmo Pikaro Date: Sat, 9 Mar 2013 09:58:30 +0200 Subject: [PATCH] Improve diagnostic - error/warning info back to C#. --- src/Parser/Parser.cpp | 27 ++++++++++++++++++++++++++- src/Parser/Parser.h | 12 ++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/Parser/Parser.cpp b/src/Parser/Parser.cpp index fef15f01..ee0072b3 100644 --- a/src/Parser/Parser.cpp +++ b/src/Parser/Parser.cpp @@ -1278,7 +1278,8 @@ void Parser::WalkMacros(clang::PreprocessingRecord* PR) macro->Expression = marshalString(Expression)->Trim(); auto M = GetModule(BeginExpr); - M->Macros->Add(macro); + if( M != nullptr ) + M->Macros->Add(macro); break; } @@ -1560,6 +1561,7 @@ struct Diagnostic { clang::SourceLocation Location; llvm::SmallString<100> Message; + clang::DiagnosticsEngine::Level Level; }; struct DiagnosticConsumer : public clang::DiagnosticConsumer @@ -1570,6 +1572,7 @@ struct DiagnosticConsumer : public clang::DiagnosticConsumer const clang::Diagnostic& Info) override { auto Diag = Diagnostic(); Diag.Location = Info.getLocation(); + Diag.Level = Level; Info.FormatDiagnostic(Diag.Message); Diagnostics.push_back(Diag); } @@ -1635,6 +1638,28 @@ ParserResult^ Parser::Parse(const std::string& File) auto PDiag = ParserDiagnostic(); PDiag.FileName = marshalString(FileName.str()); PDiag.Message = marshalString(Diag.Message.str()); + + switch( Diag.Level ) + { + case clang::DiagnosticsEngine::Ignored: + PDiag.Level = ParserDiagnosticLevel::Ignored; + break; + case clang::DiagnosticsEngine::Note: + PDiag.Level = ParserDiagnosticLevel::Note; + break; + case clang::DiagnosticsEngine::Warning: + default: + PDiag.Level = ParserDiagnosticLevel::Warning; + break; + case clang::DiagnosticsEngine::Error: + PDiag.Level = ParserDiagnosticLevel::Error; + break; + case clang::DiagnosticsEngine::Fatal: + PDiag.Level = ParserDiagnosticLevel::Fatal; + break; + break; + } // switch + res->Diagnostics->Add(PDiag); } diff --git a/src/Parser/Parser.h b/src/Parser/Parser.h index 2ccf27c4..a6a9e2bf 100644 --- a/src/Parser/Parser.h +++ b/src/Parser/Parser.h @@ -55,10 +55,22 @@ public ref struct ParserOptions bool Verbose; }; + +public enum struct ParserDiagnosticLevel +{ + Ignored, + Note, + Warning, + Error, + Fatal +}; + + public value struct ParserDiagnostic { System::String^ FileName; System::String^ Message; + ParserDiagnosticLevel Level; }; public enum struct ParserResultKind