/// <summary> /// Returns a dictionary of the function end points that are type compatible /// with any branch of replicated parameters. /// </summary> /// <param name="context"></param> /// <param name="formalParams"></param> /// <param name="replicationInstructions"></param> /// <param name="classTable"></param> /// <param name="runtimeCore"></param> /// <returns></returns> public Dictionary <FunctionEndPoint, int> GetLooseConversionDistances( Runtime.Context context, List <StackValue> formalParams, List <ReplicationInstruction> replicationInstructions, ClassTable classTable, RuntimeCore runtimeCore) { Dictionary <FunctionEndPoint, int> ret = new Dictionary <FunctionEndPoint, int>(); var reducedParams = Replicator.ComputeAllReducedParams(formalParams, replicationInstructions, runtimeCore); foreach (FunctionEndPoint fep in FunctionEndPoints) { foreach (var reducedParam in reducedParams) { int distance = fep.GetConversionDistance(reducedParam, classTable, true, runtimeCore); if (distance != (int)ProcedureDistance.InvalidDistance) { ret.Add(fep, distance); break; } } } return(ret); }
/// <summary> /// Get a list of all the function end points that are type compliant, there maybe more than one due to pattern matches /// </summary> /// <returns></returns> public List <FunctionEndPoint> GetExactTypeMatches(ProtoCore.Runtime.Context context, List <StackValue> formalParams, List <ReplicationInstruction> replicationInstructions, StackFrame stackFrame, RuntimeCore runtimeCore) { List <FunctionEndPoint> ret = new List <FunctionEndPoint>(); List <List <StackValue> > allReducedParamSVs = Replicator.ComputeAllReducedParams(formalParams, replicationInstructions, runtimeCore); //@TODO(Luke): Need to add type statistics checks to the below if it is an array to stop int[] matching char[] //Now test the reduced Params over all of the available end points StackValue thisptr = stackFrame.ThisPtr; bool isInstance = thisptr.IsPointer && thisptr.opdata != Constants.kInvalidIndex; bool isGlobal = thisptr.IsPointer && thisptr.opdata == Constants.kInvalidIndex; foreach (FunctionEndPoint fep in FunctionEndPoints) { var proc = fep.procedureNode; // Member functions are overloaded with thisptr as the first // parameter, so if member function replicates on the left hand // side, the type matching should only be applied to overloaded // member functions, otherwise should only be applied to original // member functions. if (isInstance && context.IsReplicating != proc.isAutoGeneratedThisProc) { continue; } else if (isGlobal && !proc.isConstructor && !proc.isStatic && proc.classScope != Constants.kGlobalScope) { continue; } bool typesOK = true; foreach (List <StackValue> reducedParamSVs in allReducedParamSVs) { if (!fep.DoesTypeDeepMatch(reducedParamSVs, runtimeCore)) { typesOK = false; break; } } if (typesOK) { ret.Add(fep); } } return(ret); }
/// <summary> /// Get a list of all the function end points that are type compliant, there maybe more than one due to pattern matches /// </summary> /// <returns></returns> public List <FunctionEndPoint> GetExactTypeMatches(ProtoCore.Runtime.Context context, List <StackValue> formalParams, List <ReplicationInstruction> replicationInstructions, StackFrame stackFrame, Core core) { List <FunctionEndPoint> ret = new List <FunctionEndPoint>(); List <List <StackValue> > allReducedParamSVs = Replicator.ComputeAllReducedParams(formalParams, replicationInstructions, core); List <StackValue> reducedParamSVs = allReducedParamSVs[0]; //@TODO(Luke): Need to add type statistics checks to the below if it is an array to stop int[] matching char[] //Now test the reduced Params over all of the available end points foreach (FunctionEndPoint fep in FunctionEndPoints) { if (fep.DoesTypeDeepMatch(reducedParamSVs, core)) { //// The first line checks if the lhs of a dot operation was a class name //if (stackFrame.GetAt(StackFrame.AbsoluteIndex.kThisPtr).optype == AddressType.ClassIndex // && !fep.procedureNode.isConstructor // && !fep.procedureNode.isStatic) if ((stackFrame.GetAt(StackFrame.AbsoluteIndex.kThisPtr).optype == AddressType.Pointer && stackFrame.GetAt(StackFrame.AbsoluteIndex.kThisPtr).opdata == -1 && fep.procedureNode != null && !fep.procedureNode.isConstructor) && !fep.procedureNode.isStatic && (fep.procedureNode.classScope != -1)) { continue; } ret.Add(fep); } } return(ret); }