Skip to content

Commit

Permalink
#2128: Reformat the whole code base.
Browse files Browse the repository at this point in the history
  • Loading branch information
dotnet format authored and siegfriedpammer committed Aug 27, 2020
1 parent ba744b9 commit 0d9f871
Show file tree
Hide file tree
Showing 963 changed files with 37,032 additions and 21,983 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

using Mono.Cecil;
using Mono.Cecil.Pdb;

using SRM = System.Reflection.Metadata;

namespace ICSharpCode.Decompiler.PdbProvider
Expand All @@ -38,11 +39,13 @@ public class MonoCecilDebugInfoProvider : IDebugInfoProvider

public unsafe MonoCecilDebugInfoProvider(PEFile module, string pdbFileName, string description = null)
{
if (module == null) {
if (module == null)
{
throw new ArgumentNullException(nameof(module));
}

if (!module.Reader.IsEntireImageAvailable) {
if (!module.Reader.IsEntireImageAvailable)
{
throw new ArgumentException("This provider needs access to the full image!");
}

Expand All @@ -51,18 +54,22 @@ public unsafe MonoCecilDebugInfoProvider(PEFile module, string pdbFileName, stri
var image = module.Reader.GetEntireImage();
this.debugInfo = new Dictionary<SRM.MethodDefinitionHandle, (IList<SequencePoint> SequencePoints, IList<Variable> Variables)>();
using (UnmanagedMemoryStream stream = new UnmanagedMemoryStream(image.Pointer, image.Length))
using (var moduleDef = ModuleDefinition.ReadModule(stream)) {
using (var moduleDef = ModuleDefinition.ReadModule(stream))
{
moduleDef.ReadSymbols(new PdbReaderProvider().GetSymbolReader(moduleDef, pdbFileName));

foreach (var method in module.Metadata.MethodDefinitions) {
foreach (var method in module.Metadata.MethodDefinitions)
{
var cecilMethod = moduleDef.LookupToken(MetadataTokens.GetToken(method)) as MethodDefinition;
var debugInfo = cecilMethod?.DebugInformation;
if (debugInfo == null)
continue;
IList<SequencePoint> sequencePoints = EmptyList<SequencePoint>.Instance;
if (debugInfo.HasSequencePoints) {
if (debugInfo.HasSequencePoints)
{
sequencePoints = new List<SequencePoint>(debugInfo.SequencePoints.Count);
foreach (var point in debugInfo.SequencePoints) {
foreach (var point in debugInfo.SequencePoints)
{
sequencePoints.Add(new SequencePoint {
Offset = point.Offset,
StartLine = point.StartLine,
Expand All @@ -74,10 +81,12 @@ public unsafe MonoCecilDebugInfoProvider(PEFile module, string pdbFileName, stri
}
}
var variables = new List<Variable>();
foreach (var scope in debugInfo.GetScopes()) {
foreach (var scope in debugInfo.GetScopes())
{
if (!scope.HasVariables)
continue;
foreach (var v in scope.Variables) {
foreach (var v in scope.Variables)
{
variables.Add(new Variable(v.Index, v.Name));
}
}
Expand All @@ -90,7 +99,8 @@ public unsafe MonoCecilDebugInfoProvider(PEFile module, string pdbFileName, stri

public IList<SequencePoint> GetSequencePoints(SRM.MethodDefinitionHandle handle)
{
if (!debugInfo.TryGetValue(handle, out var info)) {
if (!debugInfo.TryGetValue(handle, out var info))
{
return EmptyList<SequencePoint>.Instance;
}

Expand All @@ -99,7 +109,8 @@ public IList<SequencePoint> GetSequencePoints(SRM.MethodDefinitionHandle handle)

public IList<Variable> GetVariables(SRM.MethodDefinitionHandle handle)
{
if (!debugInfo.TryGetValue(handle, out var info)) {
if (!debugInfo.TryGetValue(handle, out var info))
{
return EmptyList<Variable>.Instance;
}

Expand All @@ -109,7 +120,8 @@ public IList<Variable> GetVariables(SRM.MethodDefinitionHandle handle)
public bool TryGetName(SRM.MethodDefinitionHandle handle, int index, out string name)
{
name = null;
if (!debugInfo.TryGetValue(handle, out var info)) {
if (!debugInfo.TryGetValue(handle, out var info))
{
return false;
}

Expand Down
50 changes: 34 additions & 16 deletions ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;

using ICSharpCode.Decompiler.Tests.Helpers;

using NUnit.Framework;

namespace ICSharpCode.Decompiler.Tests
Expand All @@ -38,7 +40,8 @@ public void AllFilesHaveTests()
.Where(m => m.GetCustomAttributes(typeof(TestAttribute), false).Any())
.Select(m => m.Name)
.ToArray();
foreach (var file in new DirectoryInfo(TestCasePath).EnumerateFiles()) {
foreach (var file in new DirectoryInfo(TestCasePath).EnumerateFiles())
{
if (file.Extension == ".txt" || file.Extension == ".exe" || file.Extension == ".config")
continue;
var testName = Path.GetFileNameWithoutExtension(file.Name);
Expand Down Expand Up @@ -213,7 +216,8 @@ public void BitNot([Values(false, true)] bool force32Bit)
{
CompilerOptions compiler = CompilerOptions.UseDebug;
AssemblerOptions asm = AssemblerOptions.None;
if (force32Bit) {
if (force32Bit)
{
compiler |= CompilerOptions.Force32Bit;
asm |= AssemblerOptions.Force32Bit;
}
Expand All @@ -237,7 +241,8 @@ public void StackTypes([Values(false, true)] bool force32Bit)
{
CompilerOptions compiler = CompilerOptions.UseRoslyn | CompilerOptions.UseDebug;
AssemblerOptions asm = AssemblerOptions.None;
if (force32Bit) {
if (force32Bit)
{
compiler |= CompilerOptions.Force32Bit;
asm |= AssemblerOptions.Force32Bit;
}
Expand All @@ -247,7 +252,8 @@ public void StackTypes([Values(false, true)] bool force32Bit)
[Test]
public void UnsafeCode([ValueSource("defaultOptions")] CompilerOptions options)
{
if (options.HasFlag(CompilerOptions.UseMcs)) {
if (options.HasFlag(CompilerOptions.UseMcs))
{
Assert.Ignore("Decompiler bug with mono!");
}
RunCS(options: options);
Expand All @@ -274,7 +280,8 @@ public void Capturing([ValueSource("defaultOptions")] CompilerOptions options)
[Test]
public void YieldReturn([ValueSource("defaultOptions")] CompilerOptions options)
{
if (options.HasFlag(CompilerOptions.UseMcs)) {
if (options.HasFlag(CompilerOptions.UseMcs))
{
Assert.Ignore("Decompiler bug with mono!");
}
RunCS(options: options);
Expand All @@ -301,7 +308,8 @@ public void StringConcat([ValueSource("defaultOptions")] CompilerOptions options
[Test]
public void MiniJSON([ValueSource("defaultOptions")] CompilerOptions options)
{
if (options.HasFlag(CompilerOptions.UseMcs)) {
if (options.HasFlag(CompilerOptions.UseMcs))
{
Assert.Ignore("Decompiler bug with mono!");
}
RunCS(options: options);
Expand All @@ -313,11 +321,13 @@ void RunCS([CallerMemberName] string testName = null, CompilerOptions options =
string testOutputFileName = testName + Tester.GetSuffix(options) + ".exe";
CompilerResults outputFile = null, decompiledOutputFile = null;

try {
try
{
outputFile = Tester.CompileCSharp(Path.Combine(TestCasePath, testFileName), options,
outputFileName: Path.Combine(TestCasePath, testOutputFileName));
string decompiledCodeFile = Tester.DecompileCSharp(outputFile.PathToAssembly, Tester.GetSettings(options));
if (forceRoslynRecompile || options.HasFlag(CompilerOptions.UseMcs)) {
if (forceRoslynRecompile || options.HasFlag(CompilerOptions.UseMcs))
{
// For second pass, use roslyn instead of mcs.
// mcs has some compiler bugs that cause it to not accept ILSpy-generated code,
// for example when there's unreachable code due to other compiler bugs in the first mcs run.
Expand All @@ -332,12 +342,14 @@ void RunCS([CallerMemberName] string testName = null, CompilerOptions options =
</configuration>");
}
decompiledOutputFile = Tester.CompileCSharp(decompiledCodeFile, options);

Tester.RunAndCompareOutput(testFileName, outputFile.PathToAssembly, decompiledOutputFile.PathToAssembly, decompiledCodeFile);

Tester.RepeatOnIOError(() => File.Delete(decompiledCodeFile));
Tester.RepeatOnIOError(() => File.Delete(decompiledOutputFile.PathToAssembly));
} finally {
}
finally
{
if (outputFile != null)
outputFile.TempFiles.Delete();
if (decompiledOutputFile != null)
Expand All @@ -352,7 +364,8 @@ void RunVB([CallerMemberName] string testName = null, CompilerOptions options =
string testOutputFileName = testName + Tester.GetSuffix(options) + ".exe";
CompilerResults outputFile = null, decompiledOutputFile = null;

try {
try
{
outputFile = Tester.CompileVB(Path.Combine(TestCasePath, testFileName), options,
outputFileName: Path.Combine(TestCasePath, testOutputFileName));
string decompiledCodeFile = Tester.DecompileCSharp(outputFile.PathToAssembly, Tester.GetSettings(options));
Expand All @@ -362,7 +375,9 @@ void RunVB([CallerMemberName] string testName = null, CompilerOptions options =

Tester.RepeatOnIOError(() => File.Delete(decompiledCodeFile));
Tester.RepeatOnIOError(() => File.Delete(decompiledOutputFile.PathToAssembly));
} finally {
}
finally
{
if (outputFile != null)
outputFile.TempFiles.Delete();
if (decompiledOutputFile != null)
Expand All @@ -375,16 +390,19 @@ void RunIL(string testFileName, CompilerOptions options = CompilerOptions.UseDeb
string outputFile = null;
CompilerResults decompiledOutputFile = null;

try {
try
{
outputFile = Tester.AssembleIL(Path.Combine(TestCasePath, testFileName), asmOptions);
string decompiledCodeFile = Tester.DecompileCSharp(outputFile, Tester.GetSettings(options));
decompiledOutputFile = Tester.CompileCSharp(decompiledCodeFile, options);

Tester.RunAndCompareOutput(testFileName, outputFile, decompiledOutputFile.PathToAssembly, decompiledCodeFile);

Tester.RepeatOnIOError(() => File.Delete(decompiledCodeFile));
Tester.RepeatOnIOError(() => File.Delete(decompiledOutputFile.PathToAssembly));
} finally {
}
finally
{
if (decompiledOutputFile != null)
decompiledOutputFile.TempFiles.Delete();
}
Expand Down
2 changes: 2 additions & 0 deletions ICSharpCode.Decompiler.Tests/DataFlowTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;

using ICSharpCode.Decompiler.FlowAnalysis;
using ICSharpCode.Decompiler.IL;
using ICSharpCode.Decompiler.TypeSystem;

using NUnit.Framework;

namespace ICSharpCode.Decompiler.Tests
Expand Down
8 changes: 6 additions & 2 deletions ICSharpCode.Decompiler.Tests/DisassemblerPrettyTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

using ICSharpCode.Decompiler.Tests.Helpers;

using NUnit.Framework;

namespace ICSharpCode.Decompiler.Tests
Expand All @@ -40,8 +42,10 @@ public void AllFilesHaveTests()
.Where(m => m.GetCustomAttributes(typeof(TestAttribute), false).Any())
.Select(m => m.Name)
.ToArray();
foreach (var file in new DirectoryInfo(TestCasePath).EnumerateFiles()) {
if (file.Extension.Equals(".il", StringComparison.OrdinalIgnoreCase)) {
foreach (var file in new DirectoryInfo(TestCasePath).EnumerateFiles())
{
if (file.Extension.Equals(".il", StringComparison.OrdinalIgnoreCase))
{
var testName = file.Name.Split('.')[0];
Assert.Contains(testName, testNames);
}
Expand Down
Loading

0 comments on commit 0d9f871

Please sign in to comment.