Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

Commit

Permalink
Rename RazorIRNode
Browse files Browse the repository at this point in the history
Get rid of references to 'IR'
  • Loading branch information
rynowak committed Jun 21, 2017
1 parent d2469e0 commit 21e26ad
Show file tree
Hide file tree
Showing 345 changed files with 7,218 additions and 7,225 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@

namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{
public class AssemblyAttributeInjectionPass : RazorIRPassBase, IRazorIROptimizationPass
public class AssemblyAttributeInjectionPass : IntermediateNodePassBase, IRazorOptimizationPass
{
private const string RazorViewAttribute = "global::Microsoft.AspNetCore.Mvc.Razor.Compilation.RazorViewAttribute";
private const string RazorPageAttribute = "global::Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.RazorPageAttribute";

protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNode irDocument)
protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
{
var @namespace = irDocument.FindPrimaryNamespace();
var @namespace = documentNode.FindPrimaryNamespace();
if (@namespace == null || string.IsNullOrEmpty(@namespace.Content))
{
// No namespace node or it's incomplete. Skip.
return;
}

var @class = irDocument.FindPrimaryClass();
var @class = documentNode.FindPrimaryClass();
if (@class == null || string.IsNullOrEmpty(@class.Name))
{
// No class node or it's incomplete. Skip.
Expand All @@ -33,12 +33,12 @@ protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNo
var escapedPath = EscapeAsVerbatimLiteral(path);

string attribute;
if (irDocument.DocumentKind == MvcViewDocumentClassifierPass.MvcViewDocumentKind)
if (documentNode.DocumentKind == MvcViewDocumentClassifierPass.MvcViewDocumentKind)
{
attribute = $"[assembly:{RazorViewAttribute}({escapedPath}, typeof({generatedTypeName}))]";
}
else if (irDocument.DocumentKind == RazorPageDocumentClassifierPass.RazorPageDocumentKind &&
PageDirective.TryGetPageDirective(irDocument, out var pageDirective))
else if (documentNode.DocumentKind == RazorPageDocumentClassifierPass.RazorPageDocumentKind &&
PageDirective.TryGetPageDirective(documentNode, out var pageDirective))
{
var escapedRoutePrefix = EscapeAsVerbatimLiteral(pageDirective.RouteTemplate);
attribute = $"[assembly:{RazorPageAttribute}({escapedPath}, typeof({generatedTypeName}), {escapedRoutePrefix})]";
Expand All @@ -48,18 +48,18 @@ protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNo
return;
}

var index = irDocument.Children.IndexOf(@namespace);
var index = documentNode.Children.IndexOf(@namespace);
Debug.Assert(index >= 0);

var pageAttribute = new CSharpCodeIRNode();
RazorIRBuilder.Create(pageAttribute)
.Add(new RazorIRToken()
var pageAttribute = new CSharpCodeIntermediateNode();
IntermediateNodeBuilder.Create(pageAttribute)
.Add(new IntermediateToken()
{
Kind = RazorIRToken.TokenKind.CSharp,
Kind = IntermediateToken.TokenKind.CSharp,
Content = attribute,
});

irDocument.Children.Insert(index, pageAttribute);
documentNode.Children.Insert(index, pageAttribute);
}

private static string EscapeAsVerbatimLiteral(string value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{
public interface IInjectDirectiveTargetExtension : ICodeTargetExtension
public interface IInjectTargetExtension : ICodeTargetExtension
{
void WriteInjectProperty(CSharpRenderingContext context, InjectDirectiveIRNode node);
void WriteInjectProperty(CSharpRenderingContext context, InjectIntermediateNode node);
}
}
21 changes: 11 additions & 10 deletions src/Microsoft.AspNetCore.Mvc.Razor.Extensions/InjectDirective.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@ public static IRazorEngineBuilder Register(IRazorEngineBuilder builder)
{
builder.AddDirective(Directive);
builder.Features.Add(new Pass());
builder.AddTargetExtension(new InjectTargetExtension());
return builder;
}

internal class Pass : RazorIRPassBase, IRazorDirectiveClassifierPass
internal class Pass : IntermediateNodePassBase, IRazorDirectiveClassifierPass
{
// Runs after the @model and @namespace directives
public override int Order => 10;

protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNode irDocument)
protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
{
var visitor = new Visitor();
visitor.Visit(irDocument);
var modelType = ModelDirective.GetModelType(irDocument);
visitor.Visit(documentNode);
var modelType = ModelDirective.GetModelType(documentNode);

var properties = new HashSet<string>(StringComparer.Ordinal);

Expand All @@ -55,7 +56,7 @@ protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNo

typeName = typeName.Replace("<TModel>", "<" + modelType + ">");

var injectNode = new InjectDirectiveIRNode()
var injectNode = new InjectIntermediateNode()
{
TypeName = typeName,
MemberName = memberName,
Expand All @@ -66,13 +67,13 @@ protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNo
}
}

private class Visitor : RazorIRNodeWalker
private class Visitor : IntermediateNodeWalker
{
public ClassDeclarationIRNode Class { get; private set; }
public ClassDeclarationIntermediateNode Class { get; private set; }

public IList<DirectiveIRNode> Directives { get; } = new List<DirectiveIRNode>();
public IList<DirectiveIntermediateNode> Directives { get; } = new List<DirectiveIntermediateNode>();

public override void VisitClassDeclaration(ClassDeclarationIRNode node)
public override void VisitClassDeclaration(ClassDeclarationIntermediateNode node)
{
if (Class == null)
{
Expand All @@ -82,7 +83,7 @@ public override void VisitClassDeclaration(ClassDeclarationIRNode node)
base.VisitClassDeclaration(node);
}

public override void VisitDirective(DirectiveIRNode node)
public override void VisitDirective(DirectiveIntermediateNode node)
{
if (node.Descriptor == Directive)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@

namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{
public class InjectDirectiveIRNode : ExtensionIRNode
public class InjectIntermediateNode : ExtensionIntermediateNode
{
public string TypeName { get; set; }

public string MemberName { get; set; }

public override RazorIRNodeCollection Children => ReadOnlyIRNodeCollection.Instance;
public override IntermediateNodeCollection Children => ReadOnlyIntermediateNodeCollection.Instance;

public override void Accept(RazorIRNodeVisitor visitor)
public override void Accept(IntermediateNodeVisitor visitor)
{
if (visitor == null)
{
throw new ArgumentNullException(nameof(visitor));
}

AcceptExtensionNode<InjectDirectiveIRNode>(this, visitor);
AcceptExtensionNode<InjectIntermediateNode>(this, visitor);
}

public override void WriteNode(CodeTarget target, CSharpRenderingContext context)
Expand All @@ -38,10 +38,10 @@ public override void WriteNode(CodeTarget target, CSharpRenderingContext context
throw new ArgumentNullException(nameof(context));
}

var extension = target.GetExtension<IInjectDirectiveTargetExtension>();
var extension = target.GetExtension<IInjectTargetExtension>();
if (extension == null)
{
context.ReportMissingExtension<IInjectDirectiveTargetExtension>();
context.ReportMissingExtension<IInjectTargetExtension>();
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{
public class InjectDirectiveTargetExtension : IInjectDirectiveTargetExtension
public class InjectTargetExtension : IInjectTargetExtension
{
private const string RazorInjectAttribute = "[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]";

public void WriteInjectProperty(CSharpRenderingContext context, InjectDirectiveIRNode node)
public void WriteInjectProperty(CSharpRenderingContext context, InjectIntermediateNode node)
{
if (context == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
{
public class InstrumentationPass : RazorIRPassBase, IRazorIROptimizationPass
public class InstrumentationPass : IntermediateNodePassBase, IRazorOptimizationPass
{
public override int Order => DefaultFeatureOrder;

protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNode irDocument)
protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
{
var walker = new Visitor();
walker.VisitDocument(irDocument);
walker.VisitDocument(documentNode);

for (var i = 0; i < walker.Items.Count; i++)
{
Expand All @@ -30,23 +30,23 @@ private static void AddInstrumentation(InstrumentationItem item)
var beginContextMethodName = "BeginContext"; /* ORIGINAL: BeginContextMethodName */
var endContextMethodName = "EndContext"; /* ORIGINAL: EndContextMethodName */

var beginNode = new CSharpCodeIRNode();
RazorIRBuilder.Create(beginNode)
.Add(new RazorIRToken()
var beginNode = new CSharpCodeIntermediateNode();
IntermediateNodeBuilder.Create(beginNode)
.Add(new IntermediateToken()
{
Kind = RazorIRToken.TokenKind.CSharp,
Kind = IntermediateToken.TokenKind.CSharp,
Content = string.Format("{0}({1}, {2}, {3});",
beginContextMethodName,
item.Source.AbsoluteIndex.ToString(CultureInfo.InvariantCulture),
item.Source.Length.ToString(CultureInfo.InvariantCulture),
item.IsLiteral ? "true" : "false")
});

var endNode = new CSharpCodeIRNode();
RazorIRBuilder.Create(endNode)
.Add(new RazorIRToken()
var endNode = new CSharpCodeIntermediateNode();
IntermediateNodeBuilder.Create(endNode)
.Add(new IntermediateToken()
{
Kind = RazorIRToken.TokenKind.CSharp,
Kind = IntermediateToken.TokenKind.CSharp,
Content = string.Format("{0}();", endContextMethodName)
});

Expand All @@ -57,28 +57,28 @@ private static void AddInstrumentation(InstrumentationItem item)

private struct InstrumentationItem
{
public InstrumentationItem(RazorIRNode node, RazorIRNode parent, bool isLiteral, SourceSpan source)
public InstrumentationItem(IntermediateNode node, IntermediateNode parent, bool isLiteral, SourceSpan source)
{
Node = node;
Parent = parent;
IsLiteral = isLiteral;
Source = source;
}

public RazorIRNode Node { get; }
public IntermediateNode Node { get; }

public RazorIRNode Parent { get; }
public IntermediateNode Parent { get; }

public bool IsLiteral { get; }

public SourceSpan Source { get; }
}

private class Visitor : RazorIRNodeWalker
private class Visitor : IntermediateNodeWalker
{
public List<InstrumentationItem> Items { get; } = new List<InstrumentationItem>();

public override void VisitHtml(HtmlContentIRNode node)
public override void VisitHtml(HtmlContentIntermediateNode node)
{
if (node.Source != null)
{
Expand All @@ -88,7 +88,7 @@ public override void VisitHtml(HtmlContentIRNode node)
VisitDefault(node);
}

public override void VisitCSharpExpression(CSharpExpressionIRNode node)
public override void VisitCSharpExpression(CSharpExpressionIntermediateNode node)
{
if (node.Source != null)
{
Expand All @@ -98,7 +98,7 @@ public override void VisitCSharpExpression(CSharpExpressionIRNode node)
VisitDefault(node);
}

public override void VisitTagHelper(TagHelperIRNode node)
public override void VisitTagHelper(TagHelperIntermediateNode node)
{
if (node.Source != null)
{
Expand All @@ -108,12 +108,12 @@ public override void VisitTagHelper(TagHelperIRNode node)
VisitDefault(node);
}

public override void VisitAddTagHelperHtmlAttribute(AddTagHelperHtmlAttributeIRNode node)
public override void VisitAddTagHelperHtmlAttribute(AddTagHelperHtmlAttributeIntermediateNode node)
{
// We don't want to instrument TagHelper attributes. Do nothing.
}

public override void VisitSetTagHelperProperty(SetTagHelperPropertyIRNode node)
public override void VisitSetTagHelperProperty(SetTagHelperPropertyIntermediateNode node)
{
// We don't want to instrument TagHelper attributes. Do nothing.
}
Expand Down
28 changes: 14 additions & 14 deletions src/Microsoft.AspNetCore.Mvc.Razor.Extensions/ModelDirective.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static IRazorEngineBuilder Register(IRazorEngineBuilder builder)
return builder;
}

public static string GetModelType(DocumentIRNode document)
public static string GetModelType(DocumentIntermediateNode document)
{
if (document == null)
{
Expand All @@ -34,7 +34,7 @@ public static string GetModelType(DocumentIRNode document)
return GetModelType(document, visitor);
}

private static string GetModelType(DocumentIRNode document, Visitor visitor)
private static string GetModelType(DocumentIntermediateNode document, Visitor visitor)
{
visitor.Visit(document);

Expand All @@ -59,7 +59,7 @@ private static string GetModelType(DocumentIRNode document, Visitor visitor)
}
}

internal class Pass : RazorIRPassBase, IRazorDirectiveClassifierPass
internal class Pass : IntermediateNodePassBase, IRazorDirectiveClassifierPass
{
private readonly bool _designTime;

Expand All @@ -71,17 +71,17 @@ public Pass(bool designTime)
// Runs after the @inherits directive
public override int Order => 5;

protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNode irDocument)
protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode)
{
var visitor = new Visitor();
var modelType = GetModelType(irDocument, visitor);
var modelType = GetModelType(documentNode, visitor);

if (_designTime)
{
// Alias the TModel token to a known type.
// This allows design time compilation to succeed for Razor files where the token isn't replaced.
var typeName = $"global::{typeof(object).FullName}";
var usingNode = new UsingStatementIRNode()
var usingNode = new UsingStatementIntermediateNode()
{
Content = $"TModel = {typeName}"
};
Expand All @@ -106,17 +106,17 @@ protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIRNo
}
}

private class Visitor : RazorIRNodeWalker
private class Visitor : IntermediateNodeWalker
{
public NamespaceDeclarationIRNode Namespace { get; private set; }
public NamespaceDeclarationIntermediateNode Namespace { get; private set; }

public ClassDeclarationIRNode Class { get; private set; }
public ClassDeclarationIntermediateNode Class { get; private set; }

public IList<DirectiveIRNode> InheritsDirectives { get; } = new List<DirectiveIRNode>();
public IList<DirectiveIntermediateNode> InheritsDirectives { get; } = new List<DirectiveIntermediateNode>();

public IList<DirectiveIRNode> ModelDirectives { get; } = new List<DirectiveIRNode>();
public IList<DirectiveIntermediateNode> ModelDirectives { get; } = new List<DirectiveIntermediateNode>();

public override void VisitNamespaceDeclaration(NamespaceDeclarationIRNode node)
public override void VisitNamespaceDeclaration(NamespaceDeclarationIntermediateNode node)
{
if (Namespace == null)
{
Expand All @@ -126,7 +126,7 @@ public override void VisitNamespaceDeclaration(NamespaceDeclarationIRNode node)
base.VisitNamespaceDeclaration(node);
}

public override void VisitClassDeclaration(ClassDeclarationIRNode node)
public override void VisitClassDeclaration(ClassDeclarationIntermediateNode node)
{
if (Class == null)
{
Expand All @@ -136,7 +136,7 @@ public override void VisitClassDeclaration(ClassDeclarationIRNode node)
base.VisitClassDeclaration(node);
}

public override void VisitDirective(DirectiveIRNode node)
public override void VisitDirective(DirectiveIntermediateNode node)
{
if (node.Descriptor == Directive)
{
Expand Down
Loading

0 comments on commit 21e26ad

Please sign in to comment.