示例#1
0
        private static CompilerResults CompileBoo(string[] sourceFiles, string[] referencedAssemblies)
        {
            // Prepare parameters
            var cp = new Boo.Lang.Compiler.CompilerParameters();
            cp.Pipeline = new CompileToMemory();
            cp.Ducky = true;
            cp.Debug = true;
            cp.OutputType = Boo.Lang.Compiler.CompilerOutputType.Library;
            cp.DefaultMethodVisibility = Boo.Lang.Compiler.Ast.TypeMemberModifiers.Public;

            // References
            cp.References.Add(typeof(System.Windows.Forms.Form).Assembly);
            cp.References.Add(typeof(System.Drawing.Color).Assembly);
            cp.References.Add(typeof(System.Xml.XmlDocument).Assembly);

            // .NET 3.5
            if (Net35) {
                if (coreAssembly == null) {
                    coreAssembly = Assembly.LoadWithPartialName("System.Core");
                }
                cp.References.Add(coreAssembly);
            }

            // Add input files
            foreach (string file in sourceFiles) {
                string ext = Path.GetExtension(file);
                if (String.Compare(ext, ".boo", StringComparison.InvariantCultureIgnoreCase) == 0) {
                    cp.Input.Add(new Boo.Lang.Compiler.IO.FileInput(file));
                }
                else if (ext.ToLowerInvariant() == ".resx") {
                    cp.Resources.Add(new Boo.Lang.Compiler.Resources.EmbeddedFileResource(file));
                }
            }

            if (cp.Input.Count == 0) {
                // Nothing to compile
                return null;
            }

            // Create compiler
            Boo.Lang.Compiler.BooCompiler booc = new Boo.Lang.Compiler.BooCompiler(cp);

            var ctx = booc.Run();

            // Convert result
            CompilerResults result = new CompilerResults(null);
            result.CompiledAssembly = ctx.GeneratedAssembly;

            result.Output.Add(booc.GetType().AssemblyQualifiedName);
            result.Output.Add("");

            foreach (Boo.Lang.Compiler.CompilerWarning w in ctx.Warnings) {
                result.Output.Add(w.ToString());
            }

            foreach (Boo.Lang.Compiler.CompilerError e in ctx.Errors) {
                result.Output.Add(e.ToString());
                result.Errors.Add(new CompilerError(e.LexicalInfo.FileName, e.LexicalInfo.Line, e.LexicalInfo.Column, e.Code, e.Message));
            }

            return result;
        }
示例#2
0
        private static CompilerResults CompileBoo(string[] sourceFiles, string[] referencedAssemblies)
        {
            // Prepare parameters
            var cp = new Boo.Lang.Compiler.CompilerParameters();

            cp.Pipeline   = new CompileToMemory();
            cp.Ducky      = true;
            cp.Debug      = true;
            cp.OutputType = Boo.Lang.Compiler.CompilerOutputType.Library;
            cp.DefaultMethodVisibility = Boo.Lang.Compiler.Ast.TypeMemberModifiers.Public;

            // References
            cp.References.Add(typeof(System.Windows.Forms.Form).Assembly);
            cp.References.Add(typeof(System.Drawing.Color).Assembly);
            cp.References.Add(typeof(System.Xml.XmlDocument).Assembly);

            // .NET 3.5
            if (Net35)
            {
                if (coreAssembly == null)
                {
                    coreAssembly = Assembly.LoadWithPartialName("System.Core");
                }
                cp.References.Add(coreAssembly);
            }

            // Add input files
            foreach (string file in sourceFiles)
            {
                string ext = Path.GetExtension(file);
                if (String.Compare(ext, ".boo", StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    cp.Input.Add(new Boo.Lang.Compiler.IO.FileInput(file));
                }
                else if (ext.ToLowerInvariant() == ".resx")
                {
                    cp.Resources.Add(new Boo.Lang.Compiler.Resources.EmbeddedFileResource(file));
                }
            }

            if (cp.Input.Count == 0)
            {
                // Nothing to compile
                return(null);
            }

            // Create compiler
            Boo.Lang.Compiler.BooCompiler booc = new Boo.Lang.Compiler.BooCompiler(cp);

            var ctx = booc.Run();

            // Convert result
            CompilerResults result = new CompilerResults(null);

            result.CompiledAssembly = ctx.GeneratedAssembly;

            result.Output.Add(booc.GetType().AssemblyQualifiedName);
            result.Output.Add("");

            foreach (Boo.Lang.Compiler.CompilerWarning w in ctx.Warnings)
            {
                result.Output.Add(w.ToString());
            }

            foreach (Boo.Lang.Compiler.CompilerError e in ctx.Errors)
            {
                result.Output.Add(e.ToString());
                result.Errors.Add(new CompilerError(e.LexicalInfo.FileName, e.LexicalInfo.Line, e.LexicalInfo.Column, e.Code, e.Message));
            }

            return(result);
        }