Search in sources :

Example 1 with TypeCheckData

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;
}
Also used : ImplicitCastData(com.oracle.truffle.dsl.processor.model.ImplicitCastData) TypeElement(javax.lang.model.element.TypeElement) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) TypeCastData(com.oracle.truffle.dsl.processor.model.TypeCastData) TypeSystemData(com.oracle.truffle.dsl.processor.model.TypeSystemData) AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeCheckData(com.oracle.truffle.dsl.processor.model.TypeCheckData) TypeMirror(javax.lang.model.type.TypeMirror)

Example 2 with TypeCheckData

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();
}
Also used : TypeCheckData(com.oracle.truffle.dsl.processor.model.TypeCheckData) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)

Aggregations

TypeCheckData (com.oracle.truffle.dsl.processor.model.TypeCheckData)2 CodeTreeBuilder (com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)1 ImplicitCastData (com.oracle.truffle.dsl.processor.model.ImplicitCastData)1 TypeCastData (com.oracle.truffle.dsl.processor.model.TypeCastData)1 TypeSystemData (com.oracle.truffle.dsl.processor.model.TypeSystemData)1 AnnotationMirror (javax.lang.model.element.AnnotationMirror)1 Element (javax.lang.model.element.Element)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 TypeElement (javax.lang.model.element.TypeElement)1 TypeMirror (javax.lang.model.type.TypeMirror)1