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. 5
      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 @@ -663,6 +663,12 @@ namespace ICSharpCode.Decompiler.CSharp
AddDefinesForConditionalAttributes(function);
var statementBuilder = new StatementBuilder(specializingTypeSystem, decompilationContext, method, function, settings, CancellationToken);
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);
if (function.IsIterator) {

5
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -1010,6 +1010,11 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1010,6 +1010,11 @@ namespace ICSharpCode.Decompiler.CSharp
bool isLambda = 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 (ame.Parameters.Any(p => p.Type.IsNull)) {
isLambda = true;

4
ICSharpCode.Decompiler/IL/ILReader.cs

@ -38,6 +38,7 @@ namespace ICSharpCode.Decompiler.IL @@ -38,6 +38,7 @@ namespace ICSharpCode.Decompiler.IL
readonly IDecompilerTypeSystem typeSystem;
public bool UseDebugSymbols { get; set; }
public List<string> Warnings { get; } = new List<string>();
public ILReader(IDecompilerTypeSystem typeSystem)
{
@ -182,7 +183,7 @@ namespace ICSharpCode.Decompiler.IL @@ -182,7 +183,7 @@ namespace ICSharpCode.Decompiler.IL
/// </summary>
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)
@ -324,6 +325,7 @@ namespace ICSharpCode.Decompiler.IL @@ -324,6 +325,7 @@ namespace ICSharpCode.Decompiler.IL
foreach (var c in function.Descendants.OfType<BlockContainer>()) {
c.SortBlocks();
}
function.Warnings.AddRange(Warnings);
return function;
}

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

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

Loading…
Cancel
Save