Bladeren bron

Remove some code duplication

* mcs/class.cs (TypeContainer.AddBasesForPart): Make virtual.
(Class.AddBasesForPart): Move CS0537 check here from ...
* mcs/cs-parser.jay (class_declaration): ... here.  Move calling of
'AddBasesForPart' to ...
(class_bases): ... here.
(struct_declaration, interface_declaration): Update to changes.
* gmcs/cs-parser.jay: Likewise.

svn path=/trunk/mcs/; revision=83329
Raja R Harinath 18 jaren geleden
bovenliggende
commit
f7845bd3ee
5 gewijzigde bestanden met toevoegingen van 37 en 61 verwijderingen
  1. 7 0
      mcs/gmcs/ChangeLog
  2. 6 30
      mcs/gmcs/cs-parser.jay
  3. 9 0
      mcs/mcs/ChangeLog
  4. 9 1
      mcs/mcs/class.cs
  5. 6 30
      mcs/mcs/cs-parser.jay

+ 7 - 0
mcs/gmcs/ChangeLog

@@ -1,3 +1,10 @@
+2007-08-03  Raja R Harinath  <[email protected]>
+
+	* cs-parser.jay (class_declaration): Update to changes in class.cs.
+	Move calling of	'AddBasesForPart' to ...
+	(class_bases): ... here.
+	(struct_declaration, interface_declaration): Update to changes.
+
 2007-08-02  Raja R Harinath  <[email protected]>
 
 	Reduce some differences between cs-parser.jay in mcs/ and gmcs/.

+ 6 - 30
mcs/gmcs/cs-parser.jay

