Browse Source

Use 'ref locals' where necessary.

pull/728/merge
Daniel Grunwald 9 years ago
parent
commit
db24116b0b
  1. 2
      ICSharpCode.Decompiler/CSharp/Transforms/CustomPatterns.cs
  2. 6
      ICSharpCode.Decompiler/CSharp/Transforms/DeclareVariables.cs
  3. 21
      ICSharpCode.Decompiler/Tests/RoundtripAssembly.cs
  4. 2
      NRefactory

2
ICSharpCode.Decompiler/CSharp/Transforms/CustomPatterns.cs

@ -40,7 +40,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -40,7 +40,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
{
ComposedType ct = other as ComposedType;
AstType o;
if (ct != null && !ct.HasNullableSpecifier && ct.PointerRank == 0 && !ct.ArraySpecifiers.Any()) {
if (ct != null && !ct.HasRefSpecifier && !ct.HasNullableSpecifier && ct.PointerRank == 0 && !ct.ArraySpecifiers.Any()) {
// Special case: ILSpy sometimes produces a ComposedType but then removed all array specifiers
// from it. In that case, we need to look at the base type for the annotations.
o = ct.BaseType;

6
ICSharpCode.Decompiler/CSharp/Transforms/DeclareVariables.cs

@ -258,7 +258,11 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -258,7 +258,11 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
continue;
var boe = (v.InsertionPoint.nextNode as ExpressionStatement)?.Expression as AssignmentExpression;
if (boe != null && boe.Left.IsMatch(new IdentifierExpression(v.Name))) {
Expression expectedExpr = new IdentifierExpression(v.Name);
if (v.Type.Kind == TypeKind.ByReference) {
expectedExpr = new DirectionExpression(FieldDirection.Ref, expectedExpr);
}
if (boe != null && boe.Left.IsMatch(expectedExpr)) {
AstType type;
if (v.Type.ContainsAnonymousType()) {
type = new SimpleType("var");

21
ICSharpCode.Decompiler/Tests/RoundtripAssembly.cs

@ -24,6 +24,7 @@ using System.Text.RegularExpressions; @@ -24,6 +24,7 @@ using System.Text.RegularExpressions;
using ICSharpCode.Decompiler.CSharp;
using ICSharpCode.Decompiler.Tests.Helpers;
using ICSharpCode.NRefactory.Utils;
using Microsoft.Win32;
using Mono.Cecil;
using NUnit.Framework;
@ -32,7 +33,6 @@ namespace ICSharpCode.Decompiler.Tests @@ -32,7 +33,6 @@ namespace ICSharpCode.Decompiler.Tests
public class RoundtripAssembly
{
static readonly string testDir = Path.GetFullPath("../../../ILSpy-tests");
static readonly string msbuild = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "msbuild", "14.0", "bin", "msbuild.exe");
static readonly string nunit = Path.Combine(testDir, "nunit", "nunit3-console.exe");
[Test]
@ -151,9 +151,26 @@ namespace ICSharpCode.Decompiler.Tests @@ -151,9 +151,26 @@ namespace ICSharpCode.Decompiler.Tests
}
}
static string FindVS2017()
{
using (var key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)) {
using (var subkey = key.OpenSubKey(@"SOFTWARE\Microsoft\VisualStudio\SxS\VS7")) {
return subkey?.GetValue("15.0") as string;
}
}
}
static string FindMSBuild()
{
string vsPath = FindVS2017();
if (vsPath == null)
throw new InvalidOperationException("Could not find VS2017");
return Path.Combine(vsPath, @"MSBuild\15.0\bin\MSBuild.exe");
}
static void Compile(string projectFile, string outputDir)
{
var info = new ProcessStartInfo(msbuild);
var info = new ProcessStartInfo(FindMSBuild());
info.Arguments = $"/nologo /v:minimal /p:OutputPath=\"{outputDir}\" \"{projectFile}\"";
info.CreateNoWindow = true;
info.UseShellExecute = false;

2
NRefactory

@ -1 +1 @@ @@ -1 +1 @@
Subproject commit 2b10193ea20a26ae9c8db21a79c60f3be8d8cca8
Subproject commit 3c638f6c43d77922e4a14c5af1b224e9563236f2
Loading…
Cancel
Save