[csharp] repl using statement fix + support for --fatal
[mono.git] / mcs / mcs / driver.cs
index 8a63e7ff2078f457389475eabd57834c65f0d77e..92eb72e87d42e5859a46f0cadbaf29d331c9d4a7 100644 (file)
@@ -167,8 +167,8 @@ namespace Mono.CSharp
                                "   --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" +
+                               "   -codepage:ID         Sets code page to the one in ID (number, utf8, reset)\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" +
@@ -184,14 +184,14 @@ namespace Mono.CSharp
                                "   -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" +                         
+                               "   -reference:ALIAS=A   Imports metadata using specified extern alias (short: -r)\n" +
+                               "   -sdk:VERSION         Specifies SDK version of referenced assemlies\n" +
+                               "                        VERSION can be one of: 2 (default), 4\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" +
@@ -782,7 +782,6 @@ namespace Mono.CSharp
                        return false;
                }
 
-#if !SMCS_SOURCE
                public static string GetPackageFlags (string packages, bool fatal, Report report)
                {
                        ProcessStartInfo pi = new ProcessStartInfo ();
@@ -819,7 +818,6 @@ namespace Mono.CSharp
 
                        return pkgout;
                }
-#endif
 
                //
                // This parses the -arg and /arg options to the compiler, even if the strings
@@ -921,7 +919,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;
 
@@ -940,7 +938,7 @@ namespace Mono.CSharp
                                
                                return true;
                        }
-#endif
+
                        case "/linkres":
                        case "/linkresource":
                        case "/res":
@@ -1193,6 +1191,26 @@ namespace Mono.CSharp
 
                                return true;
 
+                       case "/sdk":
+                               if (value.Length == 0) {
+                                       Error_RequiresArgument (option);
+                                       break;
+                               }
+
+                               switch (value.ToLowerInvariant ()) {
+                                       case "2":
+                                               RootContext.SdkVersion = SdkVersion.v2;
+                                               break;
+                                       case "4":
+                                               RootContext.SdkVersion = SdkVersion.v4;
+                                               break;
+                                       default:
+                                               Report.Error (-26, "Invalid sdk version name");
+                                               break;
+                               }
+
+                               return true;
+
                                // We just ignore this.
                        case "/errorreport":
                        case "/filealign":
@@ -1470,15 +1488,21 @@ namespace Mono.CSharp
                                stopwatch = Stopwatch.StartNew ();
 
 #if STATIC
-                       var assembly = new AssemblyDefinitionStatic (module, output_file_name, output_file);
-                       module.SetDeclaringAssembly (assembly);
-
                        var importer = new StaticImporter ();
-                       assembly.Importer = importer;
+                       var references_loader = new StaticLoader (importer, ctx);
 
-                       var loader = new StaticLoader (importer, ctx);
-                       loader.LoadReferences (module);
+                       var assembly = new AssemblyDefinitionStatic (module, references_loader, output_file_name, output_file);
+                       assembly.Create (references_loader.Domain);
 
+                       // Create compiler types first even before any referenced
+                       // assembly is loaded to allow forward referenced types from
+                       // loaded assembly into compiled builder to be resolved
+                       // correctly
+                       module.CreateType ();
+                       ShowTime ("Creating compiled types");
+
+                       importer.AddCompiledAssembly (assembly);
+                       references_loader.LoadReferences (module);
                        ShowTime ("Imporing referenced assemblies");
 
                        if (!ctx.BuildinTypes.CheckDefinitions (module))
@@ -1486,14 +1510,7 @@ namespace Mono.CSharp
 
                        ShowTime ("Initializing predefined types");
 
-                       if (!assembly.Create (loader))
-                               return false;
-
-                       // System.Object was not loaded, use compiled assembly as corlib
-                       if (loader.Corlib == null)
-                               loader.Corlib = assembly.Builder;
-
-                       loader.LoadModules (assembly, module.GlobalRootNamespace);
+                       references_loader.LoadModules (assembly, module.GlobalRootNamespace);
 #else
                        var assembly = new AssemblyDefinitionDynamic (module, output_file_name, output_file);
                        module.SetDeclaringAssembly (assembly);
@@ -1576,7 +1593,7 @@ namespace Mono.CSharp
                        assembly.Save ();
 
 #if STATIC
-                       loader.Dispose ();
+                       references_loader.Dispose ();
 #endif
 
                        ShowTime ("Saving output assembly");