2009-08-18 Marek Habersack <mhabersack@novell.com>
[mono.git] / mcs / mcs / driver.cs
index 701703ddfaf56d3015b932cf28e244b44d920750..f688846d991d93787f8598985831232e4503fdda 100644 (file)
@@ -26,6 +26,12 @@ namespace Mono.CSharp
        public enum Target {
                Library, Exe, Module, WinExe
        };
+
+#if GMCS_SOURCE
+       enum Platform {
+               AnyCPU, X86, X64, IA64
+       };
+#endif
        
        /// <summary>
        ///    The compiler driver.
@@ -35,24 +41,24 @@ namespace Mono.CSharp
                //
                // Assemblies references to be linked.   Initialized with
                // mscorlib.dll here.
-               static ArrayList references;
+               ArrayList references;
 
                //
                // If any of these fail, we ignore the problem.  This is so
                // that we can list all the assemblies in Windows and not fail
                // if they are missing on Linux.
                //
-               static ArrayList soft_references;
+               ArrayList soft_references;
 
                // 
                // External aliases for assemblies.
                //
-               static Hashtable external_aliases;
+               Hashtable external_aliases;
 
                //
                // Modules to be linked
                //
-               static ArrayList modules;
+               ArrayList modules;
 
                // Lookup paths
                static ArrayList link_paths;
@@ -74,9 +80,9 @@ namespace Mono.CSharp
                //
                // A list of resource files
                //
-               static Resources embedded_resources;
-               static string win32ResourceFile;
-               static string win32IconFile;
+               Resources embedded_resources;
+               string win32ResourceFile;
+               string win32IconFile;
 
                //
                // Output file
@@ -93,10 +99,10 @@ namespace Mono.CSharp
                //
                Encoding encoding;
 
+               static readonly char[] argument_value_separator = new char [] { ';', ',' };
+
                static public void Reset ()
                {
-                       embedded_resources = null;
-                       win32ResourceFile = win32IconFile = null;
                        output_file = null;
                }
 
@@ -105,10 +111,10 @@ namespace Mono.CSharp
                        encoding = Encoding.Default;
                }
 
