Search in sources :

Example 16 with ArrayMemory

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

the class ClassEntity method unsetProperty.

public Memory unsetProperty(Environment env, TraceInfo trace, IObject object, String property, PropertyCallCache callCache, int index) throws Throwable {
    ClassEntity context = env.getLastClassOnStack();
    PropertyEntity entity = isInstanceOf(context) ? context.properties.get(property) : properties.get(property);
    int accessFlag = entity == null ? 0 : entity.canAccess(env);
    if (entity == null) {
        PropertyEntity staticEntity = staticProperties.get(property);
        if (staticEntity != null) {
            invalidAccessToProperty(env, trace, staticEntity, staticEntity.canAccess(env));
        }
    }
    ArrayMemory props = object.getProperties();
    if (props == null || accessFlag != 0 || props.removeByScalar(entity == null ? property : entity.specificName) == null) {
        if (methodMagicUnset != null) {
            if (context != null && context.getId() == methodMagicUnset.getClazz().getId()) {
                if (env.peekCall(0).flags == FLAG_UNSET) {
                    return Memory.NULL;
                }
            }
            try {
                Memory[] args = new Memory[] { new StringMemory(property) };
                env.pushCall(trace, object, args, methodMagicUnset.getName(), methodMagicUnset.getClazz().getName(), name);
                env.peekCall(0).flags = FLAG_UNSET;
                InvokeArgumentHelper.checkType(env, trace, methodMagicUnset, args);
                methodMagicUnset.invokeDynamic(object, env, args);
            } finally {
                env.popCall();
            }
            return Memory.NULL;
        }
    }
    if (accessFlag != 0)
        invalidAccessToProperty(env, trace, entity, accessFlag);
    entity = staticProperties.get(property);
    if (entity != null) {
        env.error(trace, ErrorType.E_STRICT, Messages.ERR_ACCESSING_STATIC_PROPERTY_AS_NON_STATIC, entity.getClazz().getName(), entity.getName());
    }
    return Memory.NULL;
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) 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 17 with ArrayMemory

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

the class DumpInputStream method readMemory.

public Memory readMemory() throws IOException {
    int tmp = readInt();
    if (tmp == -1)
        return null;
    if (tmp == -2)
        return new ConstantMemory(readUTF());
    if (tmp == -3)
        return new ClassConstantMemory(readUTF(), readUTF());
    if (tmp >= 0 && tmp < Memory.Type.values().length) {
        Memory.Type type = Memory.Type.values()[tmp];
        switch(type) {
            case BOOL:
                return readBoolean() ? Memory.TRUE : Memory.FALSE;
            case INT:
                return LongMemory.valueOf(readLong());
            case DOUBLE:
                return DoubleMemory.valueOf(readDouble());
            case NULL:
                return Memory.NULL;
            case STRING:
                return StringMemory.valueOf(readUTF());
            case ARRAY:
                ArrayMemory array = new ArrayMemory();
                int size = readInt();
                if (size < 0 || size > Short.MAX_VALUE)
                    throw new DumpException("Invalid array memory size");
                for (int i = 0; i < size; i++) {
                    Memory key = readMemory();
                    Memory value = readMemory();
                    array.refOfIndex(key).assign(value);
                }
                return array;
            case OBJECT:
            default:
                throw new DumpException("Cannot read " + type.toString() + " memory");
        }
    } else
        throw new DumpException("Invalid ~Memory.Type value");
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) DoubleMemory(php.runtime.memory.DoubleMemory) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) ConstantMemory(php.runtime.memory.helper.ConstantMemory) LongMemory(php.runtime.memory.LongMemory) ClassConstantMemory(php.runtime.memory.helper.ClassConstantMemory) StringMemory(php.runtime.memory.StringMemory) ClassConstantMemory(php.runtime.memory.helper.ClassConstantMemory) ConstantMemory(php.runtime.memory.helper.ConstantMemory) ClassConstantMemory(php.runtime.memory.helper.ClassConstantMemory)

Example 18 with ArrayMemory

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

the class DumpOutputStream method writeMemory.

