Exemple #1
0
 private void EnsureCompatible(ILineBreaks lineBreaks)
 {
     if (this.LineBreaks != lineBreaks)
     {
         throw new ArgumentException();
     }
 }
        public override LineSpan GetLineFromLineNumber(int lineNumber)
        {
            if ((lineNumber < 0) || (lineNumber > this.LineBreakCount))
            {
                throw new ArgumentOutOfRangeException("lineNumber");
            }

            ILineBreaks lineBreaks = _storage.LineBreaks;

            int absoluteLineNumber = _lineBreakSpanStart + lineNumber;

            int start = (lineNumber == 0)
                        ? 0
                        : (Math.Min(this.TextSpanEnd, lineBreaks.EndOfLineBreak(absoluteLineNumber - 1)) - _textSpanStart);

            int end;
            int breakLength;

            if (lineNumber < this.LineBreakCount)
            {
                end         = Math.Max(_textSpanStart, lineBreaks.StartOfLineBreak(absoluteLineNumber));
                breakLength = Math.Min(this.TextSpanEnd, lineBreaks.EndOfLineBreak(absoluteLineNumber)) - end;

                end -= _textSpanStart;
            }
            else
            {
                end         = this.Length;
                breakLength = 0;
            }

            return(new LineSpan(lineNumber, Span.FromBounds(start, end), breakLength));
        }
Exemple #3
0
        /// <summary>
        /// Gets <see cref="Microsoft.CodeAnalysis.Text.LinePosition"/> from source position.
        /// </summary>
        public static LinePosition LinePosition(this ILineBreaks lines, int pos)
        {
            lines.GetLineColumnFromPosition(pos, out int line, out int col);

            // https://github.com/dotnet/corefx/blob/master/src/System.Reflection.Metadata/specs/PortablePdb-Metadata.md#sequence-points-blob - column must be less than 0x10000
            return(new LinePosition(line, Math.Min(col, 0x09999)));
        }
Exemple #4
0
        /// <summary>
        /// Gets <see cref="Microsoft.CodeAnalysis.Text.LinePosition"/> from source position.
        /// </summary>
        public static LinePosition LinePosition(this ILineBreaks lines, int pos)
        {
            int line, col;

            lines.GetLineColumnFromPosition(pos, out line, out col);

            return(new LinePosition(line, col));
        }
        private static StringRebuilder Create(Page content, ILineBreaks lineBreaks, int start, int length, int lineBreaksStart, int linebreaksLength)
        {
            Debug.Assert(content.Length > 0);

            var expanded = content.Expand();

            return(new StringRebuilderForCompressedChars(content, lineBreaks, start, length, lineBreaksStart, linebreaksLength, expanded[start], expanded[start + length - 1]));
        }
Exemple #6
0
        public TextPoint(ILineBreaks lineBreaks, int position)
        {
            //if (lineBreaks == null)
            //    throw new ArgumentNullException("lineBreaks");
            //if (position > lineBreaks.TextLength)
            //    throw new ArgumentException("position");

            _lineBreaks = lineBreaks;
            _position   = position;
        }
Exemple #7
0
        public SourceUnit(PhpSourceFile /*!*/ sourceFile, Encoding /*!*/ encoding, ILineBreaks /*!*/ lineBreaks)
        {
            Debug.Assert(sourceFile != null && encoding != null);
            Debug.Assert(lineBreaks != null);

            this.sourceFile      = sourceFile;
            this.encoding        = encoding;
            this.innerLineBreaks = lineBreaks;
            this.naming          = new NamingContext(null, null);
        }
Exemple #8
0
        public SourceUnit(string /*!*/ filePath, Encoding /*!*/ encoding, ILineBreaks /*!*/ lineBreaks)
        {
            Debug.Assert(filePath != null && encoding != null);
            Debug.Assert(lineBreaks != null);

            _filePath        = filePath;
            _encoding        = encoding;
            _innerLineBreaks = lineBreaks;
            _naming          = new NamingContext(null);
        }
