Search in sources :

Example 1 with DumpInputStream

use of php.runtime.loader.dump.io.DumpInputStream in project jphp by jphp-compiler.

the class PropertyDumper method load.

@Override
public PropertyEntity load(InputStream input) throws IOException {
    PropertyEntity property = new PropertyEntity(context);
    DumpInputStream data = new DumpInputStream(input);
    String docComment = data.readUTF();
    if (!docComment.isEmpty()) {
        property.setDocComment(new DocumentComment(docComment));
    }
    property.setStatic(data.readBoolean());
    property.setModifier(data.readModifier());
    property.setName(data.readName());
    property.setTrace(data.readTrace(context));
    // typed
    property.setNullable(data.readBoolean());
    property.setType(data.readHintType());
    String typeClass = data.readName();
    if (typeClass != null && !typeClass.isEmpty()) {
        property.setTypeClass(typeClass);
    }
    property.setDefault(data.readBoolean());
    property.setDefaultValue(data.readMemory());
    byte[] raw = data.readRawData();
    return property;
}
Also used : DumpInputStream(php.runtime.loader.dump.io.DumpInputStream) DocumentComment(php.runtime.reflection.DocumentComment) PropertyEntity(php.runtime.reflection.PropertyEntity)

Example 2 with DumpInputStream

use of php.runtime.loader.dump.io.DumpInputStream in project jphp by jphp-compiler.

the class StandaloneLibraryDumper method load.

public StandaloneLibrary load(InputStream input) throws IOException {
    StandaloneLibrary library = new StandaloneLibrary();
    DumpInputStream data = new DumpInputStream(input);
    String hash = data.readName();
    if (!HASH.equals(hash)) {
        throw new DumpException("Invalid standalone modules, invalid hash");
    }
    String coreVersion = data.readName();
    String likePhpVersion = data.readName();
    library.setCoreVersion(coreVersion);
    library.setLikePhpVersion(likePhpVersion);
    int count = data.readInt();
    for (int i = 0; i < count; i++) {
        String name = data.readName();
        String internalName = data.readName();
        // classes
        int classesSize = data.readInt();
        Set<String> classes = new HashSet<>();
        for (int j = 0; j < classesSize; j++) {
            classes.add(data.readName());
        }
        // functions
        int functionsSize = data.readInt();
        Set<String> functions = new HashSet<>();
        for (int j = 0; j < functionsSize; j++) {
            functions.add(data.readName());
        }
        // constants
        int constantSize = data.readInt();
        Set<String> constants = new HashSet<>();
        for (int j = 0; j < constantSize; j++) {
            constants.add(data.readName());
        }
        StandaloneLibrary.Module module = new StandaloneLibrary.Module(name, internalName, classes, functions, constants);
        library.addModule(module);
    }
    return library;
}
Also used : DumpInputStream(php.runtime.loader.dump.io.DumpInputStream) DumpException(php.runtime.loader.dump.io.DumpException)

Example 3 with DumpInputStream

use of php.runtime.loader.dump.io.DumpInputStream in project jphp by jphp-compiler.

the class GeneratorDumper method load.

@Override
public GeneratorEntity load(InputStream input) throws IOException {
    GeneratorEntity entity = classDumper.load(input, GeneratorEntity.class);
    DumpInputStream data = new DumpInputStream(input);
    entity.setReturnReference(data.readBoolean());
    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;
    }
    return entity;
}
Also used : GeneratorEntity(php.runtime.reflection.helper.GeneratorEntity) DumpInputStream(php.runtime.loader.dump.io.DumpInputStream) ParameterEntity(php.runtime.reflection.ParameterEntity) DumpException(php.runtime.loader.dump.io.DumpException)

Example 4 with DumpInputStream

use of php.runtime.loader.dump.io.DumpInputStream in project jphp by jphp-compiler.

the class MethodDumper method load.

@Override
public MethodEntity load(InputStream input) throws IOException {
    DumpInputStream data = new DumpInputStream(input);
    MethodEntity entity = new MethodEntity(context);
    String docComment = data.readUTF();
    if (!docComment.isEmpty()) {
        entity.setDocComment(new DocumentComment(docComment));
    }
    // static
    entity.setStatic(data.readBoolean());
    // final
    entity.setFinal(data.readBoolean());
    // abstract
    entity.setAbstract(data.readBoolean());
    entity.setAbstractable(data.readBoolean());
    entity.setImmutable(data.readBoolean());
    entity.setResult(data.readMemory());
    entity.setEmpty(data.readBoolean());
    // ref
    entity.setReturnReference(data.readBoolean());
    // type hinting
    entity.setReturnType(data.readHintType());
    String returnTypeClass = data.readName();
    if (returnTypeClass != null && !returnTypeClass.isEmpty()) {
        entity.setReturnTypeClass(returnTypeClass);
    }
    entity.setReturnTypeNullable(data.readBoolean());
    // uses stack trace
    entity.setUsesStackTrace(data.readBoolean());
    // modifier
    entity.setModifier(data.readModifier());
    // name
    entity.setName(data.readName());
    entity.setInternalName(data.readName());
    // trace
    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;
    }
    data.readRawData();
    return entity;
}
Also used : DumpInputStream(php.runtime.loader.dump.io.DumpInputStream) DocumentComment(php.runtime.reflection.DocumentComment) ParameterEntity(php.runtime.reflection.ParameterEntity) MethodEntity(php.runtime.reflection.MethodEntity) DumpException(php.runtime.loader.dump.io.DumpException)

Example 5 with DumpInputStream

use of php.runtime.loader.dump.io.DumpInputStream 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)

Aggregations

DumpInputStream (php.runtime.loader.dump.io.DumpInputStream)10 DumpException (php.runtime.loader.dump.io.DumpException)6 ParameterEntity (php.runtime.reflection.ParameterEntity)5 DocumentComment (php.runtime.reflection.DocumentComment)3 ConstantEntity (php.runtime.reflection.ConstantEntity)2 FunctionEntity (php.runtime.reflection.FunctionEntity)2 ClosureEntity (php.runtime.reflection.helper.ClosureEntity)2 GeneratorEntity (php.runtime.reflection.helper.GeneratorEntity)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Memory (php.runtime.Memory)1 Modifier (php.runtime.common.Modifier)1 TraceInfo (php.runtime.env.TraceInfo)1 Closure (php.runtime.lang.Closure)1 ClassEntity (php.runtime.reflection.ClassEntity)1 MethodEntity (php.runtime.reflection.MethodEntity)1 ModuleEntity (php.runtime.reflection.ModuleEntity)1 PropertyEntity (php.runtime.reflection.PropertyEntity)1