예제 #1
0
 public DataType VisitPrimitive(PrimitiveType pt)
 {
     return(pt);
 }
예제 #2
0
        public int CompareInternal(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)
            {
                return(StringComparer.InvariantCulture.Compare(tr_x.Name, tr_y.Name));
            }

            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));
            }

            ReferenceTo rX = x as ReferenceTo;
            ReferenceTo rY = y as ReferenceTo;

            if (rX != null && rY != null)
            {
                return(Compare(rX.Referent, rY.Referent, ++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
 public int VisitPrimitive(PrimitiveType pt)
 {
     return(Prim);
 }
예제 #4
0
 public Formatter VisitPrimitive(PrimitiveType pt)
 {
     writer.Write(pt.Name);
     return(writer);
 }
예제 #5
0
 public static StringType LengthPrefixedStringType(PrimitiveType charType, PrimitiveType lengthPrefixType)
 {
     return(new StringType(charType, lengthPrefixType, 0));
 }
예제 #6
0
 public static bool TryParse(string primitiveTypeName, out PrimitiveType type)
 {
     return(lookupByName.TryGetValue(primitiveTypeName, out type));
 }