2001-12-20 Miguel de Icaza <miguel@ximian.com>
authorMiguel de Icaza <miguel@gnome.org>
Fri, 21 Dec 2001 00:51:29 +0000 (00:51 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Fri, 21 Dec 2001 00:51:29 +0000 (00:51 -0000)
* literal.cs: Revert code from ravi that checked the bounds.  The
bounds are sane by the definition of the type itself.

* typemanager.cs: Fix implementation of ImplementsInterface.  We
need to actually look up in our parent hierarchy for interfaces
implemented.

svn path=/trunk/mcs/; revision=1662

mcs/mcs/ChangeLog
mcs/mcs/const.cs
mcs/mcs/driver.cs
mcs/mcs/ecore.cs
mcs/mcs/expression.cs
mcs/mcs/literal.cs
mcs/mcs/report.cs
mcs/mcs/typemanager.cs

index fe76df8bb18ee8bbd0a2921c3234f16accc7807f..2dee4a8c6eef1eb7bc8c18caf73a4d2db553b141 100755 (executable)
@@ -1,5 +1,12 @@
 2001-12-20  Miguel de Icaza  <miguel@ximian.com>
 
+       * literal.cs: Revert code from ravi that checked the bounds.  The
+       bounds are sane by the definition of the type itself. 
+
+       * typemanager.cs: Fix implementation of ImplementsInterface.  We
+       need to actually look up in our parent hierarchy for interfaces
+       implemented. 
+
        * const.cs: Use the underlying type for enumerations
 
        * delegate.cs: Compute the basename for the delegate creation,
index f8936e194534e3edaa7f15840ed06c98fdebce4a..cdc0292c47c6f3e4e08744fa0cf7da5fa8772121 100755 (executable)
@@ -8,6 +8,15 @@
 //
 //
 
+//
+// This is needed because the following situation arises:
+//
+//     The FieldBuilder is declared with the real type for an enumeration
+//
+//     When we attempt to set the value for the constant, the FieldBuilder.SetConstant
+//     function aborts because it requires its argument to be of the same type
+//
+
 namespace Mono.CSharp {
 
        using System;
@@ -49,6 +58,16 @@ namespace Mono.CSharp {
                        }
                }
 
+               void dump_tree (Type t)
+               {
+                       Console.WriteLine ("Dumping hierarchy");
+                       while (t != null){
+                               Console.WriteLine ("   " + t.FullName + " " +
+                                       (t.GetType ().IsEnum ? "yes" : "no"));
+                               t = t.BaseType;
+                       }
+               }
+
                /// <summary>
                ///   Defines the constant in the @parent
                /// </summary>
@@ -81,10 +100,6 @@ namespace Mono.CSharp {
                        } else if ((ModFlags & Modifiers.NEW) != 0)
                                WarningNotHiding (parent);
 
-                       if (type.IsSubclassOf (TypeManager.enum_type)){
-                               type = System.Enum.GetUnderlyingType (type);
-                       }
-                       
                        FieldBuilder = parent.TypeBuilder.DefineField (Name, type, FieldAttr);
 
                        TypeManager.RegisterConstant (FieldBuilder, this);
@@ -116,6 +131,14 @@ namespace Mono.CSharp {
                        }
 
                        ConstantValue = ((Literal) Expr).GetValue ();
+
+                       if (type.IsEnum){
+                               //
+                               // This sadly does not work for our user-defined enumerations types ;-(
+                               //
+                               ConstantValue = System.Enum.ToObject (
+                                       type, ConstantValue);
+                       }
                        
                        FieldBuilder.SetConstant (ConstantValue);
 
index f813e6330e1f07a57325e40b2c8b39d6dfb0e975..31b885c8a1dba6fede0340a7eb1bd0bbc43b56ea 100755 (executable)
@@ -82,6 +82,7 @@ namespace Mono.CSharp
                                "   --checked       Set default context to checked\n" +
                                "   --define SYM    Defines the symbol SYM\n" + 
                                "   --fatal         Makes errors fatal\n" +
+                               "   --stacktrace    Shows stack trace at error location\n" +
                                "   -L PATH         Adds PATH to the assembly link path\n" +
                                "   --nostdlib      Does not load core libraries\n" +
                                "   --nowarn XXX    Ignores warning number XXX\n" +
@@ -177,10 +178,9 @@ namespace Mono.CSharp
                static public int LoadReferences ()
                {
                        int errors = 0;
-                       
-                       foreach (string r in references){
+
+                       foreach (string r in references)
                                errors += LoadAssembly (r);
-                       }
 
                        return errors;
                }
@@ -248,10 +248,12 @@ namespace Mono.CSharp
 
                                if (arg.StartsWith ("@")){
                                        string [] new_args, extra_args;
-
-                                       extra_args = LoadArgs (arg.Substring (1));
+                                       string response_file = arg.Substring (1);
+                                       
+                                       extra_args = LoadArgs (response_file);
                                        if (extra_args == null){
-                                               Usage (true);
+                                               Report.Error (2011, "Unable to open response file: " +
+                                                             response_file);
                                                return;
                                        }
 
@@ -321,6 +323,10 @@ namespace Mono.CSharp
                                        case "--checked":
                                                RootContext.Checked = true;
                                                continue;
+
+                                       case "--stacktrace":
+                                               Report.Stacktrace = true;
+                                               continue;
                                                
                                        case "--target":
                                                if ((i + 1) >= argc){
index 3c3467a9a8a329f49b8a97292c131b7672ab9d11..239a126bd21c8cf9bde64b1ec1f0a096465c819c 100755 (executable)
@@ -305,7 +305,11 @@ namespace Mono.CSharp {
                                return new IntLiteral ((int) ((byte)v));
                        else if (t == TypeManager.char_type)
                                return new IntLiteral ((int) ((char)v));
-                       else
+                       else if (TypeManager.IsEnumType (t)){
+                               Expression e = Literalize (v, v.GetType ());
+
+                               return new EnumLiteral (e, t);
+                       } else
                                throw new Exception ("Unknown type for literal (" + t +
                                                     "), details: " + v);
                }
@@ -322,7 +326,7 @@ namespace Mono.CSharp {
                        else if (mi is PropertyInfo)
                                return new PropertyExpr ((PropertyInfo) mi, loc);
                        else if (mi is Type){
-                               return new TypeExpr ((Type) mi);
+                               return new TypeExpr ((System.Type) mi);
                        }
 
                        return null;
@@ -2064,6 +2068,34 @@ namespace Mono.CSharp {
                        throw new Exception ("Invalid enumeration underlying type: " + t);
                }
 
+               //
+               // Extracts the value in the enumeration on its native representation
+               //
+               public object GetPlainValue ()
+               {
+                       Type t = Child.Type.UnderlyingSystemType;
+                       object v = ((Literal) Child).GetValue ();;
+                       
+                       if (t == TypeManager.int32_type)
+                               return (int) v;
+                       if (t == TypeManager.uint32_type)
+                               return (uint) v;
+                       if (t == TypeManager.int64_type)
+                               return (long) v;
+                       if (t == TypeManager.uint64_type)
+                               return (ulong) v;
+                       if (t == TypeManager.short_type)
+                               return (short) v;
+                       if (t == TypeManager.ushort_type)
+                               return (ushort) v;
+                       if (t == TypeManager.byte_type)
+                               return (byte) v;
+                       if (t == TypeManager.sbyte_type)
+                               return (sbyte) v;
+
+                       return null;
+               }
+               
                public override string AsString ()
                {
                        return ((Literal) Child).AsString ();
@@ -2581,7 +2613,8 @@ namespace Mono.CSharp {
                                        
                                        if (c != null) {
                                                object o = c.LookupConstantValue (ec);
-                                               Expression l = Literalize (o, fi.FieldType);
+                                               object real_value = ((Literal)c.Expr).GetValue ();
+                                               Expression l = Literalize (real_value, fi.FieldType);
                                                l = l.Resolve (ec);
                                                return ((Literal) l);
                                        }
index 7a03091d01a907d93001b9ae3fd4144355fd9121..35135c407206b522f7986ced758cf9f482388b10 100755 (executable)
@@ -1316,20 +1316,48 @@ namespace Mono.CSharp {
                                return new StringLiteral (ls.Value + rs.Value);
                        }
 
-                       if (left is EnumLiteral)
-                               left = ((EnumLiteral) left).WidenToCompilerLiteral ();
-                       if (right is EnumLiteral)
-                               right = ((EnumLiteral) right).WidenToCompilerLiteral ();
+                       Type result_type = null;
+                       object l, r;
                        
+                       //
+                       // Enumerator folding
+                       //
+                       if (left.Type == right.Type && left is EnumLiteral){
+                               result_type = left.Type;
+
+                               l = ((EnumLiteral)left).GetPlainValue ();
+                               r = ((EnumLiteral)right).GetPlainValue ();
+                       } else {
+                               l = left;
+                               r = right;
+                       }
+
                        switch (oper){
-                               case Operator.BitwiseOr:
-                                       if (left is IntLiteral && right is IntLiteral){
-                                               IntLiteral ll = (IntLiteral) left;
-                                               IntLiteral rl = (IntLiteral) right;
-                                               
-                                               return new IntLiteral (ll.Value | rl.Value).Resolve (ec);
-                                       }
-                                       break;
+                       case Operator.BitwiseOr:
+                               if ((l is int) && (r is int)){
+                                       IntLiteral v;
+                                       int res = (int)l | (int)r;
+                                       
+                                       v = new IntLiteral (res);
+                                       if (result_type == null)
+                                               return v.Resolve (ec);
+                                       else
+                                               return new EnumLiteral (v.Resolve (ec), result_type);
+                               }
+                               break;
+                               
+                       case Operator.BitwiseAnd:
+                               if ((l is int) && (r is int)){
+                                       IntLiteral v;
+                                       int res = (int)l & (int)r;
+                                       
+                                       v = new IntLiteral (res);
+                                       if (result_type == null)
+                                               return v.Resolve (ec);
+                                       else
+                                               return new EnumLiteral (v.Resolve (ec), result_type);
+                               }
+                               break;
                        }
                                        
                        return null;
@@ -4032,8 +4060,8 @@ namespace Mono.CSharp {
                                        return ee;
                                }
                        }
-                       
-                       Console.WriteLine ("Support for [" + member_lookup + "] is not present yet");
+
+                       Report.Error (-100, loc, "Support for [" + member_lookup + "] is not present yet");
                        Environment.Exit (0);
                        return null;
                }
index 93e6a2a822108e57d7adbcd1a105de7e015f0ded..b57c03abcdee164504ffe8ff2616637bf0d8ea6a 100755 (executable)
@@ -169,11 +169,7 @@ namespace Mono.CSharp {
 
                public override object GetValue ()
                {
-                       if (Value <= System.Int32.MaxValue &&
-                           Value >= System.Int32.MinValue)
-                               return (object) Value;
-                       else
-                               return null;
+                       return (object) Value;
                }
 
                public override Expression DoResolve (EmitContext ec)
@@ -258,12 +254,7 @@ namespace Mono.CSharp {
 
                public override object GetValue ()
                {
-                       if (Value <= System.UInt32.MaxValue &&
-                           Value >= System.UInt32.MinValue)
-                               return (object) Value;
-                       else
-                               return null;
-
+                       return (object) Value;
                }
                
                public override Expression DoResolve (EmitContext ec)
@@ -297,11 +288,7 @@ namespace Mono.CSharp {
 
                public override object GetValue ()
                {
-                       if (Value <= System.Int64.MaxValue &&
-                           Value >= System.Int64.MinValue)
-                               return (object) Value;
-                       else
-                               return null;
+                       return (object) Value;
                }
                
                public override Expression DoResolve (EmitContext ec)
@@ -339,11 +326,7 @@ namespace Mono.CSharp {
 
                public override object GetValue ()
                {
-                       if (Value <= System.UInt64.MaxValue &&
-                           Value >= System.UInt64.MinValue)
-                               return (object) Value;
-                       else
-                               return null;
+                       return (object) Value;
                }
 
                public override Expression DoResolve (EmitContext ec)
index 5626b656c9e13389e1793d9ea625f9355d2ae2df..44ebd9d50188f912520e820f63a23b4891235c15 100644 (file)
@@ -8,6 +8,7 @@
 
 using System;
 using System.Collections;
+using System.Diagnostics;
 
 namespace Mono.CSharp {
 
@@ -15,15 +16,30 @@ namespace Mono.CSharp {
        ///   This class is used to report errors and warnings t te user.
        /// </summary>
        public class Report {
-               static int errors;
-               static int warnings;
-
-               // whether errors are fatal (they throw an exception), useful
-               // for debugging the compiler
-               static bool fatal;
-
-               // whether we consider warnings to be errors.
-               static bool warnings_are_errors;
+               /// <summary>  
+               ///   Errors encountered so far
+               /// </summary>
+               static public int Errors;
+
+               /// <summary>  
+               ///   Warnings encountered so far
+               /// </summary>
+               static public int Warnings;
+
+               /// <summary>  
+               ///   Whether errors should be throw an exception
+               /// </summary>
+               static public bool Fatal;
+               
+               /// <summary>  
+               ///   Whether warnings should be considered errors
+               /// </summary>
+               static public bool WarningsAreErrors;
+
+               /// <summary>  
+               ///   Whether to dump a stack trace on errors. 
+               /// </summary>
+               static public bool Stacktrace;
                
                //
                // If the error code is reported on the given line,
@@ -48,10 +64,12 @@ namespace Mono.CSharp {
                
                static public void RealError (string msg)
                {
-                       errors++;
+                       Errors++;
                        Console.WriteLine (msg);
 
-                       if (fatal)
+                       if (Stacktrace)
+                               Console.WriteLine (new StackTrace ().ToString ());
+                       if (Fatal)
                                throw new Exception (msg);
                }
                       
@@ -71,7 +89,7 @@ namespace Mono.CSharp {
                                        return;
                        }
                        
-                       if (warnings_are_errors)
+                       if (WarningsAreErrors)
                                Error (code, l, text);
                        else {
                                string row;
@@ -82,7 +100,7 @@ namespace Mono.CSharp {
                                        row = l.Row.ToString ();
                                
                                Console.WriteLine (l.Name + "(" + row + "): warning CS"+code+": " + text);
-                               warnings++;
+                               Warnings++;
                                Check (code);
                        }
                }
@@ -127,34 +145,6 @@ namespace Mono.CSharp {
                                return probe_error;
                        }
                }
-               
-               static public int Errors {
-                       get {
-                               return errors;
-                       }
-               }
-
-               static public int Warnings {
-                       get {
-                               return warnings;
-                       }
-               }
-
-               static public bool Fatal {
-                       set {
-                               fatal = true;
-                       }
-
-                       get {
-                               return fatal;
-                       }
-               }
-
-               static public bool WarningsAreErrors {
-                       set {
-                               warnings_are_errors = true;
-                       }
-               }
        }
 
        public class Message {
index cc77abc9bc6c495b9b59bd6a60d1b49c90ff85cf..86345210843812bdc8bed73adad1762a1c1efda1 100755 (executable)
@@ -338,8 +338,10 @@ public class TypeManager {
        {
                Type t = LookupType (name);
 
-               if (t == null)
-                       throw new Exception ("Can not find core type " + name);
+               if (t == null){
+                       Report.Error (518, "The predefined type `" + name + "' is not defined or imported");
+                       Environment.Exit (0);
+               }
 
                return t;
        }
@@ -771,29 +773,21 @@ public class TypeManager {
        // </remarks>
 
        static Hashtable type_interface_cache;
-
        public static bool ImplementsInterface (Type t, Type iface)
        {
-               Type [] interfaces = (Type []) type_interface_cache [t];
+               Type [] interfaces;
 
-               if (interfaces == null) {
-                       if (type_interface_cache.Contains (t))
-                               return false;
-                       
+               do {
                        interfaces = t.GetInterfaces ();
 
-                       type_interface_cache [t] = interfaces;
-               }
-
-               if (interfaces == null)
-                       return false;
-
-               for (int i = interfaces.Length; i > 0; ) {
-                       i--;
-                       if (interfaces [i] == iface)
-                               return true;
-               }
-
+                       for (int i = interfaces.Length; i > 0; ){
+                               i--;
+                               if (interfaces [i] == iface)
+                                       return true;
+                       }
+                       t = t.BaseType;
+               } while (t != null);
+               
                return false;
        }