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;
}
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;
}
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();
}
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;
}
Aggregations