dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/Basic/CompilerServices ByteType.cs,1


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/Basic/CompilerServices ByteType.cs,1.2,1.3 DecimalType.cs,1.2,1.3 DoubleType.cs,1.2,1.3 FlowControl.cs,1.1,1.2 IntegerType.cs,1.2,1.3 LongType.cs,1.2,1.3 ObjectType.cs,1.1,1.2 ProjectData.cs,1.1,1.2 ShortType.cs,1.2,1.3 SingleType.cs,1.2,1.3
Date: Thu, 22 May 2003 03:25:31 -0400

Update of /cvsroot/dotgnu-pnet/pnetlib/Basic/CompilerServices
In directory subversions:/tmp/cvs-serv16197/Basic/CompilerServices

Modified Files:
        ByteType.cs DecimalType.cs DoubleType.cs FlowControl.cs 
        IntegerType.cs LongType.cs ObjectType.cs ProjectData.cs 
        ShortType.cs SingleType.cs 
Log Message:


Continue implementing the VB support library's compiler services.


Index: ByteType.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Basic/CompilerServices/ByteType.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** ByteType.cs 22 May 2003 02:24:09 -0000      1.2
--- ByteType.cs 22 May 2003 07:25:29 -0000      1.3
***************
*** 77,80 ****
--- 77,85 ----
                                        try
                                        {
+                                               long lvalue;
+                                               
if(LongType.TryConvertHexOct(Value, out lvalue))
+                                               {
+                                                       return 
checked((byte)lvalue);
+                                               }
                                                return Convert.ToByte
                                                        
(Math.Round(DoubleType.Parse(Value)));

Index: DecimalType.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Basic/CompilerServices/DecimalType.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** DecimalType.cs      22 May 2003 02:24:09 -0000      1.2
--- DecimalType.cs      22 May 2003 07:25:29 -0000      1.3
***************
*** 81,98 ****
                                return FromString(Value, null);
                        }
-       [TODO]
        public static Decimal FromString
                                (String Value, NumberFormatInfo NumberFormat)
                        {
!                               // TODO
!                               return 0.0m;
                        }
  
        // Parse a string into a decimal value.
-       [TODO]
        public static Decimal Parse(String Value, NumberFormatInfo NumberFormat)
                        {
!                               // TODO
!                               return 0.0m;
                        }
  
--- 81,114 ----
                                return FromString(Value, null);
                        }
        public static Decimal FromString
                                (String Value, NumberFormatInfo NumberFormat)
                        {
!                               if(Value == null)
!                               {
!                                       return 0.0m;
!                               }
!                               try
!                               {
!                                       long lvalue;
!                                       if(LongType.TryConvertHexOct(Value, out 
lvalue))
!                                       {
!                                               return (decimal)lvalue;
!                                       }
!                                       return Parse(Value, NumberFormat);
!                               }
!                               catch(FormatException)
!                               {
!                                       throw new InvalidCastException
!                                               (String.Format
!                                                       (S._("VB_InvalidCast"),
!                                                        "System.String", 
"System.Decimal"));
!                               }
                        }
  
        // Parse a string into a decimal value.
        public static Decimal Parse(String Value, NumberFormatInfo NumberFormat)
                        {
!                               return Decimal.Parse(Utils.FixDigits(Value),
!                                                                        
NumberStyles.Any, NumberFormat);
                        }
  

Index: DoubleType.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Basic/CompilerServices/DoubleType.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** DoubleType.cs       22 May 2003 02:24:09 -0000      1.2
--- DoubleType.cs       22 May 2003 07:25:29 -0000      1.3
***************
*** 81,90 ****
                                return FromString(Value, null);
                        }
-       [TODO]
        public static double FromString
                                (String Value, NumberFormatInfo NumberFormat)
                        {
!                               // TODO
!                               return 0.0;
                        }
  
