Exemplo n.º 1
0
        public static ExpressionEmitter Prepare(
            ITypeInformation operand, DecodeContext decodeContext, bool check)
        {
            var si = decodeContext.PopStack();

            if (si.TargetType.IsValueType || si.TargetType.IsByReference || si.TargetType.IsPointer)
            {
                throw new InvalidProgramSequenceException(
                          "Invalid {0} operation: Location={1}, StackType={2}",
                          check ? "castclass" : "isinst",
                          decodeContext.CurrentCode.RawLocation,
                          si.TargetType.FriendlyName);
            }

            // It's maybe boxed objref if operand is value type.
            var resultType = operand.IsValueType ?
                             decodeContext.PrepareContext.MetadataContext.ValueTypeType :
                             operand;
            var symbol = decodeContext.PushStack(resultType);

            // If this type can cast statically:
            if (operand.IsAssignableFrom(si.TargetType))
            {
                // To interface type
                if (operand.IsInterface)
                {
                    return((extractContext, _) =>
                    {
                        return new[] { string.Format(
                                           "{0} = il2c_cast_to_interface({1}, {2}, {3})",
                                           extractContext.GetSymbolName(symbol),
                                           operand.MangledUniqueName,
                                           si.TargetType.MangledUniqueName,
                                           extractContext.GetSymbolName(si)) };
                    });
                }
                else
                {
                    return((extractContext, _) =>
                    {
                        return new[] { string.Format(
                                           "{0} = ({1}){2}",
                                           extractContext.GetSymbolName(symbol),
                                           operand.CLanguageTypeName,
                                           extractContext.GetSymbolName(si)) };
                    });
                }
            }

            return((extractContext, _) =>
            {
                return new[] { string.Format(
                                   "{0} = {1}({2}, {3})",
                                   extractContext.GetSymbolName(symbol),
                                   check ? "il2c_castclass" : "il2c_isinst",
                                   extractContext.GetSymbolName(si),
                                   operand.MangledUniqueName) };
            });
        }
Exemplo n.º 2
0
 public override Func <IExtractContext, string[]> Apply(ITypeInformation operand, DecodeContext decodeContext)
 {
     return(LdelemConverterUtilities.Apply(
                elementType => operand.IsAssignableFrom(elementType),
                operand.MakeByReference(),
                true,
                decodeContext));
 }
Exemplo n.º 3
0
 public override ExpressionEmitter Prepare(ITypeInformation operand, DecodeContext decodeContext)
 {
     return(LdelemConverterUtilities.Prepare(
                elementType => operand.IsAssignableFrom(elementType),
                operand.MakeByReference(),
                true,
                decodeContext));
 }
Exemplo n.º 4
0
        public override Func <IExtractContext, string[]> Apply(ITypeInformation operand, DecodeContext decodeContext)
        {
            // ECMA-335 III.4.26 stelem.<type> - store element to array

            var siValue = decodeContext.PopStack();

            if (!operand.IsAssignableFrom(siValue.TargetType))
            {
                throw new InvalidProgramSequenceException(
                          "Invalid array element type: Location={0}, ElementType={1}, StackType={2}",
                          decodeContext.CurrentCode.RawLocation,
                          operand.FriendlyName,
                          siValue.TargetType.FriendlyName);
            }

            var siIndex = decodeContext.PopStack();

            if (!(siIndex.TargetType.IsInt32StackFriendlyType || siIndex.TargetType.IsIntPtrStackFriendlyType))
            {
                throw new InvalidProgramSequenceException(
                          "Invalid index type: Location={0}, ElementType={1}, StackType={2}",
                          decodeContext.CurrentCode.RawLocation,
                          operand.FriendlyName,
                          siIndex.TargetType.FriendlyName);
            }

            var siArray = decodeContext.PopStack();

            if (!(siArray.TargetType.IsArray &&
                  siArray.TargetType.ElementType.IsAssignableFrom(siValue.TargetType)))
            {
                throw new InvalidProgramSequenceException(
                          "Invalid array element type: Location={0}, ArrayType={1}, ElementType={2}, StackType={3}",
                          decodeContext.CurrentCode.RawLocation,
                          siArray.TargetType.FriendlyName,
                          operand.FriendlyName,
                          siValue.TargetType.FriendlyName);
            }

            return(extractContext => new[] {
                string.Format("il2c_array_item({0}, {1}, {2}) = {3}",
                              extractContext.GetSymbolName(siArray),
                              operand.CLanguageTypeName,
                              extractContext.GetSymbolName(siIndex),
                              extractContext.GetRightExpression(siArray.TargetType.ElementType, siValue))
            });
        }
        private IPropertyInformation GetNormalizedProperty(IPropertyInformation propertyInformation, ITypeInformation instanceTypeInformation)
        {
            var originalDeclaringType = propertyInformation.GetOriginalDeclaringType();

            // Support for properties declared on instance type and base types
            if (originalDeclaringType.IsAssignableFrom(instanceTypeInformation))
            {
                return(propertyInformation);
            }

            // Support for properties declared on derived types
            if (instanceTypeInformation.IsAssignableFrom(originalDeclaringType))
            {
                return(propertyInformation);
            }

            // Support for properties declared on mixin
            if (Mixins.Utilities.ReflectionUtility.IsMixinType(originalDeclaringType.ConvertToRuntimeType()))
            {
                var instanceRuntimeType          = instanceTypeInformation.ConvertToRuntimeType();
                var interfacePropertyInformation = propertyInformation.FindInterfaceDeclarations()
                                                   .Where(p => MixinTypeUtility.IsAssignableFrom(p.GetOriginalDeclaringType().ConvertToRuntimeType(), instanceRuntimeType))
                                                   .First(
                    () =>
                    new NotSupportedException(
                        string.Format(
                            "The member '{0}.{1}' is not part of any interface introduced onto the target class '{2}'. "
                            + "Only mixed properties that are part of an introduced interface can be used within the sort-expression of a collection property.",
                            propertyInformation.DeclaringType.FullName,
                            propertyInformation.Name,
                            instanceTypeInformation.FullName
                            )));

                return(interfacePropertyInformation);
            }

            // Unreachable due to mapping validation
            throw new NotSupportedException(
                      string.Format(
                          "The member '{0}.{1}' is not part of inheritance hierarchy of class '{2}'. "
                          + "Only properties that are part of the inheritance hierarhcy can be used within the sort-expression of a collection property.",
                          propertyInformation.DeclaringType.FullName,
                          propertyInformation.Name,
                          instanceTypeInformation.FullName
                          ));
        }