Exemplo n.º 1
0
        protected void ImplementSetRelation(RelationMember[] relationMembers, FieldInstance[] f_relations)
        {
            MethodInstance template_m_setRelation = new MethodInstance(null, typeof(RootCacheValue), typeof(void), "SetRelation", typeof(int), typeof(IObjRef[]));

            IMethodVisitor mv       = VisitMethod(template_m_setRelation);
            Label          l_finish = mv.NewLabel();

            for (int relationIndex = 0, size = f_relations.Length; relationIndex < size; relationIndex++)
            {
                FieldInstance f_relation = f_relations[relationIndex];

                Label l_notEqual = mv.NewLabel();

                mv.LoadArg(0);
                mv.Push(relationIndex);

                mv.IfCmp(typeof(int), CompareOperator.NE, l_notEqual);

                mv.PutThisField(f_relation, delegate(IMethodVisitor mg)
                {
                    mg.LoadArg(1);
                });
                mv.GoTo(l_finish);
                mv.Mark(l_notEqual);
            }
            mv.ThrowException(typeof(ArgumentException), "Given relationIndex not known");
            mv.Mark(l_finish);
            mv.ReturnValue();
            mv.EndMethod();
        }
Exemplo n.º 2
0
        protected void ImplementGetRelation(RelationMember[] relationMembers, FieldInstance[] f_relations)
        {
            MethodInstance template_m_getRelation = new MethodInstance(null, typeof(RootCacheValue), typeof(IObjRef[]), "GetRelation", typeof(int));

            IMethodVisitor mv = VisitMethod(template_m_getRelation);

            if (f_relations.Length > 0)
            {
                Label   l_default   = mv.NewLabel();
                Label[] l_relations = new Label[f_relations.Length];
                for (int relationIndex = 0, size = l_relations.Length; relationIndex < size; relationIndex++)
                {
                    l_relations[relationIndex] = mv.NewLabel();
                }

                mv.LoadArg(0);
                mv.Switch(0, l_relations.Length - 1, l_default, l_relations);

                for (int relationIndex = 0, size = f_relations.Length; relationIndex < size; relationIndex++)
                {
                    FieldInstance f_relation = f_relations[relationIndex];

                    mv.Mark(l_relations[relationIndex]);
                    mv.GetThisField(f_relation);
                    mv.ReturnValue();
                }
                mv.Mark(l_default);
            }
            mv.ThrowException(typeof(ArgumentException), "Given relationIndex not known");
            mv.PushNull();
            mv.ReturnValue();
            mv.EndMethod();
        }
Exemplo n.º 3
0
 public virtual void EndMethod()
 {
     if (mv != null)
     {
         mv.EndMethod();
     }
 }
Exemplo n.º 4
0
        protected void ImplementToStringMethod(PropertyInstance p_entityEqualsTemplate)
        {
            {
                MethodInstance methodTemplate = new MethodInstance(null, typeof(Object), typeof(String), "ToString");
                MethodInstance method         = MethodInstance.FindByTemplate(methodTemplate, true);
                if (NewType.GetType(typeof(Object)).Equals(method.Owner) || method.Access.HasFlag(MethodAttributes.Abstract))
                {
                    IMethodVisitor mg = VisitMethod(methodTemplate);
                    mg.CallThisGetter(p_entityEqualsTemplate);
                    mg.LoadThis();
                    mg.LoadThis();
                    mg.InvokeVirtual(entityEquals_toString_Obj);
                    mg.ReturnValue();
                    mg.EndMethod();
                }
            }

            {
                MethodInstance methodTemplate = new MethodInstance(null, typeof(IPrintable), typeof(void), "ToString", typeof(StringBuilder));
                MethodInstance method         = MethodInstance.FindByTemplate(methodTemplate, true);
                if (method == null || method.Access.HasFlag(MethodAttributes.Abstract))
                {
                    IMethodVisitor mg = VisitMethod(methodTemplate);
                    mg.CallThisGetter(p_entityEqualsTemplate);
                    mg.LoadThis();
                    mg.LoadArgs();
                    mg.InvokeVirtual(entityEquals_toString_Printable);
                    mg.ReturnValue();
                    mg.EndMethod();
                }
            }
        }
