コード例 #1
0
 public virtual void CallThisSetter(MethodInstance method, Script script)
 {
     if (mv != null)
     {
         mv.CallThisSetter(method, script);
     }
 }
コード例 #2
0
        protected void ImplementIdVersionConstructor(PropertyInstance p_id, PropertyInstance p_version)
        {
            ConstructorInfo     superConstructor = State.CurrentType.GetConstructor(Type.EmptyTypes);
            ConstructorInstance ci_super         = new ConstructorInstance(superConstructor);

            IMethodVisitor mv = VisitMethod(new ConstructorInstance(MethodAttributes.Public, typeof(Object), typeof(Object)));

            mv.LoadThis();
            mv.InvokeConstructor(ci_super);
            mv.CallThisSetter(p_id, delegate(IMethodVisitor mg)
            {
                mg.LoadArg(0);
            });
            mv.CallThisSetter(p_version, delegate(IMethodVisitor mg)
            {
                mg.LoadArg(1);
            });
            mv.ReturnValue();
            mv.EndMethod();
        }
コード例 #3
0
        protected PropertyInstance ImplementTargetCache(PropertyInstance p_valueHolderContainerTemplate)
        {
            if (EmbeddedEnhancementHint.HasMemberPath(State.Context))
            {
                PropertyInstance p_rootEntity   = EmbeddedTypeVisitor.GetRootEntityProperty(this);
                PropertyInstance p_targetCache2 = ImplementProperty(p_template_targetCache, delegate(IMethodVisitor mv)
                {
                    Label l_finish = mv.NewLabel();
                    mv.CallThisGetter(p_rootEntity);
                    mv.Dup();
                    mv.IfNull(l_finish);
                    mv.CheckCast(typeof(IValueHolderContainer));
                    mv.InvokeInterface(p_template_targetCache.Getter);
                    mv.Mark(l_finish);
                    mv.ReturnValue();
                }, null);
                return(p_targetCache2);
            }
            ImplementSelfGetter(p_valueHolderContainerTemplate);

            FieldInstance f_targetCache = ImplementField(new FieldInstance(FieldAttributes.Private, "__targetCache", p_template_targetCache.PropertyType));

            PropertyInstance p_targetCache = ImplementProperty(p_template_targetCache, delegate(IMethodVisitor mv)
            {
                mv.GetThisField(f_targetCache);
                mv.ReturnValue();
            }, delegate(IMethodVisitor mv)
            {
                mv.PutThisField(f_targetCache, delegate(IMethodVisitor mv2)
                {
                    mv.LoadArg(0);
                });
                mv.ReturnValue();
            });

            {
                IMethodVisitor mg = VisitMethod(m_template_getCache);
                mg.CallThisGetter(p_targetCache);
                mg.ReturnValue();
                mg.EndMethod();
            }
            {
                IMethodVisitor mg = VisitMethod(m_template_detach);
                mg.CallThisSetter(p_targetCache, delegate(IMethodVisitor mg2)
                {
                    mg2.PushNull();
                });
                mg.ReturnValue();
                mg.EndMethod();
            }
            return(p_targetCache);
        }
