Get rid of Parent from IR node

This commit is contained in:
Ryan Nowak 2017-06-08 18:51:22 -07:00
parent 14944a2791
commit 503ba669d0
55 changed files with 169 additions and 236 deletions

View File

@ -59,7 +59,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{ {
TypeName = typeName, TypeName = typeName,
MemberName = memberName, MemberName = memberName,
Parent = visitor.Class,
}; };
visitor.Class.Children.Add(injectNode); visitor.Class.Children.Add(injectNode);

View File

@ -16,8 +16,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance; public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance;
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(RazorIRNodeVisitor visitor)

View File

@ -30,10 +30,7 @@ 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 CSharpCodeIRNode();
{
Parent = item.Node.Parent
};
RazorIRBuilder.Create(beginNode) RazorIRBuilder.Create(beginNode)
.Add(new RazorIRToken() .Add(new RazorIRToken()
{ {
@ -45,10 +42,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
item.IsLiteral ? "true" : "false") item.IsLiteral ? "true" : "false")
}); });
var endNode = new CSharpCodeIRNode() var endNode = new CSharpCodeIRNode();
{
Parent = item.Node.Parent
};
RazorIRBuilder.Create(endNode) RazorIRBuilder.Create(endNode)
.Add(new RazorIRToken() .Add(new RazorIRToken()
{ {
@ -56,22 +50,25 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
Content = string.Format("{0}();", endContextMethodName) Content = string.Format("{0}();", endContextMethodName)
}); });
var nodeIndex = item.Node.Parent.Children.IndexOf(item.Node); var nodeIndex = item.Parent.Children.IndexOf(item.Node);
item.Node.Parent.Children.Insert(nodeIndex, beginNode); item.Parent.Children.Insert(nodeIndex, beginNode);
item.Node.Parent.Children.Insert(nodeIndex + 2, endNode); item.Parent.Children.Insert(nodeIndex + 2, endNode);
} }
private struct InstrumentationItem private struct InstrumentationItem
{ {
public InstrumentationItem(RazorIRNode node, bool isLiteral, SourceSpan source) public InstrumentationItem(RazorIRNode node, RazorIRNode parent, bool isLiteral, SourceSpan source)
{ {
Node = node; Node = node;
Parent = parent;
IsLiteral = isLiteral; IsLiteral = isLiteral;
Source = source; Source = source;
} }
public RazorIRNode Node { get; } public RazorIRNode Node { get; }
public RazorIRNode Parent { get; }
public bool IsLiteral { get; } public bool IsLiteral { get; }
public SourceSpan Source { get; } public SourceSpan Source { get; }
@ -85,7 +82,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{ {
if (node.Source != null) if (node.Source != null)
{ {
Items.Add(new InstrumentationItem(node, isLiteral: true, source: node.Source.Value)); Items.Add(new InstrumentationItem(node, Parent, isLiteral: true, source: node.Source.Value));
} }
VisitDefault(node); VisitDefault(node);
@ -95,7 +92,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{ {
if (node.Source != null) if (node.Source != null)
{ {
Items.Add(new InstrumentationItem(node, isLiteral: false, source: node.Source.Value)); Items.Add(new InstrumentationItem(node, Parent, isLiteral: false, source: node.Source.Value));
} }
VisitDefault(node); VisitDefault(node);
@ -105,7 +102,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{ {
if (node.Source != null) if (node.Source != null)
{ {
Items.Add(new InstrumentationItem(node, isLiteral: false, source: node.Source.Value)); Items.Add(new InstrumentationItem(node, Parent, isLiteral: false, source: node.Source.Value));
} }
VisitDefault(node); VisitDefault(node);

View File

@ -79,7 +79,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
node.Children.Clear(); node.Children.Clear();
node.Children.Add(expression); node.Children.Add(expression);
expression.Parent = node;
} }
} }
} }

View File

@ -22,10 +22,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
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 CSharpCodeIRNode();
{
Parent = @class
};
RazorIRBuilder.Create(vddProperty) RazorIRBuilder.Create(vddProperty)
.Add(new RazorIRToken() .Add(new RazorIRToken()
{ {
@ -34,10 +31,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
}); });
@class.Children.Add(vddProperty); @class.Children.Add(vddProperty);
var modelProperty = new CSharpCodeIRNode() var modelProperty = new CSharpCodeIRNode();
{
Parent = @class
};
RazorIRBuilder.Create(modelProperty) RazorIRBuilder.Create(modelProperty)
.Add(new RazorIRToken() .Add(new RazorIRToken()
{ {

View File

@ -37,9 +37,9 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
} }
} }
foreach (var createNode in visitor.CreateTagHelpers) foreach (var (node, parent) in visitor.CreateTagHelpers)
{ {
RewriteCreateNode(visitor.Namespace, visitor.Class, createNode); RewriteCreateNode(visitor.Namespace, visitor.Class, node, parent);
} }
} }
@ -48,10 +48,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
var writer = new CSharpCodeWriter(); var writer = new CSharpCodeWriter();
WriteClass(writer, tagHelper); WriteClass(writer, tagHelper);
var statement = new CSharpCodeIRNode() var statement = new CSharpCodeIRNode();
{
Parent = @class
};
RazorIRBuilder.Create(statement) RazorIRBuilder.Create(statement)
.Add(new RazorIRToken() .Add(new RazorIRToken()
{ {
@ -65,12 +62,13 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
private void RewriteCreateNode( private void RewriteCreateNode(
NamespaceDeclarationIRNode @namespace, NamespaceDeclarationIRNode @namespace,
ClassDeclarationIRNode @class, ClassDeclarationIRNode @class,
CreateTagHelperIRNode node) CreateTagHelperIRNode node,
RazorIRNode parent)
{ {
var newTypeName = GetVCTHFullName(@namespace, @class, node.Descriptor); var newTypeName = GetVCTHFullName(@namespace, @class, node.Descriptor);
for (var i = 0; i < node.Parent.Children.Count; i++) for (var i = 0; i < parent.Children.Count; i++)
{ {
if (node.Parent.Children[i] is SetTagHelperPropertyIRNode setProperty && if (parent.Children[i] is SetTagHelperPropertyIRNode setProperty &&
node.Descriptor.BoundAttributes.Contains(setProperty.Descriptor)) node.Descriptor.BoundAttributes.Contains(setProperty.Descriptor))
{ {
setProperty.TagHelperTypeName = newTypeName; setProperty.TagHelperTypeName = newTypeName;
@ -232,7 +230,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
public NamespaceDeclarationIRNode Namespace { get; private set; } public NamespaceDeclarationIRNode Namespace { get; private set; }
public List<CreateTagHelperIRNode> CreateTagHelpers { get; } = new List<CreateTagHelperIRNode>(); public List<(CreateTagHelperIRNode node, RazorIRNode parent)> CreateTagHelpers { get; } = new List<(CreateTagHelperIRNode node, RazorIRNode parent)>();
public Dictionary<string, TagHelperDescriptor> TagHelpers { get; } = new Dictionary<string, TagHelperDescriptor>(); public Dictionary<string, TagHelperDescriptor> TagHelpers { get; } = new Dictionary<string, TagHelperDescriptor>();
@ -245,7 +243,7 @@ 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(node); CreateTagHelpers.Add((node, Parent));
} }
} }

View File

@ -136,14 +136,26 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
private void RenderTagHelperAttributeInline( private void RenderTagHelperAttributeInline(
CSharpRenderingContext context, CSharpRenderingContext context,
SetTagHelperPropertyIRNode property,
SourceSpan documentLocation)
{
for (var i = 0; i < property.Children.Count; i++)
{
RenderTagHelperAttributeInline(context, property, property.Children[i], documentLocation);
}
}
private void RenderTagHelperAttributeInline(
CSharpRenderingContext context,
SetTagHelperPropertyIRNode property,
RazorIRNode node, RazorIRNode node,
SourceSpan documentLocation) SourceSpan documentLocation)
{ {
if (node is SetTagHelperPropertyIRNode || node is CSharpExpressionIRNode || node is HtmlContentIRNode) if (node is CSharpExpressionIRNode || node is HtmlContentIRNode)
{ {
for (var i = 0; i < node.Children.Count; i++) for (var i = 0; i < node.Children.Count; i++)
{ {
RenderTagHelperAttributeInline(context, node.Children[i], documentLocation); RenderTagHelperAttributeInline(context, property, node.Children[i], documentLocation);
} }
} }
else if (node is RazorIRToken token) else if (node is RazorIRToken token)
@ -165,9 +177,9 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
} }
else if (node is TemplateIRNode) else if (node is TemplateIRNode)
{ {
var attributeValueNode = (SetTagHelperPropertyIRNode)node.Parent; var expectedTypeName = property.IsIndexerNameMatch ? property.Descriptor.IndexerTypeName : property.Descriptor.TypeName;
var error = new RazorError( var error = new RazorError(
LegacyResources.FormatTagHelpers_InlineMarkupBlocks_NotSupported_InAttributes(attributeValueNode.Descriptor.TypeName), LegacyResources.FormatTagHelpers_InlineMarkupBlocks_NotSupported_InAttributes(expectedTypeName),
new SourceLocation(documentLocation.AbsoluteIndex, documentLocation.CharacterIndex, documentLocation.Length), new SourceLocation(documentLocation.AbsoluteIndex, documentLocation.CharacterIndex, documentLocation.Length),
documentLocation.Length); documentLocation.Length);
context.Diagnostics.Add(RazorDiagnostic.Create(error)); context.Diagnostics.Add(RazorDiagnostic.Create(error));

View File

@ -421,14 +421,26 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
private void RenderTagHelperAttributeInline( private void RenderTagHelperAttributeInline(
CSharpRenderingContext context, CSharpRenderingContext context,
SetTagHelperPropertyIRNode property,
SourceSpan documentLocation)
{
for (var i = 0; i < property.Children.Count; i++)
{
RenderTagHelperAttributeInline(context, property, property.Children[i], documentLocation);
}
}
private void RenderTagHelperAttributeInline(
CSharpRenderingContext context,
SetTagHelperPropertyIRNode property,
RazorIRNode node, RazorIRNode node,
SourceSpan documentLocation) SourceSpan documentLocation)
{ {
if (node is SetTagHelperPropertyIRNode || node is CSharpExpressionIRNode || node is HtmlContentIRNode) if (node is CSharpExpressionIRNode || node is HtmlContentIRNode)
{ {
for (var i = 0; i < node.Children.Count; i++) for (var i = 0; i < node.Children.Count; i++)
{ {
RenderTagHelperAttributeInline(context, node.Children[i], documentLocation); RenderTagHelperAttributeInline(context, property, node.Children[i], documentLocation);
} }
} }
else if (node is RazorIRToken token) else if (node is RazorIRToken token)
@ -445,10 +457,7 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
} }
else if (node is TemplateIRNode) else if (node is TemplateIRNode)
{ {
var attributeValueNode = (SetTagHelperPropertyIRNode)node.Parent; var expectedTypeName = property.IsIndexerNameMatch ? property.Descriptor.IndexerTypeName : property.Descriptor.TypeName;
var expectedTypeName = attributeValueNode.IsIndexerNameMatch ?
attributeValueNode.Descriptor.IndexerTypeName :
attributeValueNode.Descriptor.TypeName;
var error = new RazorError( var error = new RazorError(
LegacyResources.FormatTagHelpers_InlineMarkupBlocks_NotSupported_InAttributes(expectedTypeName), LegacyResources.FormatTagHelpers_InlineMarkupBlocks_NotSupported_InAttributes(expectedTypeName),
new SourceLocation(documentLocation.AbsoluteIndex, documentLocation.CharacterIndex, documentLocation.Length), new SourceLocation(documentLocation.AbsoluteIndex, documentLocation.CharacterIndex, documentLocation.Length),

View File

@ -20,20 +20,19 @@ namespace Microsoft.AspNetCore.Razor.Language
walker.VisitDocument(irDocument); walker.VisitDocument(irDocument);
var classNode = walker.ClassNode; var classNode = walker.ClassNode;
foreach (var node in walker.FunctionsDirectiveNodes) foreach (var (node, parent) in walker.FunctionsDirectiveNodes)
{ {
node.Parent.Children.Remove(node); parent.Children.Remove(node);
foreach (var child in node.Children.Except(node.Tokens)) foreach (var child in node.Children.Except(node.Tokens))
{ {
child.Parent = classNode;
classNode.Children.Add(child); classNode.Children.Add(child);
} }
} }
foreach (var node in walker.InheritsDirectiveNodes.Reverse()) foreach (var (node, parent) in walker.InheritsDirectiveNodes.Reverse())
{ {
node.Parent.Children.Remove(node); parent.Children.Remove(node);
var token = node.Tokens.FirstOrDefault(); var token = node.Tokens.FirstOrDefault();
if (token != null) if (token != null)
@ -43,10 +42,10 @@ namespace Microsoft.AspNetCore.Razor.Language
} }
} }
foreach (var node in walker.SectionDirectiveNodes) foreach (var (node, parent) in walker.SectionDirectiveNodes)
{ {
var sectionIndex = node.Parent.Children.IndexOf(node); var sectionIndex = parent.Children.IndexOf(node);
node.Parent.Children.Remove(node); parent.Children.Remove(node);
var defineSectionEndStatement = new CSharpCodeIRNode(); var defineSectionEndStatement = new CSharpCodeIRNode();
RazorIRBuilder.Create(defineSectionEndStatement) RazorIRBuilder.Create(defineSectionEndStatement)
@ -56,11 +55,11 @@ namespace Microsoft.AspNetCore.Razor.Language
Content = "});" Content = "});"
}); });
node.Parent.Children.Insert(sectionIndex, defineSectionEndStatement); parent.Children.Insert(sectionIndex, defineSectionEndStatement);
foreach (var child in node.Children.Except(node.Tokens).Reverse()) foreach (var child in node.Children.Except(node.Tokens).Reverse())
{ {
node.Parent.Children.Insert(sectionIndex, child); parent.Children.Insert(sectionIndex, child);
} }
var lambdaContent = designTime ? "__razor_section_writer" : string.Empty; var lambdaContent = designTime ? "__razor_section_writer" : string.Empty;
@ -73,7 +72,7 @@ namespace Microsoft.AspNetCore.Razor.Language
Content = $"DefineSection(\"{sectionName}\", async ({lambdaContent}) => {{" Content = $"DefineSection(\"{sectionName}\", async ({lambdaContent}) => {{"
}); });
node.Parent.Children.Insert(sectionIndex, defineSectionStartStatement); parent.Children.Insert(sectionIndex, defineSectionStartStatement);
} }
} }
@ -81,11 +80,11 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
public ClassDeclarationIRNode ClassNode { get; private set; } public ClassDeclarationIRNode ClassNode { get; private set; }
public IList<DirectiveIRNode> FunctionsDirectiveNodes { get; } = new List<DirectiveIRNode>(); public IList<(DirectiveIRNode node, RazorIRNode parent)> FunctionsDirectiveNodes { get; } = new List<(DirectiveIRNode node, RazorIRNode parent)>();
public IList<DirectiveIRNode> InheritsDirectiveNodes { get; } = new List<DirectiveIRNode>(); public IList<(DirectiveIRNode node, RazorIRNode parent)> InheritsDirectiveNodes { get; } = new List<(DirectiveIRNode node, RazorIRNode parent)>();
public IList<DirectiveIRNode> SectionDirectiveNodes { get; } = new List<DirectiveIRNode>(); public IList<(DirectiveIRNode node, RazorIRNode parent)> SectionDirectiveNodes { get; } = new List<(DirectiveIRNode node, RazorIRNode parent)>();
public override void VisitClassDeclaration(ClassDeclarationIRNode node) public override void VisitClassDeclaration(ClassDeclarationIRNode node)
{ {
@ -101,15 +100,15 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
if (string.Equals(node.Name, CSharpCodeParser.FunctionsDirectiveDescriptor.Directive, StringComparison.Ordinal)) if (string.Equals(node.Name, CSharpCodeParser.FunctionsDirectiveDescriptor.Directive, StringComparison.Ordinal))
{ {
FunctionsDirectiveNodes.Add(node); FunctionsDirectiveNodes.Add((node, Parent));
} }
else if (string.Equals(node.Name, CSharpCodeParser.InheritsDirectiveDescriptor.Directive, StringComparison.Ordinal)) else if (string.Equals(node.Name, CSharpCodeParser.InheritsDirectiveDescriptor.Directive, StringComparison.Ordinal))
{ {
InheritsDirectiveNodes.Add(node); InheritsDirectiveNodes.Add((node, Parent));
} }
else if (string.Equals(node.Name, CSharpCodeParser.SectionDirectiveDescriptor.Directive, StringComparison.Ordinal)) else if (string.Equals(node.Name, CSharpCodeParser.SectionDirectiveDescriptor.Directive, StringComparison.Ordinal))
{ {
SectionDirectiveNodes.Add(node); SectionDirectiveNodes.Add((node, Parent));
} }
} }
} }

