Update mcs/class/System.Core/System/TimeZoneInfo.cs
[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                         // Default to 1 or mdb files would be platform speficic
186                         TabSize = 1;
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 error after COUNT fatal\n" +
674                                 "   --lint             Enhanced warnings\n" +
675                                 "   --metadata-only    Produced assembly will contain metadata only\n" +
676                                 "   --parse            Only parses the source file\n" +
677                                 "   --runtime:VERSION  Sets mscorlib.dll metadata version: v1, v2, v4\n" +
678                                 "   --stacktrace       Shows stack trace at error location\n" +
679                                 "   --timestamp        Displays time stamps of various compiler events\n" +
680                                 "   -v                 Verbose parsing (for debugging the parser)\n" +
681                                 "   --mcs-debug X      Sets MCS debugging level to X\n");
682                 }
683
684                 //
685                 // This parses the -arg and /arg options to the compiler, even if the strings
686                 // in the following text use "/arg" on the strings.
687                 //
688                 ParseResult ParseOption (string option, ref string[] args, CompilerSettings settings)
689                 {
690                         int idx = option.IndexOf (':');
691                         string arg, value;
692
693                         if (idx == -1) {
694                                 arg = option;
695                                 value = "";
696                         } else {
697                                 arg = option.Substring (0, idx);
698
699                                 value = option.Substring (idx + 1);
700                         }
701
702                         switch (arg.ToLowerInvariant ()) {
703                         case "/nologo":
704                                 return ParseResult.Success;
705
706                         case "/t":
707                         case "/target":
708                                 switch (value) {
709                                 case "exe":
710                                         settings.Target = Target.Exe;
711                                         break;
712
713                                 case "winexe":
714                                         settings.Target = Target.WinExe;
715                                         break;
716
717                                 case "library":
718                                         settings.Target = Target.Library;
719                                         settings.TargetExt = ".dll";
720                                         break;
721
722                                 case "module":
723                                         settings.Target = Target.Module;
724                                         settings.TargetExt = ".netmodule";
725                                         break;
726
727                                 default:
728                                         report.Error (2019, "Invalid target type for -target. Valid options are `exe', `winexe', `library' or `module'");
729                                         return ParseResult.Error;
730                                 }
731                                 return ParseResult.Success;
732
733                         case "/out":
734                                 if (value.Length == 0) {
735                                         Error_RequiresFileName (option);
736                                         return ParseResult.Error;
737                                 }
738                                 settings.OutputFile = value;
739                                 return ParseResult.Success;
740
741                         case "/o":
742                         case "/o+":
743                         case "/optimize":
744                         case "/optimize+":
745                                 settings.Optimize = true;
746                                 return ParseResult.Success;
747
748                         case "/o-":
749                         case "/optimize-":
750                                 settings.Optimize = false;
751                                 return ParseResult.Success;
752
753                         // TODO: Not supported by csc 3.5+
754                         case "/incremental":
755                         case "/incremental+":
756                         case "/incremental-":
757                                 // nothing.
758                                 return ParseResult.Success;
759
760                         case "/d":
761                         case "/define": {
762                                         if (value.Length == 0) {
763                                                 Error_RequiresArgument (option);
764                                                 return ParseResult.Error;
765                                         }
766
767                                         foreach (string d in value.Split (argument_value_separator)) {
768                                                 string conditional = d.Trim ();
769                                                 if (!Tokenizer.IsValidIdentifier (conditional)) {
770                                                         report.Warning (2029, 1, "Invalid conditional define symbol `{0}'", conditional);
771                                                         continue;
772                                                 }
773
774                                                 settings.AddConditionalSymbol (conditional);
775                                         }
776                                         return ParseResult.Success;
777                                 }
778
779                         case "/bugreport":
780                                 //
781                                 // We should collect data, runtime, etc and store in the file specified
782                                 //
783                                 output.WriteLine ("To file bug reports, please visit: http://www.mono-project.com/Bugs");
784                                 return ParseResult.Success;
785
786                         case "/pkg": {
787                                         string packages;
788
789                                         if (value.Length == 0) {
790                                                 Error_RequiresArgument (option);
791                                                 return ParseResult.Error;
792                                         }
793                                         packages = String.Join (" ", value.Split (new Char[] { ';', ',', '\n', '\r' }));
794                                         string pkgout = Driver.GetPackageFlags (packages, report);
795
796                                         if (pkgout == null)
797                                                 return ParseResult.Error;
798
799                                         string[] xargs = pkgout.Trim (new Char[] { ' ', '\n', '\r', '\t' }).Split (new Char[] { ' ', '\t' });
800                                         args = AddArgs (args, xargs);
801                                         return ParseResult.Success;
802                                 }
803
804                         case "/linkres":
805                         case "/linkresource":
806                         case "/res":
807                         case "/resource":
808                                 AssemblyResource res = null;
809                                 string[] s = value.Split (argument_value_separator, StringSplitOptions.RemoveEmptyEntries);
810                                 switch (s.Length) {
811                                 case 1:
812                                         if (s[0].Length == 0)
813                                                 goto default;
814                                         res = new AssemblyResource (s[0], Path.GetFileName (s[0]));
815                                         break;
816                                 case 2:
817                                         res = new AssemblyResource (s[0], s[1]);
818                                         break;
819                                 case 3:
820                                         if (s[2] != "public" && s[2] != "private") {
821                                                 report.Error (1906, "Invalid resource visibility option `{0}'. Use either `public' or `private' instead", s[2]);
822                                                 return ParseResult.Error;
823                                         }
824                                         res = new AssemblyResource (s[0], s[1], s[2] == "private");
825                                         break;
826                                 default:
827                                         report.Error (-2005, "Wrong number of arguments for option `{0}'", option);
828                                         return ParseResult.Error;
829                                 }
830
831                                 if (res != null) {
832                                         res.IsEmbeded = arg[1] == 'r' || arg[1] == 'R';
833                                         AddResource (res, settings);
834                                 }
835
836                                 return ParseResult.Success;
837
838                         case "/recurse":
839                                 if (value.Length == 0) {
840                                         Error_RequiresFileName (option);
841                                         return ParseResult.Error;
842                                 }
843                                 ProcessSourceFiles (value, true, settings.SourceFiles);
844                                 return ParseResult.Success;
845
846                         case "/r":
847                         case "/reference": {
848                                         if (value.Length == 0) {
849                                                 Error_RequiresFileName (option);
850                                                 return ParseResult.Error;
851                                         }
852
853                                         string[] refs = value.Split (argument_value_separator);
854                                         foreach (string r in refs) {
855                                                 if (r.Length == 0)
856                                                         continue;
857
858                                                 string val = r;
859                                                 int index = val.IndexOf ('=');
860                                                 if (index > -1) {
861                                                         string alias = r.Substring (0, index);
862                                                         string assembly = r.Substring (index + 1);
863                                                         AddAssemblyReference (alias, assembly, settings);
864                                                         if (refs.Length != 1) {
865                                                                 report.Error (2034, "Cannot specify multiple aliases using single /reference option");
866                                                                 return ParseResult.Error;
867                                                         }
868                                                 } else {
869                                                         settings.AssemblyReferences.Add (val);
870                                                 }
871                                         }
872                                         return ParseResult.Success;
873                                 }
874                         case "/addmodule": {
875                                         if (value.Length == 0) {
876                                                 Error_RequiresFileName (option);
877                                                 return ParseResult.Error;
878                                         }
879
880                                         string[] refs = value.Split (argument_value_separator);
881                                         foreach (string r in refs) {
882                                                 settings.Modules.Add (r);
883                                         }
884                                         return ParseResult.Success;
885                                 }
886                         case "/win32res": {
887                                         if (value.Length == 0) {
888                                                 Error_RequiresFileName (option);
889                                                 return ParseResult.Error;
890                                         }
891
892                                         if (settings.Win32IconFile != null)
893                                                 report.Error (1565, "Cannot specify the `win32res' and the `win32ico' compiler option at the same time");
894
895                                         settings.Win32ResourceFile = value;
896                                         return ParseResult.Success;
897                                 }
898                         case "/win32icon": {
899                                         if (value.Length == 0) {
900                                                 Error_RequiresFileName (option);
901                                                 return ParseResult.Error;
902                                         }
903
904                                         if (settings.Win32ResourceFile != null)
905                                                 report.Error (1565, "Cannot specify the `win32res' and the `win32ico' compiler option at the same time");
906
907                                         settings.Win32IconFile = value;
908                                         return ParseResult.Success;
909                                 }
910                         case "/doc": {
911                                         if (value.Length == 0) {
912                                                 Error_RequiresFileName (option);
913                                                 return ParseResult.Error;
914                                         }
915
916                                         settings.DocumentationFile = value;
917                                         return ParseResult.Success;
918                                 }
919                         case "/lib": {
920                                         string[] libdirs;
921
922                                         if (value.Length == 0) {
923                                                 return ParseResult.Error;
924                                         }
925
926                                         libdirs = value.Split (argument_value_separator);
927                                         foreach (string dir in libdirs)
928                                                 settings.ReferencesLookupPaths.Add (dir);
929                                         return ParseResult.Success;
930                                 }
931
932                         case "/debug-":
933                                 settings.GenerateDebugInfo = false;
934                                 return ParseResult.Success;
935
936                         case "/debug":
937                                 if (value.Equals ("full", StringComparison.OrdinalIgnoreCase) || value.Equals ("pdbonly", StringComparison.OrdinalIgnoreCase) || idx < 0) {
938                                         settings.GenerateDebugInfo = true;
939                                         return ParseResult.Success;
940                                 }
941
942                                 if (value.Length > 0) {
943                                         report.Error (1902, "Invalid debug option `{0}'. Valid options are `full' or `pdbonly'", value);
944                                 } else {
945                                         Error_RequiresArgument (option);
946                                 }
947
948                                 return ParseResult.Error;
949
950                         case "/debug+":
951                                 settings.GenerateDebugInfo = true;
952                                 return ParseResult.Success;
953
954                         case "/checked":
955                         case "/checked+":
956                                 settings.Checked = true;
957                                 return ParseResult.Success;
958
959                         case "/checked-":
960                                 settings.Checked = false;
961                                 return ParseResult.Success;
962
963                         case "/clscheck":
964                         case "/clscheck+":
965                                 settings.VerifyClsCompliance = true;
966                                 return ParseResult.Success;
967
968                         case "/clscheck-":
969                                 settings.VerifyClsCompliance = false;
970                                 return ParseResult.Success;
971
972                         case "/unsafe":
973                         case "/unsafe+":
974                                 settings.Unsafe = true;
975                                 return ParseResult.Success;
976
977                         case "/unsafe-":
978                                 settings.Unsafe = false;
979                                 return ParseResult.Success;
980
981                         case "/warnaserror":
982                         case "/warnaserror+":
983                                 if (value.Length == 0) {
984                                         settings.WarningsAreErrors = true;
985                                         parser_settings.WarningsAreErrors = true;
986                                 } else {
987                                         if (!ProcessWarningsList (value, v => settings.AddWarningAsError (v)))
988                                                 return ParseResult.Error;
989                                 }
990                                 return ParseResult.Success;
991
992                         case "/warnaserror-":
993                                 if (value.Length == 0) {
994                                         settings.WarningsAreErrors = false;
995                                 } else {
996                                         if (!ProcessWarningsList (value, v => settings.AddWarningOnly (v)))
997                                                 return ParseResult.Error;
998                                 }
999                                 return ParseResult.Success;
1000
1001                         case "/warn":
1002                         case "/w":
1003                                 if (value.Length == 0) {
1004                                         Error_RequiresArgument (option);
1005                                         return ParseResult.Error;
1006                                 }
1007
1008                                 SetWarningLevel (value, settings);
1009                                 return ParseResult.Success;
1010
1011                         case "/nowarn":
1012                                 if (value.Length == 0) {
1013                                         Error_RequiresArgument (option);
1014                                         return ParseResult.Error;
1015                                 }
1016
1017                                 if (!ProcessWarningsList (value, v => settings.SetIgnoreWarning (v)))
1018                                         return ParseResult.Error;
1019
1020                                 return ParseResult.Success;
1021
1022                         case "/noconfig":
1023                                 settings.LoadDefaultReferences = false;
1024                                 return ParseResult.Success;
1025
1026                         case "/platform":
1027                                 if (value.Length == 0) {
1028                                         Error_RequiresArgument (option);
1029                                         return ParseResult.Error;
1030                                 }
1031
1032                                 switch (value.ToLowerInvariant ()) {
1033                                 case "arm":
1034                                         settings.Platform = Platform.Arm;
1035                                         break;
1036                                 case "anycpu":
1037                                         settings.Platform = Platform.AnyCPU;
1038                                         break;
1039                                 case "x86":
1040                                         settings.Platform = Platform.X86;
1041                                         break;
1042                                 case "x64":
1043                                         settings.Platform = Platform.X64;
1044                                         break;
1045                                 case "itanium":
1046                                         settings.Platform = Platform.IA64;
1047                                         break;
1048                                 case "anycpu32bitpreferred":
1049                                         settings.Platform = Platform.AnyCPU32Preferred;
1050                                         break;
1051                                 default:
1052                                         report.Error (1672, "Invalid -platform option `{0}'. Valid options are `anycpu', `anycpu32bitpreferred', `arm', `x86', `x64' or `itanium'",
1053                                                 value);
1054                                         return ParseResult.Error;
1055                                 }
1056
1057                                 return ParseResult.Success;
1058
1059                         case "/sdk":
1060                                 if (value.Length == 0) {
1061                                         Error_RequiresArgument (option);
1062                                         return ParseResult.Error;
1063                                 }
1064
1065                                 settings.SdkVersion = value;
1066                                 return ParseResult.Success;
1067
1068                         // We just ignore this.
1069                         case "/errorreport":
1070                         case "/filealign":
1071                                 if (value.Length == 0) {
1072                                         Error_RequiresArgument (option);
1073                                         return ParseResult.Error;
1074                                 }
1075
1076                                 return ParseResult.Success;
1077
1078                         case "/helpinternal":
1079                                 OtherFlags ();
1080                                 return ParseResult.Stop;
1081
1082                         case "/help":
1083                         case "/?":
1084                                 Usage ();
1085                                 return ParseResult.Stop;
1086
1087                         case "/main":
1088                         case "/m":
1089                                 if (value.Length == 0) {
1090                                         Error_RequiresArgument (option);
1091                                         return ParseResult.Error;
1092                                 }
1093                                 settings.MainClass = value;
1094                                 return ParseResult.Success;
1095
1096                         case "/nostdlib":
1097                         case "/nostdlib+":
1098                                 settings.StdLib = false;
1099                                 return ParseResult.Success;
1100
1101                         case "/nostdlib-":
1102                                 settings.StdLib = true;
1103                                 return ParseResult.Success;
1104
1105                         case "/fullpaths":
1106                                 settings.ShowFullPaths = true;
1107                                 return ParseResult.Success;
1108
1109                         case "/keyfile":
1110                                 if (value.Length == 0) {
1111                                         Error_RequiresFileName (option);
1112                                         return ParseResult.Error;
1113                                 }
1114
1115                                 settings.StrongNameKeyFile = value;
1116                                 return ParseResult.Success;
1117
1118                         case "/keycontainer":
1119                                 if (value.Length == 0) {
1120                                         Error_RequiresArgument (option);
1121                                         return ParseResult.Error;
1122                                 }
1123
1124                                 settings.StrongNameKeyContainer = value;
1125                                 return ParseResult.Success;
1126
1127                         case "/delaysign+":
1128                         case "/delaysign":
1129                                 settings.StrongNameDelaySign = true;
1130                                 return ParseResult.Success;
1131
1132                         case "/delaysign-":
1133                                 settings.StrongNameDelaySign = false;
1134                                 return ParseResult.Success;
1135
1136                         case "/langversion":
1137                                 if (value.Length == 0) {
1138                                         Error_RequiresArgument (option);
1139                                         return ParseResult.Error;
1140                                 }
1141
1142                                 switch (value.ToLowerInvariant ()) {
1143                                 case "iso-1":
1144                                         settings.Version = LanguageVersion.ISO_1;
1145                                         return ParseResult.Success;
1146                                 case "default":
1147                                         settings.Version = LanguageVersion.Default;
1148                                         return ParseResult.Success;
1149                                 case "iso-2":
1150                                         settings.Version = LanguageVersion.ISO_2;
1151                                         return ParseResult.Success;
1152                                 case "3":
1153                                         settings.Version = LanguageVersion.V_3;
1154                                         return ParseResult.Success;
1155                                 case "4":
1156                                         settings.Version = LanguageVersion.V_4;
1157                                         return ParseResult.Success;
1158                                 case "5":
1159                                         settings.Version = LanguageVersion.V_5;
1160                                         return ParseResult.Success;
1161                                 case "future":
1162                                         settings.Version = LanguageVersion.Future;
1163                                         return ParseResult.Success;
1164                                 }
1165
1166                                 report.Error (1617, "Invalid -langversion option `{0}'. It must be `ISO-1', `ISO-2', `3', `4', `5', `Default' or `Future'", value);
1167                                 return ParseResult.Error;
1168
1169                         case "/codepage":
1170                                 if (value.Length == 0) {
1171                                         Error_RequiresArgument (option);
1172                                         return ParseResult.Error;
1173                                 }
1174
1175                                 switch (value) {
1176                                 case "utf8":
1177                                         settings.Encoding = Encoding.UTF8;
1178                                         break;
1179                                 case "reset":
1180                                         settings.Encoding = Encoding.Default;
1181                                         break;
1182                                 default:
1183                                         try {
1184                                                 settings.Encoding = Encoding.GetEncoding (int.Parse (value));
1185                                         } catch {
1186                                                 report.Error (2016, "Code page `{0}' is invalid or not installed", value);
1187                                         }
1188                                         return ParseResult.Error;
1189                                 }
1190                                 return ParseResult.Success;
1191
1192                         default:
1193                                 return ParseResult.UnknownOption;
1194                         }
1195                 }
1196
1197                 //
1198                 // Currently handles the Unix-like command line options, but will be
1199                 // deprecated in favor of the CSCParseOption, which will also handle the
1200                 // options that start with a dash in the future.
1201                 //
1202                 ParseResult ParseOptionUnix (string arg, ref string[] args, ref int i, CompilerSettings settings)
1203                 {
1204                         switch (arg){
1205                         case "-v":
1206                                 settings.VerboseParserFlag++;
1207                                 return ParseResult.Success;
1208
1209                         case "--version":
1210                                 Version ();
1211                                 return ParseResult.Stop;
1212                                 
1213                         case "--parse":
1214                                 settings.ParseOnly = true;
1215                                 return ParseResult.Success;
1216                                 
1217                         case "--main": case "-m":
1218                                 report.Warning (-29, 1, "Compatibility: Use -main:CLASS instead of --main CLASS or -m CLASS");
1219                                 if ((i + 1) >= args.Length){
1220                                         Error_RequiresArgument (arg);
1221                                         return ParseResult.Error;
1222                                 }
1223                                 settings.MainClass = args[++i];
1224                                 return ParseResult.Success;
1225                                 
1226                         case "--unsafe":
1227                                 report.Warning (-29, 1, "Compatibility: Use -unsafe instead of --unsafe");
1228                                 settings.Unsafe = true;
1229                                 return ParseResult.Success;
1230                                 
1231                         case "/?": case "/h": case "/help":
1232                         case "--help":
1233                                 Usage ();
1234                                 return ParseResult.Stop;
1235
1236                         case "--define":
1237                                 report.Warning (-29, 1, "Compatibility: Use -d:SYMBOL instead of --define SYMBOL");
1238                                 if ((i + 1) >= args.Length){
1239                                         Error_RequiresArgument (arg);
1240                                         return ParseResult.Error;
1241                                 }
1242
1243                                 settings.AddConditionalSymbol (args [++i]);
1244                                 return ParseResult.Success;
1245
1246                         case "--tokenize":
1247                                 settings.TokenizeOnly = true;
1248                                 return ParseResult.Success;
1249                                 
1250                         case "-o": 
1251                         case "--output":
1252                                 report.Warning (-29, 1, "Compatibility: Use -out:FILE instead of --output FILE or -o FILE");
1253                                 if ((i + 1) >= args.Length){
1254                                         Error_RequiresArgument (arg);
1255                                         return ParseResult.Error;
1256                                 }
1257                                 settings.OutputFile = args[++i];
1258                                 return ParseResult.Success;
1259
1260                         case "--checked":
1261                                 report.Warning (-29, 1, "Compatibility: Use -checked instead of --checked");
1262                                 settings.Checked = true;
1263                                 return ParseResult.Success;
1264                                 
1265                         case "--stacktrace":
1266                                 settings.Stacktrace = true;
1267                                 return ParseResult.Success;
1268                                 
1269                         case "--linkresource":
1270                         case "--linkres":
1271                                 report.Warning (-29, 1, "Compatibility: Use -linkres:VALUE instead of --linkres VALUE");
1272                                 if ((i + 1) >= args.Length){
1273                                         Error_RequiresArgument (arg);
1274                                         return ParseResult.Error;
1275                                 }
1276
1277                                 AddResource (new AssemblyResource (args[++i], args[i]), settings);
1278                                 return ParseResult.Success;
1279                                 
1280                         case "--resource":
1281                         case "--res":
1282                                 report.Warning (-29, 1, "Compatibility: Use -res:VALUE instead of --res VALUE");
1283                                 if ((i + 1) >= args.Length){
1284                                         Error_RequiresArgument (arg);
1285                                         return ParseResult.Error;
1286                                 }
1287
1288                                 AddResource (new AssemblyResource (args[++i], args[i], true), settings);
1289                                 return ParseResult.Success;
1290                                 
1291                         case "--target":
1292                                 report.Warning (-29, 1, "Compatibility: Use -target:KIND instead of --target KIND");
1293                                 if ((i + 1) >= args.Length){
1294                                         Error_RequiresArgument (arg);
1295                                         return ParseResult.Error;
1296                                 }
1297                                 
1298                                 string type = args [++i];
1299                                 switch (type){
1300                                 case "library":
1301                                         settings.Target = Target.Library;
1302                                         settings.TargetExt = ".dll";
1303                                         break;
1304                                         
1305                                 case "exe":
1306                                         settings.Target = Target.Exe;
1307                                         break;
1308                                         
1309                                 case "winexe":
1310                                         settings.Target = Target.WinExe;
1311                                         break;
1312                                         
1313                                 case "module":
1314                                         settings.Target = Target.Module;
1315                                         settings.TargetExt = ".dll";
1316                                         break;
1317                                 default:
1318                                         report.Error (2019, "Invalid target type for -target. Valid options are `exe', `winexe', `library' or `module'");
1319                                         break;
1320                                 }
1321                                 return ParseResult.Success;
1322                                 
1323                         case "-r":
1324                                 report.Warning (-29, 1, "Compatibility: Use -r:LIBRARY instead of -r library");
1325                                 if ((i + 1) >= args.Length){
1326                                         Error_RequiresArgument (arg);
1327                                         return ParseResult.Error;
1328                                 }
1329                                 
1330                                 string val = args [++i];
1331                                 int idx = val.IndexOf ('=');
1332                                 if (idx > -1) {
1333                                         string alias = val.Substring (0, idx);
1334                                         string assembly = val.Substring (idx + 1);
1335                                         AddAssemblyReference (alias, assembly, settings);
1336                                         return ParseResult.Success;
1337                                 }
1338
1339                                 settings.AssemblyReferences.Add (val);
1340                                 return ParseResult.Success;
1341                                 
1342                         case "-L":
1343                                 report.Warning (-29, 1, "Compatibility: Use -lib:ARG instead of --L arg");
1344                                 if ((i + 1) >= args.Length){
1345                                         Error_RequiresArgument (arg);
1346                                         return ParseResult.Error;
1347                                 }
1348                                 settings.ReferencesLookupPaths.Add (args [++i]);
1349                                 return ParseResult.Success;
1350
1351                         case "--lint":
1352                                 settings.EnhancedWarnings = true;
1353                                 return ParseResult.Success;
1354                                 
1355                         case "--nostdlib":
1356                                 report.Warning (-29, 1, "Compatibility: Use -nostdlib instead of --nostdlib");
1357                                 settings.StdLib = false;
1358                                 return ParseResult.Success;
1359                                 
1360                         case "--nowarn":
1361                                 report.Warning (-29, 1, "Compatibility: Use -nowarn instead of --nowarn");
1362                                 if ((i + 1) >= args.Length){
1363                                         Error_RequiresArgument (arg);
1364                                         return ParseResult.Error;
1365                                 }
1366                                 int warn = 0;
1367                                 
1368                                 try {
1369                                         warn = int.Parse (args [++i]);
1370                                 } catch {
1371                                         Usage ();
1372                                         Environment.Exit (1);
1373                                 }
1374                                 settings.SetIgnoreWarning (warn);
1375                                 return ParseResult.Success;
1376
1377                         case "--wlevel":
1378                                 report.Warning (-29, 1, "Compatibility: Use -warn:LEVEL instead of --wlevel LEVEL");
1379                                 if ((i + 1) >= args.Length){
1380                                         Error_RequiresArgument (arg);
1381                                         return ParseResult.Error;
1382                                 }
1383
1384                                 SetWarningLevel (args [++i], settings);
1385                                 return ParseResult.Success;
1386
1387                         case "--mcs-debug":
1388                                 if ((i + 1) >= args.Length){
1389                                         Error_RequiresArgument (arg);
1390                                         return ParseResult.Error;
1391                                 }
1392
1393                                 try {
1394                                         settings.DebugFlags = int.Parse (args [++i]);
1395                                 } catch {
1396                                         Error_RequiresArgument (arg);
1397                                         return ParseResult.Error;
1398                                 }
1399
1400                                 return ParseResult.Success;
1401                                 
1402                         case "--about":
1403                                 About ();
1404                                 return ParseResult.Stop;
1405                                 
1406                         case "--recurse":
1407                                 report.Warning (-29, 1, "Compatibility: Use -recurse:PATTERN option instead --recurse PATTERN");
1408                                 if ((i + 1) >= args.Length){
1409                                         Error_RequiresArgument (arg);
1410                                         return ParseResult.Error;
1411                                 }
1412                                 ProcessSourceFiles (args [++i], true, settings.SourceFiles);
1413                                 return ParseResult.Success;
1414                                 
1415                         case "--timestamp":
1416                                 settings.Timestamps = true;
1417                                 return ParseResult.Success;
1418
1419                         case "--debug": case "-g":
1420                                 report.Warning (-29, 1, "Compatibility: Use -debug option instead of -g or --debug");
1421                                 settings.GenerateDebugInfo = true;
1422                                 return ParseResult.Success;
1423                                 
1424                         case "--noconfig":
1425                                 report.Warning (-29, 1, "Compatibility: Use -noconfig option instead of --noconfig");
1426                                 settings.LoadDefaultReferences = false;
1427                                 return ParseResult.Success;
1428
1429                         case "--metadata-only":
1430                                 settings.WriteMetadataOnly = true;
1431                                 return ParseResult.Success;
1432
1433                         default:
1434                                 if (arg.StartsWith ("--fatal", StringComparison.Ordinal)){
1435                                         int fatal = 1;
1436                                         if (arg.StartsWith ("--fatal=", StringComparison.Ordinal))
1437                                                 int.TryParse (arg.Substring (8), out fatal);
1438
1439                                         settings.FatalCounter = fatal;
1440                                         return ParseResult.Success;
1441                                 }
1442                                 if (arg.StartsWith ("--runtime:", StringComparison.Ordinal)) {
1443                                         string version = arg.Substring (10);
1444
1445                                         switch (version) {
1446                                         case "v1":
1447                                         case "V1":
1448                                                 settings.StdLibRuntimeVersion = RuntimeVersion.v1;
1449                                                 break;
1450                                         case "v2":
1451                                         case "V2":
1452                                                 settings.StdLibRuntimeVersion = RuntimeVersion.v2;
1453                                                 break;
1454                                         case "v4":
1455                                         case "V4":
1456                                                 settings.StdLibRuntimeVersion = RuntimeVersion.v4;
1457                                                 break;
1458                                         }
1459                                         return ParseResult.Success;
1460                                 }
1461
1462                                 return ParseResult.UnknownOption;
1463                         }
1464                 }
1465
1466                 void SetWarningLevel (string s, CompilerSettings settings)
1467                 {
1468                         int level = -1;
1469
1470                         try {
1471                                 level = int.Parse (s);
1472                         } catch {
1473                         }
1474                         if (level < 0 || level > 4) {
1475                                 report.Error (1900, "Warning level must be in the range 0-4");
1476                                 return;
1477                         }
1478                         settings.WarningLevel = level;
1479                 }
1480
1481                 //
1482                 // Given a path specification, splits the path from the file/pattern
1483                 //
1484                 static void SplitPathAndPattern (string spec, out string path, out string pattern)
1485                 {
1486                         int p = spec.LastIndexOf ('/');
1487                         if (p != -1) {
1488                                 //
1489                                 // Windows does not like /file.cs, switch that to:
1490                                 // "\", "file.cs"
1491                                 //
1492                                 if (p == 0) {
1493                                         path = "\\";
1494                                         pattern = spec.Substring (1);
1495                                 } else {
1496                                         path = spec.Substring (0, p);
1497                                         pattern = spec.Substring (p + 1);
1498                                 }
1499                                 return;
1500                         }
1501
1502                         p = spec.LastIndexOf ('\\');
1503                         if (p != -1) {
1504                                 path = spec.Substring (0, p);
1505                                 pattern = spec.Substring (p + 1);
1506                                 return;
1507                         }
1508
1509                         path = ".";
1510                         pattern = spec;
1511                 }
1512
1513                 void Usage ()
1514                 {
1515                         output.WriteLine (
1516                                 "Mono C# compiler, Copyright 2001-2011 Novell, Inc., Copyright 2011-2012 Xamarin, Inc\n" +
1517                                 "mcs [options] source-files\n" +
1518                                 "   --about              About the Mono C# compiler\n" +
1519                                 "   -addmodule:M1[,Mn]   Adds the module to the generated assembly\n" +
1520                                 "   -checked[+|-]        Sets default aritmetic overflow context\n" +
1521                                 "   -clscheck[+|-]       Disables CLS Compliance verifications\n" +
1522                                 "   -codepage:ID         Sets code page to the one in ID (number, utf8, reset)\n" +
1523                                 "   -define:S1[;S2]      Defines one or more conditional symbols (short: -d)\n" +
1524                                 "   -debug[+|-], -g      Generate debugging information\n" +
1525                                 "   -delaysign[+|-]      Only insert the public key into the assembly (no signing)\n" +
1526                                 "   -doc:FILE            Process documentation comments to XML file\n" +
1527                                 "   -fullpaths           Any issued error or warning uses absolute file path\n" +
1528                                 "   -help                Lists all compiler options (short: -?)\n" +
1529                                 "   -keycontainer:NAME   The key pair container used to sign the output assembly\n" +
1530                                 "   -keyfile:FILE        The key file used to strongname the ouput assembly\n" +
1531                                 "   -langversion:TEXT    Specifies language version: ISO-1, ISO-2, 3, 4, 5, Default or Future\n" +
1532                                 "   -lib:PATH1[,PATHn]   Specifies the location of referenced assemblies\n" +
1533                                 "   -main:CLASS          Specifies the class with the Main method (short: -m)\n" +
1534                                 "   -noconfig            Disables implicitly referenced assemblies\n" +
1535                                 "   -nostdlib[+|-]       Does not reference mscorlib.dll library\n" +
1536                                 "   -nowarn:W1[,Wn]      Suppress one or more compiler warnings\n" +
1537                                 "   -optimize[+|-]       Enables advanced compiler optimizations (short: -o)\n" +
1538                                 "   -out:FILE            Specifies output assembly name\n" +
1539                                 "   -pkg:P1[,Pn]         References packages P1..Pn\n" +
1540                                 "   -platform:ARCH       Specifies the target platform of the output assembly\n" +
1541                                 "                        ARCH can be one of: anycpu, anycpu32bitpreferred, arm,\n" +
1542                                 "                        x86, x64 or itanium. The default is anycpu.\n" +
1543                                 "   -recurse:SPEC        Recursively compiles files according to SPEC pattern\n" +
1544                                 "   -reference:A1[,An]   Imports metadata from the specified assembly (short: -r)\n" +
1545                                 "   -reference:ALIAS=A   Imports metadata using specified extern alias (short: -r)\n" +
1546                                 "   -sdk:VERSION         Specifies SDK version of referenced assemblies\n" +
1547                                 "                        VERSION can be one of: 2, 4, 4.5 (default) or a custom value\n" +
1548                                 "   -target:KIND         Specifies the format of the output assembly (short: -t)\n" +
1549                                 "                        KIND can be one of: exe, winexe, library, module\n" +
1550                                 "   -unsafe[+|-]         Allows to compile code which uses unsafe keyword\n" +
1551                                 "   -warnaserror[+|-]    Treats all warnings as errors\n" +
1552                                 "   -warnaserror[+|-]:W1[,Wn] Treats one or more compiler warnings as errors\n" +
1553                                 "   -warn:0-4            Sets warning level, the default is 4 (short -w:)\n" +
1554                                 "   -helpinternal        Shows internal and advanced compiler options\n" +
1555                                 "\n" +
1556                                 "Resources:\n" +
1557                                 "   -linkresource:FILE[,ID] Links FILE as a resource (short: -linkres)\n" +
1558                                 "   -resource:FILE[,ID]     Embed FILE as a resource (short: -res)\n" +
1559                                 "   -win32res:FILE          Specifies Win32 resource file (.res)\n" +
1560                                 "   -win32icon:FILE         Use this icon for the output\n" +
1561                                                                 "   @file                   Read response file for more options\n\n" +
1562                                 "Options can be of the form -option or /option");
1563                 }
1564
1565                 void Version ()
1566                 {
1567                         string version = System.Reflection.MethodBase.GetCurrentMethod ().DeclaringType.Assembly.GetName ().Version.ToString ();
1568                         output.WriteLine ("Mono C# compiler version {0}", version);
1569                 }
1570         }
1571
1572         public class RootContext
1573         {
1574                 //
1575                 // Contains the parsed tree
1576                 //
1577                 static ModuleContainer root;
1578
1579                 static public ModuleContainer ToplevelTypes {
1580                         get { return root; }
1581                         set { root = value; }
1582                 }
1583         }
1584 }