Author: jambunathan
Date: 2005-03-25 17:05:29 -0500 (Fri, 25 Mar 2005)
New Revision: 42261

Modified:
   trunk/mcs/bmcs/ChangeLog
   trunk/mcs/bmcs/constant.cs
   trunk/mcs/bmcs/literal.cs
   trunk/mcs/bmcs/mb-parser.jay
   trunk/mcs/bmcs/mb-tokenizer.cs
   trunk/mcs/bmcs/typemanager.cs
Log:

* constant.cs (DateConstant): Added (Booroed from mbas)
* literal.cs (DateLiteral): Added (Borrowed from mbas)
* mb-parser.jay: Added support for Date type. (Borrowed from mbas)
* typemanager.cs (void_datetime_ctor_ticks_arg):  Added (Borroed from mbas)
* mb-tokenizer.cs (ParseDateLiteral, GobbleWhitespaces): Added afresh


Modified: trunk/mcs/bmcs/ChangeLog
===================================================================
--- trunk/mcs/bmcs/ChangeLog    2005-03-25 21:22:18 UTC (rev 42260)
+++ trunk/mcs/bmcs/ChangeLog    2005-03-25 22:05:29 UTC (rev 42261)
@@ -1,4 +1,12 @@
 2005-03-25  Jambunathan K  <[EMAIL PROTECTED]>
+
+       * constant.cs (DateConstant): Added (Booroed from mbas)
+       * literal.cs (DateLiteral): Added (Borrowed from mbas)
+       * mb-parser.jay: Added support for Date type. (Borrowed from mbas)
+       * typemanager.cs (void_datetime_ctor_ticks_arg):  Added (Borroed from 
mbas)
+       * mb-tokenizer.cs (ParseDateLiteral, GobbleWhitespaces): Added afresh
+
+2005-03-25  Jambunathan K  <[EMAIL PROTECTED]>
        
        * AssemblyInfo.cs: Set assembly version to 0.1
 

Modified: trunk/mcs/bmcs/constant.cs
===================================================================
--- trunk/mcs/bmcs/constant.cs  2005-03-25 21:22:18 UTC (rev 42260)
+++ trunk/mcs/bmcs/constant.cs  2005-03-25 22:05:29 UTC (rev 42261)
@@ -1137,6 +1137,43 @@
                }
        }
 
+       //
+       // VB.NET specific
+       //
+       public class DateConstant : Constant {
+               public readonly DateTime Value;
+
+               public DateConstant (DateTime s)
+               {
+                       type = TypeManager.date_type;
+                       eclass = ExprClass.Value;
+                       Value = s;
+               }
+
+               override public string AsString ()
+               {
+                       return "#" + Value.ToString() + "#";
+               }
+
+               public override object GetValue ()
+               {
+                       return Value;
+               }
+               
+               public override void Emit (EmitContext ec)
+               {
+                       ec.ig.Emit (OpCodes.Ldc_I8, Value.Ticks);
+                       ec.ig.Emit (OpCodes.Newobj, 
TypeManager.void_datetime_ctor_ticks_arg);
+               }
+
+               // FIXME:
+               public override bool IsNegative {
+                       get {
+                               return false;
+                       }
+               }
+       }
+
 }
 
 

Modified: trunk/mcs/bmcs/literal.cs
===================================================================
--- trunk/mcs/bmcs/literal.cs   2005-03-25 21:22:18 UTC (rev 42260)
+++ trunk/mcs/bmcs/literal.cs   2005-03-25 22:05:29 UTC (rev 42261)
@@ -256,4 +256,20 @@
                        return this;
                }
        }
+
+       //
+       // VB.NET specific
+       //
+       public class DateLiteral : DateConstant {
+               public DateLiteral (DateTime s) : base (s)
+               {
+               }
+
+               public override Expression DoResolve (EmitContext ec)
+               {
+                       type = TypeManager.date_type;
+
+                       return this;
+               }
+       }
 }

Modified: trunk/mcs/bmcs/mb-parser.jay
===================================================================
--- trunk/mcs/bmcs/mb-parser.jay        2005-03-25 21:22:18 UTC (rev 42260)
+++ trunk/mcs/bmcs/mb-parser.jay        2005-03-25 22:05:29 UTC (rev 42261)
@@ -4212,10 +4212,10 @@
        : boolean_literal
        | integer_literal
        | real_literal
-//     | LITERAL_DATE                  { $$ = new DateLiteral 
((DateTime)lexer.Value); }
+       | LITERAL_DATE          { $$ = new DateLiteral ((DateTime)lexer.Value); 
}
        | LITERAL_CHARACTER     { $$ = new CharLiteral ((char) lexer.Value); }
        | LITERAL_STRING        { $$ = new StringLiteral ((string) 
lexer.Value); }
-       | NOTHING                               { $$ = NullLiteral.Null; }
+       | NOTHING               { $$ = NullLiteral.Null; }
        ;
 
 real_literal
