I fixed mono CodeDom bugs to pass on the latest Microsoft CodeDom Test Suite.
authorMarek Safar <marek.safar@gmail.com>
Wed, 1 Sep 2004 18:45:52 +0000 (18:45 -0000)
committerMarek Safar <marek.safar@gmail.com>
Wed, 1 Sep 2004 18:45:52 +0000 (18:45 -0000)
svn path=/trunk/mcs/; revision=33172

mcs/class/System/Microsoft.CSharp/CSharpCodeGenerator.cs
mcs/class/System/Microsoft.CSharp/ChangeLog
mcs/class/System/System.CodeDom.Compiler/ChangeLog
mcs/class/System/System.CodeDom.Compiler/CodeGenerator.cs
mcs/class/System/System.CodeDom/ChangeLog
mcs/class/System/System.CodeDom/CodeCatchClause.cs
mcs/class/System/System.CodeDom/CodeTypeMember.cs
mcs/class/System/System.CodeDom/CodeTypeReference.cs

index c22c8fc653db9afb97bb8304479017f8217fbf8c..9bb5a5b767dc8cea99e17a14744b142ddaa7b9c3 100644 (file)
@@ -40,11 +40,16 @@ namespace Mono.CSharp
        internal class CSharpCodeGenerator
                : CodeGenerator
        {
+            
+               // It is used for beautiful "for" syntax
+               bool dont_write_semicolon;
+            
                //
                // Constructors
                //
                public CSharpCodeGenerator()
                {
+                       dont_write_semicolon = false;
                }
 
                //
@@ -87,7 +92,7 @@ namespace Mono.CSharp
 
                                OutputType( createType );
                                
-                               output.WriteLine( "[] {" );
+                               output.WriteLine( "{" );
                                ++Indent;
                                OutputExpressionList( initializers, true );
                                --Indent;
@@ -278,13 +283,16 @@ namespace Mono.CSharp
                protected override void GenerateExpressionStatement( CodeExpressionStatement statement )
                {
                        GenerateExpression( statement.Expression );
+                       if (dont_write_semicolon)
+                               return;
                        Output.WriteLine( ';' );
                }
 
                protected override void GenerateIterationStatement( CodeIterationStatement statement )
                {
                        TextWriter output = Output;
-
+                    
+                       dont_write_semicolon = true;
                        output.Write( "for (" );
                        GenerateStatement( statement.InitStatement );
                        output.Write( "; " );
@@ -292,7 +300,12 @@ namespace Mono.CSharp
                        output.Write( "; " );
                        GenerateStatement( statement.IncrementStatement );
                        output.Write( ") " );
+                       dont_write_semicolon = false;
+                       output.WriteLine ('{');
+                       ++Indent;
                        GenerateStatements( statement.Statements );
+                       --Indent;
+                       output.WriteLine ('}');
                }
 
                protected override void GenerateThrowExceptionStatement( CodeThrowExceptionStatement statement )
@@ -410,6 +423,8 @@ namespace Mono.CSharp
                        GenerateExpression( statement.Left );
                        output.Write( " = " );
                        GenerateExpression( statement.Right );
+                       if (dont_write_semicolon)
+                               return;
                        output.WriteLine( ';' );
                }
 
