ec.EmitTopBlock (Block, Location);
}
}
-
- public class Field : MemberCore {
+
+ //
+ // Fields and Events both generate FieldBuilders, we use this to share
+ // their common bits. This is also used to flag usage of the field
+ //
+ abstract public class FieldBase : MemberCore {
public readonly string Type;
public readonly Object Initializer;
public readonly Attributes OptAttributes;
[Flags]
public enum Status : byte { ASSIGNED = 1, USED = 2 }
-
+ //
+ // The constructor is only exposed to our children
+ //
+ protected FieldBase (string type, int mod, int allowed_mod, string name,
+ object init, Attributes attrs, Location loc)
+ : base (name, loc)
+ {
+ Type = type;
+ ModFlags = Modifiers.Check (allowed_mod, mod, Modifiers.PRIVATE, loc);
+ Initializer = init;
+ OptAttributes = attrs;
+ }
+ }
+
+ //
+ // The Field class is used to represents class/struct fields during parsing.
+ //
+ public class Field : FieldBase {
// <summary>
// Modifiers allowed in a class declaration
// </summary>
public Field (string type, int mod, string name, Object expr_or_array_init,
Attributes attrs, Location loc)
- : base (name, loc)
+ : base (type, mod, AllowedModifiers, name, expr_or_array_init, attrs, loc)
{
- Type = type;
- ModFlags = Modifiers.Check (AllowedModifiers, mod, Modifiers.PRIVATE, loc);
- Initializer = expr_or_array_init;
- OptAttributes = attrs;
}
public override bool Define (TypeContainer parent)
FieldBuilder = parent.TypeBuilder.DefineField (
Name, t, Modifiers.FieldAttr (ModFlags));
- TypeManager.RegisterField (FieldBuilder, this);
+ TypeManager.RegisterFieldBase (FieldBuilder, this);
return true;
}
}
}
- public class Event : MemberCore {
-
+ public class Event : FieldBase {
const int AllowedModifiers =
Modifiers.NEW |
Modifiers.PUBLIC |
Modifiers.UNSAFE |
Modifiers.ABSTRACT;
- public readonly string Type;
- public readonly Object Initializer;
public readonly Block Add;
public readonly Block Remove;
public MyEventBuilder EventBuilder;
- public FieldBuilder FieldBuilder;
- public Attributes OptAttributes;
Type EventType;
MethodBuilder AddBuilder, RemoveBuilder;
-
- public Event (string type, string name, Object init, int flags, Block add_block,
+ public Event (string type, string name, Object init, int mod, Block add_block,
Block rem_block, Attributes attrs, Location loc)
- : base (name, loc)
+ : base (type, mod, AllowedModifiers, name, init, attrs, loc)
{
- Type = type;
- Initializer = init;
- ModFlags = Modifiers.Check (AllowedModifiers, flags, Modifiers.PRIVATE, loc);
Add = add_block;
Remove = rem_block;
- OptAttributes = attrs;
}
public override bool Define (TypeContainer parent)
EventBuilder = new MyEventBuilder (parent.TypeBuilder, Name, e_attr, EventType);
- if (Add == null && Remove == null)
- FieldBuilder = parent.TypeBuilder.DefineField (Name, EventType, FieldAttributes.Private);
+ if (Add == null && Remove == null){
+ FieldBuilder = parent.TypeBuilder.DefineField (
+ Name, EventType, FieldAttributes.Private);
+ TypeManager.RegisterFieldBase (FieldBuilder, this);
+ }
//
// Now define the accessors
bool is_volatile = false;
if (FieldInfo is FieldBuilder){
- Field f = TypeManager.GetField (FieldInfo);
- if (f != null){
- if ((f.ModFlags & Modifiers.VOLATILE) != 0)
- is_volatile = true;
+ FieldBase f = TypeManager.GetField (FieldInfo);
+
+ if ((f.ModFlags & Modifiers.VOLATILE) != 0)
+ is_volatile = true;
- f.status |= Field.Status.USED;
- }
+ f.status |= Field.Status.USED;
}
if (FieldInfo.IsStatic){
source.Emit (ec);
if (FieldInfo is FieldBuilder){
- Field f = TypeManager.GetField (FieldInfo);
- if (f != null && (f.ModFlags & Modifiers.VOLATILE) != 0)
+ FieldBase f = TypeManager.GetField (FieldInfo);
+
+ if ((f.ModFlags & Modifiers.VOLATILE) != 0)
ig.Emit (OpCodes.Volatile);
}
ig.Emit (OpCodes.Stfld, FieldInfo);
if (FieldInfo is FieldBuilder){
- Field f = TypeManager.GetField (FieldInfo);
+ FieldBase f = TypeManager.GetField (FieldInfo);
f.status |= Field.Status.ASSIGNED;
}
ILGenerator ig = ec.ig;
if (FieldInfo is FieldBuilder){
- Field f = TypeManager.GetField (FieldInfo);
- if (f != null && (f.ModFlags & Modifiers.VOLATILE) != 0)
+ FieldBase f = TypeManager.GetField (FieldInfo);
+ if ((f.ModFlags & Modifiers.VOLATILE) != 0)
ig.Emit (OpCodes.Volatile);
}
if (FieldInfo is FieldBuilder){
- Field f = TypeManager.GetField (FieldInfo);
+ FieldBase f = TypeManager.GetField (FieldInfo);
if ((mode & AddressOp.Store) != 0)
f.status |= Field.Status.ASSIGNED;