public void writeMemory(Memory memory) throws IOException {
    if (memory == null) {
        writeInt(-1);
        return;
    }
    memory = memory.toValue();
    if (memory instanceof ConstantMemory) {
        writeInt(-2);
        writeUTF(((ConstantMemory) memory).getName());
        return;
    } else if (memory instanceof ClassConstantMemory) {
        writeInt(-3);
        writeUTF(((ClassConstantMemory) memory).getClassName());
        writeUTF(((ClassConstantMemory) memory).getName());
        return;
    }
    Memory.Type type = memory.getRealType();
    writeInt(type.ordinal());
    switch(type) {
        case NULL:
            break;
        case INT:
            writeLong(memory.toLong());
            break;
        case STRING:
            writeUTF(memory.toString());
            break;
        case DOUBLE:
            writeDouble(memory.toDouble());
            break;
        case BOOL:
            writeBoolean(memory.toBoolean());
            break;
        case ARRAY:
            ArrayMemory array = memory.toValue(ArrayMemory.class);
            if (array.size() > Short.MAX_VALUE)
                throw new DumpException("Array is too big");
            writeInt(array.size());
            ForeachIterator foreachIterator = array.foreachIterator(false, false);
            while (foreachIterator.next()) {
                Memory key = foreachIterator.getMemoryKey();
                Memory value = foreachIterator.getValue();
                if (value.isShortcut())
                    throw new DumpException("Cannot dump references");
                if (value.toValue() != Memory.UNDEFINED) {
                    writeMemory(key);
                    writeMemory(value.toValue());
                }
            }
            break;
        case OBJECT:
        default:
            throw new DumpException("Cannot dump " + type.toString() + " memory");
    }
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) ForeachIterator(php.runtime.lang.ForeachIterator) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) ConstantMemory(php.runtime.memory.helper.ConstantMemory) ClassConstantMemory(php.runtime.memory.helper.ClassConstantMemory) ClassConstantMemory(php.runtime.memory.helper.ClassConstantMemory) ConstantMemory(php.runtime.memory.helper.ConstantMemory) ClassConstantMemory(php.runtime.memory.helper.ClassConstantMemory)

Example 19 with ArrayMemory

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

the class PropertyEntity method getValue.

public Memory getValue(Environment env, TraceInfo trace, Object object) throws Throwable {
    if (getter != null && object instanceof IObject) {
        return ObjectInvokeHelper.invokeMethod((IObject) object, getter, env, trace, null, false);
    }
    ArrayMemory props = ((IObject) object).getProperties();
    Memory result = props.getByScalar(specificName);
    if (result == null) {
        result = props.getByScalar(name);
    }
    return result;
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) IObject(php.runtime.lang.IObject) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory)

Example 20 with ArrayMemory

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

the class PSqlConnection method getCatalogs.

@Signature
public Memory getCatalogs(Environment env) throws SQLException {
    ResultSet catalogs = metaData.getCatalogs();
    ArrayMemory r = new ArrayMemory();
    while (catalogs.next()) {
        r.add(new PSqlResult(env, catalogs).toArray(env));
    }
    return r.toConstant();
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory)

Aggregations

ArrayMemory (php.runtime.memory.ArrayMemory)148 Memory (php.runtime.Memory)60 ForeachIterator (php.runtime.lang.ForeachIterator)41 ObjectMemory (php.runtime.memory.ObjectMemory)35 LongMemory (php.runtime.memory.LongMemory)31 StringMemory (php.runtime.memory.StringMemory)29 ReferenceMemory (php.runtime.memory.ReferenceMemory)25 KeyValueMemory (php.runtime.memory.KeyValueMemory)17 Invoker (php.runtime.invoke.Invoker)9 ClassEntity (php.runtime.reflection.ClassEntity)9 Signature (php.runtime.annotation.Reflection.Signature)6 IObject (php.runtime.lang.IObject)6 Map (java.util.Map)4 Test (org.junit.Test)4 DoubleMemory (php.runtime.memory.DoubleMemory)4 ConcurrentEnvironment (php.runtime.env.ConcurrentEnvironment)3 TraceInfo (php.runtime.env.TraceInfo)3 ModuleEntity (php.runtime.reflection.ModuleEntity)3 ParameterEntity (php.runtime.reflection.ParameterEntity)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2