Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename and refactor for XamlX structure and layering. #11

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 34 additions & 25 deletions XamlX.sln
Original file line number Diff line number Diff line change
@@ -1,46 +1,39 @@


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29411.108
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{4191DEF4-DBC9-4185-A1A6-11E80A7A9B34}"
ProjectSection(SolutionItems) = preProject
README.md = README.md
EndProjectSection
ProjectSection(SolutionItems) = preProject
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XamlX", "src\XamlX\XamlX.csproj", "{3986513F-FAE6-4DA6-9221-51837AFC9B3C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XamlX", "src\XamlX\XamlX.csproj", "{3986513F-FAE6-4DA6-9221-51837AFC9B3C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{55203DEB-3DB3-4907-8275-7FBE48185148}"
ProjectSection(SolutionItems) = preProject
tests\Tests.Common.props = tests\Tests.Common.props
EndProjectSection
ProjectSection(SolutionItems) = preProject
tests\Tests.Common.props = tests\Tests.Common.props
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XamlParserTests", "tests\XamlParserTests\XamlParserTests.csproj", "{6512A859-F453-4388-9DAA-9B0C3E62956E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XamlParserTests", "tests\XamlParserTests\XamlParserTests.csproj", "{6512A859-F453-4388-9DAA-9B0C3E62956E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmarks", "src\Benchmarks\Benchmarks.csproj", "{F1C1F27D-20E5-4097-8647-0BDD74CC11FB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmarks", "src\Benchmarks\Benchmarks.csproj", "{F1C1F27D-20E5-4097-8647-0BDD74CC11FB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XamlX.Runtime", "src\XamlX.Runtime\XamlX.Runtime.csproj", "{E232146D-783D-4927-AB4D-26569AE50F78}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XamlX.Runtime", "src\XamlX.Runtime\XamlX.Runtime.csproj", "{E232146D-783D-4927-AB4D-26569AE50F78}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XamlX.Cecil", "src\XamlX.Cecil\XamlX.Cecil.csproj", "{655CC2E8-C076-4DE8-8671-B7C7792DF7A3}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XamlX.IL.Cecil", "src\XamlX.IL.Cecil\XamlX.IL.Cecil.csproj", "{655CC2E8-C076-4DE8-8671-B7C7792DF7A3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CecilTests", "tests\CecilTests\CecilTests.csproj", "{20135939-0E5C-4906-9097-67F13945D042}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CecilTests", "tests\CecilTests\CecilTests.csproj", "{20135939-0E5C-4906-9097-67F13945D042}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CecilNetstandardTests", "tests\CecilNetstandardTests\CecilNetstandardTests.csproj", "{E7E2584A-1406-4B7A-9ADA-430C1FC9AEAE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CecilNetstandardTests", "tests\CecilNetstandardTests\CecilNetstandardTests.csproj", "{E7E2584A-1406-4B7A-9ADA-430C1FC9AEAE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BenchmarksCompiler", "src\BenchmarksCompiler\BenchmarksCompiler.csproj", "{0DC5F69A-C150-4590-90D7-303B9654011C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BenchmarksCompiler", "src\BenchmarksCompiler\BenchmarksCompiler.csproj", "{0DC5F69A-C150-4590-90D7-303B9654011C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{3986513F-FAE6-4DA6-9221-51837AFC9B3C} = {4191DEF4-DBC9-4185-A1A6-11E80A7A9B34}
{6512A859-F453-4388-9DAA-9B0C3E62956E} = {55203DEB-3DB3-4907-8275-7FBE48185148}
{F1C1F27D-20E5-4097-8647-0BDD74CC11FB} = {4191DEF4-DBC9-4185-A1A6-11E80A7A9B34}
{E232146D-783D-4927-AB4D-26569AE50F78} = {4191DEF4-DBC9-4185-A1A6-11E80A7A9B34}
{655CC2E8-C076-4DE8-8671-B7C7792DF7A3} = {4191DEF4-DBC9-4185-A1A6-11E80A7A9B34}
{20135939-0E5C-4906-9097-67F13945D042} = {55203DEB-3DB3-4907-8275-7FBE48185148}
{E7E2584A-1406-4B7A-9ADA-430C1FC9AEAE} = {55203DEB-3DB3-4907-8275-7FBE48185148}
{0DC5F69A-C150-4590-90D7-303B9654011C} = {4191DEF4-DBC9-4185-A1A6-11E80A7A9B34}
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3986513F-FAE6-4DA6-9221-51837AFC9B3C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3986513F-FAE6-4DA6-9221-51837AFC9B3C}.Debug|Any CPU.Build.0 = Debug|Any CPU
Expand Down Expand Up @@ -75,4 +68,20 @@ Global
{0DC5F69A-C150-4590-90D7-303B9654011C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0DC5F69A-C150-4590-90D7-303B9654011C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{3986513F-FAE6-4DA6-9221-51837AFC9B3C} = {4191DEF4-DBC9-4185-A1A6-11E80A7A9B34}
{6512A859-F453-4388-9DAA-9B0C3E62956E} = {55203DEB-3DB3-4907-8275-7FBE48185148}
{F1C1F27D-20E5-4097-8647-0BDD74CC11FB} = {4191DEF4-DBC9-4185-A1A6-11E80A7A9B34}
{E232146D-783D-4927-AB4D-26569AE50F78} = {4191DEF4-DBC9-4185-A1A6-11E80A7A9B34}
{655CC2E8-C076-4DE8-8671-B7C7792DF7A3} = {4191DEF4-DBC9-4185-A1A6-11E80A7A9B34}
{20135939-0E5C-4906-9097-67F13945D042} = {55203DEB-3DB3-4907-8275-7FBE48185148}
{E7E2584A-1406-4B7A-9ADA-430C1FC9AEAE} = {55203DEB-3DB3-4907-8275-7FBE48185148}
{0DC5F69A-C150-4590-90D7-303B9654011C} = {4191DEF4-DBC9-4185-A1A6-11E80A7A9B34}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B701ADE9-89EA-4C9D-BB51-0AA4E8E07217}
EndGlobalSection
EndGlobal
19 changes: 12 additions & 7 deletions src/Benchmarks/BenchCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using System.Reflection;
using System.Reflection.Emit;
using XamlX.Ast;
using XamlX.Emit;
using XamlX.IL;
using XamlX.Parsers;
using XamlX.Runtime;
using XamlX.Transform;
Expand All @@ -33,18 +35,21 @@ public static Func<IServiceProvider, object> Compile(string xaml)
foreach (var p in xt.GetProperties())
p.GetCustomAttributes();
}
typeof(IXamlXParentStackProviderV1).Assembly.GetCustomAttributes();
typeof(IXamlParentStackProviderV1).Assembly.GetCustomAttributes();


var typeSystem = new SreTypeSystem();
var configuration = BenchmarksXamlXConfiguration.Configure(typeSystem);
var parsed = XDocumentXamlXParser.Parse(xaml);

var compiler = new XamlXCompiler(configuration, true);
var configuration = BenchmarksXamlConfiguration.Configure(typeSystem);
var parsed = XDocumentXamlParser.Parse(xaml);

var compiler = new XamlILCompiler(
configuration,
new XamlLanguageEmitMappings<IXamlILEmitter, XamlILNodeEmitResult>(),
true);
compiler.Transform(parsed);


var parsedTsType = ((IXamlXAstValueNode) parsed.Root).Type.GetClrType();
var parsedTsType = ((IXamlAstValueNode) parsed.Root).Type.GetClrType();

#if !NETCOREAPP
var path = Path.GetDirectoryName(typeof(BenchCompiler).Assembly.GetModules()[0].FullyQualifiedName);
Expand All @@ -63,7 +68,7 @@ public static Func<IServiceProvider, object> Compile(string xaml)

var parserTypeBuilder = ((SreTypeSystem) typeSystem).CreateTypeBuilder(t);
compiler.Compile(parsed, parserTypeBuilder, contextTypeDef, "Populate", "Build",
"XamlXNamespaceInfo", "https://github.com/kekekeks/XamlX", null);
"XamlNamespaceInfo", "https://github.com/kekekeks/Xaml", null);

var created = t.CreateType();

Expand Down
2 changes: 1 addition & 1 deletion src/Benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

namespace Benchmarks
{
class BenchmarksXamlXConfiguration
class BenchmarksXamlConfiguration
{
public static XamlXTransformerConfiguration Configure(IXamlXTypeSystem typeSystem)
public static TransformerConfiguration Configure(IXamlTypeSystem typeSystem)
{
return new XamlXTransformerConfiguration(typeSystem,
return new TransformerConfiguration(typeSystem,
typeSystem.FindAssembly("Benchmarks"),
new XamlXLanguageTypeMappings(typeSystem)
new XamlLanguageTypeMappings(typeSystem)
{
XmlnsAttributes =
{
Expand All @@ -20,7 +20,7 @@ public static XamlXTransformerConfiguration Configure(IXamlXTypeSystem typeSyste
typeSystem.GetType("Benchmarks.ContentAttribute")
},
RootObjectProvider = typeSystem.GetType("Portable.Xaml.IRootObjectProvider"),
ParentStackProvider = typeSystem.GetType("XamlX.Runtime.IXamlXParentStackProviderV1")
ParentStackProvider = typeSystem.GetType("XamlX.Runtime.IXamlParentStackProviderV1")
});
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Benchmarks/LoadBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using BenchmarkDotNet.Attributes;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -49,22 +49,22 @@ public void SystemXamlNoCache()
*/
private Func<IServiceProvider, object> _compiled;
[Benchmark]
public void XamlX()
public void Xaml()
{
_compiled = _compiled ?? BenchCompiler.Compile(new StreamReader(GetStream()).ReadToEnd());
_compiled(null);
}

public virtual object LoadXamlXPrecompiled(IServiceProvider sp)
public virtual object LoadXamlPrecompiled(IServiceProvider sp)
{
// This method will be overridden by Cecil
throw new NotImplementedException();
}

[Benchmark]
public void XamlXPrecompiled()
public void XamlPrecompiled()
{
LoadXamlXPrecompiled(null);
LoadXamlPrecompiled(null);
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/Benchmarks/LoadComplexBenchmark.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<TestObject xmlns="http://example.com/benchmark" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
<TestObject xmlns="http://example.com/benchmark" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StringProperty="Hello!"
>
<ChildObject StringProperty="Hello" IntProperty="2" DoubleProperty="123.456" BoolProperty="True" />
Expand Down
2 changes: 1 addition & 1 deletion src/Benchmarks/LoadSimpleBenchmark.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<TestObject xmlns="http://example.com/benchmark" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
<TestObject xmlns="http://example.com/benchmark" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StringProperty="Hello!"
>
</TestObject>
6 changes: 3 additions & 3 deletions src/Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
Expand All @@ -21,10 +21,10 @@ public static void Main(string[] args)
{
//var benchmark = new LoadSimpleBenchmark();
var benchmark = new LoadComplexBenchmark();
benchmark.XamlXPrecompiled();
benchmark.XamlPrecompiled();
for (int i = 0; i < 1000; i++)
{
benchmark.XamlXPrecompiled();
benchmark.XamlPrecompiled();
}
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/BenchmarksCompiler/BenchmarksCompiler.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\XamlX.Cecil\XamlX.Cecil.csproj" />
<Compile Include="..\Benchmarks\BenchmarksXamlXConfiguration.cs"/>
<ProjectReference Include="..\XamlX.IL.Cecil\XamlX.IL.Cecil.csproj" />
<Compile Include="..\Benchmarks\BenchmarksXamlConfiguration.cs"/>
</ItemGroup>

</Project>
28 changes: 18 additions & 10 deletions src/BenchmarksCompiler/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Cecil.Rocks;
using XamlX.Emit;
using XamlX.IL;
using XamlX.Transform;
using XamlX.TypeSystem;

Expand All @@ -20,14 +22,20 @@ static void Main(string[] args)
var refs = File.ReadAllLines(refsPath).Concat(new[] {target});
var typeSystem = new CecilTypeSystem(refs, target);
var asm = typeSystem.GetAssembly(typeSystem.FindAssembly("Benchmarks"));
var config = Benchmarks.BenchmarksXamlXConfiguration.Configure(typeSystem);
var config = Benchmarks.BenchmarksXamlConfiguration.Configure(typeSystem);
var loadBench = asm.MainModule.Types.First(t => t.Name == "LoadBenchmark");
var baseMethod = loadBench.Methods.First(m => m.Name == "LoadXamlXPrecompiled");
var baseMethod = loadBench.Methods.First(m => m.Name == "LoadXamlPrecompiled");

var ct = new TypeDefinition("_XamlXRuntime", "XamlXContext", TypeAttributes.Class,
var ct = new TypeDefinition("_XamlRuntime", "XamlContext", TypeAttributes.Class,
asm.MainModule.TypeSystem.Object);

asm.MainModule.Types.Add(ct);

var ctb = typeSystem.CreateTypeBuilder(ct);
var compiler = new XamlXCompiler(config, true);
var compiler = new XamlILCompiler(
config,
new XamlLanguageEmitMappings<IXamlILEmitter, XamlILNodeEmitResult>(),
true);
var contextTypeDef = compiler.CreateContextType(ctb);

asm.MainModule.Types.Add(ct);
Expand All @@ -42,7 +50,7 @@ static void Main(string[] args)
if (bt != loadBench)
continue;

var loadMethod = lb.Methods.FirstOrDefault(m => m.Name == "LoadXamlXPrecompiled");
var loadMethod = lb.Methods.FirstOrDefault(m => m.Name == "LoadXamlPrecompiled");
if (loadMethod != null)
lb.Methods.Remove(loadMethod);

Expand All @@ -53,13 +61,13 @@ static void Main(string[] args)
while (xml[0] > 128)
xml = xml.Substring(1);

var parsed = XamlX.Parsers.XDocumentXamlXParser.Parse(xml);
var parsed = XamlX.Parsers.XDocumentXamlParser.Parse(xml);
compiler.Transform(parsed);
compiler.Compile(parsed, typeSystem.CreateTypeBuilder(lb), contextTypeDef,
"PopulateXamlXPrecompiled", "LoadXamlXPrecompiled",
"XamlXXmlInfo", resource.Name, null);
"PopulateXamlPrecompiled", "LoadXamlPrecompiled",
"XamlXmlInfo", resource.Name, null);

loadMethod = lb.Methods.First(m => m.Name == "LoadXamlXPrecompiled");
loadMethod = lb.Methods.First(m => m.Name == "LoadXamlPrecompiled");
loadMethod.ReturnType = asm.MainModule.TypeSystem.Object;
loadMethod.Overrides.Add(baseMethod);
loadMethod.Body.OptimizeMacros();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace XamlX.TypeSystem
{
partial class CecilTypeSystem
{
private class CecilAssembly : IXamlXAssembly
private class CecilAssembly : IXamlAssembly
{
private Dictionary<string, CecilType> _typeCache = new Dictionary<string, CecilType>();
public CecilTypeSystem TypeSystem { get; }
Expand All @@ -19,16 +19,16 @@ public CecilAssembly(CecilTypeSystem typeSystem, AssemblyDefinition assembly)
Assembly = assembly;
}

public bool Equals(IXamlXAssembly other) => other == this;
public bool Equals(IXamlAssembly other) => other == this;

public string Name => Assembly.Name.Name;
private IReadOnlyList<IXamlXCustomAttribute> _attributes;
private IReadOnlyList<IXamlCustomAttribute> _attributes;

public IReadOnlyList<IXamlXCustomAttribute> CustomAttributes =>
public IReadOnlyList<IXamlCustomAttribute> CustomAttributes =>
_attributes ?? (_attributes =
Assembly.CustomAttributes.Select(ca => new CecilCustomAttribute(TypeSystem, ca)).ToList());

public IXamlXType FindType(string fullName)
public IXamlType FindType(string fullName)
{
if (_typeCache.TryGetValue(fullName, out var rv))
return rv;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace XamlX.TypeSystem
{
partial class CecilTypeSystem
{
class CecilCustomAttribute : IXamlXCustomAttribute
class CecilCustomAttribute : IXamlCustomAttribute
{

public CecilTypeSystem TypeSystem { get; }
Expand All @@ -18,10 +18,10 @@ public CecilCustomAttribute(CecilTypeSystem typeSystem, CustomAttribute data)
Data = data;
}

public bool Equals(IXamlXCustomAttribute other) => other is CecilCustomAttribute ca && ca.Data == Data;
public bool Equals(IXamlCustomAttribute other) => other is CecilCustomAttribute ca && ca.Data == Data;

private IXamlXType _type;
public IXamlXType Type => _type ?? (_type = TypeSystem.Resolve(Data.AttributeType));
private IXamlType _type;
public IXamlType Type => _type ?? (_type = TypeSystem.Resolve(Data.AttributeType));

private List<object> _parameters;

Expand Down
Loading