-               public static Driver Create (string [] args)
+               public static Driver Create (string [] args, bool require_files)
                {
                        Driver d = new Driver ();
-                       if (!d.ParseArguments (args))
+                       if (!d.ParseArguments (args, require_files))
                                return null;
 
                        return d;
@@ -225,36 +231,41 @@ namespace Mono.CSharp
                        Console.WriteLine (
                                "Mono C# compiler, Copyright 2001 - 2008 Novell, Inc.\n" +
                                "mcs [options] source-files\n" +
-                               "   --about            About the Mono C# compiler\n" +
-                               "   -addmodule:M1[,Mn] Adds the module to the generated assembly\n" + 
-                               "   -checked[+|-]      Sets default aritmetic overflow context\n" +
-                               "   -codepage:ID       Sets code page to the one in ID (number, utf8, reset)\n" +
-                               "   -clscheck[+|-]     Disables CLS Compliance verifications\n" +
-                               "   -define:S1[;S2]    Defines one or more conditional symbols (short: -d)\n" +
-                               "   -debug[+|-], -g    Generate debugging information\n" + 
-                               "   -delaysign[+|-]    Only insert the public key into the assembly (no signing)\n" +
-                               "   -doc:FILE          Process documentation comments to XML file\n" + 
-                               "   -help              Lists all compiler options (short: -?)\n" + 
-                               "   -keycontainer:NAME The key pair container used to sign the output assembly\n" +
-                               "   -keyfile:FILE      The key file used to strongname the ouput assembly\n" +
-                               "   -langversion:TEXT  Specifies language version modes: ISO-1, ISO-2, or Default\n" + 
-                               "   -lib:PATH1[,PATHn] Specifies the location of referenced assemblies\n" +
-                               "   -main:CLASS        Specifies the class with the Main method (short: -m)\n" +
-                               "   -noconfig[+|-]     Disables implicit references to assemblies\n" +
-                               "   -nostdlib[+|-]     Does not reference mscorlib.dll library\n" +
-                               "   -nowarn:W1[,Wn]    Suppress one or more compiler warnings\n" + 
-                               "   -optimize[+|-]     Enables advanced compiler optimizations (short: -o)\n" + 
-                               "   -out:FILE          Specifies output assembly name\n" +
-                               "   -pkg:P1[,Pn]       References packages P1..Pn\n" + 
-                               "   -recurse:SPEC      Recursively compiles files according to SPEC pattern\n" + 
-                               "   -reference:A1[,An] Imports metadata from the specified assembly (short: -r)\n" +
-                               "   -reference:ALIAS=A Imports metadata using specified extern alias (short: -r)\n" +                           
-                               "   -target:KIND       Specifies the format of the output assembly (short: -t)\n" +
-                               "                      KIND can be one of: exe, winexe, library, module\n" +
-                               "   -unsafe[+|-]       Allows to compile code which uses unsafe keyword\n" +
-                               "   -warnaserror[+|-]  Treats all warnings as errors\n" +
-                               "   -warn:0-4          Sets warning level, the default is 3 (short -w:)\n" +
-                               "   -help2             Shows internal compiler options\n" + 
+                               "   --about              About the Mono C# compiler\n" +
+                               "   -addmodule:M1[,Mn]   Adds the module to the generated assembly\n" + 
+                               "   -checked[+|-]        Sets default aritmetic overflow context\n" +
+                               "   -codepage:ID         Sets code page to the one in ID (number, utf8, reset)\n" +
+                               "   -clscheck[+|-]       Disables CLS Compliance verifications\n" +
+                               "   -define:S1[;S2]      Defines one or more conditional symbols (short: -d)\n" +
+                               "   -debug[+|-], -g      Generate debugging information\n" + 
+                               "   -delaysign[+|-]      Only insert the public key into the assembly (no signing)\n" +
+                               "   -doc:FILE            Process documentation comments to XML file\n" + 
+                               "   -help                Lists all compiler options (short: -?)\n" + 
+                               "   -keycontainer:NAME   The key pair container used to sign the output assembly\n" +
+                               "   -keyfile:FILE        The key file used to strongname the ouput assembly\n" +
+                               "   -langversion:TEXT    Specifies language version: ISO-1, ISO-2, Default, or Future\n" + 
+                               "   -lib:PATH1[,PATHn]   Specifies the location of referenced assemblies\n" +
+                               "   -main:CLASS          Specifies the class with the Main method (short: -m)\n" +
+                               "   -noconfig            Disables implicitly referenced assemblies\n" +
+                               "   -nostdlib[+|-]       Does not reference mscorlib.dll library\n" +
+                               "   -nowarn:W1[,Wn]      Suppress one or more compiler warnings\n" + 
+                               "   -optimize[+|-]       Enables advanced compiler optimizations (short: -o)\n" + 
+                               "   -out:FILE            Specifies output assembly name\n" +
+#if !SMCS_SOURCE
+                               "   -pkg:P1[,Pn]         References packages P1..Pn\n" + 
+#endif
+                               "   -platform:ARCH       Specifies the target platform of the output assembly\n" +
+                               "                        ARCH can be one of: anycpu, x86, x64 or itanium\n" +
+                               "   -recurse:SPEC        Recursively compiles files according to SPEC pattern\n" + 
+                               "   -reference:A1[,An]   Imports metadata from the specified assembly (short: -r)\n" +
+                               "   -reference:ALIAS=A   Imports metadata using specified extern alias (short: -r)\n" +                         
+                               "   -target:KIND         Specifies the format of the output assembly (short: -t)\n" +
+                               "                        KIND can be one of: exe, winexe, library, module\n" +
+                               "   -unsafe[+|-]         Allows to compile code which uses unsafe keyword\n" +
+                               "   -warnaserror[+|-]    Treats all warnings as errors\n" +
+                               "   -warnaserror[+|-]:W1[,Wn] Treats one or more compiler warnings as errors\n" +
+                               "   -warn:0-4            Sets warning level, the default is 4 (short -w:)\n" +
+                               "   -help2               Shows internal compiler options\n" + 
                                "\n" +
                                "Resources:\n" +
                                "   -linkresource:FILE[,ID] Links FILE as a resource (short: -linkres)\n" +
@@ -286,11 +297,9 @@ namespace Mono.CSharp
 
                public static int Main (string[] args)
                {
-                       RootContext.Version = LanguageVersion.Default;
-
                        Location.InEmacs = Environment.GetEnvironmentVariable ("EMACS") == "t";
 
-                       Driver d = Driver.Create (args);
+                       Driver d = Driver.Create (args, true);
                        if (d == null)
                                return 1;
 
@@ -298,12 +307,15 @@ namespace Mono.CSharp
                                if (Report.Warnings > 0) {
                                        Console.WriteLine ("Compilation succeeded - {0} warning(s)", Report.Warnings);
                                }
+                               Environment.Exit (0);
                                return 0;
-                       } else {
-                               Console.WriteLine("Compilation failed: {0} error(s), {1} warnings",
-                                       Report.Errors, Report.Warnings);
-                               return 1;
                        }
+                       
+                       
+                       Console.WriteLine("Compilation failed: {0} error(s), {1} warnings",
+                               Report.Errors, Report.Warnings);
+                       Environment.Exit (1);
+                       return 1;
                }
 
                static public void LoadAssembly (string assembly, bool soft)
@@ -399,9 +411,9 @@ namespace Mono.CSharp
 
                                // Extern aliased refs require special handling
                                if (alias == null)
-                                       RootNamespace.Global.AddAssemblyReference (a);
+                                       GlobalRootNamespace.Instance.AddAssemblyReference (a);
                                else
-                                       RootNamespace.DefineRootNamespace (alias, a);
+                                       GlobalRootNamespace.Instance.DefineRootNamespace (alias, a);
 
                        } catch (BadImageFormatException f) {
                                // .NET 2.0 throws this if we try to load a module without an assembly manifest ...
@@ -441,7 +453,7 @@ namespace Mono.CSharp
                                        }
                                }
 
