// genuniversal.beh -- generate code for DisplayVisitor. // $Id: gendisplayvis.beh,v 1.1 1998/03/11 22:27:53 dougo Exp $ Program { /** Add a "DisplayVisitor" class to the set of class definitions. Don't call this until after buildClassDefTable()! */ void addDisplayVisitor(String name) (@ addClassDef(ClassDef.parse("notparsed visitor " + name + " = int.")); @) /** Generate the behavior file for DisplayVisitor. */ void generateDisplayVisitor(String name, File file) = allParts { before Program (@ host.openOutputFile(file); Program.out.println(host.genericOutputVisitorPreamble(name)); @) (@ ClassName classname; @) before ClassDef (@ classname = host.get_classname(); // don't do anything for alternation classes if (host.isAlternationClass()) return; boolean rep = classname.isOrWasRepetitionClass(); String body = " out.print(\": " + classname + " " + (rep ? "{" : "(") + "\");\n" + " indent++;\n"; Program.out.println(classname.makeBefore(body)); body = " out.print(\" " + (rep ? "}" : ")") + "\");\n" + " indent--;\n"; Program.out.println(classname.makeAfter(body)); @) before Part (@ ClassName dest = host.get_classname(); String deststr = dest.toString(); PartName partname = host.get_partname(); String body = " out.println();" + " for (int i = 0; i < indent; i++) out.print(\"\\t\");\n" + " out.print(\"<" + partname + "> \");\n"; if (dest.isBuiltinType()) { if (deststr.equals("char")) { body += " out.print(\" '\"" + " + source.get_" + partname + "() + \"' \");\n"; } else { body += " out.print(\" : " + dest + " \\\"\" + dest + \"\\\"\");\n"; } } else if (dest.isTerminalClass()) { body += " out.print(\" : " + dest + "\");\n"; if (deststr.equals("String")) { body += " out.print(\" \\\"\"" + " + source.get_" + partname + "() + \"\\\" \");\n"; } else if (deststr.equals("Text")) { body += " out.print(\" " + Text.begin + "\"" + " + source.get_" + partname + "() + " + Text.quoted_end + " + \" \");\n"; } else if (deststr.equals("Character")) { body += " out.print(\" '\"" + " + source.get_" + partname + "() + \"' \");\n"; } else { body += " out.print(\" \\\"\" + source.get_" + partname + "() + \"\\\"\");\n"; } } Program.out.println(host.makeBefore(classname, body)); @) after Program (@ Program.out.println("}"); host.closeOutputFile(); @) } }