251 lines
12 KiB
C#
251 lines
12 KiB
C#
using Microsoft.CodeAnalysis.Text;
|
|
using Roslyn.Utilities;
|
|
|
|
namespace Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
|
|
internal class CSharpLineDirectiveMap : LineDirectiveMap<DirectiveTriviaSyntax>
|
|
{
|
|
public CSharpLineDirectiveMap(SyntaxTree syntaxTree)
|
|
: base(syntaxTree)
|
|
{
|
|
}
|
|
|
|
protected override bool ShouldAddDirective(DirectiveTriviaSyntax directive)
|
|
{
|
|
bool flag = directive.IsActive;
|
|
if (flag)
|
|
{
|
|
SyntaxKind syntaxKind = directive.Kind();
|
|
bool flag2 = ((syntaxKind == SyntaxKind.LineDirectiveTrivia || syntaxKind == SyntaxKind.LineSpanDirectiveTrivia) ? true : false);
|
|
flag = flag2;
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
protected override LineMappingEntry<DirectiveTriviaSyntax> GetEntry(DirectiveTriviaSyntax directiveNode, SourceText sourceText, LineMappingEntry<DirectiveTriviaSyntax> previous)
|
|
{
|
|
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0036: Invalid comparison between Unknown and I4
|
|
//IL_0020: 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_0040: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_004c: 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_0053: Invalid comparison between Unknown and I4
|
|
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0061: 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_0103: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00d4: 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_00e6: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
|
|
int num = sourceText.Lines.IndexOf(((SyntaxNode)directiveNode).SpanStart) + 1;
|
|
if (directiveNode is LineSpanDirectiveTriviaSyntax spanDirective)
|
|
{
|
|
return GetLineSpanDirectiveEntry(spanDirective, num);
|
|
}
|
|
LineDirectiveTriviaSyntax lineDirectiveTriviaSyntax = (LineDirectiveTriviaSyntax)directiveNode;
|
|
int num2 = num;
|
|
int num3 = (((int)previous.State == 3) ? num2 : (previous.MappedLine + num - previous.UnmappedLine));
|
|
string text = (((int)previous.State == 3) ? null : previous.MappedPathOpt);
|
|
PositionState<DirectiveTriviaSyntax> val = (PositionState<DirectiveTriviaSyntax>)1;
|
|
SyntaxToken line = lineDirectiveTriviaSyntax.Line;
|
|
if (!((SyntaxToken)(ref line)).IsMissing)
|
|
{
|
|
switch (line.Kind())
|
|
{
|
|
case SyntaxKind.HiddenKeyword:
|
|
val = (PositionState<DirectiveTriviaSyntax>)6;
|
|
break;
|
|
case SyntaxKind.DefaultKeyword:
|
|
num3 = num2;
|
|
text = null;
|
|
val = (PositionState<DirectiveTriviaSyntax>)1;
|
|
break;
|
|
case SyntaxKind.NumericLiteralToken:
|
|
if (!((SyntaxToken)(ref line)).ContainsDiagnostics)
|
|
{
|
|
object value = ((SyntaxToken)(ref line)).Value;
|
|
if (value is int)
|
|
{
|
|
num3 = (int)value - 1;
|
|
}
|
|
if (lineDirectiveTriviaSyntax.File.Kind() == SyntaxKind.StringLiteralToken)
|
|
{
|
|
SyntaxToken file = lineDirectiveTriviaSyntax.File;
|
|
text = (string)((SyntaxToken)(ref file)).Value;
|
|
}
|
|
val = (PositionState<DirectiveTriviaSyntax>)2;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
return new LineMappingEntry<DirectiveTriviaSyntax>(num2, num3, text, val);
|
|
}
|
|
|
|
private static LineMappingEntry<DirectiveTriviaSyntax> GetLineSpanDirectiveEntry(LineSpanDirectiveTriviaSyntax spanDirective, int unmappedLine)
|
|
{
|
|
//IL_0062: 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_003c: 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_004f: 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_0051: 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)
|
|
if (!((SyntaxNode)spanDirective).HasErrors && tryGetPosition(spanDirective.Start, isEnd: false, out var position) && tryGetPosition(spanDirective.End, isEnd: true, out var position2) && tryGetOptionalCharacterOffset(spanDirective.CharacterOffset, out var value) && tryGetStringLiteralValue(spanDirective.File, out var value2))
|
|
{
|
|
return new LineMappingEntry<DirectiveTriviaSyntax>(unmappedLine, new LinePositionSpan(position, position2), value, value2);
|
|
}
|
|
return new LineMappingEntry<DirectiveTriviaSyntax>(unmappedLine, unmappedLine, (string)null, (PositionState<DirectiveTriviaSyntax>)1);
|
|
static bool tryGetOneBasedNumericLiteralValue(in SyntaxToken token, out int reference)
|
|
{
|
|
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
|
|
if (!((SyntaxToken)(ref token)).IsMissing && token.Kind() == SyntaxKind.NumericLiteralToken && ((SyntaxToken)(ref token)).Value is int num)
|
|
{
|
|
reference = num - 1;
|
|
return true;
|
|
}
|
|
reference = 0;
|
|
return false;
|
|
}
|
|
static bool tryGetOptionalCharacterOffset(in SyntaxToken token, out int? reference)
|
|
{
|
|
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
|
|
if (!((SyntaxToken)(ref token)).IsMissing)
|
|
{
|
|
if (token.Kind() == SyntaxKind.None)
|
|
{
|
|
reference = null;
|
|
return true;
|
|
}
|
|
int value3 = 0;
|
|
if (tryGetOneBasedNumericLiteralValue(in token, out value3))
|
|
{
|
|
reference = value3;
|
|
return true;
|
|
}
|
|
}
|
|
reference = null;
|
|
return false;
|
|
}
|
|
static bool tryGetPosition(LineDirectivePositionSyntax syntax, bool isEnd, out LinePosition reference)
|
|
{
|
|
//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_003c: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
|
|
if (tryGetOneBasedNumericLiteralValue(syntax.Line, out var value3) && tryGetOneBasedNumericLiteralValue(syntax.Character, out var value4))
|
|
{
|
|
reference = new LinePosition(value3, isEnd ? (value4 + 1) : value4);
|
|
return true;
|
|
}
|
|
reference = default(LinePosition);
|
|
return false;
|
|
}
|
|
static bool tryGetStringLiteralValue(in SyntaxToken token, out string? reference)
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
if (token.Kind() == SyntaxKind.StringLiteralToken)
|
|
{
|
|
reference = (string)((SyntaxToken)(ref token)).Value;
|
|
return true;
|
|
}
|
|
reference = null;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
protected override LineMappingEntry<DirectiveTriviaSyntax> InitializeFirstEntry()
|
|
{
|
|
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
|
|
return new LineMappingEntry<DirectiveTriviaSyntax>(0, 0, (string)null, (PositionState<DirectiveTriviaSyntax>)1);
|
|
}
|
|
|
|
public override LineVisibility GetLineVisibility(SourceText sourceText, int position)
|
|
{
|
|
//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_0032: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0037: 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_0039: 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_003f: 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_005f: Expected I4, but got Unknown
|
|
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
|
|
LinePosition linePosition = sourceText.Lines.GetLinePosition(position);
|
|
if (base.Entries.Length == 1)
|
|
{
|
|
return (LineVisibility)2;
|
|
}
|
|
int num = base.FindEntryIndex(((LinePosition)(ref linePosition)).Line);
|
|
LineMappingEntry<DirectiveTriviaSyntax> val = base.Entries[num];
|
|
PositionState<DirectiveTriviaSyntax> state = val.State;
|
|
switch (state - 1)
|
|
{
|
|
case 0:
|
|
if (num != 0)
|
|
{
|
|
return (LineVisibility)2;
|
|
}
|
|
return (LineVisibility)0;
|
|
case 1:
|
|
case 2:
|
|
return (LineVisibility)2;
|
|
case 5:
|
|
return (LineVisibility)1;
|
|
default:
|
|
throw ExceptionUtilities.UnexpectedValue((object)val.State);
|
|
}
|
|
}
|
|
|
|
protected override LineVisibility GetUnknownStateVisibility(int index)
|
|
{
|
|
throw ExceptionUtilities.Unreachable("/_/src/Compilers/CSharp/Portable/Syntax/CSharpLineDirectiveMap.cs", 220);
|
|
}
|
|
|
|
internal override FileLinePositionSpan TranslateSpanAndVisibility(SourceText sourceText, string treeFilePath, TextSpan span, out bool isHiddenPosition)
|
|
{
|
|
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0013: 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_0020: 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_004c: 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_0053: Invalid comparison between Unknown and I4
|
|
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0035: 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)
|
|
TextLineCollection lines = sourceText.Lines;
|
|
LinePosition linePosition = lines.GetLinePosition(((TextSpan)(ref span)).Start);
|
|
LinePosition linePosition2 = lines.GetLinePosition(((TextSpan)(ref span)).End);
|
|
if (base.Entries.Length == 1)
|
|
{
|
|
isHiddenPosition = false;
|
|
return new FileLinePositionSpan(treeFilePath, linePosition, linePosition2);
|
|
}
|
|
LineMappingEntry<DirectiveTriviaSyntax> val = base.FindEntry(((LinePosition)(ref linePosition)).Line);
|
|
isHiddenPosition = (int)val.State == 6;
|
|
return base.TranslateSpan(ref val, treeFilePath, linePosition, linePosition2);
|
|
}
|
|
}
|