use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.
the class Serializer method writeArray.
public void writeArray(ArrayMemory memory, Set<Integer> used, boolean appendType) {
if (used.add(memory.getPointer())) {
if (appendType)
printer.append("a:");
printer.append(String.valueOf(memory.size())).append(":{");
ForeachIterator iterator = memory.foreachIterator(false, false);
while (iterator.next()) {
Memory key = iterator.getMemoryKey();
write(key);
if (iterator.getValue().isReference())
writeNull();
else
write(iterator.getValue());
}
printer.append("}");
used.remove(memory.getPointer());
} else
writeNull();
}
use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.
the class ArrayMemoryOperation method convert.
@Override
@SuppressWarnings("unchecked")
public Object convert(Environment env, TraceInfo trace, Memory arg) throws Throwable {
ForeachIterator iterator = arg.getNewIterator(env);
if (iterator == null) {
return null;
}
List tmp = new ArrayList();
while (iterator.next()) {
tmp.add(operation.convert(env, trace, iterator.getValue()));
}
Object[] r = (Object[]) Array.newInstance(arrayElementClass, tmp.size());
for (int i = 0; i < r.length; i++) {
r[i] = tmp.get(i);
}
return r;
}
use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.
the class PropertiesMemoryOperation method convert.
@Override
public Properties convert(Environment env, TraceInfo trace, Memory arg) throws Throwable {
if (arg == Memory.NULL) {
return null;
}
Properties properties = new Properties();
ForeachIterator iterator = arg.getNewIterator(env);
while (iterator.next()) {
if (iterator.getValue().isNull()) {
properties.setProperty(iterator.getKey().toString(), null);
} else {
properties.setProperty(iterator.getKey().toString(), iterator.getValue().toString());
}
}
return properties;
}
use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.
the class DumpOutputStream method writeMemory.
public void writeMemory(Memory memory) throws IOException {
if (memory == null) {
writeInt(-1);
return;
}
memory = memory.toValue();
if (memory instanceof ConstantMemory) {
writeInt(-2);
writeUTF(((ConstantMemory) memory).getName());
return;
} else if (memory instanceof ClassConstantMemory) {
writeInt(-3);
writeUTF(((ClassConstantMemory) memory).getClassName());
writeUTF(((ClassConstantMemory) memory).getName());
return;
}
Memory.Type type = memory.getRealType();
writeInt(type.ordinal());
switch(type) {
case NULL:
break;
case INT:
writeLong(memory.toLong());
break;
case STRING:
writeUTF(memory.toString());
break;
case DOUBLE:
writeDouble(memory.toDouble());
break;
case BOOL:
writeBoolean(memory.toBoolean());
break;
case ARRAY:
ArrayMemory array = memory.toValue(ArrayMemory.class);
if (array.size() > Short.MAX_VALUE)
throw new DumpException("Array is too big");
writeInt(array.size());
ForeachIterator foreachIterator = array.foreachIterator(false, false);
while (foreachIterator.next()) {
Memory key = foreachIterator.getMemoryKey();
Memory value = foreachIterator.getValue();
if (value.isShortcut())
throw new DumpException("Cannot dump references");
if (value.toValue() != Memory.UNDEFINED) {
writeMemory(key);
writeMemory(value.toValue());
}
}
break;
case OBJECT:
default:
throw new DumpException("Cannot dump " + type.toString() + " memory");
}
}
use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.
the class ArrayMemory method toDoubleMap.
public Map<String, Double> toDoubleMap() {
Map<String, Double> r = new LinkedHashMap<String, Double>();
ForeachIterator iterator = foreachIterator(false, false);
while (iterator.next()) {
r.put(iterator.getKey().toString(), iterator.getValue().toDouble());
}
return r;
}
Aggregations