示例#1
0
 public virtual void LoadArgs()
 {
     if (mv != null)
     {
         mv.LoadArgs();
     }
 }
示例#2
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();
            }
        }
示例#3
0
        protected void ImplementPropertyChanged(PropertyInstance p_propertyChangeTemplate)
        {
            MethodInstance m_propertyChanged_super = MethodInstance.FindByTemplate(template_m_PropertyChanged, true);
            IMethodVisitor mv = VisitMethod(template_m_PropertyChanged);

            if (m_propertyChanged_super != null)
            {
                mv.LoadThis();
                mv.LoadArgs();
                mv.InvokeSuperOfCurrentMethod();
            }
            mv.CallThisGetter(p_propertyChangeTemplate);
            mv.LoadThis();
            mv.LoadArgs();
            // call PCT.HandlePropertyChange(this, sender, arg)
            mv.InvokeVirtual(m_handlePropertyChange);
            mv.ReturnValue();
            mv.EndMethod();
        }
示例#4
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();
 }
示例#5
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();
     }
 }
        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();
            });
        }
示例#7
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();
            }
        }
示例#8
0
        protected void ImplementHashCode()
        {
            PropertyInstance p_objRefTemplate = GetObjRefTemplatePI(this);

            MethodInstance method = MethodInstance.FindByTemplate(template_m_hashCode, true);

            if (method == null || method.Access.HasFlag(MethodAttributes.Abstract))
            {
                IMethodVisitor mg = VisitMethod(template_m_hashCode);
                mg.CallThisGetter(p_objRefTemplate);
                mg.LoadThis();
                mg.LoadArgs();
                mg.InvokeVirtual(m_objRef_hashCode);
                mg.ReturnValue();
                mg.EndMethod();
            }
        }
示例#9
0
        public virtual IMethodVisitor StartOverrideWithSuperCall(MethodInstance superMethod)
        {
            IBytecodeBehaviorState state = State;

            NewType superType = NewType.GetType(state.CurrentType);

            if (!superType.Equals(superMethod.Owner))
            {
                throw new ArgumentException("Not a method of " + state.CurrentType + ": " + superMethod);
            }
            IMethodVisitor mg = VisitMethod(superMethod);

            mg.LoadThis();
            mg.LoadArgs();
            mg.InvokeSuper(superMethod);

            return(mg);
        }
示例#10
0
 protected void ImplementSelfGetter(PropertyInstance p_valueHolderContainerTemplate)
 {
     NewType        owner     = State.NewType;
     MethodInstance m_getSelf = new MethodInstance(owner, typeof(IValueHolderContainer), typeof(IObjRelation), "Get__Self", typeof(int));
     {
         // public IObjRelation getSelf(String memberName)
         // {
         // return ValueHolderContainerTemplate.GetSelf(this, relationIndex);
         // }
         IMethodVisitor mv = VisitMethod(m_getSelf);
         mv.CallThisGetter(p_valueHolderContainerTemplate);
         // this
         mv.LoadThis();
         // relationIndex
         mv.LoadArgs();
         mv.InvokeVirtual(m_template_getSelf);
         mv.ReturnValue();
         mv.EndMethod();
     }
 }
示例#11
0
        protected void ImplementRelationSetter(String propertyName, MethodInstance m_set_template, FieldInstance f_initialized, FieldInstance f_objRefs)
        {
            // public void setPropertyName(String propertyName)
            // {
            // PropertyName$initialized = true;
            // PropertyName$objRefs = null;
            // super.setPropertyName(propertyName);
            // }
            MethodInstance m_set;
            {
                IMethodVisitor mg = base.VisitMethod(m_set_template);
                m_set = mg.Method;
                mg.PutThisField(f_initialized, delegate(IMethodVisitor mv2)
                {
                    mg.PushEnum(ValueHolderState.INIT);
                });
                mg.PutThisField(f_objRefs, delegate(IMethodVisitor mv2)
                {
                    mv2.PushNull();
                });
                mg.LoadThis();
                mg.LoadArgs();
                mg.InvokeSuperOfCurrentMethod();
                mg.ReturnVoidOrThis();
                mg.EndMethod();
            }

            // public void setPropertyName$NoInit(String propertyName)
            // {
            // super.setPropertyName(propertyName);
            // }
            {
                String         noInitSetMethodName = ValueHolderIEC.GetSetterNameOfRelationPropertyWithNoInit(propertyName);
                IMethodVisitor mv = base.VisitMethod(m_set.Access, noInitSetMethodName, m_set.ReturnType, m_set.Parameters);
                mv.LoadThis();
                mv.LoadArgs();
                mv.InvokeSuper(m_set);
                mv.ReturnVoidOrThis();
                mv.EndMethod();
            }
        }
