Beispiel #1
0
 public virtual void IfNull(Label label)
 {
     if (mv != null)
     {
         mv.IfNull(label);
     }
 }
Beispiel #2
0
        /**
         * public boolean isToBeCreated() { return get__Id() == null; }
         *
         * @param owner
         */
        protected PropertyInstance ImplementToBeCreated(PropertyInstance p_toBeCreated)
        {
            IMethodVisitor mg = VisitMethod(p_toBeCreated.Getter);

            p_toBeCreated = PropertyInstance.FindByTemplate(p_toBeCreated, false);
            Member idMember = metaData.IdMember;

            if (idMember is CompositeIdMember)
            {
                List <String> names = new List <String>();
                foreach (Member itemMember in ((CompositeIdMember)idMember).Members)
                {
                    names.Add(itemMember.Name);
                }
                p_toBeCreated.AddAnnotation(c_fireThisOPC, new Object[] { names.ToArray() });
            }
            else
            {
                p_toBeCreated.AddAnnotation(c_fireThisOPC, idMember.Name);
            }

            Label trueLabel = mg.NewLabel();

            mg.LoadThis();
            mg.InvokeVirtual(GetIdMethodCreator.GetGetId());

            mg.IfNull(trueLabel);

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

            mg.Mark(trueLabel);

            mg.Push(true);
            mg.ReturnValue();
            mg.EndMethod();
            return(p_toBeCreated);
        }
Beispiel #3
0
        protected void ImplementGetValueIntern(MethodInstance template_m_getValue, IPropertyInfo[] propertyPath)
        {
            IMethodVisitor mv = VisitMethod(template_m_getValue);

            Type  declaringType = propertyPath[0].EntityType;
            Label l_finish      = mv.NewLabel();

            mv.LoadArg(0);
            Type typeOfArgumentOnStack = typeof(Object);

            for (int a = 0, size = propertyPath.Length - 1; a < size; a++)
            {
                typeOfArgumentOnStack = InvokeGetProperty(mv, propertyPath[a], typeOfArgumentOnStack);
                mv.Dup();
                mv.IfNull(l_finish);
            }
            IPropertyInfo lastProperty = propertyPath[propertyPath.Length - 1];

            typeOfArgumentOnStack = InvokeGetProperty(mv, lastProperty, typeOfArgumentOnStack);
            if (lastProperty.PropertyType.IsPrimitive)
            {
                Type pType = lastProperty.PropertyType;
                LocalVariableInfo loc_value = mv.NewLocal(pType);
                mv.StoreLocal(loc_value);
                mv.LoadLocal(loc_value);
                Label l_valueIsNonZero = mv.NewLabel();

                mv.IfZCmp(pType, CompareOperator.NE, l_valueIsNonZero);

                if (mv.Method.Parameters.Length == 2)
                {
                    Label l_nullAllowed = mv.NewLabel();
                    // check null-equi flag
                    mv.LoadArg(1);
                    mv.IfZCmp(CompareOperator.EQ, l_nullAllowed);
                    mv.PushNullOrZero(pType);
                    if (!mv.Method.ReturnType.Type.IsValueType)
                    {
                        mv.ValueOf(pType);
                    }
                    mv.ReturnValue();

                    mv.Mark(l_nullAllowed);
                }
                mv.PushNullOrZero(mv.Method.ReturnType);
                mv.ReturnValue();

                mv.Mark(l_valueIsNonZero);
                mv.LoadLocal(loc_value);
                mv.ValueOf(pType);
            }
            else if (lastProperty.PropertyType.IsValueType)
            {
                Type pType = lastProperty.PropertyType;

                MethodInfo m_hasValue = pType.GetMethod("get_HasValue");
                if (m_hasValue != null)
                {
                    LocalVariableInfo loc_value = mv.NewLocal(pType);
                    mv.StoreLocal(loc_value);
                    mv.LoadLocal(loc_value);

                    MethodInfo        m_getValue    = pType.GetMethod("get_Value");
                    LocalVariableInfo loc_realValue = mv.NewLocal(m_getValue.ReturnType);
                    Label             l_hasNoValue  = mv.NewLabel();

                    mv.InvokeOnExactOwner(m_hasValue);
                    mv.IfZCmp(CompareOperator.EQ, l_hasNoValue);
                    mv.LoadLocal(loc_value);
                    mv.InvokeOnExactOwner(m_getValue);
                    mv.StoreLocal(loc_realValue);
                    mv.LoadLocal(loc_realValue);
                    mv.IfZCmp(CompareOperator.EQ, l_hasNoValue);
                    mv.LoadLocal(loc_realValue);
                    if (!mv.Method.ReturnType.Type.IsValueType)
                    {
                        mv.ValueOf(m_getValue.ReturnType);
                    }
                    mv.ReturnValue();

                    mv.Mark(l_hasNoValue);

                    if (mv.Method.Parameters.Length == 2)
                    {
                        Label l_nullEquivalentValueAllowed = mv.NewLabel();
                        // check null-equi flag
                        mv.LoadArg(1);
                        mv.IfZCmp(CompareOperator.NE, l_nullEquivalentValueAllowed);
                        mv.PushNull();
                        mv.ReturnValue();

                        mv.Mark(l_nullEquivalentValueAllowed);
                    }
                    mv.PushNullOrZero(m_getValue.ReturnType);
                    if (!mv.Method.ReturnType.Type.IsValueType)
                    {
                        mv.ValueOf(m_getValue.ReturnType);
                    }
                }
                else
                {
                    mv.Box(pType);
                }
            }
            mv.Mark(l_finish);
            mv.ReturnValue();
            mv.EndMethod();
        }