--- 81,107 ----
                                return FromString(Value, null);
                        }
        public static double FromString
                                (String Value, NumberFormatInfo NumberFormat)
                        {
!                               if(Value == null)
!                               {
!                                       return 0.0;
!                               }
!                               try
!                               {
!                                       long lvalue;
!                                       if(LongType.TryConvertHexOct(Value, out 
lvalue))
!                                       {
!                                               return (double)lvalue;
!                                       }
!                                       return Parse(Value, NumberFormat);
!                               }
!                               catch(FormatException)
!                               {
!                                       throw new InvalidCastException
!                                               (String.Format
!                                                       (S._("VB_InvalidCast"),
!                                                        "System.String", 
"System.Decimal"));
!                               }
                        }
  
***************
*** 94,102 ****
                                return Parse(Value, null);
                        }
-       [TODO]
        public static double Parse(String Value, NumberFormatInfo NumberFormat)
                        {
!                               // TODO
!                               return 0.0;
                        }
  
--- 111,118 ----
                                return Parse(Value, null);
                        }
        public static double Parse(String Value, NumberFormatInfo NumberFormat)
                        {
!                               return Double.Parse(Utils.FixDigits(Value),
!                                                                       
NumberStyles.Any, NumberFormat);
                        }
  

Index: FlowControl.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Basic/CompilerServices/FlowControl.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** FlowControl.cs      16 May 2003 05:35:00 -0000      1.1
--- FlowControl.cs      22 May 2003 07:25:29 -0000      1.2
***************
*** 50,58 ****
  
        // Get the enumerator for an object.
-       [TODO]
        public static IEnumerator ForEachInObj(Object obj)
                        {
!                               // TODO
!                               return null;
                        }
  
--- 50,69 ----
  
        // Get the enumerator for an object.
        public static IEnumerator ForEachInObj(Object obj)
                        {
!                               if(obj == null)
!                               {
!                                       Utils.ThrowException(91);       // 
NullReferenceException.
!                               }
!                               else if(obj is IEnumerable)
!                               {
!                                       IEnumerator e = 
((IEnumerable)obj).GetEnumerator();
!                                       if(e != null)
!                                       {
!                                               return e;
!                                       }
!                               }
!                               Utils.ThrowException(100);      // 
InvalidOperationException.
!                               return null;    // Not reached - keep the 
compiler happy.
                        }
  
***************
*** 72,77 ****
                        }
  
        // Initialize a "for" loop.
-       [TODO]
        public static bool ForLoopInitObj
                                (Object Counter, Object Start, Object Limit,
--- 83,148 ----
                        }
  
+       // Cast an object to a new type.
+       private static Object CastToType(Object obj, TypeCode type)
+                       {
+                               switch(type)
+                               {
+                                       case TypeCode.Boolean:
+                                               return 
((IConvertible)obj).ToBoolean(null);
+ 
+                                       case TypeCode.Byte:
+                                               return 
((IConvertible)obj).ToByte(null);
+ 
+                                       case TypeCode.Int16:
+                                               return 
((IConvertible)obj).ToInt16(null);
+ 
+                                       case TypeCode.Int32:
+                                               return 
((IConvertible)obj).ToInt32(null);
+ 
+                                       case TypeCode.Int64:
+                                               return 
((IConvertible)obj).ToInt64(null);
+ 
+                                       case TypeCode.Single:
+                                               return 
((IConvertible)obj).ToSingle(null);
+ 
+                                       case TypeCode.Double:
+                                               return 
((IConvertible)obj).ToDouble(null);
+ 
+                                       case TypeCode.Decimal:
+                                               return 
((IConvertible)obj).ToDecimal(null);
+                               }
+                               return obj;
+                       }
+ 
+       // Determine if a value is negative.
+       private static bool ValueIsNegative(Object value, TypeCode type)
+                       {
+                               switch(type)
+                               {
+                                       case TypeCode.Boolean:
+                                               return ((bool)value);   // True 
== -1 in VB.
+ 
+                                       case TypeCode.Int16:
+                                               return (((short)value) < 0);
+ 
+                                       case TypeCode.Int32:
+                                               return (((int)value) < 0);
+ 
+                                       case TypeCode.Int64:
+                                               return (((long)value) < 0);
+ 
+                                       case TypeCode.Single:
+                                               return (((float)value) < 0.0f);
+ 
+                                       case TypeCode.Double:
+                                               return (((double)value) < 0.0);
+ 
+                                       case TypeCode.Decimal:
+                                               return (((decimal)value) < 
0.0m);
+                               }
+                               return false;
+                       }
+ 
        // Initialize a "for" loop.
        public static bool ForLoopInitObj
                                (Object Counter, Object Start, Object Limit,
***************
*** 79,84 ****
                                 ref Object CounterResult)
                        {
!                               // TODO
!                               return false;
                        }
  
