/// <summary> /// Parse an arbitrary stream /// </summary> public override CodeCompileUnit Parse(System.IO.TextReader codeStream) { // get a better filename if we can string name = "<unknown>"; StreamReader sw = codeStream as StreamReader; if (sw != null) { FileStream fs = sw.BaseStream as FileStream; if (fs != null) { name = fs.Name; } } //!!! it'd be nice to have Parser.FromStream to get proper decodings here string codeText = codeStream.ReadToEnd(); CodeCompileUnit tree = Parse(Parser.FromString(state, new CompilerContext(), codeText), name); CodeMerger.CacheCode(tree, codeText); return(tree); }
protected override void GenerateCompileUnit(CodeCompileUnit e) { #if DEBUG try { #endif if (Options != null) { Options.BlankLinesBetweenMembers = false; } try { // fetch the merger, if one is available. When a merger // is available our internal write functions will write // to a cache. When we advance output we'll commit the // cache all at once. merger = CodeMerger.GetCachedCode(e); string oldNewline = Output.NewLine; if (merger != null) { AddNewImports(e); writeCache = new StringBuilder(); lastRow = 1; lastCol = 1; col = 1; row = 1; Output.NewLine = ""; } base.GenerateCompileUnit(e); if (merger != null) { // flush the writeCache for the last time, we need // to un-supress flush incase the last thing we wrote // suppressed it (this occurs when user code is at the // end of the code compile unit). suppressFlush = false; DoFlush(-1, -1); string finalText = merger.FinalizeMerge(); if (finalText != null) { Output.Write(finalText); } Output.NewLine = oldNewline; } } finally { merger = null; writeCache = null; } #if DEBUG } catch (Exception ex) { Console.WriteLine(ex.StackTrace); Debug.Assert(false, String.Format("Unexpected exception: {0}", ex.Message), ex.StackTrace); } #endif }