当前位置: 首页>>代码示例>>C#>>正文


C# CSharp.Driver类代码示例

本文整理汇总了C#中Mono.CSharp.Driver的典型用法代码示例。如果您正苦于以下问题:C# Driver类的具体用法?C# Driver怎么用?C# Driver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Driver类属于Mono.CSharp命名空间,在下文中一共展示了Driver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Create

		public static Driver Create (string[] args, bool require_files, ReportPrinter printer)
		{
			Driver d = new Driver (new CompilerContext (new Report (printer)));

			if (!d.ParseArguments (args, require_files))
				return null;

			return d;
		}
开发者ID:litoMalone,项目名称:mono,代码行数:9,代码来源:driver.cs

示例2: Create

		public static Driver Create (string[] args, bool require_files, Func<string [], int, int> unknown_option_parser, ReportPrinter printer)
		{
			Driver d = new Driver (new CompilerContext (new Report (printer)));

			if (!d.ParseArguments (args, require_files, unknown_option_parser))
				return null;

			return d;
		}
开发者ID:nekresh,项目名称:mono,代码行数:9,代码来源:driver.cs

示例3: InvokeCompiler

        public static bool InvokeCompiler(string [] args, TextWriter error)
        {
            try {
                CommandLineParser cmd = new CommandLineParser (error);
                var setting = cmd.ParseArguments (args);
                if (setting == null)
                    return false;

                var d = new Driver (new CompilerContext (setting, new StreamReportPrinter (error)));
                return d.Compile ();
            } finally {
                Reset ();
            }
        }
开发者ID:riviti,项目名称:NRefactory,代码行数:14,代码来源:driver.cs

示例4: Init

		/// <summary>
		///   Optional initialization for the Evaluator.
		/// </summary>
		/// <remarks>
		///  Initializes the Evaluator with the command line options
		///  that would be processed by the command line compiler.  Only
		///  the first call to Init will work, any future invocations are
		///  ignored.
		///
		///  You can safely avoid calling this method if your application
		///  does not need any of the features exposed by the command line
		///  interface.
		/// </remarks>
		public static void Init (string [] args)
		{
			lock (evaluator_lock){
				if (inited)
					return;
				
				RootContext.Version = LanguageVersion.Default;
				driver = Driver.Create (args, false);
				if (driver == null)
					throw new Exception ("Failed to create compiler driver with the given arguments");
				
				driver.ProcessDefaultConfig ();
				CompilerCallableEntryPoint.Reset ();
				Driver.LoadReferences ();
				RootContext.EvalMode = true;
				inited = true;
			}
		}
开发者ID:lewurm,项目名称:benchmarker,代码行数:31,代码来源:eval.cs

示例5: ParseStartupFiles

		void ParseStartupFiles ()
		{
			Driver d = new Driver (ctx);

			Location.Initialize (ctx.SourceFiles);

			for (int i = 0; i < startup_files; ++i) {
				var sf = ctx.SourceFiles [i];
				d.Parse (sf, module);
			}
		}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:11,代码来源:eval.cs

示例6: ParseStartupFiles

		void ParseStartupFiles ()
		{
			Driver d = new Driver (ctx);

			Location.Initialize (ctx.SourceFiles);

			var parser_session = new ParserSession ();
			for (int i = 0; i < startup_files; ++i) {
				var sf = ctx.SourceFiles [i];
				d.Parse (sf, module, parser_session, ctx.Report);
			}
		}
开发者ID:FrancisVarga,项目名称:mono,代码行数:12,代码来源:eval.cs

