{
AdditionResult res;
string name = field.Name;
-
+
if ((res = IsValid (name)) != AdditionResult.Success)
return res;
-
+
if (fields == null)
fields = new ArrayList ();
-
+
fields.Add (field);
if (field.Initializer != null){
if ((field.ModFlags & Modifiers.STATIC) == 0)
have_nonstatic_fields = true;
-
+
DefineName (name, field);
return AdditionResult.Success;
}
get {
return fields;
}
+
+ set {
+ fields = value;
+ }
}
public ArrayList InstanceConstructors {
if (init is Expression)
e = (Expression) init;
else {
- string base_type = f.Type.Substring (0, f.Type.IndexOf ("["));
- string rank = f.Type.Substring (f.Type.IndexOf ("["));
- e = new ArrayCreation (base_type, rank, (ArrayList)init, f.Location);
+ e = new ArrayCreation (f.Type, "", (ArrayList)init, f.Location);
}
Location l = f.Location;
count = bases.Count;
if (is_class){
- string name = (string) bases [0];
- Type first = FindType (name);
+ Expression name = (Expression) bases [0];
+ name = ResolveTypeExpr (name, false, Location);
- if (first == null){
+ if (name == null){
error = true;
return null;
}
+ Type first = name.Type;
+
if (first.IsClass){
parent = first;
start = 1;
Type [] ifaces = new Type [count-start];
for (i = start, j = 0; i < count; i++, j++){
- string name = (string) bases [i];
- Type t = FindType (name);
+ Expression name = (Expression) bases [i];
+ Expression resolved = ResolveTypeExpr (name, false, Location);
+ bases [i] = resolved;
+ Type t = resolved.Type;
if (t == null){
error = true;
}
}
+ // add interfaces that were not added at type creation (weird API issue)
+ if (!is_class && !have_nonstatic_fields && (ifaces != null)) {
+ foreach (Type i in ifaces)
+ TypeBuilder.AddInterfaceImplementation (i);
+ }
+
//
// Finish the setup for the EmitContext
//
return true;
}
- /// <summary>
- /// Looks up the alias for the name
- /// </summary>
- public string LookupAlias (string name)
- {
- if (Namespace != null)
- return Namespace.LookupAlias (name);
- else
- return null;
- }
-
/// <summary>
/// This function is based by a delegate to the FindMembers routine
/// </summary>
if (filter == null)
filter = accepting_filter;
-
+
if ((mt & MemberTypes.Field) != 0) {
if (fields != null) {
foreach (Field f in fields) {
}
if ((mt & MemberTypes.NestedType) != 0) {
+ if (types != null){
+ foreach (TypeContainer t in types) {
+ TypeBuilder tb = t.TypeBuilder;
- if (Types != null)
- foreach (TypeContainer t in Types)
- if (filter (t.TypeBuilder, criteria) == true)
- members.Add (t.TypeBuilder);
+ if (tb != null && (filter (tb, criteria) == true))
+ members.Add (tb);
+ }
+ }
- if (Enums != null)
- foreach (Enum en in Enums)
- if (filter (en.TypeBuilder, criteria) == true)
- members.Add (en.TypeBuilder);
+ if (enums != null){
+ foreach (Enum en in enums){
+ TypeBuilder tb = en.TypeBuilder;
+
+ if (tb != null && (filter (tb, criteria) == true))
+ members.Add (tb);
+ }
+ }
+ if (delegates != null){
+ foreach (Delegate d in delegates){
+ TypeBuilder tb = d.TypeBuilder;
+
+ if (tb != null && (filter (tb, criteria) == true))
+ members.Add (tb);
+ }
+ }
}
if ((mt & MemberTypes.Constructor) != 0){
ConstructorBuilder cb =
default_static_constructor.ConstructorBuilder;
+ if (cb != null)
if (filter (cb, criteria) == true)
members.Add (cb);
}
return null;
}
- public MemberInfo GetFieldFromEvent (EventExpr event_expr)
- {
- if (events == null)
- return null;
-
- EventInfo ei = event_expr.EventInfo;
-
- foreach (Event e in events) {
-
- if (e.FieldBuilder == null)
- continue;
-
- if (Type.FilterName (e.FieldBuilder, ei.Name))
- return e.FieldBuilder;
- }
-
- return null;
- }
+
public static MemberInfo [] FindMembers (Type t, MemberTypes mt, BindingFlags bf,
MemberFilter filter, object criteria)
public bool MethodModifiersValid (int flags, string n, Location loc)
{
const int vao = (Modifiers.VIRTUAL | Modifiers.ABSTRACT | Modifiers.OVERRIDE);
+ const int va = (Modifiers.VIRTUAL | Modifiers.ABSTRACT);
const int nv = (Modifiers.NEW | Modifiers.VIRTUAL);
bool ok = true;
string name = MakeName (n);
}
}
+ if (this is Struct){
+ if ((flags & va) != 0){
+ Modifiers.Error_InvalidModifier (loc, "virtual or abstract");
+ ok = false;
+ }
+ }
+
if ((flags & Modifiers.OVERRIDE) != 0 && (flags & nv) != 0){
Report.Error (
113, loc, name +
}
public class Method : MethodCore {
- public readonly string ReturnType;
+ public Expression ReturnType;
public MethodBuilder MethodBuilder;
public readonly Attributes OptAttributes;
//
// return_type can be "null" for VOID values.
//
- public Method (string return_type, int mod, string name, Parameters parameters,
+ public Method (Expression return_type, int mod, string name, Parameters parameters,
Attributes attrs, Location l)
: base (name, parameters, l)
{
public Type GetReturnType (TypeContainer parent)
{
if (type_return_type == null)
- type_return_type = RootContext.LookupType (
- parent, ReturnType, false, Location);
+ type_return_type = parent.ResolveType (ReturnType, false, Location);
return type_return_type;
}
if ((ModFlags & Modifiers.STATIC) != 0)
implementing = null;
} else {
- if ((ModFlags & (Modifiers.PUBLIC | Modifiers.ABSTRACT)) != 0){
- Report.Error (
- 106, Location, "`public' or `abstract' modifiers "+
- "are not allowed in explicit interface declarations"
- );
+ if ((ModFlags & (Modifiers.PUBLIC | Modifiers.ABSTRACT | Modifiers.VIRTUAL)) != 0){
+ Modifiers.Error_InvalidModifier (Location, "public, virtual or abstract");
implementing = null;
}
}
return true;
t = ec.ContainerType.BaseType;
+ if (ec.ContainerType.IsValueType) {
+ Report.Error (522, location,
+ "structs cannot call base class constructors");
+ return false;
+ }
} else
t = ec.ContainerType;
public void Emit (EmitContext ec)
{
- ec.ig.Emit (OpCodes.Ldarg_0);
+ if (parent_constructor != null)
+ ec.ig.Emit (OpCodes.Ldarg_0);
if (argument_list != null)
Invocation.EmitArguments (ec, null, argument_list);
if (parent_constructor != null)
ILGenerator ig = ConstructorBuilder.GetILGenerator ();
EmitContext ec = new EmitContext (parent, Location, ig, null, ModFlags, true);
- if (parent is Class && ((ModFlags & Modifiers.STATIC) == 0)){
- if (Initializer == null)
+ if ((ModFlags & Modifiers.STATIC) == 0){
+ if (parent is Class && Initializer == null)
Initializer = new ConstructorBaseInitializer (null, parent.Location);
// `this' access
//
ec.IsStatic = true;
- if (!Initializer.Resolve (ec))
+ if (Initializer != null && !Initializer.Resolve (ec))
return;
ec.IsStatic = false;
}
// Classes can have base initializers and instance field initializers.
//
if (parent is Class){
- if ((ModFlags & Modifiers.STATIC) == 0){
+ if ((ModFlags & Modifiers.STATIC) == 0)
parent.EmitFieldInitializers (ec);
-
- Initializer.Emit (ec);
- }
}
+ if (Initializer != null)
+ Initializer.Emit (ec);
if ((ModFlags & Modifiers.STATIC) != 0)
parent.EmitFieldInitializers (ec);
// their common bits. This is also used to flag usage of the field
//
abstract public class FieldBase : MemberCore {
- public readonly string Type;
+ public Expression Type;
public readonly Object Initializer;
public readonly Attributes OptAttributes;
public FieldBuilder FieldBuilder;
//
// The constructor is only exposed to our children
//
- protected FieldBase (string type, int mod, int allowed_mod, string name,
+ protected FieldBase (Expression type, int mod, int allowed_mod, string name,
object init, Attributes attrs, Location loc)
: base (name, loc)
{
Modifiers.UNSAFE |
Modifiers.READONLY;
- public Field (string type, int mod, string name, Object expr_or_array_init,
+ public Field (Expression type, int mod, string name, Object expr_or_array_init,
Attributes attrs, Location loc)
: base (type, mod, AllowedModifiers, name, expr_or_array_init, attrs, loc)
{
public override bool Define (TypeContainer parent)
{
- Type t = RootContext.LookupType (parent, Type, false, Location);
+ Type t = parent.ResolveType (Type, false, Location);
if (t == null)
return false;
}
public class Property : MemberCore {
- public readonly string Type;
+ public Expression Type;
public Accessor Get, Set;
public PropertyBuilder PropertyBuilder;
public Attributes OptAttributes;
Modifiers.EXTERN |
Modifiers.VIRTUAL;
- public Property (string type, string name, int mod_flags,
+ public Property (Expression type, string name, int mod_flags,
Accessor get_block, Accessor set_block,
Attributes attrs, Location loc)
: base (name, loc)
if ((ModFlags & Modifiers.STATIC) != 0)
implementing = null;
} else {
- if ((ModFlags & (Modifiers.PUBLIC | Modifiers.ABSTRACT)) != 0){
- Report.Error (
- 106, Location, "`public' or `abstract' modifiers "+
- "are not allowed in explicit interface declarations"
- );
+ if ((ModFlags & (Modifiers.PUBLIC | Modifiers.ABSTRACT | Modifiers.VIRTUAL)) != 0){
+ Modifiers.Error_InvalidModifier (Location, "public, virtual or abstract");
implementing = null;
}
}
flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
// Lookup Type, verify validity
- PropertyType = RootContext.LookupType (parent, Type, false, Location);
+ PropertyType = parent.ResolveType (Type, false, Location);
if (PropertyType == null)
return false;
Type EventType;
MethodBuilder AddBuilder, RemoveBuilder;
- public Event (string type, string name, Object init, int mod, Accessor add,
+ public Event (Expression type, string name, Object init, int mod, Accessor add,
Accessor remove, Attributes attrs, Location loc)
: base (type, mod, AllowedModifiers, name, init, attrs, loc)
{
MethodAttributes m_attr = Modifiers.MethodAttr (ModFlags);
EventAttributes e_attr = EventAttributes.RTSpecialName | EventAttributes.SpecialName;
- EventType = RootContext.LookupType (parent, Type, false, Location);
+ EventType = parent.ResolveType (Type, false, Location);
if (EventType == null)
return false;
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.FamANDAssem);
+ TypeManager.RegisterPrivateFieldOfEvent ((EventInfo) EventBuilder, FieldBuilder);
TypeManager.RegisterFieldBase (FieldBuilder, this);
}
remove_name, m_attr, null, parameters);
RemoveBuilder.DefineParameter (1, ParameterAttributes.None, "value");
EventBuilder.SetRemoveOnMethod (RemoveBuilder);
+ if (parent.Pending != null)
+ parent.Pending.ImplementMethod (null, remove_name, null, parameters, false);
//
// This looks like dead code
Modifiers.EXTERN |
Modifiers.ABSTRACT;
- public readonly string Type;
+ public readonly Expression Type;
public readonly string InterfaceType;
public readonly Parameters FormalParameters;
public readonly Accessor Get, Set;
EmitContext ec;
- public Indexer (string type, string int_type, int flags, Parameters parms,
+ public Indexer (Expression type, string int_type, int flags, Parameters parms,
Accessor get_block, Accessor set_block, Attributes attrs, Location loc)
: base ("", loc)
{
if ((ModFlags & Modifiers.STATIC) != 0)
implementing = null;
} else {
- if((ModFlags&(Modifiers.PUBLIC | Modifiers.ABSTRACT)) != 0){
- Report.Error (
- 106, Location,
- "`public' or `abstract' modifiers are not "+
- "allowed in explicit interface declarations"
- );
+ if((ModFlags&(Modifiers.PUBLIC | Modifiers.ABSTRACT | Modifiers.VIRTUAL)) != 0){
+ Modifiers.Error_InvalidModifier (Location, "public, virtual or abstract");
implementing = null;
}
}
PropertyAttributes.SpecialName;
bool error = false;
- IndexerType = RootContext.LookupType (parent, Type, false, Location);
+ IndexerType = parent.ResolveType (Type, false, Location);
Type [] parameters = FormalParameters.GetParameterInfo (parent);
// Check if the return type and arguments were correct
};
public readonly OpType OperatorType;
- public readonly string ReturnType;
- public readonly string FirstArgType;
- public readonly string FirstArgName;
- public readonly string SecondArgType;
- public readonly string SecondArgName;
+ public readonly Expression ReturnType;
+ public readonly Expression FirstArgType, SecondArgType;
+ public readonly string FirstArgName, SecondArgName;
public readonly Block Block;
public Attributes OptAttributes;
public MethodBuilder OperatorMethodBuilder;
public string MethodName;
public Method OperatorMethod;
- public Operator (OpType type, string ret_type, int flags, string arg1type, string arg1name,
- string arg2type, string arg2name, Block block, Attributes attrs, Location loc)
+ public Operator (OpType type, Expression ret_type, int flags,
+ Expression arg1type, string arg1name,
+ Expression arg2type, string arg2name,
+ Block block, Attributes attrs, Location loc)
: base ("", loc)
{
OperatorType = type;