Browse Source

Improve diagnostic - error/warning info back to C#.

pull/1/head
Tarmo Pikaro 13 years ago committed by triton
parent
commit
64c46def5d
  1. 27
      src/Parser/Parser.cpp
  2. 12
      src/Parser/Parser.h

27
src/Parser/Parser.cpp

@ -1278,7 +1278,8 @@ void Parser::WalkMacros(clang::PreprocessingRecord* PR)
macro->Expression = marshalString<E_UTF8>(Expression)->Trim(); macro->Expression = marshalString<E_UTF8>(Expression)->Trim();
auto M = GetModule(BeginExpr); auto M = GetModule(BeginExpr);
M->Macros->Add(macro); if( M != nullptr )
M->Macros->Add(macro);
break; break;
} }
@ -1560,6 +1561,7 @@ struct Diagnostic
{ {
clang::SourceLocation Location; clang::SourceLocation Location;
llvm::SmallString<100> Message; llvm::SmallString<100> Message;
clang::DiagnosticsEngine::Level Level;
}; };
struct DiagnosticConsumer : public clang::DiagnosticConsumer struct DiagnosticConsumer : public clang::DiagnosticConsumer
@ -1570,6 +1572,7 @@ struct DiagnosticConsumer : public clang::DiagnosticConsumer
const clang::Diagnostic& Info) override { const clang::Diagnostic& Info) override {
auto Diag = Diagnostic(); auto Diag = Diagnostic();
Diag.Location = Info.getLocation(); Diag.Location = Info.getLocation();
Diag.Level = Level;
Info.FormatDiagnostic(Diag.Message); Info.FormatDiagnostic(Diag.Message);
Diagnostics.push_back(Diag); Diagnostics.push_back(Diag);
} }
@ -1635,6 +1638,28 @@ ParserResult^ Parser::Parse(const std::string& File)
auto PDiag = ParserDiagnostic(); auto PDiag = ParserDiagnostic();
PDiag.FileName = marshalString<E_UTF8>(FileName.str()); PDiag.FileName = marshalString<E_UTF8>(FileName.str());
PDiag.Message = marshalString<E_UTF8>(Diag.Message.str()); PDiag.Message = marshalString<E_UTF8>(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); res->Diagnostics->Add(PDiag);
} }

12
src/Parser/Parser.h

@ -55,10 +55,22 @@ public ref struct ParserOptions
bool Verbose; bool Verbose;
}; };
public enum struct ParserDiagnosticLevel
{
Ignored,
Note,
Warning,
Error,
Fatal
};
public value struct ParserDiagnostic public value struct ParserDiagnostic
{ {
System::String^ FileName; System::String^ FileName;
System::String^ Message; System::String^ Message;
ParserDiagnosticLevel Level;
}; };
public enum struct ParserResultKind public enum struct ParserResultKind

Loading…
Cancel
Save