foreach (MemberCore mc in this) {
try {
mc.Define ();
- }
- catch (Exception e) {
+ } catch (Exception e) {
throw new InternalErrorException (mc.Location, mc.GetSignatureForError (), e);
}
}
Report.Warning (659, 3, container.Location, "`{0}' overrides Object.Equals(object) but does not override Object.GetHashCode()", container.GetSignatureForError ());
}
}
-
}
public sealed class IndexerArrayList : MemberCoreArrayList
// Holds the operators
MemberCoreArrayList operators;
- // Holds the iterators
- ArrayList iterators;
+ // Holds the compiler generated classes
+ ArrayList compiler_generated;
//
// Pointers to the default constructor and the default static constructor
//
TypeExpr base_type;
TypeExpr[] iface_exprs;
+ Type GenericType;
ArrayList type_bases;
+ bool members_resolved;
+ bool members_resolved_ok;
bool members_defined;
bool members_defined_ok;
public const string DefaultIndexerName = "Item";
- public TypeContainer PartialContainer;
+#if GMCS_SOURCE
+ GenericTypeParameterBuilder[] gen_params;
+#endif
+
ArrayList partial_parts;
/// <remarks>
Attributes attrs, Kind kind)
: base (ns, parent, name, attrs)
{
- if (parent != null && parent != RootContext.Tree.Types && parent.NamespaceEntry != ns)
+ if (parent != null && parent.NamespaceEntry != ns)
throw new InternalErrorException ("A nested type should be in the same NamespaceEntry as its enclosing class");
this.Kind = kind;
this.PartialContainer = this;
}
- public bool AddToMemberContainer (MemberCore symbol)
+ public bool AddMember (MemberCore symbol)
{
- return AddToContainer (symbol, symbol.Name);
+ return AddToContainer (symbol, symbol.MemberName.MethodName);
}
- protected virtual bool AddToTypeContainer (DeclSpace ds)
+ protected virtual bool AddMemberType (DeclSpace ds)
{
return AddToContainer (ds, ds.Basename);
}
public void AddConstant (Const constant)
{
- if (!AddToMemberContainer (constant))
+ if (!AddMember (constant))
return;
if (constants == null)
public void AddEnum (Mono.CSharp.Enum e)
{
- if (!AddToTypeContainer (e))
+ if (!AddMemberType (e))
return;
if (enums == null)
enums.Add (e);
}
-
- public bool AddClassOrStruct (TypeContainer c)
- {
- if (!AddToTypeContainer (c))
- return false;
- if (types == null)
- types = new ArrayList (2);
+ public TypeContainer AddTypeContainer (TypeContainer tc, bool is_interface)
+ {
+ if (!AddMemberType (tc))
+ return tc;
- RootContext.Tree.RecordDecl (c.NamespaceEntry.NS, c.MemberName, c);
- types.Add (c);
- return true;
+ if (is_interface) {
+ if (interfaces == null)
+ interfaces = new MemberCoreArrayList ();
+ interfaces.Add (tc);
+ } else {
+ if (types == null)
+ types = new ArrayList (2);
+ types.Add (tc);
+ }
+ return tc;
}
- public virtual TypeContainer AddPartial (TypeContainer nextPart)
+ public virtual TypeContainer AddPartial (TypeContainer nextPart, bool is_interface)
{
- return AddPartial (nextPart, nextPart.Basename);
+ return AddPartial (nextPart, nextPart.Basename, is_interface);
}
- protected TypeContainer AddPartial (TypeContainer nextPart, string name)
+ protected TypeContainer AddPartial (TypeContainer nextPart, string name, bool is_interface)
{
nextPart.ModFlags |= Modifiers.PARTIAL;
TypeContainer tc = defined_names [name] as TypeContainer;
- if (tc == null) {
- if (nextPart is Interface)
- AddInterface (nextPart);
- else
- AddClassOrStruct (nextPart);
- return nextPart;
- }
+ if (tc == null)
+ return AddTypeContainer (nextPart, is_interface);
if ((tc.ModFlags & Modifiers.PARTIAL) == 0) {
Report.SymbolRelatedToPreviousError (tc);
return tc;
}
+ if (tc.MemberName.IsGeneric) {
+ TypeParameter[] tc_names = tc.TypeParameters;
+ TypeParameterName[] part_names = nextPart.MemberName.TypeArguments.GetDeclarations ();
+
+ for (int i = 0; i < tc_names.Length; ++i) {
+ if (tc_names[i].Name == part_names[i].Name)
+ continue;
+
+ Report.SymbolRelatedToPreviousError (part_names[i].Location, "");
+ Report.Error (264, tc.Location, "Partial declarations of `{0}' must have the same type parameter names in the same order",
+ tc.GetSignatureForError ());
+ return tc;
+ }
+ }
+
if (tc.partial_parts == null)
tc.partial_parts = new ArrayList (1);
public void AddDelegate (Delegate d)
{
- if (!AddToTypeContainer (d))
+ if (!AddMemberType (d))
return;
if (delegates == null)
delegates = new MemberCoreArrayList ();
-
+
delegates.Add (d);
}
public void AddMethod (Method method)
{
- if (!AddToMemberContainer (method))
+ if (!AddMember (method))
return;
if (methods == null)
//
public void AppendMethod (Method method)
{
- if (!AddToMemberContainer (method))
+ if (!AddMember (method))
return;
if (methods == null)
public void AddConstructor (Constructor c)
{
- if (c.Name != Basename) {
+ if (c.Name != MemberName.Name) {
Report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
}
return "`{0}' is already defined. Rename this member or use different parameter types";
}
}
-
- public bool AddInterface (TypeContainer iface)
- {
- if (!AddToTypeContainer (iface))
- return false;
-
- if (interfaces == null) {
- interfaces = new MemberCoreArrayList ();
- }
-
- RootContext.Tree.RecordDecl (iface.NamespaceEntry.NS, iface.MemberName, iface);
- interfaces.Add (iface);
- return true;
- }
- public void AddField (FieldMember field)
+ public void AddField (FieldBase field)
{
- if (!AddToMemberContainer (field))
+ if (!AddMember (field))
return;
if (fields == null)
public void AddProperty (Property prop)
{
- if (!AddToMemberContainer (prop) ||
- !AddToMemberContainer (prop.Get) || !AddToMemberContainer (prop.Set))
+ if (!AddMember (prop) ||
+ !AddMember (prop.Get) || !AddMember (prop.Set))
return;
if (properties == null)
public void AddEvent (Event e)
{
- if (!AddToMemberContainer (e))
+ if (!AddMember (e))
return;
if (e is EventProperty) {
- if (!AddToMemberContainer (e.Add))
+ if (!AddMember (e.Add))
return;
- if (!AddToMemberContainer (e.Remove))
+ if (!AddMember (e.Remove))
return;
}
public void AddOperator (Operator op)
{
- if (!AddToMemberContainer (op))
+ if (!AddMember (op))
return;
if (operators == null)
operators.Add (op);
}
- public void AddIterator (Iterator i)
+ public void AddCompilerGeneratedClass (CompilerGeneratedClass c)
{
- if (iterators == null)
- iterators = new ArrayList ();
+ Report.Debug (64, "ADD COMPILER GENERATED CLASS", this, c);
+
+ if (compiler_generated == null)
+ compiler_generated = new ArrayList ();
- iterators.Add (i);
+ compiler_generated.Add (c);
}
public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
}
}
- public ArrayList Iterators {
+ public ArrayList CompilerGenerated {
get {
- return iterators;
+ return compiler_generated;
}
}
}
}
- public virtual void RegisterFieldForInitialization (FieldBase field)
+ public virtual void RegisterFieldForInitialization (MemberCore field, FieldInitializer expression)
{
if ((field.ModFlags & Modifiers.STATIC) != 0){
if (initialized_static_fields == null)
initialized_static_fields = new ArrayList (4);
- initialized_static_fields.Add (field);
+ initialized_static_fields.Add (expression);
} else {
if (initialized_fields == null)
initialized_fields = new ArrayList (4);
- initialized_fields.Add (field);
+ initialized_fields.Add (expression);
}
}
if (fields == null)
return true;
- foreach (FieldBase f in fields) {
- f.EmitInitializer (ec);
+ foreach (FieldInitializer f in fields) {
+ f.EmitStatement (ec);
}
return true;
}
return base.GetClsCompliantAttributeValue ();
}
+ public void AddBasesForPart (DeclSpace part, ArrayList bases)
+ {
+ // FIXME: get rid of partial_parts and store lists of bases of each part here
+ // assumed, not verified: 'part' is in 'partial_parts'
+ ((TypeContainer) part).Bases = bases;
+ }
+
TypeExpr[] GetNormalBases (out TypeExpr base_class)
{
base_class = null;
TypeExpr [] ifaces = new TypeExpr [count-start];
for (i = start, j = 0; i < count; i++, j++){
- TypeExpr resolved = ((Expression) Bases [i]).ResolveAsTypeTerminal (this, false);
+ TypeExpr resolved = ((Expression) Bases [i]).ResolveAsBaseTerminal (this, false);
if (resolved == null) {
return null;
}
if (!iface.IsInterface) {
if (Kind != Kind.Class) {
// TODO: location of symbol related ....
- Error_TypeInListIsNotInterface (Location, iface.FullName);
+ Error_TypeInListIsNotInterface (Location, iface.GetSignatureForError ());
}
else if (base_class != null)
Report.Error (1721, Location, "`{0}': Classes cannot have multiple base classes (`{1}' and `{2}')",
return ifaces;
}
+ bool CheckGenericInterfaces (Type[] ifaces)
+ {
+#if GMCS_SOURCE
+ 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;
+
+ Type[] inferred = new Type [CountTypeParameters];
+ if (!TypeManager.MayBecomeEqualGenericInstances (iface, t, inferred, null))
+ continue;
+
+ Report.Error (695, Location,
+ "`{0}' cannot implement both `{1}' and `{2}' " +
+ "because they may unify for some type parameter substitutions",
+ TypeManager.CSharpName (TypeBuilder), TypeManager.CSharpName (iface),
+ TypeManager.CSharpName (t));
+ return false;
+ }
+
+ already_checked.Add (iface);
+ }
+#endif
+
+ return true;
+ }
+
bool error = false;
protected void Error_TypeInListIsNotInterface (Location loc, string type)
}
ModuleBuilder builder = CodeGen.Module.Builder;
+ Type default_parent = null;
+ if (Kind == Kind.Struct)
+ default_parent = TypeManager.value_type;
TypeBuilder = builder.DefineType (
- Name, TypeAttr, null, null);
+ Name, TypeAttr, default_parent, null);
} else {
TypeBuilder builder = Parent.TypeBuilder;
TypeManager.AddUserType (this);
+#if GMCS_SOURCE
+ if (IsGeneric) {
+ string[] param_names = new string [TypeParameters.Length];
+ for (int i = 0; i < TypeParameters.Length; i++)
+ param_names [i] = TypeParameters [i].Name;
+
+ gen_params = TypeBuilder.DefineGenericParameters (param_names);
+
+ int offset = CountTypeParameters - CurrentTypeParameters.Length;
+ for (int i = offset; i < gen_params.Length; i++)
+ CurrentTypeParameters [i - offset].Define (gen_params [i]);
+ }
+#endif
+
iface_exprs = GetClassBases (out base_type);
if (partial_parts != null) {
iface_exprs = GetNormalPartialBases (ref base_type);
// Let's do it as soon as possible, since code below can call DefineType() on classes
// that depend on us to be populated before they are.
//
- if (!(this is Iterator))
+ if (!(this is CompilerGeneratedClass))
RootContext.RegisterOrder (this);
+ if (IsGeneric && base_type != null && TypeManager.IsAttributeType (base_type.Type)) {
+ Report.Error (698, base_type.Location,
+ "A generic type cannot derive from `{0}' because it is an attribute class",
+ base_type.Name);
+ return false;
+ }
+
+ if (!CheckRecursiveDefinition (this))
+ return false;
if (base_type != null) {
TypeBuilder.SetParent (base_type.Type);
ObsoleteAttribute obsolete_attr = AttributeTester.GetObsoleteAttribute (base_type.Type);
- if (obsolete_attr != null && !IsInObsoleteScope) {
+ if (obsolete_attr != null && !IsInObsoleteScope)
AttributeTester.Report_ObsoleteMessage (obsolete_attr, base_type.GetSignatureForError (), Location);
- }
- }
-
- if (!CheckRecursiveDefinition (this)) {
- return false;
}
// add interfaces that were not added at type creation
if (iface_exprs != null) {
ifaces = TypeManager.ExpandInterfaces (iface_exprs);
- if (ifaces == null) {
+ if (ifaces == null)
return false;
- }
foreach (Type itype in ifaces)
- TypeBuilder.AddInterfaceImplementation (itype);
+ TypeBuilder.AddInterfaceImplementation (itype);
+
+ foreach (TypeExpr ie in iface_exprs) {
+ ObsoleteAttribute oa = AttributeTester.GetObsoleteAttribute (ie.Type);
+ if ((oa != null) && !IsInObsoleteScope)
+ AttributeTester.Report_ObsoleteMessage (
+ oa, ie.GetSignatureForError (), Location);
+ }
+
+ if (!CheckGenericInterfaces (ifaces))
+ return false;
TypeManager.RegisterBuilder (TypeBuilder, ifaces);
}
part.TypeBuilder = TypeBuilder;
}
- DefineNestedTypes ();
+ if (!(this is CompilerGeneratedClass)) {
+ if (!ResolveMembers ()) {
+ error = true;
+ return null;
+ }
+ }
+
+ if (!DefineNestedTypes ()) {
+ error = true;
+ return null;
+ }
return TypeBuilder;
}
+ public bool ResolveMembers ()
+ {
+ if (members_resolved)
+ return members_resolved_ok;
+
+ members_resolved_ok = DoResolveMembers ();
+ members_resolved = true;
+
+ return members_resolved_ok;
+ }
+
+ protected virtual bool DoResolveMembers ()
+ {
+ if (methods != null) {
+ foreach (Method method in methods) {
+ if (!method.ResolveMembers ())
+ return false;
+ }
+ }
+
+ if (instance_constructors != null) {
+ foreach (Constructor c in instance_constructors) {
+ if (!c.ResolveMembers ())
+ return false;
+ }
+ }
+
+ if (default_static_constructor != null) {
+ if (!default_static_constructor.ResolveMembers ())
+ return false;
+ }
+
+ if (operators != null) {
+ foreach (Operator o in operators) {
+ if (!o.ResolveMembers ())
+ return false;
+ }
+ }
+
+ if (properties != null) {
+ foreach (PropertyBase p in properties) {
+ if (!p.Get.IsDummy && !p.Get.ResolveMembers ())
+ return false;
+ if (!p.Set.IsDummy && !p.Set.ResolveMembers ())
+ return false;
+ }
+ }
+
+ if (indexers != null) {
+ foreach (PropertyBase p in indexers) {
+ if (!p.Get.IsDummy && !p.Get.ResolveMembers ())
+ return false;
+ if (!p.Set.IsDummy && !p.Set.ResolveMembers ())
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ Constraints [] constraints;
+ public override void SetParameterInfo (ArrayList constraints_list)
+ {
+ if (PartialContainer == this) {
+ base.SetParameterInfo (constraints_list);
+ return;
+ }
+
+ if (constraints_list == null)
+ return;
+
+ constraints = new Constraints [PartialContainer.CountCurrentTypeParameters];
+
+ TypeParameter[] current_params = PartialContainer.CurrentTypeParameters;
+ for (int i = 0; i < constraints.Length; i++) {
+ foreach (Constraints constraint in constraints_list) {
+ if (constraint.TypeParameter == current_params [i].Name) {
+ constraints [i] = constraint;
+ break;
+ }
+ }
+ }
+ }
+
+ bool UpdateTypeParameterConstraints ()
+ {
+ if (constraints == null)
+ return true;
+
+ TypeParameter[] current_params = PartialContainer.CurrentTypeParameters;
+ for (int i = 0; i < current_params.Length; i++) {
+ if (!current_params [i].UpdateConstraints (this, constraints [i])) {
+ Report.SymbolRelatedToPreviousError (Location, "");
+ Report.Error (265, PartialContainer.Location,
+ "Partial declarations of `{0}' have inconsistent constraints for type parameter `{1}'",
+ PartialContainer.GetSignatureForError (), current_params [i].Name);
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public bool ResolveType ()
+ {
+ if (!DoResolveType ())
+ return false;
+
+ if (compiler_generated != null) {
+ foreach (CompilerGeneratedClass c in compiler_generated)
+ if (!c.ResolveType ())
+ return false;
+ }
+
+ return true;
+ }
+
+ protected virtual bool DoResolveType ()
+ {
+ if ((base_type != null) &&
+ (base_type.ResolveAsTypeTerminal (this, false) == null)) {
+ error = true;
+ return false;
+ }
+
+ if (!IsGeneric)
+ return true;
+
+ if (PartialContainer != this)
+ throw new InternalErrorException ();
+
+ TypeExpr current_type = null;
+
+ foreach (TypeParameter type_param in CurrentTypeParameters) {
+ if (!type_param.Resolve (this)) {
+ error = true;
+ return false;
+ }
+ }
+
+ if (partial_parts != null) {
+ foreach (TypeContainer part in partial_parts) {
+ if (!part.UpdateTypeParameterConstraints ()) {
+ error = true;
+ return false;
+ }
+ }
+ }
+
+ foreach (TypeParameter type_param in TypeParameters) {
+ if (!type_param.DefineType (this)) {
+ error = true;
+ return false;
+ }
+ }
+
+ current_type = new ConstructedType (TypeBuilder, TypeParameters, Location);
+
+ foreach (TypeParameter type_param in TypeParameters)
+ if (!type_param.CheckDependencies ()) {
+ error = true;
+ return false;
+ }
+
+ if (current_type != null) {
+ current_type = current_type.ResolveAsTypeTerminal (this, false);
+ if (current_type == null) {
+ error = true;
+ return false;
+ }
+
+ CurrentType = current_type.Type;
+ }
+
+ return true;
+ }
+
protected virtual bool DefineNestedTypes ()
{
if (Interfaces != null) {
return false;
}
+ if (compiler_generated != null) {
+ foreach (CompilerGeneratedClass c in compiler_generated) {
+ if (c.DefineType () == null)
+ return false;
+ }
+ }
+
return true;
}
InTransit = tc;
- if (BaseType != null) {
- TypeContainer ptc = TypeManager.LookupTypeContainer (BaseType);
+ if (base_type != null) {
+ Type t = TypeManager.DropGenericTypeArguments (base_type.Type);
+ TypeContainer ptc = TypeManager.LookupTypeContainer (t);
if ((ptc != null) && !ptc.CheckRecursiveDefinition (this))
return false;
}
if (iface_exprs != null) {
foreach (TypeExpr iface in iface_exprs) {
- Type itype = iface.Type;
-
+ Type itype = TypeManager.DropGenericTypeArguments (iface.Type);
TypeContainer ptc = TypeManager.LookupTypeContainer (itype);
if ((ptc != null) && !ptc.CheckRecursiveDefinition (this))
return false;
}
}
+ if (!IsTopLevel && !Parent.PartialContainer.CheckRecursiveDefinition (this))
+ return false;
+
InTransit = null;
return true;
}
protected virtual bool DoDefineMembers ()
{
+ if (iface_exprs != null) {
+ foreach (TypeExpr iface in iface_exprs) {
+ ConstructedType ct = iface as ConstructedType;
+ if ((ct != null) && !ct.CheckConstraints (this))
+ return false;
+ }
+ }
+
+ if (base_type != null) {
+ ConstructedType ct = base_type as ConstructedType;
+ if ((ct != null) && !ct.CheckConstraints (this))
+ return false;
+ }
+
if (!IsTopLevel) {
- MemberInfo conflict_symbol = Parent.MemberCache.FindMemberWithSameName (Basename, false, TypeBuilder);
+ MemberInfo conflict_symbol = Parent.PartialContainer.FindBaseMemberWithSameName (Basename, false);
if (conflict_symbol == null) {
if ((RootContext.WarningLevel >= 4) && ((ModFlags & Modifiers.NEW) != 0))
Report.Warning (109, 4, Location, "The member `{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError ());
DefineContainerMembers (methods);
DefineContainerMembers (operators);
DefineContainerMembers (enums);
- DefineContainerMembers (delegates);
+ DefineContainerMembers (delegates);
+
+ if (CurrentType != null) {
+ GenericType = CurrentType;
+ }
+
#if CACHE
member_cache = new MemberCache (this);
part.member_cache = member_cache;
}
#endif
- if (iterators != null) {
- foreach (Iterator iterator in iterators) {
- if (iterator.DefineType () == null)
- return false;
- }
-
- foreach (Iterator iterator in iterators) {
- if (!iterator.DefineMembers ())
- return false;
- }
- }
return true;
}
public override bool Define ()
{
- if (iterators != null) {
- foreach (Iterator iterator in iterators) {
- if (!iterator.Define ())
+ if (compiler_generated != null) {
+ foreach (CompilerGeneratedClass c in compiler_generated) {
+ if (!c.Define ())
return false;
}
}
public MemberInfo FindBaseMemberWithSameName (string name, bool ignore_methods)
{
- return BaseCache.FindMemberWithSameName (name, ignore_methods, null);
+ return BaseCache == null ? null : BaseCache.FindMemberWithSameName (name, ignore_methods, null);
}
/// <summary>
// Indicated whether container has StructLayout attribute set Explicit
public bool HasExplicitLayout {
- get {
- return (caching_flags & Flags.HasExplicitLayout) != 0;
- }
- set {
- caching_flags |= Flags.HasExplicitLayout;
- }
+ get { return (caching_flags & Flags.HasExplicitLayout) != 0; }
+ set { caching_flags |= Flags.HasExplicitLayout; }
}
- public override Type FindNestedType (string name)
+ //
+ // Return the nested type with name @name. Ensures that the nested type
+ // is defined if necessary. Do _not_ use this when you have a MemberCache handy.
+ //
+ public Type FindNestedType (string name)
{
if (PartialContainer != this)
- return PartialContainer.FindNestedType (name);
+ throw new InternalErrorException ("should not happen");
ArrayList [] lists = { types, enums, delegates, interfaces };
if (fields != null) {
int len = fields.Count;
for (int i = 0; i < len; i++) {
- FieldMember f = (FieldMember) fields [i];
+ FieldBase f = (FieldBase) fields [i];
if ((f.ModFlags & modflags) == 0)
continue;
}
}
+ if (events != null) {
+ foreach (Event e in events) {
+ if ((e.ModFlags & modflags) == 0)
+ continue;
+ if ((e.ModFlags & static_mask) != static_flags)
+ continue;
+
+ MethodBuilder b = e.AddBuilder;
+ if (b != null && filter (b, criteria)) {
+ if (members == null)
+ members = new ArrayList (4);
+
+ members.Add (b);
+ }
+
+ b = e.RemoveBuilder;
+ if (b != null && filter (b, criteria)) {
+ if (members == null)
+ members = new ArrayList (4);
+
+ members.Add (b);
+ }
+ }
+ }
+
if (properties != null) {
int len = properties.Count;
for (int i = 0; i < len; i++) {
members.AddRange (list);
}
}
- if (ifaces != null) {
- foreach (Type base_type in ifaces) {
- 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);
CheckMemberUsage (constants, "constant");
if (fields != null){
- foreach (FieldMember f in fields) {
+ foreach (FieldBase f in fields) {
if ((f.ModFlags & Modifiers.Accessibility) != Modifiers.PRIVATE)
continue;
if ((f.caching_flags & Flags.IsAssigned) != 0)
continue;
+ Constant c = New.Constantify (f.Type.Type);
Report.Warning (649, 4, f.Location, "Field `{0}' is never assigned to, and will always have its default value `{1}'",
- f.GetSignatureForError (), f.Type.Type.IsValueType ? Activator.CreateInstance (f.Type.Type).ToString() : "null");
+ f.GetSignatureForError (), c == null ? "null" : c.AsString ());
}
}
}
{
if (OptAttributes != null)
OptAttributes.Emit ();
-
+
+#if GMCS_SOURCE
+ if (IsGeneric) {
+ int offset = CountTypeParameters - CurrentTypeParameters.Length;
+ for (int i = offset; i < gen_params.Length; i++)
+ CurrentTypeParameters [i - offset].EmitAttributes ();
+ }
+#endif
+
//
// Structs with no fields need to have at least one byte.
// The right thing would be to set the PackingSize in a DefineType
}
if (fields != null)
- foreach (FieldMember f in fields)
+ foreach (FieldBase f in fields)
f.Emit ();
if (events != null){
if (pending.VerifyPendingMethods ())
return;
- if (iterators != null)
- foreach (Iterator iterator in iterators)
- iterator.EmitType ();
- }
+ if (Report.Errors > 0)
+ return;
+ if (compiler_generated != null) {
+ foreach (CompilerGeneratedClass c in compiler_generated) {
+ if (!c.DefineMembers ())
+ throw new InternalErrorException ();
+ }
+ foreach (CompilerGeneratedClass c in compiler_generated)
+ c.EmitType ();
+ }
+ }
+
public override void CloseType ()
{
if ((caching_flags & Flags.CloseTypeCreated) != 0)
foreach (Delegate d in Delegates)
d.CloseType ();
- if (Iterators != null)
- foreach (Iterator i in Iterators)
- i.CloseType ();
-
+ if (CompilerGenerated != null)
+ foreach (CompilerGeneratedClass c in CompilerGenerated)
+ c.CloseType ();
+
types = null;
properties = null;
enums = null;
events = null;
indexers = null;
operators = null;
- iterators = null;
+ compiler_generated = null;
default_constructor = null;
default_static_constructor = null;
type_bases = null;
if (base_type != null && !AttributeTester.IsClsCompliant (base_type)) {
Report.Error (3009, Location, "`{0}': base type `{1}' is not CLS-compliant", GetSignatureForError (), TypeManager.CSharpName (base_type));
}
-
- if (!Parent.IsClsComplianceRequired ()) {
- Report.Error (3018, Location, "`{0}' cannot be marked as CLS-compliant because it is a member of non CLS-compliant type `{1}'",
- GetSignatureForError (), Parent.GetSignatureForError ());
- }
return true;
}
} else {
Report.SymbolRelatedToPreviousError ((MemberCore) found);
}
+#if GMCS_SOURCE
+ Report.Warning (3005, 1, mc.Location, "Identifier `{0}' differing only in case is not CLS-compliant", mc.GetSignatureForError ());
+#else
Report.Error (3005, mc.Location, "Identifier `{0}' differing only in case is not CLS-compliant", mc.GetSignatureForError ());
+#endif
}
}
/// checks whether the `interface_type' is a base inteface implementation.
/// Then it checks whether `name' exists in the interface type.
/// </summary>
- public virtual bool VerifyImplements (MemberBase mb)
+ public virtual bool VerifyImplements (InterfaceMemberBase mb)
{
if (ifaces != null) {
foreach (Type t in ifaces){
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);
}
//
protected override bool AddToContainer (MemberCore symbol, string name)
{
- if (name == Basename) {
+ if (name == MemberName.Name) {
+ if (symbol is TypeParameter) {
+ Report.Error (694, symbol.Location,
+ "Type parameter `{0}' has same name as " +
+ "containing type, or method", name);
+ return false;
+ }
+
Report.SymbolRelatedToPreviousError (this);
Report.Error (542, symbol.Location, "`{0}': member names cannot be the same as their enclosing type",
symbol.GetSignatureForError ());
if ((events != null) && (RootContext.WarningLevel >= 3)) {
foreach (Event e in events){
- if ((e.caching_flags & Flags.IsAssigned) == 0)
+ if ((e.ModFlags & Modifiers.Accessibility) != Modifiers.PRIVATE)
+ continue;
+
+ if ((e.caching_flags & Flags.IsUsed) == 0)
Report.Warning (67, 3, e.Location, "The event `{0}' is never used", e.GetSignatureForError ());
}
}
void DefineFieldInitializers ()
{
if (initialized_fields != null) {
+ EmitContext ec = new EmitContext (this, this, Location, null, null, ModFlags);
+ ec.IsFieldInitializer = true;
+
for (int i = 0; i < initialized_fields.Count; ++i) {
- FieldBase fb = (FieldBase)initialized_fields[i];
- fb.ResolveInitializer ();
- if (fb.HasDefaultInitializer && RootContext.Optimize) {
+ FieldInitializer fi = (FieldInitializer)initialized_fields[i];
+ fi.ResolveStatement (ec);
+ if (fi.IsDefaultInitializer && RootContext.Optimize) {
// Field is re-initialized to its default value => removed
initialized_fields.RemoveAt (i);
--i;
if (initialized_static_fields != null) {
bool has_complex_initializer = false;
+ EmitContext ec = new EmitContext (this, this, Location, null, null, ModFlags);
+ ec.IsStatic = true;
+ ec.IsFieldInitializer = true;
- foreach (FieldBase fb in initialized_static_fields) {
- if (fb.ResolveInitializer () is Constant)
+ foreach (FieldInitializer fi in initialized_static_fields) {
+ fi.ResolveStatement (ec);
+ if (!fi.IsComplexInitializer)
continue;
has_complex_initializer = true;
// static int b = 0;
if (!has_complex_initializer && RootContext.Optimize) {
for (int i = 0; i < initialized_static_fields.Count; ++i) {
- FieldBase fb = (FieldBase)initialized_static_fields[i];
- if (fb.HasDefaultInitializer) {
+ FieldInitializer fi = (FieldInitializer)initialized_static_fields[i];
+ if (fi.IsDefaultInitializer) {
initialized_static_fields.RemoveAt (i);
--i;
}
this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, Location);
if (IsStatic && RootContext.Version == LanguageVersion.ISO_1) {
- Report.FeatureIsNotStandardized (Location, "static classes");
+ Report.FeatureIsNotISO1 (Location, "static classes");
}
}
else if (Name != "System.Object")
base_class = TypeManager.system_object_expr;
} else {
+ if (Kind == Kind.Class && base_class is TypeParameterExpr){
+ Report.Error (
+ 689, base_class.Location,
+ "Cannot derive from `{0}' because it is a type parameter",
+ base_class.GetSignatureForError ());
+ return ifaces;
+ }
+
if (base_class.Type.IsArray || base_class.Type.IsPointer) {
Report.Error (1521, base_class.Location, "Invalid base type");
return ifaces;
}
}
- public override void RegisterFieldForInitialization (FieldBase field)
+ public override void RegisterFieldForInitialization (MemberCore field, FieldInitializer expression)
{
if ((field.ModFlags & Modifiers.STATIC) == 0) {
Report.Error (573, field.Location, "`{0}': Structs cannot have instance field initializers",
field.GetSignatureForError ());
return;
}
- base.RegisterFieldForInitialization (field);
+ base.RegisterFieldForInitialization (field, expression);
}
}
}
}
- public abstract class MethodCore : MemberBase {
+ // It is used as a base class for all property based members
+ // This includes properties, indexers, and events
+ public abstract class PropertyBasedMember : InterfaceMemberBase
+ {
+ public PropertyBasedMember (DeclSpace parent, GenericMethod generic,
+ Expression type, int mod, int allowed_mod, bool is_iface,
+ MemberName name, Attributes attrs)
+ : base (parent, generic, type, mod, allowed_mod, is_iface, name, attrs)
+ {
+ }
+
+ protected override bool CheckForDuplications ()
+ {
+ throw new NotSupportedException ();
+ }
+
+ protected override bool VerifyClsCompliance ()
+ {
+ if (!base.VerifyClsCompliance ())
+ return false;
+
+ if (!AttributeTester.IsClsCompliant (MemberType)) {
+ Report.Error (3003, Location, "Type of `{0}' is not CLS-compliant",
+ GetSignatureForError ());
+ }
+ return true;
+ }
+
+ }
+
+
+ public abstract class MethodCore : InterfaceMemberBase
+ {
public readonly Parameters Parameters;
protected ToplevelBlock block;
- //
- // The method we're overriding if this is an override method.
- //
- protected MethodInfo base_method = null;
-
- public MethodCore (DeclSpace parent, Expression type, int mod,
- int allowed_mod, bool is_interface, MemberName name,
- Attributes attrs, Parameters parameters)
- : base (parent, type, mod, allowed_mod, Modifiers.PRIVATE, name,
- attrs)
+ public MethodCore (DeclSpace parent, GenericMethod generic,
+ Expression type, int mod, int allowed_mod, bool is_iface,
+ MemberName name, Attributes attrs, Parameters parameters)
+ : base (parent, generic, type, mod, allowed_mod, is_iface, name, attrs)
{
Parameters = parameters;
- IsInterface = is_interface;
}
-
+
//
// Returns the System.Type array for the parameters of this method
//
}
}
- public void SetYields ()
+ protected bool DoDefineParameters ()
{
- ModFlags |= Modifiers.METHOD_YIELDS;
+ IResolveContext rc = GenericMethod == null ? this : (IResolveContext)ds;
+
+ // Check if arguments were correct
+ if (!Parameters.Resolve (rc))
+ return false;
+
+ return CheckParameters (Parameters);
}
protected override bool CheckBase ()
{
+ // Check whether arguments were correct.
+ if (!DoDefineParameters ())
+ return false;
+
if (!base.CheckBase ())
return false;
+
+ return true;
+ }
+
+ // TODO: create a special method for operators only to make code better
+ protected bool IsDuplicateImplementation (MethodCore method)
+ {
+ if (method == this)
+ return false;
+
+ Operator op2 = null;
+ Operator op1 = null;
+
+ if (!(method.MemberName.Equals (MemberName)))
+ {
+ op1 = this as Operator;
+ if (op1 == null || !(op1.OperatorType == Operator.OpType.Explicit || op1.OperatorType == Operator.OpType.Implicit))
+ return false;
+
+ op2 = method as Operator;
+ if (op2 == null || !(op2.OperatorType == Operator.OpType.Explicit || op2.OperatorType == Operator.OpType.Implicit))
+ return false;
+ } else {
+ op1 = this as Operator;
+ op2 = method as Operator;
+ }
+
+ Type[] param_types = method.ParameterTypes;
+ // This never happen. Rewrite this as Equal
+ if (param_types == null && ParameterTypes == null)
+ return true;
+ if (param_types == null || ParameterTypes == null)
+ return false;
+
+ if (param_types.Length != ParameterTypes.Length)
+ return false;
+
+ if (method.Parameters.HasArglist != Parameters.HasArglist)
+ return false;
- // Check whether arguments were correct.
- if (!DoDefineParameters ())
+ bool equal = true;
+
+ for (int i = 0; i < param_types.Length; i++) {
+ if (param_types [i] != ParameterTypes [i])
+ equal = false;
+ }
+
+ if (IsExplicitImpl && (method.InterfaceType != InterfaceType))
+ equal = false;
+
+ // TODO: make operator compatible with MethodCore to avoid this
+ if (op1 != null && op2 != null) {
+ if (MemberType != method.MemberType)
+ equal = false;
+ }
+
+ if (equal) {
+ //
+ // Try to report 663: method only differs on out/ref
+ //
+ Parameters info = ParameterInfo;
+ Parameters other_info = method.ParameterInfo;
+ for (int i = 0; i < info.Count; i++){
+ if (info.ParameterModifier (i) != other_info.ParameterModifier (i)){
+ Report.SymbolRelatedToPreviousError (method);
+ Report.Error (663, Location, "`{0}': Methods cannot differ only on their use of ref and out on a parameters",
+ GetSignatureForError ());
+ return false;
+ }
+ }
+
+ Report.SymbolRelatedToPreviousError (method);
+ if (this is Operator && method is Operator)
+ Report.Error (557, Location, "Duplicate user-defined conversion in type `{0}'", Parent.Name);
+ else
+ Report.Error (111, Location, TypeContainer.Error111, GetSignatureForError ());
+
+ return true;
+ }
+
+ return false;
+ }
+
+ //
+ // Returns a string that represents the signature for this
+ // member which should be used in XML documentation.
+ //
+ public override string GetDocCommentName (DeclSpace ds)
+ {
+ return DocUtil.GetMethodDocCommentName (this, Parameters, ds);
+ }
+
+ //
+ // Raised (and passed an XmlElement that contains the comment)
+ // when GenerateDocComment is writing documentation expectedly.
+ //
+ // FIXME: with a few effort, it could be done with XmlReader,
+ // that means removal of DOM use.
+ //
+ internal override void OnGenerateDocComment (XmlElement el)
+ {
+ DocUtil.OnMethodGenerateDocComment (this, el);
+ }
+
+ //
+ // Represents header string for documentation comment.
+ //
+ public override string DocCommentHeader
+ {
+ get { return "M:"; }
+ }
+
+ public virtual void SetYields ()
+ {
+ ModFlags |= Modifiers.METHOD_YIELDS;
+ }
+
+ protected override bool VerifyClsCompliance ()
+ {
+ if (!base.VerifyClsCompliance ())
return false;
+ if (Parameters.HasArglist) {
+ Report.Error (3000, Location, "Methods with variable arguments are not CLS-compliant");
+ }
+
+ if (!AttributeTester.IsClsCompliant (MemberType)) {
+ Report.Error (3002, Location, "Return type of `{0}' is not CLS-compliant",
+ GetSignatureForError ());
+ }
+
+ Parameters.VerifyClsCompliance ();
+ return true;
+ }
+
+ }
+
+ public abstract class InterfaceMemberBase : MemberBase {
+ //
+ // Whether this is an interface member.
+ //
+ public bool IsInterface;
+
+ //
+ // If true, this is an explicit interface implementation
+ //
+ public bool IsExplicitImpl;
+
+ //
+ // The interface type we are explicitly implementing
+ //
+ public Type InterfaceType;
+
+ //
+ // The method we're overriding if this is an override method.
+ //
+ protected MethodInfo base_method;
+
+ readonly int explicit_mod_flags;
+ public MethodAttributes flags;
+
+ public InterfaceMemberBase (DeclSpace parent, GenericMethod generic,
+ Expression type, int mod, int allowed_mod, bool is_iface,
+ MemberName name, Attributes attrs)
+ : base (parent, generic, type, mod, allowed_mod, Modifiers.PRIVATE,
+ name, attrs)
+ {
+ IsInterface = is_iface;
+ IsExplicitImpl = (MemberName.Left != null);
+ explicit_mod_flags = mod;
+ }
+
+ protected override bool CheckBase ()
+ {
+ if (!base.CheckBase ())
+ return false;
+
if ((caching_flags & Flags.TestMethodDuplication) != 0 && !CheckForDuplications ())
return false;
return true;
// Is null for System.Object while compiling corlib and base interfaces
- if (ParentContainer.BaseCache == null) {
- if ((RootContext.WarningLevel >= 4) && ((ModFlags & Modifiers.NEW) != 0)) {
+ if (Parent.PartialContainer.BaseCache == null) {
+ if ((ModFlags & Modifiers.NEW) != 0) {
Report.Warning (109, 4, Location, "The member `{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError ());
}
return true;
// method is override
if (base_method != null) {
-
- if (!CheckMethodAgainstBase ())
- return false;
-
- if ((ModFlags & Modifiers.NEW) == 0) {
- if (MemberType != TypeManager.TypeToCoreType (base_ret_type)) {
- Report.SymbolRelatedToPreviousError (base_method);
- if (this is PropertyBase) {
- Report.Error (1715, Location, "`{0}': type must be `{1}' to match overridden member `{2}'",
- GetSignatureForError (), TypeManager.CSharpName (base_ret_type), TypeManager.CSharpSignature (base_method));
- }
- else {
- Report.Error (508, Location, "`{0}': return type must be `{1}' to match overridden member `{2}'",
- GetSignatureForError (), TypeManager.CSharpName (base_ret_type), TypeManager.CSharpSignature (base_method));
- }
- return false;
- }
- } else {
- if (base_method.IsAbstract && !IsInterface) {
- Report.SymbolRelatedToPreviousError (base_method);
- Report.Error (533, Location, "`{0}' hides inherited abstract member `{1}'",
- GetSignatureForError (), TypeManager.CSharpSignature (base_method));
- return false;
- }
- }
-
- if (base_method.IsSpecialName && !(this is PropertyBase)) {
- Report.Error (115, Location, "`{0}': no suitable method found to override", GetSignatureForError ());
+ if (!CheckMethodAgainstBase (base_ret_type))
return false;
- }
-
- if (Name == "Equals" && Parameters.Count == 1 && ParameterTypes [0] == TypeManager.object_type)
- ParentContainer.Mark_HasEquals ();
- else if (Name == "GetHashCode" && Parameters.Empty)
- ParentContainer.Mark_HasGetHashCode ();
if ((ModFlags & Modifiers.OVERRIDE) != 0) {
ObsoleteAttribute oa = AttributeTester.GetMethodObsoleteAttribute (base_method);
if (oa != null) {
if (OptAttributes == null || !OptAttributes.Contains (TypeManager.obsolete_attribute_type)) {
Report.SymbolRelatedToPreviousError (base_method);
- Report.Warning (672, 1, Location, "Member `{0}' overrides obsolete member `{1}'. Add the Obsolete attribute to `{0}'",
- GetSignatureForError (), TypeManager.CSharpSignature (base_method) );
+ Report.Warning (672, 1, Location, "Member `{0}' overrides obsolete member `{1}'. Add the Obsolete attribute to `{0}'",
+ GetSignatureForError (), TypeManager.CSharpSignature (base_method));
+ }
+ } else {
+ if (OptAttributes != null && OptAttributes.Contains (TypeManager.obsolete_attribute_type)) {
+ Report.Warning (809, 1, Location, "Obsolete member `{0}' overrides non-obsolete member `{1}'",
+ GetSignatureForError (), TypeManager.CSharpSignature (base_method));
}
}
}
return true;
}
- MemberInfo conflict_symbol = ParentContainer.FindBaseMemberWithSameName (Name, !(this is Property));
+ MemberInfo conflict_symbol = Parent.PartialContainer.FindBaseMemberWithSameName (Name, !((this is Event) || (this is Property)));
if ((ModFlags & Modifiers.OVERRIDE) != 0) {
if (conflict_symbol != null) {
Report.SymbolRelatedToPreviousError (conflict_symbol);
- if (this is PropertyBase)
+ if (this is Event)
+ Report.Error (72, Location, "`{0}': cannot override because `{1}' is not an event", GetSignatureForError (), TypeManager.GetFullNameSignature (conflict_symbol));
+ else if (this is PropertyBase)
Report.Error (544, Location, "`{0}': cannot override because `{1}' is not a property", GetSignatureForError (), TypeManager.GetFullNameSignature (conflict_symbol));
else
Report.Error (505, Location, "`{0}': cannot override because `{1}' is not a method", GetSignatureForError (), TypeManager.GetFullNameSignature (conflict_symbol));
- } else
- Report.Error (115, Location, "`{0}': no suitable method found to override", GetSignatureForError ());
+ } else {
+ Report.Error (115, Location, "`{0}' is marked as an override but no suitable {1} found to override",
+ GetSignatureForError (), SimpleName.GetMemberType (this));
+ }
return false;
}
// `name' is the user visible name for reporting errors (this is used to
// provide the right name regarding method names and properties)
//
- bool CheckMethodAgainstBase ()
+ bool CheckMethodAgainstBase (Type baseMethodType)
{
bool ok = true;
Error_CannotChangeAccessModifiers (base_method, base_classp, null);
ok = false;
}
+
+ if (!TypeManager.IsEqual (MemberType, TypeManager.TypeToCoreType (baseMethodType))) {
+ Report.SymbolRelatedToPreviousError (base_method);
+ if (this is PropertyBasedMember) {
+ Report.Error (1715, Location, "`{0}': type must be `{1}' to match overridden member `{2}'",
+ GetSignatureForError (), TypeManager.CSharpName (baseMethodType), TypeManager.CSharpSignature (base_method));
+ }
+ else {
+ Report.Error (508, Location, "`{0}': return type must be `{1}' to match overridden member `{2}'",
+ GetSignatureForError (), TypeManager.CSharpName (baseMethodType), TypeManager.CSharpSignature (base_method));
+ }
+ ok = false;
+ }
}
- if ((ModFlags & (Modifiers.NEW | Modifiers.OVERRIDE)) == 0 && Name != "Finalize") {
- ModFlags |= Modifiers.NEW;
- Report.SymbolRelatedToPreviousError (base_method);
- if (!IsInterface && (base_method.IsVirtual || base_method.IsAbstract)) {
- Report.Warning (114, 2, Location, "`{0}' hides inherited member `{1}'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword",
- GetSignatureForError (), TypeManager.CSharpSignature (base_method));
- } else {
- Report.Warning (108, 2, Location, "`{0}' hides inherited member `{1}'. Use the new keyword if hiding was intended",
+ if ((ModFlags & Modifiers.NEW) == 0) {
+ if ((ModFlags & Modifiers.OVERRIDE) == 0 && Name != "Finalize") {
+ ModFlags |= Modifiers.NEW;
+ Report.SymbolRelatedToPreviousError (base_method);
+ if (!IsInterface && (base_method.IsVirtual || base_method.IsAbstract)) {
+ Report.Warning (114, 2, Location, "`{0}' hides inherited member `{1}'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword",
+ GetSignatureForError (), TypeManager.CSharpSignature (base_method));
+ } else {
+ Report.Warning (108, 2, Location, "`{0}' hides inherited member `{1}'. Use the new keyword if hiding was intended",
+ GetSignatureForError (), TypeManager.CSharpSignature (base_method));
+ }
+ }
+ } else {
+ if (base_method.IsAbstract && !IsInterface) {
+ Report.SymbolRelatedToPreviousError (base_method);
+ Report.Error (533, Location, "`{0}' hides inherited abstract member `{1}'",
GetSignatureForError (), TypeManager.CSharpSignature (base_method));
+ return ok = false;
}
}
public bool CheckAbstractAndExtern (bool has_block)
{
- if (ParentContainer.Kind == Kind.Interface)
+ if (Parent.PartialContainer.Kind == Kind.Interface)
return true;
if (has_block) {
return true;
}
- protected void Error_CannotChangeAccessModifiers (MemberInfo base_method, MethodAttributes ma, string suffix)
+ protected bool CheckParameters (Parameters parameters)
{
- Report.SymbolRelatedToPreviousError (base_method);
- string base_name = TypeManager.GetFullNameSignature (base_method);
- string this_name = GetSignatureForError ();
- if (suffix != null) {
- base_name += suffix;
- this_name += suffix;
- }
+ bool error = false;
- Report.Error (507, Location, "`{0}': cannot change access modifiers when overriding `{1}' inherited member `{2}'",
- this_name, Modifiers.GetDescription (ma), base_name);
- }
+ foreach (Type partype in parameters.Types){
+ if (partype.IsPointer){
+ if (!TypeManager.VerifyUnManaged (TypeManager.GetElementType (partype), Location))
+ error = true;
+ }
- protected static string Error722 {
- get {
- return "`{0}': static types cannot be used as return types";
- }
- }
-
- /// <summary>
- /// For custom member duplication search in a container
- /// </summary>
- protected abstract bool CheckForDuplications ();
-
- /// <summary>
- /// Gets base method and its return type
- /// </summary>
- protected abstract MethodInfo FindOutBaseMethod (ref Type base_ret_type);
-
- protected bool DoDefineParameters ()
- {
- // Check if arguments were correct
- if (!Parameters.Resolve (this))
- return false;
-
- return CheckParameters (ParameterTypes);
- }
-
- bool CheckParameters (Type [] parameters)
- {
- bool error = false;
- DeclSpace ds = Parent;
-
- 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 (!TypeManager.VerifyUnManaged (TypeManager.GetElementType (partype), Location))
- error = true;
- }
-
- if (ds.AsAccessible (partype, ModFlags))
- continue;
+ if (ds.AsAccessible (partype, ModFlags))
+ continue;
Report.SymbolRelatedToPreviousError (partype);
if (this is Indexer)
return !error;
}
- protected override bool VerifyClsCompliance ()
+ protected override bool DoDefine()
{
- if (!base.VerifyClsCompliance ()) {
- if ((ModFlags & Modifiers.ABSTRACT) != 0 && IsExposedFromAssembly () && Parent.IsClsComplianceRequired ()) {
- Report.Error (3011, Location, "`{0}': only CLS-compliant members can be abstract", GetSignatureForError ());
- }
+ if (!base.DoDefine ())
return false;
- }
-
- if (Parameters.HasArglist) {
- Report.Error (3000, Location, "Methods with variable arguments are not CLS-compliant");
- }
- if (!AttributeTester.IsClsCompliant (MemberType)) {
- if (this is PropertyBase)
- Report.Error (3003, Location, "Type of `{0}' is not CLS-compliant",
- GetSignatureForError ());
- else
- Report.Error (3002, Location, "Return type of `{0}' is not CLS-compliant",
- GetSignatureForError ());
- }
+ if (IsExplicitImpl) {
+ Expression expr = MemberName.Left.GetTypeExpression ();
+ TypeExpr texpr = expr.ResolveAsTypeTerminal (this, false);
+ if (texpr == null)
+ return false;
- Parameters.VerifyClsCompliance ();
+ InterfaceType = texpr.Type;
+ if (!InterfaceType.IsInterface) {
+ Report.Error (538, Location, "`{0}' in explicit interface declaration is not an interface", TypeManager.CSharpName (InterfaceType));
+ return false;
+ }
+
+ if (!Parent.PartialContainer.VerifyImplements (this))
+ return false;
+
+ }
return true;
}
- protected bool IsDuplicateImplementation (MethodCore method)
+ protected virtual bool DoDefineBase ()
{
- if (method == this || !(method.MemberName.Equals (MemberName)))
- return false;
-
- Type[] param_types = method.ParameterTypes;
- // This never happen. Rewrite this as Equal
- if (param_types == null && ParameterTypes == null)
- return true;
- if (param_types == null || ParameterTypes == null)
- return false;
+ if (Name == null)
+ throw new InternalErrorException ();
- if (param_types.Length != ParameterTypes.Length)
- return false;
+ if (IsInterface) {
+ ModFlags = Modifiers.PUBLIC |
+ Modifiers.ABSTRACT |
+ Modifiers.VIRTUAL | (ModFlags & Modifiers.UNSAFE) | (ModFlags & Modifiers.NEW);
- if (method.Parameters.HasArglist != Parameters.HasArglist)
- return false;
-
- for (int i = 0; i < param_types.Length; i++)
- if (param_types [i] != ParameterTypes [i])
+ flags = MethodAttributes.Public |
+ MethodAttributes.Abstract |
+ MethodAttributes.HideBySig |
+ MethodAttributes.NewSlot |
+ MethodAttributes.Virtual;
+ } else {
+ if (!Parent.PartialContainer.MethodModifiersValid (this))
return false;
- // TODO: make operator compatible with MethodCore to avoid this
- if (this is Operator && method is Operator) {
- if (MemberType != method.MemberType)
- return false;
+ flags = Modifiers.MethodAttr (ModFlags);
}
- //
- // Try to report 663: method only differs on out/ref
- //
- Parameters info = ParameterInfo;
- Parameters other_info = method.ParameterInfo;
- for (int i = 0; i < info.Count; i++){
- if (info.ParameterModifier (i) != other_info.ParameterModifier (i)){
- Report.SymbolRelatedToPreviousError (method);
- Report.Error (663, Location, "`{0}': Methods cannot differ only on their use of ref and out on a parameters",
- GetSignatureForError ());
+ if (IsExplicitImpl) {
+ Expression expr = MemberName.Left.GetTypeExpression ();
+ TypeExpr iface_texpr = expr.ResolveAsTypeTerminal (this, false);
+ if (iface_texpr == null)
+ return false;
+
+ InterfaceType = iface_texpr.Type;
+
+ if (!InterfaceType.IsInterface) {
+ Report.Error (538, Location, "'{0}' in explicit interface declaration is not an interface", TypeManager.CSharpName (InterfaceType));
return false;
}
+
+ if (!Parent.PartialContainer.VerifyImplements (this))
+ return false;
+
+ Modifiers.Check (Modifiers.AllowedExplicitImplFlags, explicit_mod_flags, 0, Location);
}
- Report.SymbolRelatedToPreviousError (method);
- if (this is Operator && method is Operator)
- Report.Error (557, Location, "Duplicate user-defined conversion in type `{0}'", Parent.Name);
- else
- Report.Error (111, Location, TypeContainer.Error111, GetSignatureForError ());
return true;
}
- public override bool IsUsed {
- get { return IsExplicitImpl || base.IsUsed; }
+ protected void Error_CannotChangeAccessModifiers (MemberInfo base_method, MethodAttributes ma, string suffix)
+ {
+ Report.SymbolRelatedToPreviousError (base_method);
+ string base_name = TypeManager.GetFullNameSignature (base_method);
+ string this_name = GetSignatureForError ();
+ if (suffix != null) {
+ base_name += suffix;
+ this_name += suffix;
+ }
+
+ Report.Error (507, Location, "`{0}': cannot change access modifiers when overriding `{1}' inherited member `{2}'",
+ this_name, Modifiers.GetDescription (ma), base_name);
+ }
+
+ protected static string Error722 {
+ get {
+ return "`{0}': static types cannot be used as return types";
+ }
}
+ /// <summary>
+ /// For custom member duplication search in a container
+ /// </summary>
+ protected abstract bool CheckForDuplications ();
+
+ /// <summary>
+ /// Gets base method and its return type
+ /// </summary>
+ protected abstract MethodInfo FindOutBaseMethod (ref Type base_ret_type);
+
//
- // Returns a string that represents the signature for this
- // member which should be used in XML documentation.
+ // The "short" name of this property / indexer / event. This is the
+ // name without the explicit interface.
//
- public override string GetDocCommentName (DeclSpace ds)
+ public string ShortName
{
- return DocUtil.GetMethodDocCommentName (this, ds);
+ get { return MemberName.Name; }
+ set { SetMemberName (new MemberName (MemberName.Left, value, Location)); }
}
- //
- // Raised (and passed an XmlElement that contains the comment)
- // when GenerateDocComment is writing documentation expectedly.
- //
- // FIXME: with a few effort, it could be done with XmlReader,
- // that means removal of DOM use.
- //
- internal override void OnGenerateDocComment (XmlElement el)
+ protected override bool VerifyClsCompliance ()
{
- DocUtil.OnMethodGenerateDocComment (this, el);
+ if (!base.VerifyClsCompliance ()) {
+ if (IsInterface && HasClsCompliantAttribute && Parent.IsClsComplianceRequired ()) {
+ Report.Error (3010, Location, "`{0}': CLS-compliant interfaces must have only CLS-compliant members", GetSignatureForError ());
+ }
+
+ if ((ModFlags & Modifiers.ABSTRACT) != 0 && Parent.TypeBuilder.IsClass && IsExposedFromAssembly () && Parent.IsClsComplianceRequired ()) {
+ Report.Error (3011, Location, "`{0}': only CLS-compliant members can be abstract", GetSignatureForError ());
+ }
+ return false;
+ }
+
+ if (GenericMethod != null)
+ GenericMethod.VerifyClsCompliance ();
+
+ return true;
}
- //
- // Represents header string for documentation comment.
- //
- public override string DocCommentHeader {
- get { return "M:"; }
+ public override bool IsUsed
+ {
+ get { return IsExplicitImpl || base.IsUsed; }
}
}
ListDictionary declarative_security;
protected MethodData MethodData;
+ Iterator iterator;
+ ArrayList anonymous_methods;
+
static string[] attribute_targets = new string [] { "method", "return" };
- protected MethodOrOperator (DeclSpace parent, Expression type, int mod,
+ protected MethodOrOperator (DeclSpace parent, GenericMethod generic, Expression type, int mod,
int allowed_mod, bool is_interface, MemberName name,
Attributes attrs, Parameters parameters)
- : base (parent, type, mod, allowed_mod, is_interface, name,
+ : base (parent, generic, type, mod, allowed_mod, is_interface, name,
attrs, parameters)
{
}
}
}
- public EmitContext CreateEmitContext (DeclSpace ds, ILGenerator ig)
+ public virtual EmitContext CreateEmitContext (DeclSpace tc, ILGenerator ig)
+ {
+ return new EmitContext (
+ this, tc, this.ds, Location, ig, MemberType, ModFlags, false);
+ }
+
+ public void AddAnonymousMethod (AnonymousMethodExpression anonymous)
+ {
+ if (anonymous_methods == null)
+ anonymous_methods = new ArrayList ();
+ anonymous_methods.Add (anonymous);
+ }
+
+ protected bool DefineGenericMethod ()
+ {
+ if (!DoDefineBase ())
+ return false;
+
+#if GMCS_SOURCE
+ if (GenericMethod != null) {
+ string method_name = MemberName.Name;
+
+ if (IsExplicitImpl) {
+ method_name = TypeManager.CSharpName (InterfaceType) +
+ '.' + method_name;
+ }
+
+ MethodBuilder = Parent.TypeBuilder.DefineMethod (method_name, flags);
+
+ if (!GenericMethod.Define (MethodBuilder, block))
+ return false;
+ }
+#endif
+
+ return true;
+ }
+
+ public bool ResolveMembers ()
{
- EmitContext ec = new EmitContext (this, ds, Parent, Location, ig, MemberType, ModFlags, false);
+ if (!DefineGenericMethod ())
+ return false;
+
+ if ((ModFlags & Modifiers.METHOD_YIELDS) != 0) {
+ iterator = Iterator.CreateIterator (this, Parent, GenericMethod, ModFlags);
+ if (iterator == null)
+ return false;
+ }
- ec.CurrentIterator = ds as Iterator;
- if (ec.CurrentIterator != null)
- ec.CurrentAnonymousMethod = ec.CurrentIterator.Host;
+ if (anonymous_methods != null) {
+ foreach (AnonymousMethodExpression ame in anonymous_methods) {
+ if (!ame.CreateAnonymousHelpers ())
+ return false;
+ }
+ }
- return ec;
+ return true;
}
public override bool Define ()
if (!CheckBase ())
return false;
- MethodData = new MethodData (this, ModFlags, flags, this);
+ MethodData = new MethodData (
+ this, ModFlags, flags, this, MethodBuilder, GenericMethod, base_method);
- if (!MethodData.Define (ParentContainer))
+ if (!MethodData.Define (Parent.PartialContainer))
return false;
MethodBuilder = MethodData.MethodBuilder;
}
}
+ public Iterator Iterator {
+ get { return iterator; }
+ }
+
public new Location Location {
get {
return base.Location;
}
}
- protected override bool CheckBase() {
+ protected override bool CheckBase ()
+ {
if (!base.CheckBase ())
return false;
return false;
}
+ GenericMethod IMethodData.GenericMethod {
+ get {
+ return GenericMethod;
+ }
+ }
+
#endregion
}
}
}
- public class Method : MethodOrOperator, IIteratorContainer {
+ public class Method : MethodOrOperator, IAnonymousHost {
/// <summary>
/// Modifiers allowed in a class declaration
//
// return_type can be "null" for VOID values.
//
- public Method (DeclSpace parent, Expression return_type, int mod, bool is_iface,
+ public Method (DeclSpace parent, GenericMethod generic,
+ Expression return_type, int mod, bool is_iface,
MemberName name, Parameters parameters, Attributes attrs)
- : base (parent, return_type, mod,
+ : base (parent, generic, return_type, mod,
is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
is_iface, name, attrs, parameters)
{
CodeGen.FileName, TypeManager.CSharpSignature(b));
}
- bool IsEntryPoint (MethodBuilder b, Parameters pinfo)
- {
- if (b.ReturnType != TypeManager.void_type &&
- b.ReturnType != TypeManager.int32_type)
- return false;
+ bool IsEntryPoint (Parameters pinfo)
+ {
+ if (ReturnType != TypeManager.void_type &&
+ ReturnType != TypeManager.int32_type)
+ return false;
- if (pinfo.Count == 0)
- return true;
+ if (pinfo.Count == 0)
+ return true;
- if (pinfo.Count > 1)
- return false;
+ if (pinfo.Count > 1)
+ return false;
- Type t = pinfo.ParameterType(0);
- if (t.IsArray &&
- (t.GetArrayRank() == 1) &&
- (TypeManager.GetElementType(t) == TypeManager.string_type) &&
- (pinfo.ParameterModifier(0) == Parameter.Modifier.NONE))
- return true;
- else
- return false;
- }
+ Type t = pinfo.ParameterType (0);
+ if (t.IsArray &&
+ (t.GetArrayRank () == 1) &&
+ (TypeManager.GetElementType (t) == TypeManager.string_type) &&
+ (pinfo.ParameterModifier (0) == Parameter.Modifier.NONE))
+ return true;
+ else
+ return false;
+ }
public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
{
protected override bool CheckForDuplications ()
{
- ArrayList ar = ParentContainer.Methods;
+ ArrayList ar = Parent.PartialContainer.Methods;
if (ar != null) {
int arLen = ar.Count;
}
}
- ar = ParentContainer.Properties;
+ ar = Parent.PartialContainer.Properties;
if (ar != null) {
for (int i = 0; i < ar.Count; ++i) {
PropertyBase pb = (PropertyBase) ar [i];
}
}
- ar = ParentContainer.Indexers;
+ ar = Parent.PartialContainer.Indexers;
if (ar != null) {
for (int i = 0; i < ar.Count; ++i) {
PropertyBase pb = (PropertyBase) ar [i];
}
}
- ar = ParentContainer.Events;
+ ar = Parent.PartialContainer.Events;
if (ar != null) {
for (int i = 0; i < ar.Count; ++i) {
Event ev = (Event) ar [i];
Report.Warning (465, 1, Location, "Introducing a 'Finalize' method can interfere with destructor invocation. Did you intend to declare a destructor?");
}
- //
- // Setup iterator if we are one
- //
- if ((ModFlags & Modifiers.METHOD_YIELDS) != 0){
- Iterator iterator = new Iterator (this,
- Parent,
- ModFlags);
-
- if (!iterator.DefineIterator ())
- return false;
+ if (base_method != null) {
+ if (Parameters.Count == 1 && ParameterTypes [0] == TypeManager.object_type && Name == "Equals")
+ Parent.PartialContainer.Mark_HasEquals ();
+ else if (Parameters.Empty && Name == "GetHashCode")
+ Parent.PartialContainer.Mark_HasGetHashCode ();
}
//
// This is used to track the Entry Point,
//
- if (Name == "Main" &&
- ((ModFlags & Modifiers.STATIC) != 0) && RootContext.NeedsEntryPoint &&
+ if (RootContext.NeedsEntryPoint && ((ModFlags & Modifiers.STATIC) != 0) &&
+ Name == "Main" &&
(RootContext.MainClass == null ||
RootContext.MainClass == Parent.TypeBuilder.FullName)){
- if (IsEntryPoint (MethodBuilder, ParameterInfo)) {
- IMethodData md = TypeManager.GetMethod (MethodBuilder);
- md.SetMemberIsUsed ();
+ if (IsEntryPoint (ParameterInfo)) {
if (RootContext.EntryPoint == null) {
- if (Parent.IsGeneric){
- Report.Error (-201, Location,
- "Entry point can not be defined in a generic class");
- }
+ if (Parent.IsGeneric || MemberName.IsGeneric) {
+ Report.Warning (402, 4, Location, "`{0}': an entry point cannot be generic or in a generic type",
+ GetSignatureForError ());
+ } else {
+ IMethodData md = TypeManager.GetMethod (MethodBuilder);
+ md.SetMemberIsUsed ();
- RootContext.EntryPoint = MethodBuilder;
- RootContext.EntryPointLocation = Location;
+ RootContext.EntryPoint = MethodBuilder;
+ RootContext.EntryPointLocation = Location;
+ }
} else {
Error_DuplicateEntryPoint (RootContext.EntryPoint, RootContext.EntryPointLocation);
Error_DuplicateEntryPoint (MethodBuilder, Location);
}
} else {
- if (RootContext.WarningLevel >= 4)
- Report.Warning (28, 4, Location, "`{0}' has the wrong signature to be an entry point", TypeManager.CSharpSignature(MethodBuilder));
+ Report.Warning (28, 4, Location, "`{0}' has the wrong signature to be an entry point",
+ GetSignatureForError ());
}
}
//
public override void Emit ()
{
+ Report.Debug (64, "METHOD EMIT", this, MethodBuilder, Location, Block, MethodData);
MethodData.Emit (Parent);
base.Emit ();
protected override MethodInfo FindOutBaseMethod (ref Type base_ret_type)
{
- MethodInfo mi = (MethodInfo) ParentContainer.BaseCache.FindMemberToOverride (
- Parent.TypeBuilder, Name, ParameterTypes, false);
+ MethodInfo mi = (MethodInfo) Parent.PartialContainer.BaseCache.FindMemberToOverride (
+ Parent.TypeBuilder, Name, ParameterTypes, GenericMethod, false);
if (mi == null)
return null;
return false;
if (ParameterInfo.Count > 0) {
- ArrayList al = (ArrayList)ParentContainer.MemberCache.Members [Name];
+ ArrayList al = (ArrayList)Parent.PartialContainer.MemberCache.Members [Name];
if (al.Count > 1)
MemberCache.VerifyClsParameterConflict (al, this, MethodBuilder);
}
"`{0}': Struct constructors cannot call base constructors", TypeManager.CSharpSignature (caller_builder));
return false;
}
- } else
+ } else {
+ //
+ // It is legal to have "this" initializers that take no arguments
+ // in structs, they are just no-ops.
+ //
+ // struct D { public D (int a) : this () {}
+ //
+ if (ec.ContainerType.IsValueType && argument_list == null)
+ return true;
+
t = ec.ContainerType;
+ }
base_constructor_group = Expression.MemberLookup (
ec.ContainerType, t, ".ctor", MemberTypes.Constructor,
}
if (error) {
+ Report.SymbolRelatedToPreviousError (base_constructor);
Expression.ErrorIsInaccesible (loc, TypeManager.CSharpSignature (base_constructor));
base_constructor = null;
return false;
}
-
+
if (base_constructor == caller_builder){
Report.Error (516, loc, "Constructor `{0}' cannot call itself", TypeManager.CSharpSignature (caller_builder));
return false;
}
}
- public class Constructor : MethodCore, IMethodData {
+ public class Constructor : MethodCore, IMethodData, IAnonymousHost {
public ConstructorBuilder ConstructorBuilder;
public ConstructorInitializer Initializer;
ListDictionary declarative_security;
+ ArrayList anonymous_methods;
// <summary>
// Modifiers allowed for a constructor.
static string[] attribute_targets = new string [] { "method" };
+ public Iterator Iterator {
+ get { return null; }
+ }
+
bool has_compliant_args = false;
//
// The spec claims that static is not permitted, but
//
public Constructor (DeclSpace parent, string name, int mod, Parameters args,
ConstructorInitializer init, Location loc)
- : base (parent, null, mod, AllowedModifiers, false, new MemberName (name, loc),
- null, args)
+ : base (parent, null, null, mod, AllowedModifiers, false,
+ new MemberName (name, loc), null, args)
{
Initializer = init;
}
ConstructorBuilder.SetCustomAttribute (cb);
}
-
+
+ public void AddAnonymousMethod (AnonymousMethodExpression anonymous)
+ {
+ if (anonymous_methods == null)
+ anonymous_methods = new ArrayList ();
+ anonymous_methods.Add (anonymous);
+ }
+
+ public bool ResolveMembers ()
+ {
+ if (anonymous_methods != null) {
+ foreach (AnonymousMethodExpression ame in anonymous_methods) {
+ if (!ame.CreateAnonymousHelpers ())
+ return false;
+ }
+ }
+
+ return true;
+ }
+
protected override bool CheckForDuplications ()
- {
- ArrayList ar = ParentContainer.InstanceConstructors;
+ {
+ ArrayList ar = Parent.PartialContainer.InstanceConstructors;
if (ar != null) {
int arLen = ar.Count;
if (!CheckForDuplications ())
return false;
- if (ParentContainer.Kind == Kind.Struct) {
+ if (Parent.PartialContainer.Kind == Kind.Struct) {
if (ParameterTypes.Length == 0) {
Report.Error (568, Location,
"Structs cannot contain explicit parameterless constructors");
if ((ModFlags & Modifiers.UNSAFE) != 0)
ConstructorBuilder.InitLocals = false;
- if (ParentContainer.IsComImport) {
+ if (Parent.PartialContainer.IsComImport) {
if (!IsDefault ()) {
Report.Error (669, Location, "`{0}': A class with the ComImport attribute cannot have a user-defined constructor",
Parent.GetSignatureForError ());
if (block != null) {
// If this is a non-static `struct' constructor and doesn't have any
// initializer, it must initialize all of the struct's fields.
- if ((ParentContainer.Kind == Kind.Struct) &&
+ if ((Parent.PartialContainer.Kind == Kind.Struct) &&
((ModFlags & Modifiers.STATIC) == 0) && (Initializer == null))
block.AddThisVariable (Parent, Location);
}
if ((ModFlags & Modifiers.STATIC) == 0){
- if (ParentContainer.Kind == Kind.Class && Initializer == null)
+ if (Parent.PartialContainer.Kind == Kind.Class && Initializer == null)
Initializer = new GeneratedBaseInitializer (Location);
//
// Classes can have base initializers and instance field initializers.
//
- if (ParentContainer.Kind == Kind.Class){
+ if (Parent.PartialContainer.Kind == Kind.Class){
if ((ModFlags & Modifiers.STATIC) == 0){
//
// do not emit field initializers, they are initialized in the other constructor
//
if (!(Initializer != null && Initializer is ConstructorThisInitializer))
- ParentContainer.EmitFieldInitializers (ec);
+ Parent.PartialContainer.EmitFieldInitializers (ec);
+ }
+ }
+
+ bool unreachable = false;
+ if (block != null) {
+ ec.ResolveTopBlock (null, block, ParameterInfo, this, out unreachable);
+ ec.EmitMeta (block);
+
+ if (block.ScopeInfo != null) {
+ ExpressionStatement init = block.ScopeInfo.GetScopeInitializer (ec);
+ init.EmitStatement (ec);
}
}
+
if (Initializer != null) {
Initializer.Emit (ec);
}
if ((ModFlags & Modifiers.STATIC) != 0)
- ParentContainer.EmitFieldInitializers (ec);
+ Parent.PartialContainer.EmitFieldInitializers (ec);
- ec.EmitTopBlock (this, block);
+ if (block != null)
+ ec.EmitResolvedTopBlock (block, unreachable);
if (source != null)
source.CloseMethod ();
get {
CallingConventions cc = Parameters.CallingConvention;
- if (ParentContainer.Kind == Kind.Class)
+ if (Parent.PartialContainer.Kind == Kind.Class)
if ((ModFlags & Modifiers.STATIC) == 0)
cc |= CallingConventions.HasThis;
return false;
}
- #endregion
+ GenericMethod IMethodData.GenericMethod {
+ get {
+ return null;
+ }
+ }
+
+ #endregion
}
/// <summary>
Location Location { get; }
MemberName MethodName { get; }
Type ReturnType { get; }
+ GenericMethod GenericMethod { get; }
Parameters ParameterInfo { get; }
+ Iterator Iterator { get; }
+
Attributes OptAttributes { get; }
ToplevelBlock Block { get; set; }
readonly IMethodData method;
+ public readonly GenericMethod GenericMethod;
+
//
// Are we implementing an interface ?
//
//
// Protected data.
//
- protected MemberBase member;
+ protected InterfaceMemberBase member;
protected int modifiers;
protected MethodAttributes flags;
+ protected Type declaring_type;
+ protected MethodInfo parent_method;
MethodBuilder builder = null;
public MethodBuilder MethodBuilder {
}
}
- public MethodData (MemberBase member,
+ public Type DeclaringType {
+ get {
+ return declaring_type;
+ }
+ }
+
+ public MethodData (InterfaceMemberBase member,
int modifiers, MethodAttributes flags, IMethodData method)
{
this.member = member;
this.method = method;
}
+ public MethodData (InterfaceMemberBase member,
+ int modifiers, MethodAttributes flags,
+ IMethodData method, MethodBuilder builder,
+ GenericMethod generic, MethodInfo parent_method)
+ : this (member, modifiers, flags, method)
+ {
+ this.builder = builder;
+ this.GenericMethod = generic;
+ this.parent_method = parent_method;
+ }
+
public bool Define (DeclSpace parent)
{
- string name = method.MethodName.Name;
- string method_name = name;
+ string name = method.MethodName.Basename;
+ string method_name = method.MethodName.FullName;
- TypeContainer container = ((TypeContainer) parent).PartialContainer;
+ TypeContainer container = parent.PartialContainer;
PendingImplementation pending = container.PendingImplementations;
if (pending != null){
member.GetSignatureForError (), TypeManager.CSharpSignature (implementing));
return false;
}
- method_name = member.InterfaceType.FullName + "." + name;
+
+ method_name = TypeManager.GetFullName (member.InterfaceType) +
+ '.' + method_name;
} else {
if (implementing != null) {
AbstractPropertyEventMethod prop_method = method as AbstractPropertyEventMethod;
- if (prop_method != null) {
+ if (prop_method == null) {
+ if (implementing.IsSpecialName) {
+ Report.SymbolRelatedToPreviousError (implementing);
+ Report.Error (470, method.Location, "Method `{0}' cannot implement interface accessor `{1}.{2}'",
+ method.GetSignatureForError (), TypeManager.CSharpSignature (implementing),
+ implementing.Name.StartsWith ("get_") ? "get" : "set");
+ return false;
+ }
+ } else if (implementing.DeclaringType.IsInterface) {
if (!implementing.IsSpecialName) {
Report.SymbolRelatedToPreviousError (implementing);
Report.Error (686, method.Location, "Accessor `{0}' cannot implement interface member `{1}' for type `{2}'. Use an explicit interface implementation",
// but it wont get cleared
//
if (member.IsExplicitImpl){
- if ((modifiers & (Modifiers.PUBLIC | Modifiers.ABSTRACT | Modifiers.VIRTUAL)) != 0){
- Modifiers.Error_InvalidModifier (method.Location, "public, virtual or abstract");
- implementing = null;
+ if (method.ParameterInfo.HasParams && !TypeManager.GetParameterData (implementing).HasParams) {
+ Report.SymbolRelatedToPreviousError (implementing);
+ Report.Error (466, method.Location, "`{0}': the explicit interface implementation cannot introduce the params modifier",
+ method.GetSignatureForError ());
+ return false;
}
- } else if ((flags & MethodAttributes.MemberAccessMask) != MethodAttributes.Public){
- if (TypeManager.IsInterfaceType (implementing.DeclaringType)){
+ } else {
+ if (implementing.DeclaringType.IsInterface) {
//
// If this is an interface method implementation,
// check for public accessibility
//
- implementing = null;
+ if ((flags & MethodAttributes.MemberAccessMask) != MethodAttributes.Public)
+ implementing = null;
} else if ((flags & MethodAttributes.MemberAccessMask) == MethodAttributes.Private){
// We may never be private.
implementing = null;
//
implementing = null;
}
- }
+ }
//
// Static is not allowed
flags |= MethodAttributes.Final;
}
+ EmitContext ec = method.CreateEmitContext (container, null);
+
DefineMethodBuilder (container, method_name, method.ParameterInfo.Types);
if (builder == null)
return false;
+ if (container.CurrentType != null)
+ declaring_type = container.CurrentType;
+ else
+ declaring_type = container.TypeBuilder;
+
if ((modifiers & Modifiers.UNSAFE) != 0)
builder.InitLocals = false;
TypeManager.AddMethod (builder, method);
+ if (GenericMethod != null) {
+ bool is_override = member.IsExplicitImpl |
+ ((modifiers & Modifiers.OVERRIDE) != 0);
+
+ if (implementing != null)
+ parent_method = implementing;
+
+ if (!GenericMethod.DefineType (ec, builder, parent_method, is_override))
+ return false;
+ }
+
return true;
}
/// </summary>
void DefineMethodBuilder (TypeContainer container, string method_name, Type[] ParameterTypes)
{
- const int extern_static = Modifiers.EXTERN | Modifiers.STATIC;
-
- if ((modifiers & extern_static) == extern_static) {
+ if ((modifiers & Modifiers.EXTERN) != 0) {
if (method.OptAttributes != null) {
Attribute dllimport_attribute = method.OptAttributes.Search (TypeManager.dllimport_type);
// We are more strict than Microsoft and report CS0626 like error
if (method.OptAttributes == null ||
!method.OptAttributes.Contains (TypeManager.methodimpl_attr_type)) {
- Report.Error (626, method.Location, "Method, operator, or accessor `{0}' is marked external and has no attributes on it. Consider adding a DllImport attribute to specify the external implementation",
- method.GetSignatureForError ());
+ Report.Error (626, method.Location,
+ "`{0}' is marked as an external but has no DllImport attribute. Consider adding a DllImport attribute to specify the external implementation",
+ member.GetSignatureForError ());
return;
}
}
- builder = container.TypeBuilder.DefineMethod (
- method_name, flags, method.CallingConventions,
+ if (builder == null) {
+ builder = container.TypeBuilder.DefineMethod (
+ method_name, flags, method.CallingConventions,
+ method.ReturnType, ParameterTypes);
+ return;
+ }
+
+#if GMCS_SOURCE && !MS_COMPATIBLE
+ builder.SetGenericMethodSignature (
+ flags, method.CallingConventions,
method.ReturnType, ParameterTypes);
+#endif
}
//
method.ParameterInfo.ApplyAttributes (MethodBuilder);
+ if (GenericMethod != null)
+ GenericMethod.EmitAttributes ();
+
ToplevelBlock block = method.Block;
SourceMethod source = SourceMethod.Create (parent, MethodBuilder, method.Block);
public Destructor (DeclSpace parent, Expression return_type, int mod,
string name, Parameters parameters, Attributes attrs,
Location l)
- : base (parent, return_type, mod, false, new MemberName (name, l),
+ : base (parent, null, return_type, mod, false, new MemberName (name, l),
parameters, attrs)
{ }
abstract public class MemberBase : MemberCore {
public Expression Type;
-
- public MethodAttributes flags;
-
- protected readonly int explicit_mod_flags;
-
- //
- // The "short" name of this property / indexer / event. This is the
- // name without the explicit interface.
- //
- public string ShortName {
- get { return MemberName.Name; }
- set { SetMemberName (new MemberName (MemberName.Left, value, Location)); }
- }
-
- public TypeContainer ParentContainer {
- get { return ((TypeContainer) Parent).PartialContainer; }
- }
+ public readonly DeclSpace ds;
+ public readonly GenericMethod GenericMethod;
//
// The type of this property / indexer / event
//
- Type member_type;
+ protected Type member_type;
public Type MemberType {
get {
if (member_type == null && Type != null) {
- Type = Type.ResolveAsTypeTerminal (ResolveContext, false);
+ IResolveContext rc = GenericMethod == null ? this : (IResolveContext)ds;
+ Type = Type.ResolveAsTypeTerminal (rc, false);
if (Type != null) {
member_type = Type.Type;
}
}
}
- //
- // Whether this is an interface member.
- //
- public bool IsInterface;
-
- //
- // If true, this is an explicit interface implementation
- //
- public bool IsExplicitImpl;
-
- //
- // The interface type we are explicitly implementing
- //
- public Type InterfaceType = null;
-
//
// The constructor is only exposed to our children
//
- protected MemberBase (DeclSpace parent, Expression type, int mod,
- int allowed_mod, int def_mod, MemberName name,
- Attributes attrs)
+ protected MemberBase (DeclSpace parent, GenericMethod generic,
+ Expression type, int mod, int allowed_mod, int def_mod,
+ MemberName name, Attributes attrs)
: base (parent, name, attrs)
{
- explicit_mod_flags = mod;
+ this.ds = generic != null ? generic : (DeclSpace) parent;
Type = type;
ModFlags = Modifiers.Check (allowed_mod, mod, def_mod, Location);
- IsExplicitImpl = (MemberName.Left != null);
+ GenericMethod = generic;
+ if (GenericMethod != null)
+ GenericMethod.ModFlags = ModFlags;
}
protected virtual bool CheckBase ()
{
- if ((ModFlags & Modifiers.PROTECTED) != 0 && ParentContainer.Kind == Kind.Struct) {
+ if ((ModFlags & Modifiers.PROTECTED) != 0 && Parent.PartialContainer.Kind == Kind.Struct) {
Report.Error (666, Location, "`{0}': new protected member declared in struct", GetSignatureForError ());
return false;
}
((ModFlags & Modifiers.OVERRIDE) == 0) && (Name != "Finalize")) {
Report.Warning (628, 4, Location, "`{0}': new protected member declared in sealed class", GetSignatureForError ());
}
- return true;
- }
+ return true;
+ }
protected virtual bool DoDefine ()
{
- if (Name == null)
- throw new InternalErrorException ();
-
- if (IsInterface) {
- ModFlags = Modifiers.PUBLIC |
- Modifiers.ABSTRACT |
- Modifiers.VIRTUAL | (ModFlags & Modifiers.UNSAFE) | (ModFlags & Modifiers.NEW);
-
- flags = MethodAttributes.Public |
- MethodAttributes.Abstract |
- MethodAttributes.HideBySig |
- MethodAttributes.NewSlot |
- MethodAttributes.Virtual;
- } else {
- if (!ParentContainer.MethodModifiersValid (this))
- return false;
-
- flags = Modifiers.MethodAttr (ModFlags);
- }
-
if (MemberType == null)
return false;
return false;
}
- if (IsExplicitImpl) {
- Expression expr = MemberName.Left.GetTypeExpression ();
- TypeExpr texpr = expr.ResolveAsTypeTerminal (ResolveContext, false);
- if (texpr == null)
- return false;
-
- InterfaceType = texpr.Type;
-
- if (!InterfaceType.IsInterface) {
- Report.Error (538, Location, "`{0}' in explicit interface declaration is not an interface", TypeManager.CSharpName (InterfaceType));
- return false;
- }
-
- if (!ParentContainer.VerifyImplements (this))
- return false;
-
- Modifiers.Check (Modifiers.AllowedExplicitImplFlags, explicit_mod_flags, 0, Location);
-
- }
return true;
}
}
return true;
}
-
- protected override bool VerifyClsCompliance()
- {
- if (base.VerifyClsCompliance ()) {
- return true;
- }
-
- if (IsInterface && HasClsCompliantAttribute && Parent.IsClsComplianceRequired ()) {
- Report.Error (3010, Location, "`{0}': CLS-compliant interfaces must have only CLS-compliant members", GetSignatureForError ());
- }
- return false;
- }
-
}
//
- // Fields and Events both generate FieldBuilders, we use this to share
- // their common bits. This is also used to flag usage of the field
+ // Abstract class for all fields
//
abstract public class FieldBase : MemberBase {
- public FieldBuilder FieldBuilder;
+ public FieldBuilder FieldBuilder;
public Status status;
protected Expression initializer;
- ExpressionStatement initializerStatement;
[Flags]
public enum Status : byte {
HAS_OFFSET = 4 // Used by FieldMember.
}
- static string[] attribute_targets = new string [] { "field" };
-
- /// <summary>
- /// Symbol with same name in base class/struct
- /// </summary>
- public MemberInfo conflict_symbol;
+ static readonly string[] attribute_targets = new string [] { "field" };
protected FieldBase (DeclSpace parent, Expression type, int mod,
int allowed_mod, MemberName name, Attributes attrs)
- : base (parent, type, mod, allowed_mod, Modifiers.PRIVATE,
+ : base (parent, null, type, mod, allowed_mod | Modifiers.ABSTRACT, Modifiers.PRIVATE,
name, attrs)
{
+ if ((mod & Modifiers.ABSTRACT) != 0)
+ Report.Error (681, Location, "The modifier 'abstract' is not valid on fields. Try using a property instead");
}
public override AttributeTargets AttributeTargets {
public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
{
+ if (a.Type == TypeManager.field_offset_attribute_type) {
+ status |= Status.HAS_OFFSET;
+
+ if (!Parent.PartialContainer.HasExplicitLayout) {
+ Report.Error (636, Location, "The FieldOffset attribute can only be placed on members of types marked with the StructLayout(LayoutKind.Explicit)");
+ return;
+ }
+
+ if ((ModFlags & Modifiers.STATIC) != 0 || this is Const) {
+ Report.Error (637, Location, "The FieldOffset attribute is not allowed on static or const fields");
+ return;
+ }
+ }
+
+#if NET_2_0
+ if (a.Type == TypeManager.fixed_buffer_attr_type) {
+ Report.Error (1716, Location, "Do not use 'System.Runtime.CompilerServices.FixedBuffer' attribute. Use the 'fixed' field modifier instead");
+ return;
+ }
+#endif
+
if (a.Type == TypeManager.marshal_as_attr_type) {
UnmanagedMarshal marshal = a.GetMarshal (this);
if (marshal != null) {
FieldBuilder.SetCustomAttribute (cb);
}
- public void EmitInitializer (EmitContext ec)
- {
- initializerStatement.EmitStatement (ec);
- }
-
protected override bool CheckBase ()
{
if (!base.CheckBase ())
return false;
- // TODO: Implement
- if (IsInterface)
- return true;
-
- conflict_symbol = ParentContainer.FindBaseMemberWithSameName (Name, false);
+ MemberInfo conflict_symbol = Parent.PartialContainer.FindBaseMemberWithSameName (Name, false);
if (conflict_symbol == null) {
- if ((RootContext.WarningLevel >= 4) && ((ModFlags & Modifiers.NEW) != 0)) {
+ if ((ModFlags & Modifiers.NEW) != 0) {
Report.Warning (109, 4, Location, "The member `{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError ());
}
return true;
return true;
}
- public Expression Initializer {
- set {
- if (value != null) {
- this.initializer = value;
- ParentContainer.RegisterFieldForInitialization (this);
- }
+ public override bool Define()
+ {
+ if (MemberType == null || Type == null)
+ return false;
+
+ if (MemberType == TypeManager.void_type) {
+ // TODO: wrong location
+ Expression.Error_VoidInvalidInTheContext (Location);
+ return false;
}
- }
- protected virtual bool IsFieldClsCompliant {
- get {
- if (FieldBuilder == null)
- return true;
+ if (MemberType.IsSealed && MemberType.IsAbstract) {
+ Error_VariableOfStaticClass (Location, GetSignatureForError (), MemberType);
+ return false;
+ }
- return AttributeTester.IsClsCompliant (FieldBuilder.FieldType);
+ if (!CheckBase ())
+ return false;
+
+ if (!Parent.AsAccessible (MemberType, ModFlags)) {
+ Report.Error (52, Location,
+ "Inconsistent accessibility: field type `" +
+ TypeManager.CSharpName (MemberType) + "' is less " +
+ "accessible than field `" + GetSignatureForError () + "'");
+ return false;
}
+
+ if (!IsTypePermitted ())
+ return false;
+
+ return true;
+ }
+
+ //
+ // Represents header string for documentation comment.
+ //
+ public override string DocCommentHeader {
+ get { return "F:"; }
}
- public Expression ResolveInitializer ()
+ public override void Emit ()
{
- // TODO: again it's too heavy-weight
- EmitContext ec = new EmitContext (this, Parent, Location, null, null, ModFlags);
- ec.IsFieldInitializer = true;
- initializer = initializer.Resolve (ec);
- if (initializer == null)
- return null;
+ if (OptAttributes != null) {
+ OptAttributes.Emit ();
+ }
- FieldExpr fe = new FieldExpr (FieldBuilder, Location, true);
- if ((ModFlags & Modifiers.STATIC) == 0)
- {
- fe.InstanceExpression = CompilerGeneratedThis.Instance;
+ if (((status & Status.HAS_OFFSET) == 0) && (ModFlags & Modifiers.STATIC) == 0 && Parent.PartialContainer.HasExplicitLayout) {
+ Report.Error (625, Location, "`{0}': Instance field types marked with StructLayout(LayoutKind.Explicit) must have a FieldOffset attribute.", GetSignatureForError ());
}
- initializerStatement = new Assign (fe, initializer, Location).ResolveStatement (ec);
- return initializer;
+ base.Emit ();
}
- public bool HasDefaultInitializer
+ public static void Error_VariableOfStaticClass (Location loc, string variableName, Type staticClass)
{
- get
- {
- Constant c = initializer as Constant;
- if (c == null)
- return false;
+ Report.SymbolRelatedToPreviousError (staticClass);
+ Report.Error (723, loc, "`{0}': cannot declare variables of static types",
+ variableName);
+ }
+
+ public Expression Initializer {
+ set {
+ if (value != null) {
+ this.initializer = value;
+ }
+ }
+ }
- return c.IsDefaultInitializer (MemberType);
+ protected virtual bool IsFieldClsCompliant {
+ get {
+ if (FieldBuilder == null)
+ return true;
+
+ return AttributeTester.IsClsCompliant (FieldBuilder.FieldType);
}
}
return true;
}
-
public void SetAssigned ()
{
caching_flags |= Flags.IsAssigned;
}
}
- public abstract class FieldMember : FieldBase
+ interface IFixedBuffer
{
- protected FieldMember (DeclSpace parent, Expression type, int mod,
- int allowed_mod, MemberName name, Attributes attrs)
- : base (parent, type, mod, allowed_mod | Modifiers.ABSTRACT, name, attrs)
- {
- if ((mod & Modifiers.ABSTRACT) != 0)
- Report.Error (681, Location, "The modifier 'abstract' is not valid on fields. Try using a property instead");
- }
+ FieldInfo Element { get; }
+ Type ElementType { get; }
+ }
- public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
+ public class FixedFieldExternal: IFixedBuffer
+ {
+ FieldInfo element_field;
+
+ public FixedFieldExternal (FieldInfo fi)
{
- if (a.Type == TypeManager.field_offset_attribute_type)
- {
- status |= Status.HAS_OFFSET;
+ element_field = fi.FieldType.GetField (FixedField.FixedElementName);
+ }
- if (!ParentContainer.HasExplicitLayout) {
- Report.Error (636, Location, "The FieldOffset attribute can only be placed on members of types marked with the StructLayout(LayoutKind.Explicit)");
- return;
- }
+ #region IFixedField Members
- if ((ModFlags & Modifiers.STATIC) != 0 || this is Const) {
- Report.Error (637, Location, "The FieldOffset attribute is not allowed on static or const fields");
- return;
- }
+ public FieldInfo Element {
+ get {
+ return element_field;
}
+ }
-#if NET_2_0
- if (a.Type == TypeManager.fixed_buffer_attr_type) {
- Report.Error (1716, Location, "Do not use 'System.Runtime.CompilerServices.FixedBuffer' attribute. Use the 'fixed' field modifier instead");
- return;
- }
-#endif
-
- base.ApplyAttributeBuilder (a, cb);
- }
-
- public override bool Define()
- {
- if (MemberType == null || Type == null)
- return false;
-
- if (MemberType == TypeManager.void_type) {
- Report.Error (1547, Location, "Keyword 'void' cannot be used in this context");
- return false;
- }
-
- if (!CheckBase ())
- return false;
-
- if (!Parent.AsAccessible (MemberType, ModFlags)) {
- Report.Error (52, Location,
- "Inconsistent accessibility: field type `" +
- TypeManager.CSharpName (MemberType) + "' is less " +
- "accessible than field `" + GetSignatureForError () + "'");
- return false;
- }
-
- if (!IsTypePermitted ())
- return false;
-
- return true;
- }
-
- public override void Emit ()
- {
- if (OptAttributes != null) {
- OptAttributes.Emit ();
- }
-
- if (((status & Status.HAS_OFFSET) == 0) && (ModFlags & Modifiers.STATIC) == 0 && ParentContainer.HasExplicitLayout) {
- Report.Error (625, Location, "`{0}': Instance field types marked with StructLayout(LayoutKind.Explicit) must have a FieldOffset attribute.", GetSignatureForError ());
- }
-
- base.Emit ();
- }
-
- //
- // Represents header string for documentation comment.
- //
- public override string DocCommentHeader {
- get { return "F:"; }
- }
- }
-
- interface IFixedBuffer
- {
- FieldInfo Element { get; }
- Type ElementType { get; }
- }
-
- public class FixedFieldExternal: IFixedBuffer
- {
- FieldInfo element_field;
-
- public FixedFieldExternal (FieldInfo fi)
- {
- element_field = fi.FieldType.GetField (FixedField.FixedElementName);
- }
-
- #region IFixedField Members
-
- public FieldInfo Element {
- get {
- return element_field;
- }
- }
-
- public Type ElementType {
- get {
- return element_field.FieldType;
+ public Type ElementType {
+ get {
+ return element_field.FieldType;
}
}
/// <summary>
/// Fixed buffer implementation
/// </summary>
- public class FixedField : FieldMember, IFixedBuffer
+ public class FixedField : FieldBase, IFixedBuffer
{
public const string FixedElementName = "FixedElementField";
static int GlobalCounter = 0;
base (parent, type, mod, AllowedModifiers, new MemberName (name, loc), attrs)
{
if (RootContext.Version == LanguageVersion.ISO_1)
- Report.FeatureIsNotStandardized (loc, "fixed size buffers");
+ Report.FeatureIsNotISO1 (loc, "fixed size buffers");
this.size_expr = size_expr;
}
Report.Warning (-23, 1, Location, "Only private or internal fixed sized buffers are supported by .NET 1.x");
#endif
- if (ParentContainer.Kind != Kind.Struct) {
+ if (Parent.PartialContainer.Kind != Kind.Struct) {
Report.Error (1642, Location, "`{0}': Fixed size buffer fields may only be members of structs",
GetSignatureForError ());
return false;
if (c == null)
return false;
- IntConstant buffer_size_const = c.ToInt (Location);
+ IntConstant buffer_size_const = c.ImplicitConversionRequired (TypeManager.int32_type, Location) as IntConstant;
if (buffer_size_const == null)
return false;
//
// The Field class is used to represents class/struct fields during parsing.
//
- public class Field : FieldMember {
+ public class Field : FieldBase {
// <summary>
// Modifiers allowed in a class declaration
// </summary>
FieldAttributes fa = Modifiers.FieldAttr (ModFlags);
- if (ParentContainer.Kind == Kind.Struct &&
+ if (Parent.PartialContainer.Kind == Kind.Struct &&
((fa & FieldAttributes.Static) == 0) &&
MemberType == Parent.TypeBuilder &&
!TypeManager.IsBuiltinType (MemberType)){
return false;
}
+ if (initializer != null)
+ Parent.PartialContainer.RegisterFieldForInitialization (this,
+ new FieldInitializer (FieldBuilder, initializer));
+
return true;
}
//
// `set' and `get' accessors are represented with an Accessor.
//
- public class Accessor : IIteratorContainer {
+ public class Accessor : IAnonymousHost {
//
// Null if the accessor is empty, or a Block if not
//
public Location Location;
public int ModFlags;
public bool Yields;
+ public ArrayList AnonymousMethods;
public Accessor (ToplevelBlock b, int mod, Attributes attrs, Location loc)
{
{
Yields = true;
}
+
+ public void AddAnonymousMethod (AnonymousMethodExpression ame)
+ {
+ if (AnonymousMethods == null)
+ AnonymousMethods = new ArrayList ();
+ AnonymousMethods.Add (ame);
+ }
}
// Ooouh Martin, templates are missing here.
ReturnParameter return_attributes;
- public AbstractPropertyEventMethod (MemberBase member, string prefix)
+ public AbstractPropertyEventMethod (PropertyBasedMember member, string prefix)
: base (member.Parent, SetupName (prefix, member, member.Location), null)
{
this.prefix = prefix;
IsDummy = true;
}
- public AbstractPropertyEventMethod (MemberBase member, Accessor accessor,
+ public AbstractPropertyEventMethod (InterfaceMemberBase member, Accessor accessor,
string prefix)
: base (member.Parent, SetupName (prefix, member, accessor.Location),
accessor.Attributes)
this.block = accessor.Block;
}
- static MemberName SetupName (string prefix, MemberBase member, Location loc)
+ static MemberName SetupName (string prefix, InterfaceMemberBase member, Location loc)
{
return new MemberName (member.MemberName.Left, prefix + member.ShortName, loc);
}
- public void UpdateName (MemberBase member)
+ public void UpdateName (InterfaceMemberBase member)
{
SetMemberName (SetupName (prefix, member, Location));
}
#region IMethodData Members
+ public abstract Iterator Iterator {
+ get;
+ }
+
public ToplevelBlock Block {
get {
return block;
return false;
}
+ GenericMethod IMethodData.GenericMethod {
+ get {
+ return null;
+ }
+ }
+
public MemberName MethodName {
get {
return MemberName;
System.Diagnostics.Debug.Fail ("You forgot to define special attribute target handling");
}
- public override bool Define()
+ // It is not supported for the accessors
+ public sealed override bool Define()
{
throw new NotSupportedException ();
}
// Properties and Indexers both generate PropertyBuilders, we use this to share
// their common bits.
//
- abstract public class PropertyBase : MethodCore {
+ abstract public class PropertyBase : PropertyBasedMember {
public class GetMethod : PropertyMethod
{
static string[] attribute_targets = new string [] { "method", "return" };
- public GetMethod (MethodCore method):
+ public GetMethod (PropertyBase method):
base (method, "get_")
{
}
- public GetMethod (MethodCore method, Accessor accessor):
+ public GetMethod (PropertyBase method, Accessor accessor):
base (method, accessor, "get_")
{
}
ImplicitParameter param_attr;
protected Parameters parameters;
- public SetMethod (MethodCore method):
+ public SetMethod (PropertyBase method):
base (method, "set_")
{
}
- public SetMethod (MethodCore method, Accessor accessor):
+ public SetMethod (PropertyBase method, Accessor accessor):
base (method, accessor, "set_")
{
}
public override Parameters ParameterInfo {
get {
+ if (parameters == null)
+ DefineParameters ();
return parameters;
}
}
public override MethodBuilder Define (DeclSpace parent)
{
- DefineParameters ();
if (IsDummy)
return null;
public abstract class PropertyMethod : AbstractPropertyEventMethod
{
- protected readonly MethodCore method;
+ protected readonly PropertyBase method;
protected MethodAttributes flags;
+ Iterator iterator;
+ ArrayList anonymous_methods;
bool yields;
- public PropertyMethod (MethodCore method, string prefix)
+ public PropertyMethod (PropertyBase method, string prefix)
: base (method, prefix)
{
this.method = method;
}
- public PropertyMethod (MethodCore method, Accessor accessor,
+ public PropertyMethod (PropertyBase method, Accessor accessor,
string prefix)
: base (method, accessor, prefix)
{
this.method = method;
this.ModFlags = accessor.ModFlags;
yields = accessor.Yields;
+ anonymous_methods = accessor.AnonymousMethods;
if (accessor.ModFlags != 0 && RootContext.Version == LanguageVersion.ISO_1) {
- Report.FeatureIsNotStandardized (Location, "access modifiers on properties");
+ Report.FeatureIsNotISO1 (Location, "access modifiers on properties");
}
}
+ public override Iterator Iterator {
+ get { return iterator; }
+ }
+
public override AttributeTargets AttributeTargets {
get {
return AttributeTargets.Method;
}
}
- public override bool IsClsComplianceRequired()
+ public override bool IsClsComplianceRequired ()
{
return method.IsClsComplianceRequired ();
}
+ public bool ResolveMembers ()
+ {
+ if (yields) {
+ iterator = Iterator.CreateIterator (this, Parent, null, ModFlags);
+ if (iterator == null)
+ return false;
+ }
+
+ if (anonymous_methods != null) {
+ foreach (AnonymousMethodExpression ame in anonymous_methods) {
+ if (!ame.CreateAnonymousHelpers ())
+ return false;
+ }
+ }
+
+ return true;
+ }
+
public virtual MethodBuilder Define (DeclSpace parent)
{
if (!method.CheckAbstractAndExtern (block != null))
return null;
- TypeContainer container = ((TypeContainer) parent).PartialContainer;
+ TypeContainer container = parent.PartialContainer;
//
// Check for custom access modifier
flags |= (method.flags & (~MethodAttributes.MemberAccessMask));
}
- //
- // Setup iterator if we are one
- //
- if (yields) {
- Iterator iterator = new Iterator (this, Parent as TypeContainer, ModFlags);
-
- if (!iterator.DefineIterator ())
- return null;
- }
-
return null;
}
public override EmitContext CreateEmitContext (DeclSpace ds, ILGenerator ig)
{
return new EmitContext (method,
- ds, method.Parent, method.Location, ig, ReturnType,
+ ds, method.ds, method.Location, ig, ReturnType,
method.ModFlags, false);
}
public PropertyBuilder PropertyBuilder;
public MethodBuilder GetBuilder, SetBuilder;
- protected EmitContext ec;
+ protected bool define_set_first = false;
public PropertyBase (DeclSpace parent, Expression type, int mod_flags,
int allowed_mod, bool is_iface, MemberName name,
- Parameters parameters, Attributes attrs)
- : base (parent, type, mod_flags, allowed_mod, is_iface, name,
- attrs, parameters)
+ Attributes attrs, bool define_set_first)
+ : base (parent, null, type, mod_flags, allowed_mod, is_iface, name, attrs)
{
+ this.define_set_first = define_set_first;
}
public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
return true;
}
- protected override bool CheckForDuplications ()
+ bool DefineGet ()
{
- ArrayList ar = ParentContainer.Indexers;
- if (ar != null) {
- int arLen = ar.Count;
-
- for (int i = 0; i < arLen; i++) {
- Indexer m = (Indexer) ar [i];
- if (IsDuplicateImplementation (m))
- return false;
- }
- }
+ if (Get.IsDummy)
+ return true;
- ar = ParentContainer.Properties;
- if (ar != null) {
- int arLen = ar.Count;
-
- for (int i = 0; i < arLen; i++) {
- Property m = (Property) ar [i];
- if (IsDuplicateImplementation (m))
- return false;
- }
- }
+ GetBuilder = Get.Define (Parent);
+ return GetBuilder != null;
+ }
- return true;
+ bool DefineSet (bool define)
+ {
+ if (!define || Set.IsDummy)
+ return true;
+
+ SetBuilder = Set.Define (Parent);
+ return SetBuilder != null;
}
+ protected bool DefineAccessors ()
+ {
+ return DefineSet (define_set_first) &&
+ DefineGet () &&
+ DefineSet (!define_set_first);
+ }
+
+ protected abstract PropertyInfo ResolveBaseProperty ();
+
// TODO: rename to Resolve......
protected override MethodInfo FindOutBaseMethod (ref Type base_ret_type)
{
- PropertyInfo base_property = ParentContainer.BaseCache.FindMemberToOverride (
- Parent.TypeBuilder, Name, ParameterTypes, true) as PropertyInfo;
-
+ PropertyInfo base_property = ResolveBaseProperty ();
if (base_property == null)
return null;
public Property (DeclSpace parent, Expression type, int mod, bool is_iface,
MemberName name, Attributes attrs, Accessor get_block,
- Accessor set_block)
+ Accessor set_block, bool define_set_first)
: base (parent, type, mod,
is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
- is_iface, name, Parameters.EmptyReadOnlyParameters, attrs)
+ is_iface, name, attrs, define_set_first)
{
if (get_block == null)
Get = new GetMethod (this);
public override bool Define ()
{
+ if (!DoDefineBase ())
+ return false;
+
if (!base.Define ())
return false;
flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
- if (!Get.IsDummy) {
- GetBuilder = Get.Define (Parent);
- if (GetBuilder == null)
- return false;
- }
-
- SetBuilder = Set.Define (Parent);
- if (!Set.IsDummy) {
- if (SetBuilder == null)
- return false;
- }
+ if (!DefineAccessors ())
+ return false;
// FIXME - PropertyAttributes.HasDefault ?
PropertyBuilder = Parent.TypeBuilder.DefineProperty (
- Name, PropertyAttributes.None, MemberType, null);
-
+ MemberName.ToString (), PropertyAttributes.None, MemberType, null);
+
if (!Get.IsDummy)
PropertyBuilder.SetGetMethod (GetBuilder);
TypeManager.RegisterProperty (PropertyBuilder, this);
return true;
}
+
+ protected override PropertyInfo ResolveBaseProperty ()
+ {
+ return Parent.PartialContainer.BaseCache.FindMemberToOverride (
+ Parent.TypeBuilder, Name, Parameters.EmptyReadOnlyParameters.Types, null, true) as PropertyInfo;
+ }
}
/// </summary>
public void SetUsed ()
{
if (my_event != null) {
- my_event.SetAssigned ();
+// my_event.SetAssigned ();
my_event.SetMemberIsUsed ();
}
}
/// For case when event is declared like property (with add and remove accessors).
/// </summary>
public class EventProperty: Event {
+ abstract class AEventPropertyAccessor : AEventAccessor
+ {
+ public AEventPropertyAccessor (Event method, Accessor accessor, string prefix):
+ base (method, accessor, prefix)
+ {
+ }
+
+ public override MethodBuilder Define (DeclSpace ds)
+ {
+ method.CheckAbstractAndExtern (block != null);
+ return base.Define (ds);
+ }
+ }
+
+ sealed class AddDelegateMethod: AEventPropertyAccessor
+ {
+ public AddDelegateMethod (Event method, Accessor accessor):
+ base (method, accessor, "add_")
+ {
+ }
+
+ protected override MethodInfo DelegateMethodInfo {
+ get {
+ return TypeManager.delegate_combine_delegate_delegate;
+ }
+ }
+ }
+
+ sealed class RemoveDelegateMethod: AEventPropertyAccessor
+ {
+ public RemoveDelegateMethod (Event method, Accessor accessor):
+ base (method, accessor, "remove_")
+ {
+ }
+
+ protected override MethodInfo DelegateMethodInfo {
+ get {
+ return TypeManager.delegate_remove_delegate_delegate;
+ }
+ }
+ }
- static string[] attribute_targets = new string [] { "event" }; // "property" target was disabled for 2.0 version
+
+ static readonly string[] attribute_targets = new string [] { "event" }; // "property" target was disabled for 2.0 version
public EventProperty (DeclSpace parent, Expression type, int mod_flags,
bool is_iface, MemberName name,
{
Add = new AddDelegateMethod (this, add);
Remove = new RemoveDelegateMethod (this, remove);
+ }
+
+ public override bool Define()
+ {
+ if (!base.Define ())
+ return false;
- // For this event syntax we don't report error CS0067
- // because it is hard to do it.
- SetAssigned ();
+ if (IsExplicitImpl)
+ SetMemberIsUsed ();
+
+ return true;
}
public override string[] ValidAttributeTargets {
/// Event is declared like field.
/// </summary>
public class EventField : Event {
+ abstract class EventFieldAccessor : AEventAccessor
+ {
+ protected EventFieldAccessor (Event method, string prefix)
+ : base (method, prefix)
+ {
+ }
- static string[] attribute_targets = new string [] { "event", "field", "method" };
- static string[] attribute_targets_interface = new string[] { "event", "method" };
+ protected override void EmitMethod(DeclSpace parent)
+ {
+ if ((method.ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) != 0)
+ return;
+
+ ILGenerator ig = method_data.MethodBuilder.GetILGenerator ();
+
+ // TODO: because we cannot use generics yet
+ FieldInfo field_info = ((EventField)method).FieldBuilder;
+
+ method_data.MethodBuilder.SetImplementationFlags (MethodImplAttributes.Synchronized);
+ 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);
+ }
+ }
+
+ sealed class AddDelegateMethod: EventFieldAccessor
+ {
+ public AddDelegateMethod (Event method):
+ base (method, "add_")
+ {
+ }
+
+ protected override MethodInfo DelegateMethodInfo {
+ get {
+ return TypeManager.delegate_combine_delegate_delegate;
+ }
+ }
+ }
+
+ sealed class RemoveDelegateMethod: EventFieldAccessor
+ {
+ public RemoveDelegateMethod (Event method):
+ base (method, "remove_")
+ {
+ }
+
+ protected override MethodInfo DelegateMethodInfo {
+ get {
+ return TypeManager.delegate_remove_delegate_delegate;
+ }
+ }
+ }
+
+
+ static readonly string[] attribute_targets = new string [] { "event", "field", "method" };
+ static readonly string[] attribute_targets_interface = new string[] { "event", "method" };
+
+ public FieldBuilder FieldBuilder;
+ public Expression Initializer;
public EventField (DeclSpace parent, Expression type, int mod_flags,
bool is_iface, MemberName name,
}
if (a.Target == AttributeTargets.Method) {
+ int errors = Report.Errors;
Add.ApplyAttributeBuilder (a, cb);
- Remove.ApplyAttributeBuilder (a, cb);
+ if (errors == Report.Errors)
+ Remove.ApplyAttributeBuilder (a, cb);
return;
}
if (!base.Define ())
return false;
- if (initializer != null) {
+ if (IsInterface)
+ return true;
+
+ // FIXME: We are unable to detect whether generic event is used because
+ // we are using FieldExpr instead of EventExpr for event access in that
+ // case. When this issue will be fixed this hack can be removed.
+ if (TypeManager.IsGenericType (MemberType))
+ SetMemberIsUsed();
+
+ FieldBuilder = Parent.TypeBuilder.DefineField (
+ Name, MemberType,
+ FieldAttributes.Private | ((ModFlags & Modifiers.STATIC) != 0 ? FieldAttributes.Static : 0));
+ TypeManager.RegisterEventField (EventBuilder, this);
+
+ if (Initializer != null) {
if (((ModFlags & Modifiers.ABSTRACT) != 0)) {
Report.Error (74, Location, "`{0}': abstract event cannot have an initializer",
GetSignatureForError ());
return false;
}
+
+ Parent.PartialContainer.RegisterFieldForInitialization (this,
+ new FieldInitializer (FieldBuilder, Initializer));
}
return true;
}
- public override string[] ValidAttributeTargets {
+ public override string[] ValidAttributeTargets
+ {
get {
return IsInterface ? attribute_targets_interface : attribute_targets;
}
}
}
- public abstract class Event : FieldBase {
-
- protected sealed class AddDelegateMethod: DelegateMethod
- {
-
- public AddDelegateMethod (Event method):
- base (method, "add_")
- {
- }
-
- public AddDelegateMethod (Event method, Accessor accessor):
- base (method, accessor, "add_")
- {
- }
-
- protected override MethodInfo DelegateMethodInfo {
- get {
- return TypeManager.delegate_combine_delegate_delegate;
- }
- }
-
- }
-
- protected sealed class RemoveDelegateMethod: DelegateMethod
- {
- public RemoveDelegateMethod (Event method):
- base (method, "remove_")
- {
- }
-
- public RemoveDelegateMethod (Event method, Accessor accessor):
- base (method, accessor, "remove_")
- {
- }
-
- protected override MethodInfo DelegateMethodInfo {
- get {
- return TypeManager.delegate_remove_delegate_delegate;
- }
- }
-
- }
-
- public abstract class DelegateMethod : AbstractPropertyEventMethod
+ public abstract class Event : PropertyBasedMember {
+ public abstract class AEventAccessor : AbstractPropertyEventMethod
{
protected readonly Event method;
ImplicitParameter param_attr;
- static string[] attribute_targets = new string [] { "method", "param", "return" };
+ static readonly string[] attribute_targets = new string [] { "method", "param", "return" };
- public DelegateMethod (Event method, string prefix)
+ protected AEventAccessor (Event method, string prefix)
: base (method, prefix)
{
this.method = method;
}
- public DelegateMethod (Event method, Accessor accessor, string prefix)
+ protected AEventAccessor (Event method, Accessor accessor, string prefix)
: base (method, accessor, prefix)
{
this.method = method;
}
+ public override Iterator Iterator {
+ get { return null; }
+ }
+
protected override void ApplyToExtraTarget(Attribute a, CustomAttributeBuilder cb)
{
if (a.Target == AttributeTargets.Parameter) {
return method.IsClsComplianceRequired ();
}
- public MethodBuilder Define (DeclSpace parent)
+ public virtual MethodBuilder Define (DeclSpace parent)
{
method_data = new MethodData (method, method.ModFlags,
method.flags | MethodAttributes.HideBySig | MethodAttributes.SpecialName, this);
return mb;
}
-
- protected override void EmitMethod (DeclSpace parent)
- {
- if (block != null) {
- base.EmitMethod (parent);
- return;
- }
-
- if ((method.ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) != 0)
- return;
-
- ILGenerator ig = method_data.MethodBuilder.GetILGenerator ();
- FieldInfo field_info = (FieldInfo)method.FieldBuilder;
-
- method_data.MethodBuilder.SetImplementationFlags (MethodImplAttributes.Synchronized);
- 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);
- }
-
protected abstract MethodInfo DelegateMethodInfo { get; }
public override Type ReturnType {
public override EmitContext CreateEmitContext (DeclSpace ds, ILGenerator ig)
{
- return new EmitContext (method,
+ return new EmitContext (
ds, method.Parent, Location, ig, ReturnType,
method.ModFlags, false);
}
return method.parameters;
}
}
-
}
Modifiers.SEALED |
Modifiers.OVERRIDE |
Modifiers.UNSAFE |
- Modifiers.ABSTRACT;
+ Modifiers.ABSTRACT |
+ Modifiers.EXTERN;
const int AllowedInterfaceModifiers =
Modifiers.NEW;
- public DelegateMethod Add, Remove;
+ public AEventAccessor Add, Remove;
public MyEventBuilder EventBuilder;
public MethodBuilder AddBuilder, RemoveBuilder;
+
Parameters parameters;
protected Event (DeclSpace parent, Expression type, int mod_flags,
bool is_iface, MemberName name, Attributes attrs)
- : base (parent, type, mod_flags,
- is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
+ : base (parent, null, type, mod_flags,
+ is_iface ? AllowedInterfaceModifiers : AllowedModifiers, is_iface,
name, attrs)
{
- IsInterface = is_iface;
}
public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
public override bool Define ()
{
- EventAttributes e_attr;
- e_attr = EventAttributes.None;
+ if (!DoDefineBase ())
+ return false;
if (!DoDefine ())
return false;
if (RemoveBuilder == null)
return false;
- EventBuilder = new MyEventBuilder (this, Parent.TypeBuilder, Name, e_attr, MemberType);
-
- if (Add.Block == null && Remove.Block == null && !IsInterface) {
- FieldBuilder = Parent.TypeBuilder.DefineField (
- Name, MemberType,
- FieldAttributes.Private | ((ModFlags & Modifiers.STATIC) != 0 ? FieldAttributes.Static : 0));
- TypeManager.RegisterPrivateFieldOfEvent (
- (EventInfo) EventBuilder, FieldBuilder);
- TypeManager.RegisterFieldBase (FieldBuilder, this);
- }
-
+ EventBuilder = new MyEventBuilder (this, Parent.TypeBuilder, Name, EventAttributes.None, MemberType);
EventBuilder.SetAddOnMethod (AddBuilder);
EventBuilder.SetRemoveOnMethod (RemoveBuilder);
-
- TypeManager.RegisterEvent (EventBuilder, AddBuilder, RemoveBuilder);
return true;
}
- protected override bool CheckBase ()
- {
- if (!base.CheckBase ())
- return false;
-
- if (conflict_symbol != null && (ModFlags & Modifiers.NEW) == 0) {
- if (!(conflict_symbol is EventInfo)) {
- Report.SymbolRelatedToPreviousError (conflict_symbol);
- Report.Error (72, Location, "Event `{0}' can override only event", GetSignatureForError ());
- return false;
- }
- }
-
- return true;
- }
-
public override void Emit ()
{
if (OptAttributes != null) {
base.Emit ();
}
- public override string GetSignatureForError ()
+ protected override MethodInfo FindOutBaseMethod (ref Type base_ret_type)
{
- return base.GetSignatureForError ();
+ MethodInfo mi = (MethodInfo) Parent.PartialContainer.BaseCache.FindBaseEvent (
+ Parent.TypeBuilder, Name);
+
+ if (mi == null)
+ return null;
+
+ ParameterData pd = TypeManager.GetParameterData (mi);
+ base_ret_type = pd.ParameterType (0);
+ return mi;
}
//
}
}
-
+
public class Indexer : PropertyBase {
class GetIndexerMethod : GetMethod
{
- public GetIndexerMethod (MethodCore method):
+ public GetIndexerMethod (PropertyBase method):
base (method)
{
}
- public GetIndexerMethod (MethodCore method, Accessor accessor):
+ public GetIndexerMethod (PropertyBase method, Accessor accessor):
base (method, accessor)
{
}
public override Parameters ParameterInfo {
get {
- return method.ParameterInfo;
+ return ((Indexer)method).parameters;
}
}
}
class SetIndexerMethod: SetMethod
{
- public SetIndexerMethod (MethodCore method):
+ public SetIndexerMethod (PropertyBase method):
base (method)
{
}
- public SetIndexerMethod (MethodCore method, Accessor accessor):
+ public SetIndexerMethod (PropertyBase method, Accessor accessor):
base (method, accessor)
{
}
protected override void DefineParameters ()
{
- parameters = Parameters.MergeGenerated (method.Parameters,
+ parameters = Parameters.MergeGenerated (((Indexer)method).parameters,
new Parameter (method.MemberType, "value", Parameter.Modifier.NONE, null, method.Location));
}
}
const int AllowedInterfaceModifiers =
Modifiers.NEW;
+ public readonly Parameters parameters;
public Indexer (DeclSpace parent, Expression type, MemberName name, int mod,
bool is_iface, Parameters parameters, Attributes attrs,
- Accessor get_block, Accessor set_block)
+ Accessor get_block, Accessor set_block, bool define_set_first)
: base (parent, type, mod,
is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
- is_iface, name, parameters, attrs)
+ is_iface, name, attrs, define_set_first)
{
+ this.parameters = parameters;
+
if (get_block == null)
Get = new GetIndexerMethod (this);
else
else
Set = new SetIndexerMethod (this, set_block);
}
-
+
+ protected override bool CheckForDuplications ()
+ {
+ ArrayList ar = Parent.PartialContainer.Indexers;
+ if (ar != null) {
+ int arLen = ar.Count;
+
+ for (int i = 0; i < arLen; i++) {
+ Indexer m = (Indexer) ar [i];
+ if (IsDuplicateImplementation (m))
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ bool IsDuplicateImplementation (Indexer indexer)
+ {
+ if (this == indexer)
+ return false;
+
+ if (!MemberName.Equals (indexer.MemberName))
+ return false;
+
+ Type[] param_types = indexer.parameters.Types;
+
+ // When it is not yet defined
+ if (param_types == null)
+ return false;
+
+ if (param_types.Length != parameters.Count)
+ return false;
+
+ for (int i = 0; i < param_types.Length; i++)
+ if (param_types [i] != parameters.Types [i])
+ return false;
+
+ Report.SymbolRelatedToPreviousError (indexer);
+ Report.Error (111, Location, TypeContainer.Error111, indexer.GetSignatureForError ());
+ return true;
+ }
+
+
public override bool Define ()
{
+ if (!DoDefineBase ())
+ return false;
+
if (!base.Define ())
return false;
+ if (!parameters.Resolve (ds))
+ return false;
+
+ if (!CheckParameters (parameters))
+ return false;
+
if (MemberType == TypeManager.void_type) {
Report.Error (620, Location, "Indexers cannot have void type");
return false;
ShortName = base_IndexerName;
}
- if (!ParentContainer.AddToMemberContainer (this) ||
- !ParentContainer.AddToMemberContainer (Get) || !ParentContainer.AddToMemberContainer (Set))
+ if (!Parent.PartialContainer.AddMember (this) ||
+ !Parent.PartialContainer.AddMember (Get) || !Parent.PartialContainer.AddMember (Set))
return false;
if (!CheckBase ())
return false;
flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
- if (!Get.IsDummy){
- GetBuilder = Get.Define (Parent);
- if (GetBuilder == null)
- return false;
- }
- SetBuilder = Set.Define (Parent);
- if (!Set.IsDummy){
- if (SetBuilder == null)
- return false;
+ if (!DefineAccessors ())
+ return false;
+
+ if (!Get.IsDummy) {
+ // Setup iterator if we are one
+ if ((ModFlags & Modifiers.METHOD_YIELDS) != 0){
+ Iterator iterator = Iterator.CreateIterator (Get, Parent, null, ModFlags);
+ if (iterator == null)
+ return false;
+ }
}
//
// Now name the parameters
//
- Parameter [] p = Parameters.FixedParameters;
+ Parameter [] p = parameters.FixedParameters;
if (p != null) {
// TODO: should be done in parser and it needs to do cycle
if ((p [0].ModFlags & Parameter.Modifier.ISBYREF) != 0) {
- Report.Error (631, Location, "ref and out are not valid in this context");
+ CSharpParser.Error_ParameterModifierNotValid (Location);
return false;
}
}
PropertyBuilder = Parent.TypeBuilder.DefineProperty (
- Name, PropertyAttributes.None, MemberType, ParameterTypes);
+ Name, PropertyAttributes.None, MemberType, parameters.Types);
if (!Get.IsDummy)
PropertyBuilder.SetGetMethod (GetBuilder);
if (!Set.IsDummy)
PropertyBuilder.SetSetMethod (SetBuilder);
- TypeManager.RegisterIndexer (PropertyBuilder, GetBuilder, SetBuilder, ParameterTypes);
+ TypeManager.RegisterIndexer (PropertyBuilder, GetBuilder, SetBuilder, parameters.Types);
return true;
}
+ public override string GetDocCommentName (DeclSpace ds)
+ {
+ return DocUtil.GetMethodDocCommentName (this, parameters, ds);
+ }
+
public override string GetSignatureForError ()
{
StringBuilder sb = new StringBuilder (Parent.GetSignatureForError ());
}
sb.Append (".this");
- sb.Append (Parameters.GetSignatureForError ().Replace ('(', '[').Replace (')', ']'));
+ sb.Append (parameters.GetSignatureForError ().Replace ('(', '[').Replace (')', ']'));
return sb.ToString ();
}
caching_flags |= Flags.TestMethodDuplication;
return true;
}
+
+ protected override PropertyInfo ResolveBaseProperty ()
+ {
+ return Parent.PartialContainer.BaseCache.FindMemberToOverride (
+ Parent.TypeBuilder, Name, parameters.Types, null, true) as PropertyInfo;
+ }
+
+ protected override bool VerifyClsCompliance ()
+ {
+ if (!base.VerifyClsCompliance ())
+ return false;
+
+ parameters.VerifyClsCompliance ();
+ return true;
+ }
}
- public class Operator : MethodOrOperator, IIteratorContainer {
+ public class Operator : MethodOrOperator, IAnonymousHost {
const int AllowedModifiers =
Modifiers.PUBLIC |
public Operator (DeclSpace parent, OpType type, Expression ret_type,
int mod_flags, Parameters parameters,
ToplevelBlock block, Attributes attrs, Location loc)
- : base (parent, ret_type, mod_flags, AllowedModifiers, false,
- new MemberName ("op_" + type, loc), attrs, parameters)
+ : base (parent, null, ret_type, mod_flags, AllowedModifiers, false,
+ new MemberName ("op_" + type.ToString(), loc), attrs, parameters)
{
OperatorType = type;
Block = block;
protected override bool CheckForDuplications ()
{
- ArrayList ar = ParentContainer.Operators;
+ ArrayList ar = Parent.PartialContainer.Operators;
if (ar != null) {
int arLen = ar.Count;
}
}
- ar = ParentContainer.Methods;
+ ar = Parent.PartialContainer.Methods;
if (ar != null) {
int arLen = ar.Count;
return false;
}
+ // imlicit and explicit operator of same types are not allowed
+ if (OperatorType == OpType.Explicit || OperatorType == OpType.Implicit)
+ MarkForDuplicationCheck ();
+
if (!base.Define ())
return false;
return false;
}
- Type declaring_type = MethodBuilder.DeclaringType;
+ Type declaring_type = MethodData.DeclaringType;
Type return_type = MemberType;
Type first_arg_type = ParameterTypes [0];
return false;
}
- if (first_arg_type != declaring_type && return_type != declaring_type){
+ if ((first_arg_type != declaring_type) && (return_type != declaring_type) &&
+ !TypeManager.IsNullableTypeOf (first_arg_type, declaring_type) &&
+ !TypeManager.IsNullableTypeOf (return_type, declaring_type)) {
Report.Error (
556, Location,
"User-defined conversion must convert to or from the " +
// Checks for Unary operators
if (OperatorType == OpType.Increment || OperatorType == OpType.Decrement) {
- if (return_type != declaring_type && !return_type.IsSubclassOf (declaring_type)) {
+ if (return_type != declaring_type && !TypeManager.IsSubclassOf (return_type, declaring_type)) {
Report.Error (448, Location,
"The return type for ++ or -- operator must be the containing type or derived from the containing type");
return false;