Move all remaining compiler settings into Settings class
authorMarek Safar <marek.safar@gmail.com>
Fri, 27 Jan 2012 09:08:43 +0000 (09:08 +0000)
committerMarek Safar <marek.safar@gmail.com>
Fri, 27 Jan 2012 15:34:16 +0000 (15:34 +0000)
mcs/class/Microsoft.CSharp/Microsoft.CSharp.RuntimeBinder/DynamicContext.cs
mcs/errors/cs1691-2.cs
mcs/mcs/class.cs
mcs/mcs/context.cs
mcs/mcs/cs-tokenizer.cs
mcs/mcs/doc.cs
mcs/mcs/driver.cs
mcs/mcs/eval.cs
mcs/mcs/location.cs
mcs/mcs/report.cs
mcs/mcs/settings.cs

index a71f11455a23bcbb0bf6ba471057dbe07adaf562..f42783e4cd769f2d166e5eef0a8b1c3508dfdfd1 100644 (file)
@@ -70,13 +70,11 @@ namespace Microsoft.CSharp.RuntimeBinder
                                if (dc != null)
                                        return dc;
 
-                               var reporter = new Compiler.Report (ErrorPrinter.Instance) {
+                               var settings = new Compiler.CompilerSettings () {
                                        WarningLevel = 0
                                };
 
-                               var settings = new Compiler.CompilerSettings ();
-
-                               var cc = new Compiler.CompilerContext (settings, reporter) {
+                               var cc = new Compiler.CompilerContext (settings, ErrorPrinter.Instance) {
                                        IsRuntimeBinder = true
                                };
 
index 50bfc7aab4bb7cdc457223c58121c49c8cde3915..8c096991a716d4e0d6ce8a8de49c2736d630526f 100644 (file)
@@ -1,4 +1,4 @@
 // CS1691: `2' is not a valid warning number
 // Line: 0
-// Compiler options: -warnaserror:1691,2
+// Compiler options: -warnaserror -warnaserror:1691,2
 
index 782530079e922e90d0c76bf7960579f29a854f1e..e22119c77b938db614606d24c4b7f7bddd8887cb 100644 (file)
@@ -1794,7 +1794,7 @@ namespace Mono.CSharp
                        //
                        // Check for internal or private fields that were never assigned
                        //
-                       if (!IsCompilerGenerated && Report.WarningLevel >= 3) {
+                       if (!IsCompilerGenerated && Compiler.Settings.WarningLevel >= 3) {
                                bool is_type_exposed = Kind == MemberKind.Struct || IsExposedFromAssembly ();
                                foreach (var member in members) {
                                        if (member is Event) {
@@ -1835,7 +1835,7 @@ namespace Mono.CSharp
                                        //
                                        // Only report 649 on level 4
                                        //
-                                       if (Report.WarningLevel < 4)
+                                       if (Compiler.Settings.WarningLevel < 4)
                                                continue;
 
                                        //
index 24fedc69d5af002fc03062cfb84cae10857607f7..1ed59148b7dcb58e77ed064d471c841a73a1f87b 100644 (file)
@@ -586,10 +586,10 @@ namespace Mono.CSharp
 
                Dictionary<string, SourceFile> all_source_files;
 
-               public CompilerContext (CompilerSettings settings, Report report)
+               public CompilerContext (CompilerSettings settings, ReportPrinter reportPrinter)
                {
                        this.settings = settings;
-                       this.report = report;
+                       this.report = new Report (this, reportPrinter);
                        this.builtin_types = new BuiltinTypes ();
                        this.TimeReporter = DisabledTimeReporter;
                }
index 7077e9596c8678b0a83422683043f5913626744f..399be5316d87f4e97251dc70bc4abfd19470b399 100644 (file)
@@ -134,7 +134,7 @@ namespace Mono.CSharp
                        {
 #if !FULL_AST
                                if (buffer.Length == 0)
-                                       buffer = new LocatedToken [10000];
+                                       buffer = new LocatedToken [15000];
 #endif
                                pos = 0;
                        }
@@ -179,7 +179,7 @@ namespace Mono.CSharp
                int col = 0;
                int previous_col;
                int current_token;
-               int tab_size;
+               readonly int tab_size;
                bool handle_get_set = false;
                bool handle_remove_add = false;
                bool handle_where = false;
@@ -300,12 +300,7 @@ namespace Mono.CSharp
                        get { return handle_typeof; }
                        set { handle_typeof = value; }
                }
-
-               public int TabSize {
-                       get { return tab_size; }
-                       set { tab_size = value; }
-               }
-               
+       
                public XmlCommentState doc_state {
                        get { return xml_doc_state; }
                        set {
@@ -437,10 +432,7 @@ namespace Mono.CSharp
                        xml_comment_buffer = new StringBuilder ();
                        doc_processing = ctx.Settings.DocumentationFile != null;
 
-                       if (Environment.OSVersion.Platform == PlatformID.Win32NT)
-                               tab_size = 4;
-                       else
-                               tab_size = 8;
+                       tab_size = ctx.Settings.TabSize;
 
                        Mono.CSharp.Location.Push (file, file);
                }
@@ -2285,9 +2277,9 @@ namespace Mono.CSharp
                                                                code = TokenizePragmaNumber (ref c);
                                                                if (code > 0) {
                                                                        if (disable) {
-                                                                               Report.RegisterWarningRegion (loc).WarningDisable (loc, code, Report);
+                                                                               Report.RegisterWarningRegion (loc).WarningDisable (loc, code, context.Report);
                                                                        } else {
-                                                                               Report.RegisterWarningRegion (loc).WarningEnable (loc, code, Report);
+                                                                               Report.RegisterWarningRegion (loc).WarningEnable (loc, code, context);
                                                                        }
                                                                }
                                                        } while (code >= 0 && c != '\n' && c != -1);
index 40edc1c9294ca935abf40eb4d73351af6fb9308e..1526d953c6741027ca54beb0d2474e1fd13b3f51 100644 (file)
@@ -327,7 +327,8 @@ namespace Mono.CSharp
                        doc_module.DocumentationBuilder = this;
                        source_file.NamespaceContainer = new NamespaceContainer (null, doc_module, null, source_file);
 
-                       Report parse_report = new Report (new NullReportPrinter ());
+                       var rp = new NullReportPrinter ();
+                       Report parse_report = new Report (new CompilerContext (new CompilerSettings (), rp), rp);
                        var parser = new CSharpParser (seekable, source_file, parse_report);
                        ParsedParameters = null;
                        ParsedName = null;
index faea36fe5bf8c0ecac034c6fb0372457e7c20be7..2890753292c7f2ebbe6fa9e3fea3516297be4fc5 100644 (file)
@@ -124,16 +124,15 @@ namespace Mono.CSharp
                {
                        Location.InEmacs = Environment.GetEnvironmentVariable ("EMACS") == "t";
 
-                       var r = new Report (new ConsoleReportPrinter ());
-                       CommandLineParser cmd = new CommandLineParser (r);
+                       CommandLineParser cmd = new CommandLineParser (Console.Out);
                        var settings = cmd.ParseArguments (args);
-                       if (settings == null || r.Errors > 0)
+                       if (settings == null)
                                return 1;
 
                        if (cmd.HasBeenStopped)
                                return 0;
 
-                       Driver d = new Driver (new CompilerContext (settings, r));
+                       Driver d = new Driver (new CompilerContext (settings, new ConsoleReportPrinter ()));
 
                        if (d.Compile () && d.Report.Errors == 0) {
                                if (d.Report.Warnings > 0) {
@@ -357,13 +356,12 @@ namespace Mono.CSharp
                public static bool InvokeCompiler (string [] args, TextWriter error)
                {
                        try {
-                               var r = new Report (new StreamReportPrinter (error));
-                               CommandLineParser cmd = new CommandLineParser (r, error);
+                               CommandLineParser cmd = new CommandLineParser (error);
                                var setting = cmd.ParseArguments (args);
-                               if (setting == null || r.Errors > 0)
+                               if (setting == null)
                                        return false;
 
-                               var d = new Driver (new CompilerContext (setting, r));
+                               var d = new Driver (new CompilerContext (setting, new StreamReportPrinter (error)));
                                return d.Compile ();
                        } finally {
                                Reset ();
index 7056c26104acc70c2d4377435d01382585e0dc26..d4fcfe493612bc62a1ac864e532c3d6843662670 100644 (file)
@@ -72,9 +72,9 @@ namespace Mono.CSharp
                readonly ReflectionImporter importer;
                readonly CompilationSourceFile source_file;
                
-               public Evaluator (CompilerSettings settings, Report report)
+               public Evaluator (CompilerSettings settings, ReportPrinter reportPrinter)
                {
-                       ctx = new CompilerContext (settings, report);
+                       ctx = new CompilerContext (settings, reportPrinter);
 
                        module = new ModuleContainer (ctx);
                        module.Evaluator = this;
index 4b0bd637213483ef379243d5391c95f90cee8bfc..6370aed4500604a3b374116480724805c0a4b185 100644 (file)
@@ -198,12 +198,12 @@ namespace Mono.CSharp {
                }
 
 #if FULL_AST
-               long token;
+               readonly long token;
 
                const int column_bits = 24;
                const int line_delta_bits = 24;
 #else
-               int token;
+               readonly int token;
 
                const int column_bits = 8;
                const int line_delta_bits = 8;
index fc6a69f5115760dae9f346c7ec3fa0c280523e58..64fc1bf01d277c348618484a3cea909904c55d1f 100644 (file)
@@ -21,27 +21,15 @@ namespace Mono.CSharp {
        //
        public class Report
        {
-               /// <summary>  
-               ///   Whether warnings should be considered errors
-               /// </summary>
-               public bool WarningsAreErrors;
-               List<int> warnings_as_error;
-               List<int> warnings_only;
-
                public const int RuntimeErrorId = 10000;
 
-               //
-               // Keeps track of the warnings that we are ignoring
-               //
-               HashSet<int> warning_ignore_table;
-
                Dictionary<int, WarningRegions> warning_regions_table;
 
-               int warning_level;
-
                ReportPrinter printer;
 
                int reporting_disabled;
+
+               readonly CompilerSettings settings;
                
                /// <summary>
                /// List of symbols related to reported error/warning. You have to fill it before error/warning is reported.
@@ -72,13 +60,15 @@ namespace Mono.CSharp {
 
                static HashSet<int> AllWarningsHashSet;
 
-               public Report (ReportPrinter printer)
+               public Report (CompilerContext context, ReportPrinter printer)
                {
+                       if (context == null)
+                               throw new ArgumentNullException ("settings");
                        if (printer == null)
                                throw new ArgumentNullException ("printer");
 
+                       this.settings = context.Settings;
                        this.printer = printer;
-                       warning_level = 4;
                }
 
                public void DisableReporting ()
@@ -125,44 +115,6 @@ namespace Mono.CSharp {
                                "Feature `{0}' is not supported in Mono mcs1 compiler. Consider using the `gmcs' compiler instead",
                                feature);
                }
-               
-               bool IsWarningEnabled (int code, int level, Location loc)
-               {
-                       if (WarningLevel < level)
-                               return false;
-
-                       if (IsWarningDisabledGlobally (code))
-                               return false;
-
-                       if (warning_regions_table == null || loc.IsNull)
-                               return true;
-
-                       WarningRegions regions;
-                       if (!warning_regions_table.TryGetValue (loc.File, out regions))
-                               return true;
-
-                       return regions.IsWarningEnabled (code, loc.Row);
-               }
-
-               public bool IsWarningDisabledGlobally (int code)
-               {
-                       return warning_ignore_table != null && warning_ignore_table.Contains (code);
-               }
-
-               bool IsWarningAsError (int code)
-               {
-                       bool is_error = WarningsAreErrors;
-
-                       // Check specific list
-                       if (warnings_as_error != null)
-                               is_error |= warnings_as_error.Contains (code);
-
-                       // Ignore excluded warnings
-                       if (warnings_only != null && warnings_only.Contains (code))
-                               is_error = false;
-
-                       return is_error;
-               }
                        
                public void RuntimeMissingSupport (Location loc, string feature) 
                {
@@ -217,44 +169,6 @@ namespace Mono.CSharp {
                        extra_information.Add (msg);
                }
 
-               public void AddWarningAsError (string warningId)
-               {
-                       int id;
-                       try {
-                               id = int.Parse (warningId);
-                       } catch {
-                               CheckWarningCode (warningId, Location.Null);
-                               return;
-                       }
-
-                       if (!CheckWarningCode (id, Location.Null))
-                               return;
-
-                       if (warnings_as_error == null)
-                               warnings_as_error = new List<int> ();
-                       
-                       warnings_as_error.Add (id);
-               }
-
-               public void RemoveWarningAsError (string warningId)
-               {
-                       int id;
-                       try {
-                               id = int.Parse (warningId);
-                       } catch {
-                               CheckWarningCode (warningId, Location.Null);
-                               return;
-                       }
-
-                       if (!CheckWarningCode (id, Location.Null))
-                               return;
-
-                       if (warnings_only == null)
-                               warnings_only = new List<int> ();
-
-                       warnings_only.Add (id);
-               }
-
                public bool CheckWarningCode (string code, Location loc)
                {
                        Warning (1691, 1, loc, "`{0}' is not a valid warning number", code);
@@ -300,11 +214,17 @@ namespace Mono.CSharp {
                        if (reporting_disabled > 0)
                                return;
 
-                       if (!IsWarningEnabled (code, level, loc))
+                       if (!settings.IsWarningEnabled (code, level))
                                return;
 
+                       if (warning_regions_table != null && !loc.IsNull) {
+                               WarningRegions regions;
+                               if (warning_regions_table.TryGetValue (loc.File, out regions) && !regions.IsWarningEnabled (code, loc.Row))
+                                       return;
+                       }
+
                        AbstractMessage msg;
-                       if (IsWarningAsError (code)) {
+                       if (settings.IsWarningAsError (code)) {
                                message = "Warning as Error: " + message;
                                msg = new ErrorMessage (code, loc, message, extra_information);
                        } else {
@@ -420,14 +340,6 @@ namespace Mono.CSharp {
                        get { return printer; }
                }
 
-               public void SetIgnoreWarning (int code)
-               {
-                       if (warning_ignore_table == null)
-                               warning_ignore_table = new HashSet<int> ();
-
-                       warning_ignore_table.Add (code);
-               }
-
                public ReportPrinter SetPrinter (ReportPrinter printer)
                {
                        ReportPrinter old = this.printer;
@@ -435,15 +347,6 @@ namespace Mono.CSharp {
                        return old;
                }
 
-               public int WarningLevel {
-                       get {
-                               return warning_level;
-                       }
-                       set {
-                               warning_level = value;
-                       }
-               }
-
                [Conditional ("MCS_DEBUG")]
                static public void Debug (string message, params object[] args)
                {
@@ -1200,13 +1103,13 @@ namespace Mono.CSharp {
                        regions.Add (new EnableAll (line));
                }
 
-               public void WarningEnable (Location location, int code, Report Report)
+               public void WarningEnable (Location location, int code, CompilerContext context)
                {
-                       if (!Report.CheckWarningCode (code, location))
+                       if (!context.Report.CheckWarningCode (code, location))
                                return;
 
-                       if (Report.IsWarningDisabledGlobally (code))
-                               Report.Warning (1635, 1, location, "Cannot restore warning `CS{0:0000}' because it was disabled globally", code);
+                       if (context.Settings.IsWarningDisabledGlobally (code))
+                               context.Report.Warning (1635, 1, location, "Cannot restore warning `CS{0:0000}' because it was disabled globally", code);
 
                        regions.Add (new Enable (location.Row, code));
                }
index b49d2a3e4771da8821f8b1dab37875f2575c1da2..9b8e0795941a1eff0c3226dda354430a1460ca3d 100644 (file)
@@ -66,6 +66,11 @@ namespace Mono.CSharp {
                public string StrongNameKeyContainer;
                public bool StrongNameDelaySign;
 
+               public int TabSize;
+
+               public bool WarningsAreErrors;
+               public int WarningLevel;
+
                //
                // Assemblies references to be loaded
                //
@@ -148,6 +153,10 @@ namespace Mono.CSharp {
 
                readonly List<CompilationSourceFile> source_files;
 
+               List<int> warnings_as_error;
+               List<int> warnings_only;
+               HashSet<int> warning_ignore_table;
+
                public CompilerSettings ()
                {
                        StdLib = true;
@@ -160,6 +169,12 @@ namespace Mono.CSharp {
                        Encoding = Encoding.UTF8;
                        LoadDefaultReferences = true;
                        StdLibRuntimeVersion = RuntimeVersion.v4;
+                       WarningLevel = 4;
+
+                       if (Environment.OSVersion.Platform == PlatformID.Win32NT)
+                               TabSize = 4;
+                       else
+                               TabSize = 8;
 
                        AssemblyReferences = new List<string> ();
                        AssemblyReferencesAliases = new List<Tuple<string, string>> ();
@@ -209,10 +224,62 @@ namespace Mono.CSharp {
                                conditional_symbols.Add (symbol);
                }
 
+               public void AddWarningAsError (int id)
+               {
+                       if (warnings_as_error == null)
+                               warnings_as_error = new List<int> ();
+
+                       warnings_as_error.Add (id);
+               }
+
+               public void AddWarningOnly (int id)
+               {
+                       if (warnings_only == null)
+                               warnings_only = new List<int> ();
+
+                       warnings_only.Add (id);
+               }
+
                public bool IsConditionalSymbolDefined (string symbol)
                {
                        return conditional_symbols.Contains (symbol);
                }
+
+               public bool IsWarningAsError (int code)
+               {
+                       bool is_error = WarningsAreErrors;
+
+                       // Check specific list
+                       if (warnings_as_error != null)
+                               is_error |= warnings_as_error.Contains (code);
+
+                       // Ignore excluded warnings
+                       if (warnings_only != null && warnings_only.Contains (code))
+                               is_error = false;
+
+                       return is_error;
+               }
+
+               public bool IsWarningEnabled (int code, int level)
+               {
+                       if (WarningLevel < level)
+                               return false;
+
+                       return !IsWarningDisabledGlobally (code);
+               }
+
+               public bool IsWarningDisabledGlobally (int code)
+               {
+                       return warning_ignore_table != null && warning_ignore_table.Contains (code);
+               }
+
+               public void SetIgnoreWarning (int code)
+               {
+                       if (warning_ignore_table == null)
+                               warning_ignore_table = new HashSet<int> ();
+
+                       warning_ignore_table.Add (code);
+               }
        }
 
        public class CommandLineParser
@@ -228,22 +295,27 @@ namespace Mono.CSharp {
                static readonly char[] argument_value_separator = new char[] { ';', ',' };
                static readonly char[] numeric_value_separator = new char[] { ';', ',', ' ' };
 
-               readonly Report report;
                readonly TextWriter output;
+               readonly Report report;
                bool stop_argument;
 
                Dictionary<string, int> source_file_index;
 
                public event Func<string[], int, int> UnknownOptionHandler;
 
-               public CommandLineParser (Report report)
-                       : this (report, Console.Out)
+               CompilerSettings parser_settings;
+
+               public CommandLineParser (TextWriter errorOutput)
+                       : this (errorOutput, Console.Out)
                {
                }
 
-               public CommandLineParser (Report report, TextWriter messagesOutput)
+               public CommandLineParser (TextWriter errorOutput, TextWriter messagesOutput)
                {
-                       this.report = report;
+                       var rp = new StreamReportPrinter (errorOutput);
+
+                       parser_settings = new CompilerSettings ();
+                       report = new Report (new CompilerContext (parser_settings, rp), rp);
                        this.output = messagesOutput;
                }
 
@@ -364,6 +436,9 @@ namespace Mono.CSharp {
                                ProcessSourceFiles (arg, false, settings.SourceFiles);
                        }
 
+                       if (report.Errors > 0)
+                               return null;
+
                        return settings;
                }
 
@@ -481,6 +556,38 @@ namespace Mono.CSharp {
                        source_file_index.Add (path, unit.Index);
                }
 
+               void AddWarningAsError (string warningId, CompilerSettings settings)
+               {
+                       int id;
+                       try {
+                               id = int.Parse (warningId);
+                       } catch {
+                               report.CheckWarningCode (warningId, Location.Null);
+                               return;
+                       }
+
+                       if (!report.CheckWarningCode (id, Location.Null))
+                               return;
+
+                       settings.AddWarningAsError (id);
+               }
+
+               void RemoveWarningAsError (string warningId, CompilerSettings settings)
+               {
+                       int id;
+                       try {
+                               id = int.Parse (warningId);
+                       } catch {
+                               report.CheckWarningCode (warningId, Location.Null);
+                               return;
+                       }
+
+                       if (!report.CheckWarningCode (id, Location.Null))
+                               return;
+
+                       settings.AddWarningOnly (id);
+               }
+
                void Error_RequiresArgument (string option)
                {
                        report.Error (2006, "Missing argument for `{0}' option", option);
@@ -870,19 +977,20 @@ namespace Mono.CSharp {
                        case "/warnaserror":
                        case "/warnaserror+":
                                if (value.Length == 0) {
-                                       report.WarningsAreErrors = true;
+                                       settings.WarningsAreErrors = true;
+                                       parser_settings.WarningsAreErrors = true;
                                } else {
                                        foreach (string wid in value.Split (numeric_value_separator))
-                                               report.AddWarningAsError (wid);
+                                               AddWarningAsError (wid, settings);
                                }
                                return ParseResult.Success;
 
                        case "/warnaserror-":
                                if (value.Length == 0) {
-                                       report.WarningsAreErrors = false;
+                                       settings.WarningsAreErrors = false;
                                } else {
                                        foreach (string wid in value.Split (numeric_value_separator))
-                                               report.RemoveWarningAsError (wid);
+                                               RemoveWarningAsError (wid, settings);
                                }
                                return ParseResult.Success;
 
@@ -892,7 +1000,7 @@ namespace Mono.CSharp {
                                        return ParseResult.Error;
                                }
 
-                               SetWarningLevel (value);
+                               SetWarningLevel (value, settings);
                                return ParseResult.Success;
 
                        case "/nowarn":
@@ -911,7 +1019,7 @@ namespace Mono.CSharp {
                                                        if (warn < 1) {
                                                                throw new ArgumentOutOfRangeException ("warn");
                                                        }
-                                                       report.SetIgnoreWarning (warn);
+                                                       settings.SetIgnoreWarning (warn);
                                                } catch {
                                                        report.Error (1904, "`{0}' is not a valid warning number", wc);
                                                        return ParseResult.Error;
@@ -1264,7 +1372,7 @@ namespace Mono.CSharp {
                                        Usage ();
                                        Environment.Exit (1);
                                }
-                               report.SetIgnoreWarning (warn);
+                               settings.SetIgnoreWarning (warn);
                                return ParseResult.Success;
 
                        case "--wlevel":
@@ -1274,7 +1382,7 @@ namespace Mono.CSharp {
                                        return ParseResult.Error;
                                }
 
-                               SetWarningLevel (args [++i]);
+                               SetWarningLevel (args [++i], settings);
                                return ParseResult.Success;
 
                        case "--mcs-debug":
@@ -1352,7 +1460,7 @@ namespace Mono.CSharp {
                        }
                }
 
-               void SetWarningLevel (string s)
+               void SetWarningLevel (string s, CompilerSettings settings)
                {
                        int level = -1;
 
@@ -1364,7 +1472,7 @@ namespace Mono.CSharp {
                                report.Error (1900, "Warning level must be in the range 0-4");
                                return;
                        }
-                       report.WarningLevel = level;
+                       settings.WarningLevel = level;
                }
 
                //