Thread: [Nice-commit] Nice/src/nice/tools/code Types.java,1.56,1.57
Brought to you by:
bonniot
From: <bo...@us...> - 2004-02-25 11:30:35
|
Update of /cvsroot/nice/Nice/src/nice/tools/code In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27227/src/nice/tools/code Modified Files: Types.java Log Message: Separated high-level type operations (in nice.tools.typing.Types) from the ones related to code generation (in nice.tools.code.Types). Index: Types.java =================================================================== RCS file: /cvsroot/nice/Nice/src/nice/tools/code/Types.java,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** Types.java 19 Feb 2004 08:15:33 -0000 1.56 --- Types.java 25 Feb 2004 11:23:28 -0000 1.57 *************** *** 76,80 **** public static void setBytecodeType(Monotype m) { ! m = equivalent(m); if (m instanceof mlsub.typing.TupleType) --- 76,80 ---- public static void setBytecodeType(Monotype m) { ! m = nice.tools.typing.Types.equivalent(m); if (m instanceof mlsub.typing.TupleType) *************** *** 178,186 **** private static Type javaTypeOrNull(Monotype m) { ! Type res = rawJavaType(equivalent(m)); if (res == null) return null; ! boolean maybe = isMaybe(m.equivalent()); if (maybe) return equivalentObjectType(res); --- 178,186 ---- private static Type javaTypeOrNull(Monotype m) { ! Type res = rawJavaType(nice.tools.typing.Types.equivalent(m)); if (res == null) return null; ! boolean maybe = nice.tools.typing.Types.isMaybe(m.equivalent()); if (maybe) return equivalentObjectType(res); *************** *** 612,616 **** return QuoteExp.nullExp; ! TypeConstructor tc = rawType(m).head(); if (tc == null) --- 612,616 ---- return QuoteExp.nullExp; ! TypeConstructor tc = nice.tools.typing.Types.rawType(m).head(); if (tc == null) *************** *** 638,767 **** /**************************************************************** - * Predicates - ****************************************************************/ - - public static boolean isVoid(mlsub.typing.Monotype m) - { - return equivalent(m).head() == PrimitiveType.voidTC; - } - - public static boolean isVoid(mlsub.typing.Polytype t) - { - return isVoid(t.getMonotype()); - } - - public static boolean isPrimitive(TypeConstructor tc) - { - return javaType(tc) instanceof PrimType; - } - - /**************************************************************** - * Manipulations on nice types - ****************************************************************/ - - public static boolean isMaybe(Monotype m) - { - // This is prob. laxist, since getTC() might be different but equivalent to maybeTC (?) - return (m instanceof MonotypeConstructor) - && ((MonotypeConstructor) m).getTC() == PrimitiveType.maybeTC; - } - - public static boolean isSure(Monotype m) - { - // see comment by isMaybe (e?) - return (m instanceof MonotypeConstructor) - && ((MonotypeConstructor) m).getTC() == PrimitiveType.sureTC; - } - - public static Monotype equivalent(Monotype m) - { - return rawType(m).equivalent(); - } - - public static void setMarkedKind(Monotype m) - { - m.setKind(NullnessKind.instance); - } - - public static void makeMarkedType(MonotypeVar m) - { - m.setPersistentKind(NullnessKind.instance); - } - - /** return the type with nullness markers removed */ - public static Monotype rawType(Monotype m) - { - m = m.equivalent(); - if (!(m instanceof MonotypeConstructor)) - { - // It is probably a bug if this happens - //Internal.warning("Not kinded monotype: " + m); - return m; - } - else - return ((MonotypeConstructor) m).getTP()[0]; - } - - /** return the type with nullness markers removed */ - public static Monotype rawType(MonotypeConstructor mc) - { - return mc.getTP()[0]; - } - - /** @return the domain of a functional monotype with nullness marker */ - public static Monotype[] domain(Monotype type) - { - return rawType(type).domain(); - } - - /** @return the domain of a functional polytype with nullness marker */ - public static Monotype[] domain(Polytype type) - { - return rawType(type.getMonotype()).domain(); - } - - /** @return the codomain of a functional polytype with nullness marker */ - public static Monotype codomain(Polytype type) - { - return ((FunType) rawType(type.getMonotype())).codomain(); - } - - /** @return the <code>rank</code>th type parameter of this type, or null. */ - public static Monotype getTypeParameter(Polytype type, int rank) - { - // This can only help - type.simplify(); - - return getTypeParameter(type.getMonotype(), rank); - } - - /** @return the <code>rank</code>th type parameter of this type, or null. */ - public static Monotype getTypeParameter(Monotype type, int rank) - { - // get rid of the nullness part - type = nice.tools.code.Types.rawType(type); - - if (! (type instanceof MonotypeConstructor)) - return null; - - Monotype[] parameters = ((MonotypeConstructor) type).getTP(); - - if (parameters.length <= rank) - return null; - else - return parameters[rank]; - } - - /** - Transforms \forall T:K.U into \forall T:K.sure<U> - */ - public static Polytype addSure(Polytype type) - { - return new Polytype - (type.getConstraint(), - bossa.syntax.Monotype.sure(type.getMonotype())); - } - - /**************************************************************** * Reset the state for a new compilation. ****************************************************************/ --- 638,641 ---- |