示例7: InitAndGetStartupFiles

		/// <summary>
		///   Optional initialization for the Evaluator.
		/// </summary>
		/// <remarks>
		///  Initializes the Evaluator with the command line
		///  options that would be processed by the command
		///  line compiler.  Only the first call to
		///  InitAndGetStartupFiles or Init will work, any future
		///  invocations are ignored.
		///
		///  You can safely avoid calling this method if your application
		///  does not need any of the features exposed by the command line
		///  interface.
		///
		///  This method return an array of strings that contains any
		///  files that were specified in `args'.
		/// </remarks>
		public static string [] InitAndGetStartupFiles (string [] args)
		{
			lock (evaluator_lock){
				if (inited)
					return new string [0];
				
				driver = Driver.Create (args, false, new ConsoleReportPrinter ());
				if (driver == null)
					throw new Exception ("Failed to create compiler driver with the given arguments");

				ctx = driver.ctx;

				RootContext.ToplevelTypes = new ModuleCompiled (ctx, true);
				
				driver.ProcessDefaultConfig ();

				var startup_files = new List<string> ();
				foreach (CompilationUnit file in Location.SourceFiles)
					startup_files.Add (file.Path);
				
				CompilerCallableEntryPoint.Reset ();
				RootContext.ToplevelTypes = new ModuleCompiled (ctx, true);
				var ctypes = TypeManager.InitCoreTypes ();

				ctx.MetaImporter.Initialize ();
				driver.LoadReferences ();
				TypeManager.InitCoreTypes (ctx, ctypes);
				TypeManager.InitOptionalCoreTypes (ctx);

				RootContext.EvalMode = true;
				inited = true;

				return startup_files.ToArray ();
			}
		}
开发者ID:silk,项目名称:monodevelop,代码行数:52,代码来源:eval.cs

示例8: InitAndGetStartupFiles

		/// <summary>
		///   Optional initialization for the Evaluator.
		/// </summary>
		/// <remarks>
		///  Initializes the Evaluator with the command line
		///  options that would be processed by the command
		///  line compiler.  Only the first call to
		///  InitAndGetStartupFiles or Init will work, any future
		///  invocations are ignored.
		///
		///  You can safely avoid calling this method if your application
		///  does not need any of the features exposed by the command line
		///  interface.
		///
		///  This method return an array of strings that contains any
		///  files that were specified in `args'.
		///
		///  If the unknownOptionParser is not null, this function is invoked
		///  with the current args array and the index of the option that is not
		///  known.  A value of true means that the value was processed, otherwise
		///  it will be reported as an error
		/// </remarks>
		public static string [] InitAndGetStartupFiles (string [] args, Func<string [], int, int> unknownOptionParser)
		{
			lock (evaluator_lock){
				if (inited)
					return new string [0];

				CompilerCallableEntryPoint.Reset ();
				var crp = new ConsoleReportPrinter ();
				driver = Driver.Create (args, false, unknownOptionParser, crp);
				if (driver == null)
					throw new Exception ("Failed to create compiler driver with the given arguments");

				crp.Fatal = driver.fatal_errors;
				ctx = driver.ctx;

				RootContext.ToplevelTypes = new ModuleContainer (ctx);
				
				var startup_files = new List<string> ();
				foreach (CompilationUnit file in Location.SourceFiles)
					startup_files.Add (file.Path);
				
				CompilerCallableEntryPoint.PartialReset ();

				var importer = new ReflectionImporter (ctx.BuildinTypes);
				loader = new DynamicLoader (importer, ctx);

				RootContext.ToplevelTypes.SetDeclaringAssembly (new AssemblyDefinitionDynamic (RootContext.ToplevelTypes, "temp"));

				loader.LoadReferences (RootContext.ToplevelTypes);
				ctx.BuildinTypes.CheckDefinitions (RootContext.ToplevelTypes);
				RootContext.ToplevelTypes.InitializePredefinedTypes ();

				RootContext.EvalMode = true;
				inited = true;

				return startup_files.ToArray ();
			}
		}
开发者ID:keith512,项目名称:mono,代码行数:60,代码来源:eval.cs

