//
// 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.Text;
+using Mono.CompilerServices.SymbolWriter;
#if NET_2_1
using XmlElement = System.Object;
// 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 &&
{
}
- 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 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 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);
+ 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)
{
}
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);
}
}
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 (!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;
{
}
- 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 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 ();
}
// 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))));
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;
return method.IsClsComplianceRequired ();
}
- public virtual MethodBuilder Define (DeclSpace parent)
+ public virtual MethodBuilder Define (TypeContainer parent)
{
// Fill in already resolved event type to speed things up and
// avoid confusing duplicate errors
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);
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);
}
}
}
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 ());
}
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.
//
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;
}
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 void Emit ()
+ {
+ parameters.CheckConstraints (this);
+
+ base.Emit ();
+ }
+
public override string GetSignatureForError ()
{
StringBuilder sb = new StringBuilder (Parent.GetSignatureForError ());
- if (MemberName.Left != null) {
+ if (MemberName.ExplicitInterface != null) {
sb.Append (".");
- sb.Append (MemberName.Left.GetSignatureForError ());
+ sb.Append (MemberName.ExplicitInterface.GetSignatureForError ());
}
sb.Append (".this");
return base.GetSignatureForDocumentation () + parameters.GetSignatureForDocumentation ();
}
- public AParametersCollection Parameters {
- get {
- return parameters;
- }
- }
-
- public ParametersCompiled ParameterInfo {
- get {
- return parameters;
- }
- }
-
protected override bool VerifyClsCompliance ()
{
if (!base.VerifyClsCompliance ())