View File

@ -551,7 +551,6 @@ namespace Microsoft.AspNetCore.Razor.Language
Content = span.Content, Content = span.Content,
Kind = RazorIRToken.TokenKind.Html, Kind = RazorIRToken.TokenKind.Html,
Source = BuildSourceSpanFromNode(span), Source = BuildSourceSpanFromNode(span),
Parent = node
}); });
if (node.Source != null) if (node.Source != null)
@ -571,7 +570,7 @@ namespace Microsoft.AspNetCore.Razor.Language
{ {
if (_tagHelperFields == null) if (_tagHelperFields == null)
{ {
_tagHelperFields = new DeclareTagHelperFieldsIRNode() { Parent = _document, }; _tagHelperFields = new DeclareTagHelperFieldsIRNode();
_document.Children.Add(_tagHelperFields); _document.Children.Add(_tagHelperFields);
} }

View File

@ -15,19 +15,19 @@ namespace Microsoft.AspNetCore.Razor.Language
var visitor = new Visitor(); var visitor = new Visitor();
visitor.VisitDocument(irDocument); visitor.VisitDocument(irDocument);
foreach (var node in visitor.DirectiveNodes) foreach (var (node, parent) in visitor.DirectiveNodes)
{ {
node.Parent.Children.Remove(node); parent.Children.Remove(node);
} }
} }
private class Visitor : RazorIRNodeWalker private class Visitor : RazorIRNodeWalker
{ {
public IList<DirectiveIRNode> DirectiveNodes { get; } = new List<DirectiveIRNode>(); public IList<(DirectiveIRNode node, RazorIRNode parent)> DirectiveNodes { get; } = new List<(DirectiveIRNode node, RazorIRNode parent)>();
public override void VisitDirective(DirectiveIRNode node) public override void VisitDirective(DirectiveIRNode node)
{ {
DirectiveNodes.Add(node); DirectiveNodes.Add((node, Parent));
} }
} }
} }

