Transitioned SourceLocation => MappingLocation on IRNodes.

- Also modified the property name from `SourceLocation` => `SourceRange` to avoid ambiguity.
- Updated IR baselines
- Updated IR baseline infrastructure to conditionally render the document location.

#884
This commit is contained in:
N. Taylor Mullen 2016-12-07 12:33:38 -08:00
parent 3d8798f6b1
commit 2639fad8ab
26 changed files with 99 additions and 76 deletions

View File

@ -62,8 +62,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
Name = chunkGenerator.Name, Name = chunkGenerator.Name,
Prefix = chunkGenerator.Prefix, Prefix = chunkGenerator.Prefix,
Suffix = chunkGenerator.Suffix, Suffix = chunkGenerator.Suffix,
SourceRange = new MappingLocation(block.Start, block.Length),
SourceLocation = block.Start,
}); });
} }
@ -81,7 +80,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
Builder.Push(new CSharpAttributeValueIRNode() Builder.Push(new CSharpAttributeValueIRNode()
{ {
Prefix = chunkGenerator.Prefix, Prefix = chunkGenerator.Prefix,
SourceLocation = block.Start, SourceRange = new MappingLocation(block.Start, block.Length),
}); });
} }
@ -96,7 +95,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
{ {
Prefix = chunkGenerator.Prefix, Prefix = chunkGenerator.Prefix,
Content = chunkGenerator.Value, Content = chunkGenerator.Value,
SourceLocation = span.Start, SourceRange = new MappingLocation(span.Start, span.Length),
}); });
} }
@ -118,15 +117,31 @@ namespace Microsoft.AspNetCore.Razor.Evolution
// 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 VisitStartExpressionBlock(ExpressionChunkGenerator chunkGenerator, Block block) public override void VisitStartExpressionBlock(ExpressionChunkGenerator chunkGenerator, Block block)
{ {
Builder.Push(new CSharpExpressionIRNode() Builder.Push(new CSharpExpressionIRNode());
{
SourceLocation = block.Start,
});
} }
public override void VisitEndExpressionBlock(ExpressionChunkGenerator chunkGenerator, Block block) public override void VisitEndExpressionBlock(ExpressionChunkGenerator chunkGenerator, Block block)
{ {
Builder.Pop(); var expressionNode = Builder.Pop();
if (expressionNode.Children.Count > 0)
{
var sourceRangeStart = expressionNode.Children[0].SourceRange;
var contentLength = 0;
for (var i = 0; i < expressionNode.Children.Count; i++)
{
contentLength += expressionNode.Children[i].SourceRange.ContentLength;
}
expressionNode.SourceRange = new MappingLocation(
sourceRangeStart.AbsoluteIndex,
sourceRangeStart.LineIndex,
sourceRangeStart.CharacterIndex,
contentLength,
sourceRangeStart.FilePath);
}
} }
public override void VisitExpressionSpan(ExpressionChunkGenerator chunkGenerator, Span span) public override void VisitExpressionSpan(ExpressionChunkGenerator chunkGenerator, Span span)
@ -134,7 +149,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
Builder.Add(new CSharpTokenIRNode() Builder.Add(new CSharpTokenIRNode()
{ {
Content = span.Content, Content = span.Content,
SourceLocation = span.Start, SourceRange = new MappingLocation(span.Start, span.Length),
}); });
} }
@ -143,7 +158,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
var functionsNode = new CSharpStatementIRNode() var functionsNode = new CSharpStatementIRNode()
{ {
Content = span.Content, Content = span.Content,
SourceLocation = span.Start, SourceRange = new MappingLocation(span.Start, span.Length),
Parent = Class, Parent = Class,
}; };
@ -155,7 +170,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
Builder.Add(new CSharpStatementIRNode() Builder.Add(new CSharpStatementIRNode()
{ {
Content = span.Content, Content = span.Content,
SourceLocation = span.Start, SourceRange = new MappingLocation(span.Start, span.Length),
}); });
} }
@ -172,7 +187,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
Builder.Add(new HtmlContentIRNode() Builder.Add(new HtmlContentIRNode()
{ {
Content = span.Content, Content = span.Content,
SourceLocation = span.Start, SourceRange = new MappingLocation(span.Start, span.Length),
}); });
} }
} }
@ -193,7 +208,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
{ {
Content = span.Content, Content = span.Content,
Parent = Namespace, Parent = Namespace,
SourceLocation = span.Start, SourceRange = new MappingLocation(span.Start, span.Length),
}; };
Namespace.Children.Insert(i, @using); Namespace.Children.Insert(i, @using);
@ -205,7 +220,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
{ {
Content = span.Content, Content = span.Content,
Descriptor = chunkGenerator.Descriptor, Descriptor = chunkGenerator.Descriptor,
SourceLocation = span.Start, SourceRange = new MappingLocation(span.Start, span.Length),
}); });
} }

