X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fmcs%2Fmodifiers.cs;h=a5cf6f62c036aa69c09f8546ef6b5cbd5fdc0024;hb=2b808a73a435ae7c50a5edbd98eb12ba96fef4b5;hp=0e53748c0fc1f510eab871bae6e4d58d251b336a;hpb=773a66abc5e63cc1d2f111daeaa2848891dc8f61;p=mono.git diff --git a/mcs/mcs/modifiers.cs b/mcs/mcs/modifiers.cs index 0e53748c0fc..a5cf6f62c03 100755 --- a/mcs/mcs/modifiers.cs +++ b/mcs/mcs/modifiers.cs @@ -2,8 +2,9 @@ // modifiers.cs: Modifier handling. // using System; +using System.Reflection; -namespace CIR { +namespace Mono.CSharp { public class Modifiers { // @@ -22,7 +23,9 @@ namespace CIR { public const int VIRTUAL = 0x0200; public const int OVERRIDE = 0x0400; public const int EXTERN = 0x0800; - public const int TOP = 0x0800; + public const int VOLATILE = 0x1000; + public const int UNSAFE = 0x2000; + public const int TOP = 0x2000; public const int Accessibility = PUBLIC | PROTECTED | INTERNAL | PRIVATE; @@ -56,17 +59,130 @@ namespace CIR { s = "override"; break; case Modifiers.EXTERN: s = "extern"; break; + case Modifiers.VOLATILE: + s = "volatile"; break; } return s; } + + 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; + } 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; + + 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.HaveStaticConstructor) + t |= TypeAttributes.BeforeFieldInit; + + return t; + } + + public static FieldAttributes FieldAttr (int mod_flags) + { + FieldAttributes fa = 0; + + if ((mod_flags & PUBLIC) != 0) + fa |= FieldAttributes.Public; + if ((mod_flags & PRIVATE) != 0) + fa |= FieldAttributes.Private; + if ((mod_flags & PROTECTED) != 0){ + if ((mod_flags & INTERNAL) != 0) + fa |= FieldAttributes.FamORAssem; + else + fa |= FieldAttributes.Family; + } else { + if ((mod_flags & INTERNAL) != 0) + fa |= FieldAttributes.Assembly; + } + + if ((mod_flags & STATIC) != 0) + fa |= FieldAttributes.Static; + if ((mod_flags & READONLY) != 0) + fa |= FieldAttributes.InitOnly; + + return fa; + } + + public static MethodAttributes MethodAttr (int mod_flags) + { + MethodAttributes ma = 0; + + if ((mod_flags & PUBLIC) != 0) + ma |= MethodAttributes.Public; + if ((mod_flags & PRIVATE) != 0) + ma |= MethodAttributes.Private; + if ((mod_flags & PROTECTED) != 0){ + if ((mod_flags & INTERNAL) != 0) + ma |= MethodAttributes.FamORAssem; + else + ma |= MethodAttributes.Family; + } else { + if ((mod_flags & INTERNAL) != 0) + ma |= MethodAttributes.Assembly; + } + + if ((mod_flags & STATIC) != 0) + ma |= MethodAttributes.Static; + if ((mod_flags & ABSTRACT) != 0){ + ma |= MethodAttributes.Abstract | MethodAttributes.Virtual | + MethodAttributes.HideBySig; + } + if ((mod_flags & SEALED) != 0) + ma |= MethodAttributes.Final; + + if ((mod_flags & VIRTUAL) != 0) + ma |= MethodAttributes.Virtual; + + if ((mod_flags & OVERRIDE) != 0) + ma |= MethodAttributes.Virtual | MethodAttributes.HideBySig; + else { + if ((ma & MethodAttributes.Virtual) != 0) + ma |= MethodAttributes.NewSlot; + } + + if ((mod_flags & NEW) != 0) + ma |= MethodAttributes.HideBySig; + + return ma; + } + // // Checks the object @mod modifiers to be in @allowed. // Returns the new mask. Side effect: reports any // incorrect attributes. // - public static int Check (int allowed, int mod, int def_access) + public static int Check (int allowed, int mod, int def_access, Location l) { int invalid_flags = (~allowed) & mod; int i; @@ -74,6 +190,14 @@ namespace CIR { 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"); + } + } + // // If no accessibility bits provided // then provide the defaults. @@ -94,7 +218,7 @@ namespace CIR { a = ((a & 2) >> 1) + (a & 5); a = ((a & 4) >> 2) + (a & 3); if (a > 1) - CSC.CSharpParser.error (107, "More than one protecion modifier specified"); + Report.Error (107, l, "More than one protection modifier specified"); return mod; } @@ -103,10 +227,15 @@ namespace CIR { if ((i & invalid_flags) == 0) continue; - CSC.CSharpParser.error (106, "the modifier `" + Name (i) + "' is not valid for this item"); + Error_InvalidModifier (l, Name (i)); } return allowed & mod; } + + public static void Error_InvalidModifier (Location l, string name) + { + Report.Error (106, l, "the modifier " + name + " is not valid for this item"); + } } }