Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c2be582
SyntaxRewriter: Remove VisitToken implementation
DustinCampbell Apr 3, 2025
6237c2b
SyntaxToken: Remove WithLeadingTrivia and WithTrailingTrivia
DustinCampbell Apr 3, 2025
7ff4145
SyntaxWalker: Remove VisitLeadingTrivia and VisitTrailingTrivia
DustinCampbell Apr 3, 2025
39a09d0
SyntaxNode: Remove HasLeadingTrivia and HasTrailingTrivia
DustinCampbell Apr 3, 2025
00f4ae5
SyntaxRewriter: Remove VisitList(SyntaxTriviaList)
DustinCampbell Apr 3, 2025
3060e2d
SyntaxTriviaList: Remove Enumerator.InitializeFrom helpers
DustinCampbell Apr 3, 2025
ac8fdb9
SyntaxNode: Remove GetLeadingTrivia and GetTrailingTrivia
DustinCampbell Apr 3, 2025
ab2325f
Remove SyntaxTriviaList and SyntaxTriviaListBuilder
DustinCampbell Apr 3, 2025
4371ff3
Internal.SyntaxToken: Remove uncalled constructors
DustinCampbell Apr 3, 2025
dffabf3
Internal.SyntaxRewriter: Remove VisitToken implementation
DustinCampbell Apr 3, 2025
8bc91a1
GreenNode: Remove WithLeadingTrivia and WithTrailingTrivia
DustinCampbell Apr 3, 2025
758cc7d
Internal.SyntaxToken: Remove LeadingTrivia and TrailingTrivia
DustinCampbell Apr 3, 2025
34f2a80
GeenNode: Remove HasLeadingTrivia and HasTrailingTrivia
DustinCampbell Apr 3, 2025
6197c1e
GreenNode: Remove GetLeadingTriviaWidth() and GetTrailingTriviaWidth()
DustinCampbell Apr 3, 2025
bdcc24f
GreenNode: Remove logic to write leading/trailing trivia
DustinCampbell Apr 3, 2025
099c81f
Internal.SyntaxToken: Don't compare trivia in IsEquivalentTo
DustinCampbell Apr 3, 2025
339803e
GreenNode: Remove GetLeadingTrivia() and GetTrailingTrivia()
DustinCampbell Apr 3, 2025
d17f252
Internal.SyntaxToken: Remove leading and trailing trivia fields
DustinCampbell Apr 3, 2025
5432996
Remove SyntaxTrivia and InternalSyntax.SyntaxTrivia
DustinCampbell Apr 3, 2025
1977b4a
GreenNode: Consolidate FullWidth and Width
DustinCampbell Apr 3, 2025
74259d7
SyntaxNode: Consolidate FullWidth and Width
DustinCampbell Apr 3, 2025
2186f51
SyntaxNode: Consolidate FullSpan and Span
DustinCampbell Apr 3, 2025
194bae9
Remove outdated comment and simplify GreenNode.WriteTo
DustinCampbell Apr 7, 2025
111ae93
Remove unused NodeFlags
DustinCampbell Apr 7, 2025
48b244a
GreenNode: Remove GetValue and GetValueText
DustinCampbell Apr 7, 2025
559723d
GreenNode: Remove GetFirstToken/Terminal and GetLastToken/Terminal
DustinCampbell Apr 7, 2025
8faf0e6
Remove SyntaxList<T>.FullSpan
DustinCampbell Apr 7, 2025
3d73b3b
GreenNode: Make ToString() to return the same text as ToFullString()
DustinCampbell Apr 7, 2025
947d638
Remove GreenNode.ToFullString() and SyntaxNode.ToFullString()
DustinCampbell Apr 7, 2025
684cae0
Merge branch 'main' into remove-dead-syntax
DustinCampbell Apr 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -251,31 +251,26 @@ public virtual string ToFullString()
return builder.ToString();
}

public virtual void WriteTo(TextWriter writer)
{
WriteTo(writer, includeLeadingTrivia: true, includeTrailingTrivia: true);
}

protected internal void WriteTo(TextWriter writer, bool includeLeadingTrivia, bool includeTrailingTrivia)
public void WriteTo(TextWriter writer)
{
// Use an actual Stack so we can write out deeply recursive structures without overflowing.
using var stack = new PooledArrayBuilder<StackEntry>();
using var stack = new PooledArrayBuilder<GreenNode>();

stack.Push(new(Node: this, includeLeadingTrivia, includeTrailingTrivia));
stack.Push(this);

// Separated out stack processing logic so that it does not unintentionally refer to
// "this", "leading" or "trailing.
ProcessStack(writer, ref stack.AsRef());

static void ProcessStack(TextWriter writer, ref PooledArrayBuilder<StackEntry> stack)
static void ProcessStack(TextWriter writer, ref PooledArrayBuilder<GreenNode> stack)
{
while (stack.Count > 0)
{
var (node, includeLeadingTrivia, includeTrailingTrivia) = stack.Pop();
var node = stack.Pop();

if (node.IsToken)
{
node.WriteTokenTo(writer, includeLeadingTrivia, includeTrailingTrivia);
node.WriteTokenTo(writer);
continue;
}

Expand All @@ -292,13 +287,7 @@ static void ProcessStack(TextWriter writer, ref PooledArrayBuilder<StackEntry> s
{
if (node.GetSlot(i) is GreenNode child)
{
var isFirst = i == firstIndex;
var isLast = i == lastIndex;

stack.Push(new(
child,
IncludeLeadingTrivia: includeLeadingTrivia | !isFirst,
IncludeTrailingTrivia: includeTrailingTrivia | !isLast));
stack.Push(child);
}
}
}
Expand Down Expand Up @@ -337,17 +326,12 @@ static int GetLastNonNullChildIndex(GreenNode node)
}
}

private readonly record struct StackEntry(
GreenNode Node,
bool IncludeLeadingTrivia,
bool IncludeTrailingTrivia);

protected virtual void WriteTriviaTo(TextWriter writer)
protected virtual void WriteTokenTo(TextWriter writer)
{
throw new NotImplementedException();
}

protected virtual void WriteTokenTo(TextWriter writer, bool includeLeadingTrivia, bool includeTrailingTrivia)
protected virtual void WriteTriviaTo(TextWriter writer)
{
throw new NotImplementedException();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable disable
Expand Down Expand Up @@ -40,21 +40,9 @@ internal override SyntaxNode CreateRed(SyntaxNode parent, int position)
return new Syntax.SyntaxToken(this, parent, position);
}

protected override void WriteTokenTo(TextWriter writer, bool includeLeadingTrivia, bool includeTrailingTrivia)
protected override void WriteTokenTo(TextWriter writer)
{
if (includeLeadingTrivia)
{
var trivia = GetLeadingTrivia();
trivia?.WriteTo(writer, includeLeadingTrivia: true, includeTrailingTrivia: true);
}

writer.Write(Content);

if (includeTrailingTrivia)
{
var trivia = GetTrailingTrivia();
trivia?.WriteTo(writer, includeLeadingTrivia: true, includeTrailingTrivia: true);
}
}

public sealed override GreenNode GetLeadingTrivia()
Expand Down