View File

@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate
public override RazorIRNode Parent { get; set; } public override RazorIRNode Parent { get; set; }
internal override SourceLocation SourceLocation { get; set; } internal override MappingLocation SourceRange { get; set; }
public string Prefix { get; set; } public string Prefix { get; set; }

View File

@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate
public override RazorIRNode Parent { get; set; } public override RazorIRNode Parent { get; set; }
internal override SourceLocation SourceLocation { get; set; } internal override MappingLocation SourceRange { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(RazorIRNodeVisitor visitor)
{ {

View File

@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate
public override RazorIRNode Parent { get; set; } public override RazorIRNode Parent { get; set; }
internal override SourceLocation SourceLocation { get; set; } internal override MappingLocation SourceRange { get; set; }
public string Content { get; set; } public string Content { get; set; }

View File

@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate
public override RazorIRNode Parent { get; set; } public override RazorIRNode Parent { get; set; }
internal override SourceLocation SourceLocation { get; set; } internal override MappingLocation SourceRange { get; set; }
public string Content { get; set; } public string Content { get; set; }

View File

@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate
public override RazorIRNode Parent { get; set; } public override RazorIRNode Parent { get; set; }
internal override SourceLocation SourceLocation { get; set; } internal override MappingLocation SourceRange { get; set; }
public string AccessModifier { get; set; } public string AccessModifier { get; set; }

View File

@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate
public override RazorIRNode Parent { get; set; } public override RazorIRNode Parent { get; set; }
internal override SourceLocation SourceLocation { get; set; } internal override MappingLocation SourceRange { get; set; }
public string Name { get; set; } public string Name { get; set; }

View File

@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate
public override RazorIRNode Parent { get; set; } public override RazorIRNode Parent { get; set; }
internal override SourceLocation SourceLocation { get; set; } internal override MappingLocation SourceRange { get; set; }
public string Content { get; set; } public string Content { get; set; }

View File

@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate
public override RazorIRNode Parent { get; set; } public override RazorIRNode Parent { get; set; }
internal override SourceLocation SourceLocation { get; set; } internal override MappingLocation SourceRange { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(RazorIRNodeVisitor visitor)
{ {

View File

@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate
public override RazorIRNode Parent { get; set; } public override RazorIRNode Parent { get; set; }
internal override SourceLocation SourceLocation { get; set; } internal override MappingLocation SourceRange { get; set; }
public string Name { get; set; } public string Name { get; set; }

View File

@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate
public override RazorIRNode Parent { get; set; } public override RazorIRNode Parent { get; set; }
internal override SourceLocation SourceLocation { get; set; } internal override MappingLocation SourceRange { get; set; }
public string Prefix { get; set; } public string Prefix { get; set; }

View File

@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate
public override RazorIRNode Parent { get; set; } public override RazorIRNode Parent { get; set; }
internal override SourceLocation SourceLocation { get; set; } internal override MappingLocation SourceRange { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(RazorIRNodeVisitor visitor)
{ {

View File

@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate
public override RazorIRNode Parent { get; set; } public override RazorIRNode Parent { get; set; }
internal override SourceLocation SourceLocation { get; set; } internal override MappingLocation SourceRange { get; set; }
public string Content { get; set; } public string Content { get; set; }

View File

@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate
public abstract RazorIRNode Parent { get; set; } public abstract RazorIRNode Parent { get; set; }
internal abstract SourceLocation SourceLocation { get; set; } internal abstract MappingLocation SourceRange { get; set; }
public abstract void Accept(RazorIRNodeVisitor visitor); public abstract void Accept(RazorIRNodeVisitor visitor);

View File

@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate
public override RazorIRNode Parent { get; set; } public override RazorIRNode Parent { get; set; }
internal override SourceLocation SourceLocation { get; set; } internal override MappingLocation SourceRange { get; set; }
public string AccessModifier { get; set; } public string AccessModifier { get; set; }

View File

@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate
public override RazorIRNode Parent { get; set; } public override RazorIRNode Parent { get; set; }
internal override SourceLocation SourceLocation { get; set; } internal override MappingLocation SourceRange { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(RazorIRNodeVisitor visitor)
{ {

View File

@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate
public override RazorIRNode Parent { get; set; } public override RazorIRNode Parent { get; set; }
internal override SourceLocation SourceLocation { get; set; } internal override MappingLocation SourceRange { get; set; }
public string Content { get; set; } public string Content { get; set; }

View File

@ -14,12 +14,17 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
} }
public MappingLocation(SourceLocation location, int contentLength) public MappingLocation(SourceLocation location, int contentLength)
: this (location.AbsoluteIndex, location.LineIndex, location.CharacterIndex, contentLength, location.FilePath)
{ {
}
public MappingLocation(int absoluteIndex, int lineIndex, int characterIndex, int contentLength, string filePath)
{
AbsoluteIndex = absoluteIndex;
LineIndex = lineIndex;
CharacterIndex = characterIndex;
ContentLength = contentLength; ContentLength = contentLength;
AbsoluteIndex = location.AbsoluteIndex; FilePath = filePath;
LineIndex = location.LineIndex;
CharacterIndex = location.CharacterIndex;
FilePath = location.FilePath;
} }
public int ContentLength { get; } public int ContentLength { get; }

View File

@ -89,7 +89,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.IntegrationTests
WriteIndent(); WriteIndent();
WriteName(node); WriteName(node);
WriteSeparator(); WriteSeparator();
WriteLocation(node); WriteSourceRange(node);
} }
protected void WriteContentNode(RazorIRNode node, params string[] content) protected void WriteContentNode(RazorIRNode node, params string[] content)
@ -97,7 +97,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.IntegrationTests
WriteIndent(); WriteIndent();
WriteName(node); WriteName(node);
WriteSeparator(); WriteSeparator();
WriteLocation(node); WriteSourceRange(node);
for (var i = 0; i < content.Length; i++) for (var i = 0; i < content.Length; i++)
{ {
@ -140,9 +140,12 @@ namespace Microsoft.AspNetCore.Razor.Evolution.IntegrationTests
} }
} }
protected void WriteLocation(RazorIRNode node) protected void WriteSourceRange(RazorIRNode node)
{ {
_writer.Write(node.SourceLocation.ToString()); if (node.SourceRange != null)
{
_writer.Write(node.SourceRange.ToString());
}
} }
protected void WriteContent(string content) protected void WriteContent(string content)

View File

@ -152,7 +152,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate
public override RazorIRNode Parent { get; set; } public override RazorIRNode Parent { get; set; }
internal override SourceLocation SourceLocation { get; set; } internal override MappingLocation SourceRange { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(RazorIRNodeVisitor visitor)
{ {

View File

@ -75,7 +75,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate
public override RazorIRNode Parent { get; set; } public override RazorIRNode Parent { get; set; }
internal override SourceLocation SourceLocation { get; set; } internal override MappingLocation SourceRange { get; set; }
public override void Accept(RazorIRNodeVisitor visitor) public override void Accept(RazorIRNodeVisitor visitor)
{ {

View File

@ -1,7 +1,7 @@
Document - (0:0,0) Document -
NamespaceDeclaration - (0:0,0) - NamespaceDeclaration - -
ClassDeclaration - (0:0,0) - - - - ClassDeclaration - - - - -
RazorMethodDeclaration - (0:0,0) - - - - RazorMethodDeclaration - - - - -
HtmlContent - (0:0,0) - HtmlContent - (0:0,0 [0] ) -
Directive - (0:0,0) - test_directive Directive - - test_directive
HtmlContent - (15:0,15) - HtmlContent - (15:0,15 [0] ) -

View File

@ -1,5 +1,5 @@
Document - (0:0,0) Document -
NamespaceDeclaration - (0:0,0) - NamespaceDeclaration - -
ClassDeclaration - (0:0,0) - - - - ClassDeclaration - - - - -
RazorMethodDeclaration - (0:0,0) - - - - RazorMethodDeclaration - - - - -
HtmlContent - (0:0,0) - HtmlContent - (0:0,0 [0] ) -

View File

@ -1,5 +1,5 @@
Document - (0:0,0) Document -
NamespaceDeclaration - (0:0,0) - NamespaceDeclaration - -
ClassDeclaration - (0:0,0) - - - - ClassDeclaration - - - - -
RazorMethodDeclaration - (0:0,0) - - - - RazorMethodDeclaration - - - - -
HtmlContent - (0:0,0) - Hello, World! HtmlContent - (0:0,0 [13] ) - Hello, World!

View File

@ -1,10 +1,10 @@
Document - (0:0,0) Document -
NamespaceDeclaration - (0:0,0) - NamespaceDeclaration - -
ClassDeclaration - (0:0,0) - - - - ClassDeclaration - - - - -
RazorMethodDeclaration - (0:0,0) - - - - RazorMethodDeclaration - - - - -
HtmlContent - (0:0,0) - <html>\r\n<body>\r\n <span HtmlContent - (0:0,0 [6] ) - <html>\r\n<body>\r\n <span
HtmlAttribute - (25:2,9) - val=" - " HtmlAttribute - (25:2,9 [13] ) - val=" - "
CSharpAttributeValue - (31:2,15) - CSharpAttributeValue - (31:2,15 [6] ) -
CSharpExpression - (31:2,15) CSharpExpression - (32:2,16 [5] )
CSharpToken - (32:2,16) - Hello CSharpToken - (32:2,16 [5] ) - Hello
HtmlContent - (38:2,22) - />\r\n</body>\r\n</html>" HtmlContent - (38:2,22 [3] ) - />\r\n</body>\r\n</html>"

View File

@ -1,8 +1,8 @@
Document - (0:0,0) Document -
NamespaceDeclaration - (0:0,0) - NamespaceDeclaration - -
ClassDeclaration - (0:0,0) - - - - ClassDeclaration - - - - -
RazorMethodDeclaration - (0:0,0) - - - - RazorMethodDeclaration - - - - -
HtmlContent - (0:0,0) - <html>\r\n<body>\r\n <span data\-val=" HtmlContent - (0:0,0 [6] ) - <html>\r\n<body>\r\n <span data\-val="
CSharpExpression - (36:2,20) CSharpExpression - (37:2,21 [5] )
CSharpToken - (37:2,21) - Hello CSharpToken - (37:2,21 [5] ) - Hello
HtmlContent - (42:2,26) - " />\r\n</body>\r\n</html>" HtmlContent - (42:2,26 [1] ) - " />\r\n</body>\r\n</html>"