Search in sources :

Example 1 with CodeAnnotationValue

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

the class FlatNodeGenFactory method createExplodeLoop.

private CodeAnnotationMirror createExplodeLoop() {
    DeclaredType explodeLoopType = context.getDeclaredType(ExplodeLoop.class);
    CodeAnnotationMirror explodeLoop = new CodeAnnotationMirror(explodeLoopType);
    DeclaredType loopExplosionKind = context.getDeclaredType(ExplodeLoop.LoopExplosionKind.class);
    if (loopExplosionKind != null) {
        VariableElement kindValue = ElementUtils.findVariableElement(loopExplosionKind, "FULL_EXPLODE_UNTIL_RETURN");
        if (kindValue != null) {
            explodeLoop.setElementValue(ElementUtils.findExecutableElement(explodeLoopType, "kind"), new CodeAnnotationValue(kindValue));
        }
    }
    return explodeLoop;
}
Also used : CodeAnnotationMirror(com.oracle.truffle.dsl.processor.java.model.CodeAnnotationMirror) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop) CodeVariableElement(com.oracle.truffle.dsl.processor.java.model.CodeVariableElement) VariableElement(javax.lang.model.element.VariableElement) DeclaredType(javax.lang.model.type.DeclaredType) CodeAnnotationValue(com.oracle.truffle.dsl.processor.java.model.CodeAnnotationValue)

Example 2 with CodeAnnotationValue

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

the class FlatNodeGenFactory method setFieldCompilationFinal.

private static void setFieldCompilationFinal(CodeVariableElement field, int dimensions) {
    if (field.getModifiers().contains(Modifier.FINAL) && dimensions <= 0) {
        // no need for the compilation final annotation.
        return;
    }
    CodeAnnotationMirror annotation = new CodeAnnotationMirror(ProcessorContext.getInstance().getDeclaredType(CompilationFinal.class));
    if (dimensions > 0 || field.getType().getKind() == TypeKind.ARRAY) {
        annotation.setElementValue(annotation.findExecutableElement("dimensions"), new CodeAnnotationValue(dimensions < 0 ? 0 : dimensions));
    }
    field.getAnnotationMirrors().add(annotation);
}
Also used : CodeAnnotationMirror(com.oracle.truffle.dsl.processor.java.model.CodeAnnotationMirror) CompilationFinal(com.oracle.truffle.api.CompilerDirectives.CompilationFinal) CodeAnnotationValue(com.oracle.truffle.dsl.processor.java.model.CodeAnnotationValue)

Example 3 with CodeAnnotationValue

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

the class GeneratorUtils method createClass.

static CodeTypeElement createClass(Template sourceModel, TemplateMethod sourceMethod, Set<Modifier> modifiers, String simpleName, TypeMirror superType) {
    TypeElement templateType = sourceModel.getTemplateType();
    ProcessorContext context = ProcessorContext.getInstance();
    PackageElement pack = context.getEnvironment().getElementUtils().getPackageOf(templateType);
    CodeTypeElement clazz = new CodeTypeElement(modifiers, ElementKind.CLASS, pack, simpleName);
    TypeMirror resolvedSuperType = superType;
    if (resolvedSuperType == null) {
        resolvedSuperType = context.getType(Object.class);
    }
    clazz.setSuperClass(resolvedSuperType);
    CodeAnnotationMirror generatedByAnnotation = new CodeAnnotationMirror((DeclaredType) context.getType(GeneratedBy.class));
    generatedByAnnotation.setElementValue(generatedByAnnotation.findExecutableElement("value"), new CodeAnnotationValue(templateType.asType()));
    if (sourceMethod != null && sourceMethod.getMethod() != null) {
        generatedByAnnotation.setElementValue(generatedByAnnotation.findExecutableElement("methodName"), new CodeAnnotationValue(sourceMethod.createReferenceName()));
    }
    clazz.addAnnotationMirror(generatedByAnnotation);
    return clazz;
}
Also used : CodeAnnotationMirror(com.oracle.truffle.dsl.processor.java.model.CodeAnnotationMirror) CodeTypeElement(com.oracle.truffle.dsl.processor.java.model.CodeTypeElement) ElementUtils.fromTypeMirror(com.oracle.truffle.dsl.processor.java.ElementUtils.fromTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) CodeTypeElement(com.oracle.truffle.dsl.processor.java.model.CodeTypeElement) PackageElement(javax.lang.model.element.PackageElement) ProcessorContext(com.oracle.truffle.dsl.processor.ProcessorContext) CodeAnnotationValue(com.oracle.truffle.dsl.processor.java.model.CodeAnnotationValue)