-                               RootNamespace.Global.AddModuleReference (m);
+                               GlobalRootNamespace.Instance.AddModuleReference (m);
 
                        } catch (BadImageFormatException f) {
                                Error9 ("module", f.FileName, f.FusionLog);
@@ -453,8 +465,11 @@ namespace Mono.CSharp
                /// <summary>
                ///   Loads all assemblies referenced on the command line
                /// </summary>
-               static public void LoadReferences ()
+               public void LoadReferences ()
                {
+                       link_paths.Add (GetSystemDir ());
+                       link_paths.Add (Directory.GetCurrentDirectory ());
+
                        //
                        // Load Core Library for default compilation
                        //
@@ -469,8 +484,8 @@ namespace Mono.CSharp
 
                        foreach (DictionaryEntry entry in external_aliases)
                                LoadAssembly ((string) entry.Value, (string) entry.Key, false);
-                       
-                       return;
+                               
+                       GlobalRootNamespace.Instance.ComputeNamespaces ();
                }
 
                static string [] LoadArgs (string file)
@@ -570,7 +585,7 @@ namespace Mono.CSharp
                        Location.AddFile (f);
                }
 
-               bool ParseArguments (string[] args)
+               bool ParseArguments (string[] args, bool require_files)
                {
                        references = new ArrayList ();
                        external_aliases = new Hashtable ();
@@ -586,7 +601,7 @@ namespace Mono.CSharp
                                if (arg.Length == 0)
                                        continue;
 
-                               if (arg.StartsWith ("@")) {
+                               if (arg [0] == '@') {
                                        string [] extra_args;
                                        string response_file = arg.Substring (1);
 
@@ -619,7 +634,7 @@ namespace Mono.CSharp
                                                continue;
                                        }
 
-                                       if (arg.StartsWith ("-")) {
+                                       if (arg [0] == '-') {
                                                if (UnixParseOption (arg, ref args, ref i))
                                                        continue;
 
@@ -646,6 +661,9 @@ namespace Mono.CSharp
                                ProcessSourceFiles (arg, false);
                        }
 
+                       if (require_files == false)
+                               return true;
+                                       
                        //
                        // If we are an exe, require a source file for the entry point
                        //
@@ -672,12 +690,12 @@ namespace Mono.CSharp
                {
                        Location.Initialize ();
 
-                       int files_count = Location.SourceFiles.Length;
-                       for (int i = 0; i < files_count; ++i) {
+                       ArrayList cu = Location.SourceFiles;
+                       for (int i = 0; i < cu.Count; ++i) {
                                if (tokenize) {
-                                       tokenize_file (Location.SourceFiles [i]);
+                                       tokenize_file ((CompilationUnit) cu [i]);
                                } else {
-                                       Parse (Location.SourceFiles [i]);
+                                       Parse ((CompilationUnit) cu [i]);
                                }
                        }
                }
@@ -724,8 +742,11 @@ namespace Mono.CSharp
                        }
                }
 
-               static void DefineDefaultConfig ()
+               public void ProcessDefaultConfig ()
                {
+                       if (!load_default_config)
+                               return;
+       
                        //
                        // For now the "default config" is harcoded into the compiler
                        // we can move this outside later
@@ -734,7 +755,6 @@ namespace Mono.CSharp
                                "System",
                                "System.Xml",
 #if NET_2_1
-                               "System.Core",
                                "System.Net",
                                "System.Windows",
                                "System.Windows.Browser",
@@ -763,11 +783,13 @@ namespace Mono.CSharp
                                "System.Windows.Forms"
 #endif
                        };
-                       
-                       if (RootContext.Version == LanguageVersion.LINQ)
-                               soft_references.Add ("System.Core");
 
                        soft_references.AddRange (default_config);
+
+                       if (RootContext.Version > LanguageVersion.ISO_2)
+                               soft_references.Add ("System.Core");
+                       if (RootContext.Version > LanguageVersion.V_3)
+                               soft_references.Add ("Microsoft.CSharp");
                }
 
                public static string OutputFile
@@ -971,11 +993,6 @@ namespace Mono.CSharp
                                Report.Fatal = true;
                                return true;
                                
-                       case "--werror":
-                               Report.Warning (-29, 1, "Compatibility: Use -warnaserror: option instead of --werror");
-                               Report.WarningsAreErrors = true;
-                               return true;
-
                        case "--nowarn":
                                Report.Warning (-29, 1, "Compatibility: Use -nowarn instead of --nowarn");
                                if ((i + 1) >= args.Length){
@@ -1051,6 +1068,45 @@ namespace Mono.CSharp
                        return false;
                }
 
+#if !SMCS_SOURCE
+               public static string GetPackageFlags (string packages, bool fatal)
+               {
+                       ProcessStartInfo pi = new ProcessStartInfo ();
+                       pi.FileName = "pkg-config";
+                       pi.RedirectStandardOutput = true;
+                       pi.UseShellExecute = false;
+                       pi.Arguments = "--libs " + packages;
+                       Process p = null;
+                       try {
+                               p = Process.Start (pi);
+                       } catch (Exception e) {
+                               Report.Error (-27, "Couldn't run pkg-config: " + e.Message);
+                               if (fatal)
+                                       Environment.Exit (1);
+                               p.Close ();
+                               return null;
+                       }
+                       
+                       if (p.StandardOutput == null){
+                               Report.Warning (-27, 1, "Specified package did not return any information");
+                               p.Close ();
+                               return null;
+                       }
+                       string pkgout = p.StandardOutput.ReadToEnd ();
+                       p.WaitForExit ();
+                       if (p.ExitCode != 0) {
+                               Report.Error (-27, "Error running pkg-config. Check the above output.");
+                               if (fatal)
+                                       Environment.Exit (1);
+                               p.Close ();
+                               return null;
+                       }
+                       p.Close ();
+
+                       return pkgout;
+               }
+#endif
+
                //
                // This parses the -arg and /arg options to the compiler, even if the strings
                // in the following text use "/arg" on the strings.
@@ -1069,7 +1125,7 @@ namespace Mono.CSharp
                                value = option.Substring (idx + 1);
                        }
 
