public override Type GetReturnType(ITypeMapper typeMapper) => typeMapper.MapType(typeof(float));
void Initialize(ITypeMapper typeMapper) { if (_initialized) return; _initialized = true; // TODO: proper checking as in specification if (_ifTrue.GetReturnType(typeMapper) != _ifFalse.GetReturnType(typeMapper)) throw new ArgumentException(Properties.Messages.ErrInvalidConditionalVariants); if (_cond.GetReturnType(typeMapper) != typeMapper.MapType(typeof(bool))) _cond = _cond.IsTrue(); }
public ContextualOperand Field(System.Type type, string name) { return(Field(_typeMapper.MapType(type), name)); }
private UnaryOp(ITypeMapper typeMapper) : base(typeMapper.MapType(typeof(T)), typeMapper.MapType(typeof(T))) { }
public override Type GetReturnType(ITypeMapper typeMapper) => typeMapper.MapType(_value.GetType());
public override Type GetReturnType(ITypeMapper typeMapper) => typeMapper.MapType(typeof(System.Type));
public override Type GetReturnType(ITypeMapper typeMapper) => typeMapper.MapType(typeof(string));
public override Type GetReturnType(ITypeMapper typeMapper) { return(typeMapper.MapType(_type)); }
public override Type GetReturnType(ITypeMapper typeMapper) => typeMapper.MapType(_t);
public override Type GetReturnType(ITypeMapper typeMapper) => typeMapper.MapType(_t);
private CmpOp(ITypeMapper typeMapper) : base(typeMapper.MapType(typeof(bool)), typeMapper.MapType(typeof(T)), typeMapper.MapType(typeof(T))) { // unsigned is calculated from return type by default Unsigned = IsUnsigned(typeMapper.MapType(typeof(T))); }
private ShiftOp(ITypeMapper typeMapper) : base(typeMapper.MapType(typeof(T)), typeMapper.MapType(typeof(T)), typeMapper.MapType(typeof(int))) { }
private StringConcatOp(ITypeMapper typeMapper) : base(typeMapper.MapType(typeof(string)), typeMapper.MapType(typeof(T1)), typeMapper.MapType(typeof(T2))) { _method = typeMapper.MapType(typeof(string)).GetMethod("Concat", BindingFlags.Public | BindingFlags.Static, null, ParameterTypes, null); }
private SameOp(ITypeMapper typeMapper) : base(typeMapper.MapType(typeof(T)), typeMapper.MapType(typeof(T)), typeMapper.MapType(typeof(T))) { }
private IncOp(ITypeMapper typeMapper) : base(typeMapper.MapType(typeof(T))) { }
public override Type GetReturnType(ITypeMapper typeMapper) => typeMapper.MapType(typeof(double));
public ContextualOperand InvokeEquals(Operand right, ITypeMapper typeMapper) { Operand left = this; var args = new Operand[] { left, right }; return(OperandExtensions.SetLeakedState(new ContextualOperand(new Invocation(typeMapper.TypeInfo.FindMethod(typeMapper.MapType(typeof(object)), "Equals", args, true), null, args), typeMapper), true)); }
public override Type GetReturnType(ITypeMapper typeMapper) => typeMapper.MapType(_asLong ? typeof(long) : typeof(int));
public override Type GetReturnType(ITypeMapper typeMapper) => typeMapper.MapType(typeof(string));
void Initialize(Type targetType, string methodName) { if (!_delegateType.IsSubclassOf(_typeMapper.MapType(typeof(Delegate)))) { throw new ArgumentException(Messages.ErrInvalidDelegateType, "delegateType"); } IMemberInfo delegateInvocationMethod = null; foreach (IMemberInfo mi in _typeMapper.TypeInfo.GetMethods(_delegateType)) { if (mi.Name == "Invoke") { if (delegateInvocationMethod != null) { throw new ArgumentException(Messages.ErrInvalidDelegateType, "delegateType"); } delegateInvocationMethod = mi; } } if (delegateInvocationMethod == null) { throw new ArgumentException(Messages.ErrInvalidDelegateType, "delegateType"); } foreach (IMemberInfo mi in _typeMapper.TypeInfo.GetConstructors(_delegateType)) { if (mi.IsStatic) { continue; } Type[] ctorParamTypes = mi.ParameterTypes; if (ctorParamTypes.Length == 2 && ctorParamTypes[0] == _typeMapper.MapType(typeof(object)) && ctorParamTypes[1] == _typeMapper.MapType(typeof(IntPtr))) { if (_delegateConstructor != null) { throw new ArgumentException(Messages.ErrInvalidDelegateType, "delegateType"); } _delegateConstructor = (ConstructorInfo)mi.Member; } } if (_delegateConstructor == null) { throw new ArgumentException(Messages.ErrInvalidDelegateType, "delegateType"); } Type retType = delegateInvocationMethod.ReturnType; Type[] parameterTypes = delegateInvocationMethod.ParameterTypes; for ( ; targetType != null; targetType = targetType.BaseType) { foreach (IMemberInfo mi in _typeMapper.TypeInfo.Filter(_typeMapper.TypeInfo.GetMethods(targetType), methodName, false, (object)_target == null, false)) { if (mi.ReturnType == retType && ArrayUtils.Equals(mi.ParameterTypes, parameterTypes)) { if (_method == null) { _method = (MethodInfo)mi.Member; } else { throw new AmbiguousMatchException(Messages.ErrAmbiguousBinding); } } } if (_method != null) { break; } } if (_method == null) { throw new MissingMethodException(Messages.ErrMissingMethod); } }
public ContextualOperand New(System.Type type) { return(New(_typeMapper.MapType(type))); }
public static Type TypeOf <T>(ITypeMapper typeMapper) { return(typeMapper.MapType(typeof(T))); }
public override Type GetReturnType(ITypeMapper typeMapper) { return typeMapper.MapType(_type); }
public static bool AreTypesEqual(Type a, System.Type b, ITypeMapper typeMapper) { return(a == typeMapper.MapType(b)); }
public ContextualOperand InvokeEquals(Operand right, ITypeMapper typeMapper) { Operand left = this; var args = new Operand[] { left, right }; return OperandExtensions.SetLeakedState(new ContextualOperand(new Invocation(typeMapper.TypeInfo.FindMethod(typeMapper.MapType(typeof(object)), "Equals", args, true), null, args), typeMapper), true); }
public override Type GetReturnType(ITypeMapper typeMapper) => typeMapper.MapType(typeof(decimal));
public static AttributeMap[] Create(ITypeMapper model, Assembly assembly) { #if FEAT_IKVM const bool inherit = false; System.Collections.Generic.IList <CustomAttributeData> all = assembly.__GetCustomAttributes(model.MapType(typeof(System.Attribute), true), inherit); AttributeMap[] result = new AttributeMap[all.Count]; int index = 0; foreach (CustomAttributeData attrib in all) { result[index++] = new AttributeDataMap(attrib); } return(result); #else #if WINRT Attribute[] all = System.Linq.Enumerable.ToArray(assembly.GetCustomAttributes()); #else const bool inherit = false; object[] all = assembly.GetCustomAttributes(inherit); #endif AttributeMap[] result = new AttributeMap[all.Length]; for (int i = 0; i < all.Length; i++) { result[i] = new ReflectionAttributeMap((Attribute)all[i]); } return(result); #endif }
void PrepareAf(ITypeMapper typeMapper) { if (_af != null || !ReferenceEquals(_afInterceptor, null)) { return; } Operand[] operandsValueOrDefault = new Operand[2]; Operand[] operandsHasValue = new Operand[2]; Operand[] operandsValue = new Operand[2]; int nullables = 0; int nulls = 0; int lastNullableIndex = -1; for (int i = 0; i < _operands.Length; i++) { var op = _operands[i]; if (ReferenceEquals(op, null)) { nulls++; continue; } Type vt = op.GetReturnType(typeMapper); if (vt.IsValueType && (Helpers.GetNullableUnderlyingType(vt) != null)) { if (!op.TrivialAccess) { var cache = new LocalCache(op); _caches.Add(cache); op = cache; } operandsValueOrDefault[i] = op.Invoke("GetValueOrDefault", typeMapper).SetNotLeaked(); operandsValue[i] = op.Property("Value", typeMapper).SetNotLeaked(); operandsHasValue[i] = op.Property("HasValue", typeMapper).SetNotLeaked(); nullables++; lastNullableIndex = i; } else { operandsValueOrDefault[i] = op; operandsValue[i] = op; } } if (nullables > 0 && nulls == 0) { if (_operands.Length == 2) { var nonNullableOperation = new OverloadableOperation(_op, operandsValueOrDefault[0], operandsValueOrDefault[1]); Type returnType = nonNullableOperation.GetReturnType(typeMapper); // when no value // for comparsion we return false, // for +-, etc we return nullable null Type nullableReturnType = typeMapper.MapType(typeof(Nullable <>)).MakeGenericType(returnType); // bool? || bool? - not allowed // bool? || bool - not allowed // but bool? | bool - allowed but not logical! // the difference between logical == != vs normal: for we should always return true or false // expression "(int?) == 5" is not nullable but "int? + 5" is! if (_op.IsLogical) { // true or false required _returnType = typeMapper.MapType(typeof(bool)); if (_op.BranchOp == BranchInstruction.Ne) { if (nullables == 1) { Operand notHasValue = !operandsHasValue[lastNullableIndex]; _afInterceptor = new Conditional(nonNullableOperation, true, notHasValue); } else { // ((nullable.GetValueOrDefault() != nullable2.GetValueOrDefault()) ? true : (nullable.HasValue != nullable2.HasValue)) Operand hasValueNotEqual = operandsHasValue[0] != operandsHasValue[1]; _afInterceptor = new Conditional(nonNullableOperation, true, hasValueNotEqual); } } else { // ((nullable.GetValueOrDefault() == nullable2.GetValueOrDefault()) ? (nullable.HasValue == nullable2.HasValue) : false) Operand hasValueEqualCheck = nullables == 2 ? operandsHasValue[0] == operandsHasValue[1] : operandsHasValue[lastNullableIndex]; _afInterceptor = new Conditional(nonNullableOperation, hasValueEqualCheck, false); } } else { // nullable return: // long? = int? + long? // long? = (a.HasValue && b.HasValue) ? new long?(a.Value + b.Value) : (long?)null _returnType = nullableReturnType; nonNullableOperation = new OverloadableOperation(_op, operandsValue[0], operandsValue[1]); var ctorArgs = new Operand[] { nonNullableOperation }; var ctor = typeMapper.TypeInfo.FindConstructor(nullableReturnType, ctorArgs); Operand bothWithValueCondition = nullables == 2 ? operandsHasValue[0] && operandsHasValue[1] : operandsHasValue[lastNullableIndex]; _afInterceptor = new Conditional(bothWithValueCondition, new NewObject(ctor, ctorArgs), new DefaultValue(nullableReturnType)); } return; } else if (_operands.Length == 1) { // convert increment/decrement to binary operators if (_op.OpCode == OpCodes.Add) { _afInterceptor = _operands[0] + 1; _returnType = _afInterceptor.GetReturnType(typeMapper); return; } if (_op.OpCode == OpCodes.Sub) { _afInterceptor = _operands[0] - 1; _returnType = _afInterceptor.GetReturnType(typeMapper); return; } } } PrepareAfNormally(typeMapper, _operands); if (_af == null) { throw new AmbiguousMatchException(Properties.Messages.ErrAmbiguousBinding); } _returnType = _af.Method.ReturnType; }