Search in sources :

Example 16 with ClassEntity

use of php.runtime.reflection.ClassEntity in project jphp by jphp-compiler.

the class ClassConstantMemory method toImmutable.

@Override
public Memory toImmutable(Environment env, TraceInfo trace) {
    ClassEntity classEntity = env.fetchClass(className, classLowerName, true);
    if (classEntity == null) {
        env.error(trace, ErrorType.E_ERROR, Messages.ERR_CLASS_NOT_FOUND, className);
        return NULL;
    }
    ConstantEntity entity = classEntity.findConstant(name);
    if (entity == null) {
        env.error(trace, ErrorType.E_ERROR, Messages.ERR_UNDEFINED_CLASS_CONSTANT, className + "::" + name);
        return NULL;
    }
    return entity.getValue();
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) ConstantEntity(php.runtime.reflection.ConstantEntity)

Example 17 with ClassEntity

use of php.runtime.reflection.ClassEntity in project jphp by jphp-compiler.

the class PrintR method printClosure.

@Override
protected void printClosure(Closure closure, int level, Set<Integer> used) {
    ClassEntity classEntity = closure.getReflection();
    writeObjectHeader(Closure.class.getSimpleName());
    if (used.contains(closure.getPointer())) {
        printer.write(" *RECURSION*");
    } else {
        printer.write(StringUtils.repeat(' ', level));
        writeOpen();
        level += PRINT_INDENT;
        used.add(closure.getPointer());
        level -= PRINT_INDENT;
        printer.write(StringUtils.repeat(' ', level));
        writeClose();
        used.remove(closure.getPointer());
    }
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) Closure(php.runtime.lang.Closure)

Example 18 with ClassEntity

use of php.runtime.reflection.ClassEntity in project jphp by jphp-compiler.

the class VarDump method printClosure.

@Override
protected void printClosure(Closure closure, int level, Set<Integer> used) {
    ClassEntity classEntity = closure.getReflection();
    if (used.contains(closure.getPointer())) {
        printer.write("*RECURSION*\n");
    } else {
        printer.write("object(");
        printer.write(Closure.class.getSimpleName());
        printer.write(")#" + closure.getPointer());
        printer.write(" (" + closure.getUses().length + ") {\n");
        level += PRINT_INDENT;
        used.add(closure.getPointer());
        level -= PRINT_INDENT;
        printer.write(StringUtils.repeat(' ', level));
        printer.write("}\n");
        used.remove(closure.getPointer());
    }
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) Closure(php.runtime.lang.Closure)

Example 19 with ClassEntity

use of php.runtime.reflection.ClassEntity in project jphp by jphp-compiler.

the class VarDump method printObject.

@Override
protected void printObject(ObjectMemory value, int level, Set<Integer> used) {
    ClassEntity classEntity = value.getReflection();
    if (used.contains(value.getPointer())) {
        printer.write("*RECURSION*\n");
    } else {
        ArrayMemory arr;
        if (classEntity.methodMagicDebugInfo != null) {
            try {
                Memory tmp = env.invokeMethod(value.value, classEntity.methodMagicDebugInfo.getName());
                if (tmp.isArray()) {
                    arr = tmp.toValue(ArrayMemory.class);
                } else {
                    arr = new ArrayMemory();
                }
            } catch (RuntimeException e) {
                throw e;
            } catch (Throwable throwable) {
                throw new RuntimeException(throwable);
            }
        } else
            arr = value.getProperties();
        printer.write("object(");
        printer.write(classEntity.getName());
        printer.write(")#" + value.getPointer());
        printer.write(" (" + arr.size() + ") {\n");
        level += 1;
        used.add(value.getPointer());
        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('"');
                    printer.write(":getter]=>\n");
                    printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
                    try {
                        print(entity.getValue(env, TraceInfo.UNKNOWN, value.value), level, used);
                    } catch (RuntimeException e) {
                        throw e;
                    } catch (Throwable throwable) {
                        throw new RuntimeException(throwable);
                    }
                }
            }
        }
        ForeachIterator iterator = arr.foreachIterator(false, false);
        while (iterator.next()) {
            printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
            Memory key = iterator.getMemoryKey();
            printer.write('[');
            if (key.isString()) {
                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('"');
                printer.write(realKey);
                printer.write('"');
                switch(modifier) {
                    case PRIVATE:
                        printer.write(":\"" + className + "\":private");
                        break;
                    case PROTECTED:
                        printer.write(":protected");
                }
            } else {
                printer.write(key.toString());
            }
            printer.write("]=>\n");
            printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
            print(iterator.getValue(), level, used);
        //printer.write('\n');
        }
        level -= 1;
        printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
        printer.write("}\n");
        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 20 with ClassEntity

use of php.runtime.reflection.ClassEntity in project jphp by jphp-compiler.

the class ObjectMemory method compare.

private boolean compare(Memory other, Comparator comparator) {
    switch(other.type) {
        case OBJECT:
            ClassEntity otherReflection = ((ObjectMemory) other).getReflection();
            if (otherReflection.getId() != getReflection().getId())
                return false;
            IObject otherObject = ((ObjectMemory) other).value;
            return comparator.compare(value, otherObject);
        case REFERENCE:
            return compare(other.toValue(), comparator);
    }
    return false;
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity)

Aggregations

ClassEntity (php.runtime.reflection.ClassEntity)54 ObjectMemory (php.runtime.memory.ObjectMemory)21 Memory (php.runtime.Memory)14 ArrayMemory (php.runtime.memory.ArrayMemory)14 PropertyEntity (php.runtime.reflection.PropertyEntity)10 MethodEntity (php.runtime.reflection.MethodEntity)9 StringMemory (php.runtime.memory.StringMemory)8 ConstantEntity (php.runtime.reflection.ConstantEntity)5 FunctionEntity (php.runtime.reflection.FunctionEntity)5 CriticalException (php.runtime.exceptions.CriticalException)4 Closure (php.runtime.lang.Closure)4 IObject (php.runtime.lang.IObject)4 ReferenceMemory (php.runtime.memory.ReferenceMemory)4 ClosureEntity (php.runtime.reflection.helper.ClosureEntity)4 GeneratorEntity (php.runtime.reflection.helper.GeneratorEntity)4 ForeachIterator (php.runtime.lang.ForeachIterator)3 ModuleEntity (php.runtime.reflection.ModuleEntity)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2