use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.
the class ArrayMemory method unshift.
public void unshift(Memory value, int count) {
checkCopied();
if (size == 0) {
for (int i = 0; i < count; i++) add(value);
} else {
if (list != null) {
List<ReferenceMemory> tmp = new ArrayList<ReferenceMemory>();
for (int i = 0; i < count; i++) tmp.add(new ReferenceMemory(value));
list.addAll(0, tmp);
size = list.size();
} else {
ArrayMemory tmp = new ArrayMemory();
tmp.convertToMap();
for (int i = 0; i < count; i++) tmp.add(value);
ForeachIterator iterator = getNewIterator(null, false, false);
while (iterator.next()) {
Object key = iterator.getKey();
if (key instanceof String)
tmp.put(key, iterator.getValue());
else
add(iterator.getValue());
}
lastLongIndex = tmp.lastLongIndex;
map = tmp.map;
size = tmp.size;
}
}
}
use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.
the class ArrayMemory method compare.
public int compare(ArrayMemory otherRef, boolean strict, Set<Integer> used) {
int size1 = size(), size2 = otherRef.size();
if (size1 < size2)
return -1;
else if (size1 > size2)
return 1;
ForeachIterator iterator = this.foreachIterator(false, false);
ForeachIterator iterator2 = null;
if (strict)
iterator2 = otherRef.foreachIterator(false, false);
if (used == null)
used = new HashSet<Integer>();
while (iterator.next()) {
Memory value1 = iterator.getValue();
Memory key = iterator.getMemoryKey();
Memory value2;
if (iterator2 == null)
value2 = otherRef.get(key);
else {
if (!iterator2.next())
return -2;
Object key2 = iterator2.getKey();
if (!iterator.getKey().equals(key2))
return -2;
value2 = iterator2.getValue();
}
if (value2 == null)
return -2;
if (value1.isArray() && value2.isArray()) {
ArrayMemory arr1 = value1.toValue(ArrayMemory.class);
if (used.add(value2.getPointer())) {
int r = arr1.compare(value2.toValue(ArrayMemory.class), strict, used);
if (r == 0) {
used.remove(value2.getPointer());
continue;
}
return r;
}
used.remove(value2.getPointer());
} else if (value1.isObject() && value2.isObject()) {
ObjectMemory o1 = value1.toValue(ObjectMemory.class);
ObjectMemory o2 = value2.toValue(ObjectMemory.class);
return o1.compare(o2.value, strict, used);
} else {
if ((strict && value1.identical(value2)) || (!strict && value1.equal(value2)))
continue;
if (value1.smaller(value2))
return -1;
else
return 1;
}
}
return 0;
}
use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.
the class PrintR method printArray.
@Override
protected void printArray(ArrayMemory value, int level, Set<Integer> used) {
writeArrayHeader();
if (used.contains(value.getPointer())) {
printer.write(" *RECURSION*");
} else {
printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
writeOpen();
level += 1;
used.add(value.getPointer());
ForeachIterator iterator = value.foreachIterator(false, false);
int i = 0;
int size = value.size();
while (iterator.next()) {
Memory el = iterator.getValue();
if (el == Memory.UNDEFINED)
continue;
printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
Memory key = iterator.getMemoryKey();
printer.write('[');
printer.write(key.toString());
printer.write("] => ");
print(el, level + 1, used);
writeSeparator(i == size - 1);
i++;
}
level -= 1;
printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
writeClose();
used.remove(value.getPointer());
}
}
use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.
the class VarDump method printObject.
@Override
protected void printObject(ObjectMemory value, int level, Set<Integer> used) {
ClassEntity classEntity = value.getReflection();
if (used.contains(value.getPointer())) {
printer.write("*RECURSION*\n");
} else {
ArrayMemory arr;
if (classEntity.methodMagicDebugInfo != null) {
try {
Memory tmp = env.invokeMethod(value.value, classEntity.methodMagicDebugInfo.getName());
if (tmp.isArray()) {
arr = tmp.toValue(ArrayMemory.class);
} else {
arr = new ArrayMemory();
}
} catch (RuntimeException e) {
throw e;
} catch (Throwable throwable) {
throw new RuntimeException(throwable);
}
} else
arr = value.getProperties();
printer.write("object(");
printer.write(classEntity.getName());
printer.write(")#" + value.getPointer());
printer.write(" (" + arr.size() + ") {\n");
level += 1;
used.add(value.getPointer());
if (classEntity.methodMagicDebugInfo == null) {
for (PropertyEntity entity : classEntity.getProperties()) {
if (entity.getGetter() != null && !entity.isHiddenInDebugInfo()) {
printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
printer.write("[\"");
printer.write(entity.getName());
printer.write('"');
printer.write(":getter]=>\n");
printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
try {
print(entity.getValue(env, TraceInfo.UNKNOWN, value.value), level, used);
} catch (RuntimeException e) {
throw e;
} catch (Throwable throwable) {
throw new RuntimeException(throwable);
}
}
}
}
ForeachIterator iterator = arr.foreachIterator(false, false);
while (iterator.next()) {
printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
Memory key = iterator.getMemoryKey();
printer.write('[');
if (key.isString()) {
String realKey = key.toString();
int pos;
Modifier modifier = Modifier.PUBLIC;
String className = "";
if ((pos = realKey.lastIndexOf("\0")) > -1) {
if (realKey.startsWith("\0*\0")) {
modifier = Modifier.PROTECTED;
} else {
modifier = Modifier.PRIVATE;
className = realKey.substring(1, pos);
}
realKey = realKey.substring(pos + 1);
}
printer.write('"');
printer.write(realKey);
printer.write('"');
switch(modifier) {
case PRIVATE:
printer.write(":\"" + className + "\":private");
break;
case PROTECTED:
printer.write(":protected");
}
} else {
printer.write(key.toString());
}
printer.write("]=>\n");
printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
print(iterator.getValue(), level, used);
//printer.write('\n');
}
level -= 1;
printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
printer.write("}\n");
used.remove(value.getPointer());
}
}
use of php.runtime.lang.ForeachIterator in project jphp by jphp-compiler.
the class VarExport method printArray.
protected void printArray(ArrayMemory value, int level, Set<Integer> used, boolean stripNulls) {
if (!used.add(value.getPointer())) {
recursionExists = true;
printNull();
} else {
printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
printer.write("array (\n");
ForeachIterator iterator = value.foreachIterator(false, false);
level += 1;
while (iterator.next()) {
Memory el = iterator.getValue();
if (el == Memory.UNDEFINED)
continue;
printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
Memory key = iterator.getMemoryKey();
if (key.isString()) {
String k = key.toString();
if (stripNulls) {
int pos = k.lastIndexOf('\0');
if (pos > -1)
k = k.substring(pos + 1);
}
printString(new StringMemory(k));
} else {
printer.write(key.toString());
}
printer.write(" =>");
if (el.isArray()) {
if (!used.contains(el.getPointer()))
printer.write("\n");
else
printer.write(" ");
print(el, level, used);
} else {
printer.write(" ");
print(el, level + 1, used);
}
printer.append(",\n");
}
level -= 1;
printer.write(StringUtils.repeat(' ', level * PRINT_INDENT));
printer.append(")");
used.remove(value.getPointer());
}
}
Aggregations