Fixed space indents to tabs to adhere to Mono coding guidelines.
[mono.git] / mcs / class / System / Microsoft.CSharp / CSharpCodeGenerator.cs
index 730900881c7368c0af9c904b06926ba8d0faf596..e5d9e5e7e669b6fa293eed9d2037467b419084eb 100644 (file)
@@ -4,6 +4,7 @@
 // Author:
 //   Daniel Stodden (stodden@in.tum.de)
 //   Marek Safar (marek.safar@seznam.cz)
+//   Ilker Cetinkaya (mail@ilker.de)
 //
 // (C) 2002 Ximian, Inc.
 //
@@ -171,26 +172,42 @@ namespace Mono.CSharp
                {
                        GenerateCompileUnitStart (compileUnit);
 
+                       GenerateGlobalNamespace (compileUnit);
+
                        if (compileUnit.AssemblyCustomAttributes.Count > 0) {
                                OutputAttributes (compileUnit.AssemblyCustomAttributes, 
                                        "assembly: ", false);
                                Output.WriteLine ("");
                        }
 
-                       foreach (CodeNamespace ns in compileUnit.Namespaces)
-                               GenerateNamespace (ns);
+                       GenerateLocalNamespaces (compileUnit);
 
                        GenerateCompileUnitEnd (compileUnit);
                }
 
-#if NET_2_0
+               private void GenerateGlobalNamespace (CodeCompileUnit compileUnit) {
+                       CodeNamespace globalNamespace = null;
+
+                       foreach (CodeNamespace codeNamespace in compileUnit.Namespaces)
+                               if (string.IsNullOrEmpty (codeNamespace.Name)) 
+                                       globalNamespace = codeNamespace;
+  
+                       if (globalNamespace != null)
+                               GenerateNamespace (globalNamespace);
+               }
+
+               private void GenerateLocalNamespaces (CodeCompileUnit compileUnit) {
+                       foreach (CodeNamespace codeNamespace in compileUnit.Namespaces)
+                               if (!string.IsNullOrEmpty (codeNamespace.Name))
+                                       GenerateNamespace (codeNamespace);
+               }
+
                protected override void GenerateDefaultValueExpression (CodeDefaultValueExpression e)
                {
                        Output.Write ("default(");
                        OutputType (e.Type);
                        Output.Write (')');
                }
-#endif
 
                protected override void GenerateDelegateCreateExpression (CodeDelegateCreateExpression expression)
                {
@@ -1092,6 +1109,9 @@ namespace Mono.CSharp
                                        break;
                        }
 
+                       if ((declaration.Attributes & MemberAttributes.New) != 0)
+                               output.Write ("new ");
+
                        if (declaration.IsStruct) {
                                if (declaration.IsPartial) {
                                        output.Write ("partial ");
@@ -1330,7 +1350,7 @@ namespace Mono.CSharp
                                        break;
                                default:
                                        StringBuilder sb = new StringBuilder (baseType.Length);
-                                       if (type.Options == CodeTypeReferenceOptions.GlobalReference) {
+                                       if ((type.Options & CodeTypeReferenceOptions.GlobalReference) != 0) {
                                                sb.Append ("global::");
                                        }
 
@@ -1384,14 +1404,14 @@ namespace Mono.CSharp
                }
 
                static bool is_identifier_start_character (char c)
-                {
-                        return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || c == '@' || Char.IsLetter (c);
-                }
-
-                static bool is_identifier_part_character (char c)
-                {
-                        return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || (c >= '0' && c <= '9') || Char.IsLetter (c);
-                }
+               {
+                       return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || c == '@' || Char.IsLetter (c);
+               }
+
+               static bool is_identifier_part_character (char c)
+               {
+                       return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || (c >= '0' && c <= '9') || Char.IsLetter (c);
+               }
                
                protected override bool IsValidIdentifier (string identifier)
                {
@@ -1405,13 +1425,13 @@ namespace Mono.CSharp
                                return false;
 
                        if (!is_identifier_start_character (identifier [0]))
-                                return false;
-                        
-                        for (int i = 1; i < identifier.Length; i ++)
-                                if (! is_identifier_part_character (identifier [i]))
-                                        return false;
-                        
-                        return true;
+                               return false;
+
+                       for (int i = 1; i < identifier.Length; i ++)
+                               if (! is_identifier_part_character (identifier [i]))
+                                       return false;
+
+                       return true;
                }
 
                protected override bool Supports (GeneratorSupport supports)