2008-11-05 Marek Safar <marek.safar@gmail.com>
authorMarek Safar <marek.safar@gmail.com>
Wed, 5 Nov 2008 19:26:57 +0000 (19:26 -0000)
committerMarek Safar <marek.safar@gmail.com>
Wed, 5 Nov 2008 19:26:57 +0000 (19:26 -0000)
A fix for bug #436318
* driver.cs, report.cs: Add -warnaserror:Wn to command line options.

svn path=/trunk/mcs/; revision=118021

mcs/mcs/ChangeLog
mcs/mcs/driver.cs
mcs/mcs/report.cs

index b200937c8fcce59d039b94392694be4c2cc40fdb..a60de6a9f0babfcf8bed31f5397f713a4ff1114a 100644 (file)
@@ -1,3 +1,8 @@
+2008-11-05  Marek Safar  <marek.safar@gmail.com>
+
+       A fix for bug #436318
+       * driver.cs, report.cs: Add -warnaserror:Wn to command line options.
+
 2008-11-05  Miguel de Icaza  <miguel@novell.com>
 
        * namespace.cs: Turns out that it was a really bad idea to hide
index a8a06474a2a5b4b3dee993274ed2fe4c919f780a..1d5b448a83958d4c34cb54ab1cdbb8e155d73116 100644 (file)
@@ -93,6 +93,8 @@ namespace Mono.CSharp
                //
                Encoding encoding;
 
