condition tests passes
[mono.git] / mcs / mcs / codegen.cs
index c2de800e14e4738da12db2462bc52270c72995a8..af57f0f9a717474010dcfc76972972dbc59dc82e 100644 (file)
@@ -21,6 +21,7 @@ using System;
 using System.IO;
 using System.Collections;
 using System.Collections.Specialized;
+using System.Globalization;
 using System.Reflection;
 using System.Reflection.Emit;
 using System.Runtime.InteropServices;
@@ -282,7 +283,9 @@ namespace Mono.CSharp {
                        //
                        InFieldInitializer = 1 << 8,
                        
-                       InferReturnType = 1 << 9
+                       InferReturnType = 1 << 9,
+                       
+                       InCompoundAssignment = 1 << 10
                }
 
                Flags flags;
@@ -312,7 +315,7 @@ namespace Mono.CSharp {
                ///   Points to the Type (extracted from the TypeContainer) that
                ///   declares this body of code
                /// </summary>
-               public Type ContainerType;
+               public readonly Type ContainerType;
                
                /// <summary>
                ///   Whether this is generating code for a constructor
@@ -580,6 +583,10 @@ namespace Mono.CSharp {
                public bool IsInFieldInitializer {
                        get { return (flags & Flags.InFieldInitializer) != 0; }
                }
+               
+               public bool IsInCompoundAssignment {
+                       get { return (flags & Flags.InCompoundAssignment) != 0; }
+               }               
 
                public FlowBranching CurrentBranching {
                        get { return current_flow_branching; }
@@ -1305,7 +1312,7 @@ namespace Mono.CSharp {
                        else if (aname.Version != null || aname.CultureInfo != null)
                                throw new Exception ("Friend assembly `" + a.GetString () + 
                                                "' is invalid. InternalsVisibleTo cannot have version or culture specified.");
-                       else if (aname.GetPublicKey () == null && Name.GetPublicKey () != null) {
+                       else if (aname.GetPublicKey () == null && Name.GetPublicKey () != null && Name.GetPublicKey ().Length != 0) {
                                Report.Error (1726, a.Location, "Friend assembly reference `" + aname.FullName + "' is invalid." +
                                                " Strong named assemblies must specify a public key in their InternalsVisibleTo declarations");
                                return false;
@@ -1315,6 +1322,28 @@ namespace Mono.CSharp {
                }
 #endif
 
+               static bool IsValidAssemblyVersion (string version)
+               {
+                       Version v;
+                       try {
+                               v = new Version (version);
+                       } catch {
+                               try {
+                                       int major = int.Parse (version, CultureInfo.InvariantCulture);
+                                       v = new Version (major, 0);
+                               } catch {
+                                       return false;
+                               }
+                       }
+
+                       foreach (int candidate in new int [] { v.Major, v.Minor, v.Build, v.Revision }) {
+                               if (candidate > ushort.MaxValue)
+                                       return false;
+                       }
+
+                       return true;
+               }
+
                public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder customBuilder)
                {
                        if (a.Type.IsSubclassOf (TypeManager.security_attr_type) && a.CheckSecurityActionValidity (true)) {
@@ -1336,6 +1365,19 @@ namespace Mono.CSharp {
                                }
                        }
 
+                       if (a.Type == TypeManager.assembly_version_attribute_type) {
+                               string value = a.GetString ();
+                               if (value == null || value.Length == 0)
+                                       return;
+
+                               value = value.Replace ('*', '0');
+
+                               if (!IsValidAssemblyVersion (value)) {
+                                       a.Error_AttributeEmitError (string.Format ("Specified version `{0}' is not valid", value));
+                                       return;
+                               }
+                       }
+
 #if GMCS_SOURCE
                        if (a.Type == TypeManager.internals_visible_attr_type && !CheckInternalsVisibleAttribute (a))
                                return;