private Expr ProcessRequires2(ExprCall e) { MethodDefinition mRequires = this.contractsRuntime.GetRequires(); Expr conditionExpr = e.Parameters.First(); Expr msgExpr = e.Parameters.ElementAt(1); string conditionText = this.GetConditionString(e); Expr conditionStringExpr = new ExprLoadConstant(this.methodInfo, conditionText); var call = new ExprCall(this.methodInfo, mRequires, new Expr [] { conditionExpr, msgExpr, conditionStringExpr }); this.contractRequiresInfo.Add(new ContractRequiresInfo(e, call)); return(call); }
protected override Expr VisitLoadConstant(ExprLoadConstant e) { this.Emit(e, () => { object v = e.Value; if (v == null) { return(this.il.Create(OpCodes.Ldnull)); } Type vType = v.GetType(); TypeCode vTypeCode = Type.GetTypeCode(vType); switch (vTypeCode) { case TypeCode.Int32: int value = (int)v; switch (value) { case -1: return(this.il.Create(OpCodes.Ldc_I4_M1)); case 0: return(this.il.Create(OpCodes.Ldc_I4_0)); case 1: return(this.il.Create(OpCodes.Ldc_I4_1)); case 2: return(this.il.Create(OpCodes.Ldc_I4_2)); case 3: return(this.il.Create(OpCodes.Ldc_I4_3)); case 4: return(this.il.Create(OpCodes.Ldc_I4_4)); case 5: return(this.il.Create(OpCodes.Ldc_I4_5)); case 6: return(this.il.Create(OpCodes.Ldc_I4_6)); case 7: return(this.il.Create(OpCodes.Ldc_I4_7)); case 8: return(this.il.Create(OpCodes.Ldc_I4_8)); default: if (value >= -128 && value <= 127) { return(this.il.Create(OpCodes.Ldc_I4_S, (sbyte)value)); } else { return(this.il.Create(OpCodes.Ldc_I4, value)); } } // Required due to bug in compiler throw new NotSupportedException(); case TypeCode.Single: return(this.il.Create(OpCodes.Ldc_R4, (float)v)); case TypeCode.Double: return(this.il.Create(OpCodes.Ldc_R8, (double)v)); case TypeCode.String: return(this.il.Create(OpCodes.Ldstr, (string)v)); default: throw new NotSupportedException("Cannot handle constant: " + vTypeCode); } // Required due to bug in compiler throw new NotSupportedException(); }); return(e); }
protected virtual Expr VisitLoadConstant (ExprLoadConstant e) { return e; }