Browse Source

Ad #866: No longer use Debug.Assert, but add warnings to AST.

pull/870/merge
Siegfried Pammer 9 years ago
parent
commit
3c9a0d8a41
  1. 6
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  2. 7
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
  3. 4
      ICSharpCode.Decompiler/IL/ILReader.cs
  4. 11
      ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs

6
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -663,6 +663,12 @@ namespace ICSharpCode.Decompiler.CSharp
AddDefinesForConditionalAttributes(function); AddDefinesForConditionalAttributes(function);
var statementBuilder = new StatementBuilder(specializingTypeSystem, decompilationContext, method, function, settings, CancellationToken); var statementBuilder = new StatementBuilder(specializingTypeSystem, decompilationContext, method, function, settings, CancellationToken);
var body = statementBuilder.ConvertAsBlock(function.Body); var body = statementBuilder.ConvertAsBlock(function.Body);
Comment prev = null;
foreach (string warning in function.Warnings) {
body.InsertChildAfter(prev, prev = new Comment(warning), Roles.Comment);
}
entityDecl.AddChild(body, Roles.Body); entityDecl.AddChild(body, Roles.Body);
if (function.IsIterator) { if (function.IsIterator) {

7
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -1009,7 +1009,12 @@ namespace ICSharpCode.Decompiler.CSharp
var body = builder.ConvertAsBlock(function.Body); var body = builder.ConvertAsBlock(function.Body);
bool isLambda = false; bool isLambda = false;
bool isMultiLineLambda = false; bool isMultiLineLambda = false;
Comment prev = null;
foreach (string warning in function.Warnings) {
body.InsertChildAfter(prev, prev = new Comment(warning), Roles.Comment);
}
// if there is an anonymous type involved, we are forced to use a lambda expression. // if there is an anonymous type involved, we are forced to use a lambda expression.
if (ame.Parameters.Any(p => p.Type.IsNull)) { if (ame.Parameters.Any(p => p.Type.IsNull)) {
isLambda = true; isLambda = true;

4
ICSharpCode.Decompiler/IL/ILReader.cs

@ -38,6 +38,7 @@ namespace ICSharpCode.Decompiler.IL
readonly IDecompilerTypeSystem typeSystem; readonly IDecompilerTypeSystem typeSystem;
public bool UseDebugSymbols { get; set; } public bool UseDebugSymbols { get; set; }
public List<string> Warnings { get; } = new List<string>();
public ILReader(IDecompilerTypeSystem typeSystem) public ILReader(IDecompilerTypeSystem typeSystem)
{ {
@ -182,7 +183,7 @@ namespace ICSharpCode.Decompiler.IL
/// </summary> /// </summary>
void Warn(string message) void Warn(string message)
{ {
Debug.Fail(string.Format("IL_{0:x4}: {1}", currentInstruction.Offset, message)); Warnings.Add(string.Format("IL_{0:x4}: {1}", currentInstruction.Offset, message));
} }
void MergeStacks(ImmutableStack<ILVariable> a, ImmutableStack<ILVariable> b) void MergeStacks(ImmutableStack<ILVariable> a, ImmutableStack<ILVariable> b)
@ -324,6 +325,7 @@ namespace ICSharpCode.Decompiler.IL
foreach (var c in function.Descendants.OfType<BlockContainer>()) { foreach (var c in function.Descendants.OfType<BlockContainer>()) {
c.SortBlocks(); c.SortBlocks();
} }
function.Warnings.AddRange(Warnings);
return function; return function;
} }

11
ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs

@ -34,6 +34,11 @@ namespace ICSharpCode.Decompiler.IL
public readonly MethodDefinition Method; public readonly MethodDefinition Method;
public readonly ILVariableCollection Variables; public readonly ILVariableCollection Variables;
/// <summary>
/// List of warnings of ILReader.
/// </summary>
public List<string> Warnings { get; } = new List<string>();
/// <summary> /// <summary>
/// Gets whether this function is a decompiled iterator (is using yield). /// Gets whether this function is a decompiled iterator (is using yield).
/// This flag gets set by the YieldReturnDecompiler. /// This flag gets set by the YieldReturnDecompiler.
@ -103,6 +108,12 @@ namespace ICSharpCode.Decompiler.IL
output.MarkFoldEnd(); output.MarkFoldEnd();
output.WriteLine(); output.WriteLine();
body.WriteTo(output, options); body.WriteTo(output, options);
foreach (string warning in Warnings) {
output.WriteLine("//" + warning);
}
body.WriteTo(output);
output.WriteLine(); output.WriteLine();
output.Unindent(); output.Unindent();

Loading…
Cancel
Save