Fixed overloaded constructor invocation
[mono.git] / mcs / mbas / class.cs
index 8171bc6d1292672bacbea95579a8e0350b540cee..cd16de718c72dae11491555750d80d7047a7d9fe 100644 (file)
@@ -188,13 +188,27 @@ namespace Mono.CSharp {
                public AdditionResult AddClass (Class c)
                {
                        AdditionResult res;
-
+                       
                        if ((res = IsValid (c.Basename)) != AdditionResult.Success)
                                return res;
-
+                               
+       
+                                       
                        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;
                }
 
@@ -314,8 +328,8 @@ namespace Mono.CSharp {
                        
                        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 ();
 
@@ -1958,7 +1972,7 @@ namespace Mono.CSharp {
                        Modifiers.ABSTRACT |
                        Modifiers.SEALED |
                        Modifiers.UNSAFE;
-
+               
                public Class (TypeContainer parent, string name, int mod, Attributes attrs, Location l)
                        : base (parent, name, l)
                {
@@ -2185,7 +2199,16 @@ namespace Mono.CSharp {
                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
@@ -2362,7 +2385,10 @@ namespace Mono.CSharp {
                        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;
@@ -2443,17 +2469,17 @@ namespace Mono.CSharp {
                                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;
                        }
                        
@@ -3136,6 +3162,7 @@ namespace Mono.CSharp {
        abstract public class MemberBase : MemberCore {
                public Expression Type;
                public readonly Attributes OptAttributes;
+               public Expression Implements;
 
                protected MethodAttributes flags;
 
@@ -3616,7 +3643,7 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public void Emit (TypeContainer tc)
+               public virtual void Emit (TypeContainer tc)
                {
                        //
                        // The PropertyBuilder can be null for explicit implementations, in that
@@ -3659,13 +3686,28 @@ namespace Mono.CSharp {
                                Attributes attrs, Location loc, string set_name, 
                                Parameters p_get, Parameters p_set)
                        : base (type, name, mod_flags, AllowedModifiers,
-                               p_set, // FIXME ???????????
+                               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,
@@ -3802,17 +3844,17 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public void Emit (TypeContainer tc)
+               public override void Emit (TypeContainer tc)
                {
                        base.Emit (tc);
                        
-                       if (GetData != null) \r
+                       if (GetData != null) 
                        {
                                Parameters = get_params;
                                GetData.Emit (tc, Get.Block, Get);
                        }
 
-                       if (SetData != null) \r
+                       if (SetData != null) 
                        {
                                Parameters = set_params;
                                SetData.Emit (tc, Set.Block, Set);
@@ -4629,6 +4671,12 @@ namespace Mono.CSharp {
                /// </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,
@@ -4648,6 +4696,7 @@ namespace Mono.CSharp {
                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 (
@@ -4700,11 +4749,21 @@ namespace Mono.CSharp {
                        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;