2009-03-26 Carlos Alberto Cortez <calberto.cortez@gmail.com>
[mono.git] / mcs / mcs / modifiers.cs
index 268f4f79337c28fbe40755ec0744fc2a97ed29dd..61ff6e47de8348ef791e9cac0928521f87b48389 100644 (file)
@@ -25,14 +25,19 @@ namespace Mono.CSharp {
                public const int EXTERN    = 0x0800;
                public const int VOLATILE  = 0x1000;
                public const int UNSAFE    = 0x2000;
-               public const int TOP       = 0x2000;
+               private const int TOP      = 0x4000;
 
                public const int PROPERTY_CUSTOM = 0x4000; // Custom property modifier
 
                //
-               // We use this internally to flag that the method contains an iterator
+               // Compiler specific flags
                //
-               public const int METHOD_YIELDS = 0x8000;
+               public const int PARTIAL                                = 0x20000;
+               public const int DEFAULT_ACCESS_MODIFER = 0x40000;
+               public const int METHOD_EXTENSION               = 0x80000;
+               public const int COMPILER_GENERATED             = 0x100000;
+               public const int BACKING_FIELD                  = 0x200000;
+               public const int DEBUGGER_HIDDEN                = 0x400000;
 
                public const int Accessibility =
                        PUBLIC | PROTECTED | INTERNAL | PRIVATE;
@@ -77,26 +82,48 @@ namespace Mono.CSharp {
                        return s;
                }
 
+               public static string GetDescription (MethodAttributes ma)
+               {
+                       ma &= MethodAttributes.MemberAccessMask;
+
+                       if (ma == MethodAttributes.Assembly)
+                               return "internal";
+
+                       if (ma == MethodAttributes.Family)
+                               return "protected";
+
+                       if (ma == MethodAttributes.Public)
+                               return "public";
+
+                       if (ma == MethodAttributes.FamORAssem)
+                               return "protected internal";
+
+                       if (ma == MethodAttributes.Private)
+                               return "private";
+
+                       throw new NotImplementedException (ma.ToString ());
+               }
+
                public static TypeAttributes TypeAttr (int mod_flags, bool is_toplevel)
                {
                        TypeAttributes t = 0;
 
                        if (is_toplevel){
                                if ((mod_flags & PUBLIC) != 0)
-                                       t |= TypeAttributes.Public;
-                               if ((mod_flags & PRIVATE) != 0)
-                                       t |= TypeAttributes.NotPublic;
+                                       t = TypeAttributes.Public;
+                               else if ((mod_flags & PRIVATE) != 0)
+                                       t = TypeAttributes.NotPublic;
                        } else {
                                if ((mod_flags & PUBLIC) != 0)
-                                       t |= TypeAttributes.NestedPublic;
-                               if ((mod_flags & PRIVATE) != 0)
-                                       t |= TypeAttributes.NestedPrivate;
-                               if ((mod_flags & PROTECTED) != 0 && (mod_flags & INTERNAL) != 0)
-                                       t |= TypeAttributes.NestedFamORAssem;
-                               if ((mod_flags & PROTECTED) != 0)
-                                       t |= TypeAttributes.NestedFamily;
-                               if ((mod_flags & INTERNAL) != 0)
-                                       t |= TypeAttributes.NestedAssembly;
+                                       t = TypeAttributes.NestedPublic;
+                               else if ((mod_flags & PRIVATE) != 0)
+                                       t = TypeAttributes.NestedPrivate;
+                               else if ((mod_flags & (PROTECTED | INTERNAL)) == (PROTECTED | INTERNAL))
+                                       t = TypeAttributes.NestedFamORAssem;
+                               else if ((mod_flags & PROTECTED) != 0)
+                                       t = TypeAttributes.NestedFamily;
+                               else if ((mod_flags & INTERNAL) != 0)
+                                       t = TypeAttributes.NestedAssembly;
                        }
                        
                        if ((mod_flags & SEALED) != 0)
@@ -106,19 +133,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)
                {
@@ -152,9 +166,9 @@ namespace Mono.CSharp {
 
                        if ((mod_flags & PUBLIC) != 0)
                                ma |= MethodAttributes.Public;
-                       if ((mod_flags & PRIVATE) != 0)
+                       else if ((mod_flags & PRIVATE) != 0)
                                ma |= MethodAttributes.Private;
-                       if ((mod_flags & PROTECTED) != 0){
+                       else if ((mod_flags & PROTECTED) != 0){
                                if ((mod_flags & INTERNAL) != 0)
                                        ma |= MethodAttributes.FamORAssem;
                                else 
@@ -192,18 +206,14 @@ namespace Mono.CSharp {
                // </summary>
                public static int Check (int allowed, int mod, int def_access, Location l)
                {
-                       int invalid_flags  = (~allowed) & mod;
+                       int invalid_flags  = (~allowed) & (mod & (Modifiers.TOP - 1));
                        int i;
 
                        if (invalid_flags == 0){
                                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 +222,8 @@ namespace Mono.CSharp {
                                //
                                if ((mod & Accessibility) == 0){
                                        mod |= def_access;
+                                       if (def_access != 0)
+                                               mod |= DEFAULT_ACCESS_MODIFER;
                                        return mod;
                                }
 
@@ -243,7 +255,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");
                }
        }
 }