* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / Mono.Posix / Mono.Unix.Native / make-map.cs
index d64ec79f55f031c323b9ce4e369ffdcd97649bfb..462c1b5120e1777a000e70436d39890a4b07b94b 100644 (file)
@@ -6,7 +6,7 @@
 //  Jonathan Pryor (jonpryor@vt.edu)
 //
 // (C) 2003 Novell, Inc.
-// (C) 2004 Jonathan Pryor
+// (C) 2004-2005 Jonathan Pryor
 //
 
 //
@@ -32,6 +32,7 @@
 using System;
 using System.Collections;
 using System.IO;
+using System.Globalization;
 using System.Reflection;
 using System.Runtime.InteropServices;
 
@@ -112,7 +113,8 @@ class MakeMap {
                                return 1;
                        if (t2 == null)
                                return -1;
-                       return Comparer.DefaultInvariant.Compare (t1.FullName, t2.FullName);
+                       return CultureInfo.InvariantCulture.CompareInfo.Compare (
+                                       t1.FullName, t2.FullName, CompareOptions.Ordinal);
                }
        }
 
@@ -127,11 +129,29 @@ class MakeMap {
                                return 1;
                        if (m2 == null)
                                return -1;
-                       return Comparer.DefaultInvariant.Compare (m1.Name, m2.Name);
+                       return CultureInfo.InvariantCulture.CompareInfo.Compare (
+                                       m1.Name, m2.Name, CompareOptions.Ordinal);
+               }
+       }
+
+       private class _OrdinalStringComparer : IComparer {
+               public int Compare (object o1, object o2)
+               {
+                       string s1 = o1 as string;
+                       string s2 = o2 as string;
+                       if (object.ReferenceEquals (s1, s2))
+                               return 0;
+                       if (s1 == null)
+                               return 1;
+                       if (s2 == null)
+                               return -1;
+                       return CultureInfo.InvariantCulture.CompareInfo.Compare (s1, s2, 
+                                       CompareOptions.Ordinal);
                }
        }
 
        internal static IComparer MemberNameComparer = new _MemberNameComparer ();
+       internal static IComparer OrdinalStringComparer = new _OrdinalStringComparer ();
 
        internal static string GetNativeName (string fn)
        {
@@ -227,7 +247,8 @@ abstract class FileGenerator {
                if (t.Namespace.StartsWith ("System"))
                        return "int /* warning: unknown mapping for type: " + t.Name + " */";
                string ts = "struct " +
-                       MakeMap.GetNativeName (t.FullName).Replace ("+", "_").Replace ("&", "*");
+                       MakeMap.GetNativeName (t.FullName).Replace ("+", "_").Replace ("&", "*")
+                               .Replace ("[]", "*");
                return ts;
        }
 }
@@ -462,12 +483,13 @@ class ConvertFileGenerator : FileGenerator {
                                        typeof(ObsoleteAttribute), false);
                string obsolete = "";
                if (oa != null) {
-                       obsolete = "[Obsolete (\"" + oa.Message + "\")]\n\t\t";
+                       obsolete = string.Format ("[Obsolete (\"{0}\", {1})]\n\t\t",
+                                       oa.Message, oa.IsError ? "true" : "false");
                }
-               scs.WriteLine ("\t\t[DllImport (LIB, " + 
+               scs.WriteLine ("\t\t{3}[DllImport (LIB, " + 
                        "EntryPoint=\"{0}_From{1}\")]\n" +
                        "\t\tprivate static extern int From{1} ({1} value, out {2} rval);\n",
-                       ns, t.Name, mtype);
+                       ns, t.Name, mtype, obsolete);
                scs.WriteLine ("\t\t{3}public static bool TryFrom{1} ({1} value, out {2} rval)\n" +
                        "\t\t{{\n" +
                        "\t\t\treturn From{1} (value, out rval) == 0;\n" +
@@ -479,10 +501,10 @@ class ConvertFileGenerator : FileGenerator {
                                "\t\t\t\tThrowArgumentException (value);", t.Name);
                scs.WriteLine ("\t\t\treturn rval;");
                scs.WriteLine ("\t\t}\n");
-               scs.WriteLine ("\t\t[DllImport (LIB, " + 
+               scs.WriteLine ("\t\t{3}[DllImport (LIB, " + 
                        "EntryPoint=\"{0}_To{1}\")]\n" +
                        "\t\tprivate static extern int To{1} ({2} value, out {1} rval);\n",
-                       ns, t.Name, mtype);
+                       ns, t.Name, mtype, obsolete);
                scs.WriteLine ("\t\t{2}public static bool TryTo{1} ({0} value, out {1} rval)\n" +
                        "\t\t{{\n" +
                        "\t\t\treturn To{1} (value, out rval) == 0;\n" +
@@ -564,7 +586,7 @@ class ConvertDocFileGenerator : FileGenerator {
         <param name=""value"">The managed value to convert.</param>
         <param name=""rval"">The OS-specific equivalent value.</param>
         <summary>Converts a <see cref=""T:{0}"" /> 
-          to an OS-specific value.</summary>
+          enumeration value to an OS-specific value.</summary>
         <returns><see langword=""true"" /> if the conversion was successful; 
         otherwise, <see langword=""false"" />.</returns>
         <remarks><para>This is an exception-safe alternative to 
@@ -797,7 +819,7 @@ class MphPrototypeFileGenerator : FileGenerator {
        private static IEnumerable Sort (ICollection c)
        {
                ArrayList al = new ArrayList (c);
-               al.Sort ();
+               al.Sort (MakeMap.OrdinalStringComparer);
                return al;
        }