github.com/remobjects/goldbaselibrary@v0.0.0-20230924164425-d458680a936b/Source/GoldAspect/Main.pas (about) 1 namespace GoldAspect; 2 3 uses 4 System.Linq, 5 RemObjects.Elements.Cirrus.*; 6 7 type 8 // we use this class to work around compiler issues in Gold. 9 [AttributeUsage(AttributeTargets.Assembly)] 10 GoldFixer = public partial class(Attribute, IAssemblyInterfaceDecorator) 11 public 12 /* 13 method GetCallToClassConstructor(aServices: IServices; aNamespace: String): Statement; 14 begin 15 var lType := aServices.GetType('go.'+aNamespace+'.__Global'); 16 if (lType = nil) or (lType.GetClassConstructor = nil) then exit new BeginStatement(); 17 var lMeth: IMethod := lType.GetStaticMethod('__Initialize', new IType[0], []); 18 if lMeth = nil then begin 19 lMeth := (lType as ITypeDefinition).AddMethod('__Initialize', nil, true); 20 end; 21 exit new StandaloneStatement(new ProcValue(new TypeValue(lMeth.Owner), lMeth)); 22 end; 23 24 method ForceInitializationOfNamespaces(aServices: IServices; aNamespace: String; aArgs: array of String); 25 begin 26 var lType := aServices.GetType('go.'+aNamespace+'.__Global'); 27 var lCCtor := IMethodDefinition(lType.GetClassConstructor); 28 if lCCtor = nil then 29 lCCtor := ITypeDefinition(lType).AddConstructor(true); 30 var lBeg := new BeginStatement(); 31 for each x in aArgs do 32 lBeg.Add(GetCallToClassConstructor(aServices, x)); 33 lCCtor.SurroundMethodBody(lBeg, new BeginStatement, SurroundMethod.Never); 34 end;*/ 35 36 method HandleInterface(Services: IServices); 37 begin 38 /*ForceInitializationOfNamespaces(Services, 'crypto.tls', ["crypto", 39 "crypto.hmac", 40 "crypto.md5", 41 "crypto.sha1", 42 "crypto.sha256", 43 "crypto.sha512", 44 "errors", 45 "fmt"]);*/ 46 47 {var lType := Services.GetType('go.net.http.atomicBool'); 48 ITypeDefinition(lType).RemoveMethod(lType.GetStaticMethods('isSet')[0] as IMethodDefinition); 49 ITypeDefinition(lType).RemoveMethod(lType.GetStaticMethods('setTrue')[0] as IMethodDefinition); 50 var lPar := new SelfValue; 51 var lIsSet := ITypeDefinition(lType).AddMethod('isSet', Services.GetBaseType(1), false); 52 lIsSet.ReplaceMethodBody( 53 new ExitStatement( 54 new BinaryValue(new ProcValue(new TypeValue(Services.GetType('go.sync.atomic.__Global')), 'LoadInt32', [new FieldValue(lPar, lType, 'Value')]), new DataValue(0), BinaryOperator.NotEqual) 55 )); 56 var lsetTrue := ITypeDefinition(lType).AddMethod('setTrue', nil, false); 57 lsetTrue.ReplaceMethodBody( 58 new StandaloneStatement( 59 new ProcValue(new TypeValue(Services.GetType('go.sync.atomic.__Global')), 'StoreInt32', [new FieldValue(lPar, lType, 'Value'), new DataValue(1)]) 60 ));} 61 62 var lType := Services.GetType('go.net.http.__Global'); 63 var lMethod := lType.GetStaticMethods('http2isNoCachedConnError')[0] as IMethodDefinition; 64 lMethod.ReplaceMethodBody( 65 new ExitStatement(new BinaryValue(new ParamValue(0), new TypeValue(Services.GetType('go.net.http.http2noCachedConnError')), BinaryOperator.Is)) 66 ); 67 end; 68 end; 69 70 [MethodAspect('go.reflect.__Global', true, 'TypeOf', 0, array of String(nil))] 71 TypeOfFixer = public partial class(Attribute, IMethodCallDecorator) 72 public 73 method ProcessMethodCall(aContext: IContext; aMethod: IMethod; aValue: ParameterizedValue): Value; 74 begin 75 if (aValue.Parameters[0].Kind = ValueKind.Nil) and (NilValue(aValue.Parameters[0]).Type <> nil) then begin 76 exit new NewValue(aContext.Services.GetType('go.reflect.TypeImpl'), new TypeOfValue(NilValue(aValue.Parameters[0]).Type)); 77 end; 78 exit nil; 79 end; 80 end; 81 82 end.