Update XamlX (#15488)

* Update XAMLX

* And update XamlX again

---------

Co-authored-by: Jumar Macato <16554748+jmacato@users.noreply.github.com>
This commit is contained in:
Max Katz
2024-04-24 00:34:35 -07:00
committed by GitHub
parent aa60e5d2f9
commit e38edb258d
9 changed files with 43 additions and 14 deletions
@@ -182,7 +182,8 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions
} }
public static bool CustomValueConverter(AstTransformationContext context, public static bool CustomValueConverter(AstTransformationContext context,
IXamlAstValueNode node, IXamlType type, out IXamlAstValueNode result) IXamlAstValueNode node, IReadOnlyList<IXamlCustomAttribute> customAttributes, IXamlType type,
out IXamlAstValueNode result)
{ {
if (node is AvaloniaXamlIlOptionMarkupExtensionTransformer.OptionsMarkupExtensionNode optionsNode) if (node is AvaloniaXamlIlOptionMarkupExtensionTransformer.OptionsMarkupExtensionNode optionsNode)
{ {
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using XamlX.Ast; using XamlX.Ast;
using XamlX.Emit; using XamlX.Emit;
@@ -61,6 +62,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers
public PropertySetterBinderParameters BinderParameters { get; } = public PropertySetterBinderParameters BinderParameters { get; } =
new PropertySetterBinderParameters { AllowXNull = false }; new PropertySetterBinderParameters { AllowXNull = false };
public IReadOnlyList<IXamlType> Parameters { get; } public IReadOnlyList<IXamlType> Parameters { get; }
public IReadOnlyList<IXamlCustomAttribute> CustomAttributes => Array.Empty<IXamlCustomAttribute>();
} }
class ClassBindingSetter : IXamlEmitablePropertySetter<IXamlILEmitter> class ClassBindingSetter : IXamlEmitablePropertySetter<IXamlILEmitter>
@@ -92,6 +94,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers
public PropertySetterBinderParameters BinderParameters { get; } = public PropertySetterBinderParameters BinderParameters { get; } =
new PropertySetterBinderParameters { AllowXNull = false }; new PropertySetterBinderParameters { AllowXNull = false };
public IReadOnlyList<IXamlType> Parameters { get; } public IReadOnlyList<IXamlType> Parameters { get; }
public IReadOnlyList<IXamlCustomAttribute> CustomAttributes => Array.Empty<IXamlCustomAttribute>();
} }
} }
} }
@@ -99,6 +99,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers
public PropertySetterBinderParameters BinderParameters { get; } public PropertySetterBinderParameters BinderParameters { get; }
public IReadOnlyList<IXamlType> Parameters { get; } public IReadOnlyList<IXamlType> Parameters { get; }
public IReadOnlyList<IXamlCustomAttribute> CustomAttributes => _adder.CustomAttributes;
public void Emit(IXamlILEmitter emitter) public void Emit(IXamlILEmitter emitter)
{ {
@@ -339,6 +339,8 @@ internal class AvaloniaXamlIlOptionMarkupExtensionTransformer : IXamlAstTransfor
public IXamlMethod MakeGenericMethod(IReadOnlyList<IXamlType> typeArguments) => throw new NotImplementedException(); public IXamlMethod MakeGenericMethod(IReadOnlyList<IXamlType> typeArguments) => throw new NotImplementedException();
public IReadOnlyList<IXamlCustomAttribute> CustomAttributes => Array.Empty<IXamlCustomAttribute>(); public IReadOnlyList<IXamlCustomAttribute> CustomAttributes => Array.Empty<IXamlCustomAttribute>();
public IXamlParameterInfo GetParameterInfo(int index) => new AnonymousParameterInfo(Parameters[index], index);
public void EmitCall(XamlEmitContext<IXamlILEmitter, XamlILNodeEmitResult> context, IXamlILEmitter codeGen) public void EmitCall(XamlEmitContext<IXamlILEmitter, XamlILNodeEmitResult> context, IXamlILEmitter codeGen)
{ {
// At this point this extension will be called from MarkupExtensionEmitter. // At this point this extension will be called from MarkupExtensionEmitter.
@@ -109,6 +109,8 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers
public IXamlType TargetType { get; } public IXamlType TargetType { get; }
public PropertySetterBinderParameters BinderParameters { get; } public PropertySetterBinderParameters BinderParameters { get; }
public IReadOnlyList<IXamlType> Parameters { get; } public IReadOnlyList<IXamlType> Parameters { get; }
public IReadOnlyList<IXamlCustomAttribute> CustomAttributes => _method.CustomAttributes;
public void Emit(IXamlILEmitter codegen) public void Emit(IXamlILEmitter codegen)
{ {
if (_type.IsValueType) if (_type.IsValueType)
@@ -123,6 +123,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers
public IXamlType TargetType => _parent.DeclaringType; public IXamlType TargetType => _parent.DeclaringType;
public PropertySetterBinderParameters BinderParameters { get; } = new PropertySetterBinderParameters(); public PropertySetterBinderParameters BinderParameters { get; } = new PropertySetterBinderParameters();
public IReadOnlyList<IXamlType> Parameters { get; } public IReadOnlyList<IXamlType> Parameters { get; }
public IReadOnlyList<IXamlCustomAttribute> CustomAttributes => _parent.CustomAttributes;
public void Emit(IXamlILEmitter emitter) public void Emit(IXamlILEmitter emitter)
{ {
var so = _parent._config.WellKnownTypes.Object; var so = _parent._config.WellKnownTypes.Object;
@@ -178,6 +179,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers
public IReadOnlyList<IXamlType> Parameters { get; } public IReadOnlyList<IXamlType> Parameters { get; }
public IReadOnlyList<IXamlCustomAttribute> CustomAttributes => DeclaringType.CustomAttributes; public IReadOnlyList<IXamlCustomAttribute> CustomAttributes => DeclaringType.CustomAttributes;
public IXamlParameterInfo GetParameterInfo(int index) => new AnonymousParameterInfo(Parameters[index], index);
public void EmitCall(IXamlILEmitter emitter) public void EmitCall(IXamlILEmitter emitter)
{ {
@@ -228,6 +228,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions
public PropertySetterBinderParameters BinderParameters { get; } public PropertySetterBinderParameters BinderParameters { get; }
public IReadOnlyList<IXamlType> Parameters { get; set; } public IReadOnlyList<IXamlType> Parameters { get; set; }
public IReadOnlyList<IXamlCustomAttribute> CustomAttributes => Array.Empty<IXamlCustomAttribute>();
public abstract void Emit(IXamlILEmitter emitter); public abstract void Emit(IXamlILEmitter emitter);
@@ -152,8 +152,8 @@ internal class RoslynType : IXamlType
_symbol.Constructors _symbol.Constructors
.Select(method => new RoslynConstructor(method, _assembly)) .Select(method => new RoslynConstructor(method, _assembly))
.ToList(); .ToList();
public IReadOnlyList<IXamlCustomAttribute> CustomAttributes { get; } = new List<IXamlCustomAttribute>(); public IReadOnlyList<IXamlCustomAttribute> CustomAttributes { get; } = Array.Empty<IXamlCustomAttribute>();
public IReadOnlyList<IXamlType> GenericArguments { get; private set; } = new List<IXamlType>(); public IReadOnlyList<IXamlType> GenericArguments { get; private set; } = new List<IXamlType>();
@@ -189,6 +189,8 @@ internal class RoslynType : IXamlType
public IXamlType GetEnumUnderlyingType() => null; public IXamlType GetEnumUnderlyingType() => null;
public IReadOnlyList<IXamlType> GenericParameters { get; } = new List<IXamlType>(); public IReadOnlyList<IXamlType> GenericParameters { get; } = new List<IXamlType>();
public bool IsFunctionPointer => false;
} }
internal class RoslynConstructor : IXamlConstructor internal class RoslynConstructor : IXamlConstructor
@@ -212,10 +214,10 @@ internal class RoslynConstructor : IXamlConstructor
public IReadOnlyList<IXamlType> Parameters => public IReadOnlyList<IXamlType> Parameters =>
_symbol.Parameters _symbol.Parameters
.Select(parameter => parameter.Type) .Select(parameter => new RoslynParameter(_assembly, parameter).ParameterType)
.OfType<INamedTypeSymbol>()
.Select(type => new RoslynType(type, _assembly))
.ToList(); .ToList();
public IXamlParameterInfo GetParameterInfo(int index) => new RoslynParameter(_assembly, _symbol.Parameters[index]);
} }
internal class RoslynProperty : IXamlProperty internal class RoslynProperty : IXamlProperty
@@ -243,12 +245,28 @@ internal class RoslynProperty : IXamlProperty
public IXamlMethod Getter => _symbol.GetMethod == null ? null : new RoslynMethod(_symbol.GetMethod, _assembly); public IXamlMethod Getter => _symbol.GetMethod == null ? null : new RoslynMethod(_symbol.GetMethod, _assembly);
public IXamlMethod Setter => _symbol.SetMethod == null ? null : new RoslynMethod(_symbol.SetMethod, _assembly); public IXamlMethod Setter => _symbol.SetMethod == null ? null : new RoslynMethod(_symbol.SetMethod, _assembly);
public IReadOnlyList<IXamlCustomAttribute> CustomAttributes { get; } = new List<IXamlCustomAttribute>(); public IReadOnlyList<IXamlCustomAttribute> CustomAttributes { get; } = Array.Empty<IXamlCustomAttribute>();
public IReadOnlyList<IXamlType> IndexerParameters { get; } = new List<IXamlType>(); public IReadOnlyList<IXamlType> IndexerParameters { get; } = new List<IXamlType>();
} }
internal class RoslynParameter : IXamlParameterInfo
{
private readonly RoslynAssembly _assembly;
private readonly IParameterSymbol _symbol;
public RoslynParameter(RoslynAssembly assembly, IParameterSymbol symbol)
{
_assembly = assembly;
_symbol = symbol;
}
public string Name => _symbol.Name;
public IXamlType ParameterType => new RoslynType((INamedTypeSymbol)_symbol.Type, _assembly);
public IReadOnlyList<IXamlCustomAttribute> CustomAttributes => Array.Empty<IXamlCustomAttribute>();
}
internal class RoslynMethod : IXamlMethod internal class RoslynMethod : IXamlMethod
{ {
private readonly IMethodSymbol _symbol; private readonly IMethodSymbol _symbol;
@@ -277,14 +295,13 @@ internal class RoslynMethod : IXamlMethod
public IXamlType ReturnType => new RoslynType((INamedTypeSymbol) _symbol.ReturnType, _assembly); public IXamlType ReturnType => new RoslynType((INamedTypeSymbol) _symbol.ReturnType, _assembly);
public IReadOnlyList<IXamlType> Parameters => public IReadOnlyList<IXamlType> Parameters =>
_symbol.Parameters.Select(parameter => parameter.Type) _symbol.Parameters.Select(parameter => new RoslynParameter(_assembly, parameter).ParameterType)
.OfType<INamedTypeSymbol>()
.Select(type => new RoslynType(type, _assembly))
.ToList(); .ToList();
public IXamlType DeclaringType => new RoslynType((INamedTypeSymbol)_symbol.ReceiverType, _assembly); public IXamlType DeclaringType => new RoslynType((INamedTypeSymbol)_symbol.ReceiverType, _assembly);
public IXamlMethod MakeGenericMethod(IReadOnlyList<IXamlType> typeArguments) => null; public IXamlMethod MakeGenericMethod(IReadOnlyList<IXamlType> typeArguments) => null;
public IReadOnlyList<IXamlCustomAttribute> CustomAttributes { get; } = new List<IXamlCustomAttribute>(); public IReadOnlyList<IXamlCustomAttribute> CustomAttributes { get; } = Array.Empty<IXamlCustomAttribute>();
public IXamlParameterInfo GetParameterInfo(int index) => new RoslynParameter(_assembly, _symbol.Parameters[index]);
} }