@@ -36,9 +36,9 @@ public override ILPostProcessResult Process(ICompiledAssembly compiledAssembly)
3636
3737 try
3838 {
39- ILPostProcessorUtils . InitLog < ConstExpressionILPostProcessor > ( compiledAssembly ) ;
39+ ILPPUtils . InitLog < ConstExpressionILPostProcessor > ( compiledAssembly ) ;
4040 _constExprTable = FindConstExprMethods ( ) ;
41- using ( var assembly = ILPostProcessorUtils . LoadAssemblyDefinition ( compiledAssembly ) )
41+ using ( var assembly = ILPPUtils . LoadAssemblyDefinition ( compiledAssembly ) )
4242 {
4343 var mainModule = assembly . MainModule ;
4444 _allowedStaticExpressionTypes . Add ( mainModule . ImportReference ( typeof ( Type ) ) ) ;
@@ -87,7 +87,7 @@ public override ILPostProcessResult Process(ICompiledAssembly compiledAssembly)
8787 continue ;
8888 }
8989
90- ILPostProcessorUtils . ResolveInstructionOpCode ( body . Instructions ) ;
90+ ILPPUtils . ResolveInstructionOpCode ( body . Instructions ) ;
9191 }
9292 }
9393 }
@@ -102,40 +102,40 @@ public override ILPostProcessResult Process(ICompiledAssembly compiledAssembly)
102102 } ;
103103
104104 assembly . Write ( pe , writeParameter ) ;
105- return new ILPostProcessResult ( new InMemoryAssembly ( pe . ToArray ( ) , pdb . ToArray ( ) ) , ILPostProcessorUtils . Logger . Messages ) ;
105+ return new ILPostProcessResult ( new InMemoryAssembly ( pe . ToArray ( ) , pdb . ToArray ( ) ) , ILPPUtils . Logger . Messages ) ;
106106 }
107107 }
108108 catch ( Exception e )
109109 {
110- ILPostProcessorUtils . LogException ( e ) ;
110+ ILPPUtils . LogException ( e ) ;
111111 }
112- return new ILPostProcessResult ( null , ILPostProcessorUtils . Logger . Messages ) ;
112+ return new ILPostProcessResult ( null , ILPPUtils . Logger . Messages ) ;
113113 }
114114
115115 private Dictionary < string , Delegate > FindConstExprMethods ( )
116116 {
117117 var result = new Dictionary < string , Delegate > ( ) ;
118- foreach ( var method in ILPostProcessorUtils . FindMethods < ConstExpressionAttribute > ( typeof ( ConstExpressionEntry ) . Assembly ) )
118+ foreach ( var method in ILPPUtils . FindMethods < ConstExpressionAttribute > ( typeof ( ConstExpressionEntry ) . Assembly ) )
119119 {
120120 if ( ! CheckConstExpressionError ( method ) )
121121 {
122122 continue ;
123123 }
124124
125- var delType = ILPostProcessorUtils . GetDelegateType ( method . GetParameters ( ) . Select ( v => v . ParameterType ) , method . ReturnType ) ;
125+ var delType = ILPPUtils . GetDelegateType ( method . GetParameters ( ) . Select ( v => v . ParameterType ) , method . ReturnType ) ;
126126 var del = Delegate . CreateDelegate ( delType , method ) ;
127127 var args = string . Empty ;
128128 foreach ( var parameter in method . GetParameters ( ) )
129129 {
130- args = $ "{ args } { ILPostProcessorUtils . GetTypeName ( parameter . ParameterType ) } ,";
130+ args = $ "{ args } { ILPPUtils . GetTypeName ( parameter . ParameterType ) } ,";
131131 }
132132
133133 if ( ! string . IsNullOrEmpty ( args ) )
134134 {
135135 args = args . Remove ( args . Length - 1 , 1 ) ;
136136 }
137- string returnName = ILPostProcessorUtils . GetTypeName ( method . ReturnType ) ;
138- result . Add ( $ "{ returnName } { ILPostProcessorUtils . GetTypeName ( method . ReflectedType ) } ::{ method . Name } ({ args } )", del ) ;
137+ string returnName = ILPPUtils . GetTypeName ( method . ReturnType ) ;
138+ result . Add ( $ "{ returnName } { ILPPUtils . GetTypeName ( method . ReflectedType ) } ::{ method . Name } ({ args } )", del ) ;
139139 }
140140
141141 return result ;
@@ -161,7 +161,7 @@ private bool ConstExpressionProcess(ILProcessor ilProcessor, MethodDefinition me
161161 {
162162 if ( constExpr . Method . GetCustomAttribute < ConstExpressionAttribute > ( ) . CalculationFailedWarning )
163163 {
164- ILPostProcessorUtils . LogWarning ( $ "ConstExpression calculation failed .", method , argInstruction ) ;
164+ ILPPUtils . LogWarning ( "CONSTEXPR0501" , "ConstExpression warning." , $ "ConstExpression accepts only constants as arguments .", method , instruction ) ;
165165 }
166166 return false ;
167167 }
@@ -183,7 +183,7 @@ private bool ConstExpressionProcess(ILProcessor ilProcessor, MethodDefinition me
183183 e = t . InnerException ;
184184 }
185185
186- ILPostProcessorUtils . LogException ( e ) ;
186+ ILPPUtils . LogException ( e ) ;
187187 return false ;
188188 }
189189
@@ -200,21 +200,21 @@ loadLiteral.Operand is FieldReference field &&
200200 while ( argInstruction != instruction )
201201 {
202202 -- instructionDiff ;
203- ILPostProcessorUtils . ReplaceTarget ( ilProcessor , argInstruction , loadLiteral ) ;
203+ ILPPUtils . ReplaceTarget ( ilProcessor , argInstruction , loadLiteral ) ;
204204 argInstruction = argInstruction . Next ;
205205 ilProcessor . Remove ( argInstruction . Previous ) ;
206206 }
207207
208208 -- instructionDiff ;
209- ILPostProcessorUtils . ReplaceTarget ( ilProcessor , instruction , loadLiteral ) ;
209+ ILPPUtils . ReplaceTarget ( ilProcessor , instruction , loadLiteral ) ;
210210 ilProcessor . Remove ( instruction ) ;
211211
212212 return true ;
213213 }
214214
215215 private bool TryGetConstValue ( ref Instruction instruction , Type type , out object result )
216216 {
217- if ( ILPostProcessorUtils . TryGetConstValue ( ref instruction , type , out result ) )
217+ if ( ILPPUtils . TryGetConstValue ( ref instruction , type , out result ) )
218218 {
219219 return true ;
220220 }
@@ -227,6 +227,7 @@ private bool TryGetConstValue(ref Instruction instruction, Type type, out object
227227 return ret ;
228228 }
229229
230+ /*
230231 if (instruction.OpCode == OpCodes.Ldloc_0)
231232 {
232233 var ret = TryGetConstValue(instruction, type, OpCodes.Stloc_0, instruction.Operand, out result);
@@ -262,6 +263,7 @@ private bool TryGetConstValue(ref Instruction instruction, Type type, out object
262263 var ret = TryGetConstValue(instruction, type, OpCodes.Stloc, instruction.Operand, out result);
263264 return ret;
264265 }
266+ */
265267
266268 result = null ;
267269 return false ;
@@ -288,20 +290,20 @@ private bool CheckConstExpressionError(MethodInfo method)
288290 {
289291 if ( ! method . IsStatic )
290292 {
291- ILPostProcessorUtils . LogError ( $ "ConstExpression is static method only.", method ) ;
293+ ILPPUtils . LogError ( "CONSTEXPR0001" , "ConstExpression failed." , $ "ConstExpression is static method only.", method ) ;
292294 return false ;
293295 }
294296
295297 if ( method . IsGenericMethod ||
296298 method . ReflectedType . IsGenericType )
297299 {
298- ILPostProcessorUtils . LogError ( $ "ConstExpression does not support generic argument.", method ) ;
300+ ILPPUtils . LogError ( "CONSTEXPR0002" , "ConstExpression failed." , $ "ConstExpression does not support generic argument.", method ) ;
299301 return false ;
300302 }
301303
302304 if ( ! IsAllowConstExpressionType ( method . ReturnType ) )
303305 {
304- ILPostProcessorUtils . LogError ( $ "ConstExpression does not support return of type \" { method . ReturnType . FullName } \" .", method ) ;
306+ ILPPUtils . LogError ( "CONSTEXPR0003" , "ConstExpression failed." , $ "ConstExpression does not support return of type \" { method . ReturnType . FullName } \" .", method ) ;
305307 return false ;
306308 }
307309
@@ -312,7 +314,7 @@ private bool CheckConstExpressionError(MethodInfo method)
312314 continue ;
313315 }
314316
315- ILPostProcessorUtils . LogError ( $ "ConstExpression does not support parameters of type \" { parameter . ParameterType . FullName } \" .", method ) ;
317+ ILPPUtils . LogError ( "CONSTEXPR0004" , "ConstExpression failed." , $ "ConstExpression does not support parameters of type \" { parameter . ParameterType . FullName } \" .", method ) ;
316318 return false ;
317319 }
318320
@@ -332,7 +334,7 @@ private static bool IsAllowConstExpressionType(Type type)
332334
333335 var result = type == typeof ( string ) ||
334336 type . IsEnum ||
335- ILPostProcessorUtils . IsStructRecursive ( type ) ;
337+ ILPPUtils . IsStructRecursive ( type ) ;
336338 return result ;
337339 }
338340
@@ -359,7 +361,7 @@ private bool StaticExpressionProcess(ILProcessor ilProcessor, MethodDefinition m
359361 {
360362 if ( calculationFailedWarning )
361363 {
362- ILPostProcessorUtils . LogWarning ( $ "StaticExpression calculation failed .", method , instruction ) ;
364+ ILPPUtils . LogWarning ( "CONSTEXPR1502" , "ConstExpression warning." , $ "StaticExpression cannot use GenericParameter as a type arguments .", method , instruction ) ;
363365 }
364366 return false ;
365367 }
@@ -372,11 +374,11 @@ private bool StaticExpressionProcess(ILProcessor ilProcessor, MethodDefinition m
372374 for ( int i = 0 ; i < parameters . Count ; ++ i )
373375 {
374376 argInstruction = argInstruction . Previous ;
375- if ( ! ILPostProcessorUtils . TryGetConstInstructions ( ref argInstruction , argInstructions ) )
377+ if ( ! ILPPUtils . TryGetConstInstructions ( ref argInstruction , argInstructions ) )
376378 {
377379 if ( calculationFailedWarning )
378380 {
379- ILPostProcessorUtils . LogWarning ( $ "StaticExpression calculation failed .", method , argInstruction ) ;
381+ ILPPUtils . LogWarning ( "CONSTEXPR1501" , "ConstExpression warning." , $ "StaticExpression accepts only constants as arguments .", method , instruction ) ;
380382 }
381383 return false ;
382384 }
@@ -392,13 +394,13 @@ private bool StaticExpressionProcess(ILProcessor ilProcessor, MethodDefinition m
392394 while ( argInstruction != instruction )
393395 {
394396 -- instructionDiff ;
395- ILPostProcessorUtils . ReplaceTarget ( ilProcessor , argInstruction , loadLiteral ) ;
397+ ILPPUtils . ReplaceTarget ( ilProcessor , argInstruction , loadLiteral ) ;
396398 argInstruction = argInstruction . Next ;
397399 ilProcessor . Remove ( argInstruction . Previous ) ;
398400 }
399401
400402 -- instructionDiff ;
401- ILPostProcessorUtils . ReplaceTarget ( ilProcessor , instruction , loadLiteral ) ;
403+ ILPPUtils . ReplaceTarget ( ilProcessor , instruction , loadLiteral ) ;
402404 ilProcessor . Remove ( instruction ) ;
403405 return true ;
404406 }
@@ -454,19 +456,19 @@ private bool CheckStaticExpressionError(MethodReference methodRef)
454456 var method = methodRef . Resolve ( ) ;
455457 if ( ! method . IsStatic )
456458 {
457- ILPostProcessorUtils . LogError ( $ "StaticExpression is static method only.", method ) ;
459+ ILPPUtils . LogError ( "CONSTEXPR1001" , "ConstExpression failed." , $ "StaticExpression is static method only.", method ) ;
458460 return false ;
459461 }
460462
461463 if ( ! method . IsPublic )
462464 {
463- ILPostProcessorUtils . LogError ( $ "StaticExpression is public method only.", method ) ;
465+ ILPPUtils . LogError ( "CONSTEXPR1002" , "ConstExpression failed." , $ "StaticExpression is public method only.", method ) ;
464466 return false ;
465467 }
466468
467469 if ( ! IsAllowStaticExpressionType ( methodRef . ReturnType ) )
468470 {
469- ILPostProcessorUtils . LogError ( $ "StaticExpression does not support return of type \" { methodRef . ReturnType . FullName } \" .", method ) ;
471+ ILPPUtils . LogError ( "CONSTEXPR1003" , "ConstExpression failed." , $ "StaticExpression does not support return of type \" { methodRef . ReturnType . FullName } \" .", method ) ;
470472 return false ;
471473 }
472474
@@ -477,7 +479,7 @@ private bool CheckStaticExpressionError(MethodReference methodRef)
477479 continue ;
478480 }
479481
480- ILPostProcessorUtils . LogError ( $ "StaticExpression does not support parameters of type \" { parameter . ParameterType . FullName } \" .", method ) ;
482+ ILPPUtils . LogError ( "CONSTEXPR1004" , "ConstExpression failed." , $ "StaticExpression does not support parameters of type \" { parameter . ParameterType . FullName } \" .", method ) ;
481483 return false ;
482484 }
483485
@@ -499,7 +501,7 @@ private static bool IsAllowStaticExpressionType(TypeReference type)
499501 var result = type . IsString ( ) ||
500502 type . IsEnum ( ) ||
501503 _allowedStaticExpressionTypes . Contains ( type ) ||
502- ILPostProcessorUtils . IsStructRecursive ( type ) ;
504+ ILPPUtils . IsStructRecursive ( type ) ;
503505 return result ;
504506 }
505507 }
0 commit comments