/// <summary> /// Perform the actual compilation of the scripts /// Things to note here: /// * The generated assembly reference the Castle.MonoRail.MonoRailBrail and Castle.MonoRail.Framework assemblies /// * If a common scripts assembly exist, it is also referenced /// * The AddBrailBaseClassStep compiler step is added - to create a class from the view's code /// * The ProcessMethodBodiesWithDuckTyping is replaced with ReplaceUknownWithParameters /// this allows to use naked parameters such as (output context.IsLocal) without using /// any special syntax /// * The FixTryGetParameterConditionalChecks is run afterward, to transform "if ?Error" to "if not ?Error isa IgnoreNull" /// * The ExpandDuckTypedExpressions is replace with a derived step that allows the use of Dynamic Proxy assemblies /// * The IntroduceGlobalNamespaces step is removed, to allow to use common variables such as /// date and list without accidently using the Boo.Lang.BuiltIn versions /// </summary> /// <param name="files"></param> /// <param name="name"></param> /// <returns></returns> private CompilationResult DoCompile(IEnumerable <ICompilerInput> files, string name) { var filesAsArray = new List <ICompilerInput>(files).ToArray(); var compiler = SetupCompiler(filesAsArray); var filename = Path.Combine(baseSavePath, name); compiler.Parameters.OutputAssembly = filename; // this is here and not in SetupCompiler since CompileCommon is also // using SetupCompiler, and we don't want reference to the old common from the new one if (common != null) { compiler.Parameters.References.Add(common); } // pre procsssor needs to run before the parser var processor = new BrailPreProcessor(this); compiler.Parameters.Pipeline.Insert(0, processor); // inserting the add class step after the parser compiler.Parameters.Pipeline.Insert(2, new TransformToBrailStep(options)); compiler.Parameters.Pipeline.Replace(typeof(ProcessMethodBodiesWithDuckTyping), new ReplaceUknownWithParameters()); compiler.Parameters.Pipeline.Replace(typeof(ExpandDuckTypedExpressions), new ExpandDuckTypedExpressions_WorkaroundForDuplicateVirtualMethods()); compiler.Parameters.Pipeline.Replace(typeof(InitializeTypeSystemServices), new InitializeCustomTypeSystem()); compiler.Parameters.Pipeline.InsertBefore(typeof(MacroAndAttributeExpansion), new FixTryGetParameterConditionalChecks()); compiler.Parameters.Pipeline.RemoveAt(compiler.Parameters.Pipeline.Find(typeof(IntroduceGlobalNamespaces))); return(new CompilationResult(compiler.Run(), processor)); }
private static void UnescapeInitialAndClosingDoubleQuotes(MacroStatement macro) { var value = macro.Arguments[0] as StringLiteralExpression; if (value == null) { return; } value.Value = BrailPreProcessor.UnescapeInitialAndClosingDoubleQuotes(value.Value); }
public CompilationResult(CompilerContext context, BrailPreProcessor processor) { this.context = context; this.processor = processor; }
/// <summary> /// Perform the actual compilation of the scripts /// Things to note here: /// * The generated assembly reference the Castle.MonoRail.MonoRailBrail and Castle.MonoRail.Framework assemblies /// * If a common scripts assembly exist, it is also referenced /// * The AddBrailBaseClassStep compiler step is added - to create a class from the view's code /// * The ProcessMethodBodiesWithDuckTyping is replaced with ReplaceUknownWithParameters /// this allows to use naked parameters such as (output context.IsLocal) without using /// any special syntax /// * The FixTryGetParameterConditionalChecks is run afterward, to transform "if ?Error" to "if not ?Error isa IgnoreNull" /// * The ExpandDuckTypedExpressions is replace with a derived step that allows the use of Dynamic Proxy assemblies /// * The IntroduceGlobalNamespaces step is removed, to allow to use common variables such as /// date and list without accidently using the Boo.Lang.BuiltIn versions /// </summary> /// <param name="files"></param> /// <param name="name"></param> /// <returns></returns> private CompilationResult DoCompile(IEnumerable<ICompilerInput> files, string name) { ICompilerInput[] filesAsArray = new List<ICompilerInput>(files).ToArray(); BooCompiler compiler = SetupCompiler(filesAsArray); string filename = Path.Combine(baseSavePath, name); compiler.Parameters.OutputAssembly = filename; // this is here and not in SetupCompiler since CompileCommon is also // using SetupCompiler, and we don't want reference to the old common from the new one if (common != null) { compiler.Parameters.References.Add(common); } // pre procsssor needs to run before the parser BrailPreProcessor processor = new BrailPreProcessor(this); compiler.Parameters.Pipeline.Insert(0, processor); // inserting the add class step after the parser compiler.Parameters.Pipeline.Insert(2, new TransformToBrailStep(options)); compiler.Parameters.Pipeline.Replace(typeof(ProcessMethodBodiesWithDuckTyping), new ReplaceUknownWithParameters()); compiler.Parameters.Pipeline.Replace(typeof(ExpandDuckTypedExpressions), new ExpandDuckTypedExpressions_WorkaroundForDuplicateVirtualMethods()); compiler.Parameters.Pipeline.Replace(typeof(InitializeTypeSystemServices), new InitializeCustomTypeSystem()); compiler.Parameters.Pipeline.InsertBefore(typeof(MacroAndAttributeExpansion), new FixTryGetParameterConditionalChecks()); compiler.Parameters.Pipeline.RemoveAt(compiler.Parameters.Pipeline.Find(typeof(IntroduceGlobalNamespaces))); return new CompilationResult(compiler.Run(), processor); }
/// <summary> /// Perform the actual compilation of the scripts /// Things to note here: /// * The generated assembly reference the Castle.MonoRail.MonoRailBrail and Castle.MonoRail.Framework assemblies /// * If a common scripts assembly exist, it is also referenced /// * The AddBrailBaseClassStep compiler step is added - to create a class from the view's code /// * The ProcessMethodBodiesWithDuckTyping is replaced with ReplaceUknownWithParameters /// this allows to use naked parameters such as (output context.IsLocal) without using /// any special syntax /// * The FixTryGetParameterConditionalChecks is run afterward, to transform "if ?Error" to "if not ?Error isa IgnoreNull" /// * The ExpandDuckTypedExpressions is replace with a derived step that allows the use of Dynamic Proxy assemblies /// * The IntroduceGlobalNamespaces step is removed, to allow to use common variables such as /// date and list without accidently using the Boo.Lang.BuiltIn versions /// </summary> /// <param name="files"></param> /// <param name="name"></param> /// <param name="viewname"> </param> /// <returns></returns> private CompilationResult DoCompile(IEnumerable<ICompilerInput> files, string name,string viewname) { var boomode = false; var filesAsArray = new List<ICompilerInput>(files).ToList(); var firstcode = files.First().Open().ReadToEnd(); var firstname = files.First().Name; filesAsArray.RemoveAt(0); filesAsArray.Insert(0, new StringInput(firstname, firstcode)); boomode = has_boo_only_mode(firstcode); if(boomode) { if(options.CollectStatistics) { Statistics.IsBoo(viewname); } } BooCompiler compiler = SetupCompiler(filesAsArray, boomode); string filename = Path.Combine(baseSavePath, name); compiler.Parameters.OutputAssembly = filename; // this is here and not in SetupCompiler since CompileCommon is also // using SetupCompiler, and we don't want reference to the old common from the new one /*if (common != null) { compiler.Parameters.References.Add(common); }*/ // pre procsssor needs to run before the parser var processor = new BrailPreProcessor(this, boomode); compiler.Parameters.Pipeline.Insert(0, processor); // inserting the add class step after the parser compiler.Parameters.Pipeline.Insert(2, new MONORAILTransformToBrailStep(options)); #if !LIB2 if (boomode) { compiler.Parameters.Pipeline.InsertAfter(typeof(Boo.Lang.Parser.BooParsingStep), new ExpandBmlStep()); compiler.Parameters.Pipeline.InsertAfter(typeof(Boo.Lang.Parser.BooParsingStep), new IncludeAstMacroExpandStep()); } else { compiler.Parameters.Pipeline.InsertAfter(typeof(Boo.Lang.Parser.WSABooParsingStep), new ExpandBmlStep()); compiler.Parameters.Pipeline.InsertAfter(typeof(Boo.Lang.Parser.WSABooParsingStep), new IncludeAstMacroExpandStep()); } #else if (boomode) { compiler.Parameters.Pipeline.InsertAfter(typeof(Boo.Lang.Parser.BooParsingStep), new ExpandBmlStep()); compiler.Parameters.Pipeline.InsertAfter(typeof(Boo.Lang.Parser.BooParsingStep), new IncludeAstMacroExpandStep()); } else { compiler.Parameters.Pipeline.InsertAfter(typeof(Boo.Lang.Parser.WSABooParsingStep), new ExpandBmlStep()); compiler.Parameters.Pipeline.InsertAfter(typeof(Boo.Lang.Parser.WSABooParsingStep), new IncludeAstMacroExpandStep()); } #endif compiler.Parameters.Pipeline.Replace(typeof(ProcessMethodBodiesWithDuckTyping), new ReplaceUknownWithParameters()); compiler.Parameters.Pipeline.Replace(typeof(ExpandDuckTypedExpressions), new ExpandDuckTypedExpressions_WorkaroundForDuplicateVirtualMethods()); #if !LIB2 compiler.Parameters.Pipeline.Replace(typeof(InitializeTypeSystemServices), new InitializeCustomTypeSystem()); #endif compiler.Parameters.Pipeline.InsertBefore(typeof(MacroAndAttributeExpansion), new FixTryGetParameterConditionalChecks()); compiler.Parameters.Pipeline.RemoveAt(compiler.Parameters.Pipeline.Find(typeof(IntroduceGlobalNamespaces))); //compiler.Parameters.Pipeline.InsertBefore(typeof (EmitAssembly), new PrintBoo()); var result = new CompilationResult(compiler.Run(), processor); if (options.SaveBooResult && HttpContext.Current!=null) { if (!string.IsNullOrEmpty(options.SaveBooResultDirectory)) { var dir = HttpContext.Current.Server.MapPath(options.SaveBooResultDirectory); Directory.CreateDirectory(dir); var file = Path.Combine( dir ,"last_boo.txt"); File.WriteAllText(file, result.Context.CompileUnit.ToCodeString()); } } return result; }