Revert until fixed
[mono.git] / mcs / mcs / codegen.cs
index afdb0fca3b9dd106ecd1825ecc833afadfeafe6b..4f90c9f60056ffa020a7f0a20510440f2ecf78ae 100644 (file)
@@ -7,7 +7,11 @@
 // (C) 2001, 2002, 2003 Ximian, Inc.
 // (C) 2004 Novell, Inc.
 //
-#define PRODUCTION
+
+#if !DEBUG
+       #define PRODUCTION
+#endif
+
 using System;
 using System.IO;
 using System.Collections;
@@ -86,7 +90,7 @@ namespace Mono.CSharp {
                        //
                        if (SymbolWriter == null) {
                                Report.Warning (
-                                       -18, "Could not find the symbol writer assembly (Mono.CompilerServices.SymbolWriter.dll). This is normally an installation problem. Please make sure to compile and install the mcs/class/Mono.CompilerServices.SymbolWriter directory.");
+                                       -18, 1, "Could not find the symbol writer assembly (Mono.CompilerServices.SymbolWriter.dll). This is normally an installation problem. Please make sure to compile and install the mcs/class/Mono.CompilerServices.SymbolWriter directory.");
                                return;
                        }
                }
@@ -104,11 +108,11 @@ namespace Mono.CSharp {
                        if (an.KeyPair != null) {
                                // If we are going to strong name our assembly make
                                // sure all its refs are strong named
-                               foreach (Assembly a in TypeManager.GetAssemblies ()) {
+                               foreach (Assembly a in RootNamespace.Global.Assemblies) {
                                        AssemblyName ref_name = a.GetName ();
                                        byte [] b = ref_name.GetPublicKeyToken ();
                                        if (b == null || b.Length == 0) {
-                                               Report.Warning (1577, "Assembly generation failed " +
+                                               Report.Error (1577, "Assembly generation failed " +
                                                                "-- Referenced assembly '" +
                                                                ref_name.Name +
                                                                "' does not have a strong name.");
@@ -254,6 +258,11 @@ namespace Mono.CSharp {
                /// </summary>
                public bool DoFlowAnalysis;
 
+               /// <summary>
+               ///   Whether we're control flow analysis disabled on struct
+               /// </summary>
+               public bool OmitStructFlowAnalysis;
+
                /// <summary>
                ///   Keeps track of the Type to LocalBuilder temporary storage created
                ///   to store structures (used to compute the address of the structure
@@ -502,7 +511,7 @@ namespace Mono.CSharp {
 
                public void CaptureThis ()
                {
-                       capture_context.CaptureThis ();
+                       capture_context.CaptureThis (CurrentAnonymousMethod);
                }
                
                
@@ -563,7 +572,7 @@ namespace Mono.CSharp {
                        return false;
                }
                
-               public void EmitMeta (ToplevelBlock b, InternalParameters ip)
+               public void EmitMeta (ToplevelBlock b)
                {
                        if (capture_context != null)
                                capture_context.EmitAnonymousHelperClasses (this);
@@ -578,15 +587,15 @@ namespace Mono.CSharp {
                // currently can not cope with ig == null during resolve (which must
                // be fixed for switch statements to work on anonymous methods).
                //
-               public void EmitTopBlock (IMethodData md, ToplevelBlock block, InternalParameters ip)
+               public void EmitTopBlock (IMethodData md, ToplevelBlock block)
                {
                        if (block == null)
                                return;
                        
                        bool unreachable;
                        
-                       if (ResolveTopBlock (null, block, ip, md, out unreachable)){
-                               EmitMeta (block, ip);
+                       if (ResolveTopBlock (null, block, md.ParameterInfo, md, out unreachable)){
+                               EmitMeta (block);
 
                                current_phase = Phase.Emitting;
                                EmitResolvedTopBlock (block, unreachable);
@@ -596,7 +605,7 @@ namespace Mono.CSharp {
                bool resolved;
 
                public bool ResolveTopBlock (EmitContext anonymous_method_host, ToplevelBlock block,
-                                            InternalParameters ip, IMethodData md, out bool unreachable)
+                                            Parameters ip, IMethodData md, out bool unreachable)
                {
                        current_phase = Phase.Resolving;
                        
@@ -607,7 +616,7 @@ namespace Mono.CSharp {
 
                        capture_context = block.CaptureContext;
                        
-                       if (!Location.IsNull (loc))
+                       if (!loc.IsNull)
                                CurrentFile = loc.File;
 
 #if PRODUCTION
@@ -721,13 +730,13 @@ namespace Mono.CSharp {
                /// </summary>
                public void Mark (Location loc, bool check_file)
                {
-                       if ((CodeGen.SymbolWriter == null) || Location.IsNull (loc))
+                       if ((CodeGen.SymbolWriter == null) || loc.IsNull)
                                return;
 
                        if (check_file && (CurrentFile != loc.File))
                                return;
 
-                       CodeGen.SymbolWriter.MarkSequencePoint (ig, loc.Row, 0);
+                       CodeGen.SymbolWriter.MarkSequencePoint (ig, loc.Row, loc.Column);
                }
 
                public void DefineLocalVariable (string name, LocalBuilder builder)
@@ -937,7 +946,7 @@ namespace Mono.CSharp {
        }
 
 
-       public abstract class CommonAssemblyModulClass: Attributable {
+       public abstract class CommonAssemblyModulClass : Attributable {
                protected CommonAssemblyModulClass ():
                        base (null)
                {
@@ -979,10 +988,12 @@ namespace Mono.CSharp {
                }
        }
                 
-       public class AssemblyClass: CommonAssemblyModulClass {
+       public class AssemblyClass : CommonAssemblyModulClass {
                // TODO: make it private and move all builder based methods here
                public AssemblyBuilder Builder;
                bool is_cls_compliant;
+               bool wrap_non_exception_throws;
+
                public Attribute ClsCompliantAttribute;
 
                ListDictionary declarative_security;
@@ -992,7 +1003,7 @@ namespace Mono.CSharp {
 
                public AssemblyClass (): base ()
                {
-                       is_cls_compliant = false;
+                       wrap_non_exception_throws = true;
                }
 
                public bool IsClsCompliant {
@@ -1001,24 +1012,38 @@ namespace Mono.CSharp {
                        }
                }
 
+               public bool WrapNonExceptionThrows {
+                       get {
+                               return wrap_non_exception_throws;
+                       }
+               }
+
                public override AttributeTargets AttributeTargets {
                        get {
                                return AttributeTargets.Assembly;
                        }
                }
 
-               public override bool IsClsCompliaceRequired(DeclSpace ds)
+               public override bool IsClsComplianceRequired(DeclSpace ds)
                {
                        return is_cls_compliant;
                }
 
-               public void ResolveClsCompliance ()
+               public void Resolve ()
                {
                        ClsCompliantAttribute = ResolveAttribute (TypeManager.cls_compliant_attribute_type);
-                       if (ClsCompliantAttribute == null)
-                               return;
+                       if (ClsCompliantAttribute != null) {
+                               is_cls_compliant = ClsCompliantAttribute.GetClsCompliantAttributeValue (null);
+                       }
 
-                       is_cls_compliant = ClsCompliantAttribute.GetClsCompliantAttributeValue (null);
+#if NET_2_0
+                       Attribute a = ResolveAttribute (TypeManager.runtime_compatibility_attr_type);
+                       if (a != null) {
+                               object val = a.GetPropertyValue ("WrapNonExceptionThrows");
+                               if (val != null)
+                                       wrap_non_exception_throws = (bool)val;
+                       }
+#endif
                }
 
                // fix bug #56621
@@ -1046,7 +1071,7 @@ namespace Mono.CSharp {
                                }
                        }
                        catch (Exception) {
-                               Error_AssemblySigning ("The speficied file `" + RootContext.StrongNameKeyFile + "' is incorrectly encoded");
+                               Error_AssemblySigning ("The specified file `" + RootContext.StrongNameKeyFile + "' is incorrectly encoded");
                                Environment.Exit (1);
                        }
                }
@@ -1070,7 +1095,7 @@ namespace Mono.CSharp {
                                                case "System.Reflection.AssemblyKeyFileAttribute":
                                                        if (RootContext.StrongNameKeyFile != null) {
                                                                Report.SymbolRelatedToPreviousError (a.Location, a.Name);
-                                                               Report.Warning (1616, "Option `{0}' overrides attribute `{1}' given in a source file or added module",
+                                                               Report.Warning (1616, 1, "Option `{0}' overrides attribute `{1}' given in a source file or added module",
                                     "keyfile", "System.Reflection.AssemblyKeyFileAttribute");
                                                        }
                                                        else {
@@ -1084,7 +1109,7 @@ namespace Mono.CSharp {
                                                case "System.Reflection.AssemblyKeyNameAttribute":
                                                        if (RootContext.StrongNameKeyContainer != null) {
                                                                Report.SymbolRelatedToPreviousError (a.Location, a.Name);
-                                                               Report.Warning (1616, "Option `{0}' overrides attribute `{1}' given in a source file or added module",
+                                                               Report.Warning (1616, 1, "Option `{0}' overrides attribute `{1}' given in a source file or added module",
                                                                        "keycontainer", "System.Reflection.AssemblyKeyNameAttribute");
                                                        }
                                                        else {
@@ -1152,7 +1177,7 @@ namespace Mono.CSharp {
                                                                        "ECMA key can only be used to delay-sign assemblies");
                                                        }
                                                        else {
-                                                               Error_AssemblySigning ("The speficied file `" + RootContext.StrongNameKeyFile + "' does not have a private key");
+                                                               Error_AssemblySigning ("The specified file `" + RootContext.StrongNameKeyFile + "' does not have a private key");
                                                        }
                                                        return null;
                                                }
@@ -1160,7 +1185,7 @@ namespace Mono.CSharp {
                                }
                        }
                        else {
-                               Error_AssemblySigning ("The speficied file `" + RootContext.StrongNameKeyFile + "' does not exist");
+                               Error_AssemblySigning ("The specified file `" + RootContext.StrongNameKeyFile + "' does not exist");
                                return null;
                        }
                        return an;
@@ -1223,6 +1248,15 @@ namespace Mono.CSharp {
                                        Report.RuntimeMissingSupport (Location.Null, "assembly permission setting");
                                }
                        }
+
+#if NET_2_0
+                       if (!OptAttributes.Contains (TypeManager.runtime_compatibility_attr_type, null)) {
+                               ConstructorInfo ci = TypeManager.runtime_compatibility_attr_type.GetConstructor (TypeManager.NoTypes);
+                               PropertyInfo pi = TypeManager.runtime_compatibility_attr_type.GetProperty ("WrapNonExceptionThrows");
+                               Builder.SetCustomAttribute (new CustomAttributeBuilder (ci, new object [0], 
+                                       new PropertyInfo [] { pi }, new object[] { true } ));
+                       }
+#endif
                }
 
                public override string[] ValidAttributeTargets {
@@ -1232,7 +1266,7 @@ namespace Mono.CSharp {
                }
        }
 
-       public class ModuleClass: CommonAssemblyModulClass {
+       public class ModuleClass : CommonAssemblyModulClass {
                // TODO: make it private and move all builder based methods here
                public ModuleBuilder Builder;
                bool m_module_is_unsafe;
@@ -1253,7 +1287,7 @@ namespace Mono.CSharp {
                        }
                }
 
-               public override bool IsClsCompliaceRequired(DeclSpace ds)
+               public override bool IsClsComplianceRequired(DeclSpace ds)
                {
                        return CodeGen.Assembly.IsClsCompliant;
                }
@@ -1277,7 +1311,7 @@ namespace Mono.CSharp {
                {
                        if (a.Type == TypeManager.cls_compliant_attribute_type) {
                                if (CodeGen.Assembly.ClsCompliantAttribute == null) {
-                                       Report.Warning (3012, a.Location, "You must specify the CLSCompliant attribute on the assembly, not the module, to enable CLS compliance checking");
+                                       Report.Warning (3012, 1, a.Location, "You must specify the CLSCompliant attribute on the assembly, not the module, to enable CLS compliance checking");
                                }
                                else if (CodeGen.Assembly.IsClsCompliant != a.GetBoolean ()) {
                                        Report.SymbolRelatedToPreviousError (CodeGen.Assembly.ClsCompliantAttribute.Location, CodeGen.Assembly.ClsCompliantAttribute.GetSignatureForError ());