public static void CacheModificationInternalUpdate(PropertyInstance p_cacheModification, IMethodVisitor mg, Script script) { LocalVariableInfo loc_cacheModification = mg.NewLocal <ICacheModification>(); LocalVariableInfo loc_oldActive = mg.NewLocal <bool>(); // ICacheModification cacheModification = this.cacheModification; mg.CallThisGetter(p_cacheModification); mg.StoreLocal(loc_cacheModification); // boolean oldInternalUpdate = cacheModification.isInternalUpdate(); mg.LoadLocal(loc_cacheModification); mg.InvokeInterface(new MethodInstance(null, typeof(ICacheModification), typeof(bool), "get_InternalUpdate")); mg.StoreLocal(loc_oldActive); // callModificationInternalUpdate(cacheModification, oldInternalUpdate, true) mg.LoadLocal(loc_cacheModification); mg.LoadLocal(loc_oldActive); mg.Push(true); mg.InvokeStatic(m_callCacheModificationInternalUpdate); mg.TryFinally(script, delegate(IMethodVisitor mv2) { // callModificationInternalUpdate(cacheModification, oldInternalUpdate, false) mv2.LoadLocal(loc_cacheModification); mv2.LoadLocal(loc_oldActive); mv2.Push(false); mv2.InvokeStatic(m_callCacheModificationInternalUpdate); }); }
public virtual LocalVariableInfo NewLocal <T>() { if (mv != null) { return(mv.NewLocal <T>()); } throw new NotSupportedException(); }
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(); } } }
protected void ImplementPropertyChangeOnProperty(PropertyInstance propertyInfo, PropertyInstance p_propertyChangeTemplate, MethodInstance m_firePropertyChange, FieldInstance f_propertyChangeSupport) { // add property change detection and notification if (propertyInfo.Getter == null || propertyInfo.Setter == null) { return; } if (InitializeEmbeddedMemberVisitor.IsEmbeddedMember(metaData, propertyInfo.Name)) { return; } PropertyInstance p_getterMethodHandle = ImplementAssignedReadonlyProperty(propertyInfo.Name + "$MethodHandle", new MethodHandleValueResolver(PropertyInfoProvider, propertyInfo.Name)); Type propertyType = propertyInfo.PropertyType.Type; MethodInstance m_hasPropertyChanged = GetApplicableHasPropertyChangedOverload(propertyType); // check value type of last parameter bool isBoxingNeededForHasPropertyChanged = IsBoxingNeededForHasPropertyChangedOverload(m_hasPropertyChanged, propertyType); IMethodVisitor mg = VisitMethod(propertyInfo.Setter); Label l_finish = mg.NewLabel(); Label l_noOldValue = mg.NewLabel(); Label l_noChangeCheck = mg.NewLabel(); LocalVariableInfo loc_oldValue; if (isBoxingNeededForHasPropertyChanged) { loc_oldValue = mg.NewLocal(typeof(Object)); } else { loc_oldValue = mg.NewLocal(propertyType); } LocalVariableInfo loc_valueChanged = mg.NewLocal <bool>(); MethodInstance m_getSuper = EnhancerUtil.GetSuperGetter(propertyInfo); bool relationProperty = m_getSuper.Name.EndsWith(ValueHolderIEC.GetNoInitSuffix()); // initialize flag with false mg.Push(false); mg.StoreLocal(loc_valueChanged); // initialize oldValue with null mg.PushNullOrZero(loc_oldValue.LocalType); mg.StoreLocal(loc_oldValue); if (relationProperty) { // check if a setter call to an UNINITIALIZED relation occured with value null // if it the case there would be no PCE because oldValue & newValue are both null // but we need a PCE in this special case Label l_noSpecialHandling = mg.NewLabel(); FieldInstance f_state = State.GetAlreadyImplementedField(ValueHolderIEC.GetInitializedFieldName(propertyInfo.Name)); mg.GetThisField(f_state); mg.PushEnum(ValueHolderState.INIT); mg.IfCmp(typeof(ValueHolderState), CompareOperator.EQ, l_noSpecialHandling); mg.Push(true); mg.StoreLocal(loc_valueChanged); mg.Mark(l_noSpecialHandling); } // check if value should be checked to decide for a PCE mg.LoadLocal(loc_valueChanged); mg.IfZCmp(CompareOperator.NE, l_noOldValue); // get old field value calling super property getter mg.LoadThis(); mg.InvokeOnExactOwner(m_getSuper); if (isBoxingNeededForHasPropertyChanged) { mg.Box(propertyType); } mg.StoreLocal(loc_oldValue); mg.Mark(l_noOldValue); // set new field value calling super property setter mg.LoadThis(); mg.LoadArg(0); mg.InvokeOnExactOwner(EnhancerUtil.GetSuperSetter(propertyInfo)); mg.PopIfReturnValue(EnhancerUtil.GetSuperSetter(propertyInfo)); // check if value should be checked to decide for a PCE mg.LoadLocal(loc_valueChanged); mg.IfZCmp(CompareOperator.NE, l_noChangeCheck); LocalVariableInfo loc_newValue = null; if (isBoxingNeededForHasPropertyChanged) { loc_newValue = mg.NewLocal(typeof(Object)); // loc_1 Object newValue // Object loc_1 = (Object)value; mg.LoadArg(0); mg.Box(propertyType); mg.StoreLocal(loc_newValue); } mg.CallThisGetter(p_propertyChangeTemplate); // call HasPropertyChanged (static) mg.LoadThis(); // "this" as Object obj mg.Push(propertyInfo.Name); // String propertyName mg.LoadLocal(loc_oldValue); if (loc_newValue != null) { mg.LoadLocal(loc_newValue); } else { mg.LoadArg(0); } mg.InvokeVirtual(m_hasPropertyChanged); //// if (!result) //// { return; } mg.IfZCmp(CompareOperator.EQ, l_finish); mg.Mark(l_noChangeCheck); // call firePropertyChange on this mg.LoadThis(); // propertyChangeSupport mg.GetThisField(f_propertyChangeSupport); // property mg.CallThisGetter(p_getterMethodHandle); // oldValue mg.LoadLocal(loc_oldValue); if (!isBoxingNeededForHasPropertyChanged && propertyType.IsValueType) { // old value has not already been boxed but it is now necessary mg.ValueOf(propertyType); } // newValue if (loc_newValue != null) { mg.LoadLocal(loc_newValue); } else { mg.LoadArg(0); if (propertyType.IsValueType) { mg.ValueOf(propertyType); } } // firePropertyChange(propertyChangeSupport, property, oldValue, newValue) mg.InvokeVirtual(m_firePropertyChange); // return mg.Mark(l_finish); mg.ReturnVoidOrThis(); mg.EndMethod(); }
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(); }
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(); }
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(); }); }