+
//
// class.cs: Class and Struct handlers
//
// (C) 2001, 2002 Ximian, Inc (http://www.ximian.com)
//
//
-
+// 2002-10-11 Miguel de Icaza <miguel@ximian.com>
+//
+// * class.cs: Following the comment from 2002-09-26 to AddMethod, I
+// have fixed a remaining problem: not every AddXXXX was adding a
+// fully qualified name.
+//
+// Now everyone registers a fully qualified name in the DeclSpace as
+// being defined instead of the partial name.
+//
+// Downsides: we are slower than we need to be due to the excess
+// copies and the names being registered this way.
+//
+// The reason for this is that we currently depend (on the corlib
+// bootstrap for instance) that types are fully qualified, because
+// we dump all the types in the namespace, and we should really have
+// types inserted into the proper namespace, so we can only store the
+// basenames in the defined_names array.
+//
+//
+#define CACHE
using System;
using System.Collections;
using System.Reflection;
/// <summary>
/// This is the base class for structs and classes.
/// </summary>
- public class TypeContainer : DeclSpace {
+ public class TypeContainer : DeclSpace, IMemberContainer {
// Holds a list of classes and structures
ArrayList types;
// The interfaces we implement.
Type [] ifaces;
+
+ // The parent member container and our member cache
+ IMemberContainer parent_container;
+ MemberCache member_cache;
//
// The indexer name for this class
public AdditionResult AddConstant (Const constant)
{
AdditionResult res;
- string name = constant.Name;
+ string basename = constant.Name;
- if ((res = IsValid (name)) != AdditionResult.Success)
+ if ((res = IsValid (basename)) != AdditionResult.Success)
return res;
if (constants == null)
constants = new ArrayList ();
constants.Add (constant);
- DefineName (name, constant);
+ DefineName (Name + "." + basename, constant);
return AdditionResult.Success;
}
public AdditionResult AddEnum (Mono.CSharp.Enum e)
{
AdditionResult res;
- string name = e.Name;
- if ((res = IsValid (name)) != AdditionResult.Success)
+ if ((res = IsValid (e.Basename)) != AdditionResult.Success)
return res;
if (enums == null)
enums = new ArrayList ();
enums.Add (e);
- DefineName (name, e);
+ DefineName (e.Name, e);
return AdditionResult.Success;
}
public AdditionResult AddClass (Class c)
{
AdditionResult res;
- string name = c.Name;
-
- if ((res = IsValid (name)) != AdditionResult.Success)
+ if ((res = IsValid (c.Basename)) != AdditionResult.Success)
return res;
- DefineName (name, c);
+ DefineName (c.Name, c);
types.Add (c);
return AdditionResult.Success;
public AdditionResult AddStruct (Struct s)
{
AdditionResult res;
- string name = s.Name;
- if ((res = IsValid (name)) != AdditionResult.Success)
+ if ((res = IsValid (s.Basename)) != AdditionResult.Success)
return res;
- DefineName (name, s);
+ DefineName (s.Name, s);
types.Add (s);
return AdditionResult.Success;
public AdditionResult AddDelegate (Delegate d)
{
AdditionResult res;
- string name = d.Name;
- if ((res = IsValid (name)) != AdditionResult.Success)
+ if ((res = IsValid (d.Basename)) != AdditionResult.Success)
return res;
if (delegates == null)
delegates = new ArrayList ();
- DefineName (name, d);
+ DefineName (d.Name, d);
delegates.Add (d);
return AdditionResult.Success;
public AdditionResult AddMethod (Method method)
{
- string name = method.Name;
- Object value = defined_names [name];
-
+ string basename = method.Name;
+ string fullname = Name + "." + basename;
+
+ Object value = defined_names [fullname];
+
if (value != null && (!(value is Method)))
return AdditionResult.NameExists;
- if (name == Basename)
+ if (basename == Basename)
return AdditionResult.EnclosingClash;
if (methods == null)
else
methods.Add (method);
- if (value != null)
- DefineName (name, method);
+ if (value == null)
+ DefineName (fullname, method);
return AdditionResult.Success;
}
public AdditionResult AddInterface (Interface iface)
{
AdditionResult res;
- string name = iface.Name;
- if ((res = IsValid (name)) != AdditionResult.Success)
+ if ((res = IsValid (iface.Basename)) != AdditionResult.Success)
return res;
if (interfaces == null)
interfaces = new ArrayList ();
interfaces.Add (iface);
- DefineName (name, iface);
+ DefineName (iface.Name, iface);
return AdditionResult.Success;
}
public AdditionResult AddField (Field field)
{
AdditionResult res;
- string name = field.Name;
+ string basename = field.Name;
- if ((res = IsValid (name)) != AdditionResult.Success)
+ if ((res = IsValid (basename)) != AdditionResult.Success)
return res;
if (fields == null)
if ((field.ModFlags & Modifiers.STATIC) == 0)
have_nonstatic_fields = true;
- DefineName (name, field);
+ DefineName (Name + "." + basename, field);
return AdditionResult.Success;
}
public AdditionResult AddProperty (Property prop)
{
AdditionResult res;
- string name = prop.Name;
+ string basename = prop.Name;
- if ((res = IsValid (name)) != AdditionResult.Success)
+ if ((res = IsValid (basename)) != AdditionResult.Success)
return res;
if (properties == null)
properties.Insert (0, prop);
else
properties.Add (prop);
- DefineName (name, prop);
+ DefineName (Name + "." + basename, prop);
return AdditionResult.Success;
}
public AdditionResult AddEvent (Event e)
{
AdditionResult res;
- string name = e.Name;
+ string basename = e.Name;
- if ((res = IsValid (name)) != AdditionResult.Success)
+ if ((res = IsValid (basename)) != AdditionResult.Success)
return res;
if (events == null)
events = new ArrayList ();
events.Add (e);
- DefineName (name, e);
+ DefineName (Name + "." + basename, e);
return AdditionResult.Success;
}
// if (parent_builder is ModuleBuilder) {
if (IsTopLevel){
ModuleBuilder builder = CodeGen.ModuleBuilder;
+ TypeBuilder = builder.DefineType (
+ Name, type_attributes, parent, ifaces);
- //
- // Structs with no fields need to have a ".size 1"
- // appended
- //
-
- if (!is_class && !have_nonstatic_fields)
- TypeBuilder = builder.DefineType (Name,
- type_attributes,
- parent,
- PackingSize.Unspecified, 1);
- else
- //
- // classes or structs with fields
- //
- TypeBuilder = builder.DefineType (Name,
- type_attributes,
- parent,
- ifaces);
} else {
TypeBuilder builder = Parent.TypeBuilder;
+ TypeBuilder = builder.DefineNestedType (
+ Basename, type_attributes, parent, ifaces);
+ }
- //
- // Structs with no fields need to have a ".size 1"
- // appended
- //
- if (!is_class && !have_nonstatic_fields)
- TypeBuilder = builder.DefineNestedType (Basename,
- type_attributes,
- parent,
- PackingSize.Unspecified);
- else {
- //
- // classes or structs with fields
- //
- TypeBuilder = builder.DefineNestedType (Basename,
- type_attributes,
- parent,
- ifaces);
- }
+ //
+ // Structs with no fields need to have at least one byte.
+ // The right thing would be to set the PackingSize in a DefineType
+ // but there are no functions that allow interfaces *and* the size to
+ // be specified.
+ //
+
+ if (!is_class && !have_nonstatic_fields){
+ TypeBuilder.DefineField ("$PRIVATE$", TypeManager.byte_type,
+ FieldAttributes.Private);
}
// add interfaces that were not added at type creation (weird API issue)
IndexerName = class_indexer_name;
}
- static void Report1530 (Location loc)
+ static void Error_KeywordNotAllowed (Location loc)
{
Report.Error (1530, loc, "Keyword new not allowed for namespace elements");
}
/// <summary>
/// Populates our TypeBuilder with fields and methods
/// </summary>
- public override bool Define (TypeContainer parent)
+ public override bool DefineMembers (TypeContainer parent)
{
MemberInfo [] defined_names = null;
if (interface_order != null){
foreach (Interface iface in interface_order)
if ((iface.ModFlags & Modifiers.NEW) == 0)
- iface.Define (this);
+ iface.DefineMembers (this);
else
- Report1530 (iface.Location);
+ Error_KeywordNotAllowed (iface.Location);
}
if (RootContext.WarningLevel > 1){
//
ptype = TypeBuilder.BaseType;
if (ptype != null){
- defined_names = FindMembers (
+ defined_names = (MemberInfo []) FindMembers (
ptype, MemberTypes.All & ~MemberTypes.Constructor,
BindingFlags.Public | BindingFlags.Instance |
BindingFlags.Static, null, null);
} else
IndexerName = "Item";
- if (operators != null)
+ if (operators != null){
DefineMembers (operators, null);
+ CheckPairedOperators ();
+ }
+
if (enums != null)
DefineMembers (enums, defined_names);
if (delegates != null)
DefineMembers (delegates, defined_names);
+#if CACHE
+ if (TypeBuilder.BaseType != null)
+ parent_container = TypeManager.LookupMemberContainer (TypeBuilder.BaseType);
+
+ member_cache = new MemberCache (this);
+#endif
+
+ return true;
+ }
+
+ public override bool Define (TypeContainer parent)
+ {
+ if (interface_order != null){
+ foreach (Interface iface in interface_order)
+ if ((iface.ModFlags & Modifiers.NEW) == 0)
+ iface.Define (this);
+ }
+
return true;
}
//
// Since the whole process is a no-op, it is fine to check for null here.
//
- public MemberInfo [] FindMembers (MemberTypes mt, BindingFlags bf,
- MemberFilter filter, object criteria)
+ public override MemberList FindMembers (MemberTypes mt, BindingFlags bf,
+ MemberFilter filter, object criteria)
{
ArrayList members = new ArrayList ();
- bool priv = (bf & BindingFlags.NonPublic) != 0;
+
+ int modflags = 0;
+ if ((bf & BindingFlags.Public) != 0)
+ modflags |= Modifiers.PUBLIC | Modifiers.PROTECTED |
+ Modifiers.INTERNAL;
+ if ((bf & BindingFlags.NonPublic) != 0)
+ modflags |= Modifiers.PRIVATE;
+
+ int static_mask = 0, static_flags = 0;
+ switch (bf & (BindingFlags.Static | BindingFlags.Instance)) {
+ case BindingFlags.Static:
+ static_mask = static_flags = Modifiers.STATIC;
+ break;
+
+ case BindingFlags.Instance:
+ static_mask = Modifiers.STATIC;
+ static_flags = 0;
+ break;
+
+ default:
+ static_mask = static_flags = 0;
+ break;
+ }
+
+ Timer.StartTimer (TimerType.TcFindMembers);
if (filter == null)
filter = accepting_filter;
if ((mt & MemberTypes.Field) != 0) {
if (fields != null) {
foreach (Field f in fields) {
- if ((f.ModFlags & Modifiers.PRIVATE) != 0)
- if (!priv)
- continue;
+ if ((f.ModFlags & modflags) == 0)
+ continue;
+ if ((f.ModFlags & static_mask) != static_flags)
+ continue;
FieldBuilder fb = f.FieldBuilder;
if (fb != null && filter (fb, criteria) == true)
if (constants != null) {
foreach (Const con in constants) {
- if ((con.ModFlags & Modifiers.PRIVATE) != 0)
- if (!priv)
- continue;
-
+ if ((con.ModFlags & modflags) == 0)
+ continue;
+ if ((con.ModFlags & static_mask) != static_flags)
+ continue;
+
FieldBuilder fb = con.FieldBuilder;
if (fb != null && filter (fb, criteria) == true)
members.Add (fb);
if ((mt & MemberTypes.Method) != 0) {
if (methods != null) {
foreach (Method m in methods) {
- if ((m.ModFlags & Modifiers.PRIVATE) != 0)
- if (!priv)
- continue;
+ if ((m.ModFlags & modflags) == 0)
+ continue;
+ if ((m.ModFlags & static_mask) != static_flags)
+ continue;
MethodBuilder mb = m.MethodBuilder;
if (operators != null){
foreach (Operator o in operators) {
- if ((o.ModFlags & Modifiers.PRIVATE) != 0)
- if (!priv)
- continue;
+ if ((o.ModFlags & modflags) == 0)
+ continue;
+ if ((o.ModFlags & static_mask) != static_flags)
+ continue;
MethodBuilder ob = o.OperatorMethodBuilder;
if (ob != null && filter (ob, criteria) == true)
if (properties != null){
foreach (Property p in properties){
- if ((p.ModFlags & Modifiers.PRIVATE) != 0)
- if (!priv)
- continue;
+ if ((p.ModFlags & modflags) == 0)
+ continue;
+ if ((p.ModFlags & static_mask) != static_flags)
+ continue;
MethodBuilder b;
members.Add (b);
}
}
+
+ if (indexers != null){
+ foreach (Indexer ix in indexers){
+ if ((ix.ModFlags & modflags) == 0)
+ continue;
+ if ((ix.ModFlags & static_mask) != static_flags)
+ continue;
+
+ MethodBuilder b;
+
+ b = ix.GetBuilder;
+ if (b != null && filter (b, criteria) == true)
+ members.Add (b);
+
+ b = ix.SetBuilder;
+ if (b != null && filter (b, criteria) == true)
+ members.Add (b);
+ }
+ }
}
if ((mt & MemberTypes.Event) != 0) {
if (events != null)
foreach (Event e in events) {
- if ((e.ModFlags & Modifiers.PRIVATE) != 0)
- if (!priv)
- continue;
+ if ((e.ModFlags & modflags) == 0)
+ continue;
+ if ((e.ModFlags & static_mask) != static_flags)
+ continue;
MemberInfo eb = e.EventBuilder;
if (eb != null && filter (eb, criteria) == true)
if ((mt & MemberTypes.Property) != 0){
if (properties != null)
foreach (Property p in properties) {
- if ((p.ModFlags & Modifiers.PRIVATE) != 0)
- if (!priv)
- continue;
+ if ((p.ModFlags & modflags) == 0)
+ continue;
+ if ((p.ModFlags & static_mask) != static_flags)
+ continue;
MemberInfo pb = p.PropertyBuilder;
if (pb != null && filter (pb, criteria) == true) {
if (indexers != null)
foreach (Indexer ix in indexers) {
- if ((ix.ModFlags & Modifiers.PRIVATE) != 0)
- if (!priv)
- continue;
+ if ((ix.ModFlags & modflags) == 0)
+ continue;
+ if ((ix.ModFlags & static_mask) != static_flags)
+ continue;
MemberInfo ib = ix.PropertyBuilder;
if (ib != null && filter (ib, criteria) == true) {
if ((mt & MemberTypes.NestedType) != 0) {
if (types != null){
foreach (TypeContainer t in types) {
- TypeBuilder tb = t.TypeBuilder;
+ if ((t.ModFlags & modflags) == 0)
+ continue;
+ TypeBuilder tb = t.TypeBuilder;
if (tb != null && (filter (tb, criteria) == true))
members.Add (tb);
}
if (enums != null){
foreach (Enum en in enums){
- TypeBuilder tb = en.TypeBuilder;
+ if ((en.ModFlags & modflags) == 0)
+ continue;
+ TypeBuilder tb = en.TypeBuilder;
if (tb != null && (filter (tb, criteria) == true))
members.Add (tb);
}
if (delegates != null){
foreach (Delegate d in delegates){
+ if ((d.ModFlags & modflags) == 0)
+ continue;
+
TypeBuilder tb = d.TypeBuilder;
-
+ if (tb != null && (filter (tb, criteria) == true))
+ members.Add (tb);
+ }
+ }
+
+ if (interfaces != null){
+ foreach (Interface iface in interfaces){
+ if ((iface.ModFlags & modflags) == 0)
+ continue;
+
+ TypeBuilder tb = iface.TypeBuilder;
if (tb != null && (filter (tb, criteria) == true))
members.Add (tb);
}
}
if ((mt & MemberTypes.Constructor) != 0){
- if (instance_constructors != null){
+ if (((bf & BindingFlags.Instance) != 0) && (instance_constructors != null)){
foreach (Constructor c in instance_constructors){
ConstructorBuilder cb = c.ConstructorBuilder;
-
if (cb != null)
if (filter (cb, criteria) == true)
members.Add (cb);
}
}
- if (default_static_constructor != null){
+ if (((bf & BindingFlags.Static) != 0) && (default_static_constructor != null)){
ConstructorBuilder cb =
default_static_constructor.ConstructorBuilder;
// Lookup members in parent if requested.
//
if (((bf & BindingFlags.DeclaredOnly) == 0) && (TypeBuilder.BaseType != null)) {
- MemberInfo [] mi;
-
- mi = FindMembers (TypeBuilder.BaseType, mt, bf, filter, criteria);
- if (mi != null)
- members.AddRange (mi);
- }
-
- int count = members.Count;
- if (count > 0){
- MemberInfo [] mi = new MemberInfo [count];
- members.CopyTo (mi);
- return mi;
+ MemberList list = FindMembers (TypeBuilder.BaseType, mt, bf, filter, criteria);
+ members.AddRange (list);
}
- return null;
+ Timer.StopTimer (TimerType.TcFindMembers);
+
+ return new MemberList (members);
}
-
+ public override MemberCache MemberCache {
+ get {
+ return member_cache;
+ }
+ }
- public static MemberInfo [] FindMembers (Type t, MemberTypes mt, BindingFlags bf,
- MemberFilter filter, object criteria)
+ public static MemberList FindMembers (Type t, MemberTypes mt, BindingFlags bf,
+ MemberFilter filter, object criteria)
{
TypeContainer tc = TypeManager.LookupTypeContainer (t);
if (tc != null)
return tc.FindMembers (mt, bf, filter, criteria);
else
- return t.FindMembers (mt, bf, filter, criteria);
+ return new MemberList (t.FindMembers (mt, bf, filter, criteria));
}
//
if (Delegates != null)
foreach (Delegate d in Delegates)
- d.CloseDelegate ();
+ d.CloseType ();
}
public string MakeName (string n)
{
Report.Error (539, loc, "Explicit implementation: `" + name + "' is not a member of the interface");
}
+
+ //
+ // IMemberContainer
+ //
+
+ string IMemberContainer.Name {
+ get {
+ return Name;
+ }
+ }
+
+ Type IMemberContainer.Type {
+ get {
+ return TypeBuilder;
+ }
+ }
+
+ IMemberContainer IMemberContainer.Parent {
+ get {
+ return parent_container;
+ }
+ }
+
+ MemberCache IMemberContainer.MemberCache {
+ get {
+ return member_cache;
+ }
+ }
+
+ bool IMemberContainer.IsInterface {
+ get {
+ return false;
+ }
+ }
+
+ MemberList IMemberContainer.GetMembers (MemberTypes mt, BindingFlags bf)
+ {
+ return FindMembers (mt, bf | BindingFlags.DeclaredOnly, null, null);
+ }
+
+ //
+ // Operator pair checking
+ //
+
+ class OperatorEntry {
+ public int flags;
+ public Type ret_type;
+ public Type type1, type2;
+ public Operator op;
+ public Operator.OpType ot;
+
+ public OperatorEntry (int f, Operator o)
+ {
+ flags = f;
+
+ ret_type = o.OperatorMethod.GetReturnType ();
+ Type [] pt = o.OperatorMethod.ParameterTypes;
+ type1 = pt [0];
+ type2 = pt [1];
+ op = o;
+ ot = o.OperatorType;
+ }
+
+ public override int GetHashCode ()
+ {
+ return ret_type.GetHashCode ();
+ }
+
+ public override bool Equals (object o)
+ {
+ OperatorEntry other = (OperatorEntry) o;
+
+ if (other.ret_type != ret_type)
+ return false;
+ if (other.type1 != type1)
+ return false;
+ if (other.type2 != type2)
+ return false;
+ return true;
+ }
+ }
+
+ //
+ // Checks that some operators come in pairs:
+ // == and !=
+ // > and <
+ // >= and <=
+ //
+ // They are matched based on the return type and the argument types
+ //
+ void CheckPairedOperators ()
+ {
+ Hashtable pairs = new Hashtable (null, null);
+
+ // Register all the operators we care about.
+ foreach (Operator op in operators){
+ int reg = 0;
+
+ switch (op.OperatorType){
+ case Operator.OpType.Equality:
+ reg = 1; break;
+ case Operator.OpType.Inequality:
+ reg = 2; break;
+
+ case Operator.OpType.GreaterThan:
+ reg = 1; break;
+ case Operator.OpType.LessThan:
+ reg = 2; break;
+
+ case Operator.OpType.GreaterThanOrEqual:
+ reg = 1; break;
+ case Operator.OpType.LessThanOrEqual:
+ reg = 2; break;
+ }
+ if (reg == 0)
+ continue;
+
+ OperatorEntry oe = new OperatorEntry (reg, op);
+
+ object o = pairs [oe];
+ if (o == null)
+ pairs [oe] = oe;
+ else {
+ oe = (OperatorEntry) o;
+ oe.flags |= reg;
+ }
+ }
+
+ //
+ // Look for the mistakes.
+ //
+ foreach (DictionaryEntry de in pairs){
+ OperatorEntry oe = (OperatorEntry) de.Key;
+
+ if (oe.flags == 3)
+ continue;
+
+ string s = "";
+ switch (oe.ot){
+ case Operator.OpType.Equality:
+ s = "!=";
+ break;
+ case Operator.OpType.Inequality:
+ s = "==";
+ break;
+ case Operator.OpType.GreaterThan:
+ s = "<";
+ break;
+ case Operator.OpType.LessThan:
+ s = ">";
+ break;
+ case Operator.OpType.GreaterThanOrEqual:
+ s = "<=";
+ break;
+ case Operator.OpType.LessThanOrEqual:
+ s = ">=";
+ break;
+ }
+ Report.Error (216, oe.op.Location,
+ "The operator `" + oe.op + "' requires a matching operator `" + s + "' to also be defined");
+ }
+ }
+
+
}
public class Class : TypeContainer {
// function. Provides a nice cache. (used between semantic analysis
// and actual code generation
//
- public Type GetReturnType (TypeContainer parent)
+ public Type GetReturnType ()
{
return MemberType;
}
MethodSignature ms = new MethodSignature (Name, null, ParameterTypes);
if (!IsOperator) {
- MemberInfo [] mi_this;
+ MemberList mi_this;
mi_this = TypeContainer.FindMembers (
parent.TypeBuilder, MemberTypes.Method,
BindingFlags.DeclaredOnly,
MethodSignature.method_signature_filter, ms);
- if (mi_this != null && mi_this.Length > 0) {
+ if (mi_this.Count > 0) {
Report.Error (111, Location, "Class `" + parent.Name + "' " +
"already defines a member called `" + Name + "' " +
"with the same parameter types");
// ptype is only null for System.Object while compiling corlib.
if (ptype != null){
- MemberInfo [] mi, mi_static, mi_instance;
+ MemberList mi, mi_static, mi_instance;
mi_static = TypeContainer.FindMembers (
ptype, MemberTypes.Method,
MethodSignature.inheritable_method_signature_filter,
ms);
- if (mi_instance != null && mi_instance.Length > 0){
+ if (mi_instance.Count > 0){
mi = mi_instance;
- } else if (mi_static != null && mi_static.Length > 0)
+ } else if (mi_static.Count > 0)
mi = mi_static;
else
mi = null;
- if (mi != null && mi.Length > 0){
+ if (mi != null && mi.Count > 0){
parent_method = (MethodInfo) mi [0];
string name = parent_method.DeclaringType.Name + "." +
parent_method.Name;
}
} else
t = ec.ContainerType;
-
+
parent_constructor_group = Expression.MemberLookup (
- ec, t, ".ctor",
+ ec, t, t, ".ctor",
MemberTypes.Constructor,
BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly,
loc);
public void Emit (EmitContext ec)
{
- if (parent_constructor != null)
- ec.ig.Emit (OpCodes.Ldarg_0);
- if (argument_list != null)
- Invocation.EmitArguments (ec, null, argument_list);
- if (parent_constructor != null)
- ec.ig.Emit (OpCodes.Call, parent_constructor);
+ if (parent_constructor != null){
+ if (ec.IsStatic)
+ Invocation.EmitCall (ec, true, true, null, parent_constructor, argument_list, loc);
+ else
+ Invocation.EmitCall (ec, true, false, ec.This, parent_constructor, argument_list, loc);
+ }
}
}
// <summary>
// Modifiers allowed for a constructor.
// </summary>
- const int AllowedModifiers =
+ public const int AllowedModifiers =
Modifiers.PUBLIC |
Modifiers.PROTECTED |
Modifiers.INTERNAL |
Modifiers.STATIC |
Modifiers.UNSAFE |
+ Modifiers.EXTERN |
Modifiers.PRIVATE;
//
"constructors");
return false;
}
- ca |= MethodAttributes.Public | MethodAttributes.HideBySig;
+ ca |= MethodAttributes.HideBySig;
+
+ if ((ModFlags & Modifiers.PUBLIC) != 0)
+ ca |= MethodAttributes.Public;
+ else if ((ModFlags & Modifiers.PROTECTED) != 0){
+ if ((ModFlags & Modifiers.INTERNAL) != 0)
+ ca |= MethodAttributes.FamORAssem;
+ else
+ ca |= MethodAttributes.Family;
+ } else if ((ModFlags & Modifiers.INTERNAL) != 0)
+ ca |= MethodAttributes.Assembly;
+ else if (IsDefault ())
+ ca |= MethodAttributes.Public;
+ else
+ ca |= MethodAttributes.Private;
}
ConstructorBuilder = parent.TypeBuilder.DefineConstructor (
Attribute.ApplyAttributes (ec, ConstructorBuilder, this, OptAttributes, Location);
+ // If this is a non-static `struct' constructor and doesn't have any
+ // initializer, it must initialize all of the struct's fields.
+ if ((parent is Struct) && ((ModFlags & Modifiers.STATIC) == 0) &&
+ (Initializer == null))
+ Block.AddThisVariable (parent, Location);
+
ec.EmitTopBlock (Block, ParameterInfo, Location);
}
}
else
name = member.ShortName;
method_name = prefix + name;
-
+
if (parent.Pending != null){
if (member is Indexer)
implementing = parent.Pending.IsInterfaceIndexer (
//
if (implementing.DeclaringType.IsInterface)
flags |= MethodAttributes.NewSlot;
-
+
flags |=
MethodAttributes.Virtual |
MethodAttributes.HideBySig;
if (ec.ContainerType.BaseType != null) {
Expression member_lookup = Expression.MemberLookup (
- ec, ec.ContainerType.BaseType, "Finalize",
+ ec, ec.ContainerType.BaseType, ec.ContainerType.BaseType, "Finalize",
MemberTypes.Method, Expression.AllBindingFlags, Location);
if (member_lookup != null){
// ptype is only null for System.Object while compiling corlib.
if (ptype != null){
- MemberInfo [] mi;
-
- mi = TypeContainer.FindMembers (
+ TypeContainer.FindMembers (
ptype, MemberTypes.Method,
BindingFlags.Public |
BindingFlags.Static | BindingFlags.Instance,
}
}
}
-
+
+ FieldAttributes fa = Modifiers.FieldAttr (ModFlags);
+
+ if (parent is Struct &&
+ ((fa & FieldAttributes.Static) == 0) &&
+ t == parent.TypeBuilder &&
+ !TypeManager.IsBuiltinType (t)){
+ Report.Error (523, Location, "Struct member `" + parent.Name + "." + Name +
+ "' causes a cycle in the structure layout");
+ return false;
+ }
FieldBuilder = parent.TypeBuilder.DefineField (
Name, t, Modifiers.FieldAttr (ModFlags));
if (!DoDefineParameters (parent))
return false;
- MethodSignature ms = new MethodSignature (Name, null, ParameterTypes);
- MemberInfo [] props_this;
+ if (IsExplicitImpl)
+ return true;
+
+ string report_name;
+ MethodSignature ms, base_ms;
+ if (this is Indexer) {
+ string name, base_name;
+
+ report_name = "this";
+ name = TypeManager.IndexerPropertyName (parent.TypeBuilder);
+ ms = new MethodSignature (name, null, ParameterTypes);
+ base_name = TypeManager.IndexerPropertyName (parent.TypeBuilder.BaseType);
+ base_ms = new MethodSignature (base_name, null, ParameterTypes);
+ } else {
+ report_name = Name;
+ ms = base_ms = new MethodSignature (Name, null, ParameterTypes);
+ }
+
+ MemberList props_this;
props_this = TypeContainer.FindMembers (
parent.TypeBuilder, MemberTypes.Property,
BindingFlags.DeclaredOnly,
MethodSignature.method_signature_filter, ms);
- if (props_this != null && props_this.Length > 0) {
+ if (props_this.Count > 0) {
Report.Error (111, Location, "Class `" + parent.Name + "' " +
- "already defines a member called `" + Name + "' " +
+ "already defines a member called `" + report_name + "' " +
"with the same parameter types");
return false;
}
//
// Find properties with the same name on the base class
//
- MemberInfo [] props;
- MemberInfo [] props_static = TypeContainer.FindMembers (
+ MemberList props;
+ MemberList props_static = TypeContainer.FindMembers (
parent.TypeBuilder.BaseType, MemberTypes.Property,
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static,
- MethodSignature.inheritable_property_signature_filter, ms);
+ MethodSignature.inheritable_property_signature_filter, base_ms);
- MemberInfo [] props_instance = TypeContainer.FindMembers (
+ MemberList props_instance = TypeContainer.FindMembers (
parent.TypeBuilder.BaseType, MemberTypes.Property,
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance,
MethodSignature.inheritable_property_signature_filter,
- ms);
+ base_ms);
//
// Find if we have anything
//
- if (props_static != null && props_static.Length > 0)
+ if (props_static.Count > 0)
props = props_static;
- else if (props_instance != null && props_instance.Length > 0)
+ else if (props_instance.Count > 0)
props = props_instance;
else
props = null;
//
// If we have something on the base.
- if (props != null && props.Length > 0){
+ if (props != null && props.Count > 0){
PropertyInfo pi = (PropertyInfo) props [0];
MethodInfo inherited_get = TypeManager.GetPropertyGetter (pi);
inherited_set : inherited_get;
if (reference != null) {
- string name = reference.DeclaringType.Name + "." + Name;
+ string name = reference.DeclaringType.Name + "." + report_name;
if (!CheckMethodAgainstBase (parent, flags, reference, name))
return false;
if (Add == null && Remove == null) {
FieldBuilder = parent.TypeBuilder.DefineField (
- Name, MemberType, FieldAttributes.FamANDAssem);
+ Name, MemberType,
+ FieldAttributes.FamANDAssem | ((ModFlags & Modifiers.STATIC) != 0 ? FieldAttributes.Static : 0));
TypeManager.RegisterPrivateFieldOfEvent (
(EventInfo) EventBuilder, FieldBuilder);
TypeManager.RegisterFieldBase (FieldBuilder, this);
Type [] param_types = OperatorMethod.ParameterTypes;
Type declaring_type = OperatorMethodBuilder.DeclaringType;
- Type return_type = OperatorMethod.GetReturnType (parent);
+ Type return_type = OperatorMethod.GetReturnType ();
Type first_arg_type = param_types [0];
// Rules for conversion operators
OperatorMethod.Block = Block;
OperatorMethod.Emit (parent);
}
+
+ public static string GetName (OpType ot)
+ {
+ switch (ot){
+ case OpType.LogicalNot:
+ return "!";
+ case OpType.OnesComplement:
+ return "~";
+ case OpType.Increment:
+ return "++";
+ case OpType.Decrement:
+ return "--";
+ case OpType.True:
+ return "true";
+ case OpType.False:
+ return "false";
+ case OpType.Addition:
+ return "+";
+ case OpType.Subtraction:
+ return "-";
+ case OpType.UnaryPlus:
+ return "+";
+ case OpType.UnaryNegation:
+ return "-";
+ case OpType.Multiply:
+ return "*";
+ case OpType.Division:
+ return "/";
+ case OpType.Modulus:
+ return "%";
+ case OpType.BitwiseAnd:
+ return "&";
+ case OpType.BitwiseOr:
+ return "|";
+ case OpType.ExclusiveOr:
+ return "^";
+ case OpType.LeftShift:
+ return "<<";
+ case OpType.RightShift:
+ return ">>";
+ case OpType.Equality:
+ return "==";
+ case OpType.Inequality:
+ return "!=";
+ case OpType.GreaterThan:
+ return ">";
+ case OpType.LessThan:
+ return "<";
+ case OpType.GreaterThanOrEqual:
+ return ">=";
+ case OpType.LessThanOrEqual:
+ return "<=";
+ case OpType.Implicit:
+ return "implicit";
+ case OpType.Explicit:
+ return "explicit";
+ default: return "";
+ }
+ }
+
+ public override string ToString ()
+ {
+ Type return_type = OperatorMethod.GetReturnType();
+ Type [] param_types = OperatorMethod.ParameterTypes;
+
+ if (SecondArgType == null)
+ return String.Format (
+ "{0} operator {1}({2})",
+ TypeManager.CSharpName (return_type),
+ GetName (OperatorType),
+ param_types [0]);
+ else
+ return String.Format (
+ "{0} operator {1}({2}, {3})",
+ TypeManager.CSharpName (return_type),
+ GetName (OperatorType),
+ param_types [0], param_types [1]);
+ }
}
//