Merge pull request #1949 from lewurm/fixtype
[mono.git] / mcs / mcs / settings.cs
index 1556b5ca5fa9810e8b64554982fc1d4d21fd9677..13abbd67c67425faf5f9b3701068ea4c9a2aefc2 100644 (file)
@@ -28,9 +28,10 @@ namespace Mono.CSharp {
                V_3 = 3,
                V_4 = 4,
                V_5 = 5,
-               Future = 100,
+               V_6 = 6,
+               Experimental = 100,
 
-               Default = LanguageVersion.V_5,
+               Default = LanguageVersion.V_6,
        }
 
        public enum RuntimeVersion
@@ -146,8 +147,11 @@ namespace Mono.CSharp {
                public int VerboseParserFlag;
                public int FatalCounter;
                public bool Stacktrace;
+               public bool BreakOnInternalError;
                #endregion
 
+               public List<string> GetResourceStrings;
+
                public bool ShowFullPaths;
 
                //
@@ -159,6 +163,8 @@ namespace Mono.CSharp {
 
                public RuntimeVersion StdLibRuntimeVersion;
 
+               public string RuntimeMetadataVersion;
+
                public bool WriteMetadataOnly;
 
                readonly List<string> conditional_symbols;
@@ -301,8 +307,8 @@ namespace Mono.CSharp {
                        UnknownOption
                }
 
-               static readonly char[] argument_value_separator = new char[] { ';', ',' };
-               static readonly char[] numeric_value_separator = new char[] { ';', ',', ' ' };
+               static readonly char[] argument_value_separator = { ';', ',' };
+               static readonly char[] numeric_value_separator = { ';', ',', ' ' };
 
                readonly TextWriter output;
                readonly Report report;
@@ -350,6 +356,17 @@ namespace Mono.CSharp {
                public CompilerSettings ParseArguments (string[] args)
                {
                        CompilerSettings settings = new CompilerSettings ();
+                       if (!ParseArguments (settings, args))
+                               return null;
+
+                       return settings;
+               }
+
+               public bool ParseArguments (CompilerSettings settings, string[] args)
+               {
+                       if (settings == null)
+                               throw new ArgumentNullException ("settings");
+
                        List<string> response_file_list = null;
                        bool parsing_options = true;
                        stop_argument = false;
@@ -369,7 +386,7 @@ namespace Mono.CSharp {
 
                                        if (response_file_list.Contains (response_file)) {
                                                report.Error (1515, "Response file `{0}' specified multiple times", response_file);
-                                               return null;
+                                               return false;
                                        }
 
                                        response_file_list.Add (response_file);
@@ -377,7 +394,7 @@ namespace Mono.CSharp {
                                        extra_args = LoadArgs (response_file);
                                        if (extra_args == null) {
                                                report.Error (2011, "Unable to open response file: " + response_file);
-                                               return null;
+                                               return false;
                                        }
 
                                        args = AddArgs (args, extra_args);
@@ -399,7 +416,7 @@ namespace Mono.CSharp {
                                                        continue;
                                                case ParseResult.Stop:
                                                        stop_argument = true;
-                                                       return settings;
+                                                       return true;
                                                case ParseResult.UnknownOption:
                                                        if (UnknownOptionHandler != null) {
                                                                var ret = UnknownOptionHandler (args, i);
@@ -433,11 +450,11 @@ namespace Mono.CSharp {
                                                        }
 
                                                        Error_WrongOption (arg);
-                                                       return null;
+                                                       return false;
 
                                                case ParseResult.Stop:
                                                        stop_argument = true;
-                                                       return settings;
+                                                       return true;
                                                }
                                        }
                                }
@@ -445,10 +462,7 @@ namespace Mono.CSharp {
                                ProcessSourceFiles (arg, false, settings.SourceFiles);
                        }
 
-                       if (report.Errors > 0)
-                               return null;
-
-                       return settings;
+                       return report.Errors == 0;
                }
 
                void ProcessSourceFiles (string spec, bool recurse, List<SourceFile> sourceFiles)
@@ -461,7 +475,7 @@ namespace Mono.CSharp {
                                return;
                        }
 
-                       string[] files = null;
+                       string[] files;
                        try {
                                files = Directory.GetFiles (path, pattern);
                        } catch (System.IO.DirectoryNotFoundException) {
@@ -568,16 +582,22 @@ namespace Mono.CSharp {
                public bool ProcessWarningsList (string text, Action<int> action)
                {
                        bool valid = true;
-                       foreach (string wid in text.Split (numeric_value_separator)) {
+                       foreach (string wid in text.Split (numeric_value_separator, StringSplitOptions.RemoveEmptyEntries)) {
+                               var warning = wid;
+                               if (warning.Length == 6 && warning [0] == 'C' && warning [1] == 'S')
+                                       warning = warning.Substring (2);
+
                                int id;
-                               if (!int.TryParse (wid, NumberStyles.AllowLeadingWhite, CultureInfo.InvariantCulture, out id)) {
-                                       report.Error (1904, "`{0}' is not a valid warning number", wid);
-                                       valid = false;
+                               if (!int.TryParse (warning, NumberStyles.AllowLeadingWhite, CultureInfo.InvariantCulture, out id)) {
                                        continue;
                                }
 
-                               if (report.CheckWarningCode (id, Location.Null))
+                               if (report.CheckWarningCode (id, Location.Null)) {
                                        action (id);
+                               } else {
+                                       report.Error (1904, "`{0}' is not a valid warning number", wid);
+                                       valid = false;
+                               }
                        }
 
                        return valid;
@@ -600,24 +620,7 @@ namespace Mono.CSharp {
 
                static bool IsExternAliasValid (string identifier)
                {
-                       if (identifier.Length == 0)
-                               return false;
-                       if (identifier[0] != '_' && !char.IsLetter (identifier[0]))
-                               return false;
-
-                       for (int i = 1; i < identifier.Length; i++) {
-                               char c = identifier[i];
-                               if (char.IsLetter (c) || char.IsDigit (c))
-                                       continue;
-
-                               UnicodeCategory category = char.GetUnicodeCategory (c);
-                               if (category != UnicodeCategory.Format || category != UnicodeCategory.NonSpacingMark ||
-                                               category != UnicodeCategory.SpacingCombiningMark ||
-                                               category != UnicodeCategory.ConnectorPunctuation)
-                                       return false;
-                       }
-
-                       return true;
+                       return Tokenizer.IsValidIdentifier (identifier);
                }
 
                static string[] LoadArgs (string file)
@@ -678,7 +681,8 @@ namespace Mono.CSharp {
                                "   --stacktrace       Shows stack trace at error location\n" +
                                "   --timestamp        Displays time stamps of various compiler events\n" +
                                "   -v                 Verbose parsing (for debugging the parser)\n" +
-                               "   --mcs-debug X      Sets MCS debugging level to X\n");
+                               "   --mcs-debug X      Sets MCS debugging level to X\n" +
+                               "   --break-on-ice     Breaks compilation on internal compiler error");
                }
 
                //
@@ -984,7 +988,7 @@ namespace Mono.CSharp {
                                        settings.WarningsAreErrors = true;
                                        parser_settings.WarningsAreErrors = true;
                                } else {
-                                       if (!ProcessWarningsList (value, v => settings.AddWarningAsError (v)))
+                                       if (!ProcessWarningsList (value, settings.AddWarningAsError))
                                                return ParseResult.Error;
                                }
                                return ParseResult.Success;
@@ -993,7 +997,7 @@ namespace Mono.CSharp {
                                if (value.Length == 0) {
                                        settings.WarningsAreErrors = false;
                                } else {
-                                       if (!ProcessWarningsList (value, v => settings.AddWarningOnly (v)))
+                                       if (!ProcessWarningsList (value, settings.AddWarningOnly))
                                                return ParseResult.Error;
                                }
                                return ParseResult.Success;
@@ -1014,7 +1018,7 @@ namespace Mono.CSharp {
                                        return ParseResult.Error;
                                }
 
-                               if (!ProcessWarningsList (value, v => settings.SetIgnoreWarning (v)))
+                               if (!ProcessWarningsList (value, settings.SetIgnoreWarning))
                                        return ParseResult.Error;
 
                                return ParseResult.Success;
@@ -1141,11 +1145,13 @@ namespace Mono.CSharp {
 
                                switch (value.ToLowerInvariant ()) {
                                case "iso-1":
+                               case "1":
                                        settings.Version = LanguageVersion.ISO_1;
                                        return ParseResult.Success;
                                case "default":
                                        settings.Version = LanguageVersion.Default;
                                        return ParseResult.Success;
+                               case "2":
                                case "iso-2":
                                        settings.Version = LanguageVersion.ISO_2;
                                        return ParseResult.Success;
@@ -1158,12 +1164,18 @@ namespace Mono.CSharp {
                                case "5":
                                        settings.Version = LanguageVersion.V_5;
                                        return ParseResult.Success;
-                               case "future":
-                                       settings.Version = LanguageVersion.Future;
+                               case "6":
+                                       settings.Version = LanguageVersion.V_6;
+                                       return ParseResult.Success;
+                               case "experimental":
+                                       settings.Version = LanguageVersion.Experimental;
                                        return ParseResult.Success;
+                               case "future":
+                                       report.Warning (8000, 1, "Language version `future' is no longer supported");
+                                       goto case "6";
                                }
 
-                               report.Error (1617, "Invalid -langversion option `{0}'. It must be `ISO-1', `ISO-2', `3', `4', `5', `Default' or `Future'", value);
+                               report.Error (1617, "Invalid -langversion option `{0}'. It must be `ISO-1', `ISO-2', Default or value in range 1 to 6", value);
                                return ParseResult.Error;
 
                        case "/codepage":
@@ -1189,6 +1201,15 @@ namespace Mono.CSharp {
                                }
                                return ParseResult.Success;
 
+                       case "runtimemetadataversion":
+                               if (value.Length == 0) {
+                                       Error_RequiresArgument (option);
+                                       return ParseResult.Error;
+                               }
+
+                               settings.RuntimeMetadataVersion = value;
+                               return ParseResult.Success;
+
                        default:
                                return ParseResult.UnknownOption;
                        }
@@ -1430,8 +1451,12 @@ namespace Mono.CSharp {
                                settings.WriteMetadataOnly = true;
                                return ParseResult.Success;
 
+                       case "--break-on-ice":
+                               settings.BreakOnInternalError = true;
+                               return ParseResult.Success;
+
                        default:
-                               if (arg.StartsWith ("--fatal", StringComparison.Ordinal)){
+                               if (arg.StartsWith ("--fatal", StringComparison.Ordinal)) {
                                        int fatal = 1;
                                        if (arg.StartsWith ("--fatal=", StringComparison.Ordinal))
                                                int.TryParse (arg.Substring (8), out fatal);
@@ -1459,6 +1484,20 @@ namespace Mono.CSharp {
                                        return ParseResult.Success;
                                }
 
+                               if (arg.StartsWith ("--getresourcestrings:", StringComparison.Ordinal)) {
+                                       string file = arg.Substring (21).Trim ();
+                                       if (file.Length < 1) {
+                                               Error_RequiresArgument (arg);
+                                               return ParseResult.Error;
+                                       }
+
+                                       if (settings.GetResourceStrings == null)
+                                               settings.GetResourceStrings = new List<string> ();
+
+                                       settings.GetResourceStrings.Add (file);
+                                       return ParseResult.Success;
+                               }
+
                                return ParseResult.UnknownOption;
                        }
                }
@@ -1528,7 +1567,7 @@ namespace Mono.CSharp {
                                "   -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: ISO-1, ISO-2, 3, 4, 5, Default or Future\n" +
+                               "   -langversion:TEXT    Specifies language version: ISO-1, ISO-2, 3, 4, 5, Default or Experimental\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" +