|
1 | 1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | | -// See the LICENSE file in the project root for more information. |
4 | 3 |
|
5 | 4 | using System; |
6 | 5 | using System.Linq; |
|
10 | 9 |
|
11 | 10 | namespace Mono.Linker |
12 | 11 | { |
13 | | - public readonly struct MessageOrigin : IComparable<MessageOrigin>, IEquatable<MessageOrigin> |
14 | | - { |
| 12 | + public readonly struct MessageOrigin : IComparable<MessageOrigin>, IEquatable<MessageOrigin> |
| 13 | + { |
15 | 14 | #nullable enable |
16 | | - public string? FileName { get; } |
17 | | - public IMemberDefinition? MemberDefinition { get; } |
| 15 | + public string? FileName { get; } |
| 16 | + public IMemberDefinition? MemberDefinition { get; } |
18 | 17 | #nullable disable |
19 | | - public int SourceLine { get; } |
20 | | - public int SourceColumn { get; } |
21 | | - public int? ILOffset { get; } |
| 18 | + public int SourceLine { get; } |
| 19 | + public int SourceColumn { get; } |
| 20 | + public int? ILOffset { get; } |
22 | 21 |
|
23 | | - public MessageOrigin (string fileName, int sourceLine = 0, int sourceColumn = 0) |
24 | | - { |
25 | | - FileName = fileName; |
26 | | - SourceLine = sourceLine; |
27 | | - SourceColumn = sourceColumn; |
28 | | - MemberDefinition = null; |
29 | | - ILOffset = null; |
30 | | - } |
| 22 | + public MessageOrigin(string fileName, int sourceLine = 0, int sourceColumn = 0) |
| 23 | + { |
| 24 | + FileName = fileName; |
| 25 | + SourceLine = sourceLine; |
| 26 | + SourceColumn = sourceColumn; |
| 27 | + MemberDefinition = null; |
| 28 | + ILOffset = null; |
| 29 | + } |
31 | 30 |
|
32 | | - public MessageOrigin (IMemberDefinition memberDefinition, int? ilOffset = null) |
33 | | - { |
34 | | - FileName = null; |
35 | | - MemberDefinition = memberDefinition; |
36 | | - SourceLine = 0; |
37 | | - SourceColumn = 0; |
38 | | - ILOffset = ilOffset; |
39 | | - } |
| 31 | + public MessageOrigin(IMemberDefinition memberDefinition, int? ilOffset = null) |
| 32 | + { |
| 33 | + FileName = null; |
| 34 | + MemberDefinition = memberDefinition; |
| 35 | + SourceLine = 0; |
| 36 | + SourceColumn = 0; |
| 37 | + ILOffset = ilOffset; |
| 38 | + } |
40 | 39 |
|
41 | | - public override string ToString () |
42 | | - { |
43 | | - int sourceLine = SourceLine, sourceColumn = SourceColumn; |
44 | | - string fileName = FileName; |
45 | | - if (MemberDefinition is MethodDefinition method && |
46 | | - method.DebugInformation.HasSequencePoints) { |
47 | | - var offset = ILOffset ?? 0; |
48 | | - SequencePoint correspondingSequencePoint = method.DebugInformation.SequencePoints |
49 | | - .Where (s => s.Offset <= offset)?.Last (); |
50 | | - if (correspondingSequencePoint != null) { |
51 | | - fileName = correspondingSequencePoint.Document.Url; |
52 | | - sourceLine = correspondingSequencePoint.StartLine; |
53 | | - sourceColumn = correspondingSequencePoint.StartColumn; |
54 | | - } |
55 | | - } |
| 40 | + public override string ToString() |
| 41 | + { |
| 42 | + int sourceLine = SourceLine, sourceColumn = SourceColumn; |
| 43 | + string fileName = FileName; |
| 44 | + if (MemberDefinition is MethodDefinition method && |
| 45 | + method.DebugInformation.HasSequencePoints) |
| 46 | + { |
| 47 | + var offset = ILOffset ?? 0; |
| 48 | + SequencePoint correspondingSequencePoint = method.DebugInformation.SequencePoints |
| 49 | + .Where(s => s.Offset <= offset)?.Last(); |
| 50 | + if (correspondingSequencePoint != null) |
| 51 | + { |
| 52 | + fileName = correspondingSequencePoint.Document.Url; |
| 53 | + sourceLine = correspondingSequencePoint.StartLine; |
| 54 | + sourceColumn = correspondingSequencePoint.StartColumn; |
| 55 | + } |
| 56 | + } |
56 | 57 |
|
57 | | - if (fileName == null) |
58 | | - return null; |
| 58 | + if (fileName == null) |
| 59 | + return null; |
59 | 60 |
|
60 | | - StringBuilder sb = new StringBuilder (fileName); |
61 | | - if (sourceLine != 0) { |
62 | | - sb.Append ("(").Append (sourceLine); |
63 | | - if (sourceColumn != 0) |
64 | | - sb.Append (",").Append (sourceColumn); |
| 61 | + StringBuilder sb = new StringBuilder(fileName); |
| 62 | + if (sourceLine != 0) |
| 63 | + { |
| 64 | + sb.Append("(").Append(sourceLine); |
| 65 | + if (sourceColumn != 0) |
| 66 | + sb.Append(",").Append(sourceColumn); |
65 | 67 |
|
66 | | - sb.Append (")"); |
67 | | - } |
| 68 | + sb.Append(")"); |
| 69 | + } |
68 | 70 |
|
69 | | - return sb.ToString (); |
70 | | - } |
| 71 | + return sb.ToString(); |
| 72 | + } |
71 | 73 |
|
72 | | - public bool Equals (MessageOrigin other) => |
73 | | - (FileName, MemberDefinition, SourceLine, SourceColumn) == (other.FileName, other.MemberDefinition, other.SourceLine, other.SourceColumn); |
| 74 | + public bool Equals(MessageOrigin other) => |
| 75 | + (FileName, MemberDefinition, SourceLine, SourceColumn) == (other.FileName, other.MemberDefinition, other.SourceLine, other.SourceColumn); |
74 | 76 |
|
75 | | - public override bool Equals (object obj) => obj is MessageOrigin messageOrigin && Equals (messageOrigin); |
76 | | - public override int GetHashCode () => (FileName, MemberDefinition, SourceLine, SourceColumn).GetHashCode (); |
77 | | - public static bool operator == (MessageOrigin lhs, MessageOrigin rhs) => lhs.Equals (rhs); |
78 | | - public static bool operator != (MessageOrigin lhs, MessageOrigin rhs) => !lhs.Equals (rhs); |
| 77 | + public override bool Equals(object obj) => obj is MessageOrigin messageOrigin && Equals(messageOrigin); |
| 78 | + public override int GetHashCode() => (FileName, MemberDefinition, SourceLine, SourceColumn).GetHashCode(); |
| 79 | + public static bool operator ==(MessageOrigin lhs, MessageOrigin rhs) => lhs.Equals(rhs); |
| 80 | + public static bool operator !=(MessageOrigin lhs, MessageOrigin rhs) => !lhs.Equals(rhs); |
79 | 81 |
|
80 | | - public int CompareTo (MessageOrigin other) |
81 | | - { |
82 | | - if (MemberDefinition != null && other.MemberDefinition != null) { |
83 | | - return (MemberDefinition.DeclaringType?.Module?.Assembly?.Name?.Name, MemberDefinition.DeclaringType?.Name, MemberDefinition?.Name).CompareTo |
84 | | - ((other.MemberDefinition.DeclaringType?.Module?.Assembly?.Name?.Name, other.MemberDefinition.DeclaringType?.Name, other.MemberDefinition?.Name)); |
85 | | - } else if (MemberDefinition == null && other.MemberDefinition == null) { |
86 | | - if (FileName != null && other.FileName != null) { |
87 | | - return string.Compare (FileName, other.FileName); |
88 | | - } else if (FileName == null && other.FileName == null) { |
89 | | - return (SourceLine, SourceColumn).CompareTo ((other.SourceLine, other.SourceColumn)); |
90 | | - } |
| 82 | + public int CompareTo(MessageOrigin other) |
| 83 | + { |
| 84 | + if (MemberDefinition != null && other.MemberDefinition != null) |
| 85 | + { |
| 86 | + return (MemberDefinition.DeclaringType?.Module?.Assembly?.Name?.Name, MemberDefinition.DeclaringType?.Name, MemberDefinition?.Name).CompareTo |
| 87 | + ((other.MemberDefinition.DeclaringType?.Module?.Assembly?.Name?.Name, other.MemberDefinition.DeclaringType?.Name, other.MemberDefinition?.Name)); |
| 88 | + } |
| 89 | + else if (MemberDefinition == null && other.MemberDefinition == null) |
| 90 | + { |
| 91 | + if (FileName != null && other.FileName != null) |
| 92 | + { |
| 93 | + return string.Compare(FileName, other.FileName); |
| 94 | + } |
| 95 | + else if (FileName == null && other.FileName == null) |
| 96 | + { |
| 97 | + return (SourceLine, SourceColumn).CompareTo((other.SourceLine, other.SourceColumn)); |
| 98 | + } |
91 | 99 |
|
92 | | - return (FileName == null) ? 1 : -1; |
93 | | - } |
| 100 | + return (FileName == null) ? 1 : -1; |
| 101 | + } |
94 | 102 |
|
95 | | - return (MemberDefinition == null) ? 1 : -1; |
96 | | - } |
97 | | - } |
| 103 | + return (MemberDefinition == null) ? 1 : -1; |
| 104 | + } |
| 105 | + } |
98 | 106 | } |
0 commit comments