Exemplo n.º 5
0
        protected MethodInstance ImplementUsePropertyChangeSupport(PropertyInstance p_propertyChangeTemplate, FieldInstance f_propertyChangeSupport)
        {
            MethodInstance m_getPropertyChangeSupport = MethodInstance.FindByTemplate(template_m_usePropertyChangeSupport, true);

            if (m_getPropertyChangeSupport == null)
            {
                // create field that holds propertyChangeSupport
                f_propertyChangeSupport = ImplementField(f_propertyChangeSupport);
                IMethodVisitor mg = VisitMethod(template_m_usePropertyChangeSupport);
                HideFromDebug(mg.Method);
                Label l_pcsValid = mg.NewLabel();
                mg.GetThisField(f_propertyChangeSupport);
                mg.Dup();
                mg.IfNonNull(l_pcsValid);

                mg.Pop(); // remove 2nd null instance from stack caused by previous dup
                mg.PutThisField(f_propertyChangeSupport, delegate(IMethodVisitor mg2)
                {
                    mg.CallThisGetter(p_propertyChangeTemplate);
                    mg.LoadThis();
                    mg.InvokeVirtual(m_newPropertyChangeSupport);
                });
                mg.GetThisField(f_propertyChangeSupport);

                mg.Mark(l_pcsValid);
                mg.ReturnValue(); // return instance already on the stack by both branches
                mg.EndMethod();

                m_getPropertyChangeSupport = mg.Method;
            }
            return(m_getPropertyChangeSupport);
        }
Exemplo n.º 6
0
        protected void ImplementNotifyPropertyChanged(PropertyInstance p_propertyChangeTemplate, MethodInstance m_getPropertyChangeSupport)
        {
            // implement IPropertyChanged
            foreach (MethodInfo rMethod in typeof(INotifyPropertyChanged).GetMethods())
            {
                MethodInstance existingMethod = MethodInstance.FindByTemplate(rMethod, true);
                if (existingMethod != null)
                {
                    continue;
                }
                MethodInstance method = new MethodInstance(rMethod);

                IMethodVisitor mg = VisitMethod(method);
                mg.CallThisGetter(p_propertyChangeTemplate);
                // this.propertyChangeSupport
                mg.CallThisGetter(m_getPropertyChangeSupport);
                // listener
                mg.LoadArg(0);
                if ("add_PropertyChanged".Equals(method.Name))
                {
                    // addPropertyChangeListener(propertyChangeSupport, listener)
                    mg.InvokeVirtual(m_addPropertyChangeListener);
                }
                else
                {
                    // removePropertyChangeListener(propertyChangeSupport, listener)
                    mg.InvokeVirtual(m_removePropertyChangeListener);
                }
                mg.ReturnValue();
                mg.EndMethod();
            }
        }
Exemplo n.º 7
0
        protected void ImplementCascadeLoadMode()
        {
            FieldInstance f_cascadeLoadMode = ImplementField(new FieldInstance(FieldAttributes.Private, "__cascadeLoadMode", typeof(CascadeLoadMode)));

            ImplementGetter(template_m_getCascadeLoadMode, f_cascadeLoadMode);
            ImplementSetter(template_m_setCascadeLoadMode, f_cascadeLoadMode);

            ConstructorInfo[] constructors = State.CurrentType.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
            for (int a = constructors.Length; a-- > 0;)
            {
                ConstructorInstance ci = new ConstructorInstance(constructors[a]);
                ci = new ConstructorInstance(MethodAttributes.Public, ci.Parameters);
                IMethodVisitor mv = VisitMethod(ci);
                mv.LoadThis();
                mv.LoadArgs();
                mv.InvokeSuperOfCurrentMethod();

                mv.PutThisField(f_cascadeLoadMode, delegate(IMethodVisitor mg)
                {
                    mg.PushEnum(CascadeLoadMode.DEFAULT);
                });
                mv.ReturnValue();
                mv.EndMethod();
            }
        }
