use of com.oracle.truffle.api.object.Property in project graal by oracle.
the class ConsListPropertyMap method copyAndRemove.
public ImmutableMap<Object, Property> copyAndRemove(Object key) {
Deque<Property> shelve = new ArrayDeque<>();
ConsListPropertyMap current = this;
while (!current.isEmpty()) {
if (current.getLastProperty().getKey().equals(key)) {
ConsListPropertyMap newMap = current.getParentMap();
for (Property property : shelve) {
newMap = newMap.putCopy(property);
}
return newMap;
} else {
shelve.push(current.getLastProperty());
current = current.getParentMap();
}
}
return this;
}
use of com.oracle.truffle.api.object.Property in project graal by oracle.
the class ConsListPropertyMap method replaceCopy.
@Override
public ConsListPropertyMap replaceCopy(Property oldValue, Property newValue) {
Deque<Property> shelve = new ArrayDeque<>();
ConsListPropertyMap current = this;
while (!current.isEmpty()) {
if (current.getLastProperty().equals(oldValue)) {
ConsListPropertyMap newMap = current.getParentMap();
newMap = newMap.putCopy(newValue);
for (Property property : shelve) {
newMap = newMap.putCopy(property);
}
return newMap;
} else {
shelve.push(current.getLastProperty());
current = current.getParentMap();
}
}
return this;
}
use of com.oracle.truffle.api.object.Property in project graal by oracle.
the class Debug method dumpObject.
static String dumpObject(DynamicObject object, int level, int levelStop) {
List<Property> properties = object.getShape().getPropertyListInternal(true);
StringBuilder sb = new StringBuilder(properties.size() * 10);
sb.append("{\n");
for (Property property : properties) {
indent(sb, level + 1);
sb.append(property.getKey());
sb.append('[').append(property.getLocation()).append(']');
Object value = property.get(object, false);
if (value instanceof DynamicObject) {
if (level < levelStop) {
value = dumpObject((DynamicObject) value, level + 1, levelStop);
} else {
value = value.toString();
}
}
sb.append(": ");
sb.append(value);
if (property != properties.get(properties.size() - 1)) {
sb.append(",");
}
sb.append("\n");
}
indent(sb, level);
sb.append("}");
return sb.toString();
}
use of com.oracle.truffle.api.object.Property in project graal by oracle.
the class DynamicObjectImpl method copyProperties.
private void copyProperties(DynamicObject fromObject) {
ShapeImpl fromShape = (ShapeImpl) fromObject.getShape();
ShapeImpl toShape = getShape();
assert toShape.isRelated(fromShape);
assert toShape.isValid();
assert !fromShape.isShared();
PropertyMap fromMap = fromShape.getPropertyMap();
for (Iterator<Property> toMapIt = toShape.getPropertyMap().reverseOrderedValueIterator(); toMapIt.hasNext(); ) {
Property toProperty = toMapIt.next();
Property fromProperty = fromMap.get(toProperty.getKey());
// copy only if property has a location and it's not the same as the source location
if (!toProperty.getLocation().isValue() && !toProperty.getLocation().equals(fromProperty.getLocation())) {
toProperty.setInternal(this, fromProperty.get(fromObject, false));
assert toShape.isValid();
}
}
}
use of com.oracle.truffle.api.object.Property in project graal by oracle.
the class DynamicObjectImpl method changeFlags.
/**
* @since 0.17 or earlier
*/
@TruffleBoundary
public boolean changeFlags(Object key, int newFlags) {
Shape oldShape = getShape();
Property existing = oldShape.getProperty(key);
if (existing != null) {
if (existing.getFlags() != newFlags) {
Property newProperty = existing.copyWithFlags(newFlags);
Shape newShape = oldShape.replaceProperty(existing, newProperty);
this.setShape(newShape);
}
return true;
} else {
return false;
}
}
Aggregations