Browse Source

Upgrade dotnet-format from version 5 to the version included with the .NET (6) SDK.

pull/2747/head
Daniel Grunwald 3 years ago
parent
commit
08ceffc3ad
  1. 5
      .github/workflows/build-ilspy.yml
  2. 10
      BuildTools/pre-commit
  3. 33
      BuildTools/tidy.py
  4. 3
      ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs
  5. 45
      ICSharpCode.Decompiler/CSharp/RecordDecompiler.cs
  6. 12
      ICSharpCode.Decompiler/IL/Transforms/InterpolatedStringTransform.cs
  7. 9
      ICSharpCode.Decompiler/IL/Transforms/RemoveInfeasiblePathTransform.cs
  8. 13
      ICSharpCode.Decompiler/IL/Transforms/UsingTransform.cs

5
.github/workflows/build-ilspy.yml

@ -30,9 +30,6 @@ jobs: @@ -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
@ -67,7 +64,7 @@ jobs: @@ -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'

10
BuildTools/pre-commit

@ -0,0 +1,10 @@ @@ -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
BuildTools/tidy.py

@ -1,33 +0,0 @@ @@ -1,33 +0,0 @@
#!/usr/bin/env python
import os, sys, subprocess
def check(filename):
ok = True
with open(filename, 'r') as f:
for i, line in enumerate(f):
if line.startswith(' '):
print('{}:{}: Line starting with spaces. Use tabs for indentation instead!'.format(filename, i+1))
ok = False
return ok
def main():
root_dir = os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))
dirs_to_check = (
os.path.join(root_dir, subdir)
for subdir in ('ICSharpCode.Decompiler', 'ICSharpCode.Decompiler.Tests', 'ILSpy', 'ILSpy.BamlDecompiler'))
format_result = subprocess.call(['dotnet-format', '--check', '--verbosity', 'detailed', os.path.join(root_dir, 'ILSpy.sln')])
ok = format_result == 0
for dir in dirs_to_check:
for root, dirs, files in os.walk(dir):
if '\\obj\\' in root:
continue
for filename in files:
if filename.lower().endswith('.cs') and not filename.lower().endswith('resources.designer.cs'):
if not check(os.path.join(root, filename)):
ok = False
print('Tidy check: {}'.format('successful' if ok else 'failed'))
return 0 if ok else 1
if __name__ == '__main__':
sys.exit(main())

3
ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs

@ -733,8 +733,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -733,8 +733,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
case ThisReferenceExpression _:
case PrimitiveExpression _:
case IdentifierExpression _:
case MemberReferenceExpression
{
case MemberReferenceExpression {
Target: ThisReferenceExpression
or IdentifierExpression
or BaseReferenceExpression

45
ICSharpCode.Decompiler/CSharp/RecordDecompiler.cs

@ -476,11 +476,10 @@ namespace ICSharpCode.Decompiler.CSharp @@ -476,11 +476,10 @@ namespace ICSharpCode.Decompiler.CSharp
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++;
}
@ -924,19 +923,17 @@ namespace ICSharpCode.Decompiler.CSharp @@ -924,19 +923,17 @@ namespace ICSharpCode.Decompiler.CSharp
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;
@ -1039,14 +1036,12 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1039,14 +1036,12 @@ namespace ICSharpCode.Decompiler.CSharp
{
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;

12
ICSharpCode.Decompiler/IL/Transforms/InterpolatedStringTransform.cs

@ -33,11 +33,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -33,11 +33,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms
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 _)
@ -122,8 +121,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -122,8 +121,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
Debug.Assert(insertionPoint == result.LoadInst.Parent);
}
return insertionPoint is Call
{
return insertionPoint is Call {
Arguments: { Count: 1 },
Method: { Name: "ToStringAndClear", IsStatic: false }
};

9
ICSharpCode.Decompiler/IL/Transforms/RemoveInfeasiblePathTransform.cs

@ -79,11 +79,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -79,11 +79,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms
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;
}

13
ICSharpCode.Decompiler/IL/Transforms/UsingTransform.cs

@ -389,13 +389,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -389,13 +389,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms
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;

Loading…
Cancel
Save