condition tests passes
[mono.git] / mcs / mcs / driver.cs
index 3cbc6fc98cae83936ac7222f9cbbc6e1697fc2aa..cf409aea1d4165f6fc7cda77fbc746497981b80c 100644 (file)
@@ -15,6 +15,7 @@ namespace Mono.CSharp
        using System.Reflection;
        using System.Reflection.Emit;
        using System.Collections;
+       using System.Collections.Specialized;
        using System.IO;
        using System.Text;
        using System.Globalization;
@@ -42,6 +43,11 @@ namespace Mono.CSharp
                //
                static ArrayList soft_references;
 
+               // 
+               // External aliases for assemblies.
+               //
+               static Hashtable external_aliases;
+
                //
                // Modules to be linked
                //
@@ -70,8 +76,7 @@ namespace Mono.CSharp
                //
                // A list of resource files
                //
-               static ArrayList resources;
-               static ArrayList embedded_resources;
+               static Resources embedded_resources;
                static string win32ResourceFile;
                static string win32IconFile;
 
@@ -93,10 +98,8 @@ namespace Mono.CSharp
                //
                // Encoding.
                //
-               static Encoding defaultEncoding;
                static Encoding encoding;
 
-
                static public void Reset ()
                {
                        want_debugging_support = false;
@@ -105,11 +108,11 @@ namespace Mono.CSharp
                        pause = false;
                        show_counters = false;
                        load_default_config = true;
-                       resources = embedded_resources = null;
+                       embedded_resources = null;
                        win32ResourceFile = win32IconFile = null;
                        defines = null;
                        output_file = null;
-                       encoding = defaultEncoding = null;
+                       encoding = null;
                        first_source = null;
                }
 
@@ -196,7 +199,9 @@ namespace Mono.CSharp
                        try {
                                parser.parse ();
                        } catch (Exception ex) {
-                               Report.Error(666, "Compilation aborted: " + ex);
+                               Report.Error(
+                                       666, String.Format ("Compilation aborted in file {0}, parser at {1}: {2}",
+                                                           file.Name, parser.Lexer.Location, ex));
                        } finally {
                                input.Close ();
                        }
@@ -208,10 +213,10 @@ namespace Mono.CSharp
                                "Other flags in the compiler\n" +
                                "   --fatal            Makes errors fatal\n" +
                                "   --parse            Only parses the source file\n" +
+                               "   --typetest         Tests the tokenizer's built-in type parser\n" +
                                "   --stacktrace       Shows stack trace at error location\n" +
                                "   --timestamp        Displays time stamps of various compiler events\n" +
                                "   --expect-error X   Expect that error X will be encountered\n" +
-                               "   -2                 Enables experimental C# features\n" +
                                "   -v                 Verbose parsing (for debugging the parser)\n" + 
                                "   --mcs-debug X      Sets MCS debugging level to X\n");
                }
@@ -219,40 +224,42 @@ namespace Mono.CSharp
                static void Usage ()
                {
                        Console.WriteLine (
-                               "Mono C# compiler, (C) 2001 - 2005 Novell, Inc.\n" +
+                               "Mono C# compiler, (C) 2001 - 2008 Novell, Inc.\n" +
                                "mcs [options] source-files\n" +
                                "   --about            About the Mono C# compiler\n" +
-                               "   -addmodule:MODULE  Adds the module to the generated assembly\n" + 
-                               "   -checked[+|-]      Set default context to checked\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" + Environment.NewLine +
-                               "   -define:S1[;S2]    Defines one or more symbols (short: /d:)\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          XML Documentation file to generate\n" + 
-                               "   -keycontainer:NAME The key pair container used to strongname the assembly\n" +
-                               "   -keyfile:FILE      The strongname key file used to strongname the assembly\n" +
-                               "   -langversion:TEXT  Specifies language version modes: ISO-1 or Default\n" + 
-                               "   -lib:PATH1,PATH2   Adds the paths to the assembly link path\n" +
-                               "   -main:class        Specified the class that contains the entry point\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 load core libraries\n" +
-                               "   -nowarn:W1[,W2]    Disables one or more warnings\n" + 
-                               "   -optimize[+|-]     Enables code optimalizations\n" + 
-                               "   -out:FNAME         Specifies output file\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 the files in SPEC ([dir]/file)\n" + 
-                               "   -reference:ASS     References the specified assembly (-r:ASS)\n" +
-                               "   -target:KIND       Specifies the target (KIND is one of: exe, winexe,\n" +
-                               "                      library, module), (short: /t:)\n" +
-                               "   -unsafe[+|-]       Allows unsafe code\n" +
-                               "   -warnaserror[+|-]  Treat warnings as errors\n" +
-                               "   -warn:LEVEL        Sets warning level (the highest is 4, the default is 2)\n" +
-                               "   -help2             Show other help flags\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" + 
                                "\n" +
                                "Resources:\n" +
-                               "   -linkresource:FILE[,ID] Links FILE as a resource\n" +
-                               "   -resource:FILE[,ID]     Embed FILE as a resource\n" +
+                               "   -linkresource:FILE[,ID] Links FILE as a resource (short: -linkres)\n" +
+                               "   -resource:FILE[,ID]     Embed FILE as a resource (short: -res)\n" +
                                "   -win32res:FILE          Specifies Win32 resource file (.res)\n" +
                                "   -win32icon:FILE         Use this icon for the output\n" +
                                 "   @file                   Read response file for more options\n\n" +
@@ -267,20 +274,24 @@ namespace Mono.CSharp
                static void About ()
                {
                        Console.WriteLine (
-                               "The Mono C# compiler is (C) 2001-2005, Novell, Inc.\n\n" +
+                               "The Mono C# compiler is (C) 2001-2008, Novell, Inc.\n\n" +
                                "The compiler source code is released under the terms of the GNU GPL\n\n" +
 
                                "For more information on Mono, visit the project Web site\n" +
-                               "   http://www.go-mono.com\n\n" +
+                               "   http://www.mono-project.com\n\n" +
 
-                               "The compiler was written by Miguel de Icaza, Ravi Pratap, Martin Baulig, Marek Safar, Raja R Harinath");
+                               "The compiler was written by Miguel de Icaza, Ravi Pratap, Martin Baulig, Marek Safar, Raja R Harinath, Atushi Enomoto");
                        Environment.Exit (0);
                }
 
                public static int counter1, counter2;
                
-       public static int Main (string[] args)
+               public static int Main (string[] args)
                {
+                       RootContext.Version = LanguageVersion.Default;
+
+                       Location.InEmacs = Environment.GetEnvironmentVariable ("EMACS") == "t";
+
                        bool ok = MainDriver (args);
                        
                        if (ok && Report.Errors == 0) {
@@ -303,93 +314,144 @@ namespace Mono.CSharp
 
                static public void LoadAssembly (string assembly, bool soft)
                {
-                       Assembly a;
-                       string total_log = "";
+                       LoadAssembly (assembly, null, soft);
+               }
 
-                       try {
-                               char[] path_chars = { '/', '\\' };
+               static 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);
+               }
 
-                               if (assembly.IndexOfAny (path_chars) != -1) {
-                                       a = Assembly.LoadFrom (assembly);
-                               } else {
-                                       string ass = assembly;
-                                       if (ass.EndsWith (".dll") || ass.EndsWith (".exe"))
-                                               ass = assembly.Substring (0, assembly.Length - 4);
-                                       a = Assembly.Load (ass);
-                               }
-                               TypeManager.AddAssembly (a);
+               static 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);
+               }
 
