Search in sources :

Example 11 with ReferenceMemory

use of php.runtime.memory.ReferenceMemory in project jphp by jphp-compiler.

the class ClassEntity method setProperty.

public Memory setProperty(Environment env, TraceInfo trace, IObject object, String property, Memory memory, SetterCallback callback, PropertyCallCache callCache, int cacheIndex) throws Throwable {
    ReferenceMemory value;
    PropertyEntity entity = callCache == null ? null : callCache.get(env, cacheIndex);
    if (entity == null) {
        ClassEntity context = env.getLastClassOnStack();
        entity = isInstanceOf(context) ? context.properties.get(property) : properties.get(property);
        if (callCache != null && entity != null) {
            callCache.put(env, cacheIndex, entity);
        }
    }
    if (entity == null) {
        PropertyEntity staticEntity = staticProperties.get(property);
        if (staticEntity != null) {
            invalidAccessToProperty(env, trace, staticEntity, staticEntity.canAccess(env));
            env.error(trace, ErrorType.E_STRICT, Messages.ERR_ACCESSING_STATIC_PROPERTY_AS_NON_STATIC, staticEntity.getClazz().getName(), staticEntity.getName());
        }
    }
    int accessFlag = entity == null ? 0 : entity.canAccess(env);
    ArrayMemory props = object.getProperties();
    if (entity != null) {
        if (entity.setter != null) {
            if (callback != null)
                memory = callback.invoke(getProperty(env, trace, object, property, null, 0), memory);
            try {
                ObjectInvokeHelper.invokeMethod(object, entity.setter, env, trace, new Memory[] { memory }, false);
            } catch (IllegalArgumentException e) {
                if (!object.getReflection().isInstanceOf(entity.setter.getClazz())) {
                    return setProperty(env, trace, object, property, memory, callback, null, 0);
                }
                throw e;
            }
            return memory;
        } else if (entity.getter != null) {
            env.error(trace, ErrorType.E_RECOVERABLE_ERROR, Messages.ERR_READONLY_PROPERTY.fetch(entity.getClazz().getName(), property));
        }
    }
    value = props == null || accessFlag != 0 ? null : props.getByScalar(entity == null ? property : entity.specificName);
    if (value == null) {
        boolean recursive = false;
        ClassEntity context = env.getLastClassOnStack();
        if (context != null && methodMagicSet != null && context.getId() == methodMagicSet.getClazz().getId()) {
            recursive = env.peekCall(0).flags == FLAG_SET;
        }
        if (methodMagicSet != null && !recursive) {
            StringMemory memoryProperty = new StringMemory(property);
            if (callback != null) {
                Memory o1 = Memory.NULL;
                if (methodMagicGet != null) {
                    try {
                        Memory[] args = new Memory[] { memoryProperty };
                        env.pushCall(trace, object, args, methodMagicGet.getName(), methodMagicSet.getClazz().getName(), name);
                        env.peekCall(0).flags = FLAG_GET;
                        InvokeArgumentHelper.checkType(env, trace, methodMagicGet, args);
                        o1 = methodMagicGet.invokeDynamic(object, env, memoryProperty);
                    } finally {
                        env.popCall();
                    }
                }
                memory = callback.invoke(o1, memory);
            }
            try {
                Memory[] args = new Memory[] { memoryProperty, memory };
                env.pushCall(trace, object, args, methodMagicSet.getName(), methodMagicSet.getClazz().getName(), name);
                env.peekCall(0).flags = FLAG_SET;
                InvokeArgumentHelper.checkType(env, trace, methodMagicSet, args);
                methodMagicSet.invokeDynamic(object, env, args);
            } finally {
                env.popCall();
            }
        } else {
            if (callback != null)
                memory = callback.invoke(Memory.NULL, memory);
            String name = property;
            if (entity != null) {
                if (accessFlag != 0 && context == null) {
                    switch(accessFlag) {
                        case 2:
                            if (object.getReflection().getId() == entity.getClazz().getId()) {
                                invalidAccessToProperty(env, trace, entity, accessFlag);
                                return Memory.NULL;
                            }
                            break;
                        case 1:
                            invalidAccessToProperty(env, trace, entity, accessFlag);
                            return Memory.NULL;
                    }
                }
                if (context != null) {
                    switch(entity.modifier) {
                        case PRIVATE:
                            if (entity.getClazz().getId() == context.getId())
                                name = entity.specificName;
                            break;
                        case PROTECTED:
                            if (context.isInstanceOf(entity.getClazz()))
                                name = entity.specificName;
                    }
                }
            }
            return props == null ? Memory.NULL : (entity == null ? props.refOfIndex(name).assign(memory) : entity.assignValue(env, trace, object, name, memory));
        }
    } else {
        if (callback != null)
            memory = callback.invoke(value, memory);
        if (entity instanceof CompilePropertyEntity) {
            return entity.assignValue(env, trace, object, property, memory);
        }
        return value.assign(memory);
    }
    return memory;
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ReferenceMemory(php.runtime.memory.ReferenceMemory) ArrayMemory(php.runtime.memory.ArrayMemory) Memory(php.runtime.Memory) ReferenceMemory(php.runtime.memory.ReferenceMemory) StringMemory(php.runtime.memory.StringMemory) StringMemory(php.runtime.memory.StringMemory)

Aggregations

ReferenceMemory (php.runtime.memory.ReferenceMemory)11 Memory (php.runtime.Memory)4 ArrayMemory (php.runtime.memory.ArrayMemory)4 StringMemory (php.runtime.memory.StringMemory)3 IObject (php.runtime.lang.IObject)2 NamedNodeMap (org.w3c.dom.NamedNodeMap)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1 HashedMap (php.runtime.common.collections.map.HashedMap)1 ConcurrentEnvironment (php.runtime.env.ConcurrentEnvironment)1 ForeachIterator (php.runtime.lang.ForeachIterator)1 KeyValueMemory (php.runtime.memory.KeyValueMemory)1 ObjectMemory (php.runtime.memory.ObjectMemory)1 VariadicMemory (php.runtime.memory.helper.VariadicMemory)1 ParameterEntity (php.runtime.reflection.ParameterEntity)1