2004-09-01 Marek Safar <marek.safar@seznam.cz>
authorMarek Safar <marek.safar@gmail.com>
Wed, 1 Sep 2004 18:01:56 +0000 (18:01 -0000)
committerMarek Safar <marek.safar@gmail.com>
Wed, 1 Sep 2004 18:01:56 +0000 (18:01 -0000)
C# 2.0 Static classes implemented

* class.cs (TypeContainer): instance_constructors,
initialized_fields, initialized_static_fields,
default_constructor, base_inteface_types are protected to be
accessible from StaticClass.
(TypeContainer.DefineDefaultConstructor): New virtual method
for custom default constructor generating
(StaticClass): New class to handle "Static classes" feature.

* cs-parser.jay: Handle static keyword on class like instance
of StaticClass.

* driver.cs: Added "/langversion" command line switch with two
options (iso-1, default).

svn path=/trunk/mcs/; revision=33169

mcs/mcs/ChangeLog
mcs/mcs/class.cs
mcs/mcs/cs-parser.jay
mcs/mcs/decl.cs
mcs/mcs/driver.cs
mcs/mcs/expression.cs
mcs/mcs/parameter.cs
mcs/mcs/report.cs
mcs/mcs/rootcontext.cs
mcs/mcs/statement.cs

index 6ea4e41782613f596181efabb4fd6e9405166413..c86bf39038e4defa137c3149dc2740da5d35d9bb 100755 (executable)
@@ -1,3 +1,21 @@
+2004-09-01  Marek Safar  <marek.safar@seznam.cz>
+
+       C# 2.0 Static classes implemented
+
+       * class.cs (TypeContainer): instance_constructors,
+       initialized_fields, initialized_static_fields,
+       default_constructor, base_inteface_types are protected to be
+       accessible from StaticClass.
+       (TypeContainer.DefineDefaultConstructor): New virtual method
+       for custom default constructor generating
+       (StaticClass): New class to handle "Static classes" feature.
+
+       * cs-parser.jay: Handle static keyword on class like instance
+       of StaticClass.
+
+       * driver.cs: Added "/langversion" command line switch with two
+       options (iso-1, default).
+
 2004-08-31  Marek Safar  <marek.safar@seznam.cz>
 
        * ecore.cs (FieldExpr.Resolve): Fixed bug #64689.
index 72ffaf02804db14367b230008bbf6489e573d087..6d5a6497bd985867dbb971acafb4dd4a7a502992 100755 (executable)
@@ -36,6 +36,7 @@ using System.Reflection;
 using System.Reflection.Emit;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
+using System.Text;
 
 using Mono.CompilerServices.SymbolWriter;
 
