public static IXamlILEmitter LdMethodInfo(this IXamlILEmitter emitter, IXamlMethod method) { var conv = emitter.TypeSystem.GetType("System.Reflection.MethodInfo") .FindMethod(m => m.IsStatic && m.IsPublic && m.Name == "GetMethodFromHandle"); return(emitter.Ldtoken(method).EmitCall(conv)); }
public AdderSetter(IXamlMethod getter, IXamlMethod adder) { _getter = getter; _adder = adder; TargetType = getter.DeclaringType; Parameters = adder.ParametersWithThis().Skip(1).ToList(); }
public XamlWrappedMethod(IXamlMethod method) { _method = method; ParametersWithThis = method.IsStatic ? method.Parameters : new[] { method.DeclaringType }.Concat(method.Parameters).ToList(); ReturnType = method.ReturnType; }
public XamlMarkupExtensionNode(IXamlLineInfo lineInfo, IXamlMethod provideValue, IXamlAstValueNode value) : base(lineInfo) { ProvideValue = provideValue; Value = value; Type = new XamlAstClrTypeReference(this, ProvideValue.ReturnType, false); }
public XamlLoadMethodDelegateNode(IXamlLineInfo lineInfo, IXamlAstValueNode value, IXamlType delegateType, IXamlMethod method) : base(lineInfo, value) { DelegateType = delegateType; Method = method; Type = new XamlAstClrTypeReference(value, DelegateType, false); }
public XamlRuntimeContext(IXamlType definition, IXamlType constructedType, XamlLanguageEmitMappings <TBackendEmitter, TEmitResult> mappings, Action <XamlRuntimeContext <TBackendEmitter, TEmitResult>, TBackendEmitter> factory) { ContextType = definition.MakeGenericType(constructedType); IXamlField Get(string s) => ContextType.Fields.FirstOrDefault(f => f.Name == s); IXamlMethod GetMethod(string s) => ContextType.Methods.FirstOrDefault(f => f.Name == s); RootObjectField = Get(XamlRuntimeContextDefintion.RootObjectFieldName); IntermediateRootObjectField = Get(XamlRuntimeContextDefintion.IntermediateRootObjectFieldName); ParentListField = Get(XamlRuntimeContextDefintion.ParentListFieldName); PropertyTargetObject = Get(XamlRuntimeContextDefintion.ProvideTargetObjectName); PropertyTargetProperty = Get(XamlRuntimeContextDefintion.ProvideTargetPropertyName); PushParentMethod = GetMethod(XamlRuntimeContextDefintion.PushParentMethodName); PopParentMethod = GetMethod(XamlRuntimeContextDefintion.PopParentMethodName); Constructor = ContextType.Constructors.First(); Factory = il => factory(this, il); if (mappings.ContextFactoryCallback != null) { Factory = il => { factory(this, il); mappings.ContextFactoryCallback(this, il); } } ; } }
private static XamlIlBindingPathNode TransformForTargetTyping(XamlIlBindingPathNode transformed, AstTransformationContext context) { var parentNode = context.ParentNodes().OfType <XamlPropertyAssignmentNode>().FirstOrDefault(); if (parentNode == null) { return(transformed); } var lastElement = transformed.Elements[transformed.Elements.Count - 1]; if (parentNode.Property?.Getter?.ReturnType == context.GetAvaloniaTypes().ICommand&& lastElement is XamlIlClrMethodPathElementNode methodPathElement) { IXamlMethod executeMethod = methodPathElement.Method; IXamlMethod canExecuteMethod = executeMethod.DeclaringType.FindMethod(new FindMethodMethodSignature($"Can{executeMethod.Name}", context.Configuration.WellKnownTypes.Boolean, context.Configuration.WellKnownTypes.Object)); List <string> dependsOnProperties = new(); if (canExecuteMethod is not null) { foreach (var attr in canExecuteMethod.CustomAttributes) { if (attr.Type == context.GetAvaloniaTypes().DependsOnAttribute) { dependsOnProperties.Add((string)attr.Parameters[0]); } } } transformed.Elements.RemoveAt(transformed.Elements.Count - 1); transformed.Elements.Add(new XamlIlClrMethodAsCommandPathElementNode(context.GetAvaloniaTypes().ICommand, executeMethod, canExecuteMethod, dependsOnProperties)); } return(transformed); }
protected abstract void CompileBuild( IFileSource fileSource, IXamlAstValueNode rootInstance, Func <string, IXamlType, IXamlTypeBuilder <TBackendEmitter> > createSubType, TBackendEmitter codeGen, XamlRuntimeContext <TBackendEmitter, TEmitResult> context, IXamlMethod compiledPopulate);
public RXamlWellKnownTypes(TransformerConfiguration cfg) { var ts = cfg.TypeSystem; XamlIlTypes = cfg.WellKnownTypes; Single = ts.GetType("System.Single"); Int32 = ts.GetType("System.Int32"); (Vector2, Vector2ConstructorFull) = GetNumericTypeInfo("Robust.Shared.Maths.Vector2", Single, 2); (Vector2i, Vector2iConstructorFull) = GetNumericTypeInfo("Robust.Shared.Maths.Vector2i", Int32, 2); (Thickness, ThicknessConstructorFull) = GetNumericTypeInfo("Robust.Shared.Maths.Thickness", Single, 4); (IXamlType, IXamlConstructor) GetNumericTypeInfo(string name, IXamlType componentType, int componentCount) { var type = cfg.TypeSystem.GetType(name); var ctor = type.GetConstructor(Enumerable.Repeat(componentType, componentCount).ToList()); return(type, ctor); } Color = cfg.TypeSystem.GetType("Robust.Shared.Maths.Color"); ColorFromXaml = Color.GetMethod(new FindMethodMethodSignature("FromXaml", Color, XamlIlTypes.String) { IsStatic = true }); }
public XamlMethodWithCasts(IXamlMethod method, IEnumerable <IXamlType> newArgumentTypes) { _method = method; Parameters = newArgumentTypes.ToList(); _baseParametersWithThis = _method.ParametersWithThis(); if (_baseParametersWithThis.Count != Parameters.Count) { throw new ArgumentException("Method argument count mismatch"); } }
public static IReadOnlyList <IXamlType> ParametersWithThis(this IXamlMethod method) { if (method.IsStatic) { return(method.Parameters); } var lst = method.Parameters.ToList(); lst.Insert(0, method.DeclaringType); return(lst); }
public AvaloniaXamlIlAvaloniaListConstantAstNode(IXamlLineInfo lineInfo, AvaloniaXamlIlWellKnownTypes types, IXamlType listType, IXamlType elementType, IReadOnlyList <IXamlAstValueNode> values) : base(lineInfo) { _constructor = listType.GetConstructor(); _listAddMethod = listType.GetMethod(new FindMethodMethodSignature("Add", types.XamlIlTypes.Void, elementType)); _listSetCapacityMethod = listType.GetMethod(new FindMethodMethodSignature("set_Capacity", types.XamlIlTypes.Void, types.Int)); _elementType = elementType; _values = values; Type = new XamlAstClrTypeReference(lineInfo, listType, false); }
public XamlAstClrProperty(IXamlLineInfo lineInfo, string name, IXamlType declaringType, IXamlMethod getter, IEnumerable <IXamlPropertySetter> setters) : base(lineInfo) { Name = name; DeclaringType = declaringType; Getter = getter; if (setters != null) { Setters.AddRange(setters); } }
public IXamlProperty DefineProperty(IXamlType propertyType, string name, IXamlMethod setter, IXamlMethod getter) { var p = _tb.DefineProperty(name, PropertyAttributes.None, ((SreType)propertyType).Type, new Type[0]); if (setter != null) { p.SetSetMethod(((SreMethodBuilder)setter).MethodBuilder); } if (getter != null) { p.SetGetMethod(((SreMethodBuilder)getter).MethodBuilder); } return(new SreProperty(_system, p)); }
public IXamlProperty DefineProperty(IXamlType propertyType, string name, IXamlMethod setter, IXamlMethod getter) { var s = (CecilMethod)setter; var g = (CecilMethod)getter; var def = new PropertyDefinition(name, PropertyAttributes.None, GetReference(propertyType)); def.SetMethod = s?.Definition; def.GetMethod = g?.Definition; Definition.Properties.Add(def); var rv = new CecilProperty(TypeSystem, def, SelfReference); ((List <CecilProperty>)Properties).Add(rv); return(rv); }
public AdderSetter(IXamlMethod getter, IXamlMethod adder) { _getter = getter; _adder = adder; TargetType = getter.DeclaringType; Parameters = adder.ParametersWithThis().Skip(1).ToList(); bool allowNull = Parameters.Last().AcceptsNull(); BinderParameters = new PropertySetterBinderParameters { AllowMultiple = true, AllowXNull = allowNull, AllowRuntimeNull = allowNull }; }
public static IXamlILEmitter EmitCall(this IXamlILEmitter emitter, IXamlMethod method, bool swallowResult = false) { if (method is IXamlCustomEmitMethod <IXamlILEmitter> custom) { custom.EmitCall(emitter); } else { emitter.Emit(method.IsStatic ? OpCodes.Call : OpCodes.Callvirt, method); } if (swallowResult && !(method.ReturnType.Namespace == "System" && method.ReturnType.Name == "Void")) { emitter.Pop(); } return(emitter); }
public bool Equals(IXamlMethod other) => other is XamlMethodWithCasts mwc && mwc._method.Equals(_method) &&
public bool Equals(IXamlMethod other) => ((SreMethod)other)?.Method.Equals(Method) == true;
public IXamlILEmitter Emit(OpCode code, IXamlMethod method) { _ilg.Emit(code, ((SreMethod)method).Method); return(this); }
public IXamlMethodBuilder <IXamlILEmitter> DefineMethod(IXamlType returnType, IEnumerable <IXamlType> args, string name, bool isPublic, bool isStatic, bool isInterfaceImpl, IXamlMethod overrideMethod) { var ret = ((SreType)returnType).Type; var largs = (IReadOnlyList <IXamlType>)(args?.ToList()) ?? Array.Empty <IXamlType>(); var argTypes = largs.Cast <SreType>().Select(t => t.Type); var m = _tb.DefineMethod(name, (isPublic ? MethodAttributes.Public : MethodAttributes.Private) | (isStatic ? MethodAttributes.Static : default(MethodAttributes)) | (isInterfaceImpl ? MethodAttributes.Virtual | MethodAttributes.NewSlot : default(MethodAttributes)) , ret, argTypes.ToArray()); if (overrideMethod != null) { _tb.DefineMethodOverride(m, ((SreMethod)overrideMethod).Method); } return(new SreMethodBuilder(_system, m, largs)); }
public XamlStaticOrTargetedReturnMethodCallNode(IXamlLineInfo lineInfo, IXamlMethod method, IEnumerable <IXamlAstValueNode> args) : this(lineInfo, new XamlWrappedMethod(method), args) { }
public XamlDirectCallPropertySetter(IXamlMethod method) { _method = method; Parameters = method.ParametersWithThis().Skip(1).ToList(); TargetType = method.ThisOrFirstParameter(); }
public XamlAstClrProperty(IXamlLineInfo lineInfo, string name, IXamlType declaringType, IXamlMethod getter, params IXamlMethod[] setters) : this(lineInfo, name, declaringType, getter, setters.Select(x => new XamlDirectCallPropertySetter(x))) { }
public bool Equals(IXamlMethod other) => other is GetterMethod m && m.Name == Name && m.DeclaringType.Equals(DeclaringType);
public RXamlColorAstNode(IXamlLineInfo lineInfo, RXamlWellKnownTypes types, string color) : base(lineInfo) { _color = color; Type = new XamlAstClrTypeReference(lineInfo, types.Color, false); _method = types.ColorFromXaml; }
public MethodReference GetMethodReference(IXamlMethod t) => ((CecilMethod)t).IlReference;
public XamlNoReturnMethodCallNode(IXamlLineInfo lineInfo, IXamlMethod method, IEnumerable <IXamlAstValueNode> args) : base(lineInfo, new XamlWrappedMethod(method), args) { }
public static IXamlILEmitter Ldftn(this IXamlILEmitter emitter, IXamlMethod method) => emitter.Emit(OpCodes.Ldftn, method);
public IXamlMethodBuilder <IXamlILEmitter> DefineMethod(IXamlType returnType, IEnumerable <IXamlType> args, string name, bool isPublic, bool isStatic, bool isInterfaceImpl, IXamlMethod overrideMethod = null) { var attrs = default(MethodAttributes); if (isPublic) { attrs |= MethodAttributes.Public; } if (isStatic) { attrs |= MethodAttributes.Static; } if (isInterfaceImpl) { attrs |= MethodAttributes.NewSlot | MethodAttributes.Virtual; } var def = new MethodDefinition(name, attrs, GetReference(returnType)); if (args != null) { foreach (var a in args) { def.Parameters.Add(new ParameterDefinition(GetReference(a))); } } if (overrideMethod != null) { def.Overrides.Add(Definition.Module.ImportReference(((CecilMethod)overrideMethod).Reference)); } def.Body.InitLocals = true; Definition.Methods.Add(def); var rv = new CecilMethod(TypeSystem, def, SelfReference); ((List <CecilMethod>)Methods).Add(rv); return(rv); }