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 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; } }
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; } }
if (!ElementUtils.isAssignable(nodeClassType, context.getTruffleTypes().getNode())) { nodeClassType = null;
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; }
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;
TypeElement expectError = context.getTruffleTypes().getExpectError(); if (expectError != null) { AnnotationMirror mirror = ElementUtils.findAnnotationMirror(messageElement.getAnnotationMirrors(), expectError.asType());
TypeElement expectError = context.getTruffleTypes().getExpectError(); if (expectError != null) { AnnotationMirror mirror = ElementUtils.findAnnotationMirror(messageElement.getAnnotationMirrors(), expectError.asType());
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 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; } }
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; }
if (!ElementUtils.isAssignable(templateType.asType(), context.getTruffleTypes().getNode())) { return null;
@Override public MethodSpec createSpecification(ExecutableElement method, AnnotationMirror mirror) { List<String> childNames = ElementUtils.getAnnotationValueList(String.class, mirror, "value"); NodeChildData foundChild = null; for (String childName : childNames) { foundChild = getNode().findChild(childName); if (foundChild != null) { break; } } TypeMirror baseType = getContext().getTruffleTypes().getNode(); if (foundChild != null) { baseType = foundChild.getOriginalType(); } MethodSpec spec = new MethodSpec(new ParameterSpec("child", baseType)); addDefaultFieldMethodSpec(spec); ParameterSpec childSpec = new ParameterSpec("castedChild", baseType); childSpec.setSignature(true); spec.addRequired(childSpec); return spec; }
@Override public MethodSpec createSpecification(ExecutableElement method, AnnotationMirror mirror) { List<String> childNames = ElementUtils.getAnnotationValueList(String.class, mirror, "value"); NodeChildData foundChild = null; for (String childName : childNames) { foundChild = getNode().findChild(childName); if (foundChild != null) { break; } } TypeMirror baseType = getContext().getTruffleTypes().getNode(); if (foundChild != null) { baseType = foundChild.getOriginalType(); } MethodSpec spec = new MethodSpec(new ParameterSpec("child", baseType)); addDefaultFieldMethodSpec(spec); ParameterSpec childSpec = new ParameterSpec("castedChild", baseType); childSpec.setSignature(true); spec.addRequired(childSpec); return spec; }
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);
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; }
if (!ElementUtils.isAssignable(templateType.asType(), context.getTruffleTypes().getNode())) { return null;
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; }