2007-01-28 Miguel de Icaza <miguel@novell.com>
[mono.git] / mcs / mcs / modifiers.cs
index 268f4f79337c28fbe40755ec0744fc2a97ed29dd..566a8f67604c4610070a1f149b398897ab8babdc 100644 (file)
@@ -28,11 +28,14 @@ namespace Mono.CSharp {
                public const int TOP       = 0x2000;
 
                public const int PROPERTY_CUSTOM = 0x4000; // Custom property modifier
+               public const int PARTIAL   = 0x20000;
+               public const int DEFAULT_ACCESS_MODIFER = 0x40000;
 
                //
                // We use this internally to flag that the method contains an iterator
                //
                public const int METHOD_YIELDS = 0x8000;
+               public const int METHOD_GENERIC = 0x10000;
 
                public const int Accessibility =
                        PUBLIC | PROTECTED | INTERNAL | PRIVATE;
@@ -77,6 +80,26 @@ namespace Mono.CSharp {
                        return s;
                }
 
+               public static string GetDescription (MethodAttributes ma)
+               {
+                       if ((ma & MethodAttributes.Assembly) != 0)
+                               return "internal";
+
+                       if ((ma & MethodAttributes.Family) != 0)
+                               return "protected";
+
+                       if ((ma & MethodAttributes.Public) != 0)
+                               return "public";
+
+                       if ((ma & MethodAttributes.FamANDAssem) != 0)
+                               return "protected internal";
+
+                       if ((ma & MethodAttributes.Private) != 0)
+                               return "private";
+
+                       throw new NotImplementedException (ma.ToString ());
+               }
+
                public static TypeAttributes TypeAttr (int mod_flags, bool is_toplevel)
                {
                        TypeAttributes t = 0;
@@ -106,19 +129,6 @@ namespace Mono.CSharp {
 
                        return t;
                }
-               
-               public static TypeAttributes TypeAttr (int mod_flags, TypeContainer caller)
-               {
-                       TypeAttributes t = TypeAttr (mod_flags, caller.IsTopLevel);
-
-                       // If we do not have static constructors, static methods
-                       // can be invoked without initializing the type.
-                       if (!caller.UserDefinedStaticConstructor &&
-                           (caller.Kind != Kind.Interface))
-                               t |= TypeAttributes.BeforeFieldInit;
-                               
-                       return t;
-               }
 
                public static FieldAttributes FieldAttr (int mod_flags)
                {
@@ -199,11 +209,7 @@ namespace Mono.CSharp {
                                int a = mod;
 
                                if ((mod & Modifiers.UNSAFE) != 0){
-                                       if (!RootContext.Unsafe){
-                                               Report.Error (227, l,
-                                                             "Unsafe code requires the -unsafe command " +
-                                                             "line option to be specified");
-                                       }
+                                       RootContext.CheckUnsafeOption (l);
                                }
                                
                                //
@@ -212,6 +218,8 @@ namespace Mono.CSharp {
                                //
                                if ((mod & Accessibility) == 0){
                                        mod |= def_access;
+                                       if (def_access != 0)
+                                               mod |= DEFAULT_ACCESS_MODIFER;
                                        return mod;
                                }
 
@@ -243,7 +251,7 @@ namespace Mono.CSharp {
 
                public static void Error_InvalidModifier (Location l, string name)
                {
-                       Report.Error (106, l, "the modifier " + name + " is not valid for this item");
+                       Report.Error (106, l, "The modifier `" + name + "' is not valid for this item");
                }
        }
 }