--- 150,202 ----
                                 ref Object CounterResult)
                        {
!                               // Validate the parameters.
!                               if(Start == null)
!                               {
!                                       throw new ArgumentException
!                                               (S._("VB_ValueIsNull"), 
"Start");
!                               }
!                               if(Limit == null)
!                               {
!                                       throw new ArgumentException
!                                               (S._("VB_ValueIsNull"), 
"Limit");
!                               }
!                               if(StepValue == null)
!                               {
!                                       throw new ArgumentException
!                                               (S._("VB_ValueIsNull"), 
"StepValue");
!                               }
! 
!                               // Find a common numeric type between the three 
arguments.
!                               Type enumType;
!                               TypeCode type =
!                                       ObjectType.CommonType(Start, Limit, out 
enumType);
!                               type = ObjectType.CommonType(StepValue, null, 
type, false);
!                               if(type == TypeCode.Empty)
!                               {
!                                       throw new 
ArgumentException(S._("VB_CommonForType"));
!                               }
! 
!                               // Create the "for" control object.
!                               ForInfo info = new ForInfo();
!                               LoopForResult = info;
!                               info.counter = CastToType(Start, type);
!                               info.limit = CastToType(Limit, type);
!                               info.stepValue = CastToType(StepValue, type);
!                               info.type = type;
!                               info.enumType = enumType;
!                               info.stepIsNegative = 
ValueIsNegative(info.stepValue, type);
! 
!                               // Return the initial counter value.
!                               if(enumType == null)
!                               {
!                                       CounterResult = info.counter;
!                               }
!                               else
!                               {
!                                       CounterResult = Enum.ToObject(enumType, 
info.counter);
!                               }
! 
!                               // Determine if we've already exceeded the 
limit.
!                               return CheckObjForLimit(info);
                        }
  
***************
*** 97,107 ****
                        }
  
        // Check for the end of an object iteration.
-       [TODO]
        public static bool ForNextCheckObj
                                (Object Counter, Object LoopObj, ref Object 
CounterResult)
                        {
!                               // TODO
!                               return false;
                        }
  
--- 215,259 ----
                        }
  
+       // Check the limit of an object-based "for" loop.
+       private static bool CheckObjForLimit(ForInfo info)
+                       {
+                               if(!(info.stepIsNegative))
+                               {
+                                       return (ObjectType.ObjTst(info.counter, 
info.limit, false)
+                                                               <= 0);
+                               }
+                               else
+                               {
+                                       return (ObjectType.ObjTst(info.counter, 
info.limit, false)
+                                                               >= 0);
+                               }
+                       }
+ 
        // Check for the end of an object iteration.
        public static bool ForNextCheckObj
                                (Object Counter, Object LoopObj, ref Object 
CounterResult)
                        {
!                               if(!(LoopObj is ForInfo))
!                               {
!                                       Utils.ThrowException(100);      // 
InvalidOperationException.
!                               }
!                               else if(Counter == null)
!                               {
!                                       throw new ArgumentException
!                                               (S._("VB_LoopCounterIsNull"), 
"Counter");
!                               }
!                               ForInfo info = (ForInfo)LoopObj;
!                               info.counter =
!                                       CastToType(ObjectType.AddObj(Counter, 
info.stepValue),
!                                                          info.type);
!                               if(info.enumType == null)
!                               {
!                                       CounterResult = info.counter;
!                               }
!                               else
!                               {
!                                       CounterResult = 
Enum.ToObject(info.enumType, info.counter);
!                               }
!                               return CheckObjForLimit(info);
                        }
  
