Location
using System;
using System.Runtime.CompilerServices;
namespace CLanguage.Syntax
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public struct Location : IEquatable<Location>
{
public readonly Document Document;
public readonly int Index;
public readonly int Line;
public readonly int Column;
public static readonly Location Null;
public bool IsNull => Document == null;
public Location(Document document, int index, int line, int column)
{
Document = document;
Index = index;
Line = line;
Column = column;
}
public override string ToString()
{
if (IsNull)
return "?(?,?)";
return string.Format("{0}({1},{2})", new object[3] {
Document,
Line,
Column
});
}
public static Location operator +(Location location, int columnOffset)
{
return new Location(location.Document, location.Index + columnOffset, location.Line, location.Column + columnOffset);
}
public static bool operator ==(Location x, Location y)
{
if (x.Line == y.Line && x.Column == y.Column)
return x.Document?.Path == y.Document?.Path;
return false;
}
public static bool operator !=(Location x, Location y)
{
if (x.Line == y.Line && x.Column == y.Column)
return x.Document?.Path != y.Document?.Path;
return true;
}
public override bool Equals(object obj)
{
if (obj is Location)
return Equals((Location)obj);
return false;
}
public bool Equals(Location y)
{
if (Line == y.Line && Column == y.Column)
return Document.Path == y.Document.Path;
return false;
}
public override int GetHashCode()
{
int num = (1439312346 * -1521134295 + ((Document != null) ? Document.Path.GetHashCode() : 0)) * -1521134295;
int num2 = Line;
int num3 = (num + num2.GetHashCode()) * -1521134295;
num2 = Column;
return num3 + num2.GetHashCode();
}
}
}