Exemplo n.º 8
0
        /**
         * public boolean hasPendingChanges() { return isToBeUpdated() || isToBeCreated() || isToBeDeleted(); }
         */
        protected void ImplementHasPendingChanges(PropertyInstance p_hasPendingChanges, PropertyInstance p_ToBeUpdated, PropertyInstance p_ToBeCreated,
                                                  PropertyInstance p_ToBeDeleted)
        {
            IMethodVisitor mg = VisitMethod(p_hasPendingChanges.Getter);

            p_hasPendingChanges = PropertyInstance.FindByTemplate(p_hasPendingChanges, false);
            p_hasPendingChanges.AddAnnotation(c_ignoreToBeUpdated);
            p_hasPendingChanges.AddAnnotation(c_fireThisOPC, p_ToBeCreated.Name);
            p_hasPendingChanges.AddAnnotation(c_fireThisOPC, p_ToBeUpdated.Name);
            p_hasPendingChanges.AddAnnotation(c_fireThisOPC, p_ToBeDeleted.Name);

            Label trueLabel = mg.NewLabel();

            mg.LoadThis();
            mg.InvokeVirtual(p_ToBeUpdated.Getter);
            mg.IfZCmp(CompareOperator.NE, trueLabel);

            mg.LoadThis();
            mg.InvokeVirtual(p_ToBeCreated.Getter);
            mg.IfZCmp(CompareOperator.NE, trueLabel);

            mg.LoadThis();
            mg.InvokeVirtual(p_ToBeDeleted.Getter);
            mg.IfZCmp(CompareOperator.NE, trueLabel);

            mg.Push(false);
            mg.ReturnValue();

            mg.Mark(trueLabel);
            mg.Push(true);
            mg.ReturnValue();
            mg.EndMethod();
        }
Exemplo n.º 9
0
        protected void ImplementGetRealType(IPropertyInfo[] property)
        {
            IMethodVisitor mv = VisitMethod(template_m_getRealType);

            mv.Push(property[property.Length - 1].PropertyType);
            mv.ReturnValue();
            mv.EndMethod();
        }
Exemplo n.º 10
0
        protected void ImplementCanWrite(IPropertyInfo[] property)
        {
            IMethodVisitor mv = VisitMethod(template_m_canWrite);

            mv.Push(property[property.Length - 1].IsWritable);
            mv.ReturnValue();
            mv.EndMethod();
        }
Exemplo n.º 11
0
        protected void ImplementIsToMany(IPropertyInfo[] propertyPath)
        {
            IMethodVisitor mv = VisitMethod(template_m_isToMany);

            mv.Push(ListUtil.IsCollection(propertyPath[propertyPath.Length - 1].PropertyType));
            mv.ReturnValue();
            mv.EndMethod();
        }
Exemplo n.º 12
0
        protected void ImplementGetDeclaringType(IPropertyInfo[] property)
        {
            IMethodVisitor mv = VisitMethod(template_m_getDeclaringType);

            mv.Push(declaringType);
            mv.ReturnValue();
            mv.EndMethod();
        }
Exemplo n.º 13
0
        protected void ImplementDefaultConstructor()
        {
            IMethodVisitor mv = VisitMethod(ConstructorInstance.defaultConstructor);

            mv.LoadThis();
            mv.InvokeSuperOfCurrentMethod();
            mv.ReturnValue();
            mv.EndMethod();
        }
Exemplo n.º 14
0
        public virtual MethodInstance ImplementGetter(MethodInstance method, FieldInstance field)
        {
            IMethodVisitor mg = VisitMethod(method);

            mg.GetThisField(field);
            mg.ReturnValue();
            mg.EndMethod();
            return(MethodInstance.FindByTemplate(method, false));
        }
