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,
Prefix = chunkGenerator.Prefix,
Suffix = chunkGenerator.Suffix,
SourceLocation = block.Start,
SourceRange = new MappingLocation(block.Start, block.Length),
});
}
@ -81,7 +80,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
Builder.Push(new CSharpAttributeValueIRNode()
{
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,
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
public override void VisitStartExpressionBlock(ExpressionChunkGenerator chunkGenerator, Block block)
{
Builder.Push(new CSharpExpressionIRNode()
{
SourceLocation = block.Start,
});
Builder.Push(new CSharpExpressionIRNode());
}
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)
@ -134,7 +149,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
Builder.Add(new CSharpTokenIRNode()
{
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()
{
Content = span.Content,
SourceLocation = span.Start,
SourceRange = new MappingLocation(span.Start, span.Length),
Parent = Class,
};
@ -155,7 +170,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
Builder.Add(new CSharpStatementIRNode()
{
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()
{
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,
Parent = Namespace,
SourceLocation = span.Start,
SourceRange = new MappingLocation(span.Start, span.Length),
};
Namespace.Children.Insert(i, @using);
@ -205,7 +220,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
{
Content = span.Content,
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; }
internal override SourceLocation SourceLocation { get; set; }
internal override MappingLocation SourceRange { 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; }
internal override SourceLocation SourceLocation { get; set; }
internal override MappingLocation SourceRange { get; set; }
public override void Accept(RazorIRNodeVisitor visitor)
{

View File

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

View File

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

View File

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

View File

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

View File

@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Intermediate
public override RazorIRNode Parent { get; set; }
internal override SourceLocation SourceLocation { get; set; }
internal override MappingLocation SourceRange { 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)
: 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;
AbsoluteIndex = location.AbsoluteIndex;
LineIndex = location.LineIndex;
CharacterIndex = location.CharacterIndex;
FilePath = location.FilePath;
FilePath = filePath;
}
public int ContentLength { get; }

View File

@ -89,7 +89,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.IntegrationTests
WriteIndent();
WriteName(node);
WriteSeparator();
WriteLocation(node);
WriteSourceRange(node);
}
protected void WriteContentNode(RazorIRNode node, params string[] content)
@ -97,7 +97,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution.IntegrationTests
WriteIndent();
WriteName(node);
WriteSeparator();
WriteLocation(node);
WriteSourceRange(node);
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)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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