Search in sources :

Example 1 with ProcessorContext

use of com.oracle.truffle.dsl.processor.ProcessorContext 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 2 with ProcessorContext

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

the class ExecutableTypeData method compareTo.

public int compareTo(ExecutableTypeData o2) {
    ExecutableTypeData o1 = this;
    ProcessorContext context = ProcessorContext.getInstance();
    if (canDelegateTo(o2)) {
        if (!o2.canDelegateTo(this)) {
            return 1;
        }
    } else if (o2.canDelegateTo(this)) {
        return -1;
    }
    int result = Integer.compare(o2.getEvaluatedCount(), o1.getEvaluatedCount());
    if (result != 0) {
        return result;
    }
    result = Boolean.compare(o1.hasUnexpectedValue(context), o2.hasUnexpectedValue(context));
    if (result != 0) {
        return result;
    }
    result = compareType(context, o1.getReturnType(), o2.getReturnType());
    if (result != 0) {
        return result;
    }
    result = compareType(context, o1.getFrameParameter(), o2.getFrameParameter());
    if (result != 0) {
        return result;
    }
    for (int i = 0; i < o1.getEvaluatedCount(); i++) {
        result = compareType(context, o1.getEvaluatedParameters().get(i), o2.getEvaluatedParameters().get(i));
        if (result != 0) {
            return result;
        }
    }
    result = o1.getUniqueName().compareTo(o2.getUniqueName());
    if (result != 0) {
        return result;
    }
    if (o1.getMethod() != null && o2.getMethod() != null) {
        result = ElementUtils.compareMethod(o1.getMethod(), o2.getMethod());
        if (result != 0) {
            return result;
        }
    }
    return 0;
}
Also used : ProcessorContext(com.oracle.truffle.dsl.processor.ProcessorContext)

Example 3 with ProcessorContext

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

the class GeneratorUtils method createTransferToInterpreterAndInvalidate.

static CodeTree createTransferToInterpreterAndInvalidate() {
    ProcessorContext context = ProcessorContext.getInstance();
    CodeTreeBuilder builder = CodeTreeBuilder.createBuilder();
    builder.startStatement().startStaticCall(context.getType(CompilerDirectives.class), "transferToInterpreterAndInvalidate").end().end();
    return builder.build();
}
Also used : CompilerDirectives(com.oracle.truffle.api.CompilerDirectives) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder) ProcessorContext(com.oracle.truffle.dsl.processor.ProcessorContext)

Example 4 with ProcessorContext

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

the class ExecutableTypeData method canDelegateTo.

public boolean canDelegateTo(ExecutableTypeData to) {
    ExecutableTypeData from = this;
    if (to.getEvaluatedCount() < from.getEvaluatedCount()) {
        return false;
    }
    ProcessorContext context = node.getContext();
    // we cannot delegate from generic to unexpected
    if (!from.hasUnexpectedValue(context) && to.hasUnexpectedValue(context)) {
        return false;
    }
    // we can skip the return type check for void. everything is assignable to void.
    if (!isVoid(from.getReturnType())) {
        if (!isSubtypeBoxed(context, from.getReturnType(), to.getReturnType()) && !isSubtypeBoxed(context, to.getReturnType(), from.getReturnType())) {
            return false;
        }
    }
    if (from.getFrameParameter() != to.getFrameParameter() && from.getFrameParameter() != null && to.getFrameParameter() != null && !isSubtypeBoxed(context, from.getFrameParameter(), to.getFrameParameter())) {
        return false;
    }
    for (int i = 0; i < from.getEvaluatedCount(); i++) {
        if (!isSubtypeBoxed(context, from.getEvaluatedParameters().get(i), to.getEvaluatedParameters().get(i))) {
            return false;
        }
    }
    List<TypeMirror> fromSignatureParameters = from.getSignatureParameters();
    List<TypeMirror> toSignatureParameters = to.getSignatureParameters();
    for (int i = fromSignatureParameters.size(); i < toSignatureParameters.size(); i++) {
        TypeMirror delegateToParameter = toSignatureParameters.get(i);
        if (i < node.getChildExecutions().size()) {
            TypeMirror genericType = node.getGenericType(node.getChildExecutions().get(i));
            if (!isSubtypeBoxed(context, genericType, delegateToParameter)) {
                return false;
            }
        }
    }
    return true;
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) ProcessorContext(com.oracle.truffle.dsl.processor.ProcessorContext)

Aggregations

ProcessorContext (com.oracle.truffle.dsl.processor.ProcessorContext)4 TypeMirror (javax.lang.model.type.TypeMirror)2 CompilerDirectives (com.oracle.truffle.api.CompilerDirectives)1 ElementUtils.fromTypeMirror (com.oracle.truffle.dsl.processor.java.ElementUtils.fromTypeMirror)1 CodeAnnotationMirror (com.oracle.truffle.dsl.processor.java.model.CodeAnnotationMirror)1 CodeAnnotationValue (com.oracle.truffle.dsl.processor.java.model.CodeAnnotationValue)1 CodeTreeBuilder (com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)1 CodeTypeElement (com.oracle.truffle.dsl.processor.java.model.CodeTypeElement)1 PackageElement (javax.lang.model.element.PackageElement)1 TypeElement (javax.lang.model.element.TypeElement)1