Rename RazorIRNode

Get rid of references to 'IR'
This commit is contained in:
Ryan Nowak 2017-06-21 12:55:16 -07:00
parent d2469e078a
commit 21e26ad4aa
345 changed files with 7213 additions and 7220 deletions

View File

@ -7,21 +7,21 @@ using Microsoft.AspNetCore.Razor.Language.Intermediate;
namespace Microsoft.AspNetCore.Mvc.Razor.Extensions namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{ {
public class AssemblyAttributeInjectionPass : RazorIRPassBase, IRazorIROptimizationPass public class AssemblyAttributeInjectionPass : IntermediateNodePassBase, IRazorOptimizationPass
{ {
private const string RazorViewAttribute = "global::Microsoft.AspNetCore.Mvc.Razor.Compilation.RazorViewAttribute"; private const string RazorViewAttribute = "global::Microsoft.AspNetCore.Mvc.Razor.Compilation.RazorViewAttribute";
private const string RazorPageAttribute = "global::Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.RazorPageAttribute"; private const string RazorPageAttribute = "global::Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.RazorPageAttribute";
protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNode irDocument) protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
{ {
var @namespace = irDocument.FindPrimaryNamespace(); var @namespace = documentNode.FindPrimaryNamespace();
if (@namespace == null || string.IsNullOrEmpty(@namespace.Content)) if (@namespace == null || string.IsNullOrEmpty(@namespace.Content))
{ {
// No namespace node or it's incomplete. Skip. // No namespace node or it's incomplete. Skip.
return; return;
} }
var @class = irDocument.FindPrimaryClass(); var @class = documentNode.FindPrimaryClass();
if (@class == null || string.IsNullOrEmpty(@class.Name)) if (@class == null || string.IsNullOrEmpty(@class.Name))
{ {
// No class node or it's incomplete. Skip. // No class node or it's incomplete. Skip.
@ -33,12 +33,12 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
var escapedPath = EscapeAsVerbatimLiteral(path); var escapedPath = EscapeAsVerbatimLiteral(path);
string attribute; string attribute;
if (irDocument.DocumentKind == MvcViewDocumentClassifierPass.MvcViewDocumentKind) if (documentNode.DocumentKind == MvcViewDocumentClassifierPass.MvcViewDocumentKind)
{ {
attribute = $"[assembly:{RazorViewAttribute}({escapedPath}, typeof({generatedTypeName}))]"; attribute = $"[assembly:{RazorViewAttribute}({escapedPath}, typeof({generatedTypeName}))]";
} }
else if (irDocument.DocumentKind == RazorPageDocumentClassifierPass.RazorPageDocumentKind && else if (documentNode.DocumentKind == RazorPageDocumentClassifierPass.RazorPageDocumentKind &&
PageDirective.TryGetPageDirective(irDocument, out var pageDirective)) PageDirective.TryGetPageDirective(documentNode, out var pageDirective))
{ {
var escapedRoutePrefix = EscapeAsVerbatimLiteral(pageDirective.RouteTemplate); var escapedRoutePrefix = EscapeAsVerbatimLiteral(pageDirective.RouteTemplate);
attribute = $"[assembly:{RazorPageAttribute}({escapedPath}, typeof({generatedTypeName}), {escapedRoutePrefix})]"; attribute = $"[assembly:{RazorPageAttribute}({escapedPath}, typeof({generatedTypeName}), {escapedRoutePrefix})]";
@ -48,18 +48,18 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
return; return;
} }
var index = irDocument.Children.IndexOf(@namespace); var index = documentNode.Children.IndexOf(@namespace);
Debug.Assert(index >= 0); Debug.Assert(index >= 0);
var pageAttribute = new CSharpCodeIRNode(); var pageAttribute = new CSharpCodeIntermediateNode();
RazorIRBuilder.Create(pageAttribute) IntermediateNodeBuilder.Create(pageAttribute)
.Add(new RazorIRToken() .Add(new IntermediateToken()
{ {
Kind = RazorIRToken.TokenKind.CSharp, Kind = IntermediateToken.TokenKind.CSharp,
Content = attribute, Content = attribute,
}); });
irDocument.Children.Insert(index, pageAttribute); documentNode.Children.Insert(index, pageAttribute);
} }
private static string EscapeAsVerbatimLiteral(string value) private static string EscapeAsVerbatimLiteral(string value)

View File

@ -5,8 +5,8 @@ using Microsoft.AspNetCore.Razor.Language.CodeGeneration;
namespace Microsoft.AspNetCore.Mvc.Razor.Extensions namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{ {
public interface IInjectDirectiveTargetExtension : ICodeTargetExtension public interface IInjectTargetExtension : ICodeTargetExtension
{ {
void WriteInjectProperty(CSharpRenderingContext context, InjectDirectiveIRNode node); void WriteInjectProperty(CSharpRenderingContext context, InjectIntermediateNode node);
} }
} }

View File

@ -20,19 +20,20 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{ {
builder.AddDirective(Directive); builder.AddDirective(Directive);
builder.Features.Add(new Pass()); builder.Features.Add(new Pass());
builder.AddTargetExtension(new InjectTargetExtension());
return builder; return builder;
} }
internal class Pass : RazorIRPassBase, IRazorDirectiveClassifierPass internal class Pass : IntermediateNodePassBase, IRazorDirectiveClassifierPass
{ {
// Runs after the @model and @namespace directives // Runs after the @model and @namespace directives
public override int Order => 10; public override int Order => 10;
protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNode irDocument) protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
{ {
var visitor = new Visitor(); var visitor = new Visitor();
visitor.Visit(irDocument); visitor.Visit(documentNode);
var modelType = ModelDirective.GetModelType(irDocument); var modelType = ModelDirective.GetModelType(documentNode);
var properties = new HashSet<string>(StringComparer.Ordinal); var properties = new HashSet<string>(StringComparer.Ordinal);
@ -55,7 +56,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
typeName = typeName.Replace("<TModel>", "<" + modelType + ">"); typeName = typeName.Replace("<TModel>", "<" + modelType + ">");
var injectNode = new InjectDirectiveIRNode() var injectNode = new InjectIntermediateNode()
{ {
TypeName = typeName, TypeName = typeName,
MemberName = memberName, MemberName = memberName,
@ -66,13 +67,13 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
} }
} }
private class Visitor : RazorIRNodeWalker private class Visitor : IntermediateNodeWalker
{ {
public ClassDeclarationIRNode Class { get; private set; } public ClassDeclarationIntermediateNode Class { get; private set; }
public IList<DirectiveIRNode> Directives { get; } = new List<DirectiveIRNode>(); public IList<DirectiveIntermediateNode> Directives { get; } = new List<DirectiveIntermediateNode>();
public override void VisitClassDeclaration(ClassDeclarationIRNode node) public override void VisitClassDeclaration(ClassDeclarationIntermediateNode node)
{ {
if (Class == null) if (Class == null)
{ {
@ -82,7 +83,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
base.VisitClassDeclaration(node); base.VisitClassDeclaration(node);
} }
public override void VisitDirective(DirectiveIRNode node) public override void VisitDirective(DirectiveIntermediateNode node)
{ {
if (node.Descriptor == Directive) if (node.Descriptor == Directive)
{ {

View File

@ -8,22 +8,22 @@ using Microsoft.AspNetCore.Razor.Language.Intermediate;
namespace Microsoft.AspNetCore.Mvc.Razor.Extensions namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{ {
public class InjectDirectiveIRNode : ExtensionIRNode public class InjectIntermediateNode : ExtensionIntermediateNode
{ {
public string TypeName { get; set; } public string TypeName { get; set; }
public string MemberName { get; set; } public string MemberName { get; set; }
public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance; public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance;
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
if (visitor == null) if (visitor == null)
{ {
throw new ArgumentNullException(nameof(visitor)); throw new ArgumentNullException(nameof(visitor));
} }
AcceptExtensionNode<InjectDirectiveIRNode>(this, visitor); AcceptExtensionNode<InjectIntermediateNode>(this, visitor);
} }
public override void WriteNode(CodeTarget target, CSharpRenderingContext context) public override void WriteNode(CodeTarget target, CSharpRenderingContext context)
@ -38,10 +38,10 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
throw new ArgumentNullException(nameof(context)); throw new ArgumentNullException(nameof(context));
} }
var extension = target.GetExtension<IInjectDirectiveTargetExtension>(); var extension = target.GetExtension<IInjectTargetExtension>();
if (extension == null) if (extension == null)
{ {
context.ReportMissingExtension<IInjectDirectiveTargetExtension>(); context.ReportMissingExtension<IInjectTargetExtension>();
return; return;
} }

View File

@ -6,11 +6,11 @@ using Microsoft.AspNetCore.Razor.Language.CodeGeneration;
namespace Microsoft.AspNetCore.Mvc.Razor.Extensions namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{ {
public class InjectDirectiveTargetExtension : IInjectDirectiveTargetExtension public class InjectTargetExtension : IInjectTargetExtension
{ {
private const string RazorInjectAttribute = "[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]"; private const string RazorInjectAttribute = "[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]";
public void WriteInjectProperty(CSharpRenderingContext context, InjectDirectiveIRNode node) public void WriteInjectProperty(CSharpRenderingContext context, InjectIntermediateNode node)
{ {
if (context == null) if (context == null)
{ {

View File

@ -8,14 +8,14 @@ using Microsoft.AspNetCore.Razor.Language.Intermediate;
namespace Microsoft.AspNetCore.Mvc.Razor.Extensions namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{ {
public class InstrumentationPass : RazorIRPassBase, IRazorIROptimizationPass public class InstrumentationPass : IntermediateNodePassBase, IRazorOptimizationPass
{ {
public override int Order => DefaultFeatureOrder; public override int Order => DefaultFeatureOrder;
protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNode irDocument) protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
{ {
var walker = new Visitor(); var walker = new Visitor();
walker.VisitDocument(irDocument); walker.VisitDocument(documentNode);
for (var i = 0; i < walker.Items.Count; i++) for (var i = 0; i < walker.Items.Count; i++)
{ {
@ -30,11 +30,11 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
var beginContextMethodName = "BeginContext"; /* ORIGINAL: BeginContextMethodName */ var beginContextMethodName = "BeginContext"; /* ORIGINAL: BeginContextMethodName */
var endContextMethodName = "EndContext"; /* ORIGINAL: EndContextMethodName */ var endContextMethodName = "EndContext"; /* ORIGINAL: EndContextMethodName */
var beginNode = new CSharpCodeIRNode(); var beginNode = new CSharpCodeIntermediateNode();
RazorIRBuilder.Create(beginNode) IntermediateNodeBuilder.Create(beginNode)
.Add(new RazorIRToken() .Add(new IntermediateToken()
{ {
Kind = RazorIRToken.TokenKind.CSharp, Kind = IntermediateToken.TokenKind.CSharp,
Content = string.Format("{0}({1}, {2}, {3});", Content = string.Format("{0}({1}, {2}, {3});",
beginContextMethodName, beginContextMethodName,
item.Source.AbsoluteIndex.ToString(CultureInfo.InvariantCulture), item.Source.AbsoluteIndex.ToString(CultureInfo.InvariantCulture),
@ -42,11 +42,11 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
item.IsLiteral ? "true" : "false") item.IsLiteral ? "true" : "false")
}); });
var endNode = new CSharpCodeIRNode(); var endNode = new CSharpCodeIntermediateNode();
RazorIRBuilder.Create(endNode) IntermediateNodeBuilder.Create(endNode)
.Add(new RazorIRToken() .Add(new IntermediateToken()
{ {
Kind = RazorIRToken.TokenKind.CSharp, Kind = IntermediateToken.TokenKind.CSharp,
Content = string.Format("{0}();", endContextMethodName) Content = string.Format("{0}();", endContextMethodName)
}); });
@ -57,7 +57,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
private struct InstrumentationItem private struct InstrumentationItem
{ {
public InstrumentationItem(RazorIRNode node, RazorIRNode parent, bool isLiteral, SourceSpan source) public InstrumentationItem(IntermediateNode node, IntermediateNode parent, bool isLiteral, SourceSpan source)
{ {
Node = node; Node = node;
Parent = parent; Parent = parent;
@ -65,20 +65,20 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
Source = source; Source = source;
} }
public RazorIRNode Node { get; } public IntermediateNode Node { get; }
public RazorIRNode Parent { get; } public IntermediateNode Parent { get; }
public bool IsLiteral { get; } public bool IsLiteral { get; }
public SourceSpan Source { get; } public SourceSpan Source { get; }
} }
private class Visitor : RazorIRNodeWalker private class Visitor : IntermediateNodeWalker
{ {
public List<InstrumentationItem> Items { get; } = new List<InstrumentationItem>(); public List<InstrumentationItem> Items { get; } = new List<InstrumentationItem>();
public override void VisitHtml(HtmlContentIRNode node) public override void VisitHtml(HtmlContentIntermediateNode node)
{ {
if (node.Source != null) if (node.Source != null)
{ {
@ -88,7 +88,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
VisitDefault(node); VisitDefault(node);
} }
public override void VisitCSharpExpression(CSharpExpressionIRNode node) public override void VisitCSharpExpression(CSharpExpressionIntermediateNode node)
{ {
if (node.Source != null) if (node.Source != null)
{ {
@ -98,7 +98,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
VisitDefault(node); VisitDefault(node);
} }
public override void VisitTagHelper(TagHelperIRNode node) public override void VisitTagHelper(TagHelperIntermediateNode node)
{ {
if (node.Source != null) if (node.Source != null)
{ {
@ -108,12 +108,12 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
VisitDefault(node); VisitDefault(node);
} }
public override void VisitAddTagHelperHtmlAttribute(AddTagHelperHtmlAttributeIRNode node) public override void VisitAddTagHelperHtmlAttribute(AddTagHelperHtmlAttributeIntermediateNode node)
{ {
// We don't want to instrument TagHelper attributes. Do nothing. // We don't want to instrument TagHelper attributes. Do nothing.
} }
public override void VisitSetTagHelperProperty(SetTagHelperPropertyIRNode node) public override void VisitSetTagHelperProperty(SetTagHelperPropertyIntermediateNode node)
{ {
// We don't want to instrument TagHelper attributes. Do nothing. // We don't want to instrument TagHelper attributes. Do nothing.
} }

View File

@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
return builder; return builder;
} }
public static string GetModelType(DocumentIRNode document) public static string GetModelType(DocumentIntermediateNode document)
{ {
if (document == null) if (document == null)
{ {
@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
return GetModelType(document, visitor); return GetModelType(document, visitor);
} }
private static string GetModelType(DocumentIRNode document, Visitor visitor) private static string GetModelType(DocumentIntermediateNode document, Visitor visitor)
{ {
visitor.Visit(document); visitor.Visit(document);
@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
} }
} }
internal class Pass : RazorIRPassBase, IRazorDirectiveClassifierPass internal class Pass : IntermediateNodePassBase, IRazorDirectiveClassifierPass
{ {
private readonly bool _designTime; private readonly bool _designTime;
@ -71,17 +71,17 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
// Runs after the @inherits directive // Runs after the @inherits directive
public override int Order => 5; public override int Order => 5;
protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNode irDocument) protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
{ {
var visitor = new Visitor(); var visitor = new Visitor();
var modelType = GetModelType(irDocument, visitor); var modelType = GetModelType(documentNode, visitor);
if (_designTime) if (_designTime)
{ {
// Alias the TModel token to a known type. // Alias the TModel token to a known type.
// This allows design time compilation to succeed for Razor files where the token isn't replaced. // This allows design time compilation to succeed for Razor files where the token isn't replaced.
var typeName = $"global::{typeof(object).FullName}"; var typeName = $"global::{typeof(object).FullName}";
var usingNode = new UsingStatementIRNode() var usingNode = new UsingStatementIntermediateNode()
{ {
Content = $"TModel = {typeName}" Content = $"TModel = {typeName}"
}; };
@ -106,17 +106,17 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
} }
} }
private class Visitor : RazorIRNodeWalker private class Visitor : IntermediateNodeWalker
{ {
public NamespaceDeclarationIRNode Namespace { get; private set; } public NamespaceDeclarationIntermediateNode Namespace { get; private set; }
public ClassDeclarationIRNode Class { get; private set; } public ClassDeclarationIntermediateNode Class { get; private set; }
public IList<DirectiveIRNode> InheritsDirectives { get; } = new List<DirectiveIRNode>(); public IList<DirectiveIntermediateNode> InheritsDirectives { get; } = new List<DirectiveIntermediateNode>();
public IList<DirectiveIRNode> ModelDirectives { get; } = new List<DirectiveIRNode>(); public IList<DirectiveIntermediateNode> ModelDirectives { get; } = new List<DirectiveIntermediateNode>();
public override void VisitNamespaceDeclaration(NamespaceDeclarationIRNode node) public override void VisitNamespaceDeclaration(NamespaceDeclarationIntermediateNode node)
{ {
if (Namespace == null) if (Namespace == null)
{ {
@ -126,7 +126,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
base.VisitNamespaceDeclaration(node); base.VisitNamespaceDeclaration(node);
} }
public override void VisitClassDeclaration(ClassDeclarationIRNode node) public override void VisitClassDeclaration(ClassDeclarationIntermediateNode node)
{ {
if (Class == null) if (Class == null)
{ {
@ -136,7 +136,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
base.VisitClassDeclaration(node); base.VisitClassDeclaration(node);
} }
public override void VisitDirective(DirectiveIRNode node) public override void VisitDirective(DirectiveIntermediateNode node)
{ {
if (node.Descriptor == Directive) if (node.Descriptor == Directive)
{ {

View File

@ -9,42 +9,42 @@ using Microsoft.AspNetCore.Razor.Language.Intermediate;
namespace Microsoft.AspNetCore.Mvc.Razor.Extensions namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{ {
public class ModelExpressionPass : RazorIRPassBase, IRazorIROptimizationPass public class ModelExpressionPass : IntermediateNodePassBase, IRazorOptimizationPass
{ {
private const string ModelExpressionTypeName = "Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExpression"; private const string ModelExpressionTypeName = "Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExpression";
protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNode irDocument) protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
{ {
var visitor = new Visitor(); var visitor = new Visitor();
visitor.Visit(irDocument); visitor.Visit(documentNode);
} }
private class Visitor : RazorIRNodeWalker private class Visitor : IntermediateNodeWalker
{ {
public List<TagHelperIRNode> TagHelpers { get; } = new List<TagHelperIRNode>(); public List<TagHelperIntermediateNode> TagHelpers { get; } = new List<TagHelperIntermediateNode>();
public override void VisitSetTagHelperProperty(SetTagHelperPropertyIRNode node) public override void VisitSetTagHelperProperty(SetTagHelperPropertyIntermediateNode node)
{ {
if (string.Equals(node.Descriptor.TypeName, ModelExpressionTypeName, StringComparison.Ordinal) || if (string.Equals(node.Descriptor.TypeName, ModelExpressionTypeName, StringComparison.Ordinal) ||
(node.IsIndexerNameMatch && (node.IsIndexerNameMatch &&
string.Equals(node.Descriptor.IndexerTypeName, ModelExpressionTypeName, StringComparison.Ordinal))) string.Equals(node.Descriptor.IndexerTypeName, ModelExpressionTypeName, StringComparison.Ordinal)))
{ {
var expression = new CSharpExpressionIRNode(); var expression = new CSharpExpressionIntermediateNode();
var builder = RazorIRBuilder.Create(expression); var builder = IntermediateNodeBuilder.Create(expression);
builder.Add(new RazorIRToken() builder.Add(new IntermediateToken()
{ {
Kind = RazorIRToken.TokenKind.CSharp, Kind = IntermediateToken.TokenKind.CSharp,
Content = "ModelExpressionProvider.CreateModelExpression(ViewData, __model => ", Content = "ModelExpressionProvider.CreateModelExpression(ViewData, __model => ",
}); });
if (node.Children.Count == 1 && node.Children[0] is RazorIRToken token && token.IsCSharp) if (node.Children.Count == 1 && node.Children[0] is IntermediateToken token && token.IsCSharp)
{ {
// A 'simple' expression will look like __model => __model.Foo // A 'simple' expression will look like __model => __model.Foo
builder.Add(new RazorIRToken() builder.Add(new IntermediateToken()
{ {
Kind = RazorIRToken.TokenKind.CSharp, Kind = IntermediateToken.TokenKind.CSharp,
Content = "__model." Content = "__model."
}); });
@ -54,11 +54,11 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{ {
for (var i = 0; i < node.Children.Count; i++) for (var i = 0; i < node.Children.Count; i++)
{ {
if (node.Children[i] is CSharpExpressionIRNode nestedExpression) if (node.Children[i] is CSharpExpressionIntermediateNode nestedExpression)
{ {
for (var j = 0; j < nestedExpression.Children.Count; j++) for (var j = 0; j < nestedExpression.Children.Count; j++)
{ {
if (nestedExpression.Children[j] is RazorIRToken cSharpToken && if (nestedExpression.Children[j] is IntermediateToken cSharpToken &&
cSharpToken.IsCSharp) cSharpToken.IsCSharp)
{ {
builder.Add(cSharpToken); builder.Add(cSharpToken);
@ -70,9 +70,9 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
} }
} }
builder.Add(new RazorIRToken() builder.Add(new IntermediateToken()
{ {
Kind = RazorIRToken.TokenKind.CSharp, Kind = IntermediateToken.TokenKind.CSharp,
Content = ")", Content = ")",
}); });

View File

@ -12,13 +12,13 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
protected override string DocumentKind => MvcViewDocumentKind; protected override string DocumentKind => MvcViewDocumentKind;
protected override bool IsMatch(RazorCodeDocument codeDocument, DocumentIRNode irDocument) => true; protected override bool IsMatch(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode) => true;
protected override void OnDocumentStructureCreated( protected override void OnDocumentStructureCreated(
RazorCodeDocument codeDocument, RazorCodeDocument codeDocument,
NamespaceDeclarationIRNode @namespace, NamespaceDeclarationIntermediateNode @namespace,
ClassDeclarationIRNode @class, ClassDeclarationIntermediateNode @class,
MethodDeclarationIRNode method) MethodDeclarationIntermediateNode method)
{ {
var filePath = codeDocument.GetRelativePath() ?? codeDocument.Source.FilePath; var filePath = codeDocument.GetRelativePath() ?? codeDocument.Source.FilePath;

View File

@ -31,19 +31,19 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
} }
// internal for testing // internal for testing
internal class Pass : RazorIRPassBase, IRazorDirectiveClassifierPass internal class Pass : IntermediateNodePassBase, IRazorDirectiveClassifierPass
{ {
protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNode irDocument) protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
{ {
if (irDocument.DocumentKind != RazorPageDocumentClassifierPass.RazorPageDocumentKind && if (documentNode.DocumentKind != RazorPageDocumentClassifierPass.RazorPageDocumentKind &&
irDocument.DocumentKind != MvcViewDocumentClassifierPass.MvcViewDocumentKind) documentNode.DocumentKind != MvcViewDocumentClassifierPass.MvcViewDocumentKind)
{ {
// Not a page. Skip. // Not a page. Skip.
return; return;
} }
var visitor = new Visitor(); var visitor = new Visitor();
visitor.Visit(irDocument); visitor.Visit(documentNode);
var directive = visitor.LastNamespaceDirective; var directive = visitor.LastNamespaceDirective;
if (directive == null) if (directive == null)
@ -64,11 +64,11 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
// Beautify the class name since we're using a hierarchy for namespaces. // Beautify the class name since we're using a hierarchy for namespaces.
var @class = visitor.FirstClass; var @class = visitor.FirstClass;
var prefix = CSharpIdentifier.SanitizeClassName(Path.GetFileNameWithoutExtension(codeDocument.Source.FilePath)); var prefix = CSharpIdentifier.SanitizeClassName(Path.GetFileNameWithoutExtension(codeDocument.Source.FilePath));
if (@class != null && irDocument.DocumentKind == RazorPageDocumentClassifierPass.RazorPageDocumentKind) if (@class != null && documentNode.DocumentKind == RazorPageDocumentClassifierPass.RazorPageDocumentKind)
{ {
@class.Name = prefix + "_Page"; @class.Name = prefix + "_Page";
} }
else if (@class != null && irDocument.DocumentKind == MvcViewDocumentClassifierPass.MvcViewDocumentKind) else if (@class != null && documentNode.DocumentKind == MvcViewDocumentClassifierPass.MvcViewDocumentKind)
{ {
@class.Name = prefix + "_View"; @class.Name = prefix + "_View";
} }
@ -85,7 +85,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
// //
// In the event that these two source either don't have FileNames set or don't follow a coherent hierarchy, // In the event that these two source either don't have FileNames set or don't follow a coherent hierarchy,
// we will just use the namespace verbatim. // we will just use the namespace verbatim.
internal static bool TryComputeNamespace(string source, DirectiveIRNode directive, out string @namespace) internal static bool TryComputeNamespace(string source, DirectiveIntermediateNode directive, out string @namespace)
{ {
var directiveSource = NormalizeDirectory(directive.Source?.FilePath); var directiveSource = NormalizeDirectory(directive.Source?.FilePath);
@ -159,16 +159,16 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
return path.Substring(0, lastSeparator + 1); return path.Substring(0, lastSeparator + 1);
} }
private class Visitor : RazorIRNodeWalker private class Visitor : IntermediateNodeWalker
{ {
public ClassDeclarationIRNode FirstClass { get; private set; } public ClassDeclarationIntermediateNode FirstClass { get; private set; }
public NamespaceDeclarationIRNode FirstNamespace { get; private set; } public NamespaceDeclarationIntermediateNode FirstNamespace { get; private set; }
// We want the last one, so get them all and then . // We want the last one, so get them all and then .
public DirectiveIRNode LastNamespaceDirective { get; private set; } public DirectiveIntermediateNode LastNamespaceDirective { get; private set; }
public override void VisitNamespaceDeclaration(NamespaceDeclarationIRNode node) public override void VisitNamespaceDeclaration(NamespaceDeclarationIntermediateNode node)
{ {
if (FirstNamespace == null) if (FirstNamespace == null)
{ {
@ -178,7 +178,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
base.VisitNamespaceDeclaration(node); base.VisitNamespaceDeclaration(node);
} }
public override void VisitClassDeclaration(ClassDeclarationIRNode node) public override void VisitClassDeclaration(ClassDeclarationIntermediateNode node)
{ {
if (FirstClass == null) if (FirstClass == null)
{ {
@ -188,7 +188,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
base.VisitClassDeclaration(node); base.VisitClassDeclaration(node);
} }
public override void VisitDirective(DirectiveIRNode node) public override void VisitDirective(DirectiveIntermediateNode node)
{ {
if (node.Descriptor == Directive) if (node.Descriptor == Directive)
{ {

View File

@ -29,12 +29,12 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
return builder; return builder;
} }
public static bool TryGetPageDirective(DocumentIRNode irDocument, out PageDirective pageDirective) public static bool TryGetPageDirective(DocumentIntermediateNode documentNode, out PageDirective pageDirective)
{ {
var visitor = new Visitor(); var visitor = new Visitor();
for (var i = 0; i < irDocument.Children.Count; i++) for (var i = 0; i < documentNode.Children.Count; i++)
{ {
visitor.Visit(irDocument.Children[i]); visitor.Visit(documentNode.Children[i]);
} }
if (visitor.DirectiveNode == null) if (visitor.DirectiveNode == null)
@ -63,11 +63,11 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
return content.Substring(1, content.Length - 2); return content.Substring(1, content.Length - 2);
} }
private class Visitor : RazorIRNodeWalker private class Visitor : IntermediateNodeWalker
{ {
public DirectiveIRNode DirectiveNode { get; private set; } public DirectiveIntermediateNode DirectiveNode { get; private set; }
public override void VisitDirective(DirectiveIRNode node) public override void VisitDirective(DirectiveIntermediateNode node)
{ {
if (node.Descriptor == Directive) if (node.Descriptor == Directive)
{ {

View File

@ -6,46 +6,46 @@ using Microsoft.AspNetCore.Razor.Language.Intermediate;
namespace Microsoft.AspNetCore.Mvc.Razor.Extensions namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{ {
public class PagesPropertyInjectionPass : RazorIRPassBase, IRazorIROptimizationPass public class PagesPropertyInjectionPass : IntermediateNodePassBase, IRazorOptimizationPass
{ {
protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNode irDocument) protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
{ {
if (irDocument.DocumentKind != RazorPageDocumentClassifierPass.RazorPageDocumentKind) if (documentNode.DocumentKind != RazorPageDocumentClassifierPass.RazorPageDocumentKind)
{ {
return; return;
} }
var modelType = ModelDirective.GetModelType(irDocument); var modelType = ModelDirective.GetModelType(documentNode);
var visitor = new Visitor(); var visitor = new Visitor();
visitor.Visit(irDocument); visitor.Visit(documentNode);
var @class = visitor.Class; var @class = visitor.Class;
var viewDataType = $"global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary<{modelType}>"; var viewDataType = $"global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary<{modelType}>";
var vddProperty = new CSharpCodeIRNode(); var vddProperty = new CSharpCodeIntermediateNode();
RazorIRBuilder.Create(vddProperty) IntermediateNodeBuilder.Create(vddProperty)
.Add(new RazorIRToken() .Add(new IntermediateToken()
{ {
Kind = RazorIRToken.TokenKind.CSharp, Kind = IntermediateToken.TokenKind.CSharp,
Content = $"public {viewDataType} ViewData => ({viewDataType})PageContext?.ViewData;", Content = $"public {viewDataType} ViewData => ({viewDataType})PageContext?.ViewData;",
}); });
@class.Children.Add(vddProperty); @class.Children.Add(vddProperty);
var modelProperty = new CSharpCodeIRNode(); var modelProperty = new CSharpCodeIntermediateNode();
RazorIRBuilder.Create(modelProperty) IntermediateNodeBuilder.Create(modelProperty)
.Add(new RazorIRToken() .Add(new IntermediateToken()
{ {
Kind = RazorIRToken.TokenKind.CSharp, Kind = IntermediateToken.TokenKind.CSharp,
Content = $"public {modelType} Model => ViewData.Model;", Content = $"public {modelType} Model => ViewData.Model;",
}); });
@class.Children.Add(modelProperty); @class.Children.Add(modelProperty);
} }
private class Visitor : RazorIRNodeWalker private class Visitor : IntermediateNodeWalker
{ {
public ClassDeclarationIRNode Class { get; private set; } public ClassDeclarationIntermediateNode Class { get; private set; }
public override void VisitClassDeclaration(ClassDeclarationIRNode node) public override void VisitClassDeclaration(ClassDeclarationIntermediateNode node)
{ {
if (Class == null) if (Class == null)
{ {

View File

@ -19,7 +19,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
InheritsDirective.Register(builder); InheritsDirective.Register(builder);
SectionDirective.Register(builder); SectionDirective.Register(builder);
builder.AddTargetExtension(new InjectDirectiveTargetExtension());
builder.AddTargetExtension(new TemplateTargetExtension() builder.AddTargetExtension(new TemplateTargetExtension()
{ {
TemplateTypeName = "global::Microsoft.AspNetCore.Mvc.Razor.HelperResult", TemplateTypeName = "global::Microsoft.AspNetCore.Mvc.Razor.HelperResult",

View File

@ -12,16 +12,16 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
protected override string DocumentKind => RazorPageDocumentKind; protected override string DocumentKind => RazorPageDocumentKind;
protected override bool IsMatch(RazorCodeDocument codeDocument, DocumentIRNode irDocument) protected override bool IsMatch(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
{ {
return PageDirective.TryGetPageDirective(irDocument, out var directive); return PageDirective.TryGetPageDirective(documentNode, out var directive);
} }
protected override void OnDocumentStructureCreated( protected override void OnDocumentStructureCreated(
RazorCodeDocument codeDocument, RazorCodeDocument codeDocument,
NamespaceDeclarationIRNode @namespace, NamespaceDeclarationIntermediateNode @namespace,
ClassDeclarationIRNode @class, ClassDeclarationIntermediateNode @class,
MethodDeclarationIRNode method) MethodDeclarationIntermediateNode method)
{ {
var filePath = codeDocument.GetRelativePath() ?? codeDocument.Source.FilePath; var filePath = codeDocument.GetRelativePath() ?? codeDocument.Source.FilePath;

View File

@ -11,12 +11,12 @@ using Microsoft.AspNetCore.Razor.Language.Legacy;
namespace Microsoft.AspNetCore.Mvc.Razor.Extensions namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{ {
public class ViewComponentTagHelperPass : RazorIRPassBase, IRazorIROptimizationPass public class ViewComponentTagHelperPass : IntermediateNodePassBase, IRazorOptimizationPass
{ {
protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNode irDocument) protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
{ {
var visitor = new Visitor(); var visitor = new Visitor();
visitor.Visit(irDocument); visitor.Visit(documentNode);
if (visitor.Class == null || visitor.TagHelpers.Count == 0) if (visitor.Class == null || visitor.TagHelpers.Count == 0)
{ {
@ -37,20 +37,20 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
foreach (var (parent, node) in visitor.CreateTagHelpers) foreach (var (parent, node) in visitor.CreateTagHelpers)
{ {
RewriteCreateNode(visitor.Namespace, visitor.Class, (CreateTagHelperIRNode)node, parent); RewriteCreateNode(visitor.Namespace, visitor.Class, (CreateTagHelperIntermediateNode)node, parent);
} }
} }
private void GenerateVCTHClass(ClassDeclarationIRNode @class, TagHelperDescriptor tagHelper) private void GenerateVCTHClass(ClassDeclarationIntermediateNode @class, TagHelperDescriptor tagHelper)
{ {
var writer = new CSharpCodeWriter(); var writer = new CSharpCodeWriter();
WriteClass(writer, tagHelper); WriteClass(writer, tagHelper);
var statement = new CSharpCodeIRNode(); var statement = new CSharpCodeIntermediateNode();
RazorIRBuilder.Create(statement) IntermediateNodeBuilder.Create(statement)
.Add(new RazorIRToken() .Add(new IntermediateToken()
{ {
Kind = RazorIRToken.TokenKind.CSharp, Kind = IntermediateToken.TokenKind.CSharp,
Content = writer.Builder.ToString() Content = writer.Builder.ToString()
}); });
@ -58,15 +58,15 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
} }
private void RewriteCreateNode( private void RewriteCreateNode(
NamespaceDeclarationIRNode @namespace, NamespaceDeclarationIntermediateNode @namespace,
ClassDeclarationIRNode @class, ClassDeclarationIntermediateNode @class,
CreateTagHelperIRNode node, CreateTagHelperIntermediateNode node,
RazorIRNode parent) IntermediateNode parent)
{ {
var newTypeName = GetVCTHFullName(@namespace, @class, node.Descriptor); var newTypeName = GetVCTHFullName(@namespace, @class, node.Descriptor);
for (var i = 0; i < parent.Children.Count; i++) for (var i = 0; i < parent.Children.Count; i++)
{ {
if (parent.Children[i] is SetTagHelperPropertyIRNode setProperty && if (parent.Children[i] is SetTagHelperPropertyIntermediateNode setProperty &&
node.Descriptor.BoundAttributes.Contains(setProperty.Descriptor)) node.Descriptor.BoundAttributes.Contains(setProperty.Descriptor))
{ {
setProperty.TagHelperTypeName = newTypeName; setProperty.TagHelperTypeName = newTypeName;
@ -77,8 +77,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
} }
private static string GetVCTHFullName( private static string GetVCTHFullName(
NamespaceDeclarationIRNode @namespace, NamespaceDeclarationIntermediateNode @namespace,
ClassDeclarationIRNode @class, ClassDeclarationIntermediateNode @class,
TagHelperDescriptor tagHelper) TagHelperDescriptor tagHelper)
{ {
var vcName = tagHelper.Metadata[ViewComponentTagHelperDescriptorConventions.ViewComponentNameKey]; var vcName = tagHelper.Metadata[ViewComponentTagHelperDescriptorConventions.ViewComponentNameKey];
@ -220,19 +220,19 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
.WriteLine(")]"); .WriteLine(")]");
} }
private class Visitor : RazorIRNodeWalker private class Visitor : IntermediateNodeWalker
{ {
public ClassDeclarationIRNode Class { get; private set; } public ClassDeclarationIntermediateNode Class { get; private set; }
public DeclareTagHelperFieldsIRNode Fields { get; private set; } public DeclareTagHelperFieldsIntermediateNode Fields { get; private set; }
public NamespaceDeclarationIRNode Namespace { get; private set; } public NamespaceDeclarationIntermediateNode Namespace { get; private set; }
public List<RazorIRNodeReference> CreateTagHelpers { get; } = new List<RazorIRNodeReference>(); public List<IntermediateNodeReference> CreateTagHelpers { get; } = new List<IntermediateNodeReference>();
public Dictionary<string, TagHelperDescriptor> TagHelpers { get; } = new Dictionary<string, TagHelperDescriptor>(); public Dictionary<string, TagHelperDescriptor> TagHelpers { get; } = new Dictionary<string, TagHelperDescriptor>();
public override void VisitCreateTagHelper(CreateTagHelperIRNode node) public override void VisitCreateTagHelper(CreateTagHelperIntermediateNode node)
{ {
var tagHelper = node.Descriptor; var tagHelper = node.Descriptor;
if (ViewComponentTagHelperDescriptorConventions.IsViewComponentDescriptor(tagHelper)) if (ViewComponentTagHelperDescriptorConventions.IsViewComponentDescriptor(tagHelper))
@ -241,11 +241,11 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
var vcName = tagHelper.Metadata[ViewComponentTagHelperDescriptorConventions.ViewComponentNameKey]; var vcName = tagHelper.Metadata[ViewComponentTagHelperDescriptorConventions.ViewComponentNameKey];
TagHelpers[vcName] = tagHelper; TagHelpers[vcName] = tagHelper;
CreateTagHelpers.Add(new RazorIRNodeReference(Parent, node)); CreateTagHelpers.Add(new IntermediateNodeReference(Parent, node));
} }
} }
public override void VisitNamespaceDeclaration(NamespaceDeclarationIRNode node) public override void VisitNamespaceDeclaration(NamespaceDeclarationIntermediateNode node)
{ {
if (Namespace == null) if (Namespace == null)
{ {
@ -255,7 +255,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
base.VisitNamespaceDeclaration(node); base.VisitNamespaceDeclaration(node);
} }
public override void VisitClassDeclaration(ClassDeclarationIRNode node) public override void VisitClassDeclaration(ClassDeclarationIntermediateNode node)
{ {
if (Class == null) if (Class == null)
{ {
@ -265,7 +265,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
base.VisitClassDeclaration(node); base.VisitClassDeclaration(node);
} }
public override void VisitDeclareTagHelperFields(DeclareTagHelperFieldsIRNode node) public override void VisitDeclareTagHelperFields(DeclareTagHelperFieldsIntermediateNode node)
{ {
if (Fields == null) if (Fields == null)
{ {

View File

@ -7,21 +7,21 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
{ {
public abstract class BasicWriter public abstract class BasicWriter
{ {
public abstract void WriteUsingStatement(CSharpRenderingContext context, UsingStatementIRNode node); public abstract void WriteUsingStatement(CSharpRenderingContext context, UsingStatementIntermediateNode node);
public abstract void WriteCSharpExpression(CSharpRenderingContext context, CSharpExpressionIRNode node); public abstract void WriteCSharpExpression(CSharpRenderingContext context, CSharpExpressionIntermediateNode node);
public abstract void WriteCSharpCode(CSharpRenderingContext context, CSharpCodeIRNode node); public abstract void WriteCSharpCode(CSharpRenderingContext context, CSharpCodeIntermediateNode node);
public abstract void WriteHtmlContent(CSharpRenderingContext context, HtmlContentIRNode node); public abstract void WriteHtmlContent(CSharpRenderingContext context, HtmlContentIntermediateNode node);
public abstract void WriteHtmlAttribute(CSharpRenderingContext context, HtmlAttributeIRNode node); public abstract void WriteHtmlAttribute(CSharpRenderingContext context, HtmlAttributeIntermediateNode node);
public abstract void WriteHtmlAttributeValue(CSharpRenderingContext context, HtmlAttributeValueIRNode node); public abstract void WriteHtmlAttributeValue(CSharpRenderingContext context, HtmlAttributeValueIntermediateNode node);
public abstract void WriteCSharpExpressionAttributeValue(CSharpRenderingContext context, CSharpExpressionAttributeValueIRNode node); public abstract void WriteCSharpExpressionAttributeValue(CSharpRenderingContext context, CSharpExpressionAttributeValueIntermediateNode node);
public abstract void WriteCSharpCodeAttributeValue(CSharpRenderingContext context, CSharpCodeAttributeValueIRNode node); public abstract void WriteCSharpCodeAttributeValue(CSharpRenderingContext context, CSharpCodeAttributeValueIntermediateNode node);
public abstract void BeginWriterScope(CSharpRenderingContext context, string writer); public abstract void BeginWriterScope(CSharpRenderingContext context, string writer);

View File

@ -28,15 +28,15 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
internal TagHelperRenderingContext TagHelperRenderingContext { get; set; } internal TagHelperRenderingContext TagHelperRenderingContext { get; set; }
internal Action<RazorIRNode> RenderChildren { get; set; } internal Action<IntermediateNode> RenderChildren { get; set; }
internal Action<RazorIRNode> RenderNode { get; set; } internal Action<IntermediateNode> RenderNode { get; set; }
public BasicWriter BasicWriter { get; set; } public BasicWriter BasicWriter { get; set; }
public TagHelperWriter TagHelperWriter { get; set; } public TagHelperWriter TagHelperWriter { get; set; }
public void AddLineMappingFor(RazorIRNode node) public void AddLineMappingFor(IntermediateNode node)
{ {
if (node.Source == null) if (node.Source == null)
{ {
@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
public void ReportMissingExtension<TExtension>() where TExtension : ICodeTargetExtension public void ReportMissingExtension<TExtension>() where TExtension : ICodeTargetExtension
{ {
var documentKind = CodeDocument.GetIRDocument()?.DocumentKind ?? string.Empty; var documentKind = CodeDocument.GetDocumentIntermediateNode()?.DocumentKind ?? string.Empty;
Diagnostics.Add(RazorDiagnosticFactory.CreateCodeTarget_UnsupportedExtension(documentKind, typeof(TExtension))); Diagnostics.Add(RazorDiagnosticFactory.CreateCodeTarget_UnsupportedExtension(documentKind, typeof(TExtension)));
} }

View File

@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
_context = context; _context = context;
} }
public override void WriteDocument(DocumentIRNode node) public override void WriteDocument(DocumentIntermediateNode node)
{ {
if (node == null) if (node == null)
{ {
@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
_context.RenderChildren = null; _context.RenderChildren = null;
} }
private class Visitor : RazorIRNodeVisitor private class Visitor : IntermediateNodeVisitor
{ {
private readonly CSharpRenderingContext _context; private readonly CSharpRenderingContext _context;
private readonly CodeTarget _target; private readonly CodeTarget _target;
@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
private CSharpRenderingContext Context => _context; private CSharpRenderingContext Context => _context;
public void RenderChildren(RazorIRNode node) public void RenderChildren(IntermediateNode node)
{ {
for (var i = 0; i < node.Children.Count; i++) for (var i = 0; i < node.Children.Count; i++)
{ {
@ -68,7 +68,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
} }
} }
public override void VisitDocument(DocumentIRNode node) public override void VisitDocument(DocumentIntermediateNode node)
{ {
if (!Context.Options.SuppressChecksum) if (!Context.Options.SuppressChecksum)
{ {
@ -102,12 +102,12 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
RenderChildren(node); RenderChildren(node);
} }
public override void VisitUsingStatement(UsingStatementIRNode node) public override void VisitUsingStatement(UsingStatementIntermediateNode node)
{ {
Context.BasicWriter.WriteUsingStatement(Context, node); Context.BasicWriter.WriteUsingStatement(Context, node);
} }
public override void VisitNamespaceDeclaration(NamespaceDeclarationIRNode node) public override void VisitNamespaceDeclaration(NamespaceDeclarationIntermediateNode node)
{ {
Context.Writer Context.Writer
.Write("namespace ") .Write("namespace ")
@ -120,7 +120,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
} }
} }
public override void VisitClassDeclaration(ClassDeclarationIRNode node) public override void VisitClassDeclaration(ClassDeclarationIntermediateNode node)
{ {
Context.Writer Context.Writer
.Write(node.AccessModifier) .Write(node.AccessModifier)
@ -163,7 +163,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
} }
} }
public override void VisitMethodDeclaration(MethodDeclarationIRNode node) public override void VisitMethodDeclaration(MethodDeclarationIntermediateNode node)
{ {
Context.Writer.WriteLine("#pragma warning disable 1998"); Context.Writer.WriteLine("#pragma warning disable 1998");
@ -199,62 +199,62 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
Context.Writer.WriteLine("#pragma warning restore 1998"); Context.Writer.WriteLine("#pragma warning restore 1998");
} }
public override void VisitFieldDeclaration(FieldDeclarationIRNode node) public override void VisitFieldDeclaration(FieldDeclarationIntermediateNode node)
{ {
Context.Writer.WriteField(node.AccessModifier, node.Modifiers, node.Type, node.Name); Context.Writer.WriteField(node.AccessModifier, node.Modifiers, node.Type, node.Name);
} }
public override void VisitPropertyDeclaration(PropertyDeclarationIRNode node) public override void VisitPropertyDeclaration(PropertyDeclarationIntermediateNode node)
{ {
Context.Writer.WriteAutoPropertyDeclaration(node.AccessModifier, node.Modifiers, node.Type, node.Name); Context.Writer.WriteAutoPropertyDeclaration(node.AccessModifier, node.Modifiers, node.Type, node.Name);
} }
public override void VisitExtension(ExtensionIRNode node) public override void VisitExtension(ExtensionIntermediateNode node)
{ {
node.WriteNode(_target, Context); node.WriteNode(_target, Context);
} }
public override void VisitCSharpExpression(CSharpExpressionIRNode node) public override void VisitCSharpExpression(CSharpExpressionIntermediateNode node)
{ {
Context.BasicWriter.WriteCSharpExpression(Context, node); Context.BasicWriter.WriteCSharpExpression(Context, node);
} }
public override void VisitCSharpCode(CSharpCodeIRNode node) public override void VisitCSharpCode(CSharpCodeIntermediateNode node)
{ {
Context.BasicWriter.WriteCSharpCode(Context, node); Context.BasicWriter.WriteCSharpCode(Context, node);
} }
public override void VisitHtmlAttribute(HtmlAttributeIRNode node) public override void VisitHtmlAttribute(HtmlAttributeIntermediateNode node)
{ {
Context.BasicWriter.WriteHtmlAttribute(Context, node); Context.BasicWriter.WriteHtmlAttribute(Context, node);
} }
public override void VisitHtmlAttributeValue(HtmlAttributeValueIRNode node) public override void VisitHtmlAttributeValue(HtmlAttributeValueIntermediateNode node)
{ {
Context.BasicWriter.WriteHtmlAttributeValue(Context, node); Context.BasicWriter.WriteHtmlAttributeValue(Context, node);
} }
public override void VisitCSharpExpressionAttributeValue(CSharpExpressionAttributeValueIRNode node) public override void VisitCSharpExpressionAttributeValue(CSharpExpressionAttributeValueIntermediateNode node)
{ {
Context.BasicWriter.WriteCSharpExpressionAttributeValue(Context, node); Context.BasicWriter.WriteCSharpExpressionAttributeValue(Context, node);
} }
public override void VisitCSharpCodeAttributeValue(CSharpCodeAttributeValueIRNode node) public override void VisitCSharpCodeAttributeValue(CSharpCodeAttributeValueIntermediateNode node)
{ {
Context.BasicWriter.WriteCSharpCodeAttributeValue(Context, node); Context.BasicWriter.WriteCSharpCodeAttributeValue(Context, node);
} }
public override void VisitHtml(HtmlContentIRNode node) public override void VisitHtml(HtmlContentIntermediateNode node)
{ {
Context.BasicWriter.WriteHtmlContent(Context, node); Context.BasicWriter.WriteHtmlContent(Context, node);
} }
public override void VisitDeclareTagHelperFields(DeclareTagHelperFieldsIRNode node) public override void VisitDeclareTagHelperFields(DeclareTagHelperFieldsIntermediateNode node)
{ {
Context.TagHelperWriter.WriteDeclareTagHelperFields(Context, node); Context.TagHelperWriter.WriteDeclareTagHelperFields(Context, node);
} }
public override void VisitTagHelper(TagHelperIRNode node) public override void VisitTagHelper(TagHelperIntermediateNode node)
{ {
var tagHelperRenderingContext = new TagHelperRenderingContext() var tagHelperRenderingContext = new TagHelperRenderingContext()
{ {
@ -268,27 +268,27 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
} }
} }
public override void VisitTagHelperBody(TagHelperBodyIRNode node) public override void VisitTagHelperBody(TagHelperBodyIntermediateNode node)
{ {
Context.TagHelperWriter.WriteTagHelperBody(Context, node); Context.TagHelperWriter.WriteTagHelperBody(Context, node);
} }
public override void VisitCreateTagHelper(CreateTagHelperIRNode node) public override void VisitCreateTagHelper(CreateTagHelperIntermediateNode node)
{ {
Context.TagHelperWriter.WriteCreateTagHelper(Context, node); Context.TagHelperWriter.WriteCreateTagHelper(Context, node);
} }
public override void VisitAddTagHelperHtmlAttribute(AddTagHelperHtmlAttributeIRNode node) public override void VisitAddTagHelperHtmlAttribute(AddTagHelperHtmlAttributeIntermediateNode node)
{ {
Context.TagHelperWriter.WriteAddTagHelperHtmlAttribute(Context, node); Context.TagHelperWriter.WriteAddTagHelperHtmlAttribute(Context, node);
} }
public override void VisitSetTagHelperProperty(SetTagHelperPropertyIRNode node) public override void VisitSetTagHelperProperty(SetTagHelperPropertyIntermediateNode node)
{ {
Context.TagHelperWriter.WriteSetTagHelperProperty(Context, node); Context.TagHelperWriter.WriteSetTagHelperProperty(Context, node);
} }
public override void VisitDefault(RazorIRNode node) public override void VisitDefault(IntermediateNode node)
{ {
Context.RenderChildren(node); Context.RenderChildren(node);
} }

View File

@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
{ {
public class DesignTimeBasicWriter : BasicWriter public class DesignTimeBasicWriter : BasicWriter
{ {
public override void WriteUsingStatement(CSharpRenderingContext context, UsingStatementIRNode node) public override void WriteUsingStatement(CSharpRenderingContext context, UsingStatementIntermediateNode node)
{ {
if (node.Source.HasValue) if (node.Source.HasValue)
{ {
@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
} }
} }
public override void WriteCSharpExpression(CSharpRenderingContext context, CSharpExpressionIRNode node) public override void WriteCSharpExpression(CSharpRenderingContext context, CSharpExpressionIntermediateNode node)
{ {
if (context == null) if (context == null)
{ {
@ -46,13 +46,13 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
{ {
using (context.Writer.BuildLinePragma(node.Source.Value)) using (context.Writer.BuildLinePragma(node.Source.Value))
{ {
var offset = RazorDesignTimeIRPass.DesignTimeVariable.Length + " = ".Length; var offset = DesignTimeDirectivePass.DesignTimeVariable.Length + " = ".Length;
context.Writer.WritePadding(offset, node.Source, context); context.Writer.WritePadding(offset, node.Source, context);
context.Writer.WriteStartAssignment(RazorDesignTimeIRPass.DesignTimeVariable); context.Writer.WriteStartAssignment(DesignTimeDirectivePass.DesignTimeVariable);
for (var i = 0; i < node.Children.Count; i++) for (var i = 0; i < node.Children.Count; i++)
{ {
if (node.Children[i] is RazorIRToken token && token.IsCSharp) if (node.Children[i] is IntermediateToken token && token.IsCSharp)
{ {
context.AddLineMappingFor(token); context.AddLineMappingFor(token);
context.Writer.Write(token.Content); context.Writer.Write(token.Content);
@ -69,10 +69,10 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
} }
else else
{ {
context.Writer.WriteStartAssignment(RazorDesignTimeIRPass.DesignTimeVariable); context.Writer.WriteStartAssignment(DesignTimeDirectivePass.DesignTimeVariable);
for (var i = 0; i < node.Children.Count; i++) for (var i = 0; i < node.Children.Count; i++)
{ {
if (node.Children[i] is RazorIRToken token && token.IsCSharp) if (node.Children[i] is IntermediateToken token && token.IsCSharp)
{ {
context.Writer.Write(token.Content); context.Writer.Write(token.Content);
} }
@ -86,12 +86,12 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
} }
} }
public override void WriteCSharpCode(CSharpRenderingContext context, CSharpCodeIRNode node) public override void WriteCSharpCode(CSharpRenderingContext context, CSharpCodeIntermediateNode node)
{ {
var isWhitespaceStatement = true; var isWhitespaceStatement = true;
for (var i = 0; i < node.Children.Count; i++) for (var i = 0; i < node.Children.Count; i++)
{ {
var token = node.Children[i] as RazorIRToken; var token = node.Children[i] as IntermediateToken;
if (token == null || !string.IsNullOrWhiteSpace(token.Content)) if (token == null || !string.IsNullOrWhiteSpace(token.Content))
{ {
isWhitespaceStatement = false; isWhitespaceStatement = false;
@ -117,7 +117,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
for (var i = 0; i < node.Children.Count; i++) for (var i = 0; i < node.Children.Count; i++)
{ {
if (node.Children[i] is RazorIRToken token && token.IsCSharp) if (node.Children[i] is IntermediateToken token && token.IsCSharp)
{ {
context.AddLineMappingFor(token); context.AddLineMappingFor(token);
context.Writer.Write(token.Content); context.Writer.Write(token.Content);
@ -139,17 +139,17 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
} }
} }
public override void WriteHtmlAttribute(CSharpRenderingContext context, HtmlAttributeIRNode node) public override void WriteHtmlAttribute(CSharpRenderingContext context, HtmlAttributeIntermediateNode node)
{ {
context.RenderChildren(node); context.RenderChildren(node);
} }
public override void WriteHtmlAttributeValue(CSharpRenderingContext context, HtmlAttributeValueIRNode node) public override void WriteHtmlAttributeValue(CSharpRenderingContext context, HtmlAttributeValueIntermediateNode node)
{ {
context.RenderChildren(node); context.RenderChildren(node);
} }
public override void WriteCSharpExpressionAttributeValue(CSharpRenderingContext context, CSharpExpressionAttributeValueIRNode node) public override void WriteCSharpExpressionAttributeValue(CSharpRenderingContext context, CSharpExpressionAttributeValueIntermediateNode node)
{ {
if (context == null) if (context == null)
{ {
@ -171,13 +171,13 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
{ {
using (context.Writer.BuildLinePragma(firstChild.Source.Value)) using (context.Writer.BuildLinePragma(firstChild.Source.Value))
{ {
var offset = RazorDesignTimeIRPass.DesignTimeVariable.Length + " = ".Length; var offset = DesignTimeDirectivePass.DesignTimeVariable.Length + " = ".Length;
context.Writer.WritePadding(offset, firstChild.Source, context); context.Writer.WritePadding(offset, firstChild.Source, context);
context.Writer.WriteStartAssignment(RazorDesignTimeIRPass.DesignTimeVariable); context.Writer.WriteStartAssignment(DesignTimeDirectivePass.DesignTimeVariable);
for (var i = 0; i < node.Children.Count; i++) for (var i = 0; i < node.Children.Count; i++)
{ {
if (node.Children[i] is RazorIRToken token && token.IsCSharp) if (node.Children[i] is IntermediateToken token && token.IsCSharp)
{ {
context.AddLineMappingFor(token); context.AddLineMappingFor(token);
context.Writer.Write(token.Content); context.Writer.Write(token.Content);
@ -194,10 +194,10 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
} }
else else
{ {
context.Writer.WriteStartAssignment(RazorDesignTimeIRPass.DesignTimeVariable); context.Writer.WriteStartAssignment(DesignTimeDirectivePass.DesignTimeVariable);
for (var i = 0; i < node.Children.Count; i++) for (var i = 0; i < node.Children.Count; i++)
{ {
if (node.Children[i] is RazorIRToken token && token.IsCSharp) if (node.Children[i] is IntermediateToken token && token.IsCSharp)
{ {
if (token.Source != null) if (token.Source != null)
{ {
@ -216,11 +216,11 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
} }
} }
public override void WriteCSharpCodeAttributeValue(CSharpRenderingContext context, CSharpCodeAttributeValueIRNode node) public override void WriteCSharpCodeAttributeValue(CSharpRenderingContext context, CSharpCodeAttributeValueIntermediateNode node)
{ {
for (var i = 0; i < node.Children.Count; i++) for (var i = 0; i < node.Children.Count; i++)
{ {
if (node.Children[i] is RazorIRToken token && token.IsCSharp) if (node.Children[i] is IntermediateToken token && token.IsCSharp)
{ {
IDisposable linePragmaScope = null; IDisposable linePragmaScope = null;
var isWhitespaceStatement = string.IsNullOrWhiteSpace(token.Content); var isWhitespaceStatement = string.IsNullOrWhiteSpace(token.Content);
@ -260,7 +260,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
} }
} }
public override void WriteHtmlContent(CSharpRenderingContext context, HtmlContentIRNode node) public override void WriteHtmlContent(CSharpRenderingContext context, HtmlContentIntermediateNode node)
{ {
// Do nothing // Do nothing
} }

View File

@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
private const string DirectiveTokenHelperMethodName = "__RazorDirectiveTokenHelpers__"; private const string DirectiveTokenHelperMethodName = "__RazorDirectiveTokenHelpers__";
private const string TypeHelper = "__typeHelper"; private const string TypeHelper = "__typeHelper";
public void WriteDesignTimeDirective(CSharpRenderingContext context, DesignTimeDirectiveIRNode node) public void WriteDesignTimeDirective(CSharpRenderingContext context, DesignTimeDirectiveIntermediateNode node)
{ {
context.Writer context.Writer
.WritePragma("warning disable 219") .WritePragma("warning disable 219")
@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
for (var i = 0; i < node.Children.Count; i++) for (var i = 0; i < node.Children.Count; i++)
{ {
if (node.Children[i] is DirectiveTokenIRNode n) if (node.Children[i] is DirectiveTokenIntermediateNode n)
{ {
WriteDesignTimeDirectiveToken(context, n); WriteDesignTimeDirectiveToken(context, n);
} }
@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
.WritePragma("warning restore 219"); .WritePragma("warning restore 219");
} }
private void WriteDesignTimeDirectiveToken(CSharpRenderingContext context, DirectiveTokenIRNode node) private void WriteDesignTimeDirectiveToken(CSharpRenderingContext context, DirectiveTokenIntermediateNode node)
{ {
var tokenKind = node.Descriptor.Kind; var tokenKind = node.Descriptor.Kind;
if (!node.Source.HasValue || if (!node.Source.HasValue ||

View File

@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
{ {
public string CreateTagHelperMethodName { get; set; } = "CreateTagHelper"; public string CreateTagHelperMethodName { get; set; } = "CreateTagHelper";
public override void WriteDeclareTagHelperFields(CSharpRenderingContext context, DeclareTagHelperFieldsIRNode node) public override void WriteDeclareTagHelperFields(CSharpRenderingContext context, DeclareTagHelperFieldsIntermediateNode node)
{ {
foreach (var tagHelperTypeName in node.UsedTagHelperTypeNames) foreach (var tagHelperTypeName in node.UsedTagHelperTypeNames)
{ {
@ -28,17 +28,17 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
} }
} }
public override void WriteTagHelper(CSharpRenderingContext context, TagHelperIRNode node) public override void WriteTagHelper(CSharpRenderingContext context, TagHelperIntermediateNode node)
{ {
context.RenderChildren(node); context.RenderChildren(node);
} }
public override void WriteTagHelperBody(CSharpRenderingContext context, TagHelperBodyIRNode node) public override void WriteTagHelperBody(CSharpRenderingContext context, TagHelperBodyIntermediateNode node)
{ {
context.RenderChildren(node); context.RenderChildren(node);
} }
public override void WriteCreateTagHelper(CSharpRenderingContext context, CreateTagHelperIRNode node) public override void WriteCreateTagHelper(CSharpRenderingContext context, CreateTagHelperIntermediateNode node)
{ {
var tagHelperVariableName = GetTagHelperVariableName(node.TagHelperTypeName); var tagHelperVariableName = GetTagHelperVariableName(node.TagHelperTypeName);
@ -50,12 +50,12 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
.WriteEndMethodInvocation(); .WriteEndMethodInvocation();
} }
public override void WriteAddTagHelperHtmlAttribute(CSharpRenderingContext context, AddTagHelperHtmlAttributeIRNode node) public override void WriteAddTagHelperHtmlAttribute(CSharpRenderingContext context, AddTagHelperHtmlAttributeIntermediateNode node)
{ {
context.RenderChildren(node); context.RenderChildren(node);
} }
public override void WriteSetTagHelperProperty(CSharpRenderingContext context, SetTagHelperPropertyIRNode node) public override void WriteSetTagHelperProperty(CSharpRenderingContext context, SetTagHelperPropertyIntermediateNode node)
{ {
var tagHelperVariableName = GetTagHelperVariableName(node.TagHelperTypeName); var tagHelperVariableName = GetTagHelperVariableName(node.TagHelperTypeName);
var tagHelperRenderingContext = context.TagHelperRenderingContext; var tagHelperRenderingContext = context.TagHelperRenderingContext;
@ -80,7 +80,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
context.RenderChildren(node); context.RenderChildren(node);
context.Writer.WriteStartAssignment(propertyValueAccessor); context.Writer.WriteStartAssignment(propertyValueAccessor);
if (node.Children.Count == 1 && node.Children.First() is HtmlContentIRNode htmlNode) if (node.Children.Count == 1 && node.Children.First() is HtmlContentIntermediateNode htmlNode)
{ {
var content = GetContent(htmlNode); var content = GetContent(htmlNode);
context.Writer.WriteStringLiteral(content); context.Writer.WriteStringLiteral(content);
@ -93,7 +93,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
} }
else else
{ {
var firstMappedChild = node.Children.FirstOrDefault(child => child.Source != null) as RazorIRNode; var firstMappedChild = node.Children.FirstOrDefault(child => child.Source != null) as IntermediateNode;
var valueStart = firstMappedChild?.Source; var valueStart = firstMappedChild?.Source;
using (context.Writer.BuildLinePragma(node.Source.Value)) using (context.Writer.BuildLinePragma(node.Source.Value))
@ -101,7 +101,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
var assignmentPrefixLength = propertyValueAccessor.Length + " = ".Length; var assignmentPrefixLength = propertyValueAccessor.Length + " = ".Length;
if (node.Descriptor.IsEnum && if (node.Descriptor.IsEnum &&
node.Children.Count == 1 && node.Children.Count == 1 &&
node.Children.First() is RazorIRToken token && node.Children.First() is IntermediateToken token &&
token.IsCSharp) token.IsCSharp)
{ {
assignmentPrefixLength += $"global::{node.Descriptor.TypeName}.".Length; assignmentPrefixLength += $"global::{node.Descriptor.TypeName}.".Length;
@ -136,7 +136,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
private void RenderTagHelperAttributeInline( private void RenderTagHelperAttributeInline(
CSharpRenderingContext context, CSharpRenderingContext context,
SetTagHelperPropertyIRNode property, SetTagHelperPropertyIntermediateNode property,
SourceSpan documentLocation) SourceSpan documentLocation)
{ {
for (var i = 0; i < property.Children.Count; i++) for (var i = 0; i < property.Children.Count; i++)
@ -147,18 +147,18 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
private void RenderTagHelperAttributeInline( private void RenderTagHelperAttributeInline(
CSharpRenderingContext context, CSharpRenderingContext context,
SetTagHelperPropertyIRNode property, SetTagHelperPropertyIntermediateNode property,
RazorIRNode node, IntermediateNode node,
SourceSpan documentLocation) SourceSpan documentLocation)
{ {
if (node is CSharpExpressionIRNode || node is HtmlContentIRNode) if (node is CSharpExpressionIntermediateNode || node is HtmlContentIntermediateNode)
{ {
for (var i = 0; i < node.Children.Count; i++) for (var i = 0; i < node.Children.Count; i++)
{ {
RenderTagHelperAttributeInline(context, property, node.Children[i], documentLocation); RenderTagHelperAttributeInline(context, property, node.Children[i], documentLocation);
} }
} }
else if (node is RazorIRToken token) else if (node is IntermediateToken token)
{ {
if (node.Source != null) if (node.Source != null)
{ {
@ -167,7 +167,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
context.Writer.Write(token.Content); context.Writer.Write(token.Content);
} }
else if (node is CSharpCodeIRNode) else if (node is CSharpCodeIntermediateNode)
{ {
var error = new RazorError( var error = new RazorError(
LegacyResources.TagHelpers_CodeBlocks_NotSupported_InAttributes, LegacyResources.TagHelpers_CodeBlocks_NotSupported_InAttributes,
@ -175,7 +175,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
documentLocation.Length); documentLocation.Length);
context.Diagnostics.Add(RazorDiagnostic.Create(error)); context.Diagnostics.Add(RazorDiagnostic.Create(error));
} }
else if (node is TemplateIRNode) else if (node is TemplateIntermediateNode)
{ {
var expectedTypeName = property.IsIndexerNameMatch ? property.Descriptor.IndexerTypeName : property.Descriptor.TypeName; var expectedTypeName = property.IsIndexerNameMatch ? property.Descriptor.IndexerTypeName : property.Descriptor.TypeName;
var error = new RazorError( var error = new RazorError(
@ -186,12 +186,12 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
} }
} }
private string GetContent(HtmlContentIRNode node) private string GetContent(HtmlContentIntermediateNode node)
{ {
var builder = new StringBuilder(); var builder = new StringBuilder();
for (var i = 0; i < node.Children.Count; i++) for (var i = 0; i < node.Children.Count; i++)
{ {
if (node.Children[i] is RazorIRToken token && token.IsHtml) if (node.Children[i] is IntermediateToken token && token.IsHtml)
{ {
builder.Append(token.Content); builder.Append(token.Content);
} }

View File

@ -7,6 +7,6 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
{ {
public abstract class DocumentWriter public abstract class DocumentWriter
{ {
public abstract void WriteDocument(DocumentIRNode node); public abstract void WriteDocument(DocumentIntermediateNode node);
} }
} }

View File

@ -7,6 +7,6 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
{ {
internal interface IDesignTimeDirectiveTargetExtension : ICodeTargetExtension internal interface IDesignTimeDirectiveTargetExtension : ICodeTargetExtension
{ {
void WriteDesignTimeDirective(CSharpRenderingContext context, DesignTimeDirectiveIRNode node); void WriteDesignTimeDirective(CSharpRenderingContext context, DesignTimeDirectiveIntermediateNode node);
} }
} }

View File

@ -7,12 +7,12 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
{ {
internal interface IPreallocatedAttributeTargetExtension : ICodeTargetExtension internal interface IPreallocatedAttributeTargetExtension : ICodeTargetExtension
{ {
void WriteDeclarePreallocatedTagHelperHtmlAttribute(CSharpRenderingContext context, DeclarePreallocatedTagHelperHtmlAttributeIRNode node); void WriteDeclarePreallocatedTagHelperHtmlAttribute(CSharpRenderingContext context, DeclarePreallocatedTagHelperHtmlAttributeIntermediateNode node);
void WriteAddPreallocatedTagHelperHtmlAttribute(CSharpRenderingContext context, AddPreallocatedTagHelperHtmlAttributeIRNode node); void WriteAddPreallocatedTagHelperHtmlAttribute(CSharpRenderingContext context, AddPreallocatedTagHelperHtmlAttributeIntermediateNode node);
void WriteDeclarePreallocatedTagHelperAttribute(CSharpRenderingContext context, DeclarePreallocatedTagHelperAttributeIRNode node); void WriteDeclarePreallocatedTagHelperAttribute(CSharpRenderingContext context, DeclarePreallocatedTagHelperAttributeIntermediateNode node);
void WriteSetPreallocatedTagHelperProperty(CSharpRenderingContext context, SetPreallocatedTagHelperPropertyIRNode node); void WriteSetPreallocatedTagHelperProperty(CSharpRenderingContext context, SetPreallocatedTagHelperPropertyIntermediateNode node);
} }
} }

View File

@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
public string FormatInvalidIndexerAssignmentMethodName { get; set; } = "InvalidTagHelperIndexerAssignment"; public string FormatInvalidIndexerAssignmentMethodName { get; set; } = "InvalidTagHelperIndexerAssignment";
public void WriteDeclarePreallocatedTagHelperHtmlAttribute(CSharpRenderingContext context, DeclarePreallocatedTagHelperHtmlAttributeIRNode node) public void WriteDeclarePreallocatedTagHelperHtmlAttribute(CSharpRenderingContext context, DeclarePreallocatedTagHelperHtmlAttributeIntermediateNode node)
{ {
context.Writer context.Writer
.Write("private static readonly global::") .Write("private static readonly global::")
@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
} }
} }
public void WriteAddPreallocatedTagHelperHtmlAttribute(CSharpRenderingContext context, AddPreallocatedTagHelperHtmlAttributeIRNode node) public void WriteAddPreallocatedTagHelperHtmlAttribute(CSharpRenderingContext context, AddPreallocatedTagHelperHtmlAttributeIntermediateNode node)
{ {
context.Writer context.Writer
.WriteStartInstanceMethodInvocation(ExecutionContextVariableName, ExecutionContextAddHtmlAttributeMethodName) .WriteStartInstanceMethodInvocation(ExecutionContextVariableName, ExecutionContextAddHtmlAttributeMethodName)
@ -57,7 +57,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
.WriteEndMethodInvocation(); .WriteEndMethodInvocation();
} }
public void WriteDeclarePreallocatedTagHelperAttribute(CSharpRenderingContext context, DeclarePreallocatedTagHelperAttributeIRNode node) public void WriteDeclarePreallocatedTagHelperAttribute(CSharpRenderingContext context, DeclarePreallocatedTagHelperAttributeIntermediateNode node)
{ {
context.Writer context.Writer
.Write("private static readonly global::") .Write("private static readonly global::")
@ -74,7 +74,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
.WriteEndMethodInvocation(); .WriteEndMethodInvocation();
} }
public void WriteSetPreallocatedTagHelperProperty(CSharpRenderingContext context, SetPreallocatedTagHelperPropertyIRNode node) public void WriteSetPreallocatedTagHelperProperty(CSharpRenderingContext context, SetPreallocatedTagHelperPropertyIntermediateNode node)
{ {
var tagHelperVariableName = GetTagHelperVariableName(node.TagHelperTypeName); var tagHelperVariableName = GetTagHelperVariableName(node.TagHelperTypeName);
var propertyName = node.Descriptor.GetPropertyName(); var propertyName = node.Descriptor.GetPropertyName();

View File

@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
public string TemplateTypeName { get; set; } = "Microsoft.AspNetCore.Mvc.Razor.HelperResult"; public string TemplateTypeName { get; set; } = "Microsoft.AspNetCore.Mvc.Razor.HelperResult";
public override void WriteUsingStatement(CSharpRenderingContext context, UsingStatementIRNode node) public override void WriteUsingStatement(CSharpRenderingContext context, UsingStatementIntermediateNode node)
{ {
if (node.Source.HasValue) if (node.Source.HasValue)
{ {
@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
} }
} }
public override void WriteCSharpExpression(CSharpRenderingContext context, CSharpExpressionIRNode node) public override void WriteCSharpExpression(CSharpRenderingContext context, CSharpExpressionIntermediateNode node)
{ {
if (context == null) if (context == null)
{ {
@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
for (var i = 0; i < node.Children.Count; i++) for (var i = 0; i < node.Children.Count; i++)
{ {
if (node.Children[i] is RazorIRToken token && token.IsCSharp) if (node.Children[i] is IntermediateToken token && token.IsCSharp)
{ {
context.Writer.Write(token.Content); context.Writer.Write(token.Content);
} }
@ -82,12 +82,12 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
linePragmaScope?.Dispose(); linePragmaScope?.Dispose();
} }
public override void WriteCSharpCode(CSharpRenderingContext context, CSharpCodeIRNode node) public override void WriteCSharpCode(CSharpRenderingContext context, CSharpCodeIntermediateNode node)
{ {
var isWhitespaceStatement = true; var isWhitespaceStatement = true;
for (var i = 0; i < node.Children.Count; i++) for (var i = 0; i < node.Children.Count; i++)
{ {
var token = node.Children[i] as RazorIRToken; var token = node.Children[i] as IntermediateToken;
if (token == null || !string.IsNullOrWhiteSpace(token.Content)) if (token == null || !string.IsNullOrWhiteSpace(token.Content))
{ {
isWhitespaceStatement = false; isWhitespaceStatement = false;
@ -109,7 +109,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
for (var i = 0; i < node.Children.Count; i++) for (var i = 0; i < node.Children.Count; i++)
{ {
if (node.Children[i] is RazorIRToken token && token.IsCSharp) if (node.Children[i] is IntermediateToken token && token.IsCSharp)
{ {
context.Writer.Write(token.Content); context.Writer.Write(token.Content);
} }
@ -128,15 +128,15 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
linePragmaScope?.Dispose(); linePragmaScope?.Dispose();
} }
public override void WriteHtmlAttribute(CSharpRenderingContext context, HtmlAttributeIRNode node) public override void WriteHtmlAttribute(CSharpRenderingContext context, HtmlAttributeIntermediateNode node)
{ {
var valuePieceCount = node var valuePieceCount = node
.Children .Children
.Count(child => .Count(child =>
child is HtmlAttributeValueIRNode || child is HtmlAttributeValueIntermediateNode ||
child is CSharpExpressionAttributeValueIRNode || child is CSharpExpressionAttributeValueIntermediateNode ||
child is CSharpCodeAttributeValueIRNode || child is CSharpCodeAttributeValueIntermediateNode ||
child is ExtensionIRNode); child is ExtensionIntermediateNode);
var prefixLocation = node.Source.Value.AbsoluteIndex; var prefixLocation = node.Source.Value.AbsoluteIndex;
var suffixLocation = node.Source.Value.AbsoluteIndex + node.Source.Value.Length - node.Suffix.Length; var suffixLocation = node.Source.Value.AbsoluteIndex + node.Source.Value.Length - node.Suffix.Length;
@ -162,7 +162,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
.WriteEndMethodInvocation(); .WriteEndMethodInvocation();
} }
public override void WriteHtmlAttributeValue(CSharpRenderingContext context, HtmlAttributeValueIRNode node) public override void WriteHtmlAttributeValue(CSharpRenderingContext context, HtmlAttributeValueIntermediateNode node)
{ {
var prefixLocation = node.Source.Value.AbsoluteIndex; var prefixLocation = node.Source.Value.AbsoluteIndex;
var valueLocation = node.Source.Value.AbsoluteIndex + node.Prefix.Length; var valueLocation = node.Source.Value.AbsoluteIndex + node.Prefix.Length;
@ -177,7 +177,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
// Write content // Write content
for (var i = 0; i < node.Children.Count; i++) for (var i = 0; i < node.Children.Count; i++)
{ {
if (node.Children[i] is RazorIRToken token && token.IsHtml) if (node.Children[i] is IntermediateToken token && token.IsHtml)
{ {
context.Writer.WriteStringLiteral(token.Content); context.Writer.WriteStringLiteral(token.Content);
} }
@ -198,7 +198,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
.WriteEndMethodInvocation(); .WriteEndMethodInvocation();
} }
public override void WriteCSharpExpressionAttributeValue(CSharpRenderingContext context, CSharpExpressionAttributeValueIRNode node) public override void WriteCSharpExpressionAttributeValue(CSharpRenderingContext context, CSharpExpressionAttributeValueIntermediateNode node)
{ {
using (context.Writer.BuildLinePragma(node.Source.Value)) using (context.Writer.BuildLinePragma(node.Source.Value))
{ {
@ -212,7 +212,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
for (var i = 0; i < node.Children.Count; i++) for (var i = 0; i < node.Children.Count; i++)
{ {
if (node.Children[i] is RazorIRToken token && token.IsCSharp) if (node.Children[i] is IntermediateToken token && token.IsCSharp)
{ {
context.Writer.Write(token.Content); context.Writer.Write(token.Content);
} }
@ -236,7 +236,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
} }
} }
public override void WriteCSharpCodeAttributeValue(CSharpRenderingContext context, CSharpCodeAttributeValueIRNode node) public override void WriteCSharpCodeAttributeValue(CSharpRenderingContext context, CSharpCodeAttributeValueIntermediateNode node)
{ {
const string ValueWriterName = "__razor_attribute_value_writer"; const string ValueWriterName = "__razor_attribute_value_writer";
@ -258,7 +258,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
for (var i = 0; i < node.Children.Count; i++) for (var i = 0; i < node.Children.Count; i++)
{ {
if (node.Children[i] is RazorIRToken token && token.IsCSharp) if (node.Children[i] is IntermediateToken token && token.IsCSharp)
{ {
var isWhitespaceStatement = string.IsNullOrWhiteSpace(token.Content); var isWhitespaceStatement = string.IsNullOrWhiteSpace(token.Content);
IDisposable linePragmaScope = null; IDisposable linePragmaScope = null;
@ -310,14 +310,14 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
.WriteEndMethodInvocation(); .WriteEndMethodInvocation();
} }
public override void WriteHtmlContent(CSharpRenderingContext context, HtmlContentIRNode node) public override void WriteHtmlContent(CSharpRenderingContext context, HtmlContentIntermediateNode node)
{ {
const int MaxStringLiteralLength = 1024; const int MaxStringLiteralLength = 1024;
var builder = new StringBuilder(); var builder = new StringBuilder();
for (var i = 0; i < node.Children.Count; i++) for (var i = 0; i < node.Children.Count; i++)
{ {
if (node.Children[i] is RazorIRToken token && token.IsHtml) if (node.Children[i] is IntermediateToken token && token.IsHtml)
{ {
builder.Append(token.Content); builder.Append(token.Content);
} }

View File

@ -68,7 +68,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
public string FormatInvalidIndexerAssignmentMethodName { get; set; } = "InvalidTagHelperIndexerAssignment"; public string FormatInvalidIndexerAssignmentMethodName { get; set; } = "InvalidTagHelperIndexerAssignment";
public override void WriteDeclareTagHelperFields(CSharpRenderingContext context, DeclareTagHelperFieldsIRNode node) public override void WriteDeclareTagHelperFields(CSharpRenderingContext context, DeclareTagHelperFieldsIntermediateNode node)
{ {
context.Writer.WriteLineHiddenDirective(); context.Writer.WriteLineHiddenDirective();
@ -147,7 +147,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
} }
} }
public override void WriteTagHelper(CSharpRenderingContext context, TagHelperIRNode node) public override void WriteTagHelper(CSharpRenderingContext context, TagHelperIntermediateNode node)
{ {
context.RenderChildren(node); context.RenderChildren(node);
@ -188,7 +188,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
ScopeManagerEndMethodName); ScopeManagerEndMethodName);
} }
public override void WriteTagHelperBody(CSharpRenderingContext context, TagHelperBodyIRNode node) public override void WriteTagHelperBody(CSharpRenderingContext context, TagHelperBodyIntermediateNode node)
{ {
// Call into the tag helper scope manager to start a new tag helper scope. // Call into the tag helper scope manager to start a new tag helper scope.
// Also capture the value as the current execution context. // Also capture the value as the current execution context.
@ -222,7 +222,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
context.Writer.WriteEndMethodInvocation(); context.Writer.WriteEndMethodInvocation();
} }
public override void WriteCreateTagHelper(CSharpRenderingContext context, CreateTagHelperIRNode node) public override void WriteCreateTagHelper(CSharpRenderingContext context, CreateTagHelperIntermediateNode node)
{ {
var tagHelperVariableName = GetTagHelperVariableName(node.TagHelperTypeName); var tagHelperVariableName = GetTagHelperVariableName(node.TagHelperTypeName);
@ -239,11 +239,11 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
tagHelperVariableName); tagHelperVariableName);
} }
public override void WriteAddTagHelperHtmlAttribute(CSharpRenderingContext context, AddTagHelperHtmlAttributeIRNode node) public override void WriteAddTagHelperHtmlAttribute(CSharpRenderingContext context, AddTagHelperHtmlAttributeIntermediateNode node)
{ {
var attributeValueStyleParameter = $"{HtmlAttributeValueStyleTypeName}.{node.ValueStyle}"; var attributeValueStyleParameter = $"{HtmlAttributeValueStyleTypeName}.{node.ValueStyle}";
var isConditionalAttributeValue = node.Children.Any( var isConditionalAttributeValue = node.Children.Any(
child => child is CSharpExpressionAttributeValueIRNode || child is CSharpCodeAttributeValueIRNode); child => child is CSharpExpressionAttributeValueIntermediateNode || child is CSharpCodeAttributeValueIntermediateNode);
// All simple text and minimized attributes will be pre-allocated. // All simple text and minimized attributes will be pre-allocated.
if (isConditionalAttributeValue) if (isConditionalAttributeValue)
@ -255,10 +255,10 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
// writer. // writer.
var valuePieceCount = node.Children.Count( var valuePieceCount = node.Children.Count(
child => child =>
child is HtmlAttributeValueIRNode || child is HtmlAttributeValueIntermediateNode ||
child is CSharpExpressionAttributeValueIRNode || child is CSharpExpressionAttributeValueIntermediateNode ||
child is CSharpCodeAttributeValueIRNode || child is CSharpCodeAttributeValueIntermediateNode ||
child is ExtensionIRNode); child is ExtensionIntermediateNode);
context.Writer context.Writer
.WriteStartMethodInvocation(BeginAddHtmlAttributeValuesMethodName) .WriteStartMethodInvocation(BeginAddHtmlAttributeValuesMethodName)
@ -316,7 +316,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
} }
} }
public override void WriteSetTagHelperProperty(CSharpRenderingContext context, SetTagHelperPropertyIRNode node) public override void WriteSetTagHelperProperty(CSharpRenderingContext context, SetTagHelperPropertyIntermediateNode node)
{ {
var tagHelperVariableName = GetTagHelperVariableName(node.TagHelperTypeName); var tagHelperVariableName = GetTagHelperVariableName(node.TagHelperTypeName);
var tagHelperRenderingContext = context.TagHelperRenderingContext; var tagHelperRenderingContext = context.TagHelperRenderingContext;
@ -391,7 +391,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
if (node.Descriptor.IsEnum && if (node.Descriptor.IsEnum &&
node.Children.Count == 1 && node.Children.Count == 1 &&
node.Children.First() is RazorIRToken token && node.Children.First() is IntermediateToken token &&
token.IsCSharp) token.IsCSharp)
{ {
context.Writer context.Writer
@ -421,7 +421,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
private void RenderTagHelperAttributeInline( private void RenderTagHelperAttributeInline(
CSharpRenderingContext context, CSharpRenderingContext context,
SetTagHelperPropertyIRNode property, SetTagHelperPropertyIntermediateNode property,
SourceSpan documentLocation) SourceSpan documentLocation)
{ {
for (var i = 0; i < property.Children.Count; i++) for (var i = 0; i < property.Children.Count; i++)
@ -432,22 +432,22 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
private void RenderTagHelperAttributeInline( private void RenderTagHelperAttributeInline(
CSharpRenderingContext context, CSharpRenderingContext context,
SetTagHelperPropertyIRNode property, SetTagHelperPropertyIntermediateNode property,
RazorIRNode node, IntermediateNode node,
SourceSpan documentLocation) SourceSpan documentLocation)
{ {
if (node is CSharpExpressionIRNode || node is HtmlContentIRNode) if (node is CSharpExpressionIntermediateNode || node is HtmlContentIntermediateNode)
{ {
for (var i = 0; i < node.Children.Count; i++) for (var i = 0; i < node.Children.Count; i++)
{ {
RenderTagHelperAttributeInline(context, property, node.Children[i], documentLocation); RenderTagHelperAttributeInline(context, property, node.Children[i], documentLocation);
} }
} }
else if (node is RazorIRToken token) else if (node is IntermediateToken token)
{ {
context.Writer.Write(token.Content); context.Writer.Write(token.Content);
} }
else if (node is CSharpCodeIRNode) else if (node is CSharpCodeIntermediateNode)
{ {
var error = new RazorError( var error = new RazorError(
LegacyResources.TagHelpers_CodeBlocks_NotSupported_InAttributes, LegacyResources.TagHelpers_CodeBlocks_NotSupported_InAttributes,
@ -455,7 +455,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
documentLocation.Length); documentLocation.Length);
context.Diagnostics.Add(RazorDiagnostic.Create(error)); context.Diagnostics.Add(RazorDiagnostic.Create(error));
} }
else if (node is TemplateIRNode) else if (node is TemplateIntermediateNode)
{ {
var expectedTypeName = property.IsIndexerNameMatch ? property.Descriptor.IndexerTypeName : property.Descriptor.TypeName; var expectedTypeName = property.IsIndexerNameMatch ? property.Descriptor.IndexerTypeName : property.Descriptor.TypeName;
var error = new RazorError( var error = new RazorError(

View File

@ -7,16 +7,16 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
{ {
public abstract class TagHelperWriter public abstract class TagHelperWriter
{ {
public abstract void WriteDeclareTagHelperFields(CSharpRenderingContext context, DeclareTagHelperFieldsIRNode node); public abstract void WriteDeclareTagHelperFields(CSharpRenderingContext context, DeclareTagHelperFieldsIntermediateNode node);
public abstract void WriteTagHelper(CSharpRenderingContext context, TagHelperIRNode node); public abstract void WriteTagHelper(CSharpRenderingContext context, TagHelperIntermediateNode node);
public abstract void WriteTagHelperBody(CSharpRenderingContext context, TagHelperBodyIRNode node); public abstract void WriteTagHelperBody(CSharpRenderingContext context, TagHelperBodyIntermediateNode node);
public abstract void WriteCreateTagHelper(CSharpRenderingContext context, CreateTagHelperIRNode node); public abstract void WriteCreateTagHelper(CSharpRenderingContext context, CreateTagHelperIntermediateNode node);
public abstract void WriteAddTagHelperHtmlAttribute(CSharpRenderingContext context, AddTagHelperHtmlAttributeIRNode node); public abstract void WriteAddTagHelperHtmlAttribute(CSharpRenderingContext context, AddTagHelperHtmlAttributeIntermediateNode node);
public abstract void WriteSetTagHelperProperty(CSharpRenderingContext context, SetTagHelperPropertyIRNode node); public abstract void WriteSetTagHelperProperty(CSharpRenderingContext context, SetTagHelperPropertyIntermediateNode node);
} }
} }

View File

@ -12,16 +12,16 @@ namespace Microsoft.AspNetCore.Razor.Language
protected override string DocumentKind => "default"; protected override string DocumentKind => "default";
protected override bool IsMatch(RazorCodeDocument codeDocument, DocumentIRNode irDocument) protected override bool IsMatch(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
{ {
return true; return true;
} }
protected override void OnDocumentStructureCreated( protected override void OnDocumentStructureCreated(
RazorCodeDocument codeDocument, RazorCodeDocument codeDocument,
NamespaceDeclarationIRNode @namespace, NamespaceDeclarationIntermediateNode @namespace,
ClassDeclarationIRNode @class, ClassDeclarationIntermediateNode @class,
MethodDeclarationIRNode method) MethodDeclarationIntermediateNode method)
{ {
var configuration = Engine.Features.OfType<DefaultDocumentClassifierPassFeature>().FirstOrDefault(); var configuration = Engine.Features.OfType<DefaultDocumentClassifierPassFeature>().FirstOrDefault();
if (configuration != null) if (configuration != null)

View File

@ -9,13 +9,13 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
internal class DefaultDocumentClassifierPassFeature : RazorEngineFeatureBase internal class DefaultDocumentClassifierPassFeature : RazorEngineFeatureBase
{ {
public IList<Action<RazorCodeDocument, ClassDeclarationIRNode>> ConfigureClass { get; } = public IList<Action<RazorCodeDocument, ClassDeclarationIntermediateNode>> ConfigureClass { get; } =
new List<Action<RazorCodeDocument, ClassDeclarationIRNode>>(); new List<Action<RazorCodeDocument, ClassDeclarationIntermediateNode>>();
public IList<Action<RazorCodeDocument, NamespaceDeclarationIRNode>> ConfigureNamespace { get; } = public IList<Action<RazorCodeDocument, NamespaceDeclarationIntermediateNode>> ConfigureNamespace { get; } =
new List<Action<RazorCodeDocument, NamespaceDeclarationIRNode>>(); new List<Action<RazorCodeDocument, NamespaceDeclarationIntermediateNode>>();
public IList<Action<RazorCodeDocument, MethodDeclarationIRNode>> ConfigureMethod { get; } = public IList<Action<RazorCodeDocument, MethodDeclarationIntermediateNode>> ConfigureMethod { get; } =
new List<Action<RazorCodeDocument, MethodDeclarationIRNode>>(); new List<Action<RazorCodeDocument, MethodDeclarationIntermediateNode>>();
} }
} }

View File

@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Razor.Language
protected override void ExecuteCore(RazorCodeDocument codeDocument) protected override void ExecuteCore(RazorCodeDocument codeDocument)
{ {
var irDocument = codeDocument.GetIRDocument(); var irDocument = codeDocument.GetDocumentIntermediateNode();
ThrowForMissingDocumentDependency(irDocument); ThrowForMissingDocumentDependency(irDocument);
var target = irDocument.Target; var target = irDocument.Target;
@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Razor.Language
var message = Resources.FormatDocumentMissingTarget( var message = Resources.FormatDocumentMissingTarget(
irDocument.DocumentKind, irDocument.DocumentKind,
nameof(CodeTarget), nameof(CodeTarget),
nameof(DocumentIRNode.Target)); nameof(DocumentIntermediateNode.Target));
throw new InvalidOperationException(message); throw new InvalidOperationException(message);
} }

View File

@ -4,9 +4,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language
{ {
public sealed class DefaultDiagnosticCollection : RazorDiagnosticCollection public sealed class DefaultRazorDiagnosticCollection : RazorDiagnosticCollection
{ {
private readonly List<RazorDiagnostic> _inner = new List<RazorDiagnostic>(); private readonly List<RazorDiagnostic> _inner = new List<RazorDiagnostic>();

View File

@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Razor.Language
protected override void ExecuteCore(RazorCodeDocument codeDocument) protected override void ExecuteCore(RazorCodeDocument codeDocument)
{ {
var irDocument = codeDocument.GetIRDocument(); var irDocument = codeDocument.GetDocumentIntermediateNode();
ThrowForMissingDocumentDependency(irDocument); ThrowForMissingDocumentDependency(irDocument);
foreach (var pass in Passes) foreach (var pass in Passes)
@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Razor.Language
pass.Execute(codeDocument, irDocument); pass.Execute(codeDocument, irDocument);
} }
codeDocument.SetIRDocument(irDocument); codeDocument.SetDocumentIntermediateNode(irDocument);
} }
} }
} }

View File

@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Razor.Language
protected override void ExecuteCore(RazorCodeDocument codeDocument) protected override void ExecuteCore(RazorCodeDocument codeDocument)
{ {
var irDocument = codeDocument.GetIRDocument(); var irDocument = codeDocument.GetDocumentIntermediateNode();
ThrowForMissingDocumentDependency(irDocument); ThrowForMissingDocumentDependency(irDocument);
foreach (var pass in Passes) foreach (var pass in Passes)
@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Razor.Language
pass.Execute(codeDocument, irDocument); pass.Execute(codeDocument, irDocument);
} }
codeDocument.SetIRDocument(irDocument); codeDocument.SetDocumentIntermediateNode(irDocument);
} }
} }
} }

View File

@ -1,30 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Linq;
namespace Microsoft.AspNetCore.Razor.Language
{
internal class DefaultRazorIROptimizationPhase : RazorEnginePhaseBase, IRazorIROptimizationPhase
{
public IRazorIROptimizationPass[] Passes { get; private set; }
protected override void OnIntialized()
{
Passes = Engine.Features.OfType<IRazorIROptimizationPass>().OrderBy(p => p.Order).ToArray();
}
protected override void ExecuteCore(RazorCodeDocument codeDocument)
{
var irDocument = codeDocument.GetIRDocument();
ThrowForMissingDocumentDependency(irDocument);
foreach (var pass in Passes)
{
pass.Execute(codeDocument, irDocument);
}
codeDocument.SetIRDocument(irDocument);
}
}
}

View File

@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Razor.Language.Legacy;
namespace Microsoft.AspNetCore.Razor.Language namespace Microsoft.AspNetCore.Razor.Language
{ {
internal class DefaultRazorIRLoweringPhase : RazorEnginePhaseBase, IRazorIRLoweringPhase internal class DefaultRazorIntermediateNodeLoweringPhase : RazorEnginePhaseBase, IRazorIntermediateNodeLoweringPhase
{ {
private IRazorCodeGenerationOptionsFeature[] _optionsCallbacks; private IRazorCodeGenerationOptionsFeature[] _optionsCallbacks;
@ -28,8 +28,8 @@ namespace Microsoft.AspNetCore.Razor.Language
// This might not have been set if there are no tag helpers. // This might not have been set if there are no tag helpers.
var tagHelperContext = codeDocument.GetTagHelperContext(); var tagHelperContext = codeDocument.GetTagHelperContext();
var document = new DocumentIRNode(); var document = new DocumentIntermediateNode();
var builder = RazorIRBuilder.Create(document); var builder = IntermediateNodeBuilder.Create(document);
document.Options = CreateCodeGenerationOptions(); document.Options = CreateCodeGenerationOptions();
@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.Razor.Language
var i = 0; var i = 0;
foreach (var @namespace in namespaces) foreach (var @namespace in namespaces)
{ {
var @using = new UsingStatementIRNode() var @using = new UsingStatementIntermediateNode()
{ {
Content = @namespace.Key, Content = @namespace.Key,
Source = @namespace.Value, Source = @namespace.Value,
@ -93,7 +93,7 @@ namespace Microsoft.AspNetCore.Razor.Language
} }
} }
codeDocument.SetIRDocument(document); codeDocument.SetDocumentIntermediateNode(document);
} }
private RazorCodeGenerationOptions CreateCodeGenerationOptions() private RazorCodeGenerationOptions CreateCodeGenerationOptions()
@ -109,11 +109,11 @@ namespace Microsoft.AspNetCore.Razor.Language
private class LoweringVisitor : ParserVisitor private class LoweringVisitor : ParserVisitor
{ {
protected readonly RazorIRBuilder _builder; protected readonly IntermediateNodeBuilder _builder;
protected readonly DocumentIRNode _document; protected readonly DocumentIntermediateNode _document;
protected readonly Dictionary<string, SourceSpan?> _namespaces; protected readonly Dictionary<string, SourceSpan?> _namespaces;
public LoweringVisitor(DocumentIRNode document, RazorIRBuilder builder, Dictionary<string, SourceSpan?> namespaces) public LoweringVisitor(DocumentIntermediateNode document, IntermediateNodeBuilder builder, Dictionary<string, SourceSpan?> namespaces)
{ {
_document = document; _document = document;
_builder = builder; _builder = builder;
@ -131,10 +131,10 @@ namespace Microsoft.AspNetCore.Razor.Language
public override void VisitAddTagHelperSpan(AddTagHelperChunkGenerator chunkGenerator, Span span) public override void VisitAddTagHelperSpan(AddTagHelperChunkGenerator chunkGenerator, Span span)
{ {
RazorIRNode directiveNode; IntermediateNode directiveNode;
if (IsMalformed(chunkGenerator.Diagnostics)) if (IsMalformed(chunkGenerator.Diagnostics))
{ {
directiveNode = new MalformedDirectiveIRNode() directiveNode = new MalformedDirectiveIntermediateNode()
{ {
Name = CSharpCodeParser.AddTagHelperDirectiveDescriptor.Directive, Name = CSharpCodeParser.AddTagHelperDirectiveDescriptor.Directive,
Descriptor = CSharpCodeParser.AddTagHelperDirectiveDescriptor, Descriptor = CSharpCodeParser.AddTagHelperDirectiveDescriptor,
@ -143,7 +143,7 @@ namespace Microsoft.AspNetCore.Razor.Language
} }
else else
{ {
directiveNode = new DirectiveIRNode() directiveNode = new DirectiveIntermediateNode()
{ {
Name = CSharpCodeParser.AddTagHelperDirectiveDescriptor.Directive, Name = CSharpCodeParser.AddTagHelperDirectiveDescriptor.Directive,
Descriptor = CSharpCodeParser.AddTagHelperDirectiveDescriptor, Descriptor = CSharpCodeParser.AddTagHelperDirectiveDescriptor,
@ -158,7 +158,7 @@ namespace Microsoft.AspNetCore.Razor.Language
_builder.Push(directiveNode); _builder.Push(directiveNode);
_builder.Add(new DirectiveTokenIRNode() _builder.Add(new DirectiveTokenIntermediateNode()
{ {
Content = chunkGenerator.LookupText, Content = chunkGenerator.LookupText,
Descriptor = CSharpCodeParser.AddTagHelperDirectiveDescriptor.Tokens.First(), Descriptor = CSharpCodeParser.AddTagHelperDirectiveDescriptor.Tokens.First(),
@ -170,10 +170,10 @@ namespace Microsoft.AspNetCore.Razor.Language
public override void VisitRemoveTagHelperSpan(RemoveTagHelperChunkGenerator chunkGenerator, Span span) public override void VisitRemoveTagHelperSpan(RemoveTagHelperChunkGenerator chunkGenerator, Span span)
{ {
RazorIRNode directiveNode; IntermediateNode directiveNode;
if (IsMalformed(chunkGenerator.Diagnostics)) if (IsMalformed(chunkGenerator.Diagnostics))
{ {
directiveNode = new MalformedDirectiveIRNode() directiveNode = new MalformedDirectiveIntermediateNode()
{ {
Name = CSharpCodeParser.RemoveTagHelperDirectiveDescriptor.Directive, Name = CSharpCodeParser.RemoveTagHelperDirectiveDescriptor.Directive,
Descriptor = CSharpCodeParser.RemoveTagHelperDirectiveDescriptor, Descriptor = CSharpCodeParser.RemoveTagHelperDirectiveDescriptor,
@ -182,7 +182,7 @@ namespace Microsoft.AspNetCore.Razor.Language
} }
else else
{ {
directiveNode = new DirectiveIRNode() directiveNode = new DirectiveIntermediateNode()
{ {
Name = CSharpCodeParser.RemoveTagHelperDirectiveDescriptor.Directive, Name = CSharpCodeParser.RemoveTagHelperDirectiveDescriptor.Directive,
Descriptor = CSharpCodeParser.RemoveTagHelperDirectiveDescriptor, Descriptor = CSharpCodeParser.RemoveTagHelperDirectiveDescriptor,
@ -197,7 +197,7 @@ namespace Microsoft.AspNetCore.Razor.Language
_builder.Push(directiveNode); _builder.Push(directiveNode);
_builder.Add(new DirectiveTokenIRNode() _builder.Add(new DirectiveTokenIntermediateNode()
{ {
Content = chunkGenerator.LookupText, Content = chunkGenerator.LookupText,
Descriptor = CSharpCodeParser.RemoveTagHelperDirectiveDescriptor.Tokens.First(), Descriptor = CSharpCodeParser.RemoveTagHelperDirectiveDescriptor.Tokens.First(),
@ -209,10 +209,10 @@ namespace Microsoft.AspNetCore.Razor.Language
public override void VisitTagHelperPrefixDirectiveSpan(TagHelperPrefixDirectiveChunkGenerator chunkGenerator, Span span) public override void VisitTagHelperPrefixDirectiveSpan(TagHelperPrefixDirectiveChunkGenerator chunkGenerator, Span span)
{ {
RazorIRNode directiveNode; IntermediateNode directiveNode;
if (IsMalformed(chunkGenerator.Diagnostics)) if (IsMalformed(chunkGenerator.Diagnostics))
{ {
directiveNode = new MalformedDirectiveIRNode() directiveNode = new MalformedDirectiveIntermediateNode()
{ {
Name = CSharpCodeParser.TagHelperPrefixDirectiveDescriptor.Directive, Name = CSharpCodeParser.TagHelperPrefixDirectiveDescriptor.Directive,
Descriptor = CSharpCodeParser.TagHelperPrefixDirectiveDescriptor, Descriptor = CSharpCodeParser.TagHelperPrefixDirectiveDescriptor,
@ -221,7 +221,7 @@ namespace Microsoft.AspNetCore.Razor.Language
} }
else else
{ {
directiveNode = new DirectiveIRNode() directiveNode = new DirectiveIntermediateNode()
{ {
Name = CSharpCodeParser.TagHelperPrefixDirectiveDescriptor.Directive, Name = CSharpCodeParser.TagHelperPrefixDirectiveDescriptor.Directive,
Descriptor = CSharpCodeParser.TagHelperPrefixDirectiveDescriptor, Descriptor = CSharpCodeParser.TagHelperPrefixDirectiveDescriptor,
@ -236,7 +236,7 @@ namespace Microsoft.AspNetCore.Razor.Language
_builder.Push(directiveNode); _builder.Push(directiveNode);
_builder.Add(new DirectiveTokenIRNode() _builder.Add(new DirectiveTokenIntermediateNode()
{ {
Content = chunkGenerator.Prefix, Content = chunkGenerator.Prefix,
Descriptor = CSharpCodeParser.TagHelperPrefixDirectiveDescriptor.Tokens.First(), Descriptor = CSharpCodeParser.TagHelperPrefixDirectiveDescriptor.Tokens.First(),
@ -271,7 +271,7 @@ namespace Microsoft.AspNetCore.Razor.Language
// this simple. // this simple.
private bool _insideLineDirective; private bool _insideLineDirective;
public ImportsVisitor(DocumentIRNode document, RazorIRBuilder builder, Dictionary<string, SourceSpan?> namespaces) public ImportsVisitor(DocumentIntermediateNode document, IntermediateNodeBuilder builder, Dictionary<string, SourceSpan?> namespaces)
: base(document, builder, namespaces) : base(document, builder, namespaces)
{ {
} }
@ -280,7 +280,7 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
if (_insideLineDirective) if (_insideLineDirective)
{ {
_builder.Add(new DirectiveTokenIRNode() _builder.Add(new DirectiveTokenIntermediateNode()
{ {
Content = span.Content, Content = span.Content,
Descriptor = chunkGenerator.Descriptor, Descriptor = chunkGenerator.Descriptor,
@ -295,10 +295,10 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
_insideLineDirective = true; _insideLineDirective = true;
RazorIRNode directiveNode; IntermediateNode directiveNode;
if (IsMalformed(chunkGenerator.Diagnostics)) if (IsMalformed(chunkGenerator.Diagnostics))
{ {
directiveNode = new MalformedDirectiveIRNode() directiveNode = new MalformedDirectiveIntermediateNode()
{ {
Name = chunkGenerator.Descriptor.Directive, Name = chunkGenerator.Descriptor.Directive,
Descriptor = chunkGenerator.Descriptor, Descriptor = chunkGenerator.Descriptor,
@ -307,7 +307,7 @@ namespace Microsoft.AspNetCore.Razor.Language
} }
else else
{ {
directiveNode = new DirectiveIRNode() directiveNode = new DirectiveIntermediateNode()
{ {
Name = chunkGenerator.Descriptor.Directive, Name = chunkGenerator.Descriptor.Directive,
Descriptor = chunkGenerator.Descriptor, Descriptor = chunkGenerator.Descriptor,
@ -333,10 +333,10 @@ namespace Microsoft.AspNetCore.Razor.Language
private class MainSourceVisitor : LoweringVisitor private class MainSourceVisitor : LoweringVisitor
{ {
private DeclareTagHelperFieldsIRNode _tagHelperFields; private DeclareTagHelperFieldsIntermediateNode _tagHelperFields;
private readonly string _tagHelperPrefix; private readonly string _tagHelperPrefix;
public MainSourceVisitor(DocumentIRNode document, RazorIRBuilder builder, Dictionary<string, SourceSpan?> namespaces, string tagHelperPrefix) public MainSourceVisitor(DocumentIntermediateNode document, IntermediateNodeBuilder builder, Dictionary<string, SourceSpan?> namespaces, string tagHelperPrefix)
: base(document, builder, namespaces) : base(document, builder, namespaces)
{ {
_tagHelperPrefix = tagHelperPrefix; _tagHelperPrefix = tagHelperPrefix;
@ -344,7 +344,7 @@ namespace Microsoft.AspNetCore.Razor.Language
public override void VisitDirectiveToken(DirectiveTokenChunkGenerator chunkGenerator, Span span) public override void VisitDirectiveToken(DirectiveTokenChunkGenerator chunkGenerator, Span span)
{ {
_builder.Add(new DirectiveTokenIRNode() _builder.Add(new DirectiveTokenIntermediateNode()
{ {
Content = span.Content, Content = span.Content,
Descriptor = chunkGenerator.Descriptor, Descriptor = chunkGenerator.Descriptor,
@ -354,10 +354,10 @@ namespace Microsoft.AspNetCore.Razor.Language
public override void VisitDirectiveBlock(DirectiveChunkGenerator chunkGenerator, Block block) public override void VisitDirectiveBlock(DirectiveChunkGenerator chunkGenerator, Block block)
{ {
RazorIRNode directiveNode; IntermediateNode directiveNode;
if (IsMalformed(chunkGenerator.Diagnostics)) if (IsMalformed(chunkGenerator.Diagnostics))
{ {
directiveNode = new MalformedDirectiveIRNode() directiveNode = new MalformedDirectiveIntermediateNode()
{ {
Name = chunkGenerator.Descriptor.Directive, Name = chunkGenerator.Descriptor.Directive,
Descriptor = chunkGenerator.Descriptor, Descriptor = chunkGenerator.Descriptor,
@ -366,7 +366,7 @@ namespace Microsoft.AspNetCore.Razor.Language
} }
else else
{ {
directiveNode = new DirectiveIRNode() directiveNode = new DirectiveIntermediateNode()
{ {
Name = chunkGenerator.Descriptor.Directive, Name = chunkGenerator.Descriptor.Directive,
Descriptor = chunkGenerator.Descriptor, Descriptor = chunkGenerator.Descriptor,
@ -393,7 +393,7 @@ namespace Microsoft.AspNetCore.Razor.Language
// Suffix=" // Suffix="
public override void VisitAttributeBlock(AttributeBlockChunkGenerator chunkGenerator, Block block) public override void VisitAttributeBlock(AttributeBlockChunkGenerator chunkGenerator, Block block)
{ {
_builder.Push(new HtmlAttributeIRNode() _builder.Push(new HtmlAttributeIntermediateNode()
{ {
Name = chunkGenerator.Name, Name = chunkGenerator.Name,
Prefix = chunkGenerator.Prefix, Prefix = chunkGenerator.Prefix,
@ -415,7 +415,7 @@ namespace Microsoft.AspNetCore.Razor.Language
var firstChild = block.Children.FirstOrDefault(c => c.IsBlock) as Block; var firstChild = block.Children.FirstOrDefault(c => c.IsBlock) as Block;
if (firstChild == null || firstChild.Type == BlockKindInternal.Expression) if (firstChild == null || firstChild.Type == BlockKindInternal.Expression)
{ {
_builder.Push(new CSharpExpressionAttributeValueIRNode() _builder.Push(new CSharpExpressionAttributeValueIntermediateNode()
{ {
Prefix = chunkGenerator.Prefix, Prefix = chunkGenerator.Prefix,
Source = BuildSourceSpanFromNode(block), Source = BuildSourceSpanFromNode(block),
@ -423,7 +423,7 @@ namespace Microsoft.AspNetCore.Razor.Language
} }
else else
{ {
_builder.Push(new CSharpCodeAttributeValueIRNode() _builder.Push(new CSharpCodeAttributeValueIntermediateNode()
{ {
Prefix = chunkGenerator.Prefix, Prefix = chunkGenerator.Prefix,
Source = BuildSourceSpanFromNode(block), Source = BuildSourceSpanFromNode(block),
@ -437,7 +437,7 @@ namespace Microsoft.AspNetCore.Razor.Language
public override void VisitLiteralAttributeSpan(LiteralAttributeChunkGenerator chunkGenerator, Span span) public override void VisitLiteralAttributeSpan(LiteralAttributeChunkGenerator chunkGenerator, Span span)
{ {
_builder.Push(new HtmlAttributeValueIRNode() _builder.Push(new HtmlAttributeValueIntermediateNode()
{ {
Prefix = chunkGenerator.Prefix, Prefix = chunkGenerator.Prefix,
Source = BuildSourceSpanFromNode(span), Source = BuildSourceSpanFromNode(span),
@ -455,10 +455,10 @@ namespace Microsoft.AspNetCore.Razor.Language
chunkGenerator.Value.Value.Length); chunkGenerator.Value.Value.Length);
} }
_builder.Add(new RazorIRToken() _builder.Add(new IntermediateToken()
{ {
Content = chunkGenerator.Value, Content = chunkGenerator.Value,
Kind = RazorIRToken.TokenKind.Html, Kind = IntermediateToken.TokenKind.Html,
Source = valueSpan Source = valueSpan
}); });
@ -467,7 +467,7 @@ namespace Microsoft.AspNetCore.Razor.Language
public override void VisitTemplateBlock(TemplateBlockChunkGenerator chunkGenerator, Block block) public override void VisitTemplateBlock(TemplateBlockChunkGenerator chunkGenerator, Block block)
{ {
var templateNode = new TemplateIRNode(); var templateNode = new TemplateIntermediateNode();
_builder.Push(templateNode); _builder.Push(templateNode);
VisitDefault(block); VisitDefault(block);
@ -503,13 +503,13 @@ namespace Microsoft.AspNetCore.Razor.Language
// We need to capture this in the IR so that we can give each piece the correct source mappings // We need to capture this in the IR so that we can give each piece the correct source mappings
public override void VisitExpressionBlock(ExpressionChunkGenerator chunkGenerator, Block block) public override void VisitExpressionBlock(ExpressionChunkGenerator chunkGenerator, Block block)
{ {
if (_builder.Current is CSharpExpressionAttributeValueIRNode) if (_builder.Current is CSharpExpressionAttributeValueIntermediateNode)
{ {
VisitDefault(block); VisitDefault(block);
return; return;
} }
var expressionNode = new CSharpExpressionIRNode(); var expressionNode = new CSharpExpressionIntermediateNode();
_builder.Push(expressionNode); _builder.Push(expressionNode);
@ -540,31 +540,31 @@ namespace Microsoft.AspNetCore.Razor.Language
public override void VisitExpressionSpan(ExpressionChunkGenerator chunkGenerator, Span span) public override void VisitExpressionSpan(ExpressionChunkGenerator chunkGenerator, Span span)
{ {
_builder.Add(new RazorIRToken() _builder.Add(new IntermediateToken()
{ {
Content = span.Content, Content = span.Content,
Kind = RazorIRToken.TokenKind.CSharp, Kind = IntermediateToken.TokenKind.CSharp,
Source = BuildSourceSpanFromNode(span), Source = BuildSourceSpanFromNode(span),
}); });
} }
public override void VisitStatementSpan(StatementChunkGenerator chunkGenerator, Span span) public override void VisitStatementSpan(StatementChunkGenerator chunkGenerator, Span span)
{ {
var isAttributeValue = _builder.Current is CSharpCodeAttributeValueIRNode; var isAttributeValue = _builder.Current is CSharpCodeAttributeValueIntermediateNode;
if (!isAttributeValue) if (!isAttributeValue)
{ {
var statementNode = new CSharpCodeIRNode() var statementNode = new CSharpCodeIntermediateNode()
{ {
Source = BuildSourceSpanFromNode(span) Source = BuildSourceSpanFromNode(span)
}; };
_builder.Push(statementNode); _builder.Push(statementNode);
} }
_builder.Add(new RazorIRToken() _builder.Add(new IntermediateToken()
{ {
Content = span.Content, Content = span.Content,
Kind = RazorIRToken.TokenKind.CSharp, Kind = IntermediateToken.TokenKind.CSharp,
Source = BuildSourceSpanFromNode(span), Source = BuildSourceSpanFromNode(span),
}); });
@ -590,9 +590,9 @@ namespace Microsoft.AspNetCore.Razor.Language
var source = BuildSourceSpanFromNode(span); var source = BuildSourceSpanFromNode(span);
var currentChildren = _builder.Current.Children; var currentChildren = _builder.Current.Children;
if (currentChildren.Count > 0 && currentChildren[currentChildren.Count - 1] is HtmlContentIRNode) if (currentChildren.Count > 0 && currentChildren[currentChildren.Count - 1] is HtmlContentIntermediateNode)
{ {
var existingHtmlContent = (HtmlContentIRNode)currentChildren[currentChildren.Count - 1]; var existingHtmlContent = (HtmlContentIntermediateNode)currentChildren[currentChildren.Count - 1];
if (existingHtmlContent.Source == null && source == null) if (existingHtmlContent.Source == null && source == null)
{ {
@ -610,16 +610,16 @@ namespace Microsoft.AspNetCore.Razor.Language
} }
} }
var contentNode = new HtmlContentIRNode() var contentNode = new HtmlContentIntermediateNode()
{ {
Source = source Source = source
}; };
_builder.Push(contentNode); _builder.Push(contentNode);
_builder.Add(new RazorIRToken() _builder.Add(new IntermediateToken()
{ {
Content = span.Content, Content = span.Content,
Kind = RazorIRToken.TokenKind.Html, Kind = IntermediateToken.TokenKind.Html,
Source = source, Source = source,
}); });
@ -642,7 +642,7 @@ namespace Microsoft.AspNetCore.Razor.Language
tagName = tagName.Substring(_tagHelperPrefix.Length); tagName = tagName.Substring(_tagHelperPrefix.Length);
} }
var tagHelperNode = new TagHelperIRNode() var tagHelperNode = new TagHelperIntermediateNode()
{ {
TagName = tagName, TagName = tagName,
TagMode = tagHelperBlock.TagMode, TagMode = tagHelperBlock.TagMode,
@ -656,24 +656,24 @@ namespace Microsoft.AspNetCore.Razor.Language
_builder.Push(tagHelperNode); _builder.Push(tagHelperNode);
_builder.Push(new TagHelperBodyIRNode()); _builder.Push(new TagHelperBodyIntermediateNode());
VisitDefault(block); VisitDefault(block);
_builder.Pop(); // Pop InitializeTagHelperStructureIRNode _builder.Pop(); // Pop InitializeTagHelperStructureIntermediateNode
AddTagHelperCreation(tagHelperBlock.Binding); AddTagHelperCreation(tagHelperBlock.Binding);
AddTagHelperAttributes(tagHelperBlock.Attributes, tagHelperBlock.Binding); AddTagHelperAttributes(tagHelperBlock.Attributes, tagHelperBlock.Binding);
_builder.Pop(); // Pop TagHelperIRNode _builder.Pop(); // Pop TagHelperIntermediateNode
} }
private void Combine(HtmlContentIRNode node, Span span) private void Combine(HtmlContentIntermediateNode node, Span span)
{ {
node.Children.Add(new RazorIRToken() node.Children.Add(new IntermediateToken()
{ {
Content = span.Content, Content = span.Content,
Kind = RazorIRToken.TokenKind.Html, Kind = IntermediateToken.TokenKind.Html,
Source = BuildSourceSpanFromNode(span), Source = BuildSourceSpanFromNode(span),
}); });
@ -694,7 +694,7 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
if (_tagHelperFields == null) if (_tagHelperFields == null)
{ {
_tagHelperFields = new DeclareTagHelperFieldsIRNode(); _tagHelperFields = new DeclareTagHelperFieldsIntermediateNode();
_document.Children.Add(_tagHelperFields); _document.Children.Add(_tagHelperFields);
} }
@ -711,7 +711,7 @@ namespace Microsoft.AspNetCore.Razor.Language
foreach (var descriptor in descriptors) foreach (var descriptor in descriptors)
{ {
var typeName = descriptor.GetTypeName(); var typeName = descriptor.GetTypeName();
var createTagHelper = new CreateTagHelperIRNode() var createTagHelper = new CreateTagHelperIntermediateNode()
{ {
TagHelperTypeName = typeName, TagHelperTypeName = typeName,
Descriptor = descriptor Descriptor = descriptor
@ -747,7 +747,7 @@ namespace Microsoft.AspNetCore.Razor.Language
var tagHelperTypeName = associatedDescriptor.GetTypeName(); var tagHelperTypeName = associatedDescriptor.GetTypeName();
var attributePropertyName = associatedAttributeDescriptor.GetPropertyName(); var attributePropertyName = associatedAttributeDescriptor.GetPropertyName();
var setTagHelperProperty = new SetTagHelperPropertyIRNode() var setTagHelperProperty = new SetTagHelperPropertyIntermediateNode()
{ {
PropertyName = attributePropertyName, PropertyName = attributePropertyName,
AttributeName = attribute.Name, AttributeName = attribute.Name,
@ -766,7 +766,7 @@ namespace Microsoft.AspNetCore.Razor.Language
} }
else else
{ {
var addHtmlAttribute = new AddTagHelperHtmlAttributeIRNode() var addHtmlAttribute = new AddTagHelperHtmlAttributeIntermediateNode()
{ {
Name = attribute.Name, Name = attribute.Name,
ValueStyle = attribute.ValueStyle ValueStyle = attribute.ValueStyle

View File

@ -0,0 +1,30 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Linq;
namespace Microsoft.AspNetCore.Razor.Language
{
internal class DefaultRazorOptimizationPhase : RazorEnginePhaseBase, IRazorOptimizationPhase
{
public IRazorOptimizationPass[] Passes { get; private set; }
protected override void OnIntialized()
{
Passes = Engine.Features.OfType<IRazorOptimizationPass>().OrderBy(p => p.Order).ToArray();
}
protected override void ExecuteCore(RazorCodeDocument codeDocument)
{
var documentNode = codeDocument.GetDocumentIntermediateNode();
ThrowForMissingDocumentDependency(documentNode);
foreach (var pass in Passes)
{
pass.Execute(codeDocument, documentNode);
}
codeDocument.SetDocumentIntermediateNode(documentNode);
}
}
}

View File

@ -5,45 +5,45 @@ using Microsoft.AspNetCore.Razor.Language.Intermediate;
namespace Microsoft.AspNetCore.Razor.Language namespace Microsoft.AspNetCore.Razor.Language
{ {
internal class RazorDesignTimeIRPass : RazorIRPassBase, IRazorDirectiveClassifierPass internal class DesignTimeDirectivePass : IntermediateNodePassBase, IRazorDirectiveClassifierPass
{ {
internal const string DesignTimeVariable = "__o"; internal const string DesignTimeVariable = "__o";
// This needs to run before other directive classifiers. // This needs to run before other directive classifiers.
public override int Order => -10; public override int Order => -10;
protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNode irDocument) protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
{ {
var walker = new DesignTimeHelperWalker(); var walker = new DesignTimeHelperWalker();
walker.VisitDocument(irDocument); walker.VisitDocument(documentNode);
} }
internal class DesignTimeHelperWalker : RazorIRNodeWalker internal class DesignTimeHelperWalker : IntermediateNodeWalker
{ {
private DesignTimeDirectiveIRNode _designTimeDirectiveIRNode; private DesignTimeDirectiveIntermediateNode _directiveNode;
public override void VisitClassDeclaration(ClassDeclarationIRNode node) public override void VisitClassDeclaration(ClassDeclarationIntermediateNode node)
{ {
var designTimeHelperDeclaration = new CSharpCodeIRNode(); var designTimeHelperDeclaration = new CSharpCodeIntermediateNode();
RazorIRBuilder.Create(designTimeHelperDeclaration) IntermediateNodeBuilder.Create(designTimeHelperDeclaration)
.Add(new RazorIRToken() .Add(new IntermediateToken()
{ {
Kind = RazorIRToken.TokenKind.CSharp, Kind = IntermediateToken.TokenKind.CSharp,
Content = $"private static {typeof(object).FullName} {DesignTimeVariable} = null;" Content = $"private static {typeof(object).FullName} {DesignTimeVariable} = null;"
}); });
node.Children.Insert(0, designTimeHelperDeclaration); node.Children.Insert(0, designTimeHelperDeclaration);
_designTimeDirectiveIRNode = new DesignTimeDirectiveIRNode(); _directiveNode = new DesignTimeDirectiveIntermediateNode();
VisitDefault(node); VisitDefault(node);
node.Children.Insert(0, _designTimeDirectiveIRNode); node.Children.Insert(0, _directiveNode);
} }
public override void VisitDirectiveToken(DirectiveTokenIRNode node) public override void VisitDirectiveToken(DirectiveTokenIntermediateNode node)
{ {
_designTimeDirectiveIRNode.Children.Add(node); _directiveNode.Children.Add(node);
} }
} }
} }

View File

@ -6,14 +6,14 @@ using Microsoft.AspNetCore.Razor.Language.Intermediate;
namespace Microsoft.AspNetCore.Razor.Language namespace Microsoft.AspNetCore.Razor.Language
{ {
internal class DirectiveRemovalIROptimizationPass : RazorIRPassBase, IRazorIROptimizationPass internal class DirectiveRemovalOptimizationPass : IntermediateNodePassBase, IRazorOptimizationPass
{ {
public override int Order => DefaultFeatureOrder + 50; public override int Order => DefaultFeatureOrder + 50;
protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNode irDocument) protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
{ {
var visitor = new Visitor(); var visitor = new Visitor();
visitor.VisitDocument(irDocument); visitor.VisitDocument(documentNode);
foreach (var nodeReference in visitor.DirectiveNodes) foreach (var nodeReference in visitor.DirectiveNodes)
{ {
@ -21,13 +21,13 @@ namespace Microsoft.AspNetCore.Razor.Language
} }
} }
private class Visitor : RazorIRNodeWalker private class Visitor : IntermediateNodeWalker
{ {
public IList<RazorIRNodeReference> DirectiveNodes { get; } = new List<RazorIRNodeReference>(); public IList<IntermediateNodeReference> DirectiveNodes { get; } = new List<IntermediateNodeReference>();
public override void VisitDirective(DirectiveIRNode node) public override void VisitDirective(DirectiveIntermediateNode node)
{ {
DirectiveNodes.Add(new RazorIRNodeReference(Parent, node)); DirectiveNodes.Add(new IntermediateNodeReference(Parent, node));
} }
} }
} }

View File

@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Razor.Language.Intermediate;
namespace Microsoft.AspNetCore.Razor.Language namespace Microsoft.AspNetCore.Razor.Language
{ {
public abstract class DocumentClassifierPassBase : RazorIRPassBase, IRazorDocumentClassifierPass public abstract class DocumentClassifierPassBase : IntermediateNodePassBase, IRazorDocumentClassifierPass
{ {
private static readonly ICodeTargetExtension[] EmptyExtensionArray = new ICodeTargetExtension[0]; private static readonly ICodeTargetExtension[] EmptyExtensionArray = new ICodeTargetExtension[0];
@ -22,49 +22,49 @@ namespace Microsoft.AspNetCore.Razor.Language
TargetExtensions = feature.FirstOrDefault()?.TargetExtensions.ToArray() ?? EmptyExtensionArray; TargetExtensions = feature.FirstOrDefault()?.TargetExtensions.ToArray() ?? EmptyExtensionArray;
} }
protected sealed override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNode irDocument) protected sealed override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
{ {
if (irDocument.DocumentKind != null) if (documentNode.DocumentKind != null)
{ {
return; return;
} }
if (!IsMatch(codeDocument, irDocument)) if (!IsMatch(codeDocument, documentNode))
{ {
return; return;
} }
irDocument.DocumentKind = DocumentKind; documentNode.DocumentKind = DocumentKind;
irDocument.Target = CreateTarget(codeDocument, irDocument.Options); documentNode.Target = CreateTarget(codeDocument, documentNode.Options);
Rewrite(codeDocument, irDocument); Rewrite(codeDocument, documentNode);
} }
private void Rewrite(RazorCodeDocument codeDocument, DocumentIRNode irDocument) private void Rewrite(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
{ {
// Rewrite the document from a flat structure to use a sensible default structure, // Rewrite the document from a flat structure to use a sensible default structure,
// a namespace and class declaration with a single 'razor' method. // a namespace and class declaration with a single 'razor' method.
var children = new List<RazorIRNode>(irDocument.Children); var children = new List<IntermediateNode>(documentNode.Children);
irDocument.Children.Clear(); documentNode.Children.Clear();
var @namespace = new NamespaceDeclarationIRNode(); var @namespace = new NamespaceDeclarationIntermediateNode();
@namespace.Annotations[CommonAnnotations.PrimaryNamespace] = CommonAnnotations.PrimaryNamespace; @namespace.Annotations[CommonAnnotations.PrimaryNamespace] = CommonAnnotations.PrimaryNamespace;
var @class = new ClassDeclarationIRNode(); var @class = new ClassDeclarationIntermediateNode();
@class.Annotations[CommonAnnotations.PrimaryClass] = CommonAnnotations.PrimaryClass; @class.Annotations[CommonAnnotations.PrimaryClass] = CommonAnnotations.PrimaryClass;
var method = new MethodDeclarationIRNode(); var method = new MethodDeclarationIntermediateNode();
method.Annotations[CommonAnnotations.PrimaryMethod] = CommonAnnotations.PrimaryMethod; method.Annotations[CommonAnnotations.PrimaryMethod] = CommonAnnotations.PrimaryMethod;
var documentBuilder = RazorIRBuilder.Create(irDocument); var documentBuilder = IntermediateNodeBuilder.Create(documentNode);
var namespaceBuilder = RazorIRBuilder.Create(documentBuilder.Current); var namespaceBuilder = IntermediateNodeBuilder.Create(documentBuilder.Current);
namespaceBuilder.Push(@namespace); namespaceBuilder.Push(@namespace);
var classBuilder = RazorIRBuilder.Create(namespaceBuilder.Current); var classBuilder = IntermediateNodeBuilder.Create(namespaceBuilder.Current);
classBuilder.Push(@class); classBuilder.Push(@class);
var methodBuilder = RazorIRBuilder.Create(classBuilder.Current); var methodBuilder = IntermediateNodeBuilder.Create(classBuilder.Current);
methodBuilder.Push(method); methodBuilder.Push(method);
var visitor = new Visitor(documentBuilder, namespaceBuilder, classBuilder, methodBuilder); var visitor = new Visitor(documentBuilder, namespaceBuilder, classBuilder, methodBuilder);
@ -79,7 +79,7 @@ namespace Microsoft.AspNetCore.Razor.Language
OnDocumentStructureCreated(codeDocument, @namespace, @class, method); OnDocumentStructureCreated(codeDocument, @namespace, @class, method);
} }
protected abstract bool IsMatch(RazorCodeDocument codeDocument, DocumentIRNode irDocument); protected abstract bool IsMatch(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode);
private CodeTarget CreateTarget(RazorCodeDocument codeDocument, RazorCodeGenerationOptions options) private CodeTarget CreateTarget(RazorCodeDocument codeDocument, RazorCodeGenerationOptions options)
{ {
@ -101,21 +101,21 @@ namespace Microsoft.AspNetCore.Razor.Language
protected virtual void OnDocumentStructureCreated( protected virtual void OnDocumentStructureCreated(
RazorCodeDocument codeDocument, RazorCodeDocument codeDocument,
NamespaceDeclarationIRNode @namespace, NamespaceDeclarationIntermediateNode @namespace,
ClassDeclarationIRNode @class, ClassDeclarationIntermediateNode @class,
MethodDeclarationIRNode @method) MethodDeclarationIntermediateNode @method)
{ {
// Intentionally empty. // Intentionally empty.
} }
private class Visitor : RazorIRNodeVisitor private class Visitor : IntermediateNodeVisitor
{ {
private readonly RazorIRBuilder _document; private readonly IntermediateNodeBuilder _document;
private readonly RazorIRBuilder _namespace; private readonly IntermediateNodeBuilder _namespace;
private readonly RazorIRBuilder _class; private readonly IntermediateNodeBuilder _class;
private readonly RazorIRBuilder _method; private readonly IntermediateNodeBuilder _method;
public Visitor(RazorIRBuilder document, RazorIRBuilder @namespace, RazorIRBuilder @class, RazorIRBuilder method) public Visitor(IntermediateNodeBuilder document, IntermediateNodeBuilder @namespace, IntermediateNodeBuilder @class, IntermediateNodeBuilder method)
{ {
_document = document; _document = document;
_namespace = @namespace; _namespace = @namespace;
@ -123,14 +123,14 @@ namespace Microsoft.AspNetCore.Razor.Language
_method = method; _method = method;
} }
public override void VisitUsingStatement(UsingStatementIRNode node) public override void VisitUsingStatement(UsingStatementIntermediateNode node)
{ {
var children = _namespace.Current.Children; var children = _namespace.Current.Children;
var i = children.Count - 1; var i = children.Count - 1;
for (; i >= 0; i--) for (; i >= 0; i--)
{ {
var child = children[i]; var child = children[i];
if (child is UsingStatementIRNode) if (child is UsingStatementIntermediateNode)
{ {
break; break;
} }
@ -139,14 +139,14 @@ namespace Microsoft.AspNetCore.Razor.Language
_namespace.Insert(i + 1, node); _namespace.Insert(i + 1, node);
} }
public override void VisitDeclareTagHelperFields(DeclareTagHelperFieldsIRNode node) public override void VisitDeclareTagHelperFields(DeclareTagHelperFieldsIntermediateNode node)
{ {
_class.Insert(0, node); _class.Insert(0, node);
} }
public override void VisitDefault(RazorIRNode node) public override void VisitDefault(IntermediateNode node)
{ {
if (node is MemberDeclarationIRNode) if (node is MemberDeclarationIntermediateNode)
{ {
_class.Add(node); _class.Add(node);
return; return;

View File

@ -5,17 +5,17 @@ using Microsoft.AspNetCore.Razor.Language.Intermediate;
namespace Microsoft.AspNetCore.Razor.Language.Extensions namespace Microsoft.AspNetCore.Razor.Language.Extensions
{ {
public sealed class FunctionsDirectivePass : RazorIRPassBase, IRazorDirectiveClassifierPass public sealed class FunctionsDirectivePass : IntermediateNodePassBase, IRazorDirectiveClassifierPass
{ {
protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNode irDocument) protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
{ {
var @class = irDocument.FindPrimaryClass(); var @class = documentNode.FindPrimaryClass();
if (@class == null) if (@class == null)
{ {
return; return;
} }
foreach (var functions in irDocument.FindDirectiveReferences(FunctionsDirective.Directive)) foreach (var functions in documentNode.FindDirectiveReferences(FunctionsDirective.Directive))
{ {
functions.Remove(); functions.Remove();

View File

@ -7,6 +7,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
{ {
public interface ISectionTargetExtension : ICodeTargetExtension public interface ISectionTargetExtension : ICodeTargetExtension
{ {
void WriteSection(CSharpRenderingContext context, SectionIRNode node); void WriteSection(CSharpRenderingContext context, SectionIntermediateNode node);
} }
} }

View File

@ -7,6 +7,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
{ {
public interface ITemplateTargetExtension : ICodeTargetExtension public interface ITemplateTargetExtension : ICodeTargetExtension
{ {
void WriteTemplate(CSharpRenderingContext context, TemplateIRNode node); void WriteTemplate(CSharpRenderingContext context, TemplateIntermediateNode node);
} }
} }

View File

@ -7,21 +7,21 @@ using Microsoft.AspNetCore.Razor.Language.Intermediate;
namespace Microsoft.AspNetCore.Razor.Language.Extensions namespace Microsoft.AspNetCore.Razor.Language.Extensions
{ {
public sealed class InheritsDirectivePass : RazorIRPassBase, IRazorDirectiveClassifierPass public sealed class InheritsDirectivePass : IntermediateNodePassBase, IRazorDirectiveClassifierPass
{ {
protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNode irDocument) protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
{ {
var @class = irDocument.FindPrimaryClass(); var @class = documentNode.FindPrimaryClass();
if (@class == null) if (@class == null)
{ {
return; return;
} }
foreach (var inherits in irDocument.FindDirectiveReferences(InheritsDirective.Directive)) foreach (var inherits in documentNode.FindDirectiveReferences(InheritsDirective.Directive))
{ {
inherits.Remove(); inherits.Remove();
var token = ((DirectiveIRNode)inherits.Node).Tokens.FirstOrDefault(); var token = ((DirectiveIntermediateNode)inherits.Node).Tokens.FirstOrDefault();
if (token != null) if (token != null)
{ {

View File

@ -7,21 +7,21 @@ using Microsoft.AspNetCore.Razor.Language.Intermediate;
namespace Microsoft.AspNetCore.Razor.Language.Extensions namespace Microsoft.AspNetCore.Razor.Language.Extensions
{ {
public sealed class SectionDirectivePass : RazorIRPassBase, IRazorDirectiveClassifierPass public sealed class SectionDirectivePass : IntermediateNodePassBase, IRazorDirectiveClassifierPass
{ {
protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNode irDocument) protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
{ {
var @class = irDocument.FindPrimaryClass(); var @class = documentNode.FindPrimaryClass();
if (@class == null) if (@class == null)
{ {
return; return;
} }
foreach (var directive in irDocument.FindDirectiveReferences(SectionDirective.Directive)) foreach (var directive in documentNode.FindDirectiveReferences(SectionDirective.Directive))
{ {
var sectionName = ((DirectiveIRNode)directive.Node).Tokens.FirstOrDefault()?.Content; var sectionName = ((DirectiveIntermediateNode)directive.Node).Tokens.FirstOrDefault()?.Content;
var section = new SectionIRNode() var section = new SectionIntermediateNode()
{ {
Name = sectionName, Name = sectionName,
}; };
@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
var i = 0; var i = 0;
for (; i < directive.Node.Children.Count; i++) for (; i < directive.Node.Children.Count; i++)
{ {
if (!(directive.Node.Children[i] is DirectiveTokenIRNode)) if (!(directive.Node.Children[i] is DirectiveTokenIntermediateNode))
{ {
break; break;
} }

View File

@ -7,20 +7,20 @@ using Microsoft.AspNetCore.Razor.Language.Intermediate;
namespace Microsoft.AspNetCore.Razor.Language.Extensions namespace Microsoft.AspNetCore.Razor.Language.Extensions
{ {
public sealed class SectionIRNode : ExtensionIRNode public sealed class SectionIntermediateNode : ExtensionIntermediateNode
{ {
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection();
public string Name { get; set; } public string Name { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
if (visitor == null) if (visitor == null)
{ {
throw new ArgumentNullException(nameof(visitor)); throw new ArgumentNullException(nameof(visitor));
} }
AcceptExtensionNode<SectionIRNode>(this, visitor); AcceptExtensionNode<SectionIntermediateNode>(this, visitor);
} }
public override void WriteNode(CodeTarget target, CSharpRenderingContext context) public override void WriteNode(CodeTarget target, CSharpRenderingContext context)

View File

@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
public string SectionMethodName { get; set; } = DefaultSectionMethodName; public string SectionMethodName { get; set; } = DefaultSectionMethodName;
public void WriteSection(CSharpRenderingContext context, SectionIRNode node) public void WriteSection(CSharpRenderingContext context, SectionIntermediateNode node)
{ {
// Quirk Alert! // Quirk Alert!
// //

View File

@ -7,18 +7,18 @@ using Microsoft.AspNetCore.Razor.Language.Intermediate;
namespace Microsoft.AspNetCore.Razor.Language.Extensions namespace Microsoft.AspNetCore.Razor.Language.Extensions
{ {
public sealed class TemplateIRNode : ExtensionIRNode public sealed class TemplateIntermediateNode : ExtensionIntermediateNode
{ {
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection();
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
if (visitor == null) if (visitor == null)
{ {
throw new ArgumentNullException(nameof(visitor)); throw new ArgumentNullException(nameof(visitor));
} }
AcceptExtensionNode<TemplateIRNode>(this, visitor); AcceptExtensionNode<TemplateIntermediateNode>(this, visitor);
} }
public override void WriteNode(CodeTarget target, CSharpRenderingContext context) public override void WriteNode(CodeTarget target, CSharpRenderingContext context)

View File

@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
public string TemplateTypeName { get; set; } = DefaultTemplateTypeName; public string TemplateTypeName { get; set; } = DefaultTemplateTypeName;
public void WriteTemplate(CSharpRenderingContext context, TemplateIRNode node) public void WriteTemplate(CSharpRenderingContext context, TemplateIntermediateNode node)
{ {
const string ItemParameterName = "item"; const string ItemParameterName = "item";
const string TemplateWriterName = "__razor_template_writer"; const string TemplateWriterName = "__razor_template_writer";

View File

@ -4,12 +4,12 @@
namespace Microsoft.AspNetCore.Razor.Language namespace Microsoft.AspNetCore.Razor.Language
{ {
/// <summary> /// <summary>
/// Generates C# code using the IR document. /// Generates C# code using the intermediate node document.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// After IR processing, the <see cref="IRazorCSharpLoweringPhase"/> transforms the IR document into generated C# code. /// After IR processing, the <see cref="IRazorCSharpLoweringPhase"/> transforms the intermediate node document into
/// At this time any directives or IR constructs that cannot be understood by code generation will result /// generated C# code. At this time any directives or other constructs that cannot be understood by code generation
/// in an error. /// will result in an error.
/// </remarks> /// </remarks>
public interface IRazorCSharpLoweringPhase : IRazorEnginePhase public interface IRazorCSharpLoweringPhase : IRazorEnginePhase
{ {

View File

@ -9,6 +9,6 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
int Order { get; } int Order { get; }
void Execute(RazorCodeDocument codeDocument, DocumentIRNode irDocument); void Execute(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode);
} }
} }

View File

@ -4,20 +4,19 @@
namespace Microsoft.AspNetCore.Razor.Language namespace Microsoft.AspNetCore.Razor.Language
{ {
/// <summary> /// <summary>
/// Understands directive IR nodes and performs the necessary modifications to the IR document. /// Understands directive nodes and performs the necessary modifications to the document.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// <para> /// <para>
/// The second phase of IR processing is directive classification. IR passes in this phase should interpret /// The second phase of intermediate node processing is directive classification. Passes in this phase should interpret
/// directives and processing them accordingly by transforming IR nodes or adding diagnostics to the IR. At /// directives and processing them accordingly by transforming nodes or adding diagnostics. At this time the document
/// this time the document kind has been identified, so any directive that can't be applied should trigger /// kind has been identified, so any directive that can't be applied should trigger
/// errors. If implementing a document kind that diverges from the standard structure of Razor documents /// errors. If implementing a document kind that diverges from the standard structure of Razor documents
/// it may be necessary to reimplement processing of default directives. /// it may be necessary to reimplement processing of default directives.
/// </para> /// </para>
/// <para> /// <para>
/// <see cref="IRazorDirectiveClassifierPass"/> objects are executed according to an ascending ordering of the /// <see cref="IRazorDirectiveClassifierPass"/> objects are executed according to an ascending ordering of the
/// <see cref="IRazorDirectiveClassifierPass.Order"/> property. The default configuration of <see cref="RazorEngine"/> /// <see cref="IRazorDirectiveClassifierPass.Order"/> property.
/// prescribes a logical ordering of specific phases of IR processing.
/// </para> /// </para>
/// </remarks> /// </remarks>
public interface IRazorDirectiveClassifierPhase : IRazorEnginePhase public interface IRazorDirectiveClassifierPhase : IRazorEnginePhase

View File

@ -9,6 +9,6 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
int Order { get; } int Order { get; }
void Execute(RazorCodeDocument codeDocument, DocumentIRNode irDocument); void Execute(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode);
} }
} }

View File

@ -6,21 +6,20 @@ using Microsoft.AspNetCore.Razor.Language.Intermediate;
namespace Microsoft.AspNetCore.Razor.Language namespace Microsoft.AspNetCore.Razor.Language
{ {
/// <summary> /// <summary>
/// Modifies the IR document to a desired structure. /// Modifies the intermediate node document to a desired structure.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// <para> /// <para>
/// The first phase of IR procesing is document classification. IR passes in this phase should classify the /// The first phase of intermediate node procesing is document classification. Passes in this phase should classify the
/// document according to any relevant criteria (project configuration, file extension, directive) and modify /// document according to any relevant criteria (project configuration, file extension, directive) and modify
/// the IR tree to suit the desired document shape. Document classifiers should also set /// the intermediate node document to suit the desired document shape. Document classifiers should also set
/// <see cref="DocumentIRNode.DocumentKind"/> to prevent other classifiers from running. If no classifier /// <see cref="DocumentIntermediateNode.DocumentKind"/> to prevent other classifiers from running. If no classifier
/// matches the document, then it will be classified as &quot;generic&quot; and processed according to set /// matches the document, then it will be classified as &quot;generic&quot; and processed according to set
/// of reasonable defaults. /// of reasonable defaults.
/// </para> /// </para>
/// <para> /// <para>
/// <see cref="IRazorDocumentClassifierPass"/> objects are executed according to an ascending ordering of the /// <see cref="IRazorDocumentClassifierPass"/> objects are executed according to an ascending ordering of the
/// <see cref="IRazorDocumentClassifierPass.Order"/> property. The default configuration of <see cref="RazorEngine"/> /// <see cref="IRazorDocumentClassifierPass.Order"/> property.
/// prescribes a logical ordering of specific phases of IR processing.
/// </para> /// </para>
/// </remarks> /// </remarks>
public interface IRazorDocumentClassifierPhase : IRazorEnginePhase public interface IRazorDocumentClassifierPhase : IRazorEnginePhase

View File

@ -1,19 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Razor.Language
{
/// <summary>
/// Generates the IR document from <see cref="RazorSyntaxTree"/>.
/// </summary>
/// <remarks>
/// The IR document is first produced by <see cref="IRazorIRLoweringPhase"/>. At this point no IR passes have
/// been executed. The default <see cref="IRazorIRLoweringPhase"/> will perform a mechanical transformation
/// of the syntax tree to IR resulting in a mostly flat structure. It is up to later phases to give the document
/// structure and semantics according to a document kind. The default <see cref="IRazorIRLoweringPhase"/> is
/// also responsible for synthesizing IR nodes for global cross-current concerns such as checksums or global settings.
/// </remarks>
public interface IRazorIRLoweringPhase : IRazorEnginePhase
{
}
}

View File

@ -1,24 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Razor.Language
{
/// <summary>
/// Performs necessary modifications to the IR document to optimize code generation.
/// </summary>
/// <remarks>
/// <para>
/// The last phase of IR processing is lowering. IR passes in this phase perform some kind of transformation
/// on the IR that optimizes the generated code. The key distinction here is that information may be discarded
/// during this phase.
/// </para>
/// <para>
/// <see cref="IRazorIROptimizationPass"/> objects are executed according to an ascending ordering of the
/// <see cref="IRazorIROptimizationPass.Order"/> property. The default configuration of <see cref="RazorEngine"/>
/// prescribes a logical ordering of specific phases of IR processing.
/// </para>
/// </remarks>
public interface IRazorIROptimizationPhase : IRazorEnginePhase
{
}
}

View File

@ -0,0 +1,19 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Razor.Language
{
/// <summary>
/// Generates the intermediate node document from <see cref="RazorSyntaxTree"/>.
/// </summary>
/// <remarks>
/// The document is first produced by <see cref="IRazorIntermediateNodeLoweringPhase"/>. At this point no intermediate node
/// passes have been executed. The default <see cref="IRazorIntermediateNodeLoweringPhase"/> will perform a mechanical
/// transformation of the syntax tree to intermediate nodes, resulting in a mostly flat structure. It is up to later phases
/// to give the document structure and semantics according to a document kind. The default
/// <see cref="IRazorIntermediateNodeLoweringPhase"/> is also responsible for merging nodes from imported documents.
/// </remarks>
public interface IRazorIntermediateNodeLoweringPhase : IRazorEnginePhase
{
}
}

View File

@ -5,10 +5,10 @@ using Microsoft.AspNetCore.Razor.Language.Intermediate;
namespace Microsoft.AspNetCore.Razor.Language namespace Microsoft.AspNetCore.Razor.Language
{ {
public interface IRazorIROptimizationPass : IRazorEngineFeature public interface IRazorOptimizationPass : IRazorEngineFeature
{ {
int Order { get; } int Order { get; }
void Execute(RazorCodeDocument codeDocument, DocumentIRNode irDocument); void Execute(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode);
} }
} }

View File

@ -0,0 +1,24 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Razor.Language
{
/// <summary>
/// Performs necessary modifications to the <see cref="Intermediate.DocumentIntermediateNode"/> to complete and
/// optimize code generation.
/// </summary>
/// <remarks>
/// <para>
/// The last phase of intermediate node document processing is optimization. Passes in this phase perform some
/// kind of transformation on the intermediate node document that optimizes the generated code. The key distinction
/// here is that information may be discarded during this phase.
/// </para>
/// <para>
/// <see cref="IRazorOptimizationPass"/> objects are executed according to an ascending ordering of the
/// <see cref="IRazorOptimizationPass.Order"/> property.
/// </para>
/// </remarks>
public interface IRazorOptimizationPhase : IRazorEnginePhase
{
}
}

View File

@ -6,24 +6,24 @@ using Microsoft.AspNetCore.Razor.Language.CodeGeneration;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
internal sealed class AddPreallocatedTagHelperHtmlAttributeIRNode : ExtensionIRNode internal sealed class AddPreallocatedTagHelperHtmlAttributeIntermediateNode : ExtensionIntermediateNode
{ {
public override RazorDiagnosticCollection Diagnostics { get; } = ReadOnlyDiagnosticCollection.Instance; public override RazorDiagnosticCollection Diagnostics { get; } = ReadOnlyDiagnosticCollection.Instance;
public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance; public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance;
public override bool HasDiagnostics => false; public override bool HasDiagnostics => false;
public string VariableName { get; set; } public string VariableName { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
if (visitor == null) if (visitor == null)
{ {
throw new ArgumentNullException(nameof(visitor)); throw new ArgumentNullException(nameof(visitor));
} }
AcceptExtensionNode<AddPreallocatedTagHelperHtmlAttributeIRNode>(this, visitor); AcceptExtensionNode<AddPreallocatedTagHelperHtmlAttributeIntermediateNode>(this, visitor);
} }
public override void WriteNode(CodeTarget target, CSharpRenderingContext context) public override void WriteNode(CodeTarget target, CSharpRenderingContext context)

View File

@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Razor.Language.Legacy;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class AddTagHelperHtmlAttributeIRNode : RazorIRNode public sealed class AddTagHelperHtmlAttributeIntermediateNode : IntermediateNode
{ {
private RazorDiagnosticCollection _diagnostics; private RazorDiagnosticCollection _diagnostics;
@ -18,14 +18,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
if (_diagnostics == null) if (_diagnostics == null)
{ {
_diagnostics = new DefaultDiagnosticCollection(); _diagnostics = new DefaultRazorDiagnosticCollection();
} }
return _diagnostics; return _diagnostics;
} }
} }
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection();
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
internal HtmlAttributeValueStyle ValueStyle { get; set; } internal HtmlAttributeValueStyle ValueStyle { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
if (visitor == null) if (visitor == null)
{ {

View File

@ -5,7 +5,7 @@ using System;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class CSharpCodeAttributeValueIRNode : RazorIRNode public sealed class CSharpCodeAttributeValueIntermediateNode : IntermediateNode
{ {
private RazorDiagnosticCollection _diagnostics; private RazorDiagnosticCollection _diagnostics;
@ -17,14 +17,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
if (_diagnostics == null) if (_diagnostics == null)
{ {
_diagnostics = new DefaultDiagnosticCollection(); _diagnostics = new DefaultRazorDiagnosticCollection();
} }
return _diagnostics; return _diagnostics;
} }
} }
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection();
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public string Prefix { get; set; } public string Prefix { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
if (visitor == null) if (visitor == null)
{ {

View File

@ -5,7 +5,7 @@ using System;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class CSharpCodeIRNode : RazorIRNode public sealed class CSharpCodeIntermediateNode : IntermediateNode
{ {
private ItemCollection _annotations; private ItemCollection _annotations;
private RazorDiagnosticCollection _diagnostics; private RazorDiagnosticCollection _diagnostics;
@ -29,20 +29,20 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
if (_diagnostics == null) if (_diagnostics == null)
{ {
_diagnostics = new DefaultDiagnosticCollection(); _diagnostics = new DefaultRazorDiagnosticCollection();
} }
return _diagnostics; return _diagnostics;
} }
} }
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection();
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public override bool HasDiagnostics => _diagnostics != null && _diagnostics.Count > 0; public override bool HasDiagnostics => _diagnostics != null && _diagnostics.Count > 0;
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
if (visitor == null) if (visitor == null)
{ {

View File

@ -5,7 +5,7 @@ using System;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class CSharpExpressionAttributeValueIRNode : RazorIRNode public sealed class CSharpExpressionAttributeValueIntermediateNode : IntermediateNode
{ {
private RazorDiagnosticCollection _diagnostics; private RazorDiagnosticCollection _diagnostics;
@ -17,14 +17,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
if (_diagnostics == null) if (_diagnostics == null)
{ {
_diagnostics = new DefaultDiagnosticCollection(); _diagnostics = new DefaultRazorDiagnosticCollection();
} }
return _diagnostics; return _diagnostics;
} }
} }
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection();
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public string Prefix { get; set; } public string Prefix { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
if (visitor == null) if (visitor == null)
{ {

View File

@ -5,7 +5,7 @@ using System;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class CSharpExpressionIRNode : RazorIRNode public sealed class CSharpExpressionIntermediateNode : IntermediateNode
{ {
private ItemCollection _annotations; private ItemCollection _annotations;
private RazorDiagnosticCollection _diagnostics; private RazorDiagnosticCollection _diagnostics;
@ -29,20 +29,20 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
if (_diagnostics == null) if (_diagnostics == null)
{ {
_diagnostics = new DefaultDiagnosticCollection(); _diagnostics = new DefaultRazorDiagnosticCollection();
} }
return _diagnostics; return _diagnostics;
} }
} }
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection();
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public override bool HasDiagnostics => _diagnostics != null && _diagnostics.Count > 0; public override bool HasDiagnostics => _diagnostics != null && _diagnostics.Count > 0;
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
if (visitor == null) if (visitor == null)
{ {

View File

@ -6,7 +6,7 @@ using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class ClassDeclarationIRNode : MemberDeclarationIRNode public sealed class ClassDeclarationIntermediateNode : MemberDeclarationIntermediateNode
{ {
private ItemCollection _annotations; private ItemCollection _annotations;
private RazorDiagnosticCollection _diagnostics; private RazorDiagnosticCollection _diagnostics;
@ -30,14 +30,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
if (_diagnostics == null) if (_diagnostics == null)
{ {
_diagnostics = new DefaultDiagnosticCollection(); _diagnostics = new DefaultRazorDiagnosticCollection();
} }
return _diagnostics; return _diagnostics;
} }
} }
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection();
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public IList<string> Interfaces { get; set; } public IList<string> Interfaces { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
if (visitor == null) if (visitor == null)
{ {

View File

@ -5,7 +5,7 @@ using System;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class CreateTagHelperIRNode : RazorIRNode public sealed class CreateTagHelperIntermediateNode : IntermediateNode
{ {
private RazorDiagnosticCollection _diagnostics; private RazorDiagnosticCollection _diagnostics;
@ -17,14 +17,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
if (_diagnostics == null) if (_diagnostics == null)
{ {
_diagnostics = new DefaultDiagnosticCollection(); _diagnostics = new DefaultRazorDiagnosticCollection();
} }
return _diagnostics; return _diagnostics;
} }
} }
public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance; public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance;
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public TagHelperDescriptor Descriptor { get; set; } public TagHelperDescriptor Descriptor { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
if (visitor == null) if (visitor == null)
{ {

View File

@ -7,11 +7,11 @@ using Microsoft.AspNetCore.Razor.Language.Legacy;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
internal sealed class DeclarePreallocatedTagHelperAttributeIRNode : ExtensionIRNode internal sealed class DeclarePreallocatedTagHelperAttributeIntermediateNode : ExtensionIntermediateNode
{ {
public override RazorDiagnosticCollection Diagnostics { get; } = ReadOnlyDiagnosticCollection.Instance; public override RazorDiagnosticCollection Diagnostics { get; } = ReadOnlyDiagnosticCollection.Instance;
public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance; public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance;
public override bool HasDiagnostics => false; public override bool HasDiagnostics => false;
@ -23,14 +23,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public HtmlAttributeValueStyle ValueStyle { get; set; } public HtmlAttributeValueStyle ValueStyle { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
if (visitor == null) if (visitor == null)
{ {
throw new ArgumentNullException(nameof(visitor)); throw new ArgumentNullException(nameof(visitor));
} }
AcceptExtensionNode<DeclarePreallocatedTagHelperAttributeIRNode>(this, visitor); AcceptExtensionNode<DeclarePreallocatedTagHelperAttributeIntermediateNode>(this, visitor);
} }
public override void WriteNode(CodeTarget target, CSharpRenderingContext context) public override void WriteNode(CodeTarget target, CSharpRenderingContext context)

View File

@ -7,11 +7,11 @@ using Microsoft.AspNetCore.Razor.Language.Legacy;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
internal sealed class DeclarePreallocatedTagHelperHtmlAttributeIRNode : ExtensionIRNode internal sealed class DeclarePreallocatedTagHelperHtmlAttributeIntermediateNode : ExtensionIntermediateNode
{ {
public override RazorDiagnosticCollection Diagnostics { get; } = ReadOnlyDiagnosticCollection.Instance; public override RazorDiagnosticCollection Diagnostics { get; } = ReadOnlyDiagnosticCollection.Instance;
public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance; public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance;
public override bool HasDiagnostics => false; public override bool HasDiagnostics => false;
@ -23,14 +23,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public HtmlAttributeValueStyle ValueStyle { get; set; } public HtmlAttributeValueStyle ValueStyle { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
if (visitor == null) if (visitor == null)
{ {
throw new ArgumentNullException(nameof(visitor)); throw new ArgumentNullException(nameof(visitor));
} }
AcceptExtensionNode<DeclarePreallocatedTagHelperHtmlAttributeIRNode>(this, visitor); AcceptExtensionNode<DeclarePreallocatedTagHelperHtmlAttributeIntermediateNode>(this, visitor);
} }
public override void WriteNode(CodeTarget target, CSharpRenderingContext context) public override void WriteNode(CodeTarget target, CSharpRenderingContext context)

View File

@ -6,7 +6,7 @@ using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class DeclareTagHelperFieldsIRNode : RazorIRNode public sealed class DeclareTagHelperFieldsIntermediateNode : IntermediateNode
{ {
private RazorDiagnosticCollection _diagnostics; private RazorDiagnosticCollection _diagnostics;
@ -18,14 +18,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
if (_diagnostics == null) if (_diagnostics == null)
{ {
_diagnostics = new DefaultDiagnosticCollection(); _diagnostics = new DefaultRazorDiagnosticCollection();
} }
return _diagnostics; return _diagnostics;
} }
} }
public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance; public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance;
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public ISet<string> UsedTagHelperTypeNames { get; set; } = new HashSet<string>(StringComparer.Ordinal); public ISet<string> UsedTagHelperTypeNames { get; set; } = new HashSet<string>(StringComparer.Ordinal);
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
if (visitor == null) if (visitor == null)
{ {

View File

@ -6,11 +6,11 @@ using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class DefaultIRNodeCollection : RazorIRNodeCollection public sealed class DefaultIntermediateNodeCollection : IntermediateNodeCollection
{ {
private readonly List<RazorIRNode> _inner = new List<RazorIRNode>(); private readonly List<IntermediateNode> _inner = new List<IntermediateNode>();
public override RazorIRNode this[int index] public override IntermediateNode this[int index]
{ {
get get
{ {
@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override bool IsReadOnly => false; public override bool IsReadOnly => false;
public override void Add(RazorIRNode item) public override void Add(IntermediateNode item)
{ {
if (item == null) if (item == null)
{ {
@ -51,12 +51,12 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
_inner.Clear(); _inner.Clear();
} }
public override bool Contains(RazorIRNode item) public override bool Contains(IntermediateNode item)
{ {
return _inner.Contains(item); return _inner.Contains(item);
} }
public override void CopyTo(RazorIRNode[] array, int arrayIndex) public override void CopyTo(IntermediateNode[] array, int arrayIndex)
{ {
if (array == null) if (array == null)
{ {
@ -75,12 +75,12 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
_inner.CopyTo(array, arrayIndex); _inner.CopyTo(array, arrayIndex);
} }
public override IEnumerator<RazorIRNode> GetEnumerator() public override IEnumerator<IntermediateNode> GetEnumerator()
{ {
return _inner.GetEnumerator(); return _inner.GetEnumerator();
} }
public override int IndexOf(RazorIRNode item) public override int IndexOf(IntermediateNode item)
{ {
if (item == null) if (item == null)
{ {
@ -90,7 +90,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
return _inner.IndexOf(item); return _inner.IndexOf(item);
} }
public override void Insert(int index, RazorIRNode item) public override void Insert(int index, IntermediateNode item)
{ {
if (index < 0 || index > Count) if (index < 0 || index > Count)
{ {
@ -105,7 +105,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
_inner.Insert(index, item); _inner.Insert(index, item);
} }
public override bool Remove(RazorIRNode item) public override bool Remove(IntermediateNode item)
{ {
if (item == null) if (item == null)
{ {

View File

@ -6,17 +6,17 @@ using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
internal class DefaultRazorIRBuilder : RazorIRBuilder internal class DefaultRazorIntermediateNodeBuilder : IntermediateNodeBuilder
{ {
private readonly List<RazorIRNode> _stack; private readonly List<IntermediateNode> _stack;
private int _depth; private int _depth;
public DefaultRazorIRBuilder() public DefaultRazorIntermediateNodeBuilder()
{ {
_stack = new List<RazorIRNode>(); _stack = new List<IntermediateNode>();
} }
public override RazorIRNode Current public override IntermediateNode Current
{ {
get get
{ {
@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
} }
} }
public override void Add(RazorIRNode node) public override void Add(IntermediateNode node)
{ {
if (node == null) if (node == null)
{ {
@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
Current.Children.Add(node); Current.Children.Add(node);
} }
public override void Insert(int index, RazorIRNode node) public override void Insert(int index, IntermediateNode node)
{ {
if (index < 0 || index - Current.Children.Count > 0) if (index < 0 || index - Current.Children.Count > 0)
{ {
@ -52,9 +52,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
} }
} }
public override RazorIRNode Build() public override IntermediateNode Build()
{ {
RazorIRNode node = null; IntermediateNode node = null;
while (_depth > 0) while (_depth > 0)
{ {
node = Pop(); node = Pop();
@ -63,18 +63,18 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
return node; return node;
} }
public override RazorIRNode Pop() public override IntermediateNode Pop()
{ {
if (_depth == 0) if (_depth == 0)
{ {
throw new InvalidOperationException(Resources.FormatIRBuilder_PopInvalid(nameof(Pop))); throw new InvalidOperationException(Resources.FormatIntermediateNodeBuilder_PopInvalid(nameof(Pop)));
} }
var node = _stack[--_depth]; var node = _stack[--_depth];
return node; return node;
} }
public override void Push(RazorIRNode node) public override void Push(IntermediateNode node)
{ {
if (node == null) if (node == null)
{ {

View File

@ -6,18 +6,18 @@ using Microsoft.AspNetCore.Razor.Language.CodeGeneration;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
internal sealed class DesignTimeDirectiveIRNode : ExtensionIRNode internal sealed class DesignTimeDirectiveIntermediateNode : ExtensionIntermediateNode
{ {
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection();
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
if (visitor == null) if (visitor == null)
{ {
throw new ArgumentNullException(nameof(visitor)); throw new ArgumentNullException(nameof(visitor));
} }
AcceptExtensionNode<DesignTimeDirectiveIRNode>(this, visitor); AcceptExtensionNode<DesignTimeDirectiveIntermediateNode>(this, visitor);
} }
public override void WriteNode(CodeTarget target, CSharpRenderingContext context) public override void WriteNode(CodeTarget target, CSharpRenderingContext context)

View File

@ -6,7 +6,7 @@ using System.Linq;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class DirectiveIRNode : RazorIRNode public sealed class DirectiveIntermediateNode : IntermediateNode
{ {
private ItemCollection _annotations; private ItemCollection _annotations;
private RazorDiagnosticCollection _diagnostics; private RazorDiagnosticCollection _diagnostics;
@ -30,14 +30,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
if (_diagnostics == null) if (_diagnostics == null)
{ {
_diagnostics = new DefaultDiagnosticCollection(); _diagnostics = new DefaultRazorDiagnosticCollection();
} }
return _diagnostics; return _diagnostics;
} }
} }
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection();
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
@ -45,11 +45,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public string Name { get; set; } public string Name { get; set; }
public IEnumerable<DirectiveTokenIRNode> Tokens => Children.OfType<DirectiveTokenIRNode>(); public IEnumerable<DirectiveTokenIntermediateNode> Tokens => Children.OfType<DirectiveTokenIntermediateNode>();
public DirectiveDescriptor Descriptor { get; set; } public DirectiveDescriptor Descriptor { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
visitor.VisitDirective(this); visitor.VisitDirective(this);
} }

View File

@ -3,7 +3,7 @@
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class DirectiveTokenIRNode : RazorIRNode public sealed class DirectiveTokenIntermediateNode : IntermediateNode
{ {
private RazorDiagnosticCollection _diagnostics; private RazorDiagnosticCollection _diagnostics;
@ -15,14 +15,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
if (_diagnostics == null) if (_diagnostics == null)
{ {
_diagnostics = new DefaultDiagnosticCollection(); _diagnostics = new DefaultRazorDiagnosticCollection();
} }
return _diagnostics; return _diagnostics;
} }
} }
public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance; public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance;
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public DirectiveTokenDescriptor Descriptor { get; set; } public DirectiveTokenDescriptor Descriptor { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
visitor.VisitDirectiveToken(this); visitor.VisitDirectiveToken(this);
} }

View File

@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Razor.Language.CodeGeneration;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class DocumentIRNode : RazorIRNode public sealed class DocumentIntermediateNode : IntermediateNode
{ {
private ItemCollection _annotations; private ItemCollection _annotations;
private RazorDiagnosticCollection _diagnostics; private RazorDiagnosticCollection _diagnostics;
@ -30,14 +30,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
if (_diagnostics == null) if (_diagnostics == null)
{ {
_diagnostics = new DefaultDiagnosticCollection(); _diagnostics = new DefaultRazorDiagnosticCollection();
} }
return _diagnostics; return _diagnostics;
} }
} }
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection();
public string DocumentKind { get; set; } public string DocumentKind { get; set; }
@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public CodeTarget Target { get; set; } public CodeTarget Target { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
if (visitor == null) if (visitor == null)
{ {

View File

@ -6,39 +6,39 @@ using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public static class DocumentIRNodeExtensions public static class DocumentIntermediateNodeExtensions
{ {
public static ClassDeclarationIRNode FindPrimaryClass(this DocumentIRNode node) public static ClassDeclarationIntermediateNode FindPrimaryClass(this DocumentIntermediateNode node)
{ {
if (node == null) if (node == null)
{ {
throw new ArgumentNullException(nameof(node)); throw new ArgumentNullException(nameof(node));
} }
return FindWithAnnotation<ClassDeclarationIRNode>(node, CommonAnnotations.PrimaryClass); return FindWithAnnotation<ClassDeclarationIntermediateNode>(node, CommonAnnotations.PrimaryClass);
} }
public static MethodDeclarationIRNode FindPrimaryMethod(this DocumentIRNode node) public static MethodDeclarationIntermediateNode FindPrimaryMethod(this DocumentIntermediateNode node)
{ {
if (node == null) if (node == null)
{ {
throw new ArgumentNullException(nameof(node)); throw new ArgumentNullException(nameof(node));
} }
return FindWithAnnotation<MethodDeclarationIRNode>(node, CommonAnnotations.PrimaryMethod); return FindWithAnnotation<MethodDeclarationIntermediateNode>(node, CommonAnnotations.PrimaryMethod);
} }
public static NamespaceDeclarationIRNode FindPrimaryNamespace(this DocumentIRNode node) public static NamespaceDeclarationIntermediateNode FindPrimaryNamespace(this DocumentIntermediateNode node)
{ {
if (node == null) if (node == null)
{ {
throw new ArgumentNullException(nameof(node)); throw new ArgumentNullException(nameof(node));
} }
return FindWithAnnotation<NamespaceDeclarationIRNode>(node, CommonAnnotations.PrimaryNamespace); return FindWithAnnotation<NamespaceDeclarationIntermediateNode>(node, CommonAnnotations.PrimaryNamespace);
} }
public static IReadOnlyList<RazorIRNodeReference> FindDirectiveReferences(this DocumentIRNode node, DirectiveDescriptor directive) public static IReadOnlyList<IntermediateNodeReference> FindDirectiveReferences(this DocumentIntermediateNode node, DirectiveDescriptor directive)
{ {
if (node == null) if (node == null)
{ {
@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
return visitor.Directives; return visitor.Directives;
} }
private static T FindWithAnnotation<T>(RazorIRNode node, object annotation) where T : RazorIRNode private static T FindWithAnnotation<T>(IntermediateNode node, object annotation) where T : IntermediateNode
{ {
if (node is T target && object.ReferenceEquals(target.Annotations[annotation], annotation)) if (node is T target && object.ReferenceEquals(target.Annotations[annotation], annotation))
{ {
@ -74,7 +74,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
return null; return null;
} }
private class DirectiveVisitor : RazorIRNodeWalker private class DirectiveVisitor : IntermediateNodeWalker
{ {
private readonly DirectiveDescriptor _directive; private readonly DirectiveDescriptor _directive;
@ -83,13 +83,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
_directive = directive; _directive = directive;
} }
public List<RazorIRNodeReference> Directives = new List<RazorIRNodeReference>(); public List<IntermediateNodeReference> Directives = new List<IntermediateNodeReference>();
public override void VisitDirective(DirectiveIRNode node) public override void VisitDirective(DirectiveIntermediateNode node)
{ {
if (_directive == node.Descriptor) if (_directive == node.Descriptor)
{ {
Directives.Add(new RazorIRNodeReference(Parent, node)); Directives.Add(new IntermediateNodeReference(Parent, node));
} }
base.VisitDirective(node); base.VisitDirective(node);

View File

@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Razor.Language.CodeGeneration;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public abstract class ExtensionIRNode : RazorIRNode public abstract class ExtensionIntermediateNode : IntermediateNode
{ {
private ItemCollection _annotations; private ItemCollection _annotations;
private RazorDiagnosticCollection _diagnostics; private RazorDiagnosticCollection _diagnostics;
@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
if (_diagnostics == null) if (_diagnostics == null)
{ {
_diagnostics = new DefaultDiagnosticCollection(); _diagnostics = new DefaultRazorDiagnosticCollection();
} }
return _diagnostics; return _diagnostics;
@ -42,10 +42,10 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public abstract void WriteNode(CodeTarget target, CSharpRenderingContext context); public abstract void WriteNode(CodeTarget target, CSharpRenderingContext context);
protected static void AcceptExtensionNode<TNode>(TNode node, RazorIRNodeVisitor visitor) protected static void AcceptExtensionNode<TNode>(TNode node, IntermediateNodeVisitor visitor)
where TNode : ExtensionIRNode where TNode : ExtensionIntermediateNode
{ {
var typedVisitor = visitor as IExtensionIRNodeVisitor<TNode>; var typedVisitor = visitor as IExtensionIntermediateNodeVisitor<TNode>;
if (typedVisitor == null) if (typedVisitor == null)
{ {
visitor.VisitExtension(node); visitor.VisitExtension(node);

View File

@ -6,7 +6,7 @@ using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class FieldDeclarationIRNode : MemberDeclarationIRNode public sealed class FieldDeclarationIntermediateNode : MemberDeclarationIntermediateNode
{ {
private ItemCollection _annotations; private ItemCollection _annotations;
private RazorDiagnosticCollection _diagnostics; private RazorDiagnosticCollection _diagnostics;
@ -30,14 +30,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
if (_diagnostics == null) if (_diagnostics == null)
{ {
_diagnostics = new DefaultDiagnosticCollection(); _diagnostics = new DefaultRazorDiagnosticCollection();
} }
return _diagnostics; return _diagnostics;
} }
} }
public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance; public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance;
public IList<string> Modifiers { get; set; } = new List<string>(); public IList<string> Modifiers { get; set; } = new List<string>();
@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public string Type { get; set; } public string Type { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
if (visitor == null) if (visitor == null)
{ {

View File

@ -5,7 +5,7 @@ using System;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class HtmlAttributeIRNode : RazorIRNode public sealed class HtmlAttributeIntermediateNode : IntermediateNode
{ {
private RazorDiagnosticCollection _diagnostics; private RazorDiagnosticCollection _diagnostics;
@ -17,14 +17,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
if (_diagnostics == null) if (_diagnostics == null)
{ {
_diagnostics = new DefaultDiagnosticCollection(); _diagnostics = new DefaultRazorDiagnosticCollection();
} }
return _diagnostics; return _diagnostics;
} }
} }
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection();
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public string Suffix { get; set; } public string Suffix { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
if (visitor == null) if (visitor == null)
{ {

View File

@ -6,7 +6,7 @@ using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class HtmlAttributeValueIRNode : RazorIRNode public sealed class HtmlAttributeValueIntermediateNode : IntermediateNode
{ {
private RazorDiagnosticCollection _diagnostics; private RazorDiagnosticCollection _diagnostics;
@ -18,14 +18,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
if (_diagnostics == null) if (_diagnostics == null)
{ {
_diagnostics = new DefaultDiagnosticCollection(); _diagnostics = new DefaultRazorDiagnosticCollection();
} }
return _diagnostics; return _diagnostics;
} }
} }
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection();
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public string Prefix { get; set; } public string Prefix { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
if (visitor == null) if (visitor == null)
{ {

View File

@ -6,7 +6,7 @@ using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class HtmlContentIRNode : RazorIRNode public sealed class HtmlContentIntermediateNode : IntermediateNode
{ {
private RazorDiagnosticCollection _diagnostics; private RazorDiagnosticCollection _diagnostics;
@ -18,20 +18,20 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
if (_diagnostics == null) if (_diagnostics == null)
{ {
_diagnostics = new DefaultDiagnosticCollection(); _diagnostics = new DefaultRazorDiagnosticCollection();
} }
return _diagnostics; return _diagnostics;
} }
} }
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection();
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public override bool HasDiagnostics => _diagnostics != null && _diagnostics.Count > 0; public override bool HasDiagnostics => _diagnostics != null && _diagnostics.Count > 0;
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
if (visitor == null) if (visitor == null)
{ {

View File

@ -3,7 +3,7 @@
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public interface IExtensionIRNodeVisitor<TNode> where TNode : ExtensionIRNode public interface IExtensionIntermediateNodeVisitor<TNode> where TNode : ExtensionIntermediateNode
{ {
void VisitExtension(TNode node); void VisitExtension(TNode node);
} }

View File

@ -3,18 +3,18 @@
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public abstract class RazorIRNode public abstract class IntermediateNode
{ {
public abstract ItemCollection Annotations { get; } public abstract ItemCollection Annotations { get; }
public abstract RazorDiagnosticCollection Diagnostics { get; } public abstract RazorDiagnosticCollection Diagnostics { get; }
public abstract RazorIRNodeCollection Children { get; } public abstract IntermediateNodeCollection Children { get; }
public abstract SourceSpan? Source { get; set; } public abstract SourceSpan? Source { get; set; }
public abstract bool HasDiagnostics { get; } public abstract bool HasDiagnostics { get; }
public abstract void Accept(RazorIRNodeVisitor visitor); public abstract void Accept(IntermediateNodeVisitor visitor);
} }
} }

View File

@ -0,0 +1,34 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{
public abstract class IntermediateNodeBuilder
{
public static IntermediateNodeBuilder Create(IntermediateNode root)
{
if (root == null)
{
throw new ArgumentNullException(nameof(root));
}
var builder = new DefaultRazorIntermediateNodeBuilder();
builder.Push(root);
return builder;
}
public abstract IntermediateNode Current { get; }
public abstract void Add(IntermediateNode node);
public abstract void Insert(int index, IntermediateNode node);
public abstract IntermediateNode Build();
public abstract void Push(IntermediateNode node);
public abstract IntermediateNode Pop();
}
}

View File

@ -0,0 +1,40 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections;
using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{
public abstract class IntermediateNodeCollection : IList<IntermediateNode>
{
public abstract IntermediateNode this[int index] { get; set; }
public abstract int Count { get; }
public abstract bool IsReadOnly { get; }
public abstract void Add(IntermediateNode item);
public abstract void Clear();
public abstract bool Contains(IntermediateNode item);
public abstract void CopyTo(IntermediateNode[] array, int arrayIndex);
public abstract IEnumerator<IntermediateNode> GetEnumerator();
public abstract int IndexOf(IntermediateNode item);
public abstract void Insert(int index, IntermediateNode item);
public abstract bool Remove(IntermediateNode item);
public abstract void RemoveAt(int index);
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}

View File

@ -7,11 +7,11 @@ using System.Linq;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public static class RazorIRNodeExtensions public static class IntermediateNodeExtensions
{ {
private static readonly IReadOnlyList<RazorDiagnostic> EmptyDiagnostics = Array.Empty<RazorDiagnostic>(); private static readonly IReadOnlyList<RazorDiagnostic> EmptyDiagnostics = Array.Empty<RazorDiagnostic>();
public static IReadOnlyList<RazorDiagnostic> GetAllDiagnostics(this RazorIRNode node) public static IReadOnlyList<RazorDiagnostic> GetAllDiagnostics(this IntermediateNode node)
{ {
if (node == null) if (node == null)
{ {
@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
return diagnostics?.ToList() ?? EmptyDiagnostics; return diagnostics?.ToList() ?? EmptyDiagnostics;
void AddAllDiagnostics(RazorIRNode n) void AddAllDiagnostics(IntermediateNode n)
{ {
if (n.HasDiagnostics) if (n.HasDiagnostics)
{ {

View File

@ -6,9 +6,9 @@ using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public struct RazorIRNodeReference public struct IntermediateNodeReference
{ {
public RazorIRNodeReference(RazorIRNode parent, RazorIRNode node) public IntermediateNodeReference(IntermediateNode parent, IntermediateNode node)
{ {
if (parent == null) if (parent == null)
{ {
@ -24,17 +24,17 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
Node = node; Node = node;
} }
public void Deconstruct(out RazorIRNode parent, out RazorIRNode node) public void Deconstruct(out IntermediateNode parent, out IntermediateNode node)
{ {
parent = Parent; parent = Parent;
node = Node; node = Node;
} }
public RazorIRNode Node { get; } public IntermediateNode Node { get; }
public RazorIRNode Parent { get; } public IntermediateNode Parent { get; }
public RazorIRNodeReference InsertAfter(RazorIRNode node) public IntermediateNodeReference InsertAfter(IntermediateNode node)
{ {
if (node == null) if (node == null)
{ {
@ -43,27 +43,27 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
if (Parent == null) if (Parent == null)
{ {
throw new InvalidOperationException(Resources.IRNodeReference_NotInitialized); throw new InvalidOperationException(Resources.IntermediateNodeReference_NotInitialized);
} }
if (Parent.Children.IsReadOnly) if (Parent.Children.IsReadOnly)
{ {
throw new InvalidOperationException(Resources.FormatIRNodeReference_CollectionIsReadOnly(Parent)); throw new InvalidOperationException(Resources.FormatIntermediateNodeReference_CollectionIsReadOnly(Parent));
} }
var index = Parent.Children.IndexOf(Node); var index = Parent.Children.IndexOf(Node);
if (index == -1) if (index == -1)
{ {
throw new InvalidOperationException(Resources.FormatIRNodeReference_NodeNotFound( throw new InvalidOperationException(Resources.FormatIntermediateNodeReference_NodeNotFound(
Node, Node,
Parent)); Parent));
} }
Parent.Children.Insert(index + 1, node); Parent.Children.Insert(index + 1, node);
return new RazorIRNodeReference(Parent, node); return new IntermediateNodeReference(Parent, node);
} }
public void InsertAfter(IEnumerable<RazorIRNode> nodes) public void InsertAfter(IEnumerable<IntermediateNode> nodes)
{ {
if (nodes == null) if (nodes == null)
{ {
@ -72,18 +72,18 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
if (Parent == null) if (Parent == null)
{ {
throw new InvalidOperationException(Resources.IRNodeReference_NotInitialized); throw new InvalidOperationException(Resources.IntermediateNodeReference_NotInitialized);
} }
if (Parent.Children.IsReadOnly) if (Parent.Children.IsReadOnly)
{ {
throw new InvalidOperationException(Resources.FormatIRNodeReference_CollectionIsReadOnly(Parent)); throw new InvalidOperationException(Resources.FormatIntermediateNodeReference_CollectionIsReadOnly(Parent));
} }
var index = Parent.Children.IndexOf(Node); var index = Parent.Children.IndexOf(Node);
if (index == -1) if (index == -1)
{ {
throw new InvalidOperationException(Resources.FormatIRNodeReference_NodeNotFound( throw new InvalidOperationException(Resources.FormatIntermediateNodeReference_NodeNotFound(
Node, Node,
Parent)); Parent));
} }
@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
} }
} }
public RazorIRNodeReference InsertBefore(RazorIRNode node) public IntermediateNodeReference InsertBefore(IntermediateNode node)
{ {
if (node == null) if (node == null)
{ {
@ -103,27 +103,27 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
if (Parent == null) if (Parent == null)
{ {
throw new InvalidOperationException(Resources.IRNodeReference_NotInitialized); throw new InvalidOperationException(Resources.IntermediateNodeReference_NotInitialized);
} }
if (Parent.Children.IsReadOnly) if (Parent.Children.IsReadOnly)
{ {
throw new InvalidOperationException(Resources.FormatIRNodeReference_CollectionIsReadOnly(Parent)); throw new InvalidOperationException(Resources.FormatIntermediateNodeReference_CollectionIsReadOnly(Parent));
} }
var index = Parent.Children.IndexOf(Node); var index = Parent.Children.IndexOf(Node);
if (index == -1) if (index == -1)
{ {
throw new InvalidOperationException(Resources.FormatIRNodeReference_NodeNotFound( throw new InvalidOperationException(Resources.FormatIntermediateNodeReference_NodeNotFound(
Node, Node,
Parent)); Parent));
} }
Parent.Children.Insert(index, node); Parent.Children.Insert(index, node);
return new RazorIRNodeReference(Parent, node); return new IntermediateNodeReference(Parent, node);
} }
public void InsertBefore(IEnumerable<RazorIRNode> nodes) public void InsertBefore(IEnumerable<IntermediateNode> nodes)
{ {
if (nodes == null) if (nodes == null)
{ {
@ -132,18 +132,18 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
if (Parent == null) if (Parent == null)
{ {
throw new InvalidOperationException(Resources.IRNodeReference_NotInitialized); throw new InvalidOperationException(Resources.IntermediateNodeReference_NotInitialized);
} }
if (Parent.Children.IsReadOnly) if (Parent.Children.IsReadOnly)
{ {
throw new InvalidOperationException(Resources.FormatIRNodeReference_CollectionIsReadOnly(Parent)); throw new InvalidOperationException(Resources.FormatIntermediateNodeReference_CollectionIsReadOnly(Parent));
} }
var index = Parent.Children.IndexOf(Node); var index = Parent.Children.IndexOf(Node);
if (index == -1) if (index == -1)
{ {
throw new InvalidOperationException(Resources.FormatIRNodeReference_NodeNotFound( throw new InvalidOperationException(Resources.FormatIntermediateNodeReference_NodeNotFound(
Node, Node,
Parent)); Parent));
} }
@ -158,18 +158,18 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
if (Parent == null) if (Parent == null)
{ {
throw new InvalidOperationException(Resources.IRNodeReference_NotInitialized); throw new InvalidOperationException(Resources.IntermediateNodeReference_NotInitialized);
} }
if (Parent.Children.IsReadOnly) if (Parent.Children.IsReadOnly)
{ {
throw new InvalidOperationException(Resources.FormatIRNodeReference_CollectionIsReadOnly(Parent)); throw new InvalidOperationException(Resources.FormatIntermediateNodeReference_CollectionIsReadOnly(Parent));
} }
var index = Parent.Children.IndexOf(Node); var index = Parent.Children.IndexOf(Node);
if (index == -1) if (index == -1)
{ {
throw new InvalidOperationException(Resources.FormatIRNodeReference_NodeNotFound( throw new InvalidOperationException(Resources.FormatIntermediateNodeReference_NodeNotFound(
Node, Node,
Parent)); Parent));
} }
@ -177,7 +177,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
Parent.Children.RemoveAt(index); Parent.Children.RemoveAt(index);
} }
public RazorIRNodeReference Replace(RazorIRNode node) public IntermediateNodeReference Replace(IntermediateNode node)
{ {
if (node == null) if (node == null)
{ {
@ -186,24 +186,24 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
if (Parent == null) if (Parent == null)
{ {
throw new InvalidOperationException(Resources.IRNodeReference_NotInitialized); throw new InvalidOperationException(Resources.IntermediateNodeReference_NotInitialized);
} }
if (Parent.Children.IsReadOnly) if (Parent.Children.IsReadOnly)
{ {
throw new InvalidOperationException(Resources.FormatIRNodeReference_CollectionIsReadOnly(Parent)); throw new InvalidOperationException(Resources.FormatIntermediateNodeReference_CollectionIsReadOnly(Parent));
} }
var index = Parent.Children.IndexOf(Node); var index = Parent.Children.IndexOf(Node);
if (index == -1) if (index == -1)
{ {
throw new InvalidOperationException(Resources.FormatIRNodeReference_NodeNotFound( throw new InvalidOperationException(Resources.FormatIntermediateNodeReference_NodeNotFound(
Node, Node,
Parent)); Parent));
} }
Parent.Children[index] = node; Parent.Children[index] = node;
return new RazorIRNodeReference(Parent, node); return new IntermediateNodeReference(Parent, node);
} }
} }
} }

View File

@ -3,138 +3,138 @@
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public abstract class RazorIRNodeVisitor public abstract class IntermediateNodeVisitor
{ {
public virtual void Visit(RazorIRNode node) public virtual void Visit(IntermediateNode node)
{ {
node.Accept(this); node.Accept(this);
} }
public virtual void VisitDefault(RazorIRNode node) public virtual void VisitDefault(IntermediateNode node)
{ {
} }
public virtual void VisitToken(RazorIRToken node) public virtual void VisitToken(IntermediateToken node)
{ {
VisitDefault(node); VisitDefault(node);
} }
public virtual void VisitDirectiveToken(DirectiveTokenIRNode node) public virtual void VisitDirectiveToken(DirectiveTokenIntermediateNode node)
{ {
VisitDefault(node); VisitDefault(node);
} }
public virtual void VisitDirective(DirectiveIRNode node) public virtual void VisitDirective(DirectiveIntermediateNode node)
{ {
VisitDefault(node); VisitDefault(node);
} }
public virtual void VisitMalformedDirective(MalformedDirectiveIRNode node) public virtual void VisitMalformedDirective(MalformedDirectiveIntermediateNode node)
{ {
VisitDefault(node); VisitDefault(node);
} }
public virtual void VisitExtension(ExtensionIRNode node) public virtual void VisitExtension(ExtensionIntermediateNode node)
{ {
VisitDefault(node); VisitDefault(node);
} }
public virtual void VisitCSharpCode(CSharpCodeIRNode node) public virtual void VisitCSharpCode(CSharpCodeIntermediateNode node)
{ {
VisitDefault(node); VisitDefault(node);
} }
public virtual void VisitCSharpExpression(CSharpExpressionIRNode node) public virtual void VisitCSharpExpression(CSharpExpressionIntermediateNode node)
{ {
VisitDefault(node); VisitDefault(node);
} }
public virtual void VisitHtmlAttributeValue(HtmlAttributeValueIRNode node) public virtual void VisitHtmlAttributeValue(HtmlAttributeValueIntermediateNode node)
{ {
VisitDefault(node); VisitDefault(node);
} }
public virtual void VisitCSharpExpressionAttributeValue(CSharpExpressionAttributeValueIRNode node) public virtual void VisitCSharpExpressionAttributeValue(CSharpExpressionAttributeValueIntermediateNode node)
{ {
VisitDefault(node); VisitDefault(node);
} }
public virtual void VisitCSharpCodeAttributeValue(CSharpCodeAttributeValueIRNode node) public virtual void VisitCSharpCodeAttributeValue(CSharpCodeAttributeValueIntermediateNode node)
{ {
VisitDefault(node); VisitDefault(node);
} }
public virtual void VisitHtmlAttribute(HtmlAttributeIRNode node) public virtual void VisitHtmlAttribute(HtmlAttributeIntermediateNode node)
{ {
VisitDefault(node); VisitDefault(node);
} }
public virtual void VisitClassDeclaration(ClassDeclarationIRNode node) public virtual void VisitClassDeclaration(ClassDeclarationIntermediateNode node)
{ {
VisitDefault(node); VisitDefault(node);
} }
public virtual void VisitMethodDeclaration(MethodDeclarationIRNode node) public virtual void VisitMethodDeclaration(MethodDeclarationIntermediateNode node)
{ {
VisitDefault(node); VisitDefault(node);
} }
public virtual void VisitFieldDeclaration(FieldDeclarationIRNode node) public virtual void VisitFieldDeclaration(FieldDeclarationIntermediateNode node)
{ {
VisitDefault(node); VisitDefault(node);
} }
public virtual void VisitPropertyDeclaration(PropertyDeclarationIRNode node) public virtual void VisitPropertyDeclaration(PropertyDeclarationIntermediateNode node)
{ {
VisitDefault(node); VisitDefault(node);
} }
public virtual void VisitDocument(DocumentIRNode node) public virtual void VisitDocument(DocumentIntermediateNode node)
{ {
VisitDefault(node); VisitDefault(node);
} }
public virtual void VisitHtml(HtmlContentIRNode node) public virtual void VisitHtml(HtmlContentIntermediateNode node)
{ {
VisitDefault(node); VisitDefault(node);
} }
public virtual void VisitNamespaceDeclaration(NamespaceDeclarationIRNode node) public virtual void VisitNamespaceDeclaration(NamespaceDeclarationIntermediateNode node)
{ {
VisitDefault(node); VisitDefault(node);
} }
public virtual void VisitUsingStatement(UsingStatementIRNode node) public virtual void VisitUsingStatement(UsingStatementIntermediateNode node)
{ {
VisitDefault(node); VisitDefault(node);
} }
public virtual void VisitDeclareTagHelperFields(DeclareTagHelperFieldsIRNode node) public virtual void VisitDeclareTagHelperFields(DeclareTagHelperFieldsIntermediateNode node)
{ {
VisitDefault(node); VisitDefault(node);
} }
public virtual void VisitTagHelper(TagHelperIRNode node) public virtual void VisitTagHelper(TagHelperIntermediateNode node)
{ {
VisitDefault(node); VisitDefault(node);
} }
public virtual void VisitTagHelperBody(TagHelperBodyIRNode node) public virtual void VisitTagHelperBody(TagHelperBodyIntermediateNode node)
{ {
VisitDefault(node); VisitDefault(node);
} }
public virtual void VisitCreateTagHelper(CreateTagHelperIRNode node) public virtual void VisitCreateTagHelper(CreateTagHelperIntermediateNode node)
{ {
VisitDefault(node); VisitDefault(node);
} }
public virtual void VisitSetTagHelperProperty(SetTagHelperPropertyIRNode node) public virtual void VisitSetTagHelperProperty(SetTagHelperPropertyIntermediateNode node)
{ {
VisitDefault(node); VisitDefault(node);
} }
public virtual void VisitAddTagHelperHtmlAttribute(AddTagHelperHtmlAttributeIRNode node) public virtual void VisitAddTagHelperHtmlAttribute(AddTagHelperHtmlAttributeIntermediateNode node)
{ {
VisitDefault(node); VisitDefault(node);
} }

View File

@ -5,15 +5,15 @@ using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public abstract class RazorIRNodeWalker : RazorIRNodeVisitor public abstract class IntermediateNodeWalker : IntermediateNodeVisitor
{ {
private readonly Stack<RazorIRNode> _ancestors = new Stack<RazorIRNode>(); private readonly Stack<IntermediateNode> _ancestors = new Stack<IntermediateNode>();
protected IEnumerable<RazorIRNode> Ancestors => _ancestors; protected IEnumerable<IntermediateNode> Ancestors => _ancestors;
protected RazorIRNode Parent => _ancestors.Count > 0 ? _ancestors.Peek() : null; protected IntermediateNode Parent => _ancestors.Count > 0 ? _ancestors.Peek() : null;
public override void VisitDefault(RazorIRNode node) public override void VisitDefault(IntermediateNode node)
{ {
var children = node.Children; var children = node.Children;
if (node.Children.Count == 0) if (node.Children.Count == 0)

View File

@ -5,7 +5,7 @@ using System;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class RazorIRToken : RazorIRNode public sealed class IntermediateToken : IntermediateNode
{ {
private RazorDiagnosticCollection _diagnostics; private RazorDiagnosticCollection _diagnostics;
@ -17,14 +17,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
if (_diagnostics == null) if (_diagnostics == null)
{ {
_diagnostics = new DefaultDiagnosticCollection(); _diagnostics = new DefaultRazorDiagnosticCollection();
} }
return _diagnostics; return _diagnostics;
} }
} }
public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance; public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance;
public string Content { get; set; } public string Content { get; set; }
@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override bool HasDiagnostics => _diagnostics != null && _diagnostics.Count > 0; public override bool HasDiagnostics => _diagnostics != null && _diagnostics.Count > 0;
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
if (visitor == null) if (visitor == null)
{ {

View File

@ -6,7 +6,7 @@ using System.Linq;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class MalformedDirectiveIRNode : RazorIRNode public sealed class MalformedDirectiveIntermediateNode : IntermediateNode
{ {
private RazorDiagnosticCollection _diagnostics; private RazorDiagnosticCollection _diagnostics;
@ -18,14 +18,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
if (_diagnostics == null) if (_diagnostics == null)
{ {
_diagnostics = new DefaultDiagnosticCollection(); _diagnostics = new DefaultRazorDiagnosticCollection();
} }
return _diagnostics; return _diagnostics;
} }
} }
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection();
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
@ -33,11 +33,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public string Name { get; set; } public string Name { get; set; }
public IEnumerable<DirectiveTokenIRNode> Tokens => Children.OfType<DirectiveTokenIRNode>(); public IEnumerable<DirectiveTokenIntermediateNode> Tokens => Children.OfType<DirectiveTokenIntermediateNode>();
public DirectiveDescriptor Descriptor { get; set; } public DirectiveDescriptor Descriptor { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
visitor.VisitMalformedDirective(this); visitor.VisitMalformedDirective(this);
} }

View File

@ -3,7 +3,7 @@
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public abstract class MemberDeclarationIRNode : RazorIRNode public abstract class MemberDeclarationIntermediateNode : IntermediateNode
{ {
} }
} }

View File

@ -6,7 +6,7 @@ using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class MethodDeclarationIRNode : MemberDeclarationIRNode public sealed class MethodDeclarationIntermediateNode : MemberDeclarationIntermediateNode
{ {
private ItemCollection _annotations; private ItemCollection _annotations;
private RazorDiagnosticCollection _diagnostics; private RazorDiagnosticCollection _diagnostics;
@ -30,14 +30,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
if (_diagnostics == null) if (_diagnostics == null)
{ {
_diagnostics = new DefaultDiagnosticCollection(); _diagnostics = new DefaultRazorDiagnosticCollection();
} }
return _diagnostics; return _diagnostics;
} }
} }
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection();
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public string ReturnType { get; set; } public string ReturnType { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
if (visitor == null) if (visitor == null)
{ {

View File

@ -5,7 +5,7 @@ using System;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class NamespaceDeclarationIRNode : RazorIRNode public sealed class NamespaceDeclarationIntermediateNode : IntermediateNode
{ {
private ItemCollection _annotations; private ItemCollection _annotations;
private RazorDiagnosticCollection _diagnostics; private RazorDiagnosticCollection _diagnostics;
@ -29,14 +29,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
if (_diagnostics == null) if (_diagnostics == null)
{ {
_diagnostics = new DefaultDiagnosticCollection(); _diagnostics = new DefaultRazorDiagnosticCollection();
} }
return _diagnostics; return _diagnostics;
} }
} }
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override IntermediateNodeCollection Children { get; } = new DefaultIntermediateNodeCollection();
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public string Content { get; set; } public string Content { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
if (visitor == null) if (visitor == null)
{ {

View File

@ -6,7 +6,7 @@ using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class PropertyDeclarationIRNode : MemberDeclarationIRNode public sealed class PropertyDeclarationIntermediateNode : MemberDeclarationIntermediateNode
{ {
private ItemCollection _annotations; private ItemCollection _annotations;
private RazorDiagnosticCollection _diagnostics; private RazorDiagnosticCollection _diagnostics;
@ -30,14 +30,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
if (_diagnostics == null) if (_diagnostics == null)
{ {
_diagnostics = new DefaultDiagnosticCollection(); _diagnostics = new DefaultRazorDiagnosticCollection();
} }
return _diagnostics; return _diagnostics;
} }
} }
public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance; public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance;
public IList<string> Modifiers { get; set; } = new List<string>(); public IList<string> Modifiers { get; set; } = new List<string>();
@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public string Type { get; set; } public string Type { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
if (visitor == null) if (visitor == null)
{ {

View File

@ -1,34 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{
public abstract class RazorIRBuilder
{
public static RazorIRBuilder Create(RazorIRNode root)
{
if (root == null)
{
throw new ArgumentNullException(nameof(root));
}
var builder = new DefaultRazorIRBuilder();
builder.Push(root);
return builder;
}
public abstract RazorIRNode Current { get; }
public abstract void Add(RazorIRNode node);
public abstract void Insert(int index, RazorIRNode node);
public abstract RazorIRNode Build();
public abstract void Push(RazorIRNode node);
public abstract RazorIRNode Pop();
}
}

View File

@ -1,40 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections;
using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{
public abstract class RazorIRNodeCollection : IList<RazorIRNode>
{
public abstract RazorIRNode this[int index] { get; set; }
public abstract int Count { get; }
public abstract bool IsReadOnly { get; }
public abstract void Add(RazorIRNode item);
public abstract void Clear();
public abstract bool Contains(RazorIRNode item);
public abstract void CopyTo(RazorIRNode[] array, int arrayIndex);
public abstract IEnumerator<RazorIRNode> GetEnumerator();
public abstract int IndexOf(RazorIRNode item);
public abstract void Insert(int index, RazorIRNode item);
public abstract bool Remove(RazorIRNode item);
public abstract void RemoveAt(int index);
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}

View File

@ -7,15 +7,15 @@ using System.Linq;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class ReadOnlyIRNodeCollection : RazorIRNodeCollection public sealed class ReadOnlyIntermediateNodeCollection : IntermediateNodeCollection
{ {
public static readonly ReadOnlyIRNodeCollection Instance = new ReadOnlyIRNodeCollection(); public static readonly ReadOnlyIntermediateNodeCollection Instance = new ReadOnlyIntermediateNodeCollection();
private ReadOnlyIRNodeCollection() private ReadOnlyIntermediateNodeCollection()
{ {
} }
public override RazorIRNode this[int index] public override IntermediateNode this[int index]
{ {
get get
{ {
@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override bool IsReadOnly => true; public override bool IsReadOnly => true;
public override void Add(RazorIRNode item) public override void Add(IntermediateNode item)
{ {
if (item == null) if (item == null)
{ {
@ -56,12 +56,12 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
throw new NotSupportedException(); throw new NotSupportedException();
} }
public override bool Contains(RazorIRNode item) public override bool Contains(IntermediateNode item)
{ {
return false; return false;
} }
public override void CopyTo(RazorIRNode[] array, int arrayIndex) public override void CopyTo(IntermediateNode[] array, int arrayIndex)
{ {
if (array == null) if (array == null)
{ {
@ -80,12 +80,12 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
throw new NotSupportedException(); throw new NotSupportedException();
} }
public override IEnumerator<RazorIRNode> GetEnumerator() public override IEnumerator<IntermediateNode> GetEnumerator()
{ {
return Enumerable.Empty<RazorIRNode>().GetEnumerator(); return Enumerable.Empty<IntermediateNode>().GetEnumerator();
} }
public override int IndexOf(RazorIRNode item) public override int IndexOf(IntermediateNode item)
{ {
if (item == null) if (item == null)
{ {
@ -95,7 +95,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
return -1; return -1;
} }
public override void Insert(int index, RazorIRNode item) public override void Insert(int index, IntermediateNode item)
{ {
if (index < 0 || index > Count) if (index < 0 || index > Count)
{ {
@ -110,7 +110,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
throw new NotSupportedException(); throw new NotSupportedException();
} }
public override bool Remove(RazorIRNode item) public override bool Remove(IntermediateNode item)
{ {
if (item == null) if (item == null)
{ {

View File

@ -6,11 +6,11 @@ using Microsoft.AspNetCore.Razor.Language.CodeGeneration;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
internal sealed class SetPreallocatedTagHelperPropertyIRNode : ExtensionIRNode internal sealed class SetPreallocatedTagHelperPropertyIntermediateNode : ExtensionIntermediateNode
{ {
public override RazorDiagnosticCollection Diagnostics => ReadOnlyDiagnosticCollection.Instance; public override RazorDiagnosticCollection Diagnostics => ReadOnlyDiagnosticCollection.Instance;
public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance; public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance;
public override bool HasDiagnostics => false; public override bool HasDiagnostics => false;
@ -28,14 +28,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public bool IsIndexerNameMatch { get; set; } public bool IsIndexerNameMatch { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(IntermediateNodeVisitor visitor)
{ {
if (visitor == null) if (visitor == null)
{ {
throw new ArgumentNullException(nameof(visitor)); throw new ArgumentNullException(nameof(visitor));
} }
AcceptExtensionNode<SetPreallocatedTagHelperPropertyIRNode>(this, visitor); AcceptExtensionNode<SetPreallocatedTagHelperPropertyIntermediateNode>(this, visitor);
} }
public override void WriteNode(CodeTarget target, CSharpRenderingContext context) public override void WriteNode(CodeTarget target, CSharpRenderingContext context)

Some files were not shown because too many files have changed in this diff Show More