private void generateSaveOldPolymorphismState(CodeTreeBuilder builder, FrameState frameState) { builder.declaration(state.bitSetType, OLD_STATE, state.createMaskedReference(frameState, reachableSpecializations.toArray())); if (requiresExclude()) { builder.declaration(exclude.bitSetType, OLD_EXCLUDE, "exclude"); } if (requiresCacheCheck()) { builder.declaration(context.getType(int.class), OLD_CACHE_COUNT, "state == 0 ? 0 : " + COUNT_CACHES + "()"); } }
public CodeTreeBuilder declaration(TypeMirror type, String name, CodeTreeBuilder init) { if (init == this) { throw new IllegalArgumentException("Recursive builder usage."); } return declaration(type, name, init.getTree()); }
public CodeTreeBuilder declaration(TypeMirror type, String name, CodeTreeBuilder init) { if (init == this) { throw new IllegalArgumentException("Recursive builder usage."); } return declaration(type, name, init.getTree()); }
public CodeTreeBuilder declaration(String type, String name, String init) { return declaration(type, name, singleString(init)); }
public CodeTreeBuilder declaration(String type, String name, String init) { return declaration(type, name, singleString(init)); }
public CodeTreeBuilder declaration(TypeMirror type, String name, String init) { return declaration(type, name, singleString(init)); }
public CodeTreeBuilder declaration(TypeMirror type, String name, String init) { return declaration(type, name, singleString(init)); }
public CodeTree createDeclaration(CodeTree init) { return CodeTreeBuilder.createBuilder().declaration(getTypeMirror(), getName(), init).build(); }
public CodeTree createDeclaration(CodeTree init) { return CodeTreeBuilder.createBuilder().declaration(getTypeMirror(), getName(), init).build(); }
private Collection<IfTriple> storeCache(FrameState frameState, SpecializationData specialization, CacheExpression cache, CodeTree value) { if (value == null) { return Collections.emptyList(); } String name = createFieldName(specialization, cache.getParameter()); LocalVariable var = frameState.get(name); if (var != null) { // already initialized return Collections.emptyList(); } TypeMirror type = cache.getParameter().getType(); CodeTreeBuilder builder = new CodeTreeBuilder(null); String refName = name + "_"; builder.declaration(type, refName, value); frameState.set(name, new LocalVariable(type, name, CodeTreeBuilder.singleString(refName))); return Arrays.asList(new IfTriple(builder.build(), null, null)); }
private Element createCountCaches() { TypeMirror returnType = getType(int.class); CodeExecutableElement executable = new CodeExecutableElement(modifiers(PRIVATE), returnType, COUNT_CACHES); CodeTreeBuilder builder = executable.createBuilder(); final String cacheCount = "cache" + COUNT_SUFIX; builder.declaration(context.getType(int.class), cacheCount, "0"); for (SpecializationData specialization : reachableSpecializations) { if (useSpecializationClass(specialization) && specialization.getMaximumNumberOfInstances() > 1) { String typeName = createSpecializationTypeName(specialization); String fieldName = createSpecializationFieldName(specialization); String localName = createSpecializationLocalName(specialization); builder.declaration(typeName, localName, "this." + fieldName); builder.startWhile().string(localName, " != null"); builder.end(); builder.startBlock().statement(cacheCount + "++").statement(localName + "= " + localName + ".next_"); builder.end(); } } builder.startReturn().statement(cacheCount); return executable; }
private void initializeCache(CodeTreeBuilder builder, SpecializationData specialization, CacheExpression cache, LocalContext currentValues) { CodeTree initializer = DSLExpressionGenerator.write(cache.getExpression(), accessParent(null), castBoundTypes(bindExpressionValues(cache.getExpression(), specialization, currentValues))); String name = cache.getParameter().getLocalName(); // multiple specializations might use the same name String varName = name + specialization.getIndex(); TypeMirror type = cache.getParameter().getType(); builder.declaration(type, varName, initializer); currentValues.set(name, new LocalVariable(type, varName, null, null)); }
private Element createCheckForPolymorphicSpecialize() { final boolean requiresExclude = requiresExclude(); final boolean requiresCacheCheck = requiresCacheCheck(); TypeMirror returnType = getType(void.class); CodeExecutableElement executable = new CodeExecutableElement(modifiers(PRIVATE), returnType, CHECK_FOR_POLYMORPHIC_SPECIALIZE); executable.addParameter(new CodeVariableElement(state.bitSetType, OLD_STATE)); if (requiresExclude) { executable.addParameter(new CodeVariableElement(exclude.bitSetType, OLD_EXCLUDE)); } if (requiresCacheCheck) { executable.addParameter(new CodeVariableElement(getType(int.class), OLD_CACHE_COUNT)); } CodeTreeBuilder builder = executable.createBuilder(); builder.declaration(state.bitSetType, NEW_STATE, state.createMaskedReference(FrameState.load(this), reachableSpecializations.toArray())); if (requiresExclude) { builder.declaration(exclude.bitSetType, NEW_EXCLUDE, exclude.createReference(FrameState.load(this))); } builder.startIf().string("(" + OLD_STATE + " ^ " + NEW_STATE + ") != 0"); if (requiresExclude) { builder.string(" || "); builder.string("(" + OLD_EXCLUDE + " ^ " + NEW_EXCLUDE + ") != 0"); } if (requiresCacheCheck) { builder.string(" || " + OLD_CACHE_COUNT + " < " + COUNT_CACHES + "()"); } builder.end(); // if builder.startBlock().startStatement().startCall("this", REPORT_POLYMORPHIC_SPECIALIZE).end(2); builder.end(); // true block return executable; }
callBuilder.string(" : null"); name += "_"; builder.declaration(child.getNodeType(), name, callBuilder.build());
builder.declaration("int", countName, CodeTreeBuilder.singleString("0")); builder.declaration("boolean", duplicateFoundName, CodeTreeBuilder.singleString("false"));
callBuilder.string(" : null"); name += "_"; builder.declaration(child.getNodeType(), name, callBuilder.build());
String fieldName = createSpecializationFieldName(specialization); String localName = createSpecializationLocalName(specialization); builder.declaration(typeName, localName, "this." + fieldName); CodeTree check = builder.create().startParantheses().string(localName, " == null || ", localName, ".next_ == null").end().build();
private Element createCreate(CodeTypeElement clazz) { String methodName = "create"; CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, STATIC), clazz.asType(), methodName); method.addParameter(new CodeVariableElement(context.getType(Object.class), "value")); CodeTreeBuilder builder = method.createBuilder(); builder.declaration(clazz.asType(), "newCast", builder.create().startNew(clazz.asType()).end()); for (TypeMirror sourceType : sourceTypes) { String seenField = seenFieldName(sourceType); builder.startStatement(); builder.string("newCast.").string(seenField).string(" = ").tree(TypeSystemCodeGenerator.check(typeSystem, sourceType, "value")); builder.end(); } builder.startReturn().string("newCast").end(); return method; }
builder.declaration(context.getType(Lock.class), "lock", "getLock()"); builder.declaration(context.getType(boolean.class), "hasLock", "true"); builder.statement("lock.lock()"); builder.tree(state.createLoad(frameState));
builder.declaration(context.getType(Lock.class), "lock", "getLock()");