예제 #1
0
        internal static ConversionClass ClassifyPredefinedConversion(Type TargetType, Type SourceType)
        {
            if (TargetType == SourceType)
            {
                return(ConversionClass.Identity);
            }
            TypeCode typeCode = Symbols.GetTypeCode(SourceType);
            TypeCode code2    = Symbols.GetTypeCode(TargetType);

            if (Symbols.IsIntrinsicType(typeCode) && Symbols.IsIntrinsicType(code2))
            {
                if ((Symbols.IsEnum(TargetType) && Symbols.IsIntegralType(typeCode)) && Symbols.IsIntegralType(code2))
                {
                    return(ConversionClass.Narrowing);
                }
                if ((typeCode == code2) && Symbols.IsEnum(SourceType))
                {
                    return(ConversionClass.Widening);
                }
                return(ClassifyIntrinsicConversion(code2, typeCode));
            }
            if (Symbols.IsCharArrayRankOne(SourceType) && Symbols.IsStringType(TargetType))
            {
                return(ConversionClass.Widening);
            }
            if (Symbols.IsCharArrayRankOne(TargetType) && Symbols.IsStringType(SourceType))
            {
                return(ConversionClass.Narrowing);
            }
            return(ClassifyPredefinedCLRConversion(TargetType, SourceType));
        }
예제 #2
0
 private static Type GetWidestType(Type Type1, Type Type2)
 {
     if ((Type1 != null) && (Type2 != null))
     {
         if (!Type1.IsEnum && !Type2.IsEnum)
         {
             TypeCode typeCode = Symbols.GetTypeCode(Type1);
             TypeCode code2    = Symbols.GetTypeCode(Type2);
             if (Symbols.IsNumericType(typeCode) && Symbols.IsNumericType(code2))
             {
                 return(Symbols.MapTypeCodeToType(ConversionResolution.ForLoopWidestTypeCode[(int)typeCode][(int)code2]));
             }
         }
         Symbols.Method operatorMethod = null;
         switch (ConversionResolution.ClassifyConversion(Type2, Type1, ref operatorMethod))
         {
         case ConversionResolution.ConversionClass.Identity:
         case ConversionResolution.ConversionClass.Widening:
             return(Type2);
         }
         operatorMethod = null;
         if (ConversionResolution.ClassifyConversion(Type1, Type2, ref operatorMethod) == ConversionResolution.ConversionClass.Widening)
         {
             return(Type1);
         }
     }
     return(null);
 }
예제 #3
0
 internal static ConversionClass ClassifyPredefinedCLRConversion(Type TargetType, Type SourceType)
 {
     if (TargetType == SourceType)
     {
         return(ConversionClass.Identity);
     }
     if (Symbols.IsRootObjectType(TargetType) || Symbols.IsOrInheritsFrom(SourceType, TargetType))
     {
         return(ConversionClass.Widening);
     }
     if (Symbols.IsRootObjectType(SourceType) || Symbols.IsOrInheritsFrom(TargetType, SourceType))
     {
         return(ConversionClass.Narrowing);
     }
     if (Symbols.IsInterface(SourceType))
     {
         if ((Symbols.IsClass(TargetType) || Symbols.IsArrayType(TargetType)) || Symbols.IsGenericParameter(TargetType))
         {
             return(ConversionClass.Narrowing);
         }
         if (Symbols.IsInterface(TargetType))
         {
             return(ConversionClass.Narrowing);
         }
         if (!Symbols.IsValueType(TargetType))
         {
             return(ConversionClass.Narrowing);
         }
         if (Symbols.Implements(TargetType, SourceType))
         {
             return(ConversionClass.Narrowing);
         }
         return(ConversionClass.None);
     }
     if (Symbols.IsInterface(TargetType))
     {
         if (Symbols.IsArrayType(SourceType))
         {
             return(ClassifyCLRArrayToInterfaceConversion(TargetType, SourceType));
         }
         if (Symbols.IsValueType(SourceType))
         {
             if (Symbols.Implements(SourceType, TargetType))
             {
                 return(ConversionClass.Widening);
             }
             return(ConversionClass.None);
         }
         if (Symbols.IsClass(SourceType))
         {
             if (Symbols.Implements(SourceType, TargetType))
             {
                 return(ConversionClass.Widening);
             }
             return(ConversionClass.Narrowing);
         }
     }
     if (Symbols.IsEnum(SourceType) || Symbols.IsEnum(TargetType))
     {
         if (Symbols.GetTypeCode(SourceType) != Symbols.GetTypeCode(TargetType))
         {
             return(ConversionClass.None);
         }
         if (Symbols.IsEnum(TargetType))
         {
             return(ConversionClass.Narrowing);
         }
         return(ConversionClass.Widening);
     }
     if (Symbols.IsGenericParameter(SourceType))
     {
         if (!Symbols.IsClassOrInterface(TargetType))
         {
             return(ConversionClass.None);
         }
         foreach (Type type2 in Symbols.GetInterfaceConstraints(SourceType))
         {
             switch (ClassifyPredefinedConversion(TargetType, type2))
             {
             case ConversionClass.Widening:
             case ConversionClass.Identity:
                 return(ConversionClass.Widening);
             }
         }
         Type classConstraint = Symbols.GetClassConstraint(SourceType);
         if (classConstraint != null)
         {
             switch (ClassifyPredefinedConversion(TargetType, classConstraint))
             {
             case ConversionClass.Widening:
             case ConversionClass.Identity:
                 return(ConversionClass.Widening);
             }
         }
         return(Interaction.IIf <ConversionClass>(Symbols.IsInterface(TargetType), ConversionClass.Narrowing, ConversionClass.None));
     }
     if (Symbols.IsGenericParameter(TargetType))
     {
         Type derived = Symbols.GetClassConstraint(TargetType);
         if ((derived != null) && Symbols.IsOrInheritsFrom(derived, SourceType))
         {
             return(ConversionClass.Narrowing);
         }
         return(ConversionClass.None);
     }
     if ((Symbols.IsArrayType(SourceType) && Symbols.IsArrayType(TargetType)) && (SourceType.GetArrayRank() == TargetType.GetArrayRank()))
     {
         return(ClassifyCLRConversionForArrayElementTypes(TargetType.GetElementType(), SourceType.GetElementType()));
     }
     return(ConversionClass.None);
 }