***************
*** 133,136 ****
--- 285,300 ----
                                }
                        }
+ 
+       // Storage for an object-based "for" loop.
+       private sealed class ForInfo
+       {
+               public Object counter;
+               public Object limit;
+               public Object stepValue;
+               public TypeCode type;
+               public Type enumType;
+               public bool stepIsNegative;
+ 
+       }; // class ForInfo
  
  }; // class FlowControl

Index: IntegerType.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Basic/CompilerServices/IntegerType.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** IntegerType.cs      22 May 2003 02:24:09 -0000      1.2
--- IntegerType.cs      22 May 2003 07:25:29 -0000      1.3
***************
*** 77,80 ****
--- 77,85 ----
                                        try
                                        {
+                                               long lvalue;
+                                               
if(LongType.TryConvertHexOct(Value, out lvalue))
+                                               {
+                                                       return 
checked((int)lvalue);
+                                               }
                                                return Convert.ToInt32
                                                        
(Math.Round(DoubleType.Parse(Value)));

Index: LongType.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Basic/CompilerServices/LongType.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** LongType.cs 22 May 2003 02:24:09 -0000      1.2
--- LongType.cs 22 May 2003 07:25:29 -0000      1.3
***************
*** 70,73 ****
--- 70,123 ----
                        }
  
+       // Try to convert a value using hex or octal forms into "long".
+       internal static bool TryConvertHexOct(String str, out long value)
+                       {
+                               int len = str.Length;
+                               int posn = 0;
+                               char ch;
+                               while(posn < len)
+                               {
+                                       ch = str[posn];
+                                       if(ch == '&')
+                                       {
+                                               break;
+                                       }
+                                       else if(ch == ' ' || ch == '\u3000')
+                                       {
+                                               ++posn;
+                                       }
+                                       else
+                                       {
+                                               value = 0;
+                                               return false;
+                                       }
+                               }
+                               ++posn;
+                               if(posn >= len)
+                               {
+                                       value = 0;
+                                       return false;
+                               }
+                               str = Utils.FixDigits(str);
+                               ch = str[posn];
+                               if(ch == 'h' || ch == 'H')
+                               {
+                                       // Recognize a hexadecimal value.
+                                       value = 
Convert.ToInt64(str.Substring(posn + 1), 16);
+                                       return true;
+                               }
+                               else if(ch == 'o' || ch == 'O')
+                               {
+                                       // Recognize an octal value.
+                                       value = 
Convert.ToInt64(str.Substring(posn + 1), 8);
+                                       return true;
+                               }
+                               else
+                               {
+                                       // Not a legitimate number format.
+                                       throw new 
FormatException(S._("VB_InvalidHexOrOct"));
+                               }
+                       }
+ 
        // Convert a string into a long value.
        public static long FromString(String Value)
