2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
4
using System ;
5
+ using System . Diagnostics ;
5
6
using System . Linq ;
6
7
using System . Text ;
7
8
using Mono . Cecil ;
@@ -13,19 +14,28 @@ namespace Mono.Linker
13
14
{
14
15
#nullable enable
15
16
public string ? FileName { get ; }
16
- public IMemberDefinition ? MemberDefinition { get ; }
17
-
18
- readonly IMemberDefinition _suppressionContextMember ;
19
- public IMemberDefinition ? SuppressionContextMember { get => _suppressionContextMember ?? MemberDefinition ; }
17
+ public ICustomAttributeProvider ? Provider { get ; }
18
+ readonly ICustomAttributeProvider _suppressionContextMember ;
19
+ public ICustomAttributeProvider ? SuppressionContextMember {
20
+ get {
21
+ Debug . Assert ( _suppressionContextMember == null || _suppressionContextMember is IMemberDefinition || _suppressionContextMember is AssemblyDefinition ) ;
22
+ return _suppressionContextMember ?? Provider ;
23
+ }
24
+ }
20
25
#nullable disable
21
26
public int SourceLine { get ; }
22
27
public int SourceColumn { get ; }
23
28
public int ? ILOffset { get ; }
24
29
25
30
const int HiddenLineNumber = 0xfeefee ;
26
31
27
- public MessageOrigin ( IMemberDefinition memberDefinition )
28
- : this ( memberDefinition , null )
32
+ public MessageOrigin ( IMemberDefinition memberDefinition , int ? ilOffset = null )
33
+ : this ( memberDefinition as ICustomAttributeProvider , ilOffset )
34
+ {
35
+ }
36
+
37
+ public MessageOrigin ( ICustomAttributeProvider provider )
38
+ : this ( provider , null )
29
39
{
30
40
}
31
41
@@ -34,31 +44,43 @@ public MessageOrigin (string fileName, int sourceLine = 0, int sourceColumn = 0)
34
44
FileName = fileName ;
35
45
SourceLine = sourceLine ;
36
46
SourceColumn = sourceColumn ;
37
- MemberDefinition = null ;
47
+ Provider = null ;
38
48
_suppressionContextMember = null ;
39
49
ILOffset = null ;
40
50
}
41
51
42
- public MessageOrigin ( IMemberDefinition memberDefinition , int ? ilOffset )
43
- : this ( memberDefinition , ilOffset , null )
52
+ public MessageOrigin ( ICustomAttributeProvider provider , int ? ilOffset )
53
+ : this ( provider , ilOffset , null )
44
54
{
45
55
}
46
56
47
- public MessageOrigin ( IMemberDefinition memberDefinition , int ? ilOffset , IMemberDefinition suppressionContextMember )
57
+ public MessageOrigin ( ICustomAttributeProvider provider , int ? ilOffset , ICustomAttributeProvider suppressionContextMember )
48
58
{
59
+ Debug . Assert ( provider == null || provider is IMemberDefinition || provider is AssemblyDefinition ) ;
60
+ Debug . Assert ( suppressionContextMember == null || suppressionContextMember is IMemberDefinition || provider is AssemblyDefinition ) ;
49
61
FileName = null ;
50
- MemberDefinition = memberDefinition ;
62
+ Provider = provider ;
51
63
_suppressionContextMember = suppressionContextMember ;
52
64
SourceLine = 0 ;
53
65
SourceColumn = 0 ;
54
66
ILOffset = ilOffset ;
55
67
}
56
68
69
+ public MessageOrigin ( MessageOrigin other , IMemberDefinition suppressionContextMember )
70
+ {
71
+ FileName = other . FileName ;
72
+ Provider = other . Provider ;
73
+ _suppressionContextMember = suppressionContextMember ;
74
+ SourceLine = other . SourceLine ;
75
+ SourceColumn = other . SourceColumn ;
76
+ ILOffset = other . ILOffset ;
77
+ }
78
+
57
79
public override string ToString ( )
58
80
{
59
81
int sourceLine = SourceLine , sourceColumn = SourceColumn ;
60
82
string fileName = FileName ;
61
- if ( MemberDefinition is MethodDefinition method &&
83
+ if ( Provider is MethodDefinition method &&
62
84
method . DebugInformation . HasSequencePoints ) {
63
85
var offset = ILOffset ?? 0 ;
64
86
SequencePoint correspondingSequencePoint = method . DebugInformation . SequencePoints
@@ -94,28 +116,32 @@ public override string ToString ()
94
116
}
95
117
96
118
public bool Equals ( MessageOrigin other ) =>
97
- ( FileName , MemberDefinition , SourceLine , SourceColumn , ILOffset ) == ( other . FileName , other . MemberDefinition , other . SourceLine , other . SourceColumn , other . ILOffset ) ;
119
+ ( FileName , Provider , SourceLine , SourceColumn , ILOffset ) == ( other . FileName , other . Provider , other . SourceLine , other . SourceColumn , other . ILOffset ) ;
98
120
99
121
public override bool Equals ( object obj ) => obj is MessageOrigin messageOrigin && Equals ( messageOrigin ) ;
100
- public override int GetHashCode ( ) => ( FileName , MemberDefinition , SourceLine , SourceColumn ) . GetHashCode ( ) ;
122
+ public override int GetHashCode ( ) => ( FileName , Provider , SourceLine , SourceColumn ) . GetHashCode ( ) ;
101
123
public static bool operator == ( MessageOrigin lhs , MessageOrigin rhs ) => lhs . Equals ( rhs ) ;
102
124
public static bool operator != ( MessageOrigin lhs , MessageOrigin rhs ) => ! lhs . Equals ( rhs ) ;
103
125
104
126
public int CompareTo ( MessageOrigin other )
105
127
{
106
- if ( MemberDefinition != null && other . MemberDefinition != null ) {
107
- TypeDefinition thisTypeDef = ( MemberDefinition as TypeDefinition ) ?? MemberDefinition . DeclaringType ;
108
- TypeDefinition otherTypeDef = ( other . MemberDefinition as TypeDefinition ) ?? other . MemberDefinition . DeclaringType ;
109
- int result = ( thisTypeDef ? . Module ? . Assembly ? . Name ? . Name , thisTypeDef ? . Name , MemberDefinition ? . Name ) . CompareTo
110
- ( ( otherTypeDef ? . Module ? . Assembly ? . Name ? . Name , otherTypeDef ? . Name , other . MemberDefinition ? . Name ) ) ;
128
+ if ( Provider != null && other . Provider != null ) {
129
+ var thisMember = Provider as IMemberDefinition ;
130
+ var otherMember = other . Provider as IMemberDefinition ;
131
+ TypeDefinition thisTypeDef = ( Provider as TypeDefinition ) ?? ( Provider as IMemberDefinition ) ? . DeclaringType ;
132
+ TypeDefinition otherTypeDef = ( other . Provider as TypeDefinition ) ?? ( other . Provider as IMemberDefinition ) ? . DeclaringType ;
133
+ var thisAssembly = thisTypeDef ? . Module . Assembly ?? Provider as AssemblyDefinition ;
134
+ var otherAssembly = otherTypeDef ? . Module . Assembly ?? other . Provider as AssemblyDefinition ;
135
+ int result = ( thisAssembly . Name . Name , thisTypeDef ? . Name , thisMember ? . Name ) . CompareTo
136
+ ( ( otherAssembly . Name . Name , otherTypeDef ? . Name , otherMember ? . Name ) ) ;
111
137
if ( result != 0 )
112
138
return result ;
113
139
114
140
if ( ILOffset != null && other . ILOffset != null )
115
141
return ILOffset . Value . CompareTo ( other . ILOffset ) ;
116
142
117
143
return ILOffset == null ? ( other . ILOffset == null ? 0 : 1 ) : - 1 ;
118
- } else if ( MemberDefinition == null && other . MemberDefinition == null ) {
144
+ } else if ( Provider == null && other . Provider == null ) {
119
145
if ( FileName != null && other . FileName != null ) {
120
146
return string . Compare ( FileName , other . FileName ) ;
121
147
} else if ( FileName == null && other . FileName == null ) {
@@ -125,7 +151,7 @@ public int CompareTo (MessageOrigin other)
125
151
return ( FileName == null ) ? 1 : - 1 ;
126
152
}
127
153
128
- return ( MemberDefinition == null ) ? 1 : - 1 ;
154
+ return ( Provider == null ) ? 1 : - 1 ;
129
155
}
130
156
}
131
157
}
0 commit comments