コード例 #1
0
ファイル: DataTypeTransformer.cs プロジェクト: nemerle/reko
 public virtual DataType VisitString(StringType str)
 {
     return(str);
 }
コード例 #2
0
ファイル: DataTypeComparer.cs プロジェクト: feelworld/reko
        /// <summary>
        /// Implements a partial ordering on data types, where
        /// primitives &lt; pointers &lt; arrays &lt; structs &lt; unions
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public int Compare(DataType x, DataType y, int count)
        {
            if (count > 20)
            {
                throw new ApplicationException("Way too deep");                     //$BUG: discover why datatypes recurse so deep.
            }
            int prioX = x.Accept(this);
            int prioY = y.Accept(this);
            int dPrio = prioX - prioY;

            if (dPrio != 0)
            {
                return(dPrio);
            }

            if (x is VoidType)
            {
                return(0);
            }

            PrimitiveType ix = x as PrimitiveType;
            PrimitiveType iy = y as PrimitiveType;

            if (ix != null && iy != null)
            {
                return(ix.Compare(iy));
            }
            if (ix != null)
            {
                return(-1);
            }
            if (iy != null)
            {
                return(1);
            }

            if (x is EnumType || y is EnumType)
            {
                throw new NotImplementedException();
            }

            CodeType cx = x as CodeType;
            CodeType cy = y as CodeType;

            if (cx != null && cy != null)
            {
                return(0);
            }
            if (cx != null)
            {
                return(-1);
            }
            if (cy != null)
            {
                return(1);
            }

            TypeVariable tx = x as TypeVariable;
            TypeVariable ty = y as TypeVariable;

            if (tx != null && ty != null)
            {
                return(tx.Number - ty.Number);
            }

            TypeReference tr_x = x as TypeReference;
            TypeReference tr_y = y as TypeReference;

            if (tr_x != null && tr_y != null)
            {
                var d = StringComparer.InvariantCulture.Compare(tr_x.Name, tr_y.Name);
                if (d != 0)
                {
                    return(d);
                }
                return(Compare(tr_x.Referent, tr_y.Referent, ++count));
            }

            EquivalenceClass ex = x as EquivalenceClass;
            EquivalenceClass ey = y as EquivalenceClass;

            if (ex != null && ey != null)
            {
                return(ex.Number - ey.Number);
            }

            Pointer ptrX = x as Pointer;
            Pointer ptrY = y as Pointer;

            if (ptrX != null && ptrY != null)
            {
                return(Compare(ptrX.Pointee, ptrY.Pointee, ++count));
            }

            MemberPointer mX = x as MemberPointer;
            MemberPointer mY = y as MemberPointer;

            if (mX != null && mY != null)
            {
                int d = Compare(mX.BasePointer, mY.BasePointer, ++count);
                if (d != 0)
                {
                    return(d);
                }
                return(Compare(mX.Pointee, mY.Pointee, ++count));
            }

            StructureType sX = x as StructureType;
            StructureType sY = y as StructureType;

            if (sX != null && sY != null)
            {
                return(Compare(sX, sY, ++count));
            }

            UnionType ux = x as UnionType;
            UnionType uy = y as UnionType;

            if (ux != null && uy != null)
            {
                return(Compare(ux, uy, ++count));
            }
            ArrayType ax = x as ArrayType;
            ArrayType ay = y as ArrayType;

            if (ax != null && ay != null)
            {
                return(Compare(ax, ay, ++count));
            }

            StringType strX = x as StringType;
            StringType strY = y as StringType;

            if (strX != null && strY != null)
            {
                return(Compare(strX, strY, ++count));
            }

            FunctionType fnX = x as FunctionType;
            FunctionType fnY = y as FunctionType;

            if (fnX != null && fnY != null)
            {
                return(Compare(fnX, fnY, ++count));
            }
            throw new NotImplementedException(string.Format("NYI: comparison between {0} and {1}", x.GetType(), y.GetType()));
        }
コード例 #3
0
ファイル: DataTypeComparer.cs プロジェクト: wxjwz/reko
 public int VisitString(StringType str)
 {
     return(String);
 }
コード例 #4
0
 public DataType VisitString(StringType str)
 {
     return(str);
 }