-                       } catch (FileNotFoundException){
-                               foreach (string dir in link_paths){
-                                       string full_path = Path.Combine (dir, assembly);
-                                       if (!assembly.EndsWith (".dll") && !assembly.EndsWith (".exe"))
-                                               full_path += ".dll";
+               static void BadAssembly (string filename, string log)
+               {
+                       MethodInfo adder_method = AssemblyClass.AddModule_Method;
 
+                       if (adder_method != null) {
+                               AssemblyName an = new AssemblyName ();
+                               an.Name = ".temp";
+                               AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (an, AssemblyBuilderAccess.Run);
+                               try {
+                                       object m = null;
                                        try {
-                                               a = Assembly.LoadFrom (full_path);
-                                               TypeManager.AddAssembly (a);
+                                               m = adder_method.Invoke (ab, new object [] { filename });
+                                       } catch (TargetInvocationException ex) {
+                                               throw ex.InnerException;
+                                       }
+
+                                       if (m != null) {
+                                               Report.Error (1509, "referenced file `{0}' is not an assembly; try using the '-addmodule' option", filename);
                                                return;
-                                       } catch (FileNotFoundException ff) {
-                                               total_log += ff.FusionLog;
-                                               continue;
                                        }
+                               } catch (FileNotFoundException) {
+                                       // did the file get deleted during compilation? who cares? swallow the exception
+                               } catch (BadImageFormatException) {
+                                       // swallow exception
+                               } catch (FileLoadException) {
+                                       // swallow exception
                                }
-                               if (!soft) {
-                                       Report.Error (6, "Cannot find assembly `" + assembly + "'" );
-                                       Console.WriteLine ("Log: \n" + total_log);
-                               }
-                       } catch (BadImageFormatException f) {
-                               Report.Error(6, "Cannot load assembly (bad file format)" + f.FusionLog);
-                       } catch (FileLoadException f){
-                               Report.Error(6, "Cannot load assembly " + f.FusionLog);
-                       } catch (ArgumentNullException){
-                               Report.Error(6, "Cannot load assembly (null argument)");
                        }
+                       Error9 ("assembly", filename, log);
                }
 
-               static public void LoadModule (MethodInfo adder_method, string module)
+               static public void LoadAssembly (string assembly, string alias, bool soft)
                {
-                       Module m;
+                       Assembly a = null;
                        string total_log = "";
 
                        try {
                                try {
-                                       m = (Module)adder_method.Invoke (CodeGen.Assembly.Builder, new object [] { module });
-                               }
-                               catch (TargetInvocationException ex) {
-                                       throw ex.InnerException;
-                               }
-                               TypeManager.AddModule (m);
+                                       char[] path_chars = { '/', '\\' };
 
-                       } 
-                       catch (FileNotFoundException){
-                               foreach (string dir in link_paths){
-                                       string full_path = Path.Combine (dir, module);
-                                       if (!module.EndsWith (".netmodule"))
-                                               full_path += ".netmodule";
+                                       if (assembly.IndexOfAny (path_chars) != -1) {
+                                               a = Assembly.LoadFrom (assembly);
+                                       } else {
+                                               string ass = assembly;
+                                               if (ass.EndsWith (".dll") || ass.EndsWith (".exe"))
+                                                       ass = assembly.Substring (0, assembly.Length - 4);
+                                               a = Assembly.Load (ass);
+                                       }
+                               } catch (FileNotFoundException) {
+                                       bool err = !soft;
+                                       foreach (string dir in link_paths) {
+                                               string full_path = Path.Combine (dir, assembly);
+                                               if (!assembly.EndsWith (".dll") && !assembly.EndsWith (".exe"))
+                                                       full_path += ".dll";
 
-                                       try {
                                                try {
-                                                       m = (Module)adder_method.Invoke (CodeGen.Assembly.Builder, new object [] { full_path });
+                                                       a = Assembly.LoadFrom (full_path);
+                                                       err = false;
+                                                       break;
+                                               } catch (FileNotFoundException ff) {
+                                                       if (soft)
+                                                               return;
+                                                       total_log += ff.FusionLog;
                                                }
-                                               catch (TargetInvocationException ex) {
-                                                       throw ex.InnerException;
+                                       }
+                                       if (err) {
+                                               Error6 (assembly, total_log);
+                                               return;
+                                       }
+                               }
+
+                               // Extern aliased refs require special handling
+                               if (alias == null)
+                                       RootNamespace.Global.AddAssemblyReference (a);
+                               else
+                                       RootNamespace.DefineRootNamespace (alias, a);
+
+                       } catch (BadImageFormatException f) {
+                               // .NET 2.0 throws this if we try to load a module without an assembly manifest ...
+                               BadAssembly (f.FileName, f.FusionLog);
+                       } catch (FileLoadException f) {
+                               // ... while .NET 1.1 throws this
+                               BadAssembly (f.FileName, f.FusionLog);
+                       }
+               }
+
+               static public void LoadModule (string module)
+               {
+                       Module m = null;
+                       string total_log = "";
+
+                       try {
+                               try {
+                                       m = CodeGen.Assembly.AddModule (module);
+                               } catch (FileNotFoundException) {
+                                       bool err = true;
+                                       foreach (string dir in link_paths) {
+                                               string full_path = Path.Combine (dir, module);
+                                               if (!module.EndsWith (".netmodule"))
+                                                       full_path += ".netmodule";
+
+                                               try {
+                                                       m = CodeGen.Assembly.AddModule (full_path);
+                                                       err = false;
+                                                       break;
+                                               } catch (FileNotFoundException ff) {
+                                                       total_log += ff.FusionLog;
                                                }
-                                               TypeManager.AddModule (m);
+                                       }
+                                       if (err) {
+                                               Error6 (module, total_log);
                                                return;
-                                       } catch (FileNotFoundException ff) {
-                                               total_log += ff.FusionLog;
-                                               continue;
                                        }
                                }
-                               Report.Error (6, "Cannot find module `" + module + "'" );
-                               Console.WriteLine ("Log: \n" + total_log);
+
+                               RootNamespace.Global.AddModuleReference (m);
+
                        } catch (BadImageFormatException f) {
-                               Report.Error(6, "Cannot load module (bad file format)" + f.FusionLog);
-                       } catch (FileLoadException f){
-                               Report.Error(6, "Cannot load module " + f.FusionLog);
-                       } catch (ArgumentNullException){
-                               Report.Error(6, "Cannot load module (null argument)");
+                               Error9 ("module", f.FileName, f.FusionLog);
+                       } catch (FileLoadException f) {
+                               Error9 ("module", f.FileName, f.FusionLog);
                        }
                }
 
@@ -398,11 +460,20 @@ namespace Mono.CSharp
                /// </summary>
                static public void LoadReferences ()
                {
-                       foreach (string r in references)
-                               LoadAssembly (r, false);
+                       //
+                       // Load Core Library for default compilation
+                       //
+                       if (RootContext.StdLib)
+                               LoadAssembly ("mscorlib", false);
 
                        foreach (string r in soft_references)
                                LoadAssembly (r, true);
+
+                       foreach (string r in references)
+                               LoadAssembly (r, false);
+
+                       foreach (DictionaryEntry entry in external_aliases)
+                               LoadAssembly ((string) entry.Value, (string) entry.Key, false);
                        
                        return;
                }
@@ -573,7 +644,14 @@ namespace Mono.CSharp
                        //
                        string [] default_config = {
                                "System",
-                               "System.Xml",
+#if NET_2_1
+                               "agclr",
+                               "System.Core",
+                               "System.Silverlight",
+                               "System.Xml.Core",
+#else
+                               "System.Xml"
+#endif
 #if false
                                //
                                // Is it worth pre-loading all this stuff?
@@ -599,9 +677,10 @@ namespace Mono.CSharp
 #endif
                        };
                        
-                       int p = 0;
-                       foreach (string def in default_config)
-                               soft_references.Insert (p++, def);
+                       if (RootContext.Version == LanguageVersion.LINQ)
+                               soft_references.Add ("System.Core");
+
+                       soft_references.AddRange (default_config);
                }
 
                public static string OutputFile
@@ -626,15 +705,9 @@ namespace Mono.CSharp
                                Report.Error (1900, "Warning level must be in the range 0-4");
                                return;
                        }
-                       RootContext.WarningLevel = level;
+                       Report.WarningLevel = level;
                }
 
-               static void SetupV2 ()
-               {
-                       RootContext.Version = LanguageVersion.Default;
-                       defines.Add ("__V2__");
-               }
-               
                static void Version ()
                {
                        string version = Assembly.GetExecutingAssembly ().GetName ().Version.ToString ();
@@ -663,7 +736,7 @@ namespace Mono.CSharp
                                return true;
                                
                        case "--main": case "-m":
-                               Report.Warning (-29, "Compatibility: Use -main:CLASS instead of --main CLASS or -m CLASS");
+                               Report.Warning (-29, 1, "Compatibility: Use -main:CLASS instead of --main CLASS or -m CLASS");
                                if ((i + 1) >= args.Length){
                                        Usage ();
                                        Environment.Exit (1);
@@ -672,7 +745,7 @@ namespace Mono.CSharp
                                return true;
                                
                        case "--unsafe":
-                               Report.Warning (-29, "Compatibility: Use -unsafe instead of --unsafe");
+                               Report.Warning (-29, 1, "Compatibility: Use -unsafe instead of --unsafe");
                                RootContext.Unsafe = true;
                                return true;
                                
@@ -683,7 +756,7 @@ namespace Mono.CSharp
                                return true;
 
                        case "--define":
-                               Report.Warning (-29, "Compatibility: Use -d:SYMBOL instead of --define SYMBOL");
+                               Report.Warning (-29, 1, "Compatibility: Use -d:SYMBOL instead of --define SYMBOL");
                                if ((i + 1) >= args.Length){
                                        Usage ();
                                        Environment.Exit (1);
@@ -714,7 +787,7 @@ namespace Mono.CSharp
                                
                        case "-o": 
                        case "--output":
-                               Report.Warning (-29, "Compatibility: Use -out:FILE instead of --output FILE or -o FILE");
+                               Report.Warning (-29, 1, "Compatibility: Use -out:FILE instead of --output FILE or -o FILE");
                                if ((i + 1) >= args.Length){
                                        Usage ();
                                        Environment.Exit (1);
@@ -723,7 +796,7 @@ namespace Mono.CSharp
                                return true;
 
                        case "--checked":
-                               Report.Warning (-29, "Compatibility: Use -checked instead of --checked");
+                               Report.Warning (-29, 1, "Compatibility: Use -checked instead of --checked");
                                RootContext.Checked = true;
                                return true;
                                
@@ -733,34 +806,34 @@ namespace Mono.CSharp
                                
                        case "--linkresource":
                        case "--linkres":
-                               Report.Warning (-29, "Compatibility: Use -linkres:VALUE instead of --linkres VALUE");
+                               Report.Warning (-29, 1, "Compatibility: Use -linkres:VALUE instead of --linkres VALUE");
                                if ((i + 1) >= args.Length){
                                        Usage ();
                                        Report.Error (5, "Missing argument to --linkres"); 
                                        Environment.Exit (1);
                                }
-                               if (resources == null)
-                                       resources = new ArrayList ();
+                               if (embedded_resources == null)
+                                       embedded_resources = new Resources ();
                                
-                               resources.Add (args [++i]);
+                               embedded_resources.Add (false, args [++i], args [i]);
                                return true;
                                
                        case "--resource":
                        case "--res":
-                               Report.Warning (-29, "Compatibility: Use -res:VALUE instead of --res VALUE");
+                               Report.Warning (-29, 1, "Compatibility: Use -res:VALUE instead of --res VALUE");
                                if ((i + 1) >= args.Length){
                                        Usage ();
                                        Report.Error (5, "Missing argument to --resource"); 
                                        Environment.Exit (1);
                                }
                                if (embedded_resources == null)
-                                       embedded_resources = new ArrayList ();
+                                       embedded_resources = new Resources ();
                                
-                               embedded_resources.Add (args [++i]);
+                               embedded_resources.Add (true, args [++i], args [i]);
                                return true;
                                
                        case "--target":
-                               Report.Warning (-29, "Compatibility: Use -target:KIND instead of --target KIND");
+                               Report.Warning (-29, 1, "Compatibility: Use -target:KIND instead of --target KIND");
                                if ((i + 1) >= args.Length){
                                        Environment.Exit (1);
                                        return true;
@@ -792,17 +865,26 @@ namespace Mono.CSharp
                                return true;
                                
                        case "-r":
-                               Report.Warning (-29, "Compatibility: Use -r:LIBRARY instead of -r library");
+                               Report.Warning (-29, 1, "Compatibility: Use -r:LIBRARY instead of -r library");
                                if ((i + 1) >= args.Length){
                                        Usage ();
                                        Environment.Exit (1);
                                }
                                
-                               references.Add (args [++i]);
+                               string val = args [++i];
+                               int idx = val.IndexOf ('=');
+                               if (idx > -1) {
+                                       string alias = val.Substring (0, idx);
+                                       string assembly = val.Substring (idx + 1);
+                                       AddExternAlias (alias, assembly);
+                                       return true;
+                               }
+
+                               references.Add (val);
                                return true;
                                
                        case "-L":
-                               Report.Warning (-29, "Compatibility: Use -lib:ARG instead of --L arg");
+                               Report.Warning (-29, 1, "Compatibility: Use -lib:ARG instead of --L arg");
                                if ((i + 1) >= args.Length){
                                        Usage ();       
                                        Environment.Exit (1);
@@ -811,7 +893,7 @@ namespace Mono.CSharp
                                return true;
                                
                        case "--nostdlib":
-                               Report.Warning (-29, "Compatibility: Use -nostdlib instead of --nostdlib");
+                               Report.Warning (-29, 1, "Compatibility: Use -nostdlib instead of --nostdlib");
                                RootContext.StdLib = false;
                                return true;
                                
@@ -820,12 +902,12 @@ namespace Mono.CSharp
                                return true;
                                
                        case "--werror":
-                               Report.Warning (-29, "Compatibility: Use -warnaserror: option instead of --werror");
+                               Report.Warning (-29, 1, "Compatibility: Use -warnaserror: option instead of --werror");
                                Report.WarningsAreErrors = true;
                                return true;
-                               
+
                        case "--nowarn":
-                               Report.Warning (-29, "Compatibility: Use -nowarn instead of --nowarn");
+                               Report.Warning (-29, 1, "Compatibility: Use -nowarn instead of --nowarn");
                                if ((i + 1) >= args.Length){
                                        Usage ();
                                        Environment.Exit (1);
@@ -842,7 +924,7 @@ namespace Mono.CSharp
                                return true;
                                
                        case "--wlevel":
-                               Report.Warning (-29, "Compatibility: Use -warn:LEVEL instead of --wlevel LEVEL");
+                               Report.Warning (-29, 1, "Compatibility: Use -warn:LEVEL instead of --wlevel LEVEL");
                                if ((i + 1) >= args.Length){
                                        Report.Error (
                                                1900,
@@ -872,7 +954,7 @@ namespace Mono.CSharp
                                return true;
                                
                        case "--recurse":
-                               Report.Warning (-29, "Compatibility: Use -recurse:PATTERN option instead --recurse PATTERN");
+                               Report.Warning (-29, 1, "Compatibility: Use -recurse:PATTERN option instead --recurse PATTERN");
                                if ((i + 1) >= args.Length){
                                        Report.Error (5, "--recurse requires an argument");
                                        Environment.Exit (1);
@@ -890,12 +972,12 @@ namespace Mono.CSharp
                                return true;
                                
                        case "--debug": case "-g":
-                               Report.Warning (-29, "Compatibility: Use -debug option instead of -g or --debug");
+                               Report.Warning (-29, 1, "Compatibility: Use -debug option instead of -g or --debug");
                                want_debugging_support = true;
                                return true;
                                
                        case "--noconfig":
-                               Report.Warning (-29, "Compatibility: Use -noconfig option instead of --noconfig");
+                               Report.Warning (-29, 1, "Compatibility: Use -noconfig option instead of --noconfig");
                                load_default_config = false;
                                return true;
                        }
@@ -953,18 +1035,21 @@ namespace Mono.CSharp
                                return true;
 
                        case "/out":
-                               if (value == ""){
+                               if (value.Length == 0){
                                        Usage ();
                                        Environment.Exit (1);
                                }
                                OutputFile = value;
                                return true;
 
+                       case "/o":
+                       case "/o+":
                        case "/optimize":
                        case "/optimize+":
                                RootContext.Optimize = true;
                                return true;
 
+                       case "/o-":
                        case "/optimize-":
                                RootContext.Optimize = false;
                                return true;
@@ -977,15 +1062,16 @@ namespace Mono.CSharp
 
                        case "/d":
                        case "/define": {
-                               string [] defs;
-
-                               if (value == ""){
+                               if (value.Length == 0){
                                        Usage ();
                                        Environment.Exit (1);
                                }
 
-                               defs = value.Split (new Char [] {';', ','});
-                               foreach (string d in defs){
+                               foreach (string d in value.Split (';', ',')){
+                                       if (!Tokenizer.IsValidIdentifier (d)) {
+                                               Report.Warning (2029, 1, "Invalid conditional define symbol `{0}'", d);
+                                               continue;
+                                       }
                                        defines.Add (d);
                                }
                                return true;
@@ -998,22 +1084,10 @@ namespace Mono.CSharp
                                Console.WriteLine ("To file bug reports, please visit: http://www.mono-project.com/Bugs");
                                return true;
 
-                       case "/linkres":
-                       case "/linkresource":
-                               if (value == ""){
-                                       Report.Error (5, arg + " requires an argument");
-                                       Environment.Exit (1);
-                               }
-                               if (resources == null)
-                                       resources = new ArrayList ();
-                               
-                               resources.Add (value);
-                               return true;
-
                        case "/pkg": {
                                string packages;
 
-                               if (value == ""){
+                               if (value.Length == 0){
                                        Usage ();
                                        Environment.Exit (1);
                                }
@@ -1033,7 +1107,7 @@ namespace Mono.CSharp
                                }
 
                                if (p.StandardOutput == null){
-                                       Report.Warning (-27, "Specified package did not return any information");
+                                       Report.Warning (-27, 1, "Specified package did not return any information");
                                        return true;
                                }
                                string pkgout = p.StandardOutput.ReadToEnd ();
@@ -1053,28 +1127,40 @@ namespace Mono.CSharp
                                return true;
                        }
                                
+                       case "/linkres":
+                       case "/linkresource":
                        case "/res":
                        case "/resource":
-                               if (value == ""){
-                                       Report.Error (5, "-resource requires an argument");
-                                       Environment.Exit (1);
-                               }
                                if (embedded_resources == null)
-                                       embedded_resources = new ArrayList ();
-                               
-                               if (embedded_resources.Contains (value)) {
-                                       Report.Error (1508, String.Format ("The resource identifier `{0}' has already been used in this assembly.", value));
-                               }
-                               else if (value.IndexOf (',') != -1 && embedded_resources.Contains (value.Split (',')[1])) {
-                                       Report.Error (1508, String.Format ("The resource identifier `{0}' has already been used in this assembly.", value));
-                               }
-                               else {
-                                       embedded_resources.Add (value);
+                                       embedded_resources = new Resources ();
+
+                               bool embeded = arg.StartsWith ("/r");
+                               string[] s = value.Split (',');
+                               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;
                                }
+
                                return true;
                                
                        case "/recurse":
-                               if (value == ""){
+                               if (value.Length == 0){
                                        Report.Error (5, "-recurse requires an argument");
                                        Environment.Exit (1);
                                }
@@ -1083,19 +1169,28 @@ namespace Mono.CSharp
 
                        case "/r":
                        case "/reference": {
-                               if (value == ""){
+                               if (value.Length == 0){
                                        Report.Error (5, "-reference requires an argument");
                                        Environment.Exit (1);
                                }
 
                                string [] refs = value.Split (new char [] { ';', ',' });
                                foreach (string r in refs){
-                                       references.Add (r);
+                                       string val = r;
+                                       int index = val.IndexOf ('=');
+                                       if (index > -1) {
+                                               string alias = r.Substring (0, index);
+                                               string assembly = r.Substring (index + 1);
+                                               AddExternAlias (alias, assembly);
+                                               return true;
+                                       }
+                                       
+                                       references.Add (val);
                                }
                                return true;
                        }
                        case "/addmodule": {
-                               if (value == ""){
+                               if (value.Length == 0){
                                        Report.Error (5, arg + " requires an argument");
                                        Environment.Exit (1);
                                }
@@ -1107,7 +1202,7 @@ namespace Mono.CSharp
                                return true;
                        }
                        case "/win32res": {
-                               if (value == "") {
+                               if (value.Length == 0) {
                                        Report.Error (5, arg + " requires an argument");
                                        Environment.Exit (1);
                                }
@@ -1116,7 +1211,7 @@ namespace Mono.CSharp
                                return true;
                        }
                        case "/win32icon": {
-                               if (value == "") {
+                               if (value.Length == 0) {
                                        Report.Error (5, arg + " requires an argument");
                                        Environment.Exit (1);
                                }
@@ -1125,7 +1220,7 @@ namespace Mono.CSharp
                                return true;
                        }
                        case "/doc": {
-                               if (value == ""){
+                               if (value.Length == 0){
                                        Report.Error (2006, arg + " requires an argument");
                                        Environment.Exit (1);
                                }
@@ -1135,7 +1230,7 @@ namespace Mono.CSharp
                        case "/lib": {
                                string [] libdirs;
                                
-                               if (value == ""){
+                               if (value.Length == 0){
                                        Report.Error (5, "/lib requires an argument");
                                        Environment.Exit (1);
                                }
@@ -1197,7 +1292,7 @@ namespace Mono.CSharp
                        case "/nowarn": {
                                string [] warns;
 
-                               if (value == ""){
+                               if (value.Length == 0){
                                        Report.Error (5, "/nowarn requires an argument");
                                        Environment.Exit (1);
                                }
@@ -1239,7 +1334,7 @@ namespace Mono.CSharp
 
                        case "/main":
                        case "/m":
-                               if (value == ""){
+                               if (value.Length == 0){
                                        Report.Error (5, arg + " requires an argument");                                        
                                        Environment.Exit (1);
                                }
@@ -1279,23 +1374,29 @@ namespace Mono.CSharp
                                RootContext.StrongNameDelaySign = false;
                                return true;
 
-                       case "/v2":
-                       case "/2":
-                               Console.WriteLine ("The compiler option -2 is obsolete. Please use /langversion instead");
-                               SetupV2 ();
-                               return true;
-                               
                        case "/langversion":
                                switch (value.ToLower (CultureInfo.InvariantCulture)) {
-                                       case "iso-1":
-                                               RootContext.Version = LanguageVersion.ISO_1;
-                                               return true;
-
-                                       case "default":
-                                               SetupV2 ();
-                                               return true;
+                               case "iso-1":
+                                       RootContext.Version = LanguageVersion.ISO_1;
+                                       return true;
+                                       
+                               case "default":
+                                       RootContext.Version = LanguageVersion.Default;
+#if GMCS_SOURCE                                        
+                                       defines.Add ("__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");
+                                       return true;
+#endif
                                }
-                               Report.Error (1617, "Invalid option `{0}' for /langversion. It must be either `ISO-1' or `Default'", value);
+                               Report.Error (1617, "Invalid option `{0}' for /langversion. It must be either `ISO-1', `ISO-2' or `Default'", value);
                                return true;
 
                        case "/codepage":
@@ -1304,7 +1405,7 @@ namespace Mono.CSharp
                                        encoding = new UTF8Encoding();
                                        break;
                                case "reset":
-                                       encoding = defaultEncoding;
+                                       encoding = Encoding.Default;
                                        break;
                                default:
                                        try {
@@ -1318,11 +1419,14 @@ namespace Mono.CSharp
                                return true;
                        }
 
-                       //Report.Error (2007, String.Format ("Unrecognized command-line option: `{0}'", option));
-                       //Environment.Exit (1);
                        return false;
                }
 
+               static void Error_WrongOption (string option)
+               {
+                       Report.Error (2007, "Unrecognized command-line option: `{0}'", option);
+               }
+
                static string [] AddArgs (string [] args, string [] extra_args)
                {
                        string [] new_args;
@@ -1346,6 +1450,44 @@ namespace Mono.CSharp
 
                        return new_args;
                }
+
+               static void AddExternAlias (string identifier, string assembly)
+               {
+                       if (assembly.Length == 0) {
+                               Report.Error (1680, "Invalid reference alias '" + identifier + "='. Missing filename");
+                               return;
+                       }
+
+                       if (!IsExternAliasValid (identifier)) {
+                               Report.Error (1679, "Invalid extern alias for /reference. Alias '" + identifier + "' is not a valid identifier");
+                               return;
+                       }
+                       
+                       // Could here hashtable throw an exception?
+                       external_aliases [identifier] = assembly;
+               }
+               
+               static bool IsExternAliasValid (string identifier)
+               {
+                       if (identifier.Length == 0)
+                               return false;
+                       if (identifier [0] != '_' && !Char.IsLetter (identifier [0]))
+                               return false;
+
+                       for (int i = 1; i < identifier.Length; i++) {
+                               char c = identifier [i];
+                               if (Char.IsLetter (c) || Char.IsDigit (c))
+                                       continue;
+
+                               UnicodeCategory category = Char.GetUnicodeCategory (c);
+                               if (category != UnicodeCategory.Format || category != UnicodeCategory.NonSpacingMark ||
+                                               category != UnicodeCategory.SpacingCombiningMark ||
+                                               category != UnicodeCategory.ConnectorPunctuation)
+                                       return false;
+                       }
+                       
+                       return true;
+               }
                
                /// <summary>
                ///    Parses the arguments, and drives the compilation
@@ -1362,16 +1504,10 @@ namespace Mono.CSharp
                        int i;
                        bool parsing_options = true;
 
-                       try {
-                               // Latin1
-                               defaultEncoding = Encoding.GetEncoding (28591);
-                       } catch (Exception) {
-                               // iso-8859-1
-                               defaultEncoding = Encoding.GetEncoding (1252);
-                       }
-                       encoding = defaultEncoding;
+                       encoding = Encoding.Default;
 
                        references = new ArrayList ();
+                       external_aliases = new Hashtable ();
                        soft_references = new ArrayList ();
                        modules = new ArrayList ();
                        link_paths = new ArrayList ();
@@ -1389,9 +1525,9 @@ namespace Mono.CSharp
 
                        for (i = 0; i < args.Length; i++){
                                string arg = args [i];
-                               if (arg == "")
+                               if (arg.Length == 0)
                                        continue;
-                               
+
                                if (arg.StartsWith ("@")){
                                        string [] extra_args;
                                        string response_file = arg.Substring (1);
@@ -1433,10 +1569,19 @@ namespace Mono.CSharp
                                                string csc_opt = "/" + arg.Substring (1);
                                                if (CSCParseOption (csc_opt, ref args, ref i))
                                                        continue;
+
+                                               Error_WrongOption (arg);
+                                               return false;
                                        } else {
-                                               if (arg.StartsWith ("/")){
+                                               if (arg [0] == '/'){
                                                        if (CSCParseOption (arg, ref args, ref i))
                                                                continue;
+
+                                                       // Need to skip `/home/test.cs' however /test.cs is considered as error
+                                                       if (arg.Length < 2 || arg.IndexOf ('/', 2) == -1) {
+                                                               Error_WrongOption (arg);
+                                                               return false;
+                                                       }
                                                }
                                        }
                                }
@@ -1449,17 +1594,13 @@ namespace Mono.CSharp
                        if (tokenize)
                                return true;
 
-                       //
-                       // This will point to the NamespaceEntry of the last file that was parsed, and may
-                       // not be meaningful when resolving classes from other files.  So, reset it to prevent
-                       // silent bugs.
-                       //
-                       RootContext.Tree.Types.NamespaceEntry = null;
+                       if (RootContext.ToplevelTypes.NamespaceEntry != null)
+                               throw new InternalErrorException ("who set it?");
 
                        //
                        // If we are an exe, require a source file for the entry point
                        //
-                       if (RootContext.Target == Target.Exe || RootContext.Target == Target.WinExe){
+                       if (RootContext.Target == Target.Exe || RootContext.Target == Target.WinExe || RootContext.Target == Target.Module){
                                if (first_source == null){
                                        Report.Error (2008, "No files to compile were specified");
                                        return false;
@@ -1470,7 +1611,7 @@ namespace Mono.CSharp
                        //
                        // If there is nothing to put in the assembly, and we are not a library
                        //
-                       if (first_source == null && embedded_resources == null && resources == null){
+                       if (first_source == null && embedded_resources == null){
                                Report.Error (2008, "No files to compile were specified");
                                return false;
                        }
@@ -1481,12 +1622,6 @@ namespace Mono.CSharp
                        if (parse_only)
                                return true;
 
-                       //
-                       // Load Core Library for default compilation
-                       //
-                       if (RootContext.StdLib)
-                               references.Insert (0, "mscorlib");
-
                        if (load_default_config)
                                DefineDefaultConfig ();
 
@@ -1514,6 +1649,11 @@ namespace Mono.CSharp
                        // Quick hack
                        //
                        if (output_file == null){
+                               if (first_source == null){
+                                       Report.Error (1562, "If no source files are specified you must specify the output file with -out:");
+                                       return false;
+                               }
+                                       
                                int pos = first_source.LastIndexOf ('.');
 
                                if (pos > 0)
@@ -1536,20 +1676,12 @@ namespace Mono.CSharp
                                set_method.Invoke (CodeGen.Assembly.Builder, BindingFlags.Default, null, new object[]{true}, null);
                        }
 
-                       TypeManager.AddModule (CodeGen.Module.Builder);
+                       RootNamespace.Global.AddModuleReference (CodeGen.Module.Builder);
 
                        if (modules.Count > 0) {
-                               MethodInfo adder_method = typeof (AssemblyBuilder).GetMethod ("AddModule", BindingFlags.Instance|BindingFlags.NonPublic);
-                               if (adder_method == null) {
-                                       Report.RuntimeMissingSupport (Location.Null, "/addmodule");
-                                       Environment.Exit (1);
-                               }
-
                                foreach (string module in modules)
-                                       LoadModule (adder_method, module);
+                                       LoadModule (module);
                        }
-
-                       TypeManager.ComputeNamespaces ();
                        
                        //
                        // Before emitting, we need to get the core
@@ -1568,7 +1700,7 @@ namespace Mono.CSharp
                        if (timestamps)
                                ShowTime ("   Core Types done");
 
-                       CodeGen.Module.ResolveAttributes ();
+                       CodeGen.Module.Resolve ();
 
                        //
                        // The second pass of the compiler
@@ -1583,14 +1715,14 @@ namespace Mono.CSharp
                                ShowTime ("Populate tree");
                        if (!RootContext.StdLib)
                                RootContext.BootCorlib_PopulateCoreTypes ();
-
                        RootContext.PopulateTypes ();
 
                        TypeManager.InitCodeHelpers ();
 
                        RootContext.DefineTypes ();
                        
-                       if (RootContext.Documentation != null &&
+                       if (Report.Errors == 0 &&
+                               RootContext.Documentation != null &&
                                !RootContext.Documentation.OutputDocComment (
                                        output_file))
                                return false;
@@ -1598,14 +1730,15 @@ namespace Mono.CSharp
                        //
                        // Verify using aliases now
                        //
-                       Namespace.VerifyUsing ();
+                       NamespaceEntry.VerifyAllUsing ();
                        
                        if (Report.Errors > 0){
                                return false;
                        }
+
+                       CodeGen.Assembly.Resolve ();
                        
                        if (RootContext.VerifyClsCompliance) {
-                               CodeGen.Assembly.ResolveClsCompliance ();
                                if (CodeGen.Assembly.IsClsCompliant) {
                                        AttributeTester.VerifyModulesClsCompliance ();
                                        TypeManager.LoadAllImportedTypes ();
@@ -1634,7 +1767,7 @@ namespace Mono.CSharp
                        RootContext.CloseTypes ();
 
                        PEFileKinds k = PEFileKinds.ConsoleApplication;
-                       
+
                        switch (RootContext.Target) {
                        case Target.Library:
                        case Target.Module:
@@ -1650,7 +1783,7 @@ namespace Mono.CSharp
 
                                if (ep == null) {
                                        if (RootContext.MainClass != null) {
-                                               DeclSpace main_cont = RootContext.Tree.GetDecl (MemberName.FromDotted (RootContext.MainClass));
+                                               DeclSpace main_cont = RootContext.ToplevelTypes.GetDefinition (RootContext.MainClass) as DeclSpace;
                                                if (main_cont == null) {
                                                        Report.Error (1555, "Could not find `{0}' specified for Main method", RootContext.MainClass); 
                                                        return false;
@@ -1676,56 +1809,13 @@ namespace Mono.CSharp
                                Report.Error (2017, "Cannot specify -main if building a module or library");
                        }
 
-                       //
-                       // Add the resources
-                       //
-                       if (resources != null){
-                               foreach (string spec in resources){
-                                       string file, res;
-                                       int cp;
-                                       
-                                       cp = spec.IndexOf (',');
-                                       if (cp != -1){
-                                               file = spec.Substring (0, cp);
-                                               res = spec.Substring (cp + 1);
-                                       } else
-                                               file = res = spec;
-
-                                       CodeGen.Assembly.Builder.AddResourceFile (res, file);
-                               }
-                       }
-                       
                        if (embedded_resources != null){
-                               object[] margs = new object [2];
-                               Type[] argst = new Type [2];
-                               argst [0] = argst [1] = typeof (string);
-
-                               MethodInfo 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");
-                               } else {
-                                       foreach (string spec in embedded_resources) {
-                                               int cp;
-
-                                               cp = spec.IndexOf (',');
-                                               if (cp != -1){
-                                                       margs [0] = spec.Substring (cp + 1);
-                                                       margs [1] = spec.Substring (0, cp);
-                                               } else {
-                                                       margs [1] = spec;
-                                                       margs [0] = Path.GetFileName (spec);
-                                               }
-
-                                               if (File.Exists ((string) margs [1]))
-                                                       embed_res.Invoke (CodeGen.Assembly.Builder, margs);
-                                               else {
-                                                       Report.Error (1566, "Can not find the resource " + margs [1]);
-                                               }
-                                       }
+                               if (RootContext.Target == Target.Module) {
+                                       Report.Error (1507, "Cannot link resource file when building a module");
+                                       return false;
                                }
+
+                               embedded_resources.Emit ();
                        }
 
                        //
@@ -1739,14 +1829,14 @@ namespace Mono.CSharp
                                        CodeGen.Assembly.Builder.DefineUnmanagedResource (win32ResourceFile);
                                }
                                catch (ArgumentException) {
-                                       Report.Warning (0, new Location (-1), "Cannot embed win32 resources on this runtime: try the Mono runtime instead.");
+                                       Report.RuntimeMissingSupport (Location.Null, "resource embeding");
                                }
                        }
 
                        if (win32IconFile != null) {
                                MethodInfo define_icon = typeof (AssemblyBuilder).GetMethod ("DefineIconResource", BindingFlags.Instance|BindingFlags.Public|BindingFlags.NonPublic);
                                if (define_icon == null) {
-                                       Report.Warning (0, new Location (-1), "Cannot embed icon resource on this runtime: try the Mono runtime instead.");
+                                       Report.RuntimeMissingSupport (Location.Null, "resource embeding");
                                }
                                define_icon.Invoke (CodeGen.Assembly.Builder, new object [] { win32IconFile });
                        }
@@ -1787,6 +1877,113 @@ namespace Mono.CSharp
                }
        }
 
+       class Resources
+       {
+               interface IResource
+               {
+                       void Emit ();
+                       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)
+                       {
+                               args = new object [3];
+                               args [0] = name;
+                               args [1] = file;
+                               args [2] = isPrivate ? ResourceAttributes.Private : ResourceAttributes.Public;
+                       }
+
+                       public void Emit()
+                       {
+                               embed_res.Invoke (CodeGen.Assembly.Builder, args);
+                       }
+
+                       public string FileName {
+                               get {
+                                       return (string)args [1];
+                               }
+                       }
+               }
+
+               class LinkedResource : IResource
+               {
+                       readonly string file;
+                       readonly string name;
+                       readonly ResourceAttributes attribute;
+
+                       public LinkedResource (string name, string file, bool isPrivate)
+                       {
+                               this.name = name;
+                               this.file = file;
+                               this.attribute = isPrivate ? ResourceAttributes.Private : ResourceAttributes.Public;
+                       }
+
+                       public void Emit ()
+                       {
+                               CodeGen.Assembly.Builder.AddResourceFile (name, Path.GetFileName(file), attribute);
+                       }
+
+                       public string FileName {
+                               get {
+                                       return file;
+                               }
+                       }
+               }
+
+
+               IDictionary embedded_resources = new HybridDictionary ();
+
+               public void Add (bool embeded, string file, string name)
+               {
+                       Add (embeded, file, name, false);
+               }
+
+               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);
+                               return;
+                       }
+                       IResource r = embeded ? 
+                               (IResource) new EmbededResource (name, file, isPrivate) : 
+                               new LinkedResource (name, file, isPrivate);
+
+                       embedded_resources.Add (name, r);
+               }
+
+               public void Emit ()
+               {
+                       foreach (IResource r in embedded_resources.Values) {
+                               if (!File.Exists (r.FileName)) {
+                                       Report.Error (1566, "Error reading resource file `{0}'", r.FileName);
+                                       continue;
+                               }
+                               
+                               r.Emit ();
+                       }
+               }
+       }
+
        //
        // This is the only public entry point
        //
@@ -1802,17 +1999,27 @@ namespace Mono.CSharp
                                Reset ();
                        }
                }
+
+               public static int[] AllWarningNumbers {
+                       get {
+                               return Report.AllWarnings;
+                       }
+               }
                
                static void Reset ()
                {
                        Driver.Reset ();
-                       Location.Reset ();
                        RootContext.Reset ();
+                       Tokenizer.Reset ();
+                       Location.Reset ();
                        Report.Reset ();
                        TypeManager.Reset ();
                        TypeHandle.Reset ();
-                       Namespace.Reset ();
+                       RootNamespace.Reset ();
+                       NamespaceEntry.Reset ();
                        CodeGen.Reset ();
+                       Attribute.Reset ();
+                       AttributeTester.Reset ();
                }
        }
 }