[Nice-commit] Nice/stdlib/nice/lang/inline ArraySetOp.java,1.3,1.4
Brought to you by:
bonniot
|
From: <bo...@us...> - 2003-03-06 00:50:10
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang/inline
In directory sc8-pr-cvs1:/tmp/cvs-serv13625/stdlib/nice/lang/inline
Modified Files:
ArraySetOp.java
Log Message:
Fixes setting to an array whose component type is not known precisely,
but is constrained below some primitive type.
Index: ArraySetOp.java
===================================================================
RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/inline/ArraySetOp.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ArraySetOp.java 26 Nov 2001 15:31:49 -0000 1.3
--- ArraySetOp.java 6 Mar 2003 00:50:07 -0000 1.4
***************
*** 39,47 ****
{
this.type = type;
- arrayTarget = new StackTarget(nice.tools.code.SpecialTypes.array(type));
}
private final Type type;
- private final StackTarget arrayTarget;
public void compile (ApplyExp exp, Compilation comp, Target target)
--- 39,45 ----
***************
*** 49,65 ****
Expression[] args = exp.getArgs();
CodeAttr code = comp.getCode();
!
! args[0].compile(comp, arrayTarget);
boolean bytecodeArray = Tools.monomorphicArray(code.topType());
args[1].compile(comp, Tools.intTarget);
! args[2].compile(comp, type);
if (bytecodeArray)
! code.emitArrayStore(type);
else
! code.emitInvokeStatic(reflectGet);
}
! private static Method reflectGet =
ClassType.make("java.lang.reflect.Array").getDeclaredMethod("set", 3);
--- 47,71 ----
Expression[] args = exp.getArgs();
CodeAttr code = comp.getCode();
!
! args[0].compile(comp, Target.pushObject);
boolean bytecodeArray = Tools.monomorphicArray(code.topType());
args[1].compile(comp, Tools.intTarget);
!
! Type componentType = type;
! // Try to get bytecode type information from the target array.
! if (type == Type.pointer_type)
! try {
! componentType = ((ArrayType) args[0].getType()).getComponentType();
! }
! catch (ClassCastException ex) {}
! args[2].compile(comp, componentType);
if (bytecodeArray)
! code.emitArrayStore(componentType);
else
! code.emitInvokeStatic(reflectSet);
}
! private static Method reflectSet =
ClassType.make("java.lang.reflect.Array").getDeclaredMethod("set", 3);
|