private VariableName findPreviousValidScope(ExecutedBlock scopeBlock, Instance instance) { //find variable with valid scope var block = View.PreviousBlock(scopeBlock); var scopeEnds = new HashSet <VariableName>(); ExecutedBlock firstScopeEnd = null; while (block != null) { scopeEnds.UnionWith(block.ScopeEnds(instance)); foreach (var start in block.ScopeStarts(instance)) { if (!scopeEnds.Contains(start)) { //we have found variable with valid scope return(start); } } if (firstScopeEnd == null && scopeEnds.Count > 0) { //if there is no valid variable scope with wanted instance, //then we can try to shift first scope end founded firstScopeEnd = block; } //shift to next block block = View.PreviousBlock(block); } if (firstScopeEnd != null) { if (ShiftBehindTransformation.Shift(firstScopeEnd, scopeBlock, View)) { //scope end was shifted return(firstScopeEnd.ScopeEnds(instance).First()); } } return(null); }
/// <summary> /// Get scope ends of instance for given block in current view. /// </summary> /// <param name="block">The block.</param> /// <param name="instance">Instance which scope ends are requested.</param> /// <returns>Enumeration of variables which scope ends at given block.</returns> internal IEnumerable <VariableName> ScopeEnds(ExecutedBlock block, Instance instance) { return(block.ScopeEnds(instance)); }