summaryrefslogtreecommitdiff
path: root/src/msil/ch/epfl/lamp/compiler/msil/MethodAttributes.java
blob: a703c38fb84179a3712860950578dac5639708a4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
 * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
 */


package ch.epfl.lamp.compiler.msil;

/** Specifies flags for method attributes.
 *
 * @author Nikolay Mihaylov
 * @version 1.0
 */
public final class MethodAttributes {

    //##########################################################################
    // Method access attributes

    /** Bitmask used to retrieve accessibility information. */
    public static final short MemberAccessMask = 0x0007;

    ///** Member not referenceable*/
    //public static final short CompilerConstrolled = 0x0000;

    /** Indicates that the member cannot be referenced. */
    public static final short PrivateScope = 0x0000;

    /** Method is accessible only by the current class. */
    public static final short Private = 0x0001;

    /** Method is accessible to members of this type
     *  and its derived types that are in this assembly only. */
    public static final short FamANDAssem = 0x0002;

    /** Method is accessible to any class of this assembly. */
    public static final short Assembly = 0x0003;

    /** Method is accessible only to members of this class
     *  and its derived classes. */
    public static final short Family = 0x0004;

    /** Method is accessible to derived classes anywhere,
     *  as well as to any class in the assembly. */
    public static final short FamORAssem = 0x0005;

    /** Method is accessible to any object for which this object is in scope. */
    public static final short Public = 0x0006;


    //##########################################################################
    // Flags

    /** Method is defined on the type; otherwise, it is defined per instance. */
    public static final short Static = 0x0010;

    /** Method cannot be overridden. */
    public static final short Final = 0x0020;

    /** Method is virtual. */
    public static final short Virtual = 0x0040;

    /** Method hides by name and signature; otherwise, by name only. */
    public static final short HideBySig  = 0x0080;


    //##########################################################################
    // vtable attributes

    /** Bitmask used to retrieve vtable attributes. */
    public static final short VtableLayoutMask = 0x0100;

    /** Method reuses existing slot in the vtable. */
    public static final short ReuseSlot = 0x0000;


    /** Method always gets a new slot in the vtable. */
    public static final short NewSlot = 0x0100;


    //##########################################################################
    // Flags

    /** Method does not provide implementation. */
    public static final short Abstract = 0x0400;

    /** Method is special. */
    public static final short SpecialName = 0x0800;


    //##########################################################################
    // Interop attributes

    /** Method implementation is forwarded through PInvoke. */
    public static final short PInvokeImpl = 0x2000;

    /** Reserved: shall be zero for conforming implementations.
     *  Managed method is exported by thunk to unmanaged code. */
    public static final short UnmanagedExport = 0x0008;


    //##########################################################################
    // Additional flags

    /** CLI provides special behavior, depending on the name of the method. */
    public static final short RTSpecialName = 0x1000;

    /** Method has security associated with it.
     * Reserved flag for runtime use only.
     */
    public static final short HasSecurity = 0x00000040;

    /**
     * Indicates that the method calls another method containing security code.
     * Reserved flag for runtime use only.
     */
    public static final short RequireSecObject = 0x00004000;

    /** Indicates a reserved flag for runtime use only. */
    public static final short ReservedMask = 0x0000;


    //##########################################################################

    public static String toString(short attrs) {
	StringBuffer str = new StringBuffer(accessFlagsToString(attrs));
	if ((attrs & Static) != 0) str.append(" static");
	if ((attrs & Final) != 0) str.append(" final");
	if ((attrs & Virtual) != 0) str.append(" virtual");
	if ((attrs & Abstract) != 0) str.append(" abstract");
	if ((attrs & HideBySig) != 0) str.append(" hidebysig");
	if ((attrs & NewSlot) != 0) str.append(" newslot");
	if ((attrs & SpecialName) != 0) str.append(" specialname");
	if ((attrs & PInvokeImpl) != 0) str.append(" pinvokeimpl(?!?)");
	if ((attrs & RTSpecialName) != 0) str.append(" rtspecialname");
	return str.toString();

    }

    public static String accessFlagsToString(short attrs) {
	switch (attrs & MemberAccessMask) {
	case PrivateScope: return "compilercontrolled";
	case Private:      return "private";
	case FamANDAssem:  return "famandassem";
	case Assembly:     return "assembly";
	case Family:       return "family";
	case FamORAssem:   return "famorassem";
	case Public:       return "public";
	default: return "xxx";
	}
    }

    //##########################################################################

    // makes the class uninstantiable
    private MethodAttributes() {}

    //##########################################################################

}  // class Method Attributes