public override void EmitStore(AffeCompilerState state, Expression expr) { this.Target.Emit(state); state.ILGenerator.Emit(OpCodes.Ldstr, this.Member.Name); expr.Emit(state); state.ILGenerator.Emit(OpCodes.Call, PerformWriteInvokeInfo); }
public override void EmitStore(AffeCompilerState state, Expression expr) { string target = this.Identifier.Name; Symbol s = state.Scope.GetSymbol(target); if (s == null) { // This should never happen if the analysis was run. throw new AffeException("Unknown symbol.", this); } if (!(s is VariableSymbol) && !(s is FieldSymbol)) throw new AffeException("Assignment target is not a variable or field.", this); if (s is FieldSymbol) { FieldInfo fi = ((FieldSymbol) s).Field; if (fi.IsInitOnly) throw new AffeException("Cannot assign to a read-only field.", this); if (!fi.IsStatic) state.ILGenerator.Emit(OpCodes.Ldarg_0); } expr.Emit(state); if (s is VariableSymbol) { state.ILGenerator.Emit(OpCodes.Stloc, ((VariableSymbol) s).Local); } else { FieldInfo fi = ((FieldSymbol) s).Field; state.ILGenerator.Emit(fi.IsStatic ? OpCodes.Stsfld : OpCodes.Stfld, fi); } }
public override void EmitStore(AffeCompilerState state, Expression expr) { MethodInfo setter = null; if (this.mIndexer != null) setter = this.mIndexer.GetSetMethod(); if (setter == null || !setter.IsStatic) this.Expression.Emit(state); foreach (Expression e in this.Index) e.Emit(state); expr.Emit(state); if (this.mIndexer != null) { if (setter == null) throw new AffeException("Indexer is read-only.", this); state.ILGenerator.Emit(setter.IsStatic ? OpCodes.Call : OpCodes.Callvirt, setter); } else { //state.ILGenerator.Emit(OpCodes.Stelem, this.Type); EmitStelem(state.ILGenerator, this.Type); } }
public override void EmitStore(AffeCompilerState state, Expression expr) { if (!this.CanWrite) throw new AffeException("Target is read-only.", this); PropertyInfo pi = this.mMemberInfo as PropertyInfo; FieldInfo fi = this.mMemberInfo as FieldInfo; bool stc = (pi != null) ? pi.GetGetMethod().IsStatic : fi.IsStatic; if (!stc) this.Target.Emit(state); expr.Emit(state); if (pi != null) state.ILGenerator.Emit(stc ? OpCodes.Call : OpCodes.Callvirt, pi.GetSetMethod()); else state.ILGenerator.Emit(stc ? OpCodes.Stsfld : OpCodes.Stfld, fi); }