Search in sources :

Example 96 with ForeachIterator

use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.

the class PrintR method printObject.

@Override
protected void printObject(ObjectMemory value, int level, Set<Integer> used) {
    ClassEntity classEntity = value.getReflection();
    writeObjectHeader(classEntity.getName());
    if (used.contains(value.getPointer())) {
        printer.write(" *RECURSION*");
    } else {
        printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
        writeOpen();
        level += 1;
        used.add(value.getPointer());
        ArrayMemory props;
        if (env != null && classEntity.methodMagicDebugInfo != null) {
            try {
                Memory tmp = env.invokeMethod(value.value, classEntity.methodMagicDebugInfo.getName());
                if (tmp.isArray()) {
                    props = tmp.toValue(ArrayMemory.class);
                } else {
                    props = new ArrayMemory();
                }
            } catch (RuntimeException e) {
                throw e;
            } catch (Throwable throwable) {
                throw new RuntimeException(throwable);
            }
        } else {
            props = value.getProperties();
        }
        if (classEntity.methodMagicDebugInfo != null) {
            for (PropertyEntity entity : classEntity.getProperties()) {
                if (entity.getGetter() != null && !entity.isHiddenInDebugInfo()) {
                    printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
                    printer.write("[");
                    printer.write(entity.getName());
                    printer.write(":getter] => ");
                    try {
                        print(entity.getValue(env, TraceInfo.UNKNOWN, value.value));
                    } catch (RuntimeException e) {
                        throw e;
                    } catch (Throwable throwable) {
                        throw new RuntimeException(throwable);
                    }
                    writeSeparator(false);
                }
            }
        }
        if (props != null) {
            ForeachIterator iterator = props.foreachIterator(false, false);
            int i = 0;
            int size = classEntity.properties.size();
            while (iterator.next()) {
                printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
                Object key = iterator.getKey();
                printer.write('[');
                String realKey = key.toString();
                int pos;
                Modifier modifier = Modifier.PUBLIC;
                String className = "";
                if ((pos = realKey.lastIndexOf("\0")) > -1) {
                    if (realKey.startsWith("\0*\0")) {
                        modifier = Modifier.PROTECTED;
                    } else {
                        modifier = Modifier.PRIVATE;
                        className = realKey.substring(1, pos);
                    }
                    realKey = realKey.substring(pos + 1);
                }
                printer.write(realKey);
                switch(modifier) {
                    case PRIVATE:
                        printer.write(":" + className + ":private");
                        break;
                    case PROTECTED:
                        printer.write(":protected");
                }
                printer.write("] => ");
                print(iterator.getValue(), level + 1, used);
                writeSeparator(i == size - 1);
                i++;
            }
        }
        level -= 1;
        printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
        writeClose();
        used.remove(value.getPointer());
    }
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) ForeachIterator(php.runtime.lang.ForeachIterator) PropertyEntity(php.runtime.reflection.PropertyEntity) Memory(php.runtime.Memory) Modifier(php.runtime.common.Modifier)

Example 97 with ForeachIterator

use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.

the class VarDump method printArray.

@Override
protected void printArray(ArrayMemory value, int level, Set<Integer> used) {
    if (used.contains(value.getPointer())) {
        printer.write("*RECURSION*\n");
    } else {
        printer.write("array(");
        printer.write(value.size() + "");
        printer.write(") {\n");
        level += 1;
        used.add(value.getPointer());
        ForeachIterator iterator = value.foreachIterator(false, false);
        while (iterator.next()) {
            Memory el = iterator.getValue();
            if (el == Memory.UNDEFINED)
                continue;
            printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
            Memory key = iterator.getMemoryKey();
            printer.write('[');
            if (key.isString()) {
                printer.write('"');
                printer.write(key.toString());
                printer.write('"');
            } else {
                printer.write(key.toString());
            }
            printer.write("]=>\n");
            printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
            print(el, level, used);
        //printer.write('\n');
        }
        level -= 1;
        printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
        printer.write("}\n");
        used.remove(value.getPointer());
    }
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) Memory(php.runtime.Memory)

Example 98 with ForeachIterator

use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.

the class ArrayMemory method resetCurrentIterator.

public Memory resetCurrentIterator() {
    reset();
    ForeachIterator iterator = getCurrentIterator();
    if (size == 0)
        return FALSE;
    else {
        iterator.next();
        Memory tmp = iterator.getValue();
        iterator.prev();
        return tmp;
    }
}
Also used : ForeachIterator(php.runtime.lang.ForeachIterator) ShortcutMemory(php.runtime.memory.helper.ShortcutMemory) Memory(php.runtime.Memory) ArrayKeyMemory(php.runtime.memory.helper.ArrayKeyMemory) ArrayValueMemory(php.runtime.memory.helper.ArrayValueMemory)

Example 99 with ForeachIterator

use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.

the class ClassEntity method cloneObject.

public <T extends IObject> T cloneObject(T value, Environment env, TraceInfo trace) throws Throwable {
    IObject copy = this.newObjectWithoutConstruct(env);
    ForeachIterator iterator = value.getProperties().foreachIterator(false, false);
    ArrayMemory props = copy.getProperties();
    while (iterator.next()) {
        Object key = iterator.getKey();
        if (key instanceof String) {
            String name = (String) key;
            if (name.indexOf('\0') > -1)
                name = name.substring(name.lastIndexOf('\0') + 1);
            PropertyEntity entity = properties.get(name);
            if (entity != null) {
                if (props.getByScalar(entity.getSpecificName()) == null)
                    props.put(entity.getSpecificName(), iterator.getValue().toImmutable());
            } else
                props.put(key, iterator.getValue().toImmutable());
        } else
            props.put(key, iterator.getValue().toImmutable());
    }
    if (methodMagicClone != null) {
        ObjectInvokeHelper.invokeMethod(copy, methodMagicClone, env, trace, null, true);
    }
    return (T) copy;
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ForeachIterator(php.runtime.lang.ForeachIterator) IObject(php.runtime.lang.IObject) IObject(php.runtime.lang.IObject)

Example 100 with ForeachIterator

use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.

the class ArrayMemory method slice.

public ArrayMemory slice(int offset, boolean saveKeys) {
    ArrayMemory result = new ArrayMemory();
    if (offset < 0) {
        offset = size() + offset;
    }
    if (isList()) {
        int i = 0;
        try {
            for (ReferenceMemory referenceMemory : list.subList(offset, list.size())) {
                if (saveKeys) {
                    result.refOfIndex(i + offset).assign(referenceMemory.toImmutable());
                } else {
                    result.add(referenceMemory.toImmutable());
                }
                i++;
            }
        } catch (IllegalArgumentException e) {
            throw new IndexOutOfBoundsException(e.getMessage());
        }
    } else {
        int i = 0;
        ForeachIterator iterator = foreachIterator(false, false);
        while (iterator.next()) {
            if (i >= offset) {
                if (saveKeys || !iterator.isLongKey()) {
                    result.put(iterator.getKey(), iterator.getValue().toImmutable());
                } else {
                    result.add(iterator.getValue().toImmutable());
                }
            }
            i++;
        }
    }
    return result;
}
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