-                       switch (arg){
+                       switch (arg.ToLower (CultureInfo.InvariantCulture)){
                        case "/nologo":
                                return true;
 
@@ -1133,7 +1189,7 @@ namespace Mono.CSharp
                                        Environment.Exit (1);
                                }
 
-                               foreach (string d in value.Split (';', ',')){
+                               foreach (string d in value.Split (argument_value_separator)) {
                                        if (!Tokenizer.IsValidIdentifier (d)) {
                                                Report.Warning (2029, 1, "Invalid conditional define symbol `{0}'", d);
                                                continue;
@@ -1149,7 +1205,7 @@ namespace Mono.CSharp
                                //
                                Console.WriteLine ("To file bug reports, please visit: http://www.mono-project.com/Bugs");
                                return true;
-
+#if !SMCS_SOURCE
                        case "/pkg": {
                                string packages;
 
@@ -1158,41 +1214,17 @@ namespace Mono.CSharp
                                        Environment.Exit (1);
                                }
                                packages = String.Join (" ", value.Split (new Char [] { ';', ',', '\n', '\r'}));
+                               string pkgout = GetPackageFlags (packages, true);
                                
-                               ProcessStartInfo pi = new ProcessStartInfo ();
-                               pi.FileName = "pkg-config";
-                               pi.RedirectStandardOutput = true;
-                               pi.UseShellExecute = false;
-                               pi.Arguments = "--libs " + packages;
-                               Process p = null;
-                               try {
-                                       p = Process.Start (pi);
-                               } catch (Exception e) {
-                                       Report.Error (-27, "Couldn't run pkg-config: " + e.Message);
-                                       Environment.Exit (1);
-                               }
-
-                               if (p.StandardOutput == null){
-                                       Report.Warning (-27, 1, "Specified package did not return any information");
-                                       return true;
-                               }
-                               string pkgout = p.StandardOutput.ReadToEnd ();
-                               p.WaitForExit ();
-                               if (p.ExitCode != 0) {
-                                       Report.Error (-27, "Error running pkg-config. Check the above output.");
-                                       Environment.Exit (1);
-                               }
-
                                if (pkgout != null){
                                        string [] xargs = pkgout.Trim (new Char [] {' ', '\n', '\r', '\t'}).
                                                Split (new Char [] { ' ', '\t'});
                                        args = AddArgs (args, xargs);
                                }
                                
-                               p.Close ();
                                return true;
                        }
-                               
+#endif
                        case "/linkres":
                        case "/linkresource":
                        case "/res":
@@ -1200,27 +1232,27 @@ namespace Mono.CSharp
                                if (embedded_resources == null)
                                        embedded_resources = new Resources ();
 
-                               bool embeded = arg.StartsWith ("/r");
-                               string[] s = value.Split (',');
+                               bool embeded = arg [1] == 'r' || arg [1] == 'R';
+                               string[] s = value.Split (argument_value_separator);
                                switch (s.Length) {
-                                       case 1:
-                                               if (s[0].Length == 0)
-                                                       goto default;
-                                               embedded_resources.Add (embeded, s [0], Path.GetFileName (s[0]));
-                                               break;
-                                       case 2:
-                                               embedded_resources.Add (embeded, s [0], s [1]);
-                                               break;
-                                       case 3:
-                                               if (s [2] != "public" && s [2] != "private") {
-                                                       Report.Error (1906, "Invalid resource visibility option `{0}'. Use either `public' or `private' instead", s [2]);
-                                                       return true;
-                                               }
-                                               embedded_resources.Add (embeded, s [0], s [1], s [2] == "private");
-                                               break;
-                                       default:
-                                               Report.Error (-2005, "Wrong number of arguments for option `{0}'", option);
-                                               break;
+                               case 1:
+                                       if (s[0].Length == 0)
+                                               goto default;
+                                       embedded_resources.Add (embeded, s [0], Path.GetFileName (s[0]));
+                                       break;
+                               case 2:
+                                       embedded_resources.Add (embeded, s [0], s [1]);
+                                       break;
+                               case 3:
+                                       if (s [2] != "public" && s [2] != "private") {
+                                               Report.Error (1906, "Invalid resource visibility option `{0}'. Use either `public' or `private' instead", s [2]);
+                                               return true;
+                                       }
+                                       embedded_resources.Add (embeded, s [0], s [1], s [2] == "private");
+                                       break;
+                               default:
+                                       Report.Error (-2005, "Wrong number of arguments for option `{0}'", option);
+                                       break;
                                }
 
                                return true;
@@ -1240,7 +1272,7 @@ namespace Mono.CSharp
                                        Environment.Exit (1);
                                }
 
-                               string [] refs = value.Split (new char [] { ';', ',' });
+                               string[] refs = value.Split (argument_value_separator);
                                foreach (string r in refs){
                                        string val = r;
                                        int index = val.IndexOf ('=');
@@ -1250,8 +1282,9 @@ namespace Mono.CSharp
                                                AddExternAlias (alias, assembly);
                                                return true;
                                        }
-                                       
-                                       references.Add (val);
+
+                                       if (val.Length != 0)
+                                               references.Add (val);
                                }
                                return true;
                        }