@@ -485,6 +500,9 @@ namespace Mono.CSharp
 
                protected override void GenerateEvent( CodeMemberEvent eventRef, CodeTypeDeclaration declaration )
                {
+                       if (eventRef.CustomAttributes.Count > 0)
+                               OutputAttributeDeclarations (eventRef.CustomAttributes);
+
                        OutputMemberAccessModifier (eventRef.Attributes);
                        OutputMemberScopeModifier (eventRef.Attributes | MemberAttributes.Final); // Don't output "virtual"
                        Output.Write ("event ");
@@ -499,14 +517,15 @@ namespace Mono.CSharp
                        if (field.CustomAttributes.Count > 0)
                                OutputAttributeDeclarations( field.CustomAttributes );
 
-                       MemberAttributes attributes = field.Attributes;
-                       OutputMemberAccessModifier( attributes );
-                       OutputFieldScopeModifier( attributes );
-
                        if (IsCurrentEnum)
                                Output.Write(field.Name);
-                       else
+                       else {
+                               MemberAttributes attributes = field.Attributes;
+                               OutputMemberAccessModifier( attributes );
+                               OutputFieldScopeModifier( attributes );
+
                                OutputTypeNamePair( field.Type, GetSafeName (field.Name) );
+                       }
 
                        CodeExpression initExpression = field.InitExpression;
                        if ( initExpression != null ) {
@@ -642,6 +661,9 @@ namespace Mono.CSharp
                protected override void GenerateConstructor( CodeConstructor constructor,
                                                             CodeTypeDeclaration declaration )
                {
+                       if (constructor.CustomAttributes.Count > 0)
+                               OutputAttributeDeclarations (constructor.CustomAttributes);
+
                        OutputMemberAccessModifier (constructor.Attributes);
                        Output.Write (GetSafeName (CurrentTypeName) + " (");
                        OutputParameters (constructor.Parameters);
@@ -796,6 +818,7 @@ namespace Mono.CSharp
                        Output.Write( GetTypeOutput( type ) );
                }
 
+               [MonoTODO ("Implement missing special characters")]
                protected override string QuoteSnippetString( string value )
                {
                        // FIXME: this is weird, but works.
@@ -882,59 +905,60 @@ namespace Mono.CSharp
                        if ( arrayType != null )
                                output = GetTypeOutput( arrayType );
                        else { 
-                               switch ( type.BaseType ) {
 
-                               case "System.Decimal":
+                               switch ( type.BaseType.ToLower (System.Globalization.CultureInfo.InvariantCulture)) {
+
+                               case "system.decimal":
                                        output = "decimal";
                                        break;
-                               case "System.Double":
+                               case "system.double":
                                        output = "double";
                                        break;
-                               case "System.Single":
+                               case "system.single":
                                        output = "float";
                                        break;
                                        
-                               case "System.Byte":
+                               case "system.byte":
                                        output = "byte";
                                        break;
-                               case "System.SByte":
+                               case "system.sbyte":
                                        output = "sbyte";
                                        break;
-                               case "System.Int32":
+                               case "system.int32":
                                        output = "int";
                                        break;
-                               case "System.UInt32":
+                               case "system.uint32":
                                        output = "uint";
                                        break;
-                               case "System.Int64":
+                               case "system.int64":
                                        output = "long";
                                        break;
-                               case "System.UInt64":
+                               case "system.uint64":
                                        output = "ulong";
                                        break;
-                               case "System.Int16":
+                               case "system.int16":
                                        output = "short";
                                        break;
-                               case "System.UInt16":
+                               case "system.uint16":
                                        output = "ushort";
                                        break;
 
-                               case "System.Boolean":
+                               case "system.boolean":
                                        output = "bool";
                                        break;
                                        
-                               case "System.Char":
+                               case "system.char":
                                        output = "char";
                                        break;
 
-                               case "System.String":
+                               case "system.string":
                                        output = "string";
                                        break;
-                               case "System.Object":
+                               case "system.object":
                                        output = "object";
                                        break;
 
-                               case "System.Void":
+                               case "system.void":
                                        output = "void";
                                        break;
 
@@ -954,7 +978,7 @@ namespace Mono.CSharp
                                output += "]";
                        }
 
-                       return output;
+                       return output.Replace ('+', '.');
                }
 
                protected override bool IsValidIdentifier ( string identifier )
index 611bee1616e28660da99d5cd095c089f01dbdae4..1fd92b908e03057b02fa73ca6005216137f00380 100644 (file)
@@ -1,3 +1,13 @@
+2004-09-01 Marek Safar <marek.safar@seznam.cz>
+
+       * CSharpCodeGenerator.cs : New private member dont_write_semicolon.
+       Used for one row "for" syntax.
+       (GenerateEvent): Added attributes output.
+       (GenerateField): Don't output access and scope modifier for enum field.
+       (GenerateConstructor): Added attributes output.
+       (QuoteSnippetString): Fixed mixed case type conversion. Replace '+'
+       with '.' for nested classes.
+
 2004-07-21  Lluis Sanchez Gual  <lluis@novell.com>
 
        * CSharpCodeCompiler.cs: Hack to make code generation work in 2.0.
index a2f6ee391a4f5a64ad1926e5793cdd03cbd563ab..6956bd1fff985ca4494269d2ceeb1e3772b7b9c2 100755 (executable)
@@ -1,3 +1,9 @@
+2004-09-01  Marek Safar  <marek.safar@seznam.cz>
+
+       * CodeGenerator.cs : Added newline after global attributes output.
+       (OutputAttributeDeclaration): Replace '+' with '.' for nested
+       attribute types.
+
 2004-08-09  Atsushi Enomoto  <atsushi@ximian.com>
 
        * CodeGenerator.cs :
index b3f563211bb20e39b31c8b3fb2756db7c1b74923..9b051bae07072fe15443ccb8b6b410edeaba3507 100755 (executable)
@@ -199,6 +199,7 @@ namespace System.CodeDom.Compiler {
                                        OutputAttributeDeclaration (att);
                                        GenerateAttributeDeclarationsEnd (attributes);
                                }
+                               output.WriteLine ();
                        }
 
                        foreach (CodeNamespace ns in compileUnit.Namespaces)
@@ -642,7 +643,7 @@ namespace System.CodeDom.Compiler {
 
                private void OutputAttributeDeclaration (CodeAttributeDeclaration attribute)
                {
-                       output.Write (attribute.Name);
+                       output.Write (attribute.Name.Replace ('+', '.'));
                        output.Write ('(');
                        IEnumerator enumerator = attribute.Arguments.GetEnumerator();
                        if (enumerator.MoveNext()) {
index 4db765c3319b6192d9d68cd2dc65bb0322a74c8f..450d15fdba0cdffc73fd33f8ad8c7dc6a3c5421a 100644 (file)
@@ -1,3 +1,14 @@
+2004-09-01 Marek Safar <marek.safar@seznam.cz>
+
+       * CodeCatchClause.cs: System.Exception is default type
+        for string constructor.
+
+       * CodeTypeMember.cs: Default member attributes are
+       private and final.
+
+       * CodeTypeReference.cs: Implemented array info extraction
+       from Type.
+
 2004-08-09 Gonzalo Paniagua Javier <gonzalo@ximian.com>
 
        * CodeEntryPointMethod.cs: patch by Fawad Halim that makes the entry
index 683185376d4aae8070047b3faee35514554e3d4b..20713c073488aad7b3d373eadbbd7781f23f6a50 100755 (executable)
@@ -52,6 +52,7 @@ namespace System.CodeDom
                public CodeCatchClause ( string localName )
                {
                        this.localName = localName;
+                       this.catchExceptionType = new CodeTypeReference (typeof (Exception));
                }
 
                public CodeCatchClause ( string localName,
index 088901d3371bdaac519e4deee4ee5aeb6b0ef30f..829c131779c23d12452b9914b5d7a9e6ca20986f 100755 (executable)
@@ -50,6 +50,7 @@ namespace System.CodeDom
                //
                public CodeTypeMember()
                {
+                       attributes = (MemberAttributes.Private | MemberAttributes.Final);
                }
                
                //
index 9d507f435937e8569f107fac6384933d331157de..88c0d1d5418734d3175e0827b7586a51df5182ba 100644 (file)
@@ -45,6 +45,7 @@ namespace System.CodeDom
                //
                // Constructors
                //
+               [MonoTODO ("Missing implementation. Implement array info extraction from the string")]
                public CodeTypeReference( string baseType )
                {
                        this.baseType = baseType;
@@ -52,6 +53,11 @@ namespace System.CodeDom
                
                public CodeTypeReference( Type baseType )
                {
+                       if (baseType.IsArray) {
+                               this.rank = baseType.GetArrayRank ();
+                               this.arrayType = new CodeTypeReference (baseType.GetElementType ());
+                               return;
+                       }
                        this.baseType = baseType.FullName;
                }