Skip to content

Commit

Permalink
Upgrade dotnet-format from version 5 to the version included with the…
Browse files Browse the repository at this point in the history
… .NET (6) SDK.
  • Loading branch information
dgrunwald authored and Charlie Lin committed Jul 16, 2022
1 parent 8818cc4 commit 9b38aef
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 84 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/build-ilspy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ jobs:
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.1

- name: Install dotnet-format
run: dotnet tool install dotnet-format --global --version 5.1.225507

- name: Get Version
id: version
shell: pwsh
Expand Down Expand Up @@ -67,7 +64,7 @@ jobs:
paths: "test-results/${{ matrix.configuration }}.xml"

- name: Format check
run: python BuildTools\tidy.py
run: dotnet format whitespace --verify-no-changes --verbosity detailed

- name: Verify package contents
if: matrix.configuration == 'debug'
Expand Down
10 changes: 10 additions & 0 deletions BuildTools/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
#
# To enable this hook, copy/symlink this file to ".git/hooks/pre-commit".

#if git diff --quiet --ignore-submodules; then
# dotnet format whitespace --no-restore --verbosity detailed ILSpy.sln
# git add -u -- \*\*.cs
#else
exec dotnet format whitespace --verify-no-changes --no-restore --verbosity detailed ILSpy.sln
#fi
33 changes: 0 additions & 33 deletions BuildTools/tidy.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -733,8 +733,7 @@ bool IsSimpleExpression(Expression ex)
case ThisReferenceExpression _:
case PrimitiveExpression _:
case IdentifierExpression _:
case MemberReferenceExpression
{
case MemberReferenceExpression {
Target: ThisReferenceExpression
or IdentifierExpression
or BaseReferenceExpression
Expand Down
45 changes: 20 additions & 25 deletions ICSharpCode.Decompiler/CSharp/RecordDecompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,10 @@ private bool IsGeneratedPrintMembers(IMethod method)
return false;
int pos = 0;
//Roslyn 4.0.0-3.final start to insert an call to RuntimeHelpers.EnsureSufficientExecutionStack()
if (!isStruct && !isInheritedRecord && body.Instructions[pos] is Call
{
Arguments: { Count: 0 },
Method: { Name: "EnsureSufficientExecutionStack", DeclaringType: { Namespace: "System.Runtime.CompilerServices", Name: "RuntimeHelpers" } }
})
if (!isStruct && !isInheritedRecord && body.Instructions[pos] is Call {
Arguments: { Count: 0 },
Method: { Name: "EnsureSufficientExecutionStack", DeclaringType: { Namespace: "System.Runtime.CompilerServices", Name: "RuntimeHelpers" } }
})
{
pos++;
}
Expand Down Expand Up @@ -924,19 +923,17 @@ bool IsGeneratedGetHashCode(IMethod method)

bool Visit(ILInstruction inst)
{
if (inst is BinaryNumericInstruction
{
Operator: BinaryNumericOperator.Add,
if (inst is BinaryNumericInstruction {
Operator: BinaryNumericOperator.Add,
CheckForOverflow: false,
Left: BinaryNumericInstruction {
Operator: BinaryNumericOperator.Mul,
CheckForOverflow: false,
Left: BinaryNumericInstruction
{
Operator: BinaryNumericOperator.Mul,
CheckForOverflow: false,
Left: var left,
Right: LdcI4 { Value: -1521134295 }
},
Right: var right
})
Left: var left,
Right: LdcI4 { Value: -1521134295 }
},
Right: var right
})
{
if (!Visit(left))
return false;
Expand Down Expand Up @@ -1039,14 +1036,12 @@ bool MatchMemberAccess(ILInstruction inst, out ILInstruction target, out IMember
{
target = null;
member = null;
if (inst is CallInstruction
{
Method:
{
AccessorKind: System.Reflection.MethodSemanticsAttributes.Getter,
AccessorOwner: IProperty property
}
} call && (call is CallVirt || (isSealed && call is Call)))
if (inst is CallInstruction {
Method: {
AccessorKind: System.Reflection.MethodSemanticsAttributes.Getter,
AccessorOwner: IProperty property
}
} call && (call is CallVirt || (isSealed && call is Call)))
{
if (call.Arguments.Count != 1)
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ void IStatementTransform.Run(Block block, int pos, StatementTransformContext con
int interpolationEnd;
ILInstruction insertionPoint;
// stloc v(newobj DefaultInterpolatedStringHandler..ctor(ldc.i4 literalLength, ldc.i4 formattedCount))
if (block.Instructions[pos] is StLoc
{
Variable: ILVariable { Kind: VariableKind.Local } v,
Value: NewObj { Arguments: { Count: 2 } } newObj
} stloc
if (block.Instructions[pos] is StLoc {
Variable: ILVariable { Kind: VariableKind.Local } v,
Value: NewObj { Arguments: { Count: 2 } } newObj
} stloc
&& v.Type.IsKnownType(KnownTypeCode.DefaultInterpolatedStringHandler)
&& newObj.Method.DeclaringType.IsKnownType(KnownTypeCode.DefaultInterpolatedStringHandler)
&& newObj.Arguments[0].MatchLdcI4(out _)
Expand Down Expand Up @@ -122,8 +121,7 @@ private bool FindToStringAndClear(Block block, int pos, int interpolationStart,
Debug.Assert(insertionPoint == result.LoadInst.Parent);
}

return insertionPoint is Call
{
return insertionPoint is Call {
Arguments: { Count: 1 },
Method: { Name: "ToStringAndClear", IsStatic: false }
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,10 @@ private bool MatchBlock1(Block block, [NotNullWhen(true)] out ILVariable? variab
branch = null;
if (block.Instructions.Count != 2)
return false;
if (block.Instructions[0] is not StLoc
{
Variable: { Kind: VariableKind.StackSlot } s,
Value: LdcI4 { Value: 0 or 1 } valueInst
})
if (block.Instructions[0] is not StLoc {
Variable: { Kind: VariableKind.StackSlot } s,
Value: LdcI4 { Value: 0 or 1 } valueInst
})
{
return false;
}
Expand Down
13 changes: 6 additions & 7 deletions ICSharpCode.Decompiler/IL/Transforms/UsingTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,13 +389,12 @@ bool MatchNullCheckOrTypeCheck(ILInstruction condition, ref ILVariable objVar, K
return false;
return true;
}
if (condition is MatchInstruction
{
CheckNotNull: true,
CheckType: true,
TestedOperand: LdLoc { Variable: var v },
Variable: var newObjVar
})
if (condition is MatchInstruction {
CheckNotNull: true,
CheckType: true,
TestedOperand: LdLoc { Variable: var v },
Variable: var newObjVar
})
{
if (v != objVar)
return false;
Expand Down
2 changes: 1 addition & 1 deletion TestPlugin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@

// This sets the default COM visibility of types in the assembly to invisible.
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
[assembly: ComVisible(false)]
[assembly: ComVisible(false)]

0 comments on commit 9b38aef

Please # to comment.