|
|
|
@ -2,6 +2,11 @@
@@ -2,6 +2,11 @@
|
|
|
|
|
|
|
|
|
|
namespace Cxxi |
|
|
|
|
{ |
|
|
|
|
public enum DiagnosticId |
|
|
|
|
{ |
|
|
|
|
InvalidOperatorOverload |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public enum DiagnosticKind |
|
|
|
|
{ |
|
|
|
|
Message, |
|
|
|
@ -11,6 +16,7 @@ namespace Cxxi
@@ -11,6 +16,7 @@ namespace Cxxi
|
|
|
|
|
|
|
|
|
|
public struct DiagnosticInfo |
|
|
|
|
{ |
|
|
|
|
public DiagnosticKind Kind; |
|
|
|
|
public string Message; |
|
|
|
|
public string File; |
|
|
|
|
public int Line; |
|
|
|
@ -19,12 +25,51 @@ namespace Cxxi
@@ -19,12 +25,51 @@ namespace Cxxi
|
|
|
|
|
|
|
|
|
|
public interface IDiagnosticConsumer |
|
|
|
|
{ |
|
|
|
|
void Emit(DiagnosticKind kind, DiagnosticInfo info); |
|
|
|
|
void Emit(DiagnosticInfo info); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static class DiagnosticExtensions |
|
|
|
|
{ |
|
|
|
|
public static void EmitMessage(this IDiagnosticConsumer consumer, |
|
|
|
|
DiagnosticId id, string msg, params object[] args) |
|
|
|
|
{ |
|
|
|
|
var diagInfo = new DiagnosticInfo |
|
|
|
|
{ |
|
|
|
|
Kind = DiagnosticKind.Message, |
|
|
|
|
Message = string.Format(msg, args) |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
consumer.Emit(diagInfo); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void EmitWarning(this IDiagnosticConsumer consumer, |
|
|
|
|
DiagnosticId id, string msg, params object[] args) |
|
|
|
|
{ |
|
|
|
|
var diagInfo = new DiagnosticInfo |
|
|
|
|
{ |
|
|
|
|
Kind = DiagnosticKind.Warning, |
|
|
|
|
Message = string.Format(msg, args) |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
consumer.Emit(diagInfo); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void EmitError(this IDiagnosticConsumer consumer, |
|
|
|
|
DiagnosticId id, string msg, params object[] args) |
|
|
|
|
{ |
|
|
|
|
var diagInfo = new DiagnosticInfo |
|
|
|
|
{ |
|
|
|
|
Kind = DiagnosticKind.Error, |
|
|
|
|
Message = string.Format(msg, args) |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
consumer.Emit(diagInfo); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public class TextDiagnosticPrinter : IDiagnosticConsumer |
|
|
|
|
{ |
|
|
|
|
public void Emit(DiagnosticKind kind, DiagnosticInfo info) |
|
|
|
|
public void Emit(DiagnosticInfo info) |
|
|
|
|
{ |
|
|
|
|
Console.WriteLine(info.Message); |
|
|
|
|
} |
|
|
|
|