Search in sources :

Example 71 with Memory

use of php.runtime.Memory in project jphp by jphp-compiler.

the class ReflectionFunction method invokeArgs.

@Signature(@Arg(value = "args", type = HintType.ARRAY))
public Memory invokeArgs(Environment env, Memory... args) throws Throwable {
    ArrayMemory value = args[0].toValue(ArrayMemory.class);
    Memory[] passed = value.values();
    return invoke(env, passed);
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) LongMemory(php.runtime.memory.LongMemory) ObjectMemory(php.runtime.memory.ObjectMemory) StringMemory(php.runtime.memory.StringMemory)

Example 72 with Memory

use of php.runtime.Memory in project jphp by jphp-compiler.

the class ReflectionMethod method __construct.

@Signature({ @Arg("class"), @Arg("name") })
public Memory __construct(Environment env, Memory... args) {
    ClassEntity classEntity;
    Memory _class = args[0];
    if (_class.isObject())
        classEntity = _class.toValue(ObjectMemory.class).getReflection();
    else
        classEntity = env.fetchClass(_class.toString(), true);
    if (classEntity == null) {
        exception(env, Messages.ERR_CLASS_NOT_FOUND.fetch(_class));
        return Memory.NULL;
    }
    MethodEntity entity = classEntity.findMethod(args[1].toString().toLowerCase());
    if (entity == null) {
        exception(env, Messages.ERR_METHOD_NOT_FOUND.fetch(_class, args[1]));
        return Memory.NULL;
    }
    setEntity(entity);
    return Memory.NULL;
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) ObjectMemory(php.runtime.memory.ObjectMemory) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) LongMemory(php.runtime.memory.LongMemory) ObjectMemory(php.runtime.memory.ObjectMemory) StringMemory(php.runtime.memory.StringMemory) MethodEntity(php.runtime.reflection.MethodEntity)

Example 73 with Memory

use of php.runtime.Memory in project jphp by jphp-compiler.

the class ObjectInvokeHelper method invokeParentMethod.

public static Memory invokeParentMethod(Memory object, String methodName, String methodLowerName, Environment env, TraceInfo trace, Memory[] args) throws Throwable {
    Memory[] passed = null;
    boolean doublePop = false;
    if (object.isNull()) {
        ClassEntity parent = env.__getParentClass(trace);
        return InvokeHelper.callStatic(env, trace, parent.getLowerName(), methodLowerName, parent.getName(), methodName, args, null, 0);
    }
    IObject iObject = ((ObjectMemory) object).value;
    ClassEntity childClazz = iObject.getReflection();
    ClassEntity clazz = env.getLastClassOnStack().getParent();
    MethodEntity method;
    if (clazz == null) {
        env.error(trace, "Cannot access parent:: when current class scope has no parent");
        return Memory.NULL;
    }
    if (methodName == null) {
        method = childClazz.methodMagicInvoke != null ? childClazz.methodMagicInvoke : clazz.methodMagicInvoke;
    } else {
        method = clazz.findMethod(methodLowerName);
        if (method == null && ((method = childClazz.methodMagicCall != null ? childClazz.methodMagicCall : clazz.methodMagicCall) != null)) {
            passed = new Memory[] { new StringMemory(methodName), ArrayMemory.of(args) };
            doublePop = true;
        }
    }
    String className = clazz.getName();
    if (method == null) {
        if (methodName == null)
            methodName = "__invoke";
        env.error(trace, ErrorType.E_ERROR, Messages.ERR_CALL_TO_UNDEFINED_METHOD.fetch(className + "::" + methodName));
        return Memory.NULL;
    }
    InvokeHelper.checkAccess(env, trace, method);
    if (passed == null) {
        passed = InvokeHelper.makeArguments(env, args, method.getParameters(), className, methodName, trace);
    }
    Memory result = method.getImmutableResult();
    if (result != null)
        return result;
    try {
        if (trace != null) {
            env.pushCall(trace, iObject, args, methodName, method.getClazz().getName(), className);
            if (doublePop)
                env.pushCall(trace, iObject, passed, method.getName(), method.getClazz().getName(), className);
        }
        result = method.invokeDynamic(iObject, env, passed);
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new CriticalException("Unable to call parent:: method " + className + "::" + methodName + "(), error = " + e.getMessage());
    } finally {
        if (trace != null) {
            env.popCall();
            if (doublePop)
                env.popCall();
        }
    }
    return result;
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) IObject(php.runtime.lang.IObject) ObjectMemory(php.runtime.memory.ObjectMemory) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) ReferenceMemory(php.runtime.memory.ReferenceMemory) ObjectMemory(php.runtime.memory.ObjectMemory) StringMemory(php.runtime.memory.StringMemory) MethodEntity(php.runtime.reflection.MethodEntity) StringMemory(php.runtime.memory.StringMemory) CriticalException(php.runtime.exceptions.CriticalException)

