* write out list loop
* @param adapter
* @throws TemplateException
*/
private void writeOutTypeListArray(BytecodeContext bc, boolean isArray) throws BytecodeException {
ForVisitor forVisitor = new ForVisitor();
loopVisitor=forVisitor;
GeneratorAdapter adapter = bc.getAdapter();
//List.listToArrayRemoveEmpty("", 'c')
int array = adapter.newLocal(Types.ARRAY);
int len = adapter.newLocal(Types.INT_VALUE);
if(isArray) {
getAttribute("array").getValue().writeOut(bc, Expression.MODE_REF);
}
else {
// array=List.listToArrayRemoveEmpty(list, delimter)
getAttribute("list").getValue().writeOut(bc, Expression.MODE_REF);
if(containsAttribute("delimiters")) {
getAttribute("delimiters").getValue().writeOut(bc, Expression.MODE_REF);
adapter.invokeStatic(Types.LIST_UTIL, LIST_TO_ARRAY_REMOVE_EMPTY_SS);
}
else {
adapter.visitIntInsn(Opcodes.BIPUSH, 44);// ','
//adapter.push(',');
adapter.invokeStatic(Types.LIST_UTIL, LIST_TO_ARRAY_REMOVE_EMPTY_SC);
}
}
adapter.storeLocal(array);
// int len=array.size();
adapter.loadLocal(array);
adapter.invokeInterface(Types.ARRAY, SIZE);
adapter.storeLocal(len);
//VariableInterpreter.getVariableReference(pc,Caster.toString(index));
Attribute attrIndex = getAttribute("index");
int index = -1;
if(attrIndex!=null) {
index = adapter.newLocal(Types.VARIABLE_REFERENCE);
adapter.loadArg(0);
attrIndex.getValue().writeOut(bc, Expression.MODE_REF);
adapter.invokeStatic(Types.VARIABLE_INTERPRETER, GET_VARIABLE_REFERENCE);
adapter.storeLocal(index);
}
//VariableInterpreter.getVariableReference(pc,Caster.toString(item));
Attribute attrItem = getAttribute("item");
int item = -1;
if(attrItem!=null) {
item = adapter.newLocal(Types.VARIABLE_REFERENCE);
adapter.loadArg(0);
attrItem.getValue().writeOut(bc, Expression.MODE_REF);
adapter.invokeStatic(Types.VARIABLE_INTERPRETER, GET_VARIABLE_REFERENCE);
adapter.storeLocal(item);
}
int obj=0;
if(isArray)obj=adapter.newLocal(Types.OBJECT);
// for(int i=1;i<=len;i++) {
int i = forVisitor.visitBegin(adapter, 1, false);
// index.set(pc, list.get(i));
if(isArray) {
// value
adapter.loadLocal(array);
adapter.visitVarInsn(Opcodes.ILOAD, i);
ASMConstants.NULL(adapter);
adapter.invokeInterface(Types.ARRAY, GET);
adapter.dup();
adapter.storeLocal(obj);
Label endIf=new Label();
//adapter.loadLocal(obj);
adapter.visitJumpInsn(Opcodes.IFNONNULL, endIf);
adapter.goTo(forVisitor.getContinueLabel());
adapter.visitLabel(endIf);
if(item==-1) adapter.loadLocal(index);
else adapter.loadLocal(item);
adapter.loadArg(0);
adapter.loadLocal(obj);
}
else {
if(item==-1) adapter.loadLocal(index);
else adapter.loadLocal(item);
adapter.loadArg(0);
adapter.loadLocal(array);
adapter.visitVarInsn(Opcodes.ILOAD, i);
adapter.invokeInterface(Types.ARRAY, GETE);
}
adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET);
adapter.pop();
// key
if(index!=-1 && item!=-1) {
adapter.loadLocal(index);
adapter.loadArg(0);
adapter.visitVarInsn(Opcodes.ILOAD, i);
adapter.cast(Types.INT_VALUE,Types.DOUBLE_VALUE);
adapter.invokeStatic(Types.CASTER,Methods_Caster.TO_DOUBLE[Methods_Caster.DOUBLE]);
adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET);
adapter.pop();
}
getBody().writeOut(bc);
forVisitor.visitEnd(bc, len, true,getStart());
}