Skip to content

Commit

Permalink
Merge pull request #779 from soot-oss/feature/explicitStmtPrinter
Browse files Browse the repository at this point in the history
allow to specify explicitly which StmtPrinter to use
  • Loading branch information
stschott authored Dec 19, 2023
2 parents 3cf4a05 + 9eb2b5d commit 129eeb7
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ private LabeledStmtPrinter determinePrinter() {
}

public void printTo(SootClass<?> cl, PrintWriter out) {
printTo(cl, out, determinePrinter());
}

LabeledStmtPrinter printer = determinePrinter();
public void printTo(SootClass<?> cl, PrintWriter out, LabeledStmtPrinter printer) {
printer.enableImports(options.contains(Option.UseImports));

// add jimple line number tags
Expand Down Expand Up @@ -207,7 +209,7 @@ public void printTo(SootClass<?> cl, PrintWriter out) {
}

// Print methods
printMethods(cl, printer, out);
printMethods(cl, printer);
printer.literal("}");

printer.newline();
Expand All @@ -228,7 +230,7 @@ public void printTo(SootClass<?> cl, PrintWriter out) {
out.println(printer.toString());
}

private void printMethods(SootClass<?> cl, LabeledStmtPrinter printer, PrintWriter out) {
private void printMethods(SootClass<?> cl, LabeledStmtPrinter printer) {
Iterator<? extends Method> methodIt = cl.getMethods().iterator();
if (methodIt.hasNext()) {
printer.incIndent();
Expand Down Expand Up @@ -261,19 +263,25 @@ private void printMethods(SootClass<?> cl, LabeledStmtPrinter printer, PrintWrit
}
}

public void printTo(Body body, PrintWriter out) {
printTo(body, out, determinePrinter());
}

/**
* Prints out the method corresponding to body Body, (declaration and body), in the textual format
* corresponding to the IR used to encode body body.
*/
public void printTo(Body body, PrintWriter out) {
LabeledStmtPrinter printer = determinePrinter();
public void printTo(Body body, PrintWriter out, LabeledStmtPrinter printer) {
printer.enableImports(options.contains(Option.UseImports));
printBody(body, printer);
out.print(printer);
}

public void printTo(StmtGraph<?> graph, PrintWriter out) {
LabeledStmtPrinter printer = determinePrinter();
printTo(graph, out, determinePrinter());
}

public void printTo(StmtGraph<?> graph, PrintWriter out, LabeledStmtPrinter printer) {
printStmts(graph, printer);
out.print(printer);
}
Expand Down

0 comments on commit 129eeb7

Please sign in to comment.