protected virtual void EmitPlainCompositeHashCode( CompositeCodeGenerationInfo codeGenerationInfo, CompositeModel compositeModel, CompositeTypeModel typeModel, CompositeTypeGenerationInfo publicCompositeGenInfo, CompositeTypeGenerationInfo thisGenInfo, CompositeEmittingInfo emittingInfo, IEnumerable <FragmentTypeGenerationInfo> fragmentGenerationInfos ) { this.EmitCallNonCompositeMethod( codeGenerationInfo, compositeModel, typeModel, publicCompositeGenInfo, thisGenInfo, emittingInfo, fragmentGenerationInfos, HASH_CODE_METHOD, null, null, genInfos => genInfos.FirstOrDefault(genInfo => { var result = thisGenInfo.Parents.Keys.Where(t => !thisGenInfo.Builder.Equals(t)).OnlyBottomTypes().Where(t => !OBJECT_TYPE.Equals(t)).Any(p => genInfo.Parents.ContainsKey(p.GenericDefinitionIfGArgsHaveGenericParams())) || genInfo.DirectBaseFromModel.GetFullInheritanceChain().Any(t => compositeModel.ApplicationModel.GenericFragmentBaseType.NewWrapperAsType(this.ctx).Equals(t)); if (result) { var m = TypeGenerationUtils.FindMethodImplicitlyImplementingMethod(genInfo.DirectBaseFromModel, HASH_CODE_METHOD); result = !HASH_CODE_METHOD.Equals(m); } return(result); }) ); }
protected override void EmitPublicCompositeHashCode( CompositeCodeGenerationInfo codeGenerationInfo, CompositeModel compositeModel, CompositeTypeModel typeModel, CompositeTypeGenerationInfo publicCompositeGenInfo, CompositeTypeGenerationInfo thisGenInfo, CompositeEmittingInfo emittingInfo, IEnumerable <FragmentTypeGenerationInfo> fragmentGenerationInfos ) { this.EmitPlainCompositeHashCode(codeGenerationInfo, compositeModel, typeModel, publicCompositeGenInfo, thisGenInfo, emittingInfo, fragmentGenerationInfos); }
public override IType NormalizeTypeDeclaration(IType type) { if (type == null) { return(null); } if (type is ITypeModel) { return(type); } if (_visited.ContainsKey(type)) { return(_visited[type]); } if (type is PrimaryType) { _visited[type] = new PrimaryTypeModel(type as PrimaryType); return(_visited[type]); } if (type is SequenceType) { SequenceTypeModel model = new SequenceTypeModel(type as SequenceType); _visited[type] = model; return(NormalizeSequenceType(model)); } if (type is DictionaryType) { DictionaryTypeModel model = new DictionaryTypeModel(type as DictionaryType); _visited[type] = model; return(NormalizeDictionaryType(model)); } if (type is CompositeType) { CompositeTypeModel model = NewCompositeTypeModel(type as CompositeType); _visited[type] = model; return(NormalizeCompositeType(model)); } if (type is EnumType) { EnumTypeModel model = NewEnumTypeModel(type as EnumType); _visited[type] = model; return(NormalizeEnumType(model)); } throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "Type {0} is not supported.", type.GetType())); }
protected override void EmitTheRestOfPublicCompositeConstructor( CompositeCodeGenerationInfo codeGenerationInfo, CompositeModel model, CompositeTypeModel typeModel, CompositeEmittingInfo emittingInfo, IEnumerable <FragmentTypeGenerationInfo> fragmentGenerationInfos, CompositeTypeGenerationInfo thisGenerationInfo, ConstructorGenerationInfo ctorGenerationInfo, Int32 firstAdditionalParameterIndex ) { base.EmitTheRestOfPublicCompositeConstructor(codeGenerationInfo, model, typeModel, emittingInfo, fragmentGenerationInfos, thisGenerationInfo, ctorGenerationInfo, firstAdditionalParameterIndex); Int32 baseAdditionalParamsCount = base.GetAmountOfAdditionalArgumentsForPublicCompositeConstructor(); this.EmitSetActionMethod <ActivateAttribute>( codeGenerationInfo, model, typeModel, fragmentGenerationInfos, thisGenerationInfo, thisGenerationInfo, emittingInfo, ctorGenerationInfo, firstAdditionalParameterIndex + baseAdditionalParamsCount, ACTIVATION_METHOD_NAME, false ); this.EmitSetActionMethod <PassivateAttribute>( codeGenerationInfo, model, typeModel, fragmentGenerationInfos, thisGenerationInfo, thisGenerationInfo, emittingInfo, ctorGenerationInfo, firstAdditionalParameterIndex + baseAdditionalParamsCount + 1, PASSIVATION_METHOD_NAME, true ); }
public IDictionary <CILType, TypeBindingInformation> GetEmulatedFragmentTypeBindingInfos(CompositeTypeModel typeModel) { return(this._emulatedFragmentTypeInfos.GetOrAdd(typeModel, tm => tm.FragmentTypeInfos.ToDictionary(kvp => kvp.Key.NewWrapperAsType(this._ctx), kvp => kvp.Value))); }
public AzureCompositeTypeModel(CompositeTypeModel javaCompositeType) : this(javaCompositeType.Package.Replace(".models", "")) { this.LoadFrom(javaCompositeType); }
protected virtual void EmitPlainCompositeEquals( CompositeCodeGenerationInfo codeGenerationInfo, CompositeModel compositeModel, CompositeTypeModel typeModel, CompositeTypeGenerationInfo publicCompositeGenInfo, CompositeTypeGenerationInfo thisGenInfo, CompositeEmittingInfo emittingInfo, IEnumerable <FragmentTypeGenerationInfo> fragmentGenerationInfos ) { // return Object.ReferenceEquals(this, obj) || (obj is <composite type> && <equals-implementation>); ILLabel?returnTrueL = null; ILLabel?returnFalseL = null; this.EmitCallNonCompositeMethod( codeGenerationInfo, compositeModel, typeModel, publicCompositeGenInfo, thisGenInfo, emittingInfo, fragmentGenerationInfos, EQUALS_METHOD, il => { // Make labels for true and false values returnTrueL = il.DefineLabel(); returnFalseL = il.DefineLabel(); il.EmitLoadArg(0) .EmitLoadArg(1) .EmitCall(REFERENCE_EQUALS_METHOD) .EmitBranch(BranchType.IF_TRUE, returnTrueL.Value); var continueLabel = il.DefineLabel(); foreach (var parent in thisGenInfo.Parents.Values.OnlyBottomTypes()) { il.EmitLoadArg(1) .EmitIsInst(parent) .EmitBranch(BranchType.IF_TRUE, continueLabel); } il.EmitBranch(BranchType.ALWAYS, returnFalseL.Value) .MarkLabel(continueLabel); }, il => { // return true il.MarkLabel(returnTrueL.Value) .EmitLoadBoolean(true) .EmitReturn() // return false .MarkLabel(returnFalseL.Value) .EmitLoadBoolean(false) .EmitReturn(); }, genInfos => genInfos.FirstOrDefault(genInfo => { var result = thisGenInfo.Parents.Keys.Where(t => !thisGenInfo.Builder.Equals(t)).OnlyBottomTypes().Where(t => !OBJECT_TYPE.Equals(t)).Any(p => genInfo.Parents.ContainsKey(p.GenericDefinitionIfGArgsHaveGenericParams())) || genInfo.DirectBaseFromModel.GetFullInheritanceChain().Any(t => compositeModel.ApplicationModel.GenericFragmentBaseType.NewWrapperAsType(this.ctx).Equals(t)); if (result) { var m = TypeGenerationUtils.FindMethodImplicitlyImplementingMethod(genInfo.DirectBaseFromModel, EQUALS_METHOD); result = !EQUALS_METHOD.Equals(m); } return(result); }) ); }
public PublicCompositeTypeGenerationResultImpl( CompositeModel cModel, CompositeTypeModel tModel, EventHandler <AssemblyLoadingArgs> loadingEvt, IDictionary <Assembly, Assembly> assDic, CompositeCodeGenerationInfo codeGenerationInfo ) { //var orderer = new TypeLoadOrderer( cModel ); var collectionsFactory = cModel.ApplicationModel.CollectionsFactory; var publicTypes = cModel .GetAllCompositeTypes() .Concat(cModel.GetAllFragmentTypes()) //.OrderBy( t => t, orderer ) .Where(t => cModel.ApplicationModel.AffectedAssemblies.Contains(t.GetAssembly())) .OrderBy(t => t.Equals(cModel.MainCodeGenerationType) ? 0 : 1) // Populate main code generation type first .Select(t => GetGeneratedPublicType(t, cModel, codeGenerationInfo, loadingEvt, assDic)) .Distinct() .ToArray(); var mainTypes = publicTypes.Where(iResult => iResult.IsPublicTypeMainCompositeType()); if (!mainTypes.Any() || mainTypes.Skip(1).Any()) { throw new ArgumentException((mainTypes.Any() ? "Too many" : "Too little") + " generated main types (" + String.Join(", ", mainTypes) + "), exactly one allowed."); } var mainType = mainTypes.First(); this._compositeFactory = (CompositeFactory)mainType.GetAssembly().GetType(mainType.Name + codeGenerationInfo.CompositeFactorySuffix, true) #if WINDOWS_PHONE_APP .GetAllInstanceConstructors().First() #else .GetConstructors()[0] #endif .Invoke(null); var fragmentTypeGenerationResults = tModel.FragmentTypeInfos.Keys //.OrderBy( t => t, orderer ) .Select(t => Tuple.Create(t, GetParticipantType(t, cModel, codeGenerationInfo, loadingEvt, assDic, codeGenerationInfo.FragmentPrefix, true))) .Where(t => t.Item2 != null) .Select(t => (FragmentTypeGenerationResult) new FragmentTypeGenerationResultImpl(t.Item1, t.Item2)) .ToArray(); var concernInvocationGenerationResults = tModel.ConcernInvocationTypeInfos.Keys //.OrderBy( t => t, orderer ) .Select(t => Tuple.Create(t, GetParticipantType(t, cModel, codeGenerationInfo, loadingEvt, assDic, codeGenerationInfo.ConcernInvocationPrefix))) .Where(t => t.Item2 != null) .Select(t => (TypeGenerationResult) new TypeGenerationResultImpl(t.Item2, t.Item1)) .ToArray(); var sideEffectInvocationGenerationResults = tModel.SideEffectInvocationTypeInfos.Keys //.OrderBy( t => t, orderer ) .Select(t => Tuple.Create(t, GetParticipantType(t, cModel, codeGenerationInfo, loadingEvt, assDic, codeGenerationInfo.SideEffectInvocationPrefix))) .Where(t => t.Item2 != null) .Select(t => (TypeGenerationResult) new TypeGenerationResultImpl(t.Item2, t.Item1)) .ToArray(); var privateCompositeGenerationresults = tModel.PrivateCompositeTypeInfos.Keys //.OrderBy( t => t, orderer ) .Select(t => Tuple.Create(t, GetParticipantType(t, cModel, codeGenerationInfo, loadingEvt, assDic, codeGenerationInfo.PrivateCompositePrefix))) .Where(t => t.Item2 != null) .Select(t => (TypeGenerationResult) new TypeGenerationResultImpl(t.Item2, t.Item1)) .ToArray(); var pGArgs = collectionsFactory.NewDictionaryProxy( tModel.PublicCompositeGenericArguments .Select((gArg, idx) => Tuple.Create(gArg, idx)) .GroupBy(tuple => tuple.Item1.DeclaringType) .ToDictionary(grouping => grouping.Key, grouping => collectionsFactory.NewListProxy(grouping.Select(tuple => tuple.Item2).ToList()).CQ)); this._generatedPublicMainType = mainType; this._maxParamCountForCtors = mainType #if WINDOWS_PHONE_APP .GetAllInstanceConstructors().First() #else .GetConstructors(BindingFlags.Instance | BindingFlags.Public)[0] #endif .GetParameters().Length; this._generatedPublicTypes = collectionsFactory.NewListProxy(publicTypes.Select( pt => (GeneratedTypeInfo) new GeneratedTypeInfoImpl(pt)) .ToList()).CQ; this._publicCompositeGenericArguments = pGArgs.CQ; this._privateCompositeGenerationResults = collectionsFactory.NewListProxyFromParams(privateCompositeGenerationresults).CQ; this._fragmentGenerationResults = collectionsFactory.NewListProxyFromParams(fragmentTypeGenerationResults).CQ; this._concernInvocationGenerationResults = collectionsFactory.NewListProxyFromParams(concernInvocationGenerationResults).CQ; this._sideEffectInvocationGenerationResults = collectionsFactory.NewListProxyFromParams(sideEffectInvocationGenerationResults).CQ; // Remember to remove Qi4CS assembly if present assDic.Remove(ReflectionHelper.QI4CS_ASSEMBLY); }
public PublicCompositeTypeGenerationResult LoadTypes(CompositeModel compositeModel, CompositeTypeModel tModel, EventHandler <AssemblyLoadingArgs> loadingEvt, IDictionary <Assembly, Assembly> assDic) { return(new PublicCompositeTypeGenerationResultImpl( compositeModel, tModel, loadingEvt, assDic, this._codeGenerationInfo )); }