public RuleInvocationParameterBindings Copy(Dictionary <SequenceVariable, SequenceVariable> originalToCopy, IGraphProcessingEnvironment procEnv) { RuleInvocationParameterBindings copy = (RuleInvocationParameterBindings)MemberwiseClone(); copy.ArgumentExpressions = new SequenceExpression[ArgumentExpressions.Length]; for (int i = 0; i < ArgumentExpressions.Length; ++i) { copy.ArgumentExpressions[i] = ArgumentExpressions[i].CopyExpression(originalToCopy, procEnv); } copy.ReturnVars = new SequenceVariable[ReturnVars.Length]; for (int i = 0; i < ReturnVars.Length; ++i) { copy.ReturnVars[i] = ReturnVars[i].Copy(originalToCopy, procEnv); } copy.Arguments = new object[Arguments.Length]; for (int i = 0; i < Arguments.Length; ++i) { copy.Arguments[i] = Arguments[i]; } if (copy.Subgraph != null) { copy.Subgraph = Subgraph.Copy(originalToCopy, procEnv); } return(copy); }
public int ApplyRewrite(RuleInvocationParameterBindings paramBindings, int which, int localMaxMatches, bool special, bool test, List<FilterCall> filters) { int curMaxMatches = (localMaxMatches > 0) ? localMaxMatches : MaxMatches; object[] parameters; if(paramBindings.ArgumentExpressions.Length > 0) { parameters = paramBindings.Arguments; for(int i = 0; i < paramBindings.ArgumentExpressions.Length; i++) { if(paramBindings.ArgumentExpressions[i] != null) parameters[i] = paramBindings.ArgumentExpressions[i].Evaluate(this); } } else parameters = null; if(paramBindings.Subgraph != null) SwitchToSubgraph((IGraph)paramBindings.Subgraph.GetVariableValue(this)); #if DEBUGACTIONS || MATCHREWRITEDETAIL PerformanceInfo.StartLocal(); #endif IMatches matches = paramBindings.Action.Match(this, curMaxMatches, parameters); #if DEBUGACTIONS || MATCHREWRITEDETAIL PerformanceInfo.StopMatch(); #endif for(int i=0; i<filters.Count; ++i) paramBindings.Action.Filter(this, matches, filters[i]); Matched(matches, null, special); if(matches.Count == 0) { if(paramBindings.Subgraph != null) ReturnFromSubgraph(); return 0; } PerformanceInfo.MatchesFound += matches.Count; if(test) { if(paramBindings.Subgraph != null) ReturnFromSubgraph(); return matches.Count; } Finishing(matches, special); #if DEBUGACTIONS || MATCHREWRITEDETAIL PerformanceInfo.StartLocal(); #endif List<object[]> retElemsList = Replace(matches, which); if(which == -1) { IList[] returnVars = null; if(paramBindings.ReturnVars.Length > 0) { returnVars = new IList[paramBindings.ReturnVars.Length]; for(int i = 0; i < paramBindings.ReturnVars.Length; i++) { returnVars[i] = (IList)paramBindings.ReturnVars[i].GetVariableValue(this); if(returnVars[i] == null) { string returnType = TypesHelper.DotNetTypeToXgrsType(paramBindings.Action.RulePattern.Outputs[i]); Type valueType = ContainerHelper.GetTypeFromNameForContainer(returnType, graph); returnVars[i] = ContainerHelper.NewList(valueType); paramBindings.ReturnVars[i].SetVariableValue(returnVars[i], this); } else returnVars[i].Clear(); } } for(int curRetElemNum = 0; curRetElemNum < retElemsList.Count; ++curRetElemNum) { object[] retElems = retElemsList[curRetElemNum]; for(int i = 0; i < paramBindings.ReturnVars.Length; i++) returnVars[i].Add(retElems[i]); } } else { object[] retElems = retElemsList[0]; for(int i = 0; i < paramBindings.ReturnVars.Length; i++) paramBindings.ReturnVars[i].SetVariableValue(retElems[i], this); } #if DEBUGACTIONS || MATCHREWRITEDETAIL PerformanceInfo.StopRewrite(); #endif Finished(matches, special); if(paramBindings.Subgraph != null) ReturnFromSubgraph(); return matches.Count; }
public SequenceRuleAllCall(RuleInvocationParameterBindings paramBindings, bool special, bool test, bool chooseRandom, SequenceVariable varChooseRandom, bool chooseRandom2, SequenceVariable varChooseRandom2, bool choice, List<FilterCall> filters) : base(paramBindings, special, test, filters) { SequenceType = SequenceType.RuleAllCall; ChooseRandom = chooseRandom; if(chooseRandom) { MinSpecified = chooseRandom2; if(chooseRandom2) { MinVarChooseRandom = varChooseRandom; MaxVarChooseRandom = varChooseRandom2; } else MaxVarChooseRandom = varChooseRandom; } this.choice = choice; }
public SequenceRuleCall(RuleInvocationParameterBindings paramBindings, bool special, bool test, List<FilterCall> filters) : base(special, SequenceType.RuleCall) { ParamBindings = paramBindings; Test = test; Filters = filters; }
public SequenceRuleCountAllCall(RuleInvocationParameterBindings paramBindings, bool special, bool test, SequenceVariable countResult, List<FilterCall> filters) : base(paramBindings, special, test, filters) { SequenceType = SequenceType.RuleCountAllCall; CountResult = countResult; }
private void BuildReturnParameters(RuleInvocationParameterBindings paramBindings, out String returnParameterDeclarations, out String returnArguments, out String returnAssignments, out String returnParameterDeclarationsAllCall, out String intermediateReturnAssignmentsAllCall, out String returnAssignmentsAllCall) { // can't use the normal xgrs variables for return value receiving as the type of an out-parameter must be invariant // this is bullshit, as it is perfectly safe to assign a subtype to a variable of a supertype // so we create temporary variables of exact type, which are used to receive the return values, // and finally we assign these temporary variables to the real xgrs variables StringBuilder sbReturnParameterDeclarations = new StringBuilder(); StringBuilder sbReturnArguments = new StringBuilder(); StringBuilder sbReturnAssignments = new StringBuilder(); StringBuilder sbReturnParameterDeclarationsAllCall = new StringBuilder(); StringBuilder sbIntermediateReturnAssignmentsAllCall = new StringBuilder(); StringBuilder sbReturnAssignmentsAllCall = new StringBuilder(); for(int i = 0; i < rulesToOutputTypes[paramBindings.PackagePrefixedName].Count; i++) { String varName; if(paramBindings.ReturnVars.Length != 0) varName = tmpVarCtr.ToString() + paramBindings.ReturnVars[i].PureName; else varName = tmpVarCtr.ToString(); ++tmpVarCtr; String typeName = rulesToOutputTypes[paramBindings.PackagePrefixedName][i]; sbReturnParameterDeclarations.Append(TypesHelper.XgrsTypeToCSharpType(typeName, model)); sbReturnParameterDeclarations.Append(" tmpvar_"); sbReturnParameterDeclarations.Append(varName); sbReturnParameterDeclarations.Append("; "); String returnListValueVarType = typeName; if(paramBindings.ReturnVars.Length != 0 && paramBindings.ReturnVars[i].Type != "" && paramBindings.ReturnVars[i].Type.StartsWith("array<")) returnListValueVarType = TypesHelper.ExtractSrc(paramBindings.ReturnVars[i].Type); if(paramBindings.ReturnVars.Length != 0) { sbReturnParameterDeclarationsAllCall.Append("List<"); sbReturnParameterDeclarationsAllCall.Append(TypesHelper.XgrsTypeToCSharpType(returnListValueVarType, model)); sbReturnParameterDeclarationsAllCall.Append("> tmpvarlist_"); sbReturnParameterDeclarationsAllCall.Append(varName); sbReturnParameterDeclarationsAllCall.Append(" = new List<"); sbReturnParameterDeclarationsAllCall.Append(TypesHelper.XgrsTypeToCSharpType(returnListValueVarType, model)); sbReturnParameterDeclarationsAllCall.Append(">(); "); } sbReturnArguments.Append(", out tmpvar_"); sbReturnArguments.Append(varName); if(paramBindings.ReturnVars.Length != 0) { sbReturnAssignments.Append(SetVar(paramBindings.ReturnVars[i], "tmpvar_" + varName)); sbIntermediateReturnAssignmentsAllCall.Append("tmpvarlist_"); sbIntermediateReturnAssignmentsAllCall.Append(varName); sbIntermediateReturnAssignmentsAllCall.Append(".Add(("); sbIntermediateReturnAssignmentsAllCall.Append(TypesHelper.XgrsTypeToCSharpType(returnListValueVarType, model)); sbIntermediateReturnAssignmentsAllCall.Append(")tmpvar_"); sbIntermediateReturnAssignmentsAllCall.Append(varName); sbIntermediateReturnAssignmentsAllCall.Append("); "); sbReturnAssignmentsAllCall.Append(SetVar(paramBindings.ReturnVars[i], "tmpvarlist_" + varName)); } } returnParameterDeclarations = sbReturnParameterDeclarations.ToString(); returnArguments = sbReturnArguments.ToString(); returnAssignments = sbReturnAssignments.ToString(); returnParameterDeclarationsAllCall = sbReturnParameterDeclarationsAllCall.ToString(); intermediateReturnAssignmentsAllCall = sbIntermediateReturnAssignmentsAllCall.ToString(); returnAssignmentsAllCall = sbReturnAssignmentsAllCall.ToString(); }