Search in sources :

Example 11 with ForeachIterator

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();
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) Memory(php.runtime.Memory)

Example 12 with ForeachIterator

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;
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 13 with ForeachIterator

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;
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) Properties(java.util.Properties)

Example 14 with ForeachIterator

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");
    }
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ForeachIterator(php.runtime.lang.ForeachIterator) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) ConstantMemory(php.runtime.memory.helper.ConstantMemory) ClassConstantMemory(php.runtime.memory.helper.ClassConstantMemory) ClassConstantMemory(php.runtime.memory.helper.ClassConstantMemory) ConstantMemory(php.runtime.memory.helper.ConstantMemory) ClassConstantMemory(php.runtime.memory.helper.ClassConstantMemory)

Example 15 with ForeachIterator

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;
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator)

Aggregations

ForeachIterator (php.runtime.lang.ForeachIterator)100 ArrayMemory (php.runtime.memory.ArrayMemory)49 Memory (php.runtime.Memory)47 LongMemory (php.runtime.memory.LongMemory)22 KeyValueMemory (php.runtime.memory.KeyValueMemory)18 ReferenceMemory (php.runtime.memory.ReferenceMemory)16 Invoker (php.runtime.invoke.Invoker)12 ObjectMemory (php.runtime.memory.ObjectMemory)12 IObject (php.runtime.lang.IObject)9 ArrayKeyMemory (php.runtime.memory.helper.ArrayKeyMemory)6 ArrayValueMemory (php.runtime.memory.helper.ArrayValueMemory)6 ShortcutMemory (php.runtime.memory.helper.ShortcutMemory)5 Signature (php.runtime.annotation.Reflection.Signature)4 StringMemory (php.runtime.memory.StringMemory)4 File (java.io.File)3 HashSet (java.util.HashSet)3 Element (org.w3c.dom.Element)3 FastMethod (php.runtime.annotation.Runtime.FastMethod)3 ClassEntity (php.runtime.reflection.ClassEntity)3 PropertyEntity (php.runtime.reflection.PropertyEntity)3