Example 74 with Memory

use of php.runtime.Memory in project jphp by jphp-compiler.

the class ObjectInvokeHelper method invokeMethod.

public static Memory invokeMethod(IObject iObject, MethodEntity method, Environment env, TraceInfo trace, Memory[] args, boolean checkAccess) throws Throwable {
    ClassEntity clazz = iObject.getReflection();
    if (method == null)
        method = clazz.methodMagicInvoke;
    String className = clazz.getName();
    if (method == null) {
        env.error(trace, Messages.ERR_CALL_TO_UNDEFINED_METHOD.fetch(className + "::__invoke"));
        return Memory.NULL;
    }
    if (checkAccess)
        InvokeHelper.checkAccess(env, trace, method);
    Memory[] passed = InvokeHelper.makeArguments(env, args, method.getParameters(args == null ? 0 : args.length), className, method.getName(), trace);
    Memory result = method.getImmutableResult();
    if (result != null) {
        return result;
    }
    if (trace != null) {
        String staticClass = className;
        if (iObject instanceof Closure) {
            staticClass = ((Closure) iObject).getScope();
        }
        String stackClass = clazz.isHiddenInCallStack() ? staticClass : method.getClazz().getName();
        env.pushCall(trace, iObject, args, method.getName(), stackClass, staticClass);
    }
    try {
        result = method.invokeDynamic(iObject, env, passed);
    } finally {
        if (trace != null)
            env.popCall();
    }
    return result;
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) Closure(php.runtime.lang.Closure) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) ReferenceMemory(php.runtime.memory.ReferenceMemory) ObjectMemory(php.runtime.memory.ObjectMemory) StringMemory(php.runtime.memory.StringMemory)

Example 75 with Memory

use of php.runtime.Memory in project jphp by jphp-compiler.

the class ReflectionProperty method __construct.

@Signature({ @Arg("class"), @Arg("name") })
public Memory __construct(Environment env, Memory... args) {
    ClassEntity classEntity;
    Memory arg = args[0];
    if (arg.isObject()) {
        classEntity = arg.toValue(ObjectMemory.class).getReflection();
    } else
        classEntity = env.fetchClass(arg.toString());
    if (classEntity == null) {
        exception(env, Messages.ERR_CLASS_NOT_FOUND.fetch(arg));
        return Memory.NULL;
    }
    String prop = args[1].toString();
    PropertyEntity entity = classEntity.findProperty(prop);
    if (entity == null)
        entity = classEntity.findStaticProperty(prop);
    if (entity == null) {
        exception(env, Messages.ERR_UNDEFINED_PROPERTY.fetch(classEntity.getName(), prop));
        return Memory.NULL;
    }
    setEntity(entity);
    return Memory.NULL;
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) PropertyEntity(php.runtime.reflection.PropertyEntity) Memory(php.runtime.Memory) LongMemory(php.runtime.memory.LongMemory) StringMemory(php.runtime.memory.StringMemory) ObjectMemory(php.runtime.memory.ObjectMemory)

Aggregations

Memory (php.runtime.Memory)346 Test (org.junit.Test)124 ArrayMemory (php.runtime.memory.ArrayMemory)122 ObjectMemory (php.runtime.memory.ObjectMemory)75 LongMemory (php.runtime.memory.LongMemory)58 StringMemory (php.runtime.memory.StringMemory)58 ForeachIterator (php.runtime.lang.ForeachIterator)47 ReferenceMemory (php.runtime.memory.ReferenceMemory)40 KeyValueMemory (php.runtime.memory.KeyValueMemory)25 Invoker (php.runtime.invoke.Invoker)21 ArrayKeyMemory (php.runtime.memory.helper.ArrayKeyMemory)21 ArrayValueMemory (php.runtime.memory.helper.ArrayValueMemory)21 ShortcutMemory (php.runtime.memory.helper.ShortcutMemory)21 Environment (php.runtime.env.Environment)20 IObject (php.runtime.lang.IObject)19 UndefinedMemory (php.runtime.memory.helper.UndefinedMemory)16 ClassEntity (php.runtime.reflection.ClassEntity)16 TraceInfo (php.runtime.env.TraceInfo)12 File (java.io.File)7 LocalVariable (org.develnext.jphp.core.compiler.jvm.misc.LocalVariable)7