Search in sources :

Example 21 with ParameterEntity

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

the class ClosureDumper method load.

@Override
public ClosureEntity load(InputStream input) throws IOException {
    DumpInputStream data = new DumpInputStream(input);
    ClosureEntity entity = new ClosureEntity(context);
    entity.setParent(env.scope.fetchUserClass(Closure.class));
    entity.setInternalName(data.readName());
    entity.setReturnReference(data.readBoolean());
    entity.methodMagicInvoke = methodDumper.load(input);
    entity.methodMagicInvoke.setClazz(entity);
    entity.addMethod(entity.methodMagicInvoke, null);
    int paramCount = data.readInt();
    if (paramCount < 0)
        throw new DumpException("Invalid param count");
    entity.parameters = new ParameterEntity[paramCount];
    for (int i = 0; i < paramCount; i++) {
        ParameterEntity param = parameterDumper.load(input);
        param.setTrace(entity.getTrace());
        entity.parameters[i] = param;
    }
    paramCount = data.readInt();
    if (paramCount < 0)
        throw new DumpException("Invalid param count");
    entity.uses = new ParameterEntity[paramCount];
    for (int i = 0; i < paramCount; i++) {
        ParameterEntity param = parameterDumper.load(input);
        param.setTrace(entity.getTrace());
        entity.uses[i] = param;
    }
    entity.setData(data.readRawData(Integer.MAX_VALUE));
    return entity;
}
Also used : DumpInputStream(php.runtime.loader.dump.io.DumpInputStream) ParameterEntity(php.runtime.reflection.ParameterEntity) Closure(php.runtime.lang.Closure) ClosureEntity(php.runtime.reflection.helper.ClosureEntity) DumpException(php.runtime.loader.dump.io.DumpException)

Example 22 with ParameterEntity

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

the class ClosureDumper method save.

@Override
public void save(ClosureEntity entity, OutputStream output) throws IOException {
    if (!entity.isLoaded())
        throw new DumpException("Closure not loaded");
    DumpOutputStream data = new DumpOutputStream(output);
    data.writeName(entity.getInternalName());
    data.writeBoolean(entity.isReturnReference());
    methodDumper.save(entity.methodMagicInvoke, output);
    data.writeInt(entity.parameters == null ? 0 : entity.parameters.length);
    if (entity.parameters != null)
        for (ParameterEntity param : entity.parameters) {
            parameterDumper.save(param, output);
        }
    data.writeInt(entity.uses == null ? 0 : entity.uses.length);
    if (entity.uses != null)
        for (ParameterEntity param : entity.uses) {
            parameterDumper.save(param, output);
        }
    if (includeData) {
        data.writeRawData(entity.getData(), Integer.MAX_VALUE);
    } else {
        data.writeRawData(null);
    }
}
Also used : ParameterEntity(php.runtime.reflection.ParameterEntity) DumpException(php.runtime.loader.dump.io.DumpException) DumpOutputStream(php.runtime.loader.dump.io.DumpOutputStream)

Example 23 with ParameterEntity

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

the class FunctionDumper method save.

@Override
public void save(FunctionEntity entity, OutputStream output) throws IOException {
    DumpOutputStream data = new DumpOutputStream(output);
    data.writeBoolean(entity.isStatic());
    // name
    data.writeName(entity.getName());
    data.writeName(entity.getInternalName());
    data.writeBoolean(entity.isReturnReference());
    data.writeBoolean(entity.isUsesStackTrace());
    data.writeBoolean(entity.isImmutable());
    data.writeMemory(entity.getImmutableResult());
    data.writeBoolean(entity.isEmpty());
    // trace
    data.writeTrace(debugInformation ? entity.getTrace() : null);
    data.writeInt(entity.getParameters() == null ? 0 : entity.getParameters().length);
    if (entity.getParameters() != null)
        for (ParameterEntity param : entity.getParameters()) {
            parameterDumper.save(param, output);
        }
    if (includeData) {
        data.writeRawData(entity.getData());
    } else {
        data.writeRawData(null);
    }
    data.writeRawData(null);
}
Also used : ParameterEntity(php.runtime.reflection.ParameterEntity) DumpOutputStream(php.runtime.loader.dump.io.DumpOutputStream)

Example 24 with ParameterEntity

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

the class FunctionDumper method load.

@Override
public FunctionEntity load(InputStream input) throws IOException {
    DumpInputStream data = new DumpInputStream(input);
    FunctionEntity entity = new FunctionEntity(context);
    entity.setStatic(data.readBoolean());
    entity.setName(data.readName());
    entity.setInternalName(data.readName());
    entity.setReturnReference(data.readBoolean());
    entity.setUsesStackTrace(data.readBoolean());
    entity.setImmutable(data.readBoolean());
    entity.setResult(data.readMemory());
    entity.setEmpty(data.readBoolean());
    entity.setTrace(data.readTrace(context));
    int paramCount = data.readInt();
    if (paramCount < 0)
        throw new DumpException("Invalid param count");
    entity.setParameters(new ParameterEntity[paramCount]);
    for (int i = 0; i < paramCount; i++) {
        ParameterEntity param = parameterDumper.load(input);
        param.setTrace(entity.getTrace());
        entity.getParameters()[i] = param;
    }
    entity.setData(data.readRawData(Integer.MAX_VALUE));
    data.readRawData();
    return entity;
}
Also used : DumpInputStream(php.runtime.loader.dump.io.DumpInputStream) FunctionEntity(php.runtime.reflection.FunctionEntity) ParameterEntity(php.runtime.reflection.ParameterEntity) DumpException(php.runtime.loader.dump.io.DumpException)

Example 25 with ParameterEntity

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

the class GeneratorDumper method save.

@Override
public void save(GeneratorEntity entity, OutputStream output) throws IOException {
    classDumper.save(entity, output);
    DumpOutputStream printer = new DumpOutputStream(output);
    printer.writeBoolean(entity.isReturnReference());
    printer.writeInt(entity.parameters == null ? 0 : entity.parameters.length);
    if (entity.parameters != null) {
        for (ParameterEntity param : entity.parameters) {
            parameterDumper.save(param, output);
        }
    }
}
Also used : ParameterEntity(php.runtime.reflection.ParameterEntity) DumpOutputStream(php.runtime.loader.dump.io.DumpOutputStream)

Aggregations

ParameterEntity (php.runtime.reflection.ParameterEntity)27 Test (org.junit.Test)8 ObjectMemory (php.runtime.memory.ObjectMemory)7 ArrayMemory (php.runtime.memory.ArrayMemory)6 Memory (php.runtime.Memory)5 DumpException (php.runtime.loader.dump.io.DumpException)5 DumpInputStream (php.runtime.loader.dump.io.DumpInputStream)5 DumpOutputStream (php.runtime.loader.dump.io.DumpOutputStream)4 ReferenceMemory (php.runtime.memory.ReferenceMemory)3 VariadicMemory (php.runtime.memory.helper.VariadicMemory)3 DocumentComment (php.runtime.reflection.DocumentComment)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ForeachIterator (php.runtime.lang.ForeachIterator)2 ClassEntity (php.runtime.reflection.ClassEntity)2 FunctionEntity (php.runtime.reflection.FunctionEntity)2 MethodEntity (php.runtime.reflection.MethodEntity)2 ClosureEntity (php.runtime.reflection.helper.ClosureEntity)2 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1