using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
namespace Mono.CSharp {
//
// Whether we have seen a static constructor for this class or not
//
- bool have_static_constructor = false;
+ public bool UserDefinedStaticConstructor = false;
//
// Whether we have at least one non-static field
ArrayList type_bases;
- // Information in the case we are an attribute type
-
- public AttributeTargets Targets = AttributeTargets.All;
- public bool AllowMultiple = false;
- public bool Inherited;
+ bool members_defined;
+ bool members_defined_ok;
// The interfaces we implement.
TypeExpr [] ifaces;
+ Type[] base_inteface_types;
// The parent member container and our member cache
IMemberContainer parent_container;
//
public string IndexerName;
+ Type GenericType;
+
public TypeContainer ():
- this (null, null, "", null, new Location (-1)) {
+ this (null, null, MemberName.Null, null, new Location (-1)) {
}
- public TypeContainer (NamespaceEntry ns, TypeContainer parent, string name, Attributes attrs, Location l)
+ public TypeContainer (NamespaceEntry ns, TypeContainer parent,
+ MemberName name, Attributes attrs, Location l)
: base (ns, parent, name, attrs, l)
{
types = new ArrayList ();
bool is_static = (c.ModFlags & Modifiers.STATIC) != 0;
if (is_static){
- have_static_constructor = true;
- if (default_static_constructor != null){
- Console.WriteLine ("I have a static constructor already");
- Console.WriteLine (" " + default_static_constructor);
+ UserDefinedStaticConstructor = true;
+ if (default_static_constructor != null)
return AdditionResult.MethodExists;
- }
default_static_constructor = c;
} else {
initialized_static_fields.Add (field);
- //
- // We have not seen a static constructor,
- // but we will provide static initialization of fields
- //
- have_static_constructor = true;
} else {
if (initialized_fields == null)
initialized_fields = new ArrayList ();
public AdditionResult AddProperty (Property prop)
{
AdditionResult res;
- string basename = prop.Name;
- string fullname = Name + "." + basename;
- if ((res = IsValid (basename, fullname)) != AdditionResult.Success)
+ if ((res = AddProperty (prop, prop.Name)) != AdditionResult.Success)
return res;
+ if (prop.Get != null) {
+ if ((res = AddProperty (prop, "get_" + prop.Name)) != AdditionResult.Success)
+ return res;
+ }
+
+ if (prop.Set != null) {
+ if ((res = AddProperty (prop, "set_" + prop.Name)) != AdditionResult.Success)
+ return res;
+ }
+
if (properties == null)
properties = new ArrayList ();
properties.Insert (0, prop);
else
properties.Add (prop);
+
+ return AdditionResult.Success;
+ }
+
+ AdditionResult AddProperty (Property prop, string basename)
+ {
+ AdditionResult res;
+ string fullname = Name + "." + basename;
+
+ if ((res = IsValid (basename, fullname)) != AdditionResult.Success)
+ return res;
+
DefineName (fullname, prop);
return AdditionResult.Success;
return AdditionResult.Success;
}
- public AdditionResult AddIndexer (Indexer i)
+ public void AddIndexer (Indexer i)
{
if (indexers == null)
indexers = new ArrayList ();
- if (i.InterfaceType != null)
+ if (i.ExplicitInterfaceName != null)
indexers.Insert (0, i);
else
indexers.Add (i);
-
- return AdditionResult.Success;
}
public AdditionResult AddOperator (Operator op)
operators.Add (op);
+ string basename = op.Name;
+ string fullname = Name + "." + basename;
+ if (!defined_names.Contains (fullname))
+ {
+ DefineName (fullname, op);
+ }
return AdditionResult.Success;
}
+ public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+ {
+ if (a.Type == TypeManager.default_member_type) {
+ if (Indexers != null) {
+ Report.Error (646, a.Location,
+ "Cannot specify the DefaultMember attribute on" +
+ " a type containing an indexer");
+ return;
+ }
+ }
+
+ base.ApplyAttributeBuilder (a, cb);
+ }
+
+ public override AttributeTargets AttributeTargets {
+ get {
+ throw new NotSupportedException ();
+ }
+ }
+
public void RegisterOrder (Interface iface)
{
if (interface_order == null)
}
}
- public bool HaveStaticConstructor {
- get {
- return have_static_constructor;
- }
- }
-
public virtual TypeAttributes TypeAttr {
get {
return Modifiers.TypeAttr (ModFlags, this);
void DefineDefaultConstructor (bool is_static)
{
Constructor c;
- int mods = 0;
- c = new Constructor (this, Basename, Parameters.EmptyReadOnlyParameters,
+ // The default constructor is public
+ // If the class is abstract, the default constructor is protected
+ // The default static constructor is private
+
+ int mods = Modifiers.PUBLIC;
+ if (is_static)
+ mods = Modifiers.STATIC | Modifiers.PRIVATE;
+ else if ((ModFlags & Modifiers.ABSTRACT) != 0)
+ mods = Modifiers.PROTECTED;
+
+ c = new Constructor (this, Basename, mods, Parameters.EmptyReadOnlyParameters,
new ConstructorBaseInitializer (
null, Parameters.EmptyReadOnlyParameters,
Location),
Location);
- if (is_static)
- mods = Modifiers.STATIC;
-
- //
- // If the class is abstract, the default constructor is protected
- //
- if ((ModFlags & Modifiers.ABSTRACT) != 0)
- mods |= Modifiers.PROTECTED;
-
- c.ModFlags = mods;
-
AddConstructor (c);
c.Block = new ToplevelBlock (null, Location);
}
}
- void Error_TypeParameterAsBase (TypeParameterExpr e)
- {
- Report.Error (
- -216, e.Location,
- String.Format ("Type parameter `{0}' can not be used t as a base class or interface", e.Name));
- }
-
/// <remarks>
/// The pending methods that need to be implemented (interfaces or abstract methods)
/// </remarks>
/// The @parent argument is set to the parent object or null
/// if this is `System.Object'.
/// </summary>
- TypeExpr [] GetClassBases (bool is_class, out TypeExpr parent, out bool error)
+ TypeExpr [] GetClassBases (bool is_class, bool is_iface,
+ out TypeExpr parent, out bool error)
{
ArrayList bases = Bases;
int count;
error = false;
- if (is_class)
+ if (is_class || is_iface)
parent = null;
else
parent = TypeManager.system_valuetype_expr;
}
if (name is TypeParameterExpr){
- Error_TypeParameterAsBase ((TypeParameterExpr) name);
+ Report.Error (
+ 689, name.Location,
+ "Type parameter `{0}' can not be used as a " +
+ "base class or interface", name.Name);
+ error = true;
+ return null;
+ }
+
+ if (IsGeneric && name.IsAttribute){
+ Report.Error (
+ 698, name.Location,
+ "A generic type cannot derive from `{0}' " +
+ "because it is an attribute class", name.Name);
error = true;
return null;
}
base_class_name = parent.Name;
TypeExpr [] ifaces = new TypeExpr [count-start];
-
+
for (i = start, j = 0; i < count; i++, j++){
Expression name = (Expression) bases [i];
TypeExpr resolved = ResolveTypeExpr (name, false, Location);
+
if (resolved == null)
return null;
}
for (int x = 0; x < j; x++) {
- if (resolved == ifaces [x]) {
+ if (resolved.Equals (ifaces [x])) {
Report.Error (528, "`" + name + "' is already listed in interface list");
error = true;
return null;
}
}
+ if (is_iface &&
+ !resolved.AsAccessible (Parent, ModFlags))
+ Report.Error (61, Location,
+ "Inconsistent accessibility: base interface `" +
+ name + "' is less accessible than interface `" +
+ Name + "'");
+
ifaces [j] = resolved;
}
return TypeManager.ExpandInterfaces (ifaces);
}
+ bool CheckGenericInterfaces (Type[] ifaces)
+ {
+ ArrayList already_checked = new ArrayList ();
+
+ for (int i = 0; i < ifaces.Length; i++) {
+ Type iface = ifaces [i];
+ foreach (Type t in already_checked) {
+ if (iface == t)
+ continue;
+
+ if (!TypeManager.MayBecomeEqualGenericInstances (iface, t))
+ continue;
+
+ Report.Error (
+ 695, Location,
+ "`{0}' cannot implement both `{1}' and `{2}' " +
+ "because they may unify for some type " +
+ "parameter substitutions",
+ TypeManager.GetFullName (TypeBuilder),
+ iface, t);
+ return false;
+ }
+
+ already_checked.Add (iface);
+ }
+
+ return true;
+ }
+
bool error = false;
//
public override TypeBuilder DefineType ()
{
TypeExpr parent;
- bool is_class;
+ bool is_class, is_iface;
if (TypeBuilder != null)
return TypeBuilder;
InTransit = true;
+ if (this is Interface) {
+ is_iface = true;
+ is_class = false;
+ } else {
+ is_iface = false;
if (this is Class)
is_class = true;
else
is_class = false;
+ }
ec = new EmitContext (this, Mono.CSharp.Location.Null, null, null, ModFlags);
- ifaces = GetClassBases (is_class, out parent, out error);
+ ifaces = GetClassBases (is_class, is_iface, out parent, out error);
if (error)
return null;
return null;
}
- ModuleBuilder builder = CodeGen.ModuleBuilder;
+ ModuleBuilder builder = CodeGen.Module.Builder;
TypeBuilder = builder.DefineType (
Name, type_attributes, ptype, null);
-
} else {
TypeBuilder builder = Parent.DefineType ();
- if (builder == null)
+ if (builder == null) {
+ error = true;
return null;
+ }
TypeBuilder = builder.DefineNestedType (
- Basename, type_attributes, ptype, null);
+ MemberName.Basename, type_attributes, ptype, null);
}
+ TypeManager.AddUserType (Name, TypeBuilder, this, ifaces);
+
if (IsGeneric) {
- foreach (TypeParameter type_param in TypeParameters)
- type_param.Define (TypeBuilder);
+ CurrentType = new ConstructedType (
+ Name, TypeParameters, Location);
+
+ string[] param_names = new string [TypeParameters.Length];
+ for (int i = 0; i < TypeParameters.Length; i++)
+ param_names [i] = TypeParameters [i].Name;
+
+ GenericTypeParameterBuilder[] gen_params;
+
+ gen_params = TypeBuilder.DefineGenericParameters (param_names);
+
+ for (int i = 0; i < gen_params.Length; i++)
+ TypeParameters [i].Define (gen_params [i]);
}
if (constructed != null) {
ptype = constructed.ResolveType (ec);
- if (ptype == null)
+ if (ptype == null) {
+ error = true;
return null;
+ }
TypeBuilder.SetParent (ptype);
}
if (IsGeneric) {
foreach (TypeParameter type_param in TypeParameters)
- type_param.DefineType (ec, TypeBuilder);
+ if (!type_param.DefineType (ec))
+ error = true;
+
+ if (error)
+ return null;
}
//
// be specified.
//
- if (!is_class && !have_nonstatic_fields){
+ if (!is_class && !is_iface && !have_nonstatic_fields){
TypeBuilder.DefineField ("$PRIVATE$", TypeManager.byte_type,
FieldAttributes.Private);
}
// add interfaces that were not added at type creation
if (ifaces != null) {
- foreach (TypeExpr iface in ifaces) {
- Type itype = iface.ResolveType (ec);
- TypeBuilder.AddInterfaceImplementation (itype);
+ Type[] itypes = new Type[ifaces.Length];
+ for (int i = 0; i < ifaces.Length; ++i) {
+ Type itype = ifaces [i].ResolveType (ec);
+ TypeBuilder.AddInterfaceImplementation (itype);
+ itypes [i] = itype;
+ }
+
+ if (error)
+ return null;
+
+ if (!CheckGenericInterfaces (itypes)) {
+ error = true;
+ return null;
}
}
//
ec.ContainerType = TypeBuilder;
- TypeManager.AddUserType (Name, TypeBuilder, this, ifaces);
-
if ((parent != null) && parent.IsAttribute) {
RootContext.RegisterAttribute (this);
- TypeManager.RegisterAttrType (TypeBuilder, this);
} else
RootContext.RegisterOrder (this);
//
// Defines the indexers, and also verifies that the IndexerNameAttribute in the
- // class is consisten. Either it is `Item' or it is the name defined by all the
+ // class is consistent. Either it is `Item' or it is the name defined by all the
// indexers with the `IndexerName' attribute.
//
// Turns out that the IndexerNameAttribute is applied to each indexer,
- // but it is never emitted, instead a DefaultName attribute is attached
+ // but it is never emitted, instead a DefaultMember attribute is attached
// to the class.
//
void DefineIndexers ()
// explicit one actually implements the interface while the other one is just
// a normal indexer. See bug #37714.
//
- ArrayList list = new ArrayList ();
- foreach (Indexer i in Indexers){
- if (i.ExplicitInterfaceName != null)
- list.Add (i);
- }
- foreach (Indexer i in Indexers){
- if (i.ExplicitInterfaceName == null)
- list.Add (i);
- }
- foreach (Indexer i in list){
+ // Invariant maintained by AddIndexer(): All explicit interface indexers precede normal indexers
+ bool seen_normal_indexers = false;
+ foreach (Indexer i in Indexers) {
string name;
i.Define (this);
name = i.IndexerName;
- if (i.InterfaceType != null)
+ if (i.InterfaceType != null) {
+ if (seen_normal_indexers)
+ throw new Exception ("Internal Error: 'Indexers' array not sorted properly.");
continue;
+ }
- if (class_indexer_name == null){
+ seen_normal_indexers = true;
+
+ if (class_indexer_name == null)
class_indexer_name = name;
- continue;
- }
-
- if (name == class_indexer_name)
- continue;
-
- Report.Error (
- 668, "Two indexers have different names, " +
- " you should use the same name for all your indexers");
+ else if (name != class_indexer_name)
+ Report.Error (668, "Two indexers have different names, " +
+ " you should use the same name for all your indexers");
}
- if (class_indexer_name == null)
+
+ if (seen_normal_indexers && class_indexer_name == null)
class_indexer_name = "Item";
IndexerName = class_indexer_name;
}
/// Populates our TypeBuilder with fields and methods
/// </summary>
public override bool DefineMembers (TypeContainer container)
+ {
+ if (members_defined)
+ return members_defined_ok;
+
+ members_defined_ok = DoDefineMembers ();
+ members_defined = true;
+
+ return members_defined_ok;
+ }
+
+ bool DoDefineMembers ()
{
MemberInfo [] defined_names = null;
+ //
+ // We need to be able to use the member cache while we are checking/defining
+ //
+#if CACHE
+ if (TypeBuilder.BaseType != null)
+ parent_container = TypeManager.LookupMemberContainer (TypeBuilder.BaseType);
+#endif
+
if (interface_order != null){
foreach (Interface iface in interface_order)
if ((iface.ModFlags & Modifiers.NEW) == 0)
Class pclass = Parent as Class;
if (pclass != null) {
string pname = null;
- Type ptype = null;
+ TypeExpr ptype = null;
Type t = pclass.TypeBuilder.BaseType;
while ((t != null) && (ptype == null)) {
pname = t.FullName + "." + Basename;
ReportStructInitializedInstanceError ();
}
+ if (!(this is Interface))
Pending = PendingImplementation.GetPendingImplementations (this);
//
if (events != null)
DefineMembers (events, defined_names);
- if (indexers != null) {
+ if (indexers != null)
DefineIndexers ();
- } else
- IndexerName = "Item";
if (operators != null){
DefineMembers (operators, null);
if (delegates != null)
DefineMembers (delegates, defined_names);
-#if CACHE
- if (TypeBuilder.BaseType != null)
- parent_container = TypeManager.LookupMemberContainer (TypeBuilder.BaseType);
+ if (CurrentType != null) {
+ GenericType = CurrentType.ResolveType (ec);
+ ec.ContainerType = GenericType;
+ }
+
+
+#if CACHE
member_cache = new MemberCache (this);
#endif
mif_compare = new MemberInfoCompare ();
}
+ public MethodInfo[] GetMethods ()
+ {
+ ArrayList members = new ArrayList ();
+
+ DefineMembers (null);
+
+ if (methods != null) {
+ int len = methods.Count;
+ for (int i = 0; i < len; i++) {
+ Method m = (Method) methods [i];
+
+ members.Add (m.MethodBuilder);
+ }
+ }
+
+ if (operators != null) {
+ int len = operators.Count;
+ for (int i = 0; i < len; i++) {
+ Operator o = (Operator) operators [i];
+
+ members.Add (o.OperatorMethodBuilder);
+ }
+ }
+
+ if (properties != null) {
+ int len = properties.Count;
+ for (int i = 0; i < len; i++) {
+ Property p = (Property) properties [i];
+
+ if (p.GetBuilder != null)
+ members.Add (p.GetBuilder);
+ if (p.SetBuilder != null)
+ members.Add (p.SetBuilder);
+ }
+ }
+
+ if (indexers != null) {
+ int len = indexers.Count;
+ for (int i = 0; i < len; i++) {
+ Indexer ix = (Indexer) indexers [i];
+
+ if (ix.GetBuilder != null)
+ members.Add (ix.GetBuilder);
+ if (ix.SetBuilder != null)
+ members.Add (ix.SetBuilder);
+ }
+ }
+
+ if (events != null) {
+ int len = events.Count;
+ for (int i = 0; i < len; i++) {
+ Event e = (Event) events [i];
+
+ if (e.AddBuilder != null)
+ members.Add (e.AddBuilder);
+ if (e.RemoveBuilder != null)
+ members.Add (e.RemoveBuilder);
+ }
+ }
+
+ MethodInfo[] retMethods = new MethodInfo [members.Count];
+ members.CopyTo (retMethods, 0);
+ return retMethods;
+ }
+
/// <summary>
/// This method returns the members of this type just like Type.FindMembers would
/// Only, we need to use this for types which are _being_ defined because MS'
//
// Lookup members in parent if requested.
//
- if (((bf & BindingFlags.DeclaredOnly) == 0) && (TypeBuilder.BaseType != null)) {
+ if ((bf & BindingFlags.DeclaredOnly) == 0) {
+ if (TypeBuilder.BaseType != null) {
MemberList list = FindMembers (TypeBuilder.BaseType, mt, bf, filter, criteria);
if (list.Count > 0) {
if (members == null)
members.AddRange (list);
}
}
+
+ if (base_inteface_types != null) {
+ foreach (Type base_type in base_inteface_types) {
+ MemberList list = TypeContainer.FindMembers (base_type, mt, bf, filter, criteria);
+
+ if (list.Count > 0) {
+ if (members == null)
+ members = new ArrayList ();
+ members.AddRange (list);
+ }
+ }
+ }
+ }
Timer.StopTimer (TimerType.TcFindMembers);
{
if (constants != null)
foreach (Const con in constants)
- con.EmitConstant (this);
+ con.Emit (this);
return;
}
- /// <summary>
- /// Emits the code, this step is performed after all
- /// the types, enumerations, constructors
- /// </summary>
- public void Emit ()
+ protected virtual void VerifyMembers (EmitContext ec)
{
- if (instance_constructors != null)
- foreach (Constructor c in instance_constructors)
- c.Emit (this);
-
- if (default_static_constructor != null)
- default_static_constructor.Emit (this);
-
- if (methods != null)
- foreach (Method m in methods)
- m.Emit (this);
-
- if (operators != null)
- foreach (Operator o in operators)
- o.Emit (this);
-
- if (properties != null)
- foreach (Property p in properties)
- p.Emit (this);
-
- if (indexers != null){
- foreach (Indexer ix in indexers)
- ix.Emit (this);
-
- CustomAttributeBuilder cb = Interface.EmitDefaultMemberAttr (
- this, IndexerName, ModFlags, Location);
- TypeBuilder.SetCustomAttribute (cb);
- }
-
- if (fields != null)
- foreach (Field f in fields)
- f.Emit (this);
-
- if (events != null){
- foreach (Event e in Events)
- e.Emit (this);
- }
-
- if (Pending != null)
- if (Pending.VerifyPendingMethods ())
- return;
-
- Attribute.ApplyAttributes (ec, TypeBuilder, this, OptAttributes);
-
//
// Check for internal or private fields that were never assigned
//
}
}
}
-
-// if (types != null)
-// foreach (TypeContainer tc in types)
-// tc.Emit ();
}
-
- public override void CloseType ()
+
+ /// <summary>
+ /// Emits the code, this step is performed after all
+ /// the types, enumerations, constructors
+ /// </summary>
+ public void Emit ()
{
- if (Created)
- return;
-
- try {
- Created = true;
- TypeBuilder.CreateType ();
- } catch (TypeLoadException){
- //
- // This is fine, the code still created the type
- //
-// Report.Warning (-20, "Exception while creating class: " + TypeBuilder.Name);
-// Console.WriteLine (e.Message);
- } catch {
- Console.WriteLine ("In type: " + Name);
- throw;
- }
-
- if (Enums != null)
- foreach (Enum en in Enums)
- en.CloseType ();
+ if (OptAttributes != null)
+ OptAttributes.Emit (ec, this);
- if (interface_order != null){
- foreach (Interface iface in interface_order)
- iface.CloseType ();
- }
-
- if (Types != null){
- foreach (TypeContainer tc in Types)
- if (tc is Struct)
- tc.CloseType ();
+ Emit (this);
- foreach (TypeContainer tc in Types)
- if (!(tc is Struct))
- tc.CloseType ();
- }
+ if (instance_constructors != null) {
+ if (TypeBuilder.IsSubclassOf (TypeManager.attribute_type) && IsClsCompliaceRequired (this)) {
+ bool has_compliant_args = false;
- if (Delegates != null)
- foreach (Delegate d in Delegates)
+ foreach (Constructor c in instance_constructors) {
+ c.Emit (this);
+
+ if (has_compliant_args)
+ continue;
+
+ has_compliant_args = c.HasCompliantArgs;
+ }
+ if (!has_compliant_args)
+ Report.Error_T (3015, Location, GetSignatureForError ());
+ } else {
+ foreach (Constructor c in instance_constructors)
+ c.Emit (this);
+ }
+ }
+
+ if (default_static_constructor != null)
+ default_static_constructor.Emit (this);
+
+ if (methods != null)
+ foreach (Method m in methods)
+ m.Emit (this);
+
+ if (operators != null)
+ foreach (Operator o in operators)
+ o.Emit (this);
+
+ if (properties != null)
+ foreach (Property p in properties)
+ p.Emit (this);
+
+ if (indexers != null){
+ foreach (Indexer ix in indexers)
+ ix.Emit (this);
+ if (IndexerName != null) {
+ CustomAttributeBuilder cb = EmitDefaultMemberAttr ();
+ TypeBuilder.SetCustomAttribute (cb);
+ }
+ }
+
+ if (fields != null)
+ foreach (Field f in fields)
+ f.Emit (this);
+
+ if (events != null){
+ foreach (Event e in Events)
+ e.Emit (this);
+ }
+
+ if (delegates != null) {
+ foreach (Delegate d in Delegates) {
+ d.Emit (this);
+ }
+ }
+
+ if (Pending != null)
+ if (Pending.VerifyPendingMethods ())
+ return;
+
+ VerifyMembers (ec);
+
+// if (types != null)
+// foreach (TypeContainer tc in types)
+// tc.Emit ();
+ }
+
+ CustomAttributeBuilder EmitDefaultMemberAttr ()
+ {
+ EmitContext ec = new EmitContext (this, Location, null, null, ModFlags);
+
+ Expression ml = Expression.MemberLookup (ec, TypeManager.default_member_type,
+ ".ctor", MemberTypes.Constructor,
+ BindingFlags.Public | BindingFlags.Instance,
+ Location.Null);
+
+ MethodGroupExpr mg = (MethodGroupExpr) ml;
+
+ MethodBase constructor = mg.Methods [0];
+
+ string [] vals = { IndexerName };
+
+ CustomAttributeBuilder cb = null;
+ try {
+ cb = new CustomAttributeBuilder ((ConstructorInfo) constructor, vals);
+ } catch {
+ Report.Warning (-100, "Can not set the indexer default member attribute");
+ }
+
+ return cb;
+ }
+
+ public override void CloseType ()
+ {
+ if ((caching_flags & Flags.CloseTypeCreated) != 0)
+ return;
+
+ try {
+ caching_flags |= Flags.CloseTypeCreated;
+ TypeBuilder.CreateType ();
+ } catch (TypeLoadException){
+ //
+ // This is fine, the code still created the type
+ //
+// Report.Warning (-20, "Exception while creating class: " + TypeBuilder.Name);
+// Console.WriteLine (e.Message);
+ } catch {
+ Console.WriteLine ("In type: " + Name);
+ throw;
+ }
+
+ if (Enums != null)
+ foreach (Enum en in Enums)
+ en.CloseType ();
+
+ if (interface_order != null){
+ foreach (Interface iface in interface_order)
+ iface.CloseType ();
+ }
+
+ if (Types != null){
+ foreach (TypeContainer tc in Types)
+ if (tc is Struct)
+ tc.CloseType ();
+
+ foreach (TypeContainer tc in Types)
+ if (!(tc is Struct))
+ tc.CloseType ();
+ }
+
+ if (Delegates != null)
+ foreach (Delegate d in Delegates)
d.CloseType ();
types = null;
return true;
}
+ protected override bool VerifyClsCompliance (DeclSpace ds)
+ {
+ if (!base.VerifyClsCompliance (ds))
+ return false;
+
+ // parent_container is null for System.Object
+ if (parent_container != null && !AttributeTester.IsClsCompliant (parent_container.Type)) {
+ Report.Error_T (3009, Location, GetSignatureForError (), TypeManager.CSharpName (parent_container.Type));
+ }
+ return true;
+ }
+
+
/// <summary>
/// Performs checks for an explicit interface implementation. First it
/// checks whether the `interface_type' is a base inteface implementation.
bool IMemberContainer.IsInterface {
get {
- return false;
+ return this is Interface;
}
}
MemberList IMemberContainer.GetMembers (MemberTypes mt, BindingFlags bf)
{
- return FindMembers (mt, bf | BindingFlags.DeclaredOnly, null, null);
+ BindingFlags new_bf = bf | BindingFlags.DeclaredOnly;
+
+ if (GenericType != null)
+ return TypeManager.FindMembers (GenericType, mt, new_bf,
+ null, null);
+ else
+ return FindMembers (mt, new_bf, null, null);
}
//
}
- public class Class : TypeContainer {
+ public class ClassOrStruct : TypeContainer {
+ bool hasExplicitLayout = false;
+ public ClassOrStruct (NamespaceEntry ns, TypeContainer parent, MemberName name,
+ Attributes attrs, Location l)
+ : base (ns, parent, name, attrs, l)
+ {
+ }
+
+ protected override void VerifyMembers (EmitContext ec)
+ {
+ if (Fields != null) {
+ foreach (Field f in Fields) {
+ if ((f.ModFlags & Modifiers.STATIC) != 0)
+ continue;
+ if (hasExplicitLayout) {
+ if (f.OptAttributes == null
+ || !f.OptAttributes.Contains (TypeManager.field_offset_attribute_type, ec)) {
+ Report.Error (625, f.Location,
+ "Instance field of type marked with"
+ + " StructLayout(LayoutKind.Explicit) must have a"
+ + " FieldOffset attribute.");
+ }
+ }
+ else {
+ if (f.OptAttributes != null
+ && f.OptAttributes.Contains (TypeManager.field_offset_attribute_type, ec)) {
+ Report.Error (636, f.Location,
+ "The FieldOffset attribute can only be placed on members of "
+ + "types marked with the StructLayout(LayoutKind.Explicit)");
+ }
+ }
+ }
+ }
+ base.VerifyMembers (ec);
+ }
+
+ public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+ {
+ if (a.Type == TypeManager.struct_layout_attribute_type
+ && (LayoutKind) a.GetPositionalValue (0) == LayoutKind.Explicit)
+ hasExplicitLayout = true;
+
+ base.ApplyAttributeBuilder (a, cb);
+ }
+ }
+
+ public class Class : ClassOrStruct {
// <summary>
// Modifiers allowed in a class declaration
// </summary>
Modifiers.SEALED |
Modifiers.UNSAFE;
- public Class (NamespaceEntry ns, TypeContainer parent, string name, int mod, Attributes attrs, Location l)
+ // Information in the case we are an attribute type
+ AttributeUsageAttribute attribute_usage;
+
+ public Class (NamespaceEntry ns, TypeContainer parent, MemberName name,
+ int mod, Attributes attrs, Location l)
: base (ns, parent, name, attrs, l)
{
int accmods;
accmods = Modifiers.PRIVATE;
this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, l);
+ attribute_usage = new AttributeUsageAttribute (AttributeTargets.All);
+ }
+
+ public override AttributeTargets AttributeTargets {
+ get {
+ return AttributeTargets.Class;
+ }
+ }
+
+ public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
+ {
+ if (a.UsageAttribute != null)
+ attribute_usage = a.UsageAttribute;
+
+ base.ApplyAttributeBuilder (a, cb);
+ }
+
+ public AttributeUsageAttribute AttributeUsage {
+ get {
+ return attribute_usage;
+ }
}
//
}
}
- public class Struct : TypeContainer {
+ public class Struct : ClassOrStruct {
// <summary>
// Modifiers allowed in a struct declaration
// </summary>
Modifiers.UNSAFE |
Modifiers.PRIVATE;
- public Struct (NamespaceEntry ns, TypeContainer parent, string name, int mod, Attributes attrs, Location l)
+ public Struct (NamespaceEntry ns, TypeContainer parent, MemberName name,
+ int mod, Attributes attrs, Location l)
: base (ns, parent, name, attrs, l)
{
int accmods;
this.ModFlags |= Modifiers.SEALED;
}
+ public override AttributeTargets AttributeTargets {
+ get {
+ return AttributeTargets.Struct;
+ }
+ }
+
+
//
// FIXME: Allow the user to specify a different set of attributes
// in some cases (Sealed for example is mandatory for a class,
}
}
+ /// <summary>
+ /// Interfaces
+ /// </summary>
+ public class Interface : TypeContainer, IMemberContainer {
+ /// <summary>
+ /// Modifiers allowed in a class declaration
+ /// </summary>
+ public const int AllowedModifiers =
+ Modifiers.NEW |
+ Modifiers.PUBLIC |
+ Modifiers.PROTECTED |
+ Modifiers.INTERNAL |
+ Modifiers.UNSAFE |
+ Modifiers.PRIVATE;
+
+ public Interface (NamespaceEntry ns, TypeContainer parent, MemberName name,
+ int mod, Attributes attrs, Location l)
+ : base (ns, parent, name, attrs, l)
+ {
+ int accmods;
+
+ if (parent.Parent == null)
+ accmods = Modifiers.INTERNAL;
+ else
+ accmods = Modifiers.PRIVATE;
+
+ this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, l);
+ }
+
+ public override AttributeTargets AttributeTargets {
+ get {
+ return AttributeTargets.Interface;
+ }
+ }
+
+ public override TypeAttributes TypeAttr {
+ get {
+ return base.TypeAttr |
+ TypeAttributes.AutoLayout |
+ TypeAttributes.Abstract |
+ TypeAttributes.Interface;
+ }
+ }
+ }
+
public abstract class MethodCore : MemberBase {
public readonly Parameters Parameters;
+ public readonly GenericMethod GenericMethod;
protected Block block;
- protected DeclSpace ds;
+ public DeclSpace ds;
//
// Parameters, cached for semantic analysis.
// </summary>
public bool OverridesSomething;
+ // Whether this is an operator method.
+ public bool IsOperator;
+
+ static string[] attribute_targets = new string [] { "method", "return" };
+
public MethodCore (DeclSpace ds, Expression type, int mod, int allowed_mod,
- string name, Attributes attrs, Parameters parameters, Location loc)
+ bool is_interface, MemberName name, Attributes attrs,
+ Parameters parameters, Location loc)
: base (type, mod, allowed_mod, Modifiers.PRIVATE, name, attrs, loc)
{
Parameters = parameters;
+ IsInterface = is_interface;
this.ds = ds;
+ this.GenericMethod = ds as GenericMethod;
}
//
return true;
}
- public CallingConventions GetCallingConvention (bool is_class)
+ void error_425 (Type old, Type t, string name)
{
- CallingConventions cc = 0;
-
- cc = Parameters.GetCallingConvention ();
-
- if (is_class)
- if ((ModFlags & Modifiers.STATIC) == 0)
- cc |= CallingConventions.HasThis;
-
- // FIXME: How is `ExplicitThis' used in C#?
-
- return cc;
+ Report.Error (425, Location,
+ "The constraints of type parameter `{0}' " +
+ "of method `{1}' must match the constraints for " +
+ "type parameter `{2}' of method `{3}'",
+ TypeManager.CSharpName (old), Name,
+ TypeManager.CSharpName (t), name);
}
- //
- // The method's attributes are passed in because we need to extract
- // the "return:" attribute from there to apply on the return type
- //
- static public void LabelParameters (EmitContext ec,
- MethodBase builder,
- Parameters parameters,
- Attributes method_attrs,
- Location loc)
+ protected override bool CheckGenericOverride (MethodInfo method, string name)
{
- //
- // Define each type attribute (in/out/ref) and
- // the argument names.
- //
- Parameter [] p = parameters.FixedParameters;
- int i = 0;
-
- MethodBuilder mb = null;
- ConstructorBuilder cb = null;
+ ParameterData pd = Invocation.GetParameterData (method);
- if (builder is MethodBuilder)
- mb = (MethodBuilder) builder;
- else
- cb = (ConstructorBuilder) builder;
+ for (int i = 0; i < ParameterTypes.Length; i++) {
+ GenericConstraints ogc = pd.GenericConstraints (i);
+ GenericConstraints gc = ParameterInfo.GenericConstraints (i);
- if (p != null){
- for (i = 0; i < p.Length; i++) {
- ParameterBuilder pb;
- ParameterAttributes par_attr = p [i].Attributes;
-
- if (mb == null)
- pb = cb.DefineParameter (
- i + 1, par_attr, p [i].Name);
- else
- pb = mb.DefineParameter (
- i + 1, par_attr, p [i].Name);
-
- Attributes attr = p [i].OptAttributes;
- if (attr != null){
- Attribute.ApplyAttributes (ec, pb, pb, attr);
-
- if (par_attr == ParameterAttributes.Out){
- if (attr.Contains (TypeManager.in_attribute_type))
- Report.Error (36, loc,
- "Can not use [In] attribute on out parameter");
- }
- }
+ if ((gc == null) && (ogc == null))
+ continue;
+
+ Type ot = pd.ParameterType (i);
+ Type t = ParameterTypes [i];
+
+ if (!((gc != null) && (ogc != null))) {
+ error_425 (ot, t, name);
+ return false;
}
- }
- if (parameters.ArrayParameter != null){
- ParameterBuilder pb;
- Parameter array_param = parameters.ArrayParameter;
+ if (gc.HasConstructor != ogc.HasConstructor) {
+ error_425 (ot, t, name);
+ return false;
+ }
- if (mb == null)
- pb = cb.DefineParameter (
- i + 1, array_param.Attributes,
- array_param.Name);
- else
- pb = mb.DefineParameter (
- i + 1, array_param.Attributes,
- array_param.Name);
-
- CustomAttributeBuilder a = new CustomAttributeBuilder (
- TypeManager.cons_param_array_attribute, new object [0]);
-
- pb.SetCustomAttribute (a);
- }
+ if (ogc.HasClassConstraint != gc.HasClassConstraint) {
+ error_425 (ot, t, name);
+ return false;
+ }
- //
- // And now for the return type attribute decoration
- //
- ParameterBuilder ret_pb;
- Attributes ret_attrs = null;
-
- if (mb == null || method_attrs == null)
- return;
+ if (ogc.HasClassConstraint &&
+ !ogc.ClassConstraint.Equals (gc.ClassConstraint)) {
+ error_425 (ot, t, name);
+ return false;
+ }
- foreach (AttributeSection asec in method_attrs.AttributeSections) {
+ Type[] oct = ogc.InterfaceConstraints;
+ Type[] ct = gc.InterfaceConstraints;
- if (asec.Target != "return")
- continue;
+ if (oct.Length != ct.Length) {
+ error_425 (ot, t, name);
+ return false;
+ }
- if (ret_attrs == null)
- ret_attrs = new Attributes (asec);
- else
- ret_attrs.AddAttributeSection (asec);
+ for (int j = 0; j < oct.Length; j++)
+ if (!oct [j].Equals (ct [j])) {
+ error_425 (ot, t, name);
+ return false;
+ }
}
- if (ret_attrs != null) {
- try {
- ret_pb = mb.DefineParameter (0, ParameterAttributes.None, "");
- Attribute.ApplyAttributes (ec, ret_pb, ret_pb, ret_attrs);
+ return true;
+ }
- } catch (ArgumentOutOfRangeException) {
- Report.Warning (
- -24, loc,
- ".NET SDK 1.0 does not permit setting custom attributes" +
- " on the return type of a method");
- }
+ protected override string[] ValidAttributeTargets {
+ get {
+ return attribute_targets;
}
}
- }
- public class Method : MethodCore, IIteratorContainer {
- public MethodBuilder MethodBuilder;
- public MethodData MethodData;
- public readonly GenericMethod GenericMethod;
+ protected override bool VerifyClsCompliance (DeclSpace ds)
+ {
+ if (!base.VerifyClsCompliance (ds)) {
+ if ((ModFlags & Modifiers.ABSTRACT) != 0 && IsExposedFromAssembly (ds) && ds.IsClsCompliaceRequired (ds)) {
+ Report.Error_T (3011, Location, GetSignatureForError ());
+ }
+ return false;
+ }
- /// <summary>
- /// Modifiers allowed in a class declaration
- /// </summary>
- const int AllowedModifiers =
+ AttributeTester.AreParametersCompliant (Parameters.FixedParameters, Location);
+
+ if (!AttributeTester.IsClsCompliant (MemberType)) {
+ Report.Error_T (3002, Location, GetSignatureForError ());
+ }
+
+ return true;
+ }
+
+ protected bool IsDuplicateImplementation (TypeContainer tc, MethodCore method)
+ {
+ if ((method == this) || (method.Name != Name))
+ return false;
+
+ Type[] param_types = method.ParameterTypes;
+ if (param_types == null)
+ return false;
+
+ if (param_types.Length != ParameterTypes.Length)
+ return false;
+
+ int type_params = 0;
+ if (GenericMethod != null)
+ type_params = GenericMethod.CountTypeParameters;
+
+ int m_type_params = 0;
+ if (method.GenericMethod != null)
+ m_type_params = method.GenericMethod.CountTypeParameters;
+
+ if (type_params != m_type_params)
+ return false;
+
+ bool equal = true;
+ bool may_unify;
+
+ Type[] infered_types = new Type [param_types.Length];
+ may_unify = Invocation.InferTypeArguments (
+ param_types, ParameterTypes, ref infered_types);
+
+ if (!may_unify) {
+ infered_types = new Type [param_types.Length];
+ may_unify = Invocation.InferTypeArguments (
+ ParameterTypes, param_types, ref infered_types);
+ }
+
+ for (int i = 0; i < param_types.Length; i++) {
+ Type a = param_types [i];
+ Type b = ParameterTypes [i];
+
+ if (a != b)
+ equal = false;
+ }
+
+ if (equal) {
+ //
+ // Try to report 663: method only differs on out/ref
+ //
+ ParameterData info = ParameterInfo;
+ ParameterData other_info = method.ParameterInfo;
+ for (int i = 0; i < info.Count; i++){
+ if (info.ParameterModifier (i) != other_info.ParameterModifier (i)){
+ Report.Error (663, Location,
+ "Overload method only differs " +
+ "in parameter modifier");
+ return false;
+ }
+ }
+
+ Report.Error (111, Location,
+ "Class `{0}' already defines a member called " +
+ "`{1}' with the same parameter types",
+ tc.Name, Name);
+ return true;
+ } else if (may_unify) {
+ Report.Error (408, Location,
+ "`{0}' cannot define overload members that " +
+ "may unify for some type parameter substitutions",
+ tc.Name);
+ return true;
+ }
+
+ return false;
+ }
+
+ public CallingConventions GetCallingConvention (bool is_class)
+ {
+ CallingConventions cc = 0;
+
+ cc = Parameters.GetCallingConvention ();
+
+ if (is_class)
+ if ((ModFlags & Modifiers.STATIC) == 0)
+ cc |= CallingConventions.HasThis;
+
+ // FIXME: How is `ExplicitThis' used in C#?
+
+ return cc;
+ }
+ }
+
+ public class Method : MethodCore, IIteratorContainer, IMethodData {
+ public MethodBuilder MethodBuilder;
+ public MethodData MethodData;
+ ReturnParameter return_attributes;
+
+ /// <summary>
+ /// Modifiers allowed in a class declaration
+ /// </summary>
+ const int AllowedModifiers =
Modifiers.NEW |
Modifiers.PUBLIC |
Modifiers.PROTECTED |
Modifiers.OVERRIDE |
Modifiers.ABSTRACT |
Modifiers.UNSAFE |
+ Modifiers.METHOD_YIELDS |
Modifiers.EXTERN;
+ const int AllowedInterfaceModifiers =
+ Modifiers.NEW | Modifiers.UNSAFE;
+
//
// return_type can be "null" for VOID values.
//
- public Method (DeclSpace ds, Expression return_type, int mod, string name,
- Parameters parameters, Attributes attrs, Location l)
- : base (ds, return_type, mod, AllowedModifiers, name, attrs, parameters, l)
- { }
-
- public Method (GenericMethod generic, Expression return_type, int mod, string name,
- Parameters parameters, Attributes attrs, Location l)
- : base (generic, return_type, mod, AllowedModifiers, name, attrs, parameters, l)
+ public Method (DeclSpace ds, Expression return_type, int mod, bool is_iface,
+ MemberName name, Parameters parameters, Attributes attrs,
+ Location l)
+ : base (ds, return_type, mod,
+ is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
+ is_iface, name, attrs, parameters, l)
{
- GenericMethod = generic;
}
+ public override AttributeTargets AttributeTargets {
+ get {
+ return AttributeTargets.Method | AttributeTargets.ReturnValue;
+ }
+ }
+
//
// Returns the `System.Type' for the ReturnType of this
// function. Provides a nice cache. (used between semantic analysis
return MemberType;
}
- // Whether this is an operator method.
- public bool IsOperator;
+ public override string GetSignatureForError()
+ {
+ return TypeManager.CSharpSignature (MethodBuilder);
+ }
void DuplicateEntryPoint (MethodInfo b, Location location)
{
return false;
}
+ public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+ {
+ if (a.Target == "return") {
+ if (return_attributes == null)
+ return_attributes = new ReturnParameter (MethodBuilder, Location);
+
+ return_attributes.ApplyAttributeBuilder (a, cb);
+ return;
+ }
+
+ if (a.Type == TypeManager.methodimpl_attr_type && a.IsInternalCall) {
+ MethodBuilder.SetImplementationFlags (MethodImplAttributes.InternalCall | MethodImplAttributes.Runtime);
+ }
+
+ if (a.Type == TypeManager.dllimport_type)
+ return;
+
+ MethodBuilder.SetCustomAttribute (cb);
+ }
+
//
// Checks our base implementation if any
//
if (IsOperator) {
flags |= MethodAttributes.SpecialName | MethodAttributes.HideBySig;
} else {
- MemberList mi_this;
-
- mi_this = TypeContainer.FindMembers (
- container.TypeBuilder, MemberTypes.Method,
- BindingFlags.NonPublic | BindingFlags.Public |
- BindingFlags.Static | BindingFlags.Instance |
- BindingFlags.DeclaredOnly,
- MethodSignature.method_signature_filter, ms);
-
- if (mi_this.Count > 0) {
- Report.Error (111, Location, "Class `" + container.Name + "' " +
- "already defines a member called `" + Name + "' " +
- "with the same parameter types");
- return false;
+ //
+ // Check in our class for dups
+ //
+ ArrayList ar = container.Methods;
+ if (ar != null) {
+ int arLen = ar.Count;
+
+ for (int i = 0; i < arLen; i++) {
+ Method m = (Method) ar [i];
+ if (IsDuplicateImplementation (container, m))
+ return false;
+ }
}
- }
+ }
+
//
// Verify if the parent has a type with the same name, and then
Type ptype = container.TypeBuilder.BaseType;
// ptype is only null for System.Object while compiling corlib.
- if (ptype != null){
- MemberList mi, mi_static, mi_instance;
-
- mi_instance = TypeContainer.FindMembers (
- ptype, MemberTypes.Method,
- BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance,
- MethodSignature.inheritable_method_signature_filter,
- ms);
-
- if (mi_instance.Count > 0){
- mi = mi_instance;
- } else {
- mi_static = TypeContainer.FindMembers (
- ptype, MemberTypes.Method,
- BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static,
- MethodSignature.inheritable_method_signature_filter, ms);
-
- if (mi_static.Count > 0)
- mi = mi_static;
- else
- mi = null;
+ if (ptype != null) {
+
+ //
+ // Explicit implementations do not have `parent' methods, however,
+ // the member cache stores them there. Without this check, we get
+ // an incorrect warning in corlib.
+ //
+ if (! IsExplicitImpl) {
+ parent_method = (MethodInfo)((IMemberContainer)container).Parent.MemberCache.FindMemberToOverride (
+ container.TypeBuilder, Name, ParameterTypes, false);
}
-
- if (mi != null && mi.Count > 0){
- parent_method = (MethodInfo) mi [0];
+
+ if (parent_method != null) {
string name = parent_method.DeclaringType.Name + "." +
parent_method.Name;
Type parent_ret = TypeManager.TypeToCoreType (
parent_method.ReturnType);
- if (parent_ret != MemberType) {
+ if (!parent_ret.Equals (MemberType)) {
Report.Error (
508, Location, container.MakeName (Name) + ": cannot " +
"change return type when overriding " +
//
public override bool Define (TypeContainer container)
{
- if (!DoDefine (container))
- return false;
-
+ DeclSpace decl;
MethodBuilder mb = null;
if (GenericMethod != null) {
mb = container.TypeBuilder.DefineGenericMethod (Name, flags);
- if (!GenericMethod.Define (mb))
+ if (!GenericMethod.Define (container, mb))
return false;
- }
+ decl = GenericMethod;
+ } else
+ decl = container;
- if (!CheckBase (container))
+ if (!DoDefine (decl, container))
return false;
- CallingConventions cc = GetCallingConvention (container is Class);
+ if (!CheckBase (container))
+ return false;
- MethodData = new MethodData (ds, this, null, MemberType,
- ParameterTypes, ParameterInfo, cc,
- OptAttributes, ModFlags, flags, true, mb);
+ MethodData = new MethodData (this, ParameterInfo, ModFlags, flags,
+ true, this, mb, GenericMethod);
if (!MethodData.Define (container))
return false;
//
// Emits the code
//
- public void Emit (TypeContainer container)
+ public override void Emit (TypeContainer container)
{
- MethodData.Emit (container, Block, this);
+ MethodData.Emit (container, this);
+ base.Emit (container);
Block = null;
MethodData = null;
}
{
ModFlags |= Modifiers.METHOD_YIELDS;
}
+
+ protected override bool IsIdentifierClsCompliant (DeclSpace ds)
+ {
+ return IsIdentifierAndParamClsCompliant (ds, Name, MethodBuilder, parameter_types);
+ }
+
+ #region IMethodData Members
+
+ public CallingConventions CallingConventions {
+ get {
+ CallingConventions cc = Parameters.GetCallingConvention ();
+
+ if (!IsInterface)
+ if ((ModFlags & Modifiers.STATIC) == 0)
+ cc |= CallingConventions.HasThis;
+
+ // FIXME: How is `ExplicitThis' used in C#?
+
+ return cc;
+ }
+ }
+
+ public Type ReturnType {
+ get {
+ return MemberType;
+ }
+ }
+
+ public string MethodName {
+ get {
+ return ShortName;
+ }
+ }
+
+ public new Location Location {
+ get {
+ return base.Location;
+ }
+ }
+
+ public EmitContext CreateEmitContext (TypeContainer tc, ILGenerator ig)
+ {
+ return new EmitContext (tc, ds, Location, ig, ReturnType, ModFlags, false);
+ }
+
+ #endregion
}
public abstract class ConstructorInitializer {
}
}
- public bool Resolve (EmitContext ec)
+ public bool Resolve (ConstructorBuilder caller_builder, EmitContext ec)
{
Expression parent_constructor_group;
Type t;
t = ec.ContainerType;
parent_constructor_group = Expression.MemberLookup (
- ec, t, null, t, ".ctor",
- MemberTypes.Constructor,
+ ec, t, ".ctor", MemberTypes.Constructor,
BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly,
loc);
if (parent_constructor_group == null){
- Report.Error (1501, loc,
- "Can not find a constructor for this argument list");
+ parent_constructor_group = Expression.MemberLookup (
+ ec, t, ".ctor", MemberTypes.Constructor,
+ BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly,
+ loc);
+
+ if (parent_constructor_group != null)
+ Report.Error (
+ 112, loc, "`{0}.{1}' is inaccessible due to " +
+ "its protection level", t.FullName, t.Name);
+ else
+ Report.Error (
+ 1501, loc, "Can not find a constructor for " +
+ "this argument list");
return false;
}
- parent_constructor = (ConstructorInfo) Invocation.OverloadResolve (ec,
- (MethodGroupExpr) parent_constructor_group, argument_list, loc);
+ parent_constructor = (ConstructorInfo) Invocation.OverloadResolve (
+ ec, (MethodGroupExpr) parent_constructor_group, argument_list,
+ false, loc);
if (parent_constructor == null){
Report.Error (1501, loc,
return false;
}
+ if (parent_constructor == caller_builder){
+ Report.Error (515, String.Format ("Constructor `{0}' can not call itself", TypeManager.CSharpSignature (caller_builder)));
+ return false;
+ }
+
return true;
}
Modifiers.EXTERN |
Modifiers.PRIVATE;
+ bool has_compliant_args = false;
//
// The spec claims that static is not permitted, but
// my very own code has static constructors.
//
- public Constructor (DeclSpace ds, string name, Parameters args,
+ public Constructor (DeclSpace ds, string name, int mod, Parameters args,
ConstructorInitializer init, Location l)
- : base (ds, null, 0, AllowedModifiers, name, null, args, l)
+ : base (ds, null, mod, AllowedModifiers, false,
+ new MemberName (name), null, args, l)
{
Initializer = init;
}
+ public override string GetSignatureForError()
+ {
+ return TypeManager.CSharpSignature (ConstructorBuilder);
+ }
+
+ public bool HasCompliantArgs {
+ get {
+ return has_compliant_args;
+ }
+ }
+
+ public override AttributeTargets AttributeTargets {
+ get {
+ return AttributeTargets.Constructor;
+ }
+ }
+
+
//
// Returns true if this is a default constructor
//
(Initializer.Arguments == null);
}
+ public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+ {
+ ConstructorBuilder.SetCustomAttribute (cb);
+ }
+
+ protected override bool CheckBase (TypeContainer container)
+ {
+ base.CheckBase (container);
+
+ // Check whether arguments were correct.
+ if (!DoDefineParameters ())
+ return false;
+
+ if ((ModFlags & Modifiers.STATIC) != 0)
+ return true;
+
+ if (container is Struct && ParameterTypes.Length == 0) {
+ Report.Error (568, Location,
+ "Structs can not contain explicit parameterless " +
+ "constructors");
+ return false;
+ }
+
+ //
+ // Check in our class for dups
+ //
+ ArrayList ar = container.InstanceConstructors;
+ if (ar != null) {
+ int arLen = ar.Count;
+
+ for (int i = 0; i < arLen; i++) {
+ Constructor m = (Constructor) ar [i];
+ if (IsDuplicateImplementation (container, m))
+ return false;
+ }
+ }
+
+ return true;
+ }
+
//
// Creates the ConstructorBuilder
//
MethodAttributes ca = (MethodAttributes.RTSpecialName |
MethodAttributes.SpecialName);
- // Check if arguments were correct.
- if (!DoDefineParameters ())
- return false;
-
if ((ModFlags & Modifiers.STATIC) != 0){
ca |= MethodAttributes.Static | MethodAttributes.Private;
} else {
- if (container is Struct && ParameterTypes.Length == 0){
- Report.Error (
- 568, Location,
- "Structs can not contain explicit parameterless " +
- "constructors");
- return false;
- }
ca |= MethodAttributes.HideBySig;
if ((ModFlags & Modifiers.PUBLIC) != 0)
ca |= MethodAttributes.Private;
}
+ // Check if arguments were correct.
+ if (!CheckBase (container))
+ return false;
+
ConstructorBuilder = container.TypeBuilder.DefineConstructor (
ca, GetCallingConvention (container is Class), ParameterTypes);
//
// HACK because System.Reflection.Emit is lame
//
- if (!TypeManager.RegisterMethod (ConstructorBuilder, ParameterInfo, ParameterTypes)) {
- Report.Error (
- 111, Location,
- "Class `" +container.Name+ "' already contains a definition with the " +
- "same return value and parameter types for constructor `" + Name
- + "'");
- return false;
- }
+ TypeManager.RegisterMethod (ConstructorBuilder, ParameterInfo, ParameterTypes);
return true;
}
//
// Emits the code
//
- public void Emit (TypeContainer container)
+ public override void Emit (TypeContainer container)
{
ILGenerator ig = ConstructorBuilder.GetILGenerator ();
EmitContext ec = new EmitContext (container, Location, ig, null, ModFlags, true);
// `this' access
//
ec.IsStatic = true;
- if (Initializer != null && !Initializer.Resolve (ec))
+ if (Initializer != null && !Initializer.Resolve (ConstructorBuilder, ec))
return;
ec.IsStatic = false;
}
- MethodCore.LabelParameters (ec, ConstructorBuilder,
- Parameters, OptAttributes, Location);
+ Parameters.LabelParameters (ec, ConstructorBuilder, Location);
SymbolWriter sw = CodeGen.SymbolWriter;
bool generate_debugging = false;
if ((sw != null) && (block != null) &&
!Location.IsNull (Location) &&
- !Location.IsNull (block.EndLocation)) {
-
+ !Location.IsNull (block.EndLocation) &&
+ (Location.SymbolDocument != null)) {
sw.OpenMethod (container, ConstructorBuilder, Location, block.EndLocation);
generate_debugging = true;
if ((ModFlags & Modifiers.STATIC) != 0)
container.EmitFieldInitializers (ec);
- Attribute.ApplyAttributes (ec, ConstructorBuilder, this, OptAttributes);
+ if (OptAttributes != null)
+ OptAttributes.Emit (ec, this);
// If this is a non-static `struct' constructor and doesn't have any
// initializer, it must initialize all of the struct's fields.
if (generate_debugging)
sw.CloseMethod ();
+ base.Emit (container);
+
block = null;
}
+
+ // For constructors is needed to test only parameters
+ protected override bool IsIdentifierClsCompliant (DeclSpace ds)
+ {
+ if (parameter_types == null || parameter_types.Length == 0)
+ return true;
+
+ TypeContainer tc = ds as TypeContainer;
+
+ for (int i = 0; i < tc.InstanceConstructors.Count; i++) {
+ Constructor c = (Constructor) tc.InstanceConstructors [i];
+
+ if (c == this || c.ParameterTypes.Length == 0)
+ continue;
+
+ if (!c.IsClsCompliaceRequired (ds))
+ continue;
+
+ if (!AttributeTester.AreOverloadedMethodParamsClsCompliant (parameter_types, c.ParameterTypes)) {
+ Report.Error_T (3006, Location, GetSignatureForError ());
+ return false;
+ }
+ }
+
+ if (tc.TypeBuilder.BaseType == null)
+ return true;
+
+ DeclSpace temp_ds = TypeManager.LookupDeclSpace (tc.TypeBuilder.BaseType);
+ if (temp_ds != null)
+ return IsIdentifierClsCompliant (temp_ds);
+
+ MemberInfo[] ml = tc.TypeBuilder.BaseType.FindMembers (MemberTypes.Constructor, BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance, null, null);
+ // Skip parameter-less ctor
+ if (ml.Length < 2)
+ return true;
+
+ foreach (ConstructorInfo ci in ml) {
+ object[] cls_attribute = ci.GetCustomAttributes (TypeManager.cls_compliant_attribute_type, false);
+ if (cls_attribute.Length == 1 && (!((CLSCompliantAttribute)cls_attribute[0]).IsCompliant))
+ continue;
+
+ if (!AttributeTester.AreOverloadedMethodParamsClsCompliant (parameter_types, TypeManager.GetArgumentTypes (ci))) {
+ Report.Error_T (3006, Location, GetSignatureForError ());
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ protected override bool VerifyClsCompliance (DeclSpace ds)
+ {
+ if (!base.VerifyClsCompliance (ds) || !IsExposedFromAssembly (ds)) {
+ return false;
+ }
+
+ if (ds.TypeBuilder.IsSubclassOf (TypeManager.attribute_type)) {
+ foreach (Type param in parameter_types) {
+ if (param.IsArray) {
+ return false;
+ }
+ }
+ }
+ has_compliant_args = true;
+ return true;
+ }
+
+ }
+
+ /// <summary>
+ /// Interface for MethodData class. Holds links to parent members to avoid member duplication.
+ /// </summary>
+ public interface IMethodData
+ {
+ CallingConventions CallingConventions { get; }
+ Location Location { get; }
+ string MethodName { get; }
+ Type[] ParameterTypes { get; }
+ Type ReturnType { get; }
+
+ Attributes OptAttributes { get; }
+ Block Block { get; }
+
+ EmitContext CreateEmitContext (TypeContainer tc, ILGenerator ig);
}
//
// Encapsulates most of the Method's state
//
public class MethodData {
+
+ readonly IMethodData method;
+
//
// The return type of this method
//
- public readonly Type ReturnType;
- public readonly Type[] ParameterTypes;
+ public readonly GenericMethod GenericMethod;
public readonly InternalParameters ParameterInfo;
- public readonly CallingConventions CallingConventions;
- public readonly Attributes OptAttributes;
- public readonly Location Location;
//
// Are we implementing an interface ?
//
// Protected data.
//
- protected DeclSpace ds;
protected MemberBase member;
protected int modifiers;
protected MethodAttributes flags;
protected bool is_method;
- protected string accessor_name;
+ protected Type declaring_type;
//
// It can either hold a string with the condition, or an arraylist of conditions.
object conditionals;
+ EmitContext ec;
MethodBuilder builder = null;
public MethodBuilder MethodBuilder {
}
}
- public MethodData (DeclSpace ds, MemberBase member, string name, Type return_type,
- Type [] parameter_types, InternalParameters parameters,
- CallingConventions cc, Attributes opt_attrs,
- int modifiers, MethodAttributes flags, bool is_method)
+ public Type DeclaringType {
+ get {
+ return declaring_type;
+ }
+ }
+
+ public MethodData (MemberBase member, InternalParameters parameters,
+ int modifiers, MethodAttributes flags, bool is_method,
+ IMethodData method)
{
- this.ds = ds;
this.member = member;
- this.accessor_name = name;
- this.ReturnType = return_type;
- this.ParameterTypes = parameter_types;
this.ParameterInfo = parameters;
- this.CallingConventions = cc;
- this.OptAttributes = opt_attrs;
this.modifiers = modifiers;
this.flags = flags;
this.is_method = is_method;
- this.Location = member.Location;
this.conditionals = null;
+
+ this.method = method;
}
- public MethodData (DeclSpace ds, MemberBase member, string name, Type return_type,
- Type [] parameter_types, InternalParameters parameters,
- CallingConventions cc, Attributes opt_attrs,
+ public MethodData (MemberBase member, InternalParameters parameters,
int modifiers, MethodAttributes flags, bool is_method,
- MethodBuilder builder)
- : this (ds, member, name, return_type, parameter_types, parameters,
- cc, opt_attrs, modifiers, flags, is_method)
+ IMethodData method, MethodBuilder builder,
+ GenericMethod generic)
+ : this (member, parameters, modifiers, flags, is_method, method)
{
this.builder = builder;
+ this.GenericMethod = generic;
}
//
string obsolete = null;
bool obsolete_error = false;
- public virtual bool ApplyAttributes (Attributes opt_attrs, bool is_method)
+ public virtual bool ApplyAttributes (Attributes opt_attrs, bool is_method, DeclSpace ds)
{
- if ((opt_attrs == null) || (opt_attrs.AttributeSections == null))
+ if ((opt_attrs == null) || (opt_attrs.Attrs == null))
return true;
- foreach (AttributeSection asec in opt_attrs.AttributeSections) {
- if (asec.Attributes == null)
- continue;
-
- foreach (Attribute a in asec.Attributes) {
- if (a.Name == "Conditional") {
- if (!ApplyConditionalAttribute (a))
- return false;
- } else if (a.Name == "Obsolete") {
- if (!ApplyObsoleteAttribute (a))
- return false;
- } else if (a.Name.IndexOf ("DllImport") != -1) {
- if (!is_method) {
- a.Type = TypeManager.dllimport_type;
- Attribute.Error_AttributeNotValidForElement (a, Location);
- return false;
- }
- if (!ApplyDllImportAttribute (a))
- return false;
+ foreach (Attribute a in opt_attrs.Attrs) {
+ Type attr_type = a.ResolveType (ec, true);
+ if (attr_type == TypeManager.conditional_attribute_type) {
+ if (!ApplyConditionalAttribute (a))
+ return false;
+ } else if (attr_type == TypeManager.obsolete_attribute_type) {
+ if (!ApplyObsoleteAttribute (a))
+ return false;
+ } else if (attr_type == TypeManager.dllimport_type) {
+ if (!is_method) {
+ Attribute.Error_AttributeNotValidForElement (a, method.Location);
+ return false;
}
+ if (!ApplyDllImportAttribute (a))
+ return false;
}
}
{
const int extern_static = Modifiers.EXTERN | Modifiers.STATIC;
if ((modifiers & extern_static) != extern_static) {
- Report.Error (601, Location,
+ Report.Error (601, method.Location,
"The DllImport attribute must be specified on a method " +
"marked `static' and `extern'.");
return false;
protected virtual bool ApplyObsoleteAttribute (Attribute a)
{
if (obsolete != null) {
- Report.Error (579, Location, "Duplicate `Obsolete' attribute");
+ Report.Error (579, method.Location, "Duplicate `Obsolete' attribute");
return false;
}
{
// The Conditional attribute is only valid on methods.
if (!is_method) {
- Attribute.Error_AttributeNotValidForElement (a, Location);
+ Attribute.Error_AttributeNotValidForElement (a, method.Location);
return false;
}
if (condition == null)
return false;
- if (ReturnType != TypeManager.void_type) {
- Report.Error (578, Location,
+ if (method.ReturnType != TypeManager.void_type) {
+ Report.Error (578, method.Location,
"Conditional not valid on `" + member.Name + "' " +
"because its return type is not void");
return false;
}
if ((modifiers & Modifiers.OVERRIDE) != 0) {
- Report.Error (243, Location,
+ Report.Error (243, method.Location,
"Conditional not valid on `" + member.Name + "' " +
"because it is an override method");
return false;
}
if (member.IsExplicitImpl) {
- Report.Error (577, Location,
+ Report.Error (577, method.Location,
"Conditional not valid on `" + member.Name + "' " +
"because it is an explicit interface implementation");
return false;
}
if (IsImplementing) {
- Report.Error (623, Location,
+ Report.Error (623, method.Location,
"Conditional not valid on `" + member.Name + "' " +
"because it is an interface method");
return false;
return flags;
}
- public virtual bool Define (TypeContainer container)
+ public bool Define (TypeContainer container)
{
MethodInfo implementing = null;
- string method_name, name, prefix;
+ string prefix;
- if (OptAttributes != null)
- if (!ApplyAttributes (OptAttributes, is_method))
+ if (method.OptAttributes != null)
+ if (!ApplyAttributes (method.OptAttributes, is_method, container))
return false;
if (member.IsExplicitImpl)
else
prefix = "";
- if (accessor_name != null)
- name = accessor_name + "_" + member.ShortName;
- else
- name = member.ShortName;
- method_name = prefix + name;
+ string name = method.MethodName;
+ string method_name = prefix + name;
+ Type[] ParameterTypes = method.ParameterTypes;
if (container.Pending != null){
if (member is Indexer)
implementing = container.Pending.IsInterfaceIndexer (
- member.InterfaceType, ReturnType, ParameterTypes);
+ member.InterfaceType, method.ReturnType, ParameterTypes);
else
implementing = container.Pending.IsInterfaceMethod (
- member.InterfaceType, name, ReturnType, ParameterTypes);
+ member.InterfaceType, name, method.ReturnType, ParameterTypes);
if (member.InterfaceType != null && implementing == null){
- Report.Error (539, Location, "'{0}' in explicit interface declaration is not an interface", method_name);
+ Report.Error (539, method.Location, "'{0}' in explicit interface declaration is not an interface", method_name);
return false;
}
}
//
if (member.IsExplicitImpl){
if ((modifiers & (Modifiers.PUBLIC | Modifiers.ABSTRACT | Modifiers.VIRTUAL)) != 0){
- Modifiers.Error_InvalidModifier (Location, "public, virtual or abstract");
+ Modifiers.Error_InvalidModifier (method.Location, "public, virtual or abstract");
implementing = null;
}
} else if ((flags & MethodAttributes.MemberAccessMask) != MethodAttributes.Public){
//
if ((modifiers & Modifiers.STATIC) != 0){
implementing = null;
- Modifiers.Error_InvalidModifier (Location, "static");
+ Modifiers.Error_InvalidModifier (method.Location, "static");
}
}
IsImplementing = true;
}
+ ec = method.CreateEmitContext (container, null);
+
//
// Create the MethodBuilder for the method
//
if ((flags & MethodAttributes.PinvokeImpl) != 0) {
if ((modifiers & Modifiers.STATIC) == 0) {
- Report.Error (601, Location,
+ Report.Error (601, method.Location,
"The DllImport attribute must be specified on " +
"a method marked 'static' and 'extern'.");
return false;
}
-
- EmitContext ec = new EmitContext (
- container, ds, Location, null, ReturnType, modifiers, false);
-
builder = dllimport_attribute.DefinePInvokeMethod (
ec, container.TypeBuilder, method_name, flags,
- ReturnType, ParameterTypes);
+ method.ReturnType, ParameterTypes);
} else if (builder == null)
builder = container.TypeBuilder.DefineMethod (
- method_name, flags, CallingConventions,
- ReturnType, ParameterTypes);
+ method_name, flags, method.CallingConventions,
+ method.ReturnType, ParameterTypes);
else
- builder.SetGenericMethodSignature (ReturnType, ParameterTypes);
+ builder.SetGenericMethodSignature (
+ flags, method.CallingConventions,
+ method.ReturnType, ParameterTypes);
if (builder == null)
return false;
+ if (GenericMethod != null) {
+ if (!GenericMethod.DefineType (ec, builder))
+ return false;
+ }
+
+ if (container.CurrentType != null)
+ declaring_type = container.CurrentType.ResolveType (ec);
+ else
+ declaring_type = container.TypeBuilder;
+
if ((modifiers & Modifiers.UNSAFE) != 0)
builder.InitLocals = false;
//
if (member is Indexer) {
container.Pending.ImplementIndexer (
- member.InterfaceType, builder, ReturnType,
+ member.InterfaceType, builder, method.ReturnType,
ParameterTypes, true);
} else
container.Pending.ImplementMethod (
- member.InterfaceType, name, ReturnType,
+ member.InterfaceType, name, method.ReturnType,
ParameterTypes, member.IsExplicitImpl);
if (member.IsExplicitImpl)
}
if (!TypeManager.RegisterMethod (builder, ParameterInfo, ParameterTypes)) {
- Report.Error (111, Location,
+ Report.Error (111, method.Location,
"Class `" + container.Name +
"' already contains a definition with the " +
"same return value and parameter types as the " +
//
// Emits the code
//
- public virtual void Emit (TypeContainer container, Block block, object kind)
+ public void Emit (TypeContainer container, Attributable kind)
{
- ILGenerator ig;
EmitContext ec;
if ((flags & MethodAttributes.PinvokeImpl) == 0)
- ig = builder.GetILGenerator ();
+ ec = method.CreateEmitContext (container, builder.GetILGenerator ());
else
- ig = null;
+ ec = method.CreateEmitContext (container, null);
- ec = new EmitContext (container, ds, Location, ig, ReturnType, modifiers, false);
+ Location loc = method.Location;
+ Attributes OptAttributes = method.OptAttributes;
if (OptAttributes != null)
- Attribute.ApplyAttributes (ec, builder, kind, OptAttributes);
+ OptAttributes.Emit (ec, kind);
if (member is MethodCore)
- MethodCore.LabelParameters (ec, MethodBuilder,
- ((MethodCore) member).Parameters,
- OptAttributes,
- Location);
+ ((MethodCore) member).Parameters.LabelParameters (ec, MethodBuilder, loc);
+ SymbolWriter sw = CodeGen.SymbolWriter;
+ Block block = method.Block;
+
//
// abstract or extern methods have no bodies
//
if ((modifiers & (Modifiers.ABSTRACT | Modifiers.EXTERN)) != 0){
if (block == null) {
- SymbolWriter sw = CodeGen.SymbolWriter;
-
- if ((sw != null) && ((modifiers & Modifiers.EXTERN) != 0)) {
- sw.OpenMethod (container, MethodBuilder, Location, Location);
+ if ((sw != null) && ((modifiers & Modifiers.EXTERN) != 0) &&
+ !Location.IsNull (loc) &&
+ (method.Location.SymbolDocument != null)) {
+ sw.OpenMethod (container, MethodBuilder, loc, loc);
sw.CloseMethod ();
}
//
if ((modifiers & Modifiers.ABSTRACT) != 0)
Report.Error (
- 500, Location, "Abstract method `" +
+ 500, method.Location, "Abstract method `" +
TypeManager.CSharpSignature (builder) +
"' can not have a body");
if ((modifiers & Modifiers.EXTERN) != 0)
Report.Error (
- 179, Location, "External method `" +
+ 179, method.Location, "External method `" +
TypeManager.CSharpSignature (builder) +
"' can not have a body");
//
if (block == null) {
Report.Error (
- 501, Location, "Method `" +
+ 501, method.Location, "Method `" +
TypeManager.CSharpSignature (builder) +
"' must declare a body since it is not marked " +
"abstract or extern");
//
// FIXME: This code generates buggy code
//
- if (member is Destructor)
- EmitDestructor (ec, block);
- else {
- SymbolWriter sw = CodeGen.SymbolWriter;
+ if ((sw != null) && !Location.IsNull (loc) &&
+ !Location.IsNull (block.EndLocation) &&
+ (loc.SymbolDocument != null)) {
+ sw.OpenMethod (container, MethodBuilder, loc, block.EndLocation);
- if ((sw != null) && !Location.IsNull (Location) &&
- !Location.IsNull (block.EndLocation)) {
- sw.OpenMethod (container, MethodBuilder, Location, block.EndLocation);
-
- ec.EmitTopBlock (block, ParameterInfo, Location);
+ if (member is Destructor)
+ EmitDestructor (ec, block);
+ else
+ ec.EmitTopBlock (block, ParameterInfo, loc);
sw.CloseMethod ();
- } else
- ec.EmitTopBlock (block, ParameterInfo, Location);
+ } else {
+ if (member is Destructor)
+ EmitDestructor (ec, block);
+ else
+ ec.EmitTopBlock (block, ParameterInfo, loc);
}
}
ig.BeginExceptionBlock ();
ec.ReturnLabel = finish;
ec.HasReturnLabel = true;
- ec.EmitTopBlock (block, null, Location);
+ ec.EmitTopBlock (block, null, method.Location);
// ig.MarkLabel (finish);
ig.BeginFinallyBlock ();
if (ec.ContainerType.BaseType != null) {
Expression member_lookup = Expression.MemberLookup (
ec, ec.ContainerType.BaseType, null, ec.ContainerType.BaseType,
- "Finalize", MemberTypes.Method, Expression.AllBindingFlags, Location);
+ "Finalize", MemberTypes.Method, Expression.AllBindingFlags, method.Location);
if (member_lookup != null){
MethodGroupExpr parent_destructor = ((MethodGroupExpr) member_lookup);
public Destructor (DeclSpace ds, Expression return_type, int mod, string name,
Parameters parameters, Attributes attrs, Location l)
- : base (ds, return_type, mod, name, parameters, attrs, l)
+ : base (ds, return_type, mod, false, new MemberName (name),
+ parameters, attrs, l)
{ }
}
abstract public class MemberBase : MemberCore {
public Expression Type;
- protected MethodAttributes flags;
+ public MethodAttributes flags;
protected readonly int explicit_mod_flags;
//
// The name of the interface we are explicitly implementing
//
- public string ExplicitInterfaceName = null;
+ public Expression ExplicitInterfaceName = null;
+
+ //
+ // Whether this is an interface member.
+ //
+ public bool IsInterface;
//
// If true, the interface type we are explicitly implementing
//
// The constructor is only exposed to our children
//
- protected MemberBase (Expression type, int mod, int allowed_mod, int def_mod, string name,
- Attributes attrs, Location loc)
+ protected MemberBase (Expression type, int mod, int allowed_mod, int def_mod,
+ MemberName name, Attributes attrs, Location loc)
: base (name, attrs, loc)
{
explicit_mod_flags = mod;
": can't change the access modifiers when overriding inherited " +
"member `" + name + "'");
}
+
+ protected abstract bool CheckGenericOverride (MethodInfo method, string name);
//
// Performs various checks on the MethodInfo `mb' regarding the modifier flags
"' because it is sealed.");
ok = false;
}
+
+ //
+ // Check that the constraints match when overriding a
+ // generic method.
+ //
+
+ if (!CheckGenericOverride (mb, name))
+ ok = false;
+
//
// Check that the permissions are not being changed
//
bool error = false;
foreach (Type partype in parameters){
+ if (partype == TypeManager.void_type) {
+ Report.Error (
+ 1547, Location, "Keyword 'void' cannot " +
+ "be used in this context");
+ return false;
+ }
+
if (partype.IsPointer){
if (!UnsafeOK (ds))
error = true;
return !error;
}
- protected virtual bool DoDefine (TypeContainer container)
+ protected virtual bool DoDefine (DeclSpace decl, TypeContainer container)
{
if (Name == null)
Name = "this";
+ if (IsInterface) {
+ ModFlags = Modifiers.PUBLIC |
+ Modifiers.ABSTRACT |
+ Modifiers.VIRTUAL | (ModFlags & Modifiers.UNSAFE);
+
+ flags = MethodAttributes.Public |
+ MethodAttributes.Abstract |
+ MethodAttributes.HideBySig |
+ MethodAttributes.NewSlot |
+ MethodAttributes.Virtual;
+ } else {
if (!container.MethodModifiersValid (ModFlags, Name, Location))
return false;
flags = Modifiers.MethodAttr (ModFlags);
+ }
// Lookup Type, verify validity
- MemberType = container.ResolveType (Type, false, Location);
+ MemberType = decl.ResolveType (Type, false, Location);
if (MemberType == null)
return false;
//
// Check for explicit interface implementation
//
- if ((ExplicitInterfaceName == null) && (Name.IndexOf ('.') != -1)){
- int pos = Name.LastIndexOf ('.');
-
- ExplicitInterfaceName = Name.Substring (0, pos);
- ShortName = Name.Substring (pos + 1);
+ if (MemberName.TypeName != null) {
+ ExplicitInterfaceName = MemberName.TypeName.GetTypeExpression (Location);
+ ShortName = MemberName.Name;
} else
ShortName = Name;
if (ExplicitInterfaceName != null) {
- InterfaceType = RootContext.LookupType (
- container, ExplicitInterfaceName, false, Location);
+ InterfaceType = container.ResolveType (
+ ExplicitInterfaceName, false, Location);
if (InterfaceType == null)
return false;
return true;
}
+
+ protected override bool IsIdentifierClsCompliant (DeclSpace ds)
+ {
+ return IsIdentifierAndParamClsCompliant (ds, Name, null, null);
+ }
+
+ protected override bool VerifyClsCompliance(DeclSpace ds)
+ {
+ if (base.VerifyClsCompliance (ds)) {
+ return true;
+ }
+
+ if (IsInterface && HasClsCompliantAttribute && ds.IsClsCompliaceRequired (ds)) {
+ Report.Error_T (3010, Location, GetSignatureForError ());
+ }
+ return false;
+ }
+
+
}
//
[Flags]
public enum Status : byte { ASSIGNED = 1, USED = 2 }
+ static string[] attribute_targets = new string [] { "field" };
+
//
// The constructor is only exposed to our children
//
- protected FieldBase (Expression type, int mod, int allowed_mod, string name,
+ protected FieldBase (Expression type, int mod, int allowed_mod, MemberName name,
object init, Attributes attrs, Location loc)
: base (type, mod, allowed_mod, Modifiers.PRIVATE, name, attrs, loc)
{
this.init = init;
}
+ public override AttributeTargets AttributeTargets {
+ get {
+ return AttributeTargets.Field;
+ }
+ }
+
+ public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+ {
+ if (a.Type == TypeManager.marshal_as_attr_type) {
+ UnmanagedMarshal marshal = a.GetMarshal ();
+ if (marshal != null) {
+ FieldBuilder.SetMarshal (marshal);
+ return;
+ }
+ Report.Warning_T (-24, a.Location);
+ return;
+ }
+
+
+ FieldBuilder.SetCustomAttribute (cb);
+ }
+
//
// Whether this field has an initializer.
//
Expression init_expr;
bool init_expr_initialized = false;
+ protected override bool CheckGenericOverride (MethodInfo method, string name)
+ {
+ return true;
+ }
+
//
// Resolves and returns the field initializer.
//
return init_expr;
}
+ protected override bool DoDefine (DeclSpace ds, TypeContainer container)
+ {
+ if (!base.DoDefine (ds, container))
+ return false;
+
+ if (MemberType == TypeManager.void_type) {
+ Report.Error (1547, Location,
+ "Keyword 'void' cannot be used in this context");
+ return false;
+ }
+
+ return true;
+ }
+
+ public override string GetSignatureForError ()
+ {
+ return TypeManager.GetFullNameSignature (FieldBuilder);
+ }
+
+ protected override string[] ValidAttributeTargets {
+ get {
+ return attribute_targets;
+ }
+ }
+
+ protected override bool VerifyClsCompliance (DeclSpace ds)
+ {
+ if (!base.VerifyClsCompliance (ds))
+ return false;
+
+ if (FieldBuilder == null) {
+ return true;
+ }
+
+ if (!AttributeTester.IsClsCompliant (FieldBuilder.FieldType)) {
+ Report.Error_T (3003, Location, GetSignatureForError ());
+ }
+ return true;
+ }
+
+
public void SetAssigned ()
{
status |= Status.ASSIGNED;
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)
+ : base (type, mod, AllowedModifiers, new MemberName (name),
+ expr_or_array_init, attrs, loc)
{
}
if (!((vt == TypeManager.bool_type) ||
(vt == TypeManager.sbyte_type) ||
(vt == TypeManager.byte_type) ||
- (vt == TypeManager.short_type) ||
+ (vt == TypeManager.short_type) ||
(vt == TypeManager.ushort_type) ||
- (vt == TypeManager.int32_type) ||
+ (vt == TypeManager.int32_type) ||
(vt == TypeManager.uint32_type) ||
- (vt == TypeManager.char_type) ||
- (vt == TypeManager.float_type))){
+ (vt == TypeManager.char_type) ||
+ (vt == TypeManager.float_type) ||
+ (!vt.IsValueType))){
Report.Error (
677, Location, container.MakeName (Name) +
" A volatile field can not be of type `" +
return true;
}
- public void Emit (TypeContainer tc)
+ public override void Emit (TypeContainer tc)
{
- EmitContext ec = new EmitContext (tc, Location, null,
- FieldBuilder.FieldType, ModFlags);
+ if (OptAttributes != null) {
+ EmitContext ec = new EmitContext (tc, Location, null, FieldBuilder.FieldType, ModFlags);
+ OptAttributes.Emit (ec, this);
+ }
- Attribute.ApplyAttributes (ec, FieldBuilder, this, OptAttributes);
+ base.Emit (tc);
}
}
// Null if the accessor is empty, or a Block if not
//
public Block Block;
- public Attributes OptAttributes;
+ public Attributes Attributes;
public Accessor (Block b, Attributes attrs)
{
Block = b;
- OptAttributes = attrs;
+ Attributes = attrs;
}
}
// their common bits.
//
abstract public class PropertyBase : MethodCore {
- public Accessor Get, Set;
+
+ public class GetMethod: PropertyMethod
+ {
+ static string[] attribute_targets = new string [] { "method", "return" };
+
+ public GetMethod (MethodCore method, Accessor accessor):
+ base (method, accessor)
+ {
+ }
+
+ public override MethodBuilder Define(TypeContainer container)
+ {
+ method_data = new MethodData (method, method.ParameterInfo, method.ModFlags, method.flags, false, this);
+
+ if (!method_data.Define (container))
+ return null;
+
+ return method_data.MethodBuilder;
+ }
+
+ public override string MethodName {
+ get {
+ return "get_" + method.ShortName;
+ }
+ }
+
+ public override Type ReturnType {
+ get {
+ return method.MemberType;
+ }
+ }
+
+ protected override string[] ValidAttributeTargets {
+ get {
+ return attribute_targets;
+ }
+ }
+ }
+
+ public class SetMethod: PropertyMethod {
+
+ static string[] attribute_targets = new string [] { "method", "param", "return" };
+ ImplicitParameter param_attr;
+
+ public SetMethod (MethodCore method, Accessor accessor):
+ base (method, accessor)
+ {
+ }
+
+ public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
+ {
+ if (a.Target == "param") {
+ if (param_attr == null)
+ param_attr = new ImplicitParameter (method_data.MethodBuilder);
+
+ param_attr.ApplyAttributeBuilder (a, cb);
+ return;
+ }
+
+ base.ApplyAttributeBuilder (a, cb);
+ }
+
+ protected virtual InternalParameters GetParameterInfo (TypeContainer container)
+ {
+ Parameter [] parms = new Parameter [1];
+ parms [0] = new Parameter (method.Type, "value", Parameter.Modifier.NONE, null);
+ return new InternalParameters (
+ container, new Parameters (parms, null, method.Location));
+ }
+
+ public override MethodBuilder Define(TypeContainer container)
+ {
+ method_data = new MethodData (method, GetParameterInfo (container), method.ModFlags, method.flags, false, this);
+
+ if (!method_data.Define (container))
+ return null;
+
+ return method_data.MethodBuilder;
+ }
+
+ public override string MethodName {
+ get {
+ return "set_" + method.ShortName;
+ }
+ }
+
+ public override Type[] ParameterTypes {
+ get {
+ return new Type[] { method.MemberType };
+ }
+ }
+
+ public override Type ReturnType {
+ get {
+ return TypeManager.void_type;
+ }
+ }
+
+ protected override string[] ValidAttributeTargets {
+ get {
+ return attribute_targets;
+ }
+ }
+ }
+
+ static string[] attribute_targets = new string [] { "property" };
+
+ public abstract class PropertyMethod: Attributable, IMethodData {
+ protected readonly MethodCore method;
+ protected MethodData method_data;
+ Block block;
+
+ ReturnParameter return_attributes;
+
+ public PropertyMethod (MethodCore method, Accessor accessor):
+ base (accessor.Attributes)
+ {
+ this.method = method;
+ this.block = accessor.Block;
+ }
+
+ public override AttributeTargets AttributeTargets {
+ get {
+ return AttributeTargets.Method | AttributeTargets.ReturnValue;
+ }
+ }
+
+ public override bool IsClsCompliaceRequired(DeclSpace ds)
+ {
+ return method.IsClsCompliaceRequired (ds);
+ }
+
+ public InternalParameters ParameterInfo
+ {
+ get {
+ return method_data.ParameterInfo;
+ }
+ }
+
+ #region IMethodData Members
+
+ public Block Block {
+ get {
+ return block;
+ }
+ }
+
+ public CallingConventions CallingConventions {
+ get {
+ return CallingConventions.Standard;
+ }
+ }
+
+ public abstract MethodBuilder Define (TypeContainer container);
+
+ public void Emit (TypeContainer container)
+ {
+ method_data.Emit (container, this);
+ block = null;
+
+ }
+
+ public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
+ {
+ if (a.Target == "return") {
+ if (return_attributes == null)
+ return_attributes = new ReturnParameter (method_data.MethodBuilder, Location);
+
+ return_attributes.ApplyAttributeBuilder (a, cb);
+ return;
+ }
+
+ method_data.MethodBuilder.SetCustomAttribute (cb);
+ }
+
+ public virtual Type[] ParameterTypes {
+ get {
+ return TypeManager.NoTypes;
+ }
+ }
+
+ public abstract Type ReturnType { get; }
+
+ public Location Location {
+ get {
+ return method.Location;
+ }
+ }
+
+ public abstract string MethodName { get; }
+
+ public EmitContext CreateEmitContext (TypeContainer tc, ILGenerator ig)
+ {
+ return new EmitContext (tc, method.ds, method.Location, ig, ReturnType, method.ModFlags, false);
+ }
+
+ #endregion
+ }
+
+ public PropertyMethod Get, Set;
public PropertyBuilder PropertyBuilder;
public MethodBuilder GetBuilder, SetBuilder;
- public MethodData GetData, SetData;
protected EmitContext ec;
- public PropertyBase (DeclSpace ds, Expression type, string name, int mod_flags,
- int allowed_mod, Parameters parameters,
- Accessor get_block, Accessor set_block,
- Attributes attrs, Location loc)
- : base (ds, type, mod_flags, allowed_mod, name, attrs, parameters, loc)
+ public PropertyBase (DeclSpace ds, Expression type, int mod_flags,
+ int allowed_mod, bool is_iface, MemberName name,
+ Parameters parameters, Attributes attrs,
+ Location loc)
+ : base (ds, type, mod_flags, allowed_mod, is_iface, name,
+ attrs, parameters, loc)
{
- Get = get_block;
- Set = set_block;
}
- protected override bool DoDefine (TypeContainer container)
+ public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
{
- if (!base.DoDefine (container))
+ PropertyBuilder.SetCustomAttribute (cb);
+ }
+
+ public override AttributeTargets AttributeTargets {
+ get {
+ return AttributeTargets.Property;
+ }
+ }
+
+ protected override bool DoDefine (DeclSpace decl, TypeContainer container)
+ {
+ if (!base.DoDefine (decl, container))
return false;
ec = new EmitContext (container, Location, null, MemberType, ModFlags);
return true;
}
+ public override string GetSignatureForError()
+ {
+ return TypeManager.CSharpSignature (PropertyBuilder, false);
+ }
+
+ protected virtual string RealMethodName {
+ get {
+ return Name;
+ }
+ }
+
+ protected override bool IsIdentifierClsCompliant (DeclSpace ds)
+ {
+ if (!IsIdentifierAndParamClsCompliant (ds, RealMethodName, null, null))
+ return false;
+
+ if (Get != null && !IsIdentifierAndParamClsCompliant (ds, "get_" + RealMethodName, null, null))
+ return false;
+
+ if (Set != null && !IsIdentifierAndParamClsCompliant (ds, "set_" + RealMethodName, null, null))
+ return false;
+
+ return true;
+ }
+
+
//
// Checks our base implementation if any
//
if (IsExplicitImpl)
return true;
+ //
+ // Check in our class for dups
+ //
+ ArrayList ar = container.Properties;
+ if (ar != null) {
+ int arLen = ar.Count;
+
+ for (int i = 0; i < arLen; i++) {
+ Property m = (Property) ar [i];
+ if (IsDuplicateImplementation (container, m))
+ return false;
+ }
+ }
+
+ if (IsInterface)
+ return true;
+
string report_name;
MethodSignature ms, base_ms;
if (this is Indexer) {
return true;
}
- MemberList props_this;
-
- props_this = TypeContainer.FindMembers (
- container.TypeBuilder, MemberTypes.Property,
- BindingFlags.NonPublic | BindingFlags.Public |
- BindingFlags.Static | BindingFlags.Instance |
- BindingFlags.DeclaredOnly,
- MethodSignature.method_signature_filter, ms);
-
- if (props_this.Count > 0) {
- Report.Error (111, Location, "Class `" + container.Name + "' " +
- "already defines a member called `" + report_name + "' " +
- "with the same parameter types");
- return false;
+ MemberInfo parent_member = null;
+
+ //
+ // Explicit implementations do not have `parent' methods, however,
+ // the member cache stores them there. Without this check, we get
+ // an incorrect warning in corlib.
+ //
+ if (! IsExplicitImpl) {
+ parent_member = ((IMemberContainer)container).Parent.MemberCache.FindMemberToOverride (
+ container.TypeBuilder, Name, ParameterTypes, true);
}
- MemberList mi_props;
+ if (parent_member is PropertyInfo) {
+ PropertyInfo parent_property = (PropertyInfo)parent_member;
- mi_props = TypeContainer.FindMembers (
- ptype, MemberTypes.Property,
- BindingFlags.NonPublic | BindingFlags.Public |
- BindingFlags.Instance | BindingFlags.Static,
- MethodSignature.inheritable_method_signature_filter, base_ms);
-
- if (mi_props.Count > 0){
- PropertyInfo parent_property = (PropertyInfo) mi_props [0];
string name = parent_property.DeclaringType.Name + "." +
parent_property.Name;
return false;
}
}
- } else {
+ } else if (parent_member == null){
if ((ModFlags & Modifiers.NEW) != 0)
WarningNotHiding (container);
return true;
}
- public void Emit (TypeContainer tc)
+ public override void Emit (TypeContainer tc)
{
//
// The PropertyBuilder can be null for explicit implementations, in that
// case, we do not actually emit the ".property", so there is nowhere to
// put the attribute
//
- if (PropertyBuilder != null)
- Attribute.ApplyAttributes (ec, PropertyBuilder, this, OptAttributes);
+ if (PropertyBuilder != null && OptAttributes != null)
+ OptAttributes.Emit (ec, this);
- if (GetData != null) {
- GetData.Emit (tc, Get.Block, Get);
- Get.Block = null;
- }
+ if (Get != null)
+ Get.Emit (tc);
+
+ if (Set != null)
+ Set.Emit (tc);
- if (SetData != null) {
- SetData.Emit (tc, Set.Block, Set);
- Set.Block = null;
+ base.Emit (tc);
+ }
+
+ protected override string[] ValidAttributeTargets {
+ get {
+ return attribute_targets;
}
}
}
- public class Property : PropertyBase {
+ public class Property : PropertyBase, IIteratorContainer {
const int AllowedModifiers =
Modifiers.NEW |
Modifiers.PUBLIC |
Modifiers.ABSTRACT |
Modifiers.UNSAFE |
Modifiers.EXTERN |
+ Modifiers.METHOD_YIELDS |
Modifiers.VIRTUAL;
- public Property (DeclSpace ds, Expression type, string name, int mod_flags,
- Accessor get_block, Accessor set_block,
- Attributes attrs, Location loc)
- : base (ds, type, name, mod_flags, AllowedModifiers,
- Parameters.EmptyReadOnlyParameters,
- get_block, set_block, attrs, loc)
+ const int AllowedInterfaceModifiers =
+ Modifiers.NEW;
+
+ public Property (DeclSpace ds, Expression type, int mod_flags, bool is_iface,
+ MemberName name, Attributes attrs, Accessor get_block,
+ Accessor set_block, Location loc)
+ : base (ds, type, mod_flags,
+ is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
+ is_iface, name, Parameters.EmptyReadOnlyParameters, attrs,
+ loc)
{
+ if (get_block != null)
+ Get = new GetMethod (this, get_block);
+
+ if (set_block != null)
+ Set = new SetMethod (this, set_block);
}
public override bool Define (TypeContainer container)
{
- if (!DoDefine (container))
+ if (!DoDefine (container, container))
return false;
if (!CheckBase (container))
flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
if (Get != null) {
- Type [] parameters = TypeManager.NoTypes;
-
- InternalParameters ip = new InternalParameters (
- container, Parameters.EmptyReadOnlyParameters);
- GetData = new MethodData (container, this, "get", MemberType,
- parameters, ip, CallingConventions.Standard,
- Get.OptAttributes, ModFlags, flags, false);
-
- if (!GetData.Define (container))
+ GetBuilder = Get.Define (container);
+ if (GetBuilder == null)
return false;
- GetBuilder = GetData.MethodBuilder;
+ //
+ // Setup iterator if we are one
+ //
+ if ((ModFlags & Modifiers.METHOD_YIELDS) != 0){
+ IteratorHandler ih = new IteratorHandler (
+ "get", container, MemberType,
+ TypeManager.NoTypes, Get.ParameterInfo, ModFlags, Location);
+
+ Block new_block = ih.Setup (block);
+ if (new_block == null)
+ return false;
+ block = new_block;
+ }
}
if (Set != null) {
- Type [] parameters = new Type [1];
- parameters [0] = MemberType;
-
- Parameter [] parms = new Parameter [1];
- parms [0] = new Parameter (Type, "value", Parameter.Modifier.NONE, null);
- InternalParameters ip = new InternalParameters (
- container, new Parameters (parms, null, Location));
-
- SetData = new MethodData (container, this, "set", TypeManager.void_type,
- parameters, ip, CallingConventions.Standard,
- Set.OptAttributes, ModFlags, flags, false);
-
- if (!SetData.Define (container))
+ SetBuilder = Set.Define (container);
+ if (SetBuilder == null)
return false;
- SetBuilder = SetData.MethodBuilder;
SetBuilder.DefineParameter (1, ParameterAttributes.None, "value");
}
// FIXME - PropertyAttributes.HasDefault ?
- PropertyAttributes prop_attr =
- PropertyAttributes.RTSpecialName |
+ PropertyAttributes prop_attr = PropertyAttributes.None;
+ if (!IsInterface)
+ prop_attr |= PropertyAttributes.RTSpecialName |
PropertyAttributes.SpecialName;
if (!IsExplicitImpl){
}
return true;
}
+
+ public void SetYields ()
+ {
+ ModFlags |= Modifiers.METHOD_YIELDS;
+ }
}
/// </summary>
return null;
}
- public override object [] GetCustomAttributes (Type t, bool inherit)
- {
- // FIXME : Same here !
- return null;
- }
+ public override object [] GetCustomAttributes (Type t, bool inherit)
+ {
+ // FIXME : Same here !
+ return null;
+ }
+
+ public override bool IsDefined (Type t, bool b)
+ {
+ return true;
+ }
+
+ public override EventAttributes Attributes {
+ get {
+ return attributes;
+ }
+ }
+
+ public override string Name {
+ get {
+ return name;
+ }
+ }
+
+ public override Type DeclaringType {
+ get {
+ return declaring_type;
+ }
+ }
+
+ public override Type ReflectedType {
+ get {
+ return reflected_type;
+ }
+ }
+
+ public Type EventType {
+ get {
+ return event_type;
+ }
+ }
+
+ public void SetUsed ()
+ {
+ if (my_event != null)
+ my_event.status = (FieldBase.Status.ASSIGNED | FieldBase.Status.USED);
+ }
+ }
+
+ /// <summary>
+ /// For case when event is declared like property (with add and remove accessors).
+ /// </summary>
+ public class EventProperty: Event {
+
+ static string[] attribute_targets = new string [] { "event", "property" };
+
+ public EventProperty (DeclSpace ds, Expression type, int mod_flags,
+ bool is_iface, MemberName name, Object init,
+ Attributes attrs, Accessor add, Accessor remove,
+ Location loc)
+ : base (ds, type, mod_flags, is_iface, name, init, attrs, loc)
+ {
+ Add = new AddDelegateMethod (this, add);
+ Remove = new RemoveDelegateMethod (this, remove);
+ }
+
+ protected override string[] ValidAttributeTargets {
+ get {
+ return attribute_targets;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Event is declared like field.
+ /// </summary>
+ public class EventField: Event {
+
+ static string[] attribute_targets = new string [] { "method", "field", "event" };
+
+ public EventField (DeclSpace ds, Expression type, int mod_flags, bool is_iface,
+ MemberName name, Object init, Attributes attrs, Location loc)
+ : base (ds, type, mod_flags, is_iface, name, init, attrs, loc)
+ {
+ Add = new AddDelegateMethod (this);
+ Remove = new RemoveDelegateMethod (this);
+ }
+
+ public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+ {
+ if (a.Target == "field") {
+ FieldBuilder.SetCustomAttribute (cb);
+ return;
+ }
+
+ if (a.Target == "method") {
+ AddBuilder.SetCustomAttribute (cb);
+ RemoveBuilder.SetCustomAttribute (cb);
+ return;
+ }
+
+ base.ApplyAttributeBuilder (a, cb);
+ }
+
+ protected override string[] ValidAttributeTargets {
+ get {
+ return attribute_targets;
+ }
+ }
+ }
+
+ public abstract class Event : FieldBase {
+
+ protected sealed class AddDelegateMethod: DelegateMethod
+ {
+ public AddDelegateMethod (Event method):
+ base (method)
+ {
+ }
+
+ public AddDelegateMethod (Event method, Accessor accessor):
+ base (method, accessor)
+ {
+ }
+
+ public override string MethodName {
+ get {
+ return "add_" + method.ShortName;
+ }
+ }
+
+ protected override MethodInfo DelegateMethodInfo {
+ get {
+ return TypeManager.delegate_remove_delegate_delegate;
+ }
+ }
+
+ }
+
+ protected sealed class RemoveDelegateMethod: DelegateMethod
+ {
+ public RemoveDelegateMethod (Event method):
+ base (method)
+ {
+ }
+
+ public RemoveDelegateMethod (Event method, Accessor accessor):
+ base (method, accessor)
+ {
+ }
+
+ public override string MethodName {
+ get {
+ return "remove_" + method.ShortName;
+ }
+ }
+
+ protected override MethodInfo DelegateMethodInfo {
+ get {
+ return TypeManager.delegate_combine_delegate_delegate;
+ }
+ }
+
+ }
+
+ public abstract class DelegateMethod: Attributable, IMethodData
+ {
+ protected readonly Event method;
+ protected MethodData method_data;
+ Block block;
+ ReturnParameter return_attributes;
+ ImplicitParameter param_attr;
+
+ static string[] attribute_targets = new string [] { "method", "param", "return" };
+
+ public DelegateMethod (Event method):
+ base (null)
+ {
+ this.method = method;
+ }
+
+ public DelegateMethod (Event method, Accessor accessor):
+ base (accessor.Attributes)
+ {
+ this.method = method;
+ this.block = accessor.Block;
+ }
+
+ public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
+ {
+ if (a.Target == "return") {
+ if (return_attributes == null)
+ return_attributes = new ReturnParameter (method_data.MethodBuilder, Location);
+
+ return_attributes.ApplyAttributeBuilder (a, cb);
+ return;
+ }
+
+ if (a.Target == "param") {
+ if (param_attr == null)
+ param_attr = new ImplicitParameter (method_data.MethodBuilder);
+
+ param_attr.ApplyAttributeBuilder (a, cb);
+ return;
+ }
+
+ method_data.MethodBuilder.SetCustomAttribute (cb);
+ }
+
+ public override AttributeTargets AttributeTargets {
+ get {
+ return AttributeTargets.Method;
+ }
+ }
+
+ public override bool IsClsCompliaceRequired(DeclSpace ds)
+ {
+ return method.IsClsCompliaceRequired (ds);
+ }
+
+ public MethodBuilder Define (TypeContainer container, InternalParameters ip)
+ {
+ method_data = new MethodData (method, ip, method.ModFlags,
+ method.flags | MethodAttributes.HideBySig | MethodAttributes.SpecialName, false, this);
+
+ if (!method_data.Define (container))
+ return null;
+
+ MethodBuilder mb = method_data.MethodBuilder;
+ mb.DefineParameter (1, ParameterAttributes.None, "value");
+ return mb;
+ }
+
+ #region IMethodData Members
+
+ public Block Block {
+ get {
+ return block;
+ }
+ }
+
+ public CallingConventions CallingConventions {
+ get {
+ return CallingConventions.Standard;
+ }
+ }
- public override bool IsDefined (Type t, bool b)
- {
- return true;
- }
+ public void Emit (TypeContainer tc)
+ {
+ if (block != null) {
+ method_data.Emit (tc, this);
+ block = null;
+ return;
+ }
- public override EventAttributes Attributes {
- get {
- return attributes;
+ ILGenerator ig = method_data.MethodBuilder.GetILGenerator ();
+ EmitContext ec = CreateEmitContext (tc, ig);
+ FieldInfo field_info = (FieldInfo)method.FieldBuilder;
+
+ if ((method.ModFlags & Modifiers.STATIC) != 0) {
+ ig.Emit (OpCodes.Ldsfld, field_info);
+ ig.Emit (OpCodes.Ldarg_0);
+ ig.Emit (OpCodes.Call, DelegateMethodInfo);
+ ig.Emit (OpCodes.Castclass, method.MemberType);
+ ig.Emit (OpCodes.Stsfld, field_info);
+ } else {
+ ig.Emit (OpCodes.Ldarg_0);
+ ig.Emit (OpCodes.Ldarg_0);
+ ig.Emit (OpCodes.Ldfld, field_info);
+ ig.Emit (OpCodes.Ldarg_1);
+ ig.Emit (OpCodes.Call, DelegateMethodInfo);
+ ig.Emit (OpCodes.Castclass, method.MemberType);
+ ig.Emit (OpCodes.Stfld, field_info);
+ }
+ ig.Emit (OpCodes.Ret);
}
- }
- public override string Name {
- get {
- return name;
+ protected abstract MethodInfo DelegateMethodInfo { get; }
+
+ public Type[] ParameterTypes {
+ get {
+ return new Type[] { method.MemberType };
+ }
}
- }
- public override Type DeclaringType {
- get {
- return declaring_type;
+ public Type ReturnType {
+ get {
+ return TypeManager.void_type;
+ }
}
- }
- public override Type ReflectedType {
- get {
- return reflected_type;
+ public Location Location {
+ get {
+ return method.Location;
+ }
}
- }
- public Type EventType {
- get {
- return event_type;
+ public EmitContext CreateEmitContext (TypeContainer tc, ILGenerator ig)
+ {
+ return new EmitContext (tc, method.ds, Location, ig, ReturnType, method.ModFlags, false);
+ }
+
+ public abstract string MethodName { get; }
+
+ #endregion
+
+ protected override string[] ValidAttributeTargets {
+ get {
+ return attribute_targets;
+ }
}
}
-
- public void SetUsed ()
- {
- if (my_event != null)
- my_event.status = (FieldBase.Status.ASSIGNED | FieldBase.Status.USED);
- }
- }
-
- public class Event : FieldBase {
+
+
const int AllowedModifiers =
Modifiers.NEW |
Modifiers.PUBLIC |
Modifiers.UNSAFE |
Modifiers.ABSTRACT;
- public readonly Accessor Add;
- public readonly Accessor Remove;
+ const int AllowedInterfaceModifiers =
+ Modifiers.NEW;
+
+ protected DelegateMethod Add, Remove;
public MyEventBuilder EventBuilder;
+ public MethodBuilder AddBuilder, RemoveBuilder;
+ public DeclSpace ds;
- MethodBuilder AddBuilder, RemoveBuilder;
MethodData AddData, RemoveData;
- 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)
+ public Event (DeclSpace ds, Expression type, int mod_flags, bool is_iface,
+ MemberName name, Object init, Attributes attrs, Location loc)
+ : base (type, mod_flags,
+ is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
+ name, init, attrs, loc)
+ {
+ IsInterface = is_iface;
+ this.ds = ds;
+ }
+
+ public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
{
- Add = add;
- Remove = remove;
+ EventBuilder.SetCustomAttribute (cb);
}
+ public override AttributeTargets AttributeTargets {
+ get {
+ return AttributeTargets.Event;
+ }
+ }
+
public override bool Define (TypeContainer container)
{
- EventAttributes e_attr = EventAttributes.RTSpecialName | EventAttributes.SpecialName;
- MethodAttributes m_attr = MethodAttributes.HideBySig | MethodAttributes.SpecialName
+ EventAttributes e_attr;
+ if (IsInterface)
+ e_attr = EventAttributes.None;
+ else
+ e_attr = EventAttributes.RTSpecialName |
+ EventAttributes.SpecialName;
;
- if (!DoDefine (container))
+ if (!DoDefine (container, container))
return false;
if (init != null && ((ModFlags & Modifiers.ABSTRACT) != 0)){
"': abstract event can not have an initializer");
return false;
}
-
- if (!MemberType.IsSubclassOf (TypeManager.delegate_type)) {
+
+ if (!TypeManager.IsDelegateType (MemberType)) {
Report.Error (66, Location, "'" + container.Name + "." + Name +
"' : event must be of a delegate type");
return false;
}
- Type [] parameter_types = new Type [1];
- parameter_types [0] = MemberType;
-
Parameter [] parms = new Parameter [1];
parms [0] = new Parameter (Type, "value", Parameter.Modifier.NONE, null);
InternalParameters ip = new InternalParameters (
//
// Now define the accessors
//
- AddData = new MethodData (container, this, "add", TypeManager.void_type,
- parameter_types, ip, CallingConventions.Standard,
- (Add != null) ? Add.OptAttributes : null,
- ModFlags, flags | m_attr, false);
- if (!AddData.Define (container))
+ AddBuilder = Add.Define (container, ip);
+ if (AddBuilder == null)
return false;
- AddBuilder = AddData.MethodBuilder;
- AddBuilder.DefineParameter (1, ParameterAttributes.None, "value");
-
- RemoveData = new MethodData (container, this, "remove", TypeManager.void_type,
- parameter_types, ip, CallingConventions.Standard,
- (Remove != null) ? Remove.OptAttributes : null,
- ModFlags, flags | m_attr, false);
-
- if (!RemoveData.Define (container))
+ RemoveBuilder = Remove.Define (container, ip);
+ if (RemoveBuilder == null)
return false;
- RemoveBuilder = RemoveData.MethodBuilder;
- RemoveBuilder.DefineParameter (1, ParameterAttributes.None, "value");
-
if (!IsExplicitImpl){
EventBuilder = new MyEventBuilder (this,
container.TypeBuilder, Name, e_attr, MemberType);
- if (Add == null && Remove == null) {
+ if (Add.Block == null && Remove.Block == null &&
+ !IsInterface) {
FieldBuilder = container.TypeBuilder.DefineField (
Name, MemberType,
FieldAttributes.Private | ((ModFlags & Modifiers.STATIC) != 0 ? FieldAttributes.Static : 0));
return true;
}
- void EmitDefaultMethod (EmitContext ec, bool is_add)
+ public override void Emit (TypeContainer tc)
{
- ILGenerator ig = ec.ig;
- MethodInfo method = null;
-
- if (is_add)
- method = TypeManager.delegate_combine_delegate_delegate;
- else
- method = TypeManager.delegate_remove_delegate_delegate;
-
- if ((ModFlags & Modifiers.STATIC) != 0) {
- ig.Emit (OpCodes.Ldsfld, (FieldInfo) FieldBuilder);
- ig.Emit (OpCodes.Ldarg_0);
- ig.Emit (OpCodes.Call, method);
- ig.Emit (OpCodes.Castclass, MemberType);
- ig.Emit (OpCodes.Stsfld, (FieldInfo) FieldBuilder);
- } else {
- ig.Emit (OpCodes.Ldarg_0);
- ig.Emit (OpCodes.Ldarg_0);
- ig.Emit (OpCodes.Ldfld, (FieldInfo) FieldBuilder);
- ig.Emit (OpCodes.Ldarg_1);
- ig.Emit (OpCodes.Call, method);
- ig.Emit (OpCodes.Castclass, MemberType);
- ig.Emit (OpCodes.Stfld, (FieldInfo) FieldBuilder);
+ if (OptAttributes != null) {
+ EmitContext ec = new EmitContext (tc, Location, null, MemberType, ModFlags);
+ OptAttributes.Emit (ec, this);
}
- ig.Emit (OpCodes.Ret);
- }
-
- public void Emit (TypeContainer tc)
- {
- EmitContext ec;
- ec = new EmitContext (tc, Location, null, MemberType, ModFlags);
- Attribute.ApplyAttributes (ec, EventBuilder, this, OptAttributes);
-
- if (Add != null) {
- AddData.Emit (tc, Add.Block, Add);
- Add.Block = null;
- } else {
- ILGenerator ig = AddData.MethodBuilder.GetILGenerator ();
- ec = new EmitContext (tc, Location, ig, TypeManager.void_type, ModFlags);
- EmitDefaultMethod (ec, true);
+ if (!IsInterface) {
+ Add.Emit (tc);
+ Remove.Emit (tc);
}
- if (Remove != null) {
- RemoveData.Emit (tc, Remove.Block, Remove);
- Remove.Block = null;
- } else {
- ILGenerator ig = RemoveData.MethodBuilder.GetILGenerator ();
- ec = new EmitContext (tc, Location, ig, TypeManager.void_type, ModFlags);
- EmitDefaultMethod (ec, false);
- }
+ base.Emit (tc);
}
-
}
//
public class Indexer : PropertyBase {
+ class GetIndexerMethod: GetMethod
+ {
+ public GetIndexerMethod (MethodCore method, Accessor accessor):
+ base (method, accessor)
+ {
+ }
+
+ public override Type[] ParameterTypes {
+ get {
+ return method.ParameterTypes;
+ }
+ }
+ }
+
+ class SetIndexerMethod: SetMethod
+ {
+ readonly Parameters parameters;
+
+ public SetIndexerMethod (MethodCore method, Parameters parameters, Accessor accessor):
+ base (method, accessor)
+ {
+ this.parameters = parameters;
+ }
+
+ public override Type[] ParameterTypes {
+ get {
+ int top = method.ParameterTypes.Length;
+ Type [] set_pars = new Type [top + 1];
+ method.ParameterTypes.CopyTo (set_pars, 0);
+ set_pars [top] = method.MemberType;
+ return set_pars;
+ }
+ }
+
+ protected override InternalParameters GetParameterInfo (TypeContainer container)
+ {
+ Parameter [] fixed_parms = parameters.FixedParameters;
+
+ if (fixed_parms == null){
+ throw new Exception ("We currently do not support only array arguments in an indexer at: " + method.Location);
+ // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG
+ // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG
+ //
+ // Here is the problem: the `value' parameter has
+ // to come *after* the array parameter in the declaration
+ // like this:
+ // X (object [] x, Type value)
+ // .param [0]
+ //
+ // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG
+ // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG
+
+ }
+
+ Parameter [] tmp = new Parameter [fixed_parms.Length + 1];
+
+ fixed_parms.CopyTo (tmp, 0);
+ tmp [fixed_parms.Length] = new Parameter (
+ method.Type, "value", Parameter.Modifier.NONE, null);
+
+ Parameters set_formal_params = new Parameters (tmp, null, method.Location);
+
+ return new InternalParameters (container, set_formal_params);
+ }
+
+ }
+
+
const int AllowedModifiers =
Modifiers.NEW |
Modifiers.PUBLIC |
Modifiers.EXTERN |
Modifiers.ABSTRACT;
+ const int AllowedInterfaceModifiers =
+ Modifiers.NEW;
+
public string IndexerName;
public string InterfaceIndexerName;
//
// Are we implementing an interface ?
//
- public Indexer (DeclSpace ds, Expression type, string int_type, int flags,
- Parameters parameters, Accessor get_block, Accessor set_block,
- Attributes attrs, Location loc)
- : base (ds, type, "", flags, AllowedModifiers, parameters, get_block, set_block,
- attrs, loc)
+ public Indexer (DeclSpace ds, Expression type, int mod_flags, bool is_iface,
+ MemberName name, Parameters parameters, Attributes attrs,
+ Accessor get_block, Accessor set_block, Location loc)
+ : base (ds, type, mod_flags,
+ is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
+ is_iface, name, parameters, attrs, loc)
{
- ExplicitInterfaceName = int_type;
+ if (get_block != null)
+ Get = new GetIndexerMethod (this, get_block);
+
+ if (set_block != null)
+ Set = new SetIndexerMethod (this, parameters, set_block);
}
public override bool Define (TypeContainer container)
PropertyAttributes.RTSpecialName |
PropertyAttributes.SpecialName;
- if (!DoDefine (container))
+ if (!DoDefine (container, container))
return false;
- IndexerName = Attribute.ScanForIndexerName (ec, OptAttributes);
+ if (OptAttributes != null)
+ IndexerName = OptAttributes.ScanForIndexerName (ec);
+
if (IndexerName == null)
IndexerName = "Item";
- else if (IsExplicitImpl)
+ else {
+ if (! Tokenizer.IsValidIdentifier (IndexerName)) {
+ Report.Error (633, Location, "The IndexerName specified is an invalid identifier");
+ return false;
+ }
+
+ if (IsExplicitImpl) {
Report.Error (592, Location,
- "Attribute 'IndexerName' is not valid on this declaration " +
- "type. It is valid on `property' declarations only.");
+ "Attribute 'IndexerName' is not valid on explicit implementations.");
+ return false;
+ }
+ }
ShortName = IndexerName;
if (IsExplicitImpl) {
Name = ShortName;
}
+ if (!CheckNameCollision (container))
+ return false;
+
if (!CheckBase (container))
return false;
flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
if (Get != null){
- InternalParameters ip = new InternalParameters (container, Parameters);
-
- GetData = new MethodData (container, this, "get", MemberType,
- ParameterTypes, ip, CallingConventions.Standard,
- Get.OptAttributes, ModFlags, flags, false);
-
- if (!GetData.Define (container))
+ GetBuilder = Get.Define (container);
+ if (GetBuilder == null)
return false;
-
- GetBuilder = GetData.MethodBuilder;
}
if (Set != null){
- int top = ParameterTypes.Length;
- Type [] set_pars = new Type [top + 1];
- ParameterTypes.CopyTo (set_pars, 0);
- set_pars [top] = MemberType;
-
- Parameter [] fixed_parms = Parameters.FixedParameters;
-
- if (fixed_parms == null){
- throw new Exception ("We currently do not support only array arguments in an indexer at: " + Location);
- // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG
- // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG
- //
- // Here is the problem: the `value' parameter has
- // to come *after* the array parameter in the declaration
- // like this:
- // X (object [] x, Type value)
- // .param [0]
- //
- // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG
- // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG
-
- }
-
- Parameter [] tmp = new Parameter [fixed_parms.Length + 1];
-
-
- fixed_parms.CopyTo (tmp, 0);
- tmp [fixed_parms.Length] = new Parameter (
- Type, "value", Parameter.Modifier.NONE, null);
-
- Parameters set_formal_params = new Parameters (tmp, null, Location);
-
- InternalParameters ip = new InternalParameters (container, set_formal_params);
-
- SetData = new MethodData (container, this, "set", TypeManager.void_type,
- set_pars, ip, CallingConventions.Standard,
- Set.OptAttributes, ModFlags, flags, false);
-
- if (!SetData.Define (container))
+ SetBuilder = Set.Define (container);
+ if (SetBuilder == null)
return false;
-
- SetBuilder = SetData.MethodBuilder;
}
//
PropertyBuilder = container.TypeBuilder.DefineProperty (
IndexerName, prop_attr, MemberType, ParameterTypes);
- if (GetData != null)
+ if (Get != null)
PropertyBuilder.SetGetMethod (GetBuilder);
- if (SetData != null)
+ if (Set != null)
PropertyBuilder.SetSetMethod (SetBuilder);
TypeManager.RegisterIndexer (PropertyBuilder, GetBuilder, SetBuilder,
return true;
}
+
+ bool CheckNameCollision (TypeContainer container) {
+ switch (VerifyName (container)){
+ case DeclSpace.AdditionResult.NameExists:
+ Report.Error (102, Location, "The container '{0}' already contains a definition for '{1}'", container.GetSignatureForError (), Name);
+ return false;
+
+ case DeclSpace.AdditionResult.Success:
+ return true;
+ }
+ throw new NotImplementedException ();
+ }
+
+ DeclSpace.AdditionResult VerifyName (TypeContainer container) {
+ if (!AddIndexer (container, container.Name + "." + Name))
+ return DeclSpace.AdditionResult.NameExists;
+
+ if (Get != null) {
+ if (!AddIndexer (container, container.Name + ".get_" + Name))
+ return DeclSpace.AdditionResult.NameExists;
+ }
+
+ if (Set != null) {
+ if (!AddIndexer (container, container.Name + ".set_" + Name))
+ return DeclSpace.AdditionResult.NameExists;
+ }
+ return DeclSpace.AdditionResult.Success;
+ }
+
+ bool AddIndexer (TypeContainer container, string fullname)
+ {
+ object value = container.GetDefinition (fullname);
+
+ if (value != null) {
+ return value.GetType () != GetType () ? false : true;
+ }
+
+ container.DefineName (fullname, this);
+ return true;
+ }
+
+ public override string GetSignatureForError ()
+ {
+ return TypeManager.CSharpSignature (PropertyBuilder, true);
+ }
+
+ protected override string RealMethodName {
+ get {
+ return IndexerName;
+ }
+ }
}
- public class Operator : MemberBase {
+ public class Operator : MemberBase, IIteratorContainer {
const int AllowedModifiers =
Modifiers.PUBLIC |
public string MethodName;
public Method OperatorMethod;
+ static string[] attribute_targets = new string [] { "param" };
+
public Operator (OpType type, Expression ret_type, int mod_flags,
Expression arg1type, string arg1name,
Expression arg2type, string arg2name,
Block block, Attributes attrs, Location loc)
- : base (ret_type, mod_flags, AllowedModifiers, Modifiers.PUBLIC, "", attrs, loc)
+ : base (ret_type, mod_flags, AllowedModifiers, Modifiers.PUBLIC,
+ MemberName.Null, attrs, loc)
{
OperatorType = type;
+ Name = "op_" + OperatorType;
ReturnType = ret_type;
FirstArgType = arg1type;
FirstArgName = arg1name;
return container.Name + ".operator " + OperatorType + " (" + FirstArgType + "," +
SecondArgType + ")";
}
+
+ public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+ {
+ OperatorMethod.ApplyAttributeBuilder (a, cb);
+ }
+
+ public override AttributeTargets AttributeTargets {
+ get {
+ return AttributeTargets.Method;
+ }
+ }
+ protected override bool CheckGenericOverride (MethodInfo method, string name)
+ {
+ return true;
+ }
+
public override bool Define (TypeContainer container)
{
int length = 1;
param_list[1] = new Parameter (SecondArgType, SecondArgName,
Parameter.Modifier.NONE, null);
- OperatorMethod = new Method (container, ReturnType, ModFlags, MethodName,
- new Parameters (param_list, null, Location),
- OptAttributes, Location);
+ OperatorMethod = new Method (
+ container, ReturnType, ModFlags, false,
+ new MemberName (MethodName),
+ new Parameters (param_list, null, Location),
+ OptAttributes, Location);
+ OperatorMethod.Block = Block;
OperatorMethod.IsOperator = true;
OperatorMethod.Define (container);
OperatorMethodBuilder = OperatorMethod.MethodBuilder;
Type [] param_types = OperatorMethod.ParameterTypes;
- Type declaring_type = OperatorMethodBuilder.DeclaringType;
+ Type declaring_type = OperatorMethod.MethodData.DeclaringType;
Type return_type = OperatorMethod.GetReturnType ();
Type first_arg_type = param_types [0];
return true;
}
- public void Emit (TypeContainer container)
+ public override void Emit (TypeContainer container)
{
//
// abstract or extern methods have no bodies
if ((ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) != 0)
return;
- OperatorMethod.Block = Block;
OperatorMethod.Emit (container);
Block = null;
}
GetName (OperatorType),
param_types [0], param_types [1]);
}
+
+ protected override string[] ValidAttributeTargets {
+ get {
+ return attribute_targets;
+ }
+ }
+
+ public void SetYields ()
+ {
+ ModFlags |= Modifiers.METHOD_YIELDS;
+ }
}
//
/// This delegate is used to extract methods which have the
/// same signature as the argument
/// </summary>
- public static MemberFilter method_signature_filter;
-
- /// <summary>
- /// This delegate is used to extract inheritable methods which
- /// have the same signature as the argument. By inheritable,
- /// this means that we have permissions to override the method
- /// from the current assembly and class
- /// </summary>
- public static MemberFilter inheritable_method_signature_filter;
-
- static MethodSignature ()
- {
- method_signature_filter = new MemberFilter (MemberSignatureCompare);
- inheritable_method_signature_filter = new MemberFilter (
- InheritableMemberSignatureCompare);
- }
+ public static MemberFilter method_signature_filter = new MemberFilter (MemberSignatureCompare);
public MethodSignature (string name, Type ret_type, Type [] parameters)
{
}
return true;
}
-
- //
- // This filter should be used when we are requesting methods that
- // we want to override.
- //
- // This makes a number of assumptions, for example
- // that the methods being extracted are of a parent
- // class (this means we know implicitly that we are
- // being called to find out about members by a derived
- // class).
- //
- static bool InheritableMemberSignatureCompare (MemberInfo m, object filter_criteria)
- {
- MethodInfo mi;
- PropertyInfo pi = m as PropertyInfo;
-
- if (pi != null) {
- mi = pi.GetGetMethod (true);
- if (mi == null)
- mi = pi.GetSetMethod (true);
- } else
- mi = m as MethodInfo;
-
- if (mi == null){
- Console.WriteLine ("Nothing found");
- }
-
- MethodAttributes prot = mi.Attributes & MethodAttributes.MemberAccessMask;
-
- // If only accessible to the current class.
- if (prot == MethodAttributes.Private)
- return false;
-
- if (!MemberSignatureCompare (m, filter_criteria))
- return false;
-
- // If only accessible to the defining assembly or
- if (prot == MethodAttributes.FamANDAssem ||
- prot == MethodAttributes.Assembly){
- if (m.DeclaringType.Assembly == CodeGen.AssemblyBuilder)
- return true;
- else
- return false;
- }
-
- // Anything else (FamOrAssembly and Public) is fine
- return true;
- }
}
}