Exemplo n.º 15
0
        public void visitEnd()
        {
            // AbstractPrivilege.class;
            MethodInstance template_m_getPrimitivePropertyPrivilege = new MethodInstance(null, typeof(IPrivilege), typeof(IPropertyPrivilege),
                                                                                         "GetPrimitivePropertyPrivilege", typeof(int));

            MethodInstance template_m_setPrimitivePropertyPrivilege = new MethodInstance(null, MethodAttributes.Family, typeof(void), "SetPrimitivePropertyPrivilege",
                                                                                         typeof(int), typeof(IPropertyPrivilege));

            MethodInstance template_m_getRelationPropertyPrivilege = new MethodInstance(null, typeof(IPrivilege), typeof(IPropertyPrivilege),
                                                                                        "GetRelationPropertyPrivilege", typeof(int));

            MethodInstance template_m_setRelationPropertyPrivilege = new MethodInstance(null, MethodAttributes.Family, typeof(void), "SetRelationPropertyPrivilege",
                                                                                        typeof(int), typeof(IPropertyPrivilege));

            ImplementGetSetPropertyPrivilege(metaData.PrimitiveMembers, template_m_getPrimitivePropertyPrivilege, template_m_setPrimitivePropertyPrivilege);
            ImplementGetSetPropertyPrivilege(metaData.RelationMembers, template_m_getRelationPropertyPrivilege, template_m_setRelationPropertyPrivilege);

            {
                IMethodVisitor mg = VisitMethod(new MethodInstance(null, typeof(IPrivilege), typeof(bool), "get_CreateAllowed"));
                mg.Push(create);
                mg.ReturnValue();
                mg.EndMethod();
            }
            {
                IMethodVisitor mg = VisitMethod(new MethodInstance(null, typeof(IPrivilege), typeof(bool), "get_ReadAllowed"));
                mg.Push(read);
                mg.ReturnValue();
                mg.EndMethod();
            }
            {
                IMethodVisitor mg = VisitMethod(new MethodInstance(null, typeof(IPrivilege), typeof(bool), "get_UpdateAllowed"));
                mg.Push(update);
                mg.ReturnValue();
                mg.EndMethod();
            }
            {
                IMethodVisitor mg = VisitMethod(new MethodInstance(null, typeof(IPrivilege), typeof(bool), "get_DeleteAllowed"));
                mg.Push(delete);
                mg.ReturnValue();
                mg.EndMethod();
            }
            {
                IMethodVisitor mg = VisitMethod(new MethodInstance(null, typeof(IPrivilege), typeof(bool), "get_ExecuteAllowed"));
                mg.Push(execute);
                mg.ReturnValue();
                mg.EndMethod();
            }
            {
                IMethodVisitor mg = VisitMethod(new MethodInstance(null, typeof(IPrivilege), typeof(IPropertyPrivilege), "GetDefaultPropertyPrivilegeIfValid"));
                mg.PushNull();
                mg.ReturnValue();
                mg.EndMethod();
            }
            ImplementConstructor(template_m_setPrimitivePropertyPrivilege, template_m_setRelationPropertyPrivilege);
            base.VisitEnd();
        }
Exemplo n.º 16
0
        protected void ImplementGetEntityType()
        {
            MethodInstance template_m_getEntityType = new MethodInstance(null, typeof(RootCacheValue), typeof(Type), "getEntityType");

            IMethodVisitor mv = VisitMethod(template_m_getEntityType);

            mv.Push(metaData.EntityType);
            mv.ReturnValue();
            mv.EndMethod();
        }
Exemplo n.º 17
0
 protected static void ImplementDefaultDelegatingMethod(IMethodVisitor mg, PropertyInstance p_compositeIdTemplate, PropertyInstance p_idMembers,
                                                        MethodInstance delegatedMethod)
 {
     mg.CallThisGetter(p_compositeIdTemplate);
     mg.CallThisGetter(p_idMembers);
     mg.LoadThis();
     mg.LoadArgs();
     mg.InvokeVirtual(delegatedMethod);
     mg.ReturnValue();
     mg.EndMethod();
 }
Exemplo n.º 18
0
 protected void ImplementSetUninitialized(PropertyInstance p_valueHolderContainerTemplate, PropertyInstance p_valueHolderContainerEntry)
 {
     {
         IMethodVisitor mv = VisitMethod(m_template_setUninitialized_Member);
         mv.CallThisGetter(p_valueHolderContainerEntry);
         mv.LoadThis();
         mv.LoadArgs();
         mv.InvokeVirtual(m_vhce_setUninitialized_Member);
         mv.ReturnValue();
         mv.EndMethod();
     }
 }