@@ -1261,7 +1294,7 @@ namespace Mono.CSharp
                                        Environment.Exit (1);
                                }
 
-                               string [] refs = value.Split (new char [] { ';', ',' });
+                               string[] refs = value.Split (argument_value_separator);
                                foreach (string r in refs){
                                        modules.Add (r);
                                }
@@ -1272,6 +1305,9 @@ namespace Mono.CSharp
                                        Report.Error (5, arg + " requires an argument");
                                        Environment.Exit (1);
                                }
+                               
+                               if (win32IconFile != null)
+                                       Report.Error (1565, "Cannot specify the `win32res' and the `win32ico' compiler option at the same time");
 
                                win32ResourceFile = value;
                                return true;
@@ -1282,6 +1318,9 @@ namespace Mono.CSharp
                                        Environment.Exit (1);
                                }
 
+                               if (win32ResourceFile != null)
+                                       Report.Error (1565, "Cannot specify the `win32res' and the `win32ico' compiler option at the same time");
+
                                win32IconFile = value;
                                return true;
                        }
@@ -1301,7 +1340,7 @@ namespace Mono.CSharp
                                        Environment.Exit (1);
                                }
 
-                               libdirs = value.Split (new Char [] { ',' });
+                               libdirs = value.Split (argument_value_separator);
                                foreach (string dir in libdirs)
                                        link_paths.Add (dir);
                                return true;