+               static readonly char[] argument_value_separator = new char [] { ';', ',' };
+
                static public void Reset ()
                {
                        embedded_resources = null;
@@ -225,38 +227,39 @@ namespace Mono.CSharp
                        Console.WriteLine (
                                "Mono C# compiler, Copyright 2001 - 2008 Novell, Inc.\n" +
                                "mcs [options] source-files\n" +
-                               "   --about            About the Mono C# compiler\n" +
-                               "   -addmodule:M1[,Mn] Adds the module to the generated assembly\n" + 
-                               "   -checked[+|-]      Sets default aritmetic overflow context\n" +
-                               "   -codepage:ID       Sets code page to the one in ID (number, utf8, reset)\n" +
-                               "   -clscheck[+|-]     Disables CLS Compliance verifications\n" +
-                               "   -define:S1[;S2]    Defines one or more conditional symbols (short: -d)\n" +
-                               "   -debug[+|-], -g    Generate debugging information\n" + 
-                               "   -delaysign[+|-]    Only insert the public key into the assembly (no signing)\n" +
-                               "   -doc:FILE          Process documentation comments to XML file\n" + 
-                               "   -help              Lists all compiler options (short: -?)\n" + 
-                               "   -keycontainer:NAME The key pair container used to sign the output assembly\n" +
-                               "   -keyfile:FILE      The key file used to strongname the ouput assembly\n" +
-                               "   -langversion:TEXT  Specifies language version modes: ISO-1, ISO-2, or Default\n" + 
-                               "   -lib:PATH1[,PATHn] Specifies the location of referenced assemblies\n" +
-                               "   -main:CLASS        Specifies the class with the Main method (short: -m)\n" +
-                               "   -noconfig          Disables implicitly referenced assemblies\n" +
-                               "   -nostdlib[+|-]     Does not reference mscorlib.dll library\n" +
-                               "   -nowarn:W1[,Wn]    Suppress one or more compiler warnings\n" + 
-                               "   -optimize[+|-]     Enables advanced compiler optimizations (short: -o)\n" + 
-                               "   -out:FILE          Specifies output assembly name\n" +
+                               "   --about              About the Mono C# compiler\n" +
+                               "   -addmodule:M1[,Mn]   Adds the module to the generated assembly\n" + 
+                               "   -checked[+|-]        Sets default aritmetic overflow context\n" +
+                               "   -codepage:ID         Sets code page to the one in ID (number, utf8, reset)\n" +
+                               "   -clscheck[+|-]       Disables CLS Compliance verifications\n" +
+                               "   -define:S1[;S2]      Defines one or more conditional symbols (short: -d)\n" +
+                               "   -debug[+|-], -g      Generate debugging information\n" + 
+                               "   -delaysign[+|-]      Only insert the public key into the assembly (no signing)\n" +
+                               "   -doc:FILE            Process documentation comments to XML file\n" + 
+                               "   -help                Lists all compiler options (short: -?)\n" + 
+                               "   -keycontainer:NAME   The key pair container used to sign the output assembly\n" +
+                               "   -keyfile:FILE        The key file used to strongname the ouput assembly\n" +
+                               "   -langversion:TEXT    Specifies language version modes: ISO-1, ISO-2, or Default\n" + 
+                               "   -lib:PATH1[,PATHn]   Specifies the location of referenced assemblies\n" +
+                               "   -main:CLASS          Specifies the class with the Main method (short: -m)\n" +
+                               "   -noconfig            Disables implicitly referenced assemblies\n" +
+                               "   -nostdlib[+|-]       Does not reference mscorlib.dll library\n" +
+                               "   -nowarn:W1[,Wn]      Suppress one or more compiler warnings\n" + 
+                               "   -optimize[+|-]       Enables advanced compiler optimizations (short: -o)\n" + 
+                               "   -out:FILE            Specifies output assembly name\n" +
 #if !SMCS_SOURCE
-                               "   -pkg:P1[,Pn]       References packages P1..Pn\n" + 
+                               "   -pkg:P1[,Pn]         References packages P1..Pn\n" + 
 #endif
-                               "   -recurse:SPEC      Recursively compiles files according to SPEC pattern\n" + 
-                               "   -reference:A1[,An] Imports metadata from the specified assembly (short: -r)\n" +
-                               "   -reference:ALIAS=A Imports metadata using specified extern alias (short: -r)\n" +                           
-                               "   -target:KIND       Specifies the format of the output assembly (short: -t)\n" +
-                               "                      KIND can be one of: exe, winexe, library, module\n" +
-                               "   -unsafe[+|-]       Allows to compile code which uses unsafe keyword\n" +
-                               "   -warnaserror[+|-]  Treats all warnings as errors\n" +
-                               "   -warn:0-4          Sets warning level, the default is 4 (short -w:)\n" +
-                               "   -help2             Shows internal compiler options\n" + 
+                               "   -recurse:SPEC        Recursively compiles files according to SPEC pattern\n" + 
+                               "   -reference:A1[,An]   Imports metadata from the specified assembly (short: -r)\n" +
+                               "   -reference:ALIAS=A   Imports metadata using specified extern alias (short: -r)\n" +                         
+                               "   -target:KIND         Specifies the format of the output assembly (short: -t)\n" +
+                               "                        KIND can be one of: exe, winexe, library, module\n" +
+                               "   -unsafe[+|-]         Allows to compile code which uses unsafe keyword\n" +
+                               "   -warnaserror[+|-]    Treats all warnings as errors\n" +
+                               "   -warnaserror:W1[,Wn] Treats one or more compiler warnings as errors\n" +
+                               "   -warn:0-4            Sets warning level, the default is 4 (short -w:)\n" +
+                               "   -help2               Shows internal compiler options\n" + 
                                "\n" +
                                "Resources:\n" +
                                "   -linkresource:FILE[,ID] Links FILE as a resource (short: -linkres)\n" +
@@ -1182,7 +1185,7 @@ namespace Mono.CSharp
                                        Environment.Exit (1);
                                }
 
-                               foreach (string d in value.Split (';', ',')){
+                               foreach (string d in value.Split (argument_value_separator)) {
                                        if (!Tokenizer.IsValidIdentifier (d)) {
                                                Report.Warning (2029, 1, "Invalid conditional define symbol `{0}'", d);
                                                continue;
@@ -1226,7 +1229,7 @@ namespace Mono.CSharp
                                        embedded_resources = new Resources ();
 
                                bool embeded = arg.StartsWith ("/r");
-                               string[] s = value.Split (',');
+                               string[] s = value.Split (argument_value_separator);
                                switch (s.Length) {
                                case 1:
                                        if (s[0].Length == 0)
@@ -1265,7 +1268,7 @@ namespace Mono.CSharp
                                        Environment.Exit (1);
                                }
 
-                               string [] refs = value.Split (new char [] { ';', ',' });
+                               string[] refs = value.Split (argument_value_separator);
                                foreach (string r in refs){
                                        string val = r;
                                        int index = val.IndexOf ('=');
@@ -1287,7 +1290,7 @@ namespace Mono.CSharp
                                        Environment.Exit (1);
                                }
 
-                               string [] refs = value.Split (new char [] { ';', ',' });
+                               string[] refs = value.Split (argument_value_separator);
                                foreach (string r in refs){
                                        modules.Add (r);
                                }
@@ -1333,7 +1336,7 @@ namespace Mono.CSharp
                                        Environment.Exit (1);
                                }
 
-                               libdirs = value.Split (new Char [] { ',' });
+                               libdirs = value.Split (argument_value_separator);
                                foreach (string dir in libdirs)
                                        link_paths.Add (dir);
                                return true;
@@ -1375,6 +1378,14 @@ namespace Mono.CSharp
                                return true;
 
                        case "/warnaserror":
+                               if (value.Length == 0) {
+                                       Report.WarningsAreErrors = true;
+                               } else {
+                                       foreach (string wid in value.Split (argument_value_separator))
+                                               Report.AddWarningAsError (wid);
+                               }
+                               return true;
+
                        case "/warnaserror+":
                                Report.WarningsAreErrors = true;
                                return true;
@@ -1394,8 +1405,8 @@ namespace Mono.CSharp
                                        Report.Error (5, "/nowarn requires an argument");
                                        Environment.Exit (1);
                                }
-                               
-                               warns = value.Split (new Char [] {','});
+
+                               warns = value.Split (argument_value_separator);
                                foreach (string wc in warns){
                                        try {
                                                int warn = Int32.Parse (wc);
index 8122aa13dfb75603ceb91e5c4abbe3815455dcd0..2096450fdb10e5c736189deeb22f19470f2d45a1 100644 (file)
@@ -41,7 +41,7 @@ namespace Mono.CSharp {
                ///   Whether warnings should be considered errors
                /// </summary>
                static public bool WarningsAreErrors;
-
+               static ArrayList warnings_as_error;
 
                /// <summary>  
                ///   Whether to dump a stack trace on errors. 
@@ -123,6 +123,7 @@ namespace Mono.CSharp {
                        warning_regions_table = null;
                        reporting_disabled = false;
                        error_stack = warning_stack = null;
+                       warnings_as_error = null;
                }
 
                public static void DisableReporting ()
@@ -410,12 +411,24 @@ namespace Mono.CSharp {
                                return regions.IsWarningEnabled (code, location.Row);
                        }
 
+                       bool IsErrorWarning {
+                               get {
+                                       if (WarningsAreErrors)
+                                               return true;
+
+                                       if (warnings_as_error == null)
+                                               return false;
+
+                                       return warnings_as_error.Contains (code);
+                               }
+                       }
+
                        public override void Print ()
                        {
                                if (!IsEnabled ())
                                        return;
 
-                               if (WarningsAreErrors) {
+                               if (IsErrorWarning) {
                                        new ErrorMessage (this).Print ();
                                        return;
                                }
@@ -629,7 +642,7 @@ namespace Mono.CSharp {
                        Console.WriteLine (FriendlyStackTrace (new StackTrace (true)));
                }
 
-               public static bool IsValidWarning (int code)
+               static bool IsValidWarning (int code)
                {       
                        return Array.BinarySearch (AllWarnings, code) >= 0;
                }
@@ -717,6 +730,38 @@ namespace Mono.CSharp {
                        extra_information.Add (msg);
                }
 
+               public static void AddWarningAsError (string warningId)
+               {
+                       int id;
+                       try {
+                               id = int.Parse (warningId);
+                       } catch {
+                               id = -1;
+                       }
+
+                       if (!CheckWarningCode (id, warningId, Location.Null))
+                               return;
+
+                       if (warnings_as_error == null)
+                               warnings_as_error = new ArrayList ();
+                       
+                       warnings_as_error.Add (id);
+               }
+
+               public static bool CheckWarningCode (int code, Location loc)
+               {
+                       return CheckWarningCode (code, code.ToString (), loc);
+               }
+
+               public static bool CheckWarningCode (int code, string scode, Location loc)
+               {
+                       if (IsValidWarning (code))
+                               return true;
+
+                       Report.Warning (1691, 1, loc, "`{0}' is not a valid warning number", scode);
+                       return false;
+               }
+
                public static void ExtraInformation (Location loc, string msg)
                {
                        extra_information.Add (String.Format ("{0} {1}", loc, msg));
@@ -1101,7 +1146,7 @@ namespace Mono.CSharp {
 
                public void WarningDisable (Location location, int code)
                {
-                       if (CheckWarningCode (code, location))
+                       if (Report.CheckWarningCode (code, location))
                                regions.Add (new Disable (location.Row, code));
                }
 
@@ -1112,7 +1157,7 @@ namespace Mono.CSharp {
 
                public void WarningEnable (Location location, int code)
                {
-                       if (CheckWarningCode (code, location))
+                       if (Report.CheckWarningCode (code, location))
                                regions.Add (new Enable (location.Row, code));
                }
 
@@ -1127,14 +1172,5 @@ namespace Mono.CSharp {
                        }
                        return result;
                }
-
-               static bool CheckWarningCode (int code, Location loc)
-               {
-                       if (Report.IsValidWarning (code))
-                               return true;
-
-                       Report.Warning (1691, 1, loc, "`{0}' is not a valid warning number", code.ToString ());
-                       return false;
-               }
        }
 }