2009-12-10 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / mcs / driver.cs
index b1ba132a97c3559219bba0f343bae57b8fc3935a..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;
@@ -26,6 +25,10 @@ namespace Mono.CSharp
        public enum Target {
                Library, Exe, Module, WinExe
        };
+
+       public enum Platform {
+               AnyCPU, X86, X64, IA64
+       }
        
        /// <summary>
        ///    The compiler driver.
@@ -35,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;
@@ -65,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)
@@ -93,6 +97,8 @@ namespace Mono.CSharp
                //
                Encoding encoding;
 
+               readonly CompilerContext ctx;
+
                static readonly char[] argument_value_separator = new char [] { ';', ',' };
 
                static public void Reset ()
@@ -100,20 +106,26 @@ namespace Mono.CSharp
                        output_file = null;
                }
 
-               public Driver ()
+               private Driver (CompilerContext ctx)
                {
+                       this.ctx = ctx;
                        encoding = Encoding.Default;
                }
 
-               public static Driver Create (string [] args, bool require_files)
+               public static Driver Create (string[] args, bool require_files, ReportPrinter printer)
                {
-                       Driver d = new Driver ();
+                       Driver d = new Driver (new CompilerContext (new Report (printer)));
+
                        if (!d.ParseArguments (args, require_files))
                                return null;
 
                        return d;
                }
 
+               Report Report {
+                       get { return ctx.Report; }
+               }
+
                void ShowTime (string msg)
                {
                        if (!timestamps)
@@ -142,7 +154,7 @@ namespace Mono.CSharp
                                (int) span.TotalSeconds, span.Milliseconds, msg);
                }              
               
-               void tokenize_file (CompilationUnit file)
+               void tokenize_file (CompilationUnit file, CompilerContext ctx)
                {
                        Stream input;
 
@@ -155,7 +167,7 @@ namespace Mono.CSharp
 
                        using (input){
                                SeekableStreamReader reader = new SeekableStreamReader (input, encoding);
-                               Tokenizer lexer = new Tokenizer (reader, file);
+                               Tokenizer lexer = new Tokenizer (reader, file, ctx);
                                int token, tokens = 0, errors = 0;
 
                                while ((token = lexer.token ()) != Token.EOF){
@@ -191,19 +203,14 @@ namespace Mono.CSharp
 
                        reader.Position = 0;
                        Parse (reader, file);
+                       reader.Dispose ();
                        input.Close ();
                }       
                
                void Parse (SeekableStreamReader reader, CompilationUnit file)
                {
-                       CSharpParser parser = new CSharpParser (reader, file);
-                       parser.ErrorOutput = Report.Stderr;
-                       try {
-                               parser.parse ();
-                       } catch (Exception ex) {
-                               Report.Error(589, parser.Lexer.Location,
-                                       "Compilation aborted in file `{0}', {1}", file.Name, ex);
-                       }
+                       CSharpParser parser = new CSharpParser (reader, file, ctx);
+                       parser.parse ();
                }
 
                static void OtherFlags ()
@@ -248,6 +255,8 @@ namespace Mono.CSharp
 #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" +                         
@@ -268,7 +277,7 @@ namespace Mono.CSharp
                                "Options can be of the form -option or /option");
                }
 
-               static void TargetUsage ()
+               void TargetUsage ()
                {
                        Report.Error (2019, "Invalid target type for -target. Valid options are `exe', `winexe', `library' or `module'");
                }