示例#12
0
        protected void ImplementPropertyChangeConfigurable()
        {
            String fieldName = "__propertyChangeActive";

            if (State.GetAlreadyImplementedField(fieldName) != null)
            {
                if (properties == null)
                {
                    throw new Exception("It seems that this visitor has been executing twice");
                }
                return;
            }
            else if (properties != null)
            {
                // do not apply in this case
                return;
            }
            FieldInstance f_propertyChangeActive = ImplementField(new FieldInstance(FieldAttributes.Private, fieldName, typeof(bool)));

            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]);
                IMethodVisitor      mv = VisitMethod(ci);
                mv.LoadThis();
                mv.LoadArgs();
                mv.InvokeSuperOfCurrentMethod();

                mv.PutThisField(f_propertyChangeActive, delegate(IMethodVisitor mg)
                {
                    mg.Push(true);
                });
                mv.ReturnValue();
                mv.EndMethod();
            }
            ImplementGetter(template_m_isPropertyChangeActive, f_propertyChangeActive);
            ImplementSetter(template_m_setPropertyChangeActive, f_propertyChangeActive);
        }
示例#13
0
        protected void ImplementConstructor(MethodInstance template_m_setPrimitivePropertyPrivilege, MethodInstance template_m_setRelationPropertyPrivilege)
        {
            IBytecodeBehaviorState state       = State;
            ConstructorInfo        constructor = state.CurrentType.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { typeof(bool), typeof(bool), typeof(bool), typeof(bool), typeof(bool),
                                                                                                                                                                           typeof(IPropertyPrivilege[]), typeof(IPropertyPrivilege[]) }, null);
            ConstructorInstance c_method = new ConstructorInstance(constructor);

            IMethodVisitor mg = VisitMethod(c_method);

            mg.LoadThis();
            mg.LoadArgs();
            mg.InvokeConstructor(c_method);

            Type propertyPrivilegeType = typeof(IPropertyPrivilege);

            for (int primitiveIndex = 0, size = metaData.PrimitiveMembers.Length; primitiveIndex < size; primitiveIndex++)
            {
                mg.LoadThis();
                mg.Push(primitiveIndex);
                mg.LoadArg(5);
                mg.Push(primitiveIndex);
                mg.ArrayLoad(propertyPrivilegeType);
                mg.InvokeVirtual(template_m_setPrimitivePropertyPrivilege);
            }
            for (int relationIndex = 0, size = metaData.RelationMembers.Length; relationIndex < size; relationIndex++)
            {
                mg.LoadThis();
                mg.Push(relationIndex);
                mg.LoadArg(6);
                mg.Push(relationIndex);
                mg.ArrayLoad(propertyPrivilegeType);
                mg.InvokeVirtual(template_m_setRelationPropertyPrivilege);
            }

            mg.ReturnValue();
            mg.EndMethod();
        }
示例#14
0
        protected void ImplementToString()
        {
            PropertyInstance p_objRefTemplate = GetObjRefTemplatePI(this);

            MethodInstance methodSb;
            {
                methodSb = MethodInstance.FindByTemplate(template_m_toStringSb, true);
                if (methodSb == null || methodSb.Access.HasFlag(MethodAttributes.Abstract))
                {
                    IMethodVisitor mg = VisitMethod(template_m_toStringSb);
                    mg.CallThisGetter(p_objRefTemplate);
                    mg.LoadThis();
                    mg.LoadArgs();
                    mg.InvokeVirtual(m_objRef_toStringSb);
                    mg.ReturnValue();
                    mg.EndMethod();
                    methodSb = mg.Method;
                }
            }
            {
                MethodInstance method = MethodInstance.FindByTemplate(template_m_toString, true);
                if (method == null || NewType.GetType(typeof(Object)).Equals(method.Owner) || methodSb.Access.HasFlag(MethodAttributes.Abstract))
                {
                    IMethodVisitor    mg     = VisitMethod(template_m_toString);
                    LocalVariableInfo loc_sb = mg.NewLocal(typeof(StringBuilder));
                    mg.LoadThis();
                    mg.NewInstance(c_stringBuilder, null);
                    mg.StoreLocal(loc_sb);
                    mg.LoadLocal(loc_sb);
                    mg.InvokeVirtual(methodSb);
                    mg.LoadLocal(loc_sb);
                    mg.InvokeVirtual(new MethodInstance(null, typeof(StringBuilder), typeof(String), "ToString"));
                    mg.ReturnValue();
                    mg.EndMethod();
                }
            }
        }