示例9: Compile

            public bool Compile(CompilerOptions options, ErrorReporterWrapper er)
            {
                string intermediateAssemblyFile = Path.GetTempFileName(), intermediateDocFile = Path.GetTempFileName();
                try {
                    // Compile the assembly
                    var settings = MapSettings(options, intermediateAssemblyFile, intermediateDocFile, er);
                    if (er.HasErrors)
                        return false;

                    if (!options.AlreadyCompiled) {
                        // Compile the assembly
                        var ctx = new CompilerContext(settings, new ConvertingReportPrinter(er));
                        var d = new Mono.CSharp.Driver(ctx);
                        d.Compile();
                        if (er.HasErrors)
                            return false;
                    }

                    // Compile the script
                    var md = new MetadataImporter.ScriptSharpMetadataImporter(options.MinimizeScript);
                    var n = new DefaultNamer();
                    PreparedCompilation compilation = null;
                    var rtl = new ScriptSharpRuntimeLibrary(md, er, n.GetTypeParameterName, tr => { var t = tr.Resolve(compilation.Compilation).GetDefinition(); return new JsTypeReferenceExpression(t.ParentAssembly, md.GetTypeSemantics(t).Name); });
                    var compiler = new Compiler.Compiler(md, n, rtl, er, allowUserDefinedStructs: options.References.Count == 0 /* We allow user-defined structs in mscorlib only, which can be identified by the fact that it has no references*/);

                    var references = LoadReferences(settings.AssemblyReferences, er);
                    if (references == null)
                        return false;

                    compilation = compiler.CreateCompilation(options.SourceFiles.Select(f => new SimpleSourceFile(f, settings.Encoding)), references, options.DefineConstants);
                    var compiledTypes = compiler.Compile(compilation);

                    var js = new ScriptSharpOOPEmulator(compilation.Compilation, md, rtl, er).Rewrite(compiledTypes, compilation.Compilation);
                    js = new GlobalNamespaceReferenceImporter().ImportReferences(js);

                    if (er.HasErrors)
                        return false;

                    string outputAssemblyPath = !string.IsNullOrEmpty(options.OutputAssemblyPath) ? options.OutputAssemblyPath : Path.ChangeExtension(options.SourceFiles[0], ".dll");
                    string outputScriptPath   = !string.IsNullOrEmpty(options.OutputScriptPath)   ? options.OutputScriptPath   : Path.ChangeExtension(options.SourceFiles[0], ".js");

                    if (!options.AlreadyCompiled) {
                        try {
                            File.Copy(intermediateAssemblyFile, outputAssemblyPath, true);
                        }
                        catch (IOException ex) {
                            er.Region = DomRegion.Empty;
                            er.Message(7950, ex.Message);
                            return false;
                        }
                        if (!string.IsNullOrEmpty(options.DocumentationFile)) {
                            try {
                                File.Copy(intermediateDocFile, options.DocumentationFile, true);
                            }
                            catch (IOException ex) {
                                er.Region = DomRegion.Empty;
                                er.Message(7952, ex.Message);
                                return false;
                            }
                        }
                    }

                    string script = string.Join("", js.Select(s => options.MinimizeScript ? OutputFormatter.FormatMinified(Minifier.Process(s)) : OutputFormatter.Format(s)));
                    try {
                        File.WriteAllText(outputScriptPath, script, settings.Encoding);
                    }
                    catch (IOException ex) {
                        er.Region = DomRegion.Empty;
                        er.Message(7951, ex.Message);
                        return false;
                    }
                    return true;
                }
                catch (Exception ex) {
                    er.Region = DomRegion.Empty;
                    er.InternalError(ex.ToString());
                    return false;
                }
                finally {
                    if (!options.AlreadyCompiled) {
                        try { File.Delete(intermediateAssemblyFile); } catch {}
                        try { File.Delete(intermediateDocFile); } catch {}
                    }
                }
            }
开发者ID:unintelligible,项目名称:SaltarelleCompiler,代码行数:85,代码来源:CompilerDriver.cs

示例10: Create

		public static Driver Create (string [] args, bool require_files)
		{
			Driver d = new Driver ();
			if (!d.ParseArguments (args, require_files))
				return null;

			return d;
		}
开发者ID:lewurm,项目名称:benchmarker,代码行数:8,代码来源:driver.cs