@@ -289,17 +298,17 @@ namespace Mono.CSharp
 
                public static int Main (string[] args)
                {
-                       RootContext.Version = LanguageVersion.Default;
-
                        Location.InEmacs = Environment.GetEnvironmentVariable ("EMACS") == "t";
-
-                       Driver d = Driver.Create (args, true);
+                       var crp = new ConsoleReportPrinter ();
+                       Driver d = Driver.Create (args, true, crp);
                        if (d == null)
                                return 1;
 
-                       if (d.Compile () && Report.Errors == 0) {
-                               if (Report.Warnings > 0) {
-                                       Console.WriteLine ("Compilation succeeded - {0} warning(s)", Report.Warnings);
+                       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);
                                }
                                Environment.Exit (0);
                                return 0;
@@ -307,31 +316,31 @@ namespace Mono.CSharp
                        
                        
                        Console.WriteLine("Compilation failed: {0} error(s), {1} warnings",
-                               Report.Errors, Report.Warnings);
+                               d.Report.Errors, d.Report.Warnings);
                        Environment.Exit (1);
                        return 1;
                }
 
-               static public void LoadAssembly (string assembly, bool soft)
+               public void LoadAssembly (string assembly, bool soft)
                {
                        LoadAssembly (assembly, null, soft);
                }
 
-               static void Error6 (string name, string log)
+               void Error6 (string name, string log)
                {
                        if (log != null && log.Length > 0)
                                Report.ExtraInformation (Location.Null, "Log:\n" + log + "\n(log related to previous ");
                        Report.Error (6, "cannot find metadata file `{0}'", name);
                }
 
-               static void Error9 (string type, string filename, string log)
+               void Error9 (string type, string filename, string log)
                {
                        if (log != null && log.Length > 0)
                                Report.ExtraInformation (Location.Null, "Log:\n" + log + "\n(log related to previous ");
                        Report.Error (9, "file `{0}' has invalid `{1}' metadata", filename, type);
                }
 
-               static void BadAssembly (string filename, string log)
+               void BadAssembly (string filename, string log)
                {
                        MethodInfo adder_method = AssemblyClass.AddModule_Method;
 
@@ -363,7 +372,7 @@ namespace Mono.CSharp
                        Error9 ("assembly", filename, log);
                }
 
-               static public void LoadAssembly (string assembly, string alias, bool soft)
+               public void LoadAssembly (string assembly, string alias, bool soft)
                {
                        Assembly a = null;
                        string total_log = "";
@@ -407,7 +416,7 @@ namespace Mono.CSharp
                                if (alias == null)
                                        GlobalRootNamespace.Instance.AddAssemblyReference (a);
                                else
-                                       GlobalRootNamespace.Instance.DefineRootNamespace (alias, a);
+                                       GlobalRootNamespace.Instance.DefineRootNamespace (alias, a, ctx);
 
                        } catch (BadImageFormatException f) {
                                // .NET 2.0 throws this if we try to load a module without an assembly manifest ...
@@ -418,7 +427,7 @@ namespace Mono.CSharp
                        }
                }
 
-               static public void LoadModule (string module)
+               public void LoadModule (string module)
                {
                        Module m = null;
                        string total_log = "";
@@ -476,16 +485,16 @@ 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 ();
+                       GlobalRootNamespace.Instance.ComputeNamespaces (ctx);
                }
 
                static string [] LoadArgs (string file)
                {
                        StreamReader f;
-                       ArrayList args = new ArrayList ();
+                       var args = new List<string> ();
                        string line;
                        try {
                                f = new StreamReader (file);
@@ -525,10 +534,7 @@ namespace Mono.CSharp
                                }
                        }
 
-                       string [] ret_value = new string [args.Count];
-                       args.CopyTo (ret_value, 0);
-
-                       return ret_value;
+                       return args.ToArray ();
                }
 
                //
@@ -576,18 +582,18 @@ namespace Mono.CSharp
                        if (first_source == null)
                                first_source = f;
 
-                       Location.AddFile (f);
+                       Location.AddFile (Report, f);
                }
 
                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++) {
@@ -600,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 (
@@ -684,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]);
+                                       tokenize_file (cu [i], ctx);
                                } else {
-                                       Parse ((CompilationUnit) cu [i]);
+                                       Parse (cu [i]);
                                }
                        }
                }
@@ -782,6 +788,8 @@ namespace Mono.CSharp
 
                        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
@@ -794,7 +802,7 @@ namespace Mono.CSharp
                        }
                }
 
