Ejemplo n.º 1
0
 public virtual void InvokeConstructor(ConstructorInfo constructor)
 {
     if (mv != null)
     {
         mv.InvokeConstructor(constructor);
     }
 }
Ejemplo n.º 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();
        }
Ejemplo n.º 3
0
        protected void ImplementEmbeddedConstructor(FieldInstance f_parentObject, ConstructorInstance superConstructor)
        {
            if (superConstructor.Parameters.Length > 0 && superConstructor.Parameters[0].Equals(f_parentObject.Type))
            {
                // super constructor already enhanced
                return;
            }
            bool baseIsEnhanced = false;//EntityEnhancer.IsEnhancedType(vs.CurrentType);

            NewType[] parameters = superConstructor.Parameters;
            NewType[] types;
            if (baseIsEnhanced)
            {
                // Only Pass-through constructors necessary. So signature remains the same
                types = null;//TypeUtil.GetClassesToTypes(..GetTypes(parameters);
            }
            else
            {
                types = new NewType[parameters.Length + 1];
                for (int a = parameters.Length + 1; a-- > 1;)
                {
                    types[a] = parameters[a - 1];
                }
                types[0] = f_parentObject.Type;
            }
            IMethodVisitor mv = VisitMethod(new ConstructorInstance(MethodAttributes.Public, types));

            mv.LoadThis();
            for (int a = 1, size = types.Length; a < size; a++)
            {
                mv.LoadArg(a); // Load constructor argument one by one, starting with the 2nd constructor argument
            }
            mv.InvokeConstructor(superConstructor);
            mv.PutThisField(f_parentObject, delegate(IMethodVisitor mv2)
            {
                mv2.LoadArg(0);
            });
            mv.ReturnValue();
            mv.EndMethod();
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
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();
        }