Example 4 with CodeAnnotationValue

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

the class FixWarningsVisitor method createUnused.

private CodeAnnotationMirror createUnused() {
    CodeAnnotationMirror mirror = new CodeAnnotationMirror(suppressWarnings);
    mirror.setElementValue(mirror.findExecutableElement("value"), new CodeAnnotationValue("unused"));
    return mirror;
}
Also used : CodeAnnotationMirror(com.oracle.truffle.dsl.processor.java.model.CodeAnnotationMirror) CodeAnnotationValue(com.oracle.truffle.dsl.processor.java.model.CodeAnnotationValue)

Example 5 with CodeAnnotationValue

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

the class NodeFactoryFactory method create.

public CodeTypeElement create() {
    Modifier visibility = ElementUtils.getVisibility(node.getTemplateType().getModifiers());
    TypeMirror nodeFactory = ElementUtils.getDeclaredType(ElementUtils.fromTypeMirror(context.getType(NodeFactory.class)), node.getNodeType());
    CodeTypeElement clazz = GeneratorUtils.createClass(node, null, modifiers(), factoryClassName(node), null);
    if (visibility != null) {
        clazz.getModifiers().add(visibility);
    }
    clazz.getModifiers().add(Modifier.FINAL);
    if (createdFactoryElement != null) {
        clazz.getImplements().add(nodeFactory);
        CodeAnnotationMirror supressWarnings = new CodeAnnotationMirror(context.getDeclaredType(SuppressWarnings.class));
        supressWarnings.setElementValue(supressWarnings.findExecutableElement("value"), new CodeAnnotationValue(Arrays.asList(new CodeAnnotationValue("unchecked"), new CodeAnnotationValue("rawtypes"))));
        clazz.getAnnotationMirrors().add(supressWarnings);
        clazz.add(createNodeFactoryConstructor());
        clazz.add(createCreateGetNodeClass());
        clazz.add(createCreateGetExecutionSignature());
        clazz.add(createCreateGetNodeSignatures());
        clazz.add(createCreateNodeMethod());
        clazz.add(createGetInstanceMethod(visibility));
        clazz.add(createInstanceConstant(clazz.asType()));
        createFactoryMethods(clazz);
    }
    return clazz;
}
Also used : CodeAnnotationMirror(com.oracle.truffle.dsl.processor.java.model.CodeAnnotationMirror) TypeMirror(javax.lang.model.type.TypeMirror) CodeTypeElement(com.oracle.truffle.dsl.processor.java.model.CodeTypeElement) Modifier(javax.lang.model.element.Modifier) CodeAnnotationValue(com.oracle.truffle.dsl.processor.java.model.CodeAnnotationValue)

Aggregations

CodeAnnotationMirror (com.oracle.truffle.dsl.processor.java.model.CodeAnnotationMirror)8 CodeAnnotationValue (com.oracle.truffle.dsl.processor.java.model.CodeAnnotationValue)8 CodeTypeElement (com.oracle.truffle.dsl.processor.java.model.CodeTypeElement)3 DeclaredType (javax.lang.model.type.DeclaredType)3 TypeMirror (javax.lang.model.type.TypeMirror)2 CompilationFinal (com.oracle.truffle.api.CompilerDirectives.CompilationFinal)1 GeneratedBy (com.oracle.truffle.api.dsl.GeneratedBy)1 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)1 ProcessorContext (com.oracle.truffle.dsl.processor.ProcessorContext)1 ElementUtils.fromTypeMirror (com.oracle.truffle.dsl.processor.java.ElementUtils.fromTypeMirror)1 CodeVariableElement (com.oracle.truffle.dsl.processor.java.model.CodeVariableElement)1 Modifier (javax.lang.model.element.Modifier)1 PackageElement (javax.lang.model.element.PackageElement)1 TypeElement (javax.lang.model.element.TypeElement)1 VariableElement (javax.lang.model.element.VariableElement)1