2001-12-18 Miguel de Icaza <miguel@ximian.com>
[mono.git] / mcs / mcs / modifiers.cs
index 32a2b5e605adb9d866a927792933d844c6386f2c..781a6705bc11188dddb0bd009ed480154c73d510 100755 (executable)
@@ -4,7 +4,7 @@
 using System;
 using System.Reflection;
 
-namespace CIR {
+namespace Mono.CSharp {
        public class Modifiers {
 
                //
@@ -62,39 +62,39 @@ namespace CIR {
                        return s;
                }
 
-               public static TypeAttributes TypeAttr (int mod_flags, TypeContainer parent)
+               public static TypeAttributes TypeAttr (int mod_flags, TypeContainer caller)
                {
                        TypeAttributes t = 0;
+                       bool top_level = caller.IsTopLevel;
                        
-                       if ((mod_flags & PUBLIC) != 0 && parent.IsTopLevel == true)
-                               t |= TypeAttributes.Public;
-                       else if ((mod_flags & PUBLIC) != 0)
-                               t |= TypeAttributes.NestedPublic;
-                       
-                       if ((mod_flags & PRIVATE) != 0 && parent.IsTopLevel == true)
-                               t |= TypeAttributes.NotPublic;
-                       else if ((mod_flags & PRIVATE) != 0)
-                               t |= TypeAttributes.NestedPrivate;
-
-                       if ((mod_flags & PROTECTED) != 0 && (mod_flags & INTERNAL) != 0 && parent.IsTopLevel == false)
-                               t |= TypeAttributes.NestedFamANDAssem;
-                       if ((mod_flags & PROTECTED) != 0 && parent.IsTopLevel == false)
-                               t |= TypeAttributes.NestedFamily;
-                       if ((mod_flags & INTERNAL) != 0 && parent.IsTopLevel == false)
-                               t |= TypeAttributes.NestedAssembly;
+                       if (top_level){
+                               if ((mod_flags & PUBLIC) != 0)
+                                       t |= TypeAttributes.Public;
+                               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;
+                       }
                        
-
                        if ((mod_flags & SEALED) != 0)
                                t |= TypeAttributes.Sealed;
                        if ((mod_flags & ABSTRACT) != 0)
                                t |= TypeAttributes.Abstract;
 
-                       // If we have static constructors, the runtime needs to
-                       // initialize the class, otherwise we can optimize
-                       // the case.
-                       if (parent.HaveStaticConstructor)
+                       // If we do not have static constructors, static methods
+                       // can be invoked without initializing the type.
+                       if (!caller.HaveStaticConstructor)
                                t |= TypeAttributes.BeforeFieldInit;
-                       
+                               
                        return t;
                }
 
@@ -107,7 +107,7 @@ namespace CIR {
                        if ((mod_flags & PRIVATE) != 0)
                                fa |= FieldAttributes.Private;
                        if ((mod_flags & PROTECTED) != 0 && (mod_flags & INTERNAL) != 0)
-                               fa |= FieldAttributes.FamANDAssem;
+                               fa |= FieldAttributes.FamORAssem;
                        if ((mod_flags & PROTECTED) != 0)
                                fa |= FieldAttributes.Family;
                        if ((mod_flags & INTERNAL) != 0)
@@ -130,7 +130,7 @@ namespace CIR {
                        if ((mod_flags & PRIVATE) != 0)
                                ma |= MethodAttributes.Private;
                        if ((mod_flags & PROTECTED) != 0 && (mod_flags & INTERNAL) != 0)
-                               ma |= MethodAttributes.FamANDAssem;
+                               ma |= MethodAttributes.FamORAssem;
                        if ((mod_flags & PROTECTED) != 0)
                                ma |= MethodAttributes.Family;
                        if ((mod_flags & INTERNAL) != 0)
@@ -139,13 +139,21 @@ namespace CIR {
 
                        if ((mod_flags & STATIC) != 0)
                                ma |= MethodAttributes.Static;
-                       if ((mod_flags & ABSTRACT) != 0)
-                               ma |= MethodAttributes.Abstract;
+                       if ((mod_flags & ABSTRACT) != 0){
+                               ma |= MethodAttributes.Abstract | MethodAttributes.Virtual |
+                                       MethodAttributes.NewSlot;
+                       }
                        if ((mod_flags & SEALED) != 0)
                                ma |= MethodAttributes.Final;
                        if ((mod_flags & VIRTUAL) != 0)
                                ma |= MethodAttributes.Virtual;
 
+                       if ((mod_flags & OVERRIDE) != 0)
+                               ma |= MethodAttributes.Virtual;
+                       
+                       if ((mod_flags & NEW) != 0)
+                               ma |= MethodAttributes.HideBySig;
+                       
                        return ma;
                }