public int Compare(Symbol x, Symbol y)
        {
            int comparison;

            if (x == y)
            {
                return(0);
            }

            var xSortKey = x.GetLexicalSortKey();
            var ySortKey = y.GetLexicalSortKey();

            comparison = LexicalSortKey.Compare(xSortKey, ySortKey);
            if (comparison != 0)
            {
                return(comparison);
            }

            comparison = ((ISymbol)x).Kind.ToSortOrder() - ((ISymbol)y).Kind.ToSortOrder();
            if (comparison != 0)
            {
                return(comparison);
            }

            comparison = string.CompareOrdinal(x.Name, y.Name);
            Debug.Assert(comparison != 0);
            return(comparison);
        }
        /// <summary>
        /// Compare two lexical sort keys in a compilation.
        /// </summary>
        public static int Compare(LexicalSortKey xSortKey, LexicalSortKey ySortKey)
        {
            int comparison;

            if (xSortKey.TreeOrdinal != ySortKey.TreeOrdinal)
            {
                if (xSortKey.TreeOrdinal < 0)
                {
                    return(1);
                }
                else if (ySortKey.TreeOrdinal < 0)
                {
                    return(-1);
                }

                comparison = xSortKey.TreeOrdinal - ySortKey.TreeOrdinal;
                Debug.Assert(comparison != 0);
                return(comparison);
            }

            return(xSortKey.Position - ySortKey.Position);
        }
 public void SetFrom(LexicalSortKey other)
 {
     Debug.Assert(other.IsInitialized);
     _treeOrdinal = other._treeOrdinal;
     Volatile.Write(ref _position, other._position);
 }
        public static LexicalSortKey First(LexicalSortKey xSortKey, LexicalSortKey ySortKey)
        {
            int comparison = Compare(xSortKey, ySortKey);

            return(comparison > 0 ? ySortKey : xSortKey);
        }