summaryrefslogtreecommitdiff
path: root/src/msil/ch/epfl/lamp/compiler/msil/FieldInfo.java
blob: 536a67e9a83de47129d0b7af9b506c67aa1f644b (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
/*
 * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
 */


package ch.epfl.lamp.compiler.msil;

import ch.epfl.lamp.compiler.msil.util.PECustomMod;

/**
 * Discovers the attributes of a field and provides access to field metadata.
 *
 * @author Nikolay Mihaylov
 * @version 1.0
 */
public class FieldInfo extends MemberInfo implements HasCustomModifiers {

    //##########################################################################
    // public interface

    public final int MemberType() { return MemberTypes.Field; }

    /** Attributes associated with this field. */
    public final short Attributes;

    /** Type of the field represented by this FieldInfo object. */
    public final Type FieldType;

    /** can be null */
    public final CustomModifier[] cmods;

    protected final Object value;

    public final boolean IsStatic() {
	return (Attributes & FieldAttributes.Static)   != 0;
    }

    public final boolean IsInitOnly() {
	return (Attributes & FieldAttributes.InitOnly) != 0;
    }

    public final boolean IsLiteral() {
 	return (Attributes & FieldAttributes.Literal) != 0;

    }

    public final boolean IsPublic() {
	return (Attributes & FieldAttributes.FieldAccessMask)
	    == FieldAttributes.Public;
    }

    public final boolean IsPrivate() {
	return (Attributes & FieldAttributes.FieldAccessMask)
	    == FieldAttributes.Private;
    }

    public final boolean IsFamily() {
	return (Attributes & FieldAttributes.FieldAccessMask)
	    == FieldAttributes.Family;
    }

    public final boolean IsAssembly() {
	return (Attributes & FieldAttributes.FieldAccessMask)
	    == FieldAttributes.Assembly;
    }

    public final boolean IsFamilyOrAssembly() {
	return (Attributes & FieldAttributes.FieldAccessMask)
	    == FieldAttributes.FamORAssem;
    }

    public final boolean IsFamilyAndAssembly() {
	return (Attributes & FieldAttributes.FieldAccessMask)
	    == FieldAttributes.FamANDAssem;
    }
    public final boolean IsSpecialName() {
 	return (Attributes & FieldAttributes.SpecialName) != 0;
    }

    public final boolean IsPinvokeImpl() {
 	return (Attributes & FieldAttributes.PinvokeImpl) != 0;
    }

    public final boolean IsNotSerialized() {
 	return (Attributes & FieldAttributes.NotSerialized) != 0;
    }

    private boolean knownVolatile  = false;
    private boolean cachedVolatile = false;
    public final boolean IsVolatile() {
        if(knownVolatile) return cachedVolatile;
        knownVolatile  = true;
        if(cmods == null) {
            cachedVolatile = false;
            return cachedVolatile;
        }
        for (int idx = 0; idx < cmods.length; idx++) {
            if(cmods[idx].marker == CustomModifier.VolatileMarker()) {
                cachedVolatile = true;
                return cachedVolatile;
            }
        }
        cachedVolatile = false;
        return cachedVolatile;
    }

    public final Type[] GetOptionalCustomModifiers () {
        return CustomModifier.helperCustomMods(false, cmods);
    }

    public final Type[] GetRequiredCustomModifiers() {
        return CustomModifier.helperCustomMods(true, cmods);
    }

    public String toString() {
	return FieldAttributes.toString(Attributes) + " " +
	    FieldType + " " + DeclaringType.FullName + "::" +  Name;
    }

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

    protected static final FieldInfo[] EMPTY_ARRAY = new FieldInfo[0];

    /** Initializes a new instance of the FieldInfo class. */
    protected FieldInfo(String name, Type declType,
			int attrs, PECustomMod fieldTypeWithMods, Object value)
    {
        super(name, declType);
        FieldType = fieldTypeWithMods.marked;
        cmods = fieldTypeWithMods.cmods;
        Attributes = (short) attrs;
        this.value = value;
    }

    /**
     */
    public Object getValue() { return value; }

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

}  // class FieldInfo