public override bool Execute(out ResultTuple ret, ResultTuple[] results, Plan.ParameterChooser[] parameterMap, TextWriter executionLog, TextWriter debugLog, out Exception exceptionThrown, out bool contractViolated, bool forbidNull) { contractViolated = false; Util.Assert(parameterMap.Length == 2); object receiver = results[parameterMap[0].planIndex].tuple[parameterMap[0].resultIndex]; object val = results[parameterMap[1].planIndex].tuple[parameterMap[1].resultIndex]; if (!this.coverageInfo.IsStatic) { Util.Assert(receiver != null); } if (forbidNull) { Util.Assert(val != null); } CodeExecutor.CodeToExecute call = delegate() { ffield.SetValue(receiver, val); }; executionLog.WriteLine("set field " + ffield.Name); executionLog.Flush(); if (!CodeExecutor.ExecuteReflectionCall(call, debugLog, out exceptionThrown)) { ret = null; return(false); } ret = new ResultTuple(ffield, receiver); return(true); }
public override bool Execute(out ResultTuple ret, ResultTuple[] results, Plan.ParameterChooser[] parameterMap, TextWriter executionLog, TextWriter debugLog, out Exception exceptionThrown, out bool contractViolated, bool forbidNull) { contractViolated = false; this.timesExecuted++; long startTime = 0; Timer.QueryPerformanceCounter(ref startTime); object[] objects = new object[fconstructor.GetParameters().Length]; // Get the actual objects from the results using parameterIndices; for (int i = 0; i < fconstructor.GetParameters().Length; i++) { Plan.ParameterChooser pair = parameterMap[i]; objects[i] = results[pair.planIndex].tuple[pair.resultIndex]; } if (forbidNull) { foreach (object o in objects) { Util.Assert(o != null); } } object newObject = null; CodeExecutor.CodeToExecute call = delegate() { newObject = fconstructor.Invoke(objects); }; executionLog.WriteLine("execute constructor " + this.fconstructor.DeclaringType); executionLog.Flush(); bool retval = true; if (!CodeExecutor.ExecuteReflectionCall(call, debugLog, out exceptionThrown)) { ret = null; if (exceptionThrown is AccessViolationException) { //Console.WriteLine("SECOND CHANCE AV!" + this.ToString()); //Logging.LogLine(Logging.GENERAL, "SECOND CHANCE AV!" + this.ToString()); } //for exns we can ony add the class to faulty classes when its a guideline violation if (Util.GuidelineViolation(exceptionThrown.GetType())) { PlanManager.numDistinctContractViolPlans++; KeyValuePair <MethodBase, Type> k = new KeyValuePair <MethodBase, Type>(this.fconstructor, exceptionThrown.GetType()); if (!exnViolatingMethods.ContainsKey(k)) { PlanManager.numContractViolatingPlans++; exnViolatingMethods[k] = true; } //add this class to the faulty classes contractExnViolatingClasses[fconstructor.GetType()] = true; contractExnViolatingMethods[fconstructor] = true; } return(false); } else { ret = new ResultTuple(fconstructor, newObject, objects); } //check if the objects in the output tuple violated basic contracts if (ret != null) { foreach (object o in ret.tuple) { if (o == null) { continue; } bool toStrViol, hashCodeViol, equalsViol; int count; if (Util.ViolatesContracts(o, out count, out toStrViol, out hashCodeViol, out equalsViol)) { contractViolated = true; contractExnViolatingMethods[fconstructor] = true; bool newcontractViolation = false; PlanManager.numDistinctContractViolPlans++; if (toStrViol) { if (!toStrViolatingMethods.ContainsKey(fconstructor)) { newcontractViolation = true; } toStrViolatingMethods[fconstructor] = true; } if (hashCodeViol) { if (!hashCodeViolatingMethods.ContainsKey(fconstructor)) { newcontractViolation = true; } hashCodeViolatingMethods[fconstructor] = true; } if (equalsViol) { if (!equalsViolatingMethods.ContainsKey(fconstructor)) { newcontractViolation = true; } equalsViolatingMethods[fconstructor] = true; } if (newcontractViolation) { PlanManager.numContractViolatingPlans++; } //add this class to the faulty classes contractExnViolatingClasses[fconstructor.DeclaringType] = true; retval = false; } } } long endTime = 0; Timer.QueryPerformanceCounter(ref endTime); executionTimeAccum += ((double)(endTime - startTime)) / ((double)(Timer.PerfTimerFrequency)); return(retval); }