2009-12-10 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / mcs / driver.cs
index 1ca55ca11485632d1e8d26fb21e70e69e3248413..3674bd6ce81292db2306a2181b2610e1ec388f98 100644 (file)
@@ -16,8 +16,7 @@ namespace Mono.CSharp
        using System;
        using System.Reflection;
        using System.Reflection.Emit;
-       using System.Collections;
-       using System.Collections.Specialized;
+       using System.Collections.Generic;
        using System.IO;
        using System.Text;
        using System.Globalization;
@@ -39,27 +38,27 @@ namespace Mono.CSharp
                //
                // Assemblies references to be linked.   Initialized with
                // mscorlib.dll here.
-               ArrayList references;
+               List<string> 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.
                //
-               ArrayList soft_references;
+               List<string> soft_references;
 
                // 
                // External aliases for assemblies.
                //
-               Hashtable external_aliases;
+               Dictionary<string, string> external_aliases;
 
                //
                // Modules to be linked
                //
-               ArrayList modules;
+               List<string> modules;
 
                // Lookup paths
-               static ArrayList link_paths;
+               List<string> link_paths;
 
                // Whether we want to only run the tokenizer
                bool tokenize;
@@ -69,6 +68,7 @@ namespace Mono.CSharp
                bool want_debugging_support;
                bool parse_only;
                bool timestamps;
+               bool fatal_errors;
                
                //
                // Whether to load the initial config file (what CSC.RSP has by default)
@@ -203,6 +203,7 @@ namespace Mono.CSharp
 
                        reader.Position = 0;
                        Parse (reader, file);
+                       reader.Dispose ();
                        input.Close ();
                }       
                
