private CodeAnnotationMirror createExplodeLoop() { DeclaredType explodeLoopType = context.getDeclaredType(ExplodeLoop.class); CodeAnnotationMirror explodeLoop = new CodeAnnotationMirror(explodeLoopType); DeclaredType loopExplosionKind = context.getDeclaredType(ExplodeLoop.LoopExplosionKind.class); if (loopExplosionKind != null) { VariableElement kindValue = ElementUtils.findVariableElement(loopExplosionKind, "FULL_EXPLODE_UNTIL_RETURN"); if (kindValue != null) { explodeLoop.setElementValue(ElementUtils.findExecutableElement(explodeLoopType, "kind"), new CodeAnnotationValue(kindValue)); } } return explodeLoop; }
@Override public MethodSpec createSpecification(ExecutableElement method, AnnotationMirror mirror) { MethodSpec spec = createDefaultMethodSpec(method, mirror, true, null); spec.getAnnotations().add(new AnnotatedParameterSpec(getContext().getDeclaredType(Cached.class))); return spec; }
@Override public MethodSpec createSpecification(ExecutableElement method, AnnotationMirror mirror) { MethodSpec spec = createDefaultMethodSpec(method, mirror, true, null); spec.getAnnotations().add(new CachedParameterSpec(getContext().getDeclaredType(Cached.class))); return spec; }
private static void setFieldCompilationFinal(CodeVariableElement field, int dimensions) { if (field.getModifiers().contains(Modifier.FINAL) && dimensions <= 0) { // no need for the compilation final annotation. return; } CodeAnnotationMirror annotation = new CodeAnnotationMirror(ProcessorContext.getInstance().getDeclaredType(CompilationFinal.class)); if (dimensions > 0 || field.getType().getKind() == TypeKind.ARRAY) { annotation.setElementValue(annotation.findExecutableElement("dimensions"), new CodeAnnotationValue(dimensions < 0 ? 0 : dimensions)); } field.getAnnotationMirrors().add(annotation); }
private CodeVariableElement createNodeField(Modifier visibility, TypeMirror type, String name, Class<?> annotationType) { CodeVariableElement childField = new CodeVariableElement(modifiers(), type, name); childField.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(annotationType))); setVisibility(childField.getModifiers(), visibility); return childField; }
private Element createFastPathExecuteMethod(SpecializationData specialization, ExecutableTypeData executedType, List<ExecutableTypeData> allTypes) { LocalContext currentLocals = LocalContext.load(this, executedType, Integer.MAX_VALUE); CodeExecutableElement executable = createExecuteMethod(specialization, executedType, currentLocals, false, Integer.MAX_VALUE); CodeTreeBuilder builder = executable.createBuilder(); if (specialization == null) { if (executedType.getDelegatedTo() == null) { executable.getModifiers().add(ABSTRACT); } } else { executable.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class))); } builder.tree(createFastPath(builder, specialization, executedType, allTypes, currentLocals)); return executable; }
private static CodeVariableElement createNodeField(Modifier visibility, TypeMirror type, String name, Class<?> annotationClass, Modifier... modifiers) { CodeVariableElement childField = new CodeVariableElement(modifiers(modifiers), type, name); if (annotationClass != null) { if (annotationClass == CompilationFinal.class) { setFieldCompilationFinal(childField, 0); } else { childField.getAnnotationMirrors().add(new CodeAnnotationMirror(ProcessorContext.getInstance().getDeclaredType(annotationClass))); } } setVisibility(childField.getModifiers(), visibility); return childField; }
private Element createCreatePolymorphic(Map<SpecializationData, CodeTypeElement> generatedSpecializationClasses) { SpecializationData polymorphic = node.getPolymorphicSpecialization(); CodeTypeElement generatedPolymorphic = generatedSpecializationClasses.get(polymorphic); if (generatedPolymorphic == null) { return null; } TypeMirror returnType = getType(SpecializationNode.class); CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED, FINAL), returnType, "createPolymorphic"); method.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class))); method.createBuilder().startReturn().tree(createCallCreateMethod(polymorphic, null, null)).end(); return method; }
private Element createGetSuppliedChildrenMethod() { ArrayType nodeArray = context.getEnvironment().getTypeUtils().getArrayType(getType(Node.class)); CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED, FINAL), nodeArray, "getSuppliedChildren"); method.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class))); CodeTreeBuilder builder = method.createBuilder(); builder.startReturn().tree(createGetSuppliedChildren()).end(); return method; }
private CodeTypeElement generateWrapperAndFactory(ProcessorContext context, Element e) { CodeTypeElement wrapper = generateWrapper(context, e, false); if (wrapper == null) { return null; } CodeTypeElement factory = generateFactory(context, e, wrapper); // add @SuppressWarnings("deprecation") DeclaredType suppressWarnings = context.getDeclaredType(SuppressWarnings.class); CodeAnnotationMirror suppressWarningsAnnotation = new CodeAnnotationMirror(suppressWarnings); suppressWarningsAnnotation.setElementValue(ElementUtils.findExecutableElement(suppressWarnings, "value"), new CodeAnnotationValue(Arrays.asList(new CodeAnnotationValue("deprecation")))); factory.getAnnotationMirrors().add(suppressWarningsAnnotation); wrapper.getModifiers().add(Modifier.STATIC); factory.add(wrapper); assertNoErrorExpected(e); return factory; }
private Element createCreateFallback(Map<SpecializationData, CodeTypeElement> generatedSpecializationClasses) { SpecializationData fallback = node.getGenericSpecialization(); if (fallback == null) { return null; } CodeTypeElement generatedType = generatedSpecializationClasses.get(fallback); if (generatedType == null) { return null; } TypeMirror returnType = getType(SpecializationNode.class); CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED, FINAL), returnType, "createFallback"); method.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class))); method.createBuilder().startReturn().tree(createCallCreateMethod(fallback, null, null)).end(); return method; }
private Element createDeepCopyMethod() { if (singleSpecializable) { return null; } CodeExecutableElement executable = new CodeExecutableElement(modifiers(PUBLIC), getType(Node.class), "deepCopy"); executable.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class))); CodeTreeBuilder builder = executable.createBuilder(); builder.startReturn().startStaticCall(getType(SpecializationNode.class), "updateRoot").string("super.deepCopy()").end().end(); return executable; }
private Element createUnsupported() { SpecializationData fallback = node.getGenericSpecialization(); if (fallback == null || optimizeFallback(fallback) || fallback.getMethod() == null) { return null; } LocalContext locals = LocalContext.load(this); CodeExecutableElement method = locals.createMethod(modifiers(PROTECTED, FINAL), genericType, "unsupported", varArgsThreshold, FRAME_VALUE); method.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class))); CodeTreeBuilder builder = method.createBuilder(); builder.startReturn(); builder.tree(callTemplateMethod(accessParent(null), fallback, locals)); builder.end(); return method; }
private Element createGetCostMethod() { TypeMirror returnType = getType(NodeCost.class); CodeExecutableElement executable = new CodeExecutableElement(modifiers(PUBLIC), returnType, "getCost"); executable.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class))); CodeTreeBuilder builder = executable.createBuilder(); if (singleSpecializable) { builder.startReturn().staticReference(getType(NodeCost.class), "MONOMORPHIC").end().end(); } else { builder.startReturn().startCall(specializationStartFieldName(), "getNodeCost").end().end(); } return executable; }
private CodeExecutableElement createCreateNext(final Map<SpecializationData, CodeTypeElement> specializationClasses) { final LocalContext locals = LocalContext.load(this); CodeExecutableElement method = locals.createMethod(modifiers(PROTECTED, FINAL), getType(SpecializationNode.class), "createNext", varArgsThreshold, FRAME_VALUE); method.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class))); CodeTreeBuilder builder = method.createBuilder(); SpecializationGroup group = createSpecializationGroups(); CodeTree execution = createGuardAndCast(group, genericType, locals, new SpecializationBody(false, false) { @Override public CodeTree createBody(SpecializationData specialization, LocalContext values) { CodeTypeElement generatedType = specializationClasses.get(specialization); if (generatedType == null) { throw new AssertionError("No generated type for " + specialization); } return createSlowPathExecute(specialization, values); } }); builder.tree(execution); if (hasFallthrough(group, genericType, locals, false, null)) { builder.returnNull(); } return method; }
private CodeExecutableElement createFallbackGuardMethod() { boolean frameUsed = node.isFrameUsedByAnyGuard(); LocalContext locals = LocalContext.load(this); if (!frameUsed) { locals.removeValue(FRAME_VALUE); } CodeExecutableElement boundaryMethod = locals.createMethod(modifiers(PRIVATE), getType(boolean.class), "guardFallback", varArgsThreshold, FRAME_VALUE); if (!frameUsed) { boundaryMethod.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(TruffleBoundary.class))); } CodeTreeBuilder builder = boundaryMethod.createBuilder(); builder.startReturn(); builder.startCall("createNext"); locals.addReferencesTo(builder, FRAME_VALUE); builder.end(); builder.string(" == null"); builder.end(); return boundaryMethod; }
public CodeTypeElement create() { Modifier visibility = ElementUtils.getVisibility(node.getTemplateType().getModifiers()); TypeMirror nodeFactory = ElementUtils.getDeclaredType(ElementUtils.fromTypeMirror(context.getType(NodeFactory.class)), 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.getImplements().add(nodeFactory); CodeAnnotationMirror supressWarnings = new CodeAnnotationMirror(context.getDeclaredType(SuppressWarnings.class)); supressWarnings.setElementValue(supressWarnings.findExecutableElement("value"), new CodeAnnotationValue(Arrays.asList(new CodeAnnotationValue("unchecked"), new CodeAnnotationValue("rawtypes")))); clazz.getAnnotationMirrors().add(supressWarnings); clazz.add(createNodeFactoryConstructor()); clazz.add(createCreateGetNodeClass()); clazz.add(createCreateGetExecutionSignature()); clazz.add(createCreateGetNodeSignatures()); clazz.add(createCreateNodeMethod()); clazz.add(createGetInstanceMethod(visibility)); clazz.add(createInstanceConstant(clazz.asType())); createFactoryMethods(clazz); } return clazz; }
public CodeTypeElement create() { String typeName = typeName(forType); TypeMirror baseType = context.getType(Object.class); CodeTypeElement clazz = GeneratorUtils.createClass(typeSystem, null, modifiers(PUBLIC, FINAL, STATIC), typeName, baseType); for (TypeMirror sourceType : sourceTypes) { CodeVariableElement hasSeen = new CodeVariableElement(modifiers(PUBLIC), context.getType(boolean.class), seenFieldName(sourceType)); hasSeen.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(CompilationFinal.class))); clazz.add(hasSeen); } clazz.add(createConstructor(clazz)); if (isTypeBoxingOptimized(options.monomorphicTypeBoxingOptimization(), forType)) { clazz.add(createIsMonomorphic()); } clazz.add(createCast(false)); clazz.add(createCast(true)); clazz.add(createCheck()); clazz.add(createMerge(clazz)); clazz.add(createCreate(clazz)); return clazz; }
private Element createIsValid(TypeMirror assumptionType) { CodeExecutableElement isValid = new CodeExecutableElement(modifiers(PRIVATE, STATIC), getType(boolean.class), "isValid_"); CodeTreeBuilder builder = isValid.createBuilder(); if (assumptionType.getKind() == TypeKind.ARRAY) { isValid.addAnnotationMirror(new CodeAnnotationMirror(context.getDeclaredType(ExplodeLoop.class))); isValid.addParameter(new CodeVariableElement(getType(Assumption[].class), "assumptions")); builder.startIf().string("assumptions == null").end().startBlock().returnFalse().end(); builder.startFor().startGroup().type(((ArrayType) assumptionType).getComponentType()).string(" assumption : assumptions").end().end(); builder.startBlock(); builder.startIf().string("assumption == null || !assumption.isValid()").end(); builder.startBlock(); builder.returnFalse(); builder.end(); builder.end(); builder.returnTrue(); } else { isValid.addParameter(new CodeVariableElement(getType(Assumption.class), "assumption")); builder.startReturn().string("assumption != null && assumption.isValid()").end(); } return isValid; }
private void addUnsupportedMethod(CodeTypeElement clazz) { CodeVariableElement seenUnsupportedField = new CodeVariableElement(modifiers(PRIVATE), getType(boolean.class), "seenUnsupported0"); seenUnsupportedField.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(CompilationFinal.class))); clazz.add(seenUnsupportedField); LocalContext locals = LocalContext.load(this); CodeExecutableElement method = locals.createMethod(modifiers(PRIVATE), getType(UnsupportedSpecializationException.class), "unsupported", varArgsThreshold); CodeTreeBuilder builder = method.createBuilder(); builder.startIf().string("!").string(seenUnsupportedField.getName()).end().startBlock(); builder.startStatement().startStaticCall(getType(CompilerDirectives.class), "transferToInterpreterAndInvalidate").end().end(); builder.startStatement().string(seenUnsupportedField.getName()).string(" = true").end(); builder.end(); builder.startReturn(); builder.startNew(getType(UnsupportedSpecializationException.class)); builder.string("this"); builder.tree(createGetSuppliedChildren()); locals.addReferencesTo(builder); builder.end(); builder.end(); clazz.add(method); }