Merge pull request #943 from ermshiperete/bug-novell-325669
[mono.git] / mcs / mcs / settings.cs
index 5c5a34b9ed39df581f3ed77368e3d23da6d43828..5e56f614f232f985a567d6ec9d7d3f2029cee2a1 100644 (file)
@@ -30,7 +30,7 @@ namespace Mono.CSharp {
                V_5 = 5,
                Future = 100,
 
-               Default = LanguageVersion.V_5,
+               Default = LanguageVersion.Future,
        }
 
        public enum RuntimeVersion
@@ -146,6 +146,7 @@ namespace Mono.CSharp {
                public int VerboseParserFlag;
                public int FatalCounter;
                public bool Stacktrace;
+               public bool BreakOnInternalError;
                #endregion
 
                public bool ShowFullPaths;
@@ -159,6 +160,10 @@ namespace Mono.CSharp {
 
                public RuntimeVersion StdLibRuntimeVersion;
 
+               public string RuntimeMetadataVersion;
+
+               public bool WriteMetadataOnly;
+
                readonly List<string> conditional_symbols;
 
                readonly List<SourceFile> source_files;
@@ -180,10 +185,8 @@ namespace Mono.CSharp {
                        StdLibRuntimeVersion = RuntimeVersion.v4;
                        WarningLevel = 4;
 
-                       if (Environment.OSVersion.Platform == PlatformID.Win32NT)
-                               TabSize = 4;
-                       else
-                               TabSize = 8;
+                       // Default to 1 or mdb files would be platform speficic
+                       TabSize = 1;
 
                        AssemblyReferences = new List<string> ();
                        AssemblyReferencesAliases = new List<Tuple<string, string>> ();
@@ -301,8 +304,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 +353,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 +383,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 +391,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 +413,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 +447,11 @@ namespace Mono.CSharp {
                                                        }
 
                                                        Error_WrongOption (arg);
-                                                       return null;
+                                                       return false;
 
                                                case ParseResult.Stop:
                                                        stop_argument = true;
-                                                       return settings;
+                                                       return true;
                                                }
                                        }
                                }
@@ -445,10 +459,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 +472,7 @@ namespace Mono.CSharp {
                                return;
                        }
 
-                       string[] files = null;
+                       string[] files;
                        try {
                                files = Directory.GetFiles (path, pattern);
                        } catch (System.IO.DirectoryNotFoundException) {
@@ -568,7 +579,7 @@ 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)) {
                                int id;
                                if (!int.TryParse (wid, NumberStyles.AllowLeadingWhite, CultureInfo.InvariantCulture, out id)) {
                                        report.Error (1904, "`{0}' is not a valid warning number", wid);
@@ -600,24 +611,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)
@@ -670,14 +664,16 @@ namespace Mono.CSharp {
                {
                        output.WriteLine (
                                "Other flags in the compiler\n" +
-                               "   --fatal[=COUNT]    Makes errors after COUNT fatal\n" +
+                               "   --fatal[=COUNT]    Makes error after COUNT fatal\n" +
                                "   --lint             Enhanced warnings\n" +
+                               "   --metadata-only    Produced assembly will contain metadata only\n" +
                                "   --parse            Only parses the source file\n" +
                                "   --runtime:VERSION  Sets mscorlib.dll metadata version: v1, v2, v4\n" +
                                "   --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");
                }
 
                //
@@ -933,7 +929,7 @@ namespace Mono.CSharp {
                                return ParseResult.Success;
 
                        case "/debug":
-                               if (value == "full" || value == "pdbonly" || idx < 0) {
+                               if (value.Equals ("full", StringComparison.OrdinalIgnoreCase) || value.Equals ("pdbonly", StringComparison.OrdinalIgnoreCase) || idx < 0) {
                                        settings.GenerateDebugInfo = true;
                                        return ParseResult.Success;
                                }
@@ -983,7 +979,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;
@@ -992,7 +988,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;
@@ -1013,7 +1009,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;
@@ -1188,6 +1184,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;
                        }
@@ -1425,6 +1430,14 @@ namespace Mono.CSharp {
                                settings.LoadDefaultReferences = false;
                                return ParseResult.Success;
 
+                       case "--metadata-only":
+                               settings.WriteMetadataOnly = true;
+                               return ParseResult.Success;
+
+                       case "--break-on-ice":
+                               settings.BreakOnInternalError = true;
+                               return ParseResult.Success;
+
                        default:
                                if (arg.StartsWith ("--fatal", StringComparison.Ordinal)){
                                        int fatal = 1;