-               static void SetWarningLevel (string s)
+               void SetWarningLevel (string s)
                {
                        int level = -1;
 
@@ -885,7 +893,7 @@ namespace Mono.CSharp
                                return true;
                                
                        case "--stacktrace":
-                               Report.Stacktrace = true;
+                               Report.Printer.Stacktrace = true;
                                return true;
                                
                        case "--linkresource":
@@ -897,7 +905,7 @@ namespace Mono.CSharp
                                        Environment.Exit (1);
                                }
                                if (embedded_resources == null)
-                                       embedded_resources = new Resources ();
+                                       embedded_resources = new Resources (ctx);
                                
                                embedded_resources.Add (false, args [++i], args [i]);
                                return true;
@@ -911,7 +919,7 @@ namespace Mono.CSharp
                                        Environment.Exit (1);
                                }
                                if (embedded_resources == null)
-                                       embedded_resources = new Resources ();
+                                       embedded_resources = new Resources (ctx);
                                
                                embedded_resources.Add (true, args [++i], args [i]);
                                return true;
@@ -982,7 +990,7 @@ namespace Mono.CSharp
                                return true;
                                
                        case "--fatal":
-                               Report.Fatal = true;
+                               fatal_errors = true;
                                return true;
                                
                        case "--nowarn":
@@ -1061,7 +1069,7 @@ namespace Mono.CSharp
                }
 
 #if !SMCS_SOURCE
-               public static string GetPackageFlags (string packages, bool fatal)
+               public static string GetPackageFlags (string packages, bool fatal, Report report)
                {
                        ProcessStartInfo pi = new ProcessStartInfo ();
                        pi.FileName = "pkg-config";
@@ -1072,7 +1080,7 @@ namespace Mono.CSharp
                        try {
                                p = Process.Start (pi);
                        } catch (Exception e) {
-                               Report.Error (-27, "Couldn't run pkg-config: " + e.Message);
+                               report.Error (-27, "Couldn't run pkg-config: " + e.Message);
                                if (fatal)
                                        Environment.Exit (1);
                                p.Close ();
@@ -1080,14 +1088,14 @@ namespace Mono.CSharp
                        }
                        
                        if (p.StandardOutput == null){
-                               Report.Warning (-27, 1, "Specified package did not return any information");
+                               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.");
+                               report.Error (-27, "Error running pkg-config. Check the above output.");
                                if (fatal)
                                        Environment.Exit (1);
                                p.Close ();
@@ -1182,11 +1190,12 @@ namespace Mono.CSharp
                                }
 
                                foreach (string d in value.Split (argument_value_separator)) {
-                                       if (!Tokenizer.IsValidIdentifier (d)) {
-                                               Report.Warning (2029, 1, "Invalid conditional define symbol `{0}'", d);
+                                       string conditional = d.Trim ();
+                                       if (!Tokenizer.IsValidIdentifier (conditional)) {
+                                               Report.Warning (2029, 1, "Invalid conditional define symbol `{0}'", conditional);
                                                continue;
                                        }
-                                       RootContext.AddConditional (d);
+                                       RootContext.AddConditional (conditional);
                                }
                                return true;
                        }
@@ -1206,7 +1215,7 @@ namespace Mono.CSharp
                                        Environment.Exit (1);
                                }
                                packages = String.Join (" ", value.Split (new Char [] { ';', ',', '\n', '\r'}));
