Search in sources :

Example 1 with UninitializedMemory

use of php.runtime.memory.UninitializedMemory 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;
    } else if (memory instanceof UninitializedMemory) {
        writeInt(-4);
        writeUTF(((UninitializedMemory) memory).getArg());
        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) UninitializedMemory(php.runtime.memory.UninitializedMemory) ClassConstantMemory(php.runtime.memory.helper.ClassConstantMemory) UninitializedMemory(php.runtime.memory.UninitializedMemory) ClassConstantMemory(php.runtime.memory.helper.ClassConstantMemory) ConstantMemory(php.runtime.memory.helper.ConstantMemory) ClassConstantMemory(php.runtime.memory.helper.ClassConstantMemory)

Aggregations

Memory (php.runtime.Memory)1 ForeachIterator (php.runtime.lang.ForeachIterator)1 ArrayMemory (php.runtime.memory.ArrayMemory)1 UninitializedMemory (php.runtime.memory.UninitializedMemory)1 ClassConstantMemory (php.runtime.memory.helper.ClassConstantMemory)1 ConstantMemory (php.runtime.memory.helper.ConstantMemory)1