View File

@ -10,9 +10,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
public sealed class TemplateIRNode : ExtensionIRNode public sealed class TemplateIRNode : ExtensionIRNode
{ {
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection();
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(RazorIRNodeVisitor visitor)

View File

@ -10,8 +10,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance; public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance;
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public string VariableName { get; set; } public string VariableName { get; set; }

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Razor.Language.Legacy; using Microsoft.AspNetCore.Razor.Language.Legacy;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
@ -13,8 +12,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection();
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public string Name { get; set; } public string Name { get; set; }

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
@ -12,8 +11,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection();
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public string Prefix { get; set; } public string Prefix { get; set; }

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
@ -25,8 +24,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection();
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(RazorIRNodeVisitor visitor)

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
@ -12,8 +11,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection();
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public string Prefix { get; set; } public string Prefix { get; set; }

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
@ -25,8 +24,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection();
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(RazorIRNodeVisitor visitor)

View File

@ -11,8 +11,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance; public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance;
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public string Bytes { get; set; } public string Bytes { get; set; }

View File

@ -25,8 +25,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection();
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public string AccessModifier { get; set; } public string AccessModifier { get; set; }

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
@ -12,8 +11,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance; public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance;
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public string TagHelperTypeName { get; set; } public string TagHelperTypeName { get; set; }

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Razor.Language.CodeGeneration; using Microsoft.AspNetCore.Razor.Language.CodeGeneration;
using Microsoft.AspNetCore.Razor.Language.Legacy; using Microsoft.AspNetCore.Razor.Language.Legacy;
@ -12,8 +11,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance; public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance;
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public string VariableName { get; set; } public string VariableName { get; set; }

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Razor.Language.CodeGeneration; using Microsoft.AspNetCore.Razor.Language.CodeGeneration;
using Microsoft.AspNetCore.Razor.Language.Legacy; using Microsoft.AspNetCore.Razor.Language.Legacy;
@ -12,8 +11,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance; public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance;
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public string VariableName { get; set; } public string VariableName { get; set; }

View File

@ -12,8 +12,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance; public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance;
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public ISet<string> UsedTagHelperTypeNames { get; set; } = new HashSet<string>(StringComparer.Ordinal); public ISet<string> UsedTagHelperTypeNames { get; set; } = new HashSet<string>(StringComparer.Ordinal);

View File

@ -30,8 +30,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
throw new ArgumentNullException(nameof(node)); throw new ArgumentNullException(nameof(node));
} }
node.Parent = Current;
Current.Children.Add(node); Current.Children.Add(node);
} }
@ -41,8 +40,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
throw new ArgumentOutOfRangeException(nameof(index)); throw new ArgumentOutOfRangeException(nameof(index));
} }
node.Parent = Current;
if (index == Current.Children.Count) if (index == Current.Children.Count)
{ {
// Allow inserting at 'Children.Count' to be friendlier than List<> typically is. // Allow inserting at 'Children.Count' to be friendlier than List<> typically is.
@ -95,7 +93,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
if (_depth > 0) if (_depth > 0)
{ {
var parent = _stack[_depth - 1]; var parent = _stack[_depth - 1];
node.Parent = parent;
parent.Children.Add(node); parent.Children.Add(node);
} }

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Razor.Language.CodeGeneration; using Microsoft.AspNetCore.Razor.Language.CodeGeneration;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
@ -11,8 +10,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection();
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(RazorIRNodeVisitor visitor)

View File

@ -3,7 +3,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.AspNetCore.Razor.Language.Legacy;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
@ -26,8 +25,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection();
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public string Name { get; set; } public string Name { get; set; }

View File

@ -1,9 +1,6 @@
// Copyright(c) .NET Foundation.All rights reserved. // 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public sealed class DirectiveTokenIRNode : RazorIRNode public sealed class DirectiveTokenIRNode : RazorIRNode
@ -12,8 +9,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance; public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance;
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public string Content { get; set; } public string Content { get; set; }

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Razor.Language.CodeGeneration; using Microsoft.AspNetCore.Razor.Language.CodeGeneration;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
@ -30,8 +29,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public RazorCodeGenerationOptions Options { get; set; } public RazorCodeGenerationOptions Options { get; set; }
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public CodeTarget Target { get; set; } public CodeTarget Target { get; set; }

View File

@ -27,8 +27,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public IList<string> Modifiers { get; set; } = new List<string>(); public IList<string> Modifiers { get; set; } = new List<string>();
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public string AccessModifier { get; set; } public string AccessModifier { get; set; }

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
@ -12,8 +11,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection();
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public string Name { get; set; } public string Name { get; set; }

View File

@ -12,8 +12,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection();
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public string Prefix { get; set; } public string Prefix { get; set; }

View File

@ -12,8 +12,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection();
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(RazorIRNodeVisitor visitor)

View File

@ -25,8 +25,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection();
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public string AccessModifier { get; set; } public string AccessModifier { get; set; }

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
@ -25,8 +24,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection();
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public string Content { get; set; } public string Content { get; set; }

View File

@ -27,8 +27,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public IList<string> Modifiers { get; set; } = new List<string>(); public IList<string> Modifiers { get; set; } = new List<string>();
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public string AccessModifier { get; set; } public string AccessModifier { get; set; }

View File

@ -1,20 +1,14 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public abstract class RazorIRNode public abstract class RazorIRNode
{ {
internal static readonly RazorIRNode[] EmptyArray = new RazorIRNode[0];
public abstract ItemCollection Annotations { get; } public abstract ItemCollection Annotations { get; }
public abstract RazorIRNodeCollection Children { get; } public abstract RazorIRNodeCollection Children { get; }
public abstract RazorIRNode Parent { get; set; }
public abstract SourceSpan? Source { get; set; } public abstract SourceSpan? Source { get; set; }
public abstract void Accept(RazorIRNodeVisitor visitor); public abstract void Accept(RazorIRNodeVisitor visitor);

View File

@ -1,17 +1,39 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public abstract class RazorIRNodeWalker : RazorIRNodeVisitor public abstract class RazorIRNodeWalker : RazorIRNodeVisitor
{ {
private readonly Stack<RazorIRNode> _ancestors = new Stack<RazorIRNode>();
protected IEnumerable<RazorIRNode> Ancestors => _ancestors;
protected RazorIRNode Parent => _ancestors.Count > 0 ? _ancestors.Peek() : null;
public override void VisitDefault(RazorIRNode node) public override void VisitDefault(RazorIRNode node)
{ {
var children = node.Children; var children = node.Children;
for (var i = 0; i < node.Children.Count; i++) if (node.Children.Count == 0)
{ {
var child = children[i]; return;
Visit(child); }
_ancestors.Push(node);
try
{
for (var i = 0; i < node.Children.Count; i++)
{
var child = children[i];
Visit(child);
}
}
finally
{
_ancestors.Pop();
} }
} }
} }

View File

@ -19,8 +19,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public TokenKind Kind { get; set; } = TokenKind.Unknown; public TokenKind Kind { get; set; } = TokenKind.Unknown;
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(RazorIRNodeVisitor visitor)

View File

@ -2,9 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Razor.Language.CodeGeneration; using Microsoft.AspNetCore.Razor.Language.CodeGeneration;
using Microsoft.AspNetCore.Razor.Language.Legacy;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
@ -12,8 +10,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance; public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance;
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public string VariableName { get; set; } public string VariableName { get; set; }

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Razor.Language.Legacy; using Microsoft.AspNetCore.Razor.Language.Legacy;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
@ -13,8 +12,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection();
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public string TagHelperTypeName { get; set; } public string TagHelperTypeName { get; set; }

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
@ -12,8 +11,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection();
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(RazorIRNodeVisitor visitor)

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
@ -25,8 +24,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection();
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public string TagName { get; set; } public string TagName { get; set; }

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic;
namespace Microsoft.AspNetCore.Razor.Language.Intermediate namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
@ -12,8 +11,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance; public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance;
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public string Content { get; set; } public string Content { get; set; }

View File

@ -11,7 +11,11 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.HashCodeCombiner.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All" /> <PackageReference Include="Microsoft.Extensions.HashCodeCombiner.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFrameworkIdentifier)'=='.NETFramework'">
<PackageReference Include="System.ValueTuple" Version="$(CoreFxVersion)" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -72,7 +72,6 @@ namespace Microsoft.AspNetCore.Razor.Language
Name = node.Name, Name = node.Name,
Value = plainTextValue, Value = plainTextValue,
ValueStyle = node.ValueStyle, ValueStyle = node.ValueStyle,
Parent = _classDeclaration
}; };
_classDeclaration.Children.Insert(_preallocatedDeclarationCount++, declaration); _classDeclaration.Children.Insert(_preallocatedDeclarationCount++, declaration);
} }
@ -80,11 +79,10 @@ namespace Microsoft.AspNetCore.Razor.Language
var addPreAllocatedAttribute = new AddPreallocatedTagHelperHtmlAttributeIRNode var addPreAllocatedAttribute = new AddPreallocatedTagHelperHtmlAttributeIRNode
{ {
VariableName = declaration.VariableName, VariableName = declaration.VariableName,
Parent = node.Parent
}; };
var nodeIndex = node.Parent.Children.IndexOf(node); var nodeIndex = Parent.Children.IndexOf(node);
node.Parent.Children[nodeIndex] = addPreAllocatedAttribute; Parent.Children[nodeIndex] = addPreAllocatedAttribute;
} }
public override void VisitSetTagHelperProperty(SetTagHelperPropertyIRNode node) public override void VisitSetTagHelperProperty(SetTagHelperPropertyIRNode node)
@ -127,7 +125,6 @@ namespace Microsoft.AspNetCore.Razor.Language
Name = node.AttributeName, Name = node.AttributeName,
Value = plainTextValue, Value = plainTextValue,
ValueStyle = node.ValueStyle, ValueStyle = node.ValueStyle,
Parent = _classDeclaration
}; };
_classDeclaration.Children.Insert(_preallocatedDeclarationCount++, declaration); _classDeclaration.Children.Insert(_preallocatedDeclarationCount++, declaration);
} }
@ -140,12 +137,11 @@ namespace Microsoft.AspNetCore.Razor.Language
PropertyName = node.PropertyName, PropertyName = node.PropertyName,
Descriptor = node.Descriptor, Descriptor = node.Descriptor,
Binding = node.Binding, Binding = node.Binding,
Parent = node.Parent,
IsIndexerNameMatch = node.IsIndexerNameMatch, IsIndexerNameMatch = node.IsIndexerNameMatch,
}; };
var nodeIndex = node.Parent.Children.IndexOf(node); var nodeIndex = Parent.Children.IndexOf(node);
node.Parent.Children[nodeIndex] = setPreallocatedProperty; Parent.Children[nodeIndex] = setPreallocatedProperty;
} }
private string GetContent(HtmlContentIRNode node) private string GetContent(HtmlContentIRNode node)