@@ -221,7 +222,7 @@ namespace Mono.CSharp {
                                {
                                        flags = f;
 
-                                       ret_type = o.OperatorMethod.GetReturnType ();
+                                       ret_type = o.OperatorMethod.ReturnType;
                                        Type [] pt = o.OperatorMethod.ParameterTypes;
                                        type1 = pt [0];
                                        type2 = pt [1];
@@ -382,16 +383,16 @@ namespace Mono.CSharp {
                MemberCoreArrayList delegates;
                
                // Holds the list of constructors
-               MemberCoreArrayList instance_constructors;
+               protected MemberCoreArrayList instance_constructors;
 
                // Holds the list of fields
                MemberCoreArrayList fields;
 
                // Holds a list of fields that have initializers
-               ArrayList initialized_fields;
+               protected ArrayList initialized_fields;
 
                // Holds a list of static fields that have initializers
-               ArrayList initialized_static_fields;
+               protected ArrayList initialized_static_fields;
 
                // Holds the list of constants
                MemberCoreArrayList constants;
@@ -423,8 +424,8 @@ namespace Mono.CSharp {
                //
                // Pointers to the default constructor and the default static constructor
                //
-               Constructor default_constructor;
-               Constructor default_static_constructor;
+               protected Constructor default_constructor;
+               protected Constructor default_static_constructor;
 
                //
                // Whether we have seen a static constructor for this class or not
@@ -450,7 +451,7 @@ namespace Mono.CSharp {
 
                // The interfaces we implement.
                TypeExpr [] ifaces;
-               Type[] base_inteface_types;
+               protected Type[] base_inteface_types;
 
                // The parent member container and our member cache
                IMemberContainer parent_container;
@@ -977,47 +978,6 @@ namespace Mono.CSharp {
                        return true;
                }
                
-               //
-               // Defines the default constructors
-               //
-               void DefineDefaultConstructor (bool is_static)
-               {
-                       Constructor c;
-
-                       // The default constructor is public
-                       // If the class is abstract, the default constructor is protected
-                       // The default static constructor is private
-
-                       int mods = Modifiers.PUBLIC;
-                       if (is_static)
-                               mods = Modifiers.STATIC | Modifiers.PRIVATE;
-                       else if ((ModFlags & Modifiers.ABSTRACT) != 0)
-                               mods = Modifiers.PROTECTED;
-
-                       c = new Constructor (this, Basename, mods, Parameters.EmptyReadOnlyParameters,
-                                            new ConstructorBaseInitializer (
-                                                    null, Parameters.EmptyReadOnlyParameters,
-                                                    Location),
-                                            Location);
-                       
-                       AddConstructor (c);
-                       
-                       c.Block = new ToplevelBlock (null, Location);
-                       
-               }
-
-               public void ReportStructInitializedInstanceError ()
-               {
-                       string n = TypeBuilder.FullName;
-                       
-                       foreach (Field f in initialized_fields){
-                               Report.Error (
-                                       573, Location,
-                                       "`" + n + "." + f.Name + "': can not have " +
-                                       "instance field initializers in structs");
-                       }
-               }
-
                /// <remarks>
                ///  The pending methods that need to be implemented
                //   (interfaces or abstract methods)
@@ -1161,15 +1121,13 @@ namespace Mono.CSharp {
 
                        if ((parent != null) && (Kind == Kind.Class)){
                                if (parent.IsSealed){
-                                       string detail = "";
-                                       
-                                       if (parent.IsValueType)
-                                               detail = " (a class can not inherit from a struct/enum)";
-                                       
-                                       Report.Error (509, "class `"+ Name +
-                                                     "': Cannot inherit from sealed class `"+
-                                                     parent.Name + "'" + detail);
                                        error = true;
+                                       Report.SymbolRelatedToPreviousError (parent.Type);
+                                       if (parent.Type.IsAbstract) {
+                                               Report.Error (709, Location, "'{0}': Cannot derive from static class", GetSignatureForError ());
+                                       } else {
+                                               Report.Error (509, Location, "'{0}': Cannot derive from sealed class", GetSignatureForError ());
+                                       }
                                        return null;
                                }
 
@@ -1298,23 +1256,29 @@ namespace Mono.CSharp {
                        if (parent != null)
                                base_class_type = parent.ResolveType (ec);
 
-                       if (IsTopLevel){
-                               if (TypeManager.NamespaceClash (Name, Location)) {
-                                       error = true;
-                                       return null;
-                               }
+                       try {
+                               if (IsTopLevel){
+                                       if (TypeManager.NamespaceClash (Name, Location)) {
+                                               error = true;
+                                               return null;
+                                       }
                                
-                               ModuleBuilder builder = CodeGen.Module.Builder;
-                               TypeBuilder = builder.DefineType (
-                                       Name, type_attributes, base_class_type, null);
+                                       ModuleBuilder builder = CodeGen.Module.Builder;
+                                       TypeBuilder = builder.DefineType (
+                                               Name, type_attributes, base_class_type, null);
                                
-                       } else {
-                               TypeBuilder builder = Parent.DefineType ();
-                               if (builder == null)
-                                       return null;
+                               } else {
+                                       TypeBuilder builder = Parent.DefineType ();
+                                       if (builder == null)
+                                               return null;
                                
-                               TypeBuilder = builder.DefineNestedType (
-                                       Basename, type_attributes, base_class_type, null);
+                                       TypeBuilder = builder.DefineNestedType (
+                                               Basename, type_attributes, base_class_type, null);
+                               }
+                       }
+                       catch (ArgumentException) {
+                               Report.RuntimeMissingSupport ("static classes");
+                               return null;
                        }
                                
                        //
@@ -1401,6 +1365,11 @@ namespace Mono.CSharp {
                        Report.Error (1530, loc, "Keyword new not allowed for namespace elements");
                }
 
+               protected virtual void DefineDefaultConstructor ()
+               {
+                       // Nothing to do
+               }
+
                /// <summary>
                ///   Populates our TypeBuilder with fields and methods
                /// </summary>
@@ -1452,37 +1421,10 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       if (constants != null)
-                               constants.DefineContainerMembers ();
-
-                       if (fields != null)
-                               fields.DefineContainerMembers ();
-
-                       if ((Kind == Kind.Class) && !(this is ClassPart)){
-                               if (instance_constructors == null){
-                                       if (default_constructor == null)
-                                               DefineDefaultConstructor (false);
-                               }
-
-                               if (initialized_static_fields != null &&
-                                   default_static_constructor == null)
-                                       DefineDefaultConstructor (true);
-                       }
-
-                       if (Kind == Kind.Struct){
-                               //
-                               // Structs can not have initialized instance
-                               // fields
-                               //
-                               if (initialized_static_fields != null &&
-                                   default_static_constructor == null)
-                                       DefineDefaultConstructor (true);
-
-                               if (initialized_fields != null)
-                                       ReportStructInitializedInstanceError ();
-                       }
+                       DefineContainerMembers (constants);
+                       DefineContainerMembers (fields);
 
-                       Pending = GetPendingImplementations ();
+                       DefineDefaultConstructor ();
 
                        if (parts != null) {
                                foreach (ClassPart part in parts) {
@@ -1494,32 +1436,18 @@ namespace Mono.CSharp {
                        //
                        // Constructors are not in the defined_names array
                        //
-                       if (instance_constructors != null)
-                               instance_constructors.DefineContainerMembers ();
+                       DefineContainerMembers (instance_constructors);
                
                        if (default_static_constructor != null)
                                default_static_constructor.Define ();
                        
-                       if (methods != null)
-                               methods.DefineContainerMembers ();
-
-                       if (properties != null)
-                               properties.DefineContainerMembers ();
-
-                       if (events != null)
-                               events.DefineContainerMembers ();
-
-                       if (indexers != null)
-                               indexers.DefineContainerMembers ();
-
-                       if (operators != null)
-                               operators.DefineContainerMembers ();
-
-                       if (enums != null)
-                               enums.DefineContainerMembers ();
-                       
-                       if (delegates != null)
-                               delegates.DefineContainerMembers ();
+                       DefineContainerMembers (methods);
+                       DefineContainerMembers (properties);
+                       DefineContainerMembers (events);
+                       DefineContainerMembers (indexers);
+                       DefineContainerMembers (operators);
+                       DefineContainerMembers (enums);
+                       DefineContainerMembers (delegates);                     
 
 #if CACHE
                        if (!(this is ClassPart))
@@ -1546,6 +1474,12 @@ namespace Mono.CSharp {
                        return true;
                }
 
+               protected virtual void DefineContainerMembers (MemberCoreArrayList mcal)
+               {
+                       if (mcal != null)
+                               mcal.DefineContainerMembers ();
+               }
+
                public override bool Define ()
                {
                        if (parts != null) {
@@ -2712,6 +2646,40 @@ namespace Mono.CSharp {
                        return PendingImplementation.GetPendingImplementations (this);
                }
 
+               //
+               // Defines the default constructors
+               //
+               protected void DefineDefaultConstructor (bool is_static)
+               {
+                       Constructor c;
+
+                       // The default constructor is public
+                       // If the class is abstract, the default constructor is protected
+                       // The default static constructor is private
+
+                       int mods = Modifiers.PUBLIC;
+                       if (is_static)
+                               mods = Modifiers.STATIC | Modifiers.PRIVATE;
+                       else if ((ModFlags & Modifiers.ABSTRACT) != 0)
+                               mods = Modifiers.PROTECTED;
+
+                       c = new Constructor (this, Basename, mods, Parameters.EmptyReadOnlyParameters,
+                                            new ConstructorBaseInitializer (
+                                                    null, Parameters.EmptyReadOnlyParameters,
+                                                    Location),
+                                            Location);
+                       
+                       AddConstructor (c);
+                       
+                       c.Block = new ToplevelBlock (null, Location);
+                       
+               }
+
+               protected override void DefineDefaultConstructor ()
+               {
+                       Pending = PendingImplementation.GetPendingImplementations (this);
+               }
+
                protected override void VerifyMembers (EmitContext ec) 
                {
                        if (Fields != null) {
@@ -2750,6 +2718,83 @@ namespace Mono.CSharp {
                }
        }
 
+       /// <summary>
+       /// Class handles static classes declaration
+       /// </summary>
+       public sealed class StaticClass: Class {
+               public StaticClass (NamespaceEntry ns, TypeContainer parent, string name, int mod,
+                       Attributes attrs, Location l)
+                       : base (ns, parent, name, mod & ~Modifiers.STATIC, attrs, l)
+               {
+                       if (RootContext.Version == LanguageVersion.ISO_1) {
+                               Report.FeatureIsNotStandardized ("static classes");
+                               Environment.Exit (1);
+                       }
+               }
+
+               // Only static fields are allowed
+               protected override void DefineDefaultConstructor ()
+               {
+                       if (initialized_static_fields != null &&
+                               default_static_constructor == null)
+                               DefineDefaultConstructor (true);
+               }
+
+               protected override void DefineContainerMembers (MemberCoreArrayList list)
+               {
+                       if (list == null)
+                               return;
+
+                       foreach (MemberCore m in list) {
+                               if (m is Operator) {
+                                       Report.Error (715, m.Location, "'{0}': static classes cannot contain user-defined operators", m.GetSignatureForError (this));
+                                       continue;
+                               }
+
+                               if ((m.ModFlags & Modifiers.STATIC) != 0)
+                                       continue;
+
+                               if (m is Constructor) {
+                                       Report.Error (710, m.Location, "'{0}': Static classes cannot have instance constructors", GetSignatureForError ());
+                                       continue;
+                               }
+
+                               if (m is Destructor) {
+                                       Report.Error (711, m.Location, "'{0}': Static class cannot contain destructor", GetSignatureForError ());
+                                       continue;
+                               }
+                               Report.Error (708, m.Location, "'{0}': cannot declare instance members in a static class", m.GetSignatureForError (this));
+                       }
+
+                       base.DefineContainerMembers (list);
+               }
+
+               public override TypeBuilder DefineType()
+               {
+                       TypeBuilder tb = base.DefineType ();
+                       if (tb == null)
+                               return null;
+
+                       if (base_class_type != TypeManager.object_type) {
+                               Report.Error (713, Location, "Static class '{0}' cannot derive from type '{1}'. Static classes must derive from object", GetSignatureForError (), TypeManager.CSharpName (base_class_type));
+                               return null;
+                       }
+
+                       if (base_inteface_types != null) {
+                               foreach (Type t in base_inteface_types)
+                                       Report.SymbolRelatedToPreviousError (t);
+                               Report.Error (714, Location, "'{0}': static classes cannot implement interfaces", GetSignatureForError ());
+                       }
+                       return tb;
+               }
+
+               public override TypeAttributes TypeAttr {
+                       get {
+                               return base.TypeAttr | TypeAttributes.Abstract | TypeAttributes.Sealed;
+                       }
+               }
+       }
+
        public class Class : ClassOrStruct {
                // <summary>
                //   Modifiers allowed in a class declaration
@@ -2806,6 +2851,17 @@ namespace Mono.CSharp {
                        }
                }
 
+               protected override void DefineDefaultConstructor ()
+               {
+                       if (instance_constructors == null && default_constructor == null)
+                               DefineDefaultConstructor (false);
+
+                       if (initialized_static_fields != null && default_static_constructor == null)
+                               DefineDefaultConstructor (true);
+
+                       base.DefineDefaultConstructor ();
+               }
+
                public override void Register ()
                {
                        CheckDef (Parent.AddClass (this), Name, Location);
@@ -2859,6 +2915,24 @@ namespace Mono.CSharp {
                        }
                }
 
+               protected override void DefineDefaultConstructor ()
+               {
+                       //
+                       // Structs can not have initialized instance
+                       // fields
+                       //
+                       if (initialized_static_fields != null &&
+                               default_static_constructor == null)
+                               DefineDefaultConstructor (true);
+
+                       if (initialized_fields != null) {
+                               foreach (Field f in initialized_fields)
+                                       Report.Error (573, f.Location, "'{0}': cannot have instance field initializers in structs", f.GetSignatureForError ());
+                       }
+
+                       base.DefineDefaultConstructor ();
+               }
+
                public override void Register ()
                {
                        CheckDef (Parent.AddStruct (this), Name, Location);
@@ -3203,6 +3277,12 @@ namespace Mono.CSharp {
                                "member `" + name + "'");
                }
 
+               protected static string Error722 {
+                       get {
+                               return "'{0}': static types cannot be used as return types";
+                       }
+               }
+
                /// <summary>
                /// For custom member duplication search in a container
                /// </summary>
@@ -3416,16 +3496,6 @@ namespace Mono.CSharp {
                        }
                }
                
-               //
-               // 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 ()
-               {
-                       return MemberType;
-               }
-
                public override string GetSignatureForError()
                {
                        return TypeManager.CSharpSignature (MethodBuilder);
@@ -3606,6 +3676,11 @@ namespace Mono.CSharp {
                                }
                        }
 
+                       if (MemberType.IsAbstract && MemberType.IsSealed) {
+                               Report.Error (722, Location, Error722, TypeManager.CSharpName (MemberType));
+                               return false;
+                       }
+
                        return true;
                }
 
@@ -3670,12 +3745,6 @@ namespace Mono.CSharp {
                        }
                }
 
-               public Type ReturnType {
-                       get {
-                               return MemberType;
-                       }
-               }
-
                public string MethodName {
                        get {
                                return ShortName;
@@ -3745,6 +3814,12 @@ namespace Mono.CSharp {
                        return false;
                }
 
+               public Type ReturnType {
+                       get {
+                               return MemberType;
+                       }
+               }
+
                #endregion
        }
 
@@ -4872,12 +4947,9 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               /// <summary>
-               /// Use this method when MethodBuilder is null
-               /// </summary>
-               public virtual string GetSignatureForError (TypeContainer tc)
+               public override string GetSignatureForError (TypeContainer tc)
                {
-                       return String.Concat (tc.Name, '.', Name);
+                       return String.Concat (tc.Name, '.', base.GetSignatureForError (tc));
                }
 
                protected override bool VerifyClsCompliance(DeclSpace ds)
@@ -5522,8 +5594,12 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       ec = new EmitContext (Parent, Location, null, MemberType, ModFlags);
+                       if (MemberType.IsAbstract && MemberType.IsSealed) {
+                               Report.Error (722, Location, Error722, TypeManager.CSharpName (MemberType));
+                               return false;
+                       }
 
+                       ec = new EmitContext (Parent, Location, null, MemberType, ModFlags);
                        return true;
                }
 
@@ -6521,7 +6597,7 @@ namespace Mono.CSharp {
 
                public override string GetSignatureForError(TypeContainer tc)
                {
-                       return String.Concat (tc.Name, ".this[", TypeManager.CSharpName (ParameterTypes [0]), ']');
+                       return String.Concat (tc.Name, ".this[", Parameters.FixedParameters [0].TypeName.ToString (), ']');
                }
        }
 
@@ -6604,12 +6680,6 @@ namespace Mono.CSharp {
                        Block = block;
                }
 
-               string Prototype (TypeContainer container)
-               {
-                       return container.Name + ".operator " + OperatorType + " (" + FirstArgType + "," +
-                               SecondArgType + ")";
-               }
-
                public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb) 
                {
                        OperatorMethod.ApplyAttributeBuilder (a, cb);
@@ -6635,7 +6705,7 @@ namespace Mono.CSharp {
                                Report.Error (
                                        558, Location, 
                                        "User defined operators `" +
-                                       Prototype (Parent) +
+                                       GetSignatureForError (Parent) +
                                        "' must be declared static and public");
                                return false;
                        }
@@ -6663,7 +6733,7 @@ namespace Mono.CSharp {
 
                        Type [] param_types = OperatorMethod.ParameterTypes;
                        Type declaring_type = OperatorMethodBuilder.DeclaringType;
-                       Type return_type = OperatorMethod.GetReturnType ();
+                       Type return_type = OperatorMethod.ReturnType;
                        Type first_arg_type = param_types [0];
 
                        // Rules for conversion operators
@@ -6831,19 +6901,27 @@ namespace Mono.CSharp {
                        }
                }
 
-               public override string GetSignatureForError(TypeContainer tc)
+               public override string GetSignatureForError (TypeContainer tc)
                {
-                       return ToString ();
+                       StringBuilder sb = new StringBuilder ();
+                       sb.AppendFormat ("{0}.operator {1} {2}({3}", tc.Name, GetName (OperatorType), ReturnType.ToString (), TypeManager.CSharpName (FirstArgType.Type));
+                       
+                       if (SecondArgType != null) {
+                               sb.Append (",");
+                               sb.Append (TypeManager.CSharpName (SecondArgType.Type));
+                       }
+                       sb.Append (")");
+                       return sb.ToString ();
                }
 
-               public override string GetSignatureForError()
+               public override string GetSignatureForError ()
                {
                        return ToString ();
                }
                
                public override string ToString ()
                {
-                       Type return_type = OperatorMethod.GetReturnType();
+                       Type return_type = OperatorMethod.ReturnType;
                        Type [] param_types = OperatorMethod.ParameterTypes;
                        
                        if (SecondArgType == null)
index ff51fc04c88ae68ba0f646a84e7c9b0064a647cd..a8d8e24c383af3beb7036c087af68b6ad7e6fa38 100755 (executable)
@@ -2920,19 +2920,23 @@ class_declaration
          {
                string name = MakeName ((string) $5);
                bool partial = (bool) $3;
+               int mod_flags = (int) $2;
 
                if (partial) {
                        ClassPart part = PartialContainer.CreatePart (
-                               current_namespace, current_container, name, (int) $2,
+                               current_namespace, current_container, name, mod_flags,
                                (Attributes) $1, Kind.Class, lexer.Location);
 
                        current_container = part.PartialContainer;
                        current_class = part;
                } else {
-                       current_class = new Class (
-                               current_namespace, current_container, name, (int) $2,
-                               (Attributes) $1, lexer.Location);
-
+                       if ((mod_flags & Modifiers.STATIC) != 0) {
+                               current_class = new StaticClass (current_namespace, current_container, name, mod_flags, 
+                                               (Attributes) $1, lexer.Location);
+                       } else {
+                               current_class = new Class (current_namespace, current_container, name, mod_flags, 
+                                               (Attributes) $1, lexer.Location);
+                       }
                        current_container = current_class;
                        RootContext.Tree.RecordDecl (name, current_class);
                }
index f7a2e9e2a11ee6f16d9d386c3350c19a94ae34a5..7d5088359b4628407660c5fffbb4aed18fa2ff43 100755 (executable)
@@ -96,6 +96,14 @@ namespace Mono.CSharp {
                        return Name;
                }
 
+               /// <summary>
+               /// Use this method when MethodBuilder is null
+               /// </summary>
+               public virtual string GetSignatureForError (TypeContainer tc)
+               {
+                       return Name;
+               }
+
                /// <summary>
                /// Base Emit method. This is also entry point for CLS-Compliant verification.
                /// </summary>
index 553b45e7f01ff43e2a79bb08f782128e44302e21..4f9e4b0989efa7f159e6ae9c61a0cd3f1660a91f 100755 (executable)
@@ -224,6 +224,7 @@ namespace Mono.CSharp
                                "   -g                 Generate debugging information\n" +
                                "   -keycontainer:NAME The key pair container used to strongname the assembly\n" +
                                "   -keyfile:FILE      The strongname key file used to strongname the assembly\n" +
+                               "   -langversion:TEXT  Specifies language version modes: ISO-1 or Default" + Environment.NewLine +
                                "   -lib:PATH1,PATH2   Adds the paths to the assembly link path\n" +
                                "   -main:class        Specified the class that contains the entry point\n" +
                                "   -noconfig[+|-]     Disables implicit references to assemblies\n" +
@@ -1264,9 +1265,24 @@ namespace Mono.CSharp
 
                        case "/v2":
                        case "/2":
+                               Console.WriteLine ("The compiler option -2 is obsolete. Please use /langversion instead");
                                SetupV2 ();
                                return true;
                                
+                       case "/langversion":
+                               switch (value.ToLower (CultureInfo.InvariantCulture)) {
+                                       case "iso-1":
+                                               RootContext.Version = LanguageVersion.ISO_1;
+                                               return true;
+
+                                       case "default":
+                                               SetupV2 ();
+                                               return true;
+                               }
+                               Report.Error (1617, "Invalid option '{0}' for /langversion; must be ISO-1 or Default", value);
+                               Environment.Exit (1);
+                               return false;
+
                        case "/codepage":
                                int cp = -1;
 
@@ -1293,6 +1309,7 @@ namespace Mono.CSharp
                                }
                                return true;
                        }
+
                        //Report.Error (2007, String.Format ("Unrecognized command-line option: '{0}'", option));
                        //Environment.Exit (1);
                        return false;
index 3d78d8194c4448b281f08ef12e48d26723f7c059..8b644ecab6de7aa63c3f15c61794594ee1c620c3 100755 (executable)
@@ -1770,6 +1770,11 @@ namespace Mono.CSharp {
 
                        CheckObsoleteAttribute (type);
 
+                       if (type.IsAbstract && type.IsSealed) {
+                               Report.Error (716, loc, "Cannot convert to static type '{0}'", TypeManager.CSharpName (type));
+                               return null;
+                       }
+
                        eclass = ExprClass.Value;
 
                        if (expr is Constant){
@@ -5541,6 +5546,11 @@ namespace Mono.CSharp {
                                return RequestedType;
                        }
 
+                       if (type.IsAbstract && type.IsSealed) {
+                               Report.Error (712, loc, "Cannot create an instance of the static class '{0}'", TypeManager.CSharpName (type));
+                               return null;
+                       }
+
                        if (type.IsInterface || type.IsAbstract){
                                Error (144, "It is not possible to create instances of interfaces or abstract classes");
                                return null;
@@ -6060,6 +6070,11 @@ namespace Mono.CSharp {
                        
                        array_element_type = TypeManager.GetElementType (type);
 
+                       if (array_element_type.IsAbstract && array_element_type.IsSealed) {
+                               Report.Error (719, loc, "'{0}': array elements cannot be of static type", TypeManager.CSharpName (array_element_type));
+                               return null;
+                       }
+
                        if (arg_count == 1) {
                                is_one_dimensional = true;
                                eclass = ExprClass.Value;
index bc231f51ebdef23819586384683269723b525938..f836a138c91297db89aa89eb2fe0687bb94fa927 100755 (executable)
@@ -155,6 +155,11 @@ namespace Mono.CSharp {
                {
                        parameter_type = ds.ResolveType (TypeName, false, l);
 
+                       if (parameter_type.IsAbstract && parameter_type.IsSealed) {
+                               Report.Error (721, l, "'{0}': static types cannot be used as parameters", GetSignatureForError ());
+                               return false;
+                       }
+
                        if (parameter_type == TypeManager.void_type){
                                Report.Error (1536, l, "`void' parameter is not permitted");
                                return false;
index d29ad262685e9452f9b0829a5878cc0b4175029d..fee92c8afbcff2ccad21a4e29da6f487bd9d0d12 100644 (file)
@@ -74,6 +74,11 @@ namespace Mono.CSharp {
                                Environment.Exit (0);
                        }
                }
+
+               public static void FeatureIsNotStandardized (string feature)
+               {
+                       Report.Error (1644, "Feature '{0}' cannot be used because it is not part of the standardized ISO C# language specification", feature);
+               }
                
                public static string FriendlyStackTrace (Exception e)
                {
@@ -119,7 +124,12 @@ namespace Mono.CSharp {
                static public void LocationOfPreviousError (Location loc)
                {
                        Console.WriteLine (String.Format ("{0}({1}) (Location of symbol related to previous error)", loc.Name, loc.Row));
-               }                
+               }    
+        
+               static public void RuntimeMissingSupport (string feature) 
+               {
+                       Report.Error (-88, "Your .NET Runtime does not support '{0}'. Please use the latest Mono runtime instead.");
+               }
 
                /// <summary>
                /// In most error cases is very useful to have information about symbol that caused the error.
@@ -155,7 +165,11 @@ namespace Mono.CSharp {
 
                static public void SymbolRelatedToPreviousError (Type type)
                {
-                       SymbolRelatedToPreviousError (type.Assembly.Location, TypeManager.CSharpName (type));
+                       DeclSpace temp_ds = TypeManager.LookupDeclSpace (type);
+                       if (temp_ds == null)
+                               SymbolRelatedToPreviousError (type.Assembly.Location, TypeManager.CSharpName (type));
+                       else 
+                               SymbolRelatedToPreviousError (temp_ds.Location, TypeManager.CSharpName (type));
                }
 
                static void SymbolRelatedToPreviousError (string loc, string symbol)
index c5aae10173ce2a8ad85dd872cfc9eeb188e35829..9628934b91a2188238a2cf26a67aa919f4420154 100755 (executable)
@@ -16,6 +16,12 @@ using System.Diagnostics;
 
 namespace Mono.CSharp {
 
+       public enum LanguageVersion
+       {
+               Default = 0,
+               ISO_1   = 1
+       }
+
        public class RootContext {
 
                //
@@ -66,8 +72,11 @@ namespace Mono.CSharp {
                //
                // If set, enable C# version 2 features
                //
+               [Obsolete ("Please use LanguageVersion enum insted")]
                public static bool V2 = true;
 
+               public static LanguageVersion Version = LanguageVersion.Default;
+
                //
                // We keep strongname related info here because
                // it's also used as complier options from CSC 8.x
index fcd8197b49f76702b36258fdcc698cc4fbb1cd3c..1e112fc8446f94c79eb624c05fab27d02e24eebe 100755 (executable)
@@ -1022,6 +1022,10 @@ namespace Mono.CSharp {
                        if (VariableType == null)
                                return false;
 
+                       if (VariableType.IsAbstract && VariableType.IsSealed) {
+                               Report.Error (723, Location, "Cannot declare variable of static type '{0}'", TypeManager.CSharpName (VariableType));
+                               return false;
+                       }
 // TODO: breaks the build
 //                     if (VariableType.IsPointer && !ec.InUnsafe)
 //                             Expression.UnsafeError (Location);