Search in sources :

Example 6 with FunctionEntity

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

the class WrapEnvironment method importFunction.

@Signature(@Arg("functionName"))
public Memory importFunction(Environment env, Memory... args) {
    FunctionEntity functionEntity = env.fetchFunction(args[0].toString());
    if (functionEntity == null) {
        env.exception(Messages.ERR_FUNCTION_NOT_FOUND.fetch(args[0]));
        return Memory.NULL;
    }
    environment.registerFunction(functionEntity);
    return Memory.NULL;
}
Also used : FunctionEntity(php.runtime.reflection.FunctionEntity)

Example 7 with FunctionEntity

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

the class WrapEnvironment method exportFunction.

@Signature(@Arg("functionName"))
public Memory exportFunction(Environment env, Memory... args) {
    FunctionEntity functionEntity = environment.fetchFunction(args[0].toString());
    if (functionEntity == null) {
        env.exception(Messages.ERR_FUNCTION_NOT_FOUND.fetch(args[0]));
        return Memory.NULL;
    }
    env.registerFunction(functionEntity);
    return Memory.NULL;
}
Also used : FunctionEntity(php.runtime.reflection.FunctionEntity)

Example 8 with FunctionEntity

use of php.runtime.reflection.FunctionEntity 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 9 with FunctionEntity

use of php.runtime.reflection.FunctionEntity 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 10 with FunctionEntity

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

the class ReflectionParameter method getDeclaringFunction.

@Signature
public Memory getDeclaringFunction(Environment env, Memory... args) throws Throwable {
    if (cachedFunction != null)
        return cachedFunction;
    if (functionEntity == null)
        return Memory.NULL;
    if (functionEntity instanceof FunctionEntity) {
        ClassEntity classEntity = env.fetchClass("ReflectionFunction");
        ReflectionFunction e = new ReflectionFunction(env, classEntity);
        e.setFunctionEntity((FunctionEntity) functionEntity);
        return cachedFunction = new ObjectMemory(e);
    } else {
        ClassEntity classEntity = env.fetchClass("ReflectionMethod");
        ReflectionMethod e = new ReflectionMethod(env, classEntity);
        e.setEntity((MethodEntity) functionEntity);
        return cachedFunction = new ObjectMemory(e);
    }
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) AbstractFunctionEntity(php.runtime.reflection.support.AbstractFunctionEntity) FunctionEntity(php.runtime.reflection.FunctionEntity) ObjectMemory(php.runtime.memory.ObjectMemory)

Aggregations

FunctionEntity (php.runtime.reflection.FunctionEntity)11 ClassEntity (php.runtime.reflection.ClassEntity)5 ClosureEntity (php.runtime.reflection.helper.ClosureEntity)4 DumpException (php.runtime.loader.dump.io.DumpException)3 GeneratorEntity (php.runtime.reflection.helper.GeneratorEntity)3 AbstractFunctionEntity (php.runtime.reflection.support.AbstractFunctionEntity)3 DumpInputStream (php.runtime.loader.dump.io.DumpInputStream)2 ObjectMemory (php.runtime.memory.ObjectMemory)2 ConstantEntity (php.runtime.reflection.ConstantEntity)2 ParameterEntity (php.runtime.reflection.ParameterEntity)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Test (org.junit.Test)1 Invoker (php.runtime.invoke.Invoker)1 DumpOutputStream (php.runtime.loader.dump.io.DumpOutputStream)1 ArrayMemory (php.runtime.memory.ArrayMemory)1 StringMemory (php.runtime.memory.StringMemory)1 MethodEntity (php.runtime.reflection.MethodEntity)1 ModuleEntity (php.runtime.reflection.ModuleEntity)1