Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

Commit

Permalink
Updated NRefactory and use IKVM instead of Cecil
Browse files Browse the repository at this point in the history
  • Loading branch information
erik-kallen committed Jul 4, 2013
1 parent 728a8c9 commit d25c8c6
Show file tree
Hide file tree
Showing 28 changed files with 162 additions and 123 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "Compiler/NRefactory"]
path = Compiler/NRefactory
url = git://github.com/erik-kallen/NRefactory.git
[submodule "Compiler/cecil"]
path = Compiler/cecil
url = git://github.com/jbevain/cecil.git
[submodule "Compiler/ikvm"]
path = Compiler/ikvm
url = git://github.com/erik-kallen/ikvm-fork.git
25 changes: 16 additions & 9 deletions Compiler/Compiler.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.NRefactory", "N
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.NRefactory.CSharp", "NRefactory\ICSharpCode.NRefactory.CSharp\ICSharpCode.NRefactory.CSharp.csproj", "{53DCA265-3C3C-42F9-B647-F72BA678122B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil", "cecil\Mono.Cecil.csproj", "{D68133BD-1E63-496E-9EDE-4FBDBF77B486}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SCExe", "SCExe\SCExe.csproj", "{6799A75C-6F0A-41DA-AA45-6A67587AB6C7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Mono.Cecil", "Mono.Cecil", "{88DA9D99-0FF8-4AC6-BE9D-9216B42571E7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SCTask", "SCTask\SCTask.csproj", "{7CE9DA6A-BFCC-4C98-84D3-7939D920FBC7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{ACDA69C3-9C2E-4122-80E2-C39FEF18316E}"
Expand All @@ -36,6 +32,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SCTaskWorker", "SCTaskWorke
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SCExeWorker", "SCExeWorker\SCExeWorker.csproj", "{7DFB28EE-5FDE-40E1-9E60-465B6C034F8F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.NRefactory.IKVM", "NRefactory\ICSharpCode.NRefactory.IKVM\ICSharpCode.NRefactory.IKVM.csproj", "{A727169F-D94F-443F-B305-B057D7F3B420}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "IKVM", "IKVM", "{E21C32AA-F8FD-46A6-8BA6-530CECF09048}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IKVM.Reflection", "ikvm\reflect\IKVM.Reflection.csproj", "{4CB170EF-DFE6-4A56-9E1B-A85449E827A7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -62,10 +64,6 @@ Global
{53DCA265-3C3C-42F9-B647-F72BA678122B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{53DCA265-3C3C-42F9-B647-F72BA678122B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{53DCA265-3C3C-42F9-B647-F72BA678122B}.Release|Any CPU.Build.0 = Release|Any CPU
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Debug|Any CPU.ActiveCfg = net_4_0_Debug|Any CPU
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Debug|Any CPU.Build.0 = net_4_0_Debug|Any CPU
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Release|Any CPU.ActiveCfg = net_4_0_Release|Any CPU
{D68133BD-1E63-496E-9EDE-4FBDBF77B486}.Release|Any CPU.Build.0 = net_4_0_Release|Any CPU
{6799A75C-6F0A-41DA-AA45-6A67587AB6C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6799A75C-6F0A-41DA-AA45-6A67587AB6C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6799A75C-6F0A-41DA-AA45-6A67587AB6C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -86,13 +84,22 @@ Global
{7DFB28EE-5FDE-40E1-9E60-465B6C034F8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7DFB28EE-5FDE-40E1-9E60-465B6C034F8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7DFB28EE-5FDE-40E1-9E60-465B6C034F8F}.Release|Any CPU.Build.0 = Release|Any CPU
{A727169F-D94F-443F-B305-B057D7F3B420}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A727169F-D94F-443F-B305-B057D7F3B420}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A727169F-D94F-443F-B305-B057D7F3B420}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A727169F-D94F-443F-B305-B057D7F3B420}.Release|Any CPU.Build.0 = Release|Any CPU
{4CB170EF-DFE6-4A56-9E1B-A85449E827A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4CB170EF-DFE6-4A56-9E1B-A85449E827A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4CB170EF-DFE6-4A56-9E1B-A85449E827A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4CB170EF-DFE6-4A56-9E1B-A85449E827A7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{3B2A5653-EC97-4001-BB9B-D90F1AF2C371} = {73B31ACF-DFF5-4A3A-A4FC-B89090737EDA}
{53DCA265-3C3C-42F9-B647-F72BA678122B} = {73B31ACF-DFF5-4A3A-A4FC-B89090737EDA}
{D68133BD-1E63-496E-9EDE-4FBDBF77B486} = {88DA9D99-0FF8-4AC6-BE9D-9216B42571E7}
{A727169F-D94F-443F-B305-B057D7F3B420} = {73B31ACF-DFF5-4A3A-A4FC-B89090737EDA}
{4CB170EF-DFE6-4A56-9E1B-A85449E827A7} = {E21C32AA-F8FD-46A6-8BA6-530CECF09048}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion Compiler/NRefactory
Submodule NRefactory updated 474 files
10 changes: 8 additions & 2 deletions Compiler/Saltarelle.Compiler.Tests/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@
using Moq;

namespace Saltarelle.Compiler.Tests {
internal class Common {
internal static class Common {
public static readonly string MscorlibPath = Path.GetFullPath(@"../../../Runtime/CoreLib/bin/mscorlib.dll");

private static readonly Lazy<IAssemblyReference> _mscorlibLazy = new Lazy<IAssemblyReference>(() => new CecilLoader() { IncludeInternalMembers = true }.LoadAssemblyFile(MscorlibPath));
private static readonly Lazy<IAssemblyReference> _mscorlibLazy = new Lazy<IAssemblyReference>(() => LoadAssemblyFile(MscorlibPath));
internal static IAssemblyReference Mscorlib { get { return _mscorlibLazy.Value; } }

public static IAssemblyReference LoadAssemblyFile(string path) {
var l = AssemblyLoader.Create(AssemblyLoaderBackend.IKVM);
l.IncludeInternalMembers = true;
return l.LoadAssemblyFile(path);
}

public static Mock<ITypeDefinition> CreateTypeMock(string fullName) {
int dot = fullName.LastIndexOf(".", StringComparison.InvariantCulture);
string name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
namespace Saltarelle.Compiler.Tests.CompilerTests.MethodCompilation.Expressions {
[TestFixture]
public class ExpressionTreeTests : MethodCompilerTestBase {
private static readonly Lazy<IAssemblyReference> _mscorlibLazy = new Lazy<IAssemblyReference>(() => Common.LoadAssemblyFile(typeof(object).Assembly.Location));

private static readonly Lazy<IUnresolvedAssembly> _expressionAssembly = new Lazy<IUnresolvedAssembly>(() => {
var c = PreparedCompilation.CreateCompilation(new[] { new MockSourceFile("File1.cs", @"
using System.Collections.Generic;
Expand Down Expand Up @@ -266,11 +268,11 @@ public class Expression<T> : Expression {}
public class MemberBinding {}
public class ElementInit {}
}
") }, new[] { new CecilLoader().LoadAssemblyFile(typeof(object).Assembly.Location) }, new string[0]);
") }, new[] { _mscorlibLazy.Value }, new string[0]);
return c.Compilation.MainAssembly.UnresolvedAssembly;
});

private static readonly Lazy<IAssemblyReference[]> _referencesLazy = new Lazy<IAssemblyReference[]>(() => { var l = new CecilLoader(); return new[] { l.LoadAssemblyFile(typeof(object).Assembly.Location), _expressionAssembly.Value }; });
private static readonly Lazy<IAssemblyReference[]> _referencesLazy = new Lazy<IAssemblyReference[]>(() => new[] { _mscorlibLazy.Value, _expressionAssembly.Value });

private void AssertCorrect(string csharp, string expected, IRuntimeLibrary runtimeLibrary = null, IMetadataImporter metadataImporter = null, string methodName = "M") {
base.AssertCorrect("using System; using System.Linq.Expressions; using System.Collections.Generic; class C { " + csharp + "}", expected, references: _referencesLazy.Value, methodName: methodName, metadataImporter: metadataImporter, addSkeleton: false, runtimeLibrary: runtimeLibrary);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Saltarelle.Compiler.Tests.CompilerTests.MethodCompilation.Expressions {
[TestFixture]
public class QueryExpressionTests : MethodCompilerTestBase {
private static readonly Lazy<IAssemblyReference[]> _referencesLazy = new Lazy<IAssemblyReference[]>(() => { var l = new CecilLoader() { IncludeInternalMembers = true }; return new[] { l.LoadAssemblyFile(typeof(object).Assembly.Location), l.LoadAssemblyFile(typeof(Enumerable).Assembly.Location) }; });
private static readonly Lazy<IAssemblyReference[]> _referencesLazy = new Lazy<IAssemblyReference[]>(() => new[] { Common.LoadAssemblyFile(typeof(object).Assembly.Location), Common.LoadAssemblyFile(typeof(Enumerable).Assembly.Location) });

private void AssertCorrect(string csharp, string expected) {
AssertCorrect(@"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void TokenizerCanDetectTypeTypeParameters() {
var method = FindClass("C").CSharpTypeDefinition.Methods.Single(m => m.Name == "F");

Assert.That(InlineCodeMethodCompiler.Tokenize(method, "{T1}{T2}", s => Assert.Fail("Unexpected error " + s)),
Is.EqualTo(new[] { new InlineCodeToken(InlineCodeToken.TokenType.TypeParameter, index: 0, ownerType: EntityType.TypeDefinition), new InlineCodeToken(InlineCodeToken.TokenType.TypeParameter, index: 1, ownerType: EntityType.TypeDefinition) }));
Is.EqualTo(new[] { new InlineCodeToken(InlineCodeToken.TokenType.TypeParameter, index: 0, ownerType: SymbolKind.TypeDefinition), new InlineCodeToken(InlineCodeToken.TokenType.TypeParameter, index: 1, ownerType: SymbolKind.TypeDefinition) }));
}

[Test]
Expand All @@ -111,7 +111,7 @@ public void TokenizerCanDetectMethodTypeParameters() {
var method = FindClass("C").CSharpTypeDefinition.Methods.Single(m => m.Name == "F");

Assert.That(InlineCodeMethodCompiler.Tokenize(method, "{T1}{T2}", s => Assert.Fail("Unexpected error " + s)),
Is.EqualTo(new[] { new InlineCodeToken(InlineCodeToken.TokenType.TypeParameter, index: 0, ownerType: EntityType.Method), new InlineCodeToken(InlineCodeToken.TokenType.TypeParameter, index: 1, ownerType: EntityType.Method) }));
Is.EqualTo(new[] { new InlineCodeToken(InlineCodeToken.TokenType.TypeParameter, index: 0, ownerType: SymbolKind.Method), new InlineCodeToken(InlineCodeToken.TokenType.TypeParameter, index: 1, ownerType: SymbolKind.Method) }));
}

[Test]
Expand All @@ -120,7 +120,7 @@ public void TokenizerCanDetectTypeParameterNamePreceededByAtSign() {
var method = FindClass("C").CSharpTypeDefinition.Methods.Single(m => m.Name == "F");

Assert.That(InlineCodeMethodCompiler.Tokenize(method, "{T1}{T2}", s => Assert.Fail("Unexpected error " + s)),
Is.EqualTo(new[] { new InlineCodeToken(InlineCodeToken.TokenType.TypeParameter, index: 0, ownerType: EntityType.TypeDefinition), new InlineCodeToken(InlineCodeToken.TokenType.TypeParameter, index: 0, ownerType: EntityType.Method) }));
Is.EqualTo(new[] { new InlineCodeToken(InlineCodeToken.TokenType.TypeParameter, index: 0, ownerType: SymbolKind.TypeDefinition), new InlineCodeToken(InlineCodeToken.TokenType.TypeParameter, index: 0, ownerType: SymbolKind.Method) }));
}

[Test]
Expand Down
76 changes: 46 additions & 30 deletions Compiler/Saltarelle.Compiler.Tests/DriverTests/DriverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using ICSharpCode.NRefactory;
using Mono.Cecil;
using IKVM.Reflection;
using NUnit.Framework;
using Saltarelle.Compiler.Driver;
using System.Xml.XPath;

namespace Saltarelle.Compiler.Tests.DriverTests {
[TestFixture]
public class DriverTests {
private void UsingFiles(Action a, params string[] files) {
private static void UsingAssembly(string path, Action<Assembly> action) {
using (var universe = new Universe()) {
action(universe.LoadFile(path));
}
}

private static void UsingFiles(Action a, params string[] files) {
try {
foreach (var f in files) {
var fn = Path.GetFullPath(f);
Expand Down Expand Up @@ -581,8 +586,9 @@ public void TheAssemblyNameIsCorrect() {
string doc = File.ReadAllText(Path.GetFullPath("Test.xml"));
Assert.That(XDocument.Parse(doc).XPathSelectElement("/doc/assembly/name").Value, Is.EqualTo("MyOutputAssembly"));
var asm = AssemblyDefinition.ReadAssembly(Path.GetFullPath("MyOutputAssembly.dll"));
Assert.That(asm.Name.Name, Is.EqualTo("MyOutputAssembly"));
UsingAssembly(Path.GetFullPath("MyOutputAssembly.dll"), asm => {
Assert.That(asm.GetName().Name, Is.EqualTo("MyOutputAssembly"));
});
}, "File.cs", "MyOutputAssembly.dll", "Test.js", "Test.xml");
}

Expand All @@ -603,8 +609,9 @@ public void TheOutputFileNamesAreTakenFromTheFirstSourceFileIfNotSpecified() {
Assert.That(File.Exists(Path.GetFullPath("FirstFile.dll")), Is.True);
Assert.That(File.Exists(Path.GetFullPath("FirstFile.js")), Is.True);
var asm = AssemblyDefinition.ReadAssembly(Path.GetFullPath("FirstFile.dll"));
Assert.That(asm.Name.Name, Is.EqualTo("FirstFile"));
UsingAssembly(Path.GetFullPath("FirstFile.dll"), asm => {
Assert.That(asm.GetName().Name, Is.EqualTo("FirstFile"));
});
}, "FirstFile.cs", "SecondFile.cs", "FirstFile.dll", "FirstFile.js");
}

Expand Down Expand Up @@ -944,8 +951,9 @@ public void SigningWorks() {
Assert.That(result, Is.True);
Assert.That(er.AllMessages, Is.Empty);
var asm = AssemblyDefinition.ReadAssembly("File.dll");
Assert.That(asm.Name.PublicKeyToken, Is.EqualTo(new[] { 0xf5, 0xa5, 0x6d, 0x86, 0x8e, 0xa6, 0xbd, 0x2e }));
UsingAssembly("File.dll", asm => {
Assert.That(asm.GetName().GetPublicKeyToken(), Is.EqualTo(new[] { 0xf5, 0xa5, 0x6d, 0x86, 0x8e, 0xa6, 0xbd, 0x2e }));
});
}, "Key.snk", "File.cs", "File.dll", "File.js");
}

Expand Down Expand Up @@ -1020,14 +1028,16 @@ public void @double(int x) {}
Assert.That(result, Is.True);
Assert.That(File.Exists(Path.GetFullPath("Test.dll")), Is.True, "Assembly should be written");
Assert.That(File.Exists(Path.GetFullPath("Test.js")), Is.True, "Script should be written");
var asm = AssemblyDefinition.ReadAssembly(Path.GetFullPath("Test.dll"));
Assert.That(asm.MainModule.Types.Any(t => t.Name == "char"));
Assert.That(asm.MainModule.Types.Any(t => t.FullName == "string.float.for"));
var c = asm.MainModule.Types.Single(t => t.Name == "C");
Assert.That(c.Properties.Any(p => p.Name == "int"));
Assert.That(c.Fields.Any(p => p.Name == "short"));
Assert.That(c.Methods.Any(p => p.Name == "double"));
Assert.That(c.Events.Any(p => p.Name == "if"));
UsingAssembly(Path.GetFullPath("Test.dll"), asm => {
var types = asm.GetTypes();
Assert.That(types.Any(t => t.Name == "char"));
Assert.That(types.Any(t => t.FullName == "string.float.for"));
var c = types.Single(t => t.Name == "C");
Assert.That(c.GetProperties().Any(p => p.Name == "int"));
Assert.That(c.GetFields().Any(p => p.Name == "short"));
Assert.That(c.GetMethods().Any(p => p.Name == "double"));
Assert.That(c.GetEvents().Any(p => p.Name == "if"));
});
}, "File1.cs", "Test.dll", "Test.js");
}

Expand Down Expand Up @@ -1069,19 +1079,25 @@ public void CanEmbedResources() {
var result = driver.Compile(options);
Assert.That(result, Is.True, "Compilation failed with " + string.Join(Environment.NewLine, er.AllMessages.Select(m => m.FormattedMessage)));
var asm = AssemblyDefinition.ReadAssembly("Test.dll");
var res1 = asm.MainModule.Resources.SingleOrDefault(r => r.Name == "The.Resource.Name") as Mono.Cecil.EmbeddedResource;
Assert.That(res1, Is.Not.Null, "Resource 1 not found");
Assert.That(res1.GetResourceData(), Is.EqualTo(publicContent));
Assert.That(res1.IsPublic, Is.True);
Assert.That(res1.IsPrivate, Is.False);
var res2 = asm.MainModule.Resources.SingleOrDefault(r => r.Name == "Secret.Name") as Mono.Cecil.EmbeddedResource;
Assert.That(res2, Is.Not.Null, "Resource 2 not found");
Assert.That(res2.GetResourceData(), Is.EqualTo(privateContent));
Assert.That(res2.IsPublic, Is.False);
Assert.That(res2.IsPrivate, Is.True);
UsingAssembly("Test.dll", asm => {
using (var res1 = asm.GetManifestResourceStream("The.Resource.Name")) {
Assert.That(res1, Is.Not.Null, "Resource 1 not found");
using (var ms = new MemoryStream()) {
res1.CopyTo(ms);
Assert.That(ms.ToArray(), Is.EqualTo(publicContent));
}
}
Assert.That(asm.GetManifestResourceInfo("The.Resource.Name").__ResourceAttributes, Is.EqualTo(ResourceAttributes.Public));
using (var res2 = asm.GetManifestResourceStream("Secret.Name")) {
Assert.That(res2, Is.Not.Null, "Resource 2 not found");
using (var ms = new MemoryStream()) {
res2.CopyTo(ms);
Assert.That(ms.ToArray(), Is.EqualTo(privateContent));
}
}
Assert.That(asm.GetManifestResourceInfo("Secret.Name").__ResourceAttributes, Is.EqualTo(ResourceAttributes.Private));
});
}, "File1.cs", "PublicResource.txt", "PrivateResource.txt", "Test.dll", "Test.js");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Text;
using System.Xml;
using System.Xml.Linq;
using Mono.Cecil;
using NUnit.Framework;
using System.Xml.XPath;
using Saltarelle.Compiler.Driver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ikvm\reflect\IKVM.Reflection.csproj">
<Project>{4cb170ef-dfe6-4a56-9e1b-a85449e827a7}</Project>
<Name>IKVM.Reflection</Name>
</ProjectReference>
<ProjectReference Include="..\JavaScriptParser\JavaScriptParser.csproj">
<Project>{819223CA-D211-44C2-BC01-A2B955D4CA61}</Project>
<Name>JavaScriptParser</Name>
Expand All @@ -167,10 +171,6 @@
<Project>{C84DF308-9EBF-4521-9CA2-5C531F4B245A}</Project>
<Name>JSModel</Name>
</ProjectReference>
<ProjectReference Include="..\cecil\Mono.Cecil.csproj">
<Project>{D68133BD-1E63-496E-9EDE-4FBDBF77B486}</Project>
<Name>Mono.Cecil %28Mono.Cecil\Mono.Cecil%29</Name>
</ProjectReference>
<ProjectReference Include="..\NRefactory\ICSharpCode.NRefactory.CSharp\ICSharpCode.NRefactory.CSharp.csproj">
<Project>{53DCA265-3C3C-42F9-B647-F72BA678122B}</Project>
<Name>ICSharpCode.NRefactory.CSharp</Name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ public override void VisitNamedExpression(NamedExpression namedExpression) {
HandleExpressionNode(namedExpression);
}

public override void VisitEmptyExpression(EmptyExpression emptyExpression) {
HandleExpressionNode(emptyExpression);
}

public override void VisitIsExpression(IsExpression isExpression) {
HandleExpressionNode(isExpression);
}
Expand Down
Loading

0 comments on commit d25c8c6

Please sign in to comment.