Search in sources :

Example 1 with TypeSystemData

use of com.oracle.truffle.dsl.processor.model.TypeSystemData in project graal by oracle.

the class NodeParser method parseNodeData.

private NodeData parseNodeData(TypeElement templateType, List<TypeElement> typeHierarchy) {
    AnnotationMirror typeSystemMirror = findFirstAnnotation(typeHierarchy, TypeSystemReference.class);
    TypeSystemData typeSystem = null;
    if (typeSystemMirror != null) {
        TypeMirror typeSystemType = ElementUtils.getAnnotationValue(TypeMirror.class, typeSystemMirror, "value");
        typeSystem = (TypeSystemData) context.getTemplate(typeSystemType, true);
        if (typeSystem == null) {
            NodeData nodeData = new NodeData(context, templateType);
            nodeData.addError("The used type system '%s' is invalid. Fix errors in the type system first.", ElementUtils.getQualifiedName(typeSystemType));
            return nodeData;
        }
    } else {
        // default dummy type system
        typeSystem = new TypeSystemData(context, templateType, null, true);
    }
    boolean useNodeFactory = findFirstAnnotation(typeHierarchy, GenerateNodeFactory.class) != null;
    return new NodeData(context, templateType, typeSystem, useNodeFactory);
}
Also used : TypeSystemData(com.oracle.truffle.dsl.processor.model.TypeSystemData) AnnotationMirror(javax.lang.model.element.AnnotationMirror) ArrayCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) GenerateNodeFactory(com.oracle.truffle.api.dsl.GenerateNodeFactory) NodeData(com.oracle.truffle.dsl.processor.model.NodeData)

Example 2 with TypeSystemData

use of com.oracle.truffle.dsl.processor.model.TypeSystemData 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)

Aggregations

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