***************
*** 77,80 ****
--- 127,135 ----
                                        try
                                        {
+                                               long lvalue;
+                                               if(TryConvertHexOct(Value, out 
lvalue))
+                                               {
+                                                       return lvalue;
+                                               }
                                                return Convert.ToInt64
                                                        
(Math.Round(DoubleType.Parse(Value)));

Index: ObjectType.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Basic/CompilerServices/ObjectType.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** ObjectType.cs       16 May 2003 05:35:00 -0000      1.1
--- ObjectType.cs       22 May 2003 07:25:29 -0000      1.2
***************
*** 25,28 ****
--- 25,29 ----
  using System;
  using System.ComponentModel;
+ using System.Globalization;
  
  [EditorBrowsable(EditorBrowsableState.Never)]
***************
*** 32,194 ****
        public ObjectType() {}
  
[...1665 lines suppressed...]
!                               {
!                                       case TypeCode.Boolean:
!                                       case TypeCode.Byte:
!                                       case TypeCode.Int16:
!                                       case TypeCode.Int32:
!                                       case TypeCode.Int64:
!                                       case TypeCode.Single:
!                                       case TypeCode.Double:
!                                       case TypeCode.String:
!                                       case TypeCode.Decimal:
!                                       {
!                                               bool b1 = 
BooleanType.FromObject(o1);
!                                               bool b2 = 
BooleanType.FromObject(o2);
!                                               return ((b1 && !b2) || (!b1 && 
b2));
!                                       }
!                                       // Not reached.
!                               }
!                               throw new 
InvalidCastException(S._("VB_InvalidXorArguments"));
                        }
  

Index: ProjectData.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Basic/CompilerServices/ProjectData.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** ProjectData.cs      16 May 2003 05:35:00 -0000      1.1
--- ProjectData.cs      22 May 2003 07:25:29 -0000      1.2
***************
*** 36,51 ****
  
        // Clear the project error.
-       [TODO]
        public static void ClearProjectError()
                        {
!                               // TODO
                        }
  
        // Create a new project error.
-       [TODO]
        public static Exception CreateProjectError(int hr)
                        {
!                               // TODO
!                               return null;
                        }
  
--- 36,52 ----
  
        // Clear the project error.
        public static void ClearProjectError()
                        {
!                               Information.Err().Clear();
                        }
  
        // Create a new project error.
        public static Exception CreateProjectError(int hr)
                        {
!                               ClearProjectError();
!                               hr = ErrObject.HResultToNumber(hr);
!                               Exception e = 
ErrObject.CreateExceptionFromNumber(hr, null);
!                               Information.Err().Number = hr;
!                               return e;
                        }
  
***************
*** 58,70 ****
  
        // Set the project error.
-       [TODO]
        public static void SetProjectError(Exception ex)
                        {
!                               // TODO
                        }
-       [TODO]
        public static void SetProjectError(Exception ex, int lErl)
                        {
!                               // TODO
                        }
  
--- 59,69 ----
  
        // Set the project error.
        public static void SetProjectError(Exception ex)
                        {
!                               Information.Err().SetException(ex);
                        }
        public static void SetProjectError(Exception ex, int lErl)
                        {
!                               Information.Err().SetException(ex, lErl);
                        }
  

Index: ShortType.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Basic/CompilerServices/ShortType.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** ShortType.cs        22 May 2003 02:24:09 -0000      1.2
--- ShortType.cs        22 May 2003 07:25:29 -0000      1.3
***************
*** 77,80 ****
--- 77,85 ----
                                        try
                                        {
+                                               long lvalue;
+                                               
if(LongType.TryConvertHexOct(Value, out lvalue))
+                                               {
+                                                       return 
checked((short)lvalue);
+                                               }
                                                return Convert.ToInt16
                                                        
(Math.Round(DoubleType.Parse(Value)));

Index: SingleType.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Basic/CompilerServices/SingleType.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** SingleType.cs       22 May 2003 02:24:09 -0000      1.2
--- SingleType.cs       22 May 2003 07:25:29 -0000      1.3
***************
*** 81,90 ****
                                return FromString(Value, null);
                        }
-       [TODO]
        public static float FromString
                                (String Value, NumberFormatInfo NumberFormat)
                        {
!                               // TODO
!                               return 0.0f;
                        }
  
--- 81,88 ----
                                return FromString(Value, null);
                        }
        public static float FromString
                                (String Value, NumberFormatInfo NumberFormat)
                        {
!                               return (float)(DoubleType.FromString(Value, 
NumberFormat));
                        }
  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]