Remove ChangeLog files from the repo
[mono.git] / mcs / class / System / Microsoft.VisualBasic / VBCodeGenerator.cs
index 3c0ced37f0f61b78b2974b979bb9fb4b47baf17d..eed54ad4b63bac3dda99d1e3fc5f22b9d879ccb6 100644 (file)
@@ -56,7 +56,6 @@ namespace Microsoft.VisualBasic
 {
        internal class VBCodeGenerator : CodeGenerator
        {
-#if NET_2_0
                private string [] Keywords = new string [] {
                        "AddHandler", "AddressOf", "Alias", "And",
                        "AndAlso", "Ansi", "As", "Assembly",
@@ -94,45 +93,8 @@ namespace Microsoft.VisualBasic
                        "While", "With", "WithEvents", "WriteOnly", 
                        "Xor" 
                };
-#else
-               private string [] Keywords = new string [] {
-                       "AddHandler", "AddressOf", "Alias", "And",
-                       "AndAlso", "Ansi", "As", "Assembly",
-                       "Auto", "Boolean", "ByRef", "Byte", 
-                       "ByVal", "Call", "Case", "Catch", 
-                       "CBool", "CByte", "CChar", "CDate", 
-                       "CDec", "CDbl", "Char", "CInt", 
-                       "Class", "CLng", "CObj", "Const", 
-                       "CShort", "CSng", "CStr", "CType", 
-                       "Date", "Decimal", "Declare", "Default", 
-                       "Delegate", "Dim", "DirectCast", "Do", 
-                       "Double", "Each", "Else", "ElseIf", 
-                       "End", "Enum", "Erase", "Error", 
-                       "Event", "Exit", "False", "Finally", 
-                       "For", "Friend", "Function", "Get", 
-                       "GetType", "GoSub", "GoTo", "Handles", 
-                       "If", "Implements", "Imports", "In", 
-                       "Inherits", "Integer", "Interface", "Is", 
-                       "Let", "Lib", "Like", "Long", 
-                       "Loop", "Me", "Mod", "Module", 
-                       "MustInherit", "MustOverride", "MyBase", "MyClass", 
-                       "Namespace", "New", "Next", "Not", 
-                       "Nothing", "NotInheritable", "NotOverridable", "Object", 
-                       "On", "Option", "Optional", "Or", 
-                       "OrElse", "Overloads", "Overridable", "Overrides", 
-                       "ParamArray", "Preserve", "Private", "Property", 
-                       "Protected", "Public", "RaiseEvent", "ReadOnly", 
-                       "ReDim", "REM", "RemoveHandler", "Resume", 
-                       "Return", "Select", "Set", "Shadows", 
-                       "Shared", "Short", "Single", "Static", 
-                       "Step", "Stop", "String", "Structure", 
-                       "Sub", "SyncLock", "Then", "Throw", 
-                       "To", "True", "Try", "TypeOf", 
-                       "Unicode", "Until", "Variant", "When", 
-                       "While", "With", "WithEvents", "WriteOnly", 
-                       "Xor" 
-               };
-#endif
+
+               private CodeAttributeDeclarationCollection assemblyCustomAttributes;
 
                public VBCodeGenerator()
                {
@@ -270,13 +232,17 @@ namespace Microsoft.VisualBasic
 
                protected override void GenerateCompileUnit (CodeCompileUnit compileUnit)
                {
-                       GenerateCompileUnitStart (compileUnit);
+                       assemblyCustomAttributes = compileUnit.AssemblyCustomAttributes;
 
-                       OutputAttributes (compileUnit.AssemblyCustomAttributes,
-                               "Assembly: ", LineHandling.NewLine);
+                       GenerateCompileUnitStart (compileUnit);
 
                        GenerateNamespaces (compileUnit);
 
+                       // In the case there are no namespaces, and hence no Import statements, now 
+                       // is the time to emit assembly level attributes.
+                       if (assemblyCustomAttributes != null) 
+                               GenerateAssemblyAttributes ();
+
                        GenerateCompileUnitEnd (compileUnit);
                }
 
@@ -379,13 +345,8 @@ namespace Microsoft.VisualBasic
                {
                        CodeEventReferenceExpression ev = expression.TargetObject as CodeEventReferenceExpression;
                        
-#if ONLY_1_1
-                       Output.Write ("RaiseEvent ");
-#endif
                        if (ev != null) {
-#if NET_2_0
                                Output.Write ("RaiseEvent ");
-#endif
                                if (ev.TargetObject != null && !(ev.TargetObject is CodeThisReferenceExpression)) {
                                        GenerateExpression (ev.TargetObject);
                                        Output.Write (".");
@@ -420,7 +381,6 @@ namespace Microsoft.VisualBasic
                        if (e.Value is char) {
                                char c = (char) e.Value;
                                int ch = (int) c;
-#if NET_2_0
                                Output.Write("Global.Microsoft.VisualBasic.ChrW(" + ch.ToString(CultureInfo.InvariantCulture) + ")");
                        } else if (e.Value is ushort) {
                                ushort uc = (ushort) e.Value;
@@ -439,9 +399,6 @@ namespace Microsoft.VisualBasic
                                Output.Write ("CSByte(");
                                Output.Write (sb.ToString(CultureInfo.InvariantCulture));
                                Output.Write (')');
-#else
-                               Output.Write("Microsoft.VisualBasic.ChrW(" + ch.ToString(CultureInfo.InvariantCulture) + ")");
-#endif
                        } else {
                                base.GeneratePrimitiveExpression(e);
                        }
@@ -716,7 +673,6 @@ namespace Microsoft.VisualBasic
                        output.Write ("Event ");
                        OutputTypeNamePair (eventRef.Type, GetEventName(eventRef));
 
-#if NET_2_0
                        if (eventRef.ImplementationTypes.Count > 0) {
                                OutputImplementationTypes (eventRef.ImplementationTypes, eventRef.Name);
                        } else if (eventRef.PrivateImplementationType != null) {
@@ -725,7 +681,6 @@ namespace Microsoft.VisualBasic
                                output.Write ('.');
                                output.Write (eventRef.Name);
                        }
-#endif
 
                        output.WriteLine ();
                }
@@ -766,10 +721,8 @@ namespace Microsoft.VisualBasic
                
                protected override void GenerateEntryPointMethod (CodeEntryPointMethod method, CodeTypeDeclaration declaration)
                {
-#if NET_2_0
                        OutputAttributes (method.CustomAttributes, null,
                                LineHandling.ContinueLine);
-#endif
 
                        Output.WriteLine ("Public Shared Sub Main()");
                        Indent++;
@@ -812,11 +765,7 @@ namespace Microsoft.VisualBasic
                                output.Write ("Function ");
 
                        output.Write (GetMethodName(method));
-
-#if NET_2_0
                        OutputTypeParameters (method.TypeParameters);
-#endif
-
                        output.Write ('(');
                        OutputParameters (method.Parameters);
                        output.Write (')');
@@ -889,19 +838,11 @@ namespace Microsoft.VisualBasic
 
                        output.Write ("Property ");
                        Output.Write (GetPropertyName (property));
-#if NET_2_0
                        // in .NET 2.0, always output parantheses (whether or not there 
                        // are any parameters to output
                        Output.Write ('(');
                        OutputParameters (property.Parameters);
                        Output.Write (')');
-#else
-                       if (property.Parameters.Count > 0) {
-                               Output.Write ('(');
-                               OutputParameters (property.Parameters);
-                               Output.Write (')');
-                       }
-#endif
                        Output.Write (" As ");
                        Output.Write (GetTypeOutput(property.Type));
 
@@ -920,18 +861,22 @@ namespace Microsoft.VisualBasic
                                ++Indent;
                                if (property.HasGet) {
                                        output.WriteLine ("Get");
-                                       ++Indent;
-                                       GenerateStatements (property.GetStatements);
-                                       --Indent;
-                                       output.WriteLine ("End Get");
+                                       if (!IsAbstract (property.Attributes)) {
+                                               ++Indent;
+                                               GenerateStatements (property.GetStatements);
+                                               --Indent;
+                                               output.WriteLine ("End Get");
+                                       }
                                }
 
                                if (property.HasSet) {
                                        output.WriteLine ("Set");
-                                       ++Indent;
-                                       GenerateStatements (property.SetStatements);
-                                       --Indent;
-                                       output.WriteLine ("End Set");
+                                       if (!IsAbstract (property.Attributes)) {
+                                               ++Indent;
+                                               GenerateStatements (property.SetStatements);
+                                               --Indent;
+                                               output.WriteLine ("End Set");
+                                       }
                                }
 
                                --Indent;
@@ -964,11 +909,7 @@ namespace Microsoft.VisualBasic
                                        Output.Write ("MyBase.New(");
                                        OutputExpressionList (ctorArgs);
                                        Output.WriteLine (")");
-#if NET_2_0
                                } else if (IsCurrentClass) {
-#else
-                               } else {
-#endif
                                        // call default base ctor
                                        Output.WriteLine ("MyBase.New");
                                }
@@ -983,10 +924,8 @@ namespace Microsoft.VisualBasic
                        if (IsCurrentDelegate || IsCurrentEnum || IsCurrentInterface)
                                return;
 
-#if NET_2_0
                        OutputAttributes (constructor.CustomAttributes, null,
                                LineHandling.ContinueLine);
-#endif
 
                        Output.WriteLine ("Shared Sub New()");
                        Indent++;
@@ -1020,9 +959,7 @@ namespace Microsoft.VisualBasic
                                }
 
                                output.Write (CreateEscapedIdentifier (delegateDecl.Name));
-#if NET_2_0
                                OutputTypeParameters (delegateDecl.TypeParameters);
-#endif
                                output.Write ("(");
                                OutputParameters (delegateDecl.Parameters);
                                Output.Write (")");
@@ -1034,9 +971,7 @@ namespace Microsoft.VisualBasic
                        } else {
                                OutputTypeAttributes (declaration);
                                output.Write (CreateEscapedIdentifier (declaration.Name));
-#if NET_2_0
                                OutputTypeParameters (declaration.TypeParameters);
-#endif
 
                                if (IsCurrentEnum) {
                                        if (declaration.BaseTypes.Count > 0) {
@@ -1098,7 +1033,14 @@ namespace Microsoft.VisualBasic
                protected override void GenerateNamespace(CodeNamespace ns)
                {
                        GenerateNamespaceImports (ns);
+
+                       // Assembly level attributes can't be emitted before the Import statements
+                       // in the file.  
+                       if (assemblyCustomAttributes != null)
+                               GenerateAssemblyAttributes ();
+
                        Output.WriteLine ();
+
                        GenerateCommentStatements (ns.Comments);
                        GenerateNamespaceStart (ns); 
                        GenerateTypes (ns);
@@ -1328,11 +1270,7 @@ namespace Microsoft.VisualBasic
                                //
                                MemberAttributes access = attributes & MemberAttributes.AccessMask;
                                if (access == MemberAttributes.Public || 
-#if NET_2_0
                                        access == MemberAttributes.Family || access == MemberAttributes.Assembly)
-#else
-                                       access == MemberAttributes.Family)
-#endif
                                        Output.Write ("Overridable ");
                                break;
                        }
@@ -1400,10 +1338,8 @@ namespace Microsoft.VisualBasic
                        TextWriter output = Output;
                        TypeAttributes attributes = declaration.TypeAttributes;
 
-#if NET_2_0
                        if (declaration.IsPartial)
                                output.Write ("Partial ");
-#endif
                        
                        switch (attributes & TypeAttributes.VisibilityMask) {
                        case TypeAttributes.Public:
@@ -1413,7 +1349,6 @@ namespace Microsoft.VisualBasic
                        case TypeAttributes.NestedPrivate:
                                output.Write ("Private ");
                                break;
-#if NET_2_0
                        case TypeAttributes.NotPublic:
                        case TypeAttributes.NestedFamANDAssem:
                        case TypeAttributes.NestedAssembly:
@@ -1425,7 +1360,6 @@ namespace Microsoft.VisualBasic
                        case TypeAttributes.NestedFamORAssem:
                                output.Write ("Protected Friend ");
                                break;
-#endif
                        }
 
                        if (declaration.IsStruct) {
@@ -1447,7 +1381,6 @@ namespace Microsoft.VisualBasic
                        }
                }
 
-#if NET_2_0
                void OutputTypeParameters (CodeTypeParameterCollection parameters)
                {
                        int count = parameters.Count;
@@ -1493,14 +1426,11 @@ namespace Microsoft.VisualBasic
                        if (constraint_count > 1)
                                Output.Write ("}");
                }
-#endif
 
                protected override void OutputTypeNamePair (CodeTypeReference typeRef, String name)
                {
-#if NET_2_0
                        if (name.Length == 0)
                                name = "__exception";
-#endif
                        Output.Write (CreateEscapedIdentifier(name) + " As " + GetTypeOutput (typeRef));
                }
 
@@ -1621,7 +1551,6 @@ namespace Microsoft.VisualBasic
                                case "System.Object":
                                        output = "Object";
                                        break;
-#if NET_2_0
                                case "System.SByte":
                                        output = "SByte";
                                        break;
@@ -1634,7 +1563,6 @@ namespace Microsoft.VisualBasic
                                case "System.UInt64":
                                        output = "ULong";
                                        break;
-#endif
                                default:
                                        output = type.BaseType.Replace('+', '.');
                                        output = CreateEscapedIdentifier (output);
@@ -1706,15 +1634,11 @@ namespace Microsoft.VisualBasic
 
                private string GetEventName (CodeMemberEvent evt)
                {
-#if NET_2_0
                        if (evt.PrivateImplementationType == null)
                                return evt.Name;
 
                        string baseType = evt.PrivateImplementationType.BaseType.Replace ('.', '_');
                        return baseType + "_" + evt.Name;
-#else
-                       return evt.Name;
-#endif
                }
 
                private string GetMethodName (CodeMemberMethod method)
@@ -1735,6 +1659,18 @@ namespace Microsoft.VisualBasic
                        return baseType + "_" + property.Name;
                }
 
+               static bool IsAbstract (MemberAttributes attributes)
+               {
+                       return (attributes & MemberAttributes.ScopeMask) == MemberAttributes.Abstract;
+               }
+
+               private void GenerateAssemblyAttributes ()
+               {
+                       OutputAttributes (assemblyCustomAttributes,
+                               "Assembly: ", LineHandling.NewLine);
+                       assemblyCustomAttributes = null;
+               }
+
                private enum LineHandling
                {
                        InLine,