コード例 #4
0
        public override void VisitEnd()
        {
            HashMap <String, List <MethodInfo> > nameToMethodsMap = new HashMap <String, List <MethodInfo> >();

            foreach (MethodInfo method in ReflectUtil.GetMethods(State.OriginalType))
            {
                List <MethodInfo> methodList = nameToMethodsMap.Get(method.Name);
                if (methodList == null)
                {
                    methodList = new List <MethodInfo>();
                    nameToMethodsMap.Put(method.Name, methodList);
                }
                methodList.Add(method);
            }
            foreach (IPropertyInfo propertyInfo in propertyInfos)
            {
                MethodInfo getter = ((MethodPropertyInfo)propertyInfo).Getter;
                MethodInfo setter = ((MethodPropertyInfo)propertyInfo).Setter;
                if (getter == null)
                {
                    // look for abstract definition of the getter
                    getter = ReflectUtil.GetDeclaredMethod(true, State.CurrentType, propertyInfo.PropertyType, "get_" + propertyInfo.Name);
                }
                if (setter == null)
                {
                    // look for abstract definition of the setter
                    setter = ReflectUtil.GetDeclaredMethod(true, State.CurrentType, typeof(void), "set_" + propertyInfo.Name,
                                                           propertyInfo.PropertyType);
                }
                MethodInstance m_getterTemplate = getter != null ? new MethodInstance(getter) : null;
                MethodInstance m_setterTemplate = setter != null ? new MethodInstance(setter) : null;
                MethodInstance m_getter         = MethodInstance.FindByTemplate(m_getterTemplate, true);
                MethodInstance m_setter         = MethodInstance.FindByTemplate(m_setterTemplate, true);

                if (m_getter != null && m_setter != null)
                {
                    // ensure both accessors are public
                    if (!m_getter.Access.HasFlag(MethodAttributes.Public))
                    {
                        IMethodVisitor mv = VisitMethod(m_getter.DeriveAccess(MethodAttributes.Public));
                        mv.LoadThis();
                        mv.LoadArgs();
                        mv.InvokeSuper(m_getter);
                        mv.ReturnValue();
                        mv.EndMethod();
                    }
                    if (!m_setter.Access.HasFlag(MethodAttributes.Public))
                    {
                        IMethodVisitor mv = VisitMethod(m_setter.DeriveAccess(MethodAttributes.Public));
                        mv.LoadThis();
                        mv.LoadArgs();
                        mv.InvokeSuper(m_getter);
                        mv.ReturnValue();
                        mv.EndMethod();
                    }
                    continue;
                }
                if (m_getter != null || m_setter != null)
                {
                    // at least one of the accessors is explicitly implemented
                    continue;
                }
                FieldInstance f_backingField = EnsureBackingField(propertyInfo);
                if (f_backingField == null)
                {
                    continue;
                }
                if (m_setterTemplate == null)
                {
                    m_setterTemplate = new MethodInstance(null, MethodAttributes.Public | MethodAttributes.SpecialName, m_setterTemplate != null ? m_setterTemplate.ReturnType : NewType.VOID_TYPE,
                                                          "set_" + propertyInfo.Name, f_backingField.Type);
                }
                // implement setter
                m_setterTemplate = ImplementSetter(m_setterTemplate, f_backingField);
                List <MethodInfo> allSettersWithSameName = nameToMethodsMap.Get(m_setterTemplate.Name);
                if (allSettersWithSameName != null)
                {
                    MethodInstance f_m_setterTemplate = m_setterTemplate;
                    foreach (MethodInfo setterWithSameName in allSettersWithSameName)
                    {
                        MethodInstance m_setterWithSameName = MethodInstance.FindByTemplate(setterWithSameName, true);
                        if (m_setterWithSameName != null)
                        {
                            // method is implemented, so nothing to do
                            continue;
                        }
                        IMethodVisitor mv = VisitMethod(new MethodInstance(setterWithSameName));
                        if (mv.Method.Parameters.Length != 1)
                        {
                            // this visitor handles only "true" setters with exactly one argument
                            continue;
                        }
                        mv.CallThisSetter(m_setterTemplate, delegate(IMethodVisitor mg)
                        {
                            mg.LoadArg(0);
                            mg.CheckCast(f_m_setterTemplate.Parameters[0].Type);
                        });
                        mv.ReturnVoidOrThis();
                        mv.EndMethod();
                    }
                }
                if (m_getterTemplate == null)
                {
                    m_getterTemplate = new MethodInstance(null, MethodAttributes.Public | MethodAttributes.SpecialName, f_backingField.Type, "get_" + propertyInfo.Name, null);
                }
                // implement getter
                m_getterTemplate = ImplementGetter(m_getterTemplate, f_backingField);
                List <MethodInfo> allGettersWithSameName = nameToMethodsMap.Get(m_getterTemplate.Name);
                if (allGettersWithSameName != null)
                {
                    foreach (MethodInfo getterWithSameName in allGettersWithSameName)
                    {
                        MethodInstance m_getterWithSameName = MethodInstance.FindByTemplate(getterWithSameName, true);
                        if (m_getterWithSameName != null)
                        {
                            // method is implemented, so nothing to do
                            continue;
                        }
                        IMethodVisitor mv = VisitMethod(new MethodInstance(getterWithSameName));
                        mv.CallThisGetter(m_getterTemplate);
                        mv.ReturnValue();
                        mv.EndMethod();
                    }
                }
            }
            base.VisitEnd();
        }