File: SourceLineInfo.cs

package info (click to toggle)
mono 6.14.1%2Bds2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,282,732 kB
  • sloc: cs: 11,182,461; xml: 2,850,281; ansic: 699,123; cpp: 122,919; perl: 58,604; javascript: 30,841; asm: 21,845; makefile: 19,602; sh: 10,973; python: 4,772; pascal: 925; sql: 859; sed: 16; php: 1
file content (96 lines) | stat: -rw-r--r-- 3,885 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//------------------------------------------------------------------------------
// <copyright file="SourceLineInfo.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
// <owner current="true" primary="true">Microsoft</owner>
//------------------------------------------------------------------------------

using System.Diagnostics;

namespace System.Xml.Xsl {

    [DebuggerDisplay("({Line},{Pos})")]
    internal struct Location {
        private ulong value;

        public int Line { get { return (int)(this.value >> 32); } }
        public int Pos  { get { return (int)(this.value      ); } }

        public Location(int line, int pos) {
            this.value = (((ulong)line) << 32) | (uint)pos;
        }

        public Location(Location that) {
            this.value = that.value;
        }

        public bool LessOrEqual(Location that) {
            return this.value <= that.value;
        }
    }

    [DebuggerDisplay("{Uri} [{StartLine},{StartPos} -- {EndLine},{EndPos}]")]
    internal class SourceLineInfo : ISourceLineInfo {
        protected string    uriString;
        protected Location  start;
        protected Location  end;

        public SourceLineInfo(string uriString, int startLine, int startPos, int endLine, int endPos)
            : this(uriString, new Location(startLine, startPos), new Location(endLine, endPos))
        {}

        public SourceLineInfo(string uriString, Location start, Location end) {
            this.uriString = uriString;
            this.start     = start;
            this.end       = end;
            Validate(this);
        }

        public string   Uri       { get { return this.uriString ; } }
        public int      StartLine { get { return this.start.Line; } }
        public int      StartPos  { get { return this.start.Pos ; } }
        public int      EndLine   { get { return this.end.Line  ; } }
        public int      EndPos    { get { return this.end.Pos   ; } }
        public Location End       { get { return this.end       ; } }
        public Location Start     { get { return this.start     ; } }

        /// <summary>
        /// Magic number 0xfeefee is used in PDB to denote a section of IL that does not map to any user code.
        /// When VS debugger steps into IL marked with 0xfeefee, it will continue the step until it reaches
        /// some user code.
        /// </summary>
        protected const int NoSourceMagicNumber = 0xfeefee;

        public static SourceLineInfo NoSource = new SourceLineInfo(string.Empty, NoSourceMagicNumber, 0, NoSourceMagicNumber, 0);

        public bool IsNoSource {
            get { return this.StartLine == NoSourceMagicNumber; }
        }

        [Conditional("DEBUG")]
        public static void Validate(ISourceLineInfo lineInfo) {
            if (lineInfo.Start.Line == 0 || lineInfo.Start.Line == NoSourceMagicNumber) {
                Debug.Assert(lineInfo.Start.Line == lineInfo.End.Line);
                Debug.Assert(lineInfo.Start.Pos == 0 && lineInfo.End.Pos == 0);
            } else {
                Debug.Assert(0 < lineInfo.Start.Line && 0 < lineInfo.Start.Pos, "0 < start");
                Debug.Assert(0 < lineInfo.End.Line   && 0 < lineInfo.End.Pos  , "0 < end");
                Debug.Assert(lineInfo.Start.LessOrEqual(lineInfo.End), "start <= end");
            }
        }

        // Returns file path for local and network URIs. Used for PDB generating and error reporting.
        public static string GetFileName(string uriString) {
            Debug.Assert(uriString != null);
            Uri uri;

            if (uriString.Length != 0 &&
                System.Uri.TryCreate(uriString, UriKind.Absolute, out uri) &&
                uri.IsFile
            ) {
                return uri.LocalPath;
            }
            return uriString;
        }
    }
}