internal override ScopeBounds GetIteratorScopes(ArrayBuilder <Cci.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 Cci.LocalScope( begin, endAdjusted - begin, ImmutableArray <Cci.ILocalDefinition> .Empty, ImmutableArray <Cci.ILocalDefinition> .Empty); foreach (var iv in this.IteratorVariables) { while (scopesWithIteratorLocals.Count <= iv) { scopesWithIteratorLocals.Add(default(Cci.LocalScope)); } scopesWithIteratorLocals[iv] = newScope; } } return(new ScopeBounds(begin, end)); }
internal override ScopeBounds GetLocalScopes(ArrayBuilder <Cci.LocalScope> result, 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 = GetLocalScopes(result, _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 ((_localVariables != null || _localConstants != null) && end > begin) { uint endAdjusted = edgeInclusive ? end - 1 : end; var newScope = new Cci.LocalScope( begin, endAdjusted - begin, _localConstants.AsImmutableOrEmpty <Cci.ILocalDefinition>(), _localVariables.AsImmutableOrEmpty <Cci.ILocalDefinition>()); result.Add(newScope); } return(new ScopeBounds(begin, end)); }
private static void SerializeTupleElementNames(ArrayBuilder <LocalAndScope> locals, BlobBuilder cmw) { cmw.WriteInt32(locals.Count); foreach (LocalAndScope localAndScope in locals) { ILocalDefinition local = localAndScope.Local; LocalScope scope = localAndScope.Scope; System.Collections.Immutable.ImmutableArray <TypedConstant> tupleElementNames = local.TupleElementNames; cmw.WriteInt32(tupleElementNames.Length); foreach (TypedConstant tupleElementName in tupleElementNames) { WriteUtf8String(cmw, (string)tupleElementName.Value ?? string.Empty); } cmw.WriteInt32(local.SlotIndex); cmw.WriteInt32(scope.StartOffset); cmw.WriteInt32(scope.EndOffset); WriteUtf8String(cmw, local.Name); } }
private void DefineScopeLocals(LocalScope currentScope, uint localSignatureToken) { foreach (ILocalDefinition scopeConstant in currentScope.Constants) { uint token = _metadataWriter.SerializeLocalConstantSignature(scopeConstant); if (!_metadataWriter.IsLocalNameTooLong(scopeConstant)) { DefineLocalConstant(scopeConstant.Name, scopeConstant.CompileTimeValue.Value, _metadataWriter.GetConstantTypeCode(scopeConstant), token); } } foreach (ILocalDefinition scopeLocal in currentScope.Variables) { if (!_metadataWriter.IsLocalNameTooLong(scopeLocal)) { Debug.Assert(scopeLocal.SlotIndex >= 0); DefineLocalVariable((uint)scopeLocal.SlotIndex, scopeLocal.Name, scopeLocal.PdbAttributes, localSignatureToken); } } }
private void DefineLocalScopes(ImmutableArray <LocalScope> scopes, uint localSignatureToken) { // VB scope ranges are end-inclusive bool endInclusive = this.Module.GenerateVisualBasicStylePdb; // The order of OpenScope and CloseScope calls must follow the scope nesting. var scopeStack = ArrayBuilder <LocalScope> .GetInstance(); for (int i = 1; i < scopes.Length; i++) { var currentScope = scopes[i]; // Close any scopes that have finished. while (scopeStack.Count > 0) { LocalScope topScope = scopeStack.Last(); if (currentScope.StartOffset < topScope.StartOffset + topScope.Length) { break; } scopeStack.RemoveLast(); CloseScope(endInclusive ? topScope.EndOffset - 1 : topScope.EndOffset); } // Open this scope. scopeStack.Add(currentScope); OpenScope(currentScope.StartOffset); this.DefineScopeLocals(currentScope, localSignatureToken); } // Close remaining scopes. for (int i = scopeStack.Count - 1; i >= 0; i--) { LocalScope scope = scopeStack[i]; CloseScope(endInclusive ? scope.EndOffset - 1 : scope.EndOffset); } scopeStack.Free(); }
private void DefineLocalScopes(ImmutableArray <LocalScope> scopes, uint localSignatureToken) { // The order of OpenScope and CloseScope calls must follow the scope nesting. var scopeStack = ArrayBuilder <LocalScope> .GetInstance(); for (int i = 1; i < scopes.Length; i++) { var currentScope = scopes[i]; // Close any scopes that have finished. while (scopeStack.Count > 0) { LocalScope topScope = scopeStack.Last(); if (currentScope.Offset < topScope.Offset + topScope.Length) { break; } scopeStack.RemoveLast(); CloseScope(topScope.Offset + topScope.Length); } // Open this scope. scopeStack.Add(currentScope); OpenScope(currentScope.Offset); this.DefineScopeLocals(currentScope, localSignatureToken); } // Close remaining scopes. for (int i = scopeStack.Count - 1; i >= 0; i--) { LocalScope scope = scopeStack[i]; CloseScope(scope.Offset + scope.Length); } scopeStack.Free(); }
private void DefineScopeLocals(LocalScope currentScope, uint localSignatureToken) { foreach (ILocalDefinition scopeConstant in currentScope.Constants) { int token = _metadataWriter.SerializeLocalConstantStandAloneSignature(scopeConstant); if (!_metadataWriter.IsLocalNameTooLong(scopeConstant)) { DefineLocalConstant(scopeConstant.Name, scopeConstant.CompileTimeValue.Value, _metadataWriter.GetConstantTypeCode(scopeConstant), (uint)token); } } foreach (ILocalDefinition scopeLocal in currentScope.Variables) { if (!_metadataWriter.IsLocalNameTooLong(scopeLocal)) { Debug.Assert(scopeLocal.SlotIndex >= 0); DefineLocalVariable((uint)scopeLocal.SlotIndex, scopeLocal.Name, scopeLocal.PdbAttributes, localSignatureToken); } } }
internal LocalAndScope(ILocalDefinition local, LocalScope scope) { Local = local; Scope = scope; }
private void DefineScopeLocals(LocalScope currentScope, uint localSignatureToken) { foreach (ILocalDefinition scopeConstant in currentScope.Constants) { uint token = peWriter.SerializeLocalConstantSignature(scopeConstant); if (!peWriter.IsLocalNameTooLong(scopeConstant)) { DefineLocalConstant(scopeConstant.Name, scopeConstant.CompileTimeValue.Value, peWriter.GetConstantTypeCode(scopeConstant), token); } } foreach (ILocalDefinition scopeLocal in currentScope.Variables) { if (!peWriter.IsLocalNameTooLong(scopeLocal)) { Debug.Assert(scopeLocal.SlotIndex >= 0); DefineLocalVariable((uint)scopeLocal.SlotIndex, scopeLocal.Name, scopeLocal.IsCompilerGenerated, localSignatureToken); } } }