Exemplo n.º 19
0
        protected void ImplementGetPrimitive(Member[] primitiveMember, FieldInstance[] f_primitives, FieldInstance[] f_nullFlags)
        {
            MethodInstance template_m_getPrimitive = new MethodInstance(null, typeof(RootCacheValue), typeof(Object), "GetPrimitive", typeof(int));

            IMethodVisitor mv = VisitMethod(template_m_getPrimitive);

            if (f_primitives.Length > 0)
            {
                Label   l_default    = mv.NewLabel();
                Label[] l_primitives = new Label[f_primitives.Length];
                for (int primitiveIndex = 0, size = f_primitives.Length; primitiveIndex < size; primitiveIndex++)
                {
                    l_primitives[primitiveIndex] = mv.NewLabel();
                }

                mv.LoadArg(0);
                mv.Switch(0, l_primitives.Length - 1, l_default, l_primitives);

                for (int primitiveIndex = 0, size = f_primitives.Length; primitiveIndex < size; primitiveIndex++)
                {
                    FieldInstance f_primitive = f_primitives[primitiveIndex];
                    FieldInstance f_nullFlag  = f_nullFlags[primitiveIndex];

                    mv.Mark(l_primitives[primitiveIndex]);

                    Label?l_fieldIsNull = null;

                    if (f_nullFlag != null)
                    {
                        l_fieldIsNull = mv.NewLabel();
                        // only do something if the field is non-null
                        mv.GetThisField(f_nullFlag);
                        mv.IfZCmp(CompareOperator.NE, l_fieldIsNull.Value);
                    }
                    mv.GetThisField(f_primitive);
                    mv.ValueOf(f_primitive.Type.Type);
                    mv.ReturnValue();

                    if (f_nullFlag != null)
                    {
                        mv.Mark(l_fieldIsNull.Value);
                        mv.PushNull();
                    }
                    mv.ReturnValue();
                }
                mv.Mark(l_default);
            }
            mv.ThrowException(typeof(ArgumentException), "Given relationIndex not known");
            mv.PushNull();
            mv.ReturnValue();
            mv.EndMethod();
        }
Exemplo n.º 20
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);
        }
Exemplo n.º 21
0
        protected void ImplementGetNullEquivalentValue(IPropertyInfo[] property)
        {
            IMethodVisitor mv           = VisitMethod(template_m_getNullEquivalentValue);
            Type           propertyType = property[property.Length - 1].PropertyType;

            mv.PushNullOrZero(propertyType);
            if (propertyType.IsPrimitive)
            {
                mv.Box(propertyType);
            }
            mv.ReturnValue();
            mv.EndMethod();
        }
Exemplo n.º 22
0
        public MethodInstance ImplementSwitchByIndex(MethodInstance method, String exceptionMessageOnIllegalIndex, int indexSize, ScriptWithIndex script)
        {
            IMethodVisitor mv = VisitMethod(method);

            if (indexSize == 0)
            {
                mv.ThrowException(typeof(ArgumentException), exceptionMessageOnIllegalIndex);
                mv.PushNull();
                mv.ReturnValue();
                mv.EndMethod();
                return(mv.Method);
            }

            Label l_default = mv.NewLabel();

            Label[] l_fields = new Label[indexSize];
            for (int index = 0, size = indexSize; index < size; index++)
            {
                l_fields[index] = mv.NewLabel();
            }

            mv.LoadArg(0);
            mv.VisitTableSwitchInsn(0, l_fields.Length - 1, l_default, l_fields);

            for (int index = 0, size = l_fields.Length; index < size; index++)
            {
                mv.Mark(l_fields[index]);

                script(mv, index);
            }
            mv.Mark(l_default);

            mv.ThrowException(typeof(ArgumentException), "Given relationIndex not known");
            mv.PushNull();
            mv.ReturnValue();
            mv.EndMethod();
            return(mv.Method);
        }
Exemplo n.º 23
0
        protected void ImplementGetEntityType(IPropertyInfo[] property)
        {
            IMethodVisitor  mv         = VisitMethod(template_m_getEntityType);
            Type            entityType = this.entityType;
            IEntityMetaData metaData   = entityMetaDataProvider.GetMetaData(entityType, true);

            if (metaData != null)
            {
                entityType = metaData.EntityType;
            }
            mv.Push(entityType);
            mv.ReturnValue();
            mv.EndMethod();
        }
Exemplo n.º 24
0
        public virtual MethodInstance ImplementSetter(MethodInstance method, FieldInstance field)
        {
            ParamChecker.AssertParamNotNull(method, "method");
            ParamChecker.AssertParamNotNull(field, "field");
            IMethodVisitor mg = VisitMethod(method);

            mg.PutThisField(field, delegate(IMethodVisitor mg2)
            {
                mg2.LoadArg(0);
            });
            mg.ReturnVoidOrThis();
            mg.EndMethod();
            return(MethodInstance.FindByTemplate(method, false));
        }
