Ooops.
[mono.git] / mcs / gmcs / codegen.cs
old mode 100755 (executable)
new mode 100644 (file)
index bf708bc..7f5d62e
@@ -88,7 +88,7 @@ namespace Mono.CSharp {
                        //
                        if (SymbolWriter == null) {
                                Report.Warning (
-                                       -18, "Could not find the symbol writer assembly (Mono.CSharp.Debugger.dll). This is normally an installation problem. Please make sure to compile and install the mcs/class/Mono.CSharp.Debugger directory.");
+                                       -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.");
                                return;
                        }
                }
@@ -435,6 +435,9 @@ namespace Mono.CSharp {
                        DeclSpace = ds;
                        CheckState = RootContext.Checked;
                        ConstantCheckState = true;
+
+                       if ((return_type is TypeBuilder) && return_type.IsGenericTypeDefinition)
+                               throw new Exception ("FUCK");
                        
                        IsStatic = (code_flags & Modifiers.STATIC) != 0;
                        InIterator = (code_flags & Modifiers.METHOD_YIELDS) != 0;
@@ -661,7 +664,7 @@ namespace Mono.CSharp {
                                CurrentFile = loc.File;
 
 #if PRODUCTION
-                       try {
+                           try {
 #endif
                                int errors = Report.Errors;
 
@@ -697,15 +700,15 @@ namespace Mono.CSharp {
                                                unreachable = true;
                                        }
 #if PRODUCTION
-                       } catch (Exception e) {
-                               Console.WriteLine ("Exception caught by the compiler while compiling:");
-                               Console.WriteLine ("   Block that caused the problem begin at: " + loc);
-
-                               if (CurrentBlock != null){
-                                       Console.WriteLine ("                     Block being compiled: [{0},{1}]",
-                                                          CurrentBlock.StartLocation, CurrentBlock.EndLocation);
-                               }
-                               Console.WriteLine (e.GetType ().FullName + ": " + e.Message);
+                           } catch (Exception e) {
+                                       Console.WriteLine ("Exception caught by the compiler while compiling:");
+                                       Console.WriteLine ("   Block that caused the problem begin at: " + loc);
+                                       
+                                       if (CurrentBlock != null){
+                                               Console.WriteLine ("                     Block being compiled: [{0},{1}]",
+                                                                  CurrentBlock.StartLocation, CurrentBlock.EndLocation);
+                                       }
+                                       Console.WriteLine (e.GetType ().FullName + ": " + e.Message);
                                throw;
                        }
 #endif
@@ -716,7 +719,7 @@ namespace Mono.CSharp {
                                                Report.Error (1643, loc, "Not all code paths return a value in anonymous method of type `{0}'",
                                                              CurrentAnonymousMethod.Type);
                                        } else {
-                                               Report.Error (161, loc, "Not all code paths return a value");
+                                       Report.Error (161, loc, "Not all code paths return a value");
                                        }
 
                                        return false;
@@ -908,7 +911,7 @@ namespace Mono.CSharp {
                        
                        if (!InIterator && !HasReturnLabel) 
                                HasReturnLabel = true;
-               }
+                       }
 
                //
                // Creates a field `name' with the type `t' on the proxy class
@@ -1025,7 +1028,6 @@ namespace Mono.CSharp {
                                return;
                        }
                        OptAttributes.AddAttributes (attrs);
-                       OptAttributes.CheckTargets (this);
                }
 
                public virtual void Emit (TypeContainer tc) 
@@ -1042,7 +1044,11 @@ namespace Mono.CSharp {
                        if (OptAttributes == null)
                                return null;
 
-                       EmitContext temp_ec = new EmitContext (new RootTypes (), Mono.CSharp.Location.Null, null, null, 0, false);
+                       // Ensure that we only have GlobalAttributes, since the Search below isn't safe with other types.
+                       if (!OptAttributes.CheckTargets (this))
+                               return null;
+
+                       EmitContext temp_ec = new EmitContext (RootContext.Tree.Types, Mono.CSharp.Location.Null, null, null, 0, false);
                        Attribute a = OptAttributes.Search (TypeManager.cls_compliant_attribute_type, temp_ec);
                        if (a != null) {
                                a.Resolve (temp_ec);
@@ -1056,6 +1062,7 @@ namespace Mono.CSharp {
                public AssemblyBuilder Builder;
                     
                bool is_cls_compliant;
+               public Attribute ClsCompliantAttribute;
 
                ListDictionary declarative_security;
 
@@ -1085,11 +1092,11 @@ namespace Mono.CSharp {
 
                public void ResolveClsCompliance ()
                {
-                       Attribute a = GetClsCompliantAttribute ();
-                       if (a == null)
+                       ClsCompliantAttribute = GetClsCompliantAttribute ();
+                       if (ClsCompliantAttribute == null)
                                return;
 
-                       is_cls_compliant = a.GetClsCompliantAttributeValue (null);
+                       is_cls_compliant = ClsCompliantAttribute.GetClsCompliantAttributeValue (null);
                }
 
                // fix bug #56621
@@ -1123,12 +1130,15 @@ namespace Mono.CSharp {
                        }
                }
 
+               // TODO: rewrite this code (to kill N bugs and make it faster) and use standard ApplyAttribute way.
                public AssemblyName GetAssemblyName (string name, string output) 
                {
                        if (OptAttributes != null) {
                                foreach (Attribute a in OptAttributes.Attrs) {
-                                       if (a.Target != AttributeTargets.Assembly)
-                                               continue;
+                                      // cannot rely on any resolve-based members before you call Resolve
+                                      if (a.ExplicitTarget == null || a.ExplicitTarget != "assembly")
+                                              continue;
+
                                        // TODO: This code is buggy: comparing Attribute name without resolving it is wrong.
                                        //       However, this is invoked by CodeGen.Init, at which time none of the namespaces
                                        //       are loaded yet.
@@ -1320,13 +1330,20 @@ namespace Mono.CSharp {
                                return;
                        }
                                
-                       ApplyAttributeBuilder (null, new CustomAttributeBuilder (TypeManager.unverifiable_code_ctor, new object [0]));
+                       Builder.SetCustomAttribute (new CustomAttributeBuilder (TypeManager.unverifiable_code_ctor, new object [0]));
                }
                 
                public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder customBuilder)
                {
-                       if (a != null && a.Type == TypeManager.cls_compliant_attribute_type) {
-                               Report.Warning (3012, a.Location, "You must specify the CLSCompliant attribute on the assembly, not the module, to enable CLS compliance checking");
+                       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");
+                               }
+                               else if (CodeGen.Assembly.IsClsCompliant != a.GetBoolean ()) {
+                                       Report.SymbolRelatedToPreviousError (CodeGen.Assembly.ClsCompliantAttribute.Location, CodeGen.Assembly.ClsCompliantAttribute.Name);
+                                       Report.Error (3017, a.Location, "You cannot specify the CLSCompliant attribute on a module that differs from the CLSCompliant attribute on the assembly");
+                                       return;
+                               }
                        }
 
                        Builder.SetCustomAttribute (customBuilder);