protected override string InputParameterType(int i, Invocation invocation, GrGenType ownerType) { if (invocation is RuleInvocation) { RuleInvocation ruleInvocation = (RuleInvocation)invocation; IAction action = SequenceBase.GetAction(ruleInvocation); return(TypesHelper.DotNetTypeToXgrsType(action.RulePattern.Inputs[i])); } else if (invocation is SequenceInvocation) { SequenceSequenceCallInterpreted seqInvocation = (SequenceSequenceCallInterpreted)invocation; if (seqInvocation.SequenceDef is SequenceDefinitionInterpreted) { SequenceDefinitionInterpreted seqDef = (SequenceDefinitionInterpreted)seqInvocation.SequenceDef; return(seqDef.InputVariables[i].Type); } else { SequenceDefinitionCompiled seqDef = (SequenceDefinitionCompiled)seqInvocation.SequenceDef; return(TypesHelper.DotNetTypeToXgrsType(seqDef.SeqInfo.ParameterTypes[i])); } } else if (invocation is ProcedureInvocation) { ProcedureInvocation procInvocation = (ProcedureInvocation)invocation; if (ownerType != null) { IProcedureDefinition procDef = ownerType.GetProcedureMethod(procInvocation.Name); return(TypesHelper.DotNetTypeToXgrsType(procDef.Inputs[i])); } else { SequenceComputationProcedureCallInterpreted procInvocationInterpreted = (SequenceComputationProcedureCallInterpreted)procInvocation; return(TypesHelper.DotNetTypeToXgrsType(procInvocationInterpreted.ProcedureDef.Inputs[i])); } } else if (invocation is FunctionInvocation) { FunctionInvocation funcInvocation = (FunctionInvocation)invocation; if (ownerType != null) { IFunctionDefinition funcDef = ownerType.GetFunctionMethod(funcInvocation.Name); return(TypesHelper.DotNetTypeToXgrsType(funcDef.Inputs[i])); } else { SequenceExpressionFunctionCallInterpreted funcInvocationInterpreted = (SequenceExpressionFunctionCallInterpreted)funcInvocation; return(TypesHelper.DotNetTypeToXgrsType(funcInvocationInterpreted.FunctionDef.Inputs[i])); } } throw new Exception("Internal error"); }
protected override int NumInputParameters(Invocation invocation, InheritanceType ownerType) { if (invocation is RuleInvocation) { RuleInvocation ruleInvocation = (RuleInvocation)invocation; IAction action = SequenceBase.GetAction(ruleInvocation); return(action.RulePattern.Inputs.Length); } else if (invocation is SequenceInvocation) { SequenceSequenceCallInterpreted seqInvocation = (SequenceSequenceCallInterpreted)invocation; if (seqInvocation.SequenceDef is SequenceDefinitionInterpreted) { SequenceDefinitionInterpreted seqDef = (SequenceDefinitionInterpreted)seqInvocation.SequenceDef; return(seqDef.InputVariables.Length); } else { SequenceDefinitionCompiled seqDef = (SequenceDefinitionCompiled)seqInvocation.SequenceDef; return(seqDef.SeqInfo.ParameterTypes.Length); } } else if (invocation is ProcedureInvocation) { ProcedureInvocation procInvocation = (ProcedureInvocation)invocation; if (ownerType != null) { IProcedureDefinition procDef = ownerType.GetProcedureMethod(procInvocation.Name); return(procDef.Inputs.Length); } else { SequenceComputationProcedureCallInterpreted procInvocationInterpreted = (SequenceComputationProcedureCallInterpreted)procInvocation; return(procInvocationInterpreted.ProcedureDef.Inputs.Length); } } else if (invocation is FunctionInvocation) { FunctionInvocation funcInvocation = (FunctionInvocation)invocation; if (ownerType != null) { IFunctionDefinition funcDef = ownerType.GetFunctionMethod(funcInvocation.Name); return(funcDef.Inputs.Length); } else { SequenceExpressionFunctionCallInterpreted funcInvocationInterpreted = (SequenceExpressionFunctionCallInterpreted)funcInvocation; return(funcInvocationInterpreted.FunctionDef.Inputs.Length); } } throw new Exception("Internal error"); }
/// <summary> /// Register a graph rewrite sequence definition. /// An interpreted sequence can be overwritten by a new one of the same name and signature. /// A compiled sequence is fixed, an exception is thrown if you try to set a sequence of the same name. /// </summary> /// <param name="sequenceDef">The sequence definition</param> /// <returns>Returns true if an existing definition was overwritten.</returns> public bool RegisterGraphRewriteSequenceDefinition(SequenceDefinition sequenceDef) { if (namesToSequenceDefinitions.ContainsKey(sequenceDef.SequenceName)) { if (namesToSequenceDefinitions[sequenceDef.SequenceName] is SequenceDefinitionCompiled) { throw new Exception("A compiled sequence can't be overwritten!"); } SequenceDefinitionInterpreted existingSequenceDef = (SequenceDefinitionInterpreted)namesToSequenceDefinitions[sequenceDef.SequenceName]; SequenceDefinitionInterpreted interpretedSequenceDef = (SequenceDefinitionInterpreted)sequenceDef; if (interpretedSequenceDef.InputVariables.Length != existingSequenceDef.InputVariables.Length) { throw new Exception("Old and new sequence definition for " + sequenceDef.SequenceName + " have a different number of parameters"); } for (int i = 0; i < interpretedSequenceDef.InputVariables.Length; ++i) { if (interpretedSequenceDef.InputVariables[i].Type != existingSequenceDef.InputVariables[i].Type) { throw new Exception("Old and new sequence definition for " + sequenceDef.SequenceName + " differ in parameter #" + i); } } if (interpretedSequenceDef.OutputVariables.Length != existingSequenceDef.OutputVariables.Length) { throw new Exception("Old and new sequence definition for " + sequenceDef.SequenceName + " have a different number of output parameters"); } for (int i = 0; i < interpretedSequenceDef.OutputVariables.Length; ++i) { if (interpretedSequenceDef.OutputVariables[i].Type != existingSequenceDef.OutputVariables[i].Type) { throw new Exception("Old and new sequence definition for " + sequenceDef.SequenceName + " differ in output parameter #" + i); } } namesToSequenceDefinitions[sequenceDef.SequenceName] = sequenceDef; // replace definition in map by name used for new sequences foreach (SequenceDefinition seqDef in namesToSequenceDefinitions.Values) // replace all references in old sequences to new one { if (!(seqDef is SequenceDefinitionCompiled)) { seqDef.ReplaceSequenceDefinition(existingSequenceDef, sequenceDef); } } existingSequenceDef.WasReplacedBy(sequenceDef); // flush sequence copy cache for this name return(true); } namesToSequenceDefinitions.Add(sequenceDef.SequenceName, sequenceDef); return(false); }
private static void PrintSequenceDefinitionInterpreted(SequenceDefinitionInterpreted seqDef, Sequence parent, PrintSequenceContext context) { HighlightingMode mode = HighlightingMode.None; if (seqDef.ExecutionState == SequenceExecutionState.Success) { mode = HighlightingMode.LastSuccess; } if (seqDef.ExecutionState == SequenceExecutionState.Fail) { mode = HighlightingMode.LastFail; } WorkaroundManager.Workaround.PrintHighlighted(seqDef.Symbol + ": ", mode); PrintSequence(seqDef.Seq, seqDef.Seq, context); }
private void TogglePointInAllInstances(int pos, bool choice) { if (debugSequences.Count > 1) { SequenceDefinitionInterpreted top = (SequenceDefinitionInterpreted)debugSequences.Peek(); Sequence[] callStack = debugSequences.ToArray(); for (int i = 0; i <= callStack.Length - 2; ++i) // non definition bottom excluded { SequenceDefinitionInterpreted seqDef = (SequenceDefinitionInterpreted)callStack[i]; if (seqDef.SequenceName == top.SequenceName) { if (choice) { ToggleChoicepoint(seqDef, pos); } else { ToggleBreakpoint(seqDef, pos); } } } // additionally handle the internally cached sequences foreach (SequenceDefinitionInterpreted seqDef in top.CachedSequenceCopies) { if (choice) { ToggleChoicepoint(seqDef, pos); } else { ToggleBreakpoint(seqDef, pos); } } } else { if (choice) { ToggleChoicepoint(debugSequences.Peek(), pos); } else { ToggleBreakpoint(debugSequences.Peek(), pos); } } }