[Mono-list] PATCH: Various fixes to C# CodeDom provider

Jaroslaw Kowalski jaak@zd.com.pl
Sat, 16 Aug 2003 00:39:27 +0200


This is a multi-part message in MIME format.

------=_NextPart_000_0007_01C3638E.D8E70330
Content-Type: text/plain;
	charset="iso-8859-2"
Content-Transfer-Encoding: 7bit


Hi all!

I needed to use CodeDom functionality of Mono but it was broken (or not
compatible with MS) in some places, so I fixed it.

My changes (all in System.dll):

    * Microsoft.CSharp/CSharpCodeGenerator.cs:

      - fixed support for method references where target
        object is null
      - fixed CodeThrowExceptionStatement
      - disabled member access modifiers for private method
        implementations
      - disabled generation of empty method body for interface
        declarations
      - disabled generation of empty property accessor bodies
        in interface declarations
      - added support for indexers (properties named "Item")
      - added support for chained constructor arguments and
        base constructor arguments

    * System.CodeDom/CodeTypeDeclaration.cs:

      - TypeAttributes of CodeTypeDeclaration now defaults to
        TypeAttributes.Public (same as MS implementation)

Can anybody please review my patch (made against fresh anoncvs) and commit
it to CVS? ChangeLog included.

It was tested on my quite complicated CodeDom tree and now it produces
output that compiles without problems.

Jarek

------=_NextPart_000_0007_01C3638E.D8E70330
Content-Type: application/octet-stream;
	name="codedom.diff"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="codedom.diff"

Index: ChangeLog=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: /mono/mcs/class/System/ChangeLog,v=0A=
retrieving revision 1.56=0A=
diff -u -r1.56 ChangeLog=0A=
--- ChangeLog	27 Jul 2003 09:58:55 -0000	1.56=0A=
+++ ChangeLog	15 Aug 2003 22:33:13 -0000=0A=
@@ -1,3 +1,25 @@=0A=
+2003-08-15  Jaroslaw Kowalski <jarek@atm.com.pl>=0A=
+=0A=
+	* Microsoft.CSharp/CSharpCodeGenerator.cs:=0A=
+	=0A=
+	  - fixed support for method references where target=0A=
+		object is null=0A=
+	  - fixed CodeThrowExceptionStatement=0A=
+	  - disabled member access modifiers for private method=0A=
+	    implementations=0A=
+	  - disabled generation of empty method body for interface=0A=
+	    declarations=0A=
+	  - disabled generation of empty property accessor bodies=0A=
+	    in interface declarations=0A=
+	  - added support for indexers (properties named "Item")=0A=
+	  - added support for chained constructor arguments and=0A=
+	    base constructor arguments=0A=
+=0A=
+	* System.CodeDom/CodeTypeDeclaration.cs:=0A=
+=0A=
+	  - TypeAttributes of CodeTypeDeclaration now defaults to=0A=
+	    TypeAttributes.Public (same as MS implementation)=0A=
+=0A=
 2003-07-27  Andreas Nahr <ClassDevelopment@A-SoftTech.com>=0A=
 =0A=
 	* System.dll.sources: SRDescriptionAttribute.cs moved=0A=
Index: Microsoft.CSharp/CSharpCodeGenerator.cs=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: =
/mono/mcs/class/System/Microsoft.CSharp/CSharpCodeGenerator.cs,v=0A=
retrieving revision 1.9=0A=
diff -u -r1.9 CSharpCodeGenerator.cs=0A=
--- Microsoft.CSharp/CSharpCodeGenerator.cs	7 Aug 2003 22:24:27 -0000	1.9=0A=
+++ Microsoft.CSharp/CSharpCodeGenerator.cs	15 Aug 2003 22:33:14 -0000=0A=
@@ -202,8 +202,11 @@=0A=
 =0A=
 		protected override void GenerateMethodReferenceExpression( =
CodeMethodReferenceExpression expression )=0A=
 		{=0A=
-			GenerateExpression( expression.TargetObject );=0A=
-			Output.Write( '.' );=0A=
+			if (expression.TargetObject !=3D null)=0A=
+			{=0A=
+				GenerateExpression( expression.TargetObject );=0A=
+				Output.Write( '.' );=0A=
+			};=0A=
 			Output.Write( GetSafeName (expression.MethodName) );=0A=
 		}=0A=
 =0A=
@@ -271,6 +274,7 @@=0A=
 		{=0A=
 			Output.Write( "throw " );=0A=
 			GenerateExpression( statement.ToThrow );=0A=
+			Output.WriteLine(";");=0A=
 		}=0A=
 =0A=
 		protected override void GenerateComment( CodeComment comment )=0A=
@@ -497,7 +501,10 @@=0A=
 =0A=
 			MemberAttributes attributes =3D method.Attributes;=0A=
 =0A=
-			OutputMemberAccessModifier( attributes );=0A=
+			if (method.PrivateImplementationType =3D=3D null)=0A=
+			{=0A=
+				OutputMemberAccessModifier( attributes );=0A=
+			};=0A=
 			OutputMemberScopeModifier( attributes );=0A=
 =0A=
 			OutputType( method.ReturnType );=0A=
@@ -515,7 +522,7 @@=0A=
 			OutputParameters( method.Parameters );=0A=
 			output.Write( ')' );=0A=
 =0A=
