//
// Copyright 2001, 2002, 2003 Ximian, Inc (http://www.ximian.com)
// Copyright 2004-2008 Novell, Inc
+// Copyright 2011 Xamarin Inc
//
using System;
using System.Collections.Generic;
-using System.Reflection;
-using System.Reflection.Emit;
using System.Text;
+using Mono.CompilerServices.SymbolWriter;
#if NET_2_1
using XmlElement = System.Object;
#endif
+#if STATIC
+using IKVM.Reflection;
+using IKVM.Reflection.Emit;
+#else
+using System.Reflection;
+using System.Reflection.Emit;
+#endif
namespace Mono.CSharp
{
// This includes properties, indexers, and events
public abstract class PropertyBasedMember : InterfaceMemberBase
{
- public PropertyBasedMember (DeclSpace parent, GenericMethod generic,
- FullNamedExpression type, Modifiers mod, Modifiers allowed_mod,
- MemberName name, Attributes attrs)
- : base (parent, generic, type, mod, allowed_mod, name, attrs)
+ public PropertyBasedMember (TypeDefinition parent, FullNamedExpression type, Modifiers mod, Modifiers allowed_mod, MemberName name, Attributes attrs)
+ : base (parent, type, mod, allowed_mod, name, attrs)
{
}
}
}
- public bool IsNotRealProperty {
- get {
- return (state & StateFlags.IsNotRealProperty) != 0;
- }
- set {
- state |= StateFlags.IsNotRealProperty;
- }
- }
-
public bool HasDifferentAccessibility {
get {
return HasGet && HasSet &&
ps.memberType = inflator.Inflate (memberType);
return ps;
}
+
+ public override List<TypeSpec> ResolveMissingDependencies ()
+ {
+ return memberType.ResolveMissingDependencies ();
+ }
}
//
public class GetMethod : PropertyMethod
{
- static string[] attribute_targets = new string [] { "method", "return" };
+ static readonly string[] attribute_targets = new string [] { "method", "return" };
internal const string Prefix = "get_";
{
}
- public override MethodBuilder Define (DeclSpace parent)
+ public override MethodBuilder Define (TypeContainer parent)
{
base.Define (parent);
method_data = new MethodData (method, ModFlags, flags, this);
- if (!method_data.Define (parent, method.GetFullName (MemberName), Report))
+ if (!method_data.Define (parent.PartialContainer, method.GetFullName (MemberName)))
return null;
Spec.SetMetaInfo (method_data.MethodBuilder);
public class SetMethod : PropertyMethod {
- static string[] attribute_targets = new string [] { "method", "param", "return" };
+ static readonly string[] attribute_targets = new string[] { "method", "param", "return" };
internal const string Prefix = "set_";
- ImplicitParameter param_attr;
protected ParametersCompiled parameters;
public SetMethod (PropertyBase method, Modifiers modifiers, ParametersCompiled parameters, Attributes attrs, Location loc)
protected override void ApplyToExtraTarget (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
{
if (a.Target == AttributeTargets.Parameter) {
- if (param_attr == null)
- param_attr = new ImplicitParameter (method_data.MethodBuilder);
-
- param_attr.ApplyAttributeBuilder (a, ctor, cdata, pa);
+ parameters[0].ApplyAttributeBuilder (a, ctor, cdata, pa);
return;
}
}
}
- public override MethodBuilder Define (DeclSpace parent)
+ public override MethodBuilder Define (TypeContainer parent)
{
parameters.Resolve (this);
method_data = new MethodData (method, ModFlags, flags, this);
- if (!method_data.Define (parent, method.GetFullName (MemberName), Report))
+ if (!method_data.Define (parent.PartialContainer, method.GetFullName (MemberName)))
return null;
Spec.SetMetaInfo (method_data.MethodBuilder);
public override TypeSpec ReturnType {
get {
- return TypeManager.void_type;
+ return Parent.Compiler.BuiltinTypes.Void;
}
}
}
}
- static string[] attribute_targets = new string [] { "property" };
+ static readonly string[] attribute_targets = new string[] { "property" };
public abstract class PropertyMethod : AbstractPropertyEventMethod
{
- public const Modifiers AllowedModifiers =
+ const Modifiers AllowedModifiers =
Modifiers.PUBLIC |
Modifiers.PROTECTED |
Modifiers.INTERNAL |
: base (method, prefix, attrs, loc)
{
this.method = method;
- this.ModFlags = modifiers | (method.ModFlags & (Modifiers.STATIC | Modifiers.UNSAFE));
+ this.ModFlags = ModifiersExtensions.Check (AllowedModifiers, modifiers, 0, loc, Report);
+ this.ModFlags |= (method.ModFlags & (Modifiers.STATIC | Modifiers.UNSAFE));
}
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
return method.IsClsComplianceRequired ();
}
- public virtual MethodBuilder Define (DeclSpace parent)
+ public virtual MethodBuilder Define (TypeContainer parent)
{
- TypeContainer container = parent.PartialContainer;
+ var container = parent.PartialContainer;
//
// Check for custom access modifier
if (container.Kind == MemberKind.Interface)
Report.Error (275, Location, "`{0}': accessibility modifiers may not be used on accessors in an interface",
GetSignatureForError ());
-
- if ((method.ModFlags & Modifiers.ABSTRACT) != 0 && (ModFlags & Modifiers.PRIVATE) != 0) {
+ else if ((method.ModFlags & Modifiers.ABSTRACT) != 0 && (ModFlags & Modifiers.PRIVATE) != 0) {
Report.Error (442, Location, "`{0}': abstract properties cannot have private accessors", GetSignatureForError ());
}
CheckAbstractAndExtern (block != null);
CheckProtectedModifier ();
- if (block != null && block.IsIterator)
- Iterator.CreateIterator (this, Parent.PartialContainer, ModFlags, Compiler);
+ if (block != null) {
+ if (block.IsIterator)
+ Iterator.CreateIterator (this, Parent.PartialContainer, ModFlags);
+
+ if (Compiler.Settings.WriteMetadataOnly)
+ block = null;
+ }
return null;
}
PropertyMethod get, set, first;
PropertyBuilder PropertyBuilder;
- public PropertyBase (DeclSpace parent, FullNamedExpression type, Modifiers mod_flags,
- Modifiers allowed_mod, MemberName name, Attributes attrs)
- : base (parent, null, type, mod_flags, allowed_mod, name, attrs)
+ public PropertyBase (TypeDefinition parent, FullNamedExpression type, Modifiers mod_flags, Modifiers allowed_mod, MemberName name, Attributes attrs)
+ : base (parent, type, mod_flags, allowed_mod, name, attrs)
{
}
}
}
+ public override Variance ExpectedMemberTypeVariance {
+ get {
+ return (get != null && set != null) ?
+ Variance.None : set == null ?
+ Variance.Covariant :
+ Variance.Contravariant;
+ }
+ }
+
public PropertyMethod Get {
get {
return get;
if (first == null)
first = value;
- Parent.AddMember (get);
+ Parent.AddNameToContainer (get, get.MemberName.Basename);
}
}
if (first == null)
first = value;
- Parent.AddMember (set);
+ Parent.AddNameToContainer (set, set.MemberName.Basename);
}
}
if (OptAttributes != null)
OptAttributes.Emit ();
- if (member_type == InternalType.Dynamic) {
- Compiler.PredefinedAttributes.Dynamic.EmitAttribute (PropertyBuilder);
+ if (member_type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) {
+ Module.PredefinedAttributes.Dynamic.EmitAttribute (PropertyBuilder);
} else if (member_type.HasDynamicElement) {
- Compiler.PredefinedAttributes.Dynamic.EmitAttribute (PropertyBuilder, member_type);
+ Module.PredefinedAttributes.Dynamic.EmitAttribute (PropertyBuilder, member_type, Location);
}
+ ConstraintChecker.Check (this, member_type, type_expr.Location);
+
first.Emit (Parent);
if (AccessorSecond != null)
AccessorSecond.Emit (Parent);
Set.UpdateName (this);
}
+ public override void WriteDebugSymbol (MonoSymbolFile file)
+ {
+ if (get != null)
+ get.WriteDebugSymbol (file);
+
+ if (set != null)
+ set.WriteDebugSymbol (file);
+ }
+
//
// Represents header string for documentation comment.
//
this.property = p;
}
- public string OriginalName {
+ public Property OriginalProperty {
get {
- return property.Name;
+ return property;
}
}
}
}
- public Property (DeclSpace parent, FullNamedExpression type, Modifiers mod,
+ public Property (TypeDefinition parent, FullNamedExpression type, Modifiers mod,
MemberName name, Attributes attrs)
: base (parent, type, mod,
parent.PartialContainer.Kind == MemberKind.Interface ? AllowedModifiersInterface :
{
}
+ public override void Accept (StructuralVisitor visitor)
+ {
+ visitor.Visit (this);
+ }
+
+
void CreateAutomaticProperty ()
{
// Create backing field
if (!field.Define ())
return;
- Parent.PartialContainer.AddField (field);
+ Parent.PartialContainer.Members.Add (field);
FieldExpr fe = new FieldExpr (field, Location);
if ((field.ModFlags & Modifiers.STATIC) == 0)
- fe.InstanceExpression = new CompilerGeneratedThis (fe.Type, Location);
+ fe.InstanceExpression = new CompilerGeneratedThis (Parent.CurrentType, Location);
- // Create get block
- Get.Block = new ToplevelBlock (Compiler, ParametersCompiled.EmptyReadOnlyParameters, Location);
- Return r = new Return (fe, Location);
+ //
+ // Create get block but we careful with location to
+ // emit only single sequence point per accessor. This allow
+ // to set a breakpoint on it even with no user code
+ //
+ Get.Block = new ToplevelBlock (Compiler, ParametersCompiled.EmptyReadOnlyParameters, Location.Null);
+ Return r = new Return (fe, Get.Location);
Get.Block.AddStatement (r);
// Create set block
- Set.Block = new ToplevelBlock (Compiler, Set.ParameterInfo, Location);
- Assign a = new SimpleAssign (fe, new SimpleName ("value", Location));
- Set.Block.AddStatement (new StatementExpression (a));
+ Set.Block = new ToplevelBlock (Compiler, Set.ParameterInfo, Location.Null);
+ Assign a = new SimpleAssign (fe, new SimpleName ("value", Location.Null), Location.Null);
+ Set.Block.AddStatement (new StatementExpression (a, Set.Location));
}
public override bool Define ()
if (!IsInterface && (ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) == 0 &&
AccessorSecond != null && Get.Block == null && Set.Block == null) {
- if (RootContext.Version <= LanguageVersion.ISO_2)
- Report.FeatureIsNotAvailable (Location, "automatically implemented properties");
+ if (Compiler.Settings.Version <= LanguageVersion.ISO_2)
+ Report.FeatureIsNotAvailable (Compiler, Location, "automatically implemented properties");
Get.ModFlags |= Modifiers.COMPILER_GENERATED;
Set.ModFlags |= Modifiers.COMPILER_GENERATED;
if (!DefineAccessors ())
return false;
+ if (AccessorSecond == null) {
+ PropertyMethod pm;
+ if (AccessorFirst is GetMethod)
+ pm = new SetMethod (this, 0, ParametersCompiled.EmptyReadOnlyParameters, null, Location);
+ else
+ pm = new GetMethod (this, 0, null, Location);
+
+ Parent.AddNameToContainer (pm, pm.MemberName.Basename);
+ }
+
if (!CheckBase ())
return false;
base.Emit ();
}
-
- public override string GetDocCommentName (DeclSpace ds)
- {
- return String.Concat (DocCommentHeader, ds.Name, ".", GetFullName (ShortName).Replace ('.', '#'));
- }
}
/// <summary>
{
}
- public override MethodBuilder Define (DeclSpace ds)
+ public override MethodBuilder Define (TypeContainer ds)
{
CheckAbstractAndExtern (block != null);
return base.Define (ds);
static readonly string[] attribute_targets = new string [] { "event" };
- public EventProperty (DeclSpace parent, FullNamedExpression type, Modifiers mod_flags, MemberName name, Attributes attrs)
+ public EventProperty (TypeDefinition parent, FullNamedExpression type, Modifiers mod_flags, MemberName name, Attributes attrs)
: base (parent, type, mod_flags, name, attrs)
{
}
+ public override void Accept (StructuralVisitor visitor)
+ {
+ visitor.Visit (this);
+ }
+
public override bool Define()
{
if (!base.Define ())
abstract class EventFieldAccessor : AEventAccessor
{
protected EventFieldAccessor (EventField method, string prefix)
- : base (method, prefix, null, Location.Null)
+ : base (method, prefix, null, method.Location)
{
}
- protected abstract MethodSpec Operation { get; }
+ protected abstract MethodSpec GetOperation (Location loc);
- public override void Emit (DeclSpace parent)
+ public override void Emit (TypeDefinition parent)
{
- if ((method.ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) == 0) {
- block = new ToplevelBlock (Compiler, ParameterInfo, Location);
+ if ((method.ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) == 0 && !Compiler.Settings.WriteMetadataOnly) {
+ block = new ToplevelBlock (Compiler, ParameterInfo, Location) {
+ IsCompilerGenerated = true
+ };
FabricateBodyStatement ();
}
void FabricateBodyStatement ()
{
- var cas = TypeManager.gen_interlocked_compare_exchange;
- if (cas == null) {
- TypeSpec t = TypeManager.CoreLookupType (Compiler, "System.Threading", "Interlocked", MemberKind.Class, true);
- if (t != null) {
- var p = new ParametersImported (
- new[] {
- new ParameterData (null, Parameter.Modifier.REF),
- new ParameterData (null, Parameter.Modifier.NONE),
- new ParameterData (null, Parameter.Modifier.NONE)
- },
- new [] {
- new TypeParameterSpec (0, null, SpecialConstraint.None, Variance.None, null),
- new TypeParameterSpec (0, null, SpecialConstraint.None, Variance.None, null),
- new TypeParameterSpec (0, null, SpecialConstraint.None, Variance.None, null),
- }, false);
-
- var filter = new MemberFilter ("CompareExchange", 1, MemberKind.Method, p, null);
- cas = TypeManager.gen_interlocked_compare_exchange = TypeManager.GetPredefinedMethod (t, filter, Location);
- }
- }
-
//
// Delegate obj1 = backing_field
// do {
// Delegate obj2 = obj1;
- // obj1 = Interlocked.CompareExchange (ref backing_field, Delegate.Combine|Remove(obj2, value), obj1);
- // } while (obj1 != obj2)
+ // obj1 = Interlocked.CompareExchange (ref backing_field, Delegate.Combine|Remove(obj2, value), obj1);
+ // } while ((object)obj1 != (object)obj2)
//
var field_info = ((EventField) method).backing_field;
block.AddStatement (new StatementExpression (new SimpleAssign (new LocalVariableReference (obj1, Location), f_expr)));
var cond = new BooleanExpression (new Binary (Binary.Operator.Inequality,
- new LocalVariableReference (obj1, Location), new LocalVariableReference (obj2, Location), Location));
+ new Cast (new TypeExpression (Module.Compiler.BuiltinTypes.Object, Location), new LocalVariableReference (obj1, Location), Location),
+ new Cast (new TypeExpression (Module.Compiler.BuiltinTypes.Object, Location), new LocalVariableReference (obj2, Location), Location)));
var body = new ExplicitBlock (block, Location, Location);
- block.AddStatement (new Do (body, cond, Location));
+ block.AddStatement (new Do (body, cond, Location, Location));
body.AddStatement (new StatementExpression (
new SimpleAssign (new LocalVariableReference (obj2, Location), new LocalVariableReference (obj1, Location))));
args_oper.Add (new Argument (new LocalVariableReference (obj2, Location)));
args_oper.Add (new Argument (block.GetParameterReference (0, Location)));
+ var op_method = GetOperation (Location);
+
var args = new Arguments (3);
args.Add (new Argument (f_expr, Argument.AType.Ref));
args.Add (new Argument (new Cast (
new TypeExpression (field_info.MemberType, Location),
- new Invocation (MethodGroupExpr.CreatePredefined (Operation, Operation.DeclaringType, Location), args_oper),
+ new Invocation (MethodGroupExpr.CreatePredefined (op_method, op_method.DeclaringType, Location), args_oper),
Location)));
args.Add (new Argument (new LocalVariableReference (obj1, Location)));
+ var cas = Module.PredefinedMembers.InterlockedCompareExchange_T.Resolve (Location);
+ if (cas == null)
+ return;
+
body.AddStatement (new StatementExpression (new SimpleAssign (
new LocalVariableReference (obj1, Location),
new Invocation (MethodGroupExpr.CreatePredefined (cas, cas.DeclaringType, Location), args))));
{
}
- protected override MethodSpec Operation {
- get {
- if (TypeManager.delegate_combine_delegate_delegate == null) {
- TypeManager.delegate_combine_delegate_delegate = TypeManager.GetPredefinedMethod (
- TypeManager.delegate_type, "Combine", Location, TypeManager.delegate_type, TypeManager.delegate_type);
- }
-
- return TypeManager.delegate_combine_delegate_delegate;
- }
+ protected override MethodSpec GetOperation (Location loc)
+ {
+ return Module.PredefinedMembers.DelegateCombine.Resolve (loc);
}
}
{
}
- protected override MethodSpec Operation {
- get {
- if (TypeManager.delegate_remove_delegate_delegate == null) {
- TypeManager.delegate_remove_delegate_delegate = TypeManager.GetPredefinedMethod (
- TypeManager.delegate_type, "Remove", Location, TypeManager.delegate_type, TypeManager.delegate_type);
- }
-
- return TypeManager.delegate_remove_delegate_delegate;
- }
+ protected override MethodSpec GetOperation (Location loc)
+ {
+ return Module.PredefinedMembers.DelegateRemove.Resolve (loc);
}
}
Field backing_field;
List<FieldDeclarator> declarators;
- public EventField (DeclSpace parent, FullNamedExpression type, Modifiers mod_flags, MemberName name, Attributes attrs)
+ public EventField (TypeDefinition parent, FullNamedExpression type, Modifiers mod_flags, MemberName name, Attributes attrs)
: base (parent, type, mod_flags, name, attrs)
{
Add = new AddDelegateMethod (this);
#region Properties
+ public List<FieldDeclarator> Declarators {
+ get {
+ return this.declarators;
+ }
+ }
+
bool HasBackingField {
get {
return !IsInterface && (ModFlags & Modifiers.ABSTRACT) == 0;
#endregion
+
+ public override void Accept (StructuralVisitor visitor)
+ {
+ visitor.Visit (this);
+ }
+
public void AddDeclarator (FieldDeclarator declarator)
{
if (declarators == null)
declarators.Add (declarator);
- // TODO: This will probably break
- Parent.AddMember (this, declarator.Name.Value);
+ Parent.AddNameToContainer (this, declarator.Name.Value);
}
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
mod_flags_src &= ~(Modifiers.AccessibilityMask | Modifiers.DEFAULT_ACCESS_MODIFER);
var t = new TypeExpression (MemberType, TypeExpression.Location);
- int index = Parent.PartialContainer.Events.IndexOf (this);
foreach (var d in declarators) {
var ef = new EventField (Parent, t, mod_flags_src, new MemberName (d.Name.Value, d.Name.Location), OptAttributes);
if (d.Initializer != null)
ef.initializer = d.Initializer;
- Parent.PartialContainer.Events.Insert (++index, ef);
+ ef.Define ();
+ Parent.PartialContainer.Members.Add (ef);
}
}
Modifiers.BACKING_FIELD | Modifiers.COMPILER_GENERATED | Modifiers.PRIVATE | (ModFlags & (Modifiers.STATIC | Modifiers.UNSAFE)),
MemberName, null);
- Parent.PartialContainer.AddField (backing_field);
+ Parent.PartialContainer.Members.Add (backing_field);
backing_field.Initializer = Initializer;
backing_field.ModFlags &= ~Modifiers.COMPILER_GENERATED;
public abstract class AEventAccessor : AbstractPropertyEventMethod
{
protected readonly Event method;
- ImplicitParameter param_attr;
- ParametersCompiled parameters;
+ readonly ParametersCompiled parameters;
static readonly string[] attribute_targets = new string [] { "method", "param", "return" };
{
this.method = method;
this.ModFlags = method.ModFlags;
- this.parameters = ParametersCompiled.CreateImplicitParameter (method.TypeExpression, loc);;
+ this.parameters = ParametersCompiled.CreateImplicitParameter (method.TypeExpression, loc);
}
public bool IsInterfaceImplementation {
protected override void ApplyToExtraTarget (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
{
if (a.Target == AttributeTargets.Parameter) {
- if (param_attr == null)
- param_attr = new ImplicitParameter (method_data.MethodBuilder);
-
- param_attr.ApplyAttributeBuilder (a, ctor, cdata, pa);
+ parameters[0].ApplyAttributeBuilder (a, ctor, cdata, pa);
return;
}
return method.IsClsComplianceRequired ();
}
- public virtual MethodBuilder Define (DeclSpace parent)
+ public virtual MethodBuilder Define (TypeContainer parent)
{
- parameters.Resolve (this);
+ // Fill in already resolved event type to speed things up and
+ // avoid confusing duplicate errors
+ ((Parameter) parameters.FixedParameters[0]).Type = method.member_type;
+ parameters.Types = new TypeSpec[] { method.member_type };
method_data = new MethodData (method, method.ModFlags,
method.flags | MethodAttributes.HideBySig | MethodAttributes.SpecialName, this);
- if (!method_data.Define (parent, method.GetFullName (MemberName), Report))
+ if (!method_data.Define (parent.PartialContainer, method.GetFullName (MemberName)))
return null;
+ if (Compiler.Settings.WriteMetadataOnly)
+ block = null;
+
MethodBuilder mb = method_data.MethodBuilder;
Spec = new MethodSpec (MemberKind.Method, parent.PartialContainer.Definition, this, ReturnType, mb, ParameterInfo, method.ModFlags);
public override TypeSpec ReturnType {
get {
- return TypeManager.void_type;
+ return Parent.Compiler.BuiltinTypes.Void;
}
}
EventBuilder EventBuilder;
protected EventSpec spec;
- protected Event (DeclSpace parent, FullNamedExpression type, Modifiers mod_flags, MemberName name, Attributes attrs)
- : base (parent, null, type, mod_flags,
+ protected Event (TypeDefinition parent, FullNamedExpression type, Modifiers mod_flags, MemberName name, Attributes attrs)
+ : base (parent, type, mod_flags,
parent.PartialContainer.Kind == MemberKind.Interface ? AllowedModifiersInterface :
parent.PartialContainer.Kind == MemberKind.Struct ? AllowedModifiersStruct :
AllowedModifiersClass,
}
set {
add = value;
- Parent.AddMember (value);
+ Parent.AddNameToContainer (value, value.MemberName.Basename);
+ }
+ }
+
+ public override Variance ExpectedMemberTypeVariance {
+ get {
+ return Variance.Contravariant;
}
}
}
set {
remove = value;
- Parent.AddMember (value);
+ Parent.AddNameToContainer (value, value.MemberName.Basename);
}
}
#endregion
if (!base.Define ())
return false;
- if (!TypeManager.IsDelegateType (MemberType)) {
+ if (!MemberType.IsDelegate) {
Report.Error (66, Location, "`{0}': event must be of a delegate type", GetSignatureForError ());
}
if (RemoveBuilder == null)
return false;
- EventBuilder = Parent.TypeBuilder.DefineEvent (Name, EventAttributes.None, MemberType.GetMetaInfo ());
+ EventBuilder = Parent.TypeBuilder.DefineEvent (GetFullName (MemberName), EventAttributes.None, MemberType.GetMetaInfo ());
EventBuilder.SetAddOnMethod (AddBuilder);
EventBuilder.SetRemoveOnMethod (RemoveBuilder);
spec = new EventSpec (Parent.Definition, this, MemberType, ModFlags, Add.Spec, remove.Spec);
- Parent.MemberCache.AddMember (this, Name, spec);
+ Parent.MemberCache.AddMember (this, GetFullName (MemberName), spec);
Parent.MemberCache.AddMember (this, AddBuilder.Name, Add.Spec);
Parent.MemberCache.AddMember (this, RemoveBuilder.Name, remove.Spec);
OptAttributes.Emit ();
}
+ ConstraintChecker.Check (this, member_type, type_expr.Location);
+
Add.Emit (Parent);
Remove.Emit (Parent);
base.Emit ();
}
+ public override void WriteDebugSymbol (MonoSymbolFile file)
+ {
+ add.WriteDebugSymbol (file);
+ remove.WriteDebugSymbol (file);
+ }
+
//
// Represents header string for documentation comment.
//
return es;
}
+
+ public override List<TypeSpec> ResolveMissingDependencies ()
+ {
+ return MemberType.ResolveMissingDependencies ();
+ }
}
public class Indexer : PropertyBase, IParametersMember
this.parameters = parameters;
}
- public override MethodBuilder Define (DeclSpace parent)
+ public override MethodBuilder Define (TypeContainer parent)
{
- parameters.Resolve (this);
+ // Disable reporting, parameters are resolved twice
+ Report.DisableReporting ();
+ try {
+ parameters.Resolve (this);
+ } finally {
+ Report.EnableReporting ();
+ }
+
return base.Define (parent);
}
readonly ParametersCompiled parameters;
- public Indexer (DeclSpace parent, FullNamedExpression type, MemberName name, Modifiers mod,
- ParametersCompiled parameters, Attributes attrs)
+ public Indexer (TypeDefinition parent, FullNamedExpression type, MemberName name, Modifiers mod, ParametersCompiled parameters, Attributes attrs)
: base (parent, type, mod,
parent.PartialContainer.Kind == MemberKind.Interface ? AllowedInterfaceModifiers : AllowedModifiers,
name, attrs)
this.parameters = parameters;
}
+ #region Properties
+
+ AParametersCollection IParametersMember.Parameters {
+ get {
+ return parameters;
+ }
+ }
+
+ public ParametersCompiled ParameterInfo {
+ get {
+ return parameters;
+ }
+ }
+
+ #endregion
+
+
+ public override void Accept (StructuralVisitor visitor)
+ {
+ visitor.Visit (this);
+ }
+
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
{
if (a.Type == pa.IndexerName) {
- if (IsExplicitImpl) {
- Report.Error (415, a.Location,
- "The `{0}' attribute is valid only on an indexer that is not an explicit interface member declaration",
- TypeManager.CSharpName (a.Type));
- }
-
// Attribute was copied to container
return;
}
return false;
if (OptAttributes != null) {
- Attribute indexer_attr = OptAttributes.Search (Compiler.PredefinedAttributes.IndexerName);
+ Attribute indexer_attr = OptAttributes.Search (Module.PredefinedAttributes.IndexerName);
if (indexer_attr != null) {
var compiling = indexer_attr.Type.MemberDefinition as TypeContainer;
if (compiling != null)
compiling.Define ();
- string name = indexer_attr.GetIndexerAttributeValue ();
- if ((ModFlags & Modifiers.OVERRIDE) != 0) {
+ if (IsExplicitImpl) {
+ Report.Error (415, indexer_attr.Location,
+ "The `{0}' attribute is valid only on an indexer that is not an explicit interface member declaration",
+ indexer_attr.Type.GetSignatureForError ());
+ } else if ((ModFlags & Modifiers.OVERRIDE) != 0) {
Report.Error (609, indexer_attr.Location,
"Cannot set the `IndexerName' attribute on an indexer marked override");
- }
+ } else {
+ string name = indexer_attr.GetIndexerAttributeValue ();
- if (!string.IsNullOrEmpty (name))
- ShortName = name;
+ if (!string.IsNullOrEmpty (name)) {
+ SetMemberName (new MemberName (MemberName.Left, name, Location));
+ }
+ }
}
}
if (InterfaceType != null) {
string base_IndexerName = InterfaceType.MemberDefinition.GetAttributeDefaultMember ();
- if (base_IndexerName != Name)
- ShortName = base_IndexerName;
+ if (base_IndexerName != ShortName) {
+ SetMemberName (new MemberName (MemberName.Left, base_IndexerName, new TypeExpression (InterfaceType, Location), Location));
+ }
}
- if (!Parent.PartialContainer.AddMember (this))
- return false;
+ Parent.AddNameToContainer (this, MemberName.Basename);
flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
return base.EnableOverloadChecks (overload);
}
- public override string GetDocCommentName (DeclSpace ds)
+ public override void Emit ()
{
- return DocUtil.GetMethodDocCommentName (this, parameters, ds);
+ parameters.CheckConstraints (this);
+
+ base.Emit ();
}
public override string GetSignatureForError ()
{
StringBuilder sb = new StringBuilder (Parent.GetSignatureForError ());
- if (MemberName.Left != null) {
- sb.Append ('.');
- sb.Append (MemberName.Left.GetSignatureForError ());
+ if (MemberName.ExplicitInterface != null) {
+ sb.Append (".");
+ sb.Append (MemberName.ExplicitInterface.GetSignatureForError ());
}
sb.Append (".this");
- sb.Append (parameters.GetSignatureForError ().Replace ('(', '[').Replace (')', ']'));
+ sb.Append (parameters.GetSignatureForError ("[", "]", parameters.Count));
return sb.ToString ();
}
- public AParametersCollection Parameters {
- get {
- return parameters;
- }
- }
-
- public ParametersCompiled ParameterInfo {
- get {
- return parameters;
- }
+ public override string GetSignatureForDocumentation ()
+ {
+ return base.GetSignatureForDocumentation () + parameters.GetSignatureForDocumentation ();
}
protected override bool VerifyClsCompliance ()
}
#endregion
+ public override string GetSignatureForDocumentation ()
+ {
+ return base.GetSignatureForDocumentation () + parameters.GetSignatureForDocumentation ();
+ }
+
public override string GetSignatureForError ()
{
return DeclaringType.GetSignatureForError () + ".this" + parameters.GetSignatureForError ("[", "]", parameters.Count);
spec.parameters = parameters.Inflate (inflator);
return spec;
}
+
+ public override List<TypeSpec> ResolveMissingDependencies ()
+ {
+ var missing = base.ResolveMissingDependencies ();
+ foreach (var pt in parameters.Types) {
+ var m = pt.GetMissingDependencies ();
+ if (m == null)
+ continue;
+
+ if (missing == null)
+ missing = new List<TypeSpec> ();
+
+ missing.AddRange (m);
+ }
+
+ return missing;
+ }
}
}