Rework gc descriptor to include size information in more cases.
[mono.git] / mcs / mcs / driver.cs
index 7b5acc819760800db4960e13781e396d926711cd..ef3467e45d3e2e52b35650e6624f14f9652dae99 100644 (file)
@@ -9,6 +9,7 @@
 //
 // Copyright 2001, 2002, 2003 Ximian, Inc (http://www.ximian.com)
 // Copyright 2004, 2005, 2006, 2007, 2008 Novell, Inc
+// Copyright 2011 Xamarin Inc
 //
 
 using System;
@@ -40,7 +41,7 @@ namespace Mono.CSharp
                        }
                }
 
-               void tokenize_file (CompilationUnit file)
+               void tokenize_file (CompilationSourceFile file)
                {
                        Stream input;
 
@@ -69,20 +70,20 @@ namespace Mono.CSharp
 
                void Parse (ModuleContainer module)
                {
-                       Location.Initialize ();
+                       Location.Initialize (module.Compiler.SourceFiles);
 
-                       bool tokenize_only = ctx.Settings.TokenizeOnly;
-                       var cu = Location.SourceFiles;
-                       for (int i = 0; i < cu.Count; ++i) {
+                       bool tokenize_only = module.Compiler.Settings.TokenizeOnly;
+                       var sources = module.Compiler.SourceFiles;
+                       for (int i = 0; i < sources.Count; ++i) {
                                if (tokenize_only) {
-                                       tokenize_file (cu[i]);
+                                       tokenize_file (sources[i]);
                                } else {
-                                       Parse (cu[i], module);
+                                       Parse (sources[i], module);
                                }
                        }
                }
 
-               void Parse (CompilationUnit file, ModuleContainer module)
+               public void Parse (CompilationSourceFile file, ModuleContainer module)
                {
                        Stream input;
 
@@ -108,9 +109,11 @@ namespace Mono.CSharp
                        input.Close ();
                }       
                
-               public void Parse (SeekableStreamReader reader, CompilationUnit file, ModuleContainer module)
+               public void Parse (SeekableStreamReader reader, CompilationSourceFile file, ModuleContainer module)
                {
-                       CSharpParser parser = new CSharpParser (reader, file, module);
+                       file.NamespaceContainer = new NamespaceContainer (null, module, null, file);
+
+                       CSharpParser parser = new CSharpParser (reader, file);
                        parser.parse ();
                }
                
@@ -197,7 +200,7 @@ namespace Mono.CSharp
                        // If we are an exe, require a source file for the entry point or
                        // if there is nothing to put in the assembly, and we are not a library
                        //
-                       if (Location.FirstFile == null &&
+                       if (settings.FirstSourceFile == null &&
                                ((settings.Target == Target.Exe || settings.Target == Target.WinExe || settings.Target == Target.Module) ||
                                settings.Resources == null)) {
                                Report.Error (2008, "No files to compile were specified");
@@ -218,22 +221,23 @@ namespace Mono.CSharp
                        if (Report.Errors > 0)
                                return false;
 
-                       if (settings.TokenizeOnly || settings.ParseOnly)
+                       if (settings.TokenizeOnly || settings.ParseOnly) {
+                               tr.StopTotal ();
+                               tr.ShowStats ();
                                return true;
-
-                       if (RootContext.ToplevelTypes.NamespaceEntry != null)
-                               throw new InternalErrorException ("who set it?");
+                       }
 
                        var output_file = settings.OutputFile;
                        string output_file_name;
                        if (output_file == null) {
-                               output_file_name = Location.FirstFile;
+                               var source_file = settings.FirstSourceFile;
 
-                               if (output_file_name == null) {
+                               if (source_file == null) {
                                        Report.Error (1562, "If no source files are specified you must specify the output file with -out:");
                                        return false;
                                }
 
+                               output_file_name = source_file.Name;
                                int pos = output_file_name.LastIndexOf ('.');
 
                                if (pos > 0)
@@ -266,7 +270,7 @@ namespace Mono.CSharp
                        references_loader.LoadReferences (module);
 
                        tr.Start (TimeReporter.TimerType.PredefinedTypesInit);
-                       if (!ctx.BuildinTypes.CheckDefinitions (module))
+                       if (!ctx.BuiltinTypes.CheckDefinitions (module))
                                return false;
 
                        tr.Stop (TimeReporter.TimerType.PredefinedTypesInit);
@@ -276,13 +280,13 @@ namespace Mono.CSharp
                        var assembly = new AssemblyDefinitionDynamic (module, output_file_name, output_file);
                        module.SetDeclaringAssembly (assembly);
 
-                       var importer = new ReflectionImporter (module, ctx.BuildinTypes);
+                       var importer = new ReflectionImporter (module, ctx.BuiltinTypes);
                        assembly.Importer = importer;
 
                        var loader = new DynamicLoader (importer, ctx);
                        loader.LoadReferences (module);
 
-                       if (!ctx.BuildinTypes.CheckDefinitions (module))
+                       if (!ctx.BuiltinTypes.CheckDefinitions (module))
                                return false;
 
                        if (!assembly.Create (AppDomain.CurrentDomain, AssemblyBuilderAccess.Save))
@@ -292,6 +296,14 @@ namespace Mono.CSharp
 
                        loader.LoadModules (assembly, module.GlobalRootNamespace);
 #endif
+                       module.InitializePredefinedTypes ();
+
+                       tr.Start (TimeReporter.TimerType.UsingResolve);
+                       foreach (var source_file in ctx.SourceFiles) {
+                               source_file.NamespaceContainer.Define ();
+                       }
+                       tr.Stop (TimeReporter.TimerType.UsingResolve);
+
                        tr.Start (TimeReporter.TimerType.ModuleDefinitionTotal);
                        module.Define ();
                        tr.Stop (TimeReporter.TimerType.ModuleDefinitionTotal);
@@ -299,20 +311,9 @@ namespace Mono.CSharp
                        if (Report.Errors > 0)
                                return false;
 
-                       if (settings.Documentation != null &&
-                               !settings.Documentation.OutputDocComment (
-                                       output_file, Report))
-                               return false;
-
-                       //
-                       // Verify using aliases now
-                       //
-                       tr.Start (TimeReporter.TimerType.UsingVerification);
-                       NamespaceEntry.VerifyAllUsing ();
-                       tr.Stop (TimeReporter.TimerType.UsingVerification);
-                       
-                       if (Report.Errors > 0){
-                               return false;
+                       if (settings.DocumentationFile != null) {
+                               var doc = new DocumentationBuilder (module);
+                               doc.OutputDocComment (output_file, settings.DocumentationFile);
                        }
 
                        assembly.Resolve ();
@@ -396,22 +397,12 @@ namespace Mono.CSharp
                        if (!full_flag)
                                return;
 
-                       RootContext.Reset (full_flag);
-                       ReferenceContainer.Reset ();
-                       PointerContainer.Reset ();
-                       Parameter.Reset ();
-
-                       StringConcat.Reset ();
-                       
-                       NamespaceEntry.Reset ();
-                       Attribute.Reset ();
                        AnonymousTypeClass.Reset ();
                        AnonymousMethodBody.Reset ();
                        AnonymousMethodStorey.Reset ();
                        SymbolWriter.Reset ();
                        Switch.Reset ();
                        Linq.QueryBlock.TransparentParameter.Reset ();
-                       Convert.Reset ();
                        TypeInfo.Reset ();
                }
        }