committed by
GitHub
11 changed files with 216 additions and 65 deletions
@ -1,6 +1,18 @@ |
|||||
|
using System.Collections.Generic; |
||||
using Avalonia.Collections; |
using Avalonia.Collections; |
||||
|
|
||||
namespace Avalonia |
namespace Avalonia |
||||
{ |
{ |
||||
public sealed class Points : AvaloniaList<Point> { } |
public sealed class Points : AvaloniaList<Point> |
||||
|
{ |
||||
|
public Points() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public Points(IEnumerable<Point> points) : base(points) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,71 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Reflection.Emit; |
||||
|
using Avalonia.Controls; |
||||
|
using Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers; |
||||
|
using XamlX; |
||||
|
using XamlX.Ast; |
||||
|
using XamlX.Emit; |
||||
|
using XamlX.IL; |
||||
|
using XamlX.Transform; |
||||
|
using XamlX.TypeSystem; |
||||
|
|
||||
|
namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.AstNodes |
||||
|
{ |
||||
|
class AvaloniaXamlIlArrayConstantAstNode : XamlAstNode, IXamlAstValueNode, IXamlAstILEmitableNode |
||||
|
{ |
||||
|
private readonly IXamlType _elementType; |
||||
|
private readonly IReadOnlyList<IXamlAstValueNode> _values; |
||||
|
|
||||
|
public AvaloniaXamlIlArrayConstantAstNode(IXamlLineInfo lineInfo, IXamlType arrayType, IXamlType elementType, IReadOnlyList<IXamlAstValueNode> values) : base(lineInfo) |
||||
|
{ |
||||
|
_elementType = elementType; |
||||
|
_values = values; |
||||
|
|
||||
|
Type = new XamlAstClrTypeReference(lineInfo, arrayType, false); |
||||
|
|
||||
|
foreach (var element in values) |
||||
|
{ |
||||
|
if (!elementType.IsAssignableFrom(element.Type.GetClrType())) |
||||
|
{ |
||||
|
throw new XamlParseException("x:Array element is not assignable to the array element type!", lineInfo); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public IXamlAstTypeReference Type { get; } |
||||
|
|
||||
|
public XamlILNodeEmitResult Emit(XamlEmitContext<IXamlILEmitter, XamlILNodeEmitResult> context, IXamlILEmitter codeGen) |
||||
|
{ |
||||
|
codeGen.Ldc_I4(_values.Count) |
||||
|
.Newarr(_elementType); |
||||
|
|
||||
|
for (var index = 0; index < _values.Count; index++) |
||||
|
{ |
||||
|
var value = _values[index]; |
||||
|
|
||||
|
codeGen |
||||
|
.Dup() |
||||
|
.Ldc_I4(index); |
||||
|
|
||||
|
context.Emit(value, codeGen, _elementType); |
||||
|
|
||||
|
if (value.Type.GetClrType() is { IsValueType: true } valTypeInObjArr) |
||||
|
{ |
||||
|
if (!_elementType.IsValueType) |
||||
|
{ |
||||
|
codeGen.Box(valTypeInObjArr); |
||||
|
} |
||||
|
// It seems like ASM codegen for "stelem valuetype" and "stelem.i4" is identical,
|
||||
|
// so we don't need to try to optimize it here.
|
||||
|
codeGen.Emit(OpCodes.Stelem, valTypeInObjArr); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
codeGen.Stelem_ref(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return XamlILNodeEmitResult.Type(0, Type.GetClrType()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1 +1 @@ |
|||||
Subproject commit 5dd0b042e144e677638224c49fec16dab66143e8 |
Subproject commit 5d1025f30d0ed6d8f419d82959c148276301f393 |
||||
Loading…
Reference in new issue