Browse Source

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

pull/2747/head
Daniel Grunwald 4 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
  9. 2
      TestPlugin/Properties/AssemblyInfo.cs

5
.github/workflows/build-ilspy.yml

@ -30,9 +30,6 @@ jobs:
- name: Add msbuild to PATH - name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.1 uses: microsoft/setup-msbuild@v1.1
- name: Install dotnet-format
run: dotnet tool install dotnet-format --global --version 5.1.225507
- name: Get Version - name: Get Version
id: version id: version
shell: pwsh shell: pwsh
@ -67,7 +64,7 @@ jobs:
paths: "test-results/${{ matrix.configuration }}.xml" paths: "test-results/${{ matrix.configuration }}.xml"
- name: Format check - name: Format check
run: python BuildTools\tidy.py run: dotnet format whitespace --verify-no-changes --verbosity detailed
- name: Verify package contents - name: Verify package contents
if: matrix.configuration == 'debug' if: matrix.configuration == 'debug'

10
BuildTools/pre-commit

@ -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 @@
#!/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
case ThisReferenceExpression _: case ThisReferenceExpression _:
case PrimitiveExpression _: case PrimitiveExpression _:
case IdentifierExpression _: case IdentifierExpression _:
case MemberReferenceExpression case MemberReferenceExpression {
{
Target: ThisReferenceExpression Target: ThisReferenceExpression
or IdentifierExpression or IdentifierExpression
or BaseReferenceExpression or BaseReferenceExpression

45
ICSharpCode.Decompiler/CSharp/RecordDecompiler.cs

@ -476,11 +476,10 @@ namespace ICSharpCode.Decompiler.CSharp
return false; return false;
int pos = 0; int pos = 0;
//Roslyn 4.0.0-3.final start to insert an call to RuntimeHelpers.EnsureSufficientExecutionStack() //Roslyn 4.0.0-3.final start to insert an call to RuntimeHelpers.EnsureSufficientExecutionStack()
if (!isStruct && !isInheritedRecord && body.Instructions[pos] is Call if (!isStruct && !isInheritedRecord && body.Instructions[pos] is Call {
{ Arguments: { Count: 0 },
Arguments: { Count: 0 }, Method: { Name: "EnsureSufficientExecutionStack", DeclaringType: { Namespace: "System.Runtime.CompilerServices", Name: "RuntimeHelpers" } }
Method: { Name: "EnsureSufficientExecutionStack", DeclaringType: { Namespace: "System.Runtime.CompilerServices", Name: "RuntimeHelpers" } } })
})
{ {
pos++; pos++;
} }
@ -924,19 +923,17 @@ namespace ICSharpCode.Decompiler.CSharp
bool Visit(ILInstruction inst) bool Visit(ILInstruction inst)
{ {
if (inst is BinaryNumericInstruction if (inst is BinaryNumericInstruction {
{ Operator: BinaryNumericOperator.Add,
Operator: BinaryNumericOperator.Add, CheckForOverflow: false,
Left: BinaryNumericInstruction {
Operator: BinaryNumericOperator.Mul,
CheckForOverflow: false, CheckForOverflow: false,
Left: BinaryNumericInstruction Left: var left,
{ Right: LdcI4 { Value: -1521134295 }
Operator: BinaryNumericOperator.Mul, },
CheckForOverflow: false, Right: var right
Left: var left, })
Right: LdcI4 { Value: -1521134295 }
},
Right: var right
})
{ {
if (!Visit(left)) if (!Visit(left))
return false; return false;
@ -1039,14 +1036,12 @@ namespace ICSharpCode.Decompiler.CSharp
{ {
target = null; target = null;
member = null; member = null;
if (inst is CallInstruction if (inst is CallInstruction {
{ Method: {
Method: AccessorKind: System.Reflection.MethodSemanticsAttributes.Getter,
{ AccessorOwner: IProperty property
AccessorKind: System.Reflection.MethodSemanticsAttributes.Getter, }
AccessorOwner: IProperty property } call && (call is CallVirt || (isSealed && call is Call)))
}
} call && (call is CallVirt || (isSealed && call is Call)))
{ {
if (call.Arguments.Count != 1) if (call.Arguments.Count != 1)
return false; return false;

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

@ -33,11 +33,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms
int interpolationEnd; int interpolationEnd;
ILInstruction insertionPoint; ILInstruction insertionPoint;
// stloc v(newobj DefaultInterpolatedStringHandler..ctor(ldc.i4 literalLength, ldc.i4 formattedCount)) // stloc v(newobj DefaultInterpolatedStringHandler..ctor(ldc.i4 literalLength, ldc.i4 formattedCount))
if (block.Instructions[pos] is StLoc if (block.Instructions[pos] is StLoc {
{ Variable: ILVariable { Kind: VariableKind.Local } v,
Variable: ILVariable { Kind: VariableKind.Local } v, Value: NewObj { Arguments: { Count: 2 } } newObj
Value: NewObj { Arguments: { Count: 2 } } newObj } stloc
} stloc
&& v.Type.IsKnownType(KnownTypeCode.DefaultInterpolatedStringHandler) && v.Type.IsKnownType(KnownTypeCode.DefaultInterpolatedStringHandler)
&& newObj.Method.DeclaringType.IsKnownType(KnownTypeCode.DefaultInterpolatedStringHandler) && newObj.Method.DeclaringType.IsKnownType(KnownTypeCode.DefaultInterpolatedStringHandler)
&& newObj.Arguments[0].MatchLdcI4(out _) && newObj.Arguments[0].MatchLdcI4(out _)
@ -122,8 +121,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
Debug.Assert(insertionPoint == result.LoadInst.Parent); Debug.Assert(insertionPoint == result.LoadInst.Parent);
} }
return insertionPoint is Call return insertionPoint is Call {
{
Arguments: { Count: 1 }, Arguments: { Count: 1 },
Method: { Name: "ToStringAndClear", IsStatic: false } Method: { Name: "ToStringAndClear", IsStatic: false }
}; };

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

@ -79,11 +79,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms
branch = null; branch = null;
if (block.Instructions.Count != 2) if (block.Instructions.Count != 2)
return false; return false;
if (block.Instructions[0] is not StLoc if (block.Instructions[0] is not StLoc {
{ Variable: { Kind: VariableKind.StackSlot } s,
Variable: { Kind: VariableKind.StackSlot } s, Value: LdcI4 { Value: 0 or 1 } valueInst
Value: LdcI4 { Value: 0 or 1 } valueInst })
})
{ {
return false; return false;
} }

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

@ -389,13 +389,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return false; return false;
return true; return true;
} }
if (condition is MatchInstruction if (condition is MatchInstruction {
{ CheckNotNull: true,
CheckNotNull: true, CheckType: true,
CheckType: true, TestedOperand: LdLoc { Variable: var v },
TestedOperand: LdLoc { Variable: var v }, Variable: var newObjVar
Variable: var newObjVar })
})
{ {
if (v != objVar) if (v != objVar)
return false; return false;

2
TestPlugin/Properties/AssemblyInfo.cs

@ -15,4 +15,4 @@ using System.Runtime.InteropServices;
// This sets the default COM visibility of types in the assembly to invisible. // 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. // If you need to expose a type to COM, use [ComVisible(true)] on that type.
[assembly: ComVisible(false)] [assembly: ComVisible(false)]

Loading…
Cancel
Save