Search in sources :

Example 21 with CodeVariableElement

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

the class InstrumentableProcessor method generateFactory.

@SuppressWarnings("deprecation")
private static CodeTypeElement generateFactory(ProcessorContext context, Element e, CodeTypeElement wrapper) {
    TypeElement sourceType = (TypeElement) e;
    PackageElement pack = context.getEnvironment().getElementUtils().getPackageOf(sourceType);
    Set<Modifier> typeModifiers = ElementUtils.modifiers(Modifier.PUBLIC, Modifier.FINAL);
    CodeTypeElement factory = new CodeTypeElement(typeModifiers, ElementKind.CLASS, pack, createWrapperClassName(sourceType));
    TypeMirror factoryType = context.reloadType(context.getType(com.oracle.truffle.api.instrumentation.InstrumentableFactory.class));
    factory.getImplements().add(new CodeTypeMirror.DeclaredCodeTypeMirror(ElementUtils.fromTypeMirror(factoryType), Arrays.asList(sourceType.asType())));
    addGeneratedBy(context, factory, sourceType);
    TypeMirror returnType = context.getType(com.oracle.truffle.api.instrumentation.InstrumentableFactory.WrapperNode.class);
    CodeExecutableElement createMethod = new CodeExecutableElement(ElementUtils.modifiers(Modifier.PUBLIC), returnType, "createWrapper");
    createMethod.addParameter(new CodeVariableElement(sourceType.asType(), FIELD_DELEGATE));
    createMethod.addParameter(new CodeVariableElement(context.getType(ProbeNode.class), FIELD_PROBE));
    CodeTreeBuilder builder = createMethod.createBuilder();
    ExecutableElement constructor = ElementFilter.constructorsIn(wrapper.getEnclosedElements()).iterator().next();
    String firstParameterReference = null;
    if (constructor.getParameters().size() > 2) {
        TypeMirror firstParameter = constructor.getParameters().get(0).asType();
        if (ElementUtils.typeEquals(firstParameter, sourceType.asType())) {
            firstParameterReference = FIELD_DELEGATE;
        } else if (ElementUtils.typeEquals(firstParameter, context.getType(SourceSection.class))) {
            firstParameterReference = FIELD_DELEGATE + ".getSourceSection()";
        }
    }
    builder.startReturn().startNew(wrapper.asType());
    if (firstParameterReference != null) {
        builder.string(firstParameterReference);
    }
    builder.string(FIELD_DELEGATE).string(FIELD_PROBE);
    builder.end().end();
    factory.add(createMethod);
    return factory;
}
Also used : CodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror) CodeExecutableElement(com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement) TypeElement(javax.lang.model.element.TypeElement) CodeTypeElement(com.oracle.truffle.dsl.processor.java.model.CodeTypeElement) CodeExecutableElement(com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement) ExecutableElement(javax.lang.model.element.ExecutableElement) CodeTypeElement(com.oracle.truffle.dsl.processor.java.model.CodeTypeElement) CodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) CodeVariableElement(com.oracle.truffle.dsl.processor.java.model.CodeVariableElement) PackageElement(javax.lang.model.element.PackageElement) Modifier(javax.lang.model.element.Modifier) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)

Example 22 with CodeVariableElement

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

the class InstrumentableProcessor method createNodeChild.

private static CodeVariableElement createNodeChild(ProcessorContext context, TypeMirror type, String name) {
    CodeVariableElement var = new CodeVariableElement(ElementUtils.modifiers(Modifier.PRIVATE), type, name);
    var.addAnnotationMirror(new CodeAnnotationMirror((DeclaredType) context.getType(Child.class)));
    return var;
}
Also used : CodeAnnotationMirror(com.oracle.truffle.dsl.processor.java.model.CodeAnnotationMirror) CodeVariableElement(com.oracle.truffle.dsl.processor.java.model.CodeVariableElement) Child(com.oracle.truffle.api.nodes.Node.Child) DeclaredType(javax.lang.model.type.DeclaredType)

Aggregations

CodeVariableElement (com.oracle.truffle.dsl.processor.java.model.CodeVariableElement)22 CodeExecutableElement (com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement)14 TypeMirror (javax.lang.model.type.TypeMirror)12 CodeTreeBuilder (com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)8 ArrayCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror)8 VariableElement (javax.lang.model.element.VariableElement)8 ArrayList (java.util.ArrayList)7 GeneratedTypeMirror (com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror)6 DeclaredCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.DeclaredCodeTypeMirror)5 SpecializationData (com.oracle.truffle.dsl.processor.model.SpecializationData)5 ExecutableElement (javax.lang.model.element.ExecutableElement)5 CodeTypeElement (com.oracle.truffle.dsl.processor.java.model.CodeTypeElement)4 TypeElement (javax.lang.model.element.TypeElement)4 Child (com.oracle.truffle.api.nodes.Node.Child)3 CodeAnnotationMirror (com.oracle.truffle.dsl.processor.java.model.CodeAnnotationMirror)3 CodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror)3 NodeChildData (com.oracle.truffle.dsl.processor.model.NodeChildData)3 NodeExecutionData (com.oracle.truffle.dsl.processor.model.NodeExecutionData)3 Parameter (com.oracle.truffle.dsl.processor.model.Parameter)3 Assumption (com.oracle.truffle.api.Assumption)2