Browse Source

Implement DecompileMemberBodies setting in CSharpDecompiler. (This fixes #1032)

pull/1039/head
Siegfried Pammer 8 years ago
parent
commit
8db1934105
  1. 27
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  2. 19
      ICSharpCode.Decompiler/DecompilerSettings.cs

27
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -47,7 +47,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -47,7 +47,7 @@ namespace ICSharpCode.Decompiler.CSharp
{
readonly DecompilerTypeSystem typeSystem;
readonly DecompilerSettings settings;
private SyntaxTree syntaxTree;
SyntaxTree syntaxTree;
List<IILTransform> ilTransforms = GetILTransforms();
@ -761,18 +761,27 @@ namespace ICSharpCode.Decompiler.CSharp @@ -761,18 +761,27 @@ namespace ICSharpCode.Decompiler.CSharp
CancellationToken.ThrowIfCancellationRequested();
transform.Run(function, context);
function.CheckInvariant(ILPhase.Normal);
// When decompiling definitions only, we can cancel decompilation of all steps
// after yield and async detection, because only those are needed to properly set
// IsAsync/IsIterator flags on ILFunction.
if (!settings.DecompileMemberBodies && transform is AsyncAwaitDecompiler)
break;
}
AddDefinesForConditionalAttributes(function);
var statementBuilder = new StatementBuilder(specializingTypeSystem, decompilationContext, function, settings, CancellationToken);
var body = statementBuilder.ConvertAsBlock(function.Body);
var body = BlockStatement.Null;
// Generate C# AST only if bodies should be displayed.
if (settings.DecompileMemberBodies) {
AddDefinesForConditionalAttributes(function);
var statementBuilder = new StatementBuilder(specializingTypeSystem, decompilationContext, function, settings, CancellationToken);
body = statementBuilder.ConvertAsBlock(function.Body);
Comment prev = null;
foreach (string warning in function.Warnings) {
body.InsertChildAfter(prev, prev = new Comment(warning), Roles.Comment);
}
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);
}
entityDecl.AddAnnotation(function);
if (function.IsIterator) {

19
ICSharpCode.Decompiler/DecompilerSettings.cs

@ -306,7 +306,7 @@ namespace ICSharpCode.Decompiler @@ -306,7 +306,7 @@ namespace ICSharpCode.Decompiler
bool objectCollectionInitializers = true;
/// <summary>
/// Gets/Sets whether to use C# 3.0 object/collection initializers
/// Gets/Sets whether to use C# 3.0 object/collection initializers.
/// </summary>
public bool ObjectOrCollectionInitializers {
get { return objectCollectionInitializers; }
@ -321,7 +321,7 @@ namespace ICSharpCode.Decompiler @@ -321,7 +321,7 @@ namespace ICSharpCode.Decompiler
bool showXmlDocumentation = true;
/// <summary>
/// Gets/Sets whether to include XML documentation comments in the decompiled code
/// Gets/Sets whether to include XML documentation comments in the decompiled code.
/// </summary>
public bool ShowXmlDocumentation {
get { return showXmlDocumentation; }
@ -345,6 +345,21 @@ namespace ICSharpCode.Decompiler @@ -345,6 +345,21 @@ namespace ICSharpCode.Decompiler
}
}
bool decompileMemberBodies = true;
/// <summary>
/// Gets/Sets whether member bodies should be decompiled.
/// </summary>
public bool DecompileMemberBodies {
get { return decompileMemberBodies; }
set {
if (decompileMemberBodies != value) {
decompileMemberBodies = value;
OnPropertyChanged();
}
}
}
#region Options to aid VB decompilation
bool introduceIncrementAndDecrement = true;

Loading…
Cancel
Save