-                               string pkgout = GetPackageFlags (packages, true);
+                               string pkgout = GetPackageFlags (packages, true, Report);
                                
                                if (pkgout != null){
                                        string [] xargs = pkgout.Trim (new Char [] {' ', '\n', '\r', '\t'}).
@@ -1222,7 +1231,7 @@ namespace Mono.CSharp
                        case "/res":
                        case "/resource":
                                if (embedded_resources == null)
-                                       embedded_resources = new Resources ();
+                                       embedded_resources = new Resources (ctx);
 
                                bool embeded = arg [1] == 'r' || arg [1] == 'R';
                                string[] s = value.Split (argument_value_separator);
@@ -1343,10 +1352,9 @@ namespace Mono.CSharp
                                return true;
                                
                        case "/debug":
-                               if (value == "pdbonly" || value == "full"){
-                                       /* ignore */
-                               } else
+                               if (value == "full" || value == "")
                                        want_debugging_support = true;
+
                                return true;
                                
                        case "/debug+":
@@ -1432,10 +1440,30 @@ namespace Mono.CSharp
                                load_default_config = false;
                                return true;
 
+                       case "/platform":
+                               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;
+                               }
+
+                               return true;
+
                                // We just ignore this.
                        case "/errorreport":
                        case "/filealign":
-                       case "/platform":
                                return true;
                                
                        case "/help2":
@@ -1495,24 +1523,23 @@ 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;
-#if GMCS_SOURCE
                                case "iso-2":
                                        RootContext.Version = LanguageVersion.ISO_2;
                                        return true;
+                               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":
@@ -1538,7 +1565,7 @@ namespace Mono.CSharp
                        return false;
                }
 
-               static void Error_WrongOption (string option)
+               void Error_WrongOption (string option)
                {
                        Report.Error (2007, "Unrecognized command-line option: `{0}'", option);
                }
@@ -1611,7 +1638,7 @@ namespace Mono.CSharp
                public bool Compile ()
                {
                        // TODO: Should be passed to parser as an argument
-                       RootContext.ToplevelTypes = new ModuleContainer (RootContext.Unsafe);
+                       RootContext.ToplevelTypes = new ModuleCompiled (ctx, RootContext.Unsafe);
 
                        Parse ();
                        if (Report.Errors > 0)
@@ -1642,7 +1669,7 @@ namespace Mono.CSharp
                                        output_file = first_source + RootContext.TargetExt;
                        }
 
-                       if (!CodeGen.Init (output_file, output_file, want_debugging_support))
+                       if (!CodeGen.Init (output_file, output_file, want_debugging_support, ctx))
                                return false;
 
                        if (RootContext.Target == Target.Module) {
@@ -1674,10 +1701,10 @@ namespace Mono.CSharp
                        if (timestamps)
                                ShowTime ("References loaded");
                        
-                       if (!TypeManager.InitCoreTypes () || Report.Errors > 0)
+                       if (!TypeManager.InitCoreTypes (ctx) || Report.Errors > 0)
                                return false;
 
-                       TypeManager.InitOptionalCoreTypes ();
+                       TypeManager.InitOptionalCoreTypes (ctx);
 
                        if (timestamps)
                                ShowTime ("   Core Types done");
@@ -1700,7 +1727,7 @@ namespace Mono.CSharp
                        if (Report.Errors == 0 &&
                                RootContext.Documentation != null &&
                                !RootContext.Documentation.OutputDocComment (
-                                       output_file))
+                                       output_file, Report))
                                return false;
 
                        //
@@ -1716,7 +1743,7 @@ namespace Mono.CSharp
                        
                        if (RootContext.VerifyClsCompliance) {
                                if (CodeGen.Assembly.IsClsCompliant) {
-                                       AttributeTester.VerifyModulesClsCompliance ();
+                                       AttributeTester.VerifyModulesClsCompliance (ctx);
                                        TypeManager.LoadAllImportedTypes ();
                                }
                        }
@@ -1802,7 +1829,7 @@ 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 ();
@@ -1811,7 +1838,7 @@ namespace Mono.CSharp
                        if (win32IconFile != null) {
                                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 });
                                }
@@ -1820,30 +1847,13 @@ namespace Mono.CSharp
                        if (Report.Errors > 0)
                                return false;
                        
-                       CodeGen.Save (output_file, want_debugging_support);
+                       CodeGen.Save (output_file, want_debugging_support, Report);
                        if (timestamps) {
                                ShowTime ("Saved output");
                                ShowTotalTime ("Total");
                        }
 
                        Timer.ShowTimers ();