Exemplo n.º 25
0
        protected void ImplementGetBaseType()
        {
            MethodInstance getBaseType = MethodInstance.FindByTemplate(template_m_getBaseType, true);

            if (getBaseType != null)
            {
                return;
            }
            IBytecodeBehaviorState state = State;
            IMethodVisitor         mg    = VisitMethod(template_m_getBaseType);

            mg.Push(state.OriginalType);
            mg.ReturnValue();
            mg.EndMethod();
        }
Exemplo n.º 26
0
        public virtual PropertyInstance ImplementLazyInitProperty(PropertyInstance property, Script script, params String[] fireThisOnPropertyNames)
        {
            FieldInstance  field          = ImplementField(new FieldInstance(FieldAttributes.Private, "f_" + property.Name, property.PropertyType));
            IMethodVisitor mv             = VisitMethod(property.Getter);
            Label          returnInstance = mv.NewLabel();

            mv.GetThisField(field);
            mv.IfNonNull(returnInstance);
            mv.PutThisField(field, script);
            mv.Mark(returnInstance);
            mv.GetThisField(field);
            mv.ReturnValue();
            mv.EndMethod();
            return(FireThisOnPropertyChange(property, fireThisOnPropertyNames));
        }
        protected void ImplementConstructor(PropertyInstance p_embeddedMemberTemplate)
        {
            HashSet <Member> alreadyHandledFirstMembers = new HashSet <Member>();

            List <Script> scripts = new List <Script>();

            {
                Script script = HandleMember(p_embeddedMemberTemplate, metaData.IdMember, alreadyHandledFirstMembers);
                if (script != null)
                {
                    scripts.Add(script);
                }
            }
            foreach (Member member in metaData.PrimitiveMembers)
            {
                Script script = HandleMember(p_embeddedMemberTemplate, member, alreadyHandledFirstMembers);
                if (script != null)
                {
                    scripts.Add(script);
                }
            }
            foreach (RelationMember member in metaData.RelationMembers)
            {
                Script script = HandleMember(p_embeddedMemberTemplate, member, alreadyHandledFirstMembers);
                if (script != null)
                {
                    scripts.Add(script);
                }
            }
            if (scripts.Count == 0)
            {
                return;
            }
            OverrideConstructors(delegate(IClassVisitor cv, ConstructorInstance superConstructor)
            {
                IMethodVisitor mv = cv.VisitMethod(superConstructor);
                mv.LoadThis();
                mv.LoadArgs();
                mv.InvokeSuperOfCurrentMethod();

                foreach (Script script in scripts)
                {
                    script(mv);
                }
                mv.ReturnValue();
                mv.EndMethod();
            });
        }
Exemplo n.º 28
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.º 29
0
        protected void ImplementHashCodeMethod(PropertyInstance p_entityEqualsTemplate)
        {
            MethodInstance methodTemplate = new MethodInstance(null, typeof(Object), typeof(int), "GetHashCode");
            MethodInstance method         = MethodInstance.FindByTemplate(methodTemplate, true);

            if (NewType.GetType(typeof(Object)).Equals(method.Owner) || method.Access.HasFlag(MethodAttributes.Abstract))
            {
                IMethodVisitor mg = VisitMethod(methodTemplate);
                mg.CallThisGetter(p_entityEqualsTemplate);
                mg.LoadThis();
                mg.LoadArgs();
                mg.InvokeVirtual(entityEquals_HashCode);
                mg.ReturnValue();
                mg.EndMethod();
            }
        }
Exemplo n.º 30
0
 public virtual PropertyInstance ImplementProperty(PropertyInstance property, Script getterScript, Script setterScript)
 {
     if (getterScript != null)
     {
         IMethodVisitor mv = VisitMethod(property.Getter);
         getterScript.Invoke(mv);
         mv.EndMethod();
     }
     if (setterScript != null)
     {
         IMethodVisitor mv = VisitMethod(property.Setter);
         setterScript.Invoke(mv);
         mv.EndMethod();
     }
     return(PropertyInstance.FindByTemplate(property, false));
 }