ProcessorContext(ProcessingEnvironment env, ProcessCallback callback) { this.environment = env; this.callback = callback; this.log = new Log(environment); this.truffleTypes = new TruffleTypes(this); }
private void verifyExpectedMessages(ProcessorContext context, Log log, List<Message> msgs) { TypeElement expectError = context.getTruffleTypes().getExpectError(); if (expectError != null) { Element element = getMessageElement(); if (element != null) { AnnotationMirror mirror = ElementUtils.findAnnotationMirror(element.getAnnotationMirrors(), expectError.asType()); if (mirror != null) { List<String> values = ElementUtils.getAnnotationValueList(String.class, mirror, "value"); if (values == null) { values = Collections.emptyList(); } if (values.size() != msgs.size()) { log.message(Kind.ERROR, element, mirror, ElementUtils.getAnnotationValue(mirror, "value"), String.format("Error count expected %s but was %s.", values.size(), msgs.size())); } } } } }
private TypeMirror inheritType(AnnotationMirror annotation, String valueName, TypeMirror parentType) { TypeMirror inhertNodeType = context.getTruffleTypes().getNode(); TypeMirror value = ElementUtils.getAnnotationValue(TypeMirror.class, annotation, valueName); if (ElementUtils.typeEquals(inhertNodeType, value)) { return parentType; } else { return value; } }
TruffleTypes(ProcessorContext context) { node = getRequired(context, Node.class); nodeArray = context.getEnvironment().getTypeUtils().getArrayType(node); unexpectedValueException = getRequired(context, UnexpectedResultException.class); frame = getRequired(context, VirtualFrame.class); childAnnotation = getRequired(context, Child.class); childrenAnnotation = getRequired(context, Children.class); compilerDirectives = getRequired(context, CompilerDirectives.class); compilerAsserts = getRequired(context, CompilerAsserts.class); assumption = getRequired(context, Assumption.class); invalidAssumption = getRequired(context, InvalidAssumptionException.class); nodeInfoAnnotation = getRequired(context, NodeInfo.class); nodeCost = getRequired(context, NodeCost.class); truffleBoundary = getRequired(context, TruffleBoundary.class); sourceSection = getRequired(context, SourceSection.class); truffleOptions = getRequired(context, TruffleOptions.class); compilationFinal = getRequired(context, CompilationFinal.class); nodeUtil = getRequired(context, NodeUtil.class); nodeFactory = getRequired(context, NodeFactory.class); expectError = getOptional(context, EXPECT_ERROR_CLASS_NAME1); generateNodeFactory = getRequired(context, GenerateNodeFactory.class); }
static CodeExecutableElement createExpectMethod(Modifier visibility, TypeSystemData typeSystem, TypeMirror sourceTypeOriginal, TypeMirror expectedTypeOriginal) { TypeMirror expectedType = ElementUtils.fillInGenericWildcards(expectedTypeOriginal); TypeMirror sourceType = ElementUtils.fillInGenericWildcards(sourceTypeOriginal); if (ElementUtils.isObject(expectedType) || ElementUtils.isVoid(expectedType)) { return null; } CodeExecutableElement method = new CodeExecutableElement(modifiers(STATIC), expectedType, TypeSystemCodeGenerator.expectTypeMethodName(typeSystem, expectedType)); method.setVisibility(visibility); method.addParameter(new CodeVariableElement(sourceType, LOCAL_VALUE)); method.addThrownType(typeSystem.getContext().getTruffleTypes().getUnexpectedValueException()); CodeTreeBuilder body = method.createBuilder(); body.startIf().tree(check(typeSystem, expectedType, LOCAL_VALUE)).end().startBlock(); body.startReturn().tree(cast(typeSystem, expectedType, LOCAL_VALUE)).end(); body.end(); body.startThrow().startNew(typeSystem.getContext().getTruffleTypes().getUnexpectedValueException()).string(LOCAL_VALUE).end().end(); return method; }
public final M parse(Element element) { M model = null; try { AnnotationMirror mirror = null; if (getAnnotationType() != null) { mirror = ElementUtils.findAnnotationMirror(processingEnv, element.getAnnotationMirrors(), getAnnotationType()); } if (!context.getTruffleTypes().verify(context, element, mirror)) { return null; } model = parse(element, mirror); if (model == null) { return null; } redirectMessages(new HashSet<MessageContainer>(), model, model); model.emitMessages(context, log); return filterErrorElements(model); } catch (CompileErrorException e) { log.message(Kind.WARNING, element, null, null, "The truffle processor could not parse class due to error: %s", e.getMessage()); return null; } }
public CodeTypeElement create() { Modifier visibility = ElementUtils.getVisibility(node.getTemplateType().getModifiers()); TypeMirror nodeFactory = ElementUtils.getDeclaredType(ElementUtils.fromTypeMirror(context.getTruffleTypes().getNodeFactoryBase()), 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.setSuperClass(nodeFactory); clazz.add(createNodeFactoryConstructor()); clazz.add(createCreateNodeMethod()); clazz.add(createGetInstanceMethod(visibility)); clazz.add(createInstanceConstant(clazz.asType())); createFactoryMethods(clazz); } return clazz; }
builder.staticReference(context.getTruffleTypes().getDslMetadata(), EMPTY_CLASS_ARRAY); } else { builder.startNewArray(new ArrayCodeTypeMirror(context.getType(Class.class)), null); builder.startGroup(); if (constructor.getParameters().isEmpty()) { builder.staticReference(context.getTruffleTypes().getDslMetadata(), EMPTY_CLASS_ARRAY); } else { builder.startNewArray(new ArrayCodeTypeMirror(context.getType(Class.class)), null);
TruffleTypes(ProcessorContext context) { node = getRequired(context, Node.class); nodeArray = context.getEnvironment().getTypeUtils().getArrayType(node); unexpectedValueException = getRequired(context, UnexpectedResultException.class); frame = getRequired(context, VirtualFrame.class); childAnnotation = getRequired(context, Child.class); childrenAnnotation = getRequired(context, Children.class); compilerDirectives = getRequired(context, CompilerDirectives.class); compilerAsserts = getRequired(context, CompilerAsserts.class); assumption = getRequired(context, Assumption.class); invalidAssumption = getRequired(context, InvalidAssumptionException.class); nodeInfoAnnotation = getRequired(context, NodeInfo.class); nodeCost = getRequired(context, NodeCost.class); truffleBoundary = getRequired(context, TruffleBoundary.class); sourceSection = getRequired(context, SourceSection.class); truffleOptions = getRequired(context, TruffleOptions.class); compilationFinal = getRequired(context, CompilationFinal.class); nodeUtil = getRequired(context, NodeUtil.class); dslNode = getRequired(context, DSLNode.class); dslShare = getRequired(context, DSLShare.class); nodeFactory = getRequired(context, NodeFactory.class); nodeFactoryBase = getRequired(context, NodeFactoryBase.class); dslMetadata = getRequired(context, DSLMetadata.class); expectError = getOptional(context, EXPECT_ERROR_CLASS_NAME); generateNodeFactory = getRequired(context, GenerateNodeFactory.class); }
public static CodeExecutableElement createExpectMethod(Modifier visibility, TypeSystemData typeSystem, TypeMirror sourceTypeOriginal, TypeMirror expectedTypeOriginal) { TypeMirror expectedType = ElementUtils.fillInGenericWildcards(expectedTypeOriginal); TypeMirror sourceType = ElementUtils.fillInGenericWildcards(sourceTypeOriginal); if (ElementUtils.isObject(expectedType) || ElementUtils.isVoid(expectedType)) { return null; } CodeExecutableElement method = new CodeExecutableElement(modifiers(STATIC), expectedType, TypeSystemCodeGenerator.expectTypeMethodName(typeSystem, expectedType)); method.setVisibility(visibility); method.addParameter(new CodeVariableElement(sourceType, LOCAL_VALUE)); method.addThrownType(typeSystem.getContext().getTruffleTypes().getUnexpectedValueException()); CodeTreeBuilder body = method.createBuilder(); body.startIf().tree(check(typeSystem, expectedType, LOCAL_VALUE)).end().startBlock(); body.startReturn().tree(cast(typeSystem, expectedType, LOCAL_VALUE)).end(); body.end(); body.startThrow().startNew(typeSystem.getContext().getTruffleTypes().getUnexpectedValueException()).string(LOCAL_VALUE).end().end(); return method; }
public final M parse(Element element) { M model = null; try { AnnotationMirror mirror = null; if (getAnnotationType() != null) { mirror = ElementUtils.findAnnotationMirror(processingEnv, element.getAnnotationMirrors(), getAnnotationType()); } if (!context.getTruffleTypes().verify(context, element, mirror)) { return null; } model = parse(element, mirror); if (model == null) { return null; } redirectMessages(new HashSet<MessageContainer>(), model, model); model.emitMessages(context, log); if (model instanceof NodeData) { return model; } else { return filterErrorElements(model); } } catch (CompileErrorException e) { log.message(Kind.WARNING, element, null, null, "The truffle processor could not parse class due to error: %s", e.getMessage()); return null; } }
private TypeMirror inheritType(AnnotationMirror annotation, String valueName, TypeMirror parentType) { TypeMirror inhertNodeType = context.getTruffleTypes().getNode(); TypeMirror value = ElementUtils.getAnnotationValue(TypeMirror.class, annotation, valueName); if (ElementUtils.typeEquals(inhertNodeType, value)) { return parentType; } else { return value; } }
private void verifyExpectedMessages(ProcessorContext context, Log log, List<Message> msgs) { TypeElement expectError = context.getTruffleTypes().getExpectError(); if (expectError != null) { Element element = getMessageElement(); if (element != null) { AnnotationMirror mirror = ElementUtils.findAnnotationMirror(element.getAnnotationMirrors(), expectError.asType()); if (mirror != null) { List<String> values = ElementUtils.getAnnotationValueList(String.class, mirror, "value"); if (values == null) { values = Collections.emptyList(); } if (values.size() != msgs.size()) { log.message(Kind.ERROR, element, mirror, ElementUtils.getAnnotationValue(mirror, "value"), String.format("Error count expected %s but was %s.", values.size(), msgs.size())); } } } } }
ProcessorContext(ProcessingEnvironment env, ProcessCallback callback) { this.environment = env; this.callback = callback; this.log = new Log(environment); this.truffleTypes = new TruffleTypes(this); }
if (!ElementUtils.isAssignable(nodeClassType, context.getTruffleTypes().getNode())) { nodeClassType = null;
TypeElement expectError = context.getTruffleTypes().getExpectError(); if (expectError != null) { AnnotationMirror mirror = ElementUtils.findAnnotationMirror(messageElement.getAnnotationMirrors(), expectError.asType());
private NodeData parseChildNodeData(NodeData parentNode, NodeChildData child, TypeElement originalTemplateType) { TypeElement templateType = ElementUtils.fromTypeMirror(context.reloadTypeElement(originalTemplateType)); if (ElementUtils.findAnnotationMirror(processingEnv, originalTemplateType, GeneratedBy.class) != null) { // generated nodes should not get called again. return null; } if (!ElementUtils.isAssignable(templateType.asType(), context.getTruffleTypes().getNode())) { return null; } List<TypeElement> lookupTypes = collectSuperClasses(new ArrayList<TypeElement>(), templateType); // Declaration order is not required for child nodes. List<? extends Element> members = processingEnv.getElementUtils().getAllMembers(templateType); NodeData node = parseNodeData(templateType, lookupTypes); if (node.hasErrors()) { return node; } List<TypeMirror> frameTypes = Collections.emptyList(); if (parentNode.getFrameType() != null) { frameTypes = Arrays.asList(parentNode.getFrameType()); } node.getExecutableTypes().addAll(parseExecutableTypeData(node, members, child.getExecuteWith().size(), frameTypes, true)); node.setFrameType(parentNode.getFrameType()); return node; }
TypeElement expectError = context.getTruffleTypes().getExpectError(); if (expectError != null) { AnnotationMirror mirror = ElementUtils.findAnnotationMirror(messageElement.getAnnotationMirrors(), expectError.asType());
private NodeData parseChildNodeData(NodeData parentNode, NodeChildData child, TypeElement originalTemplateType) { TypeElement templateType = ElementUtils.fromTypeMirror(context.reloadTypeElement(originalTemplateType)); if (ElementUtils.findAnnotationMirror(processingEnv, originalTemplateType, GeneratedBy.class) != null) { // generated nodes should not get called again. return null; } if (!ElementUtils.isAssignable(templateType.asType(), context.getTruffleTypes().getNode())) { return null; } List<TypeElement> lookupTypes = collectSuperClasses(new ArrayList<TypeElement>(), templateType); // Declaration order is not required for child nodes. List<? extends Element> members = processingEnv.getElementUtils().getAllMembers(templateType); NodeData node = parseNodeData(templateType, lookupTypes); if (node.hasErrors()) { return node; } List<TypeMirror> frameTypes = Collections.emptyList(); if (parentNode.getFrameType() != null) { frameTypes = Arrays.asList(parentNode.getFrameType()); } node.getExecutableTypes().addAll(parseExecutableTypeData(node, members, child.getExecuteWith().size(), frameTypes, true)); node.setFrameType(parentNode.getFrameType()); return node; }
if (!ElementUtils.isAssignable(nodeClassType, context.getTruffleTypes().getNode())) { nodeClassType = null;