Expose code builder on generator result, and some tidying up

This commit is contained in:
Yishai Galatzer 2014-10-13 09:30:56 -07:00
parent 2637894ab6
commit 7364c6f6db
5 changed files with 16 additions and 13 deletions

View File

@ -56,4 +56,4 @@ namespace Microsoft.AspNet.Razor.Generator
/// </summary> /// </summary>
public string Checksum { get; set; } public string Checksum { get; set; }
} }
} }

View File

@ -1,9 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.AspNet.Razor.Parser.SyntaxTree; using Microsoft.AspNet.Razor.Parser.SyntaxTree;
namespace Microsoft.AspNet.Razor.Generator.Compiler namespace Microsoft.AspNet.Razor.Generator.Compiler

View File

@ -9,32 +9,38 @@ namespace Microsoft.AspNet.Razor
{ {
public class GeneratorResults : ParserResults public class GeneratorResults : ParserResults
{ {
public GeneratorResults(ParserResults parserResults, CodeBuilderResult codeBuilderResult) public GeneratorResults(ParserResults parserResults, CodeBuilderResult codeBuilderResult, CodeTree codeTree)
: this(parserResults.Document, : this(parserResults.Document,
parserResults.ParserErrors, parserResults.ParserErrors,
codeBuilderResult) codeBuilderResult,
codeTree)
{ {
} }
public GeneratorResults(Block document, public GeneratorResults(Block document,
IList<RazorError> parserErrors, IList<RazorError> parserErrors,
CodeBuilderResult codeBuilderResult) CodeBuilderResult codeBuilderResult,
: this(parserErrors.Count == 0, document, parserErrors, codeBuilderResult) CodeTree codeTree)
: this(parserErrors.Count == 0, document, parserErrors, codeBuilderResult, codeTree)
{ {
} }
protected GeneratorResults(bool success, protected GeneratorResults(bool success,
Block document, Block document,
IList<RazorError> parserErrors, IList<RazorError> parserErrors,
CodeBuilderResult codeBuilderResult) CodeBuilderResult codeBuilderResult,
CodeTree codeTree)
: base(success, document, parserErrors) : base(success, document, parserErrors)
{ {
GeneratedCode = codeBuilderResult.Code; GeneratedCode = codeBuilderResult.Code;
DesignTimeLineMappings = codeBuilderResult.DesignTimeLineMappings; DesignTimeLineMappings = codeBuilderResult.DesignTimeLineMappings;
CodeTree = codeTree;
} }
public string GeneratedCode { get; private set; } public string GeneratedCode { get; private set; }
public IList<LineMapping> DesignTimeLineMappings { get; private set; } public IList<LineMapping> DesignTimeLineMappings { get; private set; }
public CodeTree CodeTree { get; private set; }
} }
} }

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNet.Razor.Generator; using Microsoft.AspNet.Razor.Generator;
using Microsoft.AspNet.Razor.Generator.Compiler; using Microsoft.AspNet.Razor.Generator.Compiler;
using Microsoft.AspNet.Razor.Generator.Compiler.CSharp;
using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Parser;
using Microsoft.AspNet.Razor.TagHelpers; using Microsoft.AspNet.Razor.TagHelpers;

View File

@ -243,12 +243,12 @@ namespace Microsoft.AspNet.Razor
rootNamespace = (rootNamespace ?? Host.DefaultNamespace) ?? DefaultNamespace; rootNamespace = (rootNamespace ?? Host.DefaultNamespace) ?? DefaultNamespace;
// Run the parser // Run the parser
RazorParser parser = CreateParser(); var parser = CreateParser();
Debug.Assert(parser != null); Debug.Assert(parser != null);
ParserResults results = parser.Parse(input); var results = parser.Parse(input);
// Generate code // Generate code
RazorCodeGenerator generator = CreateCodeGenerator(className, rootNamespace, sourceFileName); var generator = CreateCodeGenerator(className, rootNamespace, sourceFileName);
generator.DesignTimeMode = Host.DesignTimeMode; generator.DesignTimeMode = Host.DesignTimeMode;
generator.Visit(results); generator.Visit(results);
@ -258,7 +258,7 @@ namespace Microsoft.AspNet.Razor
var builderResult = builder.Build(); var builderResult = builder.Build();
// Collect results and return // Collect results and return
return new GeneratorResults(results, builderResult); return new GeneratorResults(results, builderResult, codeBuilderContext.CodeTreeBuilder.CodeTree);
} }
protected internal virtual RazorCodeGenerator CreateCodeGenerator(string className, string rootNamespace, string sourceFileName) protected internal virtual RazorCodeGenerator CreateCodeGenerator(string className, string rootNamespace, string sourceFileName)