View File

@ -13,16 +13,16 @@ namespace RazorPageGenerator
var walker = new Walker(); var walker = new Walker();
walker.Visit(irDocument); walker.Visit(irDocument);
walker.ChecksumNode.Parent.Children.Remove(walker.ChecksumNode); walker.Checksum.parent.Children.Remove(walker.Checksum.node);
} }
private class Walker : RazorIRNodeWalker private class Walker : RazorIRNodeWalker
{ {
public ChecksumIRNode ChecksumNode { get; private set; } public (ChecksumIRNode node, RazorIRNode parent) Checksum { get; private set; }
public override void VisitChecksum(ChecksumIRNode node) public override void VisitChecksum(ChecksumIRNode node)
{ {
ChecksumNode = node; Checksum = (node, Parent);
} }
} }
} }

View File

@ -41,7 +41,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
Source = new SourceSpan(imports, 0, 0, 0, 0), Source = new SourceSpan(imports, 0, 0, 0, 0),
}; };
node.Children.Add(new DirectiveTokenIRNode() { Content = string.Empty }); node.Children.Add(new DirectiveTokenIRNode() { Content = string.Empty });
node.Children[0].Parent = node;
// Act // Act
var computed = NamespaceDirective.TryComputeNamespace(source, node, out var @namespace); var computed = NamespaceDirective.TryComputeNamespace(source, node, out var @namespace);
@ -71,7 +70,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
}; };
node.Children.Add(new DirectiveTokenIRNode() { Content = "Base" }); node.Children.Add(new DirectiveTokenIRNode() { Content = "Base" });
node.Children[0].Parent = node;
// Act // Act
var computed = NamespaceDirective.TryComputeNamespace(source, node, out var @namespace); var computed = NamespaceDirective.TryComputeNamespace(source, node, out var @namespace);
@ -102,7 +100,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
}; };
node.Children.Add(new DirectiveTokenIRNode() { Content = "Base" }); node.Children.Add(new DirectiveTokenIRNode() { Content = "Base" });
node.Children[0].Parent = node;
// Act // Act
var computed = NamespaceDirective.TryComputeNamespace(source, node, out var @namespace); var computed = NamespaceDirective.TryComputeNamespace(source, node, out var @namespace);