@@ -298,11 +299,13 @@ namespace Mono.CSharp
                public static int Main (string[] args)
                {
                        Location.InEmacs = Environment.GetEnvironmentVariable ("EMACS") == "t";
-
-                       Driver d = Driver.Create (args, true, new ConsoleReportPrinter ());
+                       var crp = new ConsoleReportPrinter ();
+                       Driver d = Driver.Create (args, true, crp);
                        if (d == null)
                                return 1;
 
+                       crp.Fatal = d.fatal_errors;
+
                        if (d.Compile () && d.Report.Errors == 0) {
                                if (d.Report.Warnings > 0) {
                                        Console.WriteLine ("Compilation succeeded - {0} warning(s)", d.Report.Warnings);
@@ -482,8 +485,8 @@ namespace Mono.CSharp
                        foreach (string r in references)
                                LoadAssembly (r, false);
 
-                       foreach (DictionaryEntry entry in external_aliases)
-                               LoadAssembly ((string) entry.Value, (string) entry.Key, false);
+                       foreach (var entry in external_aliases)
+                               LoadAssembly (entry.Value, entry.Key, false);
                                
                        GlobalRootNamespace.Instance.ComputeNamespaces (ctx);
                }
@@ -491,7 +494,7 @@ namespace Mono.CSharp
                static string [] LoadArgs (string file)
                {
                        StreamReader f;
-                       ArrayList args = new ArrayList ();
+                       var args = new List<string> ();
                        string line;
                        try {
                                f = new StreamReader (file);
@@ -531,10 +534,7 @@ namespace Mono.CSharp
                                }
                        }
 
-                       string [] ret_value = new string [args.Count];
-                       args.CopyTo (ret_value, 0);
-
-                       return ret_value;
+                       return args.ToArray ();
                }
 
                //
@@ -587,13 +587,13 @@ namespace Mono.CSharp
 
                bool ParseArguments (string[] args, bool require_files)
                {
-                       references = new ArrayList ();
-                       external_aliases = new Hashtable ();
-                       soft_references = new ArrayList ();
-                       modules = new ArrayList (2);
-                       link_paths = new ArrayList ();
+                       references = new List<string> ();
+                       external_aliases = new Dictionary<string, string> ();
+                       soft_references = new List<string> ();
+                       modules = new List<string> (2);
+                       link_paths = new List<string> ();
 
-                       ArrayList response_file_list = null;
+                       List<string> response_file_list = null;
                        bool parsing_options = true;
 
                        for (int i = 0; i < args.Length; i++) {
@@ -606,7 +606,7 @@ namespace Mono.CSharp
                                        string response_file = arg.Substring (1);
 
                                        if (response_file_list == null)
-                                               response_file_list = new ArrayList ();
+                                               response_file_list = new List<string> ();
 
                                        if (response_file_list.Contains (response_file)) {
                                                Report.Error (
@@ -690,12 +690,12 @@ namespace Mono.CSharp
                {
                        Location.Initialize ();
 
-                       ArrayList cu = Location.SourceFiles;
+                       var cu = Location.SourceFiles;
                        for (int i = 0; i < cu.Count; ++i) {
                                if (tokenize) {
-                                       tokenize_file ((CompilationUnit) cu [i], ctx);
+                                       tokenize_file (cu [i], ctx);
                                } else {
-                                       Parse ((CompilationUnit) cu [i]);
+                                       Parse (cu [i]);
                                }
                        }
                }
@@ -990,7 +990,7 @@ namespace Mono.CSharp
                                return true;
                                
                        case "--fatal":
-                               Report.Fatal = true;
+                               fatal_errors = true;
                                return true;
                                
                        case "--nowarn":
@@ -1441,7 +1441,6 @@ namespace Mono.CSharp
                                return true;
 
                        case "/platform":
-#if GMCS_SOURCE
                                switch (value.ToLower (CultureInfo.InvariantCulture)) {
                                case "anycpu":
                                        RootContext.Platform = Platform.AnyCPU;
@@ -1459,7 +1458,7 @@ namespace Mono.CSharp
                                        Report.Error (1672, "Invalid platform type for -platform. Valid options are `anycpu', `x86', `x64' or `itanium'");
                                        break;
                                }
-#endif
+
                                return true;
 
                                // We just ignore this.
@@ -1524,13 +1523,10 @@ namespace Mono.CSharp
                                switch (value.ToLower (CultureInfo.InvariantCulture)) {
                                case "iso-1":
                                        RootContext.Version = LanguageVersion.ISO_1;
-                                       return true;
-                                       
+                                       return true;    
                                case "default":
                                        RootContext.Version = LanguageVersion.Default;
-#if GMCS_SOURCE                                        
                                        RootContext.AddConditional ("__V2__");
-#endif
                                        return true;
                                case "iso-2":
                                        RootContext.Version = LanguageVersion.ISO_2;
@@ -1642,7 +1638,7 @@ namespace Mono.CSharp
                public bool Compile ()
                {
                        // TODO: Should be passed to parser as an argument
-                       RootContext.ToplevelTypes = new ModuleContainer (ctx, RootContext.Unsafe);
+                       RootContext.ToplevelTypes = new ModuleCompiled (ctx, RootContext.Unsafe);
 
                        Parse ();
                        if (Report.Errors > 0)
@@ -1871,28 +1867,13 @@ namespace Mono.CSharp
        {
                interface IResource
                {
-                       void Emit ();
+                       void Emit (CompilerContext cc);
                        string FileName { get; }
                }
 
                class EmbededResource : IResource
                {
                        static MethodInfo embed_res;
-
-                       static EmbededResource () {
-                               Type[] argst = new Type [] { 
-                                                                                          typeof (string), typeof (string), typeof (ResourceAttributes)
-                                                                                  };
-
-                               embed_res = typeof (AssemblyBuilder).GetMethod (
-                                       "EmbedResourceFile", BindingFlags.Instance|BindingFlags.Public|BindingFlags.NonPublic,
-                                       null, CallingConventions.Any, argst, null);
-                               
-                               if (embed_res == null) {
-                                       RootContext.ToplevelTypes.Compiler.Report.RuntimeMissingSupport (Location.Null, "Resource embedding");
-                               }
-                       }
-
                        readonly object[] args;
 
                        public EmbededResource (string name, string file, bool isPrivate)
@@ -1903,8 +1884,22 @@ namespace Mono.CSharp
                                args [2] = isPrivate ? ResourceAttributes.Private : ResourceAttributes.Public;
                        }
 
-                       public void Emit()
+                       public void Emit (CompilerContext cc)
                        {
+                               if (embed_res == null) {
+                                       var argst = new [] {
+                                               typeof (string), typeof (string), typeof (ResourceAttributes)
+                                       };
+
+                                       embed_res = typeof (AssemblyBuilder).GetMethod (
+                                               "EmbedResourceFile", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
+                                               null, CallingConventions.Any, argst, null);
+
+                                       if (embed_res == null) {
+                                               cc.Report.RuntimeMissingSupport (Location.Null, "Resource embedding");
+                                       }
+                               }
+
                                embed_res.Invoke (CodeGen.Assembly.Builder, args);
                        }
 
@@ -1928,7 +1923,7 @@ namespace Mono.CSharp
                                this.attribute = isPrivate ? ResourceAttributes.Private : ResourceAttributes.Public;
                        }
 
-                       public void Emit ()
+                       public void Emit (CompilerContext cc)
                        {
                                CodeGen.Assembly.Builder.AddResourceFile (name, Path.GetFileName(file), attribute);
                        }
@@ -1941,7 +1936,7 @@ namespace Mono.CSharp
                }
 
 
-               IDictionary embedded_resources = new HybridDictionary ();
+               Dictionary<string, IResource> embedded_resources = new Dictionary<string, IResource> ();
                readonly CompilerContext ctx;
 
                public Resources (CompilerContext ctx)
@@ -1956,7 +1951,7 @@ namespace Mono.CSharp
 
                public void Add (bool embeded, string file, string name, bool isPrivate)
                {
-                       if (embedded_resources.Contains (name)) {
+                       if (embedded_resources.ContainsKey (name)) {
                                ctx.Report.Error (1508, "The resource identifier `{0}' has already been used in this assembly", name);
                                return;
                        }
@@ -1975,7 +1970,7 @@ namespace Mono.CSharp
                                        continue;
                                }
                                
-                               r.Emit ();
+                               r.Emit (ctx);
                        }
                }
        }