Search in sources :

Example 46 with StringMemory

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

the class ClassEntity method getProperty.

public Memory getProperty(Environment env, TraceInfo trace, IObject object, String property, PropertyCallCache callCache, int cacheIndex) throws Throwable {
    Memory value;
    PropertyEntity entity = callCache == null || env instanceof ConcurrentEnvironment ? 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);
    if (entity != null && accessFlag != 0) {
        value = null;
    } else {
        if (entity != null) {
            value = entity.getValue(env, trace, object);
        } else {
            ArrayMemory props = object.getProperties();
            value = props == null ? null : props.getByScalar(property);
        }
    }
    if (value != null)
        return value;
    if (methodMagicGet != null) {
        Memory result;
        ClassEntity context = env.getLastClassOnStack();
        if (context != null && context.getId() == methodMagicGet.getClazz().getId()) {
            if (env.peekCall(0).flags == FLAG_GET) {
                env.error(trace, ErrorType.E_NOTICE, Messages.ERR_UNDEFINED_PROPERTY, name, property);
                return Memory.NULL;
            }
        }
        try {
            Memory[] args = new Memory[] { new StringMemory(property) };
            env.pushCall(trace, object, args, methodMagicGet.getName(), methodMagicGet.getClazz().getName(), name);
            env.peekCall(0).flags = FLAG_GET;
            InvokeArgumentHelper.checkType(env, trace, methodMagicGet, args);
            result = methodMagicGet.invokeDynamic(object, env, args);
        } finally {
            env.popCall();
        }
        return result;
    }
    if (accessFlag != 0)
        invalidAccessToProperty(env, trace, entity, accessFlag);
    env.error(trace, ErrorType.E_NOTICE, Messages.ERR_UNDEFINED_PROPERTY, name, property);
    return Memory.NULL;
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ConcurrentEnvironment(php.runtime.env.ConcurrentEnvironment) ArrayMemory(php.runtime.memory.ArrayMemory) Memory(php.runtime.Memory) ReferenceMemory(php.runtime.memory.ReferenceMemory) StringMemory(php.runtime.memory.StringMemory) StringMemory(php.runtime.memory.StringMemory)

Example 47 with StringMemory

use of php.runtime.memory.StringMemory 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

StringMemory (php.runtime.memory.StringMemory)47 ArrayMemory (php.runtime.memory.ArrayMemory)14 Memory (php.runtime.Memory)11 ObjectMemory (php.runtime.memory.ObjectMemory)8 ReferenceMemory (php.runtime.memory.ReferenceMemory)7 BigDecimal (java.math.BigDecimal)5 Invoker (php.runtime.invoke.Invoker)4 ClassEntity (php.runtime.reflection.ClassEntity)4 TraceInfo (php.runtime.env.TraceInfo)3 IObject (php.runtime.lang.IObject)3 LongMemory (php.runtime.memory.LongMemory)3 StringWriter (java.io.StringWriter)2 ComponentProperties (org.develnext.jphp.swing.ComponentProperties)2 UIReader (org.develnext.jphp.swing.loader.UIReader)2 Signature (php.runtime.annotation.Reflection.Signature)2 CallStackItem (php.runtime.env.CallStackItem)2 ConcurrentEnvironment (php.runtime.env.ConcurrentEnvironment)2 CriticalException (php.runtime.exceptions.CriticalException)2 MethodEntity (php.runtime.reflection.MethodEntity)2 BigInteger (java.math.BigInteger)1