@@ -1312,6 +1351,11 @@ namespace Mono.CSharp
                                return true;
                                
                        case "/debug":
+                               if (value == "full" || value == "")
+                                       want_debugging_support = true;
+
+                               return true;
+                               
                        case "/debug+":
                                want_debugging_support = true;
                                return true;
@@ -1344,11 +1388,21 @@ namespace Mono.CSharp
 
                        case "/warnaserror":
                        case "/warnaserror+":
-                               Report.WarningsAreErrors = true;
+                               if (value.Length == 0) {
+                                       Report.WarningsAreErrors = true;
+                               } else {
+                                       foreach (string wid in value.Split (argument_value_separator))
+                                               Report.AddWarningAsError (wid);
+                               }
                                return true;
 
                        case "/warnaserror-":
-                               Report.WarningsAreErrors = false;
+                               if (value.Length == 0) {
+                                       Report.WarningsAreErrors = false;
+                               } else {
+                                       foreach (string wid in value.Split (argument_value_separator))
+                                               Report.RemoveWarningAsError (wid);
+                               }
                                return true;
 
                        case "/warn":
@@ -1362,10 +1416,13 @@ namespace Mono.CSharp
                                        Report.Error (5, "/nowarn requires an argument");
                                        Environment.Exit (1);
                                }
