Exemple #1
0
		//
		// Main compilation method
		//
		public bool Compile ()
		{
			var module = new ModuleContainer (ctx);
			RootContext.ToplevelTypes = module;

			if (timestamps) {
				stopwatch = Stopwatch.StartNew ();
				first_time = DateTime.Now;
			}

			Parse (module);
			ShowTime ("Parsing source files");

			if (Report.Errors > 0)
				return false;

			if (tokenize || parse_only)
				return true;

			if (RootContext.ToplevelTypes.NamespaceEntry != null)
				throw new InternalErrorException ("who set it?");

			//
			// 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)
					output_file = first_source.Substring (0, pos) + RootContext.TargetExt;
				else
					output_file = first_source + RootContext.TargetExt;
			}

			//
			// Load assemblies required
			//
			if (timestamps)
				stopwatch = Stopwatch.StartNew ();

			var assembly = module.MakeExecutable (output_file, output_file);

			var importer = new ReflectionImporter (ctx.BuildinTypes);
			assembly.Importer = importer;

			var loader = new DynamicLoader (importer, ctx);
			loader.LoadReferences (module);

			ShowTime ("Imporing referenced assemblies");

			if (!ctx.BuildinTypes.CheckDefinitions (module))
				return false;

			ShowTime ("Initializing predefined types");

			if (!assembly.Create (AppDomain.CurrentDomain, AssemblyBuilderAccess.Save))
				return false;

			loader.LoadModules (assembly);

			module.Define ();

			ShowTime ("Types definition");

			if (Report.Errors > 0)
				return false;

			if (Report.Errors == 0 &&
				RootContext.Documentation != null &&
				!RootContext.Documentation.OutputDocComment (
					output_file, Report))
				return false;

			//
			// Verify using aliases now
			//
			NamespaceEntry.VerifyAllUsing ();
			
			if (Report.Errors > 0){
				return false;
			}

			assembly.Resolve ();
			
			if (Report.Errors > 0)
				return false;
			
			//
			// The code generator
			//
			if (timestamps)
				stopwatch = Stopwatch.StartNew ();

			assembly.Emit ();

			ShowTime ("Resolving and emitting members blocks");

			if (Report.Errors > 0){
				return false;
			}

			module.CloseType ();

			ShowTime ("Closing types");

			if (timestamps)
				stopwatch = Stopwatch.StartNew ();

			assembly.EmbedResources ();
			ShowTime ("Embedding resources");

			if (Report.Errors > 0)
				return false;

			if (timestamps)
				stopwatch = Stopwatch.StartNew ();
			
			assembly.Save ();

			ShowTime ("Saving output assembly");

			if (RootContext.GenerateDebugInfo) {
				SymbolWriter.WriteSymbolFile ();
				ShowTime ("Saving debug symbols");
			}

			ShowTotalTime ("Total");

			Timer.ShowTimers ();

			return (Report.Errors == 0);
		}