Exemplo n.º 1
0
 public virtual void CheckCast(Type castedType)
 {
     if (mv != null)
     {
         mv.CheckCast(castedType);
     }
 }
Exemplo n.º 2
0
        protected void ImplementSetValue(IPropertyInfo[] propertyPath)
        {
            IMethodVisitor mv = VisitMethod(template_m_setValue);

            IPropertyInfo lastProperty = propertyPath[propertyPath.Length - 1];

            if (lastProperty is MethodPropertyInfo && ((MethodPropertyInfo)lastProperty).Setter == null)
            {
                throw new Exception("Property not writable: " + lastProperty.EntityType.FullName + "." + lastProperty.Name);
            }
            mv.LoadArg(0);
            Type typeOfArgumentOnStack = typeof(Object);

            for (int a = 0, size = propertyPath.Length - 1; a < size; a++)
            {
                typeOfArgumentOnStack = InvokeGetProperty(mv, propertyPath[a], typeOfArgumentOnStack);
            }
            if (!lastProperty.DeclaringType.Equals(typeOfArgumentOnStack))
            {
                mv.CheckCast(lastProperty.DeclaringType);
            }
            mv.LoadArg(1);
            Type lastPropertyType = lastProperty.PropertyType;

            if (lastProperty.PropertyType.IsPrimitive)
            {
                Type  pType            = lastProperty.PropertyType;
                Label l_valueIsNonNull = mv.NewLabel();
                Label l_valueIsValid   = mv.NewLabel();

                mv.IfNonNull(l_valueIsNonNull);
                mv.PushNullOrZero(pType);
                mv.GoTo(l_valueIsValid);

                mv.Mark(l_valueIsNonNull);
                mv.LoadArg(1);
                mv.Unbox(pType);
                mv.Mark(l_valueIsValid);
            }
            else
            {
                mv.CheckCast(lastPropertyType);
            }
            InvokeSetProperty(mv, lastProperty);
            mv.ReturnValue();

            mv.EndMethod();
        }
Exemplo n.º 3
0
 protected Type InvokeGetProperty(IMethodVisitor mv, IPropertyInfo property, Type typeOfArgumentOnStack)
 {
     if (property is MethodPropertyInfo)
     {
         MethodInfo     method = ((MethodPropertyInfo)property).Getter;
         MethodInstance mi     = new MethodInstance(method);
         if (method.DeclaringType.IsInterface)
         {
             mv.InvokeInterface(mi);
         }
         else
         {
             if (!mi.Owner.Equals(typeOfArgumentOnStack))
             {
                 mv.CheckCast(mi.Owner);
             }
             mv.InvokeVirtual(mi);
             typeOfArgumentOnStack = mi.ReturnType.Type;
         }
     }
     else
     {
         FieldInfo     field = ((FieldPropertyInfo)property).BackingField;
         FieldInstance fi    = new FieldInstance(field);
         mv.GetField(fi);
         typeOfArgumentOnStack = fi.Type.Type;
     }
     return(typeOfArgumentOnStack);
 }
Exemplo n.º 4
0
        protected void ImplementRelationGetter(String propertyName, MethodInstance m_getMethod_template, MethodInstance m_setMethod, int relationIndex,
                                               PropertyInstance p_valueHolderContainerTemplate, PropertyInstance p_targetCache, PropertyInstance p_relationMembers, FieldInstance f_initialized,
                                               FieldInstance f_objRefs)
        {
            // public String getPropertyName()
            // {
            // if (!PropertyName$initialized)
            // {
            // setPropertyName(RelationsGetterVisitor.valueHolderContainer_getValue(this, $relationMembers, get__IndexOfPropertyName(), $targetCache, $beanContext,
            // propertyName$objRefs));
            // }
            // return super.getPropertyName();
            // }
            Script script_getVHC;

            if (EmbeddedEnhancementHint.HasMemberPath(State.Context))
            {
                PropertyInstance p_rootEntity = EmbeddedTypeVisitor.GetRootEntityProperty(this);
                script_getVHC = delegate(IMethodVisitor mv)
                {
                    mv.CallThisGetter(p_rootEntity);
                };
            }
            else
            {
                script_getVHC = delegate(IMethodVisitor mv)
                {
                    // this
                    mv.LoadThis();
                };
            }

            MethodInstance m_getMethod;
            {
                PropertyInstance p_cacheModification = SetCacheModificationMethodCreator.GetCacheModificationPI(this);
                MethodInstance   m_getMethod_scoped  = new MethodInstance(State.NewType,
                                                                          MethodAttributes.HideBySig | MethodAttributes.Private | MethodAttributes.Final, NewType.VOID_TYPE, propertyName + "$DoInitialize");
                {
                    IMethodVisitor mg = VisitMethod(m_getMethod_scoped);

                    // this => for this.setPropertyName(...)
                    mg.LoadThis();
                    // call template.getValue(..)
                    mg.CallThisGetter(p_valueHolderContainerTemplate);
                    // getVhc()
                    script_getVHC.Invoke(mg);
                    // $relationMembers
                    mg.CallThisGetter(p_relationMembers);
                    // get__IndexOfPropertyName()
                    mg.Push(relationIndex);
                    // $targetCache
                    mg.CallThisGetter(p_targetCache);
                    // propertyName$objRefs
                    mg.GetThisField(f_objRefs);
                    mg.InvokeVirtual(m_template_getValue);
                    mg.CheckCast(m_setMethod.Parameters[0].Type);
                    mg.InvokeVirtual(m_setMethod);
                    mg.ReturnValue();
                    mg.EndMethod();
                }
                {
                    IMethodVisitor mg = base.VisitMethod(m_getMethod_template);
                    m_getMethod = mg.Method;
                    HideFromDebug(m_getMethod);
                    Label l_initialized = mg.NewLabel();
                    mg.GetThisField(f_initialized);
                    mg.PushEnum(ValueHolderState.INIT);
                    mg.IfCmp(typeof(ValueHolderState), CompareOperator.EQ, l_initialized);

                    SetCacheModificationMethodCreator.CacheModificationInternalUpdate(p_cacheModification, mg,
                                                                                      delegate(IMethodVisitor mv2)
                    {
                        mv2.LoadThis();
                        mv2.InvokeOnExactOwner(m_getMethod_scoped);
                    });

                    mg.Mark(l_initialized);
                    mg.LoadThis();
                    mg.InvokeSuperOfCurrentMethod();
                    mg.ReturnValue();
                    mg.EndMethod();
                }
            }

            // public String getPropertyName$NoInit()
            // {
            // return super.getPropertyName();
            // }
            {
                MethodInstance   m_getNoInit = m_getMethod_template.DeriveName(ValueHolderIEC.GetGetterNameOfRelationPropertyWithNoInit(propertyName));
                IMethodVisitor   mg          = base.VisitMethod(m_getNoInit);
                PropertyInstance p_getNoInit = PropertyInstance.FindByTemplate(propertyName + ValueHolderIEC.GetNoInitSuffix(), m_getNoInit.ReturnType, false);
                p_getNoInit.AddAnnotation(c_fireThisOPC, propertyName);
                p_getNoInit.AddAnnotation(c_fireTargetOPC, propertyName);
                mg.LoadThis();
                mg.InvokeSuper(m_getMethod);
                mg.ReturnValue();
                mg.EndMethod();
            }
        }