Browse Source

Update XamlX (#15488)

* Update XAMLX

* And update XamlX again

---------

Co-authored-by: Jumar Macato <[email protected]>
Max Katz 1 năm trước cách đây
mục cha
commit
e38edb258d

+ 2 - 1
src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlLanguage.cs

@@ -182,7 +182,8 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions
         }
 
         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)
             {

+ 3 - 0
src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlClassesPropertyResolver.cs

@@ -1,3 +1,4 @@
+using System;
 using System.Collections.Generic;
 using XamlX.Ast;
 using XamlX.Emit;
@@ -61,6 +62,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers
             public PropertySetterBinderParameters BinderParameters { get; } =
                 new PropertySetterBinderParameters { AllowXNull = false };
             public IReadOnlyList<IXamlType> Parameters { get; }
+            public IReadOnlyList<IXamlCustomAttribute> CustomAttributes => Array.Empty<IXamlCustomAttribute>();
         }
 
         class ClassBindingSetter : IXamlEmitablePropertySetter<IXamlILEmitter>
@@ -92,6 +94,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers
             public PropertySetterBinderParameters BinderParameters { get; } =
                 new PropertySetterBinderParameters { AllowXNull = false };
             public IReadOnlyList<IXamlType> Parameters { get; }
+            public IReadOnlyList<IXamlCustomAttribute> CustomAttributes => Array.Empty<IXamlCustomAttribute>();
         }
     }
 }

+ 1 - 0
src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlDeferredResourceTransformer.cs

@@ -99,6 +99,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers
             public PropertySetterBinderParameters BinderParameters { get; }
 
             public IReadOnlyList<IXamlType> Parameters { get; }
+            public IReadOnlyList<IXamlCustomAttribute> CustomAttributes => _adder.CustomAttributes;
 
             public void Emit(IXamlILEmitter emitter)
             {

+ 2 - 0
src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlOptionMarkupExtensionTransformer.cs

@@ -339,6 +339,8 @@ internal class AvaloniaXamlIlOptionMarkupExtensionTransformer : IXamlAstTransfor
         public IXamlMethod MakeGenericMethod(IReadOnlyList<IXamlType> typeArguments) => throw new NotImplementedException();
         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)
         {
             // At this point this extension will be called from MarkupExtensionEmitter.

+ 2 - 0
src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlSetterTransformer.cs

@@ -109,6 +109,8 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers
                 public IXamlType TargetType { get; }
                 public PropertySetterBinderParameters BinderParameters { get; }
                 public IReadOnlyList<IXamlType> Parameters { get; }
+                public IReadOnlyList<IXamlCustomAttribute> CustomAttributes => _method.CustomAttributes;
+
                 public void Emit(IXamlILEmitter codegen)
                 {
                     if (_type.IsValueType)

+ 2 - 0
src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlTransformInstanceAttachedProperties.cs

@@ -123,6 +123,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers
                 public IXamlType TargetType => _parent.DeclaringType;
                 public PropertySetterBinderParameters BinderParameters { get; } = new PropertySetterBinderParameters();
                 public IReadOnlyList<IXamlType> Parameters { get; }
+                public IReadOnlyList<IXamlCustomAttribute> CustomAttributes => _parent.CustomAttributes;
                 public void Emit(IXamlILEmitter emitter)
                 {
                     var so = _parent._config.WellKnownTypes.Object;
@@ -178,6 +179,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers
                 public IReadOnlyList<IXamlType> Parameters { get; }
 
                 public IReadOnlyList<IXamlCustomAttribute> CustomAttributes => DeclaringType.CustomAttributes;
+                public IXamlParameterInfo GetParameterInfo(int index) => new AnonymousParameterInfo(Parameters[index], index);
 
                 public void EmitCall(IXamlILEmitter emitter)
                 {

+ 1 - 0
src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/XamlIlAvaloniaPropertyHelper.cs

@@ -228,6 +228,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions
             public PropertySetterBinderParameters BinderParameters { get; }
 
             public IReadOnlyList<IXamlType> Parameters { get; set; }
+            public IReadOnlyList<IXamlCustomAttribute> CustomAttributes => Array.Empty<IXamlCustomAttribute>();
 
             public abstract void Emit(IXamlILEmitter emitter);
 

+ 1 - 1
src/Markup/Avalonia.Markup.Xaml.Loader/xamlil.github

@@ -1 +1 @@
-Subproject commit 5683cc4f0e629ed30ad7bb6b5e920379ee5c344a
+Subproject commit 941dafce490ffd21178f4493a7f0425e9d478e60

+ 29 - 12
src/tools/Avalonia.Generators/Compiler/RoslynTypeSystem.cs

@@ -152,8 +152,8 @@ internal class RoslynType : IXamlType
         _symbol.Constructors
             .Select(method => new RoslynConstructor(method, _assembly))
             .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>();
 
@@ -189,6 +189,8 @@ internal class RoslynType : IXamlType
     public IXamlType GetEnumUnderlyingType() => null;
 
     public IReadOnlyList<IXamlType> GenericParameters { get; } = new List<IXamlType>();
+
+    public bool IsFunctionPointer => false;
 }
 
 internal class RoslynConstructor : IXamlConstructor
@@ -212,10 +214,10 @@ internal class RoslynConstructor : IXamlConstructor
 
     public IReadOnlyList<IXamlType> Parameters =>
         _symbol.Parameters
-            .Select(parameter => parameter.Type)
-            .OfType<INamedTypeSymbol>()
-            .Select(type => new RoslynType(type, _assembly))
+            .Select(parameter => new RoslynParameter(_assembly, parameter).ParameterType)
             .ToList();
+
+    public IXamlParameterInfo GetParameterInfo(int index) => new RoslynParameter(_assembly, _symbol.Parameters[index]);
 }
 
 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 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>();
 }
 
+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
 {
     private readonly IMethodSymbol _symbol;
@@ -277,14 +295,13 @@ internal class RoslynMethod : IXamlMethod
     public IXamlType ReturnType => new RoslynType((INamedTypeSymbol) _symbol.ReturnType, _assembly);
 
     public IReadOnlyList<IXamlType> Parameters =>
-        _symbol.Parameters.Select(parameter => parameter.Type)
-            .OfType<INamedTypeSymbol>()
-            .Select(type => new RoslynType(type, _assembly))
+        _symbol.Parameters.Select(parameter => new RoslynParameter(_assembly, parameter).ParameterType)
             .ToList();
-        
+
     public IXamlType DeclaringType => new RoslynType((INamedTypeSymbol)_symbol.ReceiverType, _assembly);
         
     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]);
 }