-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
AvaloniaList compile time parsing #11073
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
38c1cc9
Init AvaloniaListAttribute
maxkatz6 862d07f
Support special case for points collection
maxkatz6 477abdd
Remove AvaloniaListAttribute
maxkatz6 c2b2803
Nullable attributes
maxkatz6 ec19a08
Cleanup Points collection usage, make it use IList
maxkatz6 56d8793
Inject array for IList
maxkatz6 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,18 @@ | ||
using System.Collections.Generic; | ||
using Avalonia.Collections; | ||
|
||
namespace Avalonia | ||
{ | ||
public sealed class Points : AvaloniaList<Point> { } | ||
public sealed class Points : AvaloniaList<Point> | ||
{ | ||
public Points() | ||
{ | ||
|
||
} | ||
|
||
public Points(IEnumerable<Point> points) : base(points) | ||
{ | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...onia.Markup.Xaml.Loader/CompilerExtensions/AstNodes/AvaloniaXamlIlArrayConstantAstNode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to this PR, but changes nullability of points property to be consistent with PolyLineSegment/Geometry.