/// <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; }
internal override void ReplaceSequenceDefinition(SequenceDefinition oldDef, SequenceDefinition newDef) { throw new Exception("ReplaceSequenceDefinition not supported on compiled sequences"); }
internal override void ReplaceSequenceDefinition(SequenceDefinition oldDef, SequenceDefinition newDef) { if(ParamBindings.SequenceDef==oldDef) ParamBindings.SequenceDef = newDef; }
public void WasReplacedBy(SequenceDefinition newSeq) { if(newSeq.SequenceName != SequenceName) throw new Exception("Internal Failure: name mismatch on sequence replacement"); nameToCopies.Remove(SequenceName); }
internal override void ReplaceSequenceDefinition(SequenceDefinition oldDef, SequenceDefinition newDef) { Seq.ReplaceSequenceDefinition(oldDef, newDef); }
internal override void ReplaceSequenceDefinition(SequenceDefinition oldDef, SequenceDefinition newDef) { foreach(Sequence seq in Sequences) seq.ReplaceSequenceDefinition(oldDef, newDef); }
internal override void ReplaceSequenceDefinition(SequenceDefinition oldDef, SequenceDefinition newDef) { Condition.ReplaceSequenceDefinition(oldDef, newDef); TrueCase.ReplaceSequenceDefinition(oldDef, newDef); FalseCase.ReplaceSequenceDefinition(oldDef, newDef); }
/// <summary> /// After a sequence definition was replaced by a new one, all references from then on will use the new one, /// but the old references are still there and must get replaced. /// </summary> /// <param name="oldDef">The old definition which is to be replaced</param> /// <param name="newDef">The new definition which replaces the old one</param> internal virtual void ReplaceSequenceDefinition(SequenceDefinition oldDef, SequenceDefinition newDef) { // most sequences are basic ones not referencing seqences // this null implementation saves us the effort of implementing this method everywhere, needed or not }