2004-08-04 Anirban Bhattacharjee <banirban@novell.com>
[mono.git] / mcs / mbas / class.cs
index 1cae5aae28f3d24f9ef6100a6cef487eaa7b83e8..8f9d087943a167c1618203060aa6f4a290025b81 100644 (file)
@@ -4,6 +4,7 @@
 //
 // Authors: Miguel de Icaza (miguel@gnu.org)
 //          Martin Baulig (martin@gnome.org)
+//                     Anirban Bhattacharjee (banirban@novell.com)
 //
 // Licensed under the terms of the GNU GPL
 //
@@ -88,6 +89,9 @@ namespace Mono.MonoBASIC {
                // Holds the operators
                ArrayList operators;
 
+               // Holds AddHandlers stements for events
+               ArrayList handlers;
+
                // The emit context for toplevel objects.
                EmitContext ec;
 
@@ -415,6 +419,15 @@ namespace Mono.MonoBASIC {
                        return AdditionResult.Success;
                }
 
+               public AdditionResult AddEventHandler (Statement stmt)
+               {
+                       if (handlers == null)
+                               handlers = new ArrayList ();
+
+                       handlers.Add (stmt);
+                       return AdditionResult.Success;
+               }
+
                public void RegisterOrder (Interface iface)
                {
                        if (interface_order == null)
@@ -533,6 +546,12 @@ namespace Mono.MonoBASIC {
                        }
                }
 
+               public ArrayList EventHandlers {
+                       get {
+                               return handlers;
+                       }
+               }
+
                //
                // Emits the instance field initializers
                //
@@ -586,15 +605,17 @@ namespace Mono.MonoBASIC {
                        int mods = 0;
 
                        c = new Constructor ("New", Parameters.EmptyReadOnlyParameters,
-                                            new ConstructorBaseInitializer (
-                                                    null, Parameters.EmptyReadOnlyParameters,
-                                                    Location.Null),
+                                            null,
                                             Location.Null);
                        
-                       if (is_static)
+                       if (is_static) {
                                mods = Modifiers.STATIC;
-
-                       c.ModFlags |= mods;
+                               c.ModFlags = mods;
+                       }
+                       else 
+                               c.Initializer = new ConstructorBaseInitializer (
+                                       null, Parameters.EmptyReadOnlyParameters,
+                                       Location.Null);
 
                        AddConstructor (c);
                        
@@ -608,7 +629,7 @@ namespace Mono.MonoBASIC {
                        
                        foreach (Field f in initialized_fields){
                                Report.Error (
-                                       573, Location,
+                                       31049, Location,
                                        "`" + n + "." + f.Name + "': can not have " +
                                        "instance field initializers in structs");
                        }
@@ -791,6 +812,9 @@ namespace Mono.MonoBASIC {
                        if (error)
                                return null;
 
+                       if (this is Interface)
+                               parent = null;
+
                        if (is_class && parent != null){
                                if (parent == TypeManager.enum_type ||
                                    (parent == TypeManager.value_type && RootContext.StdLib) ||
@@ -806,7 +830,7 @@ namespace Mono.MonoBASIC {
                        if (!is_class && TypeManager.value_type == null)
                                throw new Exception ();
 
-                       if (is_class  && Parent.Parent == null) \r
+                       if (is_class  && Parent.Parent == null && (!(this is Interface))\r
                        {
                                if ((ModFlags & Modifiers.PRIVATE) != 0)
                                        Report.Error (31089, Location,
@@ -816,6 +840,16 @@ namespace Mono.MonoBASIC {
                                        Report.Error (31047, Location,
                                                "Only internal classes can be declared as 'Protected'");
                        }
+
+                       if ((Parent is Module) && ((ModFlags & Modifiers.PROTECTED) != 0))
+                               Report.Error (30735, Location,
+                                       "'Type' inside a 'Module' can not be " +
+                                       "declared as 'Protected'");
+
+                       if ((Parent is Struct) && ((ModFlags & Modifiers.PROTECTED) != 0))
+                               Report.Error (30435, Location,
+                                       "'Type' inside a 'Structure' can not be " +
+                                       "declared as 'Protected'");
                        
                        TypeAttributes type_attributes = TypeAttr;
 
@@ -831,23 +865,25 @@ namespace Mono.MonoBASIC {
                                        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)
+                       {
+                               // structure must contain atleast one member variable
+                               if(!have_nonstatic_fields){
+                                       Report.Error (
+                                               30281, Location, "Structure `" + Name + "' do not " +
+                                               "contain any member Variable");
 
-                       if (!is_class && !have_nonstatic_fields){
-                               TypeBuilder.DefineField ("$PRIVATE$", TypeManager.byte_type,
-                                                        FieldAttributes.Private);
-                       }
+                                       /*TypeBuilder.DefineField ("$PRIVATE$", TypeManager.byte_type,
+                                                                FieldAttributes.Private);*/
+                               }
 
-                       // add interfaces that were not added at type creation (weird API issue)
-                       if (!is_class && !have_nonstatic_fields && (ifaces != null)) {
-                               foreach (Type i in ifaces)
-                                       TypeBuilder.AddInterfaceImplementation (i);
+                               // add interfaces that were not added at type creation (weird API issue)
+                               if (!have_nonstatic_fields && (ifaces != null)) {
+                                       foreach (Type i in ifaces)
+                                               TypeBuilder.AddInterfaceImplementation (i);
+                               }
                        }
+
                        
                        //
                        // Finish the setup for the EmitContext
@@ -1072,7 +1108,7 @@ namespace Mono.MonoBASIC {
                        if (fields != null)
                                DefineMembers (fields, defined_names);
 
-                       if (this is Class){
+                       if (this is Class && (!(this is Interface))){
                                if (instance_constructors == null){
                                        if (default_constructor == null) \r
                                                DefineDefaultConstructor (false);
@@ -1350,6 +1386,7 @@ namespace Mono.MonoBASIC {
                                                        continue;
 
                                                MemberInfo pb = p.PropertyBuilder;
+
                                                if (pb != null && filter (pb, criteria) == true) {
                                                        members.Add (p.PropertyBuilder);
                                                }
@@ -1515,9 +1552,9 @@ namespace Mono.MonoBASIC {
                                foreach (Indexer ix in indexers)
                                        ix.Emit (this);
                                
-                               CustomAttributeBuilder cb = Interface.EmitDefaultMemberAttr (
+                               /*CustomAttributeBuilder cb = Interface.EmitDefaultMemberAttr (
                                        this, IndexerName, ModFlags, Location);
-                               TypeBuilder.SetCustomAttribute (cb);
+                               TypeBuilder.SetCustomAttribute (cb);*/
                        }
                        
                        if (fields != null)
@@ -1923,7 +1960,7 @@ namespace Mono.MonoBASIC {
 
                bool IMemberContainer.IsInterface {
                        get {
-                               return false;
+                               return this is Interface;
                        }
                }
 
@@ -2149,6 +2186,9 @@ namespace Mono.MonoBASIC {
                //
                protected InternalParameters parameter_info;
                protected Type [] parameter_types;
+       
+               // Whether this is an operator
+               public bool IsOperator;
 
                public MethodCore (Expression type, int mod, int allowed_mod, string name,
                                   Attributes attrs, Parameters parameters, Location loc)
@@ -2319,50 +2359,47 @@ namespace Mono.MonoBASIC {
                        return MemberType;
                }
 
-               // Whether this is an operator method.
-               public bool IsOperator;
+               void DuplicateEntryPoint (MethodInfo b, Location location)
+               {
+                               Report.Error (
+                                               30738, location,
+                                               "Program `" + CodeGen.FileName +
+                                               "'  has more than one entry point defined: `" +
+                                               TypeManager.MonoBASIC_Signature(b) + "'");
+               }
 
-                void DuplicateEntryPoint (MethodInfo b, Location location)
-                {
-                        Report.Error (
-                                17, location,
-                                "Program `" + CodeGen.FileName +
-                                "'  has more than one entry point defined: `" +
-                                TypeManager.MonoBASIC_Signature(b) + "'");
-                }
-
-                void Report28 (MethodInfo b)
-                {
+               void Report28 (MethodInfo b)
+               {
                        if (RootContext.WarningLevel < 4) 
                                return;
                                
-                        Report.Warning (
-                                28, Location,
-                                "`" + TypeManager.MonoBASIC_Signature(b) +
-                                "' has the wrong signature to be an entry point");
-                }
-
-                public bool IsEntryPoint (MethodBuilder b, InternalParameters pinfo)
-                {
-                        if (b.ReturnType != TypeManager.void_type &&
-                            b.ReturnType != TypeManager.int32_type)
-                                return false;
-
-                        if (pinfo.Count == 0)
-                                return true;
-
-                        if (pinfo.Count > 1)
-                                return false;
-
-                        Type t = pinfo.ParameterType(0);
-                        if (t.IsArray &&
-                            (t.GetArrayRank() == 1) &&
-                            (t.GetElementType() == TypeManager.string_type) &&
-                            (pinfo.ParameterModifier(0) == Parameter.Modifier.NONE))
-                                return true;
-                        else
-                                return false;
-                }
+                       Report.Warning (
+                                       28, Location,
+                                       "`" + TypeManager.MonoBASIC_Signature(b) +
+                                       "' has the wrong signature to be an entry point");
+               }
+
+               public bool IsEntryPoint (MethodBuilder b, InternalParameters pinfo)
+               {
+                       if (b.ReturnType != TypeManager.void_type &&
+                               b.ReturnType != TypeManager.int32_type)
+                                       return false;
+
+                       if (pinfo.Count == 0)
+                                       return true;
+
+                       if (pinfo.Count > 1)
+                                       return false;
+
+                       Type t = pinfo.ParameterType(0);
+                       if (t.IsArray &&
+                               (t.GetArrayRank() == 1) &&
+                               (t.GetElementType() == TypeManager.string_type) &&
+                               (pinfo.ParameterModifier(0) == Parameter.Modifier.NONE))
+                                       return true;
+                       else
+                                       return false;
+               }
 
                //
                // Checks our base implementation if any
@@ -2459,10 +2496,18 @@ namespace Mono.MonoBASIC {
                                                                "not maked as Overrides");
                                                }
                                        }
+                                       // if a member of module is not inherited from Object class
+                                       // can not be declared protected
+                                       if ((parent is Module) && ((ModFlags & Modifiers.PROTECTED) != 0))
+                                               Report.Error (31066, Location,
+                                                               "'Sub' or 'Function' inside a 'Module' can not be declared as " +
+                                                               "'Protected' or 'Protected Friend'");
                                }
-                       }/* else if ((ModFlags & Modifiers.NEW) != 0)
+                       }
+                       /* else if ((ModFlags & Modifiers.NEW) != 0)
                                WarningNotHiding (parent);
                        */
+
                        return true;
                }
 
@@ -2477,6 +2522,11 @@ namespace Mono.MonoBASIC {
                        if (!CheckBase (parent))
                                return false;
 
+                       if ((parent is Struct) && ((ModFlags & Modifiers.PROTECTED) != 0))
+                               Report.Error (31067, Location,
+                                       "'Sub' or 'Function' inside a 'Structure' can not be declared as " +
+                                       "'Protected' or 'Protected Friend'");
+
                        CallingConventions cc = GetCallingConvention (parent is Class);
 
                        MethodData = new MethodData (this, null, MemberType, ParameterTypes,
@@ -2664,6 +2714,12 @@ namespace Mono.MonoBASIC {
                        Initializer = init;
                }
 
+               public Constructor (string name, int mod, Parameters args, ConstructorInitializer init, Location l)
+                       : base (null, mod, AllowedModifiers, name, null, args, l)
+               {
+                       Initializer = init;
+               }
+
                //
                // Returns true if this is a default constructor
                //
@@ -2688,6 +2744,13 @@ namespace Mono.MonoBASIC {
                        MethodAttributes ca = (MethodAttributes.RTSpecialName |
                                               MethodAttributes.SpecialName);
 
+                       if (parent.EventHandlers != null) {
+                               ArrayList hdlrs = parent.EventHandlers;
+                               foreach(Statement stmt in hdlrs)
+                    this.Block.AddStatement (stmt);
+                       }
+
+
                        // Check if arguments were correct.
                        if (!DoDefineParameters (parent))
                                return false;
@@ -2715,7 +2778,7 @@ namespace Mono.MonoBASIC {
                        else {
                                if (parent is Struct && ParameterTypes.Length == 0)     {
                                        Report.Error (
-                                               568, Location, 
+                                               30629, Location, 
                                                "Structs can not contain explicit parameterless " +
                                                "constructors");
                                        return false;
@@ -3445,7 +3508,7 @@ namespace Mono.MonoBASIC {
                        //
                        // Check for explicit interface implementation
                        //
-                       if ((ExplicitInterfaceName == null) && (Name.IndexOf (".") != -1)){
+                       if ((ExplicitInterfaceName == null) && (Name.IndexOf (".") != -1)) {
                                int pos = Name.LastIndexOf (".");
 
                                ExplicitInterfaceName = Name.Substring (0, pos);
@@ -3542,14 +3605,14 @@ namespace Mono.MonoBASIC {
                //   Modifiers allowed in a class declaration
                // </summary>
                const int AllowedModifiers =
-                       Modifiers.NEW |
+                       Modifiers.SHADOWS |
                        Modifiers.PUBLIC |
                        Modifiers.PROTECTED |
                        Modifiers.INTERNAL |
                        Modifiers.PRIVATE |
                        Modifiers.STATIC |
-                       Modifiers.VOLATILE |
-                       Modifiers.UNSAFE |
+                  //     Modifiers.VOLATILE |
+                  //     Modifiers.UNSAFE |
                        Modifiers.READONLY;
 
                public Field (Expression type, int mod, string name, Object expr_or_array_init,
@@ -3576,18 +3639,41 @@ namespace Mono.MonoBASIC {
                        if (t.IsPointer && !UnsafeOK (parent))
                                return false;
                                
-                       if (RootContext.WarningLevel > 1){
-                               Type ptype = parent.TypeBuilder.BaseType;
+                       Type ptype = parent.TypeBuilder.BaseType;
 
-                               // ptype is only null for System.Object while compiling corlib.
-                               if (ptype != null){
-                                       TypeContainer.FindMembers (
-                                               ptype, MemberTypes.Method,
-                                               BindingFlags.Public |
-                                               BindingFlags.Static | BindingFlags.Instance,
-                                               System.Type.FilterName, Name);
+                       // ptype is only null for System.Object while compiling corlib.
+                       if (ptype != null){
+                               MemberList list = TypeContainer.FindMembers (
+                                       ptype, MemberTypes.Field,
+                                       BindingFlags.Public |
+                                       BindingFlags.Static | BindingFlags.Instance,
+                                       System.Type.FilterName, Name);
+
+                               if (RootContext.WarningLevel > 1){      
+                                       if ((list.Count > 0) && ((ModFlags & Modifiers.SHADOWS) == 0)) \r
+                                       {
+                                               Report.Warning (
+                                                       40004, 2, Location, 
+                                                       "Variable '" + Name + "' should be declared " +
+                                                       "Shadows since the base type '" + ptype.Name + 
+                                                       "' has a variable with same name");
+
+                                               ModFlags |= Modifiers.SHADOWS;
+                                       }
                                }
+                               if (list.Count == 0)
+                                       // if a member of module is not inherited from Object class
+                                       // can not be declared protected
+                                       if ((parent is Module) && ((ModFlags & Modifiers.PROTECTED) != 0))
+                                       Report.Error (30593, Location,
+                                               "'Variable' inside a 'Module' can not be " +
+                                               "declared as 'Protected'");
                        }
+                       
+                       if ((parent is Struct) && ((ModFlags & Modifiers.PROTECTED) != 0))
+                               Report.Error (30435, Location,
+                                       "'Variable' inside a 'Structure' can not be " +
+                                       "declared as 'Protected'");
 
                        if ((ModFlags & Modifiers.VOLATILE) != 0){
                                if (!t.IsClass){
@@ -3689,111 +3775,147 @@ namespace Mono.MonoBASIC {
                //
                // Checks our base implementation if any
                //
-               protected override bool CheckBase (TypeContainer parent)
+               protected override bool CheckBase (TypeContainer container)
                {
+                       base.CheckBase (container);
+                       
                        // Check whether arguments were correct.
-                       if (!DoDefineParameters (parent))
+                       if (!DoDefineParameters (container))
                                return false;
 
                        if (IsExplicitImpl)
                                return true;
 
+                       MethodSignature ms = new MethodSignature (Name, null, ParameterTypes);
+                       if (!IsOperator) \r
+                       {
+                               MemberList mi_this;
+
+                               mi_this = TypeContainer.FindMembers (
+                                       container.TypeBuilder, MemberTypes.Property,
+                                       BindingFlags.NonPublic | BindingFlags.Public |
+                                       BindingFlags.Static | BindingFlags.Instance |
+                                       BindingFlags.DeclaredOnly,
+                                       MethodSignature.method_signature_filter, ms);
+
+                               if (mi_this.Count > 0) {
+                                       Report.Error (111, Location, "Class `" + container.Name + "' " +
+                                               "already defines a member called `" + Name + "' " +
+                                               "with the same parameter types");
+                                       return false;
+                               }
+                       }
+
+                       if (container is Interface)
+                               return true;
+                       
                        string report_name;
-                       MethodSignature ms, base_ms;
+                       MethodSignature base_ms;
                        if (this is Indexer) {
                                string name, base_name;
 
                                report_name = "this";
-                               name = TypeManager.IndexerPropertyName (parent.TypeBuilder);
+                               name = TypeManager.IndexerPropertyName (container.TypeBuilder);
                                ms = new MethodSignature (name, null, ParameterTypes);
-                               base_name = TypeManager.IndexerPropertyName (parent.TypeBuilder.BaseType);
+                               base_name = TypeManager.IndexerPropertyName (container.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 (
-                               parent.TypeBuilder, MemberTypes.Property,
-                               BindingFlags.NonPublic | BindingFlags.Public |
-                               BindingFlags.Static | BindingFlags.Instance |
-                               BindingFlags.DeclaredOnly,
-                               MethodSignature.method_signature_filter, ms);
-
-                       if (props_this.Count > 0) {
-                               Report.Error (111, Location, "Class `" + parent.Name + "' " +
-                                             "already defines a member called `" + report_name + "' " +
-                                             "with the same parameter types");
-                               return false;
-                       }
-
                        //
-                       // Find properties with the same name on the base class
+                       // Verify if the parent has a type with the same name, and then
+                       // check whether we have to create a new slot for it or not.
                        //
-                       MemberList props;
-                       MemberList props_static = TypeContainer.FindMembers (
-                               parent.TypeBuilder.BaseType, MemberTypes.Property,
+                       Type ptype = container.TypeBuilder.BaseType;
+
+                       MemberInfo parent_member = null;
+                       MemberList mi, mi_static, mi_instance;
+
+                       mi_static = TypeContainer.FindMembers (
+                               ptype, MemberTypes.Property,
                                BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static,
-                               MethodSignature.inheritable_property_signature_filter, base_ms);
+                               MethodSignature.inheritable_method_signature_filter, ms);
 
-                       MemberList props_instance = TypeContainer.FindMembers (
-                               parent.TypeBuilder.BaseType, MemberTypes.Property,
+                       mi_instance = TypeContainer.FindMembers (
+                               ptype, MemberTypes.Property,
                                BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance,
-                               MethodSignature.inheritable_property_signature_filter,
-                               base_ms);
+                               MethodSignature.inheritable_method_signature_filter,
+                               ms);
 
-                       //
-                       // Find if we have anything
-                       //
-                       if (props_static.Count > 0)
-                               props = props_static;
-                       else if (props_instance.Count > 0)
-                               props = props_instance;
+                       if (mi_instance.Count > 0) {
+                               mi = mi_instance;
+                       } else if (mi_static.Count > 0)
+                               mi = mi_static;
                        else
-                               props = null;
+                               mi = null;
 
+                       if (mi != null && mi.Count > 0)\r
+                               parent_member = (MethodInfo) mi [0];
+\r
+                       if (parent_member is PropertyInfo) {
+                               PropertyInfo parent_property = (PropertyInfo)parent_member;
 
-                       //
-                       // If we have something on the base.
-                       if (props != null && props.Count > 0){
-                               PropertyInfo pi = (PropertyInfo) props [0];
-
-                               MethodInfo inherited_get = TypeManager.GetPropertyGetter (pi);
-                               MethodInfo inherited_set = TypeManager.GetPropertySetter (pi);
+                               string name = parent_property.DeclaringType.Name + "." +
+                                       parent_property.Name;
 
-                               MethodInfo reference = inherited_get == null ?
-                                       inherited_set : inherited_get;
-                               
-                               if (reference != null) {
-                                       string name = reference.DeclaringType.Name + "." + report_name;
+                               MethodInfo get, set, parent_method;
+                               get = parent_property.GetGetMethod (true);
+                               set = parent_property.GetSetMethod (true);
 
-                                       if (!CheckMethodAgainstBase (parent, flags, reference, name))
-                                               return false;
-                               }
+                               if (get != null)
+                                       parent_method = get;
+                               else if (set != null)
+                                       parent_method = set;
+                               else
+                                       throw new Exception ("Internal error!");
 
-                               if (((ModFlags & Modifiers.NEW) == 0) && (pi.PropertyType != MemberType)) {
-                                       Report.Error (508, parent.MakeName (Name) + ": cannot " +
-                                                     "change return type when overriding inherited " +
-                                                     "member `" + pi.DeclaringType + "." + pi.Name + "'");
+                               if (!CheckMethodAgainstBase (container, flags, parent_method, name))
                                        return false;
+
+                               if ((ModFlags & Modifiers.NEW) == 0) {
+                                       Type parent_type = TypeManager.TypeToCoreType (
+                                               parent_property.PropertyType);
+
+                                       if (parent_type != MemberType) {
+                                               Report.Error (
+                                                       508, Location, container.MakeName (Name) + ": cannot " +
+                                                       "change return type when overriding " +
+                                                       "inherited member " + name);
+                                               return false;
+                                       }
                                }
-                       } else {
+                       } else if (parent_member == null) {
                                /*if ((ModFlags & Modifiers.NEW) != 0)
-                                       WarningNotHiding (parent);*/
-                               
-                               if ((ModFlags & Modifiers.OVERRIDE) != 0){
+                                       WarningNotHiding (container);
+                               */
+                               if ((ModFlags & Modifiers.OVERRIDE) != 0) {
                                        if (this is Indexer)
                                                Report.Error (115, Location,
-                                                             parent.MakeName (Name) +
-                                                             " no suitable indexers found to override");
+                                                       container.MakeName (Name) +
+                                                       " no suitable indexers found to override");
                                        else
                                                Report.Error (115, Location,
-                                                             parent.MakeName (Name) +
-                                                             " no suitable properties found to override");
+                                                       container.MakeName (Name) +
+                                                       " no suitable properties found to override");
                                        return false;
                                }
+
+                               if ((ModFlags & ( Modifiers.NEW | Modifiers.SHADOWS | Modifiers.OVERRIDE )) == 0) {
+                                       if ((ModFlags & Modifiers.NONVIRTUAL) != 0)     {
+                                               Report.Error (31088, Location,
+                                                       container.MakeName (Name) + " : Cannot " +
+                                                       "be declared NotOverridable since this method is " +
+                                                       "not maked as Overrides");
+                                       }
+                               }
+                               // if a member of module is not inherited from Object class
+                               // can not be declared protected
+                               if ((container is Module) && ((ModFlags & Modifiers.PROTECTED) != 0))
+                                       Report.Error (31066, Location,
+                                               "'Property' inside a 'Module' can not be declared as " +
+                                               "'Protected' or 'Protected Friend'");
                        }
                        return true;
                }
@@ -3831,6 +3953,7 @@ namespace Mono.MonoBASIC {
                    Modifiers.UNSAFE |
                        Modifiers.EXTERN |
                        Modifiers.VIRTUAL |
+                       Modifiers.NONVIRTUAL |
                        Modifiers.DEFAULT |
                        Modifiers.READONLY |
                        Modifiers.WRITEONLY |
@@ -3868,6 +3991,11 @@ namespace Mono.MonoBASIC {
                        Parameter [] g_parms, s_parms;
                        InternalParameters g_ip=null, s_ip=null;
 
+                       if ((parent is Struct) && ((ModFlags & Modifiers.PROTECTED) != 0))
+                               Report.Error (30435, Location,
+                                       "'Property' inside a 'Structure' can not be declared as " +
+                                       "'Protected' or 'Protected Friend'");
+
                        if (!DoDefine (parent))
                                return false;
 
@@ -3876,23 +4004,24 @@ namespace Mono.MonoBASIC {
 
                        flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
 
-                       if (Get != null) {
-                               if (get_params == Parameters.EmptyReadOnlyParameters) 
-                               {
+                       if (Get == null) {
+                               if ((ModFlags & Modifiers.WRITEONLY) == 0)
+                                       Report.Error (
+                                               30124, Location,
+                                               "Property without 'Get' accessor must have a 'WriteOnly' modifier");
+                       }
+                       else {
+                               if (get_params == Parameters.EmptyReadOnlyParameters) {
                                        g_parameters = TypeManager.NoTypes;
                                        g_ip = new InternalParameters (
                                                        parent, Parameters.EmptyReadOnlyParameters);
-                               }
-                               else
-                               {
+                               } else  {
                                        g_parameters = new Type [get_params.FixedParameters.Length];
-                                       for (int i = 0; i < get_params.FixedParameters.Length; i ++) 
-                                       {
+                                       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 ++) 
-                                       {
+                                       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);
@@ -3911,47 +4040,50 @@ namespace Mono.MonoBASIC {
                                GetBuilder = GetData.MethodBuilder;
                        }
 
-                       if (Set != null) {
+                       if (Set == null) {
+                               if ((ModFlags & Modifiers.READONLY) == 0)
+                                       Report.Error (
+                                               30124, Location,
+                                               "Property without 'Set' accessor must have a 'ReadOnly' modifier");
+                                               
+                       }
+                       else \r
+                       {
                                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, 
+                                       s_parms [0] = new Parameter (Type, set_parameter_name, 
                                                Parameter.Modifier.NONE, null);
-                               }
-                               else
-                               {
+                               } else {
                                        s_parameters = new Type [set_params.FixedParameters.Length];
-                                       for (int i = 0; i < set_params.FixedParameters.Length; i ++) 
-                                       {
+                                       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 ++) 
-                                       {
+                                       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.Modifier.NONE, null);
                                        }
                                }
 
                                s_ip = new InternalParameters (
                                        parent, new Parameters (s_parms, null, Location));
 
-                               
                                SetData = new MethodData (this, "set", TypeManager.void_type,
-                                                         s_parameters, s_ip, CallingConventions.Standard,
-                                                         Set.OptAttributes, ModFlags, flags, false);
+                                       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, 
-                                                               /* was "value" */ set_parameter_name); 
+                                       set_parameter_name); 
                        }
 
                        // FIXME - PropertyAttributes.HasDefault ?
@@ -3964,11 +4096,8 @@ namespace Mono.MonoBASIC {
                                PropertyBuilder = parent.TypeBuilder.DefineProperty (
                                        Name, prop_attr, MemberType, null);
                                
-                               if (Get != null)
-                                       PropertyBuilder.SetGetMethod (GetBuilder);
-                               
-                               if (Set != null)
-                                       PropertyBuilder.SetSetMethod (SetBuilder);
+                               PropertyBuilder.SetGetMethod (GetBuilder);
+                               PropertyBuilder.SetSetMethod (SetBuilder);
 
                                //
                                // HACK for the reasons exposed above
@@ -4176,7 +4305,7 @@ namespace Mono.MonoBASIC {
                                return false;
 
                        if (!MemberType.IsSubclassOf (TypeManager.delegate_type)) {
-                               Report.Error (66, Location, "'" + parent.Name + "." + Name +
+                               Report.Error (31044, Location, "'" + parent.Name + "." + Name +
                                              "' : event must be of a delegate type");
                                return false;
                        }