Select Git revision
labcomm_fd_reader_writer.h
Forked from
Anders Blomdell / LabComm
Source project has a limited visibility.
PrettyPrint.jrag 2.55 KiB
import java.io.PrintStream;
aspect PPIndentation {
inh String Exp.pp_indent();
inh String Field.pp_indent();
inh String StructType.pp_indent();
eq StructType.getField(int index).pp_indent() = pp_indent() + " ";
eq Program.getDecl(int index).pp_indent() = "";
}
aspect PrettyPrint {
public void ASTNode.pp(PrintStream out) {
throw new Error(this.getClass().getName() +
".pp(PrintStream out)" +
" not declared");
}
public void Program.pp(PrintStream out) {
for(int i = 0; i < getNumDecl(); i++) {
getDecl(i).pp(out);
}
}
// Pretty print declarations
public void TypeDecl.pp(PrintStream out) {
out.print("typedef ");
getType().ppIdentifier(out, getName());
out.println(";");
}
public void SampleDecl.pp(PrintStream out) {
out.print("sample ");
getType().ppIdentifier(out, getName());
out.println(";");
}
public void Field.pp(PrintStream out) {
out.print(pp_indent());
getType().ppIdentifier(out, getName());
out.println(";");
}
// Pretty print variable of a given type
public void Type.ppIdentifier(PrintStream out, String id) {
ppPrefix(out);
out.print(" ");
out.print(id);
}
public void ArrayType.ppIdentifier(PrintStream out, String id) {
ppPrefix(out);
out.print(" ");
out.print(id);
ppSuffix(out);
}
// PrettyPrint prefix type info
public void Type.ppPrefix(PrintStream out) {
throw new Error(this.getClass().getName() +
".ppPrefix(PrintStream out)" +
" not declared");
}
public void VoidType.ppPrefix(PrintStream out) {
out.print("void");
}