}
base.ApplyAttributeBuilder (a, cb);
- }
+ }
public override AttributeTargets AttributeTargets {
get {
// Invariant maintained by AddIndexer(): All explicit interface indexers precede normal indexers
bool seen_normal_indexers = false;
foreach (Indexer i in Indexers) {
- if (i.MemberName.TypeName != null)
- seen_normal_indexers = true;
- else if (seen_normal_indexers)
- throw new Exception ("Internal Error: 'Indexers' array not sorted properly.");
- }
- foreach (Indexer i in Indexers){
string name;
i.Define (this);
name = i.IndexerName;
- if (i.InterfaceType != null)
+ if (i.InterfaceType != null) {
+ if (seen_normal_indexers)
+ throw new Exception ("Internal Error: 'Indexers' array not sorted properly.");
continue;
+ }
+
+ seen_normal_indexers = true;
- if (class_indexer_name == null){
+ if (class_indexer_name == null)
class_indexer_name = name;
- continue;
- }
-
- if (name == class_indexer_name)
- continue;
-
- Report.Error (
- 668, "Two indexers have different names, " +
- " you should use the same name for all your indexers");
+ else if (name != class_indexer_name)
+ Report.Error (668, "Two indexers have different names, " +
+ " you should use the same name for all your indexers");
}
if (seen_normal_indexers && class_indexer_name == null)
// Whether this is an operator method.
public bool IsOperator;
+ static string[] attribute_targets = new string [] { "method", "return" };
+
public MethodCore (DeclSpace ds, Expression type, int mod, int allowed_mod,
bool is_interface, MemberName name, Attributes attrs,
Parameters parameters, Location loc)
return true;
}
+ protected override string[] ValidAttributeTargets {
+ get {
+ return attribute_targets;
+ }
+ }
+
protected override bool VerifyClsCompliance (DeclSpace ds)
{
if (!base.VerifyClsCompliance (ds)) {
public class Method : MethodCore, IIteratorContainer, IMethodData {
public MethodBuilder MethodBuilder;
public MethodData MethodData;
+ ReturnParameter return_attributes;
/// <summary>
/// Modifiers allowed in a class declaration
public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
{
+ if (a.Target == "return") {
+ if (return_attributes == null)
+ return_attributes = new ReturnParameter (MethodBuilder, Location);
+
+ return_attributes.ApplyAttributeBuilder (a, cb);
+ return;
+ }
+
if (a.Type == TypeManager.methodimpl_attr_type && a.IsInternalCall) {
MethodBuilder.SetImplementationFlags (MethodImplAttributes.InternalCall | MethodImplAttributes.Runtime);
}
ec.IsStatic = false;
}
- Parameters.LabelParameters (ec, ConstructorBuilder,
- OptAttributes, Location);
+ Parameters.LabelParameters (ec, ConstructorBuilder, Location);
SymbolWriter sw = CodeGen.SymbolWriter;
bool generate_debugging = false;
public virtual bool ApplyAttributes (Attributes opt_attrs, bool is_method, DeclSpace ds)
{
- if ((opt_attrs == null) || (opt_attrs.AttributeSections == null))
+ if ((opt_attrs == null) || (opt_attrs.Attrs == null))
return true;
- foreach (AttributeSection asec in opt_attrs.AttributeSections) {
- if (asec.Attributes == null)
- continue;
-
- foreach (Attribute a in asec.Attributes) {
- Type attr_type = a.ResolveType (ec, true);
- if (attr_type == TypeManager.conditional_attribute_type) {
- if (!ApplyConditionalAttribute (a))
- return false;
- } else if (attr_type == TypeManager.obsolete_attribute_type) {
- if (!ApplyObsoleteAttribute (a))
- return false;
- } else if (attr_type == TypeManager.dllimport_type) {
- if (!is_method) {
- Attribute.Error_AttributeNotValidForElement (a, method.Location);
- return false;
- }
- if (!ApplyDllImportAttribute (a))
- return false;
+ foreach (Attribute a in opt_attrs.Attrs) {
+ Type attr_type = a.ResolveType (ec, true);
+ if (attr_type == TypeManager.conditional_attribute_type) {
+ if (!ApplyConditionalAttribute (a))
+ return false;
+ } else if (attr_type == TypeManager.obsolete_attribute_type) {
+ if (!ApplyObsoleteAttribute (a))
+ return false;
+ } else if (attr_type == TypeManager.dllimport_type) {
+ if (!is_method) {
+ Attribute.Error_AttributeNotValidForElement (a, method.Location);
+ return false;
}
+ if (!ApplyDllImportAttribute (a))
+ return false;
}
}
OptAttributes.Emit (ec, kind);
if (member is MethodCore)
- ((MethodCore) member).Parameters.LabelParameters (ec, MethodBuilder,OptAttributes, loc);
+ ((MethodCore) member).Parameters.LabelParameters (ec, MethodBuilder, loc);
SymbolWriter sw = CodeGen.SymbolWriter;
Block block = method.Block;
[Flags]
public enum Status : byte { ASSIGNED = 1, USED = 2 }
+ static string[] attribute_targets = new string [] { "field" };
+
//
// The constructor is only exposed to our children
//
return TypeManager.GetFullNameSignature (FieldBuilder);
}
+ protected override string[] ValidAttributeTargets {
+ get {
+ return attribute_targets;
+ }
+ }
+
protected override bool VerifyClsCompliance (DeclSpace ds)
{
if (!base.VerifyClsCompliance (ds))
public class GetMethod: PropertyMethod
{
+ static string[] attribute_targets = new string [] { "method", "return" };
+
public GetMethod (MethodCore method, Accessor accessor):
base (method, accessor)
{
return method.MemberType;
}
}
+
+ protected override string[] ValidAttributeTargets {
+ get {
+ return attribute_targets;
+ }
+ }
}
public class SetMethod: PropertyMethod {
+
+ static string[] attribute_targets = new string [] { "method", "param", "return" };
+ ImplicitParameter param_attr;
+
public SetMethod (MethodCore method, Accessor accessor):
base (method, accessor)
{
}
+ public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
+ {
+ if (a.Target == "param") {
+ if (param_attr == null)
+ param_attr = new ImplicitParameter (method_data.MethodBuilder);
+
+ param_attr.ApplyAttributeBuilder (a, cb);
+ return;
+ }
+
+ base.ApplyAttributeBuilder (a, cb);
+ }
+
protected virtual InternalParameters GetParameterInfo (TypeContainer container)
{
Parameter [] parms = new Parameter [1];
return TypeManager.void_type;
}
}
+
+ protected override string[] ValidAttributeTargets {
+ get {
+ return attribute_targets;
+ }
+ }
}
+ static string[] attribute_targets = new string [] { "property" };
+
public abstract class PropertyMethod: Attributable, IMethodData {
protected readonly MethodCore method;
protected MethodData method_data;
Block block;
+ ReturnParameter return_attributes;
+
public PropertyMethod (MethodCore method, Accessor accessor):
base (accessor.Attributes)
{
public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
{
+ if (a.Target == "return") {
+ if (return_attributes == null)
+ return_attributes = new ReturnParameter (method_data.MethodBuilder, Location);
+
+ return_attributes.ApplyAttributeBuilder (a, cb);
+ return;
+ }
+
method_data.MethodBuilder.SetCustomAttribute (cb);
}
base.Emit (tc);
}
+
+ protected override string[] ValidAttributeTargets {
+ get {
+ return attribute_targets;
+ }
+ }
}
public class Property : PropertyBase, IIteratorContainer {
}
}
- public class Event : FieldBase {
+ /// <summary>
+ /// For case when event is declared like property (with add and remove accessors).
+ /// </summary>
+ public class EventProperty: Event {
+
+ static string[] attribute_targets = new string [] { "event", "property" };
+
+ public EventProperty (DeclSpace ds, Expression type, int mod_flags,
+ bool is_iface, MemberName name, Object init,
+ Attributes attrs, Accessor add, Accessor remove,
+ Location loc)
+ : base (ds, type, mod_flags, is_iface, name, init, attrs, loc)
+ {
+ Add = new AddDelegateMethod (this, add);
+ Remove = new RemoveDelegateMethod (this, remove);
+ }
+
+ protected override string[] ValidAttributeTargets {
+ get {
+ return attribute_targets;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Event is declared like field.
+ /// </summary>
+ public class EventField: Event {
+
+ static string[] attribute_targets = new string [] { "method", "field", "event" };
- sealed class AddDelegateMethod: DelegateMethod
+ public EventField (DeclSpace ds, Expression type, int mod_flags, bool is_iface,
+ MemberName name, Object init, Attributes attrs, Location loc)
+ : base (ds, type, mod_flags, is_iface, name, init, attrs, loc)
+ {
+ Add = new AddDelegateMethod (this);
+ Remove = new RemoveDelegateMethod (this);
+ }
+
+ public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+ {
+ if (a.Target == "field") {
+ FieldBuilder.SetCustomAttribute (cb);
+ return;
+ }
+
+ if (a.Target == "method") {
+ AddBuilder.SetCustomAttribute (cb);
+ RemoveBuilder.SetCustomAttribute (cb);
+ return;
+ }
+
+ base.ApplyAttributeBuilder (a, cb);
+ }
+
+ protected override string[] ValidAttributeTargets {
+ get {
+ return attribute_targets;
+ }
+ }
+ }
+
+ public abstract class Event : FieldBase {
+
+ protected sealed class AddDelegateMethod: DelegateMethod
{
public AddDelegateMethod (Event method):
base (method)
}
- sealed class RemoveDelegateMethod: DelegateMethod
+ protected sealed class RemoveDelegateMethod: DelegateMethod
{
public RemoveDelegateMethod (Event method):
base (method)
protected readonly Event method;
protected MethodData method_data;
Block block;
+ ReturnParameter return_attributes;
+ ImplicitParameter param_attr;
+
+ static string[] attribute_targets = new string [] { "method", "param", "return" };
public DelegateMethod (Event method):
base (null)
public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
{
+ if (a.Target == "return") {
+ if (return_attributes == null)
+ return_attributes = new ReturnParameter (method_data.MethodBuilder, Location);
+
+ return_attributes.ApplyAttributeBuilder (a, cb);
+ return;
+ }
+
+ if (a.Target == "param") {
+ if (param_attr == null)
+ param_attr = new ImplicitParameter (method_data.MethodBuilder);
+
+ param_attr.ApplyAttributeBuilder (a, cb);
+ return;
+ }
+
method_data.MethodBuilder.SetCustomAttribute (cb);
}
public EmitContext CreateEmitContext (TypeContainer tc, ILGenerator ig)
{
- return new EmitContext (tc, method.ds, method.Location, ig, ReturnType, method.ModFlags, false);
+ return new EmitContext (tc, method.ds, Location, ig, ReturnType, method.ModFlags, false);
}
public abstract string MethodName { get; }
#endregion
+ protected override string[] ValidAttributeTargets {
+ get {
+ return attribute_targets;
+ }
+ }
}
const int AllowedInterfaceModifiers =
Modifiers.NEW;
- readonly DelegateMethod Add, Remove;
+ protected DelegateMethod Add, Remove;
public MyEventBuilder EventBuilder;
public MethodBuilder AddBuilder, RemoveBuilder;
public DeclSpace ds;
MethodData AddData, RemoveData;
- public Event (DeclSpace ds, Expression type, int mod_flags, bool is_iface,
- MemberName name, Object init, Attributes attrs, Accessor add,
- Accessor remove, Location loc)
- : base (type, mod_flags,
- is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
- name, init, attrs, loc)
- {
- IsInterface = is_iface;
- this.ds = ds;
-
- Add = new AddDelegateMethod (this, add);
- Remove = new RemoveDelegateMethod (this, remove);
- }
-
public Event (DeclSpace ds, Expression type, int mod_flags, bool is_iface,
MemberName name, Object init, Attributes attrs, Location loc)
: base (type, mod_flags,
{
IsInterface = is_iface;
this.ds = ds;
-
- Add = new AddDelegateMethod (this);
- Remove = new RemoveDelegateMethod (this);
}
public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
base.Emit (tc);
}
-
}
//
if (!DoDefine (container, container))
return false;
- IndexerName = Attribute.ScanForIndexerName (ec, OptAttributes);
+ if (OptAttributes != null)
+ IndexerName = OptAttributes.ScanForIndexerName (ec);
+
if (IndexerName == null)
IndexerName = "Item";
else {
if (IsExplicitImpl) {
Report.Error (592, Location,
- "Attribute 'IndexerName' is not valid on explicit " +
- "implementations.");
-
+ "Attribute 'IndexerName' is not valid on explicit implementations.");
return false;
}
}
public string MethodName;
public Method OperatorMethod;
+ static string[] attribute_targets = new string [] { "param" };
+
public Operator (OpType type, Expression ret_type, int mod_flags,
Expression arg1type, string arg1name,
Expression arg2type, string arg2name,
param_types [0], param_types [1]);
}
+ protected override string[] ValidAttributeTargets {
+ get {
+ return attribute_targets;
+ }
+ }
+
public void SetYields ()
{
ModFlags |= Modifiers.METHOD_YIELDS;