Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to specify explicitly which StmtPrinter to use #779

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@
}

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 @@
}

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

printer.newline();
Expand All @@ -228,7 +230,7 @@
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 @@
}
}

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());
}

Check warning on line 282 in sootup.core/src/main/java/sootup/core/util/printer/JimplePrinter.java

View check run for this annotation

Codecov / codecov/patch

sootup.core/src/main/java/sootup/core/util/printer/JimplePrinter.java#L281-L282

Added lines #L281 - L282 were not covered by tests

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