public TState GetState(FlowLocation location) { int index = BinarySearchLowerBound(this.locations, location); var nearestLocation = this.locations[index]; return(this.states[nearestLocation]); }
public override void VisitWhileStatement(WhileStatementSyntax node) { var saveContinueLocation = this.continueLocation; var saveBreakLocation = this.breakLocation; // merge with any states that branch back to start (continue) this.JoinState(node.StartLocation(), this.lexicalState); TState trueState; TState falseState; this.VisitCondition(node.Condition, out trueState, out falseState); this.continueLocation = node.StartLocation(); this.breakLocation = node.EndLocation(); // statement only executes when condition is true this.SetState(node.Statement.StartLocation(), trueState); this.Visit(node.Statement); // at end of loop, branch back to top this.BranchToLocation(this.continueLocation, this.lexicalState); // merge with any states that branch to end (break & natural exit) this.JoinState(node.EndLocation(), falseState); this.continueLocation = saveContinueLocation; this.breakLocation = saveBreakLocation; }
private void BranchToLocation(FlowLocation location, FlowState state) { TState existingState; if (this.joinStates.TryGetValue(location, out existingState)) { this.joinStates = this.joinStates.SetItem(location, (TState)existingState.Join(this.lexicalState)); } else { this.joinStates = this.joinStates.SetItem(location, this.lexicalState); } }
public void JoinState(FlowLocation location, TState state) { TState existingState; if (this.joinStates.TryGetValue(location, out existingState)) { this.lexicalState = (TState)existingState.Join(state); } else { this.lexicalState = state; } this.joinStates = this.joinStates.SetItem(location, this.lexicalState); }
private static int BinarySearchLowerBound(FlowLocation[] array, FlowLocation value) { int low = 0; int high = array.Length - 1; while (low <= high) { int middle = low + ((high - low) >> 1); if (array[middle].CompareTo(value) > 0) { high = middle - 1; } else { low = middle + 1; } } return(high); }
public void SetState(FlowLocation location, TState state) { this.lexicalState = state; this.joinStates = this.joinStates.SetItem(location, state); }