-                               
-                               warns = value.Split (new Char [] {','});
+
+                               warns = value.Split (argument_value_separator);
                                foreach (string wc in warns){
                                        try {
+                                               if (wc.Trim ().Length == 0)
+                                                       continue;
+
                                                int warn = Int32.Parse (wc);
                                                if (warn < 1) {
                                                        throw new ArgumentOutOfRangeException("warn");
@@ -1378,15 +1435,37 @@ namespace Mono.CSharp
                                return true;
                        }
 
-                       case "/noconfig-":
-                               load_default_config = true;
-                               return true;
-                               
                        case "/noconfig":
-                       case "/noconfig+":
                                load_default_config = false;
                                return true;
 
+                       case "/platform":
+#if GMCS_SOURCE
+                               switch (value.ToLower (CultureInfo.InvariantCulture)) {
+                               case "anycpu":
+                                       RootContext.Platform = Platform.AnyCPU;
+                                       break;
+                               case "x86":
+                                       RootContext.Platform = Platform.X86;
+                                       break;
+                               case "x64":
+                                       RootContext.Platform = Platform.X64;
+                                       break;
+                               case "itanium":
+                                       RootContext.Platform = Platform.IA64;
+                                       break;
+                               default:
+                                       Report.Error (1672, "Invalid platform type for -platform. Valid options are `anycpu', `x86', `x64' or `itanium'");
+                                       break;
+                               }
+#endif
+                               return true;
+
+                               // We just ignore this.
+                       case "/errorreport":
+                       case "/filealign":
+                               return true;
+                               
                        case "/help2":
                                OtherFlags ();
                                Environment.Exit(0);
@@ -1452,17 +1531,18 @@ namespace Mono.CSharp
                                        RootContext.AddConditional ("__V2__");
 #endif
                                        return true;
-#if GMCS_SOURCE
                                case "iso-2":
                                        RootContext.Version = LanguageVersion.ISO_2;
                                        return true;
-                                       
-                               case "linq":
-                                       Report.Warning (-30, 1, "Deprecated: The `linq' option is no longer required and should not be used");
+                               case "3":
+                                       RootContext.Version = LanguageVersion.V_3;
+                                       return true;
+                               case "future":
+                                       RootContext.Version = LanguageVersion.Future;
                                        return true;
-#endif
                                }
-                               Report.Error (1617, "Invalid option `{0}' for /langversion. It must be either `ISO-1', `ISO-2' or `Default'", value);
+
+                               Report.Error (1617, "Invalid -langversion option `{0}'. It must be `ISO-1', `ISO-2', `3' or `Default'", value);
                                return true;
 
                        case "/codepage":
@@ -1517,7 +1597,7 @@ namespace Mono.CSharp
                        return new_args;
                }
 