Beispiel #4
0
        protected void ImplementSetPrimitives(Member[] primitiveMembers, FieldInstance[] f_primitives, FieldInstance[] f_nullFlags)
        {
            MethodInstance template_m_setPrimitives = new MethodInstance(null, typeof(RootCacheValue), typeof(void), "SetPrimitives", typeof(Object[]));

            IMethodVisitor    mv       = VisitMethod(template_m_setPrimitives);
            LocalVariableInfo loc_item = mv.NewLocal(objType);

            for (int primitiveIndex = 0, size = f_primitives.Length; primitiveIndex < size; primitiveIndex++)
            {
                FieldInstance f_primitive  = f_primitives[primitiveIndex];
                FieldInstance f_nullFlag   = f_nullFlags[primitiveIndex];
                Member        member       = primitiveMembers[primitiveIndex];
                Type          originalType = member.RealType;

                Script script_loadArrayValue = new Script(delegate(IMethodVisitor mg)
                {
                    mg.LoadArg(0);
                    mg.Push(primitiveIndex);
                    mg.ArrayLoad(objType);
                });

                Label l_finish = mv.NewLabel();

                if (f_nullFlag == null)
                {
                    if (!originalType.IsValueType)
                    {
                        mv.PutThisField(f_primitive, script_loadArrayValue);
                        continue;
                    }
                    script_loadArrayValue(mv);
                    mv.StoreLocal(loc_item);
                    mv.LoadLocal(loc_item);
                    mv.IfNull(l_finish);

                    mv.PutThisField(f_primitive, new Script(delegate(IMethodVisitor mg)
                    {
                        mg.LoadLocal(loc_item);
                        mg.Unbox(f_primitive.Type.Type);
                    }));

                    mv.Mark(l_finish);
                    continue;
                }

                Label l_itemIsNull = mv.NewLabel();

                script_loadArrayValue(mv);
                mv.StoreLocal(loc_item);

                mv.LoadLocal(loc_item);
                mv.IfNull(l_itemIsNull);

                mv.PutThisField(f_primitive, delegate(IMethodVisitor mg)
                {
                    mg.LoadLocal(loc_item);
                    mg.Unbox(f_primitive.Type.Type);
                });

                if (f_nullFlag != null)
                {
                    // field is a nullable numeric value in the entity, but a native numeric value in our RCV
                    mv.PutThisField(f_nullFlag, delegate(IMethodVisitor mg)
                    {
                        mg.Push(false);
                    });
                }

                mv.GoTo(l_finish);
                mv.Mark(l_itemIsNull);

                if (f_nullFlag != null)
                {
                    // field is a nullable numeric value in the entity, but a native numeric value in our RCV
                    mv.PutThisField(f_nullFlag, delegate(IMethodVisitor mg)
                    {
                        mg.Push(true);
                    });
                }
                else
                {
                    mv.PutThisField(f_primitive, delegate(IMethodVisitor mg)
                    {
                        mg.PushNullOrZero(f_primitive.Type.Type);
                    });
                }
                mv.Mark(l_finish);
            }
            mv.ReturnValue();
            mv.EndMethod();
        }