protected virtual Expr VisitLoadConstant (ExprLoadConstant e) { return e; }
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); } } 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); } }); return e; }
private Expr ProcessRequires1 (ExprCall e) { MethodDefinition mRequires = this.contractsRuntime.GetRequires (); Expr conditionExpr = e.Parameters.First (); Expr nullArgExpr = new ExprLoadConstant (this.methodInfo, null); string conditionText = this.GetConditionString (e); Expr conditionStringExpr = new ExprLoadConstant (this.methodInfo, conditionText); var call = new ExprCall (this.methodInfo, mRequires, new Expr [] { conditionExpr, nullArgExpr, conditionStringExpr }); this.contractRequiresInfo.Add (new ContractRequiresInfo (e, call)); return call; }