View File

@ -551,8 +551,6 @@ Render Node - CSharpExpressionIRNode
{ {
public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance; public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance;
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public override SourceSpan? Source { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(RazorIRNodeVisitor visitor)

View File

@ -445,7 +445,6 @@ if (true) { }
{ {
Content = "SomeContent", Content = "SomeContent",
Kind = RazorIRToken.TokenKind.Html, Kind = RazorIRToken.TokenKind.Html,
Parent = node
}); });
// Act // Act
@ -476,7 +475,6 @@ if (true) { }
{ {
Content = new string('*', 2000), Content = new string('*', 2000),
Kind = RazorIRToken.TokenKind.Html, Kind = RazorIRToken.TokenKind.Html,
Parent = node
}); });
// Act // Act
@ -652,7 +650,6 @@ WriteAttributeValue("" "", 27, false, 28, 6, false);
{ {
public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance; public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance;
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public override SourceSpan? Source { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(RazorIRNodeVisitor visitor)

View File

@ -34,11 +34,10 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
// Assert // Assert
Assert.Same(node, builder.Current); Assert.Same(node, builder.Current);
Assert.Null(node.Parent);
} }
[Fact] [Fact]
public void Push_WhenNonEmpty_SetsUpParentAndChild() public void Push_WhenNonEmpty_SetsUpChild()
{ {
// Arrange // Arrange
var builder = new DefaultRazorIRBuilder(); var builder = new DefaultRazorIRBuilder();
@ -53,7 +52,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
// Assert // Assert
Assert.Same(node, builder.Current); Assert.Same(node, builder.Current);
Assert.Same(parent, node.Parent);
Assert.Collection(parent.Children, n => Assert.Same(node, n)); Assert.Collection(parent.Children, n => Assert.Same(node, n));
} }
@ -122,12 +120,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
// Assert // Assert
Assert.Same(parent, builder.Current); Assert.Same(parent, builder.Current);
Assert.Same(parent, node.Parent);
Assert.Collection(parent.Children, n => Assert.Same(node, n)); Assert.Collection(parent.Children, n => Assert.Same(node, n));
} }
[Fact] [Fact]
public void Insert_AddsToChildrenAndSetsParent_EmptyCollection() public void Insert_AddsToChildren_EmptyCollection()
{ {
// Arrange // Arrange
var builder = new DefaultRazorIRBuilder(); var builder = new DefaultRazorIRBuilder();
@ -142,12 +139,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
// Assert // Assert
Assert.Same(parent, builder.Current); Assert.Same(parent, builder.Current);
Assert.Same(parent, node.Parent);
Assert.Collection(parent.Children, n => Assert.Same(node, n)); Assert.Collection(parent.Children, n => Assert.Same(node, n));
} }
[Fact] [Fact]
public void Insert_AddsToChildrenAndSetsParent_NonEmpyCollection() public void Insert_AddsToChildren_NonEmpyCollection()
{ {
// Arrange // Arrange
var builder = new DefaultRazorIRBuilder(); var builder = new DefaultRazorIRBuilder();
@ -165,12 +161,11 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
// Assert // Assert
Assert.Same(parent, builder.Current); Assert.Same(parent, builder.Current);
Assert.Same(parent, node.Parent);
Assert.Collection(parent.Children, n => Assert.Same(node, n), n => Assert.Same(child, n)); Assert.Collection(parent.Children, n => Assert.Same(node, n), n => Assert.Same(child, n));
} }
[Fact] [Fact]
public void Insert_AddsToChildrenAndSetsParent_NonEmpyCollection_AtEnd() public void Insert_AddsToChildren_NonEmpyCollection_AtEnd()
{ {
// Arrange // Arrange
var builder = new DefaultRazorIRBuilder(); var builder = new DefaultRazorIRBuilder();
@ -188,7 +183,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
// Assert // Assert
Assert.Same(parent, builder.Current); Assert.Same(parent, builder.Current);
Assert.Same(parent, node.Parent);
Assert.Collection(parent.Children, n => Assert.Same(child, n), n => Assert.Same(node, n)); Assert.Collection(parent.Children, n => Assert.Same(child, n), n => Assert.Same(node, n));
} }
@ -218,8 +212,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection();
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(RazorIRNodeVisitor visitor)

