Search in sources :

Example 1 with DumpException

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

the class ClassDumper method save.

@Override
public void save(ClassEntity entity, OutputStream output) throws IOException {
    if (entity.getType() == ClassEntity.Type.CLASS && entity.getData() == null)
        throw new DumpException("Class '" + entity.getName() + "' not compiled");
    DumpOutputStream printer = new DumpOutputStream(output);
    printer.writeBoolean(entity.isStatic());
    // type
    printer.writeEnum(entity.getType());
    printer.writeBoolean(entity.isAbstract());
    printer.writeBoolean(entity.isFinal());
    // print name
    printer.writeName(entity.getName());
    printer.writeName(entity.getCompiledInternalName());
    printer.writeTrace(debugInformation ? entity.getTrace() : null);
    // parent
    ClassEntity parent = entity.getParent();
    if (entity.getParent() != null) {
        printer.writeName(parent.getName());
    } else {
        // write null
        printer.writeName(null);
    }
    // constants
    List<ConstantEntity> constants = new ArrayList<ConstantEntity>();
    for (ConstantEntity el : entity.getConstants()) {
        if (el.isOwned(entity))
            constants.add(el);
    }
    printer.writeInt(constants.size());
    for (ConstantEntity el : constants) {
        constantDumper.save(el, output);
    }
    // properties
    List<PropertyEntity> properties = new ArrayList<PropertyEntity>();
    for (PropertyEntity el : entity.getStaticProperties()) {
        if (el.isOwned(entity))
            properties.add(el);
    }
    for (PropertyEntity el : entity.getProperties()) {
        if (el.isOwned(entity))
            properties.add(el);
    }
    printer.writeInt(properties.size());
    for (PropertyEntity el : properties) {
        propertyDumper.save(el, output);
    }
    // methods
    printer.writeInt(entity.getMethodCounts());
    List<MethodEntity> methods = entity.getOwnedMethods();
    printer.writeInt(methods.size());
    for (MethodEntity el : methods) {
        methodDumper.save(el, output);
    }
    // interfaces
    printer.writeInt(entity.getInterfaces().size());
    for (ClassEntity el : entity.getInterfaces().values()) {
        printer.writeName(el.getName());
    }
    // traits
    printer.writeInt(entity.getTraits().size());
    for (ClassEntity el : entity.getTraits().values()) {
        printer.writeName(el.getName());
    }
    if (includeData) {
        printer.writeRawData(entity.getData(), Integer.MAX_VALUE);
    } else {
        printer.writeRawData(null);
    }
    // addition raw data
    printer.writeRawData(null);
}
Also used : ArrayList(java.util.ArrayList) DumpException(php.runtime.loader.dump.io.DumpException) DumpOutputStream(php.runtime.loader.dump.io.DumpOutputStream)

Example 2 with DumpException

use of php.runtime.loader.dump.io.DumpException 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 3 with DumpException

use of php.runtime.loader.dump.io.DumpException 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());
    // 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 4 with DumpException

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

the class ModuleDumper method save.

@Override
public void save(ModuleEntity entity, OutputStream output) throws IOException {
    if (entity.getData() == null)
        throw new DumpException("Module '" + entity.getName() + "' not compiled");
    DumpOutputStream data = new DumpOutputStream(output);
    // version
    data.writeInt(DUMP_STAMP);
    data.writeInt(DUMP_VERSION);
    // legacy code.
    data.writeEnum(LangMode.DEFAULT);
    // module name
    data.writeName(entity.getContext().getModuleName());
    data.writeName(entity.getInternalName());
    // trace
    data.writeTrace(entity.getTrace());
    // constants
    data.writeInt(entity.getConstants().size());
    for (ConstantEntity e : entity.getConstants()) {
        constantDumper.save(e, output);
    }
    // closures
    data.writeInt(entity.getClosures().size());
    for (ClosureEntity e : entity.getClosures()) {
        closureDumper.save(e, output);
    }
    // generators
    data.writeInt(entity.getGenerators().size());
    for (GeneratorEntity e : entity.getGenerators()) {
        generatorDumper.save(e, output);
    }
    // functions
    data.writeInt(entity.getFunctions().size());
    for (FunctionEntity e : entity.getFunctions()) {
        functionDumper.save(e, output);
    }
    // classes
    data.writeInt(entity.getClasses().size());
    for (ClassEntity e : entity.getClasses()) {
        classDumper.save(e, output);
    }
    if (includeData) {
        // byte code
        data.writeInt(entity.getData().length);
        data.write(entity.getData());
    } else {
        data.writeInt(0);
    }
    // 5 mb
    data.writeRawData(null, 1024 * 1024 * 5);
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) GeneratorEntity(php.runtime.reflection.helper.GeneratorEntity) FunctionEntity(php.runtime.reflection.FunctionEntity) ClosureEntity(php.runtime.reflection.helper.ClosureEntity) DumpException(php.runtime.loader.dump.io.DumpException) DumpOutputStream(php.runtime.loader.dump.io.DumpOutputStream) ConstantEntity(php.runtime.reflection.ConstantEntity)

Example 5 with DumpException

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

DumpException (php.runtime.loader.dump.io.DumpException)8 DumpInputStream (php.runtime.loader.dump.io.DumpInputStream)5 ParameterEntity (php.runtime.reflection.ParameterEntity)5 DumpOutputStream (php.runtime.loader.dump.io.DumpOutputStream)3 FunctionEntity (php.runtime.reflection.FunctionEntity)3 ClosureEntity (php.runtime.reflection.helper.ClosureEntity)3 GeneratorEntity (php.runtime.reflection.helper.GeneratorEntity)3 ClassEntity (php.runtime.reflection.ClassEntity)2 ConstantEntity (php.runtime.reflection.ConstantEntity)2 ArrayList (java.util.ArrayList)1 Closure (php.runtime.lang.Closure)1 DocumentComment (php.runtime.reflection.DocumentComment)1 MethodEntity (php.runtime.reflection.MethodEntity)1 ModuleEntity (php.runtime.reflection.ModuleEntity)1