2008-11-06 Jonathan Pobst <monkey@jpobst.com>
[mono.git] / mcs / mcs / typemanager.cs
index e1ccc3eb26495b561c14a2bb104a0fa6b9f4785d..8e103f54ee6a639e5e2665ae5e7e85b5d9c2ebee 100644 (file)
@@ -600,36 +600,51 @@ namespace Mono.CSharp {
                if (t == typeof (AnonymousMethodBody))
                        return "anonymous method";
 
-               return CSharpName (GetFullName (t));
-    }
+               if (t == null)
+                       return "internal error";
+
+               return CSharpName (GetFullName (t), t);
+       }
 
        static readonly char [] elements = new char [] { '*', '[' };
 
-       public static string CSharpName (string name)
+       public static string CSharpName (string name, Type type)
        {
                if (name.Length > 10) {
+                       string s;
                        switch (name) {
-                       case "System.Int32": return "int";
-                       case "System.Int64": return "long";
-                       case "System.String": return "string";
-                       case "System.Boolean": return "bool";
-                       case "System.Void": return "void";
-                       case "System.Object": return "object";
-                       case "System.UInt32": return "uint";
-                       case "System.Int16": return "short";
-                       case "System.UInt16": return "ushort";
-                       case "System.UInt64": return "ulong";
-                       case "System.Single": return "float";
-                       case "System.Double": return "double";
-                       case "System.Decimal": return "decimal";
-                       case "System.Char": return "char";
-                       case "System.Byte": return "byte";
-                       case "System.SByte": return "sbyte";
+                       case "System.Int32": s = "int"; break;
+                       case "System.Int64": s = "long"; break;
+                       case "System.String": s = "string"; break;
+                       case "System.Boolean": s = "bool"; break;
+                       case "System.Void": s = "void"; break;
+                       case "System.Object": s = "object"; break;
+                       case "System.UInt32": s = "uint"; break;
+                       case "System.Int16": s = "short"; break;
+                       case "System.UInt16": s = "ushort"; break;
+                       case "System.UInt64": s = "ulong"; break;
+                       case "System.Single": s = "float"; break;
+                       case "System.Double": s = "double"; break;
+                       case "System.Decimal": s = "decimal"; break;
+                       case "System.Char": s = "char"; break;
+                       case "System.Byte": s = "byte"; break;
+                       case "System.SByte": s = "sbyte"; break;
+                       default: s = null; break;
+                       }
+
+                       if (s != null) {
+                               //
+                               // Predefined names can come from mscorlib only
+                               //
+                               if (type == null || type.Module.Name == "mscorlib.dll" || !RootContext.StdLib)
+                                       return s;
+                                       
+                               return name;
                        }
 
                        int idx = name.IndexOfAny (elements, 10);
                        if (idx > 0)
-                               return CSharpName (name.Substring (0, idx)) + name.Substring (idx);
+                               return CSharpName (name.Substring (0, idx), type) + name.Substring (idx);
                }
 
                if (name [0] == AnonymousTypeClass.ClassNamePrefix [0] && name.StartsWith (AnonymousTypeClass.ClassNamePrefix))
@@ -770,8 +785,14 @@ namespace Mono.CSharp {
                if (!mb.IsConstructor && TypeManager.IsSpecialMethod (mb)) {
                        string op_name = Operator.GetName (mb.Name);
                        if (op_name != null) {
-                               sig.Append ("operator ");
-                               sig.Append (op_name);
+                               if (op_name == "explicit" || op_name == "implicit") {
+                                       sig.Append (op_name);
+                                       sig.Append (" operator ");
+                                       sig.Append (CSharpName (((MethodInfo)mb).ReturnType));
+                               } else {
+                                       sig.Append ("operator ");
+                                       sig.Append (op_name);
+                               }
                                sig.Append (parameters);
                                return sig.ToString ();
                        }
@@ -1034,6 +1055,28 @@ namespace Mono.CSharp {
        //
        public static void InitOptionalCoreTypes ()
        {
+               system_string_expr.Type = string_type;
+               system_boolean_expr.Type = bool_type;
+               system_decimal_expr.Type = decimal_type;
+               system_single_expr.Type = float_type;
+               system_double_expr.Type = double_type;
+               system_sbyte_expr.Type = sbyte_type;
+               system_byte_expr.Type = byte_type;
+               system_int16_expr.Type = short_type;
+               system_uint16_expr.Type = ushort_type;
+               system_int32_expr.Type = int32_type;
+               system_uint32_expr.Type = uint32_type;
+               system_int64_expr.Type = int64_type;
+               system_uint64_expr.Type = uint64_type;
+               system_char_expr.Type = char_type;
+               system_void_expr.Type = void_type;
+
+               //
+               // These are only used for compare purposes
+               //
+               anonymous_method_type = typeof (AnonymousMethodBody);
+               null_type = typeof (NullLiteral);
+               
                void_ptr_type = GetPointerType (void_type);
                char_ptr_type = GetPointerType (char_type);
 
@@ -1057,7 +1100,7 @@ namespace Mono.CSharp {
                if (obsolete_attribute_type != null) {
                        Class c = TypeManager.LookupClass (obsolete_attribute_type);
                        if (c != null)
-                               c.DefineMembers ();
+                               c.Define ();
                }
 
                dllimport_type = CoreLookupType ("System.Runtime.InteropServices", "DllImportAttribute", Kind.Class, false);
@@ -1132,28 +1175,6 @@ namespace Mono.CSharp {
                                        TypeManager.CSharpName (system_4_type_arg));
                        }
                }
-
-               system_string_expr.Type = string_type;
-               system_boolean_expr.Type = bool_type;
-               system_decimal_expr.Type = decimal_type;
-               system_single_expr.Type = float_type;
-               system_double_expr.Type = double_type;
-               system_sbyte_expr.Type = sbyte_type;
-               system_byte_expr.Type = byte_type;
-               system_int16_expr.Type = short_type;
-               system_uint16_expr.Type = ushort_type;
-               system_int32_expr.Type = int32_type;
-               system_uint32_expr.Type = uint32_type;
-               system_int64_expr.Type = int64_type;
-               system_uint64_expr.Type = uint64_type;
-               system_char_expr.Type = char_type;
-               system_void_expr.Type = void_type;
-
-               //
-               // These are only used for compare purposes
-               //
-               anonymous_method_type = typeof (AnonymousMethodBody);
-               null_type = typeof (NullLiteral);
        }
 
        const BindingFlags instance_and_static = BindingFlags.Static | BindingFlags.Instance;
@@ -1618,6 +1639,11 @@ namespace Mono.CSharp {
                return false;
        }
 
+       public static bool IsSpecialType (Type t)
+       {
+               return t == arg_iterator_type || t == typed_reference_type;
+       }
+
        //
        // Checks whether `extern_type' is friend of the output assembly
        //
@@ -1688,10 +1714,9 @@ namespace Mono.CSharp {
 
        static void Error_FriendAccessNameNotMatching (string other_name)
        {
-               Report.Error (281, "Friend access was granted to `" + other_name + 
-                               "', but the output assembly is named `" + CodeGen.Assembly.Name.FullName +
-                               "'. Try adding a reference to `" + other_name + 
-                               "' or change the output assembly name to match it");
+               Report.Error (281,
+                       "Friend access was granted to `{0}', but the output assembly is named `{1}'. Try adding a reference to `{0}' or change the output assembly name to match it",
+                       other_name, CodeGen.Assembly.Name.FullName);
        }
 #endif