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. 6
      ILSpy/VB/VBLanguage.cs

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

@ -40,6 +40,13 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
MemberName = "TypeHandle" MemberName = "TypeHandle"
}; };
DecompilerContext context;
public ReplaceMethodCallsWithOperators(DecompilerContext context)
{
this.context = context;
}
public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data) public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data)
{ {
base.VisitInvocationExpression(invocationExpression, data); base.VisitInvocationExpression(invocationExpression, data);
@ -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 // detect increment/decrement
if (assignment.Right.IsMatch(new PrimitiveExpression(1))) { if (assignment.Right.IsMatch(new PrimitiveExpression(1))) {
// only if it's not a custom operator // only if it's not a custom operator

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

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

17
ICSharpCode.Decompiler/DecompilerSettings.cs

@ -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; public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName) protected virtual void OnPropertyChanged(string propertyName)

6
ILSpy/VB/VBLanguage.cs

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

Loading…
Cancel
Save