View File

@ -46,7 +46,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
{ {
public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance; public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance;
public override RazorIRNode Parent { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public override SourceSpan? Source { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public override SourceSpan? Source { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(RazorIRNodeVisitor visitor)

View File

@ -74,8 +74,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection(); public override RazorIRNodeCollection Children { get; } = new DefaultIRNodeCollection();
public override RazorIRNode Parent { get; set; }
public override SourceSpan? Source { get; set; } public override SourceSpan? Source { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(RazorIRNodeVisitor visitor)

View File

@ -2,7 +2,9 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Text; using System.Text;
using Microsoft.AspNetCore.Razor.Language.Intermediate; using Microsoft.AspNetCore.Razor.Language.Intermediate;
using Xunit; using Xunit;
@ -47,7 +49,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
_visitor.Visit(node); _visitor.Visit(node);
var actual = _writer.GetStringBuilder().ToString(); var actual = _writer.GetStringBuilder().ToString();
AssertNodeEquals(node, expected, actual); AssertNodeEquals(node, Ancestors, expected, actual);
_visitor.Depth++; _visitor.Depth++;
base.VisitDefault(node); base.VisitDefault(node);
@ -60,7 +62,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
Assert.True(_baseline.Length == _index, "Not all lines of the baseline were visited!"); Assert.True(_baseline.Length == _index, "Not all lines of the baseline were visited!");
} }
private void AssertNodeEquals(RazorIRNode node, string expected, string actual) private void AssertNodeEquals(RazorIRNode node, IEnumerable<RazorIRNode> ancestors, string expected, string actual)
{ {
if (string.Equals(expected, actual)) if (string.Equals(expected, actual))
{ {
@ -71,21 +73,21 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
if (expected == null) if (expected == null)
{ {
var message = "The node is missing from baseline."; var message = "The node is missing from baseline.";
throw new IRBaselineException(node, expected, actual, message); throw new IRBaselineException(node, Ancestors.ToArray(), expected, actual, message);
} }
int charsVerified = 0; int charsVerified = 0;
AssertNestingEqual(node, expected, actual, ref charsVerified); AssertNestingEqual(node, ancestors, expected, actual, ref charsVerified);
AssertNameEqual(node, expected, actual, ref charsVerified); AssertNameEqual(node, ancestors, expected, actual, ref charsVerified);
AssertDelimiter(node, expected, actual, true, ref charsVerified); AssertDelimiter(node, expected, actual, true, ref charsVerified);
AssertLocationEqual(node, expected, actual, ref charsVerified); AssertLocationEqual(node, ancestors, expected, actual, ref charsVerified);
AssertDelimiter(node, expected, actual, false, ref charsVerified); AssertDelimiter(node, expected, actual, false, ref charsVerified);
AssertContentEqual(node, expected, actual, ref charsVerified); AssertContentEqual(node, ancestors, expected, actual, ref charsVerified);
throw new InvalidOperationException("We can't figure out HOW these two things are different. This is a bug."); throw new InvalidOperationException("We can't figure out HOW these two things are different. This is a bug.");
} }
private void AssertNestingEqual(RazorIRNode node, string expected, string actual, ref int charsVerified) private void AssertNestingEqual(RazorIRNode node, IEnumerable<RazorIRNode> ancestors, string expected, string actual, ref int charsVerified)
{ {
var i = 0; var i = 0;
for (; i < expected.Length; i++) for (; i < expected.Length; i++)
@ -115,13 +117,13 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
if (failed) if (failed)
{ {
var message = "The node is at the wrong level of nesting. This usually means a child is missing."; var message = "The node is at the wrong level of nesting. This usually means a child is missing.";
throw new IRBaselineException(node, expected, actual, message); throw new IRBaselineException(node, ancestors.ToArray(), expected, actual, message);
} }
charsVerified = j; charsVerified = j;
} }
private void AssertNameEqual(RazorIRNode node, string expected, string actual, ref int charsVerified) private void AssertNameEqual(RazorIRNode node, IEnumerable<RazorIRNode> ancestors, string expected, string actual, ref int charsVerified)
{ {
var expectedName = GetName(expected, charsVerified); var expectedName = GetName(expected, charsVerified);
var actualName = GetName(actual, charsVerified); var actualName = GetName(actual, charsVerified);
@ -129,7 +131,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
if (!string.Equals(expectedName, actualName)) if (!string.Equals(expectedName, actualName))
{ {
var message = $"Node names are not equal."; var message = $"Node names are not equal.";
throw new IRBaselineException(node, expected, actual, message); throw new IRBaselineException(node, ancestors.ToArray(), expected, actual, message);
} }
charsVerified += expectedName.Length; charsVerified += expectedName.Length;
@ -170,7 +172,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
charsVerified += 3; charsVerified += 3;
} }
private void AssertLocationEqual(RazorIRNode node, string expected, string actual, ref int charsVerified) private void AssertLocationEqual(RazorIRNode node, IEnumerable<RazorIRNode> ancestors, string expected, string actual, ref int charsVerified)
{ {
var expectedLocation = GetLocation(expected, charsVerified); var expectedLocation = GetLocation(expected, charsVerified);
var actualLocation = GetLocation(actual, charsVerified); var actualLocation = GetLocation(actual, charsVerified);
@ -178,13 +180,13 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
if (!string.Equals(expectedLocation, actualLocation)) if (!string.Equals(expectedLocation, actualLocation))
{ {
var message = $"Locations are not equal."; var message = $"Locations are not equal.";
throw new IRBaselineException(node, expected, actual, message); throw new IRBaselineException(node, ancestors.ToArray(), expected, actual, message);
} }
charsVerified += expectedLocation.Length; charsVerified += expectedLocation.Length;
} }
private void AssertContentEqual(RazorIRNode node, string expected, string actual, ref int charsVerified) private void AssertContentEqual(RazorIRNode node, IEnumerable<RazorIRNode> ancestors, string expected, string actual, ref int charsVerified)
{ {
var expectedContent = GetContent(expected, charsVerified); var expectedContent = GetContent(expected, charsVerified);
var actualContent = GetContent(actual, charsVerified); var actualContent = GetContent(actual, charsVerified);
@ -192,7 +194,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
if (!string.Equals(expectedContent, actualContent)) if (!string.Equals(expectedContent, actualContent))
{ {
var message = $"Contents are not equal."; var message = $"Contents are not equal.";
throw new IRBaselineException(node, expected, actual, message); throw new IRBaselineException(node, ancestors.ToArray(), expected, actual, message);
} }
charsVerified += expectedContent.Length; charsVerified += expectedContent.Length;
@ -222,8 +224,8 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
private class IRBaselineException : XunitException private class IRBaselineException : XunitException
{ {
public IRBaselineException(RazorIRNode node, string expected, string actual, string userMessage) public IRBaselineException(RazorIRNode node, RazorIRNode[] ancestors, string expected, string actual, string userMessage)
: base(Format(node, expected, actual, userMessage)) : base(Format(node, ancestors, expected, actual, userMessage))
{ {
Node = node; Node = node;
Expected = expected; Expected = expected;
@ -236,7 +238,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
public string Expected { get; } public string Expected { get; }
private static string Format(RazorIRNode node, string expected, string actual, string userMessage) private static string Format(RazorIRNode node, RazorIRNode[] ancestors, string expected, string actual, string userMessage)
{ {
var builder = new StringBuilder(); var builder = new StringBuilder();
builder.AppendLine(userMessage); builder.AppendLine(userMessage);
@ -254,15 +256,16 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
builder.AppendLine(actual); builder.AppendLine(actual);
} }
builder.AppendLine(); if (ancestors != null)
builder.AppendLine("Path:");
var current = node;
do
{ {
builder.AppendLine(current.ToString()); builder.AppendLine();
builder.AppendLine("Path:");
foreach (var ancestor in ancestors)
{
builder.AppendLine(ancestor.ToString());
}
} }
while ((current = current.Parent) != null);
return builder.ToString(); return builder.ToString();
} }

View File

@ -431,13 +431,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
private class IRAssertException : XunitException private class IRAssertException : XunitException
{ {
public IRAssertException(RazorIRNode node, string userMessage) public IRAssertException(RazorIRNode node, string userMessage)
: base(Format(node, null, userMessage)) : base(Format(node, null, null, userMessage))
{ {
Node = node; Node = node;
} }
public IRAssertException(RazorIRNode node, IEnumerable<RazorIRNode> nodes, string userMessage) public IRAssertException(RazorIRNode node, IEnumerable<RazorIRNode> nodes, string userMessage)
: base(Format(node, nodes, userMessage)) : base(Format(node, null, nodes, userMessage))
{ {
Node = node; Node = node;
Nodes = nodes; Nodes = nodes;
@ -448,7 +448,17 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
IEnumerable<RazorIRNode> nodes, IEnumerable<RazorIRNode> nodes,
string userMessage, string userMessage,
Exception innerException) Exception innerException)
: base(Format(node, nodes, userMessage), innerException) : base(Format(node, null, nodes, userMessage), innerException)
{
}
public IRAssertException(
RazorIRNode node,
RazorIRNode[] ancestors,
IEnumerable<RazorIRNode> nodes,
string userMessage,
Exception innerException)
: base(Format(node, ancestors, nodes, userMessage), innerException)
{ {
} }
@ -456,7 +466,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public IEnumerable<RazorIRNode> Nodes { get; } public IEnumerable<RazorIRNode> Nodes { get; }
private static string Format(RazorIRNode node, IEnumerable<RazorIRNode> nodes, string userMessage) private static string Format(RazorIRNode node, RazorIRNode[] ancestors, IEnumerable<RazorIRNode> nodes, string userMessage)
{ {
var builder = new StringBuilder(); var builder = new StringBuilder();
builder.AppendLine(userMessage); builder.AppendLine(userMessage);
@ -477,12 +487,16 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
builder.AppendLine("Path:"); builder.AppendLine("Path:");
var current = node; if (ancestors != null)
do
{ {
builder.AppendLine(current.ToString()); builder.AppendLine();
builder.AppendLine("Path:");
foreach (var ancestor in ancestors)
{
builder.AppendLine(ancestor.ToString());
}
} }
while ((current = current.Parent) != null);
return builder.ToString(); return builder.ToString();
} }