@@ -4432,7 +4432,7 @@
        : CBOOL         { $$ = TypeManager.system_boolean_expr;         }
        | CBYTE         { $$ = TypeManager.system_byte_expr;            }
        | CCHAR         { $$ = TypeManager.system_char_expr;            }
-//     | CDATE         { $$ = TypeManager.system_date_expr;            }
+       | CDATE         { $$ = TypeManager.system_date_expr;            }
        | CDBL          { $$ = TypeManager.system_double_expr;          }
        | CDEC          { $$ = TypeManager.system_decimal_expr;         }
        | CINT          { $$ = TypeManager.system_int32_expr;           }
@@ -4753,7 +4753,7 @@
 primitive_type
        : numeric_type
        | BOOLEAN       { $$ = TypeManager.system_boolean_expr; }
-//     | DATE          { $$ = TypeManager.system_date_expr; }
+       | DATE          { $$ = TypeManager.system_date_expr; }
        | CHAR          { $$ = TypeManager.system_char_expr; }
        | STRING        { $$ = TypeManager.system_string_expr; }
        ;

Modified: trunk/mcs/bmcs/mb-tokenizer.cs
===================================================================
--- trunk/mcs/bmcs/mb-tokenizer.cs      2005-03-25 21:22:18 UTC (rev 42260)
+++ trunk/mcs/bmcs/mb-tokenizer.cs      2005-03-25 22:05:29 UTC (rev 42261)
@@ -417,7 +417,7 @@
                                if(tokens_seen)
                                {
                                        if (cant_have_a_type_character) 
-                                               return ExtractDateTimeLiteral();
+                                               return ParseDateLiteral();
                                        else
                                                return Token.NUMBER_SIGN;
                                }
@@ -863,6 +863,16 @@
                {
                        return (c == ' ' || c == '\t' || c == '\v' || c == '\r' 
|| c == 0xa0);
                }
+
+               private void GobbleWhiteSpaces ()
+               {
+                       int d = peekChar ();
+                       while (is_whitespace (d)) {
+                               getChar ();
+                               d = peekChar ();
+                       }
+
+               }
                
                private bool tokens_seen = false;
                
@@ -986,25 +996,144 @@
                        return Token.EOF;
                }
 
