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