use of com.oracle.truffle.dsl.processor.model.TypeCheckData in project graal by oracle.
the class TypeSystemParser method parse.
@Override
protected TypeSystemData parse(Element element, AnnotationMirror mirror) {
TypeElement templateType = (TypeElement) element;
AnnotationMirror templateTypeAnnotation = mirror;
TypeSystemData typeSystem = new TypeSystemData(context, templateType, templateTypeAnnotation, false);
// annotation type on class path!?
TypeElement annotationTypeElement = processingEnv.getElementUtils().getTypeElement(getAnnotationType().getCanonicalName());
if (annotationTypeElement == null) {
typeSystem.addError("Required class %s is not on the classpath.", getAnnotationType().getName());
}
if (templateType.getModifiers().contains(Modifier.PRIVATE)) {
typeSystem.addError("A @%s must have at least package protected visibility.", getAnnotationType().getName());
}
if (templateType.getModifiers().contains(Modifier.FINAL)) {
typeSystem.addError("The @%s must not be final.", getAnnotationType().getName());
}
if (typeSystem.hasErrors()) {
return typeSystem;
}
if (typeSystem.hasErrors()) {
return typeSystem;
}
verifyExclusiveMethodAnnotation(typeSystem, TypeCast.class, TypeCheck.class);
List<Element> elements = newElementList(context.getEnvironment().getElementUtils().getAllMembers(templateType));
List<ImplicitCastData> implicitCasts = new ImplicitCastParser(context, typeSystem).parse(elements);
List<TypeCastData> casts = new TypeCastParser(context, typeSystem).parse(elements);
List<TypeCheckData> checks = new TypeCheckParser(context, typeSystem).parse(elements);
if (casts == null || checks == null || implicitCasts == null) {
return typeSystem;
}
List<TypeMirror> legacyTypes = ElementUtils.getAnnotationValueList(TypeMirror.class, typeSystem.getTemplateTypeAnnotation(), "value");
for (int i = 0; i < legacyTypes.size(); i++) {
legacyTypes.set(i, ElementUtils.fillInGenericWildcards(legacyTypes.get(i)));
}
typeSystem.getLegacyTypes().addAll(legacyTypes);
verifyTypes(typeSystem);
typeSystem.getLegacyTypes().add(context.getType(Object.class));
typeSystem.getLegacyTypes().add(context.getType(void.class));
verifyNamesUnique(typeSystem);
typeSystem.getImplicitCasts().addAll(implicitCasts);
typeSystem.getCasts().addAll(casts);
typeSystem.getChecks().addAll(checks);
if (typeSystem.hasErrors()) {
return typeSystem;
}
return typeSystem;
}
use of com.oracle.truffle.dsl.processor.model.TypeCheckData in project graal by oracle.
the class TypeSystemCodeGenerator method check.
static CodeTree check(TypeSystemData typeSystem, TypeMirror type, CodeTree content) {
if (ElementUtils.isObject(type)) {
return content;
}
CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
TypeCheckData check = typeSystem.getCheck(type);
if (check == null) {
builder.instanceOf(content, ElementUtils.boxType(typeSystem.getContext(), type));
} else {
builder.startStaticCall(typeSystem.getTemplateType().asType(), check.getMethodName()).tree(content).end();
}
return builder.build();
}
Aggregations