// (C) 2001, 2002 Ximian, Inc (http://www.ximian.com)
//
//
+// 2002-10-11 Miguel de Icaza <miguel@ximian.com>
+//
+// * class.cs: Following the comment from 2002-09-26 to AddMethod, I
+// have fixed a remaining problem: not every AddXXXX was adding a
+// fully qualified name.
+//
+// Now everyone registers a fully qualified name in the DeclSpace as
+// being defined instead of the partial name.
+//
+// Downsides: we are slower than we need to be due to the excess
+// copies and the names being registered this way.
+//
+// The reason for this is that we currently depend (on the corlib
+// bootstrap for instance) that types are fully qualified, because
+// we dump all the types in the namespace, and we should really have
+// types inserted into the proper namespace, so we can only store the
+// basenames in the defined_names array.
+//
+//
#define CACHE
using System;
using System.Collections;
public AdditionResult AddConstant (Const constant)
{
AdditionResult res;
- string name = constant.Name;
+ string basename = constant.Name;
- if ((res = IsValid (name)) != AdditionResult.Success)
+ if ((res = IsValid (basename)) != AdditionResult.Success)
return res;
if (constants == null)
constants = new ArrayList ();
constants.Add (constant);
- DefineName (name, constant);
+ DefineName (Name + "." + basename, constant);
return AdditionResult.Success;
}
public AdditionResult AddEnum (Mono.CSharp.Enum e)
{
AdditionResult res;
- string name = e.Name;
- if ((res = IsValid (name)) != AdditionResult.Success)
+ if ((res = IsValid (e.Basename)) != AdditionResult.Success)
return res;
if (enums == null)
enums = new ArrayList ();
enums.Add (e);
- DefineName (name, e);
+ DefineName (e.Name, e);
return AdditionResult.Success;
}
public AdditionResult AddClass (Class c)
{
AdditionResult res;
- string name = c.Name;
-
-
- if ((res = IsValid (name)) != AdditionResult.Success)
+
+ if ((res = IsValid (c.Basename)) != AdditionResult.Success)
return res;
-
- DefineName (name, c);
+
+
+
+ DefineName (c.Name, c);
types.Add (c);
-
+
+ // FIXME: Do we really need to explicitly add an empty default static constructor?
+ // Apparently we don't
+/* if (c.default_static_constructor == null)
+ {
+ bool isModule = c is Mono.MonoBASIC.Module;
+ Constructor dc = new Constructor ("New", Parameters.EmptyReadOnlyParameters, null, c.Location);
+ dc.ModFlags = isModule ? Modifiers.PUBLIC | Modifiers.STATIC : Modifiers.PUBLIC;
+ c.AddConstructor (dc);
+ }
+*/
+ // --------------------------------------------------------------
+
return AdditionResult.Success;
}
public AdditionResult AddStruct (Struct s)
{
AdditionResult res;
- string name = s.Name;
- if ((res = IsValid (name)) != AdditionResult.Success)
+ if ((res = IsValid (s.Basename)) != AdditionResult.Success)
return res;
- DefineName (name, s);
+ DefineName (s.Name, s);
types.Add (s);
return AdditionResult.Success;
public AdditionResult AddDelegate (Delegate d)
{
AdditionResult res;
- string name = d.Name;
- if ((res = IsValid (name)) != AdditionResult.Success)
+ if ((res = IsValid (d.Basename)) != AdditionResult.Success)
return res;
if (delegates == null)
delegates = new ArrayList ();
- DefineName (name, d);
+ DefineName (d.Name, d);
delegates.Add (d);
return AdditionResult.Success;
public AdditionResult AddMethod (Method method)
{
- string name = method.Name;
- Object value = defined_names [name];
-
+ string basename = method.Name;
+ string fullname = Name + "." + basename;
+
+ Object value = defined_names [fullname];
+
if (value != null && (!(value is Method)))
return AdditionResult.NameExists;
- if (name == Basename)
+ if (basename == Basename)
return AdditionResult.EnclosingClash;
if (methods == null)
else
methods.Add (method);
- if (value != null)
- DefineName (name, method);
+ if (value == null)
+ DefineName (fullname, method);
return AdditionResult.Success;
}
public AdditionResult AddConstructor (Constructor c)
{
- if (c.Name != Basename)
+ if (c.Name != "New")
return AdditionResult.NotAConstructor;
bool is_static = (c.ModFlags & Modifiers.STATIC) != 0;
public AdditionResult AddInterface (Interface iface)
{
AdditionResult res;
- string name = iface.Name;
- if ((res = IsValid (name)) != AdditionResult.Success)
+ if ((res = IsValid (iface.Basename)) != AdditionResult.Success)
return res;
if (interfaces == null)
interfaces = new ArrayList ();
interfaces.Add (iface);
- DefineName (name, iface);
+ DefineName (iface.Name, iface);
return AdditionResult.Success;
}
public AdditionResult AddField (Field field)
{
AdditionResult res;
- string name = field.Name;
+ string basename = field.Name;
- if ((res = IsValid (name)) != AdditionResult.Success)
+ if ((res = IsValid (basename)) != AdditionResult.Success)
return res;
if (fields == null)
fields.Add (field);
- if (field.HasInitializer){
- if ((field.ModFlags & Modifiers.STATIC) != 0){
+ if (field.HasInitializer){
+ if ((field.ModFlags & Modifiers.STATIC) != 0) {
if (initialized_static_fields == null)
initialized_static_fields = new ArrayList ();
if ((field.ModFlags & Modifiers.STATIC) == 0)
have_nonstatic_fields = true;
- DefineName (name, field);
+ DefineName (Name + "." + basename, field);
return AdditionResult.Success;
}
public AdditionResult AddProperty (Property prop)
{
AdditionResult res;
- string name = prop.Name;
+ string basename = prop.Name;
- if ((res = IsValid (name)) != AdditionResult.Success)
+ if ((res = IsValid (basename)) != AdditionResult.Success)
return res;
if (properties == null)
properties.Insert (0, prop);
else
properties.Add (prop);
- DefineName (name, prop);
+ DefineName (Name + "." + basename, prop);
return AdditionResult.Success;
}
public AdditionResult AddEvent (Event e)
{
AdditionResult res;
- string name = e.Name;
+ string basename = e.Name;
- if ((res = IsValid (name)) != AdditionResult.Success)
+ if ((res = IsValid (basename)) != AdditionResult.Success)
return res;
if (events == null)
events = new ArrayList ();
events.Add (e);
- DefineName (name, e);
+ DefineName (Name + "." + basename, e);
return AdditionResult.Success;
}
// if (parent_builder is ModuleBuilder) {
if (IsTopLevel){
ModuleBuilder builder = CodeGen.ModuleBuilder;
+ TypeBuilder = builder.DefineType (
+ Name, type_attributes, parent, ifaces);
- //
- // Structs with no fields need to have a ".size 1"
- // appended
- //
-
- if (!is_class && !have_nonstatic_fields)
- TypeBuilder = builder.DefineType (Name,
- type_attributes,
- parent,
- PackingSize.Unspecified, 1);
- else
- //
- // classes or structs with fields
- //
- TypeBuilder = builder.DefineType (Name,
- type_attributes,
- parent,
- ifaces);
} else {
TypeBuilder builder = Parent.TypeBuilder;
+ TypeBuilder = builder.DefineNestedType (
+ Basename, type_attributes, parent, ifaces);
+ }
- //
- // Structs with no fields need to have a ".size 1"
- // appended
- //
- if (!is_class && !have_nonstatic_fields)
- TypeBuilder = builder.DefineNestedType (Basename,
- type_attributes,
- parent,
- PackingSize.Unspecified);
- else {
- //
- // classes or structs with fields
- //
- TypeBuilder = builder.DefineNestedType (Basename,
- type_attributes,
- parent,
- ifaces);
- }
+ //
+ // Structs with no fields need to have at least one byte.
+ // The right thing would be to set the PackingSize in a DefineType
+ // but there are no functions that allow interfaces *and* the size to
+ // be specified.
+ //
+
+ if (!is_class && !have_nonstatic_fields){
+ TypeBuilder.DefineField ("$PRIVATE$", TypeManager.byte_type,
+ FieldAttributes.Private);
}
// add interfaces that were not added at type creation (weird API issue)
IndexerName = class_indexer_name;
}
- static void Report1530 (Location loc)
+ static void Error_KeywordNotAllowed (Location loc)
{
Report.Error (1530, loc, "Keyword new not allowed for namespace elements");
}
if ((iface.ModFlags & Modifiers.NEW) == 0)
iface.DefineMembers (this);
else
- Report1530 (iface.Location);
+ Error_KeywordNotAllowed (iface.Location);
}
if (RootContext.WarningLevel > 1){
} else
IndexerName = "Item";
- if (operators != null)
+ if (operators != null){
DefineMembers (operators, null);
+ CheckPairedOperators ();
+ }
+
if (enums != null)
DefineMembers (enums, defined_names);
{
return FindMembers (mt, bf | BindingFlags.DeclaredOnly, null, null);
}
+
+ //
+ // Operator pair checking
+ //
+
+ class OperatorEntry {
+ public int flags;
+ public Type ret_type;
+ public Type type1, type2;
+ public Operator op;
+ public Operator.OpType ot;
+
+ public OperatorEntry (int f, Operator o)
+ {
+ flags = f;
+
+ ret_type = o.OperatorMethod.GetReturnType ();
+ Type [] pt = o.OperatorMethod.ParameterTypes;
+ type1 = pt [0];
+ type2 = pt [1];
+ op = o;
+ ot = o.OperatorType;
+ }
+
+ public override int GetHashCode ()
+ {
+ return ret_type.GetHashCode ();
+ }
+
+ public override bool Equals (object o)
+ {
+ OperatorEntry other = (OperatorEntry) o;
+
+ if (other.ret_type != ret_type)
+ return false;
+ if (other.type1 != type1)
+ return false;
+ if (other.type2 != type2)
+ return false;
+ return true;
+ }
+ }
+
+ //
+ // Checks that some operators come in pairs:
+ // == and !=
+ // > and <
+ // >= and <=
+ //
+ // They are matched based on the return type and the argument types
+ //
+ void CheckPairedOperators ()
+ {
+ Hashtable pairs = new Hashtable (null, null);
+
+ // Register all the operators we care about.
+ foreach (Operator op in operators){
+ int reg = 0;
+
+ switch (op.OperatorType){
+ case Operator.OpType.Equality:
+ reg = 1; break;
+ case Operator.OpType.Inequality:
+ reg = 2; break;
+
+ case Operator.OpType.GreaterThan:
+ reg = 1; break;
+ case Operator.OpType.LessThan:
+ reg = 2; break;
+
+ case Operator.OpType.GreaterThanOrEqual:
+ reg = 1; break;
+ case Operator.OpType.LessThanOrEqual:
+ reg = 2; break;
+ }
+ if (reg == 0)
+ continue;
+
+ OperatorEntry oe = new OperatorEntry (reg, op);
+
+ object o = pairs [oe];
+ if (o == null)
+ pairs [oe] = oe;
+ else {
+ oe = (OperatorEntry) o;
+ oe.flags |= reg;
+ }
+ }
+
+ //
+ // Look for the mistakes.
+ //
+ foreach (DictionaryEntry de in pairs){
+ OperatorEntry oe = (OperatorEntry) de.Key;
+
+ if (oe.flags == 3)
+ continue;
+
+ string s = "";
+ switch (oe.ot){
+ case Operator.OpType.Equality:
+ s = "!=";
+ break;
+ case Operator.OpType.Inequality:
+ s = "==";
+ break;
+ case Operator.OpType.GreaterThan:
+ s = "<";
+ break;
+ case Operator.OpType.LessThan:
+ s = ">";
+ break;
+ case Operator.OpType.GreaterThanOrEqual:
+ s = "<=";
+ break;
+ case Operator.OpType.LessThanOrEqual:
+ s = ">=";
+ break;
+ }
+ Report.Error (216, oe.op.Location,
+ "The operator `" + oe.op + "' requires a matching operator `" + s + "' to also be defined");
+ }
+ }
+
+
}
public class Class : TypeContainer {
Modifiers.ABSTRACT |
Modifiers.SEALED |
Modifiers.UNSAFE;
-
+
public Class (TypeContainer parent, string name, int mod, Attributes attrs, Location l)
: base (parent, name, l)
{
}
public abstract class MethodCore : MemberBase {
- public readonly Parameters Parameters;
+ public /* readonly */ Parameters Parameters;
Block block;
//
}
public void LabelParameters (EmitContext ec, Type [] parameters, MethodBase builder)
+ {
+ LabelParameters (ec, parameters, builder, null);
+ }
+
+ public void LabelParameters (EmitContext ec, Type [] parameters, MethodBase builder, Parameters p_params)
{
//
// Define each type attribute (in/out/ref) and
// the argument names.
//
- Parameter [] p = Parameters.FixedParameters;
+ Parameter [] p = p_params == null ? Parameters.FixedParameters : p_params.FixedParameters;
int i = 0;
MethodBuilder mb = null;
public Method (Expression return_type, int mod, string name, Parameters parameters,
Attributes attrs, Location l)
: base (return_type, mod, AllowedModifiers, name, attrs, parameters, l)
- { }
+ {
+ Implements = null;
+ }
+
+ public Method (Expression return_type, int mod, string name, Parameters parameters,
+ Attributes attrs, Expression impl_what, Location l)
+ : base (return_type, mod, AllowedModifiers, name, attrs, parameters, l)
+ {
+ Implements = impl_what;
+ }
//
// Returns the `System.Type' for the ReturnType of this
// function. Provides a nice cache. (used between semantic analysis
// and actual code generation
//
- public Type GetReturnType (TypeContainer parent)
+ public Type GetReturnType ()
{
return MemberType;
}
if (Name == "Main" &&
((ModFlags & Modifiers.STATIC) != 0) &&
(RootContext.MainClass == null ||
- RootContext.MainClass == parent.TypeBuilder.FullName)){
+ RootContext.MainClass == parent.TypeBuilder.FullName ||
+ (RootContext.RootNamespace != null &&
+ RootContext.RootNamespace.Length > 0 &&
+ (RootContext.RootNamespace + "." + RootContext.MainClass) == parent.TypeBuilder.FullName))) {
if (IsEntryPoint (MethodBuilder, ParameterInfo)) {
if (RootContext.EntryPoint == null) {
RootContext.EntryPoint = MethodBuilder;
loc);
if (parent_constructor_group == null){
- Report.Error (1501, loc,
- "Can not find a constructor for this argument list");
+ string s = String.Format ("'{0}': Can not find a constructor for this argument list", t);
+ Report.Error (1501, loc, s);
return false;
}
-
+
parent_constructor = (ConstructorInfo) Invocation.OverloadResolve (ec,
(MethodGroupExpr) parent_constructor_group, argument_list, loc);
if (parent_constructor == null){
- Report.Error (1501, loc,
- "Can not find a constructor for this argument list");
+ string s = String.Format ("'{0}': Can not find a constructor for this argument list", t);
+ Report.Error (1501, loc, s);
return false;
}
public void Emit (EmitContext ec)
{
- if (parent_constructor != null)
- ec.ig.Emit (OpCodes.Ldarg_0);
- if (argument_list != null)
- Invocation.EmitArguments (ec, null, argument_list);
- if (parent_constructor != null)
- ec.ig.Emit (OpCodes.Call, parent_constructor);
+ if (parent_constructor != null){
+ if (ec.IsStatic)
+ Invocation.EmitCall (ec, true, true, null, parent_constructor, argument_list, loc);
+ else
+ Invocation.EmitCall (ec, true, false, ec.This, parent_constructor, argument_list, loc);
+ }
}
}
// <summary>
// Modifiers allowed for a constructor.
// </summary>
- const int AllowedModifiers =
+ public const int AllowedModifiers =
Modifiers.PUBLIC |
Modifiers.PROTECTED |
Modifiers.INTERNAL |
Modifiers.STATIC |
Modifiers.UNSAFE |
+ Modifiers.EXTERN |
Modifiers.PRIVATE;
//
}
ca |= MethodAttributes.HideBySig;
- if ((ModFlags & Modifiers.PRIVATE) != 0)
- ca |= MethodAttributes.Private;
+ if ((ModFlags & Modifiers.PUBLIC) != 0)
+ ca |= MethodAttributes.Public;
else if ((ModFlags & Modifiers.PROTECTED) != 0){
if ((ModFlags & Modifiers.INTERNAL) != 0)
ca |= MethodAttributes.FamORAssem;
ca |= MethodAttributes.Family;
} else if ((ModFlags & Modifiers.INTERNAL) != 0)
ca |= MethodAttributes.Assembly;
- else
+ else if (IsDefault ())
ca |= MethodAttributes.Public;
+ else
+ ca |= MethodAttributes.Private;
}
ConstructorBuilder = parent.TypeBuilder.DefineConstructor (
else
name = member.ShortName;
method_name = prefix + name;
-
+
if (parent.Pending != null){
if (member is Indexer)
implementing = parent.Pending.IsInterfaceIndexer (
Location end = block.EndLocation;
MethodToken token = MethodBuilder.GetToken ();
sw.OpenMethod (new SymbolToken (token.Token));
- sw.SetMethodSourceRange (Location.SymbolDocument,
- Location.Row, 0,
- end.SymbolDocument,
- end.Row, 0);
+ // Avoid error if we don't support debugging for the platform
+ try {
+ sw.SetMethodSourceRange (Location.SymbolDocument,
+ Location.Row, 0,
+ end.SymbolDocument,
+ end.Row, 0);
+ } catch (Exception) {
+ }
- ec.EmitTopBlock (block, ParameterInfo, Location);
+ ec.EmitTopBlock (block, member.Name, ParameterInfo, Location);
sw.CloseMethod ();
} else
- ec.EmitTopBlock (block, ParameterInfo, Location);
+ ec.EmitTopBlock (block, member.Name, ParameterInfo, Location);
}
}
abstract public class MemberBase : MemberCore {
public Expression Type;
public readonly Attributes OptAttributes;
+ public Expression Implements;
protected MethodAttributes flags;
}
}
}
-
+
+ FieldAttributes fa = Modifiers.FieldAttr (ModFlags);
+
+ if (parent is Struct &&
+ ((fa & FieldAttributes.Static) == 0) &&
+ t == parent.TypeBuilder &&
+ !TypeManager.IsBuiltinType (t)){
+ Report.Error (523, Location, "Struct member `" + parent.Name + "." + Name +
+ "' causes a cycle in the structure layout");
+ return false;
+ }
FieldBuilder = parent.TypeBuilder.DefineField (
Name, t, Modifiers.FieldAttr (ModFlags));
if (!DoDefineParameters (parent))
return false;
- MethodSignature ms = new MethodSignature (Name, null, ParameterTypes);
+ if (IsExplicitImpl)
+ return true;
+
+ string report_name;
+ MethodSignature ms, base_ms;
+ if (this is Indexer) {
+ string name, base_name;
+
+ report_name = "this";
+ name = TypeManager.IndexerPropertyName (parent.TypeBuilder);
+ ms = new MethodSignature (name, null, ParameterTypes);
+ base_name = TypeManager.IndexerPropertyName (parent.TypeBuilder.BaseType);
+ base_ms = new MethodSignature (base_name, null, ParameterTypes);
+ } else {
+ report_name = Name;
+ ms = base_ms = new MethodSignature (Name, null, ParameterTypes);
+ }
+
MemberList props_this;
props_this = TypeContainer.FindMembers (
if (props_this.Count > 0) {
Report.Error (111, Location, "Class `" + parent.Name + "' " +
- "already defines a member called `" + Name + "' " +
+ "already defines a member called `" + report_name + "' " +
"with the same parameter types");
return false;
}
MemberList props_static = TypeContainer.FindMembers (
parent.TypeBuilder.BaseType, MemberTypes.Property,
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static,
- MethodSignature.inheritable_property_signature_filter, ms);
+ MethodSignature.inheritable_property_signature_filter, base_ms);
MemberList props_instance = TypeContainer.FindMembers (
parent.TypeBuilder.BaseType, MemberTypes.Property,
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance,
MethodSignature.inheritable_property_signature_filter,
- ms);
+ base_ms);
//
// Find if we have anything
inherited_set : inherited_get;
if (reference != null) {
- string name = reference.DeclaringType.Name + "." + Name;
+ string name = reference.DeclaringType.Name + "." + report_name;
if (!CheckMethodAgainstBase (parent, flags, reference, name))
return false;
return true;
}
- public void Emit (TypeContainer tc)
+ public virtual void Emit (TypeContainer tc)
{
//
// The PropertyBuilder can be null for explicit implementations, in that
//
if (PropertyBuilder != null)
Attribute.ApplyAttributes (ec, PropertyBuilder, this, OptAttributes, Location);
-
+/*
if (GetData != null)
GetData.Emit (tc, Get.Block, Get);
if (SetData != null)
SetData.Emit (tc, Set.Block, Set);
+*/
}
}
Modifiers.EXTERN |
Modifiers.VIRTUAL;
+ string set_parameter_name;
+ Parameters get_params;
+ Parameters set_params;
+
+ public Property (Expression type, string name, int mod_flags,
+ Accessor get_block, Accessor set_block,
+ Attributes attrs, Location loc, string set_name,
+ Parameters p_get, Parameters p_set)
+ : base (type, name, mod_flags, AllowedModifiers,
+ p_set,
+ get_block, set_block, attrs, loc)
+ {
+ set_parameter_name = set_name;
+ get_params = p_get;
+ set_params = p_set;
+ Implements = null;
+ }
+
+ public Property (Expression type, string name, int mod_flags,
+ Accessor get_block, Accessor set_block,
+ Attributes attrs, Location loc, string set_name,
+ Parameters p_get, Parameters p_set, Expression impl_what)
+ : base (type, name, mod_flags, AllowedModifiers,
+ p_set,
+ get_block, set_block, attrs, loc)
+ {
+ set_parameter_name = set_name;
+ get_params = p_get;
+ set_params = p_set;
+ Implements = impl_what;
+ }
+
public Property (Expression type, string name, int mod_flags,
Accessor get_block, Accessor set_block,
Attributes attrs, Location loc)
Parameters.EmptyReadOnlyParameters,
get_block, set_block, attrs, loc)
{
+ set_parameter_name = "Value";
+ get_params = Parameters.EmptyReadOnlyParameters;
+ set_params = Parameters.EmptyReadOnlyParameters;
}
public override bool Define (TypeContainer parent)
{
+ Type [] g_parameters=null, s_parameters=null;
+ Parameter [] g_parms, s_parms;
+ InternalParameters g_ip=null, s_ip=null;
+
if (!DoDefine (parent))
return false;
flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
if (Get != null) {
- Type [] parameters = TypeManager.NoTypes;
-
- InternalParameters ip = new InternalParameters (
- parent, Parameters.EmptyReadOnlyParameters);
+ if (get_params == Parameters.EmptyReadOnlyParameters)
+ {
+ g_parameters = TypeManager.NoTypes;
+ g_ip = new InternalParameters (
+ parent, Parameters.EmptyReadOnlyParameters);
+ }
+ else
+ {
+ g_parameters = new Type [get_params.FixedParameters.Length];
+ for (int i = 0; i < get_params.FixedParameters.Length; i ++)
+ {
+ g_parameters[i] = get_params.FixedParameters[i].ParameterType;
+ }
+ g_parms = new Parameter [get_params.FixedParameters.Length];
+ for (int i = 0; i < get_params.FixedParameters.Length; i ++)
+ {
+ Parameter tp = get_params.FixedParameters[i];
+ g_parms[i] = new Parameter (tp.TypeName, tp.Name,
+ Parameter.Modifier.NONE, null);
+ }
+ g_ip = new InternalParameters (
+ parent, new Parameters (g_parms, null, Location));
+ }
GetData = new MethodData (this, "get", MemberType,
- parameters, ip, CallingConventions.Standard,
+ g_parameters, g_ip, CallingConventions.Standard,
Get.OptAttributes, ModFlags, flags, false);
if (!GetData.Define (parent))
}
if (Set != null) {
- Type [] parameters = new Type [1];
- parameters [0] = MemberType;
+ if (set_params == Parameters.EmptyReadOnlyParameters)
+ {
+ s_parameters = new Type [1];
+ s_parameters [0] = MemberType;
+
+ s_parms = new Parameter [1];
+ s_parms [0] = new Parameter (Type, /* was "value" */ set_parameter_name,
+ Parameter.Modifier.NONE, null);
+ }
+ else
+ {
+ s_parameters = new Type [set_params.FixedParameters.Length];
+ for (int i = 0; i < set_params.FixedParameters.Length; i ++)
+ {
+ s_parameters[i] = set_params.FixedParameters[i].ParameterType;
+ }
+
+ s_parms = new Parameter [set_params.FixedParameters.Length];
+ for (int i = 0; i < set_params.FixedParameters.Length; i ++)
+ {
+ Parameter tp = set_params.FixedParameters[i];
+ s_parms[i] = new Parameter (tp.TypeName, tp.Name,
+ Parameter.Modifier.NONE, null);
+ }
+ }
- Parameter [] parms = new Parameter [1];
- parms [0] = new Parameter (Type, "value", Parameter.Modifier.NONE, null);
- InternalParameters ip = new InternalParameters (
- parent, new Parameters (parms, null, Location));
+ s_ip = new InternalParameters (
+ parent, new Parameters (s_parms, null, Location));
+
SetData = new MethodData (this, "set", TypeManager.void_type,
- parameters, ip, CallingConventions.Standard,
+ s_parameters, s_ip, CallingConventions.Standard,
Set.OptAttributes, ModFlags, flags, false);
if (!SetData.Define (parent))
return false;
SetBuilder = SetData.MethodBuilder;
- SetBuilder.DefineParameter (1, ParameterAttributes.None, "value");
+ SetBuilder.DefineParameter (1, ParameterAttributes.None,
+ /* was "value" */ set_parameter_name);
}
// FIXME - PropertyAttributes.HasDefault ?
}
return true;
}
+
+ public override void Emit (TypeContainer tc)
+ {
+ base.Emit (tc);
+
+ if (GetData != null)
+ {
+ Parameters = get_params;
+ GetData.Emit (tc, Get.Block, Get);
+ }
+
+ if (SetData != null)
+ {
+ Parameters = set_params;
+ SetData.Emit (tc, Set.Block, Set);
+ }
+
+ }
}
/// </summary>
parameter_types [0] = MemberType;
Parameter [] parms = new Parameter [1];
- parms [0] = new Parameter (Type, "value", Parameter.Modifier.NONE, null);
+ parms [0] = new Parameter (Type, /* was "value" */ this.Name, Parameter.Modifier.NONE, null);
InternalParameters ip = new InternalParameters (
parent, new Parameters (parms, null, Location));
return false;
AddBuilder = AddData.MethodBuilder;
- AddBuilder.DefineParameter (1, ParameterAttributes.None, "value");
+ AddBuilder.DefineParameter (1, ParameterAttributes.None, /* was "value" */ this.Name);
RemoveData = new MethodData (this, "remove", TypeManager.void_type,
parameter_types, ip, CallingConventions.Standard,
return false;
RemoveBuilder = RemoveData.MethodBuilder;
- RemoveBuilder.DefineParameter (1, ParameterAttributes.None, "value");
+ RemoveBuilder.DefineParameter (1, ParameterAttributes.None, /* was "value" */ this.Name);
if (!IsExplicitImpl){
EventBuilder = new MyEventBuilder (
if (Add == null && Remove == null) {
FieldBuilder = parent.TypeBuilder.DefineField (
- Name, MemberType, FieldAttributes.FamANDAssem);
+ Name, MemberType,
+ FieldAttributes.FamANDAssem | ((ModFlags & Modifiers.STATIC) != 0 ? FieldAttributes.Static : 0));
TypeManager.RegisterPrivateFieldOfEvent (
(EventInfo) EventBuilder, FieldBuilder);
TypeManager.RegisterFieldBase (FieldBuilder, this);
fixed_parms.CopyTo (tmp, 0);
tmp [fixed_parms.Length] = new Parameter (
- Type, "value", Parameter.Modifier.NONE, null);
+ Type, /* was "value" */ this.Name, Parameter.Modifier.NONE, null);
Parameters set_formal_params = new Parameters (tmp, null, Location);
SetBuilder.DefineParameter (
i + 1, p [i].Attributes, p [i].Name);
}
+
if (Set != null)
SetBuilder.DefineParameter (
- i + 1, ParameterAttributes.None, "value");
+ i + 1, ParameterAttributes.None, /* was "value" */ this.Name);
if (i != ParameterTypes.Length) {
Parameter array_param = Parameters.ArrayParameter;
Type [] param_types = OperatorMethod.ParameterTypes;
Type declaring_type = OperatorMethodBuilder.DeclaringType;
- Type return_type = OperatorMethod.GetReturnType (parent);
+ Type return_type = OperatorMethod.GetReturnType ();
Type first_arg_type = param_types [0];
// Rules for conversion operators
OperatorMethod.Block = Block;
OperatorMethod.Emit (parent);
}
+
+ public static string GetName (OpType ot)
+ {
+ switch (ot){
+ case OpType.LogicalNot:
+ return "!";
+ case OpType.OnesComplement:
+ return "~";
+ case OpType.Increment:
+ return "++";
+ case OpType.Decrement:
+ return "--";
+ case OpType.True:
+ return "true";
+ case OpType.False:
+ return "false";
+ case OpType.Addition:
+ return "+";
+ case OpType.Subtraction:
+ return "-";
+ case OpType.UnaryPlus:
+ return "+";
+ case OpType.UnaryNegation:
+ return "-";
+ case OpType.Multiply:
+ return "*";
+ case OpType.Division:
+ return "/";
+ case OpType.Modulus:
+ return "%";
+ case OpType.BitwiseAnd:
+ return "&";
+ case OpType.BitwiseOr:
+ return "|";
+ case OpType.ExclusiveOr:
+ return "^";
+ case OpType.LeftShift:
+ return "<<";
+ case OpType.RightShift:
+ return ">>";
+ case OpType.Equality:
+ return "==";
+ case OpType.Inequality:
+ return "!=";
+ case OpType.GreaterThan:
+ return ">";
+ case OpType.LessThan:
+ return "<";
+ case OpType.GreaterThanOrEqual:
+ return ">=";
+ case OpType.LessThanOrEqual:
+ return "<=";
+ case OpType.Implicit:
+ return "implicit";
+ case OpType.Explicit:
+ return "explicit";
+ default: return "";
+ }
+ }
+
+ public override string ToString ()
+ {
+ Type return_type = OperatorMethod.GetReturnType();
+ Type [] param_types = OperatorMethod.ParameterTypes;
+
+ if (SecondArgType == null)
+ return String.Format (
+ "{0} operator {1}({2})",
+ TypeManager.CSharpName (return_type),
+ GetName (OperatorType),
+ param_types [0]);
+ else
+ return String.Format (
+ "{0} operator {1}({2}, {3})",
+ TypeManager.CSharpName (return_type),
+ GetName (OperatorType),
+ param_types [0], param_types [1]);
+ }
}
//
/// </summary>
public static MemberFilter method_signature_filter;
+ /// <summary>
+ /// This delegate is used to extract methods which have the
+ /// same signature as the argument except for the name
+ /// </summary>
+ public static MemberFilter method_signature_noname_filter;
+
/// <summary>
/// This delegate is used to extract inheritable methods which
/// have the same signature as the argument. By inheritable,
static MethodSignature ()
{
method_signature_filter = new MemberFilter (MemberSignatureCompare);
+ method_signature_noname_filter = new MemberFilter (MemberSignatureCompareNoName);
inheritable_method_signature_filter = new MemberFilter (
InheritableMemberSignatureCompare);
inheritable_property_signature_filter = new MemberFilter (
return true;
}
+ static bool MemberSignatureCompareNoName (MemberInfo m, object filter_criteria)
+ {
+ return MemberSignatureCompare (m, filter_criteria, false);
+ }
+
static bool MemberSignatureCompare (MemberInfo m, object filter_criteria)
+ {
+ return MemberSignatureCompare (m, filter_criteria, true);
+ }
+
+ static bool MemberSignatureCompare (MemberInfo m, object filter_criteria, bool use_name)
{
MethodSignature sig = (MethodSignature) filter_criteria;
- if (m.Name != sig.Name)
+ if (use_name && (m.Name != sig.Name))
return false;
Type ReturnType;