using System;
using System.Reflection;
-namespace CIR {
+namespace Mono.CSharp {
public class Modifiers {
//
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;
}
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)
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)
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;
}