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
};
// CS1691: `2' is not a valid warning number
// Line: 0
-// Compiler options: -warnaserror:1691,2
+// Compiler options: -warnaserror -warnaserror:1691,2
//
// 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) {
//
// Only report 649 on level 4
//
- if (Report.WarningLevel < 4)
+ if (Compiler.Settings.WarningLevel < 4)
continue;
//
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;
}
{
#if !FULL_AST
if (buffer.Length == 0)
- buffer = new LocatedToken [10000];
+ buffer = new LocatedToken [15000];
#endif
pos = 0;
}
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;
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 {
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);
}
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);
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;
{
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) {
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 ();
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;
}
#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;
//
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.
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 ()
"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)
{
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);
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 {
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;
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)
{
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));
}
public string StrongNameKeyContainer;
public bool StrongNameDelaySign;
+ public int TabSize;
+
+ public bool WarningsAreErrors;
+ public int WarningLevel;
+
//
// Assemblies references to be loaded
//
readonly List<CompilationSourceFile> source_files;
+ List<int> warnings_as_error;
+ List<int> warnings_only;
+ HashSet<int> warning_ignore_table;
+
public CompilerSettings ()
{
StdLib = true;
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>> ();
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
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;
}
ProcessSourceFiles (arg, false, settings.SourceFiles);
}
+ if (report.Errors > 0)
+ return null;
+
return settings;
}
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);
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;
return ParseResult.Error;
}
- SetWarningLevel (value);
+ SetWarningLevel (value, settings);
return ParseResult.Success;
case "/nowarn":
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;
Usage ();
Environment.Exit (1);
}
- report.SetIgnoreWarning (warn);
+ settings.SetIgnoreWarning (warn);
return ParseResult.Success;
case "--wlevel":
return ParseResult.Error;
}
- SetWarningLevel (args [++i]);
+ SetWarningLevel (args [++i], settings);
return ParseResult.Success;
case "--mcs-debug":
}
}
- void SetWarningLevel (string s)
+ void SetWarningLevel (string s, CompilerSettings settings)
{
int level = -1;
report.Error (1900, "Warning level must be in the range 0-4");
return;
}
- report.WarningLevel = level;
+ settings.WarningLevel = level;
}
//