extra_information.Add (msg);
}
- public bool CheckWarningCode (string code, Location loc)
- {
- Warning (1691, 1, loc, "`{0}' is not a valid warning number", code);
- return false;
- }
-
public bool CheckWarningCode (int code, Location loc)
{
if (AllWarningsHashSet == null)
if (AllWarningsHashSet.Contains (code))
return true;
- return CheckWarningCode (code.ToString (), loc);
+ Warning (1691, 1, loc, "`{0}' is not a valid warning number", code);
+ return false;
}
public void ExtraInformation (Location loc, string msg)
source_file_index.Add (path, unit.Index);
}
- void AddWarningAsError (string warningId, CompilerSettings settings)
+ public bool ProcessWarningsList (string text, Action<int> action)
{
- int id;
- try {
- id = int.Parse (warningId);
- } catch {
- report.CheckWarningCode (warningId, Location.Null);
- return;
- }
-
- if (!report.CheckWarningCode (id, Location.Null))
- return;
-
- settings.AddWarningAsError (id);
- }
+ bool valid = true;
+ foreach (string wid in text.Split (numeric_value_separator)) {
+ 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;
+ continue;
+ }
- 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))
+ action (id);
}
- if (!report.CheckWarningCode (id, Location.Null))
- return;
-
- settings.AddWarningOnly (id);
+ return valid;
}
void Error_RequiresArgument (string option)
settings.WarningsAreErrors = true;
parser_settings.WarningsAreErrors = true;
} else {
- foreach (string wid in value.Split (numeric_value_separator))
- AddWarningAsError (wid, settings);
+ if (!ProcessWarningsList (value, v => settings.AddWarningAsError (v)))
+ return ParseResult.Error;
}
return ParseResult.Success;
if (value.Length == 0) {
settings.WarningsAreErrors = false;
} else {
- foreach (string wid in value.Split (numeric_value_separator))
- RemoveWarningAsError (wid, settings);
+ if (!ProcessWarningsList (value, v => settings.AddWarningOnly (v)))
+ return ParseResult.Error;
}
return ParseResult.Success;
return ParseResult.Success;
case "/nowarn":
- if (value.Length == 0) {
- Error_RequiresArgument (option);
- return ParseResult.Error;
- }
+ if (value.Length == 0) {
+ Error_RequiresArgument (option);
+ return ParseResult.Error;
+ }
- var warns = value.Split (numeric_value_separator);
- foreach (string wc in warns) {
- try {
- if (wc.Trim ().Length == 0)
- continue;
+ if (!ProcessWarningsList (value, v => settings.SetIgnoreWarning (v)))
+ return ParseResult.Error;
- int warn = Int32.Parse (wc);
- if (warn < 1) {
- throw new ArgumentOutOfRangeException ("warn");
- }
- settings.SetIgnoreWarning (warn);
- } catch {
- report.Error (1904, "`{0}' is not a valid warning number", wc);
- return ParseResult.Error;
- }
- }
- return ParseResult.Success;
+ return ParseResult.Success;
case "/noconfig":
settings.LoadDefaultReferences = false;