Exemple #9
0
        protected UnaryStringRebuilder(ILineBreaks lineBreaks, int start, int length, int linebreaksStart, int linebreaksLength, char first, char last)
            : base(length, linebreaksLength, first, last)
        {
            #if DEBUG
            Interlocked.Increment(ref _totalCreated);
            #endif

            _lineBreaks = lineBreaks;

            _textSpanStart      = start;
            _lineBreakSpanStart = linebreaksStart;
        }
        internal static StringRebuilder Create(string source, ILineBreaks lineBreaks, int start, int length, int lineBreaksStart, int lineBreaksLength)
        {
            Debug.Assert(length != 0);

            if (lineBreaksLength == 0)
            {
                return(new StringRebuilderForString(source, LineBreakManager.Empty, start, length, 0, 0, source[start], source[start + length - 1]));
            }
            else
            {
                return(new StringRebuilderForString(source, lineBreaks, start, length, lineBreaksStart, lineBreaksLength, source[start], source[start + length - 1]));
            }
        }
Exemple #11
0
        public TextSpan(ILineBreaks lineBreaks, Span span)
        {
            if (lineBreaks == null)
            {
                throw new ArgumentNullException("lineBreaks");
            }

            if (span.End > lineBreaks.TextLength)
            {
                throw new ArgumentOutOfRangeException("span");
            }

            _start  = new TextPoint(lineBreaks, span.Start);
            _length = span.Length;
        }
Exemple #12
0
        /// <summary>
        /// Gets <see cref="Span"/> of whole <paramref name="line"/>.
        /// </summary>
        /// <param name="lineBreaks">Information about line breaks in the document. Cannot be <c>null</c>.</param>
        /// <param name="line">Line number.</param>
        /// <returns><see cref="Span"/> of line specified by parameter <paramref name="line"/> within the document <paramref name="lineBreaks"/>.</returns>
        public static Span GetLineSpan(this ILineBreaks /*!*/ lineBreaks, int line)
        {
            if (lineBreaks == null)
            {
                throw new ArgumentNullException("lineBreaks");
            }

            if (line < 0 || line > lineBreaks.Count)
            {
                throw new ArgumentException("line");
            }

            int start = (line != 0) ? lineBreaks.EndOfLineBreak(line - 1) : 0;
            int end   = (line < lineBreaks.Count) ? lineBreaks.EndOfLineBreak(line) : lineBreaks.TextLength;

            return(Span.FromBounds(start, end));
        }
Exemple #13
0
 public TextSpan(ILineBreaks lineBreaks, int start, int length)
 {
     _start  = new TextPoint(lineBreaks, start);
     _length = length;
 }
 internal static StringRebuilder Create(Page content, ILineBreaks lineBreaks)
 {
     return(StringRebuilderForCompressedChars.Create(content, lineBreaks, 0, content.Length, 0, lineBreaks.Length));
 }
 internal static StringRebuilder Create(string source, int length, ILineBreaks lineBreaks)
 {
     return(StringRebuilderForString.Create(source, lineBreaks, 0, length, 0, lineBreaks.Length));
 }
 private StringRebuilderForCompressedChars(Page content, ILineBreaks lineBreaks, int start, int length, int lineBreaksStart, int linebreaksLength, char first, char last)
     : base(lineBreaks, start, length, lineBreaksStart, linebreaksLength, first, last)
 {
     _content = content;
 }
 private StringRebuilderForString(string source, ILineBreaks lineBreaks, int start, int length, int lineBreaksStart, int lineBreaksLength, char first, char last)
     : base(lineBreaks, start, length, lineBreaksStart, lineBreaksLength, first, last)
 {
     _content = source;
 }
Exemple #18
0
        public CompilationSourceUnit(CompilationUnitBase /*!*/ compilationUnit, PhpSourceFile /*!*/ sourceFile, Encoding /*!*/ encoding, ILineBreaks /*!*/ lineBreaks)
            : base(sourceFile, encoding, lineBreaks)
        {
            Debug.Assert(compilationUnit != null);

            this.compilationUnit           = compilationUnit;
            this.namingContextFieldBuilder = null;        // to be filled during compilation just before the unit gets emitted
            this.symbolDocumentWriter      = null;        // to be filled during compilation just before the unit gets emitted
        }