@@ -850,18 +850,13 @@ struct_declaration
 	  type_name
 	  { 
 		MemberName name = MakeName ((MemberName) $6);
-		push_current_class (new Struct (
-			current_namespace, current_class, name, (int) $2,
-			(Attributes) $1), $3);
+		push_current_class (new Struct (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
 	  }
 	  opt_class_base
 	  opt_type_parameter_constraints_clauses
 	  {
 		lexer.ConstraintsParsing = false;
 
-		if ($8 != null)
-			current_container.AddBasesForPart (current_class, (ArrayList) $8);
-
 		current_class.SetParameterInfo ((ArrayList) $9);
 
 		if (RootContext.Documentation != null)
@@ -1664,19 +1659,13 @@ interface_declaration
 	  type_name
 	  {
 		MemberName name = MakeName ((MemberName) $6);
-
-		push_current_class (new Interface (
-			current_namespace, current_class, name, (int) $2,
-			(Attributes) $1), $3);
+		push_current_class (new Interface (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
 	  }
 	  opt_class_base
 	  opt_type_parameter_constraints_clauses
 	  {
 		lexer.ConstraintsParsing = false;
 
-		if ($8 != null)
-			current_container.AddBasesForPart (current_class, (ArrayList) $8);
-
 		current_class.SetParameterInfo ((ArrayList) $9);
 
 		if (RootContext.Documentation != null) {
@@ -4312,26 +4301,13 @@ class_declaration
 	  type_name
 	  {
 		MemberName name = MakeName ((MemberName) $6);
-		int mod_flags = (int) $2;
-
-		push_current_class (new Class (
-			current_namespace, current_class, name,
-			mod_flags, (Attributes) $1), $3);
+		push_current_class (new Class (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
 	  }
 	  opt_class_base
 	  opt_type_parameter_constraints_clauses
 	  {
 		lexer.ConstraintsParsing = false;
 
-		if ($8 != null) {
-			if (current_class.Name == "System.Object") {
-				Report.Error (537, current_class.Location,
-					      "The class System.Object cannot have a base " +
-					      "class or implement an interface.");
-			}
-			current_container.AddBasesForPart (current_class, (ArrayList) $8);
-		}
-
 		current_class.SetParameterInfo ((ArrayList) $9);
 
 		if (RootContext.Documentation != null) {
@@ -4395,12 +4371,12 @@ modifier
 	;
 
 opt_class_base
-	: /* empty */		{ $$ = null; }
-	| class_base		{ $$ = $1;   }
+	: /* empty */
+	| class_base
 	;
 
 class_base
-	: COLON type_list { $$ = $2; }
+	: COLON type_list	{ current_container.AddBasesForPart (current_class, (ArrayList) $2); }
 	;
 
 opt_type_parameter_constraints_clauses

+ 9 - 0
mcs/mcs/ChangeLog

@@ -1,3 +1,12 @@
+2007-08-03  Raja R Harinath  <[email protected]>
+
+	* class.cs (TypeContainer.AddBasesForPart): Make virtual.
+	(Class.AddBasesForPart): Move CS0537 check here from ...
+	* cs-parser.jay (class_declaration): ... here.  Move calling of
+	'AddBasesForPart' to ...
+	(class_bases): ... here.
+	(struct_declaration, interface_declaration): Update to changes.
+
 2007-08-02  Marek Safar  <[email protected]>
 
 	A fix for bug #81923

+ 9 - 1
mcs/mcs/class.cs

@@ -857,7 +857,7 @@ namespace Mono.CSharp {
 			return base.GetClsCompliantAttributeValue ();
 		}
 
-		public void AddBasesForPart (DeclSpace part, ArrayList bases)
+		public virtual void AddBasesForPart (DeclSpace part, ArrayList bases)
 		{
 			// FIXME: get rid of partial_parts and store lists of bases of each part here
 			// assumed, not verified: 'part' is in 'partial_parts' 
@@ -2914,6 +2914,14 @@ namespace Mono.CSharp {
 			}
 		}
 
+		public override void AddBasesForPart (DeclSpace part, ArrayList bases)
+		{
+			if (part.Name == "System.Object")
+				Report.Error (537, part.Location,
+					"The class System.Object cannot have a base class or implement an interface.");
+			base.AddBasesForPart (part, bases);
+		}
+
 		public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
 		{
 			if (a.Type == TypeManager.attribute_usage_type) {

+ 6 - 30
mcs/mcs/cs-parser.jay

@@ -814,15 +814,10 @@ struct_declaration
 	  type_name
 	  { 
 		MemberName name = MakeName ((MemberName) $6);
-		push_current_class (new Struct (
-			current_namespace, current_class, name, (int) $2,
-			(Attributes) $1), $3);
+		push_current_class (new Struct (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
 	  }
 	  opt_class_base
 	  {
-		if ($8 != null)
-			current_container.AddBasesForPart (current_class, (ArrayList) $8);
-
 		if (RootContext.Documentation != null)
 			current_container.DocComment = Lexer.consume_doc_comment ();
 	  }
@@ -1564,16 +1559,10 @@ interface_declaration
 	  type_name
 	  {
 		MemberName name = MakeName ((MemberName) $6);
-
-		push_current_class (new Interface (
-			current_namespace, current_class, name, (int) $2,
-			(Attributes) $1), $3);
+		push_current_class (new Interface (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
 	  }
 	  opt_class_base
 	  {
-		if ($8 != null)
-			current_container.AddBasesForPart (current_class, (ArrayList) $8);
-
 		if (RootContext.Documentation != null) {
 			current_container.DocComment = Lexer.consume_doc_comment ();
 			Lexer.doc_state = XmlCommentState.Allowed;
@@ -3746,23 +3735,10 @@ class_declaration
 	  type_name
 	  {
 		MemberName name = MakeName ((MemberName) $6);
-		int mod_flags = (int) $2;
-
-		push_current_class (new Class (
-			current_namespace, current_class, name,
-			mod_flags, (Attributes) $1), $3);
+		push_current_class (new Class (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
 	  }
 	  opt_class_base
 	  {
-		if ($8 != null) {
-			if (current_class.Name == "System.Object") {
-				Report.Error (537, current_class.Location,
-					      "The class System.Object cannot have a base " +
-					      "class or implement an interface.");
-			}
-			current_container.AddBasesForPart (current_class, (ArrayList) $8);
-		}
-
 		if (RootContext.Documentation != null) {
 			current_container.DocComment = Lexer.consume_doc_comment ();
 			Lexer.doc_state = XmlCommentState.Allowed;
@@ -3824,12 +3800,12 @@ modifier
 	;
 
 opt_class_base
-	: /* empty */		{ $$ = null; }
-	| class_base		{ $$ = $1;   }
+	: /* empty */
+	| class_base
 	;
 
 class_base
-	: COLON type_list { $$ = $2; }
+	: COLON type_list	{ current_container.AddBasesForPart (current_class, (ArrayList) $2); }
 	;
 
 //