22// The .NET Foundation licenses this file to you under the MIT license. 
33
44using  System ; 
5+ using  System . Diagnostics ; 
56using  System . Linq ; 
67using  System . Text ; 
78using  Mono . Cecil ; 
@@ -13,19 +14,28 @@ namespace Mono.Linker
1314	{ 
1415#nullable enable
1516		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+ 		} 
2025#nullable disable
2126		public  int  SourceLine  {  get ;  } 
2227		public  int  SourceColumn  {  get ;  } 
2328		public  int ?  ILOffset  {  get ;  } 
2429
2530		const  int  HiddenLineNumber  =  0xfeefee ; 
2631
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 ) 
2939		{ 
3040		} 
3141
@@ -34,31 +44,43 @@ public MessageOrigin (string fileName, int sourceLine = 0, int sourceColumn = 0)
3444			FileName  =  fileName ; 
3545			SourceLine  =  sourceLine ; 
3646			SourceColumn  =  sourceColumn ; 
37- 			MemberDefinition  =  null ; 
47+ 			Provider  =  null ; 
3848			_suppressionContextMember  =  null ; 
3949			ILOffset  =  null ; 
4050		} 
4151
42- 		public  MessageOrigin  ( IMemberDefinition   memberDefinition ,  int ?  ilOffset ) 
43- 			:  this  ( memberDefinition ,  ilOffset ,  null ) 
52+ 		public  MessageOrigin  ( ICustomAttributeProvider   provider ,  int ?  ilOffset ) 
53+ 			:  this  ( provider ,  ilOffset ,  null ) 
4454		{ 
4555		} 
4656
47- 		public  MessageOrigin  ( IMemberDefinition   memberDefinition ,  int ?  ilOffset ,  IMemberDefinition  suppressionContextMember ) 
57+ 		public  MessageOrigin  ( ICustomAttributeProvider   provider ,  int ?  ilOffset ,  ICustomAttributeProvider  suppressionContextMember ) 
4858		{ 
59+ 			Debug . Assert  ( provider  ==  null  ||  provider  is  IMemberDefinition  ||  provider  is  AssemblyDefinition ) ; 
60+ 			Debug . Assert  ( suppressionContextMember  ==  null  ||  suppressionContextMember  is  IMemberDefinition  ||  provider  is  AssemblyDefinition ) ; 
4961			FileName  =  null ; 
50- 			MemberDefinition  =  memberDefinition ; 
62+ 			Provider  =  provider ; 
5163			_suppressionContextMember  =  suppressionContextMember ; 
5264			SourceLine  =  0 ; 
5365			SourceColumn  =  0 ; 
5466			ILOffset  =  ilOffset ; 
5567		} 
5668
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+ 
5779		public  override  string  ToString  ( ) 
5880		{ 
5981			int  sourceLine  =  SourceLine ,  sourceColumn  =  SourceColumn ; 
6082			string  fileName  =  FileName ; 
61- 			if  ( MemberDefinition  is  MethodDefinition  method  && 
83+ 			if  ( Provider  is  MethodDefinition  method  && 
6284				method . DebugInformation . HasSequencePoints )  { 
6385				var  offset  =  ILOffset  ??  0 ; 
6486				SequencePoint  correspondingSequencePoint  =  method . DebugInformation . SequencePoints 
@@ -94,28 +116,32 @@ public override string ToString ()
94116		} 
95117
96118		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 ) ; 
98120
99121		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  ( ) ; 
101123		public  static bool  operator  ==  ( MessageOrigin  lhs ,  MessageOrigin  rhs )  =>  lhs . Equals  ( rhs ) ; 
102124		public  static bool  operator  !=  ( MessageOrigin  lhs ,  MessageOrigin  rhs )  =>  ! lhs . Equals  ( rhs ) ; 
103125
104126		public  int  CompareTo  ( MessageOrigin  other ) 
105127		{ 
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 ) ) ; 
111137				if  ( result  !=  0 ) 
112138					return  result ; 
113139
114140				if  ( ILOffset  !=  null  &&  other . ILOffset  !=  null ) 
115141					return  ILOffset . Value . CompareTo  ( other . ILOffset ) ; 
116142
117143				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 )  { 
119145				if  ( FileName  !=  null  &&  other . FileName  !=  null )  { 
120146					return  string . Compare  ( FileName ,  other . FileName ) ; 
121147				}  else  if  ( FileName  ==  null  &&  other . FileName  ==  null )  { 
@@ -125,7 +151,7 @@ public int CompareTo (MessageOrigin other)
125151				return  ( FileName  ==  null )  ?  1  :  - 1 ; 
126152			} 
127153
128- 			return  ( MemberDefinition  ==  null )  ?  1  :  - 1 ; 
154+ 			return  ( Provider  ==  null )  ?  1  :  - 1 ; 
129155		} 
130156	} 
131157} 
0 commit comments