* mb-parser.jay: Removed 'static_constructor_declaration' - this is not required...
authorAnirban Bhattacharjee <anirban@mono-cvs.ximian.com>
Wed, 14 Apr 2004 10:47:00 +0000 (10:47 -0000)
committerAnirban Bhattacharjee <anirban@mono-cvs.ximian.com>
Wed, 14 Apr 2004 10:47:00 +0000 (10:47 -0000)
 * class.cs: Handling couple of negative scenarios related to static constructors and bug fixes

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

mcs/mbas/ChangeLog
mcs/mbas/class.cs
mcs/mbas/mb-parser.jay

index 9e36da0cf885e915f121d013cc69dd253206d0e9..a89f8ecc2e52552d5aa0c7c463aaeb7ec7ff984e 100644 (file)
@@ -1,3 +1,7 @@
+2004-04-13 Anirban Bhattacharjee <banirban@novell.com>
+       * mb-parser.jay: Removed 'static_constructor_declaration' - this is not required as 'constructor_declaration' implementation is good enough to handle static constructors too
+       * class.cs: Handling couple of negative scenarios related to static constructors and bug fixes
+
 2004-04-13 Anirban Bhattacharjee <banirban@novell.com>
        * class.cs: Couple of negative scenario handling
 
index 01bda5493263d935c33d12a3f57830383eaa3c03..1cae5aae28f3d24f9ef6100a6cef487eaa7b83e8 100644 (file)
@@ -594,7 +594,7 @@ namespace Mono.MonoBASIC {
                        if (is_static)
                                mods = Modifiers.STATIC;
 
-                       c.ModFlags = mods;
+                       c.ModFlags |= mods;
 
                        AddConstructor (c);
                        
@@ -2692,10 +2692,28 @@ namespace Mono.MonoBASIC {
                        if (!DoDefineParameters (parent))
                                return false;
 
-                       if ((ModFlags & Modifiers.STATIC) != 0)
+                       if ((ModFlags & Modifiers.STATIC) != 0) {
                                ca |= MethodAttributes.Static;
+
+                               if (this.Parameters != Parameters.EmptyReadOnlyParameters)
+                                       Report.Error (
+                                               30479, Location, 
+                                               "Shared constructor can not have parameters");
+
+                               if ((ModFlags & Modifiers.Accessibility) != 0)
+                                       Report.Error (
+                                               30480, Location, 
+                                               "Shared constructor can not be declared " +
+                                               "explicitly as public, private, friend or protected");
+
+                               if (this.Initializer != null)
+                                       Report.Error (
+                                               30043, Location, 
+                                               "Keywords like MyBase, MyClass, Me are not " +
+                                               "valid inside a Shared Constructor");
+                       }
                        else {
-                               if (parent is Struct && ParameterTypes.Length == 0){
+                               if (parent is Struct && ParameterTypes.Length == 0)     {
                                        Report.Error (
                                                568, Location, 
                                                "Structs can not contain explicit parameterless " +
@@ -2706,12 +2724,13 @@ namespace Mono.MonoBASIC {
 
                                if ((ModFlags & Modifiers.PUBLIC) != 0)
                                        ca |= MethodAttributes.Public;
-                               else if ((ModFlags & Modifiers.PROTECTED) != 0){
+                               else if ((ModFlags & Modifiers.PROTECTED) != 0) {
                                        if ((ModFlags & Modifiers.INTERNAL) != 0)
                                                ca |= MethodAttributes.FamORAssem;
                                        else 
                                                ca |= MethodAttributes.Family;
-                               } else if ((ModFlags & Modifiers.INTERNAL) != 0)
+                               }\r
+                               else if ((ModFlags & Modifiers.INTERNAL) != 0)
                                        ca |= MethodAttributes.Assembly;
                                else if (IsDefault ())
                                        ca |= MethodAttributes.Public;
@@ -2772,13 +2791,14 @@ namespace Mono.MonoBASIC {
                                        parent.EmitFieldInitializers (ec);
                        }
 
-                       if (this.ConstructorBuilder.Equals (Initializer.ParentConstructor))
-                               Report.Error (
-                                       30297, Location,
-                                       "A constructor can not call itself" );
+                       if (Initializer != null) {
+                               if (this.ConstructorBuilder.Equals (Initializer.ParentConstructor))
+                                       Report.Error (
+                                               30297, Location,
+                                               "A constructor can not call itself" );
 
-                       if (Initializer != null)
                                Initializer.Emit (ec);
+                       }
                        
                        if ((ModFlags & Modifiers.STATIC) != 0)
                                parent.EmitFieldInitializers (ec);
index 86c25894505b0f2d0758e422dc582d1ef196f93a..80f25cf36dc3a994a305808484a784388cf2342b 100644 (file)
@@ -937,7 +937,7 @@ module_member_declaration
        ;
 
 module_member_declarator
-       :  static_constructor_declaration
+       :  constructor_declaration
        |  method_declaration
           { 
                Method method = (Method) $1;
@@ -1638,6 +1638,9 @@ field_declaration
                // Structure members are Public by default                      
                if ((current_container is Struct) && (mod == 0))
                        mod = Modifiers.PUBLIC;                 
+               
+               if ((mod & Modifiers.Accessibility) == 0)
+                       mod |= Modifiers.PRIVATE;
                                        
                foreach (VariableDeclaration var in (ArrayList) $2){
                        Location l = var.Location;
@@ -1743,7 +1746,8 @@ opt_empty_parens
        : /* empty */
        | OPEN_PARENS CLOSE_PARENS
        ;       
-       
+
+/*     
 static_constructor_declaration
        : SHARED SUB NEW opt_empty_parens EOL
          {
@@ -1765,6 +1769,7 @@ static_constructor_declaration
                current_local_parameters = null;
          }
          END SUB EOL
+*/
        
 constructor_declaration
        : SUB NEW OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS EOL