-			if ( (attributes & MemberAttributes.ScopeMask) =3D=3D =
MemberAttributes.Abstract )=0A=
+			if ( (attributes & MemberAttributes.ScopeMask) =3D=3D =
MemberAttributes.Abstract || declaration.IsInterface)=0A=
 				output.WriteLine( ';' );=0A=
 			else {=0A=
 				output.WriteLine( " {" );=0A=
@@ -538,30 +545,50 @@=0A=
 			OutputMemberAccessModifier( attributes );=0A=
 			OutputMemberScopeModifier( attributes );=0A=
 =0A=
-			OutputTypeNamePair( property.Type, GetSafeName (property.Name));=0A=
+			if (property.Name =3D=3D "Item")=0A=
+			{=0A=
+				// indexer=0A=
+				=0A=
+				OutputTypeNamePair( property.Type, "this");=0A=
+				output.Write("[");=0A=
+				OutputParameters(property.Parameters);=0A=
+				output.Write("]");=0A=
+			}=0A=
+			else=0A=
+			{=0A=
+				OutputTypeNamePair( property.Type, GetSafeName (property.Name));=0A=
+			}=0A=
 			output.WriteLine (" {");=0A=
 			++Indent;=0A=
 =0A=
-			if (property.HasGet)=0A=
+			if (declaration.IsInterface)=0A=
 			{=0A=
-				output.WriteLine ("get {");=0A=
-				++Indent;=0A=
-=0A=
-				GenerateStatements (property.GetStatements);=0A=
-=0A=
-				--Indent;=0A=
-				output.WriteLine ("}");=0A=
+				if (property.HasGet) output.WriteLine("get; ");=0A=
+				if (property.HasSet) output.WriteLine("set; ");=0A=
 			}=0A=
-			=0A=
-			if (property.HasSet)=0A=
+			else=0A=
 			{=0A=
-				output.WriteLine ("set {");=0A=
-				++Indent;=0A=
-=0A=
-				GenerateStatements (property.SetStatements);=0A=
-=0A=
-				--Indent;=0A=
-				output.WriteLine ("}");=0A=
+				if (property.HasGet)=0A=
+				{=0A=
+					output.WriteLine ("get {");=0A=
+					++Indent;=0A=
+=0A=
+					GenerateStatements (property.GetStatements);=0A=
+=0A=
+					--Indent;=0A=
+					output.WriteLine ("}");=0A=
+				}=0A=
+=0A=
+				if (property.HasSet)=0A=
+				{=0A=
+					output.WriteLine ("set {");=0A=
+					++Indent;=0A=
+=0A=
+					GenerateStatements (property.SetStatements);=0A=
+=0A=
+					--Indent;=0A=
+					output.WriteLine ("}");=0A=
+				}=0A=
 			}=0A=
 =0A=
 			--Indent;=0A=
@@ -574,7 +601,36 @@=0A=
 			OutputMemberAccessModifier (constructor.Attributes);=0A=
 			Output.Write (GetSafeName (CurrentTypeName) + " (");=0A=
 			OutputParameters (constructor.Parameters);=0A=
-			Output.WriteLine (") {");=0A=
+			Output.Write (") ");=0A=
+			if (constructor.ChainedConstructorArgs.Count > 0)=0A=
+			{=0A=
+				Output.Write(": this(");=0A=
+				bool first =3D true;=0A=
+				foreach (CodeExpression ex in constructor.ChainedConstructorArgs)=0A=
+				{=0A=
+					if (!first)=0A=
+						Output.Write(", ");=0A=
+					first =3D false;=0A=
+					GenerateExpression(ex);=0A=
+				}=0A=
+				=0A=
+				Output.Write(") ");=0A=
+			};=0A=
+ 			if (constructor.BaseConstructorArgs.Count > 0)=0A=
+			{=0A=
+				Output.Write(": base(");=0A=
+				bool first =3D true;=0A=
+				foreach (CodeExpression ex in constructor.BaseConstructorArgs)=0A=
+				{=0A=
+					if (!first)=0A=
+						Output.Write(", ");=0A=
+					first =3D false;=0A=
+					GenerateExpression(ex);=0A=
+				}=0A=
+				=0A=
+				Output.Write(") ");=0A=
+			};=0A=
+			Output.WriteLine ("{");=0A=
 			Indent++;=0A=
 			GenerateStatements (constructor.Statements);=0A=
 			Indent--;=0A=
Index: System.CodeDom/CodeTypeDeclaration.cs=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: /mono/mcs/class/System/System.CodeDom/CodeTypeDeclaration.cs,v=0A=
retrieving revision 1.5=0A=
diff -u -r1.5 CodeTypeDeclaration.cs=0A=
--- System.CodeDom/CodeTypeDeclaration.cs	28 May 2002 06:59:57 -0000	1.5=0A=
+++ System.CodeDom/CodeTypeDeclaration.cs	15 Aug 2003 22:33:14 -0000=0A=
@@ -21,7 +21,7 @@=0A=
 	{=0A=
 		private CodeTypeReferenceCollection baseTypes;=0A=
 		private CodeTypeMemberCollection members;=0A=
-		private TypeAttributes typeAttributes;=0A=
+		private TypeAttributes typeAttributes =3D TypeAttributes.Public;=0A=
 		private bool isEnum;=0A=
 		private bool isStruct;=0A=
 =0A=

------=_NextPart_000_0007_01C3638E.D8E70330--