示例11: Compile

		public bool Compile(CompilerOptions options) {
			string intermediateAssemblyFile = Path.GetTempFileName(), intermediateDocFile = Path.GetTempFileName();
			var actualOut = Console.Out;
			var er = new ErrorReporterWrapper(_errorReporter, actualOut);
			try {
				Console.SetOut(new StringWriter());	// I don't trust the third-party libs to not generate spurious random messages, so make sure that any of those messages are suppressed.

				var settings = MapSettings(options, intermediateAssemblyFile, intermediateDocFile, er);
				if (er.HasErrors)
					return false;

				if (!options.AlreadyCompiled) {
					// Compile the assembly
					var ctx = new CompilerContext(settings, new ConvertingReportPrinter(er));
					var d = new Mono.CSharp.Driver(ctx);
					d.Compile();
					if (er.HasErrors)
						return false;
				}

				var references = LoadReferences(settings.AssemblyReferences, er);
				if (references == null)
					return false;

				PreparedCompilation compilation = PreparedCompilation.CreateCompilation(settings.AssemblyName, options.SourceFiles.Select(f => new SimpleSourceFile(f, settings.Encoding)), references.Select(r => r.Item1), options.DefineConstants, LoadResources(options.EmbeddedResources));

				IMethod entryPoint = FindEntryPoint(options, er, compilation);

				var container = new WindsorContainer();
				foreach (var plugin in TopologicalSortPlugins(references).Reverse())
					RegisterPlugin(container, plugin);

				container.Register(Component.For<IErrorReporter>().Instance(er),
				                   Component.For<CompilerOptions>().Instance(options),
				                   Component.For<ICompilation>().Instance(compilation.Compilation),
				                   Component.For<ICompiler>().ImplementedBy<Compiler.Compiler>()
				                  );

				container.Resolve<IMetadataImporter>().Prepare(compilation.Compilation.GetAllTypeDefinitions());

				var compiledTypes = container.Resolve<ICompiler>().Compile(compilation);

				foreach (var rewriter in container.ResolveAll<IJSTypeSystemRewriter>())
					compiledTypes = rewriter.Rewrite(compiledTypes);

				var invoker = new OOPEmulatorInvoker(container.Resolve<IOOPEmulator>(), container.Resolve<IMetadataImporter>(), container.Resolve<IErrorReporter>());

				var js = invoker.Process(compiledTypes.ToList(), entryPoint);
				js = container.Resolve<ILinker>().Process(js);

				if (er.HasErrors)
					return false;

				string outputAssemblyPath = !string.IsNullOrEmpty(options.OutputAssemblyPath) ? options.OutputAssemblyPath : Path.ChangeExtension(options.SourceFiles[0], ".dll");
				string outputScriptPath   = !string.IsNullOrEmpty(options.OutputScriptPath)   ? options.OutputScriptPath   : Path.ChangeExtension(options.SourceFiles[0], ".js");

				if (!options.AlreadyCompiled) {
					try {
						File.Copy(intermediateAssemblyFile, outputAssemblyPath, true);
					}
					catch (IOException ex) {
						er.Region = DomRegion.Empty;
						er.Message(Messages._7950, ex.Message);
						return false;
					}
					if (!string.IsNullOrEmpty(options.DocumentationFile)) {
						try {
							File.Copy(intermediateDocFile, options.DocumentationFile, true);
						}
						catch (IOException ex) {
							er.Region = DomRegion.Empty;
							er.Message(Messages._7952, ex.Message);
							return false;
						}
					}
				}

				if (options.MinimizeScript) {
					js = ((JsBlockStatement)Minifier.Process(JsStatement.Block(js))).Statements;
				}

				string script = options.MinimizeScript ? OutputFormatter.FormatMinified(js) : OutputFormatter.Format(js);
				try {
					File.WriteAllText(outputScriptPath, script, settings.Encoding);
				}
				catch (IOException ex) {
					er.Region = DomRegion.Empty;
					er.Message(Messages._7951, ex.Message);
					return false;
				}
				return true;
			}
			catch (Exception ex) {
				er.Region = DomRegion.Empty;
				er.InternalError(ex.ToString());
				return false;
			}
			finally {
				if (!options.AlreadyCompiled) {
					try { File.Delete(intermediateAssemblyFile); } catch {}
//.........这里部分代码省略.........
开发者ID:chenxustu1,项目名称:SaltarelleCompiler,代码行数:101,代码来源:CompilerDriver.cs

示例12: InitAndGetStartupFiles

		/// <summary>
		///   Optional initialization for the Evaluator.
		/// </summary>
		/// <remarks>
		///  Initializes the Evaluator with the command line
		///  options that would be processed by the command
		///  line compiler.  Only the first call to
		///  InitAndGetStartupFiles or Init will work, any future
		///  invocations are ignored.
		///
		///  You can safely avoid calling this method if your application
		///  does not need any of the features exposed by the command line
		///  interface.
		///
		///  This method return an array of strings that contains any
		///  files that were specified in `args'.
		/// </remarks>
		public static string [] InitAndGetStartupFiles (string [] args)
		{
			lock (evaluator_lock){
				if (inited)
					return new string [0];
				
				driver = Driver.Create (args, false, new ConsoleReportPrinter ());
				if (driver == null)
					throw new Exception ("Failed to create compiler driver with the given arguments");

				RootContext.ToplevelTypes = new ModuleContainer (ctx, true);
				
				driver.ProcessDefaultConfig ();

				ArrayList startup_files = new ArrayList ();
				foreach (CompilationUnit file in Location.SourceFiles)
					startup_files.Add (file.Path);
				
				CompilerCallableEntryPoint.Reset ();
				RootContext.ToplevelTypes = new ModuleContainer (ctx, true);

				driver.LoadReferences ();
				RootContext.EvalMode = true;
				inited = true;

				return (string []) startup_files.ToArray (typeof (string));
			}
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:45,代码来源:eval.cs

示例13: Parse

		public CompilationUnit Parse (Stream stream, string fileName, int lineModifier = 0)
		{
			lock (parseLock) {
				errorReportPrinter = new ErrorReportPrinter ("");
				var ctx = new CompilerContext (CompilerSettings, errorReportPrinter);
				ctx.Settings.TabSize = 1;
				var reader = new SeekableStreamReader (stream, Encoding.UTF8);
				var file = new SourceFile (fileName, fileName, 0);
				Location.Initialize (new List<SourceFile> (new [] { file }));
				var module = new ModuleContainer (ctx);
				var driver = new Driver (ctx);
				var parser = driver.Parse (reader, file, module);
				
				var top = new CompilerCompilationUnit () { 
					ModuleCompiled = module,
					LocationsBag = parser.LocationsBag,
					SpecialsBag = parser.Lexer.sbag
				};
				var unit = Parse (top, fileName, lineModifier);		
				unit.Errors.AddRange (errorReportPrinter.Errors);
				CompilerCallableEntryPoint.Reset ();
				return unit;
			}
		}
开发者ID:Netring,项目名称:ILSpy,代码行数:24,代码来源:CSharpParser.cs

示例14: ParseFile

		public static CompilerCompilationUnit ParseFile (string[] args, Stream input, string inputFile, ReportPrinter reportPrinter)
		{
			lock (parseLock) {
				try {
//                                     Driver d = Driver.Create (args, false, null, reportPrinter);
//                                     if (d == null)
//                                             return null;
       
                                       var r = new Report (reportPrinter);
                                       CommandLineParser cmd = new CommandLineParser (r, Console.Out);
                                       var setting = cmd.ParseArguments (args);
                                       if (setting == null || r.Errors > 0)
						return null;

                                       CompilerContext ctx = new CompilerContext (setting, r);
                                       var d = new Driver (ctx);

					Location.AddFile (null, inputFile);
					Location.Initialize ();
	
					// TODO: encoding from driver
					SeekableStreamReader reader = new SeekableStreamReader (input, Encoding.Default);
					
					RootContext.ToplevelTypes = new ModuleContainer (ctx);
					CompilationUnit unit = null;
					try {
						unit = (CompilationUnit) Location.SourceFiles [0];
					} catch (Exception) {
						string path = Path.GetFullPath (inputFile);
						unit = new CompilationUnit (inputFile, path, 0);
					}
					CSharpParser parser = new CSharpParser (reader, unit, RootContext.ToplevelTypes);
					parser.Lexer.TabSize = 1;
					parser.Lexer.sbag = new SpecialsBag ();
					parser.LocationsBag = new LocationsBag ();
					parser.UsingsBag = new UsingsBag ();
					parser.parse ();
					
					return new CompilerCompilationUnit () { ModuleCompiled = RootContext.ToplevelTypes, LocationsBag = parser.LocationsBag, UsingsBag = parser.UsingsBag, SpecialsBag = parser.Lexer.sbag };
				} finally {
					Reset ();
				}
			}
		}
开发者ID:sandyarmstrong,项目名称:monodevelop,代码行数:44,代码来源:driver.cs

示例15: Compile

            public bool Compile(CompilerOptions options, ErrorReporterWrapper er)
            {
                string intermediateAssemblyFile = Path.GetTempFileName(), intermediateDocFile = Path.GetTempFileName();
                try {
                    // Compile the assembly
                    var settings = MapSettings(options, intermediateAssemblyFile, intermediateDocFile, er);
                    if (er.HasErrors)
                        return false;

                    var ctx = new CompilerContext(settings, new ConvertingReportPrinter(er));
                    var d = new Mono.CSharp.Driver(ctx);
                    d.Compile();

                    if (er.HasErrors)
                        return false;

                    // Compile the script
                    var nc = new MetadataImporter.ScriptSharpMetadataImporter(options.MinimizeScript);
                    PreparedCompilation compilation = null;
                    var rtl = new ScriptSharpRuntimeLibrary(nc, tr => { var t = tr.Resolve(compilation.Compilation).GetDefinition(); return new JsTypeReferenceExpression(t.ParentAssembly, nc.GetTypeSemantics(t).Name); });
                    var compiler = new Saltarelle.Compiler.Compiler.Compiler(nc, rtl, er);

                    var references = LoadReferences(ctx.Settings.AssemblyReferences, er);
                    if (references == null)
                        return false;

                    compilation = compiler.CreateCompilation(options.SourceFiles.Select(f => new SimpleSourceFile(f)), references, options.DefineConstants);
                    var compiledTypes = compiler.Compile(compilation);

                    var js = new OOPEmulator.ScriptSharpOOPEmulator(nc, er).Rewrite(compiledTypes, compilation.Compilation);
                    js = new GlobalNamespaceReferenceImporter().ImportReferences(js);

                    if (er.HasErrors)
                        return false;

                    string outputAssemblyPath = !string.IsNullOrEmpty(options.OutputAssemblyPath) ? options.OutputAssemblyPath : Path.ChangeExtension(options.SourceFiles[0], ".dll");
                    string outputScriptPath   = !string.IsNullOrEmpty(options.OutputScriptPath)   ? options.OutputScriptPath   : Path.ChangeExtension(options.SourceFiles[0], ".js");

                    try {
                        File.Copy(intermediateAssemblyFile, outputAssemblyPath, true);
                    }
                    catch (IOException ex) {
                        er.Message(7950, null, TextLocation.Empty, ex.Message);
                        return false;
                    }
                    if (!string.IsNullOrEmpty(options.DocumentationFile)) {
                        try {
                            File.Copy(intermediateDocFile, options.DocumentationFile, true);
                        }
                        catch (IOException ex) {
                            er.Message(7952, null, TextLocation.Empty, ex.Message);
                            return false;
                        }
                    }

                    string script = string.Join("", js.Select(s => OutputFormatter.Format(s, allowIntermediates: false)));
                    try {
                        File.WriteAllText(outputScriptPath, script);
                    }
                    catch (IOException ex) {
                        er.Message(7951, null, TextLocation.Empty, ex.Message);
                        return false;
                    }
                    return true;
                }
                catch (Exception ex) {
                    er.InternalError(ex.ToString(), DomRegion.Empty);
                    return false;
                }
                finally {
                    try { File.Delete(intermediateAssemblyFile); } catch {}
                    try { File.Delete(intermediateDocFile); } catch {}
                }
            }
开发者ID:arnauddias,项目名称:SaltarelleCompiler,代码行数:74,代码来源:CompilerDriver.cs


注:本文中的Mono.CSharp.Driver类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。