Exemplo n.º 1
0
 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);
     })
         );
 }
Exemplo n.º 2
0
 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);
 }
        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
                );
        }
Exemplo n.º 4
0
        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);
            })
                );
        }