/// <summary>
        /// Finds a span of IL containing the specified offset where local variables and imports are guaranteed to be the same.
        /// Examples:
        /// scopes: [   [   ) x [  )  )
        /// result:         [   )
        /// 
        /// scopes: [ x [   )   [  )  )
        /// result: [   )     
        /// 
        /// scopes: [   [ x )   [  )  )
        /// result:     [   )     
        /// </summary>
        public static ILSpan CalculateReuseSpan(int ilOffset, ILSpan initialSpan, IEnumerable<ILSpan> scopes)
        {
            Debug.Assert(ilOffset >= 0);

            uint _startOffset = initialSpan.StartOffset;
            uint _endOffsetExclusive = initialSpan.EndOffsetExclusive;

            foreach (ILSpan scope in scopes)
            {
                if (ilOffset < scope.StartOffset)
                {
                    _endOffsetExclusive = Math.Min(_endOffsetExclusive, scope.StartOffset);
                }
                else if (ilOffset >= scope.EndOffsetExclusive)
                {
                    _startOffset = Math.Max(_startOffset, scope.EndOffsetExclusive);
                }
                else
                {
                    _startOffset = Math.Max(_startOffset, scope.StartOffset);
                    _endOffsetExclusive = Math.Min(_endOffsetExclusive, scope.EndOffsetExclusive);
                }
            }

            return new ILSpan(_startOffset, _endOffsetExclusive);
        }
        internal MethodContextReuseConstraints(Guid moduleVersionId, int methodToken, int methodVersion, ILSpan span)
        {
            Debug.Assert(moduleVersionId != default(Guid));
            Debug.Assert(MetadataTokens.Handle(methodToken).Kind == HandleKind.MethodDefinition);
            Debug.Assert(methodVersion >= 1);

            _moduleVersionId = moduleVersionId;
            _methodToken = methodToken;
            _methodVersion = methodVersion;
            _span = span;
        }
        public void DebugEnd(AstNode node)
        {
            var state = debugStack.Pop();

            if (currentMethodDebugInfoBuilder != null)
            {
                foreach (var ilSpan in ILSpan.OrderAndCompact(GetILSpans(state)))
                {
                    currentMethodDebugInfoBuilder.Add(new SourceStatement(ilSpan, new TextSpan(state.StartLocation, output.NextPosition - state.StartLocation)));
                }
            }
            else if (multiMappings != null)
            {
                foreach (var mm in multiMappings)
                {
                    foreach (var ilSpan in ILSpan.OrderAndCompact(mm.Item2))
                    {
                        mm.Item1.Add(new SourceStatement(ilSpan, new TextSpan(state.StartLocation, output.NextPosition - state.StartLocation)));
                    }
                }
            }
        }