[Nice-commit] Nice/src/nice/tools/code TupleType.java,NONE,1.1 Types.java,1.47,1.48
Brought to you by:
bonniot
|
From: <bo...@us...> - 2003-03-17 20:11:50
|
Update of /cvsroot/nice/Nice/src/nice/tools/code
In directory sc8-pr-cvs1:/tmp/cvs-serv9380/src/nice/tools/code
Modified Files:
Types.java
Added Files:
TupleType.java
Log Message:
Correctly handle nested tuples involving primitive subtyping.
--- NEW FILE: TupleType.java ---
/**************************************************************************/
/* N I C E */
/* A high-level object-oriented research language */
/* (c) Daniel Bonniot 2002 */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License, or */
/* (at your option) any later version. */
/* */
/**************************************************************************/
package nice.tools.code;
/**
The bytecode type of a tuple.
@version $Date: 2003/03/17 20:11:42 $
@author Daniel Bonniot (bo...@us...)
*/
import gnu.bytecode.*;
public class TupleType extends ArrayType
{
TupleType (Type arrayType, Type[] componentTypes)
{
super (arrayType);
this.componentTypes = componentTypes;
}
TupleType (Type[] componentTypes)
{
this(Types.lowestCommonSupertype(componentTypes), componentTypes);
}
public Type[] componentTypes;
public static gnu.expr.Expression createExp
(Type arrayType, Type[] componentTypes,
gnu.expr.Expression[] components)
{
return new gnu.expr.ApplyExp
(new nice.tools.code.LiteralArrayProc
(new TupleType(arrayType, componentTypes), components.length),
components);
}
}
Index: Types.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/nice/tools/code/Types.java,v
retrieving revision 1.47
retrieving revision 1.48
diff -C2 -d -r1.47 -r1.48
*** Types.java 13 Mar 2003 23:33:45 -0000 1.47
--- Types.java 17 Mar 2003 20:11:41 -0000 1.48
***************
*** 78,83 ****
m = equivalent(m);
! if (m instanceof TupleType)
! setBytecodeType(((TupleType) m).getComponents());
TypeConstructor tc = m.head();
--- 78,83 ----
m = equivalent(m);
! if (m instanceof mlsub.typing.TupleType)
! setBytecodeType(((mlsub.typing.TupleType) m).getComponents());
TypeConstructor tc = m.head();
***************
*** 176,182 ****
return res;
! if (m instanceof TupleType)
! // not SpecialArray
! return ArrayType.make(componentType((TupleType) m));
if (m instanceof FunType)
--- 176,181 ----
return res;
! if (m instanceof mlsub.typing.TupleType)
! return new TupleType(javaType(((mlsub.typing.TupleType) m).getComponents()));
if (m instanceof FunType)
***************
*** 211,220 ****
}
- /** Returns the common bytecode type used for elements of this tuple. */
- public static Type componentType(TupleType t)
- {
- return lowestCommonSupertype(t.getComponents());
- }
-
/**
@return the most precise bytecode type able to store values of the given
--- 210,213 ----
***************
*** 226,229 ****
--- 219,234 ----
for (int i = 1; res!=null && i<types.length; i++)
res = Type.lowestCommonSuperType(res, javaType(types[i]));
+
+ if (res == null)
+ return Type.pointer_type;
+ else
+ return res;
+ }
+
+ static Type lowestCommonSupertype(Type[] types)
+ {
+ Type res = types[0];
+ for (int i = 1; res != null && i < types.length; i++)
+ res = Type.lowestCommonSuperType(res, types[i]);
if (res == null)
|