private void genSortVisitors(ADT api) {
Iterator<Type> types = api.typeIterator();
bothPrintFoldOpen("sort visitors");
while (types.hasNext()) {
Type type = types.next();
String type_id = StringConversions.makeIdentifier(type.getId());
String type_name = buildTypeName(type);
StringBuffer decl_buf = new StringBuffer();
String visitor_name = prefix + "visit" + type_id;
decl_buf.append(type_name);
decl_buf.append(" ");
decl_buf.append(visitor_name);
decl_buf.append("(");
decl_buf.append(type_name);
decl_buf.append(" arg");
Iterator<Field> fields = type.fieldIterator();
while (fields.hasNext()) {
Field field = fields.next();
if (!field.getType().equals(type.getId())) {
decl_buf.append(", ");
decl_buf.append(genAcceptor(field));
}
}
decl_buf.append(")");
String decl = decl_buf.toString();
hprintln(decl + ";");
printDocHead("Apply functions to the children of a " + type_name,
"");
printDocReturn("A new "
+ type_name
+ " with new children where the argument functions might have applied");
printDocTail();
printFoldOpen(decl);
println(decl + " {");
Iterator<Alternative> alts = type.alternativeIterator();
while (alts.hasNext()) {
Alternative alt = alts.next();
genSortVisitorAltImpl(type, alt);
}