-                       
-                       if (Report.ExpectedError != 0) {
-                               if (Report.Errors == 0) {
-                                       Console.WriteLine ("Failed to report expected error " + Report.ExpectedError + ".\n" +
-                                               "No other errors reported.");
-                                       
-                                       Environment.Exit (2);
-                               } else {
-                                       Console.WriteLine ("Failed to report expected error " + Report.ExpectedError + ".\n" +
-                                               "However, other errors were reported.");
-                                       
-                                       Environment.Exit (1);
-                               }
-                               
-                               
-                               return false;
-                       }
 
 #if DEBUGME
                        Console.WriteLine ("Size of strings held: " + DeclSpace.length);
@@ -1857,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) {
-                                       Report.RuntimeMissingSupport (Location.Null, "Resource embedding");
-                               }
-                       }
-
                        readonly object[] args;
 
                        public EmbededResource (string name, string file, bool isPrivate)
@@ -1889,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);
                        }
 
@@ -1914,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);
                        }
@@ -1927,7 +1936,13 @@ namespace Mono.CSharp
                }
 
 
-               IDictionary embedded_resources = new HybridDictionary ();
+               Dictionary<string, IResource> embedded_resources = new Dictionary<string, IResource> ();
+               readonly CompilerContext ctx;
+
+               public Resources (CompilerContext ctx)
+               {
+                       this.ctx = ctx;
+               }
 
                public void Add (bool embeded, string file, string name)
                {
@@ -1936,8 +1951,8 @@ namespace Mono.CSharp
 
                public void Add (bool embeded, string file, string name, bool isPrivate)
                {
-                       if (embedded_resources.Contains (name)) {
-                               Report.Error (1508, "The resource identifier `{0}' has already been used in this assembly", name);
+                       if (embedded_resources.ContainsKey (name)) {
+                               ctx.Report.Error (1508, "The resource identifier `{0}' has already been used in this assembly", name);
                                return;
                        }
                        IResource r = embeded ? 
@@ -1951,11 +1966,11 @@ namespace Mono.CSharp
                {
                        foreach (IResource r in embedded_resources.Values) {
                                if (!File.Exists (r.FileName)) {
-                                       Report.Error (1566, "Error reading resource file `{0}'", r.FileName);
+                                       ctx.Report.Error (1566, "Error reading resource file `{0}'", r.FileName);
                                        continue;
                                }
                                
-                               r.Emit ();
+                               r.Emit (ctx);
                        }
                }
        }
@@ -1966,16 +1981,14 @@ namespace Mono.CSharp
        public class CompilerCallableEntryPoint : MarshalByRefObject {
                public static bool InvokeCompiler (string [] args, TextWriter error)
                {
-                       Report.Stderr = error;
                        try {
-                               Driver d = Driver.Create (args, true);
+                               StreamReportPrinter srp = new StreamReportPrinter (error);
+                               Driver d = Driver.Create (args, true, srp);
                                if (d == null)
                                        return false;
 
-                               return d.Compile () && Report.Errors == 0;
-                       }
-                       finally {
-                               Report.Stderr = Console.Error;
+                               return d.Compile () && srp.ErrorsCount == 0;
+                       } finally {
                                Reset ();
                        }
                }
@@ -1999,9 +2012,9 @@ namespace Mono.CSharp
                public static void Reset (bool full_flag)
                {
                        Driver.Reset ();
+                       CSharpParser.yacc_verbose_flag = 0;
                        RootContext.Reset (full_flag);
                        Location.Reset ();
-                       Report.Reset ();
                        TypeManager.Reset ();
                        PredefinedAttributes.Reset ();
                        TypeHandle.Reset ();
@@ -2021,7 +2034,7 @@ namespace Mono.CSharp
                        Linq.QueryBlock.TransparentParameter.Reset ();
                        Convert.Reset ();
                        TypeInfo.Reset ();
+                       DynamicExpressionStatement.Reset ();
                }
-
        }
 }