public void NextCase(IWorkshopTree value) { // If the state is on a case and the action count was changed, create new skip that will skip to the end of the switch. if (AutoBreak && State == SwitchBuilderState.OnCase && actionSet.ActionCount != LastCaseStart) { // Create the skip and add it to the actionset. SkipStartMarker skipToEnd = new SkipStartMarker(actionSet); actionSet.AddAction(skipToEnd); // Add it to the list of skips that need to skip to the end. SkipToEnd.Add(skipToEnd); } // Update the state. State = SwitchBuilderState.OnCase; // Mark the start of the case. SkipEndMarker startCase = new SkipEndMarker(); actionSet.AddAction(startCase); // Add the skip length to the start of the case to the skipCounts. skipCounts.Add(Skipper.GetSkipCount(startCase)); // Add the skip value. skipValues.Add(value); // Update the number of actions. LastCaseStart = actionSet.ActionCount; }
public void Finish() { SkipEndMarker endMarker = new SkipEndMarker(); ActionSet.AddAction(endMarker); SkipMarker.SkipCount = SkipMarker.GetSkipCount(endMarker); }
public void Translate(ActionSet actionSet) { SkipStartMarker ifStart = new SkipStartMarker(actionSet, Expression.Parse(actionSet)); actionSet.AddAction(ifStart); Block.Translate(actionSet); List <SkipStartMarker> blockCaps = new List <SkipStartMarker>(); if (ElseBlock != null || ElseIfs.Length > 0) { SkipStartMarker ifCap = new SkipStartMarker(actionSet); actionSet.AddAction(ifCap); blockCaps.Add(ifCap); } SkipEndMarker ifEnd = new SkipEndMarker(); actionSet.AddAction(ifEnd); ifStart.SkipCount = ifStart.GetSkipCount(ifEnd); // Get the else-ifs. for (int i = 0; i < ElseIfs.Length; i++) { bool isLast = i == ElseIfs.Length - 1 && ElseBlock == null; SkipStartMarker elseIfStart = new SkipStartMarker(actionSet, ElseIfs[i].Expression.Parse(actionSet)); actionSet.AddAction(elseIfStart); ElseIfs[i].Block.Translate(actionSet); if (!isLast) { SkipStartMarker elseIfCap = new SkipStartMarker(actionSet); actionSet.AddAction(elseIfCap); blockCaps.Add(elseIfCap); } SkipEndMarker elseIfEnd = new SkipEndMarker(); actionSet.AddAction(elseIfEnd); elseIfStart.SkipCount = elseIfStart.GetSkipCount(elseIfEnd); } if (ElseBlock != null) { ElseBlock.Translate(actionSet); } SkipEndMarker contextCap = new SkipEndMarker(); actionSet.AddAction(contextCap); foreach (var blockCap in blockCaps) { blockCap.SkipCount = blockCap.GetSkipCount(contextCap); } }