-               static void AddExternAlias (string identifier, string assembly)
+               void AddExternAlias (string identifier, string assembly)
                {
                        if (assembly.Length == 0) {
                                Report.Error (1680, "Invalid reference alias '" + identifier + "='. Missing filename");
@@ -1554,12 +1634,15 @@ namespace Mono.CSharp
                        
                        return true;
                }
-               
+
                //
                // Main compilation method
                //
                public bool Compile ()
                {
+                       // TODO: Should be passed to parser as an argument
+                       RootContext.ToplevelTypes = new ModuleContainer (RootContext.Unsafe);
+
                        Parse ();
                        if (Report.Errors > 0)
                                return false;
@@ -1570,28 +1653,7 @@ namespace Mono.CSharp
                        if (RootContext.ToplevelTypes.NamespaceEntry != null)
                                throw new InternalErrorException ("who set it?");
 
-                       if (load_default_config)
-                               DefineDefaultConfig ();
-
-                       if (Report.Errors > 0){
-                               return false;
-                       }
-
-                       //
-                       // Load assemblies required
-                       //
-                       if (timestamps)
-                               ShowTime ("Loading references");
-                       link_paths.Add (GetSystemDir ());
-                       link_paths.Add (Directory.GetCurrentDirectory ());
-                       LoadReferences ();
-                       
-                       if (timestamps)
-                               ShowTime ("   References loaded");
-                       
-                       if (Report.Errors > 0){
-                               return false;
-                       }
+                       ProcessDefaultConfig ();
 
                        //
                        // Quick hack
@@ -1624,14 +1686,25 @@ namespace Mono.CSharp
                                set_method.Invoke (CodeGen.Assembly.Builder, BindingFlags.Default, null, new object[]{true}, null);
                        }
 
-                       RootNamespace.Global.AddModuleReference (CodeGen.Module.Builder);
+                       GlobalRootNamespace.Instance.AddModuleReference (RootContext.ToplevelTypes.Builder);
 
+                       //
+                       // Load assemblies required
+                       //
+                       if (timestamps)
+                               ShowTime ("Loading references");
+
+                       LoadReferences ();
+                       
                        if (modules.Count > 0) {
                                foreach (string module in modules)
                                        LoadModule (module);
                        }
                        
-                       if (!TypeManager.InitCoreTypes ())
+                       if (timestamps)
+                               ShowTime ("References loaded");
+                       
+                       if (!TypeManager.InitCoreTypes () || Report.Errors > 0)
                                return false;
 
                        TypeManager.InitOptionalCoreTypes ();
@@ -1639,8 +1712,6 @@ namespace Mono.CSharp
                        if (timestamps)
                                ShowTime ("   Core Types done");
 
-                       CodeGen.Module.Resolve ();
-
                        //
                        // The second pass of the compiler
                        //
@@ -1656,8 +1727,6 @@ namespace Mono.CSharp
                                RootContext.BootCorlib_PopulateCoreTypes ();
                        RootContext.PopulateTypes ();
 
-                       RootContext.DefineTypes ();
-                       
                        if (Report.Errors == 0 &&
                                RootContext.Documentation != null &&
                                !RootContext.Documentation.OutputDocComment (
@@ -1716,7 +1785,7 @@ namespace Mono.CSharp
                        }
 
                        if (RootContext.NeedsEntryPoint) {
-                               MethodInfo ep = RootContext.EntryPoint;
+                               Method ep = RootContext.EntryPoint;
 
                                if (ep == null) {
                                        if (RootContext.MainClass != null) {
@@ -1741,7 +1810,7 @@ namespace Mono.CSharp
                                        return false;
                                }
 
-                               CodeGen.Assembly.Builder.SetEntryPoint (ep, k);
+                               CodeGen.Assembly.Builder.SetEntryPoint (ep.MethodBuilder, k);
                        } else if (RootContext.MainClass != null) {
                                Report.Error (2017, "Cannot specify -main if building a module or library");
                        }
@@ -1763,18 +1832,19 @@ namespace Mono.CSharp
                                try {
                                        CodeGen.Assembly.Builder.DefineUnmanagedResource (win32ResourceFile);
                                } catch (ArgumentException) {
-                                       Report.RuntimeMissingSupport (Location.Null, "resource embeding");
+                                       Report.RuntimeMissingSupport (Location.Null, "resource embedding ");
                                }
                        } else {
                                CodeGen.Assembly.Builder.DefineVersionInfoResource ();
                        }
 
                        if (win32IconFile != null) {
-                               MethodInfo define_icon = typeof (AssemblyBuilder).GetMethod ("DefineIconResource", BindingFlags.Instance|BindingFlags.Public|BindingFlags.NonPublic);
+                               MethodInfo define_icon = typeof (AssemblyBuilder).GetMethod ("DefineIconResource", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                                if (define_icon == null) {
-                                       Report.RuntimeMissingSupport (Location.Null, "resource embeding");
+                                       Report.RuntimeMissingSupport (Location.Null, "resource embedding");
+                               } else {
+                                       define_icon.Invoke (CodeGen.Assembly.Builder, new object [] { win32IconFile });
                                }
-                               define_icon.Invoke (CodeGen.Assembly.Builder, new object [] { win32IconFile });
                        }
 
                        if (Report.Errors > 0)
@@ -1928,7 +1998,7 @@ namespace Mono.CSharp
                {
                        Report.Stderr = error;
                        try {
-                               Driver d = Driver.Create (args);
+                               Driver d = Driver.Create (args, true);
                                if (d == null)
                                        return false;
 
@@ -1945,17 +2015,30 @@ namespace Mono.CSharp
                                return Report.AllWarnings;
                        }
                }
+
+               public static void Reset ()
+               {
+                       Reset (true);
+               }
+
+               public static void PartialReset ()
+               {
+                       Reset (false);
+               }
                
-               static void Reset ()
+               public static void Reset (bool full_flag)
                {
                        Driver.Reset ();
-                       RootContext.Reset ();
-                       Tokenizer.Reset ();
+                       RootContext.Reset (full_flag);
                        Location.Reset ();
                        Report.Reset ();
                        TypeManager.Reset ();
+                       PredefinedAttributes.Reset ();
                        TypeHandle.Reset ();
-                       RootNamespace.Reset ();
+
+                       if (full_flag)
+                               GlobalRootNamespace.Reset ();
+                       
                        NamespaceEntry.Reset ();
                        CodeGen.Reset ();
                        Attribute.Reset ();
@@ -1963,6 +2046,12 @@ namespace Mono.CSharp
                        AnonymousTypeClass.Reset ();
                        AnonymousMethodBody.Reset ();
                        AnonymousMethodStorey.Reset ();
+                       SymbolWriter.Reset ();
+                       Switch.Reset ();
+                       Linq.QueryBlock.TransparentParameter.Reset ();
+                       Convert.Reset ();
+                       TypeInfo.Reset ();
                }
+
        }
 }