public void PrintLineNumber(dynamic node)
 {
     if (this.codeGenerator != null && this.codeGenerator.UseMcgLineNumbers)
     {
         this.CodePrinter.WriteLine();
         int lineNumber = node.GetSourceSpan().Start.Line;
         this.CodePrinter.WriteLine("#line {0} \"{1}\"", this.baseLineNumber + lineNumber, this.fileName);
     }
 }
 public void Process_Template(dynamic template)
 {
     if (template == null) return;
     try
     {
         this.PrintLineNumber(template);
         this.CodePrinter.Write("public List<string> Generated_{0}(", template.Name);
         if (template.Parameters != null)
         {
             string delim = "";
             foreach (dynamic param in template.Parameters)
             {
                 this.CodePrinter.Write(delim);
                 this.Process(param);
                 delim = ", ";
             }
         }
         this.CodePrinter.WriteLine(")");
         this.CodePrinter.WriteLine("{");
         if (template.Content != null)
         {
             this.BeginScope();
             if (template.Parameters != null)
             {
                 foreach (dynamic param in template.Parameters)
                 {
                     this.CurrentScope.Add(param.Name);
                 }
             }
             this.CodePrinter.AppendIndent("    ");
             this.CodePrinter.WriteLine("List<string> __result = new List<string>();");
             this.CodePrinter.WriteLine("using(TemplatePrinter __printer = new TemplatePrinter(__result))");
             this.CodePrinter.WriteLine("{");
             this.CodePrinter.AppendIndent("    ");
             int lineNumber = template.GetSourceSpan().Start.Line;
             foreach (dynamic line in template.Content)
             {
                 ++lineNumber;
                 this.baseLineNumber = lineNumber - 1;
                 string text = line.ToString();
                 OsloErrorReporter templateLineErrorReporter = new OsloErrorReporter();
                 dynamic program = this.rootCodeGenerator.TemplateParser.Parse(new StringReader(text), templateLineErrorReporter);
                 foreach (var error in templateLineErrorReporter.Errors)
                 {
                     this.rootCodeGenerator.ErrorReporter.Report(
                         new SourceLocation(
                             new SourceSpan(
                                 new SourcePoint(lineNumber, error.Location.Span.Start.Column),
                                 new SourcePoint(lineNumber, error.Location.Span.End.Column)),
                             error.Location.FileName),
                         error);
                 }
                 if (program != null)
                 {
                     bool hasStatement = false;
                     foreach (dynamic content in program.Content)
                     {
                         if (content.GetBrand() == "TemplateControl" && content.Statement != null)
                         {
                             hasStatement = true;
                         }
                         this.Process(content);
                     }
                     if (hasStatement)
                     {
                         this.CodePrinter.WriteLine("__printer.TrimLine();");
                     }
                     this.CodePrinter.WriteLine("__printer.WriteLine();");
                 }
                 else if (templateLineErrorReporter.ErrorCount == 0)
                 {
                     this.rootCodeGenerator.ErrorReporter.Error(
                         new SourceLocation(
                             new SourceSpan(
                                 new SourcePoint(lineNumber, 0),
                                 new SourcePoint(lineNumber, text.Length)),
                             this.codeGenerator.FileName),
                         "Could not process line in template {1}.", template.Name);
                 }
             }
             this.CodePrinter.ResetIndent();
             this.CodePrinter.WriteLine("}");
             this.CodePrinter.WriteLine("return __result;");
             this.CodePrinter.ResetIndent();
             this.EndScope();
         }
         this.CodePrinter.WriteLine("}");
         this.CodePrinter.ForcedWriteLine();
         ++this.functionCounter;
         this.rootCodeGenerator.Progress(this.functionCounter, this.rootCodeGenerator.FunctionCount);
     }
     finally
     {
         this.baseLineNumber = 0;
     }
 }