Check warning number for nowarn option as well
[mono.git] / mcs / mcs / settings.cs
1 //
2 // settings.cs: All compiler settings
3 //
4 // Author: Miguel de Icaza (miguel@ximian.com)
5 //            Ravi Pratap  (ravi@ximian.com)
6 //            Marek Safar  (marek.safar@gmail.com)
7 //
8 //
9 // Dual licensed under the terms of the MIT X11 or GNU GPL
10 //
11 // Copyright 2001 Ximian, Inc (http://www.ximian.com)
12 // Copyright 2004-2008 Novell, Inc
13 // Copyright 2011 Xamarin, Inc (http://www.xamarin.com)
14 //
15
16 using System.Collections.Generic;
17 using System.IO;
18 using System.Text;
19 using System.Globalization;
20 using System;
21
22 namespace Mono.CSharp {
23
24         public enum LanguageVersion
25         {
26                 ISO_1 = 1,
27                 ISO_2 = 2,
28                 V_3 = 3,
29                 V_4 = 4,
30                 V_5 = 5,
31                 Future = 100,
32
33                 Default = LanguageVersion.V_5,
34         }
35
36         public enum RuntimeVersion
37         {
38                 v1,
39                 v2,
40                 v4
41         }
42
43         public enum Target
44         {
45                 Library, Exe, Module, WinExe
46         }
47
48         public enum Platform
49         {
50                 AnyCPU,
51                 AnyCPU32Preferred,
52                 Arm,
53                 X86,
54                 X64,
55                 IA64
56         }
57
58         public class CompilerSettings
59         {
60                 public Target Target;
61                 public Platform Platform;
62                 public string TargetExt;
63                 public bool VerifyClsCompliance;
64                 public bool Optimize;
65                 public LanguageVersion Version;
66                 public bool EnhancedWarnings;
67                 public bool LoadDefaultReferences;
68                 public string SdkVersion;
69
70                 public string StrongNameKeyFile;
71                 public string StrongNameKeyContainer;
72                 public bool StrongNameDelaySign;
73
74                 public int TabSize;
75
76                 public bool WarningsAreErrors;
77                 public int WarningLevel;
78
79                 //
80                 // Assemblies references to be loaded
81                 //
82                 public List<string> AssemblyReferences;
83
84                 // 
85                 // External aliases for assemblies
86                 //
87                 public List<Tuple<string, string>> AssemblyReferencesAliases;
88
89                 //
90                 // Modules to be embedded
91                 //
92                 public List<string> Modules;
93
94                 //
95                 // Lookup paths for referenced assemblies
96                 //
97                 public List<string> ReferencesLookupPaths;
98
99                 //
100                 // Encoding.
101                 //
102                 public Encoding Encoding;
103
104                 //
105                 // If set, enable XML documentation generation
106                 //
107                 public string DocumentationFile;
108
109                 public string MainClass;
110
111                 //
112                 // Output file
113                 //
114                 public string OutputFile;
115
116                 // 
117                 // The default compiler checked state
118                 //
119                 public bool Checked;
120
121                 //
122                 // If true, the compiler is operating in statement mode,
123                 // this currently turns local variable declaration into
124                 // static variables of a class
125                 //
126                 public bool StatementMode;      // TODO: SUPER UGLY
127                 
128                 //
129                 // Whether to allow Unsafe code
130                 //
131                 public bool Unsafe;
132
133                 public string Win32ResourceFile;
134                 public string Win32IconFile;
135
136                 //
137                 // A list of resource files for embedding
138                 //
139                 public List<AssemblyResource> Resources;
140
141                 public bool GenerateDebugInfo;
142
143                 #region Compiler debug flags only
144                 public bool ParseOnly, TokenizeOnly, Timestamps;
145                 public int DebugFlags;
146                 public int VerboseParserFlag;
147                 public int FatalCounter;
148                 public bool Stacktrace;
149                 #endregion
150
151                 public bool ShowFullPaths;
152
153                 //
154                 // Whether we are being linked against the standard libraries.
155                 // This is only used to tell whether `System.Object' should
156                 // have a base class or not.
157                 //
158                 public bool StdLib;
159
160                 public RuntimeVersion StdLibRuntimeVersion;
161
162                 readonly List<string> conditional_symbols;
163
164                 readonly List<SourceFile> source_files;
165
166                 List<int> warnings_as_error;
167                 List<int> warnings_only;
168                 HashSet<int> warning_ignore_table;
169
170                 public CompilerSettings ()
171                 {
172                         StdLib = true;
173                         Target = Target.Exe;
174                         TargetExt = ".exe";
175                         Platform = Platform.AnyCPU;
176                         Version = LanguageVersion.Default;
177                         VerifyClsCompliance = true;
178                         Encoding = Encoding.UTF8;
179                         LoadDefaultReferences = true;
180                         StdLibRuntimeVersion = RuntimeVersion.v4;
181                         WarningLevel = 4;
182
183                         if (Environment.OSVersion.Platform == PlatformID.Win32NT)
184                                 TabSize = 4;
185                         else
186                                 TabSize = 8;
187
188                         AssemblyReferences = new List<string> ();
189                         AssemblyReferencesAliases = new List<Tuple<string, string>> ();
190                         Modules = new List<string> ();
191                         ReferencesLookupPaths = new List<string> ();
192
193                         conditional_symbols = new List<string> ();
194                         //
195                         // Add default mcs define
196                         //
197                         conditional_symbols.Add ("__MonoCS__");
198
199                         source_files = new List<SourceFile> ();
200                 }
201
202                 #region Properties
203
204                 public SourceFile FirstSourceFile {
205                         get {
206                                 return source_files.Count > 0 ? source_files [0] : null;
207                         }
208                 }
209
210                 public bool HasKeyFileOrContainer {
211                         get {
212                                 return StrongNameKeyFile != null || StrongNameKeyContainer != null;
213                         }
214                 }
215
216                 public bool NeedsEntryPoint {
217                         get {
218                                 return Target == Target.Exe || Target == Target.WinExe;
219                         }
220                 }
221
222                 public List<SourceFile> SourceFiles {
223                         get {
224                                 return source_files;
225                         }
226                 }
227
228                 #endregion
229
230                 public void AddConditionalSymbol (string symbol)
231                 {
232                         if (!conditional_symbols.Contains (symbol))
233                                 conditional_symbols.Add (symbol);
234                 }
235
236                 public void AddWarningAsError (int id)
237                 {
238                         if (warnings_as_error == null)
239                                 warnings_as_error = new List<int> ();
240
241                         warnings_as_error.Add (id);
242                 }
243
244                 public void AddWarningOnly (int id)
245                 {
246                         if (warnings_only == null)
247                                 warnings_only = new List<int> ();
248
249                         warnings_only.Add (id);
250                 }
251
252                 public bool IsConditionalSymbolDefined (string symbol)
253                 {
254                         return conditional_symbols.Contains (symbol);
255                 }
256
257                 public bool IsWarningAsError (int code)
258                 {
259                         bool is_error = WarningsAreErrors;
260
261                         // Check specific list
262                         if (warnings_as_error != null)
263                                 is_error |= warnings_as_error.Contains (code);
264
265                         // Ignore excluded warnings
266                         if (warnings_only != null && warnings_only.Contains (code))
267                                 is_error = false;
268
269                         return is_error;
270                 }
271
272                 public bool IsWarningEnabled (int code, int level)
273                 {
274                         if (WarningLevel < level)
275                                 return false;
276
277                         return !IsWarningDisabledGlobally (code);
278                 }
279
280                 public bool IsWarningDisabledGlobally (int code)
281                 {
282                         return warning_ignore_table != null && warning_ignore_table.Contains (code);
283                 }
284
285                 public void SetIgnoreWarning (int code)
286                 {
287                         if (warning_ignore_table == null)
288                                 warning_ignore_table = new HashSet<int> ();
289
290                         warning_ignore_table.Add (code);
291                 }
292         }
293
294         public class CommandLineParser
295         {
296                 enum ParseResult
297                 {
298                         Success,
299                         Error,
300                         Stop,
301                         UnknownOption
302                 }
303
304                 static readonly char[] argument_value_separator = new char[] { ';', ',' };
305                 static readonly char[] numeric_value_separator = new char[] { ';', ',', ' ' };
306
307                 readonly TextWriter output;
308                 readonly Report report;
309                 bool stop_argument;
310
311                 Dictionary<string, int> source_file_index;
312
313                 public event Func<string[], int, int> UnknownOptionHandler;
314
315                 CompilerSettings parser_settings;
316
317                 public CommandLineParser (TextWriter errorOutput)
318                         : this (errorOutput, Console.Out)
319                 {
320                 }
321
322                 public CommandLineParser (TextWriter errorOutput, TextWriter messagesOutput)
323                 {
324                         var rp = new StreamReportPrinter (errorOutput);
325
326                         parser_settings = new CompilerSettings ();
327                         report = new Report (new CompilerContext (parser_settings, rp), rp);
328                         this.output = messagesOutput;
329                 }
330
331                 public bool HasBeenStopped {
332                         get {
333                                 return stop_argument;
334                         }
335                 }
336
337                 void About ()
338                 {
339                         output.WriteLine (
340                                 "The Mono C# compiler is Copyright 2001-2011, Novell, Inc.\n\n" +
341                                 "The compiler source code is released under the terms of the \n" +
342                                 "MIT X11 or GNU GPL licenses\n\n" +
343
344                                 "For more information on Mono, visit the project Web site\n" +
345                                 "   http://www.mono-project.com\n\n" +
346
347                                 "The compiler was written by Miguel de Icaza, Ravi Pratap, Martin Baulig, Marek Safar, Raja R Harinath, Atushi Enomoto");
348                 }
349
350                 public CompilerSettings ParseArguments (string[] args)
351                 {
352                         CompilerSettings settings = new CompilerSettings ();
353                         List<string> response_file_list = null;
354                         bool parsing_options = true;
355                         stop_argument = false;
356                         source_file_index = new Dictionary<string, int> ();
357
358                         for (int i = 0; i < args.Length; i++) {
359                                 string arg = args[i];
360                                 if (arg.Length == 0)
361                                         continue;
362
363                                 if (arg[0] == '@') {
364                                         string[] extra_args;
365                                         string response_file = arg.Substring (1);
366
367                                         if (response_file_list == null)
368                                                 response_file_list = new List<string> ();
369
370                                         if (response_file_list.Contains (response_file)) {
371                                                 report.Error (1515, "Response file `{0}' specified multiple times", response_file);
372                                                 return null;
373                                         }
374
375                                         response_file_list.Add (response_file);
376
377                                         extra_args = LoadArgs (response_file);
378                                         if (extra_args == null) {
379                                                 report.Error (2011, "Unable to open response file: " + response_file);
380                                                 return null;
381                                         }
382
383                                         args = AddArgs (args, extra_args);
384                                         continue;
385                                 }
386
387                                 if (parsing_options) {
388                                         if (arg == "--") {
389                                                 parsing_options = false;
390                                                 continue;
391                                         }
392
393                                         bool dash_opt = arg[0] == '-';
394                                         bool slash_opt = arg[0] == '/';
395                                         if (dash_opt) {
396                                                 switch (ParseOptionUnix (arg, ref args, ref i, settings)) {
397                                                 case ParseResult.Error:
398                                                 case ParseResult.Success:
399                                                         continue;
400                                                 case ParseResult.Stop:
401                                                         stop_argument = true;
402                                                         return settings;
403                                                 case ParseResult.UnknownOption:
404                                                         if (UnknownOptionHandler != null) {
405                                                                 var ret = UnknownOptionHandler (args, i);
406                                                                 if (ret != -1) {
407                                                                         i = ret;
408                                                                         continue;
409                                                                 }
410                                                         }
411                                                         break;
412                                                 }
413                                         }
414
415                                         if (dash_opt || slash_opt) {
416                                                 // Try a -CSCOPTION
417                                                 string csc_opt = dash_opt ? "/" + arg.Substring (1) : arg;
418                                                 switch (ParseOption (csc_opt, ref args, settings)) {
419                                                 case ParseResult.Error:
420                                                 case ParseResult.Success:
421                                                         continue;
422                                                 case ParseResult.UnknownOption:
423                                                         // Need to skip `/home/test.cs' however /test.cs is considered as error
424                                                         if ((slash_opt && arg.Length > 3 && arg.IndexOf ('/', 2) > 0))
425                                                                 break;
426
427                                                         if (UnknownOptionHandler != null) {
428                                                                 var ret = UnknownOptionHandler (args, i);
429                                                                 if (ret != -1) {
430                                                                         i = ret;
431                                                                         continue;
432                                                                 }
433                                                         }
434
435                                                         Error_WrongOption (arg);
436                                                         return null;
437
438                                                 case ParseResult.Stop:
439                                                         stop_argument = true;
440                                                         return settings;
441                                                 }
442                                         }
443                                 }
444
445                                 ProcessSourceFiles (arg, false, settings.SourceFiles);
446                         }
447
448                         if (report.Errors > 0)
449                                 return null;
450
451                         return settings;
452                 }
453
454                 void ProcessSourceFiles (string spec, bool recurse, List<SourceFile> sourceFiles)
455                 {
456                         string path, pattern;
457
458                         SplitPathAndPattern (spec, out path, out pattern);
459                         if (pattern.IndexOf ('*') == -1) {
460                                 AddSourceFile (spec, sourceFiles);
461                                 return;
462                         }
463
464                         string[] files = null;
465                         try {
466                                 files = Directory.GetFiles (path, pattern);
467                         } catch (System.IO.DirectoryNotFoundException) {
468                                 report.Error (2001, "Source file `" + spec + "' could not be found");
469                                 return;
470                         } catch (System.IO.IOException) {
471                                 report.Error (2001, "Source file `" + spec + "' could not be found");
472                                 return;
473                         }
474                         foreach (string f in files) {
475                                 AddSourceFile (f, sourceFiles);
476                         }
477
478                         if (!recurse)
479                                 return;
480
481                         string[] dirs = null;
482
483                         try {
484                                 dirs = Directory.GetDirectories (path);
485                         } catch {
486                         }
487
488                         foreach (string d in dirs) {
489
490                                 // Don't include path in this string, as each
491                                 // directory entry already does
492                                 ProcessSourceFiles (d + "/" + pattern, true, sourceFiles);
493                         }
494                 }
495
496                 static string[] AddArgs (string[] args, string[] extra_args)
497                 {
498                         string[] new_args;
499                         new_args = new string[extra_args.Length + args.Length];
500
501                         // if args contains '--' we have to take that into account
502                         // split args into first half and second half based on '--'
503                         // and add the extra_args before --
504                         int split_position = Array.IndexOf (args, "--");
505                         if (split_position != -1) {
506                                 Array.Copy (args, new_args, split_position);
507                                 extra_args.CopyTo (new_args, split_position);
508                                 Array.Copy (args, split_position, new_args, split_position + extra_args.Length, args.Length - split_position);
509                         } else {
510                                 args.CopyTo (new_args, 0);
511                                 extra_args.CopyTo (new_args, args.Length);
512                         }
513
514                         return new_args;
515                 }
516
517                 void AddAssemblyReference (string alias, string assembly, CompilerSettings settings)
518                 {
519                         if (assembly.Length == 0) {
520                                 report.Error (1680, "Invalid reference alias `{0}='. Missing filename", alias);
521                                 return;
522                         }
523
524                         if (!IsExternAliasValid (alias)) {
525                                 report.Error (1679, "Invalid extern alias for -reference. Alias `{0}' is not a valid identifier", alias);
526                                 return;
527                         }
528
529                         settings.AssemblyReferencesAliases.Add (Tuple.Create (alias, assembly));
530                 }
531
532                 void AddResource (AssemblyResource res, CompilerSettings settings)
533                 {
534                         if (settings.Resources == null) {
535                                 settings.Resources = new List<AssemblyResource> ();
536                                 settings.Resources.Add (res);
537                                 return;
538                         }
539
540                         if (settings.Resources.Contains (res)) {
541                                 report.Error (1508, "The resource identifier `{0}' has already been used in this assembly", res.Name);
542                                 return;
543                         }
544
545                         settings.Resources.Add (res);
546                 }
547
548                 void AddSourceFile (string fileName, List<SourceFile> sourceFiles)
549                 {
550                         string path = Path.GetFullPath (fileName);
551
552                         int index;
553                         if (source_file_index.TryGetValue (path, out index)) {
554                                 string other_name = sourceFiles[index - 1].Name;
555                                 if (fileName.Equals (other_name))
556                                         report.Warning (2002, 1, "Source file `{0}' specified multiple times", other_name);
557                                 else
558                                         report.Warning (2002, 1, "Source filenames `{0}' and `{1}' both refer to the same file: {2}", fileName, other_name, path);
559
560                                 return;
561                         }
562
563                         var unit = new SourceFile (fileName, path, sourceFiles.Count + 1);
564                         sourceFiles.Add (unit);
565                         source_file_index.Add (path, unit.Index);
566                 }
567
568                 public bool ProcessWarningsList (string text, Action<int> action)
569                 {
570                         bool valid = true;
571                         foreach (string wid in text.Split (numeric_value_separator)) {
572                                 int id;
573                                 if (!int.TryParse (wid, NumberStyles.AllowLeadingWhite, CultureInfo.InvariantCulture, out id)) {
574                                         report.Error (1904, "`{0}' is not a valid warning number", wid);
575                                         valid = false;
576                                         continue;
577                                 }
578
579                                 if (report.CheckWarningCode (id, Location.Null))
580                                         action (id);
581                         }
582
583                         return valid;
584                 }
585
586                 void Error_RequiresArgument (string option)
587                 {
588                         report.Error (2006, "Missing argument for `{0}' option", option);
589                 }
590
591                 void Error_RequiresFileName (string option)
592                 {
593                         report.Error (2005, "Missing file specification for `{0}' option", option);
594                 }
595
596                 void Error_WrongOption (string option)
597                 {
598                         report.Error (2007, "Unrecognized command-line option: `{0}'", option);
599                 }
600
601                 static bool IsExternAliasValid (string identifier)
602                 {
603                         if (identifier.Length == 0)
604                                 return false;
605                         if (identifier[0] != '_' && !char.IsLetter (identifier[0]))
606                                 return false;
607
608                         for (int i = 1; i < identifier.Length; i++) {
609                                 char c = identifier[i];
610                                 if (char.IsLetter (c) || char.IsDigit (c))
611                                         continue;
612
613                                 UnicodeCategory category = char.GetUnicodeCategory (c);
614                                 if (category != UnicodeCategory.Format || category != UnicodeCategory.NonSpacingMark ||
615                                                 category != UnicodeCategory.SpacingCombiningMark ||
616                                                 category != UnicodeCategory.ConnectorPunctuation)
617                                         return false;
618                         }
619
620                         return true;
621                 }
622
623                 static string[] LoadArgs (string file)
624                 {
625                         StreamReader f;
626                         var args = new List<string> ();
627                         string line;
628                         try {
629                                 f = new StreamReader (file);
630                         } catch {
631                                 return null;
632                         }
633
634                         StringBuilder sb = new StringBuilder ();
635
636                         while ((line = f.ReadLine ()) != null) {
637                                 int t = line.Length;
638
639                                 for (int i = 0; i < t; i++) {
640                                         char c = line[i];
641
642                                         if (c == '"' || c == '\'') {
643                                                 char end = c;
644
645                                                 for (i++; i < t; i++) {
646                                                         c = line[i];
647
648                                                         if (c == end)
649                                                                 break;
650                                                         sb.Append (c);
651                                                 }
652                                         } else if (c == ' ') {
653                                                 if (sb.Length > 0) {
654                                                         args.Add (sb.ToString ());
655                                                         sb.Length = 0;
656                                                 }
657                                         } else
658                                                 sb.Append (c);
659                                 }
660                                 if (sb.Length > 0) {
661                                         args.Add (sb.ToString ());
662                                         sb.Length = 0;
663                                 }
664                         }
665
666                         return args.ToArray ();
667                 }
668
669                 void OtherFlags ()
670                 {
671                         output.WriteLine (
672                                 "Other flags in the compiler\n" +
673                                 "   --fatal[=COUNT]    Makes errors after COUNT fatal\n" +
674                                 "   --lint             Enhanced warnings\n" +
675                                 "   --parse            Only parses the source file\n" +
676                                 "   --runtime:VERSION  Sets mscorlib.dll metadata version: v1, v2, v4\n" +
677                                 "   --stacktrace       Shows stack trace at error location\n" +
678                                 "   --timestamp        Displays time stamps of various compiler events\n" +
679                                 "   -v                 Verbose parsing (for debugging the parser)\n" +
680                                 "   --mcs-debug X      Sets MCS debugging level to X\n");
681                 }
682
683                 //
684                 // This parses the -arg and /arg options to the compiler, even if the strings
685                 // in the following text use "/arg" on the strings.
686                 //
687                 ParseResult ParseOption (string option, ref string[] args, CompilerSettings settings)
688                 {
689                         int idx = option.IndexOf (':');
690                         string arg, value;
691
692                         if (idx == -1) {
693                                 arg = option;
694                                 value = "";
695                         } else {
696                                 arg = option.Substring (0, idx);
697
698                                 value = option.Substring (idx + 1);
699                         }
700
701                         switch (arg.ToLowerInvariant ()) {
702                         case "/nologo":
703                                 return ParseResult.Success;
704
705                         case "/t":
706                         case "/target":
707                                 switch (value) {
708                                 case "exe":
709                                         settings.Target = Target.Exe;
710                                         break;
711
712                                 case "winexe":
713                                         settings.Target = Target.WinExe;
714                                         break;
715
716                                 case "library":
717                                         settings.Target = Target.Library;
718                                         settings.TargetExt = ".dll";
719                                         break;
720
721                                 case "module":
722                                         settings.Target = Target.Module;
723                                         settings.TargetExt = ".netmodule";
724                                         break;
725
726                                 default:
727                                         report.Error (2019, "Invalid target type for -target. Valid options are `exe', `winexe', `library' or `module'");
728                                         return ParseResult.Error;
729                                 }
730                                 return ParseResult.Success;
731
732                         case "/out":
733                                 if (value.Length == 0) {
734                                         Error_RequiresFileName (option);
735                                         return ParseResult.Error;
736                                 }
737                                 settings.OutputFile = value;
738                                 return ParseResult.Success;
739
740                         case "/o":
741                         case "/o+":
742                         case "/optimize":
743                         case "/optimize+":
744                                 settings.Optimize = true;
745                                 return ParseResult.Success;
746
747                         case "/o-":
748                         case "/optimize-":
749                                 settings.Optimize = false;
750                                 return ParseResult.Success;
751
752                         // TODO: Not supported by csc 3.5+
753                         case "/incremental":
754                         case "/incremental+":
755                         case "/incremental-":
756                                 // nothing.
757                                 return ParseResult.Success;
758
759                         case "/d":
760                         case "/define": {
761                                         if (value.Length == 0) {
762                                                 Error_RequiresArgument (option);
763                                                 return ParseResult.Error;
764                                         }
765
766                                         foreach (string d in value.Split (argument_value_separator)) {
767                                                 string conditional = d.Trim ();
768                                                 if (!Tokenizer.IsValidIdentifier (conditional)) {
769                                                         report.Warning (2029, 1, "Invalid conditional define symbol `{0}'", conditional);
770                                                         continue;
771                                                 }
772
773                                                 settings.AddConditionalSymbol (conditional);
774                                         }
775                                         return ParseResult.Success;
776                                 }
777
778                         case "/bugreport":
779                                 //
780                                 // We should collect data, runtime, etc and store in the file specified
781                                 //
782                                 output.WriteLine ("To file bug reports, please visit: http://www.mono-project.com/Bugs");
783                                 return ParseResult.Success;
784
785                         case "/pkg": {
786                                         string packages;
787
788                                         if (value.Length == 0) {
789                                                 Error_RequiresArgument (option);
790                                                 return ParseResult.Error;
791                                         }
792                                         packages = String.Join (" ", value.Split (new Char[] { ';', ',', '\n', '\r' }));
793                                         string pkgout = Driver.GetPackageFlags (packages, report);
794
795                                         if (pkgout == null)
796                                                 return ParseResult.Error;
797
798                                         string[] xargs = pkgout.Trim (new Char[] { ' ', '\n', '\r', '\t' }).Split (new Char[] { ' ', '\t' });
799                                         args = AddArgs (args, xargs);
800                                         return ParseResult.Success;
801                                 }
802
803                         case "/linkres":
804                         case "/linkresource":
805                         case "/res":
806                         case "/resource":
807                                 AssemblyResource res = null;
808                                 string[] s = value.Split (argument_value_separator, StringSplitOptions.RemoveEmptyEntries);
809                                 switch (s.Length) {
810                                 case 1:
811                                         if (s[0].Length == 0)
812                                                 goto default;
813                                         res = new AssemblyResource (s[0], Path.GetFileName (s[0]));
814                                         break;
815                                 case 2:
816                                         res = new AssemblyResource (s[0], s[1]);
817                                         break;
818                                 case 3:
819                                         if (s[2] != "public" && s[2] != "private") {
820                                                 report.Error (1906, "Invalid resource visibility option `{0}'. Use either `public' or `private' instead", s[2]);
821                                                 return ParseResult.Error;
822                                         }
823                                         res = new AssemblyResource (s[0], s[1], s[2] == "private");
824                                         break;
825                                 default:
826                                         report.Error (-2005, "Wrong number of arguments for option `{0}'", option);
827                                         return ParseResult.Error;
828                                 }
829
830                                 if (res != null) {
831                                         res.IsEmbeded = arg[1] == 'r' || arg[1] == 'R';
832                                         AddResource (res, settings);
833                                 }
834
835                                 return ParseResult.Success;
836
837                         case "/recurse":
838                                 if (value.Length == 0) {
839                                         Error_RequiresFileName (option);
840                                         return ParseResult.Error;
841                                 }
842                                 ProcessSourceFiles (value, true, settings.SourceFiles);
843                                 return ParseResult.Success;
844
845                         case "/r":
846                         case "/reference": {
847                                         if (value.Length == 0) {
848                                                 Error_RequiresFileName (option);
849                                                 return ParseResult.Error;
850                                         }
851
852                                         string[] refs = value.Split (argument_value_separator);
853                                         foreach (string r in refs) {
854                                                 if (r.Length == 0)
855                                                         continue;
856
857                                                 string val = r;
858                                                 int index = val.IndexOf ('=');
859                                                 if (index > -1) {
860                                                         string alias = r.Substring (0, index);
861                                                         string assembly = r.Substring (index + 1);
862                                                         AddAssemblyReference (alias, assembly, settings);
863                                                         if (refs.Length != 1) {
864                                                                 report.Error (2034, "Cannot specify multiple aliases using single /reference option");
865                                                                 return ParseResult.Error;
866                                                         }
867                                                 } else {
868                                                         settings.AssemblyReferences.Add (val);
869                                                 }
870                                         }
871                                         return ParseResult.Success;
872                                 }
873                         case "/addmodule": {
874                                         if (value.Length == 0) {
875                                                 Error_RequiresFileName (option);
876                                                 return ParseResult.Error;
877                                         }
878
879                                         string[] refs = value.Split (argument_value_separator);
880                                         foreach (string r in refs) {
881                                                 settings.Modules.Add (r);
882                                         }
883                                         return ParseResult.Success;
884                                 }
885                         case "/win32res": {
886                                         if (value.Length == 0) {
887                                                 Error_RequiresFileName (option);
888                                                 return ParseResult.Error;
889                                         }
890
891                                         if (settings.Win32IconFile != null)
892                                                 report.Error (1565, "Cannot specify the `win32res' and the `win32ico' compiler option at the same time");
893
894                                         settings.Win32ResourceFile = value;
895                                         return ParseResult.Success;
896                                 }
897                         case "/win32icon": {
898                                         if (value.Length == 0) {
899                                                 Error_RequiresFileName (option);
900                                                 return ParseResult.Error;
901                                         }
902
903                                         if (settings.Win32ResourceFile != null)
904                                                 report.Error (1565, "Cannot specify the `win32res' and the `win32ico' compiler option at the same time");
905
906                                         settings.Win32IconFile = value;
907                                         return ParseResult.Success;
908                                 }
909                         case "/doc": {
910                                         if (value.Length == 0) {
911                                                 Error_RequiresFileName (option);
912                                                 return ParseResult.Error;
913                                         }
914
915                                         settings.DocumentationFile = value;
916                                         return ParseResult.Success;
917                                 }
918                         case "/lib": {
919                                         string[] libdirs;
920
921                                         if (value.Length == 0) {
922                                                 return ParseResult.Error;
923                                         }
924
925                                         libdirs = value.Split (argument_value_separator);
926                                         foreach (string dir in libdirs)
927                                                 settings.ReferencesLookupPaths.Add (dir);
928                                         return ParseResult.Success;
929                                 }
930
931                         case "/debug-":
932                                 settings.GenerateDebugInfo = false;
933                                 return ParseResult.Success;
934
935                         case "/debug":
936                                 if (value == "full" || value == "pdbonly" || idx < 0) {
937                                         settings.GenerateDebugInfo = true;
938                                         return ParseResult.Success;
939                                 }
940
941                                 if (value.Length > 0) {
942                                         report.Error (1902, "Invalid debug option `{0}'. Valid options are `full' or `pdbonly'", value);
943                                 } else {
944                                         Error_RequiresArgument (option);
945                                 }
946
947                                 return ParseResult.Error;
948
949                         case "/debug+":
950                                 settings.GenerateDebugInfo = true;
951                                 return ParseResult.Success;
952
953                         case "/checked":
954                         case "/checked+":
955                                 settings.Checked = true;
956                                 return ParseResult.Success;
957
958                         case "/checked-":
959                                 settings.Checked = false;
960                                 return ParseResult.Success;
961
962                         case "/clscheck":
963                         case "/clscheck+":
964                                 settings.VerifyClsCompliance = true;
965                                 return ParseResult.Success;
966
967                         case "/clscheck-":
968                                 settings.VerifyClsCompliance = false;
969                                 return ParseResult.Success;
970
971                         case "/unsafe":
972                         case "/unsafe+":
973                                 settings.Unsafe = true;
974                                 return ParseResult.Success;
975
976                         case "/unsafe-":
977                                 settings.Unsafe = false;
978                                 return ParseResult.Success;
979
980                         case "/warnaserror":
981                         case "/warnaserror+":
982                                 if (value.Length == 0) {
983                                         settings.WarningsAreErrors = true;
984                                         parser_settings.WarningsAreErrors = true;
985                                 } else {
986                                         if (!ProcessWarningsList (value, v => settings.AddWarningAsError (v)))
987                                                 return ParseResult.Error;
988                                 }
989                                 return ParseResult.Success;
990
991                         case "/warnaserror-":
992                                 if (value.Length == 0) {
993                                         settings.WarningsAreErrors = false;
994                                 } else {
995                                         if (!ProcessWarningsList (value, v => settings.AddWarningOnly (v)))
996                                                 return ParseResult.Error;
997                                 }
998                                 return ParseResult.Success;
999
1000                         case "/warn":
1001                                 if (value.Length == 0) {
1002                                         Error_RequiresArgument (option);
1003                                         return ParseResult.Error;
1004                                 }
1005
1006                                 SetWarningLevel (value, settings);
1007                                 return ParseResult.Success;
1008
1009                         case "/nowarn":
1010                                 if (value.Length == 0) {
1011                                         Error_RequiresArgument (option);
1012                                         return ParseResult.Error;
1013                                 }
1014
1015                                 if (!ProcessWarningsList (value, v => settings.SetIgnoreWarning (v)))
1016                                         return ParseResult.Error;
1017
1018                                 return ParseResult.Success;
1019
1020                         case "/noconfig":
1021                                 settings.LoadDefaultReferences = false;
1022                                 return ParseResult.Success;
1023
1024                         case "/platform":
1025                                 if (value.Length == 0) {
1026                                         Error_RequiresArgument (option);
1027                                         return ParseResult.Error;
1028                                 }
1029
1030                                 switch (value.ToLowerInvariant ()) {
1031                                 case "arm":
1032                                         settings.Platform = Platform.Arm;
1033                                         break;
1034                                 case "anycpu":
1035                                         settings.Platform = Platform.AnyCPU;
1036                                         break;
1037                                 case "x86":
1038                                         settings.Platform = Platform.X86;
1039                                         break;
1040                                 case "x64":
1041                                         settings.Platform = Platform.X64;
1042                                         break;
1043                                 case "itanium":
1044                                         settings.Platform = Platform.IA64;
1045                                         break;
1046                                 case "anycpu32bitpreferred":
1047                                         settings.Platform = Platform.AnyCPU32Preferred;
1048                                         break;
1049                                 default:
1050                                         report.Error (1672, "Invalid -platform option `{0}'. Valid options are `anycpu', `anycpu32bitpreferred', `arm', `x86', `x64' or `itanium'",
1051                                                 value);
1052                                         return ParseResult.Error;
1053                                 }
1054
1055                                 return ParseResult.Success;
1056
1057                         case "/sdk":
1058                                 if (value.Length == 0) {
1059                                         Error_RequiresArgument (option);
1060                                         return ParseResult.Error;
1061                                 }
1062
1063                                 settings.SdkVersion = value;
1064                                 return ParseResult.Success;
1065
1066                         // We just ignore this.
1067                         case "/errorreport":
1068                         case "/filealign":
1069                                 if (value.Length == 0) {
1070                                         Error_RequiresArgument (option);
1071                                         return ParseResult.Error;
1072                                 }
1073
1074                                 return ParseResult.Success;
1075
1076                         case "/helpinternal":
1077                                 OtherFlags ();
1078                                 return ParseResult.Stop;
1079
1080                         case "/help":
1081                         case "/?":
1082                                 Usage ();
1083                                 return ParseResult.Stop;
1084
1085                         case "/main":
1086                         case "/m":
1087                                 if (value.Length == 0) {
1088                                         Error_RequiresArgument (option);
1089                                         return ParseResult.Error;
1090                                 }
1091                                 settings.MainClass = value;
1092                                 return ParseResult.Success;
1093
1094                         case "/nostdlib":
1095                         case "/nostdlib+":
1096                                 settings.StdLib = false;
1097                                 return ParseResult.Success;
1098
1099                         case "/nostdlib-":
1100                                 settings.StdLib = true;
1101                                 return ParseResult.Success;
1102
1103                         case "/fullpaths":
1104                                 settings.ShowFullPaths = true;
1105                                 return ParseResult.Success;
1106
1107                         case "/keyfile":
1108                                 if (value.Length == 0) {
1109                                         Error_RequiresFileName (option);
1110                                         return ParseResult.Error;
1111                                 }
1112
1113                                 settings.StrongNameKeyFile = value;
1114                                 return ParseResult.Success;
1115
1116                         case "/keycontainer":
1117                                 if (value.Length == 0) {
1118                                         Error_RequiresArgument (option);
1119                                         return ParseResult.Error;
1120                                 }
1121
1122                                 settings.StrongNameKeyContainer = value;
1123                                 return ParseResult.Success;
1124
1125                         case "/delaysign+":
1126                         case "/delaysign":
1127                                 settings.StrongNameDelaySign = true;
1128                                 return ParseResult.Success;
1129
1130                         case "/delaysign-":
1131                                 settings.StrongNameDelaySign = false;
1132                                 return ParseResult.Success;
1133
1134                         case "/langversion":
1135                                 if (value.Length == 0) {
1136                                         Error_RequiresArgument (option);
1137                                         return ParseResult.Error;
1138                                 }
1139
1140                                 switch (value.ToLowerInvariant ()) {
1141                                 case "iso-1":
1142                                         settings.Version = LanguageVersion.ISO_1;
1143                                         return ParseResult.Success;
1144                                 case "default":
1145                                         settings.Version = LanguageVersion.Default;
1146                                         return ParseResult.Success;
1147                                 case "iso-2":
1148                                         settings.Version = LanguageVersion.ISO_2;
1149                                         return ParseResult.Success;
1150                                 case "3":
1151                                         settings.Version = LanguageVersion.V_3;
1152                                         return ParseResult.Success;
1153                                 case "4":
1154                                         settings.Version = LanguageVersion.V_4;
1155                                         return ParseResult.Success;
1156                                 case "5":
1157                                         settings.Version = LanguageVersion.V_5;
1158                                         return ParseResult.Success;
1159                                 case "future":
1160                                         settings.Version = LanguageVersion.Future;
1161                                         return ParseResult.Success;
1162                                 }
1163
1164                                 report.Error (1617, "Invalid -langversion option `{0}'. It must be `ISO-1', `ISO-2', `3', `4', `5', `Default' or `Future'", value);
1165                                 return ParseResult.Error;
1166
1167                         case "/codepage":
1168                                 if (value.Length == 0) {
1169                                         Error_RequiresArgument (option);
1170                                         return ParseResult.Error;
1171                                 }
1172
1173                                 switch (value) {
1174                                 case "utf8":
1175                                         settings.Encoding = Encoding.UTF8;
1176                                         break;
1177                                 case "reset":
1178                                         settings.Encoding = Encoding.Default;
1179                                         break;
1180                                 default:
1181                                         try {
1182                                                 settings.Encoding = Encoding.GetEncoding (int.Parse (value));
1183                                         } catch {
1184                                                 report.Error (2016, "Code page `{0}' is invalid or not installed", value);
1185                                         }
1186                                         return ParseResult.Error;
1187                                 }
1188                                 return ParseResult.Success;
1189
1190                         default:
1191                                 return ParseResult.UnknownOption;
1192                         }
1193                 }
1194
1195                 //
1196                 // Currently handles the Unix-like command line options, but will be
1197                 // deprecated in favor of the CSCParseOption, which will also handle the
1198                 // options that start with a dash in the future.
1199                 //
1200                 ParseResult ParseOptionUnix (string arg, ref string[] args, ref int i, CompilerSettings settings)
1201                 {
1202                         switch (arg){
1203                         case "-v":
1204                                 settings.VerboseParserFlag++;
1205                                 return ParseResult.Success;
1206
1207                         case "--version":
1208                                 Version ();
1209                                 return ParseResult.Stop;
1210                                 
1211                         case "--parse":
1212                                 settings.ParseOnly = true;
1213                                 return ParseResult.Success;
1214                                 
1215                         case "--main": case "-m":
1216                                 report.Warning (-29, 1, "Compatibility: Use -main:CLASS instead of --main CLASS or -m CLASS");
1217                                 if ((i + 1) >= args.Length){
1218                                         Error_RequiresArgument (arg);
1219                                         return ParseResult.Error;
1220                                 }
1221                                 settings.MainClass = args[++i];
1222                                 return ParseResult.Success;
1223                                 
1224                         case "--unsafe":
1225                                 report.Warning (-29, 1, "Compatibility: Use -unsafe instead of --unsafe");
1226                                 settings.Unsafe = true;
1227                                 return ParseResult.Success;
1228                                 
1229                         case "/?": case "/h": case "/help":
1230                         case "--help":
1231                                 Usage ();
1232                                 return ParseResult.Stop;
1233
1234                         case "--define":
1235                                 report.Warning (-29, 1, "Compatibility: Use -d:SYMBOL instead of --define SYMBOL");
1236                                 if ((i + 1) >= args.Length){
1237                                         Error_RequiresArgument (arg);
1238                                         return ParseResult.Error;
1239                                 }
1240
1241                                 settings.AddConditionalSymbol (args [++i]);
1242                                 return ParseResult.Success;
1243
1244                         case "--tokenize":
1245                                 settings.TokenizeOnly = true;
1246                                 return ParseResult.Success;
1247                                 
1248                         case "-o": 
1249                         case "--output":
1250                                 report.Warning (-29, 1, "Compatibility: Use -out:FILE instead of --output FILE or -o FILE");
1251                                 if ((i + 1) >= args.Length){
1252                                         Error_RequiresArgument (arg);
1253                                         return ParseResult.Error;
1254                                 }
1255                                 settings.OutputFile = args[++i];
1256                                 return ParseResult.Success;
1257
1258                         case "--checked":
1259                                 report.Warning (-29, 1, "Compatibility: Use -checked instead of --checked");
1260                                 settings.Checked = true;
1261                                 return ParseResult.Success;
1262                                 
1263                         case "--stacktrace":
1264                                 settings.Stacktrace = true;
1265                                 return ParseResult.Success;
1266                                 
1267                         case "--linkresource":
1268                         case "--linkres":
1269                                 report.Warning (-29, 1, "Compatibility: Use -linkres:VALUE instead of --linkres VALUE");
1270                                 if ((i + 1) >= args.Length){
1271                                         Error_RequiresArgument (arg);
1272                                         return ParseResult.Error;
1273                                 }
1274
1275                                 AddResource (new AssemblyResource (args[++i], args[i]), settings);
1276                                 return ParseResult.Success;
1277                                 
1278                         case "--resource":
1279                         case "--res":
1280                                 report.Warning (-29, 1, "Compatibility: Use -res:VALUE instead of --res VALUE");
1281                                 if ((i + 1) >= args.Length){
1282                                         Error_RequiresArgument (arg);
1283                                         return ParseResult.Error;
1284                                 }
1285
1286                                 AddResource (new AssemblyResource (args[++i], args[i], true), settings);
1287                                 return ParseResult.Success;
1288                                 
1289                         case "--target":
1290                                 report.Warning (-29, 1, "Compatibility: Use -target:KIND instead of --target KIND");
1291                                 if ((i + 1) >= args.Length){
1292                                         Error_RequiresArgument (arg);
1293                                         return ParseResult.Error;
1294                                 }
1295                                 
1296                                 string type = args [++i];
1297                                 switch (type){
1298                                 case "library":
1299                                         settings.Target = Target.Library;
1300                                         settings.TargetExt = ".dll";
1301                                         break;
1302                                         
1303                                 case "exe":
1304                                         settings.Target = Target.Exe;
1305                                         break;
1306                                         
1307                                 case "winexe":
1308                                         settings.Target = Target.WinExe;
1309                                         break;
1310                                         
1311                                 case "module":
1312                                         settings.Target = Target.Module;
1313                                         settings.TargetExt = ".dll";
1314                                         break;
1315                                 default:
1316                                         report.Error (2019, "Invalid target type for -target. Valid options are `exe', `winexe', `library' or `module'");
1317                                         break;
1318                                 }
1319                                 return ParseResult.Success;
1320                                 
1321                         case "-r":
1322                                 report.Warning (-29, 1, "Compatibility: Use -r:LIBRARY instead of -r library");
1323                                 if ((i + 1) >= args.Length){
1324                                         Error_RequiresArgument (arg);
1325                                         return ParseResult.Error;
1326                                 }
1327                                 
1328                                 string val = args [++i];
1329                                 int idx = val.IndexOf ('=');
1330                                 if (idx > -1) {
1331                                         string alias = val.Substring (0, idx);
1332                                         string assembly = val.Substring (idx + 1);
1333                                         AddAssemblyReference (alias, assembly, settings);
1334                                         return ParseResult.Success;
1335                                 }
1336
1337                                 settings.AssemblyReferences.Add (val);
1338                                 return ParseResult.Success;
1339                                 
1340                         case "-L":
1341                                 report.Warning (-29, 1, "Compatibility: Use -lib:ARG instead of --L arg");
1342                                 if ((i + 1) >= args.Length){
1343                                         Error_RequiresArgument (arg);
1344                                         return ParseResult.Error;
1345                                 }
1346                                 settings.ReferencesLookupPaths.Add (args [++i]);
1347                                 return ParseResult.Success;
1348
1349                         case "--lint":
1350                                 settings.EnhancedWarnings = true;
1351                                 return ParseResult.Success;
1352                                 
1353                         case "--nostdlib":
1354                                 report.Warning (-29, 1, "Compatibility: Use -nostdlib instead of --nostdlib");
1355                                 settings.StdLib = false;
1356                                 return ParseResult.Success;
1357                                 
1358                         case "--nowarn":
1359                                 report.Warning (-29, 1, "Compatibility: Use -nowarn instead of --nowarn");
1360                                 if ((i + 1) >= args.Length){
1361                                         Error_RequiresArgument (arg);
1362                                         return ParseResult.Error;
1363                                 }
1364                                 int warn = 0;
1365                                 
1366                                 try {
1367                                         warn = int.Parse (args [++i]);
1368                                 } catch {
1369                                         Usage ();
1370                                         Environment.Exit (1);
1371                                 }
1372                                 settings.SetIgnoreWarning (warn);
1373                                 return ParseResult.Success;
1374
1375                         case "--wlevel":
1376                                 report.Warning (-29, 1, "Compatibility: Use -warn:LEVEL instead of --wlevel LEVEL");
1377                                 if ((i + 1) >= args.Length){
1378                                         Error_RequiresArgument (arg);
1379                                         return ParseResult.Error;
1380                                 }
1381
1382                                 SetWarningLevel (args [++i], settings);
1383                                 return ParseResult.Success;
1384
1385                         case "--mcs-debug":
1386                                 if ((i + 1) >= args.Length){
1387                                         Error_RequiresArgument (arg);
1388                                         return ParseResult.Error;
1389                                 }
1390
1391                                 try {
1392                                         settings.DebugFlags = int.Parse (args [++i]);
1393                                 } catch {
1394                                         Error_RequiresArgument (arg);
1395                                         return ParseResult.Error;
1396                                 }
1397
1398                                 return ParseResult.Success;
1399                                 
1400                         case "--about":
1401                                 About ();
1402                                 return ParseResult.Stop;
1403                                 
1404                         case "--recurse":
1405                                 report.Warning (-29, 1, "Compatibility: Use -recurse:PATTERN option instead --recurse PATTERN");
1406                                 if ((i + 1) >= args.Length){
1407                                         Error_RequiresArgument (arg);
1408                                         return ParseResult.Error;
1409                                 }
1410                                 ProcessSourceFiles (args [++i], true, settings.SourceFiles);
1411                                 return ParseResult.Success;
1412                                 
1413                         case "--timestamp":
1414                                 settings.Timestamps = true;
1415                                 return ParseResult.Success;
1416
1417                         case "--debug": case "-g":
1418                                 report.Warning (-29, 1, "Compatibility: Use -debug option instead of -g or --debug");
1419                                 settings.GenerateDebugInfo = true;
1420                                 return ParseResult.Success;
1421                                 
1422                         case "--noconfig":
1423                                 report.Warning (-29, 1, "Compatibility: Use -noconfig option instead of --noconfig");
1424                                 settings.LoadDefaultReferences = false;
1425                                 return ParseResult.Success;
1426
1427                         default:
1428                                 if (arg.StartsWith ("--fatal", StringComparison.Ordinal)){
1429                                         int fatal = 1;
1430                                         if (arg.StartsWith ("--fatal=", StringComparison.Ordinal))
1431                                                 int.TryParse (arg.Substring (8), out fatal);
1432
1433                                         settings.FatalCounter = fatal;
1434                                         return ParseResult.Success;
1435                                 }
1436                                 if (arg.StartsWith ("--runtime:", StringComparison.Ordinal)) {
1437                                         string version = arg.Substring (10);
1438
1439                                         switch (version) {
1440                                         case "v1":
1441                                         case "V1":
1442                                                 settings.StdLibRuntimeVersion = RuntimeVersion.v1;
1443                                                 break;
1444                                         case "v2":
1445                                         case "V2":
1446                                                 settings.StdLibRuntimeVersion = RuntimeVersion.v2;
1447                                                 break;
1448                                         case "v4":
1449                                         case "V4":
1450                                                 settings.StdLibRuntimeVersion = RuntimeVersion.v4;
1451                                                 break;
1452                                         }
1453                                         return ParseResult.Success;
1454                                 }
1455
1456                                 return ParseResult.UnknownOption;
1457                         }
1458                 }
1459
1460                 void SetWarningLevel (string s, CompilerSettings settings)
1461                 {
1462                         int level = -1;
1463
1464                         try {
1465                                 level = int.Parse (s);
1466                         } catch {
1467                         }
1468                         if (level < 0 || level > 4) {
1469                                 report.Error (1900, "Warning level must be in the range 0-4");
1470                                 return;
1471                         }
1472                         settings.WarningLevel = level;
1473                 }
1474
1475                 //
1476                 // Given a path specification, splits the path from the file/pattern
1477                 //
1478                 static void SplitPathAndPattern (string spec, out string path, out string pattern)
1479                 {
1480                         int p = spec.LastIndexOf ('/');
1481                         if (p != -1) {
1482                                 //
1483                                 // Windows does not like /file.cs, switch that to:
1484                                 // "\", "file.cs"
1485                                 //
1486                                 if (p == 0) {
1487                                         path = "\\";
1488                                         pattern = spec.Substring (1);
1489                                 } else {
1490                                         path = spec.Substring (0, p);
1491                                         pattern = spec.Substring (p + 1);
1492                                 }
1493                                 return;
1494                         }
1495
1496                         p = spec.LastIndexOf ('\\');
1497                         if (p != -1) {
1498                                 path = spec.Substring (0, p);
1499                                 pattern = spec.Substring (p + 1);
1500                                 return;
1501                         }
1502
1503                         path = ".";
1504                         pattern = spec;
1505                 }
1506
1507                 void Usage ()
1508                 {
1509                         output.WriteLine (
1510                                 "Mono C# compiler, Copyright 2001-2011 Novell, Inc., Copyright 2011-2012 Xamarin, Inc\n" +
1511                                 "mcs [options] source-files\n" +
1512                                 "   --about              About the Mono C# compiler\n" +
1513                                 "   -addmodule:M1[,Mn]   Adds the module to the generated assembly\n" +
1514                                 "   -checked[+|-]        Sets default aritmetic overflow context\n" +
1515                                 "   -clscheck[+|-]       Disables CLS Compliance verifications\n" +
1516                                 "   -codepage:ID         Sets code page to the one in ID (number, utf8, reset)\n" +
1517                                 "   -define:S1[;S2]      Defines one or more conditional symbols (short: -d)\n" +
1518                                 "   -debug[+|-], -g      Generate debugging information\n" +
1519                                 "   -delaysign[+|-]      Only insert the public key into the assembly (no signing)\n" +
1520                                 "   -doc:FILE            Process documentation comments to XML file\n" +
1521                                 "   -fullpaths           Any issued error or warning uses absolute file path\n" +
1522                                 "   -help                Lists all compiler options (short: -?)\n" +
1523                                 "   -keycontainer:NAME   The key pair container used to sign the output assembly\n" +
1524                                 "   -keyfile:FILE        The key file used to strongname the ouput assembly\n" +
1525                                 "   -langversion:TEXT    Specifies language version: ISO-1, ISO-2, 3, 4, 5, Default or Future\n" +
1526                                 "   -lib:PATH1[,PATHn]   Specifies the location of referenced assemblies\n" +
1527                                 "   -main:CLASS          Specifies the class with the Main method (short: -m)\n" +
1528                                 "   -noconfig            Disables implicitly referenced assemblies\n" +
1529                                 "   -nostdlib[+|-]       Does not reference mscorlib.dll library\n" +
1530                                 "   -nowarn:W1[,Wn]      Suppress one or more compiler warnings\n" +
1531                                 "   -optimize[+|-]       Enables advanced compiler optimizations (short: -o)\n" +
1532                                 "   -out:FILE            Specifies output assembly name\n" +
1533                                 "   -pkg:P1[,Pn]         References packages P1..Pn\n" +
1534                                 "   -platform:ARCH       Specifies the target platform of the output assembly\n" +
1535                                 "                        ARCH can be one of: anycpu, anycpu32bitpreferred, arm,\n" +
1536                                 "                        x86, x64 or itanium. The default is anycpu.\n" +
1537                                 "   -recurse:SPEC        Recursively compiles files according to SPEC pattern\n" +
1538                                 "   -reference:A1[,An]   Imports metadata from the specified assembly (short: -r)\n" +
1539                                 "   -reference:ALIAS=A   Imports metadata using specified extern alias (short: -r)\n" +
1540                                 "   -sdk:VERSION         Specifies SDK version of referenced assemblies\n" +
1541                                 "                        VERSION can be one of: 2, 4, 4.5 (default) or a custom value\n" +
1542                                 "   -target:KIND         Specifies the format of the output assembly (short: -t)\n" +
1543                                 "                        KIND can be one of: exe, winexe, library, module\n" +
1544                                 "   -unsafe[+|-]         Allows to compile code which uses unsafe keyword\n" +
1545                                 "   -warnaserror[+|-]    Treats all warnings as errors\n" +
1546                                 "   -warnaserror[+|-]:W1[,Wn] Treats one or more compiler warnings as errors\n" +
1547                                 "   -warn:0-4            Sets warning level, the default is 4 (short -w:)\n" +
1548                                 "   -helpinternal        Shows internal and advanced compiler options\n" +
1549                                 "\n" +
1550                                 "Resources:\n" +
1551                                 "   -linkresource:FILE[,ID] Links FILE as a resource (short: -linkres)\n" +
1552                                 "   -resource:FILE[,ID]     Embed FILE as a resource (short: -res)\n" +
1553                                 "   -win32res:FILE          Specifies Win32 resource file (.res)\n" +
1554                                 "   -win32icon:FILE         Use this icon for the output\n" +
1555                                                                 "   @file                   Read response file for more options\n\n" +
1556                                 "Options can be of the form -option or /option");
1557                 }
1558
1559                 void Version ()
1560                 {
1561                         string version = System.Reflection.MethodBase.GetCurrentMethod ().DeclaringType.Assembly.GetName ().Version.ToString ();
1562                         output.WriteLine ("Mono C# compiler version {0}", version);
1563                 }
1564         }
1565
1566         public class RootContext
1567         {
1568                 //
1569                 // Contains the parsed tree
1570                 //
1571                 static ModuleContainer root;
1572
1573                 static public ModuleContainer ToplevelTypes {
1574                         get { return root; }
1575                         set { root = value; }
1576                 }
1577         }
1578 }