2 // modifiers.cs: Modifier handling.
7 public class Modifiers {
10 // The ordering of the following 4 constants
11 // has been carefully done.
13 public const int PROTECTED = 0x0001;
14 public const int PUBLIC = 0x0002;
15 public const int PRIVATE = 0x0004;
16 public const int INTERNAL = 0x0008;
17 public const int NEW = 0x0010;
18 public const int ABSTRACT = 0x0020;
19 public const int SEALED = 0x0040;
20 public const int STATIC = 0x0080;
21 public const int READONLY = 0x0100;
22 public const int VIRTUAL = 0x0200;
23 public const int OVERRIDE = 0x0400;
24 public const int EXTERN = 0x0800;
25 public const int TOP = 0x0800;
27 public const int Accessibility =
28 PUBLIC | PROTECTED | INTERNAL | PRIVATE;
30 static public string Name (int i)
37 case Modifiers.PUBLIC:
39 case Modifiers.PROTECTED:
40 s = "protected"; break;
41 case Modifiers.INTERNAL:
42 s = "internal"; break;
43 case Modifiers.PRIVATE:
45 case Modifiers.ABSTRACT:
46 s = "abstract"; break;
47 case Modifiers.SEALED:
49 case Modifiers.STATIC:
51 case Modifiers.READONLY:
52 s = "readonly"; break;
53 case Modifiers.VIRTUAL:
55 case Modifiers.OVERRIDE:
56 s = "override"; break;
57 case Modifiers.EXTERN:
65 // Checks the object @mod modifiers to be in @allowed.
66 // Returns the new mask. Side effect: reports any
67 // incorrect attributes.
69 public static int Check (int allowed, int mod, int def_access)
71 int invalid_flags = (~allowed) & mod;
74 if (invalid_flags == 0){
78 // If no accessibility bits provided
79 // then provide the defaults.
81 if ((mod & Accessibility) == 0){
87 // Make sure that no conflicting accessibility
88 // bits have been set. Protected+Internal is
89 // allowed, that is why they are placed on bits
90 // 1 and 4 (so the shift 3 basically merges them)
94 a = ((a & 2) >> 1) + (a & 5);
95 a = ((a & 4) >> 2) + (a & 3);
97 CSC.CSharpParser.error (107, "More than one protecion modifier specified");
102 for (i = 1; i < TOP; i <<= 1){
103 if ((i & invalid_flags) == 0)
106 CSC.CSharpParser.error (106, "the modifier `" + Name (i) + "' is not valid for this item");
109 return allowed & mod;