652 lines
30 KiB
C#
652 lines
30 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Linq;
|
|
using Microsoft.CodeAnalysis.Syntax;
|
|
using Microsoft.CodeAnalysis.Text;
|
|
|
|
namespace Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
|
|
internal static class SyntaxNodeRemover
|
|
{
|
|
private class SyntaxRemover : CSharpSyntaxRewriter
|
|
{
|
|
private readonly HashSet<SyntaxNode> _nodesToRemove;
|
|
|
|
private readonly SyntaxRemoveOptions _options;
|
|
|
|
private readonly TextSpan _searchSpan;
|
|
|
|
private readonly SyntaxTriviaListBuilder _residualTrivia;
|
|
|
|
private HashSet<SyntaxNode>? _directivesToKeep;
|
|
|
|
internal SyntaxTriviaList ResidualTrivia
|
|
{
|
|
get
|
|
{
|
|
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
|
|
if (_residualTrivia != null)
|
|
{
|
|
return _residualTrivia.ToList();
|
|
}
|
|
return default(SyntaxTriviaList);
|
|
}
|
|
}
|
|
|
|
public SyntaxRemover(SyntaxNode[] nodesToRemove, SyntaxRemoveOptions options)
|
|
: base(nodesToRemove.Any((SyntaxNode n) => n.IsPartOfStructuredTrivia()))
|
|
{
|
|
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
|
|
_nodesToRemove = new HashSet<SyntaxNode>(nodesToRemove);
|
|
_options = options;
|
|
_searchSpan = ComputeTotalSpan(nodesToRemove);
|
|
_residualTrivia = SyntaxTriviaListBuilder.Create();
|
|
}
|
|
|
|
private static TextSpan ComputeTotalSpan(SyntaxNode[] nodes)
|
|
{
|
|
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
|
|
TextSpan fullSpan = nodes[0].FullSpan;
|
|
int num = ((TextSpan)(ref fullSpan)).Start;
|
|
int num2 = ((TextSpan)(ref fullSpan)).End;
|
|
for (int i = 1; i < nodes.Length; i++)
|
|
{
|
|
TextSpan fullSpan2 = nodes[i].FullSpan;
|
|
num = Math.Min(num, ((TextSpan)(ref fullSpan2)).Start);
|
|
num2 = Math.Max(num2, ((TextSpan)(ref fullSpan2)).End);
|
|
}
|
|
return new TextSpan(num, num2 - num);
|
|
}
|
|
|
|
private void AddResidualTrivia(SyntaxTriviaList trivia, bool requiresNewLine = false)
|
|
{
|
|
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
|
|
if (requiresNewLine)
|
|
{
|
|
AddEndOfLine((SyntaxTrivia)(((_003F?)GetEndOfLine(trivia)) ?? SyntaxFactory.CarriageReturnLineFeed));
|
|
}
|
|
_residualTrivia.Add(ref trivia);
|
|
}
|
|
|
|
private void AddEndOfLine(SyntaxTrivia? eolTrivia)
|
|
{
|
|
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
|
|
if (eolTrivia.HasValue && (_residualTrivia.Count == 0 || !IsEndOfLine(_residualTrivia[_residualTrivia.Count - 1])))
|
|
{
|
|
_residualTrivia.Add(eolTrivia.Value);
|
|
}
|
|
}
|
|
|
|
private static bool IsEndOfLine(SyntaxTrivia trivia)
|
|
{
|
|
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
|
|
if (trivia.Kind() != SyntaxKind.EndOfLineTrivia && trivia.Kind() != SyntaxKind.SingleLineCommentTrivia)
|
|
{
|
|
return ((SyntaxTrivia)(ref trivia)).IsDirective;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private static SyntaxTrivia? GetEndOfLine(SyntaxTriviaList list)
|
|
{
|
|
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
|
|
Enumerator enumerator = ((SyntaxTriviaList)(ref list)).GetEnumerator();
|
|
while (((Enumerator)(ref enumerator)).MoveNext())
|
|
{
|
|
SyntaxTrivia current = ((Enumerator)(ref enumerator)).Current;
|
|
if (current.Kind() == SyntaxKind.EndOfLineTrivia)
|
|
{
|
|
return current;
|
|
}
|
|
if (((SyntaxTrivia)(ref current)).IsDirective && ((SyntaxTrivia)(ref current)).GetStructure() is DirectiveTriviaSyntax { EndOfDirectiveToken: var endOfDirectiveToken })
|
|
{
|
|
return GetEndOfLine(((SyntaxToken)(ref endOfDirectiveToken)).TrailingTrivia);
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private bool IsForRemoval(SyntaxNode node)
|
|
{
|
|
return _nodesToRemove.Contains(node);
|
|
}
|
|
|
|
private bool ShouldVisit(SyntaxNode node)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
|
|
TextSpan fullSpan = node.FullSpan;
|
|
if (!((TextSpan)(ref fullSpan)).IntersectsWith(_searchSpan))
|
|
{
|
|
if (_residualTrivia != null)
|
|
{
|
|
return _residualTrivia.Count > 0;
|
|
}
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
[return: NotNullIfNotNull("node")]
|
|
public override SyntaxNode? Visit(SyntaxNode? node)
|
|
{
|
|
SyntaxNode result = node;
|
|
if (node != null)
|
|
{
|
|
if (IsForRemoval(node))
|
|
{
|
|
AddTrivia(node);
|
|
result = null;
|
|
}
|
|
else if (ShouldVisit(node))
|
|
{
|
|
result = base.Visit(node);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public override SyntaxToken VisitToken(SyntaxToken token)
|
|
{
|
|
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
|
|
SyntaxToken val = token;
|
|
if (VisitIntoStructuredTrivia)
|
|
{
|
|
val = base.VisitToken(token);
|
|
}
|
|
if (val.Kind() != SyntaxKind.None && _residualTrivia != null && _residualTrivia.Count > 0)
|
|
{
|
|
SyntaxTriviaListBuilder residualTrivia = _residualTrivia;
|
|
SyntaxTriviaList leadingTrivia = ((SyntaxToken)(ref val)).LeadingTrivia;
|
|
residualTrivia.Add(ref leadingTrivia);
|
|
val = ((SyntaxToken)(ref val)).WithLeadingTrivia(_residualTrivia.ToList());
|
|
_residualTrivia.Clear();
|
|
}
|
|
return val;
|
|
}
|
|
|
|
public override SeparatedSyntaxList<TNode> VisitList<TNode>(SeparatedSyntaxList<TNode> list)
|
|
{
|
|
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0199: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_018e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0193: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0149: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_014b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_014d: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0085: Expected O, but got Unknown
|
|
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_016d: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_015b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0161: Expected O, but got Unknown
|
|
//IL_0162: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0106: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_012f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
|
|
SyntaxNodeOrTokenList withSeparators = list.GetWithSeparators();
|
|
bool flag = false;
|
|
SyntaxNodeOrTokenListBuilder val = null;
|
|
int num = 0;
|
|
int count = ((SyntaxNodeOrTokenList)(ref withSeparators)).Count;
|
|
bool flag2 = default(bool);
|
|
bool flag3 = default(bool);
|
|
while (num < count)
|
|
{
|
|
SyntaxNodeOrToken val2 = ((SyntaxNodeOrTokenList)(ref withSeparators))[num];
|
|
SyntaxNodeOrToken val3;
|
|
if (((SyntaxNodeOrToken)(ref val2)).IsToken)
|
|
{
|
|
if (flag)
|
|
{
|
|
flag = false;
|
|
val3 = default(SyntaxNodeOrToken);
|
|
}
|
|
else
|
|
{
|
|
val3 = SyntaxNodeOrToken.op_Implicit(VisitListSeparator(((SyntaxNodeOrToken)(ref val2)).AsToken()));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
TNode val4 = (TNode)(object)((SyntaxNodeOrToken)(ref val2)).AsNode();
|
|
if (IsForRemoval((SyntaxNode)(object)val4))
|
|
{
|
|
if (val == null)
|
|
{
|
|
val = new SyntaxNodeOrTokenListBuilder(count);
|
|
val.Add(withSeparators, 0, num);
|
|
}
|
|
CommonSyntaxNodeRemover.GetSeparatorInfo(withSeparators, num, 8539, ref flag2, ref flag3);
|
|
SyntaxNodeOrToken val5;
|
|
if (!flag3 && val.Count > 0)
|
|
{
|
|
val5 = val[val.Count - 1];
|
|
if (((SyntaxNodeOrToken)(ref val5)).IsToken)
|
|
{
|
|
val5 = val[val.Count - 1];
|
|
SyntaxToken token = ((SyntaxNodeOrToken)(ref val5)).AsToken();
|
|
AddTrivia(token, (SyntaxNode)(object)val4);
|
|
val.RemoveLast();
|
|
goto IL_012d;
|
|
}
|
|
}
|
|
if (flag2)
|
|
{
|
|
val5 = ((SyntaxNodeOrTokenList)(ref withSeparators))[num + 1];
|
|
SyntaxToken token2 = ((SyntaxNodeOrToken)(ref val5)).AsToken();
|
|
AddTrivia((SyntaxNode)(object)val4, token2);
|
|
flag = true;
|
|
}
|
|
else
|
|
{
|
|
AddTrivia((SyntaxNode)(object)val4);
|
|
}
|
|
goto IL_012d;
|
|
}
|
|
val3 = SyntaxNodeOrToken.op_Implicit((SyntaxNode)(object)VisitListElement(val4));
|
|
}
|
|
goto IL_014b;
|
|
IL_014b:
|
|
if (val2 != val3 && val == null)
|
|
{
|
|
val = new SyntaxNodeOrTokenListBuilder(count);
|
|
val.Add(withSeparators, 0, num);
|
|
}
|
|
if (val != null && val3.Kind() != SyntaxKind.None)
|
|
{
|
|
val.Add(ref val3);
|
|
}
|
|
num++;
|
|
continue;
|
|
IL_012d:
|
|
val3 = default(SyntaxNodeOrToken);
|
|
goto IL_014b;
|
|
}
|
|
if (val != null)
|
|
{
|
|
return val.ToList().AsSeparatedList<TNode>();
|
|
}
|
|
return list;
|
|
}
|
|
|
|
private void AddTrivia(SyntaxNode node)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
|
|
if ((_options & 1) != 0)
|
|
{
|
|
AddResidualTrivia(node.GetLeadingTrivia());
|
|
}
|
|
else if ((_options & 0x10) != 0)
|
|
{
|
|
AddEndOfLine(GetEndOfLine(node.GetLeadingTrivia()));
|
|
}
|
|
if ((_options & 0xC) != 0)
|
|
{
|
|
AddDirectives(node, GetRemovedSpan(node.Span, node.FullSpan));
|
|
}
|
|
if ((_options & 2) != 0)
|
|
{
|
|
AddResidualTrivia(node.GetTrailingTrivia());
|
|
}
|
|
else if ((_options & 0x10) != 0)
|
|
{
|
|
AddEndOfLine(GetEndOfLine(node.GetTrailingTrivia()));
|
|
}
|
|
if ((_options & 0x20) != 0)
|
|
{
|
|
AddResidualTrivia(SyntaxFactory.TriviaList(SyntaxFactory.ElasticMarker));
|
|
}
|
|
}
|
|
|
|
private void AddTrivia(SyntaxToken token, SyntaxNode node)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0117: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_011c: Unknown result type (might be due to invalid IL or missing references)
|
|
if ((_options & 1) != 0)
|
|
{
|
|
AddResidualTrivia(((SyntaxToken)(ref token)).LeadingTrivia);
|
|
AddResidualTrivia(((SyntaxToken)(ref token)).TrailingTrivia);
|
|
AddResidualTrivia(node.GetLeadingTrivia());
|
|
}
|
|
else if ((_options & 0x10) != 0)
|
|
{
|
|
SyntaxTrivia? eolTrivia = GetEndOfLine(((SyntaxToken)(ref token)).LeadingTrivia) ?? GetEndOfLine(((SyntaxToken)(ref token)).TrailingTrivia);
|
|
AddEndOfLine(eolTrivia);
|
|
}
|
|
if ((_options & 0xC) != 0)
|
|
{
|
|
TextSpan val = ((SyntaxToken)(ref token)).Span;
|
|
int start = ((TextSpan)(ref val)).Start;
|
|
val = node.Span;
|
|
TextSpan span = TextSpan.FromBounds(start, ((TextSpan)(ref val)).End);
|
|
val = ((SyntaxToken)(ref token)).FullSpan;
|
|
int start2 = ((TextSpan)(ref val)).Start;
|
|
val = node.FullSpan;
|
|
TextSpan fullSpan = TextSpan.FromBounds(start2, ((TextSpan)(ref val)).End);
|
|
AddDirectives(node.Parent, GetRemovedSpan(span, fullSpan));
|
|
}
|
|
if ((_options & 2) != 0)
|
|
{
|
|
AddResidualTrivia(node.GetTrailingTrivia());
|
|
}
|
|
else if ((_options & 0x10) != 0)
|
|
{
|
|
AddEndOfLine(GetEndOfLine(node.GetTrailingTrivia()));
|
|
}
|
|
if ((_options & 0x20) != 0)
|
|
{
|
|
AddResidualTrivia(SyntaxFactory.TriviaList(SyntaxFactory.ElasticMarker));
|
|
}
|
|
}
|
|
|
|
private void AddTrivia(SyntaxNode node, SyntaxToken token)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0109: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
|
|
if ((_options & 1) != 0)
|
|
{
|
|
AddResidualTrivia(node.GetLeadingTrivia());
|
|
}
|
|
else if ((_options & 0x10) != 0)
|
|
{
|
|
AddEndOfLine(GetEndOfLine(node.GetLeadingTrivia()));
|
|
}
|
|
if ((_options & 0xC) != 0)
|
|
{
|
|
TextSpan val = node.Span;
|
|
int start = ((TextSpan)(ref val)).Start;
|
|
val = ((SyntaxToken)(ref token)).Span;
|
|
TextSpan span = TextSpan.FromBounds(start, ((TextSpan)(ref val)).End);
|
|
val = node.FullSpan;
|
|
int start2 = ((TextSpan)(ref val)).Start;
|
|
val = ((SyntaxToken)(ref token)).FullSpan;
|
|
TextSpan fullSpan = TextSpan.FromBounds(start2, ((TextSpan)(ref val)).End);
|
|
AddDirectives(node.Parent, GetRemovedSpan(span, fullSpan));
|
|
}
|
|
if ((_options & 2) != 0)
|
|
{
|
|
AddResidualTrivia(node.GetTrailingTrivia());
|
|
AddResidualTrivia(((SyntaxToken)(ref token)).LeadingTrivia);
|
|
AddResidualTrivia(((SyntaxToken)(ref token)).TrailingTrivia);
|
|
}
|
|
else if ((_options & 0x10) != 0)
|
|
{
|
|
SyntaxTrivia? eolTrivia = GetEndOfLine(node.GetTrailingTrivia()) ?? GetEndOfLine(((SyntaxToken)(ref token)).TrailingTrivia);
|
|
AddEndOfLine(eolTrivia);
|
|
}
|
|
if ((_options & 0x20) != 0)
|
|
{
|
|
AddResidualTrivia(SyntaxFactory.TriviaList(SyntaxFactory.ElasticMarker));
|
|
}
|
|
}
|
|
|
|
private TextSpan GetRemovedSpan(TextSpan span, TextSpan fullSpan)
|
|
{
|
|
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
|
|
TextSpan result = fullSpan;
|
|
if ((_options & 1) != 0)
|
|
{
|
|
result = TextSpan.FromBounds(((TextSpan)(ref span)).Start, ((TextSpan)(ref result)).End);
|
|
}
|
|
if ((_options & 2) != 0)
|
|
{
|
|
result = TextSpan.FromBounds(((TextSpan)(ref result)).Start, ((TextSpan)(ref span)).End);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private void AddDirectives(SyntaxNode node, TextSpan span)
|
|
{
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_01af: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
|
|
if (!node.ContainsDirectives)
|
|
{
|
|
return;
|
|
}
|
|
if (_directivesToKeep == null)
|
|
{
|
|
_directivesToKeep = new HashSet<SyntaxNode>();
|
|
}
|
|
else
|
|
{
|
|
_directivesToKeep.Clear();
|
|
}
|
|
foreach (DirectiveTriviaSyntax item in from tr in node.DescendantTrivia(span, (Func<SyntaxNode, bool>)((SyntaxNode n) => n.ContainsDirectives), true)
|
|
where ((SyntaxTrivia)(ref tr)).IsDirective
|
|
select (DirectiveTriviaSyntax)(object)((SyntaxTrivia)(ref tr)).GetStructure())
|
|
{
|
|
if ((_options & 8) != 0)
|
|
{
|
|
_directivesToKeep.Add((SyntaxNode)(object)item);
|
|
}
|
|
else if (item.Kind() == SyntaxKind.DefineDirectiveTrivia || item.Kind() == SyntaxKind.UndefDirectiveTrivia)
|
|
{
|
|
_directivesToKeep.Add((SyntaxNode)(object)item);
|
|
}
|
|
else if (HasRelatedDirectives(item))
|
|
{
|
|
List<DirectiveTriviaSyntax> relatedDirectives = item.GetRelatedDirectives();
|
|
if (!relatedDirectives.All(delegate(DirectiveTriviaSyntax rd)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
|
|
TextSpan fullSpan = ((SyntaxNode)rd).FullSpan;
|
|
return ((TextSpan)(ref fullSpan)).OverlapsWith(span);
|
|
}))
|
|
{
|
|
foreach (DirectiveTriviaSyntax item2 in relatedDirectives.Where(delegate(DirectiveTriviaSyntax rd)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
|
|
TextSpan fullSpan = ((SyntaxNode)rd).FullSpan;
|
|
return ((TextSpan)(ref fullSpan)).OverlapsWith(span);
|
|
}))
|
|
{
|
|
_directivesToKeep.Add((SyntaxNode)(object)item2);
|
|
}
|
|
}
|
|
}
|
|
if (_directivesToKeep.Contains((SyntaxNode)(object)item))
|
|
{
|
|
AddResidualTrivia(SyntaxFactory.TriviaList(((SyntaxNode)item).ParentTrivia), requiresNewLine: true);
|
|
}
|
|
}
|
|
}
|
|
|
|
private static bool HasRelatedDirectives(DirectiveTriviaSyntax directive)
|
|
{
|
|
SyntaxKind syntaxKind = directive.Kind();
|
|
if (syntaxKind - 8548 <= (SyntaxKind)5)
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
internal static TRoot? RemoveNodes<TRoot>(TRoot root, IEnumerable<SyntaxNode> nodes, SyntaxRemoveOptions options) where TRoot : SyntaxNode
|
|
{
|
|
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
|
|
if (nodes == null)
|
|
{
|
|
return root;
|
|
}
|
|
if (nodes.ToArray().Length == 0)
|
|
{
|
|
return root;
|
|
}
|
|
SyntaxRemover syntaxRemover = new SyntaxRemover(nodes.ToArray(), options);
|
|
SyntaxNode val = syntaxRemover.Visit((SyntaxNode?)(object)root);
|
|
SyntaxTriviaList residualTrivia = syntaxRemover.ResidualTrivia;
|
|
if (val != null && ((SyntaxTriviaList)(ref residualTrivia)).Count > 0)
|
|
{
|
|
val = SyntaxNodeExtensions.WithTrailingTrivia<SyntaxNode>(val, ((IEnumerable<SyntaxTrivia>)(object)val.GetTrailingTrivia()).Concat((IEnumerable<SyntaxTrivia>)(object)residualTrivia));
|
|
}
|
|
return (TRoot)(object)val;
|
|
}
|
|
}
|