Search in sources :

Example 1 with ArrayAccess

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

the class ObjectMemory method unsetOfIndex.

@Override
public void unsetOfIndex(TraceInfo trace, Memory index) {
    if (value instanceof ArrayAccess) {
        Environment env = value.getEnvironment();
        if (env != null && trace != null) {
            Memory[] args = new Memory[] { index };
            env.pushCall(value, "offsetUnset", args);
            try {
                ((ArrayAccess) value).offsetUnset(env, args);
            } finally {
                env.popCall();
            }
        } else
            invalidUseAsArray(trace);
    } else
        invalidUseAsArray(trace);
}
Also used : ArrayAccess(php.runtime.lang.spl.ArrayAccess) Memory(php.runtime.Memory) Environment(php.runtime.env.Environment)

Example 2 with ArrayAccess

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

the class ObjectMemory method refOfIndex.

@Override
public Memory refOfIndex(final TraceInfo trace, final Memory index) {
    if (value instanceof ArrayAccess) {
        return new ReferenceMemory() {

            @Override
            public Memory assign(Memory memory) {
                Environment env = ObjectMemory.this.value.getEnvironment();
                if (env != null && trace != null) {
                    ArrayAccess array = (ArrayAccess) ObjectMemory.this.value;
                    Memory[] args = new Memory[] { index, memory };
                    env.pushCall(ObjectMemory.this.value, "offsetSet", args);
                    try {
                        array.offsetSet(env, args);
                    } finally {
                        env.popCall();
                    }
                } else
                    invalidUseAsArray(trace);
                return memory;
            }

            @Override
            public Memory assignRef(Memory reference) {
                return assign(reference);
            }

            @Override
            public Memory assign(long memory) {
                return assign(LongMemory.valueOf(memory));
            }

            @Override
            public Memory assign(String memory) {
                return assign(StringMemory.valueOf(memory));
            }

            @Override
            public Memory assign(boolean memory) {
                return assign(TrueMemory.valueOf(memory));
            }

            @Override
            public Memory assign(double memory) {
                return assign(DoubleMemory.valueOf(memory));
            }

            @Override
            public Memory assignConcat(Memory memory) {
                return assign(toValue().concat(memory));
            }

            @Override
            public Memory assignConcat(long memory) {
                return assign(toValue().concat(memory));
            }

            @Override
            public Memory assignConcat(double memory) {
                return assign(toValue().concat(memory));
            }

            @Override
            public Memory assignConcat(boolean memory) {
                return assign(toValue().concat(memory));
            }

            @Override
            public Memory assignConcat(String memory) {
                return assign(toValue().concat(memory));
            }

            @Override
            public Memory assignPlus(Memory memory) {
                value = toValue();
                return super.assignPlus(memory);
            }

            @Override
            public Memory assignPlus(long memory) {
                value = toValue();
                return super.assignPlus(memory);
            }

            @Override
            public Memory assignPlus(double memory) {
                value = toValue();
                return super.assignPlus(memory);
            }

            @Override
            public Memory assignPlus(boolean memory) {
                value = toValue();
                return super.assignPlus(memory);
            }

            @Override
            public Memory assignPlus(String memory) {
                value = toValue();
                return super.assignPlus(memory);
            }

            @Override
            public Memory assignPlusRight(Memory memory) {
                value = toValue();
                return super.assignPlusRight(memory);
            }

            @Override
            public Memory assignMinus(Memory memory) {
                value = toValue();
                return super.assignMinus(memory);
            }

            @Override
            public Memory assignMinus(long memory) {
                value = toValue();
                return super.assignMinus(memory);
            }

            @Override
            public Memory assignMinus(double memory) {
                value = toValue();
                return super.assignMinus(memory);
            }

            @Override
            public Memory assignMinus(boolean memory) {
                value = toValue();
                return super.assignMinus(memory);
            }

            @Override
            public Memory assignMinus(String memory) {
                value = toValue();
                return super.assignMinus(memory);
            }

            @Override
            public Memory assignMinusRight(Memory memory) {
                value = toValue();
                return super.assignMinusRight(memory);
            }

            @Override
            public Memory assignMul(Memory memory) {
                value = toValue();
                return super.assignMul(memory);
            }

            @Override
            public Memory assignMul(long memory) {
                value = toValue();
                return super.assignMul(memory);
            }

            @Override
            public Memory assignMul(double memory) {
                value = toValue();
                return super.assignMul(memory);
            }

            @Override
            public Memory assignMul(boolean memory) {
                value = toValue();
                return super.assignMul(memory);
            }

            @Override
            public Memory assignMul(String memory) {
                value = toValue();
                return super.assignMul(memory);
            }

            @Override
            public Memory assignMulRight(Memory memory) {
                value = toValue();
                return super.assignMulRight(memory);
            }

            @Override
            public Memory assignDiv(Memory memory) {
                value = toValue();
                return super.assignDiv(memory);
            }

            @Override
            public Memory assignDiv(long memory) {
                value = toValue();
                return super.assignDiv(memory);
            }

            @Override
            public Memory assignDiv(double memory) {
                value = toValue();
                return super.assignDiv(memory);
            }

            @Override
            public Memory assignDiv(boolean memory) {
                value = toValue();
                return super.assignDiv(memory);
            }

            @Override
            public Memory assignDiv(String memory) {
                value = toValue();
                return super.assignDiv(memory);
            }

            @Override
            public Memory assignDivRight(Memory memory) {
                value = toValue();
                return super.assignDivRight(memory);
            }

            @Override
            public Memory assignMod(Memory memory) {
                value = toValue();
                return super.assignMod(memory);
            }

            @Override
            public Memory assignMod(long memory) {
                value = toValue();
                return super.assignMod(memory);
            }

            @Override
            public Memory assignMod(double memory) {
                value = toValue();
                return super.assignMod(memory);
            }

            @Override
            public Memory assignMod(boolean memory) {
                value = toValue();
                return super.assignMod(memory);
            }

            @Override
            public Memory assignMod(String memory) {
                value = toValue();
                return super.assignMod(memory);
            }

            @Override
            public Memory assignModRight(Memory memory) {
                value = toValue();
                return super.assignModRight(memory);
            }

            @Override
            public Memory assignBitShr(Memory memory) {
                value = toValue();
                return super.assignBitShr(memory);
            }

            @Override
            public Memory assignBitShr(long memory) {
                value = toValue();
                return super.assignBitShr(memory);
            }

            @Override
            public Memory assignBitShr(double memory) {
                value = toValue();
                return super.assignBitShr(memory);
            }

            @Override
            public Memory assignBitShr(boolean memory) {
                value = toValue();
                return super.assignBitShr(memory);
            }

            @Override
            public Memory assignBitShr(String memory) {
                value = toValue();
                return super.assignBitShr(memory);
            }

            @Override
            public Memory assignBitShrRight(Memory memory) {
                value = toValue();
                return super.assignBitShrRight(memory);
            }

            @Override
            public Memory assignBitShl(Memory memory) {
                value = toValue();
                return super.assignBitShl(memory);
            }

            @Override
            public Memory assignBitShl(long memory) {
                value = toValue();
                return super.assignBitShl(memory);
            }

            @Override
            public Memory assignBitShl(double memory) {
                value = toValue();
                return super.assignBitShl(memory);
            }

            @Override
            public Memory assignBitShl(boolean memory) {
                value = toValue();
                return super.assignBitShl(memory);
            }

            @Override
            public Memory assignBitShl(String memory) {
                value = toValue();
                return super.assignBitShl(memory);
            }

            @Override
            public Memory assignBitShlRight(Memory memory) {
                value = toValue();
                return super.assignBitShlRight(memory);
            }

            @Override
            public Memory assignBitAnd(Memory memory) {
                value = toValue();
                return super.assignBitAnd(memory);
            }

            @Override
            public Memory assignBitAnd(long memory) {
                value = toValue();
                return super.assignBitAnd(memory);
            }

            @Override
            public Memory assignBitAnd(double memory) {
                value = toValue();
                return super.assignBitAnd(memory);
            }

            @Override
            public Memory assignBitAnd(boolean memory) {
                value = toValue();
                return super.assignBitAnd(memory);
            }

            @Override
            public Memory assignBitAnd(String memory) {
                value = toValue();
                return super.assignBitAnd(memory);
            }

            @Override
            public Memory assignBitAndRight(Memory memory) {
                value = toValue();
                return super.assignBitAndRight(memory);
            }

            @Override
            public Memory assignBitOr(Memory memory) {
                value = toValue();
                return super.assignBitOr(memory);
            }

            @Override
            public Memory assignBitOr(long memory) {
                value = toValue();
                return super.assignBitOr(memory);
            }

            @Override
            public Memory assignBitOr(double memory) {
                value = toValue();
                return super.assignBitOr(memory);
            }

            @Override
            public Memory assignBitOr(boolean memory) {
                value = toValue();
                return super.assignBitOr(memory);
            }

            @Override
            public Memory assignBitOr(String memory) {
                value = toValue();
                return super.assignBitOr(memory);
            }

            @Override
            public Memory assignBitOrRight(Memory memory) {
                value = toValue();
                return super.assignBitOrRight(memory);
            }

            @Override
            public Memory assignBitXor(Memory memory) {
                value = toValue();
                return super.assignBitXor(memory);
            }

            @Override
            public Memory assignBitXor(long memory) {
                value = toValue();
                return super.assignBitXor(memory);
            }

            @Override
            public Memory assignBitXor(double memory) {
                value = toValue();
                return super.assignBitXor(memory);
            }

            @Override
            public Memory assignBitXor(boolean memory) {
                value = toValue();
                return super.assignBitXor(memory);
            }

            @Override
            public Memory assignBitXor(String memory) {
                value = toValue();
                return super.assignBitXor(memory);
            }

            @Override
            public Memory assignBitXorRight(Memory memory) {
                value = toValue();
                return super.assignBitXorRight(memory);
            }

            @Override
            public Memory toValue() {
                return ObjectMemory.this.valueOfIndex(trace, index);
            }

            @Override
            public ReferenceMemory getReference() {
                Memory ret = toValue();
                if (ret instanceof ReferenceMemory)
                    return (ReferenceMemory) ret;
                else
                    return new ReferenceMemory();
            }

            @Override
            public Memory toImmutable() {
                return toValue().toImmutable();
            }

            @Override
            public Memory inc() {
                return toValue().inc();
            }

            @Override
            public Memory dec() {
                return toValue().dec();
            }

            @Override
            public Memory valueOfIndex(TraceInfo trace, Memory index) {
                return toValue().valueOfIndex(trace, index);
            }

            @Override
            public Memory valueOfIndex(TraceInfo trace, long index) {
                return toValue().valueOfIndex(trace, index);
            }

            @Override
            public Memory valueOfIndex(TraceInfo trace, double index) {
                return toValue().valueOfIndex(trace, index);
            }

            @Override
            public Memory valueOfIndex(TraceInfo trace, String index) {
                return toValue().valueOfIndex(trace, index);
            }

            @Override
            public Memory valueOfIndex(TraceInfo trace, boolean index) {
                return toValue().valueOfIndex(trace, index);
            }

            @Override
            public Memory refOfPush(TraceInfo trace) {
                return toValue().refOfPush(trace);
            }

            @Override
            public Memory refOfIndexAsShortcut(TraceInfo trace, Memory index) {
                return toValue().refOfIndexAsShortcut(trace, index);
            }

            @Override
            public Memory refOfIndex(TraceInfo trace, Memory index) {
                return toValue().refOfIndex(trace, index);
            }

            @Override
            public Memory refOfIndex(TraceInfo trace, long index) {
                return toValue().refOfIndex(trace, index);
            }

            @Override
            public Memory refOfIndex(TraceInfo trace, double index) {
                return toValue().refOfIndex(trace, index);
            }

            @Override
            public Memory refOfIndex(TraceInfo trace, String index) {
                return toValue().refOfIndex(trace, index);
            }

            @Override
            public Memory refOfIndex(TraceInfo trace, boolean index) {
                return toValue().refOfIndex(trace, index);
            }

            @Override
            public void unsetOfIndex(TraceInfo trace, Memory index) {
                toValue().unsetOfIndex(trace, index);
            }

            @Override
            public Memory issetOfIndex(TraceInfo trace, Memory index) {
                return toValue().issetOfIndex(trace, index);
            }

            @Override
            public Memory emptyOfIndex(TraceInfo trace, Memory index) {
                return toValue().emptyOfIndex(trace, index);
            }
        };
    } else {
        invalidUseAsArray(trace);
        return new ReferenceMemory();
    }
}
Also used : ArrayAccess(php.runtime.lang.spl.ArrayAccess) Memory(php.runtime.Memory) Environment(php.runtime.env.Environment) TraceInfo(php.runtime.env.TraceInfo)