示例#15
0
        /**
         * {@inheritDoc}
         */
        public override void VisitEnd()
        {
            if (!HasValidConstructor())
            {
                IBytecodeBehaviorState state        = State;
                ConstructorInfo[]      constructors = state.CurrentType.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);

                foreach (ConstructorInfo constructor in constructors)
                {
                    MethodAttributes access = constructor.Attributes;
                    access &= ~MethodAttributes.Family;
                    access &= ~MethodAttributes.Private;
                    access |= MethodAttributes.Public;
                    ConstructorInstance c_method = new ConstructorInstance(access, TypeUtil.GetClassesToTypes(constructor.GetParameters()));

                    IMethodVisitor mg = VisitMethod(c_method);
                    mg.LoadThis();
                    mg.LoadArgs();
                    mg.InvokeConstructor(new ConstructorInstance(constructor));

                    mg.ReturnValue();
                    mg.EndMethod();
                }
                if (constructors.Length == 0)
                {
                    // Implement "first" default constructor
                    ConstructorInstance c_method = new ConstructorInstance(typeof(Object).GetConstructor(null));
                    IMethodVisitor      ga       = VisitMethod(c_method);
                    ga.LoadThis();
                    ga.InvokeConstructor(c_method);
                    ga.ReturnValue();
                    ga.EndMethod();
                }
            }
            base.VisitEnd();
        }
示例#16
0
        protected void ImplementConstructors()
        {
            if (metaData.RelationMembers.Length == 0)
            {
                return;
            }
            RelationMember[]       relationMembers = metaData.RelationMembers;
            List <FieldInstance[]> fieldsList      = new List <FieldInstance[]>();

            for (int a = relationMembers.Length; a-- > 0;)
            {
                RelationMember relationMember = relationMembers[a];
                relationMember = (RelationMember)GetApplicableMember(relationMember);
                if (relationMember == null)
                {
                    // member is handled in another type
                    continue;
                }
                String        propertyName = relationMember.Name;
                String        fieldName    = ValueHolderIEC.GetObjRefsFieldName(propertyName);
                FieldInstance field        = State.GetAlreadyImplementedField(fieldName);

                String        fieldName2 = ValueHolderIEC.GetInitializedFieldName(propertyName);
                FieldInstance field2     = State.GetAlreadyImplementedField(fieldName2);

                fieldsList.Add(new FieldInstance[] { field, field2 });
            }
            if (fieldsList.Count == 0)
            {
                return;
            }
            PropertyInstance p_emptyRelations = ImplementAssignedReadonlyProperty("EmptyRelations", ObjRef.EMPTY_ARRAY);

            OverrideConstructors(delegate(IClassVisitor cv, ConstructorInstance superConstructor)
            {
                IMethodVisitor mv = cv.VisitMethod(superConstructor);
                mv.LoadThis();
                mv.LoadArgs();
                mv.InvokeSuperOfCurrentMethod();

                LocalVariableInfo loc_emptyRelations = mv.NewLocal <IObjRef[]>();
                LocalVariableInfo loc_lazyState      = mv.NewLocal <ValueHolderState>();
                mv.CallThisGetter(p_emptyRelations);
                mv.StoreLocal(loc_emptyRelations);
                mv.PushEnum(ValueHolderState.LAZY);
                mv.StoreLocal(loc_lazyState);
                foreach (FieldInstance[] fields in fieldsList)
                {
                    mv.PutThisField(fields[0], delegate(IMethodVisitor mv2)
                    {
                        mv2.LoadLocal(loc_emptyRelations);
                    });
                    mv.PutThisField(fields[1], delegate(IMethodVisitor mv2)
                    {
                        mv2.LoadLocal(loc_lazyState);
                    });
                }
                mv.ReturnValue();
                mv.EndMethod();
            });
        }
        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();
        }