예제 #4
0
            public static bool ForLoopInitObj(object Counter, object Start, object Limit, object StepValue, ref object LoopForResult, ref object CounterResult)
            {
                if (Start == null)
                {
                    throw new ArgumentException(Utils.GetResourceString("Argument_InvalidNullValue1", new string[] { "Start" }));
                }
                if (Limit == null)
                {
                    throw new ArgumentException(Utils.GetResourceString("Argument_InvalidNullValue1", new string[] { "Limit" }));
                }
                if (StepValue == null)
                {
                    throw new ArgumentException(Utils.GetResourceString("Argument_InvalidNullValue1", new string[] { "Step" }));
                }
                Type type3 = Start.GetType();
                Type type2 = Limit.GetType();
                Type type4 = StepValue.GetType();
                Type type5 = GetWidestType(type4, type3, type2);

                if (type5 == null)
                {
                    throw new ArgumentException(Utils.GetResourceString("ForLoop_CommonType3", new string[] { Utils.VBFriendlyName(type3), Utils.VBFriendlyName(type2), Utils.VBFriendlyName(StepValue) }));
                }
                ObjectFlowControl.ForLoopControl loopFor = new ObjectFlowControl.ForLoopControl();
                TypeCode typeCode = Symbols.GetTypeCode(type5);

                switch (typeCode)
                {
                case TypeCode.Object:
                    loopFor.UseUserDefinedOperators = true;
                    break;

                case TypeCode.String:
                    typeCode = TypeCode.Double;
                    break;
                }
                TypeCode code2 = Type.GetTypeCode(type3);
                TypeCode code  = Type.GetTypeCode(type2);
                TypeCode code3 = Type.GetTypeCode(type4);
                Type     type  = null;

                if ((code2 == typeCode) && type3.IsEnum)
                {
                    type = type3;
                }
                if ((code == typeCode) && type2.IsEnum)
                {
                    if ((type != null) && (type != type2))
                    {
                        type = null;
                        goto Label_015E;
                    }
                    type = type2;
                }
                if ((code3 == typeCode) && type4.IsEnum)
                {
                    if ((type != null) && (type != type4))
                    {
                        type = null;
                    }
                    else
                    {
                        type = type4;
                    }
                }
Label_015E:
                loopFor.EnumType = type;
                if (!loopFor.UseUserDefinedOperators)
                {
                    loopFor.WidestType = Symbols.MapTypeCodeToType(typeCode);
                }
                else
                {
                    loopFor.WidestType = type5;
                }
                loopFor.WidestTypeCode = typeCode;
                loopFor.Counter        = ConvertLoopElement("Start", Start, type3, loopFor.WidestType);
                loopFor.Limit          = ConvertLoopElement("Limit", Limit, type2, loopFor.WidestType);
                loopFor.StepValue      = ConvertLoopElement("Step", StepValue, type4, loopFor.WidestType);
                if (loopFor.UseUserDefinedOperators)
                {
                    loopFor.OperatorPlus = VerifyForLoopOperator(Symbols.UserDefinedOperator.Plus, loopFor.Counter, loopFor.WidestType);
                    VerifyForLoopOperator(Symbols.UserDefinedOperator.Minus, loopFor.Counter, loopFor.WidestType);
                    loopFor.OperatorLessEqual    = VerifyForLoopOperator(Symbols.UserDefinedOperator.LessEqual, loopFor.Counter, loopFor.WidestType);
                    loopFor.OperatorGreaterEqual = VerifyForLoopOperator(Symbols.UserDefinedOperator.GreaterEqual, loopFor.Counter, loopFor.WidestType);
                }
                loopFor.PositiveStep = Operators.ConditionalCompareObjectGreaterEqual(loopFor.StepValue, Operators.SubtractObject(loopFor.StepValue, loopFor.StepValue), false);
                LoopForResult        = loopFor;
                if (loopFor.EnumType != null)
                {
                    CounterResult = Enum.ToObject(loopFor.EnumType, loopFor.Counter);
                }
                else
                {
                    CounterResult = loopFor.Counter;
                }
                return(CheckContinueLoop(loopFor));
            }
