use of php.runtime.Memory 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;
}
use of php.runtime.Memory in project jphp by jphp-compiler.
the class CompileMethodEntity method invokeDynamic.
public Memory invokeDynamic(Object _this, Environment env, Memory... arguments) throws Throwable {
try {
if (isAbstract) {
env.error(ErrorType.E_ERROR, "Cannot call abstract method %s", getSignatureString(false));
return Memory.NULL;
}
if (_this == null && !isStatic) {
_this = clazz.newMock(env);
if (_this == null)
env.error(ErrorType.E_ERROR, Messages.ERR_STATIC_METHOD_CALLED_DYNAMICALLY.fetch(getClazz().getName() + "::" + getName()));
}
CompileMethod.Method method = function.find(arguments == null ? 0 : arguments.length);
if (method == null) {
env.warning(env.trace(), Messages.ERR_EXPECT_LEAST_PARAMS.fetch(name, function.getMinArgs(), arguments == null ? 0 : arguments.length));
return Memory.NULL;
} else {
if (arguments != null && arguments.length > method.argsCount && !method.isVarArg()) {
env.error(env.trace(), ErrorType.E_ERROR, Messages.ERR_EXPECT_EXACTLY_PARAMS, name, method.argsCount, arguments.length);
return Memory.NULL;
}
}
Class<?>[] types = method.parameterTypes;
Object[] passed = new Object[types.length];
int i = 0;
int j = 0;
for (Class<?> clazz : types) {
boolean isRef = method.references[i];
boolean mutableValue = method.mutableValues[i];
MemoryOperation<?> operation = method.argumentOperations[i];
if (clazz == Memory.class) {
passed[i] = isRef ? arguments[j] : (mutableValue ? arguments[j].toValue() : arguments[j].toImmutable());
j++;
} else if (operation != null) {
if (operation instanceof InjectMemoryOperation) {
passed[i] = operation.convert(env, trace, null);
} else {
passed[i] = operation.convert(env, trace, arguments[j]);
j++;
}
} else if (i == types.length - 1 && types[i] == Memory[].class) {
Memory[] arg = new Memory[arguments.length - i + 1];
if (!isRef) {
for (int k = 0; k < arg.length; k++) arg[i] = arguments[i].toImmutable();
} else {
System.arraycopy(arguments, j, arg, 0, arg.length);
}
passed[i] = arg;
break;
} else {
env.error(trace, ErrorType.E_CORE_ERROR, name + "(): Cannot call this method dynamically");
passed[i] = Memory.NULL;
}
i++;
}
try {
return method.returnOperation.unconvertNoThow(env, trace, method.method.invoke(_this, passed));
} finally {
i = 0;
if (this != this.getClazz().methodConstruct) {
for (Object o : passed) {
MemoryOperation operation = method.argumentOperations[i];
if (operation != null) {
operation.releaseConverted(env, trace, o);
}
i++;
}
}
}
} catch (InvocationTargetException e) {
return env.__throwException(e);
} catch (Throwable e) {
throw e;
} finally {
unsetArguments(arguments);
}
}
use of php.runtime.Memory 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");
}
use of php.runtime.Memory 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");
}
}
use of php.runtime.Memory in project jphp by jphp-compiler.
the class ArrayMemory method toBoolArray.
public boolean[] toBoolArray() {
boolean[] r = new boolean[size];
int i = 0;
for (Memory e : this) {
r[i] = e.toBoolean();
i++;
}
return r;
}
Aggregations