Example 3 with ArrayAccess

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

the class ObjectMemory method issetOfIndex.

private Memory issetOfIndex(TraceInfo trace, Memory index, boolean asEmpty) {
    if (value instanceof ArrayAccess) {
        Environment env = value.getEnvironment();
        if (env != null && trace != null) {
            Memory[] args = new Memory[] { index };
            env.pushCall(value, "offsetExists", args);
            try {
                if (((ArrayAccess) value).offsetExists(env, args).toBoolean())
                    return asEmpty ? valueOfIndex(trace, index) : TRUE;
                else
                    return NULL;
            } finally {
                env.popCall();
            }
        } else {
            invalidUseAsArray(trace);
            return NULL;
        }
    } else {
        invalidUseAsArray(trace);
        return NULL;
    }
}
Also used : ArrayAccess(php.runtime.lang.spl.ArrayAccess) Memory(php.runtime.Memory) Environment(php.runtime.env.Environment)

Example 4 with ArrayAccess

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

the class ObjectMemory method valueOfIndex.

@Override
public Memory valueOfIndex(TraceInfo trace, Memory index) {
    if (value instanceof ArrayAccess) {
        Environment env = value.getEnvironment();
        if (env != null && trace != null) {
            Memory[] args = new Memory[] { index };
            env.pushCall(value, "offsetGet", args);
            try {
                return ((ArrayAccess) value).offsetGet(env, args);
            } finally {
                env.popCall();
            }
        } else {
            invalidUseAsArray(trace);
            return NULL;
        }
    } else {
        invalidUseAsArray(trace);
        return NULL;
    }
}
Also used : ArrayAccess(php.runtime.lang.spl.ArrayAccess) Memory(php.runtime.Memory) Environment(php.runtime.env.Environment)

Aggregations

Memory (php.runtime.Memory)4 Environment (php.runtime.env.Environment)4 ArrayAccess (php.runtime.lang.spl.ArrayAccess)4 TraceInfo (php.runtime.env.TraceInfo)1