Search in sources :

Example 11 with IObject

use of php.runtime.lang.IObject in project jphp by jphp-compiler.

the class ObjectInvokeHelper method invokeMethod.

public static Memory invokeMethod(Memory object, String methodName, String methodLowerName, Environment env, TraceInfo trace, Memory[] args) throws Throwable {
    object = object.toValue();
    Memory[] passed = null;
    boolean doublePop = false;
    if (object.type != Memory.Type.OBJECT) {
        env.error(trace, ErrorType.E_RECOVERABLE_ERROR, Messages.ERR_CANNOT_CALL_OF_NON_OBJECT.fetch(methodName));
        return Memory.NULL;
    }
    IObject iObject = ((ObjectMemory) object).value;
    ClassEntity clazz = iObject.getReflection();
    MethodEntity method;
    if (methodName == null) {
        method = clazz.methodMagicInvoke;
    } else {
        method = clazz.findMethod(methodLowerName);
        if (method != null && method.isContextDepends()) {
            ClassEntity context = env.getLastClassOnStack();
            if (context != null) {
                MethodEntity contextMethod = context.findMethod(methodLowerName);
                if (contextMethod != null) {
                    method = contextMethod;
                }
            }
        }
        if (method == null && ((method = clazz.methodMagicCall) != null)) {
            clazz.methodMagicCall.setModifier(Modifier.PUBLIC);
            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(args == null ? 0 : args.length), className, methodName, trace);
    }
    Memory result = method.getImmutableResult();
    if (result != null) {
        return result;
    }
    try {
        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, methodName, stackClass, staticClass);
            if (doublePop) {
                env.pushCall(trace, iObject, passed, method.getName(), stackClass, staticClass);
            }
        }
        return method.invokeDynamic(iObject, env, passed);
    } catch (NoClassDefFoundError e) {
        throw new CriticalException("Unable to call method " + className + "::" + methodName + "(), " + e.getMessage());
    } finally {
        if (trace != null) {
            env.popCall();
            if (doublePop)
                env.popCall();
        }
    }
}
Also used : ClassEntity(php.runtime.reflection.ClassEntity) IObject(php.runtime.lang.IObject) Closure(php.runtime.lang.Closure) 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 12 with IObject

use of php.runtime.lang.IObject in project jphp by jphp-compiler.

the class ObjectInvokeHelper method GetAndDecProperty.

public static Memory GetAndDecProperty(Memory object, String property, Environment env, TraceInfo trace, PropertyCallCache callCache, int cacheIndex) throws Throwable {
    IObject iObject = fetchObject(object, property, env, trace);
    if (iObject == null)
        return Memory.NULL;
    ReferenceMemory ref = new ReferenceMemory();
    iObject.getReflection().minusProperty(env, trace, iObject, property, Memory.CONST_INT_1, ref);
    return ref.value;
}
Also used : ReferenceMemory(php.runtime.memory.ReferenceMemory) IObject(php.runtime.lang.IObject)

Example 13 with IObject

use of php.runtime.lang.IObject in project jphp by jphp-compiler.

the class ObjectInvokeHelper method getRefProperty.

public static Memory getRefProperty(Memory object, String property, Environment env, TraceInfo trace, PropertyCallCache callCache, int cacheIndex) throws Throwable {
    object = object.toValue();
    if (!object.isObject()) {
        env.error(trace, Messages.ERR_CANNOT_GET_PROPERTY_OF_NON_OBJECT.fetch(property));
        return Memory.NULL;
    }
    IObject iObject = ((ObjectMemory) object).value;
    return iObject.getReflection().getRefProperty(env, trace, iObject, property, callCache, cacheIndex);
}
Also used : IObject(php.runtime.lang.IObject) ObjectMemory(php.runtime.memory.ObjectMemory)

Example 14 with IObject

use of php.runtime.lang.IObject in project jphp by jphp-compiler.

the class ObjectInvokeHelper method unsetProperty.

public static void unsetProperty(Memory object, String property, Environment env, TraceInfo trace, PropertyCallCache callCache, int cacheIndex) throws Throwable {
    object = object.toValue();
    if (!object.isObject()) {
        env.error(trace, Messages.ERR_CANNOT_GET_PROPERTY_OF_NON_OBJECT.fetch(property));
    }
    IObject iObject = ((ObjectMemory) object).value;
    iObject.getReflection().unsetProperty(env, trace, iObject, property, callCache, cacheIndex);
}
Also used : IObject(php.runtime.lang.IObject) ObjectMemory(php.runtime.memory.ObjectMemory)

Example 15 with IObject

use of php.runtime.lang.IObject in project jphp by jphp-compiler.

the class ObjectInvokeHelper method emptyProperty.

public static Memory emptyProperty(Memory object, String property, Environment env, TraceInfo trace, PropertyCallCache callCache, int cacheIndex) throws Throwable {
    object = object.toValue();
    if (!object.isObject()) {
        return Memory.NULL;
    //env.error(trace, Messages.ERR_CANNOT_GET_PROPERTY_OF_NON_OBJECT.fetch(property));
    }
    IObject iObject = ((ObjectMemory) object).value;
    return iObject.getReflection().emptyProperty(env, trace, iObject, property);
}
Also used : IObject(php.runtime.lang.IObject) ObjectMemory(php.runtime.memory.ObjectMemory)

Aggregations

IObject (php.runtime.lang.IObject)23 ObjectMemory (php.runtime.memory.ObjectMemory)13 Memory (php.runtime.Memory)9 ArrayMemory (php.runtime.memory.ArrayMemory)8 ReferenceMemory (php.runtime.memory.ReferenceMemory)4 StringMemory (php.runtime.memory.StringMemory)4 ClassEntity (php.runtime.reflection.ClassEntity)4 CriticalException (php.runtime.exceptions.CriticalException)3 ForeachIterator (php.runtime.lang.ForeachIterator)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Test (org.junit.Test)2 Serializable (php.runtime.lang.spl.Serializable)2 MethodEntity (php.runtime.reflection.MethodEntity)2 Constructor (java.lang.reflect.Constructor)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 LinkedHashSet (java.util.LinkedHashSet)1 NativeObject (org.develnext.jphp.ext.pna.classes.NativeObject)1 Environment (php.runtime.env.Environment)1 TraceInfo (php.runtime.env.TraceInfo)1 BaseWrapper (php.runtime.lang.BaseWrapper)1