예제 #1
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);
 }
예제 #2
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));
            }
예제 #3
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));
            }