예제 #5
0
            public static bool ForNextCheckObj(object Counter, object LoopObj, ref object CounterResult)
            {
                if (LoopObj == null)
                {
                    throw ExceptionUtils.VbMakeException(0x5c);
                }
                if (Counter == null)
                {
                    throw new NullReferenceException(Utils.GetResourceString("Argument_InvalidNullValue1", new string[] { "Counter" }));
                }
                ObjectFlowControl.ForLoopControl loopFor = (ObjectFlowControl.ForLoopControl)LoopObj;
                bool flag2 = false;

                if (!loopFor.UseUserDefinedOperators)
                {
                    TypeCode typeCode = ((IConvertible)Counter).GetTypeCode();
                    if ((typeCode != loopFor.WidestTypeCode) || (typeCode == TypeCode.String))
                    {
                        if (typeCode == TypeCode.Object)
                        {
                            throw new ArgumentException(Utils.GetResourceString("ForLoop_CommonType2", new string[] { Utils.VBFriendlyName(Symbols.MapTypeCodeToType(typeCode)), Utils.VBFriendlyName(loopFor.WidestType) }));
                        }
                        TypeCode code2 = Symbols.GetTypeCode(GetWidestType(Symbols.MapTypeCodeToType(typeCode), loopFor.WidestType));
                        if (code2 == TypeCode.String)
                        {
                            code2 = TypeCode.Double;
                        }
                        loopFor.WidestTypeCode = code2;
                        loopFor.WidestType     = Symbols.MapTypeCodeToType(code2);
                        flag2 = true;
                    }
                }
                if (flag2 || loopFor.UseUserDefinedOperators)
                {
                    Counter = ConvertLoopElement("Start", Counter, Counter.GetType(), loopFor.WidestType);
                    if (!loopFor.UseUserDefinedOperators)
                    {
                        loopFor.Limit     = ConvertLoopElement("Limit", loopFor.Limit, loopFor.Limit.GetType(), loopFor.WidestType);
                        loopFor.StepValue = ConvertLoopElement("Step", loopFor.StepValue, loopFor.StepValue.GetType(), loopFor.WidestType);
                    }
                }
                if (!loopFor.UseUserDefinedOperators)
                {
                    loopFor.Counter = Operators.AddObject(Counter, loopFor.StepValue);
                    TypeCode code3 = ((IConvertible)loopFor.Counter).GetTypeCode();
                    if (loopFor.EnumType != null)
                    {
                        CounterResult = Enum.ToObject(loopFor.EnumType, loopFor.Counter);
                    }
                    else
                    {
                        CounterResult = loopFor.Counter;
                    }
                    if (code3 != loopFor.WidestTypeCode)
                    {
                        loopFor.Limit     = Conversions.ChangeType(loopFor.Limit, Symbols.MapTypeCodeToType(code3));
                        loopFor.StepValue = Conversions.ChangeType(loopFor.StepValue, Symbols.MapTypeCodeToType(code3));
                        return(false);
                    }
                }
                else
                {
                    loopFor.Counter = Operators.InvokeUserDefinedOperator(loopFor.OperatorPlus, true, new object[] { Counter, loopFor.StepValue });
                    if (loopFor.Counter.GetType() != loopFor.WidestType)
                    {
                        loopFor.Counter = ConvertLoopElement("Start", loopFor.Counter, loopFor.Counter.GetType(), loopFor.WidestType);
                    }
                    CounterResult = loopFor.Counter;
                }
                return(CheckContinueLoop(loopFor));
            }