use of com.oracle.truffle.api.object.ObjectType in project graal by oracle.
the class ImplicitCastTest method testIntOtherObject.
@Test
public void testIntOtherObject() {
Shape rootShape = layout.createShape(new ObjectType());
DynamicObject object = rootShape.newInstance();
object.define("a", intVal);
object.define("a", otherVal);
object.define("a", "");
Location location = object.getShape().getProperty("a").getLocation();
Assert.assertEquals(Object.class, getLocationType(location));
Assert.assertEquals(String.class, object.get("a").getClass());
}
use of com.oracle.truffle.api.object.ObjectType in project graal by oracle.
the class ShapeTest method testToString.
@Test
public void testToString() {
Layout layout = new DefaultLayoutFactory().createLayout(Layout.newLayout().addAllowedImplicitCast(ImplicitCast.IntToLong));
Shape rootShape = layout.createShape(new ObjectType());
DOTestAsserts.assertShape("{}", rootShape);
Shape aInt = rootShape.defineProperty("a", 1, 0);
DOTestAsserts.assertShape("{\"a\":int@0" + "\n}", aInt);
Shape aObj = aInt.defineProperty("a", new Object(), 0);
DOTestAsserts.assertShape("{\"a\":Object@0" + "\n}", aObj);
Shape aObjBInt = aObj.defineProperty("b", 2, 0);
DOTestAsserts.assertShape("{" + "\"b\":int@1,\n" + "\"a\":Object@0" + "\n}", aObjBInt);
Shape aIntBObj = aInt.defineProperty("b", new Object(), 0);
DOTestAsserts.assertShape("{" + "\"b\":Object@0,\n" + "\"a\":int@0" + "\n}", aIntBObj);
Shape bool = rootShape.addProperty(Property.create("bool", rootShape.allocator().locationForType(boolean.class), 0));
DOTestAsserts.assertShape("{\"bool\":boolean@0\n}", bool);
Shape str = rootShape.addProperty(Property.create("str", rootShape.allocator().locationForType(String.class), 0));
DOTestAsserts.assertShape("{\"str\":Object@0\n}", str);
Shape shapeWithExtArray = aIntBObj.defineProperty("c", true, 0).defineProperty("d", 3.14, 0).defineProperty("e", 1L << 44, 0);
DOTestAsserts.assertShape("{" + "\"e\":long[0],\n" + "\"d\":double@2,\n" + "\"c\":boolean@1,\n" + "\"b\":Object@0,\n" + "\"a\":int@0" + "\n}", shapeWithExtArray);
}
use of com.oracle.truffle.api.object.ObjectType in project graal by oracle.
the class LayoutParser method parseGuard.
private void parseGuard(ExecutableElement methodElement) {
if (methodElement.getParameters().size() != 1) {
processor.reportError(methodElement, "@Layout guard methods must have just one parameter");
}
final VariableElement parameter = methodElement.getParameters().get(0);
final TypeMirror type = parameter.asType();
final String parameterName = parameter.getSimpleName().toString();
final String expectedParameterName;
if (isSameType(type, DynamicObject.class)) {
hasDynamicObjectGuard = true;
expectedParameterName = "object";
} else if (isSameType(type, ObjectType.class)) {
hasObjectTypeGuard = true;
expectedParameterName = "objectType";
} else if (isSameType(type, Object.class)) {
hasObjectGuard = true;
expectedParameterName = "object";
} else {
processor.reportError(methodElement, "@Layout guard method with unknown parameter type %s - don't know how to guard on this", type);
expectedParameterName = null;
}
if (expectedParameterName != null && !matches(parameterName, expectedParameterName)) {
processor.reportError(methodElement, "@Layout guard method should have a parameter named %s", expectedParameterName);
}
}
Aggregations