Search in sources :

Example 6 with ConstantEntity

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

the class ConstantDumper method load.

@Override
public ConstantEntity load(InputStream input) throws IOException {
    DumpInputStream dump = new DumpInputStream(input);
    boolean cs = dump.readBoolean();
    Modifier modifier = dump.readModifier();
    String name = dump.readName();
    TraceInfo trace = dump.readTrace(context);
    Memory value = dump.readMemory();
    ConstantEntity entity = new ConstantEntity(name, value, cs);
    entity.setContext(context);
    entity.setTrace(trace);
    dump.readRawData();
    return entity;
}
Also used : DumpInputStream(php.runtime.loader.dump.io.DumpInputStream) Memory(php.runtime.Memory) TraceInfo(php.runtime.env.TraceInfo) Modifier(php.runtime.common.Modifier) ConstantEntity(php.runtime.reflection.ConstantEntity)

Example 7 with ConstantEntity

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

the class ModuleDumper method load.

@Override
public ModuleEntity load(InputStream input) throws IOException {
    DumpInputStream data = new DumpInputStream(input);
    int STAMP = data.readInt();
    if (STAMP != DUMP_STAMP)
        throw new DumpException("Invalid file format");
    int VERSION = data.readInt();
    if (VERSION != DUMP_VERSION)
        throw new DumpException("Invalid dump version - " + VERSION + ", only " + DUMP_VERSION);
    // legacy
    data.readLangMode();
    ModuleEntity entity = new ModuleEntity(context);
    entity.setName(data.readName());
    entity.setInternalName(data.readName());
    entity.setTrace(data.readTrace(context));
    // constants
    int count = data.readInt();
    for (int i = 0; i < count; i++) {
        ConstantEntity el = constantDumper.load(input);
        el.setModule(entity);
        entity.addConstant(el);
    }
    // closures
    count = data.readInt();
    for (int i = 0; i < count; i++) {
        ClosureEntity el = closureDumper.load(input);
        el.setModule(entity);
        entity.addClosure(el);
    }
    count = data.readInt();
    for (int i = 0; i < count; i++) {
        GeneratorEntity el = generatorDumper.load(input);
        el.setModule(entity);
        entity.addGenerator(el);
    }
    // functions
    count = data.readInt();
    for (int i = 0; i < count; i++) {
        FunctionEntity el = functionDumper.load(input);
        el.setModule(entity);
        entity.addFunction(el);
    }
    // classes
    count = data.readInt();
    ClassDumper classDumper = new ClassDumper(context, entity, env, debugInformation);
    for (int i = 0; i < count; i++) {
        ClassEntity el = classDumper.load(input);
        el.setModule(entity);
        entity.addClass(el);
    }
    // byte code
    entity.setData(data.readRawData(Integer.MAX_VALUE));
    data.readRawData(1024 * 1024 * 5);
    return entity;
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) GeneratorEntity(php.runtime.reflection.helper.GeneratorEntity) DumpInputStream(php.runtime.loader.dump.io.DumpInputStream) FunctionEntity(php.runtime.reflection.FunctionEntity) ClosureEntity(php.runtime.reflection.helper.ClosureEntity) ModuleEntity(php.runtime.reflection.ModuleEntity) DumpException(php.runtime.loader.dump.io.DumpException) ConstantEntity(php.runtime.reflection.ConstantEntity)

Example 8 with ConstantEntity

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

the class InfoFunctions method get_defined_constants.

public static Memory get_defined_constants(Environment env, boolean capitalize) {
    Set<String> exists = new HashSet<String>();
    ArrayMemory result = new ArrayMemory();
    for (String ext : env.scope.getExtensions()) {
        Extension extension = env.scope.getExtension(ext);
        ArrayMemory item = result;
        if (capitalize)
            item = (ArrayMemory) result.refOfIndex(ext).assign(new ArrayMemory());
        for (CompileConstant constant : extension.getConstants().values()) {
            item.put(constant.name, constant.value);
            exists.add(constant.name);
        }
    }
    ArrayMemory item = result;
    if (capitalize)
        item = (ArrayMemory) result.refOfIndex("user").assign(new ArrayMemory());
    for (ConstantEntity constant : env.scope.getConstants()) {
        if (!exists.contains(constant.getName()))
            item.put(constant.getName(), constant.getValue());
    }
    for (ConstantEntity constant : env.getConstants().values()) {
        if (!exists.contains(constant.getName()))
            item.put(constant.getName(), constant.getValue());
    }
    return result;
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) Extension(php.runtime.ext.support.Extension) CompileConstant(php.runtime.ext.support.compile.CompileConstant) ConstantEntity(php.runtime.reflection.ConstantEntity) HashSet(java.util.HashSet)

Aggregations

ConstantEntity (php.runtime.reflection.ConstantEntity)8 ClassEntity (php.runtime.reflection.ClassEntity)5 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Test (org.junit.Test)2 Memory (php.runtime.Memory)2 DumpException (php.runtime.loader.dump.io.DumpException)2 DumpInputStream (php.runtime.loader.dump.io.DumpInputStream)2 ArrayMemory (php.runtime.memory.ArrayMemory)2 FunctionEntity (php.runtime.reflection.FunctionEntity)2 ClosureEntity (php.runtime.reflection.helper.ClosureEntity)2 GeneratorEntity (php.runtime.reflection.helper.GeneratorEntity)2 HashSet (java.util.HashSet)1 Modifier (php.runtime.common.Modifier)1 TraceInfo (php.runtime.env.TraceInfo)1 Extension (php.runtime.ext.support.Extension)1 CompileConstant (php.runtime.ext.support.compile.CompileConstant)1 DumpOutputStream (php.runtime.loader.dump.io.DumpOutputStream)1 ObjectMemory (php.runtime.memory.ObjectMemory)1 ReferenceMemory (php.runtime.memory.ReferenceMemory)1