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(); }
public virtual void PushNull() { if (mv != null) { mv.PushNull(); } }
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(); }
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(); }
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); }
public static FieldInstance ImplementNativeField(IClassVisitor cv, Member member, MethodInstance m_get, MethodInstance m_set) { if (member == null) { // NoOp implementation { IMethodVisitor mv = cv.VisitMethod(m_get); mv.PushNull(); mv.ReturnValue(); mv.EndMethod(); } { IMethodVisitor mv = cv.VisitMethod(m_set); mv.ReturnValue(); mv.EndMethod(); } return(null); } if (member is CompositeIdMember || (!member.RealType.IsPrimitive && ImmutableTypeSet.GetUnwrappedType(member.RealType) == null)) { // no business case for any complex efforts FieldInstance f_id2 = cv.ImplementField(new FieldInstance(FieldAttributes.Private, GetFieldName(member), typeof(Object))); cv.ImplementGetter(m_get, f_id2); cv.ImplementSetter(m_set, f_id2); return(f_id2); } Type nativeType = member.RealType; if (!nativeType.IsPrimitive) { nativeType = ImmutableTypeSet.GetUnwrappedType(nativeType); } FieldInstance f_id = cv.ImplementField(new FieldInstance(FieldAttributes.Private, GetFieldName(member), nativeType)); { IMethodVisitor mv = cv.VisitMethod(m_get); mv.GetThisField(f_id); mv.ValueOf(nativeType); mv.ReturnValue(); mv.EndMethod(); } { IMethodVisitor mv = cv.VisitMethod(m_set); mv.PutThisField(f_id, delegate(IMethodVisitor mg) { Label l_isNotNull = mg.NewLabel(); Label l_finish = mg.NewLabel(); mg.LoadArg(0); mg.IfNonNull(l_isNotNull); mg.PushNullOrZero(nativeType); mg.GoTo(l_finish); mg.Mark(l_isNotNull); mg.LoadArg(0); mg.Unbox(nativeType); mg.Mark(l_finish); }); mv.ReturnValue(); mv.EndMethod(); } return(f_id); }
protected PropertyInstance ImplementNotifyPropertyChangedSource(PropertyInstance p_propertyChangeTemplate, FieldInstance f_propertyChangeSupport) { MethodInstance m_onPropertyChanged_Values = MethodInstance.FindByTemplate(template_m_onPropertyChanged_Values, true); if (m_onPropertyChanged_Values == null) { IMethodVisitor mv = VisitMethod(template_m_onPropertyChanged_Values); mv.CallThisGetter(p_propertyChangeTemplate); mv.LoadThis(); mv.GetThisField(f_propertyChangeSupport); // getMethodHandle(sender, propertyName) mv.CallThisGetter(p_propertyChangeTemplate); mv.LoadThis(); mv.LoadArg(0); mv.InvokeVirtual(m_getMethodHandle); mv.LoadArg(1); mv.LoadArg(2); // firePropertyChange(sender, propertyChangeSupport, property, oldValue, newValue) mv.InvokeVirtual(m_firePropertyChange); mv.PopIfReturnValue(m_firePropertyChange); mv.ReturnVoidOrThis(); mv.EndMethod(); m_onPropertyChanged_Values = mv.Method; } MethodInstance m_onPropertyChanged = MethodInstance.FindByTemplate(template_m_onPropertyChanged, true); if (m_onPropertyChanged == null) { IMethodVisitor mv = VisitMethod(template_m_onPropertyChanged); mv.LoadThis(); mv.LoadArg(0); mv.PushNull(); mv.PushNull(); mv.InvokeVirtual(m_onPropertyChanged_Values); mv.PopIfReturnValue(m_onPropertyChanged_Values); mv.ReturnVoidOrThis(); mv.EndMethod(); m_onPropertyChanged = mv.Method; } PropertyInstance p_pceHandlers = PropertyInstance.FindByTemplate(p_propertyChangeSupport, true); if (p_pceHandlers == null) { HideFromDebug(ImplementGetter(p_propertyChangeSupport.Getter, f_propertyChangeSupport)); p_pceHandlers = PropertyInstance.FindByTemplate(p_propertyChangeSupport, false); } if (EmbeddedEnhancementHint.HasMemberPath(State.Context)) { PropertyInstance p_parentEntity = EmbeddedTypeVisitor.GetParentObjectProperty(this); if (MethodInstance.FindByTemplate(p_parentChildEventHandler.Getter, true) == null) { IMethodVisitor mv = VisitMethod(p_parentChildEventHandler.Getter); mv.CallThisGetter(p_parentEntity); mv.InvokeInterface(p_parentChildEventHandler.Getter); mv.ReturnValue(); mv.EndMethod(); HideFromDebug(mv.Method); } if (MethodInstance.FindByTemplate(p_collectionEventHandler.Getter, true) == null) { IMethodVisitor mv = VisitMethod(p_collectionEventHandler.Getter); mv.CallThisGetter(p_parentEntity); mv.InvokeInterface(p_collectionEventHandler.Getter); mv.ReturnValue(); mv.EndMethod(); HideFromDebug(mv.Method); } } else { if (MethodInstance.FindByTemplate(p_parentChildEventHandler.Getter, true) == null) { HideFromDebug(ImplementLazyInitProperty(p_parentChildEventHandler, delegate(IMethodVisitor mv) { MethodInstance method = new MethodInstance(null, typeof(NotifyPropertyChangedClassVisitor), typeof(PropertyChangedEventHandler), "CreateParentChildEventHandler", typeof(Object)); mv.LoadThis(); mv.InvokeStatic(method); })); } if (MethodInstance.FindByTemplate(p_collectionEventHandler.Getter, true) == null) { HideFromDebug(ImplementLazyInitProperty(p_collectionEventHandler, delegate(IMethodVisitor mv) { MethodInstance method = new MethodInstance(null, typeof(NotifyPropertyChangedClassVisitor), typeof(NotifyCollectionChangedEventHandler), "CreateCollectionEventHandler", typeof(Object)); mv.LoadThis(); mv.InvokeStatic(method); })); } } //MethodAttributes ma = MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig; //{ // ConstructorInfo pceaCI = typeof(PropertyChangedEventArgs).GetConstructor(new Type[] { typeof(String) }); // MethodBuilder mb = VisitorUtil.DefineMethod(vs, onPropertyChangedMI_string, ma); // ILGenerator gen = mb.GetILGenerator(); // gen.Emit(OpCodes.Ldarg_0); // gen.Emit(OpCodes.Ldarg_1); // gen.Emit(OpCodes.Newobj, pceaCI); // gen.Emit(OpCodes.Call, onPropertyChangedMI_pceArg); // gen.Emit(OpCodes.Ret); //} //{ // MethodBuilder mb = VisitorUtil.DefineMethod(vs, onPropertyChangedMI_pceArg, ma); // ILGenerator gen = mb.GetILGenerator(); // gen.Emit(OpCodes.Ldarg_0); // gen.Emit(OpCodes.Call, pctPI.GetGetMethod()); // gen.Emit(OpCodes.Ldarg_0); // gen.Emit(OpCodes.Ldarg_1); // gen.Emit(OpCodes.Call, FirePropertyChangedMI); // gen.Emit(OpCodes.Ret); //} // List<PropertyChangedEventHandler> PropertyChangedEventHandlers { get; } //void OnPropertyChanged(String propertyName); //void OnPropertyChanged(PropertyChangedEventArgs args); return(p_pceHandlers); }
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(); }