-               private int ExtractDateTimeLiteral()
+               private int ParseDateLiteral ()
                {
-                       int c;
+                       int c, d;
+                       object temp;
+                       int month = 1, day = 1, year = 1, hours = 0, minutes = 
0, seconds = 0, date_separator;
+                       bool minutes_specified = false, seconds_specified = 
false;
+                       bool am_specified = false, pm_specified = false;
                        
-                       StringBuilder sb = new StringBuilder();
-                       for (;(c = getChar ()) != -1; col++)
-                       {
-                               if (c == '#') {
-                                       val = ParseDateLiteral(sb);
-                                       return Token.LITERAL_DATE;
+
+                       GobbleWhiteSpaces ();
+                       d = peekChar ();
+                       if (d == '#') 
+                               goto parse_error;
+
+                       temp = ParseIntLiteral ();
+                       if (temp == null)
+                               goto parse_error;
+
+                       d = peekChar ();
+                       if (d == '/' || d == '-') {
+                               c = getChar ();
+                               date_separator = c;
+
+                               month = (int) temp;
+                               // Console.WriteLine ("Month: " + month);
+
+                               temp = ParseIntLiteral ();
+                               if (temp == null)
+                                       goto parse_error;
+                               day = (int) temp;
+                               // Console.WriteLine ("Day: " + day);
+
+                               c = getChar ();
+                               if (c != date_separator)
+                                       goto parse_error;
+
+                               temp = ParseIntLiteral ();
+                               if (temp == null)
+                                       goto parse_error;
+                               year = (int) temp;
+                               // Console.WriteLine ("Year: " + year);
+
+                               GobbleWhiteSpaces ();
+                               d = peekChar ();
+                               if (d == '#') {
+                                       c = getChar ();
+                                       goto parse_done;
                                }
-                               if (IsEOL(c)) {
-                                       break;
+
+                               temp = ParseIntLiteral ();
+                               if (temp == null) 
+                                       goto parse_error;
+                               d = peekChar ();
+                       }
+
+                       hours = (int) temp;
+                       // Console.WriteLine ("Hours: " + hours);
+                       
+                       if (d == ':') {
+                               c = getChar ();
+                               
+                               temp = ParseIntLiteral ();
+                               if (temp == null)
+                                       goto parse_error;
+                               minutes = (int) temp; 
+                               // Console.WriteLine ("Minutes: " + minutes);
+                               minutes_specified = true;
+
+                               d = peekChar ();
+                               if (d == ':') {
+                                       c = getChar ();
+
+                                       temp = ParseIntLiteral ();
+                                       if (temp == null)
+                                               goto parse_error;
+                                       seconds = (int) temp;
+                                       // Console.WriteLine ("Seconds: " + 
seconds);
+                                       seconds_specified = true;
                                } 
-                               if (c == '-')
-                                       c = '/';
-                               sb.Append((char)c);
                        }
+
+
+                       GobbleWhiteSpaces ();
+                       d = peekChar ();
+                       if (d == 'A' ) {
+                               c = getChar ();
+
+                               d = peekChar ();
+                               if (d != 'M')
+                                       goto parse_error;
+
+                               c = getChar ();
+                               // Console.WriteLine ("AM");
+                               am_specified = true;
+                       } else if (d == 'P' ) {
+                               c = getChar ();
+
+                               d = peekChar ();
+                               if (d != 'M')
+                                       goto parse_error;
+                               
+                               c = getChar ();
+                               // Console.WriteLine ("PM");
+                               pm_specified = true;
+                       }
+                       
+                       GobbleWhiteSpaces ();
+                       
+                       d = peekChar ();
+                       if (d == '#') {
+                               c = getChar ();
+                               if (!minutes_specified && !seconds_specified && 
 !am_specified && ! pm_specified)
+                                       goto parse_error;
+
+                               if ((am_specified || pm_specified) && hours > 
12)
+                                       goto parse_error;
+
+                               if (pm_specified)
+                                       hours += 12;
+
+                               goto parse_done;
+                       }
+
+               parse_error:
+                       // Console.WriteLine ("Parse Error");
                        return Token.ERROR;
+
+               parse_done:
+                       try {
+                               temp = new DateTime (year, month, day, hours, 
minutes, seconds);
+                       } catch (Exception ex) {
+                               // Console.WriteLine (ex);
+                               return Token.ERROR;
+                       }
+
+                       // Console.WriteLine ("Success");
+                       val =temp;
+                       return Token.LITERAL_DATE;
                }
                
                private int ExtractStringOrCharLiteral(int c)
@@ -1045,27 +1174,26 @@
                        return Token.ERROR;
                }
 
-               static IFormatProvider enUSculture = new CultureInfo("en-US", 
true);
+               private object ParseIntLiteral ()
+               {
+                       object retval;
+                       
+                       int d = peekChar ();
+                       
+                       if (!Char.IsDigit ((char) d))
+                               return null;
 
-               private DateTime ParseDateLiteral(StringBuilder value)
-               {
-                       try
-                       {
-                               return DateTime.Parse(value.ToString(),
-                                                 enUSculture,
-                                                 
DateTimeStyles.NoCurrentDateDefault | DateTimeStyles.AllowWhiteSpaces);
-                       }
-                       catch (FormatException ex)
-                       {
-                               //TODO: What is the correct error number and 
message?
-                               Report.Error (1, Location, 
string.Format("Invalid date literal '{0}'", value.ToString()) 
-                                       + Environment.NewLine + ex.ToString());
-                       }
-                       catch (Exception)
-                       {
-                               Report.Error (1, Location, "Error parsing date 
literal");       //TODO: What is the correct error number and message?
-                       }
-                       return new DateTime();
+                       int c = getChar ();
+                       number = new StringBuilder ();
+                       decimal_digits (c);
+
+                       try {
+                               retval = System.Int32.Parse (number.ToString 
());
+                       } catch (Exception ex) {
+                               return null; 
+                       }
+
+                       return retval;
                }
  
                public void PositionCursorAtNextPreProcessorDirective()

Modified: trunk/mcs/bmcs/typemanager.cs
===================================================================
--- trunk/mcs/bmcs/typemanager.cs       2005-03-25 21:22:18 UTC (rev 42260)
+++ trunk/mcs/bmcs/typemanager.cs       2005-03-25 22:05:29 UTC (rev 42261)
@@ -229,6 +229,12 @@
        static public ConstructorInfo invalid_operation_ctor;
        static public ConstructorInfo default_member_ctor;
        static public ConstructorInfo decimal_constant_attribute_ctor;
+
+       //
+       // VB.NET specific
+       //
+
+       static public ConstructorInfo void_datetime_ctor_ticks_arg;
        
        // <remarks>
        //   Holds the Array of Assemblies that have been loaded
@@ -1439,6 +1445,12 @@
                void_decimal_ctor_int_arg = GetConstructor (decimal_type, 
int_arg);
 
                //
+               // VB.NET specific: DateTime constructor
+               //
+               Type [] ticks_arg = { int64_type };
+               void_datetime_ctor_ticks_arg = GetConstructor ( date_type, 
ticks_arg);
+
+               //
                // Attributes
                //
                cons_param_array_attribute = GetConstructor (

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to