internal override ScopeBounds GetScopesWithLocals(ArrayBuilder <LocalScope> scopesWithVariables, bool edgeInclusive) { uint begin = uint.MaxValue; uint end = 0; // It may seem overkill to scan all blocks, // but blocks may be reordered so we cannot be sure which ones are first/last. if (Blocks != null) { for (int i = 0; i < Blocks.Count; i++) { var block = Blocks[i]; if (block.Reachability != Reachability.NotReachable) { begin = Math.Min(begin, (uint)block.Start); end = Math.Max(end, (uint)(block.Start + block.TotalSize)); } } } // if there are nested scopes, dump them too // also may need to adjust current scope bounds. if (NestedScopes != null) { ScopeBounds nestedBounds = GetScopesWithLocals(scopesWithVariables, NestedScopes, edgeInclusive); begin = Math.Min(begin, nestedBounds.Begin); end = Math.Max(end, nestedBounds.End); } // we are not interested in scopes with no variables or no code in them. if ((this.LocalVariables != null || this.LocalConstants != null) && end > begin) { uint endAdjusted = edgeInclusive ? end - 1 : end; IEnumerable <Microsoft.Cci.ILocalDefinition> localConstantDefinitions = this.LocalConstants == null ? SpecializedCollections.EmptyEnumerable <Microsoft.Cci.ILocalDefinition>() : this.LocalConstants.ToArray(); IEnumerable <Microsoft.Cci.ILocalDefinition> localDefinitions = this.LocalVariables == null ? SpecializedCollections.EmptyEnumerable <Microsoft.Cci.ILocalDefinition>() : this.LocalVariables.ToArray(); LocalScope newScope = new LocalScope(begin, endAdjusted, null, localConstantDefinitions, localDefinitions); scopesWithVariables.Add(newScope); } return(new ScopeBounds(begin, end)); }
internal override ScopeBounds GetIteratorScopes(ArrayBuilder <LocalScope> scopesWithIteratorLocals, bool edgeInclusive) { uint begin = uint.MaxValue; uint end = 0; // It may seem overkill to scan all blocks, // but blocks may be reordered so we cannot be sure which ones are first/last. if (Blocks != null) { for (int i = 0; i < Blocks.Count; i++) { var block = Blocks[i]; if (block.Reachability != Reachability.NotReachable) { begin = Math.Min(begin, (uint)block.Start); end = Math.Max(end, (uint)(block.Start + block.TotalSize)); } } } // if there are nested scopes, dump them too // also may need to adjust current scope bounds. if (NestedScopes != null) { ScopeBounds nestedBounds = GetIteratorScopes(scopesWithIteratorLocals, NestedScopes, edgeInclusive); begin = Math.Min(begin, nestedBounds.Begin); end = Math.Max(end, nestedBounds.End); } // we are not interested in scopes with no variables or no code in them. if (this.IteratorVariables != null && end > begin) { uint endAdjusted = edgeInclusive ? end - 1 : end; var newScope = new LocalScope(begin, endAdjusted, null, null, null); foreach (var iv in this.IteratorVariables) { while (scopesWithIteratorLocals.Count <= iv) { scopesWithIteratorLocals.Add(null); } scopesWithIteratorLocals[iv] = newScope; } } return(new ScopeBounds(begin, end)); }