Browse Source

add IntroduceIncrementAndDecrement setting for VB

pull/254/head
Siegfried Pammer 14 years ago
parent
commit
4c4374cc8c
  1. 9
      ICSharpCode.Decompiler/Ast/Transforms/ReplaceMethodCallsWithOperators.cs
  2. 2
      ICSharpCode.Decompiler/Ast/Transforms/TransformationPipeline.cs
  3. 17
      ICSharpCode.Decompiler/DecompilerSettings.cs
  4. 4
      ILSpy/VB/VBLanguage.cs

9
ICSharpCode.Decompiler/Ast/Transforms/ReplaceMethodCallsWithOperators.cs

@ -40,6 +40,13 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -40,6 +40,13 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
MemberName = "TypeHandle"
};
DecompilerContext context;
public ReplaceMethodCallsWithOperators(DecompilerContext context)
{
this.context = context;
}
public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data)
{
base.VisitInvocationExpression(invocationExpression, data);
@ -211,7 +218,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -211,7 +218,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
}
}
}
if (assignment.Operator == AssignmentOperatorType.Add || assignment.Operator == AssignmentOperatorType.Subtract) {
if (context.Settings.IntroduceIncrementAndDecrement && (assignment.Operator == AssignmentOperatorType.Add || assignment.Operator == AssignmentOperatorType.Subtract)) {
// detect increment/decrement
if (assignment.Right.IsMatch(new PrimitiveExpression(1))) {
// only if it's not a custom operator

2
ICSharpCode.Decompiler/Ast/Transforms/TransformationPipeline.cs

@ -35,7 +35,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -35,7 +35,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
new PushNegation(),
new DelegateConstruction(context),
new PatternStatementTransform(context),
new ReplaceMethodCallsWithOperators(),
new ReplaceMethodCallsWithOperators(context),
new IntroduceUnsafeModifier(),
new AddCheckedBlocks(),
new DeclareVariables(context), // should run after most transforms that modify statements

17
ICSharpCode.Decompiler/DecompilerSettings.cs

@ -224,6 +224,23 @@ namespace ICSharpCode.Decompiler @@ -224,6 +224,23 @@ namespace ICSharpCode.Decompiler
}
}
#region Options to aid VB decompilation
bool introduceIncrementAndDecrement = true;
/// <summary>
/// Gets/Sets whether to use increment and decrement operators
/// </summary>
public bool IntroduceIncrementAndDecrement {
get { return introduceIncrementAndDecrement; }
set {
if (introduceIncrementAndDecrement != value) {
introduceIncrementAndDecrement = value;
OnPropertyChanged("IntroduceIncrementAndDecrement");
}
}
}
#endregion
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)

4
ILSpy/VB/VBLanguage.cs

@ -122,10 +122,10 @@ namespace ICSharpCode.ILSpy.VB @@ -122,10 +122,10 @@ namespace ICSharpCode.ILSpy.VB
if (currentModule == null)
currentModule = currentType.Module;
DecompilerSettings settings = options.DecompilerSettings;
if (isSingleMember) {
settings = settings.Clone();
if (isSingleMember)
settings.UsingDeclarations = false;
}
settings.IntroduceIncrementAndDecrement = false;
return new AstBuilder(
new DecompilerContext(currentModule) {
CancellationToken = options.CancellationToken,

Loading…
Cancel
Save